From patchwork Tue Aug 6 23:31:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13755490 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 9EA3EC52D6F for ; Tue, 6 Aug 2024 23:37:31 +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=KZZoo2aiGFcC8GHomd95Q5u1fLWQlnX/Du5UTasLzFw=; b=S/EANL17WPQ9idpMIk3en4hk7t WG+fTfIvQXNZ2ka5EWAZhwaZg87f1K6bmR9MPg/ppPUmfGMzthbgpapNOnA+0qrD9H31t07fBRKqd FJkpm5zuAynSZyShvnKmav7Cf51VFHzPOiNQgpc4OjX7fts9MdCnIPgeZo0M/8Ci5jv6TMmgCMUAN Pf7tCb6yRD1l8cPFzT36JnZTyI6LNTahcQBmdlUKhsh97YPs+KqSnmpy1yG+5P+k/fIYevnDoy8N3 O+E4NjcUH4n0x+4t6tQYb5hSGN9YFdozJW1dT5SJQhOq885YbEUh4GBKmmqyctTyYji97YuVYPmMY Ija3CctQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTjx-00000003L8P-3PbA; Tue, 06 Aug 2024 23:37:18 +0000 Received: from mail-dm3nam02on20601.outbound.protection.outlook.com ([2a01:111:f403:2405::601] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTeh-00000003Jej-0nbG for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 23:31:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qxg9Y3tWusQX/WIxIpAUZeXyw5S/xHDm20Lt43GhAmjcUEOhJxev4zpmc64KD/LFe0/S0A+glx6n2ZMqQ8pD9GlnKwJO7vd44x+LJ3gT5Mtk6EDhsUecfEqQxCrg3OqKg6XikDgTbD1/LGXy0JU/t2JQGHQGS8m1o6wk+r9rao/OSKd1/P02aJVvcModZW905MFAWxwCigQzZf+mJXRUdJIW446YfvbaF13Y3NQiYrioFsnfwHo7U5OAjyhgY/zBYOeTHAyal91I/q83ld9KfEHPczuWI8yKP5oEfJ6iUkMq4TOsAH0wVxj87YzzkDfR31QvUoa6zat1QidRTm6e4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=KZZoo2aiGFcC8GHomd95Q5u1fLWQlnX/Du5UTasLzFw=; b=LxF3iJk0lZZRSgju+ihe6UVdUadViP0ZSdk7EgJQ7kx4Bv3+v5D4efJ/d7Njgl7hDhYaPhuBjnUkS3vjCCeBVn7+De677Ndfyx50Q2pmSEuWetfN1U5UFXfSBivR5xGrefAjzZe+j0KcyAa+uSUQ9pWo5YrbsV6yOToEMWsIjhRRYVjx4XOWY7clnS+uXg3ix48ahVoVQ9FPIoxHS+FhFWjtDeAVI4iq1UWYzmvGlY26y7ZljA8/PTbG7607GizUwXh1yYxkLhPQzwGytKbG9T+UvlGu+FHe0iU4JjWPrvN7+4nj0BCLpTy8zgSqNVmqlMObDbO4BSR4eGUh6btsnw== 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=KZZoo2aiGFcC8GHomd95Q5u1fLWQlnX/Du5UTasLzFw=; b=rSeq7ns3YR4xSIgnUMS3kkiWesnAdQVbqUOlLiAcU86rx5FlF4AjvWxs+MBzvTJFhkHWX+rpOhWwy/V01XO2N1+0cD4dxBcDv06vIbCdD80OvcOyCSJOfFx2cUaeFwmbPxQo7ZwXvtZRrYOmyvwF0suA7MuQMGGMMRbv4gGx7psKqfiYlI5rv6IXMQH/MKLi/rC+9JK3Uh2nrJIuEabXjyuA/mfjdAQYID5UnAN7SNhK5ENTfKDwy+JeYqnKth9wNQPuoxmLiA9alnq37AFdqRibBmwi/QMGh34QZ2H1km2HYVLPIKpKbsWl7VIWbTYolcsKW39LNBMg4Qplns4JNw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) by MN0PR12MB6248.namprd12.prod.outlook.com (2603:10b6:208:3c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Tue, 6 Aug 2024 23:31:29 +0000 Received: from CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8]) by CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8%3]) with mapi id 15.20.7849.008; Tue, 6 Aug 2024 23:31:29 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Ryan Roberts , Mostafa Saleh Subject: [PATCH v3 3/9] iommu/arm-smmu-v3: Add types for each level of the 2 level stream table Date: Tue, 6 Aug 2024 20:31:17 -0300 Message-ID: <3-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: BN9PR03CA0097.namprd03.prod.outlook.com (2603:10b6:408:fd::12) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|MN0PR12MB6248:EE_ X-MS-Office365-Filtering-Correlation-Id: 4e256306-6d11-4138-2189-08dcb66fe351 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014; X-Microsoft-Antispam-Message-Info: ecggRX0cu87zXlHYLQQEKSB056S4w/Agb/f4CcsmLsMY4aFBTQ/4lBkUEOLEmnv9DrOSH9zu+BPt5IhrM/unlkbfGPuhZpQ36+1nh+e+RdLqfTj7HYNcnnjXfjcQZIchqMPo2sOY/ReH5iGVyKiENRuCcSK22cWPMPLVcmJfSeZ5ZjRi6hcLimQAwR3LKIr0w8tXcDR2xHTRK814Q8CZc5K3t3UmTDTEMhbthX1O3W0gxmZH/xGSQ0Vg+2gUriKr6RsmxzJEiK53Be35vMWfs24EWlAw+3cE2CLKIrg78KGHuj9AErnLMR57Vh8+ND9H9kkWaxwE0DowVHFHhaqoBCFqseZV1JHS7UnpJe5dh0vGSCFRIgYrLO12RuMvhBAKGDWn9a19PAxWsL2APvXNA/hxaFHzP0is7jGcugvwlUfH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SWxt7mUblwrOohGfvkZ7PheDeH4Lvbzr4aiean/fgOFJa34i3C9r0AEYRYiH/XPWoR2HpyjWBT7sLshEOJ9EjXa1ONJBb5lozTev/jX6DK8qpJiL1wr44ujQgkFsUWmk8sqL8CdOHAcGulYt36yp+5vAnJZvLg3uhzZ8Rc66EJsX2cHegesYQK2OiNs4DIzK23aSVeZT+X9yDRnRdGiMwBpC+zc7Kr9GSQkI1W/5K2EruK8xrtn4y681XWvyvC0hsqj7Q7ECL0aqR87gJX1AVA6VpP8T8jxOYgZBIvgOvNmTsZvvmHcdNlt1o/Iax5YKP69OFMy1ZBwePp1n1SrlT6rwtXUxfiGRVEJa9bofB1bbDGoiZTsv8F26XSF9x7I0q/DBHSAr46+Kn7SVzzq8jIu4SssxRchGoKrXXzywv8pTDz0/1GR7/nE56/DX2zbb3i6Df33ehGRuJ8W1wa8Qd+NJ/zOkH4gJaIsNxq2wNCOaxI3yTaLuA4l+0rqQ6qHFNoRzob8SMipBz17XmvJeCajnNZYC5nAhsTIu+88hNRp5qrUCZ6Tx0SZwS2sciiqBFNI= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4e256306-6d11-4138-2189-08dcb66fe351 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 23:31:25.2023 (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: UfJ93bj14vWS5tSXYxNha9OuwXdpGdCgaLLFgRYX3UsEHKX5g2TdhV63iUBugfFl X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6248 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_163151_256645_94C0BE2D X-CRM114-Status: GOOD ( 14.10 ) 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 Add types struct arm_smmu_strtab_l1 and l2 to represent the HW layout of the descriptors, and use them in most places, following patches will get the remaing places. The size of the l1 and l2 HW allocations are sizeof(struct arm_smmu_strtab_l1/2). This provides some more clarity than having raw __le64 *'s and sizes computed via macros. Remove STRTAB_L1_DESC_DWORDS. Tested-by: Nicolin Chen Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 22 +++++++++++---------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 10 ++++++++-- 2 files changed, 20 insertions(+), 12 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 a695e5f8fc2880..7a2d102fc11eb0 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1458,7 +1458,8 @@ static void arm_smmu_free_cd_tables(struct arm_smmu_master *master) } /* Stream table manipulation functions */ -static void arm_smmu_write_strtab_l1_desc(__le64 *dst, dma_addr_t l2ptr_dma) +static void arm_smmu_write_strtab_l1_desc(struct arm_smmu_strtab_l1 *dst, + dma_addr_t l2ptr_dma) { u64 val = 0; @@ -1466,7 +1467,7 @@ static void arm_smmu_write_strtab_l1_desc(__le64 *dst, dma_addr_t l2ptr_dma) val |= l2ptr_dma & STRTAB_L1_DESC_L2PTR_MASK; /* The HW has 64 bit atomicity with stores to the L2 STE table */ - WRITE_ONCE(*dst, cpu_to_le64(val)); + WRITE_ONCE(dst->l2ptr, cpu_to_le64(val)); } struct arm_smmu_ste_writer { @@ -1678,9 +1679,8 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) if (desc->l2ptr) return 0; - desc->l2ptr = dmam_alloc_coherent( - smmu->dev, STRTAB_NUM_L2_STES * sizeof(struct arm_smmu_ste), - &l2ptr_dma, GFP_KERNEL); + desc->l2ptr = dmam_alloc_coherent(smmu->dev, sizeof(*desc->l2ptr), + &l2ptr_dma, GFP_KERNEL); if (!desc->l2ptr) { dev_err(smmu->dev, "failed to allocate l2 stream table for SID %u\n", @@ -1688,9 +1688,11 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) return -ENOMEM; } - arm_smmu_init_initial_stes(desc->l2ptr, STRTAB_NUM_L2_STES); - arm_smmu_write_strtab_l1_desc(&cfg->strtab[arm_smmu_strtab_l1_idx(sid)], - l2ptr_dma); + arm_smmu_init_initial_stes(desc->l2ptr->stes, STRTAB_NUM_L2_STES); + arm_smmu_write_strtab_l1_desc( + (struct arm_smmu_strtab_l1 *)&cfg + ->strtab[arm_smmu_strtab_l1_idx(sid)], + l2ptr_dma); return 0; } @@ -2449,7 +2451,7 @@ arm_smmu_get_step_for_sid(struct arm_smmu_device *smmu, u32 sid) if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) { /* Two-level walk */ return &cfg->l1_desc[arm_smmu_strtab_l1_idx(sid)] - .l2ptr[arm_smmu_strtab_l2_idx(sid)]; + .l2ptr->stes[arm_smmu_strtab_l2_idx(sid)]; } else { /* Simple linear lookup */ return (struct arm_smmu_ste *)&cfg @@ -3608,7 +3610,7 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) ilog2(cfg->num_l1_ents * STRTAB_NUM_L2_STES), smmu->sid_bits); - l1size = cfg->num_l1_ents * (STRTAB_L1_DESC_DWORDS << 3); + l1size = cfg->num_l1_ents * sizeof(struct arm_smmu_strtab_l1); strtab = dmam_alloc_coherent(smmu->dev, l1size, &cfg->strtab_dma, GFP_KERNEL); if (!strtab) { 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 45ec88c9aa355f..3a8a459f899fd8 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -204,7 +204,6 @@ */ #define STRTAB_SPLIT 8 -#define STRTAB_L1_DESC_DWORDS 1 #define STRTAB_L1_DESC_SPAN GENMASK_ULL(4, 0) #define STRTAB_L1_DESC_L2PTR_MASK GENMASK_ULL(51, 6) @@ -215,6 +214,13 @@ struct arm_smmu_ste { }; #define STRTAB_NUM_L2_STES (1 << STRTAB_SPLIT) +struct arm_smmu_strtab_l2 { + struct arm_smmu_ste stes[STRTAB_NUM_L2_STES]; +}; + +struct arm_smmu_strtab_l1 { + __le64 l2ptr; +}; #define STRTAB_MAX_L1_ENTRIES (1 << 17) static inline u32 arm_smmu_strtab_l1_idx(u32 sid) @@ -597,7 +603,7 @@ struct arm_smmu_priq { /* High-level stream table and context descriptor structures */ struct arm_smmu_strtab_l1_desc { - struct arm_smmu_ste *l2ptr; + struct arm_smmu_strtab_l2 *l2ptr; }; struct arm_smmu_ctx_desc {