按照标准PCI总线扫描但结果异常

问题描述

这是扫码

uint32_t pci_read_configd(uint8_t bus,uint8_t dev,uint8_t func,uint8_t offset)
{
    uint32_t address;
    uint32_t lbus  = (uint32_t)bus;
    uint32_t ldev = (uint32_t)dev;
    uint32_t lfunc = (uint32_t)func;
    address = (uint32_t)((lbus << 16) | (ldev << 11) |  (lfunc << 8) | (offset & 0xfc) | ((uint32_t)1 << 31));
    out_port32(0xcf8,address);
    return in_port32(0xcfc);
}

void init_pci(void)
{
    klog("pci","scanning device...");
    
    for (size_t i = 0; i < 16; i++)
    {
        for (size_t l = 0; l < 128; L++)
        {
                if(pci_read_configd(i,l,0) != 0xffff)
                {
                    klog("pci","found device at Bus.%h Dev.%h ID:%h BAR1:%h",i,pci_read_configd(i,0));
                }
        }
    }
    for (size_t i = 0; i < 0x3c; i+=4)
    {
        klog("pci","%h at %h",pci_read_configd(0,3,i),i);
    }
    
    klog("pci","OK");
}

这是真实的 pci 设备信息(由 qemu 监视器提供)

(qemu) info pci
  Bus  0,device   0,function 0:
    Host bridge: PCI device 8086:1237
      id ""
  Bus  0,device   1,function 0:
    ISA bridge: PCI device 8086:7000
      id ""
  Bus  0,function 1:
    IDE controller: PCI device 8086:7010
      BAR4: I/O at 0xc040 [0xc04f].
      id ""
  Bus  0,function 3:
    Bridge: PCI device 8086:7113
      IRQ 9.
      id ""
  Bus  0,device   2,function 0:
    VGA controller: PCI device 1234:1111
      BAR0: 32 bit prefetchable memory at 0xfd000000 [0xfdffffff].
      BAR2: 32 bit memory at 0xfebf0000 [0xfebf0fff].
      BAR6: 32 bit memory at 0xffffffffffffffff [0x0000fffe].
      id ""
  Bus  0,device   3,function 0:
    Ethernet controller: PCI device 8086:100e
      IRQ 11.
      BAR0: 32 bit memory at 0xfebc0000 [0xfebdffff].
      BAR1: I/O at 0xc000 [0xc03f].
      BAR6: 32 bit memory at 0xffffffffffffffff [0x0003fffe].
      id ""

这是PCI bus0 dev3 func0手动扫描的结果

[0x00000000]pci:scanning device...
[0x00000000]pci:found device at Bus.0x00000000Dev.0x00000000
[0x00000000]pci:found device at Bus.0x00000000Dev.0x00000001
[0x00000000]pci:found device at Bus.0x00000000Dev.0x00000002
[0x00000000]pci:found device at Bus.0x00000000Dev.0x00000003
[0x00000000]pci:0x00008086at 0x00000000
[0x00000000]pci:0x00000103at 0x00000004
[0x00000000]pci:0x00000003at 0x00000008
[0x00000000]pci:0x00000000at 0x0000000C
[0x00000000]pci:0x00000000at 0x00000010
[0x00000000]pci:0x0000C001at 0x00000014
[0x00000000]pci:0x00000000at 0x00000018
[0x00000000]pci:0x00000000at 0x0000001C
[0x00000000]pci:0x00000000at 0x00000020
[0x00000000]pci:0x00000000at 0x00000024
[0x00000000]pci:0x00000000at 0x00000028
[0x00000000]pci:0x00001AF4at 0x0000002C
[0x00000000]pci:0x00000000at 0x00000030
[0x00000000]pci:0x00000000at 0x00000034
[0x00000000]pci:0x00000000at 0x00000038
[0x00000000]pci:OK

out_port32 是 outl 指令的封装 in_port32 是一样的

发现一件事,每次读进去只能读一个词(有用吗?)

但是按照PCI标准,这样的代码实现是没有问题的

我也使用了 OSDEV Wiki 的示例代码 问题依然存在 https://wiki.osdev.org/PCI

其他代码有问题可以访问github:LithiumOS-Team Lithium-OS

感谢您的帮助

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)