Adding upstream version 4.00~pre54+dfsg.
[syslinux-debian/hramrach.git] / com32 / lib / pci / readx.c
blobed66d5b2ac72e0c8a9f5aa3cc3d3cc8b0dea9433
1 #include "pci/pci.h"
3 TYPE BWL(pci_read) (pciaddr_t a)
5 TYPE r;
7 for (;;) {
8 switch (__pci_cfg_type) {
9 case PCI_CFG_AUTO:
10 pci_set_config_type(PCI_CFG_AUTO);
11 break; /* Try again */
13 case PCI_CFG_TYPE1:
15 uint32_t oldcf8;
16 cli();
17 oldcf8 = inl(0xcf8);
18 outl(a, 0xcf8);
19 r = BWL(in) (0xcfc + (a & 3));
20 outl(oldcf8, 0xcf8);
21 sti();
23 return r;
25 case PCI_CFG_TYPE2:
27 uint8_t oldcf8, oldcfa;
29 if (a & (0x10 << 11))
30 return (TYPE) ~ 0; /* Device 16-31 not supported */
32 cli();
33 oldcf8 = inb(0xcf8);
34 oldcfa = inb(0xcfa);
35 outb(0xf0 + ((a >> (8 - 1)) & 0x0e), 0xcf8);
36 outb(a >> 16, 0xcfa);
37 r = BWL(in) (0xc000 + ((a >> (11 - 8)) & 0xf00) + (a & 0xff));
38 outb(oldcf8, 0xcf8);
39 outb(oldcfa, 0xcfa);
40 sti();
42 return r;
44 case PCI_CFG_BIOS:
45 return (TYPE) __pci_read_write_bios(BIOSCALL, 0, a);
47 default:
48 return (TYPE) ~ 0;