From patchwork Tue Apr 30 17:21:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13649708 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 31B4EC10F16 for ; Tue, 30 Apr 2024 17:22:28 +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=hDl8UrBXcp0CLWaj87MR1uszCiRfPf8EHI0uc6W7HVE=; b=g2qzZ7M5ZSuk1p M2AMpFMp2txZCCo7KZPzxAAfC4T55Uunha6GxwBNjH2f9oMSI54S3vw4odfKUSIvmBsRHBD/9+Shq kHiZXsERiOKqtPs0hwEclSyj+KdECAHFKVlsUeJ13XhBVLbAyjRwmP2Vr81q8xVQYwtzr/RV1/ZZY g0I4Tl5dAhUC0kn2W6fQice5rQjsn1UKg9yH+YBfa6JD22/zsYUAsalgENnt8DUUeFW9Vg5ZIEp/S tzE3LXc3GgRr0fhtiW6TamnXMVHdcCqrCmfl9N8mjRr2jlwgai7sKxo78Xn+WD1oIojZXJfJHv8HZ vp3iLFye5W8scsOJstzw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1rBF-00000007OhO-3F1n; Tue, 30 Apr 2024 17:22:13 +0000 Received: from mail-bn8nam12on20601.outbound.protection.outlook.com ([2a01:111:f403:2418::601] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1rB1-00000007OX2-3anC for linux-arm-kernel@lists.infradead.org; Tue, 30 Apr 2024 17:22:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NbsnZaUM3j5q1aJ6bB0WWzYzDymC2CFHE1J1edegXZUx/A77kwhGTPKOGNU63Fsw9vMwpmZb+fq84iJsw+eNAHpAV0YVEIblOP6PQsD3v33FAchydf1dYFoM/pdnxJ5Q1HGm0AhRS4bdl0Z5c1dA8+UiebSzjQJ/gNjoWUGgEa91mZ5IlKNbYAPEpocDuEg9ivbYUQwnanXNeyJb7f+BnVy1jUbP9mc6La7Zk0tuBeemmMU26epDVqexK0ef+lfu6iSBtPnmxmE6OcSNXbsPmDBeqvHLQXdKbSroTpa9qDyIs4+KyRQuawWWmZyQUIOeQuCs54N0vum+yWutad2HMA== 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=NuOQM+tk1hBYURM7kywp08aMkUjx537isuXThrhYqWA=; b=Ap92EnrdsqfOUwPvlLZO4Dm5m9XM9nvyYZvqgtg5IKjTm0wM/kxU3kok6dfso/7nk37eslbS5a4ayiLm5Aa/qV4l4sbczvie98wgZbZkuxVisKAlS84DIb0jta7AgUD3pOSLg+jDDfdOEMn2Chgk3ZSlmLMJHUI9UYcW8wSdAOcFFi/vx0NsFb1aNZZ5yDQwlEtBX+nP/14R8KPhPbe2hQtp/y4ztkC9OU5RsAEK3ZU/4nXWKs0h+2YcEF9jvgMMDhG6qXysdIPlgvZL4SVa4Sd6EcpddfhTMUtgMMkWzK8LHKr9ui/WSrdsSd7UPV4vI2AEmuOW/q1co3yjF0/AYg== 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=NuOQM+tk1hBYURM7kywp08aMkUjx537isuXThrhYqWA=; b=NHNOnKoBdG5TVKL71VcJ/gP1IxM88C42DEzSt/8oQYC8OUVTb3X09AOzRgyUIKmiRLZbaw+Lne5zgoz1NanukODgGlr4NS7BvYpMWhYlbEX+bqGEy7RihM9IJBwTzeqyRlCEZHY7Vi7n1F18vHLClxN7qKZHZ795/LmX/28HkDB2RWCAgs8KV4LWUs2zRB5y4466iou1Aqgc0AjO0UHcebPyr9s0l3ECcHV9gHH082bfU0dshyiI595KgkCxtYEQAjEqKN/B7M2EVY+hupl4WQIic9xl7OEMptkbmEH3SiDBgdvGpJWeTFNg1BLFjz06b8XOKtTAiWhaf5f/S0uoxA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by DM6PR12MB4172.namprd12.prod.outlook.com (2603:10b6:5:212::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.35; Tue, 30 Apr 2024 17:21:45 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%3]) with mapi id 15.20.7519.031; Tue, 30 Apr 2024 17:21:45 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Eric Auger , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameer Kolothum , Mostafa Saleh Subject: [PATCH v9 1/9] iommu/arm-smmu-v3: Add an ops indirection to the STE code Date: Tue, 30 Apr 2024 14:21:33 -0300 Message-ID: <1-v9-5040dc602008+177d7-smmuv3_newapi_p2_jgg@nvidia.com> In-Reply-To: <0-v9-5040dc602008+177d7-smmuv3_newapi_p2_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR03CA0139.namprd03.prod.outlook.com (2603:10b6:208:32e::24) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|DM6PR12MB4172:EE_ X-MS-Office365-Filtering-Correlation-Id: e567b83b-35f3-43e2-f655-08dc693a014b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|376005|7416005|366007; X-Microsoft-Antispam-Message-Info: mJRm9jHIgJlHgv700SvHtuO6K45KnnH4C/mHrIttoojFjfU0Sw8mghP20zALtg77SfYbM2v20NgUQ3AAaDYYx2yt1GFxQzZlzrZd1QSrKV1DCsWicIpTrEPyOW8VEgcdc+ftyh31mTPA3A5XsRpG2HDMd5Z9ezHyAPB7yQiVOV34UV0XmiDDEokbhcRVayD+DSKbWNZKAHAOEUCS6vMFGlMOepOyWoATsZ0Lx/TEdbZSlSSmlF/7ayHR+qLT5kTMWm6Mx5kA2ubZFnJf5GCtRc7n3xiF2yBuxeRj4Lcm/d6E7rCUOrJHzr8FOY2NiShoSW7W7vXOleK/HgQlxebFgRniim7JCRr18jhLi73M1tPMey+7sAfSMjm9afss6jmrNLX4RGU62vovdjn8UJ19y2Kj3Lko5TwCs3bGd9HwcsyRjzsETwBMYaO96t823gqMJSLSuxDuoEIPETQ/vwcgpLmrfI1rYQtVTlGavlCN6TNF3SfpzmdsA/TWlSSvJUE/Ugf42H7Q10qL3W/PVPI88LKGXvFUKG7QYSK/FIYne0iSLzXUHjswASeqnDehjABGdzqvPAClmr+dCti+bcAs9VcPYz5DGiExpk/xrY8+ag+RANulRb8g8KJ45Sz31ECUF9GiQ1aj/okAe1vL+wUQqBmpulMk6Hf+nmy+rfpb7E3IaB+1VgWDk25BNJ4pkf3kbL3PdxBEGMRr+/m2Qj/butUtr0yBBPLzfN+/ntqFtIGeJaHMwkIRMBccox3GpG0wljlPsf8B7Vc/8yjqWXlDiCoScQ2qme0Oh/DNwoRf55BUW1UM961ko9nF687K0qkCj1Y87sWWAofGlpnyMJo6n+N/r4NodLqb9GdHJqMbN7bRqQGoY+K8O7T+arXImWdB2is+eZyk/a9T0YtTL4RTMVZR1iqsbpA39EOMsT1HeUWkEBq4JJDiOk9ZDyZwZPiG0f5CgQxcvpw2UramAAjFefDT4fmuy/MKtmDcZdtaca4O6SabZ2aEqF9EgIDxDySV/Aq5E27UAe403mPOtUZOBpyU0hV1V1CQuxuPMGWtoqOc34G4BKuy9LO0zKQZwvhhsNgQ+v2mPX9ReDFu1M5tC0WexrftjKnhf8Q0gfih6n5cD4O8epuvLnFclG57qWQ4r/lIz355Oe/WL84j7oBiuk2PIgtPwg4uWlDEaQ+nMkE8iOOwbwiiGzKQT8oSBFWGm8UjDrGMG11/QZnxtkSnVrkfNSibOSjOlOx57QaC/MclYNYbfp9Vsa6Y7E8u461tKfwNGlWMZY3m/NB9npRntA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(376005)(7416005)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: z+OZzhbyUxpk0cI+d3FR6qSTbXIVmLD9vAsT5W6dbHDK7clEbj2ebj83V5UzBmurbCGFhLSkQERnkwZGmiKQiuUcLatd2hzTTLwaIcw5ibuFw+NkaquYyvCb3X0rodo+5SQ2VQhTvcv5/7gDP2vwf9QXZ5KT4zWfuaLaIvhvboZVUYSnpRNmnPE1iTHNKSno2SgUjejcmtUfBNFdDXQ5euq7ADiF05DqJ7JdNfq1j+WxO6QsleAL4ntCwOGFvt97QsVyS+5ZKu3M82Nz/WdSjcc7mP1jFN6uNR1wuv12o++GX+HOiwia52yy0OBnnZIMiGNkjmrxzKL2OuGG3pLqy+w6cAJzuCfkY4NwZNLY3u2vC/+AF/6W4AD3l2PsQBHe4oNto8c35qoK78uS6qlzjO1LakvnsYRsq3zNItsTZ4Qhp4O3Iip4H4OOparkRsWGCd07U2+3bkaFnJecGcNffcIhARfpH2FRze71aHBHSzaDNzHSmyf75O5wrgDRNWLb81wO4m1JHcydofgJbxFBSRB8mC3VDhPAgf0pEVZWEPobWqopwCMk9upAhC4H40UDgiwmUc36pRyDDaL5mj8QbEQs0lpHc+v19+eqzaIt2mhVYXxhyh3Bg6Fm0SI2eP+VUewLraezSpg3sEQpUwlyg+HN2OdfI7hso7HgHl7jkpLw2q4Rf1Vyjr7EjOMkWOFScwny3w+9SD7Zkp0Bz5ggdbSSpLfTOxs5cXK8t9Lqfr9B1q2O4hXiVTNoKMCt2pWblpPTScLjrDk1rsi9p8DjXfLe6ykIIkpSbVGGUbz/kZOXn5n0xL64vbm51CdaeRyRKGLSbrG0KaKKZVwTMl+qtpDpFglmMBbX1XjerPOwhkOum78QwfI3WkciDWSMma/mS+7npgrnJU/Lv3P2myy02mesowSwo9/syFUPg/uAIJ4N/RnmeRsohfr4kG4MCRFBIzNCQHA1kNNNvoNkbEE1nzfEqELw2/GjImGLaCFaVdBE3C42kFc73niM4XoNcs2phBj4d1fK5eH6mR873wMXxmrIKAZ0Xce9649/TFXovt0m66a7fdgmDeGOnbt+DpJr1LKCNlXsqQIEvL2/uHobSNlBF5lQudtIuN/xWFM1vdb/j1lIVBh4AtFPd6gN1Cy9z/V6zbN2L+php7ePkbhv04hgQEhfaBaJP+BfkZSgtRm+otGUOwaaO2+LhcNNCzBIX6SkvLFAmjPsUOMVVFQbJZF4snZfoxj/Ft04yWtUKdoGSG9nH+5qaQtnETMhfTpSkG0p40+2DjJ9qKiNDtcAJkV2tkXKPRgAE8fJbEZrPV0DO+wAe4SwHJxl341DHoEcOJe5xBuYZ0If8250EUU4NowBeETIS6HbMuoVzmVnGKARJB8KNvKQVrBCoeyAINN7dLCr+zqS6rAaiEdFgUPWoNtbxUMJ6kFlV7WWQRvOnAynrAF9Sdk4/uAstNKWJpydSfxfdTEct4DVx/kzSRrO+bldCqEpP3pLhoBhbl2TGjVXS49hM1eqR0Ep6jZ7JrycqO9Ijd0jFDoYVJIYkdnrf4Ascv/O02cGlWVmVvvlNHshRRh5tCoNg9qQCAyvVz2+ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e567b83b-35f3-43e2-f655-08dc693a014b X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2024 17:21:43.2833 (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: oorGk7qelFH6JRcmc28o8aMBKMsYVrLfAJeqUVmhfUwk8tuSOe3ncRTzdnVy927t X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4172 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240430_102200_037163_7AA68993 X-CRM114-Status: GOOD ( 21.26 ) 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 Prepare to put the CD code into the same mechanism. Add an ops indirection around all the STE specific code and make the worker functions independent of the entry content being processed. get_used and sync ops are provided to hook the correct code. Signed-off-by: Michael Shavit Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 176 ++++++++++++-------- 1 file changed, 104 insertions(+), 72 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 79c18e95dd293e..196aeaf280042c 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -42,8 +42,19 @@ enum arm_smmu_msi_index { ARM_SMMU_MAX_MSIS, }; -static void arm_smmu_sync_ste_for_sid(struct arm_smmu_device *smmu, - ioasid_t sid); +struct arm_smmu_entry_writer_ops; +struct arm_smmu_entry_writer { + const struct arm_smmu_entry_writer_ops *ops; + struct arm_smmu_master *master; +}; + +struct arm_smmu_entry_writer_ops { + void (*get_used)(const __le64 *entry, __le64 *used); + void (*sync)(struct arm_smmu_entry_writer *writer); +}; + +#define NUM_ENTRY_QWORDS 8 +static_assert(sizeof(struct arm_smmu_ste) == NUM_ENTRY_QWORDS * sizeof(u64)); static phys_addr_t arm_smmu_msi_cfg[ARM_SMMU_MAX_MSIS][3] = { [EVTQ_MSI_INDEX] = { @@ -972,43 +983,42 @@ void arm_smmu_tlb_inv_asid(struct arm_smmu_device *smmu, u16 asid) * would be nice if this was complete according to the spec, but minimally it * has to capture the bits this driver uses. */ -static void arm_smmu_get_ste_used(const struct arm_smmu_ste *ent, - struct arm_smmu_ste *used_bits) +static void arm_smmu_get_ste_used(const __le64 *ent, __le64 *used_bits) { - unsigned int cfg = FIELD_GET(STRTAB_STE_0_CFG, le64_to_cpu(ent->data[0])); + unsigned int cfg = FIELD_GET(STRTAB_STE_0_CFG, le64_to_cpu(ent[0])); - used_bits->data[0] = cpu_to_le64(STRTAB_STE_0_V); - if (!(ent->data[0] & cpu_to_le64(STRTAB_STE_0_V))) + used_bits[0] = cpu_to_le64(STRTAB_STE_0_V); + if (!(ent[0] & cpu_to_le64(STRTAB_STE_0_V))) return; - used_bits->data[0] |= cpu_to_le64(STRTAB_STE_0_CFG); + used_bits[0] |= cpu_to_le64(STRTAB_STE_0_CFG); /* S1 translates */ if (cfg & BIT(0)) { - used_bits->data[0] |= cpu_to_le64(STRTAB_STE_0_S1FMT | - STRTAB_STE_0_S1CTXPTR_MASK | - STRTAB_STE_0_S1CDMAX); - used_bits->data[1] |= + used_bits[0] |= cpu_to_le64(STRTAB_STE_0_S1FMT | + STRTAB_STE_0_S1CTXPTR_MASK | + STRTAB_STE_0_S1CDMAX); + used_bits[1] |= cpu_to_le64(STRTAB_STE_1_S1DSS | STRTAB_STE_1_S1CIR | STRTAB_STE_1_S1COR | STRTAB_STE_1_S1CSH | STRTAB_STE_1_S1STALLD | STRTAB_STE_1_STRW | STRTAB_STE_1_EATS); - used_bits->data[2] |= cpu_to_le64(STRTAB_STE_2_S2VMID); + used_bits[2] |= cpu_to_le64(STRTAB_STE_2_S2VMID); } /* S2 translates */ if (cfg & BIT(1)) { - used_bits->data[1] |= + used_bits[1] |= cpu_to_le64(STRTAB_STE_1_EATS | STRTAB_STE_1_SHCFG); - used_bits->data[2] |= + used_bits[2] |= cpu_to_le64(STRTAB_STE_2_S2VMID | STRTAB_STE_2_VTCR | STRTAB_STE_2_S2AA64 | STRTAB_STE_2_S2ENDI | STRTAB_STE_2_S2PTW | STRTAB_STE_2_S2R); - used_bits->data[3] |= cpu_to_le64(STRTAB_STE_3_S2TTB_MASK); + used_bits[3] |= cpu_to_le64(STRTAB_STE_3_S2TTB_MASK); } if (cfg == STRTAB_STE_0_CFG_BYPASS) - used_bits->data[1] |= cpu_to_le64(STRTAB_STE_1_SHCFG); + used_bits[1] |= cpu_to_le64(STRTAB_STE_1_SHCFG); } /* @@ -1017,57 +1027,55 @@ static void arm_smmu_get_ste_used(const struct arm_smmu_ste *ent, * unused_update is an intermediate value of entry that has unused bits set to * their new values. */ -static u8 arm_smmu_entry_qword_diff(const struct arm_smmu_ste *entry, - const struct arm_smmu_ste *target, - struct arm_smmu_ste *unused_update) +static u8 arm_smmu_entry_qword_diff(struct arm_smmu_entry_writer *writer, + const __le64 *entry, const __le64 *target, + __le64 *unused_update) { - struct arm_smmu_ste target_used = {}; - struct arm_smmu_ste cur_used = {}; + __le64 target_used[NUM_ENTRY_QWORDS] = {}; + __le64 cur_used[NUM_ENTRY_QWORDS] = {}; u8 used_qword_diff = 0; unsigned int i; - arm_smmu_get_ste_used(entry, &cur_used); - arm_smmu_get_ste_used(target, &target_used); + writer->ops->get_used(entry, cur_used); + writer->ops->get_used(target, target_used); - for (i = 0; i != ARRAY_SIZE(target_used.data); i++) { + for (i = 0; i != NUM_ENTRY_QWORDS; i++) { /* * Check that masks are up to date, the make functions are not * allowed to set a bit to 1 if the used function doesn't say it * is used. */ - WARN_ON_ONCE(target->data[i] & ~target_used.data[i]); + WARN_ON_ONCE(target[i] & ~target_used[i]); /* Bits can change because they are not currently being used */ - unused_update->data[i] = (entry->data[i] & cur_used.data[i]) | - (target->data[i] & ~cur_used.data[i]); + unused_update[i] = (entry[i] & cur_used[i]) | + (target[i] & ~cur_used[i]); /* * Each bit indicates that a used bit in a qword needs to be * changed after unused_update is applied. */ - if ((unused_update->data[i] & target_used.data[i]) != - target->data[i]) + if ((unused_update[i] & target_used[i]) != target[i]) used_qword_diff |= 1 << i; } return used_qword_diff; } -static bool entry_set(struct arm_smmu_device *smmu, ioasid_t sid, - struct arm_smmu_ste *entry, - const struct arm_smmu_ste *target, unsigned int start, +static bool entry_set(struct arm_smmu_entry_writer *writer, __le64 *entry, + const __le64 *target, unsigned int start, unsigned int len) { bool changed = false; unsigned int i; for (i = start; len != 0; len--, i++) { - if (entry->data[i] != target->data[i]) { - WRITE_ONCE(entry->data[i], target->data[i]); + if (entry[i] != target[i]) { + WRITE_ONCE(entry[i], target[i]); changed = true; } } if (changed) - arm_smmu_sync_ste_for_sid(smmu, sid); + writer->ops->sync(writer); return changed; } @@ -1097,24 +1105,21 @@ static bool entry_set(struct arm_smmu_device *smmu, ioasid_t sid, * V=0 process. This relies on the IGNORED behavior described in the * specification. */ -static void arm_smmu_write_ste(struct arm_smmu_master *master, u32 sid, - struct arm_smmu_ste *entry, - const struct arm_smmu_ste *target) +static void arm_smmu_write_entry(struct arm_smmu_entry_writer *writer, + __le64 *entry, const __le64 *target) { - unsigned int num_entry_qwords = ARRAY_SIZE(target->data); - struct arm_smmu_device *smmu = master->smmu; - struct arm_smmu_ste unused_update; + __le64 unused_update[NUM_ENTRY_QWORDS]; u8 used_qword_diff; used_qword_diff = - arm_smmu_entry_qword_diff(entry, target, &unused_update); + arm_smmu_entry_qword_diff(writer, entry, target, unused_update); if (hweight8(used_qword_diff) == 1) { /* * Only one qword needs its used bits to be changed. This is a - * hitless update, update all bits the current STE is ignoring - * to their new values, then update a single "critical qword" to - * change the STE and finally 0 out any bits that are now unused - * in the target configuration. + * hitless update, update all bits the current STE/CD is + * ignoring to their new values, then update a single "critical + * qword" to change the STE/CD and finally 0 out any bits that + * are now unused in the target configuration. */ unsigned int critical_qword_index = ffs(used_qword_diff) - 1; @@ -1123,22 +1128,21 @@ static void arm_smmu_write_ste(struct arm_smmu_master *master, u32 sid, * writing it in the next step anyways. This can save a sync * when the only change is in that qword. */ - unused_update.data[critical_qword_index] = - entry->data[critical_qword_index]; - entry_set(smmu, sid, entry, &unused_update, 0, num_entry_qwords); - entry_set(smmu, sid, entry, target, critical_qword_index, 1); - entry_set(smmu, sid, entry, target, 0, num_entry_qwords); + unused_update[critical_qword_index] = + entry[critical_qword_index]; + entry_set(writer, entry, unused_update, 0, NUM_ENTRY_QWORDS); + entry_set(writer, entry, target, critical_qword_index, 1); + entry_set(writer, entry, target, 0, NUM_ENTRY_QWORDS); } else if (used_qword_diff) { /* * At least two qwords need their inuse bits to be changed. This * requires a breaking update, zero the V bit, write all qwords * but 0, then set qword 0 */ - unused_update.data[0] = entry->data[0] & - cpu_to_le64(~STRTAB_STE_0_V); - entry_set(smmu, sid, entry, &unused_update, 0, 1); - entry_set(smmu, sid, entry, target, 1, num_entry_qwords - 1); - entry_set(smmu, sid, entry, target, 0, 1); + unused_update[0] = 0; + entry_set(writer, entry, unused_update, 0, 1); + entry_set(writer, entry, target, 1, NUM_ENTRY_QWORDS - 1); + entry_set(writer, entry, target, 0, 1); } else { /* * No inuse bit changed. Sanity check that all unused bits are 0 @@ -1146,18 +1150,7 @@ static void arm_smmu_write_ste(struct arm_smmu_master *master, u32 sid, * compute_qword_diff(). */ WARN_ON_ONCE( - entry_set(smmu, sid, entry, target, 0, num_entry_qwords)); - } - - /* It's likely that we'll want to use the new STE soon */ - if (!(smmu->options & ARM_SMMU_OPT_SKIP_PREFETCH)) { - struct arm_smmu_cmdq_ent - prefetch_cmd = { .opcode = CMDQ_OP_PREFETCH_CFG, - .prefetch = { - .sid = sid, - } }; - - arm_smmu_cmdq_issue_cmd(smmu, &prefetch_cmd); + entry_set(writer, entry, target, 0, NUM_ENTRY_QWORDS)); } } @@ -1430,17 +1423,56 @@ arm_smmu_write_strtab_l1_desc(__le64 *dst, struct arm_smmu_strtab_l1_desc *desc) WRITE_ONCE(*dst, cpu_to_le64(val)); } -static void arm_smmu_sync_ste_for_sid(struct arm_smmu_device *smmu, u32 sid) +struct arm_smmu_ste_writer { + struct arm_smmu_entry_writer writer; + u32 sid; +}; + +static void arm_smmu_ste_writer_sync_entry(struct arm_smmu_entry_writer *writer) { + struct arm_smmu_ste_writer *ste_writer = + container_of(writer, struct arm_smmu_ste_writer, writer); struct arm_smmu_cmdq_ent cmd = { .opcode = CMDQ_OP_CFGI_STE, .cfgi = { - .sid = sid, + .sid = ste_writer->sid, .leaf = true, }, }; - arm_smmu_cmdq_issue_cmd_with_sync(smmu, &cmd); + arm_smmu_cmdq_issue_cmd_with_sync(writer->master->smmu, &cmd); +} + +static const struct arm_smmu_entry_writer_ops arm_smmu_ste_writer_ops = { + .sync = arm_smmu_ste_writer_sync_entry, + .get_used = arm_smmu_get_ste_used, +}; + +static void arm_smmu_write_ste(struct arm_smmu_master *master, u32 sid, + struct arm_smmu_ste *ste, + const struct arm_smmu_ste *target) +{ + struct arm_smmu_device *smmu = master->smmu; + struct arm_smmu_ste_writer ste_writer = { + .writer = { + .ops = &arm_smmu_ste_writer_ops, + .master = master, + }, + .sid = sid, + }; + + arm_smmu_write_entry(&ste_writer.writer, ste->data, target->data); + + /* It's likely that we'll want to use the new STE soon */ + if (!(smmu->options & ARM_SMMU_OPT_SKIP_PREFETCH)) { + struct arm_smmu_cmdq_ent + prefetch_cmd = { .opcode = CMDQ_OP_PREFETCH_CFG, + .prefetch = { + .sid = sid, + } }; + + arm_smmu_cmdq_issue_cmd(smmu, &prefetch_cmd); + } } static void arm_smmu_make_abort_ste(struct arm_smmu_ste *target)