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:23 UTC
(nuttx) 06/13: pci: add pci read/write config/io space 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 45f159756218c24f10e59c690daf3f676c99f20b
Author: lipengfei28 <li...@xiaomi.com>
AuthorDate: Fri May 31 16:56:23 2024 +0800
pci: add pci read/write config/io space interface
Signed-off-by: lipengfei28 <li...@xiaomi.com>
---
drivers/pci/pci.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++--
include/nuttx/pci/pci.h | 84 ++++++++++++++++++++++++++++++++
2 files changed, 205 insertions(+), 5 deletions(-)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index f1ae5df529..e5cc22fd5c 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -53,7 +53,7 @@
\
if (!PCI_##len##_BAD) \
{ \
- ret = bus->ctrl->ops->read(bus, devfn, where, size, &data); \
+ ret = pci_bus_read_config(bus, devfn, where, size, &data); \
} \
\
*value = (type)data; \
@@ -68,7 +68,7 @@
\
if (!PCI_##len##_BAD) \
{ \
- ret = bus->ctrl->ops->write(bus, devfn, where, size, value); \
+ ret = pci_bus_write_config(bus, devfn, where, size, value); \
} \
\
return ret; \
@@ -83,7 +83,7 @@
\
if (!PCI_##len##_BAD) \
{ \
- ret = bus->ctrl->ops->read_io(bus, where, size, &data); \
+ ret = pci_bus_read_io(bus, where, size, &data); \
} \
\
*value = (type)data; \
@@ -98,7 +98,7 @@
\
if (!PCI_##len##_BAD) \
{ \
- ret = bus->ctrl->ops->write_io(bus, where, size, value); \
+ ret = pci_bus_write_io(bus, where, size, value); \
} \
\
return ret; \
@@ -782,6 +782,122 @@ static void pci_scan_bus(FAR struct pci_bus_s *bus)
* Public Functions
****************************************************************************/
+/****************************************************************************
+ * Name: pci_bus_read_config
+ *
+ * Description:
+ * Read pci device config space
+ *
+ * Input Parameters:
+ * bus - The PCI device belong to
+ * devfn - The PCI device dev number and function number
+ * where - The register address
+ * size - The data length
+ * val - The data buffer
+ *
+ * Returned Value:
+ * Zero if success, otherwise nagative
+ *
+ ****************************************************************************/
+
+int pci_bus_read_config(FAR struct pci_bus_s *bus,
+ unsigned int devfn, int where,
+ int size, FAR uint32_t *val)
+{
+ if (size != 1 && size != 2 && size != 4)
+ {
+ return -EINVAL;
+ }
+
+ return bus->ctrl->ops->read(bus, devfn, where, size, val);
+}
+
+/****************************************************************************
+ * Name: pci_bus_write_config
+ *
+ * Description:
+ * Read pci device config space
+ *
+ * Input Parameters:
+ * bus - The PCI device belong to
+ * devfn - The PCI device dev number and function number
+ * where - The register address
+ * size - The data length
+ * val - The data
+ *
+ * Returned Value:
+ * Zero if success, otherwise nagative
+ *
+ ****************************************************************************/
+
+int pci_bus_write_config(FAR struct pci_bus_s *bus,
+ unsigned int devfn, int where,
+ int size, uint32_t val)
+{
+ if (size != 1 && size != 2 && size != 4)
+ {
+ return -EINVAL;
+ }
+
+ return bus->ctrl->ops->write(bus, devfn, where, size, val);
+}
+
+/****************************************************************************
+ * Name: pci_bus_read_io
+ *
+ * Description:
+ * Read pci device io space
+ *
+ * Input Parameters:
+ * bus - The PCI device belong to
+ * addr - The address to read
+ * size - The data length
+ * val - The data buffer
+ *
+ * Returned Value:
+ * Zero if success, otherwise nagative
+ *
+ ****************************************************************************/
+
+int pci_bus_read_io(FAR struct pci_bus_s *bus, uintptr_t addr,
+ int size, FAR uint32_t *val)
+{
+ if (size != 1 && size != 2 && size != 4)
+ {
+ return -EINVAL;
+ }
+
+ return bus->ctrl->ops->read_io(bus, addr, size, val);
+}
+
+/****************************************************************************
+ * Name: pci_bus_write_io
+ *
+ * Description:
+ * Read pci device io space
+ *
+ * Input Parameters:
+ * bus - The PCI device belong to
+ * addr - The address to write
+ * size - The data length
+ * val - The data
+ *
+ * Returned Value:
+ * Zero if success, otherwise nagative
+ *
+ ****************************************************************************/
+
+int pci_bus_write_io(FAR struct pci_bus_s *bus, uintptr_t addr,
+ int size, uint32_t val)
+{
+ if (size != 1 && size != 2 && size != 4)
+ {
+ return -EINVAL;
+ }
+
+ return bus->ctrl->ops->write_io(bus, addr, size, val);
+}
+
/****************************************************************************
* Name: pci_set_master
*
@@ -1206,4 +1322,4 @@ PCI_BUS_READ_IO(word, uint16_t, 2)
PCI_BUS_READ_IO(dword, uint32_t, 4)
PCI_BUS_WRITE_IO(byte, uint8_t, 1)
PCI_BUS_WRITE_IO(word, uint16_t, 2)
-PCI_BUS_WRITE_IO(dword, uint32_t, 4)
\ No newline at end of file
+PCI_BUS_WRITE_IO(dword, uint32_t, 4)
diff --git a/include/nuttx/pci/pci.h b/include/nuttx/pci/pci.h
index 2f1db1eebd..61466de3f4 100644
--- a/include/nuttx/pci/pci.h
+++ b/include/nuttx/pci/pci.h
@@ -302,6 +302,90 @@ struct pci_driver_s
* Public Function Prototypes
****************************************************************************/
+/****************************************************************************
+ * Name: pci_bus_read_config
+ *
+ * Description:
+ * read pci device config space
+ *
+ * Input Parameters:
+ * bus - The PCI device to belong to
+ * devfn - The PCI device number and function number
+ * where - The register address
+ * size - The length data
+ * val - The data buf
+ *
+ * Returned Value:
+ * Zero if success, otherwise nagative
+ *
+ ****************************************************************************/
+
+int pci_bus_read_config(FAR struct pci_bus_s *bus,
+ unsigned int devfn, int where,
+ int size, FAR uint32_t *val);
+
+/****************************************************************************
+ * Name: pci_bus_write_config
+ *
+ * Description:
+ * read pci device config space
+ *
+ * Input Parameters:
+ * bus - The PCI device to belong to
+ * devfn - The PCI device number and function number
+ * where - The register address
+ * size - The length data
+ * val - The data
+ *
+ * Returned Value:
+ * Zero if success, otherwise nagative
+ *
+ ****************************************************************************/
+
+int pci_bus_write_config(FAR struct pci_bus_s *bus,
+ unsigned int devfn, int where,
+ int size, uint32_t val);
+
+/****************************************************************************
+ * Name: pci_bus_read_io
+ *
+ * Description:
+ * Read pci device io space
+ *
+ * Input Parameters:
+ * bus - The PCI device belong to
+ * addr - The address to read
+ * size - The data length
+ * val - The data buffer
+ *
+ * Returned Value:
+ * Zero if success, otherwise nagative
+ *
+ ****************************************************************************/
+
+int pci_bus_read_io(FAR struct pci_bus_s *bus, uintptr_t addr,
+ int size, FAR uint32_t *val);
+
+/****************************************************************************
+ * Name: pci_bus_write_io
+ *
+ * Description:
+ * Read pci device io space
+ *
+ * Input Parameters:
+ * bus - The PCI device belong to
+ * addr - The address to write
+ * size - The data length
+ * val - The data
+ *
+ * Returned Value:
+ * Zero if success, otherwise nagative
+ *
+ ****************************************************************************/
+
+int pci_bus_write_io(FAR struct pci_bus_s *bus, uintptr_t addr,
+ int size, uint32_t val);
+
/****************************************************************************
* Name: pci_set_master
*