From patchwork Fri Sep 6 15:47:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13794405 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 3DB88E6FE2D for ; Fri, 6 Sep 2024 15:57:41 +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=McuXPTXyQ5FRCyBye6+FrLNwEcFfYllq2gUqemMhrVI=; b=mpdMvCu4cLDMYYLUQNRBB2RV7c 8l5Sg6iVBcbw85+GJQ2zW50ecVrJ3VvHulKT0Feqlri/n1jkGgR5GuKjtMMnebMcGxs4Z6IVlGgUi +wkF8IXuVHof624/p7JceRx0CLR9wxJoWpQqYKk/D3muc/S+yUa3pRgYqrL7V+/y3qwYiPAdU3EV+ BgDGMcNupDlLUaXDzQJf6hayM7RWVfYxJXG38Me9SBEfiiOa3jSClhmCIF1JaP5XWuE8Jd1Nk5WGL T7F8sIEJzuQ9ZV214NX6NwxTED1XSFx9k3znC19F0TtdSvrTkMOygv7Rz92eFEIfLa1sqFY1vonFp jODp3krA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smbL0-0000000CroA-2s3h; Fri, 06 Sep 2024 15:57:30 +0000 Received: from mail-dm6nam12on20627.outbound.protection.outlook.com ([2a01:111:f403:2417::627] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1smbC6-0000000Cpj0-1PCD for linux-arm-kernel@lists.infradead.org; Fri, 06 Sep 2024 15:48:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RUJSZsr+LtbTZvU88QGIZ4yuuvCt8hcD9PDNwGFnJ2+Kael0PYv2Hjn/rW+CxLb0mFLgFlZc6qViyQZlAg8b7wUJwIBIR73CI3LyICVXPS67V8eZkBoBo8jeMSuBWGnW0x0ERRPNZDAWvmhhrPogTfkmFkeOIKebqkmpps8oDn+dnX3ytlbAuvSQclp6f/vXaI7emTFaWbNmdtmE+wmWWp3z7mT4RFy737ZNwYab+gkoQcK8/qDk7gd2QPdVITciRLaycvBdHkimk1ERDrQNAAvVasWEoil8rE+vMu9egtMM1omSOX5dVg6PCzvFGrLFmAVo44BsdmQWXnjlR3qWHA== 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=McuXPTXyQ5FRCyBye6+FrLNwEcFfYllq2gUqemMhrVI=; b=r/0Tz2bfS9VMXrQSPCHUOCBnDz5BpwS3w91SIVVBn4wKMOdGX0d4SUSgUmdeLcQadF+veePkivAB79Vfdg5SSQJVyD/pK7NE/P4c4tl/dYYwenp9JLlje53tw2iuoxaff9yL49/vBo+0Uu4hqnj9cGTgRELyDEiSw1H+Lf06UgrIC9/fvoZ+cziR1BKVpWWL6ZdTQ1FTMrdsCjJaVo/cVA8//b31B7Lfo4g2gG7L7/kLfm4CvrZ0zZgXwZjNIMuFVY1urfMljWWZWWn8+eJ7JnVQQWQNlBQTsjT6q3oCljlEQB6T9paNlqP1ibs20/79PcZUaxEST3TNCZQor4wqww== 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=McuXPTXyQ5FRCyBye6+FrLNwEcFfYllq2gUqemMhrVI=; b=WFw2KMd/UAI4GyMwG79KXfUnJi58zaJ3wYPWm4K5KSOeUy6x07MbXlE1QRgpWNrlLP7+Q2bdwNSadpXFT2FytEHA0xV+XkCXS0NUY1yPTOP50oTtDtL5nC5va5wPo89h0An24zY2CZSGsMoQJuhYRRLUo9DOkJ13Dck9VdoC2tv8Hi4/+zfChb7G2t3Mzj6sY+ebCg+HyW0tRY9yVvlEfzl7tXZ5gcJEJgzcjycyudMzJM0n8smi2JYq8GHO0VtcXHL+s5UmFOOSEDH8dmnzjaNYLVm90l/q81fgW1fJZoCjU5/kh5DCbTmdda7PeEl2Do7Ps0xPy5TaMQZqivC3zw== 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:04 +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:04 +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 1/8] iommu/arm-smmu-v3: Add arm_smmu_strtab_l1/2_idx() Date: Fri, 6 Sep 2024 12:47:48 -0300 Message-ID: <1-v4-6416877274e1+1af-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v4-6416877274e1+1af-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR14CA0011.namprd14.prod.outlook.com (2603:10b6:208:23e::16) 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: efa3b6d3-ccf2-4aa5-b3f9-08dcce8b473d 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: 0bqzAdE7yTllDuZaLyogp8hCQzGLW8p5O7o1CDEEQ+bXg5FpDDj5cOm0LceNx0pPzMSywyicrJtVRQ844sZLjY7HrvH9wRvrCrHHKVsjn/bp2QcbNT8Th1DZhhKmiRiObnlUsD/4YbNkYRBeSL1jVG0w7QeWwwLJ5+q3rbLsmHA6PhykV8HkBSm0ixxi1JE5kl0gEq38DSM57+zsBm8DzStlO7Y32hqR/oJxlAgHwrvo9amfrCk8eII5/czcO8cfLbwhxvi3s5beoxqv56QFJqQn5dWAQ6Dy/SE6OZWtrk+25EVpIlPZPl5AXmmX2CxeRB31/ak0bBS9nUe5x2aLBSNFfRCCUBahhlS6cghI/lhYrqq2F1NzUnSSTj3AdmNHI8igFYBpEJ5lm4l5i8MoHqNPDFKaJGue5dXAibFxNmtPQLwTrlmwi2FVhaZr21FSAkCW3bxmhpvaceNDHxeGZry/Jxg04MaJVu8kEC3vyNoLx/46EA9sHLpRxXfFa0rbAaySaNyVNYhJKqO5mkoR/U5kcK/ogHtiCgX4PGSROG3gvGK9lX3PtdDKsETIdAz0NhRX0dkyKj1IR0iC0tlUn6EXWP+sgMKh8DSOd0jYgB883Dkggjnae2Bxi6tbE7LbqJQeGn58FB0428jkU7VAFLaJv3uzhfrUM5t1MB0iGjII2oEDWJOGqEqqfEWaK1AbWYpxFKYRr9O1hiM/95guXzVsHIgUkEfs2NRb2YXWtoE/o3LXFe+92Rz0ryQmLoJRbKDlfk142XhMncT2MvdWbBZzA8OgaYl9QUwyLSTLVUa+gJgQFEval8YNDSlij7UbHj03JATncH4rkThS00bRVCi8Zrhj8MyrXCPrjekLtifPtywboHWUNs+61WYKVNch1okn+CWkK0JV7wCKiYKW3gZtRXQgnfFaT3kaKmEGiHjTYCMtgY47N50FCKC50Pjrrv+9xepqRLS+LLCZqUPLPzoZWT7SOjjwA25rtcVSjaAYpJd0CTZeNhrfb3DvPPjwTe5zdgaQ8OL1PNepC/8XOFNe6+R7P9NCre4AgCIjowsxW1V5vmPDRzbqI9+RLeIjG1FDYOj/e+MoR1BvtviVmX2kMleNGgiU9kC1tlN16D4PsdVwIalF1tKrM+u3BiJTU3E4UvbmaVSFfMFCfoMzMdt8vw1UluQ8JuoLCTr2PRD510Nl1FPfXcovZWgxV7rBGtvJhoFAg1bt6uQKnoXbe1gokcDsVwvnyVxjS05VTtvhn3Guo9iw9+VuhYFiH1X85yWQrJ74GoHUOaWyWsDQTYti2KFyZyxkAWjbJIRu8BskJUzECt7hw3KLtdUJUvLXghhiP5TX+XKjHFrhhONUeQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB7763.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wHQHNgJRtRJ3VNsKAGGKp7Z8klMXL0FSbL1WaVj3N6yOgErBaq/DtlHOm6kFSCu5qzTmFL08AlQE1hnd/Hkt6UySbWCARwny8yVVIuN2YHKVPO5sEr+36XZc8EULrkNBT4ayf3nCoEio6lJE25lU/TPI/Zu/ItgBsy0e6iGbxTgWwJhOIOB8vx8rYB5idvrb8IQXMa30kfH1Od4hy8DC/J5woRC4xfZ7dB+5Q622cThfygULNNK6Izn7FhBtYkoqrl8HPjhhYHNbvhqWEQ7hbwrV5a6dwr1LFcxy6ul0KkAwD83xv6ZbKXGUAm1QhSTrKG2xYS5r1+IOTLoAgPT3L5guz9jSThCKzs9e+IxdIU6mxW3CEBKrLkuid4jJQTDzNpMyv68tUaMvnQ8P/rpQGxoj4JfN2RRt+niAMpBT5Ag8Sz4Ypz7ei3XxUK3hC8WFEmLReqe0zurnUq1im8zAOWN0VJSSIzGQ+tg2FtsOVwZRGcTUftfhT1sOIxCzIB1HEqzcbyPIFJLcJX4ACYyhQw6przJVWpXg10hKgvHeWPVomAzTKt7QgVyK5Vu7Tj2KsejUY4aE63hKRXFmQBi/gztrzfGDcXZbvuasP6EhobJ4ZOq9kp+/jfveysh5a3/z5e8lHzBb7dwmSXo/4pCgWY57Wr2JGcwDXmeesRB8agfLGewZa6EVB1j8W/wRrfqeqB8TH3VffKUiDIZmq+3x2G+zI8YZJRusE1y50TlfvUTnSYFoEc6q8eTy/pVWJUtrbI+7rwsuAejunk5HgMoJVKvCeP3iA9Dg/KDAcPl3PrFvzMBfdSedW5Qx8hw116ZDMjmwETp3fHxf2hvWp7N5WT1O6zZHYA7LaWRmXWMt4klaw3b7+WFkofxaU/5FaSE64DgVm3med5f5gXyGHtXZgAF/0PjuDIofOO5JPj9CIPNB4CnkDo+WQu95MuoMxuxZm4B4+Sol8C5vjCQbniLz6p2mNsuKr5DNuASbnBIwXBkaXOYRY9I8bsVdqr3bSArGF6nywlNMFKxgNBXvQy08yAy+SqDB+S2eHuU0WsB26aLtkz7G8YK8Wpt3cbMteDQ9FyZwiSM6UEOwTjzqBH/aSPwD2Hte+mahde8O+WJlebTLUZd8WxOzJSwmwkNoNI7ODZs33FfVDQA6nIboyqw8yjh9N7WopHB11TjgPk/ppeo2/6NxNbL2L2V+ff/u4nHtrTpgjed5oNHWEFmVAg/G390d0dWjSEUHjueCz6nz0A0W1/fT6sYlq5BCsh5ebp08k1trfzyI1l6ZVE7IOp5BLhPxQzvrFTwRLgWOJ51t95qZCHDuY5vvqeuqpJeUA4D4NTXHAdwcBPBd7mVcuqVdIDEDbc7ZpL9ee2m+9WXNx6UabQNM0JE8rG9rv5cpI7DtfLVChSP0OriMFn20IX74d6C2xJ3qwxB8oXWjp+HB+EDfK73B7dzhzKWAS96rgrTfOtaZDfEoY4aXIvIKk1y0fAaDmj1z97EOQi1BdVwVB/8+6hrS+rYv1qU14h5zV3Bfuh7gFjA5heSGFQLAZFFVvl18zh/R5MOqr5PDOCj5NbC84AmoYulYzbW5vlTykz3Z X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: efa3b6d3-ccf2-4aa5-b3f9-08dcce8b473d 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.1836 (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: AlbYewllSp0TfeBTgRKKHi1/dhDNXA7p2cVVZO0BcVGTloaBWAiMjOhCMpnC1Bkj X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6792 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240906_084818_416262_4FDD3700 X-CRM114-Status: GOOD ( 15.21 ) 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 Don't open code the calculations of the indexes for each level, provide two functions to do that math and call them in all the places. Update all the places computing indexes. Calculate the L1 table size directly based on the max required index from the cap. Remove STRTAB_L1_SZ_SHIFT in favour of STRTAB_NUM_L2_STES. Use STRTAB_NUM_L2_STES to replace remaining open coded 1 << STRTAB_SPLIT. Tested-by: Nicolin Chen Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 45 +++++++++------------ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 14 ++++++- 2 files changed, 32 insertions(+), 27 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 fb8b71b02d96a8..cdf146bad5bd24 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1710,17 +1710,15 @@ 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; - void *strtab; dma_addr_t l2ptr_dma; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; - struct arm_smmu_strtab_l1_desc *desc = &cfg->l1_desc[sid >> STRTAB_SPLIT]; + struct arm_smmu_strtab_l1_desc *desc; + desc = &cfg->l1_desc[arm_smmu_strtab_l1_idx(sid)]; if (desc->l2ptr) return 0; - size = 1 << (STRTAB_SPLIT + ilog2(STRTAB_STE_DWORDS) + 3); - strtab = &cfg->strtab[(sid >> STRTAB_SPLIT) * STRTAB_L1_DESC_DWORDS]; - + size = STRTAB_NUM_L2_STES * sizeof(struct arm_smmu_ste); desc->l2ptr = dmam_alloc_coherent(smmu->dev, size, &l2ptr_dma, GFP_KERNEL); if (!desc->l2ptr) { @@ -1730,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, 1 << STRTAB_SPLIT); - arm_smmu_write_strtab_l1_desc(strtab, l2ptr_dma); + 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); return 0; } @@ -2486,12 +2485,9 @@ arm_smmu_get_step_for_sid(struct arm_smmu_device *smmu, u32 sid) struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) { - unsigned int idx1, idx2; - /* Two-level walk */ - idx1 = (sid >> STRTAB_SPLIT) * STRTAB_L1_DESC_DWORDS; - idx2 = sid & ((1 << STRTAB_SPLIT) - 1); - return &cfg->l1_desc[idx1].l2ptr[idx2]; + return &cfg->l1_desc[arm_smmu_strtab_l1_idx(sid)] + .l2ptr[arm_smmu_strtab_l2_idx(sid)]; } else { /* Simple linear lookup */ return (struct arm_smmu_ste *)&cfg @@ -3195,12 +3191,9 @@ struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode) static bool arm_smmu_sid_in_range(struct arm_smmu_device *smmu, u32 sid) { - unsigned long limit = smmu->strtab_cfg.num_l1_ents; - if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) - limit *= 1UL << STRTAB_SPLIT; - - return sid < limit; + return arm_smmu_strtab_l1_idx(sid) < smmu->strtab_cfg.num_l1_ents; + return sid < smmu->strtab_cfg.num_l1_ents; } static int arm_smmu_init_sid_strtab(struct arm_smmu_device *smmu, u32 sid) @@ -3637,19 +3630,18 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) { void *strtab; u64 reg; - u32 size, l1size; + u32 l1size; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; + unsigned int last_sid_idx = + arm_smmu_strtab_l1_idx((1 << smmu->sid_bits) - 1); /* Calculate the L1 size, capped to the SIDSIZE. */ - size = STRTAB_L1_SZ_SHIFT - (ilog2(STRTAB_L1_DESC_DWORDS) + 3); - size = min(size, smmu->sid_bits - STRTAB_SPLIT); - cfg->num_l1_ents = 1 << size; - - size += STRTAB_SPLIT; - if (size < smmu->sid_bits) + cfg->num_l1_ents = min(last_sid_idx + 1, STRTAB_MAX_L1_ENTRIES); + if (cfg->num_l1_ents <= last_sid_idx) dev_warn(smmu->dev, "2-level strtab only covers %u/%u bits of SID\n", - size, smmu->sid_bits); + ilog2(cfg->num_l1_ents * STRTAB_NUM_L2_STES), + smmu->sid_bits); l1size = cfg->num_l1_ents * (STRTAB_L1_DESC_DWORDS << 3); strtab = dmam_alloc_coherent(smmu->dev, l1size, &cfg->strtab_dma, @@ -3664,7 +3656,8 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) /* Configure strtab_base_cfg for 2 levels */ reg = FIELD_PREP(STRTAB_BASE_CFG_FMT, STRTAB_BASE_CFG_FMT_2LVL); - reg |= FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, size); + reg |= FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, + ilog2(cfg->num_l1_ents) + STRTAB_SPLIT); reg |= FIELD_PREP(STRTAB_BASE_CFG_SPLIT, STRTAB_SPLIT); cfg->strtab_base_cfg = reg; 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 e8320e9341d70f..7d8ed274af40e5 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 @@ struct arm_smmu_device; * 2lvl: 128k L1 entries, * 256 lazy entries per table (each table covers a PCI bus) */ -#define STRTAB_L1_SZ_SHIFT 20 #define STRTAB_SPLIT 8 #define STRTAB_L1_DESC_DWORDS 1 @@ -217,6 +216,19 @@ struct arm_smmu_ste { __le64 data[STRTAB_STE_DWORDS]; }; +#define STRTAB_NUM_L2_STES (1 << STRTAB_SPLIT) +#define STRTAB_MAX_L1_ENTRIES (1 << 17) + +static inline u32 arm_smmu_strtab_l1_idx(u32 sid) +{ + return sid / STRTAB_NUM_L2_STES; +} + +static inline u32 arm_smmu_strtab_l2_idx(u32 sid) +{ + return sid % STRTAB_NUM_L2_STES; +} + #define STRTAB_STE_0_V (1UL << 0) #define STRTAB_STE_0_CFG GENMASK_ULL(3, 1) #define STRTAB_STE_0_CFG_ABORT 0