vfio 中的 ioctl (VFIO_DEVICE_GET_REGION_INFO) 返回的 "num_regions" 是什么

what is "num_regions" returned by the ioctl (VFIO_DEVICE_GET_REGION_INFO) in vfio

我想了解 vfio 如何在 pci 上工作。 我已经阅读了 https://www.kernel.org/doc/Documentation/vfio.txt,并且我正在基于它编写一个测试。 在某些时候,我的代码看起来像这样:

/* Get pci device information (number of regions and interrupts...) */
ret = ioctl(vfio_dev_fd, VFIO_DEVICE_GET_INFO, &device_info);
if (ret) {
        printf("  %s cannot get device info, "
                        "error %i (%s)\n", pci_addr, errno, strerror(errno));
        close(vfio_dev_fd);
        return -1;
}
printf ("found %d regions in the device\n", device_info.num_regions);

我不明白的是最后的printf显示9(九)个区域! 查看我的 PCI 设备的配置 space 我可以看到:

cat /sys/bus/pci/devices/0000\:06\:00.0/config | hd
00000000  e4 14 81 16 00 04 10 00  10 00 00 02 10 00 00 00  |................|
00000010  04 00 de f3 00 00 00 00  04 00 df f3 00 00 00 00  |................|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 28 10 6e 02  |............(.n.|
00000030  00 00 00 00 48 00 00 00  00 00 00 00 0a 01 00 00  |....H...........|
00000040

我是 PCI 的新手,但我对此的解释是这块板上只有两个 BARS(0 和 2)。我虽然 PCI 上的最大区域数(BAR?)是 6。

尽管如此,有一点迹象表明我误解了一些东西:上面提到的内核文档指出:

For PCI devices, config space is a region

所以这可能导致我正在查看的板有 3 个区域...它仍然显示 9... pci_vfio 的 PCI 区域是什么?它们是如何编号和访问的?...

谢谢。

来自vfio.h:

/*
 * The VFIO-PCI bus driver makes use of the following fixed region and
 * IRQ index mapping.  Unimplemented regions return a size of zero.
 * Unimplemented IRQ types return a count of zero.
 */

enum {
    VFIO_PCI_BAR0_REGION_INDEX,
    VFIO_PCI_BAR1_REGION_INDEX,
    VFIO_PCI_BAR2_REGION_INDEX,
    VFIO_PCI_BAR3_REGION_INDEX,
    VFIO_PCI_BAR4_REGION_INDEX,
    VFIO_PCI_BAR5_REGION_INDEX,
    VFIO_PCI_ROM_REGION_INDEX,
    VFIO_PCI_CONFIG_REGION_INDEX,
    /*
     * Expose VGA regions defined for PCI base class 03, subclass 00.
     * This includes I/O port ranges 0x3b0 to 0x3bb and 0x3c0 to 0x3df
     * as well as the MMIO range 0xa0000 to 0xbffff.  Each implemented
     * range is found at it's identity mapped offset from the region
     * offset, for example 0x3b0 is region_info.offset + 0x3b0.  Areas
     * between described ranges are unimplemented.
     */
    VFIO_PCI_VGA_REGION_INDEX,
    VFIO_PCI_NUM_REGIONS
};

因此,这些额外的区域是提供配置 space、选项 ROM 和 VGA 特定 I/O(端口和旧版帧缓冲区 0xa0000...0xbffff window 的一种方式).