From 1788597ddd21ecd24bc442cfd4c213c4a4fa8a9e Mon Sep 17 00:00:00 2001 From: zhujiale <945386260@qq.com> Date: Sat, 14 Sep 2024 16:09:42 +0800 Subject: [PATCH] pci --- components/drivers/include/drivers/pci.h | 3 +-- components/drivers/pci/pci.c | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/components/drivers/include/drivers/pci.h b/components/drivers/include/drivers/pci.h index 9590e4bade7f..1ae439351cb6 100644 --- a/components/drivers/include/drivers/pci.h +++ b/components/drivers/include/drivers/pci.h @@ -596,8 +596,7 @@ const struct rt_pci_device_id *rt_pci_match_ids(struct rt_pci_device *pdev, rt_err_t rt_pci_driver_register(struct rt_pci_driver *pdrv); rt_err_t rt_pci_device_register(struct rt_pci_device *pdev); -struct rt_pci_bus_resource *rt_pci_find_bar(struct rt_pci_device* pdev,rt_ubase_t flags); - +struct rt_pci_bus_resource *rt_pci_find_bar(struct rt_pci_device* pdev,rt_ubase_t flags,int index); #define RT_PCI_DRIVER_EXPORT(driver) RT_DRIVER_EXPORT(driver, pci, BUILIN) extern struct rt_spinlock rt_pci_lock; diff --git a/components/drivers/pci/pci.c b/components/drivers/pci/pci.c index 7063d2824fa6..369856e0e99c 100644 --- a/components/drivers/pci/pci.c +++ b/components/drivers/pci/pci.c @@ -712,12 +712,16 @@ rt_err_t rt_pci_device_alloc_resource(struct rt_pci_host_bridge *host_bridge, return err; } -struct rt_pci_bus_resource *rt_pci_find_bar(struct rt_pci_device* pdev,rt_ubase_t flags) +struct rt_pci_bus_resource *rt_pci_find_bar(struct rt_pci_device* pdev,rt_ubase_t flags,int index) { for (int i = 0; i < RT_PCI_BAR_NR_MAX; i++) { if (pdev->resource[i].flags == flags) - return &pdev->resource[i]; + { + index--; + if (index == 0) + return &pdev->resource[i]; + } } return RT_NULL; }