From patchwork Fri Sep 6 15:47:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13794409 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 36BABE6FE2D for ; Fri, 6 Sep 2024 16:01:48 +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=6VSx7GJjByykq3ngj6XltgXHh4Jtvz7TnXubglStN+s=; b=rPSauHNtmG+DhvwB3PyBFUb9Y6 HrOVN2dcLBPimuKSu83k9+FUpHe1w6JCeVea1R/aBPc9jB7SrmUmEYBCkPRpmnkwXXuvKxBB/Bcfv 4NJvmJZBALrK74VPukX0Nrq/2HK0KQJIHTOqhOkUsa/kQWlIgmAROC0TRx5Dkn4HtUCrmofZJeVAU ZLbh04BgzzLaMwxUYhgn2bu4fMW9DmmeKBbxoNVbSaeSpZmnohIP1bZr+mCDp0HUeeNo5ARHn3QT2 RjRygnaRW/cgW8I0sYRk2JIRwV6xP7K8lwlHOUNBk+/Up0vq3t4et45nEkKvzkFFKDeFvpoVEHqRG XXZJ/aew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smbOx-0000000CsYd-2Vkh; Fri, 06 Sep 2024 16:01:35 +0000 Received: from mail-dm6nam12on20618.outbound.protection.outlook.com ([2a01:111:f403:2417::618] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1smbC9-0000000Cpl0-1AUg for linux-arm-kernel@lists.infradead.org; Fri, 06 Sep 2024 15:48:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ISOr/zRsqTLnlXKXZjcmrp6keRJfymdWiFavBJEvmpX8l11tgVmFoN17r6Yj5tBWQGkd232WgTUqmhkkQ8emDvX315OEXmOo9NvYV1RXvaOoQSsCSjmEodtmbbUpIxUpHTOS1qVW2UFjCXXkf0SSCL7hbeOi6UjuK6z8GbRxvLKQYl/Y+HI5L7ex3MdyscHUauP1d2JMPz8cf3lYEQQ+6PfPwXuSG2jzSLcTxHm/Ar/Ei9QVywuGwpeXpdVbsoAOV8OA9wuzVP8S+OAU2k0R74fqa93145BVpR5y0n4qjsDl0mpbyfZd1ywH94W77ck12wtanfolPYfl1uyGoLvaNQ== 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=6VSx7GJjByykq3ngj6XltgXHh4Jtvz7TnXubglStN+s=; b=W7Eb/q/FG1yFd9z46QUVn1uCbmLk+gCI7ejm5iqbK/Aa/yVdzXDr5HwRQbNRruYD+a+6EMQ+oO8IbDfZ8ceI3CJBR+mcvN2GnAePOwvIRBph+w7th0wgvLgTKmhRvQgFDlG1z9fOIyDxwV2JTXyARQg1YfSdYt8NM+ZHsw10Pwcfcq3Ggn8sGd+X6XRZCsDMx6nwaYVsNySxTQY4AozGkqMCDZRwMevCYcxoRNeDWmddehlFWoB/8/r0wVE2FE1EpGT+VC2eCeCvWHiuXb821Nq3FpKJ6RA3WKc5UGiZ9LauIHMfHDwfz/by4LfOj2v1ggn8CQ3NTFD+RnGbN4duog== 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=6VSx7GJjByykq3ngj6XltgXHh4Jtvz7TnXubglStN+s=; b=LrjwMDaeoMeLcspnCpTs1pW/qMJ7qWRkbWGw25dqnGL/jYwblQnqYYSHywrQbwVYq77dtBIZWhwWiiUwrt8tlCP5dAA2XGwsz4kAVpXOcqpD3/YN821gsgFFeKt8jGsNA3cuRTtS6nV9Era02me0oelqW7f2BTk77vtxU5nWbPC+PDmPMeeQn4mLGWnAfritq93kDu4t5VB/QQHvha7QqLssw5vyLAhwa1DH+ZFbcp5MmKmUsTMJ6FU9kgTW72FnRVVdOFeDQJUY9HllnAfLOs+ENR5vzfk+xUjNcS5PEYdTPriMAyTpeRAy67YAytRNETgV80uLtPGP7ger6lLK8g== 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 SN7PR12MB6792.namprd12.prod.outlook.com (2603:10b6:806:267::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.28; Fri, 6 Sep 2024 15:48:05 +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.7918.024; Fri, 6 Sep 2024 15:48:05 +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 v4 2/8] iommu/arm-smmu-v3: Add types for each level of the 2 level stream table Date: Fri, 6 Sep 2024 12:47:49 -0300 Message-ID: <2-v4-6416877274e1+1af-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v4-6416877274e1+1af-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR14CA0008.namprd14.prod.outlook.com (2603:10b6:208:23e::13) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|SN7PR12MB6792:EE_ X-MS-Office365-Filtering-Correlation-Id: eeab2ba3-4536-419a-4a44-08dcce8b4791 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: pOtZYJH9AAQmzTeBisKdy3H+QuY71utvSknuAXwUZWFrl8dTj0z3zti59AfRT3BgWVlcvjrNWWRhyzfkcjOAAJ2YyEXkTdGdAcpMCa0Cjv4h4oQ8YKIvwwCt/9+zzeJ0ptKOsi9Zm5bd0TPr8Ojvo9gfHXmRKkyJku5J/fDwjeojKMezeXiXeSwI11fr7hH4+Fav0UtJQULEWl4IUif3zi8Wvz1sboBwaRKFkU/tL+kKd/p1u0lBhW7Z5ScVtnnnKB6mSwZolFYgwKHzafsPKotU1zJD1JGohrQ2HSzZG4fM6kl85okLS26i3NRyzSx13I9FU401YcUWmmSuvS8QeJzQp/XTf3BuwA58LNe+7lKVrGD2+Z68XZ0b0jsljRMN1UCkLuHfNx05jQldUQDACInSgCusn8RqRLEXPkMOJ1JFbJHgf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FN+gM7rVl6Etfe2cjQq1K2bZDGiA0wFcvURNaG+jWKfnWJ3/XoqLFfFurweLn3J53fHWCc3nNBwJMN9AE5FFfOQbBhuqmB+Sx+Qnb2Wy79S5gJsaC93Mh7lZiFSeJxYNiG3g26FCTqTUlAeL8lZJ/PSIErJLwr5zD5oKUTMWAcXvVyzpTT/dnja0PhPJdHXSLSm/Fmm57RExapypArD8eWg1dkvAczSD6sQaRI+EsSfLRI+7Woe8lc7vPWlgndPs4/Xcw+z+KYaqCkCCqvmClkfxAuI/dmjSv1SH79D+bzConVuce87ftyQu+xQ+LU+ac25jYCXvt2E8LgRy4WvTwbPCDxlfn2BHE5q+xYDsFJVAVCqxxoMWDunKoe5NyisZaKklrLfcYAVy96xX54XAxLRD2X/7dFMVWjfYpTZRnIw54dDBbyO+ite9r2uvVAaIqPzl0BvO7CCIVVmqnVsm8mD792z6JJBthdIyDn5H+gyzih+0B0cMIxlK6oJ+Wacc7lXHH+yC+GIcQSLyJHISAFsFV61wWD1wuXdOhYGhbWjruBCuA9F0xXpwmoNzLDt2qN9jLxsKNb4muw/oKMqs7W7sHxhXTPYqKjcl2+ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: eeab2ba3-4536-419a-4a44-08dcce8b4791 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2024 15:47:57.7368 (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: kF+U2D2lUfHQpjFZiEv/vpZ4r8ZsAFEvlWIc7P2QhhEeS7FINkBLjMT/6y3uuwOS X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6792 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240906_084821_362620_F85E42B3 X-CRM114-Status: GOOD ( 14.48 ) 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 | 21 +++++++++++---------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 10 ++++++++-- 2 files changed, 19 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 cdf146bad5bd24..f9faaec946c294 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1496,7 +1496,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; @@ -1504,7 +1505,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 { @@ -1709,18 +1710,17 @@ static void arm_smmu_init_initial_stes(struct arm_smmu_ste *strtab, static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) { - size_t size; dma_addr_t l2ptr_dma; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; struct arm_smmu_strtab_l1_desc *desc; + __le64 *dst; desc = &cfg->l1_desc[arm_smmu_strtab_l1_idx(sid)]; if (desc->l2ptr) return 0; - size = STRTAB_NUM_L2_STES * sizeof(struct arm_smmu_ste); - desc->l2ptr = dmam_alloc_coherent(smmu->dev, size, &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", @@ -1728,8 +1728,9 @@ 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)], + arm_smmu_init_initial_stes(desc->l2ptr->stes, STRTAB_NUM_L2_STES); + dst = &cfg->strtab[arm_smmu_strtab_l1_idx(sid)]; + arm_smmu_write_strtab_l1_desc((struct arm_smmu_strtab_l1 *)dst, l2ptr_dma); return 0; } @@ -2487,7 +2488,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 @@ -3643,7 +3644,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 7d8ed274af40e5..b25dd72179415b 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -206,7 +206,6 @@ struct arm_smmu_device; */ #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) @@ -217,6 +216,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) @@ -608,7 +614,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 {