From patchwork Wed Jan 4 11:00:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hector Martin X-Patchwork-Id: 38866 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp5082598wrt; Wed, 4 Jan 2023 03:03:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXtxtwNNJto0sLZvCNMitwLwosGYfWKbW9ww/JR1Bcmgb8M731axPOkNoHsCdx+CXSqldEHU X-Received: by 2002:a17:907:6746:b0:836:e7de:9792 with SMTP id qm6-20020a170907674600b00836e7de9792mr26564551ejc.32.1672830238614; Wed, 04 Jan 2023 03:03:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672830238; cv=none; d=google.com; s=arc-20160816; b=d/niYvSsMgS/TcxySM846aCqWeazUNhPm2nCC2OSKulBKK9ly28euH3WrwdG1Ds/ju BgAW+5c0DyO2Rrfrk8rAlMbn/wXzxlWfd49OnWh4UTlc1bW2KexqmAxjwq7JoN3UzDKG Q5tyG/3Vk4jLuhsEh8k1gJYmOhX02k4vW6oBI0dfK5Hl3uPDjcFXr/zcnF0t7wAFcb6o aJNCATE7cLvo0saoKqo+l+W64YTqgw+5H09mx7xH7m2SD4uk2QEB4ZL4nj9h2TuNRuBm zTDNijmLyfAmUM78x5CAfGcknSkNeTsLVaOJFXU8dyV+U9KEE6zoip1YE3imHkmk4Y/h /KjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Cqy55ng//uFbUxRiFqEyngWlEqcbMg0qukLxiyA21f0=; b=bIMWJkEJCorhcqwz9JOSEVc743atzEyU9mUIFmX37lTvq4qMhVlOe4cBNLvpSyiGHp 4acEkGHZoZYvKV+zJU4/zG25YeHw1YpQsiEE03QZb2s8ubcvqHsKWsbv7Xz9RCZdUDFC wVdl9A7vplDEJ8tOAyC8X6t55fTJcpUhuM9foVXIh83O3K2jrAGOB6YZ3xEO9qtFf/vF RW37OU0J3R2KLtIv+6nX8XIVFmmgEpulRmfVsVNvnf2hIQV458ykQm0+KmnE5xWTnbA7 UTN5uvDj3i9ztcpoVKm1f7rfJwwk4qVX9gFkNrwpRPwHB5Q1iscFkza0+uc5bFNUTqvz FBrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@marcan.st header.s=default header.b=OooIov77; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=marcan.st Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h2-20020a0564020e8200b0048eafc90734si4756960eda.544.2023.01.04.03.03.35; Wed, 04 Jan 2023 03:03:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@marcan.st header.s=default header.b=OooIov77; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=marcan.st Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239080AbjADLCx (ORCPT + 99 others); Wed, 4 Jan 2023 06:02:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239068AbjADLCR (ORCPT ); Wed, 4 Jan 2023 06:02:17 -0500 Received: from mail.marcansoft.com (marcansoft.com [212.63.210.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0E5D1EACC; Wed, 4 Jan 2023 03:02:00 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: sendonly@marcansoft.com) by mail.marcansoft.com (Postfix) with ESMTPSA id 98D6842300; Wed, 4 Jan 2023 11:01:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=marcan.st; s=default; t=1672830119; bh=142QbbUohcowan5JaKEvzqkzDXOTXTkt2BTbRaBx+j4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OooIov772mSNFIsjnQOuis1lqhvu4NLFsgs7+rXRxXr43HWhl9d+sVjOvyLUMyIot RUPwqQAP9tsTM0KLiR0LtuRihLhqz6Fav1Na/KoC8sBbyqnJA+iFDgjbrj56ihx1iT hnz9S7bYeVanxhR2PfA43oFUWKuDmAcFRiv61fvAF9d/EN+MJm8Yo/+c7mtEwsoQLT 0cZBNKmZtXge2mM0RTrNSCKb+aYmt3/oW44t59ryUDlDlfkFgGq2tkQlrbGJk4fkPp BlmtoIE0u8kuQ9ER81AgC1YQ751Te00fb5hV5zA8AWfMlJFDya6xZMo593k6TcGFaX H55YW358mECbA== From: Hector Martin To: Joerg Roedel , Will Deacon , Robin Murphy Cc: Sven Peter , Alyssa Rosenzweig , Janne Grunau , Rob Herring , Krzysztof Kozlowski , devicetree@vger.kernel.org, iommu@lists.linux.dev, asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Hector Martin Subject: [PATCH 4/7] iommu: dart: Support a variable number of TTBRs per stream Date: Wed, 4 Jan 2023 20:00:10 +0900 Message-Id: <20230104110013.24738-5-marcan@marcan.st> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230104110013.24738-1-marcan@marcan.st> References: <20230104110013.24738-1-marcan@marcan.st> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754089640287211339?= X-GMAIL-MSGID: =?utf-8?q?1754089640287211339?= T8110 only has one TTBR per stream, so un-hardcode that. Signed-off-by: Hector Martin Reviewed-by: Sven Peter --- drivers/iommu/apple-dart.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 48743bcd5b9d..189487c1d978 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -77,15 +77,21 @@ #define DART_TCR_BYPASS0_ENABLE BIT(8) #define DART_TCR_BYPASS1_ENABLE BIT(12) -#define DART_TTBR(sid, idx) (0x200 + 16 * (sid) + 4 * (idx)) #define DART_TTBR_VALID BIT(31) #define DART_TTBR_SHIFT 12 +#define DART_TTBR(dart, sid, idx) (0x200 + \ + (((dart)->hw->ttbr_count * (sid)) << 2) + \ + ((idx) << 2)) + + struct apple_dart_hw { u32 oas; enum io_pgtable_fmt fmt; int max_sid_count; + + int ttbr_count; }; /* @@ -245,7 +251,7 @@ static void apple_dart_hw_set_ttbr(struct apple_dart_stream_map *stream_map, WARN_ON(paddr & ((1 << DART_TTBR_SHIFT) - 1)); for_each_set_bit(sid, stream_map->sidmap, dart->num_streams) writel(DART_TTBR_VALID | (paddr >> DART_TTBR_SHIFT), - dart->regs + DART_TTBR(sid, idx)); + dart->regs + DART_TTBR(dart, sid, idx)); } static void apple_dart_hw_clear_ttbr(struct apple_dart_stream_map *stream_map, @@ -255,7 +261,7 @@ static void apple_dart_hw_clear_ttbr(struct apple_dart_stream_map *stream_map, int sid; for_each_set_bit(sid, stream_map->sidmap, dart->num_streams) - writel(0, dart->regs + DART_TTBR(sid, idx)); + writel(0, dart->regs + DART_TTBR(dart, sid, idx)); } static void @@ -263,7 +269,7 @@ apple_dart_hw_clear_all_ttbrs(struct apple_dart_stream_map *stream_map) { int i; - for (i = 0; i < DART_MAX_TTBR; ++i) + for (i = 0; i < stream_map->dart->hw->ttbr_count; ++i) apple_dart_hw_clear_ttbr(stream_map, i); } @@ -415,7 +421,7 @@ apple_dart_setup_translation(struct apple_dart_domain *domain, for (i = 0; i < pgtbl_cfg->apple_dart_cfg.n_ttbrs; ++i) apple_dart_hw_set_ttbr(stream_map, i, pgtbl_cfg->apple_dart_cfg.ttbr[i]); - for (; i < DART_MAX_TTBR; ++i) + for (; i < stream_map->dart->hw->ttbr_count; ++i) apple_dart_hw_clear_ttbr(stream_map, i); apple_dart_hw_enable_translation(stream_map); @@ -956,11 +962,15 @@ static const struct apple_dart_hw apple_dart_hw_t8103 = { .oas = 36, .fmt = APPLE_DART, .max_sid_count = 16, + + .ttbr_count = 4, }; static const struct apple_dart_hw apple_dart_hw_t6000 = { .oas = 42, .fmt = APPLE_DART2, .max_sid_count = 16, + + .ttbr_count = 4, }; static __maybe_unused int apple_dart_suspend(struct device *dev) @@ -970,9 +980,9 @@ static __maybe_unused int apple_dart_suspend(struct device *dev) for (sid = 0; sid < dart->num_streams; sid++) { dart->save_tcr[sid] = readl_relaxed(dart->regs + DART_TCR(sid)); - for (idx = 0; idx < DART_MAX_TTBR; idx++) + for (idx = 0; idx < dart->hw->ttbr_count; idx++) dart->save_ttbr[sid][idx] = - readl(dart->regs + DART_TTBR(sid, idx)); + readl(dart->regs + DART_TTBR(dart, sid, idx)); } return 0; @@ -993,7 +1003,7 @@ static __maybe_unused int apple_dart_resume(struct device *dev) for (sid = 0; sid < dart->num_streams; sid++) { for (idx = 0; idx < DART_MAX_TTBR; idx++) writel(dart->save_ttbr[sid][idx], - dart->regs + DART_TTBR(sid, idx)); + dart->regs + DART_TTBR(dart, sid, idx)); writel(dart->save_tcr[sid], dart->regs + DART_TCR(sid)); }