Subversion Repositories shark

Rev

Rev 428 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
430 giacomo 1
#include <linuxcomp.h>
2
 
428 giacomo 3
#include <linux/pci.h>
4
#include <linux/module.h>
5
#include <linux/ioport.h>
6
 
7
/*
8
 * This interrupt-safe spinlock protects all accesses to PCI
9
 * configuration space.
10
 */
11
 
12
static spinlock_t pci_lock = SPIN_LOCK_UNLOCKED;
13
 
14
/*
15
 *  Wrappers for all PCI configuration access functions.  They just check
16
 *  alignment, do locking and call the low-level functions pointed to
17
 *  by pci_dev->ops.
18
 */
19
 
20
#define PCI_byte_BAD 0
21
#define PCI_word_BAD (pos & 1)
22
#define PCI_dword_BAD (pos & 3)
23
 
24
#define PCI_OP_READ(size,type,len) \
25
int pci_bus_read_config_##size \
26
        (struct pci_bus *bus, unsigned int devfn, int pos, type *value) \
27
{                                                                       \
28
        int res;                                                        \
29
        unsigned long flags;                                            \
30
        u32 data = 0;                                                   \
31
        if (PCI_##size##_BAD) return PCIBIOS_BAD_REGISTER_NUMBER;       \
32
        spin_lock_irqsave(&pci_lock, flags);                            \
33
        res = bus->ops->read(bus, devfn, pos, len, &data);              \
34
        *value = (type)data;                                            \
35
        spin_unlock_irqrestore(&pci_lock, flags);                       \
36
        return res;                                                     \
37
}
38
 
39
#define PCI_OP_WRITE(size,type,len) \
40
int pci_bus_write_config_##size \
41
        (struct pci_bus *bus, unsigned int devfn, int pos, type value)  \
42
{                                                                       \
43
        int res;                                                        \
44
        unsigned long flags;                                            \
45
        if (PCI_##size##_BAD) return PCIBIOS_BAD_REGISTER_NUMBER;       \
46
        spin_lock_irqsave(&pci_lock, flags);                            \
47
        res = bus->ops->write(bus, devfn, pos, len, value);             \
48
        spin_unlock_irqrestore(&pci_lock, flags);                       \
49
        return res;                                                     \
50
}
51
 
52
PCI_OP_READ(byte, u8, 1)
53
PCI_OP_READ(word, u16, 2)
54
PCI_OP_READ(dword, u32, 4)
55
PCI_OP_WRITE(byte, u8, 1)
56
PCI_OP_WRITE(word, u16, 2)
57
PCI_OP_WRITE(dword, u32, 4)
58
 
59
EXPORT_SYMBOL(pci_bus_read_config_byte);
60
EXPORT_SYMBOL(pci_bus_read_config_word);
61
EXPORT_SYMBOL(pci_bus_read_config_dword);
62
EXPORT_SYMBOL(pci_bus_write_config_byte);
63
EXPORT_SYMBOL(pci_bus_write_config_word);
64
EXPORT_SYMBOL(pci_bus_write_config_dword);