Proper way to access registers in a PCI configuration space

时间秒杀一切 提交于 2019-12-06 06:22:37

问题


When you need to access registers in the PCI configuration space, do you simply need to used built-in BIOS functions to read/write DWORDs into the configuration space?

For example, if I am trying to use an IDE controller that is on B0:D31:F1 do I proceed to read/write the configuration register using that BDF as the parameters to the BIOS functions? So if I wanted to get the vendor id I would read the first DWORD in a given BDF?

Or am I just way off base?

EDIT:

In the PCI BIOS specification, I have been looking over the definitions of the BIOS functions for reading and writing words into the configuration space. Which I believe means that I can write into the registers at various offsets within the configuration space. I guess my question is, is this the correct way of accessing these registers at this level?


回答1:


After reading the PCI specification, I simply need to call the PCI BIOS functions through a given interrupt vector (1Ah). However, this is complicated by the PCI configuration which must happen before hand.

The PCI configuration space appears to not use an explicit address for access, but BIOS function calls.

EDIT: Actually, turns out the BIOS does a lot more than I knew. All I had to do was enumerate the PCI bus until I found the IDE controller's device and vendor ID. The only assembly needed was the in/out port wrappers.


pci_dev_t dev = { 0xffffffff, 0xffffffff, 0xffffffff };

for ( bus = 0; bus < 0xffff; ++bus ) {
  for ( slot = 0; slot < 0xffff; ++slot ) {
    for ( func = 0; func < 0xff; ++func ) {
      uint16_t dev_id  = _pci_read_config_data( bus, slot, func, 0x00, PCI_READ_CONFIG_WORD );
      uint16_t vend_id = _pci_read_config_data( bus, slot, func, 0x02, PCI_READ_CONFIG_WORD );

      if ((vendor == vend_id) && (device == dev_id)) {
        dev.bus      = bus;
        dev.device   = slot;
        dev.function = func;

        return dev;
      }
    }
  }
}


来源:https://stackoverflow.com/questions/778121/proper-way-to-access-registers-in-a-pci-configuration-space

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!