From patchwork Fri Jan 13 10:50:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hector Martin X-Patchwork-Id: 43158 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp201145wrt; Fri, 13 Jan 2023 02:55:04 -0800 (PST) X-Google-Smtp-Source: AMrXdXusXFsQpiLoi06XdkVBgdT468SyEYO9ad+P45wep9FTmfgeY8OBDMQ0GLukySPWonP7+g1r X-Received: by 2002:a05:6a20:2d23:b0:b2:6a7a:6072 with SMTP id g35-20020a056a202d2300b000b26a7a6072mr93565717pzl.14.1673607304316; Fri, 13 Jan 2023 02:55:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673607304; cv=none; d=google.com; s=arc-20160816; b=pEuJl7O5Z31ErFd78BZREoCrhLkR4NQ8E3buhwlrFG3BYxGNsapm+ErCqv9eBaoBnb mCAq+jIiukaP9FAInVy1Zmn53TvyynuS0ma4wRCvOkUepzxi9NhbESGFOXLXu4nnWwD3 pNh5Yl9JimV75hZ8B3Muy+Sf2BBdEsVyYrcBRHpMa87ZoXJjan9NZOi/TnsrPoZeKgOT LMCIY+K7vD1tCvul0bth61mGryXC7+yLKwnyI8DRx6k5ogoPC+xdzia4RjELNAFFUmIE u6YuFd3dVvagK9NdNu64Oic+o4rviWwTliYIbzz7z5Fh1Lda5o1USqj7DRHGmNpITKt7 HJsg== 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=VOcNZl3VPUVZ8gYXt8vOGx1Yq4yvEW/DnDIRBv+t/SYTr23T+tr3iJMHS0XDOjUqdP 5XMASX4m7Dpvws+UWDBS9eUbuxH+d0ke/3zk0PPf8oq8IUArVFCGJrdBisUrB+l/Kf5X G7GDo4daNlbRv2b15bo7PzOsmqA74wIt8PHzNJg4GCNHDCFNG6pj//L8/1iCxKmWKBeE Cs6/ojsCkwxuLSjqXtFnoA/X+XSFln5/hf6Zyqpb9Mxkrnzq5CA61KyEIawjZepS7K9n HELOuU2DFxpW6jJg+KGVLT57GIRsVwQpQWIDGKYnI2T3riDn10TFk/MUq+GaEhGzWJBg PW2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@marcan.st header.s=default header.b=Ae6JuKjU; 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 31-20020a17090a0fa200b002238dff236esi20211827pjz.148.2023.01.13.02.54.52; Fri, 13 Jan 2023 02:55:04 -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=Ae6JuKjU; 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 S241423AbjAMKxx (ORCPT + 99 others); Fri, 13 Jan 2023 05:53:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241221AbjAMKxM (ORCPT ); Fri, 13 Jan 2023 05:53:12 -0500 Received: from mail.marcansoft.com (marcansoft.com [212.63.210.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 581E777AC5; Fri, 13 Jan 2023 02:51:38 -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 2D25841A42; Fri, 13 Jan 2023 10:51:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=marcan.st; s=default; t=1673607096; bh=kZ5l2St5RyPUjKSIYXwu/uDFjCyPWx8nT0BPyLp8JKg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Ae6JuKjU00sx2HlcWmPSHOOZ6+AsJUs2stuywa5lTiHEy/YHVyhuP8cLlNhyfNuDJ dT3X5k/glqXl8aDaTc7iEgvdq3mBUWuTTxrJjvJ0m6ev4ZWmxmuz8KFkN0Yx0nsw+9 8XtaZYbyBtGNF0p4jHFJ6tRhMVlRv36PMWCZ1mDTXZGbdnarK9OQRR6c61JH9fc1Pm WFhv3oJAorH1hQBYSw1Pz6jqdI0Z+T4/gNFmsYCLxPjYyT9gpLvnvIbNfRiJ2+Olq+ HJcQVI4ORIKsrIzTMm2Ksl6Av2ZiazoV589IOT3Y0nMlMuJbZlHhypOuOJK8LXjOGq 4bK0m04MRxKfw== 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: Fri, 13 Jan 2023 19:50:25 +0900 Message-Id: <20230113105029.26654-3-marcan@marcan.st> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230113105029.26654-1-marcan@marcan.st> References: <20230113105029.26654-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?1754904452613742623?= X-GMAIL-MSGID: =?utf-8?q?1754904452613742623?= 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,