2 #include <linux/module.h>
3 #include <linux/ioport.h>
6 * This interrupt-safe spinlock protects all accesses to PCI
10 static DEFINE_SPINLOCK(pci_lock);
13 * Wrappers for all PCI configuration access functions. They just check
14 * alignment, do locking and call the low-level functions pointed to
18 #define PCI_byte_BAD 0
19 #define PCI_word_BAD (pos & 1)
20 #define PCI_dword_BAD (pos & 3)
22 #define PCI_OP_READ(size,type,len) \
23 int pci_bus_read_config_##size \
24 (struct pci_bus *bus, unsigned int devfn, int pos, type *value) \
27 unsigned long flags; \
29 if (PCI_##size##_BAD) return PCIBIOS_BAD_REGISTER_NUMBER; \
30 spin_lock_irqsave(&pci_lock, flags); \
31 res = bus->ops->read(bus, devfn, pos, len, &data); \
32 *value = (type)data; \
33 spin_unlock_irqrestore(&pci_lock, flags); \
37 #define PCI_OP_WRITE(size,type,len) \
38 int pci_bus_write_config_##size \
39 (struct pci_bus *bus, unsigned int devfn, int pos, type value) \
42 unsigned long flags; \
43 if (PCI_##size##_BAD) return PCIBIOS_BAD_REGISTER_NUMBER; \
44 spin_lock_irqsave(&pci_lock, flags); \
45 res = bus->ops->write(bus, devfn, pos, len, value); \
46 spin_unlock_irqrestore(&pci_lock, flags); \
50 PCI_OP_READ(byte, u8, 1)
51 PCI_OP_READ(word, u16, 2)
52 PCI_OP_READ(dword, u32, 4)
53 PCI_OP_WRITE(byte, u8, 1)
54 PCI_OP_WRITE(word, u16, 2)
55 PCI_OP_WRITE(dword, u32, 4)
57 EXPORT_SYMBOL(pci_bus_read_config_byte);
58 EXPORT_SYMBOL(pci_bus_read_config_word);
59 EXPORT_SYMBOL(pci_bus_read_config_dword);
60 EXPORT_SYMBOL(pci_bus_write_config_byte);
61 EXPORT_SYMBOL(pci_bus_write_config_word);
62 EXPORT_SYMBOL(pci_bus_write_config_dword);