From patchwork Wed Jul 20 20:38:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 72503 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp76764qga; Wed, 20 Jul 2016 13:45:45 -0700 (PDT) X-Received: by 10.55.164.205 with SMTP id n196mr60235748qke.73.1469047545487; Wed, 20 Jul 2016 13:45:45 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id x130si2774389qkb.24.2016.07.20.13.45.45; Wed, 20 Jul 2016 13:45:45 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 2C9FA686EF; Wed, 20 Jul 2016 20:45:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id A846568922; Wed, 20 Jul 2016 20:39:55 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 816B6686EF; Wed, 20 Jul 2016 20:39:47 +0000 (UTC) Received: from mail-lf0-f41.google.com (mail-lf0-f41.google.com [209.85.215.41]) by lists.linaro.org (Postfix) with ESMTPS id 4A1AF688FF for ; Wed, 20 Jul 2016 20:39:15 +0000 (UTC) Received: by mail-lf0-f41.google.com with SMTP id l69so46359762lfg.1 for ; Wed, 20 Jul 2016 13:39:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IJkh+q6Do6fsXkNU0zYuB9JTHnNjUH+RRYqaRHL2s2A=; b=BYH0BrlkJCwtOxCXsTIZQIuBj9haMCyQOkx5FmnIVR35bw9/Rcgz5xM2aYhNWoI39Q gmWN1lZ0w/Qk19yldaAoRGbhFdZFcmWYfhQmVYabkt9And8lhji1nqG5rFl1Ty7QxYcY C+NTKTUunTO6Jl0PEWnIQXK9RPQYyxmg3P+VwFN5TB3VE6z4YLJg2T9a1GICdlT50O1Q kc03LRYkDYswlDncJbQmJgkrm47PRnypTsiCS5vDYr3buZa17dZsCiYqeaiItQ1bu/2b spfABzHkXK0uZLNbYSgnBm3VwXziwe6umNBPVJLc5D9U09YkUI6NQNyLHukU2BYUv+1e s4Fg== X-Gm-Message-State: ALyK8tJ+4czaAMIwNLX4p6FLJyb+TsGKC7uiiGS3f/nQmRUGxK5NXXUBLFGNNf/QlkPtIna4yDQ= X-Received: by 10.46.0.17 with SMTP id 17mr21149780lja.54.1469047154052; Wed, 20 Jul 2016 13:39:14 -0700 (PDT) Received: from localhost.localdomain (c-83-233-90-46.cust.bredband2.com. [83.233.90.46]) by smtp.gmail.com with ESMTPSA id 29sm895112lfu.43.2016.07.20.13.39.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 20 Jul 2016 13:39:13 -0700 (PDT) From: Christophe Milard To: mike.holmes@linaro.org, lng-odp@lists.linaro.org, balakrishna.garapati@linaro.org Date: Wed, 20 Jul 2016 22:38:51 +0200 Message-Id: <1469047144-7960-6-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1469047144-7960-1-git-send-email-christophe.milard@linaro.org> References: <1469047144-7960-1-git-send-email-christophe.milard@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv2 05/18] linux-generic: drv: adding byteorder.h X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Based on API interface files (sha:77a27212b563299959fb2a609b86bb9117a8f918). Signed-off-by: Christophe Milard --- include/odp_drv.h | 1 + platform/linux-generic/Makefile.am | 5 + platform/linux-generic/include/odp/drv/byteorder.h | 146 +++++++++++++++++++++ .../include/odp/drv/plat/byteorder_types.h | 80 +++++++++++ 4 files changed, 232 insertions(+) create mode 100644 platform/linux-generic/include/odp/drv/byteorder.h create mode 100644 platform/linux-generic/include/odp/drv/plat/byteorder_types.h -- 2.7.4 diff --git a/include/odp_drv.h b/include/odp_drv.h index a6d3a44..1956e8c 100644 --- a/include/odp_drv.h +++ b/include/odp_drv.h @@ -18,6 +18,7 @@ extern C { #endif +#include #include #include diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 991ccd2..5b70fb4 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -93,8 +93,13 @@ odpapiplatinclude_HEADERS = \ odpdrvincludedir = $(includedir)/odp/drv odpdrvinclude_HEADERS = \ + $(srcdir)/include/odp/drv/byteorder.h \ $(srcdir)/include/odp/drv/compiler.h +odpdrvplatincludedir = $(includedir)/odp/drv/plat +odpdrvplatinclude_HEADERS = \ + $(srcdir)/include/odp/drv/plat/byteorder_types.h + noinst_HEADERS = \ ${srcdir}/include/odp_align_internal.h \ ${srcdir}/include/odp_atomic_internal.h \ diff --git a/platform/linux-generic/include/odp/drv/byteorder.h b/platform/linux-generic/include/odp/drv/byteorder.h new file mode 100644 index 0000000..709a520 --- /dev/null +++ b/platform/linux-generic/include/odp/drv/byteorder.h @@ -0,0 +1,146 @@ +/* Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODPDRV byteorder + */ + +#ifndef ODPDRVP_PLAT_BYTEORDER_H_ +#define ODPDRVP_PLAT_BYTEORDER_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +/** @ingroup odpdrv_compiler_optim + * @{ + */ + +static inline uint16_t odpdrv_be_to_cpu_16(odpdrv_u16be_t be16) +{ +#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN + return __odpdrv_builtin_bswap16((__odpdrv_force uint16_t)be16); +#else + return (__odpdrv_force uint16_t)be16; +#endif +} + +static inline uint32_t odpdrv_be_to_cpu_32(odpdrv_u32be_t be32) +{ +#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN + return __builtin_bswap32((__odpdrv_force uint32_t)be32); +#else + return (__odpdrv_force uint32_t)be32; +#endif +} + +static inline uint64_t odpdrv_be_to_cpu_64(odpdrv_u64be_t be64) +{ +#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN + return __builtin_bswap64((__odpdrv_force uint64_t)be64); +#else + return (__odpdrv_force uint64_t)be64; +#endif +} + +static inline odpdrv_u16be_t odpdrv_cpu_to_be_16(uint16_t cpu16) +{ +#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN + return (__odpdrv_force odpdrv_u16be_t)__odpdrv_builtin_bswap16(cpu16); +#else + return (__odpdrv_force odpdrv_u16be_t)cpu16; +#endif +} + +static inline odpdrv_u32be_t odpdrv_cpu_to_be_32(uint32_t cpu32) +{ +#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN + return (__odpdrv_force odpdrv_u32be_t)__builtin_bswap32(cpu32); +#else + return (__odpdrv_force odpdrv_u32be_t)cpu32; +#endif +} + +static inline odpdrv_u64be_t odpdrv_cpu_to_be_64(uint64_t cpu64) +{ +#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN + return (__odpdrv_force odpdrv_u64be_t)__builtin_bswap64(cpu64); +#else + return (__odpdrv_force odpdrv_u64be_t)cpu64; +#endif +} + +static inline uint16_t odpdrv_le_to_cpu_16(odpdrv_u16le_t le16) +{ +#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN + return (__odpdrv_force uint16_t)le16; +#else + return __odpdrv_builtin_bswap16((__odpdrv_force uint16_t)le16); +#endif +} + +static inline uint32_t odpdrv_le_to_cpu_32(odpdrv_u32le_t le32) +{ +#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN + return (__odpdrv_force uint32_t)le32; +#else + return __builtin_bswap32((__odpdrv_force uint32_t)le32); +#endif +} + +static inline uint64_t odpdrv_le_to_cpu_64(odpdrv_u64le_t le64) +{ +#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN + return (__odpdrv_force uint64_t)le64; +#else + return __builtin_bswap64((__odpdrv_force uint64_t)le64); +#endif +} + +static inline odpdrv_u16le_t odpdrv_cpu_to_le_16(uint16_t cpu16) +{ +#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN + return (__odpdrv_force odpdrv_u16le_t)cpu16; +#else + return (__odpdrv_force odpdrv_u16le_t)__odpdrv_builtin_bswap16(cpu16); +#endif +} + +static inline odpdrv_u32le_t odpdrv_cpu_to_le_32(uint32_t cpu32) +{ +#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN + return (__odpdrv_force odpdrv_u32le_t)cpu32; +#else + return (__odpdrv_force odpdrv_u32le_t)__builtin_bswap32(cpu32); +#endif +} + +static inline odpdrv_u64le_t odpdrv_cpu_to_le_64(uint64_t cpu64) +{ +#if ODPDRVP_BYTE_ORDER == ODPDRVP_LITTLE_ENDIAN + return (__odpdrv_force odpdrv_u64le_t)cpu64; +#else + return (__odpdrv_force odpdrv_u64le_t)__builtin_bswap64(cpu64); +#endif +} + +/** + * @} + */ + +#include + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/include/odp/drv/plat/byteorder_types.h b/platform/linux-generic/include/odp/drv/plat/byteorder_types.h new file mode 100644 index 0000000..bf461e5 --- /dev/null +++ b/platform/linux-generic/include/odp/drv/plat/byteorder_types.h @@ -0,0 +1,80 @@ +/* Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODPDRV byteorder + */ + +#ifndef ODPDRV_BYTEORDER_TYPES_H_ +#define ODPDRV_BYTEORDER_TYPES_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef __BYTE_ORDER__ +#error __BYTE_ORDER not defined! +#endif + +#ifndef __ORDER_BIG_ENDIAN__ +#error __BIG_ENDIAN not defined! +#endif + +#ifndef __ORDER_LITTLE_ENDIAN__ +#error __LITTLE_ENDIAN not defined! +#endif + +/* for use with type checkers such as sparse */ +#ifdef __CHECKER__ +/** @internal bitwise attribute */ +#define __odpdrv_bitwise __attribute__((bitwise)) +/** @internal force attribute */ +#define __odpdrv_force __attribute__((force)) +#else +/** @internal bitwise attribute */ +#define __odpdrv_bitwise +/** @internal force attribute */ +#define __odpdrv_force +#endif + +/** @addtogroup odpdrv_compiler_optim + * @{ + */ +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + #define ODPDRV_LITTLE_ENDIAN 1 + #define ODPDRV_BIG_ENDIAN 0 + #define ODPDRV_BYTE_ORDER ODP_LITTLE_ENDIAN + #define ODPDRV_LITTLE_ENDIAN_BITFIELD +#else + #define ODPDRV_LITTLE_ENDIAN 0 + #define ODPDRV_BIG_ENDIAN 1 + #define ODPDRV_BYTE_ORDER ODP_BIG_ENDIAN + #define ODPDRV_BIG_ENDIAN_BITFIELD +#endif + +typedef uint16_t __odpdrv_bitwise odpdrv_u16le_t; +typedef uint16_t __odpdrv_bitwise odpdrv_u16be_t; + +typedef uint32_t __odpdrv_bitwise odpdrv_u32le_t; +typedef uint32_t __odpdrv_bitwise odpdrv_u32be_t; + +typedef uint64_t __odpdrv_bitwise odpdrv_u64le_t; +typedef uint64_t __odpdrv_bitwise odpdrv_u64be_t; + +typedef uint16_t __odpdrv_bitwise odpdrv_u16sum_t; +typedef uint32_t __odpdrv_bitwise odpdrv_u32sum_t; + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif