From patchwork Wed Aug 23 16:47:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13362888 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 B873FC6FA8F for ; Wed, 23 Aug 2023 16:50:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=O8cvW84AteYGsHkKJoxDmgX1gvmm/kLqlAnWOZtGp1s=; b=0QdNcsROeuUNAIwv+VEUUjwiEa JRT+FHuPymV/IN9r9c2Kvk6t1kaZDEYqj4qH/zq4suQBK5L4w5L8MLhxZ93M5EvRkp/5QPInljI1p Ca394wY1+TAQzQrRAtyughtypAXKBeEBZcrry3ca0+GSKFiEk6+eX08AE5qPeAKgv45QHtET7vT8I IPJxnyt/C9JXjjn7Dbczg4pnhtI+mF7WiRuFzWlUmWDzYnmW+nyBTqEM3jF/11nP+fNQf46w5GnHW 5gqR6xmSCOVLTiI/C88uHvm5TjmpqZ1+fCJeShMwdAsLppjCnin7oWsEamYlbl8+0B5lU4cHxsokj myt2HWSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qYr42-0018eg-0y; Wed, 23 Aug 2023 16:50:38 +0000 Received: from mail-dm3nam02on20610.outbound.protection.outlook.com ([2a01:111:f400:7e83::610] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qYr1e-0016PI-1D; Wed, 23 Aug 2023 16:48:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kjS/s97c/GhA+gKyR/rPOMvf3NV/rr5Ft7boYuOtaRd/RtxMQzYeO4RyTuQemA9kUSJt0xu4pMDVtxsKejPv6g/pkWkp3ibhv/aEjGaQWa37QYPPOROzCrsq+NGF/g1O+lTNe24ffc1yPb/5gBGeyPKVHe9EfKgy3TOuX2bT6qElu7+8UU44Z/efaSykw/qMtx5cPd5QEhsrud9yxKm0IVex0v1QtaJIAzzYcu5r7caETh7OLsvrQaJWLL/HndyM3tBd3oXxwLAP4EVao4QpwSuBGLTdZM5hZzLPT65kyY/4x38z1fX5D7h2ZwpXKdkp4jznIeU618Siy0QsqqbbQg== 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=O8cvW84AteYGsHkKJoxDmgX1gvmm/kLqlAnWOZtGp1s=; b=Bd0QjWCt+MAy5xSV7RyptE3xXY1szeF//fvOJoqc3s/Jl+OJMLMa5HknbfFEjDi2KDARcZm6z78W4PaV3P5zvX++llalcrZTX4iovUBq4Q9s8Yjvca1PxkSFnB9KlpFFX/nfOqzTnsOejQQ3gEE6CUgxpkFjW3TbYxNh1HZvHKNyXczqZMrAKIK9GlAXpDPK/fg1piPahmx/98TVUmi/M0LKQuE9indmoSDfbVP4mZ4gr1x4qGb9JV9EkQxR2ReaGmo9uaBv10tdd7ObHdR9h0+MUrfEtank0rJONqUtw3Y22vP2UECJvp1YFIaPtllXGAkydNuP2P514XSPxH9rnQ== 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=O8cvW84AteYGsHkKJoxDmgX1gvmm/kLqlAnWOZtGp1s=; b=cspIGCsFzxi/J8TTwRA1r4A1eZ0Vg6rJf5sYltxhGYi17f8FxDaGVj/yr12FXlUr1mzWWT14hamLLQ0lOR1YtazrIL+hZWRkm+CZkJoz0WOKN0YTShBDml021KIc6SUaYGQLuOdQv2MSAsH/b1aKBBq2na53P3/w6ZzhHW4F//Fw9Szmf9USTcTkNn4LrmioS6lGhfB55DjilLzNido9ui5t922WbibnOZ0HRV5HU1F3j8h2pkrmN5BsRPOCJTp7N2MzPf099aMxnR3PMqjZFuY3el+dIllYWt1c0utoHBPVwrAolmS59WOUSInuBvCgv69mjnP3TPXjYe6ItYm3Vw== 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 CH0PR12MB5044.namprd12.prod.outlook.com (2603:10b6:610:e3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.26; Wed, 23 Aug 2023 16:48:02 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1%6]) with mapi id 15.20.6699.020; Wed, 23 Aug 2023 16:48:02 +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 v7 19/24] iommu/sun50i: Add an IOMMU_IDENTITIY_DOMAIN Date: Wed, 23 Aug 2023 13:47:33 -0300 Message-ID: <19-v7-de04a3217c48+15055-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v7-de04a3217c48+15055-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR03CA0417.namprd03.prod.outlook.com (2603:10b6:610:11b::6) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|CH0PR12MB5044:EE_ X-MS-Office365-Filtering-Correlation-Id: b87e2f5f-dc1b-42ac-2e70-08dba3f8ade5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: q8MxGlR7ENx/1dVqVQoS/EnSLFVvuIvbKPU8/41HFtDdoXOnnAE3LaoAiDr1CjAVyMI0uN/dKDhVDkZUryi4obToTBE28AbmGB6YskJfYxa2LjpEyO4ESB35lbzEoN1cDNySKj+EOByOlk8/u9BUZ9JUnzyzxc4bLkauCJM087k3hdOhAhYOAIq+tE7pobGqDwU74lLWpnhMlv1oo3LK6gdp6+S1RDcxXf3gOj/wsORLU4co85aHzPRlpixuOsOB5Y8RRwpCvhr5JDah0wAiVEtMnQMy65rLr3kEgBxtAHmSY21EocuFF8fB0aNsOR4o/ZxlMPEILSbSiZdba+vw8j4xWz7AQ+hFhJBbZtRdoPa+9cN/rU6ekxnfb1Mgbd7cwuE3WTGYACDRu8R73qF9MQ0lHT5RPBwxxhnml8BQe5PByl/b2KeI2PNhMDKLF8qDSDuKB0dusPlADGws3btwkSuAtbryr4U0chr0ewL7tQBogQkVfFa0oJ+tLfpeHhsrxZ51CqJVKAjY0B+lwlPQhvUmU8LFidywJyTBTtWXphEIMnG09evroWb5dFY3Y6fpiFSfSjGeKCF7iwluVfkDg+zCyIfsc4NvCnuQE7e3fzE= 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:(13230031)(39860400002)(136003)(376002)(346002)(396003)(366004)(1800799009)(186009)(451199024)(83380400001)(2906002)(921005)(38100700002)(86362001)(36756003)(41300700001)(6512007)(110136005)(66946007)(66556008)(54906003)(66476007)(6486002)(6506007)(316002)(5660300002)(2616005)(4326008)(8936002)(8676002)(478600001)(6666004)(26005)(7416002)(7406005)(107886003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +WCm69P7cBxiIVe5NaB6YSOEkEhtQueJ7h4asP0CJ+4ybMOfep6v0kiW3uxELQSxySKyCwEypfnbf+sriK5sl2WAdOQK6kpBX03ey/WtOFoPL7+8YImKk+LwEfhJnW+CZ+9cmp061qkuWyhlSrdS19o1jkuCKcDEQb1H1766fqNYZC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RH1tLa0T+ob4CF6DMFCQ+IjWL6KAdMpE34QjxajJ5cS84M7AtWQYz4B8D7vxAWK8PFcGuaMyh8ameoEM1XLjZXxy1WceQSwzgCz8uOAiXlBKgU4GryfcSPpDekXLwLbBCp3L/yvSQbLzWVQwZZwOufnkQ/T/UQ6HAxb4AKLES13+oU6VSUsXXiijugm6/rpNeJGsHorQjkBKZw1uTcmxkOv8OubcUyNO57+6ZGLOHEg8WvC2RZ42Lb/3/DxjnMCzxqYJ8Q05Dxly7dDoc1zxRzaRVg91Mg08toe8RjjOMEhRXQNxOlXiVbQTapLzH2YlpMNzYkxmIk1E9opfTNz4MosNzGkVLdK0 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b87e2f5f-dc1b-42ac-2e70-08dba3f8ade5 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2023 16:47:47.1404 (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: CbCj4GviW22psL2M4n564UbHizyCnuT7OyC4dY5W92YLahDxtg4EgaGLBZWPAiu3 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5044 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230823_094810_482197_1ED5CE5D X-CRM114-Status: GOOD ( 14.20 ) X-BeenThere: linux-mediatek@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-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Prior to commit 1b932ceddd19 ("iommu: Remove detach_dev callbacks") the sun50i_iommu_detach_device() function was being called by ops->detach_dev(). This is an IDENTITY domain so convert sun50i_iommu_detach_device() into sun50i_iommu_identity_attach() and a full IDENTITY domain and thus hook it back up the same was as the old ops->detach_dev(). Signed-off-by: Jason Gunthorpe Reviewed-by: Jerry Snitselaar --- drivers/iommu/sun50i-iommu.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c index 74c5cb93e90027..0bf08b120cf105 100644 --- a/drivers/iommu/sun50i-iommu.c +++ b/drivers/iommu/sun50i-iommu.c @@ -757,21 +757,32 @@ static void sun50i_iommu_detach_domain(struct sun50i_iommu *iommu, iommu->domain = NULL; } -static void sun50i_iommu_detach_device(struct iommu_domain *domain, - struct device *dev) +static int sun50i_iommu_identity_attach(struct iommu_domain *identity_domain, + struct device *dev) { - struct sun50i_iommu_domain *sun50i_domain = to_sun50i_domain(domain); struct sun50i_iommu *iommu = dev_iommu_priv_get(dev); + struct sun50i_iommu_domain *sun50i_domain; dev_dbg(dev, "Detaching from IOMMU domain\n"); - if (iommu->domain != domain) - return; + if (iommu->domain == identity_domain) + return 0; + sun50i_domain = to_sun50i_domain(iommu->domain); if (refcount_dec_and_test(&sun50i_domain->refcnt)) sun50i_iommu_detach_domain(iommu, sun50i_domain); + return 0; } +static struct iommu_domain_ops sun50i_iommu_identity_ops = { + .attach_dev = sun50i_iommu_identity_attach, +}; + +static struct iommu_domain sun50i_iommu_identity_domain = { + .type = IOMMU_DOMAIN_IDENTITY, + .ops = &sun50i_iommu_identity_ops, +}; + static int sun50i_iommu_attach_device(struct iommu_domain *domain, struct device *dev) { @@ -789,8 +800,7 @@ static int sun50i_iommu_attach_device(struct iommu_domain *domain, if (iommu->domain == domain) return 0; - if (iommu->domain) - sun50i_iommu_detach_device(iommu->domain, dev); + sun50i_iommu_identity_attach(&sun50i_iommu_identity_domain, dev); sun50i_iommu_attach_domain(iommu, sun50i_domain); @@ -827,6 +837,7 @@ static int sun50i_iommu_of_xlate(struct device *dev, } static const struct iommu_ops sun50i_iommu_ops = { + .identity_domain = &sun50i_iommu_identity_domain, .pgsize_bitmap = SZ_4K, .device_group = sun50i_iommu_device_group, .domain_alloc = sun50i_iommu_domain_alloc, @@ -985,6 +996,7 @@ static int sun50i_iommu_probe(struct platform_device *pdev) if (!iommu) return -ENOMEM; spin_lock_init(&iommu->iommu_lock); + iommu->domain = &sun50i_iommu_identity_domain; platform_set_drvdata(pdev, iommu); iommu->dev = &pdev->dev;