diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2009-04-21 19:18:10 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2009-04-21 19:18:10 +0000 |
commit | 46c3215394ff5366759d3c079519c102f888575a (patch) | |
tree | a6fd08ddb4849b7172a3f66847ff492b695ee470 /sys/arch/amd64/pci | |
parent | ade68dd42e5a7a30c8ba693d71d965a7ea5faffb (diff) |
Simplify PCI config space access code. There is no way we're ever going to
see the ancient mode 2 on machines capable of running OpenBSD/amd64.
ok deraadt@, toby@, oga@
Diffstat (limited to 'sys/arch/amd64/pci')
-rw-r--r-- | sys/arch/amd64/pci/pci_machdep.c | 230 |
1 files changed, 19 insertions, 211 deletions
diff --git a/sys/arch/amd64/pci/pci_machdep.c b/sys/arch/amd64/pci/pci_machdep.c index 29d371f7067..19137f17676 100644 --- a/sys/arch/amd64/pci/pci_machdep.c +++ b/sys/arch/amd64/pci/pci_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pci_machdep.c,v 1.27 2009/04/21 17:05:29 oga Exp $ */ +/* $OpenBSD: pci_machdep.c,v 1.28 2009/04/21 19:18:09 kettenis Exp $ */ /* $NetBSD: pci_machdep.c,v 1.3 2003/05/07 21:33:58 fvdl Exp $ */ /*- @@ -63,14 +63,6 @@ /* * Machine-specific functions for PCI autoconfiguration. - * - * On PCs, there are two methods of generating PCI configuration cycles. - * We try to detect the appropriate mechanism for this machine and set - * up a few function pointers to access the correct method directly. - * - * The configuration method can be hard-coded in the config file by - * using `options PCI_CONF_MODE=N', where `N' is the configuration mode - * as defined section 3.6.4.1, `Generating Configuration Cycles'. */ #include <sys/types.h> @@ -104,8 +96,6 @@ #include <machine/mpbiosvar.h> #endif -int pci_mode = -1; - struct mutex pci_conf_lock = MUTEX_INITIALIZER(IPL_HIGH); #define PCI_CONF_LOCK() \ @@ -122,30 +112,6 @@ do { \ #define PCI_MODE1_ADDRESS_REG 0x0cf8 #define PCI_MODE1_DATA_REG 0x0cfc -#define PCI_MODE2_ENABLE_REG 0x0cf8 -#define PCI_MODE2_FORWARD_REG 0x0cfa - -#define _m1tag(b, d, f) \ - (PCI_MODE1_ENABLE | ((b) << 16) | ((d) << 11) | ((f) << 8)) -#define _qe(bus, dev, fcn, vend, prod) \ - {_m1tag(bus, dev, fcn), PCI_ID_CODE(vend, prod)} -struct { - u_int32_t tag; - pcireg_t id; -} pcim1_quirk_tbl[] = { - _qe(0, 0, 0, PCI_VENDOR_COMPAQ, PCI_PRODUCT_COMPAQ_TRIFLEX1), - /* XXX Triflex2 not tested */ - _qe(0, 0, 0, PCI_VENDOR_COMPAQ, PCI_PRODUCT_COMPAQ_TRIFLEX2), - _qe(0, 0, 0, PCI_VENDOR_COMPAQ, PCI_PRODUCT_COMPAQ_TRIFLEX4), - /* Triton needed for Connectix Virtual PC */ - _qe(0, 0, 0, PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82437FX), - /* Connectix Virtual PC 5 has a 440BX */ - _qe(0, 0, 0, PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82443BX_NOAGP), - {0, 0xffffffff} /* patchable */ -}; -#undef _m1tag -#undef _qe - /* * PCI doesn't have any special needs; just use the generic versions * of these functions. @@ -173,82 +139,37 @@ void pci_attach_hook(struct device *parent, struct device *self, struct pcibus_attach_args *pba) { - if (pba->pba_bus == 0) { - printf(": configuration mode %d", pci_mode); #ifndef SMALL_KERNEL + if (pba->pba_bus == 0) amdgart_probe(pba); #endif /* !SMALL_KERNEL */ - } } int pci_bus_maxdevs(pci_chipset_tag_t pc, int busno) { - - /* - * Bus number is irrelevant. If Configuration Mechanism 2 is in - * use, can only have devices 0-15 on any bus. If Configuration - * Mechanism 1 is in use, can have devices 0-32 (i.e. the `normal' - * range). - */ - if (pci_mode == 2) - return (16); - else - return (32); + return (32); } pcitag_t pci_make_tag(pci_chipset_tag_t pc, int bus, int device, int function) { - pcitag_t tag; - - switch (pci_mode) { - case 1: - if (bus >= 256 || device >= 32 || function >= 8) - panic("pci_make_tag: bad request"); - - tag.mode1 = PCI_MODE1_ENABLE | - (bus << 16) | (device << 11) | (function << 8); - break; - case 2: - if (bus >= 256 || device >= 16 || function >= 8) - panic("pci_make_tag: bad request"); - - tag.mode2.port = 0xc000 | (device << 8); - tag.mode2.enable = 0xf0 | (function << 1); - tag.mode2.forward = bus; - break; - default: - panic("pci_make_tag: mode not configured"); - } + if (bus >= 256 || device >= 32 || function >= 8) + panic("pci_make_tag: bad request"); - return tag; + return (PCI_MODE1_ENABLE | + (bus << 16) | (device << 11) | (function << 8)); } void pci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag, int *bp, int *dp, int *fp) { - - switch (pci_mode) { - case 1: - if (bp != NULL) - *bp = (tag.mode1 >> 16) & 0xff; - if (dp != NULL) - *dp = (tag.mode1 >> 11) & 0x1f; - if (fp != NULL) - *fp = (tag.mode1 >> 8) & 0x7; - break; - case 2: - if (bp != NULL) - *bp = tag.mode2.forward & 0xff; - if (dp != NULL) - *dp = (tag.mode2.port >> 8) & 0xf; - if (fp != NULL) - *fp = (tag.mode2.enable >> 1) & 0x7; - break; - default: - panic("pci_decompose_tag: mode not configured"); - } + if (bp != NULL) + *bp = (tag >> 16) & 0xff; + if (dp != NULL) + *dp = (tag >> 11) & 0x1f; + if (fp != NULL) + *fp = (tag >> 8) & 0x7; } pcireg_t @@ -257,21 +178,9 @@ pci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg) pcireg_t data; PCI_CONF_LOCK(); - switch (pci_mode) { - case 1: - outl(PCI_MODE1_ADDRESS_REG, tag.mode1 | reg); - data = inl(PCI_MODE1_DATA_REG); - outl(PCI_MODE1_ADDRESS_REG, 0); - break; - case 2: - outb(PCI_MODE2_ENABLE_REG, tag.mode2.enable); - outb(PCI_MODE2_FORWARD_REG, tag.mode2.forward); - data = inl(tag.mode2.port | reg); - outb(PCI_MODE2_ENABLE_REG, 0); - break; - default: - panic("pci_conf_read: mode not configured"); - } + outl(PCI_MODE1_ADDRESS_REG, tag | reg); + data = inl(PCI_MODE1_DATA_REG); + outl(PCI_MODE1_ADDRESS_REG, 0); PCI_CONF_UNLOCK(); return data; @@ -280,112 +189,11 @@ pci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg) void pci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data) { - PCI_CONF_LOCK(); - switch (pci_mode) { - case 1: - outl(PCI_MODE1_ADDRESS_REG, tag.mode1 | reg); - outl(PCI_MODE1_DATA_REG, data); - outl(PCI_MODE1_ADDRESS_REG, 0); - break; - case 2: - outb(PCI_MODE2_ENABLE_REG, tag.mode2.enable); - outb(PCI_MODE2_FORWARD_REG, tag.mode2.forward); - outl(tag.mode2.port | reg, data); - outb(PCI_MODE2_ENABLE_REG, 0); - break; - default: - panic("pci_conf_write: mode not configured"); - } - PCI_CONF_UNLOCK(); -} - -int -pci_mode_detect(void) -{ - -#ifdef PCI_CONF_MODE -#if (PCI_CONF_MODE == 1) || (PCI_CONF_MODE == 2) - return (pci_mode = PCI_CONF_MODE); -#else -#error Invalid PCI configuration mode. -#endif -#else - u_int32_t sav, val; - int i; - pcireg_t idreg; - - if (pci_mode != -1) - return pci_mode; - - /* - * We try to divine which configuration mode the host bridge wants. - */ - - sav = inl(PCI_MODE1_ADDRESS_REG); - - pci_mode = 1; /* assume this for now */ - /* - * catch some known buggy implementations of mode 1 - */ - for (i = 0; i < sizeof(pcim1_quirk_tbl) / sizeof(pcim1_quirk_tbl[0]); - i++) { - pcitag_t t; - - if (!pcim1_quirk_tbl[i].tag) - break; - t.mode1 = pcim1_quirk_tbl[i].tag; - idreg = pci_conf_read(0, t, PCI_ID_REG); /* needs "pci_mode" */ - if (idreg == pcim1_quirk_tbl[i].id) { -#ifdef DEBUG - printf("known mode 1 PCI chipset (%08x)\n", - idreg); -#endif - return (pci_mode); - } - } - - /* - * Strong check for standard compliant mode 1: - * 1. bit 31 ("enable") can be set - * 2. byte/word access does not affect register - */ - outl(PCI_MODE1_ADDRESS_REG, PCI_MODE1_ENABLE); - outb(PCI_MODE1_ADDRESS_REG + 3, 0); - outw(PCI_MODE1_ADDRESS_REG + 2, 0); - val = inl(PCI_MODE1_ADDRESS_REG); - if ((val & 0x80fffffc) != PCI_MODE1_ENABLE) { -#ifdef DEBUG - printf("pci_mode_detect: mode 1 enable failed (%x)\n", - val); -#endif - goto not1; - } + outl(PCI_MODE1_ADDRESS_REG, tag | reg); + outl(PCI_MODE1_DATA_REG, data); outl(PCI_MODE1_ADDRESS_REG, 0); - val = inl(PCI_MODE1_ADDRESS_REG); - if ((val & 0x80fffffc) != 0) - goto not1; - return (pci_mode); -not1: - outl(PCI_MODE1_ADDRESS_REG, sav); - - /* - * This mode 2 check is quite weak (and known to give false - * positives on some Compaq machines). - * However, this doesn't matter, because this is the - * last test, and simply no PCI devices will be found if - * this happens. - */ - outb(PCI_MODE2_ENABLE_REG, 0); - outb(PCI_MODE2_FORWARD_REG, 0); - if (inb(PCI_MODE2_ENABLE_REG) != 0 || - inb(PCI_MODE2_FORWARD_REG) != 0) - goto not2; - return (pci_mode = 2); -not2: - - return (pci_mode = 0); -#endif + PCI_CONF_UNLOCK(); } int |