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: 10671631 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0C5151709 for ; Wed, 7 Nov 2018 00:33:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF8312B47B for ; Wed, 7 Nov 2018 00:33:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3BFD2B493; Wed, 7 Nov 2018 00:33:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 87FF22B47B for ; Wed, 7 Nov 2018 00:33:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=hdPl6SnAHSm7122ZbI3zAPEvY+mMJC/Xk6yDP5niL84=; b=ABPZa0u2I6rPhRAcFcJykdGPrv o4mJbsvisIrppiFx/ax1TmQr4lklbQ/D7MSiTKzWxBw3l6DF+i5UBK2fek7bfBZPashbshqzQWTwQ s/mC9UYXTTjNEcg2Fy4Yr71x+JPzOCgAf1BBFHLCQtO9n8hv8mv66dMaI1G4KsM5vwiLYhG5iCppM PpxULbtcPs5e3mV+7Mo37oITv9NHgYagdYeTEvV2n5XDKAEMIe64fFkq5WwBAQnLS5A6RAGDDYcjC UdMHxhJQmfeOb4s6PhIO22iakbFi9LAaE+hQJxm68N19tOHR7Yu8v6h2d2GiVXokDxPCdnKjkZMJF 7yUIqvgQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gKBn6-0000G4-Cn; Wed, 07 Nov 2018 00:33:52 +0000 Received: from mail-it1-x142.google.com ([2607:f8b0:4864:20::142]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gKBma-00082q-3W for linux-arm-kernel@lists.infradead.org; Wed, 07 Nov 2018 00:33:22 +0000 Received: by mail-it1-x142.google.com with SMTP id p11-v6so11753658itf.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=OQNqHFKm8k9tqxA96s0+3nmj1VSsB9mlBVPJjU8SNPtVcTJb3aqss99Yb105X1aDkI sOoNft/gvUDTfurE9CaWiVn/3cc5j2C0s/vSPBHC7ffz6lcrsqgizhT1jkTHQIHU6Fls i7tr1UfNv7V2iFlK/kWCIJEec+nAQ49+Me02t98z74AtjJrfHSV6Jk+7mGQsUj5K9cB8 LlDt72u+NT3GhEHuvbd/mvf3ZhB8q+mi8a8NNSXubfR9v2+C2P8yU8/KzybukMChcF/T dSVcumrUBbMiG5HcXtTKt5NKLpnkxvOUC0pYfDJsYWgIQ3ImIFMbhz3CYGTh3eOydSsl OHPg== X-Gm-Message-State: AGRZ1gKMAHyoC+WWL4ndKGFIBIdyO3jWEu68BgRm/dXZMQsQJ3WP1Ky/ fuhS+DqeAMzI2CGh2OAy16Vcpg== X-Google-Smtp-Source: AJdET5fc96+Vvpxcaxjsyi6rLtBcRzz7GokxwEQ2SeDLr5Pay1oBKGGI8r1HlytuVfQSsqvCDEDUfA== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181106_163320_146143_E5D0F797 X-CRM114-Status: GOOD ( 16.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, syadagir@codeaurora.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, robh+dt@kernel.org, linux-arm-msm@vger.kernel.org, mjavid@codeaurora.org, linux-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 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_ */