From patchwork Fri Jun 9 19:55:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13274407 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 6D39CC7EE2E for ; Fri, 9 Jun 2023 19:58:14 +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=J4id+ylWldTem3kd0IhJPDMoFDAKFaiI+k1qEI2h6fo=; b=QCyFaJ/eQDzpJL fSctLs0MaZjWmrzXUTFsly/g3RbzDiIURpfCaHyq81MPU+YPPfBRPOrjjfgl6FC8Gtxo6lk0zNxxW vIQOaOb41uGuStMCmKagYVe6yFWbXf4/1r40TcbjF3cIwsWHD+T7dsqAGnqtK2IeQIDV6l6x723fU dPIyMQPcRP4yWZzmEoEBz9s05kg5SitjSICcknRW1zsRJXk+FQarNkV/dnUwCUuQ38QXN1u6hvpRd LA/3MsL7zvqW6sSozY30dXaTV6roSZykmKA105X4zyMTfVGGKmY0R8pR4W8l75OCxxAdQT2MWKLTp 28zVtDeIqVopF/j/+dsg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7iEx-00E5cs-22; Fri, 09 Jun 2023 19:57:43 +0000 Received: from mail-mw2nam12on2061c.outbound.protection.outlook.com ([2a01:111:f400:fe5a::61c] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q7iDr-00E4R9-2P; Fri, 09 Jun 2023 19:56:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ONnco2GF8WhzqRHjgt9JCr6mJOw6MxU9QvhK17Qg37xr3MTAY2ARpvNFdpuiIM7cUidq00keu5gOnWEn84EHKw6GoMu0TjDoWoK+Gsy6yIUjNG+n5l1ATMzcOVQ35WB9JBCowaveiadNWBbpn2bEJsZIOE/g2aSuU/7+Avv7oEFO+G2i8fekomzQEJZDb3x8uUY0y063SYRfvNi1p6xLp1v+a13+kPK0vnpIFs9K53KUmfsL7rnLAnTh/R+7FZ0HnlUFmAsCvwh294E9cd/KDwOZ/eTILSKIralo7S35Gmx/3fQAVAuXfwf2MKgHhQAkThboX/EcFYgyYc5aR5A46Q== 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=oc9+cmsyQ7ClyqBWCUJKmesYXwKbwskFnJn3iebEKMo=; b=kgmaQd0AoUYyReaqMuVXh3RtbfANb+apS8fmMMzeH6ZcYBLNzTQtcaLBRYezchy/CGfKDK0HDNRn9uvnF+W8J2QuVu5e7Q9VWyeRSpWKY3jUwNLWzvb+vtwvCE/nNRyhK64ct5+FcXd8svrB0V9nxc+a/X/2mnU/mZSeZNcPxB7fIgtzjBwVSW4cXf+MFGWgBbebzbRwuaVe6vLYUsoIP6if7lYfkbJJdBykcRLO4Ohr/JgOSepCT8dPre8a2hKyZkv92vL9Hu+RqM1jmrUJRKlLjB1R4/69rhKkF6k8odUuzcKqK6b+XY9S9vt7HVykLYKS8uhya4LwtwqAMDm3Bw== 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=oc9+cmsyQ7ClyqBWCUJKmesYXwKbwskFnJn3iebEKMo=; b=A6of4EQYw97VfRbv2z3Le0aECz9dEaiU47foB5hd4aJOsrlTDr8JWnElJLDsDbsZHH4XqAm/9DDtOwWHlMjyKQ6tp6nS6ka1zZpelbRgQ2HNTNF6WVYOfIr9xqwifaiMK6xNWPkO12bIlUoPaiDbusuduSXBKUOTuEqZLf42466NQKOWu9NT5azw1nnSm63BnOaoLy0RD59GXdl0U9wEGRRi306plYyhdjIOJKeLY+pFZGwDejNoDwwMeCMSQkwSNkNkS4HPNq7EbhnLyVX0Cauc1CsxCFrZUzMI3JmrMDFMVKABh8WRZEO4j4G1gZFkswURv0IWwaDlEKv+nWVllA== 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 07/25] iommu/mtk_iommu_v1: Implement an IDENTITY domain Date: Fri, 9 Jun 2023 16:55:55 -0300 Message-Id: <7-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: BY3PR05CA0051.namprd05.prod.outlook.com (2603:10b6:a03:39b::26) 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: 7856a976-9cca-4824-e529-08db692397eb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YKexdcYZjJdWXnlzmcT+KeLI0vO5uvOI77vGkZuPhzHhtPn+xRmmCgjMNDnonDo5LHUYE+RnrkIxBa8+ThyincXbLwBFFrrh6Jd+iWVIAJzk/P2+UD6TqEKxfb1qi//v2nz3FxLtgzTi+HnrrI5bxMG5CRpdKKSGOBG9ISaZn/a4OqActydHtbrrdRae+AQajP1TxCziDjehXFM6AmE1VZMNFaiWorEa5ZuLkZF2mN5+yOPQdkn+rKj8WPBNXXP5pMgaGk/YP9qCMiM+6Ewmt8QA2UQzxzeJdoIDeO5/DaUZyYRgT0hFqMMU8BpwtqqMQgE5IxNlrRI4gkepxs6qUryHZB3o0TCJtgcV/OcZmgIagRpjzBgQMsk1ti7QIrI084aSpBonWtShnxDaz2Jcfvkw5aEeRE2JL/48moe5Hai8iR4/aYWppFehyyA5tqjMHZVZuLO6DiZfUaJxxC1oc1A6yC0ZdlNGr6kYmsd7vLWLPbhcsgzZUHtonaUoiq8+kpD3AdI2zu1fi98R5SdHV5nhH4GCi4wlltlWDnz2Z9z5ydrjpE7OvsFb6L0chpYSwZfdTAyyA1Oe5AzBOa4aY00EerE/JOo5OEaF59BaoH2pL9sRhuyfL6vLf1U1GZct 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: mugXLiFcQTl5IT2CoKPn8SmoCPQfeYUSdWYNvjwmqyEItiOnWQBf3Qv1c47Hi+dx7SY0sGQ9dD3w+Sl2QjjOACJqByHNXLtYw6C+H75Cxl2FP8GboERYGnr9jxjgSkJdUYW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s8zfstQRfiqgGtJxfPpOWP0fLSd8tC2vB2DnVNfHDWzANDzV0U0mAN5d4YGS8NCGbZeiila0oKSXqA7P9wytZdXbbiHmhZttSzRSEHXrgMxyK7bi/fDENoyxxV0rs3yPkMgL+cdGKftTNPbxZOVIutGgh1ge8unYpoL48J6d010O7UnwHwsYqyBzBarp5SdC7lr4KOtgYy8uwOV2W9qciBjacYz8fbMaOFwIaCvL/qRW6lHlExM7SxHfJKhmTGsYbVpnaVDM2L2Rg7kdLWXX4qVhq4yJM6NVldbWiADiWjbBJtlKs8jAOJ5n1F1vT64ySQzDopHNuAZF3KOei3IXIebttkybQGuEcXtrpFM2lKT9g8+HXWNZu3acB+picetfQnp X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7856a976-9cca-4824-e529-08db692397eb 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.8465 (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: 34Vg+yhZaOkC51JWqFMk/o03N9htSqYZ08AqdguWagkA8fZ5Bd9kMYcPvDL3atzY X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5264 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230609_125635_803684_9A104C69 X-CRM114-Status: GOOD ( 13.64 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org What mtk does during mtk_iommu_v1_set_platform_dma() is actually putting the iommu into identity mode. Make this available as a proper IDENTITY domain. The mtk_iommu_v1_def_domain_type() from commit 8bbe13f52cb7 ("iommu/mediatek-v1: Add def_domain_type") explains this was needed to allow probe_finalize() to be called, but now the IDENTITY domain will do the same job so change the returned def_domain_type. mkt_v1 is the only driver that returns IOMMU_DOMAIN_UNMANAGED from def_domain_type(). This allows the next patch to enforce an IDENTITY domain policy for this driver. Signed-off-by: Jason Gunthorpe --- drivers/iommu/mtk_iommu_v1.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c index 8a0a5e5d049f4a..cc3e7d53d33ad9 100644 --- a/drivers/iommu/mtk_iommu_v1.c +++ b/drivers/iommu/mtk_iommu_v1.c @@ -319,11 +319,27 @@ static int mtk_iommu_v1_attach_device(struct iommu_domain *domain, struct device return 0; } -static void mtk_iommu_v1_set_platform_dma(struct device *dev) +static int mtk_iommu_v1_identity_attach(struct iommu_domain *identity_domain, + struct device *dev) { struct mtk_iommu_v1_data *data = dev_iommu_priv_get(dev); mtk_iommu_v1_config(data, dev, false); + return 0; +} + +static struct iommu_domain_ops mtk_iommu_v1_identity_ops = { + .attach_dev = mtk_iommu_v1_identity_attach, +}; + +static struct iommu_domain mtk_iommu_v1_identity_domain = { + .type = IOMMU_DOMAIN_IDENTITY, + .ops = &mtk_iommu_v1_identity_ops, +}; + +static void mtk_iommu_v1_set_platform_dma(struct device *dev) +{ + mtk_iommu_v1_identity_attach(&mtk_iommu_v1_identity_domain, dev); } static int mtk_iommu_v1_map(struct iommu_domain *domain, unsigned long iova, @@ -443,7 +459,7 @@ static int mtk_iommu_v1_create_mapping(struct device *dev, struct of_phandle_arg static int mtk_iommu_v1_def_domain_type(struct device *dev) { - return IOMMU_DOMAIN_UNMANAGED; + return IOMMU_DOMAIN_IDENTITY; } static struct iommu_device *mtk_iommu_v1_probe_device(struct device *dev) @@ -578,6 +594,7 @@ static int mtk_iommu_v1_hw_init(const struct mtk_iommu_v1_data *data) } static const struct iommu_ops mtk_iommu_v1_ops = { + .identity_domain = &mtk_iommu_v1_identity_domain, .domain_alloc = mtk_iommu_v1_domain_alloc, .probe_device = mtk_iommu_v1_probe_device, .probe_finalize = mtk_iommu_v1_probe_finalize,