diff mbox

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

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

Commit Message

Bill Fischofer Jan. 30, 2015, 4:27 a.m. UTC
Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
---
 platform/linux-generic/include/odp/plat/buffer_types.h |  9 +++++----
 platform/linux-generic/include/odp_buffer_inlines.h    | 12 ++++++------
 platform/linux-generic/odp_packet.c                    | 13 +++++++------
 3 files changed, 18 insertions(+), 16 deletions(-)
diff mbox

Patch

diff --git a/platform/linux-generic/include/odp/plat/buffer_types.h b/platform/linux-generic/include/odp/plat/buffer_types.h
index 8601e61..0890bcd 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,16 @@  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)
 
 /**
  * @}
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 f902679..f24dc43 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;