From patchwork Sat Jan 31 20:50:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 44096 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4EDB72359E for ; Sat, 31 Jan 2015 20:51:20 +0000 (UTC) Received: by mail-wi0-f198.google.com with SMTP id h11sf8768727wiw.1 for ; Sat, 31 Jan 2015 12:51:19 -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=G06RDvGdxHx+H1YY7I8r92SJxLDhn406qildywEefx8=; b=JZmPmD+X72A6FYWg7hagJdnHf7tTxM8MfCy1tWXOKy/FY7FBe+U3TidAiioVZo0gAP TpXAMlBphArPTNd0EsDZSUyNkqI4TgTtbKOn1lQ6XW9t/v/OqQ62pPB/rXxA3uXqpKfI K+PMLQadslOE+FC28/OiMP2o1BNIeM9h/o39+/gFQYXtK44D3Kc1p9TKKaFjqG8wzreb jyhOokDGK9K1vTMs7jTAfz5JJthohLX6Y5NDCFDqlBFBhjTdJasNErRZ2DeALBNntSWn quK4H2ORBnzIiE8XX1zrLHbjMoyrHKsaJRbqR8sGuvmcCmTG7Q+AB7g/lqZBzrPO3pTv L6tw== X-Gm-Message-State: ALoCoQk+/DRIWzb/CrDfwA5bNQu50Lpu1GSyW3Ww+/U/GZzHBbgdELvhMvZmv4ODh+ntwEYryTtw X-Received: by 10.180.93.165 with SMTP id cv5mr350014wib.6.1422737479541; Sat, 31 Jan 2015 12:51:19 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.19.73 with SMTP id c9ls534020lae.74.gmail; Sat, 31 Jan 2015 12:51:19 -0800 (PST) X-Received: by 10.153.4.5 with SMTP id ca5mr9326508lad.28.1422737479306; Sat, 31 Jan 2015 12:51:19 -0800 (PST) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id r14si13150255lal.15.2015.01.31.12.51.19 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 31 Jan 2015 12:51:19 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by mail-la0-f48.google.com with SMTP id pv20so30485764lab.7 for ; Sat, 31 Jan 2015 12:51:19 -0800 (PST) X-Received: by 10.152.20.169 with SMTP id o9mr12565352lae.50.1422737478993; Sat, 31 Jan 2015 12:51:18 -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 h5csp450266lbj; Sat, 31 Jan 2015 12:51:18 -0800 (PST) X-Received: by 10.140.30.197 with SMTP id d63mr20921204qgd.13.1422737477381; Sat, 31 Jan 2015 12:51:17 -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 i47si19163824qgd.126.2015.01.31.12.51.16 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sat, 31 Jan 2015 12:51:17 -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 1YHf0c-0000v2-6Z; Sat, 31 Jan 2015 20:51:14 +0000 Received: from mail-oi0-f49.google.com ([209.85.218.49]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YHf0Q-0000tu-Tr for lng-odp@lists.linaro.org; Sat, 31 Jan 2015 20:51:02 +0000 Received: by mail-oi0-f49.google.com with SMTP id a3so39303923oib.8 for ; Sat, 31 Jan 2015 12:50:57 -0800 (PST) X-Received: by 10.60.114.40 with SMTP id jd8mr7640343oeb.12.1422737457653; Sat, 31 Jan 2015 12:50:57 -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 uv10sm7202439obc.27.2015.01.31.12.50.56 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 31 Jan 2015 12:50:56 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Sat, 31 Jan 2015 14:50:42 -0600 Message-Id: <1422737449-11540-3-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1422737449-11540-1-git-send-email-bill.fischofer@linaro.org> References: <1422737449-11540-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv3 2/9] 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.48 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 --- include/odp/api/buffer.h | 13 +++++++++ .../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 ++++----- 5 files changed, 53 insertions(+), 31 deletions(-) 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 +#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_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/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;