You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/09/06 02:01:24 UTC

(nuttx) 07/13: pci: add pci bus find capability interface

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit c25f839b064a039c3ab3d7d43c6b79a7b067cbcd
Author: lipengfei28 <li...@xiaomi.com>
AuthorDate: Mon Jun 3 20:09:24 2024 +0800

    pci: add pci bus find capability interface
    
    Signed-off-by: lipengfei28 <li...@xiaomi.com>
---
 drivers/pci/pci.c       | 36 ++++++++++++++++++++++++++++++++++++
 include/nuttx/pci/pci.h | 23 +++++++++++++++++++++++
 2 files changed, 59 insertions(+)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index e5cc22fd5c..96254fb73c 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1311,6 +1311,42 @@ int pci_register_controller(FAR struct pci_controller_s *ctrl)
   return 0;
 }
 
+/****************************************************************************
+ * Name: pci_bus_find_capability
+ *
+ * Description:
+ *   Query for devices' capabilities
+ *
+ *   Tell if a device supports a given PCI capability.
+ *
+ * Input Parameters:
+ *   bus    - PCI device bus belong to
+ *   devfn  - PCI device number and function number
+ *   cap    - Capability code
+ *
+ * Returned Value:
+ *   Returns the address of the requested capability structure within the
+ *   device's PCI configuration space or 0 in case the device does not
+ *   support it.
+ *
+ ****************************************************************************/
+
+uint8_t pci_bus_find_capability(FAR struct pci_bus_s *bus,
+                                unsigned int devfn, int cap)
+{
+  uint8_t type = 0;
+  uint8_t pos;
+
+  pci_bus_read_config_byte(bus, devfn, PCI_HEADER_TYPE, &type);
+  pos = pci_bus_find_start_cap(bus, devfn, type);
+  if (pos)
+    {
+      pos = pci_find_next_cap(bus, devfn, pos, cap);
+    }
+
+  return pos;
+}
+
 PCI_BUS_READ_CONFIG(byte, uint8_t, 1)
 PCI_BUS_READ_CONFIG(word, uint16_t, 2)
 PCI_BUS_READ_CONFIG(dword, uint32_t, 4)
diff --git a/include/nuttx/pci/pci.h b/include/nuttx/pci/pci.h
index 61466de3f4..1058e51cfc 100644
--- a/include/nuttx/pci/pci.h
+++ b/include/nuttx/pci/pci.h
@@ -599,6 +599,29 @@ int pci_unregister_device(FAR struct pci_device_s *dev);
 
 int pci_register_controller(FAR struct pci_controller_s *ctrl);
 
+/****************************************************************************
+ * Name: pci_bus_find_capability
+ *
+ * Description:
+ *   Query for devices' capabilities
+ *
+ *   Tell if a device supports a given PCI capability.
+ *
+ * Input Parameters:
+ *   bus    - PCI device bus belong to
+ *   devfn  - PCI device number and function number
+ *   cap    - Capability code
+ *
+ * Returned Value:
+ *   Returns the address of the requested capability structure within the
+ *   device's PCI configuration space or 0 in case the device does not
+ *   support it.
+ *
+ ****************************************************************************/
+
+uint8_t pci_bus_find_capability(FAR struct pci_bus_s *bus,
+                                unsigned int devfn, int cap);
+
 /****************************************************************************
  * Name: pci_bus_read_config_byte
  *