pci_bus_read_config_dword实现说明

来源:互联网 发布:blending 算法 编辑:程序博客网 时间:2024/06/09 15:02

  在学习linux 内核启动pci总线枚举的过程中,发现跟踪到底层扫描总线上每个设备,是通过读取每个设备的vendor id来确定设备的有无,在这里遇到了一个问题,就是函数pci_bus_read_config_dword没有找到实现,只是找到了EXPORT_SYMBOL(pci_bus_read_config_dword),没有具体的实现,仔细看了一下access.c文件才发现这个问题所在,先贴出代码:


#define PCI_byte_BAD 0
#define PCI_word_BAD (pos & 1)
#define PCI_dword_BAD (pos & 3)

#define PCI_OP_READ(size,type,len) \
int pci_bus_read_config_##size \
    (struct pci_bus *bus, unsigned int devfn, int pos, type *value) \
{                                   \
    int res;                            \
    unsigned long flags;                        \
    u32 data = 0;                           \
    if (PCI_##size##_BAD) return PCIBIOS_BAD_REGISTER_NUMBER;   \
    spin_lock_irqsave(&pci_lock, flags);                \
    res = bus->ops->read(bus, devfn, pos, len, &data);      \
    *value = (type)data;                        \
    spin_unlock_irqrestore(&pci_lock, flags);           \
    return res;                         \
}

#define PCI_OP_WRITE(size,type,len) \
int pci_bus_write_config_##size \
    (struct pci_bus *bus, unsigned int devfn, int pos, type value)  \
{                                   \
    int res;                            \
    unsigned long flags;                        \
    if (PCI_##size##_BAD) return PCIBIOS_BAD_REGISTER_NUMBER;   \
    spin_lock_irqsave(&pci_lock, flags);                \
    res = bus->ops->write(bus, devfn, pos, len, value);     \
    spin_unlock_irqrestore(&pci_lock, flags);           \
    return res;                         \
}

PCI_OP_READ(byte, u8, 1)
PCI_OP_READ(word, u16, 2)
PCI_OP_READ(dword, u32, 4)
PCI_OP_WRITE(byte, u8, 1)
PCI_OP_WRITE(word, u16, 2)
PCI_OP_WRITE(dword, u32, 4)

EXPORT_SYMBOL(pci_bus_read_config_byte);
EXPORT_SYMBOL(pci_bus_read_config_word);
EXPORT_SYMBOL(pci_bus_read_config_dword);
EXPORT_SYMBOL(pci_bus_write_config_byte);
EXPORT_SYMBOL(pci_bus_write_config_word);
EXPORT_SYMBOL(pci_bus_write_config_dword);

看PCI_OP_READ宏定义,##是宏定义中用来字符串替换的,也就是将宏定义穿进来的参数字符串原封不动替换。

这样的话也酒有了相应的函数pci_bus_read_config_byte/word/dword...