This is an automated email from the ASF dual-hosted git repository. btashton pushed a commit to branch pci in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 1fe5521db31988e8ae18c40229f53610bd1811c9 Author: Yang Chung-Fan <sonic.tw...@gmail.com> AuthorDate: Wed May 6 20:28:41 2020 +0900 pcie: make pcie enumerate routine as common instead of architecture dependent --- boards/x86_64/intel64/qemu-intel64/src/qemu_pcie.c | 82 ------------------- drivers/pcie/Kconfig | 11 ++- drivers/pcie/pcie_root.c | 92 +++++++++++++++++++++- 3 files changed, 101 insertions(+), 84 deletions(-) diff --git a/boards/x86_64/intel64/qemu-intel64/src/qemu_pcie.c b/boards/x86_64/intel64/qemu-intel64/src/qemu_pcie.c index 5670fdd..f23bec9 100644 --- a/boards/x86_64/intel64/qemu-intel64/src/qemu_pcie.c +++ b/boards/x86_64/intel64/qemu-intel64/src/qemu_pcie.c @@ -74,15 +74,10 @@ * Pre-processor Definitions ****************************************************************************/ -#define QEMU_PCIE_MAX_BDF 0x10000 - /**************************************************************************** * Private Functions Definitions ****************************************************************************/ -static int qemu_pci_enumerate(FAR struct pcie_bus_s *bus, - FAR struct pcie_dev_type_s **types); - static int qemu_pci_cfg_write(FAR struct pcie_dev_s *dev, uintptr_t addr, FAR const void *buffer, unsigned int size); @@ -107,7 +102,6 @@ static int qemu_pci_msi_register(FAR struct pcie_dev_s *dev, struct pcie_bus_ops_s qemu_pcie_bus_ops = { - .pcie_enumerate = qemu_pci_enumerate, .pci_cfg_write = qemu_pci_cfg_write, .pci_cfg_read = qemu_pci_cfg_read, .pci_map_bar = qemu_pci_map_bar, @@ -126,82 +120,6 @@ struct pcie_bus_s qemu_pcie_bus = ****************************************************************************/ /**************************************************************************** - * Name: qemu_pci_enumerate - * - * Description: - * Scan the PCI bus and enumerate the devices. - * Initialize any recognized devices, given in types. - * - * Input Parameters: - * bus - PCI-E bus structure - * type - List of pointers to devices types recognized, NULL terminated - * - * Returned Value: - * 0: success, <0: A negated errno - * - ****************************************************************************/ - -static int qemu_pci_enumerate(FAR struct pcie_bus_s *bus, - FAR struct pcie_dev_type_s **types) -{ - unsigned int bdf; - uint16_t vid; - uint16_t id; - uint16_t rev; - - if (!bus) - return -EINVAL; - if (!types) - return -EINVAL; - - for (bdf = 0; bdf < QEMU_PCIE_MAX_BDF; bdf++) - { - __qemu_pci_cfg_read(bdf, PCI_CFG_VENDOR_ID, &vid, 2); - __qemu_pci_cfg_read(bdf, PCI_CFG_DEVICE_ID, &id, 2); - __qemu_pci_cfg_read(bdf, PCI_CFG_REVERSION, &rev, 2); - - if (vid == PCI_ID_ANY) - continue; - - pciinfo("[%02x:%02x.%x] Found %04x:%04x, class/reversion %08x\n", - bdf >> 8, (bdf >> 3) & 0x1f, bdf & 0x3, - vid, id, rev); - - for (int i = 0; types[i] != NULL; i++) - { - if (types[i]->vendor == PCI_ID_ANY || - types[i]->vendor == vid) - { - if (types[i]->device == PCI_ID_ANY || - types[i]->device == id) - { - if (types[i]->class_rev == PCI_ID_ANY || - types[i]->class_rev == rev) - { - if (types[i]->probe) - { - pciinfo("[%02x:%02x.%x] %s\n", - bdf >> 8, (bdf >> 3) & 0x1f, bdf & 0x3, - types[i]->name); - types[i]->probe(bus, types[i], bdf); - } - else - { - pcierr("[%02x:%02x.%x] Error: Invalid \ - device probe function\n", - bdf >> 8, (bdf >> 3) & 0x1f, bdf & 0x3); - } - break; - } - } - } - } - } - - return OK; -} - -/**************************************************************************** * Name: qemu_pci_cfg_write * * Description: diff --git a/drivers/pcie/Kconfig b/drivers/pcie/Kconfig index d4138ff..7ac9db5 100644 --- a/drivers/pcie/Kconfig +++ b/drivers/pcie/Kconfig @@ -3,9 +3,18 @@ # see the file kconfig-language.txt in the NuttX tools repository. # -config PCIE +menuconfig PCIE bool "Support for PCI-E Bus" default n ---help--- Enables support for the PCI-E bus. Backend bust be provided by per-arch or per-board implementation.. + +if PCIE +config PCIE_MAX_BDF + hex "Maximum bdf to scan on PCI-E bus" + default 0x10000 + ---help--- + The maximum bdf number to be scaned on PCI-E bus + +endif diff --git a/drivers/pcie/pcie_root.c b/drivers/pcie/pcie_root.c index 362e677..2b420e1 100644 --- a/drivers/pcie/pcie_root.c +++ b/drivers/pcie/pcie_root.c @@ -52,6 +52,96 @@ struct pcie_dev_type_s *pci_device_types[] = ****************************************************************************/ /**************************************************************************** + * Name: pci_enumerate + * + * Description: + * Scan the PCI bus and enumerate the devices. + * Initialize any recognized devices, given in types. + * + * Input Parameters: + * bus - PCI-E bus structure + * type - List of pointers to devices types recognized, NULL terminated + * + * Returned Value: + * 0: success, <0: A negated errno + * + ****************************************************************************/ + +int pci_enumerate(FAR struct pcie_bus_s *bus, + FAR struct pcie_dev_type_s **types) +{ + unsigned int bdf; + uint16_t vid; + uint16_t id; + uint16_t rev; + struct pcie_dev_s tmp_dev; + struct pcie_dev_type_s tmp_type = + { + .name = "Unknown", + .vendor = PCI_ID_ANY, + .device = PCI_ID_ANY, + .class_rev = PCI_ID_ANY, + .probe = NULL, + }; + + if (!bus) + return -EINVAL; + if (!types) + return -EINVAL; + + for (bdf = 0; bdf < CONFIG_PCIE_MAX_BDF; bdf++) + { + tmp_dev.bus = bus; + tmp_dev.type = &tmp_type; + tmp_dev.bdf = bdf; + + bus->ops->pci_cfg_read(&tmp_dev, PCI_CFG_VENDOR_ID, &vid, 2); + bus->ops->pci_cfg_read(&tmp_dev, PCI_CFG_DEVICE_ID, &id, 2); + bus->ops->pci_cfg_read(&tmp_dev, PCI_CFG_REVERSION, &rev, 2); + + if (vid == PCI_ID_ANY) + continue; + + pciinfo("[%02x:%02x.%x] Found %04x:%04x, class/reversion %08x\n", + bdf >> 8, (bdf >> 3) & 0x1f, bdf & 0x3, + vid, id, rev); + + for (int i = 0; types[i] != NULL; i++) + { + if (types[i]->vendor == PCI_ID_ANY || + types[i]->vendor == vid) + { + if (types[i]->device == PCI_ID_ANY || + types[i]->device == id) + { + if (types[i]->class_rev == PCI_ID_ANY || + types[i]->class_rev == rev) + { + if (types[i]->probe) + { + pciinfo("[%02x:%02x.%x] %s\n", + bdf >> 8, (bdf >> 3) & 0x1f, bdf & 0x3, + types[i]->name); + types[i]->probe(bus, types[i], bdf); + } + else + { + pcierr("[%02x:%02x.%x] Error: Invalid \ + device probe function\n", + bdf >> 8, (bdf >> 3) & 0x1f, bdf & 0x3); + } + break; + } + } + } + } + } + + return OK; +} + + +/**************************************************************************** * Name: pcie_initialize * * Description: @@ -71,7 +161,7 @@ struct pcie_dev_type_s *pci_device_types[] = int pcie_initialize(FAR struct pcie_bus_s *bus) { - return bus->ops->pcie_enumerate(bus, pci_device_types); + return pci_enumerate(bus, pci_device_types); } /****************************************************************************