From nobody Thu Sep 24 15:11:02 2026 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5429454147A; Tue, 22 Sep 2026 12:18:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790079506; cv=none; b=fS52KSfkCCZiExZhh2D8IU1ugYjxiBb6quSCvmRkcHqGkRxk2THR8ORg61HUzCI2x1IITvbsKaV84giBPCsjeQN7Iqb4qovxBLd5KrGjaf27Z6IHrHlvfcwaWWE2SobLRJj6huxwbzjDsuasR5mu6vCY2Ebr/WWgNvdJHxUBRRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790079506; c=relaxed/simple; bh=BHw8oYA5cUdxj0Pv1MbAjMukmRTWHNxTlSixQVJdkmQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HKIuxpH3k8+hQIVPPOqmsfPKOaLqp13qel4TkUideNYvK81ibM+M/9O4+T8bHt5VHlwXvFhTG5+wrlwQOO8wQtNr73MBba0phdzy6yqJLHAkb5acCswSvWRJ4W9d1sNzeCGqcpF2qnYD03+u9MjgxxZTPMoGJz5ffkcnhaVBbOA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8BxhvANcrJqSaAOAA--.42670S3; Tue, 22 Sep 2026 20:18:21 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowJBx6c0LcrJqysAjAA--.44690S3; Tue, 22 Sep 2026 20:18:20 +0800 (CST) From: Bibo Mao To: Huacai Chen , "Rafael J . Wysocki" , Maciej Wieczor-Retman , Pawel Chmielewski Cc: Len Brown , linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, lixianglai@loongson.cn Subject: [PATCH v4 1/4] ACPICA: actbl2.h: Add bit constants of the Flags field in the IOVT IOMMU structure Date: Tue, 22 Sep 2026 20:10:55 +0800 Message-Id: <20260922121058.972734-2-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20260922121058.972734-1-maobibo@loongson.cn> References: <20260922121058.972734-1-maobibo@loongson.cn> 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 X-CM-TRANSID: qMiowJBx6c0LcrJqysAjAA--.44690S3 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Content-Type: text/plain; charset="utf-8" According to the IOVT specification, define macros for each bit of the Flags field in the IOVT IOMMU structure. Link: https://github.com/open-acpica/acpica/commit/352f750e4cc0 Signed-off-by: Bibo Mao --- include/acpi/actbl2.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h index baef525367b5..76e4a5bc79b4 100644 --- a/include/acpi/actbl2.h +++ b/include/acpi/actbl2.h @@ -919,6 +919,13 @@ struct acpi_iovt_iommu { u32 device_entry_offset; }; =20 +/* Masks for Flags field above */ +#define ACPI_IOVT_IOMMU_PCI_DEVICE (1<<0) +#define ACPI_IOVT_IOMMU_PXM_VALID (1<<1) +#define ACPI_IOVT_IOMMU_MAGAGE_BY_SEGMENT (1<<2) +#define ACPI_IOVT_IOMMU_HW_CAP_SUPPORT (1<<3) +#define ACPI_IOVT_IOMMU_MSI_INT_BYPASS (1<<4) + struct acpi_iovt_device_entry { u8 type; u8 length; --=20 2.39.3 From nobody Thu Sep 24 15:11:02 2026 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3479E52E07F; Tue, 22 Sep 2026 12:18:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790079507; cv=none; b=lwxmLZl9VDlebmo5ohw4WfzVtURTU/JkzfM8Hul58IIb8ouBFohAnLADd99tsbhZc2tn1ONyUwpNGD67DE4j21oD0Cuyh1Ny5PfRnIEIxos4KHCJdQPtOVFkBOgMfwipx7u4wD/njoK1s46ysgah6u5iM00vZHd4BE/7pgAQ6HM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790079507; c=relaxed/simple; bh=m2fcyxt8G+UQ01+6Gx37X6NQ1voUD2S9O4fvtCxUP2I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GlnTLoMOZRQ/T1+OFav05MvmL8o/Y8HTXcFEyhs9sZ1LnnXM/fv7BcXomvRSINJi6ViKCUtHb5KTjEdbbB+rJikf3es45hMsfMbAOSZIvP7LT6IzRiNkTXtrLDwvipPez/rjGlVQseMF02UygndF0ubjUy1KAtRUXAkEkJy0+2g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8BxLtMOcrJqTaAOAA--.42680S3; Tue, 22 Sep 2026 20:18:22 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowJBx6c0LcrJqysAjAA--.44690S4; Tue, 22 Sep 2026 20:18:21 +0800 (CST) From: Bibo Mao To: Huacai Chen , "Rafael J . Wysocki" , Maciej Wieczor-Retman , Pawel Chmielewski Cc: Len Brown , linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, lixianglai@loongson.cn Subject: [PATCH v4 2/4] ACPI: LoongArch: Add acpi_arch_[late]_init() Date: Tue, 22 Sep 2026 20:10:56 +0800 Message-Id: <20260922121058.972734-3-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20260922121058.972734-1-maobibo@loongson.cn> References: <20260922121058.972734-1-maobibo@loongson.cn> 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 X-CM-TRANSID: qMiowJBx6c0LcrJqysAjAA--.44690S4 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Content-Type: text/plain; charset="utf-8" LoongArch IOMMU scanning flow is similar with virtio-iommu, there is early init and late_init. In early init function, PCI ACS is enabled if there is IOMMU table, and late_init is called after PCI device scanning, where IOVT table scanning function is executed. Here add acpi_arch_init() and acpi_arch_late_init() API on LoongArch, function acpi_iovt_init() is to enable PCI ACS function if IOMMU device exists in IOVT table, and function acpi_iovt_late_init() is to scan IOVT table, add IOMMU devices. Signed-off-by: Bibo Mao --- arch/loongarch/Kconfig | 1 + drivers/acpi/Kconfig | 4 + drivers/acpi/Makefile | 2 +- drivers/acpi/bus.c | 2 + drivers/acpi/loongarch/Kconfig | 7 + drivers/acpi/loongarch/Makefile | 3 + drivers/acpi/loongarch/init.c | 16 +++ drivers/acpi/loongarch/init.h | 5 + drivers/acpi/loongarch/iovt.c | 219 ++++++++++++++++++++++++++++++++ include/linux/acpi.h | 1 + 10 files changed, 259 insertions(+), 1 deletion(-) create mode 100644 drivers/acpi/loongarch/Kconfig create mode 100644 drivers/acpi/loongarch/Makefile create mode 100644 drivers/acpi/loongarch/init.c create mode 100644 drivers/acpi/loongarch/init.h create mode 100644 drivers/acpi/loongarch/iovt.c diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index 2067d1f2ad7a..d7f8e4fec952 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -6,6 +6,7 @@ config LOONGARCH select ACPI_GENERIC_GSI if ACPI select ACPI_MCFG if ACPI select ACPI_HOTPLUG_CPU if ACPI_PROCESSOR && HOTPLUG_CPU + select ACPI_IOVT if ACPI select ACPI_PPTT if ACPI select ACPI_SYSTEM_POWER_STATES_SUPPORT if ACPI select ARCH_BINFMT_ELF_STATE diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index f165d14cf61a..192e6f18eda1 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -550,6 +550,10 @@ if ARM64 source "drivers/acpi/arm64/Kconfig" endif =20 +if LOONGARCH +source "drivers/acpi/loongarch/Kconfig" +endif + if RISCV source "drivers/acpi/riscv/Kconfig" endif diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index d1b0affb844f..91584a3c1e01 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -131,6 +131,6 @@ obj-y +=3D dptf/ obj-$(CONFIG_ARM64) +=3D arm64/ =20 obj-$(CONFIG_ACPI_VIOT) +=3D viot.o - +obj-$(CONFIG_LOONGARCH) +=3D loongarch/ obj-$(CONFIG_RISCV) +=3D riscv/ obj-$(CONFIG_X86) +=3D x86/ diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 808c6746be14..33d752eacde3 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -1465,6 +1465,7 @@ struct kobject *acpi_kobj; EXPORT_SYMBOL_GPL(acpi_kobj); =20 void __weak __init acpi_arch_init(void) { } +void __weak __init acpi_arch_late_init(void) { } =20 static int __init acpi_init(void) { @@ -1503,6 +1504,7 @@ static int __init acpi_init(void) acpi_wakeup_device_init(); acpi_debugger_init(); acpi_setup_sb_notify_handler(); + acpi_arch_late_init(); acpi_viot_init(); return 0; } diff --git a/drivers/acpi/loongarch/Kconfig b/drivers/acpi/loongarch/Kconfig new file mode 100644 index 000000000000..91ba3c35b9bf --- /dev/null +++ b/drivers/acpi/loongarch/Kconfig @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# ACPI Configuration for LOONGARCH +# + +config ACPI_IOVT + bool diff --git a/drivers/acpi/loongarch/Makefile b/drivers/acpi/loongarch/Makef= ile new file mode 100644 index 000000000000..c338d3102fc1 --- /dev/null +++ b/drivers/acpi/loongarch/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-y +=3D init.o +obj-$(CONFIG_ACPI_IOVT) +=3D iovt.o diff --git a/drivers/acpi/loongarch/init.c b/drivers/acpi/loongarch/init.c new file mode 100644 index 000000000000..e7272ee197c7 --- /dev/null +++ b/drivers/acpi/loongarch/init.c @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include "init.h" + +void __init acpi_arch_init(void) +{ + if (IS_ENABLED(CONFIG_ACPI_IOVT)) + acpi_iovt_init(); +} + +void __init acpi_arch_late_init(void) +{ + if (IS_ENABLED(CONFIG_ACPI_IOVT)) + acpi_iovt_late_init(); +} diff --git a/drivers/acpi/loongarch/init.h b/drivers/acpi/loongarch/init.h new file mode 100644 index 000000000000..85e5197553ad --- /dev/null +++ b/drivers/acpi/loongarch/init.h @@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#include + +void __init acpi_iovt_init(void); +void __init acpi_iovt_late_init(void); diff --git a/drivers/acpi/loongarch/iovt.c b/drivers/acpi/loongarch/iovt.c new file mode 100644 index 000000000000..302ca6a75905 --- /dev/null +++ b/drivers/acpi/loongarch/iovt.c @@ -0,0 +1,219 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include "init.h" + +struct iovt_device_entry { + struct list_head list; + int start_devid; + int end_devid; +}; + +struct iovt_fwnode { + struct list_head list; + struct fwnode_handle *fwnode; + int flag; + int segment; + int devid; + int nid; + struct list_head ep_list; +}; + +/* Root pointer to the mapped IOVT table */ +static LIST_HEAD(iovt_fwnode_list); +static DEFINE_SPINLOCK(iovt_fwnode_lock); + +#ifdef CONFIG_PCI +static void __init iovt_enable_acs(struct acpi_iovt_iommu *iommu) +{ + static bool acs_enabled __initdata; + + if (acs_enabled) + return; + + /* IOMMU V1 only supports PCI device management */ + if ((iommu->header.type =3D=3D ACPI_IOVT_IOMMU_V1) || + (iommu->flags & (ACPI_IOVT_IOMMU_PCI_DEVICE | ACPI_IOVT_IOMMU_MAGAGE_= BY_SEGMENT))) { + pci_request_acs(); + acs_enabled =3D true; + } +} +#else +static inline void iovt_enable_acs(struct acpi_iovt_iommu *iommu) { } +#endif + +static int __init iovt_get_pci_iommu_fwnode(struct iovt_fwnode *np, u16 se= gment, u16 bdf) +{ + struct pci_dev *pdev; + struct fwnode_handle *fwnode; + + pdev =3D pci_get_domain_bus_and_slot(segment, PCI_BUS_NUM(bdf), bdf & 0xf= f); + if (!pdev) { + pr_err("No PCI IOMMU found for segment 0x%x bdf 0x%x\n", segment, bdf); + return -ENODEV; + } + + fwnode =3D dev_fwnode(&pdev->dev); + if (!fwnode) { + /* + * PCI devices aren't necessarily described by ACPI. Create a + * fwnode so the IOMMU subsystem can identify this device. + */ + fwnode =3D acpi_alloc_fwnode_static(); + if (!fwnode) { + pci_dev_put(pdev); + return -ENOMEM; + } + set_primary_fwnode(&pdev->dev, fwnode); + } + + np->fwnode =3D dev_fwnode(&pdev->dev); + if (np->flag & ACPI_IOVT_IOMMU_PXM_VALID) + set_dev_node(&pdev->dev, np->nid); + pci_dev_put(pdev); + return 0; +} + +static int __init iovt_add_iommu(struct acpi_iovt_iommu *iommu) +{ + struct iovt_fwnode *np; + struct fwnode_handle *fwnode; + struct acpi_iovt_device_entry *ep; + struct iovt_device_entry *entry; + int i, ret, start_devid; + bool is_start =3D false; + + np =3D kzalloc_obj(struct iovt_fwnode, GFP_ATOMIC); + if (WARN_ON(!np)) + return -ENOMEM; + + INIT_LIST_HEAD(&np->list); + np->flag =3D iommu->flags; + np->segment =3D iommu->segment; + if (np->flag & ACPI_IOVT_IOMMU_PXM_VALID) + np->nid =3D pxm_to_node(iommu->proximity_domain); + + if (np->flag & ACPI_IOVT_IOMMU_PCI_DEVICE) { + np->devid =3D iommu->device_id; + ret =3D iovt_get_pci_iommu_fwnode(np, np->segment, np->devid); + if (ret) { + kfree(np); + return ret; + } + + } else { + fwnode =3D acpi_alloc_fwnode_static(); + if (!fwnode) { + kfree(np); + return -ENOMEM; + } + + np->fwnode =3D fwnode; + } + + /* All devices in the segment are managed by this IOMMU */ + if (np->flag & ACPI_IOVT_IOMMU_MAGAGE_BY_SEGMENT) + goto skip; + + INIT_LIST_HEAD(&np->ep_list); + ep =3D ACPI_ADD_PTR(struct acpi_iovt_device_entry, iommu, iommu->device_e= ntry_offset); + for (i =3D 0; i < iommu->device_entry_num; i++) { + switch (ep->type) { + case ACPI_IOVT_DEVICE_ENTRY_START: + is_start =3D true; + start_devid =3D ep->device_id; + break; + case ACPI_IOVT_DEVICE_ENTRY_END: + if (!is_start) + break; + + entry =3D kzalloc_obj(struct iovt_device_entry, GFP_ATOMIC); + if (!entry) + return -ENOMEM; + + entry->start_devid =3D start_devid; + entry->end_devid =3D ep->device_id; + list_add_tail(&entry->list, &np->ep_list); + is_start =3D false; + break; + case ACPI_IOVT_DEVICE_ENTRY_SINGLE: + entry =3D kzalloc_obj(struct iovt_device_entry, GFP_ATOMIC); + if (!entry) + return -ENOMEM; + + entry->start_devid =3D ep->device_id; + entry->end_devid =3D ep->device_id; + list_add_tail(&entry->list, &np->ep_list); + is_start =3D false; + break; + default: + break; + } + ep =3D ACPI_ADD_PTR(struct acpi_iovt_device_entry, ep, ep->length); + } + +skip: + spin_lock(&iovt_fwnode_lock); + list_add_tail(&np->list, &iovt_fwnode_list); + spin_unlock(&iovt_fwnode_lock); + return 0; +} + +static void __init iovt_init_devices(struct acpi_table_header *header) +{ + struct acpi_iovt_iommu *iommu; + struct acpi_table_iovt *iovt; + int i; + + /* Get the first IOVT node */ + iovt =3D (struct acpi_table_iovt *)header; + iommu =3D ACPI_ADD_PTR(struct acpi_iovt_iommu, iovt, iovt->iommu_offset); + for (i =3D 0; i < iovt->iommu_count; i++) { + iovt_add_iommu(iommu); + iommu =3D ACPI_ADD_PTR(struct acpi_iovt_iommu, iommu, iommu->header.leng= th); + } +} + +void __init acpi_iovt_init(void) +{ + acpi_status status; + struct acpi_table_header *hdr; + struct acpi_table_iovt *iovt; + struct acpi_iovt_iommu *iommu; + int i; + + status =3D acpi_get_table(ACPI_SIG_IOVT, 0, &hdr); + if (ACPI_FAILURE(status)) { + if (status !=3D AE_NOT_FOUND) + pr_err("Failed to get table, %s\n", acpi_format_exception(status)); + + return; + } + + iovt =3D (struct acpi_table_iovt *)&hdr; + iommu =3D ACPI_ADD_PTR(struct acpi_iovt_iommu, iovt, iovt->iommu_offset); + for (i =3D 0; i < iovt->iommu_count; i++) { + iovt_enable_acs(iommu); + iommu =3D ACPI_ADD_PTR(struct acpi_iovt_iommu, iommu, iommu->header.leng= th); + } + + acpi_put_table(hdr); +} + +void __init acpi_iovt_late_init(void) +{ + acpi_status status; + struct acpi_table_header *hdr; + + status =3D acpi_get_table(ACPI_SIG_IOVT, 0, &hdr); + if (ACPI_FAILURE(status)) { + if (status !=3D AE_NOT_FOUND) + pr_err("Failed to get table, %s\n", acpi_format_exception(status)); + + return; + } + + iovt_init_devices(hdr); + acpi_put_table(hdr); +} diff --git a/include/linux/acpi.h b/include/linux/acpi.h index ddacac812094..2a621c095b8b 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -1642,6 +1642,7 @@ static inline int acpi_pptt_get_cpumask_from_cache_id= (u32 cache_id, #endif =20 void acpi_arch_init(void); +void acpi_arch_late_init(void); =20 #ifdef CONFIG_ACPI_PCC void acpi_init_pcc(void); --=20 2.39.3 From nobody Thu Sep 24 15:11:02 2026 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7DB12541E72; Tue, 22 Sep 2026 12:18:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790079509; cv=none; b=rpn5TztFuC2ed9sdjsqTbIzFK7XCPe3ulLIPaQRdbVqeTRWra/9dTrjzNPPDaNJMrxuBzq8Z2rfdzAa7gRulXDJaX3vee8Jcn9a1ldhuwpp9PdSQAGcz3erp3Fhn76W9R/MXaC/wU4re6AlonmL0g6R2pFDfpIq7m/CkvWWhFb0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790079509; c=relaxed/simple; bh=pLW252z9yEnMHMKpqlmSUn5bSCY4r+q8VwadCnjyVHo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HVXo+bBPf2mKoR/r0GR36N44ZNCoD/s45hD7NzZ0w2OLzGPKKPJGoY/j8Yood/2pyQkrP7S3vQDS6SEc3Iktk5/W/M+s5537FW5afhHPSw/+7orco3DeiCkYF5j2a7m0mtHtri4e8sunjkcyD2aSUNl3oPgu8Bp1YnLFctXDLQ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8DxjdIQcrJqUaAOAA--.42497S3; Tue, 22 Sep 2026 20:18:24 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowJBx6c0LcrJqysAjAA--.44690S5; Tue, 22 Sep 2026 20:18:24 +0800 (CST) From: Bibo Mao To: Huacai Chen , "Rafael J . Wysocki" , Maciej Wieczor-Retman , Pawel Chmielewski Cc: Len Brown , linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, lixianglai@loongson.cn Subject: [PATCH v4 3/4] ACPI: scan: Add support for LoongArch in acpi_iommu_configure_id() Date: Tue, 22 Sep 2026 20:10:57 +0800 Message-Id: <20260922121058.972734-4-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20260922121058.972734-1-maobibo@loongson.cn> References: <20260922121058.972734-1-maobibo@loongson.cn> 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 X-CM-TRANSID: qMiowJBx6c0LcrJqysAjAA--.44690S5 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Content-Type: text/plain; charset="utf-8" acpi_iommu_configure_id() currently supports only IORT and VIOT. Add support for IOVT as well. Signed-off-by: Bibo Mao Acked-by: Rafael J. Wysocki (Intel) --- drivers/acpi/loongarch/iovt.c | 61 +++++++++++++++++++++++++++++++++++ drivers/acpi/scan.c | 3 ++ include/linux/acpi_iovt.h | 13 ++++++++ 3 files changed, 77 insertions(+) create mode 100644 include/linux/acpi_iovt.h diff --git a/drivers/acpi/loongarch/iovt.c b/drivers/acpi/loongarch/iovt.c index 302ca6a75905..df14ce48eac6 100644 --- a/drivers/acpi/loongarch/iovt.c +++ b/drivers/acpi/loongarch/iovt.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only =20 #include +#include #include #include "init.h" =20 @@ -217,3 +218,63 @@ void __init acpi_iovt_late_init(void) iovt_init_devices(hdr); acpi_put_table(hdr); } + +static int iovt_pci_dev_iommu_init(struct pci_dev *pdev, u16 dev_id, void = *data) +{ + u32 sbdf; + struct iovt_fwnode *np; + struct device *aliased_dev =3D data; + u32 domain =3D pci_domain_nr(pdev->bus); + struct iovt_device_entry *entry; + bool found =3D false; + + list_for_each_entry(np, &iovt_fwnode_list, list) { + if (domain !=3D np->segment) + continue; + + /* We're not translating ourself */ + if (dev_id =3D=3D np->devid) + return -EINVAL; + + if (np->flag & ACPI_IOVT_IOMMU_MAGAGE_BY_SEGMENT) { + found =3D true; + break; + } + + list_for_each_entry(entry, &np->ep_list, list) { + if (dev_id < entry->start_devid) + continue; + + if (dev_id > entry->end_devid) + continue; + + found =3D true; + break; + } + + if (found) + break; + } + + if (!found) + return -ENODEV; + + sbdf =3D (domain << 16) + dev_id; + return acpi_iommu_fwspec_init(aliased_dev, sbdf, np->fwnode); +} + +/* + * iovt_iommu_configure_id - Set-up IOMMU configuration for a device. + * + * @dev: device to configure + * @id_in: optional input id const value pointer + * + * Returns: 0 on success, <0 on failure + */ +int iovt_iommu_configure_id(struct device *dev, const u32 *id_in) +{ + if (!dev_is_pci(dev)) + return -ENODEV; + + return pci_for_each_dma_alias(to_pci_dev(dev), iovt_pci_dev_iommu_init, d= ev); +} diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 163a3cccf197..827cd526a099 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -1626,6 +1627,8 @@ static int acpi_iommu_configure_id(struct device *dev= , const u32 *id_in) err =3D iort_iommu_configure_id(dev, id_in); if (err && err !=3D -EPROBE_DEFER) err =3D rimt_iommu_configure_id(dev, id_in); + if (err && err !=3D -EPROBE_DEFER) + err =3D iovt_iommu_configure_id(dev, id_in); if (err && err !=3D -EPROBE_DEFER) err =3D viot_iommu_configure(dev); =20 diff --git a/include/linux/acpi_iovt.h b/include/linux/acpi_iovt.h new file mode 100644 index 000000000000..25a846b96260 --- /dev/null +++ b/include/linux/acpi_iovt.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ACPI_IOVT_H__ +#define __ACPI_IOVT_H__ + +#if defined(CONFIG_IOMMU_API) && defined(CONFIG_ACPI_IOVT) +int iovt_iommu_configure_id(struct device *dev, const u32 *id_in); +#else +static inline int iovt_iommu_configure_id(struct device *dev, const u32 *i= d_in) +{ return -ENODEV; } +#endif + +#endif --=20 2.39.3 From nobody Thu Sep 24 15:11:02 2026 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B268954147A; Tue, 22 Sep 2026 12:18:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790079511; cv=none; b=Mso+aIgg7Datj3Ag9ZlO/DUHjV3ootnXXkCyos6yCnpOXjocso5VLy4XSB7N0rTllJHXz4uEIr1RhXqZDDAoK3ig3WRRJEpb6xIZ9iiqqbMWRdvv3l5Yb4aYFxj5Gi/2gsf4aN/UMGN8oXhh2W4bqdroQO5LbO6ryBnnK261WKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790079511; c=relaxed/simple; bh=XnTjQ59ZCsiFN7d715NkJvR8ea2j8/XgdgbYql7zwSw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Dmod3UqnQApsPdfxvc6/hnQBLuk71loUQZ0nueOh6swNc1Kf6rv9bULO01i1SYoGHhXVyL1f1VE8T3rG4PwFWejurdJZnrBc9q00ucIwUA1QDB6BHHXFwAUkQrejUf7iD0HWlkwXqf2GIBw6GoVlMaKghXFEf47y+UWtZGbsya4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8AxHNITcrJqVqAOAA--.42720S3; Tue, 22 Sep 2026 20:18:27 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowJAxHs8ScrJqzMAjAA--.45156S2; Tue, 22 Sep 2026 20:18:26 +0800 (CST) From: Bibo Mao To: Huacai Chen , "Rafael J . Wysocki" , Maciej Wieczor-Retman , Pawel Chmielewski Cc: Len Brown , linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, lixianglai@loongson.cn Subject: [PATCH v4 4/4] MAINTAINERS: Add entry for drivers/acpi/loongarch Date: Tue, 22 Sep 2026 20:10:58 +0800 Message-Id: <20260922121058.972734-5-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20260922121058.972734-1-maobibo@loongson.cn> References: <20260922121058.972734-1-maobibo@loongson.cn> 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 X-CM-TRANSID: qMiowJAxHs8ScrJqzMAjAA--.45156S2 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Content-Type: text/plain; charset="utf-8" ACPI defines few LoongArch specific tables which need parsing code added in drivers/acpi/loongarch. Add maintainer entries for this newly created folder. Signed-off-by: Bibo Mao --- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index cc3cae2e378b..f9ae86a42dec 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -347,6 +347,15 @@ S: Maintained F: drivers/acpi/riscv/ F: include/linux/acpi_rimt.h =20 +ACPI FOR LOONGARCH (ACPI/LoongArch) +M: Bibo Mao +M: Huacai Chen +L: linux-acpi@vger.kernel.org +L: loongarch@lists.linux.dev +S: Maintained +F: drivers/acpi/loongarch/ +F: include/linux/acpi_iovt.h + ACPI PCC(Platform Communication Channel) MAILBOX DRIVER M: Sudeep Holla L: linux-acpi@vger.kernel.org --=20 2.39.3