From cc07dcc6049faee3b2adec7249d2b09d27500d2c Mon Sep 17 00:00:00 2001 From: Tuomas Taipale Date: Mon, 30 Oct 2023 09:22:07 +0000 Subject: [PATCH 1/2] abi: dma: increase default transfer ID size Increase default `odp_dma_transfer_id_t` size to 64 bit from 32 bit. This enables different implementations to potentially utilize pointers as the transfer ID. Signed-off-by: Tuomas Taipale Reviewed-by: Matias Elo --- include/odp/api/abi-default/dma_types.h | 2 +- platform/linux-generic/odp_dma.c | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/odp/api/abi-default/dma_types.h b/include/odp/api/abi-default/dma_types.h index ce133661eb..1d27a11aa4 100644 --- a/include/odp/api/abi-default/dma_types.h +++ b/include/odp/api/abi-default/dma_types.h @@ -29,7 +29,7 @@ typedef _odp_abi_dma_t *odp_dma_compl_t; #define ODP_DMA_COMPL_INVALID ((odp_dma_compl_t)0) -typedef uint32_t odp_dma_transfer_id_t; +typedef uint64_t odp_dma_transfer_id_t; #define ODP_DMA_TRANSFER_ID_INVALID ((odp_dma_transfer_id_t)0) diff --git a/platform/linux-generic/odp_dma.c b/platform/linux-generic/odp_dma.c index 82d7370736..5ffeb20cee 100644 --- a/platform/linux-generic/odp_dma.c +++ b/platform/linux-generic/odp_dma.c @@ -31,6 +31,8 @@ #define MAX_SEGS 16 #define MAX_SEG_LEN (128 * 1024) +ODP_STATIC_ASSERT(MAX_TRANSFERS < UINT32_MAX, "Too many inflight transfers"); + typedef struct segment_t { void *addr; uint32_t len; @@ -597,6 +599,7 @@ int odp_dma_transfer_start(odp_dma_t dma, const odp_dma_transfer_param_t *transf { int ret; dma_session_t *session = dma_session_from_handle(dma); + const uint32_t transfer_id = compl->transfer_id; if (odp_unlikely(dma == ODP_DMA_INVALID)) { _ODP_ERR("Bad DMA handle\n"); @@ -608,9 +611,8 @@ int odp_dma_transfer_start(odp_dma_t dma, const odp_dma_transfer_param_t *transf case ODP_DMA_COMPL_NONE: break; case ODP_DMA_COMPL_POLL: - if (compl->transfer_id == ODP_DMA_TRANSFER_ID_INVALID || - compl->transfer_id > MAX_TRANSFERS) { - _ODP_ERR("Bad transfer ID: %u\n", compl->transfer_id); + if (transfer_id == ODP_DMA_TRANSFER_ID_INVALID || transfer_id > MAX_TRANSFERS) { + _ODP_ERR("Bad transfer ID: %u\n", transfer_id); return -1; } break; @@ -632,7 +634,7 @@ int odp_dma_transfer_start(odp_dma_t dma, const odp_dma_transfer_param_t *transf return ret; if (compl->compl_mode == ODP_DMA_COMPL_POLL) { - uint32_t index = index_from_transfer_id(compl->transfer_id); + uint32_t index = index_from_transfer_id(transfer_id); session->result[index].user_ptr = compl->user_ptr; @@ -687,20 +689,20 @@ int odp_dma_transfer_done(odp_dma_t dma, odp_dma_transfer_id_t transfer_id, odp_dma_result_t *result) { dma_session_t *session = dma_session_from_handle(dma); + const uint32_t id = transfer_id; if (odp_unlikely(dma == ODP_DMA_INVALID)) { _ODP_ERR("Bad DMA handle\n"); return -1; } - if (odp_unlikely(transfer_id == ODP_DMA_TRANSFER_ID_INVALID || - transfer_id > MAX_TRANSFERS)) { - _ODP_ERR("Bad transfer ID: %u\n", transfer_id); + if (odp_unlikely(id == ODP_DMA_TRANSFER_ID_INVALID || id > MAX_TRANSFERS)) { + _ODP_ERR("Bad transfer ID: %u\n", id); return -1; } if (result) { - uint32_t index = index_from_transfer_id(transfer_id); + uint32_t index = index_from_transfer_id(id); result->success = 1; result->user_ptr = session->result[index].user_ptr; From 0d9b508e8e4b3e622424070cf9fdef9897039f78 Mon Sep 17 00:00:00 2001 From: Tuomas Taipale Date: Mon, 30 Oct 2023 10:20:45 +0000 Subject: [PATCH 2/2] linux-gen: dma: utilize _odp_pri() Utilize `_odp_pri()` to get rid of repetitive `(uint64_t)(uintptr_t)` casts. Signed-off-by: Tuomas Taipale Reviewed-by: Matias Elo --- platform/linux-generic/odp_dma.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/platform/linux-generic/odp_dma.c b/platform/linux-generic/odp_dma.c index 5ffeb20cee..b3439498c0 100644 --- a/platform/linux-generic/odp_dma.c +++ b/platform/linux-generic/odp_dma.c @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -758,12 +759,12 @@ odp_pool_t odp_dma_pool_create(const char *name, const odp_dma_pool_param_t *dma uint64_t odp_dma_to_u64(odp_dma_t dma) { - return (uint64_t)(uintptr_t)dma; + return _odp_pri(dma); } uint64_t odp_dma_compl_to_u64(odp_dma_compl_t dma_compl) { - return (uint64_t)(uintptr_t)dma_compl; + return _odp_pri(dma_compl); } void odp_dma_print(odp_dma_t dma) @@ -796,12 +797,11 @@ void odp_dma_compl_print(odp_dma_compl_t dma_compl) _ODP_PRINT("\nDMA completion\n"); _ODP_PRINT("--------------\n"); - _ODP_PRINT(" Compl event handle: 0x%" PRIx64 "\n", (uint64_t)(uintptr_t)dma_compl); + _ODP_PRINT(" Compl event handle: 0x%" PRIx64 "\n", _odp_pri(dma_compl)); if (ret == 0) { _ODP_PRINT(" Result: %s\n", result.success ? "success" : "fail"); - _ODP_PRINT(" User pointer: 0x%" PRIx64 "\n", - (uint64_t)(uintptr_t)result.user_ptr); + _ODP_PRINT(" User pointer: 0x%" PRIx64 "\n", _odp_pri(result.user_ptr)); } else { _ODP_PRINT(" No result metadata\n"); }