From patchwork Fri Mar 21 19:09:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Th=C3=A9o_Lebrun?= X-Patchwork-Id: 14025947 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 20977C36000 for ; Fri, 21 Mar 2025 19:14:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9DcIRgoMgfykUTine+K9KJLvPqRDRopD8Tbclq+UFLs=; b=rq4OcLmMre0bx+ kUJD+ADMqoKLZld46H1lQphTxLhf9K8oww5Zp+EogRD84ZZpVZrXsXbQjZvbchAHPycU1nCT2MIt7 kNgG8G9uaCcIRQVQaFnhFh6BOlya7QGPCXMNLb5iCcb5lAigqNeyrrmvz8TmAYLDMKrZALAgTUbOM WCaAn6WQm9wwP7Mh/Q3DZLs0yWAhq+zB/m6g26JJBVXZQr3dSxcI+dcozCBS7iOjzhmDUgqsTrxq5 aFkvaqwu6jPMru5BsDuXO+sTobOD6fVzNdzmGdp0jqhQ1fQ61cyjGW202fHAMSc8b64xELR6CaxqP WhQFMRZH8/jthXAP2qPw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tvhpC-0000000FzUu-2lWh; Fri, 21 Mar 2025 19:14:34 +0000 Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tvhos-0000000FzNf-3puN for linux-riscv@lists.infradead.org; Fri, 21 Mar 2025 19:14:16 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id EEF1144556; Fri, 21 Mar 2025 19:14:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1742584453; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZxMXQ8+TQxJ1/iSCHV+R2mBv/BVVSKHckDX7uY0hwe0=; b=lqKhGEh9fwsVTezNpVpcsMWOr21wObSDgaEKTxugDByXwco09sUs7wkuUf6snZJdNkWxoM Pp+hzcz6MZidPk3+0m7ar1Lnup98wk474Qn5o+ARpHXGOJXZfXAuihbCaMS2kjerdV8kUt x+ps3ofIyqPQT3bkXxhXJOJn4ngb1ZuCKYF7aT1qEvp6aMjOo3ggpHRPoNT7hhJpYCB9pQ 9+6PNXhtF4Pcr1P08M7wUDsZmfkaYyBIWK6Dsf5BMjueoQh/krNwKFvj0dZq8z1xiE3+MP aza7F0kT16z6fV+AweepQnOrc8VgUGdR046brxDMOTgAIhzs03nHYQb9uH7xPg== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Fri, 21 Mar 2025 20:09:42 +0100 Subject: [PATCH net-next 11/13] MIPS: mobileye: add EyeQ5 DMA IOCU support MIME-Version: 1.0 Message-Id: <20250321-macb-v1-11-537b7e37971d@bootlin.com> References: <20250321-macb-v1-0-537b7e37971d@bootlin.com> In-Reply-To: <20250321-macb-v1-0-537b7e37971d@bootlin.com> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nicolas Ferre , Claudiu Beznea , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Samuel Holland , Richard Cochran , Russell King , Thomas Bogendoerfer , Vladimir Kondratiev , Gregory CLEMENT Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-mips@vger.kernel.org, Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.14.2 X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduheduledtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthekredtredtjeenucfhrhhomhepvfhhrohoucfnvggsrhhunhcuoehthhgvohdrlhgvsghruhhnsegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeelvefhkeeufedvkefghefhgfdukeejlefgtdehtdeivddtteetgedvieelieeuhfenucfkphepjeejrddufeehrdekuddrieehnecuvehluhhsthgvrhfuihiivgepkeenucfrrghrrghmpehinhgvthepjeejrddufeehrdekuddrieehpdhhvghloheplgduledvrdduieekrddurdeftdgnpdhmrghilhhfrhhomhepthhhvghordhlvggsrhhunhessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvdekpdhrtghpthhtohepghhrvghgohhrhidrtghlvghmvghnthessghoohhtlhhinhdrtghomhdprhgtphhtthhopehlihhnuhigqdhrihhstghvsehlihhsthhsrdhinhhfrhgruggvrggurdhorhhgpdhrtghpthhtohepphgruhhlrdifrghlmhhslhgvhiesshhifhhivhgvrdgtohhmpdhrtghpthhtohepthhssghoghgvnhgusegrlhhphhgrrdhfrhgrnhhkvghnrdguvgdprhgtphhtthhopehkuhgsrgesk hgvrhhnvghlrdhorhhgpdhrtghpthhtohepnhgvthguvghvsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepnhhitgholhgrshdrfhgvrhhrvgesmhhitghrohgthhhiphdrtghomhdprhgtphhtthhopehthhhomhgrshdrphgvthgriiiiohhnihessghoohhtlhhinhdrtghomh X-GND-Sasl: theo.lebrun@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250321_121415_214586_3F89B652 X-CRM114-Status: GOOD ( 17.58 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Both Cadence GEM Ethernet controllers on EyeQ5 are hardwired through CM3 IO Coherency Units (IOCU). For DMA coherent accesses, BIT(36) must be set in DMA addresses. Implement that in platform-specific dma_map_ops which get attached to both instances of `cdns,eyeq5-gem` through a notifier block. Signed-off-by: Théo Lebrun --- MAINTAINERS | 2 +- arch/mips/mobileye/Kconfig | 1 + arch/mips/mobileye/Makefile | 2 + arch/mips/mobileye/eyeq5-iocu-dma.c | 160 ++++++++++++++++++++++++++++++++++++ 4 files changed, 164 insertions(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index 5959513a7359f46e10d91bafd5a736b8dceeb7c5..a943f88fc8d4ffe502479e3cd5de6d1a2b1e1fc0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -15975,7 +15975,7 @@ F: Documentation/devicetree/bindings/mips/mobileye.yaml F: Documentation/devicetree/bindings/soc/mobileye/ F: arch/mips/boot/dts/mobileye/ F: arch/mips/configs/eyeq5_defconfig -F: arch/mips/mobileye/board-epm5.its.S +F: arch/mips/mobileye/ F: drivers/clk/clk-eyeq.c F: drivers/pinctrl/pinctrl-eyeq5.c F: drivers/reset/reset-eyeq.c diff --git a/arch/mips/mobileye/Kconfig b/arch/mips/mobileye/Kconfig index f9abb2d6e1787dbc5a173db48606ed5a02088e41..b9040f3a9b3ddc7f5addcd8e5f110cb9c775b6b1 100644 --- a/arch/mips/mobileye/Kconfig +++ b/arch/mips/mobileye/Kconfig @@ -9,6 +9,7 @@ choice config MACH_EYEQ5 bool "Mobileye EyeQ5 SoC" + select ARCH_HAS_DMA_OPS config MACH_EYEQ6H bool "Mobileye EyeQ6H SoC" diff --git a/arch/mips/mobileye/Makefile b/arch/mips/mobileye/Makefile index 315c06b689cfbb83f9f205d1140ecf5058e2aa02..50fc7d0ae167c3fb3dc8585bcd45583c6cc3f2d2 100644 --- a/arch/mips/mobileye/Makefile +++ b/arch/mips/mobileye/Makefile @@ -1 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-or-later + +obj-$(CONFIG_MACH_EYEQ5) += eyeq5-iocu-dma.o diff --git a/arch/mips/mobileye/eyeq5-iocu-dma.c b/arch/mips/mobileye/eyeq5-iocu-dma.c new file mode 100644 index 0000000000000000000000000000000000000000..71d1c35f911636db141c4467dccc405af69835ec --- /dev/null +++ b/arch/mips/mobileye/eyeq5-iocu-dma.c @@ -0,0 +1,160 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static void *eyeq5_iocu_alloc(struct device *dev, size_t size, + dma_addr_t *dma_handle, gfp_t gfp, + unsigned long attrs) +{ + void *p = dma_direct_alloc(dev, size, dma_handle, gfp, attrs); + + *dma_handle |= BIT_ULL(36); + return p; +} + +static void eyeq5_iocu_free(struct device *dev, size_t size, + void *vaddr, dma_addr_t dma_handle, + unsigned long attrs) +{ + dma_handle &= ~BIT_ULL(36); + dma_direct_free(dev, size, vaddr, dma_handle, attrs); +} + +static int eyeq5_iocu_mmap(struct device *dev, struct vm_area_struct *vma, + void *cpu_addr, dma_addr_t dma_addr, size_t size, + unsigned long attrs) +{ + unsigned long pfn = PHYS_PFN(dma_to_phys(dev, dma_addr)); + unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT; + unsigned long user_count = vma_pages(vma); + int ret; + + vma->vm_page_prot = dma_pgprot(dev, vma->vm_page_prot, attrs); + + if (dma_mmap_from_dev_coherent(dev, vma, cpu_addr, size, &ret)) + return ret; + + if (vma->vm_pgoff >= count || user_count > count - vma->vm_pgoff) + return -ENXIO; + + return remap_pfn_range(vma, vma->vm_start, pfn + vma->vm_pgoff, + user_count << PAGE_SHIFT, vma->vm_page_prot); +} + +static int eyeq5_iocu_get_sgtable(struct device *dev, struct sg_table *sgt, + void *cpu_addr, dma_addr_t dma_addr, size_t size, + unsigned long attrs) +{ + struct page *page = virt_to_page(cpu_addr); + int ret; + + ret = sg_alloc_table(sgt, 1, GFP_KERNEL); + if (!ret) + sg_set_page(sgt->sgl, page, PAGE_ALIGN(size), 0); + return ret; +} + +static dma_addr_t eyeq5_iocu_map_page(struct device *dev, struct page *page, + unsigned long offset, size_t size, + enum dma_data_direction dir, + unsigned long attrs) +{ + phys_addr_t phys = page_to_phys(page) + offset; + + /* BIT(36) toggles routing through IOCU for DMA operations. */ + return phys_to_dma(dev, phys) | BIT_ULL(36); +} + +static void eyeq5_iocu_unmap_page(struct device *dev, dma_addr_t dma_handle, + size_t size, enum dma_data_direction dir, + unsigned long attrs) +{ +} + +static int eyeq5_iocu_map_sg(struct device *dev, struct scatterlist *sgl, + int nents, enum dma_data_direction dir, + unsigned long attrs) +{ + struct scatterlist *sg; + int i; + + for_each_sg(sgl, sg, nents, i) { + sg->dma_address = eyeq5_iocu_map_page(dev, sg_page(sg), + sg->offset, sg->length, + dir, attrs); + if (sg->dma_address == DMA_MAPPING_ERROR) + return 0; /* No cleanup because ->unmap_page() is a no-op. */ + sg_dma_len(sg) = sg->length; + } + + return nents; +} + +static void eyeq5_iocu_unmap_sg(struct device *dev, struct scatterlist *sgl, + int nents, enum dma_data_direction dir, + unsigned long attrs) +{ + /* We know page ->unmap_page() is a no-op. */ +} + +const struct dma_map_ops eyeq5_iocu_ops = { + .alloc = eyeq5_iocu_alloc, + .free = eyeq5_iocu_free, + .alloc_pages_op = dma_direct_alloc_pages, + .free_pages = dma_direct_free_pages, + .mmap = eyeq5_iocu_mmap, + .get_sgtable = eyeq5_iocu_get_sgtable, + .map_page = eyeq5_iocu_map_page, + .unmap_page = eyeq5_iocu_unmap_page, + .map_sg = eyeq5_iocu_map_sg, + .unmap_sg = eyeq5_iocu_unmap_sg, + .get_required_mask = dma_direct_get_required_mask, +}; +EXPORT_SYMBOL(eyeq5_iocu_ops); + +static int eyeq5_iocu_notifier(struct notifier_block *nb, + unsigned long event, + void *data) +{ + struct device *dev = data; + + /* + * IOCU routing is hardwired; we must use our above custom + * routines for cache-coherent DMA on ethernet interfaces. + */ + if (event == BUS_NOTIFY_ADD_DEVICE && + device_is_compatible(dev, "mobileye,eyeq5-gem")) { + set_dma_ops(dev, &eyeq5_iocu_ops); + return NOTIFY_OK; + } + + return NOTIFY_DONE; +} + +static struct notifier_block eyeq5_iocu_nb = { + .notifier_call = eyeq5_iocu_notifier, +}; + +static int __init eyeq5_iocu_init(void) +{ + return bus_register_notifier(&platform_bus_type, &eyeq5_iocu_nb); +} +postcore_initcall(eyeq5_iocu_init);