From nobody Tue Dec 16 09:32:21 2025 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BE821E47AE for ; Fri, 3 Jan 2025 09:32:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735896757; cv=none; b=pPSeJvLs5iWXjjxl5Tgrumx34AfiKVfi7qgHb2B10teU2n7IVF2KQVQ17yZc2+cz39RRKBYv/bKOVknQxKWq9DGna9OtBtWPX20NZ8XGmDgJka2Q8m/8arGla+tBP8+appKCA+0NXog9w+w/NzSRl8JrWxRUcL9ec9T3yTyMCGQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735896757; c=relaxed/simple; bh=HPlL6ailNaMPIU0XaRMkBsXzcZT42yYQPb4AgE35MIo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AsigjXeQLm8pSxGwbTmuVYbG0pzclQMeu4jWAFugmR6ckbViz4W3yhN5u0k6WrYiIN7/dEP6VSuM1z2VjIjshm/oMNqFCQ8KppAaqfeoGwxj96bGntJfor1fyhloqKJ2W8OhkaGtdnXcXxpGw3g555ulnssXM6TxUpheF5Dx/FA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=T7TgmCdU; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="T7TgmCdU" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-218c8aca5f1so210081285ad.0 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=vger.kernel.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=T7TgmCdUXfjj5CxCTvlJF9/XAuEnKMleWMxK8Oj17Rb9ekchJ9si3amBDtnaCw9rGu W2TyGkcqhRkwYQ8PoS7irNetLBxKp27O+dyIft9CZQI1MYGc8G1INXwqRWaiKThj8vkL N4ta5v0sxcHlZjVSNV9TLSim0eCzPr9Ljx92PZx/Vz3u6oGmYnxN3ZyQ28Itg8uuEGbl IzpwyCUr74qgSA47i8AzfK8UH2/HgmIxIegnT/6cCgcJEvwlzY/+j5ZsoSIIODbrTZ9I rXJnCn6WTVYb9S7SG85DrPhMbkVEBmc8jCqjuacoD+2CRNsMxo70pxuNzLm+q7TU9+LM QEjg== 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=I2N2SGOhcZFlzNblw6Zfjg6gxU1nDhLC94NFZm3eKBhZy7V1nHaJQFVFXMFb7puPLF OHgo13nUTrA2cL1hDxrT1zjDLrgVRn+AAw20dUAz2fuG3NnWck+ONOOBwFKw7nSlrSrN 2Dago32aafH8S7Ep9jJuvwI7rUVywufhDTFSZbQh2TlZLQRv7DTIqHgI6aPcv8WhRT1y YBBvN3kFsLGBVR2ZzWUxxneR0FinkZbbpXeitKHKfQQmZ90jrY6y1cwirJT6CgIdn3Ij Pa5L9ulbH6xndSaAp0Q00bcA61555o5Zw5lY6aKBRgKMpAGJs5C7PAeJo5aDiB4oirEo Z4Dw== X-Forwarded-Encrypted: i=1; AJvYcCXttRpDT24svEIWBxjQgRne9Nj3UQthx55bdobw4xB7GsI5567G5YMIfjiA1ZFNZeKk5EfzrITRmNNRgXs=@vger.kernel.org X-Gm-Message-State: AOJu0YzQ0rN5LcWUMIzmJnBwzjHN8M/5FODdle7SoQ7Q1RqV9OTLgEz4 LXAYPRbsk2y6WvVRk0RE8RarBOg9XEX0WhLiSzgEDyE75p89jK7PJmQKm8iIscE= X-Gm-Gg: ASbGncthHTTQTyQfOh4bkhltej3e8tUiCEWM/TYPKXypaHneSMojEXv7enz2VBvpjEl EL5X5BuRaSpSj/CpbmuAo4W8T5d6gydO3Htff7If/7vb3pMq/Apg2f87MPf145UJHtyDJdRd8kH 6k2nGuvSUfHdRwyH9uyViYXMPLJAyrvYscFRAuCgGaVoEKLHOuye0bG5N5fT+y6ME36kvJjR+OR vL+YQl9VO87wT/YM1JZbDItpsIGPEmj35iTS9nc8E5x1MOkmzxnLUmoi6ObhMdEc6ou56gVkwcH eHi7O/c7D9AgUc6ouCfRTpbR2qO8ORFFNBc3mKA= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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-pc= i.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 *pde= v) riscv_iommu_remove(iommu); } =20 +static void riscv_iommu_pci_shutdown(struct pci_dev *pdev) +{ + struct riscv_iommu_device *iommu =3D dev_get_drvdata(&pdev->dev); + + riscv_iommu_disable(iommu); +} + static const struct pci_device_id riscv_iommu_pci_tbl[] =3D { {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 =3D { .id_table =3D riscv_iommu_pci_tbl, .probe =3D riscv_iommu_pci_probe, .remove =3D riscv_iommu_pci_remove, + .shutdown =3D riscv_iommu_pci_shutdown, .driver =3D { .suppress_bind_attrs =3D true, }, diff --git a/drivers/iommu/riscv/iommu-platform.c b/drivers/iommu/riscv/iom= mu-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)); }; =20 +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[] =3D { {.compatible =3D "riscv,iommu",}, {}, @@ -82,6 +87,7 @@ static const struct of_device_id riscv_iommu_of_match[] = =3D { static struct platform_driver riscv_iommu_platform_driver =3D { .probe =3D riscv_iommu_platform_probe, .remove =3D riscv_iommu_platform_remove, + .shutdown =3D riscv_iommu_platform_shutdown, .driver =3D { .name =3D "riscv,iommu", .of_match_table =3D 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(struc= t 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 { =20 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); =20 #define riscv_iommu_readl(iommu, addr) \ readl_relaxed((iommu)->reg + (addr)) --=20 2.20.1