在PCI配置空间中访问寄存器的正确方法 [英] Proper way to access registers in a PCI configuration space

查看:505
本文介绍了在PCI配置空间中访问寄存器的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您需要访问PCI配置空间中的寄存器时,是否只需要使用内置的BIOS函数来将DWORD读/写到配置空间中?



例如,如果我尝试使用B0:D31:F1上的IDE控制器,是否继续使用该BDF作为BIOS函数的参数来读取/写入配置寄存器?因此,如果我想获取供应商ID,我会读取给定BDF中的第一个DWORD吗?



还是我离基准点远一点?



编辑:



在PCI BIOS规范中,我一直在研究BIOS功能的定义,这些功能用于在配置中读取和写入单词空间。我相信这意味着我可以在配置空间内的各个偏移量处写入寄存器。我想我的问题是,这是在此级别访问这些寄存器的正确方法吗?

解决方案

在阅读了PCI规范之后,我只需要通过给定的中断向量(1Ah)调用PCI BIOS函数。但是,这必须事先进行PCI配置,从而使情况变得复杂。



PCI配置空间似乎没有使用显式地址进行访问,而是使用了BIOS函数。 / p>

编辑:实际上,事实证明BIOS所做的比我知道的要多得多。我要做的就是枚举PCI总线,直到找到IDE控制器的设备和供应商ID。唯一需要的组件是输入/输出端口包装器。 ;

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(总线,插槽,功能,0x02,PCI_READ_CONFIG_WORD);

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

return dev;
}
}
}
}


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?

解决方案

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;
      }
    }
  }
}

这篇关于在PCI配置空间中访问寄存器的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆