#include <stdint.h>
#include <stdbool.h>
+#include <rte_bitops.h>
#include <rte_compat.h>
/**
struct rte_gpu_info {
/** Unique identifier name. */
const char *name;
+ /** Opaque handler of the device context. */
+ uint64_t context;
/** Device ID. */
int16_t dev_id;
+ /** ID of the parent device, RTE_GPU_ID_NONE if no parent */
+ int16_t parent;
/** Total processors available on device. */
uint32_t processor_count;
/** Total memory available on device. */
__rte_experimental
bool rte_gpu_is_valid(int16_t dev_id);
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Create a virtual device representing a context in the parent device.
+ *
+ * @param name
+ * Unique string to identify the device.
+ * @param parent
+ * Device ID of the parent.
+ * @param child_context
+ * Opaque context handler.
+ *
+ * @return
+ * Device ID of the new created child, -rte_errno otherwise:
+ * - EINVAL if empty name
+ * - ENAMETOOLONG if long name
+ * - EEXIST if existing device name
+ * - ENODEV if invalid parent
+ * - EPERM if secondary process
+ * - ENOENT if too many devices
+ * - ENOMEM if out of space
+ */
+__rte_experimental
+int16_t rte_gpu_add_child(const char *name,
+ int16_t parent, uint64_t child_context);
+
/**
* @warning
* @b EXPERIMENTAL: this API may change without prior notice.
*
* @param dev_id
* The initial device ID to start the research.
+ * @param parent
+ * The device ID of the parent.
+ * RTE_GPU_ID_NONE means no parent.
+ * RTE_GPU_ID_ANY means no or any parent.
*
* @return
* Next device ID corresponding to a valid and initialized computing device,
* RTE_GPU_ID_NONE if there is none.
*/
__rte_experimental
-int16_t rte_gpu_find_next(int16_t dev_id);
+int16_t rte_gpu_find_next(int16_t dev_id, int16_t parent);
/**
* @warning
* The ID of the next possible valid device, usually 0 to iterate all.
*/
#define RTE_GPU_FOREACH(dev_id) \
- for (dev_id = rte_gpu_find_next(0); \
- dev_id > 0; \
- dev_id = rte_gpu_find_next(dev_id + 1))
+ RTE_GPU_FOREACH_CHILD(dev_id, RTE_GPU_ID_ANY)
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Macro to iterate over all valid computing devices having no parent.
+ *
+ * @param dev_id
+ * The ID of the next possible valid device, usually 0 to iterate all.
+ */
+#define RTE_GPU_FOREACH_PARENT(dev_id) \
+ RTE_GPU_FOREACH_CHILD(dev_id, RTE_GPU_ID_NONE)
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Macro to iterate over all valid children of a computing device parent.
+ *
+ * @param dev_id
+ * The ID of the next possible valid device, usually 0 to iterate all.
+ * @param parent
+ * The device ID of the parent.
+ */
+#define RTE_GPU_FOREACH_CHILD(dev_id, parent) \
+ for (dev_id = rte_gpu_find_next(0, parent); \
+ dev_id >= 0; \
+ dev_id = rte_gpu_find_next(dev_id + 1, parent))
/**
* @warning
* @b EXPERIMENTAL: this API may change without prior notice.
*
- * Close device.
+ * Close device or child context.
* All resources are released.
*
* @param dev_id
__rte_experimental
int rte_gpu_info_get(int16_t dev_id, struct rte_gpu_info *info);
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Allocate a chunk of memory in the device.
+ *
+ * @param dev_id
+ * Device ID requiring allocated memory.
+ * @param size
+ * Number of bytes to allocate.
+ * Requesting 0 will do nothing.
+ *
+ * @return
+ * A pointer to the allocated memory, otherwise NULL and rte_errno is set:
+ * - ENODEV if invalid dev_id
+ * - EINVAL if reserved flags
+ * - ENOTSUP if operation not supported by the driver
+ * - E2BIG if size is higher than limit
+ * - ENOMEM if out of space
+ * - EPERM if driver error
+ */
+__rte_experimental
+void *rte_gpu_mem_alloc(int16_t dev_id, size_t size)
+__rte_alloc_size(2);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Deallocate a chunk of memory allocated with rte_gpu_mem_alloc().
+ *
+ * @param dev_id
+ * Reference device ID.
+ * @param ptr
+ * Pointer to the memory area to be deallocated.
+ * NULL is a no-op accepted value.
+ *
+ * @return
+ * 0 on success, -rte_errno otherwise:
+ * - ENODEV if invalid dev_id
+ * - ENOTSUP if operation not supported by the driver
+ * - EPERM if driver error
+ */
+__rte_experimental
+int rte_gpu_mem_free(int16_t dev_id, void *ptr);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Register a chunk of memory on the CPU usable by the device.
+ *
+ * @param dev_id
+ * Device ID requiring allocated memory.
+ * @param size
+ * Number of bytes to allocate.
+ * Requesting 0 will do nothing.
+ * @param ptr
+ * Pointer to the memory area to be registered.
+ * NULL is a no-op accepted value.
+
+ * @return
+ * A pointer to the allocated memory, otherwise NULL and rte_errno is set:
+ * - ENODEV if invalid dev_id
+ * - EINVAL if reserved flags
+ * - ENOTSUP if operation not supported by the driver
+ * - E2BIG if size is higher than limit
+ * - ENOMEM if out of space
+ * - EPERM if driver error
+ */
+__rte_experimental
+int rte_gpu_mem_register(int16_t dev_id, size_t size, void *ptr);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Deregister a chunk of memory previously registered with rte_gpu_mem_register()
+ *
+ * @param dev_id
+ * Reference device ID.
+ * @param ptr
+ * Pointer to the memory area to be unregistered.
+ * NULL is a no-op accepted value.
+ *
+ * @return
+ * 0 on success, -rte_errno otherwise:
+ * - ENODEV if invalid dev_id
+ * - ENOTSUP if operation not supported by the driver
+ * - EPERM if driver error
+ */
+__rte_experimental
+int rte_gpu_mem_unregister(int16_t dev_id, void *ptr);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Enforce a GPU write memory barrier.
+ *
+ * @param dev_id
+ * Reference device ID.
+ *
+ * @return
+ * 0 on success, -rte_errno otherwise:
+ * - ENODEV if invalid dev_id
+ * - ENOTSUP if operation not supported by the driver
+ * - EPERM if driver error
+ */
+__rte_experimental
+int rte_gpu_wmb(int16_t dev_id);
+
#ifdef __cplusplus
}
#endif