c - 以编程方式获取 Linux 中的 USB 主机控制器参数
问题描述
我需要获取一些与 Linux 中的 USB 主机控制器相关的参数。我在互联网上进行了很多搜索,发现的唯一方法是使用 pciutils lib。每个 PCI 设备都在 pci.h 中的 pci_dev 结构中:
struct pci_dev {
struct pci_dev *next; /* Next device in the chain */
u16 domain_16; /* 16-bit version of the PCI domain for backward compatibility */
/* 0xffff if the real domain doesn't fit in 16 bits */
u8 bus, dev, func; /* Bus inside domain, device and function */
/* These fields are set by pci_fill_info() */
int known_fields; /* Set of info fields already known */
u16 vendor_id, device_id; /* Identity of the device */
u16 device_class; /* PCI device class */
int irq; /* IRQ number */
pciaddr_t base_addr[6]; /* Base addresses including flags in lower bits */
pciaddr_t size[6]; /* Region sizes */
pciaddr_t rom_base_addr; /* Expansion ROM base address */
pciaddr_t rom_size; /* Expansion ROM size */
struct pci_cap *first_cap; /* List of capabilities */
char *phy_slot; /* Physical slot */
char *module_alias; /* Linux kernel module alias */
char *label; /* Device name as exported by BIOS */
int numa_node; /* NUMA node */
pciaddr_t flags[6]; /* PCI_IORESOURCE_* flags for regions */
pciaddr_t rom_flags; /* PCI_IORESOURCE_* flags for expansion ROM */
int domain; /* PCI domain (host bridge) */
/* Fields used internally */
struct pci_access *access;
struct pci_methods *methods;
u8 *cache; /* Cached config registers */
int cache_len;
int hdrtype; /* Cached low 7 bits of header type, -1 if unknown */
void *aux; /* Auxiliary data */
struct pci_property *properties; /* A linked list of extra properties */
struct pci_cap *last_cap; /* Last capability in the list */
};
我还发现我可以解析 pci 设备如下:
struct pci_access *pacc1;
struct pci_dev *dev1;
unsigned int c1;
char namebuf1[1024], *name1;
pacc1 = pci_alloc(); /* Get the pci_access structure */
/* Set all options you want -- here we stick with the defaults */
pci_init(pacc1); /* Initialize the PCI library */
pci_scan_bus(pacc1); /* We want to get the list of devices */
for (dev1=pacc1->devices; dev1; dev1=dev1->next) /* Iterate over all devices */
{
pci_fill_info(dev1, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_CLASS); /* Fill in header info we need */
c1 = pci_read_byte(dev1, PCI_INTERRUPT_PIN); /* Read config register directly */
printf("%04x:%02x:%02x.%d vendor=%04x device=%04x class=%04x irq=%d (pin %d) base0=%lx",
dev1->domain, dev1->bus, dev1->dev, dev1->func, dev1->vendor_id, dev1->device_id,
dev1->device_class, dev1->irq, c1, (long) dev1->base_addr[0]);
/* Look up and print the full name of the device */
name1 = pci_lookup_name(pacc, namebuf1, sizeof(namebuf1), PCI_LOOKUP_DEVICE, dev1->vendor_id, dev1->device_id);
printf(" ***************** %d: (%s)\n", dev1->dev, name1);
}
pci_cleanup(pacc1); /* Close everything */
如果相应的 pci 设备对应于 USB 主机控制器,有没有办法检查循环?或者有没有更简单的方法来获取 USB 主机控制器信息?
解决方案
推荐阅读
- python - 如何将密码查询值存储到 python 函数内的变量中?
- upload - 为什么我的 esp-01 在编程模式下(GPIO0 接地)时将我的另一个 esp-01 与我的 esp32 接入点断开连接?
- python - 如何制作一个提供请求的csv文件的python网络服务器
- python - 我试图让一个对象在我的游戏中随机生成一段时间,当我的角色走过该对象时它会消失
- asp.net - 嵌套用户控件中的访问方法
- sql - 如何按三分之二或四分之二对数据进行分类 - Oracle SQL
- itext - 带有签名文件的 iTextsharp
- java - 从测试套件重复运行仅在 Eclipse JUnit 视图中显示最终运行
- azure - 在 Azure DevOps Pipelines 中跨阶段共享变量
- c# - 如何在 C# WPF 中有一个多列下拉框?