From patchwork Fri Jun 9 19:55:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13274349 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 084CDC7EE29 for ; Fri, 9 Jun 2023 19:57:58 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yGCG/YtThgNr/bxmHa5Tk3zj9TrJR0xp/IhsivxIjSI=; b=GpkEtov2HPVIVG tV/zRnwZQHuHOYFRM/X8zw5HsQnUz/0LXvl3gbn8vR7wL3oEaDuRBbk3Gvjb5kFve9JjPwfQJUm4f l6GNCBpzouGhKvluq6MlkIMUwa+bXVnudSoj74mcVXzaMgcGo4i8KSmmLpGd6E6IFlfscLcQJXvJU xgsuxPG4X+DygbucUSaCPh6G30zAVHL53q/d6UF1EOCw75gjF1EtmDFoTqSL0n2NDtzSyRC8oVlYD bG1hl8Ye4BzGmDx8N6aOc5aBL69yJB5rL7lf0622joCSF99Cpkhg6h8bpN2zEx0kf3FAHlFNujQgB 2EXCshq2UVR3xI/gOgwQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7iF1-00E5gk-13; Fri, 09 Jun 2023 19:57:47 +0000 Received: from mail-mw2nam12on20618.outbound.protection.outlook.com ([2a01:111:f400:fe5a::618] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q7iDp-00E4Rq-2V; Fri, 09 Jun 2023 19:56:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HwE07d6nUcUPbcn5Ft0y8VJdw4liT38tmylgMa8beP68yQumRb0IwURKEBWUU8c66dht/rPUb14sFz9B4IxOc5ECOLTH1TfItvLwY1DIKMGzTOeluG+8NWvy0+1GoRQEGWjT4cBV1YB+fSE+1erq3SWqbGTpSQbmS4lhizduvLKiB7ClU95b8HP8XkOCRLO33YMYSwrP+xIqGg/wHt9KAwDDMt6/PUOcaQckImbivOWLkhGrGxyfaZxVh9Q2qUFQ10L9oYGKo8NOlCQ8MqoE6WmzH6M6wWqosl9MRPVn8JRNvJlBgAhoLo1CjNuamK4uPli5qVSxxN8V9vdVNyIQug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JNyTRyxbNWq/jd5aCXqxAkKB4mcTO+zABe+4bu/mqLE=; b=PHky4GH4Xf2OA2sJnM/DwCLR9Guh9mfjOtbpbQEsT1fp6nb1I045F/uv5hB0TYpFRHGMyB7Q77Ur+E7GHgu7yXTyBJKPrUzTpX7mehEWpjP35XJAfWIT/GQHATp3AtwOm8TJctkoHWZRpblljp+/HzjPkoF6r+7wUd+npSvwa6vcov3Yp0drNS/7lxV98Zk7yqJ5du4mS7eGZkC+GZvI/62s6+dI/thu1S7uD3DTclKOkTLeX6Ly/HwASfyVbevNggcD2lXA+mYHVrDIgIXEIFyHSg2FpHI4pP0fmo45Cp1r/0+qnrtdkR2qNibKL2Lm3jHcTRkuWfmj0EaygEzNuQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JNyTRyxbNWq/jd5aCXqxAkKB4mcTO+zABe+4bu/mqLE=; b=BKYrg2k0u0ILSYQJX0IQyKK9qvww3ktPficLTDZAROrbPNuJ2IDH3mfHwO+vwwgVeh3ikBufDl7ZOEuPwPWO4l2tQ5x0cuOaeztdBOpSzZCh6eYhOiqVEiN40L8srFplquiKRSoKyBKk+nzInCvSctF6sFI8uu0K/ZfVaMDLpepT2ouORteLSqoYq7F5sOadqIsGK5krX2pg39vorLNhzno2iZh5tFEcZZfeBiH/ArBCNNRthZ/gwavHqZ1gtg0/ipZFld8ibB7BuzePG0Sjjrks2QQ/ulWOTtwUVJyAbQNXtIe7g3+mfjOBjxa2QEZy7i74X3ZGtHMWnx+AWsXPIw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by DM4PR12MB5264.namprd12.prod.outlook.com (2603:10b6:5:39c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.33; Fri, 9 Jun 2023 19:56:21 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%6]) with mapi id 15.20.6455.030; Fri, 9 Jun 2023 19:56:21 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v3 05/25] iommu/fsl_pamu: Implement a PLATFORM domain Date: Fri, 9 Jun 2023 16:55:53 -0300 Message-Id: <5-v3-89830a6c7841+43d-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v3-89830a6c7841+43d-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: BY3PR05CA0040.namprd05.prod.outlook.com (2603:10b6:a03:39b::15) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DM4PR12MB5264:EE_ X-MS-Office365-Filtering-Correlation-Id: dc09b036-3b27-4070-fa13-08db692397df X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Bp3k+FpztduMrx3QZfg/nXNhYNgK6TtCoufKjp/P/ae2i2E4KRz5qjlkLlcB3EiO2/y0wIUbROmPnW5yNege/namDj/VbdWbTMJsXNPvZBmm78YEoHREa776Q3COnmgZaqND8uyPriiMAqWqbaVGVpJp1JFNztEoYtWzUJRVzo0nQa6jr3pPnKd5jut7DOV2ynJGUO4ySkZvt+D+Sm3vj7HMZv1AYB81FhxXRfJPaYBmCWYZhGmudyqcXNa/cjDR8Ltwq/q8rbTGitGqsd+qAzQhYezciXzO/kl1auYlAZapMp09sWtqdFMvlPMUs3uEEoJpJjSVxceXgZzah04czXRdvdz1M4RbRciDw2x3RZAXwE9itCXD47cAPxsbo9AEvyjh9m4zno2Pj7ZjxcWbXEmv4mizjVK//TZCikd8dlXzpRVQBr+mcxCq/qAsD7KRVxEzxhe5wjc2/++2ri8MNjcswaGReF8STEPESCk3Exh/BLKGTLSeQdD6fINTmcWnieFr+D5UWbn3jvGuBtswfWvrPWggPUeK2XbyKLDlFYzagXFtQeokh6nCtNJ77rh70CMnjzMs+6vnGYojgRkkqkSh9PipurDhNW7VJrcx3a1uo9iDjoNMxLP0KtSuiqS/ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(346002)(39860400002)(366004)(136003)(376002)(396003)(451199021)(2906002)(83380400001)(36756003)(26005)(6512007)(6506007)(478600001)(54906003)(110136005)(107886003)(6486002)(6666004)(8936002)(7416002)(7406005)(5660300002)(2616005)(41300700001)(66946007)(66556008)(4326008)(66476007)(8676002)(186003)(316002)(38100700002)(921005)(86362001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: T0yPWI2H1PKhBeP215/wQiwm0tuVUKrlXXGQQCi/V81xqX4WIXdAa7CyOWtuYJPpWpgzl6eFZKJ/HPOIxVEf+CbSwBWdw0cqJJsIvn+3dXZ6qvXYkCqZn2UU2gHm/y2fvBoOBOX+EyXi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ewaVIQqy79lZt8hmyPslYDDk5Vrh6j5n/chsQyXfiPLGnLr6f4tfHN53u9x0HltfvaX+mCyYjI8djUcD6j0yVFb0uXCijluDXrRrfVVmN0D5aPKIP1D/ZsnS/6upQor2fQe0lJ3qbylKZHz+HmRnkVsnpcEC017frdc/MhNlcueJ/ZMoTV9X1+FDju1J9NLWXfpaE2HRQXqr94QOOaFHPsFgCl++l8vVMhdCcguyCiRhzG+tbNKXVvRGWQAcA6242FuEbtW0z11rUPOZySQHInP1oCTt/7AA1S/YkbgGqTm3CSWiW8pSpiAIRzFIf3eTBt4PgPQKuUfVWSsC41zToC8rxY/auXL8e58bDsMAzzUOh7lMIteU+9H X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: dc09b036-3b27-4070-fa13-08db692397df X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2023 19:56:19.7093 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jnQ7oErbksC+CGScW2foijE0RdCmlcO25ETyTWqkfJ0SgYUovsWf+jA6+d/aSSSC X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5264 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230609_125633_876242_6C451F09 X-CRM114-Status: GOOD ( 18.71 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org This driver is nonsensical. To not block migrating the core API away from NULL default_domains give it a hacky of a PLATFORM domain that keeps it working exactly as it always did. Leave some comments around to warn away any future people looking at this. Signed-off-by: Jason Gunthorpe --- drivers/iommu/fsl_pamu_domain.c | 41 ++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c index 4ac0e247ec2b51..e9d2bff4659b7c 100644 --- a/drivers/iommu/fsl_pamu_domain.c +++ b/drivers/iommu/fsl_pamu_domain.c @@ -196,6 +196,13 @@ static struct iommu_domain *fsl_pamu_domain_alloc(unsigned type) { struct fsl_dma_domain *dma_domain; + /* + * FIXME: This isn't creating an unmanaged domain since the + * default_domain_ops do not have any map/unmap function it doesn't meet + * the requirements for __IOMMU_DOMAIN_PAGING. The only purpose seems to + * allow drivers/soc/fsl/qbman/qman_portal.c to do + * fsl_pamu_configure_l1_stash() + */ if (type != IOMMU_DOMAIN_UNMANAGED) return NULL; @@ -283,15 +290,33 @@ static int fsl_pamu_attach_device(struct iommu_domain *domain, return ret; } -static void fsl_pamu_set_platform_dma(struct device *dev) +/* + * FIXME: fsl/pamu is completely broken in terms of how it works with the iommu + * API. Immediately after probe the HW is left in an IDENTITY translation and + * the driver provides a non-working UNMANAGED domain that it can switch over + * to. However it cannot switch back to an IDENTITY translation, instead it + * switches to what looks like BLOCKING. + */ +static int fsl_pamu_platform_attach(struct iommu_domain *platform_domain, + struct device *dev) { struct iommu_domain *domain = iommu_get_domain_for_dev(dev); - struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain); + struct fsl_dma_domain *dma_domain; const u32 *prop; int len; struct pci_dev *pdev = NULL; struct pci_controller *pci_ctl; + /* + * Hack to keep things working as they always have, only leaving an + * UNMANAGED domain makes it BLOCKING. + */ + if (domain == platform_domain || !domain || + domain->type != IOMMU_DOMAIN_UNMANAGED) + return 0; + + dma_domain = to_fsl_dma_domain(domain); + /* * Use LIODN of the PCI controller while detaching a * PCI device. @@ -312,8 +337,18 @@ static void fsl_pamu_set_platform_dma(struct device *dev) detach_device(dev, dma_domain); else pr_debug("missing fsl,liodn property at %pOF\n", dev->of_node); + return 0; } +static struct iommu_domain_ops fsl_pamu_platform_ops = { + .attach_dev = fsl_pamu_platform_attach, +}; + +static struct iommu_domain fsl_pamu_platform_domain = { + .type = IOMMU_DOMAIN_PLATFORM, + .ops = &fsl_pamu_platform_ops, +}; + /* Set the domain stash attribute */ int fsl_pamu_configure_l1_stash(struct iommu_domain *domain, u32 cpu) { @@ -395,11 +430,11 @@ static struct iommu_device *fsl_pamu_probe_device(struct device *dev) } static const struct iommu_ops fsl_pamu_ops = { + .default_domain = &fsl_pamu_platform_domain, .capable = fsl_pamu_capable, .domain_alloc = fsl_pamu_domain_alloc, .probe_device = fsl_pamu_probe_device, .device_group = fsl_pamu_device_group, - .set_platform_dma_ops = fsl_pamu_set_platform_dma, .default_domain_ops = &(const struct iommu_domain_ops) { .attach_dev = fsl_pamu_attach_device, .iova_to_phys = fsl_pamu_iova_to_phys,