diff mbox

[PATCHv2,2/9] linux-generic: buffers: add strong typing support

Message ID 1422720866-22194-3-git-send-email-bill.fischofer@linaro.org
State New
Headers show

Commit Message

Bill Fischofer Jan. 31, 2015, 4:14 p.m. UTC
Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
---
 include/odp/api/buffer.h                               | 13 +++++++++++++
 platform/linux-generic/include/odp/plat/buffer_types.h | 15 +++++++++++----
 platform/linux-generic/include/odp_buffer_inlines.h    | 12 ++++++------
 platform/linux-generic/odp_packet.c                    | 13 +++++++------
 4 files changed, 37 insertions(+), 16 deletions(-)
diff mbox

Patch

diff --git a/include/odp/api/buffer.h b/include/odp/api/buffer.h
index 12b2f5a..3967034 100644
--- a/include/odp/api/buffer.h
+++ b/include/odp/api/buffer.h
@@ -113,6 +113,19 @@  odp_pool_t odp_buffer_pool(odp_buffer_t buf);
 void odp_buffer_print(odp_buffer_t buf);
 
 /**
+ * Get printable value for an odp_buffer_t
+ *
+ * @param hdl  odp_buffer_t handle to be printed
+ * @return     uint64_t value that can be used to print/display this
+ *             handle
+ *
+ * @note This routine is intended to be used for diagnostic purposes
+ * to enable applications to generate a printable value that represents
+ * an odp_buffer_t handle.
+ */
+uint64_t odp_buffer_t_print(odp_buffer_t hdl);
+
+/**
  * @}
  */
 
diff --git a/platform/linux-generic/include/odp/plat/buffer_types.h b/platform/linux-generic/include/odp/plat/buffer_types.h
index 8601e61..fcac068 100644
--- a/platform/linux-generic/include/odp/plat/buffer_types.h
+++ b/platform/linux-generic/include/odp/plat/buffer_types.h
@@ -18,6 +18,7 @@  extern "C" {
 #endif
 
 #include <odp/std_types.h>
+#include <odp/plat/strong_types.h>
 
 /** @addtogroup odp_buffer ODP BUFFER
  *  Operations on a buffer.
@@ -25,16 +26,22 @@  extern "C" {
  */
 
 /** ODP buffer */
-typedef uint32_t odp_buffer_t;
+typedef odp_handle_t odp_buffer_t;
 
 /** Invalid buffer */
-#define ODP_BUFFER_INVALID (0xffffffff)
+#define ODP_BUFFER_INVALID _odp_cast_scalar(odp_buffer_t, 0xffffffff)
 
 /** ODP buffer segment */
-typedef odp_buffer_t odp_buffer_seg_t;
+typedef odp_handle_t odp_buffer_seg_t;
 
 /** Invalid segment */
-#define ODP_SEGMENT_INVALID ODP_BUFFER_INVALID
+#define ODP_SEGMENT_INVALID ((odp_buffer_seg_t)ODP_BUFFER_INVALID)
+
+/** Get printable format of odp_buffer_t */
+static inline uint64_t odp_buffer_t_print(odp_buffer_t hdl)
+{
+	return _odp_pri(hdl);
+}
 
 /**
  * @}
diff --git a/platform/linux-generic/include/odp_buffer_inlines.h b/platform/linux-generic/include/odp_buffer_inlines.h
index 6a30a07..ba358f1 100644
--- a/platform/linux-generic/include/odp_buffer_inlines.h
+++ b/platform/linux-generic/include/odp_buffer_inlines.h
@@ -31,7 +31,7 @@  static inline odp_buffer_t odp_buffer_encode_handle(odp_buffer_hdr_t *hdr)
 		ODP_CACHE_LINE_SIZE;
 	handle.seg = 0;
 
-	return handle.u32;
+	return handle.handle;
 }
 
 static inline odp_buffer_t odp_hdr_to_buf(odp_buffer_hdr_t *hdr)
@@ -46,7 +46,7 @@  static inline odp_buffer_hdr_t *odp_buf_to_hdr(odp_buffer_t buf)
 	uint32_t index;
 	struct pool_entry_s *pool;
 
-	handle.u32 = buf;
+	handle.handle = buf;
 	pool_id    = handle.pool_id;
 	index      = handle.index;
 
@@ -100,7 +100,7 @@  static inline odp_buffer_hdr_t *validate_buf(odp_buffer_t buf)
 {
 	odp_buffer_bits_t handle;
 	odp_buffer_hdr_t *buf_hdr;
-	handle.u32 = buf;
+	handle.handle = buf;
 
 	/* For buffer handles, segment index must be 0 and pool id in range */
 	if (handle.seg != 0 || handle.pool_id >= ODP_CONFIG_POOLS)
@@ -150,7 +150,7 @@  static inline odp_buffer_seg_t segment_next(odp_buffer_hdr_t *buf,
 					    odp_buffer_seg_t seg)
 {
 	odp_buffer_bits_t seghandle;
-	seghandle.u32 = seg;
+	seghandle.handle = (odp_buffer_t)seg;
 
 	if (seg == ODP_SEGMENT_INVALID ||
 	    seghandle.prefix != buf->handle.prefix ||
@@ -158,7 +158,7 @@  static inline odp_buffer_seg_t segment_next(odp_buffer_hdr_t *buf,
 		return ODP_SEGMENT_INVALID;
 	else {
 		seghandle.seg++;
-		return (odp_buffer_seg_t)seghandle.u32;
+		return (odp_buffer_seg_t)seghandle.handle;
 	}
 }
 
@@ -171,7 +171,7 @@  static inline void *segment_map(odp_buffer_hdr_t *buf,
 	uint32_t seg_offset, buf_left;
 	odp_buffer_bits_t seghandle;
 	uint8_t *seg_addr;
-	seghandle.u32 = seg;
+	seghandle.handle = (odp_buffer_t)seg;
 
 	if (seghandle.prefix != buf->handle.prefix ||
 	    seghandle.seg >= buf->segcount)
diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c
index 968ad3e..a031f13 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -193,7 +193,7 @@  void *odp_packet_offset(odp_packet_t pkt, uint32_t offset, uint32_t *len,
 
 	if (addr != NULL && seg != NULL) {
 		odp_buffer_bits_t seghandle;
-		seghandle.u32 = (uint32_t)pkt;
+		seghandle.handle = pkt;
 		seghandle.seg = (pkt_hdr->headroom + offset) /
 			pkt_hdr->buf_hdr.segsize;
 		*seg = seghandle.handle;
@@ -325,7 +325,7 @@  odp_packet_seg_t odp_packet_last_seg(odp_packet_t pkt)
 	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
 	odp_buffer_bits_t seghandle;
 
-	seghandle.u32 = (uint32_t)pkt;
+	seghandle.handle = pkt;
 	seghandle.seg = pkt_hdr->buf_hdr.segcount - 1;
 	return seghandle.handle;
 }
@@ -334,7 +334,8 @@  odp_packet_seg_t odp_packet_next_seg(odp_packet_t pkt, odp_packet_seg_t seg)
 {
 	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
 
-	return segment_next(&pkt_hdr->buf_hdr, seg);
+	return (odp_packet_seg_t)segment_next(&pkt_hdr->buf_hdr,
+					      (odp_buffer_seg_t)seg);
 }
 
 /*
@@ -348,7 +349,7 @@  void *odp_packet_seg_buf_addr(odp_packet_t pkt, odp_packet_seg_t seg)
 {
 	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
 
-	return segment_map(&pkt_hdr->buf_hdr, seg, NULL,
+	return segment_map(&pkt_hdr->buf_hdr, (odp_buffer_seg_t)seg, NULL,
 			   pkt_hdr->headroom + pkt_hdr->frame_len, 0);
 }
 
@@ -362,7 +363,7 @@  void *odp_packet_seg_data(odp_packet_t pkt, odp_packet_seg_t seg)
 {
 	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
 
-	return segment_map(&pkt_hdr->buf_hdr, seg, NULL,
+	return segment_map(&pkt_hdr->buf_hdr, (odp_buffer_seg_t)seg, NULL,
 			   pkt_hdr->frame_len, pkt_hdr->headroom);
 }
 
@@ -371,7 +372,7 @@  uint32_t odp_packet_seg_data_len(odp_packet_t pkt, odp_packet_seg_t seg)
 	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
 	uint32_t seglen = 0;
 
-	segment_map(&pkt_hdr->buf_hdr, seg, &seglen,
+	segment_map(&pkt_hdr->buf_hdr, (odp_buffer_seg_t)seg, &seglen,
 		    pkt_hdr->frame_len, pkt_hdr->headroom);
 
 	return seglen;