fixup_pci.c revision 69783
169783Smsmith/*-
269783Smsmith * Copyright (c) 1994,1995 Stefan Esser, Wolfgang StanglMeier
369783Smsmith * Copyright (c) 2000 Michael Smith <msmith@freebsd.org>
469783Smsmith * Copyright (c) 2000 BSDi
569783Smsmith * All rights reserved.
669783Smsmith *
769783Smsmith * Redistribution and use in source and binary forms, with or without
869783Smsmith * modification, are permitted provided that the following conditions
969783Smsmith * are met:
1069783Smsmith * 1. Redistributions of source code must retain the above copyright
1169783Smsmith *    notice, this list of conditions and the following disclaimer.
1269783Smsmith * 2. Redistributions in binary form must reproduce the above copyright
1369783Smsmith *    notice, this list of conditions and the following disclaimer in the
1469783Smsmith *    documentation and/or other materials provided with the distribution.
1569783Smsmith * 3. The name of the author may not be used to endorse or promote products
1669783Smsmith *    derived from this software without specific prior written permission.
1769783Smsmith *
1869783Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1969783Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2069783Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2169783Smsmith * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2269783Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2369783Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2469783Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2569783Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2669783Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2769783Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2869783Smsmith * SUCH DAMAGE.
2969783Smsmith *
3069783Smsmith *	$FreeBSD: head/sys/dev/pci/fixup_pci.c 69783 2000-12-08 22:11:23Z msmith $
3169783Smsmith */
3269783Smsmith
3369783Smsmith#include <sys/param.h>
3469783Smsmith#include <sys/systm.h>
3569783Smsmith#include <sys/malloc.h>
3669783Smsmith#include <sys/kernel.h>
3769783Smsmith#include <sys/bus.h>
3869783Smsmith
3969783Smsmith#include <pci/pcivar.h>
4069783Smsmith#include <pci/pcireg.h>
4169783Smsmith
4269783Smsmith/*
4369783Smsmith * Chipset fixups.
4469783Smsmith *
4569783Smsmith * These routines are invoked during the probe phase for devices which
4669783Smsmith * typically don't have specific device drivers, but which require
4769783Smsmith * some cleaning up.
4869783Smsmith */
4969783Smsmith
5069783Smsmithstatic int	fixup_pci_probe(device_t dev);
5169783Smsmithstatic void	fixbushigh_i1225(device_t dev);
5269783Smsmithstatic void	fixwsc_natoma(device_t dev);
5369783Smsmith
5469783Smsmithstatic device_method_t fixup_pci_methods[] = {
5569783Smsmith    /* Device interface */
5669783Smsmith    DEVMETHOD(device_probe,		fixup_pci_probe),
5769783Smsmith    DEVMETHOD(device_attach,		bus_generic_attach),
5869783Smsmith    { 0, 0 }
5969783Smsmith};
6069783Smsmith
6169783Smsmithstatic driver_t fixup_pci_driver = {
6269783Smsmith    "fixup_pci",
6369783Smsmith    fixup_pci_methods,
6469783Smsmith    0,
6569783Smsmith};
6669783Smsmith
6769783Smsmithstatic devclass_t fixup_pci_devclass;
6869783Smsmith
6969783SmsmithDRIVER_MODULE(fixup_pci, pci, fixup_pci_driver, fixup_pci_devclass, 0, 0);
7069783Smsmith
7169783Smsmithstatic int
7269783Smsmithfixup_pci_probe(device_t dev)
7369783Smsmith{
7469783Smsmith    switch (pci_get_devid(dev)) {
7569783Smsmith    case 0x12258086:		/* Intel 82454KX/GX (Orion) */
7669783Smsmith	fixbushigh_i1225(dev);
7769783Smsmith	break;
7869783Smsmith    case 0x12378086:		/* Intel 82440FX (Natoma) */
7969783Smsmith	fixwsc_natoma(dev);
8069783Smsmith	break;
8169783Smsmith    }
8269783Smsmith    return(ENXIO);
8369783Smsmith}
8469783Smsmith
8569783Smsmithstatic void
8669783Smsmithfixbushigh_i1225(device_t dev)
8769783Smsmith{
8869783Smsmith    int		supbus;
8969783Smsmith
9069783Smsmith    supbus = pci_read_config(dev, 0x41, 1);
9169783Smsmith    if (supbus != 0xff) {
9269783Smsmith	pci_set_secondarybus(dev, supbus + 1);
9369783Smsmith	pci_set_subordinatebus(dev, supbus + 1);
9469783Smsmith    }
9569783Smsmith}
9669783Smsmith
9769783Smsmithstatic void
9869783Smsmithfixwsc_natoma(device_t dev)
9969783Smsmith{
10069783Smsmith    int		pmccfg;
10169783Smsmith
10269783Smsmith    pmccfg = pci_read_config(dev, 0x50, 2);
10369783Smsmith#if defined(SMP)
10469783Smsmith    if (pmccfg & 0x8000) {
10569783Smsmith	printf("Correcting Natoma config for SMP\n");
10669783Smsmith	pmccfg &= ~0x8000;
10769783Smsmith	pci_write_config(dev, 0x50, 2, pmccfg);
10869783Smsmith    }
10969783Smsmith#else
11069783Smsmith    if ((pmccfg & 0x8000) == 0) {
11169783Smsmith	printf("Correcting Natoma config for non-SMP\n");
11269783Smsmith	pmccfg |= 0x8000;
11369783Smsmith	pci_write_config(dev, 0x50, 2, pmccfg);
11469783Smsmith    }
11569783Smsmith#endif
11669783Smsmith}
117