From patchwork Wed Mar 8 11:02:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 9610863 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3FCE26046A for ; Wed, 8 Mar 2017 11:11:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 454EE28559 for ; Wed, 8 Mar 2017 11:11:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 383402856E; Wed, 8 Mar 2017 11:11:30 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A196828559 for ; Wed, 8 Mar 2017 11:11:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752744AbdCHLKv (ORCPT ); Wed, 8 Mar 2017 06:10:51 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:35035 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750853AbdCHLKt (ORCPT ); Wed, 8 Mar 2017 06:10:49 -0500 Received: by mail-pg0-f66.google.com with SMTP id 187so3139687pgb.2; Wed, 08 Mar 2017 03:08:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:date:message-id:in-reply-to:references:subject; bh=edQHHV0r1GTyruyrx/7JGKFpU5jDZxD9jh32ChTt+SA=; b=VJry4MPohkpCBA+MkxRdftm7NWIh3ktrf//raJL3j7PzMbSVms/2HrBn6qALnATc1R OK6UDkRa50tmwDluFA0ctXBCpZULP5boIuh+sKaIOVn1fOQyY+GGDdEDFMFrF8sGkTql 5h819B/qJCO5g6qIRwp/nAwTvwH9Fa+0khev6PbUFh+3tptwMvmlQiMY6uOmr8JOxS8V 9KeBhI55ElEvxVf9S66q1C9Qz9qj4JqZADTSW7BIUae6oEiNdnlu9J3G+0GUgGfDgvPt nPjn8yJe/PkrTXzbly9ZsoVMhCn4VahFR49rqdhUpzDhLWh7FcxUBiOrhNI0WUnOGS7/ z1NQ== 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:date:message-id:in-reply-to :references:subject; bh=edQHHV0r1GTyruyrx/7JGKFpU5jDZxD9jh32ChTt+SA=; b=DrMnRY4WsaBar+cQsPr6EHEoiLopLCgJu5sIVK2j5+m/RJk7Q96ekg+hKodewyyUcq SPONrO55Y3EDSqQRiK07/6SOaOMuMLGfD7rIEblnEASmYgLwf51S0LsHLMOkP+f17Obe kJmyBL52FOrKn0FbSCmBYgFEMGDR9hT3XxzfJ48UEiFaWhq2bFTofOVTmCJqKHSwvHrb EhLm5meGehUV0ma0z0NeEte4C8wQP2ORlVgse/03EBOF8pT4VN6VrlwhWjsnqKktU60l XyncWrBgVMJYQIEPV5vB8+UZ43r+sael7QPlDxmXbzTTJLFuEEqZHFVzy+WRfUz9YMst fbjA== X-Gm-Message-State: AMke39kf/4QA/Rf+L3ItLfdNoVpCWDAsfc6vX1JMuO/P8ScZEYPUUy0YJvosF1NC2tG/gQ== X-Received: by 10.84.140.36 with SMTP id 33mr7889249pls.136.1488971315174; Wed, 08 Mar 2017 03:08:35 -0800 (PST) Received: from [127.0.0.1] (s214090.ppp.asahi-net.or.jp. [220.157.214.90]) by smtp.gmail.com with ESMTPSA id y184sm5520560pfg.86.2017.03.08.03.08.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Mar 2017 03:08:33 -0800 (PST) From: Magnus Damm To: joro@8bytes.org Cc: laurent.pinchart+renesas@ideasonboard.com, geert+renesas@glider.be, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, iommu@lists.linux-foundation.org, horms+renesas@verge.net.au, Magnus Damm , robin.murphy@arm.com, m.szyprowski@samsung.com Date: Wed, 08 Mar 2017 20:02:53 +0900 Message-Id: <148897097336.16106.17118406255063350893.sendpatchset@little-apple> In-Reply-To: <148897088333.16106.13237004440297956899.sendpatchset@little-apple> References: <148897088333.16106.13237004440297956899.sendpatchset@little-apple> Subject: [PATCH v3 09/09] iommu/ipmmu-vmsa: Hook up r8a7795 DT matching code Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Magnus Damm Tie in r8a7795 features and update the IOMMU_OF_DECLARE compat string to include the updated compat string. TODO: - Consider making use of iommu_fwspec_add_ids() for uTLB handling Needed to coexist with non-OF R-Car Gen2 somehow... - Break out stuff useful for R-Car Gen2 from this series Fix up the Gen2 IPMMU support code and/or Fold more stuff into the multi-arch series - Add support for sysfs and iommu_device_link()/unlink() Signed-off-by: Magnus Damm --- Changes since V2: - Check for lack of root device in ->xlate() This fixed a bug when IPMMU-MM is disabled in DT the system hangs on boot - Added code to ipmmu_init_platform_device() to handle multiple ->xlate() calls - Include empty white list by default - Updated TODO list Changes since V1: - Enable multi context feature - Update TODO list drivers/iommu/ipmmu-vmsa.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) --- 0018/drivers/iommu/ipmmu-vmsa.c +++ work/drivers/iommu/ipmmu-vmsa.c 2017-03-08 19:11:53.600607110 +0900 @@ -23,6 +23,7 @@ #include #include #include +#include #if defined(CONFIG_ARM) && !defined(CONFIG_IOMMU_DMA) #include @@ -770,6 +771,10 @@ static int ipmmu_init_platform_device(st int num_utlbs; int ret = -ENODEV; + /* Initialize once - xlate() will call multiple times */ + if (to_archdata(dev)) + return 0; + /* Find the master corresponding to the device. */ num_utlbs = of_count_phandle_with_args(dev->of_node, "iommus", @@ -1043,6 +1048,17 @@ static struct iommu_group *ipmmu_find_gr return group; } +static bool ipmmu_slave_whitelist(struct device *dev) +{ + /* By default, do not allow use of IPMMU */ + return false; +} + +static const struct soc_device_attribute soc_r8a7795[] = { + { .soc_id = "r8a7795", }, + { /* sentinel */ } +}; + static int ipmmu_of_xlate_dma(struct device *dev, struct of_phandle_args *spec) { @@ -1053,6 +1069,18 @@ static int ipmmu_of_xlate_dma(struct dev if (!of_device_is_available(spec->np)) return -ENODEV; + /* Failing in ->attach_device() results in a hang, so make + * sure the root device is installed before going there + */ + if (!__ipmmu_find_root()) { + dev_info(dev, "Unable to locate IPMMU root device\n"); + return -ENODEV; + } + + /* For R-Car Gen3 use a white list to opt-in slave devices */ + if (soc_device_match(soc_r8a7795) && !ipmmu_slave_whitelist(dev)) + return -ENODEV; + return ipmmu_init_platform_device(dev); } @@ -1095,11 +1123,22 @@ static const struct ipmmu_features ipmmu .twobit_imttbcr_sl0 = false, }; +static const struct ipmmu_features ipmmu_features_r8a7795 = { + .use_ns_alias_offset = false, + .has_cache_leaf_nodes = true, + .has_eight_ctx = true, + .setup_imbuscr = false, + .twobit_imttbcr_sl0 = true, +}; + static const struct of_device_id ipmmu_of_ids[] = { { .compatible = "renesas,ipmmu-vmsa", .data = &ipmmu_features_default, }, { + .compatible = "renesas,ipmmu-r8a7795", + .data = &ipmmu_features_r8a7795, + }, { /* Terminator */ }, }; @@ -1288,6 +1327,8 @@ static int __init ipmmu_vmsa_iommu_of_se IOMMU_OF_DECLARE(ipmmu_vmsa_iommu_of, "renesas,ipmmu-vmsa", ipmmu_vmsa_iommu_of_setup); +IOMMU_OF_DECLARE(ipmmu_r8a7795_iommu_of, "renesas,ipmmu-r8a7795", + ipmmu_vmsa_iommu_of_setup); #endif MODULE_DESCRIPTION("IOMMU API for Renesas VMSA-compatible IPMMU");