From patchwork Fri Sep 6 15:47:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13794410 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 831DDE6FE2F for ; Fri, 6 Sep 2024 16:02: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=cPK+G/DRqkbiWej6K4XqotLhQ4Sg5GN2OAYLdilihFQ=; b=RI4y3fYQlSU8YfXMshmnaInIHE /Q65PYse96JIZSqdDCMtCHAPYOk7X+BCIZ/pt0xQ8Nt5FixGCyqeINo6L66E8unFuJsWnDc/RMVyv 86c92PA/vWMTrUvrrt0Gb/u3vVDKDvEE4wq1mBxKlD8pDgLBb4ed5zwEiwbAaokEI1aWpIFGsecjK kOsTmxX500njMibhq6j9OqAN3W2La0FcXNWm/+rBBlRCwadwKJWeipeDd0+hqSNpXh1xa+MPNBpa8 oc49b0ulVDTGwnu4BBwlC37KXW+2o4kdWgaLsxgVtTiA5nHD02S/f0gyqDqHu8nqaVsq01p5r5hsH RP6VukhQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smbPv-0000000Cskl-0JBX; Fri, 06 Sep 2024 16:02:35 +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 1smbC9-0000000Cpj0-3CeZ for linux-arm-kernel@lists.infradead.org; Fri, 06 Sep 2024 15:48:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=h2uvx+c1lR8sk+kmC72OivjE7nUrLc1Vg+P7wf4WfQJASNfC4Xxp1AWPl6lMm2P4OUEfEku9dJpCvwOPkycnML9mwovJGRbRdIWlf8e6IF8fpUKTJtRCmX9OvYwCkTjy/sY3+q2h2PKJBU+pbtXz+4mijjBzdvOEqf9dGjHEqQTILd4P89il7YLBDUyRXqMdRCX/UcntyQ1epVbTtkS7MpYdD32qxmXZy++nxDzjHLe2Vzd9rvrucISkzIigZtsphzm49kzG4Xjo3OsTbGpaZysGZemttcuE/LPkbhIzqfNcPR3/YHF1BTkDt6prn5jm5VJjJnL4k/dVxGFVD9vGSA== 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=cPK+G/DRqkbiWej6K4XqotLhQ4Sg5GN2OAYLdilihFQ=; b=LWFawGMB5WX3xKSbTxgnPLYO/fqtUbNZzaCoaljn1GoApDqa8X4tJwjau622CJcAhXNwJr07GSgCaWJEygDIydX4yNwPq0r5z8cnoggU2FpKhNw+dzKjxzz0hsYYyaP27QWSVUHqGmtju8vZ19rD3rQQWifKwk1r7/FQgt5564P34gSbiwNyAc7xR7Uc7uvcyJmi/35Xrkb9JxL7KOOMZo4zR69QjzjLBcrMzgfMkV5exTlvSoCG5SkdgQIv5mLbnRwmr1fMfEWnMmTM5n8qFCtxyuALj9J2U7Y3HRqF94vp+nN44jDwJEAHc9khbrJLK6zSrRQ1NXD+0UOjAQOWTg== 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=cPK+G/DRqkbiWej6K4XqotLhQ4Sg5GN2OAYLdilihFQ=; b=Bz/q03hpBvfQmr2GMkKLuvG/kofJYlNZrT8w4TNGZx7eS4BDoQmu+FElmWgFcPtkhMDUJs/yJERtA0SNnffPIroGCKXxH6UGRT7Vh32eXGrCaaWvlqWW2wMvVAJ59tivppW2NQh0+afFRMmYceFITUc/E9Z+qK0ni8tgwTAqMr1kgVh/hHY4+k6Jj6Br37dxs2ueZbziyudHjCOCtSxN4sM1YFWMDeImiQJjQPVsNffMQhq/tLwu29h8wDL4C7tl76bHN6iA1Gx+ikN72bb1WWbZczMDiswM3ypvHYvmJs3x9APeORcWT+XyTTDIUDDaX2vVXci4PRlU1GSL23o/Wg== 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 7/8] iommu/arm-smmu-v3: Add types for each level of the CD table Date: Fri, 6 Sep 2024 12:47:54 -0300 Message-ID: <7-v4-6416877274e1+1af-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v4-6416877274e1+1af-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR05CA0026.namprd05.prod.outlook.com (2603:10b6:208:335::8) 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: c19a4d5c-517f-4a55-4de9-08dcce8b4793 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: 93qsWZ/0mi2MpGVnXplNV4lCIdcEYyFPgTlYjgs2PS/UnpjEuXOsP0jXCJFbQTz+EZYDmyzhBBHCMopCQ9EBeF9U7RqW2tg9LvfBpSo73e0GBg9/6juoYxnAVkdT94pVumDkG5mopXa8XRFMkOkPFYzczjWuPJhalrxBreodcXn5camBuicSSNilL0jnYms0n8tvTDWXxDRumMzGlvqgnqsuGiLW5oirIMaxOFTs7Yv2Izu+wS8ZY5B2hcG99RH/cq1jLj9J8EYsxWI8uS1WZHm6z0vB5dplecLnSrniKunorUnmPf6YKme4RuwXSK08oRWV9ygUjOskjFLpOra58TYd59I2h1/DfwR7/FunUM7jxci+cye27gi1PFAxTKQ2Hzy/QDqRclqSrn4CslgF+zIxPuP4N4cSDgmYu+Eg3vxeV0Q3MZZka1r+M079xjb/plPUmhcuOPl+d9wB12xR7jyRAaofLY2zFcIa2/n3kT3bMnYMIZlOjPUmRTc0dyWR/QgNmVF6E++Vov746JrfABwpYJa1fF1vhOU0XuQievhM/ZcsO6NZfgxGJD8N5rULbXuXmow3zsUKCchR7omilxvoL8YdBxs1txb5eeqd//dgg/VWRR+AoAABfSeau+qK/4Ri6uK8gwYFEQ134CvicUWQlOWUPUlCWC9N4dM2X19kDcgB20p1jGYJtWPfQCYjEkegSEvRy4EGj7ETtJ6xmxy1017hZsJqhjwqd+g31kamfA5UwDoMzfY39aLx9GEDKHuweGcpg/8ELa55AvQkj7D6pDDGVUnnkPcXu939aHO/Z4y3xdNxbpgsAQ3eXhKnxdoowVwB3Fw1AMly8glXFAmMFQCbilhgLMQymdDQ+o8ae3zOlWr2HucQfu51kq0rKnTkODpfCusDyA11qZatUUtsPZHWpt/gRO4is+JWvyL5VtEsZytXpccu92/1GbKS+ub4jDN2smoryJ41nf8YQEJFI1XZcpTh3No5Z+Ed8pLpz8P9zDLuQOS8v9Uay3jauVuHCsqL8glErazhK6pY7+cxXFizSSAsnc5uFcE3V/YW0m1Sv2mlYOlEsxNi0lVXMxItwQfwcXEjUXrHIDIG23Tr799PeB0nFXNFZ231cCWPo585bent5HzbCu210VLzdIrhbEbirf3+3+g9JOBXi8HeFvhkRyBZBedQfnZCBLfFiG8pQlGegkiJdrcont2l9j2gKHLbgvZUw3veq3QJInCN2rHf33Do5P22bRlFoOHho/oucJBli46zpMWmYbhCxSEKzaqVbGYPd/u+9WYUg5P5fQxI+nCt7ktaayTYHlqNRRNT7cX31BnbT7JLwr0qSHLErhqomaNPUJbcvENxAg== 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: tJpOefLVyoeozMfvLNw7SiuD2SebLFXPs3aThnrHzxmtN6Z/dhPzW3wxE2W/enlLTj1iRgy2HW7K0E0Etp7fVIvA8ATjow95EG6lBG5LcWmXg+Iq0ZTPnW8DoZj6vhnloif0av1QSNA1WgMX8cIRwLCf6TsQkDOXwrfj+GouAjnePFeQZkLz0Lns2Nra3DfS9+pOcbg1YDGlQ9aokBrEnhL0ciLjVqLIe4tnKOrHIy8r1TVZOyh9VEeGiAi478qniiJgiRMOjPvBZcVc8QOeh48aOhMM9z4LEJxl4r71qgnUD3+J/jpihT9y3qjbOc4KxozPk9XVjZBfH/X660//+vp1PCljKTvjdMMz2UDR/9yEGUX5vi7aUZfAtOmo7cKJ80Yn8dEAjcyu9HeGdy4Aj0Y/tbf/c+5IlJBKnukHJJCDLhiXhkngybkURU6wD7SYWWK6WWxE9KMKhoviENqoHnH0oN5JU6gavk0zwKsf/VUxwipAR13Oo8HoJX97Qu6kok7IJT8XV+uX1/enQHapF7Li6QNN7GHrHsvgQcqtgNEywzhoWrRbIL6iHUNdfPYgr/OjDH39ILWcHmgjJFkfU7ehz9gi/aDX46v0REJl8Z80ltSiXcLCn1leIv/kbjlGenmws7eTPuybf8+f1IsEiHA3YhsN3UkQeu36WehPuIdqv1X8WjsmA9y+9CksfHXycdLmGgidZg4LiXz3wXbLwpuXRG6/c34Kteux4gLy+9UrdKOphod1LnfhMMqH2b8RHQDjfnV2cEgzWSKg5yY/bIHQgW0dAznLLXbG8d+bNn11LsG0XAeQUyfckOrfLgj6hm7Sa5j7lVB+57AnMR1YLkp6Vn60lRGuDB484J3FWKspIQ3PcRxjoBwU6e/iFzkX5cH0rubmiuVWNIQq0Q1JNxk2Az+QdgMbych93cMWxATHgYKjNN6zPPBYVQvlD4u+zS4Zl0fW8iWA079CzfmgFHBZ0rWMURzgjmP1T2sQmBkIfV+GCeSmapCpAgJ0WsOz35+gSKbjHuVmPxeThEtONwjYruDCyVzYjBmPgmHSSiPtVy37CD2RBU8mccWwJy41FVX3kX8Sw9pAz2dFRxa2stcWF/FBWjo+oyiQTsMU6xILFmPLTfJmV/f5tb734pJ3ebl+hSBTewQCMVV6NO8NSQUCAmSPC4Ra50Dfu8py5defhr7B7fEu8oIZ2hiOJAFH4LnswhKusteRnpBpniDxRrKnvqB6wgxbuTyDR/PVgnZeYex8TQT0TFEDEqTJnVxxcowuHkhCFOJa7HsqCx/Vj7WtWvMbULfmKwiyM0MHYBjwwSVthZsZR/AIOlRSCIuREUtHKNJQOAkXJqyMWSSe2rcjuGnt5nOE4/zSSchNlN2NIJ+x8kSo601Ehh9JrzE90bSC8pCsZPfsLzkA0exNDFp5bWKGe+nGQXRr3Wx4MGdTks2UJEfefAOAjzMb5zi6FGUz9DSIQGPsj2108IreuJzAowSy2wAQ9BhFCzDmPYd2hkP+Q9aCtZwJQUja/oeguvNm+4VqGxBChNE43xxbbfnciDLmmFkl3nGKHxpU8yksY7pXF7ERf64e76xX10Mt X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c19a4d5c-517f-4a55-4de9-08dcce8b4793 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.7600 (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: XxFuzHyLSJtKJiilISGECLDCvpi429s1YifSGQnc1t3AaMsR1aDkLXeR7wmDR/vD X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6792 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240906_084821_947957_1AED8FAE X-CRM114-Status: GOOD ( 15.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 As well as indexing helpers arm_smmu_cdtab_l1/2_idx(). Remove CTXDESC_L1_DESC_DWORDS and CTXDESC_CD_DWORDS replacing them all with type specific calculations. 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 | 23 +++++++++-- 2 files changed, 44 insertions(+), 24 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 3c33ebffbe62de..534a2141445647 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1217,17 +1217,18 @@ static void arm_smmu_sync_cd(struct arm_smmu_master *master, arm_smmu_cmdq_batch_submit(smmu, &cmds); } -static void arm_smmu_write_cd_l1_desc(__le64 *dst, dma_addr_t l2ptr_dma) +static void arm_smmu_write_cd_l1_desc(struct arm_smmu_cdtab_l1 *dst, + dma_addr_t l2ptr_dma) { u64 val = (l2ptr_dma & CTXDESC_L1_DESC_L2PTR_MASK) | CTXDESC_L1_DESC_V; /* The HW has 64 bit atomicity with stores to the L2 CD table */ - WRITE_ONCE(*dst, cpu_to_le64(val)); + WRITE_ONCE(dst->l2ptr, cpu_to_le64(val)); } -static dma_addr_t arm_smmu_cd_l1_get_desc(const __le64 *src) +static dma_addr_t arm_smmu_cd_l1_get_desc(const struct arm_smmu_cdtab_l1 *src) { - return le64_to_cpu(*src) & CTXDESC_L1_DESC_L2PTR_MASK; + return le64_to_cpu(src->l2ptr) & CTXDESC_L1_DESC_L2PTR_MASK; } struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, @@ -1240,13 +1241,12 @@ struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, return NULL; if (cd_table->s1fmt == STRTAB_STE_0_S1FMT_LINEAR) - return (struct arm_smmu_cd *)(cd_table->cdtab + - ssid * CTXDESC_CD_DWORDS); + return &((struct arm_smmu_cd *)cd_table->cdtab)[ssid]; - l1_desc = &cd_table->l1_desc[ssid / CTXDESC_L2_ENTRIES]; + l1_desc = &cd_table->l1_desc[arm_smmu_cdtab_l1_idx(ssid)]; if (!l1_desc->l2ptr) return NULL; - return &l1_desc->l2ptr[ssid % CTXDESC_L2_ENTRIES]; + return &l1_desc->l2ptr->cds[arm_smmu_cdtab_l2_idx(ssid)]; } static struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, @@ -1264,11 +1264,12 @@ static struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, } if (cd_table->s1fmt == STRTAB_STE_0_S1FMT_64K_L2) { - unsigned int idx = ssid / CTXDESC_L2_ENTRIES; + unsigned int idx = arm_smmu_cdtab_l1_idx(ssid); struct arm_smmu_l1_ctx_desc *l1_desc; l1_desc = &cd_table->l1_desc[idx]; if (!l1_desc->l2ptr) { + struct arm_smmu_cdtab_l1 *dst; dma_addr_t l2ptr_dma; size_t size; @@ -1279,8 +1280,8 @@ static struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, if (!l1_desc->l2ptr) return NULL; - arm_smmu_write_cd_l1_desc(&cd_table->cdtab[idx], - l2ptr_dma); + dst = &((struct arm_smmu_cdtab_l1 *)cd_table->cdtab)[idx]; + arm_smmu_write_cd_l1_desc(dst, l2ptr_dma); /* An invalid L1CD can be cached */ arm_smmu_sync_cd(master, ssid, false); } @@ -1424,7 +1425,7 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) cd_table->s1fmt = STRTAB_STE_0_S1FMT_LINEAR; cd_table->num_l1_ents = max_contexts; - l1size = max_contexts * (CTXDESC_CD_DWORDS << 3); + l1size = max_contexts * sizeof(struct arm_smmu_cd); } else { cd_table->s1fmt = STRTAB_STE_0_S1FMT_64K_L2; cd_table->num_l1_ents = DIV_ROUND_UP(max_contexts, @@ -1436,7 +1437,7 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) if (!cd_table->l1_desc) return -ENOMEM; - l1size = cd_table->num_l1_ents * (CTXDESC_L1_DESC_DWORDS << 3); + l1size = cd_table->num_l1_ents * sizeof(struct arm_smmu_cdtab_l1); } cd_table->cdtab = dma_alloc_coherent(smmu->dev, l1size, @@ -1460,27 +1461,29 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) static void arm_smmu_free_cd_tables(struct arm_smmu_master *master) { int i; - size_t size, l1size; + size_t l1size; struct arm_smmu_device *smmu = master->smmu; struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table; if (cd_table->l1_desc) { - size = CTXDESC_L2_ENTRIES * (CTXDESC_CD_DWORDS << 3); - for (i = 0; i < cd_table->num_l1_ents; i++) { + dma_addr_t dma_handle; + if (!cd_table->l1_desc[i].l2ptr) continue; - dma_free_coherent(smmu->dev, size, + dma_handle = arm_smmu_cd_l1_get_desc(&( + (struct arm_smmu_cdtab_l1 *)cd_table->cdtab)[i]); + dma_free_coherent(smmu->dev, + sizeof(*cd_table->l1_desc[i].l2ptr), cd_table->l1_desc[i].l2ptr, - arm_smmu_cd_l1_get_desc( - &cd_table->cdtab[i])); + dma_handle); } kfree(cd_table->l1_desc); - l1size = cd_table->num_l1_ents * (CTXDESC_L1_DESC_DWORDS << 3); + l1size = cd_table->num_l1_ents * sizeof(struct arm_smmu_cdtab_l1); } else { - l1size = cd_table->num_l1_ents * (CTXDESC_CD_DWORDS << 3); + l1size = cd_table->num_l1_ents * sizeof(struct arm_smmu_cd); } dma_free_coherent(smmu->dev, l1size, cd_table->cdtab, cd_table->cdtab_dma); 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 8b5628771b9671..6fe68f8b38408f 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -301,7 +301,6 @@ static inline u32 arm_smmu_strtab_l2_idx(u32 sid) */ #define CTXDESC_L2_ENTRIES 1024 -#define CTXDESC_L1_DESC_DWORDS 1 #define CTXDESC_L1_DESC_V (1UL << 0) #define CTXDESC_L1_DESC_L2PTR_MASK GENMASK_ULL(51, 12) @@ -311,6 +310,24 @@ struct arm_smmu_cd { __le64 data[CTXDESC_CD_DWORDS]; }; +struct arm_smmu_cdtab_l2 { + struct arm_smmu_cd cds[CTXDESC_L2_ENTRIES]; +}; + +struct arm_smmu_cdtab_l1 { + __le64 l2ptr; +}; + +static inline unsigned int arm_smmu_cdtab_l1_idx(unsigned int ssid) +{ + return ssid / CTXDESC_L2_ENTRIES; +} + +static inline unsigned int arm_smmu_cdtab_l2_idx(unsigned int ssid) +{ + return ssid % CTXDESC_L2_ENTRIES; +} + #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) @@ -341,7 +358,7 @@ struct arm_smmu_cd { * When the SMMU only supports linear context descriptor tables, pick a * reasonable size limit (64kB). */ -#define CTXDESC_LINEAR_CDMAX ilog2(SZ_64K / (CTXDESC_CD_DWORDS << 3)) +#define CTXDESC_LINEAR_CDMAX ilog2(SZ_64K / sizeof(struct arm_smmu_cd)) /* Command queue */ #define CMDQ_ENT_SZ_SHIFT 4 @@ -618,7 +635,7 @@ struct arm_smmu_ctx_desc { }; struct arm_smmu_l1_ctx_desc { - struct arm_smmu_cd *l2ptr; + struct arm_smmu_cdtab_l2 *l2ptr; }; struct arm_smmu_ctx_desc_cfg {