From patchwork Tue Mar 10 15:31:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taras Kondratiuk X-Patchwork-Id: 45589 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DCD66214BF for ; Tue, 10 Mar 2015 15:32:21 +0000 (UTC) Received: by labgm9 with SMTP id gm9sf2068331lab.1 for ; Tue, 10 Mar 2015 08:32:20 -0700 (PDT) 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:cc: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=HubkI292g+fZgS5xsWrEBwH7xBa7H9x++kRDIujdnCc=; b=VokVRlfXj/INFb6JvhvbWG6o46EwErAADI1Bzecof9PQ1G0eBB7i4+mD1WFEpnITZk y6QNDsV9y1ZCAOYENMsNrhdLI0n8vm4r9y0WA0IG07i0UipmqfXDeNezguu/jliXWRoQ YHl0PHLzsv4x7n4j2tsbu1WXaoN67uCViMoiY5KGQl8vZ4aNWDtnz5qW6vLAaUUcxs1u iU21DaqtuH5n4qTLtKFeSZTtsToGwHXMX93nL/L6Y2QzA3kWma3zO4jxtQWnKavti4Ju X7oAe0vLopTWAaRcbg7DxC54l9+EAFK+6jYN7enCjbThxen54bTKUGVesANrhFDRD0Bn HrCg== X-Gm-Message-State: ALoCoQmDnFNHNztFmzazAQ4CrGbss19Q7T3+WYiDrMOMDeSlfRYRXMZ83pkxPL3UFu+ugHHLUdl6 X-Received: by 10.152.6.41 with SMTP id x9mr4792845lax.10.1426001540710; Tue, 10 Mar 2015 08:32:20 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.197.97 with SMTP id it1ls45743lac.1.gmail; Tue, 10 Mar 2015 08:32:20 -0700 (PDT) X-Received: by 10.152.26.136 with SMTP id l8mr31067278lag.109.1426001540429; Tue, 10 Mar 2015 08:32:20 -0700 (PDT) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id wh2si587803lbb.41.2015.03.10.08.32.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Mar 2015 08:32:20 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by lbiz12 with SMTP id z12so2520111lbi.12 for ; Tue, 10 Mar 2015 08:32:20 -0700 (PDT) X-Received: by 10.112.130.39 with SMTP id ob7mr31881355lbb.32.1426001540210; Tue, 10 Mar 2015 08:32:20 -0700 (PDT) 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 h5csp2206885lbj; Tue, 10 Mar 2015 08:32:19 -0700 (PDT) X-Received: by 10.140.146.68 with SMTP id 65mr26295377qhs.101.1426001535982; Tue, 10 Mar 2015 08:32:15 -0700 (PDT) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id t5si753591qgd.84.2015.03.10.08.32.14 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 10 Mar 2015 08:32:15 -0700 (PDT) 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 1YVM8i-0003vZ-Tf; Tue, 10 Mar 2015 15:32:12 +0000 Received: from mail-lb0-f172.google.com ([209.85.217.172]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YVM85-0003pC-H4 for lng-odp@lists.linaro.org; Tue, 10 Mar 2015 15:31:33 +0000 Received: by lbjf15 with SMTP id f15so2594364lbj.2 for ; Tue, 10 Mar 2015 08:31:27 -0700 (PDT) X-Received: by 10.152.36.226 with SMTP id t2mr29361360laj.53.1426001487867; Tue, 10 Mar 2015 08:31:27 -0700 (PDT) Received: from uglx0153363.synapse.com ([195.238.92.128]) by mx.google.com with ESMTPSA id a2sm106609lbm.32.2015.03.10.08.31.27 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Mar 2015 08:31:27 -0700 (PDT) From: Taras Kondratiuk To: lng-odp@lists.linaro.org Date: Tue, 10 Mar 2015 17:31:06 +0200 Message-Id: <1426001473-14618-9-git-send-email-taras.kondratiuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1426001473-14618-1-git-send-email-taras.kondratiuk@linaro.org> References: <1426001473-14618-1-git-send-email-taras.kondratiuk@linaro.org> X-Topics: patch Cc: Taras Kondratiuk Subject: [lng-odp] [KEYSTONE2 PATCH 08/15] linux-ks2: plat: add abstraction layer for CPPI 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: taras.kondratiuk@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.217.172 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: Taras Kondratiuk Signed-off-by: Taras Kondratiuk --- platform/linux-keystone2/Makefile.am | 1 + platform/linux-keystone2/include/odp/plat/osal.h | 310 +++++++++++++++++++++++ 2 files changed, 311 insertions(+) create mode 100644 platform/linux-keystone2/include/odp/plat/osal.h diff --git a/platform/linux-keystone2/Makefile.am b/platform/linux-keystone2/Makefile.am index a6ee070..296062b 100644 --- a/platform/linux-keystone2/Makefile.am +++ b/platform/linux-keystone2/Makefile.am @@ -61,6 +61,7 @@ odpplatinclude_HEADERS = \ $(srcdir)/include/odp/plat/align.h \ $(srcdir)/include/odp/plat/debug.h \ $(srcdir)/include/odp/plat/mcsdk_tune.h \ + $(srcdir)/include/odp/plat/osal.h \ $(srcdir)/include/odp/plat/state.h \ $(srcdir)/include/odp/plat/ti_mcsdk.h \ $(linux_generic_srcdir)/include/odp/plat/atomic_types.h \ diff --git a/platform/linux-keystone2/include/odp/plat/osal.h b/platform/linux-keystone2/include/odp/plat/osal.h new file mode 100644 index 0000000..05704e9 --- /dev/null +++ b/platform/linux-keystone2/include/odp/plat/osal.h @@ -0,0 +1,310 @@ +/* + * Copyright (c) 2014, Linaro Limited + * Copyright (c) 2014, Texas Instruments Incorporated + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_PLAT_OSAL_H_ +#define ODP_PLAT_OSAL_H_ + +#include +#include + +typedef uintptr_t odp_pa_t; + +static inline odp_pa_t _odp_mem_virt_to_phys(void *virt) +{ + odp_pa_t phys = (odp_pa_t)hplib_mVMVirtToPhy(virt); + ODP_ASSERT(virt ? !!phys : !phys, "Failed virt to phys conversion"); + return phys; +} + +static inline void *_odp_mem_phys_to_virt(odp_pa_t phys) +{ + void *virt = hplib_mVMPhyToVirt((void *)phys); + ODP_ASSERT(phys ? !!virt : !virt, "Failed phys to virt conversion"); + return hplib_mVMPhyToVirt((void *)phys); +} + +#ifdef ODP_DEBUG +static inline void _odp_mem_verify_phys(odp_pa_t phys) +{ + void *virt = hplib_mVMPhyToVirt((void *)phys); + ODP_ASSERT(phys ? !!virt : !virt, "Wrong physical address"); +} + +static inline void _odp_mem_verify_virt(void *virt) +{ + odp_pa_t phys = (odp_pa_t)hplib_mVMVirtToPhy(virt); + ODP_ASSERT(virt ? !!phys : !phys, "Wrong virtual address"); +} +#else +static inline void _odp_mem_verify_phys(odp_pa_t phys) {}; +static inline void _odp_mem_verify_virt(void *virt) {}; +#endif + +/* + * Original buffer info + */ +static inline void _cppi_desc_orig_info(Cppi_HostDesc *desc, + odp_pa_t *buf_addr, + uint32_t *buf_len) +{ + Cppi_getOriginalBufInfo(Cppi_DescType_HOST, + (Cppi_Desc *)desc, + (uint8_t **)buf_addr, + buf_len); +} + +static inline void _cppi_desc_orig_info_set(Cppi_HostDesc *desc, + odp_pa_t buf_addr, + uint32_t buf_len) +{ + Cppi_setOriginalBufInfo(Cppi_DescType_HOST, + (Cppi_Desc *)desc, + (void *)buf_addr, + buf_len); +} + +/** Read original buffer pointer. Assume physical address is read. */ +static inline odp_pa_t _cppi_desc_orig_ptr(Cppi_HostDesc *desc) +{ + odp_pa_t buf_addr = desc->origBuffPtr; + _odp_mem_verify_phys(buf_addr); + return buf_addr; +} + +/** Set original buffer pointer. Assume physical address is stored. */ +static inline void _cppi_desc_orig_ptr_set(Cppi_HostDesc *desc, + odp_pa_t buf_addr) +{ + _odp_mem_verify_phys(buf_addr); + desc->origBuffPtr = (uint32_t)buf_addr; +} + +/** Read buffer pointer. Assume virtual address is read. */ +static inline uint8_t *_cppi_desc_orig_vptr(Cppi_HostDesc *desc) +{ + uint8_t *buf_addr = (uint8_t *)desc->origBuffPtr; + _odp_mem_verify_virt(buf_addr); + return buf_addr; +} + +/** Set buffer pointer. Assume virtual address is stored. */ +static inline void _cppi_desc_orig_vptr_set(Cppi_HostDesc *desc, + void *buf_addr) +{ + _odp_mem_verify_virt(buf_addr); + desc->origBuffPtr = (uint32_t)buf_addr; +} + +static inline uint32_t _cppi_desc_orig_len(Cppi_HostDesc *desc) +{ + return CSL_FEXTR(desc->origBufferLen, 21, 0); +} + +static inline void _cppi_desc_orig_len_set(Cppi_HostDesc *desc, + uint32_t buf_len) +{ + CSL_FINSR(desc->origBufferLen, 21, 0, buf_len); +} + + +/* + * Current buffer info + */ +static inline void _cppi_desc_buf_info_set(Cppi_HostDesc *desc, + odp_pa_t buf_addr, + uint32_t buf_size) +{ + Cppi_setData(Cppi_DescType_HOST, + (Cppi_Desc *)desc, + (uint8_t *)buf_addr, + buf_size); +} + +/** Read buffer pointer. Assume physical address is read. */ +static inline odp_pa_t _cppi_desc_buf_ptr(Cppi_HostDesc *desc) +{ + odp_pa_t buf_addr = desc->buffPtr; + _odp_mem_verify_phys(buf_addr); + return buf_addr; +} + +/** Set buffer pointer. Assume physical address is stored. */ +static inline void _cppi_desc_buf_ptr_set(Cppi_HostDesc *desc, + odp_pa_t buf_addr) +{ + _odp_mem_verify_phys(buf_addr); + desc->buffPtr = buf_addr; +} + +/** Read buffer pointer. Assume virtual address is read. */ +static inline uint8_t *_cppi_desc_buf_vptr(Cppi_HostDesc *desc) +{ + uint8_t *buf_addr = (uint8_t *)desc->buffPtr; + _odp_mem_verify_virt(buf_addr); + return buf_addr; +} + +/** Set buffer pointer. Assume virtual address is stored. */ +static inline void _cppi_desc_buf_vptr_set(Cppi_HostDesc *desc, + uint8_t *buf_addr) +{ + _odp_mem_verify_virt(buf_addr); + ODP_ASSERT(_odp_mem_virt_to_phys(buf_addr) != 0, + "Not a correct virtual address"); + desc->buffPtr = (uint32_t)buf_addr; +} + +static inline uint32_t _cppi_desc_buf_len(Cppi_HostDesc *desc) +{ + return desc->buffLen; +} + +static inline void _cppi_desc_buf_len_set(Cppi_HostDesc *desc, + uint32_t buf_len) +{ + desc->buffLen = buf_len; +} + + +/* + * Packet info + */ +static inline uint32_t _cppi_desc_pkt_len(Cppi_HostDesc *desc) +{ + return Cppi_getPacketLen(Cppi_DescType_HOST, (Cppi_Desc *)desc); +} + +static inline void _cppi_desc_pkt_len_set(Cppi_HostDesc *desc, + uint32_t pktlen) +{ + Cppi_setPacketLen(Cppi_DescType_HOST, (Cppi_Desc *)desc, pktlen); +} + +static inline odp_pa_t _cppi_desc_next(Cppi_HostDesc *desc) +{ + odp_pa_t next_desc = (odp_pa_t)Cppi_getNextBD(Cppi_DescType_HOST, + (Cppi_Desc *)desc); + _odp_mem_verify_phys(next_desc); + return next_desc; +} + +static inline Cppi_HostDesc *_cppi_desc_vnext(Cppi_HostDesc *desc) +{ + Cppi_HostDesc *next_desc = (Cppi_HostDesc *) + Cppi_getNextBD(Cppi_DescType_HOST, (Cppi_Desc *)desc); + _odp_mem_verify_virt(next_desc); + return next_desc; +} + +static inline void _cppi_desc_next_set(Cppi_HostDesc *desc, + odp_pa_t next_desc) +{ + _odp_mem_verify_phys(next_desc); + Cppi_linkNextBD(Cppi_DescType_HOST, (Cppi_Desc *)desc, + (Cppi_Desc *)next_desc); +} + +static inline void _cppi_desc_vnext_set(Cppi_HostDesc *desc, + Cppi_HostDesc *next_desc) +{ + _odp_mem_verify_virt(next_desc); + Cppi_linkNextBD(Cppi_DescType_HOST, (Cppi_Desc *)desc, + (Cppi_Desc *)next_desc); +} +/* + * Metadata in CPPI descriptor + */ +static inline void _cppi_desc_pool_id_set(Cppi_HostDesc *desc, uint8_t pool_id) +{ + Cppi_setOrigBufferpooIndex(Cppi_DescType_HOST, + (Cppi_Desc *)desc, pool_id); +} + +static inline uint8_t _cppi_desc_pool_id(Cppi_HostDesc *desc) +{ + return Cppi_getOrigBufferpooIndex(Cppi_DescType_HOST, + (Cppi_Desc *)desc); +} + +static inline void _cppi_desc_pkt_type_set(Cppi_HostDesc *desc, uint8_t type) +{ + Cppi_setPacketType(Cppi_DescType_HOST, (Cppi_Desc *)desc, type); +} + +static inline uint8_t _cppi_desc_pkt_type(Cppi_HostDesc *desc) +{ + return Cppi_getPacketType(Cppi_DescType_HOST, (Cppi_Desc *)desc); +} + +/* + * Helpers + */ +static inline uint32_t _cppi_desc_orig_len_total(Cppi_HostDesc *desc) +{ + uint32_t len = 0; + while (desc) { + len += _cppi_desc_orig_len(desc); + desc = _cppi_desc_vnext(desc); + } + return len; +} + +static inline uint32_t _cppi_desc_num_bufs(Cppi_HostDesc *desc) +{ + uint32_t num = 0; + while (desc) { + num++; + desc = _cppi_desc_vnext(desc); + } + return num; +} + +static inline Cppi_HostDesc *_cppi_desc_last(Cppi_HostDesc *desc) +{ + while (_cppi_desc_vnext(desc)) + desc = _cppi_desc_vnext(desc); + return desc; +} + +static inline uint8_t *_cppi_desc_orig_end(Cppi_HostDesc *desc) +{ + return _cppi_desc_orig_vptr(desc) + _cppi_desc_orig_len(desc); +} + +static inline uint8_t *_cppi_desc_buf_end(Cppi_HostDesc *desc) +{ + return _cppi_desc_buf_vptr(desc) + _cppi_desc_buf_len(desc); +} + +/* Returns descriptor which contains data offset */ +static inline +Cppi_HostDesc *_cppi_desc_offset(Cppi_HostDesc *desc, uint32_t *offset) +{ + uint32_t data_len = _cppi_desc_buf_len(desc); + uint32_t off = *offset; + + while (off >= data_len) { + off -= data_len; + desc = _cppi_desc_vnext(desc); + ODP_ASSERT(desc, "Not enough descriptors"); + data_len = _cppi_desc_buf_len(desc); + } + + *offset = off; + return desc; +} + +static inline void _cppi_desc_shift_vptr(Cppi_HostDesc *desc, int32_t offset) +{ + _cppi_desc_buf_vptr_set(desc, _cppi_desc_buf_vptr(desc) + offset); + _cppi_desc_buf_len_set(desc, _cppi_desc_buf_len(desc) - offset); + _cppi_desc_pkt_len_set(desc, _cppi_desc_pkt_len(desc) - offset); +} + + +#endif /* ODP_TI_MCSDK_H_ */