From patchwork Fri Jan 3 09:32:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Lu X-Patchwork-Id: 13925425 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 99C03E77188 for ; Fri, 3 Jan 2025 09:32:47 +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=PWiFjcH+lkMmfM0xrtRosmpbQQbfT5FY7F+ghlYABgI=; b=t+VdzKFseN4NR4 dZLJvpDodP+IuwnChOhe6yODVtBn3Tw6mkhyZ2h9Xv+NI+PjlLZvj2xJOYHcI/dis616rHmnv2UzD tu5itqlKznleHen7XjRZESG2yvExgn852gLjZoDpc4MEHRDgk5OZ4kg/IWMekpwrlQRXj1v9mWa8R YtGqEasCzZKBmtw+eeKAEeWDsFCjDE0rkuDkjq3u90Au/3hTlIL2yOAck2nRJuC7KHB5sF+sZ7Nwn WV04ZJjp31Gcb9dpwTYB2hKSTZkUkwzgeRJNHmvknMD2c6zjnnpihnhEh2h4S1bwJ8ISf4KFyvnDq L2lNGkqQRA6n47Ptm1Zg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTe2t-0000000Ccms-1gJJ; Fri, 03 Jan 2025 09:32:43 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTe2r-0000000CcmG-3lAU for linux-riscv@bombadil.infradead.org; Fri, 03 Jan 2025 09:32:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=LeEQjuKWeFN2ZDkGY720uCzhuIIhCR6ezIvsDMVpnR4=; b=dTzebGzEQ5S/LyWeK6RiKQUPNn 4AO2Z2Rymkj7SD8W2/k44Cmjnd6EgbyGjEGwSb3xwjtwTcj+7V5UdSdcUUJXGhp1C5CbkvWiemYO3 PWd3i1AviL8qtpg3VM2ZxHhD2fPeaDdsNRb9flFzsiswFtz4ZsgydAG/atsFE3r4Q7pO5kOuxweSE baxFL++Hrlq0Czpr7bwCnnXGAUo2PCz+NJfd3qceUng2BIEcrk3+8uKJgIMnW69Vba8s45gY10h3h b2hobnlKkq+rnjujhkJ7GCB2Od/GigIx61scDDCl1NndMOTeMxaLRja5Krqj3IED8z/7S8+Tt5dFR /TaLMdMw==; Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTe2o-00000008Lr9-2jBd for linux-riscv@lists.infradead.org; Fri, 03 Jan 2025 09:32:40 +0000 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-21628b3fe7dso163063085ad.3 for ; Fri, 03 Jan 2025 01:32:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1735896751; x=1736501551; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LeEQjuKWeFN2ZDkGY720uCzhuIIhCR6ezIvsDMVpnR4=; b=B7L3ynhdu3k8eooyP0ltv/7o7zGfjgGhWOQtjn8DrJGvGODpIfdIJtpRgAzSGifVwX zxjwI8Z0e7Ngbys4evZBLXYuteWHjnbZP8yF51ddcbxG6yY4qT9WXAUy3CQHnprJ8IgA CXc4Peoaqh7B194xyA7K7EPpPnXPZyWTgmkRuexvL2T9sIr7FeZqYh2PnQYnU/VsfoUr k47HaZUCXmEQr5pt2hgl3ed/uuG6/4xcBqizslxqvDjP9mLm+Ctl3beSxdrDPDjil/WD EaIpLLsDH4VZ10q97nQ3gAynq+y0H94azyz2S7utvE3NE9719NiNflCRgUmD4PzKStJ3 OQJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735896751; x=1736501551; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LeEQjuKWeFN2ZDkGY720uCzhuIIhCR6ezIvsDMVpnR4=; b=bJquXDJBcFqRGB82LBW1zLAcr0uOuS4jNQwuLeXdTF3eouNwnKbCzVMUy4/GTIMlrg 9Uwyq7KUTJLlvOfKboI4M7rtVxXkVqnoEFuFNf8pETGC5zDkykvKz/2/VpZCHcTRAar7 TwPc8xzl82GR9AS3x7b0FFsuZ/X30UjAi2CKiA676r2WGnlV4RpknwV6xz6Chjjd0SjI RHmoMKTfEwx+sgdtmPFb1Lsp1gyCCij3FyxLIgHfCrom/T8HWdAYZL6Un5ioZc6+rePB YDxx7qeJhg+7rrnqew/kiuxj2wk8jdQfpFrUth0ImRCQiMKVrrM+fEkDEU4Sahxeb4PA YOMw== X-Forwarded-Encrypted: i=1; AJvYcCVwRmZs3W23RlGDV/RzMlu350rCdE2ggfRYEn5AaOtW2gh0wJmUKotV3VVQwW0Cmcd3healAiXF6yyxNg==@lists.infradead.org X-Gm-Message-State: AOJu0Yx9wcYB+G3+2ENuUtK6h8TD+zyRXKJrJ7NKKCSjLPh7HfJXBa6G JExx+p5JES/YciQCLTwkrdca2qjYAdoFaoseFMg6mDjEInk6I9m4VAlhaLEBxWs= X-Gm-Gg: ASbGnctNm1WNbb04Z4cFQ/QvGv+9bSlr1Tz/DZDgkKB2DAV55jbcwcRuL7f0sFTt7Ot u+I2R+W1HuCvgELbAJ73OmL8aXAu4qsUO0S4YEYlm0ImOGnAejVbrDYEfa0E1+JTQdvWhP6uPOG K4/A6xhphe2kE7vJlzDA9a3tfFqvzwZt6sQDohG6CYD8t+VMHJyXQJIvtRS/cZNgz+gDS2V4eVd QVZwnalcO4fO6Nq3O4co9+ua1bx7IZaG72aJT/x0gAOYu46wW/+tSyaFyvHtfowBj5q0FC8vA9y UjbLEHaYTAOgjCrcnRB0TcdyAx2CU7D9SfRq6/c= X-Google-Smtp-Source: AGHT+IG4QJX7EAklgM5+vW3k3M8U8TM525HblsN4/w7dza4jbpmygtOX60zOg0aNJpRf3CH/K14zmA== X-Received: by 2002:a17:902:f542:b0:216:2426:7668 with SMTP id d9443c01a7336-219e6e9a26emr700703695ad.13.1735896751356; Fri, 03 Jan 2025 01:32:31 -0800 (PST) Received: from J9GPGXL7NT.bytedance.net ([61.213.176.55]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc9f4a2csm242227395ad.175.2025.01.03.01.32.28 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 03 Jan 2025 01:32:31 -0800 (PST) From: Xu Lu To: tjeznach@rivosinc.com, joro@8bytes.org, will@kernel.org Cc: lihangjing@bytedance.com, xieyongji@bytedance.com, guojinhui.liam@bytedance.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Xu Lu Subject: [PATCH RESEND 1/2] iommu/riscv: Empty iommu queue before enabling it Date: Fri, 3 Jan 2025 17:32:19 +0800 Message-Id: <20250103093220.38106-2-luxu.kernel@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250103093220.38106-1-luxu.kernel@bytedance.com> References: <20250103093220.38106-1-luxu.kernel@bytedance.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250103_093239_152831_3B3EAB59 X-CRM114-Status: UNSURE ( 8.72 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Changing cqen/fqen/pqen from 0 to 1 sets the cqh/fqt/pqt registers to 0. But the cqt/fqh/pqh registers are left unmodified. This commit resets cqt/fqh/pqh registers to ensure corresponding queues are empty before being enabled during initialization. Signed-off-by: Xu Lu --- drivers/iommu/riscv/iommu.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c index 8a05def774bd..84806724f568 100644 --- a/drivers/iommu/riscv/iommu.c +++ b/drivers/iommu/riscv/iommu.c @@ -240,6 +240,12 @@ static int riscv_iommu_queue_enable(struct riscv_iommu_device *iommu, return rc; } + /* Empty queue before enabling it */ + if (queue->qid == RISCV_IOMMU_INTR_CQ) + riscv_iommu_writel(queue->iommu, Q_TAIL(queue), 0); + else + riscv_iommu_writel(queue->iommu, Q_HEAD(queue), 0); + /* * Enable queue with interrupts, clear any memory fault if any. * Wait for the hardware to acknowledge request and activate queue From patchwork Fri Jan 3 09:32:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Lu X-Patchwork-Id: 13925424 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 E219AE7718F for ; Fri, 3 Jan 2025 09:32:41 +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=c8IKBVrOOZYQmQfyKaY0qQIvC9U/3/Dy8Y+hqEgq8oA=; b=tjDVTCkMCTyzrm RyggxaQ0LxO6oQPQeVRRfc/2Ycu6ozOjw4U60mJaERXS3aE8XcWPwgKlV6K41Af5dp84u94NxHRMI kxC9LuTBwPlGXI6Idlpc7d7c12d5HTDVAtcIn/wdG0OBBo6lSiOXdN8TmnZLwsW0PuT7BvXxsSRZ0 EMHZnButnQSVUtcEh13bJc87nD8MLTqbCny8bldS7rtTbR29nxYp7GkG8DmGKnCGHcJFHTNZbUsZY 34Bzicw9qWDHpwylpt9wYD3zLLfBDywr8kje9XMbjbGTzHwCark5bP61ZWEtzQF4UXc//4FGspmr6 +eQ4pFHqignl5Kih/o9A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTe2n-0000000CckL-3SzK; Fri, 03 Jan 2025 09:32:37 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTe2l-0000000Ccj9-1LjM for linux-riscv@lists.infradead.org; Fri, 03 Jan 2025 09:32:36 +0000 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-2166651f752so194283645ad.3 for ; Fri, 03 Jan 2025 01:32:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1735896754; x=1736501554; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yc21+WdKHK3grlhMkYoFV2YGOVlkOtA7hk0YotJEPa8=; b=VESwixuZYR9pEj2VKZYItu/sKrpTakcLvXknB69bkfeHHl3p+1JTibKGdreZIN4SUf NpFj7ARl5wSkf2CFmCcomZBFjdBKcDJKngcYH+1Habzk2lRUcO5kcv33b2adyFY9U1ld zhY+irRGl+nIKfz3rKsNEeartviEaAx+fMrgsRuK7XiyN5A0Fo/iBsJ9qGf6tHFFIaWC L52R4quJDXGrPyqoYIOWkVhChJmlEl07em0wxuTAQuBYHPbGwTghitToq4pXG9E+uDJW gO7Sdo48onnwsvYtyWaI1QnCjdFymRWGnbefmsnUZR4nOWG+2sTvzZrKflcFMv/oyF4Z AJ9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735896754; x=1736501554; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yc21+WdKHK3grlhMkYoFV2YGOVlkOtA7hk0YotJEPa8=; b=AgItO5BtLztzydtPUCsMa45WpSbkKPMgN9gn0OLP0YlmaqWrgEy0cRNcIczY+jouz6 DzoxysC5bKLa+hBay8mbH/iEn4KqO3GlOK4YOYfak4hgJKewyxNGb3RpbbBLLcOggete 6HjtB7hDiE4JMofVnyAMREFElS+f9B1c9cg4k2gxI6A/gzbqNXYvWVfnDEfo+ytZayU9 9MU2TuIPvkuMdtSHz+I+HhOrBm+KUSbqvigRqxioQadP9j/sgcfwhKcbLkR0GDntE0VK OxtoZah2J7ct+x2/B7UyOd9BpCP8w6gK0smp8TCb61ZIKiS/7JimcUrWyu58bCp6qEnO VUYw== X-Forwarded-Encrypted: i=1; AJvYcCX8URUgAdxl1/GDflAWOnVzBVw1J8B2qJtxl1CSB4DpEApZ4rLr4kk6ZxVUPDHjGVVZdfbgiVCiOQzbcg==@lists.infradead.org X-Gm-Message-State: AOJu0YziY0oNrtG8zTq2Sa687whWHgFbCnk+L5zPIrVWLmhzJO84VRmp 4zFmBelkmNAEsjnzdbcPcdw9S9/ukNHU5Yx0NH+U6TyL+Q3uj/fRCzmpzylMKs4= X-Gm-Gg: ASbGncsGoBEHVL41tDJhVCDNr4KZrarqbdhbPRcGdj2mIa9j4UZpYMgHmvX9IazhRez 8MVw6B44UwlhHf+lbw/ksuCbVR/VYwmCyuZM7P7fyWiQp5282tWtQw3buyLicu+ev89xz5oKANz P6/KfD1BWU5u4KEGD9zHZLVsWlM8GAQ4uVYhFO3snOgU8JSJP+7n32UfyS9Ta5YDNIkdXWWZep5 f3QgVEjZKgKAf9MYFJ9ZZB1FgrVScI2Vld3RzlZI1gt3hk1fm91o/KbP27vQYr5mThy5fgKoYw5 ynpsyC9ZXmG8s4oHumxIdOxistZhn0lRSAZDS7Y= X-Google-Smtp-Source: AGHT+IHU+UwYIa1+lGh0eizBZY5fnuQHt83z1liw3I1NBL2QnUe92EbAa77SFkBIPk0s+08dLn1S/A== X-Received: by 2002:a17:902:cec5:b0:219:d28a:ca23 with SMTP id d9443c01a7336-219e6f1484emr625056355ad.36.1735896754656; Fri, 03 Jan 2025 01:32:34 -0800 (PST) Received: from J9GPGXL7NT.bytedance.net ([61.213.176.55]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc9f4a2csm242227395ad.175.2025.01.03.01.32.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 03 Jan 2025 01:32:34 -0800 (PST) From: Xu Lu To: tjeznach@rivosinc.com, joro@8bytes.org, will@kernel.org Cc: lihangjing@bytedance.com, xieyongji@bytedance.com, guojinhui.liam@bytedance.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Xu Lu Subject: [PATCH RESEND 2/2] iommu/riscv: Add shutdown function for iommu driver Date: Fri, 3 Jan 2025 17:32:20 +0800 Message-Id: <20250103093220.38106-3-luxu.kernel@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250103093220.38106-1-luxu.kernel@bytedance.com> References: <20250103093220.38106-1-luxu.kernel@bytedance.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250103_013235_359171_1FAAE51C X-CRM114-Status: GOOD ( 12.92 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org This commit supplies shutdown callback for iommu driver. The shutdown callback resets necessary registers so that newly booted kernel can pass riscv_iommu_init_check() after kexec. Also, the shutdown callback resets iommu mode to bare instead of off so that new kernel can still use PCIE devices even when CONFIG_RISCV_IOMMU is not enabled. Signed-off-by: Xu Lu --- drivers/iommu/riscv/iommu-pci.c | 8 ++++++++ drivers/iommu/riscv/iommu-platform.c | 6 ++++++ drivers/iommu/riscv/iommu.c | 6 ++++-- drivers/iommu/riscv/iommu.h | 1 + 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/riscv/iommu-pci.c b/drivers/iommu/riscv/iommu-pci.c index c7a89143014c..d82d2b00904c 100644 --- a/drivers/iommu/riscv/iommu-pci.c +++ b/drivers/iommu/riscv/iommu-pci.c @@ -101,6 +101,13 @@ static void riscv_iommu_pci_remove(struct pci_dev *pdev) riscv_iommu_remove(iommu); } +static void riscv_iommu_pci_shutdown(struct pci_dev *pdev) +{ + struct riscv_iommu_device *iommu = dev_get_drvdata(&pdev->dev); + + riscv_iommu_disable(iommu); +} + static const struct pci_device_id riscv_iommu_pci_tbl[] = { {PCI_VDEVICE(REDHAT, PCI_DEVICE_ID_REDHAT_RISCV_IOMMU), 0}, {PCI_VDEVICE(RIVOS, PCI_DEVICE_ID_RIVOS_RISCV_IOMMU_GA), 0}, @@ -112,6 +119,7 @@ static struct pci_driver riscv_iommu_pci_driver = { .id_table = riscv_iommu_pci_tbl, .probe = riscv_iommu_pci_probe, .remove = riscv_iommu_pci_remove, + .shutdown = riscv_iommu_pci_shutdown, .driver = { .suppress_bind_attrs = true, }, diff --git a/drivers/iommu/riscv/iommu-platform.c b/drivers/iommu/riscv/iommu-platform.c index 382ba2841849..62c40b99cf62 100644 --- a/drivers/iommu/riscv/iommu-platform.c +++ b/drivers/iommu/riscv/iommu-platform.c @@ -74,6 +74,11 @@ static void riscv_iommu_platform_remove(struct platform_device *pdev) riscv_iommu_remove(dev_get_drvdata(&pdev->dev)); }; +static void riscv_iommu_platform_shutdown(struct platform_device *pdev) +{ + riscv_iommu_disable(dev_get_drvdata(&pdev->dev)); +}; + static const struct of_device_id riscv_iommu_of_match[] = { {.compatible = "riscv,iommu",}, {}, @@ -82,6 +87,7 @@ static const struct of_device_id riscv_iommu_of_match[] = { static struct platform_driver riscv_iommu_platform_driver = { .probe = riscv_iommu_platform_probe, .remove = riscv_iommu_platform_remove, + .shutdown = riscv_iommu_platform_shutdown, .driver = { .name = "riscv,iommu", .of_match_table = riscv_iommu_of_match, diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c index 84806724f568..670b4302aca8 100644 --- a/drivers/iommu/riscv/iommu.c +++ b/drivers/iommu/riscv/iommu.c @@ -651,9 +651,11 @@ static struct riscv_iommu_dc *riscv_iommu_get_dc(struct riscv_iommu_device *iomm * This is best effort IOMMU translation shutdown flow. * Disable IOMMU without waiting for hardware response. */ -static void riscv_iommu_disable(struct riscv_iommu_device *iommu) +void riscv_iommu_disable(struct riscv_iommu_device *iommu) { - riscv_iommu_writeq(iommu, RISCV_IOMMU_REG_DDTP, 0); + riscv_iommu_writeq(iommu, RISCV_IOMMU_REG_DDTP, + FIELD_PREP(RISCV_IOMMU_DDTP_IOMMU_MODE, + RISCV_IOMMU_DDTP_IOMMU_MODE_BARE)); riscv_iommu_writel(iommu, RISCV_IOMMU_REG_CQCSR, 0); riscv_iommu_writel(iommu, RISCV_IOMMU_REG_FQCSR, 0); riscv_iommu_writel(iommu, RISCV_IOMMU_REG_PQCSR, 0); diff --git a/drivers/iommu/riscv/iommu.h b/drivers/iommu/riscv/iommu.h index b1c4664542b4..46df79dd5495 100644 --- a/drivers/iommu/riscv/iommu.h +++ b/drivers/iommu/riscv/iommu.h @@ -64,6 +64,7 @@ struct riscv_iommu_device { int riscv_iommu_init(struct riscv_iommu_device *iommu); void riscv_iommu_remove(struct riscv_iommu_device *iommu); +void riscv_iommu_disable(struct riscv_iommu_device *iommu); #define riscv_iommu_readl(iommu, addr) \ readl_relaxed((iommu)->reg + (addr))