From patchwork Thu Dec 21 16:00:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 122579 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1081122qgn; Thu, 21 Dec 2017 08:06:21 -0800 (PST) X-Google-Smtp-Source: ACJfBovHxUz9g+jrY+J3EHd2uTlIZO0KhjQYb6nD8gNyw4ZBwXQK3VKG/x4ZOouYwr53pMevrVzE X-Received: by 10.237.42.22 with SMTP id c22mr14889696qtd.162.1513872381479; Thu, 21 Dec 2017 08:06:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513872381; cv=none; d=google.com; s=arc-20160816; b=MIu6nTMoJYUbY4PRfQuabRBA8kA362K0oOtk9q68bEVebEP8q8uCWz9JhTuRKqMkrI CSlja5osZih+GwMHLefDpaaBhlKxDN8ejMOpC5kwKluTP9/MZCmsVDC2U1wO2CjQKbWB 8J+fEO+QN5cJqbwajdIBS0oNNDW/ecwgL4hHS+OY6WvY8FCdozdImi9Knh8Vbm+ZgFTQ Bz+bjmrArWZ1wzLp+iV0b8kUShW0C1wpTy6fmo/BfUfxzxpzXFgLZy2LpaNY3JBNqdp7 GEsVDPNOhGNaekcCIqEW5ZJBuse6x4Mk4zB2ZDldCIuwcHbfM7T0El00+vet2//s/s8o QNHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=6Z+6cBtVg0drBj0pf4O2eBeNmNhfbelOdwM6rvvozqk=; b=sonDViQS9xw0ailGHEZVZNobK4DSFwruz+rbbsn+XW0EAEwkpEHRTWOyrXAIH36gjA C5HaJMYqYDa7K0p9Qxra3WnW1Hhnj4IRXwykEn15soKKPsuNASy7C8JRDZ4oqw03XzYA g8VXH7bUB0BRLGL3t2lI5EqFV5sUgGnI2CMACQbFDd+dwMjTarfXJ5E0tnPO27L5Jnvg 0uJFzLWdz36b0Vt+5AAYQTqQO0BVTzJEwbuzuA3683u2C3NK7BwbRzSTiVdo3MR9z9oC Rs8MG3AdjcZtYsJcpbxiIApXK9nFlVJV8lUadxfqmy5Cq9chZMOzEB07wOMfJop/rYXD Zrnw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id n189si81965qkf.215.2017.12.21.08.06.21; Thu, 21 Dec 2017 08:06:21 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 2EAB36171B; Thu, 21 Dec 2017 16:06:21 +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,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, 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 79E4361516; Thu, 21 Dec 2017 16:01:38 +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 41FFC60B11; Thu, 21 Dec 2017 16:01:12 +0000 (UTC) Received: from forward104j.mail.yandex.net (forward104j.mail.yandex.net [5.45.198.247]) by lists.linaro.org (Postfix) with ESMTPS id CB91360975 for ; Thu, 21 Dec 2017 16:00:19 +0000 (UTC) Received: from mxback8j.mail.yandex.net (mxback8j.mail.yandex.net [IPv6:2a02:6b8:0:1619::111]) by forward104j.mail.yandex.net (Yandex) with ESMTP id 2DACC439D9 for ; Thu, 21 Dec 2017 19:00:18 +0300 (MSK) Received: from smtp1j.mail.yandex.net (smtp1j.mail.yandex.net [2a02:6b8:0:801::ab]) by mxback8j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id lVuJgh3X67-0Ipe0j93; Thu, 21 Dec 2017 19:00:18 +0300 Received: by smtp1j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id bLqbqs0pBY-0HPC2udM; Thu, 21 Dec 2017 19:00:17 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 21 Dec 2017 19:00:13 +0300 Message-Id: <1513872016-2819-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513872016-2819-1-git-send-email-odpbot@yandex.ru> References: <1513872016-2819-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 359 Subject: [lng-odp] [PATCH CATERPILLAR v1 1/4] linux-gen: add memory-mapped I/O access API 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" From: Mykyta Iziumtsev Signed-off-by: Mykyta Iziumtsev --- /** Email created from pull request 359 (MykytaI:caterpillar_mdev_auxiliary) ** https://github.com/Linaro/odp/pull/359 ** Patch: https://github.com/Linaro/odp/pull/359.patch ** Base sha: 63fd88635cc10caaa02fdccd3f52c9494487bdd2 ** Merge commit sha: 0e9885d54ac547d0bdf599d65b6fe32de445adb7 **/ include/odp/drv/spec/mmio.h | 145 +++++++++++++++++++++ platform/linux-generic/include/odp/drv/mmio.h | 179 ++++++++++++++++++++++++++ scripts/checkpatch.pl | 1 + 3 files changed, 325 insertions(+) create mode 100644 include/odp/drv/spec/mmio.h create mode 100644 platform/linux-generic/include/odp/drv/mmio.h diff --git a/include/odp/drv/spec/mmio.h b/include/odp/drv/spec/mmio.h new file mode 100644 index 000000000..35807637b --- /dev/null +++ b/include/odp/drv/spec/mmio.h @@ -0,0 +1,145 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * API to access memory-mapped I/O. + * + */ + +#ifndef ODPDRV_MMIO_H_ +#define ODPDRV_MMIO_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** @addtogroup odpdrv_mmio ODPDRV MMIO + * @{ + */ + +/** + * Convert endianness and write value to MMIO + * @param value cpu native 8-bit value to write to MMIO + * @param addr MMIO address to write at + */ +void odpdrv_mmio_u8le_write(uint8_t value, volatile void *addr); + +/** + * Convert endianness and write value to MMIO + * @param value cpu native 8-bit value to write to MMIO + * @param addr MMIO address to write at + */ +void odpdrv_mmio_u8be_write(uint8_t value, volatile void *addr); + +/** + * Convert endianness and write value to MMIO + * @param value cpu native 16-bit value to write to MMIO + * @param addr MMIO address to write at + */ +void odpdrv_mmio_u16le_write(uint16_t value, volatile void *addr); + +/** + * Convert endianness and write value to MMIO + * @param value cpu native 16-bit value to write to MMIO + * @param addr MMIO address to write at + */ +void odpdrv_mmio_u16be_write(uint16_t value, volatile void *addr); + +/** + * Convert endianness and write value to MMIO + * @param value cpu native 32-bit value to write to MMIO + * @param addr MMIO address to write at + */ +void odpdrv_mmio_u32le_write(uint32_t value, volatile void *addr); + +/** + * Convert endianness and write value to MMIO + * @param value cpu native 32-bit value to write to MMIO + * @param addr MMIO address to write at + */ +void odpdrv_mmio_u32be_write(uint32_t value, volatile void *addr); + +/** + * Convert endianness and write value to MMIO + * @param value cpu native 64-bit value to write to MMIO + * @param addr MMIO address to write at + */ +void odpdrv_mmio_u64le_write(uint64_t value, volatile void *addr); + +/** + * Convert endianness and write value to MMIO + * @param value cpu native 64-bit value to write to MMIO + * @param addr MMIO address to write at + */ +void odpdrv_mmio_u64be_write(uint64_t value, volatile void *addr); + +/** + * Read from MMIO and convert endianness + * @param addr MMIO address to read at + * @return cpu native 8-bit value + */ +uint8_t odpdrv_mmio_u8le_read(volatile void *addr); + +/** + * Read from MMIO and convert endianness + * @param addr MMIO address to read at + * @return cpu native 8-bit value + */ +uint8_t odpdrv_mmio_u8be_read(volatile void *addr); + +/** + * Read from MMIO and convert endianness + * @param addr MMIO address to read at + * @return cpu native 16-bit value + */ +uint16_t odpdrv_mmio_u16le_read(volatile void *addr); + +/** + * Read from MMIO and convert endianness + * @param addr MMIO address to read at + * @return cpu native 16-bit value + */ +uint16_t odpdrv_mmio_u16be_read(volatile void *addr); + +/** + * Read from MMIO and convert endianness + * @param addr MMIO address to read at + * @return cpu native 32-bit value + */ +uint32_t odpdrv_mmio_u32le_read(volatile void *addr); + +/** + * Read from MMIO and convert endianness + * @param addr MMIO address to read at + * @return cpu native 32-bit value + */ +uint32_t odpdrv_mmio_u32be_read(volatile void *addr); + +/** + * Read from MMIO and convert endianness + * @param addr MMIO address to read at + * @return cpu native 64-bit value + */ +uint64_t odpdrv_mmio_u64le_read(volatile void *addr); + +/** + * Read from MMIO and convert endianness + * @param addr MMIO address to read at + * @return cpu native 64-bit value + */ +uint64_t odpdrv_mmio_u64be_read(volatile void *addr); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/include/odp/drv/mmio.h b/platform/linux-generic/include/odp/drv/mmio.h new file mode 100644 index 000000000..b757a26c7 --- /dev/null +++ b/platform/linux-generic/include/odp/drv/mmio.h @@ -0,0 +1,179 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * API to access memory-mapped I/O. + */ + +#ifndef ODPDRV_PLAT_MMIO_H_ +#define ODPDRV_PLAT_MMIO_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** @ingroup odpdrv_mmio ODPDRV MMIO + * @{ + */ + +/* for use with type checkers such as sparse */ +#ifdef __CHECKER__ +/** @internal MMIO attribute */ +#define __odpdrv_mmio __attribute__((noderef, address_space(2))) +#else +/** @internal MMIO attribute */ +#define __odpdrv_mmio +#endif + +#define odpdrv_io_mb() do { __asm__ __volatile__("" ::: "memory"); } while (0) +#define odpdrv_io_rmb() do { __asm__ __volatile__("" ::: "memory"); } while (0) +#define odpdrv_io_wmb() do { __asm__ __volatile__("" ::: "memory"); } while (0) + +static inline void +odpdrv_mmio_u8le_write(uint8_t value, volatile void __odpdrv_mmio *addr) +{ + odpdrv_io_wmb(); + *(__odp_force volatile uint8_t *)addr = value; +} + +static inline void +odpdrv_mmio_u8be_write(uint8_t value, volatile void __odpdrv_mmio *addr) +{ + odpdrv_mmio_u8le_write(value, addr); +} + +static inline void +odpdrv_mmio_u16le_write(uint16_t value, volatile void __odpdrv_mmio *addr) +{ + odpdrv_io_wmb(); + *(__odp_force volatile odp_u16le_t *)addr = odp_cpu_to_le_16(value); +} + +static inline void +odpdrv_mmio_u16be_write(uint16_t value, volatile void __odpdrv_mmio *addr) +{ + odpdrv_io_wmb(); + *(__odp_force volatile odp_u16be_t *)addr = odp_cpu_to_be_16(value); +} + +static inline void +odpdrv_mmio_u32le_write(uint32_t value, volatile void __odpdrv_mmio *addr) +{ + odpdrv_io_wmb(); + *(__odp_force volatile odp_u32le_t *)addr = odp_cpu_to_le_32(value); +} + +static inline void +odpdrv_mmio_u32be_write(uint32_t value, volatile void __odpdrv_mmio *addr) +{ + odpdrv_io_wmb(); + *(__odp_force volatile odp_u32be_t *)addr = odp_cpu_to_be_32(value); +} + +static inline void +odpdrv_mmio_u64le_write(uint64_t value, volatile void __odpdrv_mmio *addr) +{ + odpdrv_io_wmb(); + *(__odp_force volatile odp_u64le_t *)addr = odp_cpu_to_le_64(value); +} + +static inline void +odpdrv_mmio_u64be_write(uint64_t value, volatile void __odpdrv_mmio *addr) +{ + odpdrv_io_wmb(); + *(__odp_force volatile odp_u64be_t *)addr = odp_cpu_to_be_64(value); +} + +static inline uint8_t +odpdrv_mmio_u8le_read(volatile void __odpdrv_mmio *addr) +{ + uint8_t value = *(__odp_force volatile uint8_t *)addr; + + odpdrv_io_rmb(); + return value; +} + +static inline uint8_t +odpdrv_mmio_u8be_read(volatile void __odpdrv_mmio *addr) +{ + return odpdrv_mmio_u8le_read(addr); +} + +static inline uint16_t +odpdrv_mmio_u16le_read(volatile void __odpdrv_mmio *addr) +{ + uint16_t value = + odp_le_to_cpu_16(*(__odp_force volatile odp_u16le_t *)addr); + + odpdrv_io_rmb(); + return value; +} + +static inline uint16_t +odpdrv_mmio_u16be_read(volatile void __odpdrv_mmio *addr) +{ + uint16_t value = + odp_be_to_cpu_16(*(__odp_force volatile odp_u16be_t *)addr); + + odpdrv_io_rmb(); + return value; +} + +static inline uint32_t +odpdrv_mmio_u32le_read(volatile void __odpdrv_mmio *addr) +{ + uint32_t value = + odp_le_to_cpu_32(*(__odp_force volatile odp_u32le_t *)addr); + + odpdrv_io_rmb(); + return value; +} + +static inline uint32_t +odpdrv_mmio_u32be_read(volatile void __odpdrv_mmio *addr) +{ + uint32_t value = + odp_be_to_cpu_32(*(__odp_force volatile odp_u32be_t *)addr); + + odpdrv_io_rmb(); + return value; +} + +static inline uint64_t +odpdrv_mmio_u64le_read(volatile void __odpdrv_mmio *addr) +{ + uint64_t value = + odp_le_to_cpu_64(*(__odp_force volatile odp_u64le_t *)addr); + + odpdrv_io_rmb(); + return value; +} + +static inline uint64_t +odpdrv_mmio_u64be_read(volatile void __odpdrv_mmio *addr) +{ + uint64_t value = + odp_be_to_cpu_64(*(__odp_force volatile odp_u64be_t *)addr); + + odpdrv_io_rmb(); + return value; +} + +/** + * @} + */ + +#include + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 16316b928..9c256e29a 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -257,6 +257,7 @@ sub hash_show_words { __kernel| __force| __iomem| + __odpdrv_mmio| __must_check| __init_refok| __kprobes|