From patchwork Wed Nov 7 00:32:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 150355 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4548134ljp; Tue, 6 Nov 2018 16:33:13 -0800 (PST) X-Google-Smtp-Source: AJdET5dV+kDroN0F3tlI0D3s+aw7VWLJhe+zZMX+Sj5P0XKJSM+31p334SkhCfosCRxlApQT37d4 X-Received: by 2002:a17:902:684e:: with SMTP id f14-v6mr10266119pln.242.1541550793039; Tue, 06 Nov 2018 16:33:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541550793; cv=none; d=google.com; s=arc-20160816; b=Sn33lJHcyKw8W6BwdQQep5yk5cSmAS6KJzrG7fNjOrQ2BH1z6BSqsOgos5J7T8p4W/ 4UAPhQkfhZVBxC2zzVIIWFvCawTMZ1SLe0DyYGL7gowDuvxq3SpJXD7d444ffDXexb3J 3zdsbU0WwKrmyW/xj+Gh2unD93mLKw2fwgXcb+6dXkMyc71+YZHaOfbSBXb+VK1t0nwY D1P5azupN4j+mftnegkQxrPRCjNhAU+wQLoykzQhkej66pei+1E9WysavU/yQeEK70qY wVZZhvBXFR9HBUlqUv8jDTdgZENVsfGW6QtQF/WJ+LnVJOOfNd3tfsJuwlHKRH04rxKX yLUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=mChNx9VPrLoj/ohW2Qed5LeAGe8qnQ1vrW73K+GOCFs=; b=wy9vxgTqr5Z9sDHVCI8r9+tbzXz6vhBIHQJzgqamec6jdLGXiYO4hbOySK+NxwfzBO zTwVheT0n+pOLigJpEomtpqX45O0BTqf9ythCoT+4L0GzyCuhbw3/Bu3MH2NH+MVlNfE lqzO17sR17Uv76TeYj8YLyF8RqaKkRP83MpRAUXaBakYFfMloqMsO6BoFAWsIeAjvL25 uQdGCm+jVnMmcQUuMGEYSQxk/slaPNJa1aP5Q47yjYbCc3KiM1t79Xd3pYHB+yFHj4w4 YkeSHYO8/N4hQDXdBz3It5D2BjXSVI/v5uwjXtkQmL1whnpWlqX6uEIU3zbK4qElbgZo 65HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=f2IYf7Ra; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p20-v6si24720344plq.379.2018.11.06.16.33.12; Tue, 06 Nov 2018 16:33:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=f2IYf7Ra; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388954AbeKGKBE (ORCPT + 32 others); Wed, 7 Nov 2018 05:01:04 -0500 Received: from mail-it1-f193.google.com ([209.85.166.193]:34900 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388888AbeKGKBD (ORCPT ); Wed, 7 Nov 2018 05:01:03 -0500 Received: by mail-it1-f193.google.com with SMTP id v11so14309411itj.0 for ; Tue, 06 Nov 2018 16:33:09 -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=mChNx9VPrLoj/ohW2Qed5LeAGe8qnQ1vrW73K+GOCFs=; b=f2IYf7Ra+LGI0tRtEQXE1i/zvFYB5PcP6cP0XaOJJoYU3TIQD5yu68p7FJ+FIftxEE BI4Y+iL5A7iSOtflBBDOu/YRZ6HidRJJS/jB5LmZw0Gfqz9EwAa4Loqzq44Gc2IdwZp7 TjG7nYw0kDn1vb4IfZXPMC7V/JSDzCNp2EHe4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mChNx9VPrLoj/ohW2Qed5LeAGe8qnQ1vrW73K+GOCFs=; b=oRBWj5GtshQ9dRQ94BCO5iug4srsUURhBiCO9EK1uOmLSATq8BEQjXL2JvA4MiBxwA AMf2PCj9up1YWQlltk9++gBFSPCcu0N3LsqO0VCz7zPLsbGS9PUriSa+uLEElBttN8kj RuJrRiAWejzlz8j3Yc0Ti+bHo2wU5n4zi0lqRC2B6kc83wgVaxm9mMsn53Sn7FUfbjU2 smWDqjBRAEIp2VDMl39V+zEeML351qlewZrFbJs8O7WhodA2p4sPjxln/B0IEhW5LaW2 mPL77bmiwivBC0CpyavrI7TUR+pRjmEBvFicXEoSfgirdTApwactt4bnU4y+YyJ3I3p1 XSpw== X-Gm-Message-State: AGRZ1gKzUQ+1O2ga9xwITgILQqNFJT1QFeiPdavKopCtULwrtX905pya Etebd/yMSM+6QsabTxBIa/cfvg== X-Received: by 2002:a24:4a95:: with SMTP id k143-v6mr117987itb.132.1541550788960; Tue, 06 Nov 2018 16:33:08 -0800 (PST) Received: from shibby.gateway.innflux.com ([66.228.239.218]) by smtp.gmail.com with ESMTPSA id e184-v6sm1061128ite.9.2018.11.06.16.33.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Nov 2018 16:33:08 -0800 (PST) From: Alex Elder To: davem@davemloft.net, arnd@arndb.de, bjorn.andersson@linaro.org, ilias.apalodimas@linaro.org Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, syadagir@codeaurora.org, mjavid@codeaurora.org, robh+dt@kernel.org, mark.rutland@arm.com Subject: [RFC PATCH 02/12] soc: qcom: ipa: DMA helpers Date: Tue, 6 Nov 2018 18:32:40 -0600 Message-Id: <20181107003250.5832-3-elder@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181107003250.5832-1-elder@linaro.org> References: <20181107003250.5832-1-elder@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch includes code implementing the IPA DMA module, which defines a structure to represent a DMA allocation for the IPA device. It's used throughout the IPA code. Signed-off-by: Alex Elder --- drivers/net/ipa/ipa_dma.c | 61 +++++++++++++++++++++++++++++++++++++++ drivers/net/ipa/ipa_dma.h | 61 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 drivers/net/ipa/ipa_dma.c create mode 100644 drivers/net/ipa/ipa_dma.h -- 2.17.1 diff --git a/drivers/net/ipa/ipa_dma.c b/drivers/net/ipa/ipa_dma.c new file mode 100644 index 000000000000..dfde59e5072a --- /dev/null +++ b/drivers/net/ipa/ipa_dma.c @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Copyright (c) 2018, The Linux Foundation. All rights reserved. + * Copyright (C) 2018 Linaro Ltd. + */ + +#include +#include +#include +#include + +#include "ipa_dma.h" + +static struct device *ipa_dma_dev; + +int ipa_dma_init(struct device *dev, u32 align) +{ + int ret; + + /* Ensure DMA addresses will have the alignment we require */ + if (dma_get_cache_alignment() % align) + return -ENOTSUPP; + + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); + if (!ret) + ipa_dma_dev = dev; + + return ret; +} + +void ipa_dma_exit(void) +{ + ipa_dma_dev = NULL; +} + +int ipa_dma_alloc(struct ipa_dma_mem *mem, size_t size, gfp_t gfp) +{ + dma_addr_t phys; + void *virt; + + virt = dma_zalloc_coherent(ipa_dma_dev, size, &phys, gfp); + if (!virt) + return -ENOMEM; + + mem->virt = virt; + mem->phys = phys; + mem->size = size; + + return 0; +} + +void ipa_dma_free(struct ipa_dma_mem *mem) +{ + dma_free_coherent(ipa_dma_dev, mem->size, mem->virt, mem->phys); + memset(mem, 0, sizeof(*mem)); +} + +void *ipa_dma_phys_to_virt(struct ipa_dma_mem *mem, dma_addr_t phys) +{ + return mem->virt + (phys - mem->phys); +} diff --git a/drivers/net/ipa/ipa_dma.h b/drivers/net/ipa/ipa_dma.h new file mode 100644 index 000000000000..e211dbd9d4ec --- /dev/null +++ b/drivers/net/ipa/ipa_dma.h @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Copyright (c) 2018, The Linux Foundation. All rights reserved. + * Copyright (C) 2018 Linaro Ltd. + */ +#ifndef _IPA_DMA_H_ +#define _IPA_DMA_H_ + +#include +#include + +/** + * struct ipa_dma_mem - IPA allocated DMA memory descriptor + * @virt: host virtual base address of allocated DMA memory + * @phys: bus physical base address of DMA memory + * @size: size (bytes) of DMA memory + */ +struct ipa_dma_mem { + void *virt; + dma_addr_t phys; + size_t size; +}; + +/** + * ipa_dma_init() - Initialize IPA DMA system. + * @dev: IPA device structure + * @align: Hardware required alignment for DMA memory + * + * Returns: 0 if successful, or a negative error code. + */ +int ipa_dma_init(struct device *dev, u32 align); + +/** + * ipa_dma_exit() - shut down/clean up IPA DMA system + */ +void ipa_dma_exit(void); + +/** + * ipa_dma_alloc() - allocate a DMA buffer, describe it in mem struct + * @mem: Memory structure to fill with allocation information. + * @size: Size of DMA buffer to allocate. + * @gfp: Allocation mode. + */ +int ipa_dma_alloc(struct ipa_dma_mem *mem, size_t size, gfp_t gfp); + +/** + * ipa_dma_free() - free a previously-allocated DMA buffer + * @mem: Information about DMA allocation to free + */ +void ipa_dma_free(struct ipa_dma_mem *mem); + +/** + * ipa_dma_phys_to_virt() - return the virtual equivalent of a DMA address + * @phys: DMA allocation information + * @phys: Physical address to convert + * + * Return: Virtual address corresponding to the given physical address + */ +void *ipa_dma_phys_to_virt(struct ipa_dma_mem *mem, dma_addr_t phys); + +#endif /* !_IPA_DMA_H_ */