From patchwork Fri Jan 8 20:29:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 59388 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp750167lbb; Fri, 8 Jan 2016 11:35:16 -0800 (PST) X-Received: by 10.55.78.207 with SMTP id c198mr145484691qkb.34.1452281716181; Fri, 08 Jan 2016 11:35:16 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id f129si61773820qhd.109.2016.01.08.11.35.15; Fri, 08 Jan 2016 11:35:16 -0800 (PST) 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; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id BC76D6195C; Fri, 8 Jan 2016 19:35:15 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=XIuf8IUW; dkim-adsp=none (unprotected policy); dkim-atps=neutral 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.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,T_DKIM_INVALID,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 1CBF461A23; Fri, 8 Jan 2016 19:31:50 +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 C4D9361648; Fri, 8 Jan 2016 19:31:39 +0000 (UTC) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com [209.85.217.176]) by lists.linaro.org (Postfix) with ESMTPS id D4AB761648 for ; Fri, 8 Jan 2016 19:31:36 +0000 (UTC) Received: by mail-lb0-f176.google.com with SMTP id bc4so229215154lbc.2 for ; Fri, 08 Jan 2016 11:31:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CraQEl4DdZjJtZ5f3WWxiQEBSztpuIpMKqIm69FYU7k=; b=XIuf8IUW8HXpN/n0Mczd4dFm6qFaJFVyvJywfjVsGJp37OnPkWKoR4KaYv8v/bW4hG ZWUviuAgMqveGzsg3vYhscCWBB3HkMzXGRU4EKJHT1H4VjOERIbWipMcMFIyHUwhGB0D MMrmTFZjmSKWKL5LbcHQmBRxIIXyGdBEN8M60= 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=CraQEl4DdZjJtZ5f3WWxiQEBSztpuIpMKqIm69FYU7k=; b=azD47PRO0nwmp2wUJvExQAyu3G/HWUkGYxPyOrNRx1mzXofJbUNOsce0Xl5uH4Zehq qA544jzE9vHFIQcvOkDMjQWOtWSlaJ2qLovvS32LrLeDHD8kdtInm7D8WGvxz8qA5+vZ hQmwVvgrCF+Ou5Y0+hzP667T5N+cAh2T9OQQNgP70vPmUEI0j7vm8kTvsSGmMzoniFSM 3/Jr8amTv7jbVkXtDSqPNM6euZcRfiRFYRZC2NiZMWjnSCETm76+MoxFkIMlXJhl6mLS EBDD/fIBmSfn0AMEL4KoOsVrqemnFVGVkkbfWo4U1Kzg3XshS4876h0p2py84+NKsIfD gkHw== X-Gm-Message-State: ALoCoQkTrCTSZxVaMU65b8LZnWsHfD+YgmIjeS1zwAB7W/9megDwhvmZ8V8pCTOeS+BtYwt+QMgaRyaNmrFJDgpwVCA8ZdJ99w== X-Received: by 10.112.142.70 with SMTP id ru6mr41366693lbb.51.1452281495806; Fri, 08 Jan 2016 11:31:35 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-90-46.cust.bredband2.com. [83.233.90.46]) by smtp.gmail.com with ESMTPSA id l204sm2085534lfg.49.2016.01.08.11.31.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 08 Jan 2016 11:31:35 -0800 (PST) From: Christophe Milard To: anders.roxell@linaro.org, mike.holmes@linaro.org, stuart.haslam@linaro.org, maxim.uvarov@linaro.org, bill.fischofer@linaro.org, petri.savolainen@linaro.org, edavis@broadcom.com Date: Fri, 8 Jan 2016 21:29:46 +0100 Message-Id: <1452285014-60320-4-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1452285014-60320-1-git-send-email-christophe.milard@linaro.org> References: <1452285014-60320-1-git-send-email-christophe.milard@linaro.org> Cc: lng-odp@lists.linaro.org Subject: [lng-odp] [API-NEXT RFC 03/31] linux-generix: dma: implementation 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: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Implementation (for linux generic) of the DMA descriptor and related methods. Signed-off-by: Christophe Milard --- platform/linux-generic/Makefile.am | 4 ++ platform/linux-generic/include/odp/dma.h | 36 ++++++++++ .../linux-generic/include/odp/plat/dma_types.h | 42 ++++++++++++ platform/linux-generic/include/odp_dma_internal.h | 67 +++++++++++++++++++ platform/linux-generic/odp_dma.c | 78 ++++++++++++++++++++++ 5 files changed, 227 insertions(+) create mode 100644 platform/linux-generic/include/odp/dma.h create mode 100644 platform/linux-generic/include/odp/plat/dma_types.h create mode 100644 platform/linux-generic/include/odp_dma_internal.h create mode 100644 platform/linux-generic/odp_dma.c diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 75ca703..d0938c9 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -24,6 +24,7 @@ odpinclude_HEADERS = \ $(srcdir)/include/odp/cpumask.h \ $(srcdir)/include/odp/crypto.h \ $(srcdir)/include/odp/debug.h \ + $(srcdir)/include/odp/dma.h \ $(srcdir)/include/odp/errno.h \ $(srcdir)/include/odp/event.h \ $(srcdir)/include/odp/hash.h \ @@ -63,6 +64,7 @@ odpplatinclude_HEADERS = \ $(srcdir)/include/odp/plat/classification_types.h \ $(srcdir)/include/odp/plat/cpumask_types.h \ $(srcdir)/include/odp/plat/crypto_types.h \ + $(srcdir)/include/odp/plat/dma_types.h \ $(srcdir)/include/odp/plat/event_types.h \ $(srcdir)/include/odp/plat/packet_types.h \ $(srcdir)/include/odp/plat/packet_io_types.h \ @@ -93,6 +95,7 @@ noinst_HEADERS = \ ${srcdir}/include/odp_classification_internal.h \ ${srcdir}/include/odp_crypto_internal.h \ ${srcdir}/include/odp_debug_internal.h \ + ${srcdir}/include/odp_dma_internal.h \ ${srcdir}/include/odp_forward_typedefs_internal.h \ ${srcdir}/include/odp_internal.h \ ${srcdir}/include/odp_name_table_internal.h \ @@ -122,6 +125,7 @@ __LIB__libodp_la_SOURCES = \ odp_cpumask.c \ odp_cpumask_task.c \ odp_crypto.c \ + odp_dma.c \ odp_errno.c \ odp_event.c \ odp_hash.c \ diff --git a/platform/linux-generic/include/odp/dma.h b/platform/linux-generic/include/odp/dma.h new file mode 100644 index 0000000..af7aaeb --- /dev/null +++ b/platform/linux-generic/include/odp/dma.h @@ -0,0 +1,36 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP dma interface + */ + +#include + +#ifndef ODP_PLAT_DMA_H_ +#define ODP_PLAT_DMA_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** @ingroup odp_dma + * @{ + */ + +/** + * @} + */ + +#include + +#ifdef __cplusplus +} +#endif + +#endif /* ODP_PLAT_DMA_H_ */ diff --git a/platform/linux-generic/include/odp/plat/dma_types.h b/platform/linux-generic/include/odp/plat/dma_types.h new file mode 100644 index 0000000..8f180de --- /dev/null +++ b/platform/linux-generic/include/odp/plat/dma_types.h @@ -0,0 +1,42 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP dma interface + */ + +#ifndef ODP_DMA_TYPES_H_ +#define ODP_DMA_TYPES_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +/** @addtogroup odp_dma + * @{ + */ + +/** A address usable by a DMA (i.e. either physical or iova, if iommu ) */ +typedef uint64_t odp_dma_addr_t; + +/** DMA descriptor */ +typedef ODP_HANDLE_T(odp_dma_map_t); +#define ODP_DMA_REGION_INVALID _odp_cast_scalar(odp_dma_map_t, 0) + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* ODP_DMA_TYPES_H_ */ diff --git a/platform/linux-generic/include/odp_dma_internal.h b/platform/linux-generic/include/odp_dma_internal.h new file mode 100644 index 0000000..888ef3b --- /dev/null +++ b/platform/linux-generic/include/odp_dma_internal.h @@ -0,0 +1,67 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP dma interface - implementation internal + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef ODP_DMA_INTERNAL_H_ +#define ODP_DMA_INTERNAL_H_ + +#include +#include +#include +#include +#include + +/** @addtogroup odp_dma + * @{ + */ + +/** the linux implementation of a DMA map descriptor (odp_dma_map_t) */ +typedef struct dma_map_t dma_map_t; +typedef struct dma_map_t { + /**< address (virtual, in driver user space) of the region */ + void *addr; + /**< DMA address (either physical, or IO virtual if iommu) for region */ + odp_dma_addr_t dma_addr; + /**< size of the region, in bytes */ + uint64_t size; + /**< link to next dma region, or NULL for last */ + dma_map_t *next; +} dma_map_t; + +/** + * Returns a pointer to a linux DMA map descriptor from the related ODP + * handle. + */ +static inline dma_map_t *dma_map_handle_to_map(odp_dma_map_t map_hdl) +{ + return (dma_map_t *)map_hdl; +} + +/** + * Allocate a (not filled) DMA map structure. + */ +dma_map_t *_odp_dma_map_alloc(void); + +/** + * Link two DMA map descriptors (hence describing a scattered area) + * returns a pointer to the second structure (map2). + */ +dma_map_t *_odp_dma_map_link(dma_map_t *map1, dma_map_t *map2); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/odp_dma.c b/platform/linux-generic/odp_dma.c new file mode 100644 index 0000000..513e46f --- /dev/null +++ b/platform/linux-generic/odp_dma.c @@ -0,0 +1,78 @@ +/* Copyright (c) 2015, Linaro Limited + * Copyright (c) 2015, Nokia Solutions and Networks + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include +#include + +/* operations on DMA map descriptors: */ + +/* + * allocate a single DMA region descriptor + */ +dma_map_t *_odp_dma_map_alloc(void) +{ + dma_map_t *dma_map = malloc(sizeof(dma_map_t)); + + if (!(dma_map)) + return NULL; + dma_map->next = NULL; + return dma_map; +} + +/* + * extend a DMA region descriptor list (link map2 to map1) + */ +dma_map_t *_odp_dma_map_link(dma_map_t *map1, dma_map_t *map2) +{ + if (odp_unlikely(map2 == NULL)) + return NULL; + + if (odp_unlikely(map1 == NULL)) + return map2; /*first of a chain */ + + map1->next = map2; + + return map2; +} + +void *odp_dma_map_get_addr(odp_dma_map_t map) +{ + return dma_map_handle_to_map(map)->addr; +} + +odp_dma_addr_t odp_dma_map_get_dma_addr(odp_dma_map_t map) +{ + return dma_map_handle_to_map(map)->dma_addr; +} + +int odp_dma_map_get_size(odp_dma_map_t map) +{ + return dma_map_handle_to_map(map)->size; +} + +odp_dma_map_t odp_dma_map_get_next(odp_dma_map_t map) +{ + dma_map_t *map_s = dma_map_handle_to_map(map)->next; + + if (map_s) + return (odp_dma_map_t)map_s; + else + return ODP_DMA_REGION_INVALID; +} + +void odp_dma_map_free(odp_dma_map_t map) +{ + dma_map_t *next; + dma_map_t *map_s = dma_map_handle_to_map(map); + + do { + next = map_s->next; + free(map); + } while (next != NULL); +}