1bb0d0a8eSMike Smith /*- 2bb0d0a8eSMike Smith * Copyright (c) 1994,1995 Stefan Esser, Wolfgang StanglMeier 3bb0d0a8eSMike Smith * Copyright (c) 2000 Michael Smith <msmith@freebsd.org> 4bb0d0a8eSMike Smith * Copyright (c) 2000 BSDi 5bb0d0a8eSMike Smith * All rights reserved. 6bb0d0a8eSMike Smith * 7bb0d0a8eSMike Smith * Redistribution and use in source and binary forms, with or without 8bb0d0a8eSMike Smith * modification, are permitted provided that the following conditions 9bb0d0a8eSMike Smith * are met: 10bb0d0a8eSMike Smith * 1. Redistributions of source code must retain the above copyright 11bb0d0a8eSMike Smith * notice, this list of conditions and the following disclaimer. 12bb0d0a8eSMike Smith * 2. Redistributions in binary form must reproduce the above copyright 13bb0d0a8eSMike Smith * notice, this list of conditions and the following disclaimer in the 14bb0d0a8eSMike Smith * documentation and/or other materials provided with the distribution. 15bb0d0a8eSMike Smith * 3. The name of the author may not be used to endorse or promote products 16bb0d0a8eSMike Smith * derived from this software without specific prior written permission. 17bb0d0a8eSMike Smith * 18bb0d0a8eSMike Smith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19bb0d0a8eSMike Smith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20bb0d0a8eSMike Smith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21bb0d0a8eSMike Smith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22bb0d0a8eSMike Smith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23bb0d0a8eSMike Smith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24bb0d0a8eSMike Smith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25bb0d0a8eSMike Smith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26bb0d0a8eSMike Smith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27bb0d0a8eSMike Smith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28bb0d0a8eSMike Smith * SUCH DAMAGE. 29bb0d0a8eSMike Smith * 30bb0d0a8eSMike Smith * $FreeBSD$ 31bb0d0a8eSMike Smith */ 32bb0d0a8eSMike Smith 33bb0d0a8eSMike Smith #include <sys/param.h> 34bb0d0a8eSMike Smith #include <sys/systm.h> 35bb0d0a8eSMike Smith #include <sys/malloc.h> 36bb0d0a8eSMike Smith #include <sys/kernel.h> 37bb0d0a8eSMike Smith #include <sys/bus.h> 38bb0d0a8eSMike Smith 39bb0d0a8eSMike Smith #include <pci/pcivar.h> 40bb0d0a8eSMike Smith #include <pci/pcireg.h> 41bb0d0a8eSMike Smith 42bb0d0a8eSMike Smith /* 43bb0d0a8eSMike Smith * Chipset fixups. 44bb0d0a8eSMike Smith * 45bb0d0a8eSMike Smith * These routines are invoked during the probe phase for devices which 46bb0d0a8eSMike Smith * typically don't have specific device drivers, but which require 47bb0d0a8eSMike Smith * some cleaning up. 48bb0d0a8eSMike Smith */ 49bb0d0a8eSMike Smith 50bb0d0a8eSMike Smith static int fixup_pci_probe(device_t dev); 51bb0d0a8eSMike Smith static void fixbushigh_i1225(device_t dev); 52bb0d0a8eSMike Smith static void fixwsc_natoma(device_t dev); 53bb0d0a8eSMike Smith 54bb0d0a8eSMike Smith static device_method_t fixup_pci_methods[] = { 55bb0d0a8eSMike Smith /* Device interface */ 56bb0d0a8eSMike Smith DEVMETHOD(device_probe, fixup_pci_probe), 57bb0d0a8eSMike Smith DEVMETHOD(device_attach, bus_generic_attach), 58bb0d0a8eSMike Smith { 0, 0 } 59bb0d0a8eSMike Smith }; 60bb0d0a8eSMike Smith 61bb0d0a8eSMike Smith static driver_t fixup_pci_driver = { 62bb0d0a8eSMike Smith "fixup_pci", 63bb0d0a8eSMike Smith fixup_pci_methods, 64bb0d0a8eSMike Smith 0, 65bb0d0a8eSMike Smith }; 66bb0d0a8eSMike Smith 67bb0d0a8eSMike Smith static devclass_t fixup_pci_devclass; 68bb0d0a8eSMike Smith 69bb0d0a8eSMike Smith DRIVER_MODULE(fixup_pci, pci, fixup_pci_driver, fixup_pci_devclass, 0, 0); 70bb0d0a8eSMike Smith 71bb0d0a8eSMike Smith static int 72bb0d0a8eSMike Smith fixup_pci_probe(device_t dev) 73bb0d0a8eSMike Smith { 74bb0d0a8eSMike Smith switch (pci_get_devid(dev)) { 75bb0d0a8eSMike Smith case 0x12258086: /* Intel 82454KX/GX (Orion) */ 76bb0d0a8eSMike Smith fixbushigh_i1225(dev); 77bb0d0a8eSMike Smith break; 78bb0d0a8eSMike Smith case 0x12378086: /* Intel 82440FX (Natoma) */ 79bb0d0a8eSMike Smith fixwsc_natoma(dev); 80bb0d0a8eSMike Smith break; 81bb0d0a8eSMike Smith } 82bb0d0a8eSMike Smith return(ENXIO); 83bb0d0a8eSMike Smith } 84bb0d0a8eSMike Smith 85bb0d0a8eSMike Smith static void 86bb0d0a8eSMike Smith fixbushigh_i1225(device_t dev) 87bb0d0a8eSMike Smith { 88bb0d0a8eSMike Smith int supbus; 89bb0d0a8eSMike Smith 90bb0d0a8eSMike Smith supbus = pci_read_config(dev, 0x41, 1); 91bb0d0a8eSMike Smith if (supbus != 0xff) { 92bb0d0a8eSMike Smith pci_set_secondarybus(dev, supbus + 1); 93bb0d0a8eSMike Smith pci_set_subordinatebus(dev, supbus + 1); 94bb0d0a8eSMike Smith } 95bb0d0a8eSMike Smith } 96bb0d0a8eSMike Smith 97bb0d0a8eSMike Smith static void 98bb0d0a8eSMike Smith fixwsc_natoma(device_t dev) 99bb0d0a8eSMike Smith { 100bb0d0a8eSMike Smith int pmccfg; 101bb0d0a8eSMike Smith 102bb0d0a8eSMike Smith pmccfg = pci_read_config(dev, 0x50, 2); 103bb0d0a8eSMike Smith #if defined(SMP) 104bb0d0a8eSMike Smith if (pmccfg & 0x8000) { 105bb0d0a8eSMike Smith printf("Correcting Natoma config for SMP\n"); 106bb0d0a8eSMike Smith pmccfg &= ~0x8000; 107bb0d0a8eSMike Smith pci_write_config(dev, 0x50, 2, pmccfg); 108bb0d0a8eSMike Smith } 109bb0d0a8eSMike Smith #else 110bb0d0a8eSMike Smith if ((pmccfg & 0x8000) == 0) { 111bb0d0a8eSMike Smith printf("Correcting Natoma config for non-SMP\n"); 112bb0d0a8eSMike Smith pmccfg |= 0x8000; 113bb0d0a8eSMike Smith pci_write_config(dev, 0x50, 2, pmccfg); 114bb0d0a8eSMike Smith } 115bb0d0a8eSMike Smith #endif 116bb0d0a8eSMike Smith } 117