From patchwork Wed Nov 1 23:36:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13443144 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 0A10BC4167D for ; Wed, 1 Nov 2023 23:37:42 +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=JFv6S/of3jwt72G4+MowYHhRLQz6Qrp+wNvHI/hsRoY=; b=MVx3xmCyAhL3pw uiNZZMXSfnDm0XzEAN4fKIK3uJFOFNB8oRUdAT4mKkMFl8LQdCaKdsmtzi+lbb+6kuxiNi8DJUNeq DU3u9KS6DJ46+a2YFFic1ULOMwZebkdTpExMrUFMXR9aYHFxN9yGvoj32RrKqVjGC8d9Pdj1lkHs3 2jqraa9BDAIlWhXB4lLiwV2DyCkyM9xcRlYyS0ZoXFnLtsjMf8r/lFrsTHUYwa6+lPLSKe3w02xH2 2CBhSVhhM+dPVw49bwSNH4qPjJ+bQKL2wCwKVxaUX995l38yCSKCxQ3X0Pmq7PDW3+ZoXpRWWSuCi AnF/Tx1ZvxT3FKBy3Hmw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qyKln-008Jdh-2V; Wed, 01 Nov 2023 23:37:07 +0000 Received: from mail-mw2nam12on2060e.outbound.protection.outlook.com ([2a01:111:f400:fe5a::60e] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qyKlg-008JU6-09 for linux-arm-kernel@lists.infradead.org; Wed, 01 Nov 2023 23:37:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hC51d7Lk0JVfj7JiEAKKuKZiKw4DbNHW+qd4B5/fe8zOYmnCekcT3N/jpuOHGIZVpfZpn9FcIc/xahZTR5rmU0Az179opGCZ3V8KvUjdW9YqdfBtMYbkXa3KnG6zCKpn9WCs3C6XZ95igZt1E1J7iiZpki7ob1r9yutLdb9ybolAAY6SMgx6hoSh/fdZF3lyyG2wF+POxnhG+4uhHsmpPIhZ7iRvt6o8zrgtY07xVyrWcsAZr+nRDey7nJovkQinjY2ITD/dGpPmdOLIRg/v9jX69ZzOrmgldhgM2H2XCZNfPvNEPOMsweAHDW5m/8R5zJDymShjzWfL/NgjjWiQ5Q== 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=6SBEHUNiHJavSDEijDhFP1X9EW/JTL8xJUkX0CCpjUk=; b=FwiKJnWDvT6u9mEfpDHwTcSDP5BoonQSzkhnNt7ZaS+pi1R+AKcEq0VWb4ljHVtaeigsOO3cEwiIjhnK1CLKcRMLdGUA2+skqd1JQPxmT2EA7RCuSrXOubVTHlRBVEeBho62U5wlIIrfztb/KF7etgt/CB5o34kObfgnlKlydLjtKh+0S01efPPbGSiMrf2Q2lveiZ+SAl4hpenTS1ioisrCJY+T+kfD7oTItqMqYC7EohPxW3Cb9I76tXT+3acD4ZExP6sc5kM5c8XR2BOD3SDyf71AiREjfy0q2EDD93gt/UMJV2CIe/RA+fIgDsR7oesW41rWXoqnaFrea2w7iw== 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=6SBEHUNiHJavSDEijDhFP1X9EW/JTL8xJUkX0CCpjUk=; b=TC7ZQZIFuOGDTALqjegahhlOJmdK6xErzFge8mCa9CvOmLSFCsj/5uBigaIeVBetZovmjdavz4hSlCOSFllGjC1nbP1RW1l6jOJ7ojtPEvhfNMhuuy++cVswXHyeNNUFmDaXVmZwEzicVfmXMfRGraywVGvpj/mdrv6UQ5i57JXYrpSccgvqMm8ScMb7tgVDTt5Gd2NAQpfYXxtSk2eFkgl8y1Vfs2cpjgOjEQWY8SZnIjSqzpM8bpHXtbQLVTkHzwdtiGatmPN78p8IOqgICuPhH/aT82RSfqaITDt/mns4akUQ35p6JLcClGBDwNSfLrKlKB8cSFkkREBkZRJcSA== 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 BL1PR12MB5301.namprd12.prod.outlook.com (2603:10b6:208:31f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.19; Wed, 1 Nov 2023 23:36:46 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::b53a:1092:9be2:cfb9]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::b53a:1092:9be2:cfb9%4]) with mapi id 15.20.6933.027; Wed, 1 Nov 2023 23:36:46 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Jean-Philippe Brucker , Michael Shavit , Nicolin Chen Subject: [PATCH v2 04/27] iommu/arm-smmu-v3: Add a type for the CD entry Date: Wed, 1 Nov 2023 20:36:22 -0300 Message-ID: <4-v2-16665a652079+5947-smmuv3_newapi_p2_jgg@nvidia.com> In-Reply-To: <0-v2-16665a652079+5947-smmuv3_newapi_p2_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR02CA0033.namprd02.prod.outlook.com (2603:10b6:208:fc::46) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|BL1PR12MB5301:EE_ X-MS-Office365-Filtering-Correlation-Id: 0166c8af-05a8-46f8-83b6-08dbdb33694f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aF4zVTBT9nYtQcqTwmT2rhqhC7HEHbAltxT8CFM48Frwp1thKMR1OqJYOjJ0lvoR6fUQ768QEMXSIZAMfHtBXFHf2oJHMEPhUdfQmkoJdVTc3rypdBQazK3AMd1kiHvXb1v6c7eIlB3pQ2z43PjHv84PZWRfcwgeM1P+82fgNKJfQIW2r53cS6r84rMTJys5/WueoVlYOPfZHbgI/OFKTzHlEMA7Mt0qYoLIVlOlPrEdSjs08YnhUXZTVsx5ibMfMOl7ODuLopAGoTqWHYgM41ZHyy0MO9RtDy9guKWmUxu8yRGZzSkordxwNWZcKte0llEH2eXWqLDTpqxNWROMFCD5aim82f4zJX6t17s6ODMhCwZuUkadm/yXMnRYzGtG1b3JQ20X0QFRvx9dKx51coZgUslS+1Lunn4pKXAwo/j+4BNNIhdzJP79o1SeURYPYJrctWkrznlVGCbTGbgHmy3JOAZgEujJoXPcLS8EsvaM2caKjqWvTLaS7SVCNrpv8nDz7K+ZzYQl1d3qOuoyd0UcK9Fv2i4q+1RE+BD3Wb6sLZJD0O23FfqyeWSQtX02yo1vzZ0lXzNsw8Sw88Ud0+xt0QveBaZmd5+6R/iJJrBlxZgVGeb2wp4zL9dOVdPuKyr1mL3sBnwQtoAa2UPZ/w== 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)(366004)(136003)(346002)(396003)(39860400002)(376002)(230922051799003)(451199024)(64100799003)(1800799009)(186009)(4326008)(8936002)(83380400001)(86362001)(2906002)(38100700002)(8676002)(36756003)(5660300002)(41300700001)(26005)(66946007)(6506007)(6512007)(478600001)(6486002)(6666004)(54906003)(66476007)(316002)(66556008)(110136005)(2616005)(107886003)(4216001)(473944003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: c4TiSmxQAjPpzl/HPiACInZzn/cFHbQVbQ3bhG74PsAzBob6Z81V2nuhPvdtnMAhetYPHofj9DJMVyRyT5nML1lhbBLPZrrkXau7Bop68+VuF04hcTq4kZ447PGDINBeKqkiKarQcWRY8qRbUeWm14yXQGCoUGHMSb5AfPKPu8NSvUX709KD6K40jXo/yk3Va+ufDonImMxbtzM9hmqOF8gYoeze0fpfdqaLj6xIGStO//71NxH1Kk3nxYfyL9gOfgD9hgSVT7bxBC0FMC7PSzZ1sqpof6jDwKqFi5z81B9Y1ULsqCNkfoXQ+nyWP6zB648fCaSvvBz8w0OBrVshiuBrBNetq6CsZGJL9pqXKgjFi0oTFt2x7ShtXfskZ5PfbCCPbW6/4R5yB4ccSb4ZPemCfsXR+xRcbBbPaXQgOANYupVl2x3mhJ185cBbgZMO8NrAP1AwIAZnV2yT+mTe0o++5shMSWj8/JFxeflbI9Cb1t0prw20AyK2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TUdadb1qoNswu7IEtxdc1W5fg X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0166c8af-05a8-46f8-83b6-08dbdb33694f X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2023 23:36:46.1203 (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: PDmIfkl1TMapqFUrP53fuXWI+aDbfIEBepvesG1mnNKmkC06ke3H75cjYmur0RNw X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5301 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231101_163700_106545_B830E95F X-CRM114-Status: GOOD ( 13.92 ) 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 Instead of passing a naked __le16 * around to represent a CD table entry wrap it in a "struct arm_smmu_cd" with an array of the correct size. This makes it much clearer which functions will comprise the "CD API". Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 20 +++++++++++--------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 7 ++++++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 9a0eaae586f2e1..80cbedcf33aabc 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1118,7 +1118,8 @@ static void arm_smmu_write_cd_l1_desc(__le64 *dst, WRITE_ONCE(*dst, cpu_to_le64(val)); } -static __le64 *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, u32 ssid) +static struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, + u32 ssid) { __le64 *l1ptr; unsigned int idx; @@ -1127,7 +1128,8 @@ static __le64 *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, u32 ssid) struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table; if (cd_table->s1fmt == STRTAB_STE_0_S1FMT_LINEAR) - return cd_table->cdtab + ssid * CTXDESC_CD_DWORDS; + return (struct arm_smmu_cd *)(cd_table->cdtab + + ssid * CTXDESC_CD_DWORDS); idx = ssid >> CTXDESC_SPLIT; l1_desc = &cd_table->l1_desc[idx]; @@ -1141,7 +1143,7 @@ static __le64 *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, u32 ssid) arm_smmu_sync_cd(master, ssid, false); } idx = ssid & (CTXDESC_L2_ENTRIES - 1); - return l1_desc->l2ptr + idx * CTXDESC_CD_DWORDS; + return &l1_desc->l2ptr[idx]; } int arm_smmu_write_ctx_desc(struct arm_smmu_master *master, int ssid, @@ -1160,7 +1162,7 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_master *master, int ssid, */ u64 val; bool cd_live; - __le64 *cdptr; + struct arm_smmu_cd *cdptr; struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table; if (WARN_ON(ssid >= (1 << cd_table->s1cdmax))) @@ -1170,7 +1172,7 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_master *master, int ssid, if (!cdptr) return -ENOMEM; - val = le64_to_cpu(cdptr[0]); + val = le64_to_cpu(cdptr->data[0]); cd_live = !!(val & CTXDESC_CD_0_V); if (!cd) { /* (5) */ @@ -1185,9 +1187,9 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_master *master, int ssid, * this substream's traffic */ } else { /* (1) and (2) */ - cdptr[1] = cpu_to_le64(cd->ttbr & CTXDESC_CD_1_TTB0_MASK); - cdptr[2] = 0; - cdptr[3] = cpu_to_le64(cd->mair); + cdptr->data[1] = cpu_to_le64(cd->ttbr & CTXDESC_CD_1_TTB0_MASK); + cdptr->data[2] = 0; + cdptr->data[3] = cpu_to_le64(cd->mair); /* * STE may be live, and the SMMU might read dwords of this CD in any @@ -1219,7 +1221,7 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_master *master, int ssid, * field within an aligned 64-bit span of a structure can be altered * without first making the structure invalid. */ - WRITE_ONCE(cdptr[0], cpu_to_le64(val)); + WRITE_ONCE(cdptr->data[0], cpu_to_le64(val)); arm_smmu_sync_cd(master, ssid, true); return 0; } diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 6f62184eaa2434..24a77e0a97898b 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -282,6 +282,11 @@ struct arm_smmu_ste { #define CTXDESC_L1_DESC_L2PTR_MASK GENMASK_ULL(51, 12) #define CTXDESC_CD_DWORDS 8 + +struct arm_smmu_cd { + __le64 data[CTXDESC_CD_DWORDS]; +}; + #define CTXDESC_CD_0_TCR_T0SZ GENMASK_ULL(5, 0) #define CTXDESC_CD_0_TCR_TG0 GENMASK_ULL(7, 6) #define CTXDESC_CD_0_TCR_IRGN0 GENMASK_ULL(9, 8) @@ -591,7 +596,7 @@ struct arm_smmu_ctx_desc { }; struct arm_smmu_l1_ctx_desc { - __le64 *l2ptr; + struct arm_smmu_cd *l2ptr; dma_addr_t l2ptr_dma; };