From patchwork Mon Jul 27 12:05:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 6872721 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D40AE9F46B for ; Mon, 27 Jul 2015 12:01:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C5C6E2066F for ; Mon, 27 Jul 2015 12:01:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0BF402068A for ; Mon, 27 Jul 2015 12:01:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753254AbbG0MBu (ORCPT ); Mon, 27 Jul 2015 08:01:50 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:34412 "EHLO mail-pa0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752544AbbG0MBs (ORCPT ); Mon, 27 Jul 2015 08:01:48 -0400 Received: by pacan13 with SMTP id an13so51706396pac.1 for ; Mon, 27 Jul 2015 05:01:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:date:message-id:subject; bh=HKBYLzNmQJ2DDMUR6HIH8iOwy4JaI+HqkGu50YCcZQI=; b=jcJ3rkGG7OSzQ80keJcdUUpJ2nXYdFUu41+yK4CFizqDTx8LI77OM0Guskxr6aIf/2 gPQqaoaAOwJgODS7aSE+CDM6DIFd3uYZOvaPzh+LYbCqmX3EjjaHjiJZoXefrpUjH+QT UvQ23LmKJtSv1g0UPkzgVISfc+av0l89UZtQ4SSj3CpUqnq1ks4G4pHZZSzznYL4aNGV yBfIlfcS11s5d8v6UDL65OPhEf4uSShE1hC2qLCpNrJ6+H6vXeMgqwe5PHVTOPLw135b 6elPZpkZhh2H6mt+94FSS6aMzS5UOFXwKTn3fJDy9qdmzrhf7sW+QlO91ZLMn56oKzDi vtkA== X-Received: by 10.66.65.227 with SMTP id a3mr65844977pat.147.1437998507893; Mon, 27 Jul 2015 05:01:47 -0700 (PDT) Received: from [127.0.0.1] (s214090.ppp.asahi-net.or.jp. [220.157.214.90]) by smtp.gmail.com with ESMTPSA id j4sm29180378pdp.36.2015.07.27.05.01.43 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Jul 2015 05:01:45 -0700 (PDT) From: Magnus Damm To: linux-sh@vger.kernel.org Cc: laurent.pinchart+renesas@ideasonboard.com, kuninori.morimoto.gx@renesas.com, geert+renesas@glider.be, yoshihiro.shimoda.uh@renesas.com, horms@verge.net.au, ulrich.hecht+renesas@gmail.com, Magnus Damm Date: Mon, 27 Jul 2015 21:05:18 +0900 Message-Id: <20150727120518.1584.18226.sendpatchset@little-apple> Subject: [PATCH] ARM: shmobile: IPMMU and DMAC prototype Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Magnus Damm This patch is a prototype hack to enable DMA Engine over IPMMU for devices such as QSPI, SDHI and MMCIF. The simple approach taken here is to identity map the DMA Engine slave devices in the IPMMU driver. As expected this is just a test to see if the actual hardware works. I believe it at least half-works - the IPMMU fault errors go away when I test on r8a7791 Koelsch. The code is far from ready for upstream merge for various reasons: - The code is one huge layering violation (topology fixes should be elsewhere) - It also clobbers the virtual I/O space without reservation (corruption!) - Moreover, the identity mappings are added for all devices (just plain wrong) Next step would be to figure out how to fix this properly. Not-Yet-Signed-off-by: Magnus Damm --- arch/arm/boot/dts/r8a7791.dtsi | 32 +++++++++++++++++++++- drivers/iommu/ipmmu-vmsa.c | 57 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- 0001/arch/arm/boot/dts/r8a7791.dtsi +++ work/arch/arm/boot/dts/r8a7791.dtsi 2015-07-27 15:15:34.922366518 +0900 @@ -270,6 +270,21 @@ clock-names = "fck"; #dma-cells = <1>; dma-channels = <15>; + iommus = <&ipmmu_ds 0>, + <&ipmmu_ds 1>, + <&ipmmu_ds 2>, + <&ipmmu_ds 3>, + <&ipmmu_ds 4>, + <&ipmmu_ds 5>, + <&ipmmu_ds 6>, + <&ipmmu_ds 7>, + <&ipmmu_ds 8>, + <&ipmmu_ds 9>, + <&ipmmu_ds 10>, + <&ipmmu_ds 11>, + <&ipmmu_ds 12>, + <&ipmmu_ds 13>, + <&ipmmu_ds 14>; }; dmac1: dma-controller@e6720000 { @@ -300,6 +315,21 @@ clock-names = "fck"; #dma-cells = <1>; dma-channels = <15>; + iommus = <&ipmmu_ds 15>, + <&ipmmu_ds 16>, + <&ipmmu_ds 17>, + <&ipmmu_ds 18>, + <&ipmmu_ds 19>, + <&ipmmu_ds 20>, + <&ipmmu_ds 21>, + <&ipmmu_ds 22>, + <&ipmmu_ds 23>, + <&ipmmu_ds 24>, + <&ipmmu_ds 25>, + <&ipmmu_ds 26>, + <&ipmmu_ds 27>, + <&ipmmu_ds 28>, + <&ipmmu_ds 29>; }; audma0: dma-controller@ec700000 { @@ -1522,7 +1552,7 @@ interrupts = <0 198 IRQ_TYPE_LEVEL_HIGH>, <0 199 IRQ_TYPE_LEVEL_HIGH>; #iommu-cells = <1>; - status = "disabled"; + status = "okay"; }; ipmmu_mp: mmu@ec680000 { --- 0001/drivers/iommu/ipmmu-vmsa.c +++ work/drivers/iommu/ipmmu-vmsa.c 2015-07-27 20:48:02.642366518 +0900 @@ -491,6 +491,61 @@ static void ipmmu_domain_free(struct iom kfree(domain); } +/* Hack to identity map address ranges needed by the DMAC hardware */ +static struct { + phys_addr_t base; + size_t size; +} dmac_workaround[] = { + { + .base = 0xe6b10000, /* QSPI */ + .size = SZ_4K, + }, + { + .base = 0xee100000, /* SDHI0 */ + .size = SZ_16K, + }, + { + .base = 0xee120000, /* SDHIx */ + .size = SZ_16K, + }, + { + .base = 0xee140000, /* SDHIy */ + .size = SZ_16K, + }, + { + .base = 0xee160000, /* SDHIz */ + .size = SZ_16K, + }, + { + .base = 0xee200000, /* MMCIF0 */ + .size = SZ_4K, + }, + { + .base = 0xee220000, /* MMCIF1 */ + .size = SZ_4K, + }, +}; + +static void ipmmu_workaround(struct iommu_domain *domain) +{ + int k; + + for (k = 0; k < ARRAY_SIZE(dmac_workaround); k++) { + phys_addr_t phys_addr; + + printk("xxxx adding workaround for device at %pap\n", + &dmac_workaround[k].base); + + phys_addr = iommu_iova_to_phys(domain, dmac_workaround[k].base); + if (phys_addr) + continue; + + iommu_map(domain, dmac_workaround[k].base, + dmac_workaround[k].base, dmac_workaround[k].size, + IOMMU_READ | IOMMU_READ); + } +} + static int ipmmu_attach_device(struct iommu_domain *io_domain, struct device *dev) { @@ -530,6 +585,8 @@ static int ipmmu_attach_device(struct io for (i = 0; i < archdata->num_utlbs; ++i) ipmmu_utlb_enable(domain, archdata->utlbs[i]); + ipmmu_workaround(io_domain); + return 0; }