aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/access.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/pci/access.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/pci/access.c')
-rw-r--r--drivers/pci/access.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/drivers/pci/access.c b/drivers/pci/access.c
new file mode 100644
index 000000000000..24a76de49f41
--- /dev/null
+++ b/drivers/pci/access.c
@@ -0,0 +1,62 @@
1#include <linux/pci.h>
2#include <linux/module.h>
3#include <linux/ioport.h>
4
5/*
6 * This interrupt-safe spinlock protects all accesses to PCI
7 * configuration space.
8 */
9
10static DEFINE_SPINLOCK(pci_lock);
11
12/*
13 * Wrappers for all PCI configuration access functions. They just check
14 * alignment, do locking and call the low-level functions pointed to
15 * by pci_dev->ops.
16 */
17
18#define PCI_byte_BAD 0
19#define PCI_word_BAD (pos & 1)
20#define PCI_dword_BAD (pos & 3)
21
22#define PCI_OP_READ(size,type,len) \
23int pci_bus_read_config_##size \
24 (struct pci_bus *bus, unsigned int devfn, int pos, type *value) \
25{ \
26 int res; \
27 unsigned long flags; \
28 u32 data = 0; \
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); \
34 return res; \
35}
36
37#define PCI_OP_WRITE(size,type,len) \
38int pci_bus_write_config_##size \
39 (struct pci_bus *bus, unsigned int devfn, int pos, type value) \
40{ \
41 int res; \
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); \
47 return res; \
48}
49
50PCI_OP_READ(byte, u8, 1)
51PCI_OP_READ(word, u16, 2)
52PCI_OP_READ(dword, u32, 4)
53PCI_OP_WRITE(byte, u8, 1)
54PCI_OP_WRITE(word, u16, 2)
55PCI_OP_WRITE(dword, u32, 4)
56
57EXPORT_SYMBOL(pci_bus_read_config_byte);
58EXPORT_SYMBOL(pci_bus_read_config_word);
59EXPORT_SYMBOL(pci_bus_read_config_dword);
60EXPORT_SYMBOL(pci_bus_write_config_byte);
61EXPORT_SYMBOL(pci_bus_write_config_word);
62EXPORT_SYMBOL(pci_bus_write_config_dword);