From patchwork Wed Jan 4 11:00:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hector Martin X-Patchwork-Id: 38862 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp5082413wrt; Wed, 4 Jan 2023 03:03:32 -0800 (PST) X-Google-Smtp-Source: AMrXdXu5IQzkT+BL0I/3akzl6EaczHGyMYGM1/vcT8cXrKL97x4Ya1KzsSeRqNbFUIYpIikoyfIM X-Received: by 2002:a17:906:fb18:b0:82d:1d5f:2617 with SMTP id lz24-20020a170906fb1800b0082d1d5f2617mr42041038ejb.69.1672830212704; Wed, 04 Jan 2023 03:03:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672830212; cv=none; d=google.com; s=arc-20160816; b=J4IKmtc2AWXsm0UdXAf5QO3jCq+wGzcPrZARB2jTth9iQcBXbpl38KhBz7HXhePFc3 fPyDaKYcplTlukIbWAaiNKlM1ktbMOjxr6zUF7+WXQh4qxlQSjZYcIc94W2Dt1ihgIfA 5WcJ3zjHECz1dzNvtfwx4wfbxmGJgQ7XcQY+GLlm2TigizmYZPMbmLu/XBc07S0qfX3B UD7FPVHNDrUne3TpJ+Rpp8UPvt7wzEVsoEZqsSUoGkdWBTljQKaXxVY7AK4TA2UIhWrb fZw/oFWzeZSspZtHfAkGHXR25Wo+MmR8B7KfcGYKrocrwvQewSw6iyJATnJWJbbBsJ4S tV9A== 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=SI3Z2iJh5jYLtZvYarLtIHeHb/wjqxqza5f9jNzpmjI=; b=PeS5vNJMQ3RtN88+wQk8davSqUhGjqfr3Ikh8tPCI8yL4ZEtc9+DAX6GrtAyJWjy1M /5os5myeyowX3CA7CqkdSt0q1+I/cZ3fypvMx44mM9EmwUrmZ6wUta8iQsU8kJP7XHqu ZLwEwcx3E6Svw71xRSvv1nz0Al0A1aGjrqShc+C/UjgHIrhxFbEI3bq67w1ncls88i9n vEwMk5TOjczAycwR77HrgL9A7GmLS8vgbGJnPoawBzzE3nm2NVvDvDX4y6lRT/W6AEMj iQjOUiRIT6ieRPoF7OrmWAbnmYggrLI4ujDRwwUtenAjVbax2rVtSAtJF138urcEU1PQ /XpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@marcan.st header.s=default header.b="hLxQDz/W"; 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 cs17-20020a170906dc9100b007aa6ce58d9asi30329896ejc.712.2023.01.04.03.03.08; Wed, 04 Jan 2023 03:03:32 -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="hLxQDz/W"; 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 S238902AbjADLCo (ORCPT + 99 others); Wed, 4 Jan 2023 06:02:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238925AbjADLCO (ORCPT ); Wed, 4 Jan 2023 06:02:14 -0500 Received: from mail.marcansoft.com (marcansoft.com [212.63.210.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E341513DCB; Wed, 4 Jan 2023 03:01:51 -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 CC94342118; Wed, 4 Jan 2023 11:01:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=marcan.st; s=default; t=1672830110; bh=kZ5l2St5RyPUjKSIYXwu/uDFjCyPWx8nT0BPyLp8JKg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hLxQDz/W5Z13+zieD047u9edVn6Pueo/vSYgI7QbY4fEHbb1xBVZJd0bjrI3pfFCs hV1Ka7kPUHkjDaeuUmaxBAvuTML/NiZaYMofgEO/1JoPCH/pb5VdQ74dyb7ZMgQuFl s9g/ReIj0Ux/JndJKszGO+3GxCmPWdoMewLCUa61jABC1g9udjVrIkG/GpSRebZfdp 0BxVQumN358ME1s3kjVHu4mTxS2C7+80ITe6kCVe3HRnGta6rqiywtjDoqqL2vqg8x 1m96HTaPAw9z4x3PtNSOxyQhloSzNOClYFEY21h0TUhsZ6NJYKFYXbzv7jEi3V2sFg sQKuGaD/9H62Q== 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 2/7] iommu: dart: Add suspend/resume support Date: Wed, 4 Jan 2023 20:00:08 +0900 Message-Id: <20230104110013.24738-3-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?1754089613206498346?= X-GMAIL-MSGID: =?utf-8?q?1754089613206498346?= We need to save/restore the TCR/TTBR registers, since they are lost on power gate. Reviewed-by: Sven Peter Signed-off-by: Hector Martin --- drivers/iommu/apple-dart.c | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 4f4a323be0d0..2458416122f8 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -121,6 +121,9 @@ struct apple_dart { struct iommu_group *sid2group[DART_MAX_STREAMS]; struct iommu_device iommu; + + u32 save_tcr[DART_MAX_STREAMS]; + u32 save_ttbr[DART_MAX_STREAMS][DART_MAX_TTBR]; }; /* @@ -932,6 +935,45 @@ static const struct apple_dart_hw apple_dart_hw_t6000 = { .fmt = APPLE_DART2, }; +static __maybe_unused int apple_dart_suspend(struct device *dev) +{ + struct apple_dart *dart = dev_get_drvdata(dev); + unsigned int sid, idx; + + for (sid = 0; sid < DART_MAX_STREAMS; sid++) { + dart->save_tcr[sid] = readl_relaxed(dart->regs + DART_TCR(sid)); + for (idx = 0; idx < DART_MAX_TTBR; idx++) + dart->save_ttbr[sid][idx] = + readl(dart->regs + DART_TTBR(sid, idx)); + } + + return 0; +} + +static __maybe_unused int apple_dart_resume(struct device *dev) +{ + struct apple_dart *dart = dev_get_drvdata(dev); + unsigned int sid, idx; + int ret; + + ret = apple_dart_hw_reset(dart); + if (ret) { + dev_err(dev, "Failed to reset DART on resume\n"); + return ret; + } + + for (sid = 0; sid < DART_MAX_STREAMS; sid++) { + for (idx = 0; idx < DART_MAX_TTBR; idx++) + writel(dart->save_ttbr[sid][idx], + dart->regs + DART_TTBR(sid, idx)); + writel(dart->save_tcr[sid], dart->regs + DART_TCR(sid)); + } + + return 0; +} + +DEFINE_SIMPLE_DEV_PM_OPS(apple_dart_pm_ops, apple_dart_suspend, apple_dart_resume); + static const struct of_device_id apple_dart_of_match[] = { { .compatible = "apple,t8103-dart", .data = &apple_dart_hw_t8103 }, { .compatible = "apple,t6000-dart", .data = &apple_dart_hw_t6000 }, @@ -944,6 +986,7 @@ static struct platform_driver apple_dart_driver = { .name = "apple-dart", .of_match_table = apple_dart_of_match, .suppress_bind_attrs = true, + .pm = pm_sleep_ptr(&apple_dart_pm_ops), }, .probe = apple_dart_probe, .remove = apple_dart_remove,