From patchwork Tue Feb 3 04:44:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 44194 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E757E2034D for ; Tue, 3 Feb 2015 04:46:11 +0000 (UTC) Received: by mail-wi0-f200.google.com with SMTP id fb4sf23594849wid.3 for ; Mon, 02 Feb 2015 20:46:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=+z6sDIcNF5pqQXh6ZyxGgxS9OqrXPgz+AAxJRCf3t2E=; b=FbiHr8WqITPts0jZe91X8sxDn9BOPqY+TTyT6Q2mwgpL8ETbZDkUnV4L3Xx7Fprv2L TUuPSqgWHo6Kvqc+JQANL4Lwt7NNJCXP2FnhH8lT8uNn5JTe48XECJ+hIZQlt2RZtO7f D6cP26OIL5s8ai6HbFM8savT6WXJ4T6aAY+FE0vjaMO+pgh7XDr59iN5cq2AcF/ErU8R jDDB0CUN0vbJLQWupamukK+pt0uqTohgFnV9vNoEJeA43JL2px8seR0CrMGW3qZkpWel BFc9dh46IVzImJiUvU7wzscjJhMBYxQ9S18KeRg0GPqPNFO7Me8SjfaZiDFcIsYcBcyJ mpDA== X-Gm-Message-State: ALoCoQnMLAPCTwdoCmJ6IKhccEyrE0s7YBbMWe+IanVQBjUYzY6NGW1y9bfO4RtnqJsfQRc9mRbl X-Received: by 10.112.99.37 with SMTP id en5mr2752509lbb.17.1422938771234; Mon, 02 Feb 2015 20:46:11 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.68 with SMTP id kw4ls758069lac.101.gmail; Mon, 02 Feb 2015 20:46:10 -0800 (PST) X-Received: by 10.112.148.73 with SMTP id tq9mr22542979lbb.37.1422938770661; Mon, 02 Feb 2015 20:46:10 -0800 (PST) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id tz3si18391245lbb.66.2015.02.02.20.46.10 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 02 Feb 2015 20:46:10 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by mail-la0-f47.google.com with SMTP id hz20so47835013lab.6 for ; Mon, 02 Feb 2015 20:46:10 -0800 (PST) X-Received: by 10.112.98.99 with SMTP id eh3mr22179501lbb.32.1422938770191; Mon, 02 Feb 2015 20:46:10 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp1712439lbj; Mon, 2 Feb 2015 20:46:09 -0800 (PST) X-Received: by 10.140.16.50 with SMTP id 47mr46948966qga.105.1422938768864; Mon, 02 Feb 2015 20:46:08 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id a4si26944251qcf.32.2015.02.02.20.46.07 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 02 Feb 2015 20:46:08 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YIVNF-00067Z-Jh; Tue, 03 Feb 2015 04:46:05 +0000 Received: from mail-oi0-f50.google.com ([209.85.218.50]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YIVMi-00060R-ML for lng-odp@lists.linaro.org; Tue, 03 Feb 2015 04:45:32 +0000 Received: by mail-oi0-f50.google.com with SMTP id h136so47712775oig.9 for ; Mon, 02 Feb 2015 20:45:27 -0800 (PST) X-Received: by 10.182.230.194 with SMTP id ta2mr1264940obc.71.1422938727453; Mon, 02 Feb 2015 20:45:27 -0800 (PST) Received: from localhost.localdomain (cpe-24-28-70-239.austin.res.rr.com. [24.28.70.239]) by mx.google.com with ESMTPSA id vs5sm10277537oeb.14.2015.02.02.20.45.26 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Feb 2015 20:45:27 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Mon, 2 Feb 2015 22:44:51 -0600 Message-Id: <1422938699-12877-12-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1422938699-12877-1-git-send-email-bill.fischofer@linaro.org> References: <1422938699-12877-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv5 11/19] linux-generic: buffers: add strong typing support X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: bill.fischofer@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Signed-off-by: Bill Fischofer --- .../linux-generic/include/odp/plat/buffer_types.h | 15 ++++++++--- .../linux-generic/include/odp_buffer_inlines.h | 12 ++++----- .../linux-generic/include/odp_buffer_internal.h | 31 +++++++++++----------- platform/linux-generic/odp_packet.c | 13 ++++----- 4 files changed, 40 insertions(+), 31 deletions(-) diff --git a/platform/linux-generic/include/odp/plat/buffer_types.h b/platform/linux-generic/include/odp/plat/buffer_types.h index 8601e61..3e7070e 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 +#include /** @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_to_u64(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/include/odp_buffer_internal.h b/platform/linux-generic/include/odp_buffer_internal.h index b3137a7..f199e2e 100644 --- a/platform/linux-generic/include/odp_buffer_internal.h +++ b/platform/linux-generic/include/odp_buffer_internal.h @@ -77,29 +77,30 @@ _ODP_STATIC_ASSERT((ODP_CONFIG_PACKET_BUF_LEN_MAX % #define ODP_BUFFER_INVALID_INDEX (ODP_BUFFER_MAX_BUFFERS - 1) typedef union odp_buffer_bits_t { - uint32_t u32; odp_buffer_t handle; - - struct { + union { + uint32_t u32; + struct { #if ODP_BYTE_ORDER == ODP_BIG_ENDIAN - uint32_t pool_id:ODP_BUFFER_POOL_BITS; - uint32_t index:ODP_BUFFER_INDEX_BITS; - uint32_t seg:ODP_BUFFER_SEG_BITS; + uint32_t pool_id:ODP_BUFFER_POOL_BITS; + uint32_t index:ODP_BUFFER_INDEX_BITS; + uint32_t seg:ODP_BUFFER_SEG_BITS; #else - uint32_t seg:ODP_BUFFER_SEG_BITS; - uint32_t index:ODP_BUFFER_INDEX_BITS; - uint32_t pool_id:ODP_BUFFER_POOL_BITS; + uint32_t seg:ODP_BUFFER_SEG_BITS; + uint32_t index:ODP_BUFFER_INDEX_BITS; + uint32_t pool_id:ODP_BUFFER_POOL_BITS; #endif - }; + }; - struct { + struct { #if ODP_BYTE_ORDER == ODP_BIG_ENDIAN - uint32_t prefix:ODP_BUFFER_PREFIX_BITS; - uint32_t pfxseg:ODP_BUFFER_SEG_BITS; + uint32_t prefix:ODP_BUFFER_PREFIX_BITS; + uint32_t pfxseg:ODP_BUFFER_SEG_BITS; #else - uint32_t pfxseg:ODP_BUFFER_SEG_BITS; - uint32_t prefix:ODP_BUFFER_PREFIX_BITS; + uint32_t pfxseg:ODP_BUFFER_SEG_BITS; + uint32_t prefix:ODP_BUFFER_PREFIX_BITS; #endif + }; }; } odp_buffer_bits_t; 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;