eal: simplify meson build of common directory
[dpdk.git] / lib / librte_eal / common / include / rte_bus.h
index aebf57e..d3034d0 100644 (file)
@@ -1,34 +1,5 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2016 NXP
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of NXP nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2016 NXP
  */
 
 #ifndef _RTE_BUS_H_
@@ -56,6 +27,21 @@ extern "C" {
 /** Double linked list of buses */
 TAILQ_HEAD(rte_bus_list, rte_bus);
 
+
+/**
+ * IOVA mapping mode.
+ *
+ * IOVA mapping mode is iommu programming mode of a device.
+ * That device (for example: IOMMU backed DMA device) based
+ * on rte_iova_mode will generate physical or virtual address.
+ *
+ */
+enum rte_iova_mode {
+       RTE_IOVA_DC = 0,        /* Don't care mode */
+       RTE_IOVA_PA = (1 << 0), /* DMA using physical address */
+       RTE_IOVA_VA = (1 << 1)  /* DMA using virtual address */
+};
+
 /**
  * Bus specific scan for devices attached on the bus.
  * For each bus object, the scan would be responsible for finding devices and
@@ -114,15 +100,11 @@ typedef struct rte_device *
  * @param dev
  *     Device pointer that was returned by a previous call to find_device.
  *
- * @param devargs
- *     Device declaration.
- *
  * @return
  *     0 on success.
  *     !0 on error.
  */
-typedef int (*rte_bus_plug_t)(struct rte_device *dev,
-                             const char *devargs);
+typedef int (*rte_bus_plug_t)(struct rte_device *dev);
 
 /**
  * Implementation specific remove function which is responsible for unlinking
@@ -157,6 +139,107 @@ typedef int (*rte_bus_unplug_t)(struct rte_device *dev);
  */
 typedef int (*rte_bus_parse_t)(const char *name, void *addr);
 
+/**
+ * Device level DMA map function.
+ * After a successful call, the memory segment will be mapped to the
+ * given device.
+ *
+ * @param dev
+ *     Device pointer.
+ * @param addr
+ *     Virtual address to map.
+ * @param iova
+ *     IOVA address to map.
+ * @param len
+ *     Length of the memory segment being mapped.
+ *
+ * @return
+ *     0 if mapping was successful.
+ *     Negative value and rte_errno is set otherwise.
+ */
+typedef int (*rte_dev_dma_map_t)(struct rte_device *dev, void *addr,
+                                 uint64_t iova, size_t len);
+
+/**
+ * Device level DMA unmap function.
+ * After a successful call, the memory segment will no longer be
+ * accessible by the given device.
+ *
+ * @param dev
+ *     Device pointer.
+ * @param addr
+ *     Virtual address to unmap.
+ * @param iova
+ *     IOVA address to unmap.
+ * @param len
+ *     Length of the memory segment being mapped.
+ *
+ * @return
+ *     0 if un-mapping was successful.
+ *     Negative value and rte_errno is set otherwise.
+ */
+typedef int (*rte_dev_dma_unmap_t)(struct rte_device *dev, void *addr,
+                                  uint64_t iova, size_t len);
+
+/**
+ * Implement a specific hot-unplug handler, which is responsible for
+ * handle the failure when device be hot-unplugged. When the event of
+ * hot-unplug be detected, it could call this function to handle
+ * the hot-unplug failure and avoid app crash.
+ * @param dev
+ *     Pointer of the device structure.
+ *
+ * @return
+ *     0 on success.
+ *     !0 on error.
+ */
+typedef int (*rte_bus_hot_unplug_handler_t)(struct rte_device *dev);
+
+/**
+ * Implement a specific sigbus handler, which is responsible for handling
+ * the sigbus error which is either original memory error, or specific memory
+ * error that caused of device be hot-unplugged. When sigbus error be captured,
+ * it could call this function to handle sigbus error.
+ * @param failure_addr
+ *     Pointer of the fault address of the sigbus error.
+ *
+ * @return
+ *     0 for success handle the sigbus for hot-unplug.
+ *     1 for not process it, because it is a generic sigbus error.
+ *     -1 for failed to handle the sigbus for hot-unplug.
+ */
+typedef int (*rte_bus_sigbus_handler_t)(const void *failure_addr);
+
+/**
+ * Bus scan policies
+ */
+enum rte_bus_scan_mode {
+       RTE_BUS_SCAN_UNDEFINED,
+       RTE_BUS_SCAN_WHITELIST,
+       RTE_BUS_SCAN_BLACKLIST,
+};
+
+/**
+ * A structure used to configure bus operations.
+ */
+struct rte_bus_conf {
+       enum rte_bus_scan_mode scan_mode; /**< Scan policy. */
+};
+
+
+/**
+ * Get common iommu class of the all the devices on the bus. The bus may
+ * check that those devices are attached to iommu driver.
+ * If no devices are attached to the bus. The bus may return with don't care
+ * (_DC) value.
+ * Otherwise, The bus will return appropriate _pa or _va iova mode.
+ *
+ * @return
+ *      enum rte_iova_mode value.
+ */
+typedef enum rte_iova_mode (*rte_bus_get_iommu_class_t)(void);
+
+
 /**
  * A structure describing a generic bus.
  */
@@ -169,6 +252,16 @@ struct rte_bus {
        rte_bus_plug_t plug;         /**< Probe single device for drivers */
        rte_bus_unplug_t unplug;     /**< Remove single device from driver */
        rte_bus_parse_t parse;       /**< Parse a device name */
+       rte_dev_dma_map_t dma_map;   /**< DMA map for device in the bus */
+       rte_dev_dma_unmap_t dma_unmap; /**< DMA unmap for device in the bus */
+       struct rte_bus_conf conf;    /**< Bus configuration */
+       rte_bus_get_iommu_class_t get_iommu_class; /**< Get iommu class */
+       rte_dev_iterate_t dev_iterate; /**< Device iterator. */
+       rte_bus_hot_unplug_handler_t hot_unplug_handler;
+                               /**< handle hot-unplug failure on the bus */
+       rte_bus_sigbus_handler_t sigbus_handler;
+                                       /**< handle sigbus error on the bus */
+
 };
 
 /**
@@ -213,10 +306,6 @@ int rte_bus_probe(void);
  *
  * @param f
  *      A valid and open output stream handle
- *
- * @return
- *      0 in case of success
- *     !0 in case there is error in opening the output stream
  */
 void rte_bus_dump(FILE *f);
 
@@ -272,13 +361,22 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
  */
 struct rte_bus *rte_bus_find_by_name(const char *busname);
 
+
+/**
+ * Get the common iommu class of devices bound on to buses available in the
+ * system. RTE_IOVA_DC means that no preference has been expressed.
+ *
+ * @return
+ *     enum rte_iova_mode value.
+ */
+enum rte_iova_mode rte_bus_get_iommu_class(void);
+
 /**
  * Helper for Bus registration.
  * The constructor has higher priority than PMD constructors.
  */
 #define RTE_REGISTER_BUS(nm, bus) \
-RTE_INIT_PRIO(businitfn_ ##nm, 101); \
-static void businitfn_ ##nm(void) \
+RTE_INIT_PRIO(businitfn_ ##nm, BUS) \
 {\
        (bus).name = RTE_STR(nm);\
        rte_bus_register(&bus); \