Proper way to access registers in a PCI configuration space

冷暖自知 提交于 2019-12-04 15:03:40

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