Signed-off-by: Zhangfei Gao zhangfei.gao@linaro.org --- include/uacce.h | 6 +++++- include/wd.h | 16 ++++++++++++++++ wd.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-)
diff --git a/include/uacce.h b/include/uacce.h index f7fae27..c7a5752 100644 --- a/include/uacce.h +++ b/include/uacce.h @@ -15,6 +15,7 @@ extern "C" {
#define UACCE_CMD_START _IO('W', 0) #define UACCE_CMD_PUT_Q _IO('W', 1) +#define UACCE_CMD_GET_SS_DMA _IOR('W', 3, unsigned long)
/** * UACCE Device flags: @@ -25,7 +26,9 @@ extern "C" { */
enum { - UACCE_DEV_SVA = 0x1, + UACCE_DEV_SVA = 0x1, + UACCE_DEV_NOIOMMU = 0x2, + UACCE_DEV_IOMMUU = 0x80, };
#define UACCE_API_VER_NOIOMMU_SUBFIX "_noiommu" @@ -33,6 +36,7 @@ enum { enum uacce_qfrt { UACCE_QFRT_MMIO = 0, /* device mmio region */ UACCE_QFRT_DUS = 1, /* device user share */ + UACCE_QFRT_SS, /* static share memory */ UACCE_QFRT_MAX, };
diff --git a/include/wd.h b/include/wd.h index b62d355..556a992 100644 --- a/include/wd.h +++ b/include/wd.h @@ -604,6 +604,22 @@ struct wd_capability { struct wd_capability *wd_get_alg_cap(void); void wd_release_alg_cap(struct wd_capability *head);
+/** + * wd_is_noiommu() - Check if the system is noiommu. + * @h_ctx: The handle of context. + * + * Return 1 if noiommu, 0 for has iommu, less than 0 otherwise. + */ +int wd_is_noiommu(handle_t h_ctx); + +/** + * wd_reserve_mem() - Reserve memory iva mmap. + * @h_ctx: The handle of context. + * @size: size of the reserved memory. + * + * Return NULL if fail, pointer of the memory if success. + */ +void *wd_reserve_mem(handle_t h_ctx, size_t size); #ifdef __cplusplus } #endif diff --git a/wd.c b/wd.c index 5fa8feb..5c930f4 100644 --- a/wd.c +++ b/wd.c @@ -578,6 +578,19 @@ int wd_ctx_wait(handle_t h_ctx, __u16 ms) return ret; }
+int wd_is_noiommu(handle_t h_ctx) +{ + struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx; + + if (!ctx || !ctx->dev) + return -WD_EINVAL; + + if ((unsigned int)ctx->dev->flags & UACCE_DEV_NOIOMMU) + return 1; + + return 0; +} + int wd_is_sva(handle_t h_ctx) { struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx; @@ -974,3 +987,20 @@ alloc_err: return NULL; }
+void *wd_reserve_mem(handle_t h_ctx, size_t size) +{ + struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx; + void *ptr; + + if (!ctx) + return NULL; + + ptr = mmap(0, size, PROT_READ | PROT_WRITE, + MAP_SHARED, ctx->fd, UACCE_QFRT_SS * getpagesize()); + if (ptr == MAP_FAILED) { + WD_ERR("wd drv mmap fail!(err = %d)\n", errno); + return NULL; + } + + return ptr; +}