Adding upstream version 3.50~pre5.
[syslinux-debian/hramrach.git] / com32 / lib / pci / readx.c
blob3f19cad291a4d517e8f8fc4bda73796add04ce76
1 #include "pci/pci.h"
2 #include <string.h>
4 TYPE BWL(pci_read) (pciaddr_t a)
6 TYPE r;
8 for (;;) {
9 switch ( __pci_cfg_type ) {
10 case PCI_CFG_AUTO:
11 pci_set_config_type(PCI_CFG_AUTO);
12 break; /* Try again */
14 case PCI_CFG_TYPE1:
16 uint32_t oldcf8;
17 cli();
18 oldcf8 = inl(0xcf8);
19 outl(a, 0xcf8);
20 r = BWL(in) (0xcfc + (a & 3));
21 outl(oldcf8, 0xcf8);
22 sti();
24 return r;
26 case PCI_CFG_TYPE2:
28 uint8_t oldcf8, oldcfa;
30 if ( a & (0x10 << 11) )
31 return (TYPE)~0; /* Device 16-31 not supported */
33 cli();
34 oldcf8 = inb(0xcf8);
35 oldcfa = inb(0xcfa);
36 outb(0xf0 + ((a >> (8-1)) & 0x0e), 0xcf8);
37 outb(a >> 16, 0xcfa);
38 r = BWL(in) (0xc000 + ((a >> (11-8)) & 0xf00) + (a & 0xff));
39 outb(oldcf8, 0xcf8);
40 outb(oldcfa, 0xcfa);
41 sti();
43 return r;
45 case PCI_CFG_BIOS:
46 return (TYPE) __pci_read_bios(BIOSCALL, a);
48 default:
49 return (TYPE)~0;