From patchwork Fri Jan 26 18:15:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13533242 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 ADCC3C48285 for ; Fri, 26 Jan 2024 19:20:13 +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=rwkLbEuwN6IplRdLBYpemTGljTymnDvZuP9gsG3H1+k=; b=sgEsikYemN6Gqn gMob/s5TmNWhA2OxvdZ/c5iiXFJ7buqKSoBXpeD0mUnLGZdFuZ5XZIkvvE14U5c6a9cXD6r/jMIDS bLwEqF9kIK37yRWIb9OeJIKk04Zg6lGMr6nhhPp+Rg2jlnEcPAUyFLjG+53rhds1pgX7izoHoX9LL kruSJODBz7EaNXuasGZnN/ayQK8NctM5MRl62aeUIKPeHb2hSbLGKM89NSGnXYsFvHwGS9U2Lwsdx XGrGS++zJ91dU2PqWMIJXYfcdUDFmT0Yn3YNmXXDkh/NT23ukOylLGslPQeuGHnLQQozCU+W1rWQk gAqpxz8io5gQ/YdjGPvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rTRkB-00000005C1J-1nyM; Fri, 26 Jan 2024 19:20:03 +0000 Received: from mail-dm6nam10on20605.outbound.protection.outlook.com ([2a01:111:f400:7e88::605] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rTQkA-000000051Vs-19A1 for linux-arm-kernel@lists.infradead.org; Fri, 26 Jan 2024 18:16:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aOe0K8pSoDd2zDTXyvwXXLC4q7PxdIcn++/a+/UTIqccbCKQS5fqOmcfGrtLXZnw1lWjkh+Euk9MfMK1vgalKNq5GN420Z9su9XTK0a5K1NTdI9dcL1duOb6Bi9ZOD+TOdXwemWAtb/C9KkNoka0fIP/K187e+jGC0b6reh3BRczEv2PK2+oqtt7COBUjrMPP3245osIvvYfjUh0OubVCD1EErPjMgu+zUIiYdn3EIJbmRAape3ziQEYkFS4WlDYxzGqp/qgSTVVsDIi82CRagmY0P6qBXfQAQlHnxM/bDFBdV0a50gWMZlCqluzTKS1L1KxRRDPljnEliJg+kBTNw== 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=k0zbDOBIoFk6JE6MgIKy9eXE0pi/4oPD9NUSlezPX9s=; b=ndWH/50wsYEv4W/ptqAEll3DrzJb88ZD4HQyh9hhlmt8nfo/+79VHXMKbwOHvMrW+PkCJTDUWGNN/50VpEQ0a7iGaCqEy/PGgn91sKm5Ohi19r+z5BR0Hk/9KECsOhAB2q9zlZDvCRdbU+y2s0AoFQKWOzqD0AlSXE6sOrHc/Z16QNCRBXJcM/AfVs5ssAEMwm3zG69kF/i5GHGgK+eJD+lM9mEpJXFh0uDEzXx+C+WV4fqWaSUuAtXM+7OLjPZQIDSobyxPJDKG52lqAFlWxONh6sR9BgHFgekiWMXAefFKng1xePZcDFSWGILTlwtSpOoTaWoqL7FcuDipcroIKA== 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=k0zbDOBIoFk6JE6MgIKy9eXE0pi/4oPD9NUSlezPX9s=; b=QaRF+8lcIwdrchE1bSmQIYd7mgZ8lsXGRIST/lyIel4GYvzJVNtVq7uTPkK3wsHLM41ALB+k08jY6uviEDIWFbaSAufcbBltc/njfwFR/U+qTFIWQLVfOuVFcYpildpfbSNkkfwEVddUAKdGg4nnkDVmnCF6Iy0kX/Lw2BzcAABZHAaHL0p5zVfevC1QwLz03MuvE/zZLxmwlwX4zeOMGAq16ijsBiSixo/W5uPeV3fYDuN8QSGI/q+DEg/KHS/Vz+Ku0NYLoSj8zdEO6z/CEBQwhHncXDe3+dxV4bOquN2AkhuoKiAM/Bo7tnM/KxrPRMTvpk/ODlZPwXqkcN0TmA== 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 PH7PR12MB7185.namprd12.prod.outlook.com (2603:10b6:510:201::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.29; Fri, 26 Jan 2024 18:15:40 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7228.022; Fri, 26 Jan 2024 18:15:40 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v4 04/27] iommu/arm-smmu-v3: Add a type for the CD entry Date: Fri, 26 Jan 2024 14:15:06 -0400 Message-ID: <4-v4-e7091cdd9e8d+43b1-smmuv3_newapi_p2_jgg@nvidia.com> In-Reply-To: <0-v4-e7091cdd9e8d+43b1-smmuv3_newapi_p2_jgg@nvidia.com> References: X-ClientProxiedBy: SN6PR16CA0041.namprd16.prod.outlook.com (2603:10b6:805:ca::18) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|PH7PR12MB7185:EE_ X-MS-Office365-Filtering-Correlation-Id: 8a3a7bc3-c980-4667-d6a7-08dc1e9ac947 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hRbHwqy7BIMMyXDpLUicY9zvLW99nAZqiC4UGjifw3zUYUfqFg77oeIGqEB/wpOPg4KMDirDvzyQiUyt5Zz/i0pjwhcjtkZYndfvSgRjC7/TbQ2DmIvNBfL59/p60JE8Fdxnm5h4efgd3cfNY4bKpWFzag0MGGVpYwkzEPBwgZoUK7qWscCvyrf71qKeGLmA6ldXDzTgsVXXpxYmHHeNlVNJJqicX9OAOSRGD0cPdomHSQRg6UGLnvHIffXuZcMirdfnkS4ELY+TxvIX2k+FUJTtZUXf4HUpTr4dbdWyt+AOSO+ejg6oyPcrdlnatFuR3ArgNKE96V954Gn6KycM9SSFGxjeahgn09ZYvzxG62kqM14n0HnD3Tyhx0yeGq8CfP9+cO5Ct5UXXvhBd6xsazNJHt6DuzAQqtX/jAYcuMHTzXtwovn7yeeNWleMA5ubv0KT0r0eGMNPABaGtUzFQWzZRqtfn1vwGxw2yDgegJzcn79STTbLI4g/UkrPUUvBezjb+ZLiJex6rU4zV9vrwtGq02UKwIDOq/CQCAp8W28AuUJcTbqZRx3aaxwBjqGW+Lyrs99PtzDVV7yzOe5QANsLYGbbDMkkF9dggnAbX7PKODJJrg9Di7AMyjZs5qc57xDbJUGhhaOX6n7ZDs4eig== 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)(346002)(396003)(39860400002)(376002)(136003)(366004)(230922051799003)(1800799012)(186009)(451199024)(64100799003)(8676002)(5660300002)(66946007)(316002)(66476007)(478600001)(110136005)(54906003)(26005)(6486002)(6512007)(6666004)(2906002)(8936002)(7416002)(2616005)(66556008)(4326008)(6506007)(36756003)(38100700002)(83380400001)(41300700001)(86362001)(4216001)(473944003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: KNodjc2femEDmITVCrQlhnS3+Ke9Y4rEoLbWaDAKzl57lhdg/3XtEV9fPxD188zwbie5Iw0pz3QU6IdlLRfrFXitD/WKQOanaJD8G+vIOFx7hjF9cUInq7qdHAoM3CwNhCP1V8FcdUMm6HzctIAeKCGFNNfDXWlV/d3tPEc7JPQbCqv/2bWxnuxbCMh+YPPyOo7+jacjZ3UXy3l0k7Zec3rH2MLVIPAJIinnqb4L9U2ZO8bBshZy1kWHtI5e0tmhE9MVtazCFPVfqm7oyZhemL1Qwou+zqOyizBfALC6WiqBM3FxDYN0ewLM+6xLEyS/wOMfX5hvyRVjSRVDPmSLKK1OqkKMyRwQ8OeJ38wu0/BuiQT3M7BNN7Tx3X991ln7MzFFVAfrkiJ+JZ2T9UA3a0ib90sOETkMZC8x82dHh8fSs62eA3Yt7aSQp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lBe3P5vOicPoM/bv5JwtwCPMuNURYKM45U78cQQ2I8WImHEZcOZmDVP//s9W/+aYgFO2TxHp+wFz2ZNS6+yg X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8a3a7bc3-c980-4667-d6a7-08dc1e9ac947 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 18:15:33.1533 (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: hFCRT6FvBW/nUe7UYeem31TppW8s+3NRS+crJxLrFmRNNIWjvHgsbsS3R2k0UZWE X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7185 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240126_101558_513769_1F1F1E5C X-CRM114-Status: GOOD ( 13.38 ) 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 710016ec41af13..7798a53e14124f 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1173,7 +1173,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; @@ -1182,7 +1183,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]; @@ -1196,7 +1198,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, @@ -1215,7 +1217,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; struct arm_smmu_device *smmu = master->smmu; @@ -1226,7 +1228,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) */ @@ -1243,9 +1245,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 @@ -1277,7 +1279,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 23baf117e7e4b5..7078ed569fd4d3 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; };