Hello,

There is a code (frugally commented) which deals with PCI. In
`drivers/pci/pci_intel.h' there are following macros.

#define PCII_RREG8_(bus, dev, func, reg) \
(pci_outl(PCII_CONFADD, PCII_SELREG_(bus, dev, func, reg)), \
pci_inb(PCII_CONFDATA+((reg)&3)))
#define PCII_RREG16_(bus, dev, func, reg) \
(PCII_RREG8_(bus, dev, func, reg) | \
(PCII_RREG8_(bus, dev, func, reg+1) << 8))
#define PCII_RREG32_(bus, dev, func, reg) \
(PCII_RREG16_(bus, dev, func, reg) | \
(PCII_RREG16_(bus, dev, func, reg+2) << 16))

#define PCII_WREG8_(bus, dev, func, reg, val) \
(pci_outl(PCII_CONFADD, PCII_SELREG_(bus, dev, func, reg)), \
pci_outb(PCII_CONFDATA+((reg)&3), (val)))
#define PCII_WREG16_(bus, dev, func, reg, val) \
(PCII_WREG8_(bus, dev, func, reg, (val)), \
(PCII_WREG8_(bus, dev, func, reg+1, (val) >> 8)))
#define PCII_WREG32_(bus, dev, func, reg, val) \
(PCII_WREG16_(bus, dev, func, reg, (val)), \
(PCII_WREG16_(bus, dev, func, reg+2, (val) >> 16)))

I was just wondering why multiple byte values are read/written byte
after byte. Couldn't 16-bit and 32-bit values be read/written at once
as follows?:

#define PCII_RREG8_(bus, dev, func, reg) \
(pci_outl(PCII_CONFADD, PCII_SELREG_(bus, dev, func, reg)), \
pci_inb(PCII_CONFDATA+((reg)&3)))
#define PCII_RREG16_(bus, dev, func, reg) \
(pci_outl(PCII_CONFADD, PCII_SELREG_(bus, dev, func, reg)), \
pci_inw(PCII_CONFDATA+((reg)&3)))
#define PCII_RREG32_(bus, dev, func, reg) \
(pci_outl(PCII_CONFADD, PCII_SELREG_(bus, dev, func, reg)), \
pci_inl(PCII_CONFDATA))

#define PCII_WREG8_(bus, dev, func, reg, val) \
(pci_outl(PCII_CONFADD, PCII_SELREG_(bus, dev, func, reg)), \
pci_outb(PCII_CONFDATA+((reg)&3), (val)))
#define PCII_WREG16_(bus, dev, func, reg, val) \
(pci_outl(PCII_CONFADD, PCII_SELREG_(bus, dev, func, reg)), \
pci_outw(PCII_CONFDATA+((reg)&3), (val)))
#define PCII_WREG32_(bus, dev, func, reg, val) \
(pci_outl(PCII_CONFADD, PCII_SELREG_(bus, dev, func, reg)), \
pci_outl(PCII_CONFDATA, (val)))

It would perhaps be simpler to understand. Minix with these
modifications works in Qemu as well as natively.

Regards
--
Matej Košík