diff mbox

[API-NEXT,RFC,07/31] driver api: adding pci interface

Message ID 1452285014-60320-8-git-send-email-christophe.milard@linaro.org
State New
Headers show

Commit Message

Christophe Milard Jan. 8, 2016, 8:29 p.m. UTC
Note that the functions to init/release the pci device are not part of
the interface as they are expected to be used by ODP (internaly) only.

Signed-off-by: Christophe Milard <christophe.milard@linaro.org>
---
 include/odp/api/pci.h | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/odp_driver.h  |   1 +
 2 files changed, 132 insertions(+)
 create mode 100644 include/odp/api/pci.h
diff mbox

Patch

diff --git a/include/odp/api/pci.h b/include/odp/api/pci.h
new file mode 100644
index 0000000..3fe36ce
--- /dev/null
+++ b/include/odp/api/pci.h
@@ -0,0 +1,131 @@ 
+/* Copyright (c) 2015, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+/**
+ * @file
+ *
+ * ODP interface to PCI (for drivers)
+ */
+
+#ifndef ODP_API_PCI_H_
+#define ODP_API_PCI_H_
+
+#include <odp/dma.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** @defgroup odp_pci PCI
+ *  @{
+ */
+
+/**
+ * @typedef odp_pci_dev_t
+ * An ODP PCI device.
+ */
+
+/**
+ * get the vendor_id from a pci device
+ *
+ * @param dev		the pci device as returned by odp_pci_init
+ * @returns             the pci device vendor ID
+ */
+uint16_t odp_pci_get_vendor(odp_pci_dev_t pci_dev);
+/**
+ * get the device_id from a pci device
+ *
+ * @param dev		the pci device as returned by odp_pci_init
+ * @returns             the pci device ID
+ */
+uint16_t odp_pci_get_device(odp_pci_dev_t pci_dev);
+/**
+ * get the subsystem_vendor_id from a pci device
+ *
+ * @param dev		the pci device as returned by odp_pci_init
+ * @returns             the pci device subsystem vendor ID
+ */
+uint16_t odp_pci_get_subsystem_vendor(odp_pci_dev_t pci_dev);
+/**
+ * get the subsystem_device_id from a pci device
+ *
+ * @param dev		the pci device as returned by odp_pci_init
+ * @returns             the pci device subsystem device ID
+ */
+uint16_t odp_pci_get_subsystem_device(odp_pci_dev_t pci_dev);
+/**
+ * get the address of resource (BAR)
+ *
+ * @param dev		the pci device as returned by odp_pci_init
+ * @param bar		the resource region number (0-5)
+ * @returns             the userspace virtual base address for that resource.
+ */
+void *odp_pci_get_resource_addr(odp_pci_dev_t pci_dev, int bar);
+/**
+ * get the PCI address
+ *
+ * @param dev		the pci device as returned by odp_pci_init
+ * @returns             the PCI address, <root>:<bus>:<dev>:<function>
+ *			as a string (e.g. "0000:23:00.0")
+ */
+char *odp_pci_get_addr_str(odp_pci_dev_t pci_dev);
+
+/**
+ * DMA map a (possibly fragmented) DMA region
+ *
+ * @param dev		the pci device as returned by odp_pci_init
+ * @param region	A DMA region descriptor
+ *
+ * @returns 0 on success or a negative value on error
+ */
+int odp_pci_map_dma_region(odp_pci_dev_t dev, odp_dma_map_t region);
+
+/**
+ * DMA unmap a (possibly fragmented) DMA region
+ *
+ * @param dev		the pci device as returned by odp_pci_init
+ * @param region	A DMA region descriptor
+ *
+ * @returns 0 on success or a negative value on error
+ */
+int odp_pci_unmap_dma_region(odp_pci_dev_t dev, odp_dma_map_t region);
+
+/**
+ * Read the PCI config area
+ *
+ * @param dev		the pci device as returned by odp_pci_init
+ * @param buf		where to write the read data
+ * @param len		the number of bytes to read
+ * @param offs		the offset where read should start
+ *
+ * @returns the number of read bytes
+ */
+
+int odp_pci_read_config(odp_pci_dev_t dev, void *buf, size_t len, int offs);
+
+/**
+ * Write the PCI config area
+ *
+ * @param dev		the pci device as returned by odp_pci_init
+ * @param buf		where to take the data to be written
+ * @param len		the number of bytes to written
+ * @param offs		the offset where data should be written
+ *
+ * @returns the number of written bytes
+ */
+
+int odp_pci_write_config(odp_pci_dev_t dev, const void *buf,
+			 size_t len, int offs);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ODP_API_PCI_H_ */
diff --git a/include/odp_driver.h b/include/odp_driver.h
index b59f7df..6c1eded 100644
--- a/include/odp_driver.h
+++ b/include/odp_driver.h
@@ -22,6 +22,7 @@  extern "C" {
 #include <odp/std_types.h>
 #include <odp/byteorder.h>
 #include <odp/dma.h>
+#include <odp/pci.h>
 #include <odp/align.h>
 #include <odp/sync.h>
 #include <odp/hints.h>