RISC-V: ACPI: Add external interrupt controller support
Sunil V L
maintainerv4 cover RISC-V: ACPI: Add external interrupt controller support
This series adds support for the below ECR approved by ASWG.
1) MADT - https://drive.google.com/file/d/1oMGPyOD58JaPgMl1pKasT-VKsIKia7zR/view?usp=sharing
The series primarily enables irqchip drivers for RISC-V ACPI based platforms.
The series can be broadly categorized like below.
1) PCI ACPI related functions are migrated from arm64 to common file so that we don't need to duplicate them for RISC-V.
2) Added support for re-ordering the probe of interrupt controllers when IRQCHIP_ACPI_DECLARE is used.
3) To ensure probe order between interrupt controllers and devices, implicit dependency is created similar to when _DEP is present.
4) When PNP devices like Generic 16550A UART, have the dependency on the interrupt controller, they will not be added to PNP data structures. So, added second phase of pnpacpi_init to handle this.
5) ACPI support added in RISC-V interrupt controller drivers.
This series is still kept as RFC to seek feedback on above design changes. Looking forward for the feedback!
Changes since RFC v3:
1) Moved to _DEP method instead of fw_devlink.
2) PLIC/APLIC driver probe using namespace devices.
3) Handling PNP devices as part of clearing dependency.
4) Rebased to latest linux-next to get AIA DT drivers.
Changes since RFC v2:
1) Introduced fw_devlink for ACPI nodes for IRQ dependency.
2) Dropped patches in drivers which are not required due to fw_devlink support.
3) Dropped pci_set_msi() patch and added a patch in pci_create_root_bus().
4) Updated pnp_irq() patch so that none of the actual PNP drivers need to change.
Changes since RFC v1:
1) Abandoned swnode approach as per Marc's feedback.
2) To cope up with AIA series changes which changed irqchip driver probe from core_initcall() to platform_driver, added patches to support deferred probing.
3) Rebased on top of Anup's AIA v11 and added tags.
To test the series,
1) Qemu should be built using the riscv_acpi_namespace_v1 branch at
https://github.com/vlsunil/qemu.git
2) EDK2 should be built using the instructions at:
https://github.com/tianocore/edk2/blob/master/OvmfPkg/RiscVVirt/README.md
3) Build Linux using this series.
Run Qemu:
qemu-system-riscv64 \
-M virt,pflash0=pflash0,pflash1=pflash1,aia=aplic-imsic \
-m 2G -smp 8 \
-serial mon:stdio \
-device virtio-gpu-pci -full-screen \
-device qemu-xhci \
-device usb-kbd \
-blockdev node-name=pflash0,driver=file,read-only=on,filename=RISCV_VIRT_CODE.fd \
-blockdev node-name=pflash1,driver=file,filename=RISCV_VIRT_VARS.fd \
-netdev user,id=net0 -device virtio-net-pci,netdev=net0 \
-kernel arch/riscv/boot/Image \
-initrd rootfs.cpio \
-append "root=/dev/ram ro console=ttyS0 rootwait earlycon=uart8250,mmio,0x10000000"
To boot with APLIC only, use aia=aplic.
To boot with PLIC, remove aia= option.
This series is also available in acpi_b2_v4_autodep_v1 branch at
https://github.com/vlsunil/linux.git
Based-on: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tag/?h=next-20240415
Sunil V L (20):
arm64: PCI: Migrate ACPI related functions to pci-acpi.c
RISC-V: ACPI: Implement PCI related functionality
PCI: Make pci_create_root_bus() declare its reliance on MSI domains
ACPI: scan.c: Add weak arch specific function to reorder the IRQCHIP
probe
ACPI: RISC-V: Implement arch function to reorder irqchip probe entries
ACPI: bus: Add acpi_riscv_init function
RISC-V: Kconfig: Select deferred GSI probe for ACPI systems
ACPI: scan: Refactor dependency creation drivers/acpi/scan.c: Update _DEP honor list
RISC-V: ACPI: Initialize GSI mapping structures
ACPI: scan.c: Define weak function to populate dependencies
RISC-V: ACPI: Implement function to add implicit dependencies ACPI/PNP: Initialize PNP devices skipped due to _DEP
irqchip: riscv-intc: Add ACPI support for AIA
irqchip: riscv-imsic: Add ACPI support
irqchip: riscv-aplic: Add ACPI support
irqchip: irq-sifive-plic: Add ACPI support
ACPI: bus: Add RINTC IRQ model for RISC-V
irqchip: riscv-intc: Set ACPI irqmodel
ACPI: pci_link: Clear the dependencies after probe
arch/arm64/kernel/pci.c | 191 ------------ arch/riscv/Kconfig | 3 + arch/riscv/include/asm/irq.h | 57 ++++ arch/riscv/kernel/acpi.c | 31 +- drivers/acpi/Kconfig | 3 + drivers/acpi/bus.c | 4 + drivers/acpi/pci_link.c | 3 + drivers/acpi/riscv/Makefile | 2 +- drivers/acpi/riscv/init.c | 14 + drivers/acpi/riscv/init.h | 4 + drivers/acpi/riscv/irq.c | 323 +++++++++++++++++++++ drivers/acpi/scan.c | 69 +++-- drivers/irqchip/irq-riscv-aplic-direct.c | 20 +- drivers/irqchip/irq-riscv-aplic-main.c | 70 +++-- drivers/irqchip/irq-riscv-aplic-main.h | 1 + drivers/irqchip/irq-riscv-aplic-msi.c | 9 +- drivers/irqchip/irq-riscv-imsic-early.c | 52 +++- drivers/irqchip/irq-riscv-imsic-platform.c | 32 +- drivers/irqchip/irq-riscv-imsic-state.c | 115 ++++---- drivers/irqchip/irq-riscv-imsic-state.h | 2 +- drivers/irqchip/irq-riscv-intc.c | 102 ++++++- drivers/irqchip/irq-sifive-plic.c | 89 ++++-- drivers/pci/pci-acpi.c | 182 ++++++++++++ drivers/pci/probe.c | 3 + drivers/pnp/pnpacpi/core.c | 24 +- drivers/pnp/pnpacpi/rsparser.c | 63 ++-- include/acpi/acpi_bus.h | 2 + include/linux/acpi.h | 9 + include/linux/irqchip/riscv-imsic.h | 10 + include/linux/pnp.h | 7 + 30 files changed, 1108 insertions(+), 388 deletions(-) create mode 100644 drivers/acpi/riscv/init.c create mode 100644 drivers/acpi/riscv/init.h create mode 100644 drivers/acpi/riscv/irq.c
Signature · 1 line
2.40.1
Sunil V L
maintainerRFC PATCH v4 1/20 arm64: PCI: Migrate ACPI related functions to pci-acpi.c
The functions defined in arm64 for ACPI support are required for RISC-V also. To avoid duplication, move these functions to common location.
--- arch/arm64/kernel/pci.c | 191 ---------------------------------------- drivers/pci/pci-acpi.c | 182 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 182 insertions(+), 191 deletions(-)
arch/arm64/kernel/pci.c +0 -191
@@ -6,28 +6,7 @@* Copyright (C) 2014 ARM Ltd. */ -#include <linux/acpi.h> -#include <linux/init.h> -#include <linux/io.h> -#include <linux/kernel.h> -#include <linux/mm.h> #include <linux/pci.h> -#include <linux/pci-acpi.h> -#include <linux/pci-ecam.h> -#include <linux/slab.h> - -#ifdef CONFIG_ACPI -/* -* Try to assign the IRQ number when probing a new device -*/ -int pcibios_alloc_irq (struct pci_dev *dev) -{ -if (!acpi_disabled) -acpi_pci_irq_enable (dev); - -return 0 ; -} -#endif /* * raw_pci_read/write - Platform-specific PCI config space access.
@@ -61,173 +40,3 @@ int pcibus_to_node(struct pci_bus *bus)EXPORT_SYMBOL (pcibus_to_node);#endif - -#ifdef CONFIG_ACPI - -struct acpi_pci_generic_root_info { -struct acpi_pci_root_info common; -struct pci_config_window *cfg;/* config space mapping */ -}; - -int acpi_pci_bus_find_domain_nr (struct pci_bus *bus) -{ -struct pci_config_window *cfg = bus->sysdata; -struct acpi_device *adev =to_acpi_device (cfg->parent); -struct acpi_pci_root *root =acpi_driver_data (adev); - -return root->segment; -} - -int pcibios_root_bridge_prepare (struct pci_host_bridge *bridge) -{ -struct pci_config_window *cfg; -struct acpi_device *adev; -struct device *bus_dev; - -if (acpi_disabled) -return 0 ; - - cfg = bridge->bus->sysdata; - -/* -* On Hyper-V there is no corresponding ACPI device for a root bridge, -* therefore ->parent is set as NULL by the driver. And set 'adev' as -* NULL in this case because there is no proper ACPI device. -*/ -if (!cfg->parent) - adev =NULL ; -else - adev =to_acpi_device (cfg->parent); - - bus_dev = &bridge->bus->dev; - -ACPI_COMPANION_SET (&bridge->dev, adev); -set_dev_node (bus_dev,acpi_get_node (acpi_device_handle (adev))); - -return 0 ; -} - -static int pci_acpi_root_prepare_resources (struct acpi_pci_root_info *ci) -{ -struct resource_entry *entry, *tmp; -int status; - - status =acpi_pci_probe_root_resources (ci); -resource_list_for_each_entry_safe (entry, tmp, &ci->resources) { -if (!(entry->res->flags &IORESOURCE_WINDOW )) -resource_list_destroy_entry (entry); - } -return status; -} - -/* -* Lookup the bus range for the domain in MCFG, and set up config space -* mapping. -*/ -static struct pci_config_window * -pci_acpi_setup_ecam_mapping (struct acpi_pci_root *root) -{ -struct device *dev = &root->device->dev; -struct resource *bus_res = &root->secondary; -u16 seg = root->segment; -const struct pci_ecam_ops *ecam_ops; -struct resource cfgres; -struct acpi_device *adev; -struct pci_config_window *cfg; -int ret; - - ret =pci_mcfg_lookup (root, &cfgres, &ecam_ops); -if (ret) { -dev_err (dev,"%04x:%pR ECAM region not found\n" , seg, bus_res); -return NULL ; - } - - adev =acpi_resource_consumer (&cfgres); -if (adev) -dev_info (dev,"ECAM area %pR reserved by %s\n" , &cfgres, -dev_name (&adev->dev)); -else -dev_warn (dev,FW_BUG "ECAM area %pR not reserved in ACPI namespace\n" , - &cfgres); - - cfg =pci_ecam_create (dev, &cfgres, bus_res, ecam_ops); -if (IS_ERR (cfg)) { -dev_err (dev,"%04x:%pR error %ld mapping ECAM\n" , seg, bus_res, -PTR_ERR (cfg)); -return NULL ; - } - -return cfg; -} - -/* release_info: free resources allocated by init_info */ -static void pci_acpi_generic_release_info (struct acpi_pci_root_info *ci) -{ -struct acpi_pci_generic_root_info *ri; - - ri = container_of(ci, struct acpi_pci_generic_root_info, common); -pci_ecam_free (ri->cfg); -kfree (ci->ops); -kfree (ri); -} - -/* Interface called from ACPI code to setup PCI host controller */ -struct pci_bus *pci_acpi_scan_root (struct acpi_pci_root *root) -{ -struct acpi_pci_generic_root_info *ri; -struct pci_bus *bus, *child; -struct acpi_pci_root_ops *root_ops; -struct pci_host_bridge *host; - - ri =kzalloc (sizeof (*ri),GFP_KERNEL ); -if (!ri) -return NULL ; - - root_ops =kzalloc (sizeof (*root_ops),GFP_KERNEL ); -if (!root_ops) { -kfree (ri); -return NULL ; - } - - ri->cfg =pci_acpi_setup_ecam_mapping (root); -if (!ri->cfg) { -kfree (ri); -kfree (root_ops); -return NULL ; - } - - root_ops->release_info = pci_acpi_generic_release_info; - root_ops->prepare_resources = pci_acpi_root_prepare_resources; - root_ops->pci_ops = (struct pci_ops *)&ri->cfg->ops->pci_ops; - bus =acpi_pci_root_create (root, root_ops, &ri->common, ri->cfg); -if (!bus) -return NULL ; - -/* If we must preserve the resource configuration, claim now */ - host =pci_find_host_bridge (bus); -if (host->preserve_config) -pci_bus_claim_resources (bus); - -/* -* Assign whatever was left unassigned. If we didn't claim above, -* this will reassign everything. -*/ -pci_assign_unassigned_root_bus_resources (bus); - -list_for_each_entry (child, &bus->children, node) -pcie_bus_configure_settings (child); - -return bus; -} - -void pcibios_add_bus (struct pci_bus *bus) -{ -acpi_pci_add_bus (bus); -} - -void pcibios_remove_bus (struct pci_bus *bus) -{ -acpi_pci_remove_bus (bus); -} - -#endif
drivers/pci/pci-acpi.c +182 -0
191 lines not on this page · raw message
Signature · 1 line
2.40.1
Sunil V L
maintainerRFC PATCH v4 2/20 RISC-V: ACPI: Implement PCI related functionality
In reply to Sunil V LReplace the dummy implementation for PCI related functions with actual implementation. This needs ECAM and MCFG CONFIG options to be enabled for RISC-V.
--- arch/riscv/Kconfig | 2 ++ arch/riscv/kernel/acpi.c | 31 ++++++++++++++----------------- drivers/pci/pci-acpi.c | 2 +- 3 files changed, 17 insertions(+), 18 deletions(-)
arch/riscv/Kconfig +2 -0
@@ -13,6 +13,7 @@ config 32BIT config RISCV def_bool y select ACPI_GENERIC_GSI if ACPI + select ACPI_MCFG if (ACPI && PCI) select ACPI_REDUCED_HARDWARE_ONLY if ACPI select ARCH_DMA_DEFAULT_COHERENT select ARCH_ENABLE_HUGEPAGE_MIGRATION if HUGETLB_PAGE && MIGRATION
@@ -173,6 +174,7 @@ config RISCV select OF_EARLY_FLATTREE select OF_IRQ select PCI_DOMAINS_GENERIC if PCI + select PCI_ECAM if (ACPI && PCI) select PCI_MSI if PCI select RISCV_ALTERNATIVE if !XIP_KERNEL select RISCV_APLIC
arch/riscv/kernel/acpi.c +14 -17
@@ -306,29 +306,26 @@ void __iomem *acpi_os_ioremap(acpi_physical_address phys, acpi_size size)#ifdef CONFIG_PCI /* -* These interfaces are defined just to enable building ACPI core. -* TODO: Update it with actual implementation when external interrupt -* controller support is added in RISC-V ACPI. +* raw_pci_read/write - Platform-specific PCI config space access. */ -int raw_pci_read (unsigned int domain,unsigned int bus,unsigned int devfn, -int reg,int len,u32 *val) +int raw_pci_read (unsigned int domain,unsigned int bus, +unsigned int devfn,int reg,int len,u32 *val) { -return PCIBIOS_DEVICE_NOT_FOUND ; -} +struct pci_bus *b =pci_find_bus (domain, bus); -int raw_pci_write (unsigned int domain,unsigned int bus,unsigned int devfn, -int reg,int len,u32 val) -{ -return PCIBIOS_DEVICE_NOT_FOUND ; +if (!b) +return PCIBIOS_DEVICE_NOT_FOUND ; +return b->ops->read (b, devfn, reg, len, val); } -int acpi_pci_bus_find_domain_nr (struct pci_bus *bus) +int raw_pci_write (unsigned int domain,unsigned int bus, +unsigned int devfn,int reg,int len,u32 val) { -return -1 ; -} +struct pci_bus *b =pci_find_bus (domain, bus); -struct pci_bus *pci_acpi_scan_root (struct acpi_pci_root *root) -{ -return NULL ; +if (!b) +return PCIBIOS_DEVICE_NOT_FOUND ; +return b->ops->write (b, devfn, reg, len, val); } +#endif /* CONFIG_PCI */
drivers/pci/pci-acpi.c +1 -1
@@ -1521,7 +1521,7 @@ static int __init acpi_pci_init(void) }arch_initcall (acpi_pci_init); -#if defined(CONFIG_ARM64 ) +#if defined(CONFIG_ARM64 ) || defined(CONFIG_RISCV )/* * Try to assign the IRQ number when probing a new device
Signature · 1 line
2.40.1
Sunil V L
maintainerRFC PATCH v4 3/20 PCI: Make pci_create_root_bus() declare its reliance on MSI domains
In reply to Sunil V LSimilar to commit 9ec37efb8783 ("PCI/MSI: Make pci_host_common_probe() declare its reliance on MSI domains"), declare this dependency for PCI probe in ACPI based flow.
This is required especially for RISC-V platforms where MSI controller can be absent. However, setting this for all architectures seem to cause issues on non RISC-V architectures [1]. Hence, enabled this only for RISC-V.
[1] - https://lore.kernel.org/oe-lkp/[email protected]
--- drivers/pci/probe.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/pci/probe.c +3 -0
@@ -3048,6 +3048,9 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus, bridge->sysdata = sysdata; bridge->busnr = bus; bridge->ops = ops; +#ifdef CONFIG_RISCV + bridge->msi_domain = true; +#endif error =pci_register_host_bridge (bridge);if (error <0 )
Signature · 1 line
2.40.1
Sunil V L
maintainerRFC PATCH v4 4/20 ACPI: scan.c: Add weak arch specific function to reorder the IRQCHIP probe
In reply to Sunil V LUnlike OF framework, the irqchip probe using IRQCHIP_ACPI_DECLARE has no order defined. Depending on the driver Makefile is not a good idea. So, usually it is worked around by mandating only root interrupt controller probed using IRQCHIP_ACPI_DECLARE and other interrupt controllers are probed via cascade mechanism.
However, this is also not a clean solution because if there are multiple root controllers (ex: RINTC in RISC-V which is per CPU) which need to be probed first, then the cascade will happen for every root controller. So, introduce a architecture specific weak function to order the probing of the interrupt controllers which can be implemented by different architectures as per their interrupt controller hierarchy.
--- drivers/acpi/scan.c | 3 +++ include/linux/acpi.h | 2 ++ 2 files changed, 5 insertions(+)
drivers/acpi/scan.c +3 -0
@@ -2749,6 +2749,8 @@ static int __init acpi_match_madt(union acpi_subtable_headers *header,return 0 ; } +void __weak arch_sort_irqchip_probe (struct acpi_probe_entry *ap_head,int nr) { } +int __init __acpi_probe_device_table (struct acpi_probe_entry *ap_head,int nr) {int count =0 ;
@@ -2757,6 +2759,7 @@ int __init __acpi_probe_device_table(struct acpi_probe_entry *ap_head, int nr)return 0 ;mutex_lock (&acpi_probe_mutex); +arch_sort_irqchip_probe (ap_head, nr);for (ape = ap_head; nr; ape++, nr--) {if (ACPI_COMPARE_NAMESEG (ACPI_SIG_MADT , ape->id)) { acpi_probe_count =0 ;
include/linux/acpi.h +2 -0
@@ -1337,6 +1337,8 @@ struct acpi_probe_entry {kernel_ulong_t driver_data; }; +void arch_sort_irqchip_probe (struct acpi_probe_entry *ap_head,int nr); +#define ACPI_DECLARE_PROBE_ENTRY (table, name, table_id, subtable, \ valid, data, fn) \ static const struct acpi_probe_entry __acpi_probe_##name \
Signature · 1 line
2.40.1
Sunil V L
maintainerRFC PATCH v4 5/20 ACPI: RISC-V: Implement arch function to reorder irqchip probe entries
In reply to Sunil V LACPI MADT entries for interrupt controllers don't have a way to describe the hierarchy. However, the hierarchy is known to the architecture and on RISC-V platforms, the MADT sub table types are ordered in the incremental order from the root controller which is RINTC. So, add architecture function for RISC-V to reorder the interrupt controller probing as per the hierarchy as below.
--- drivers/acpi/riscv/Makefile | 2 +- drivers/acpi/riscv/irq.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 drivers/acpi/riscv/irq.c
drivers/acpi/riscv/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-y += rhct.o +obj-y += rhct.o irq.o obj-$(CONFIG_ACPI_PROCESSOR_IDLE) += cpuidle.o obj-$(CONFIG_ACPI_CPPC_LIB) += cppc.o
drivers/acpi/riscv/irq.c new file +32 -0
@@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2023, Ventana Micro Systems Inc +* Author: Sunil V L <[email protected]> +* +*/ + +#include <linux/acpi.h> +#include <linux/sort.h> + +static int irqchip_cmp_func (const void *in0,const void *in1) +{ +struct acpi_probe_entry *elem0 = (struct acpi_probe_entry *)in0; +struct acpi_probe_entry *elem1 = (struct acpi_probe_entry *)in1; + +return (elem0->type > elem1->type) - (elem0->type < elem1->type); +} + +/* +* RISC-V irqchips in MADT of ACPI spec are defined in the same order how +* they should be probed. Since IRQCHIP_ACPI_DECLARE doesn't define any +* order, this arch function will reorder the probe functions as per the +* required order for the architecture. +*/ +void arch_sort_irqchip_probe (struct acpi_probe_entry *ap_head,int nr) +{ +struct acpi_probe_entry *ape = ap_head; + +if (nr ==1 || !ACPI_COMPARE_NAMESEG (ACPI_SIG_MADT , ape->id)) +return ; +sort (ape, nr,sizeof (*ape), irqchip_cmp_func,NULL ); +}
Signature · 1 line
2.40.1
Sunil V L
maintainerRFC PATCH v4 6/20 ACPI: bus: Add acpi_riscv_init function
In reply to Sunil V LAdd a new function for RISC-V to do any architecture specific initialization. This function will be used to create platform devices like APLIC, PLIC, RISC-V IOMMU etc. This is similar to acpi_arm_init().
--- drivers/acpi/bus.c | 1 + drivers/acpi/riscv/Makefile | 2 +- drivers/acpi/riscv/init.c | 12 ++++++++++++ include/linux/acpi.h | 6 ++++++ 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 drivers/acpi/riscv/init.c
drivers/acpi/bus.c +1 -0
@@ -1446,6 +1446,7 @@ static int __init acpi_init(void)acpi_hest_init ();acpi_ghes_init ();acpi_arm_init (); +acpi_riscv_init ();acpi_scan_init ();acpi_ec_init ();acpi_debugfs_init ();
drivers/acpi/riscv/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-y += rhct.o irq.o +obj-y += rhct.o irq.o init.o obj-$(CONFIG_ACPI_PROCESSOR_IDLE) += cpuidle.o obj-$(CONFIG_ACPI_CPPC_LIB) += cppc.o
drivers/acpi/riscv/init.c new file +12 -0
@@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2023, Ventana Micro Systems Inc +* Author: Sunil V L <[email protected]> +* +*/ + +#include <linux/acpi.h> + +void __init acpi_riscv_init (void ) +{ +}
include/linux/acpi.h +6 -0
@@ -1525,6 +1525,12 @@ void acpi_arm_init(void);static inline void acpi_arm_init (void ) { }#endif +#ifdef CONFIG_RISCV +void acpi_riscv_init (void ); +#else +static inline void acpi_riscv_init (void ) { } +#endif +#ifdef CONFIG_ACPI_PCC void acpi_init_pcc (void );#else
Signature · 1 line
2.40.1
Sunil V L
maintainerRFC PATCH v4 7/20 RISC-V: Kconfig: Select deferred GSI probe for ACPI systems
In reply to Sunil V LOn RISC-V platforms, apart from root interrupt controllers (which provide local interrupts and IPI), other interrupt controllers in the hierarchy are probed late. Enable this CONFIG option for RISC-V ACPI based platforms.
--- arch/riscv/Kconfig | 1 + drivers/acpi/Kconfig | 3 +++ 2 files changed, 4 insertions(+)
arch/riscv/Kconfig +1 -0
@@ -15,6 +15,7 @@ config RISCV select ACPI_GENERIC_GSI if ACPI select ACPI_MCFG if (ACPI && PCI) select ACPI_REDUCED_HARDWARE_ONLY if ACPI + select ARCH_ACPI_DEFERRED_GSI if ACPI select ARCH_DMA_DEFAULT_COHERENT select ARCH_ENABLE_HUGEPAGE_MIGRATION if HUGETLB_PAGE && MIGRATION select ARCH_ENABLE_SPLIT_PMD_PTLOCK if PGTABLE_LEVELS > 2
drivers/acpi/Kconfig +3 -0
@@ -587,6 +587,9 @@ config ACPI_PRMT substantially increase computational overhead related to the initialization of some server systems. +config ARCH_ACPI_DEFERRED_GSI + bool + endif # ACPI config X86_PM_TIMER
Signature · 1 line
2.40.1
Sunil V L
maintainerRFC PATCH v4 8/20 ACPI: scan: Refactor dependency creation
In reply to Sunil V LSome architectures like RISC-V will use implicit dependencies like GSI map to create dependencies between interrupt controller and devices. To support doing that, the function which creates the dependency, is refactored bit and made public so that dependency can be added from outside of scan.c as well.
--- drivers/acpi/scan.c | 48 ++++++++++++++++++++++++----------------- include/acpi/acpi_bus.h | 1 + 2 files changed, 29 insertions(+), 20 deletions(-)
drivers/acpi/scan.c +28 -20
@@ -2028,33 +2028,18 @@ static void acpi_scan_init_hotplug(struct acpi_device *adev) } } -static u32 acpi_scan_check_dep (acpi_handle handle) +int acpi_scan_add_dep (acpi_handle handle,struct acpi_handle_list *dep_devices) { -struct acpi_handle_list dep_devices;u32 count;int i; -/* -* Check for _HID here to avoid deferring the enumeration of: -* 1. PCI devices. -* 2. ACPI nodes describing USB ports. -* Still, checking for _HID catches more then just these cases ... -*/ -if (!acpi_has_method (handle,"_DEP" ) || !acpi_has_method (handle,"_HID" )) -return 0 ; - -if (!acpi_evaluate_reference (handle,"_DEP" ,NULL , &dep_devices)) { -acpi_handle_debug (handle,"Failed to evaluate _DEP.\n" ); -return 0 ; - } - -for (count =0 , i =0 ; i < dep_devices.count; i++) { +for (count =0 , i =0 ; i < dep_devices->count; i++) {struct acpi_device_info *info;struct acpi_dep_data *dep;bool skip, honor_dep;acpi_status status; - status =acpi_get_object_info (dep_devices.handles[i], &info); + status =acpi_get_object_info (dep_devices->handles[i], &info);if (ACPI_FAILURE (status)) {acpi_handle_debug (handle,"Error reading _DEP device info\n" );continue ;
@@ -2073,7 +2058,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle) count++; - dep->supplier = dep_devices.handles[i]; + dep->supplier = dep_devices->handles[i]; dep->consumer = handle; dep->honor_dep = honor_dep;
@@ -2082,7 +2067,30 @@ static u32 acpi_scan_check_dep(acpi_handle handle)mutex_unlock (&acpi_dep_list_lock); } -acpi_handle_list_free (&dep_devices); +acpi_handle_list_free (dep_devices); +return count; +} + +static u32 acpi_scan_check_dep (acpi_handle handle) +{ +struct acpi_handle_list dep_devices; +u32 count =0 ; + +/* +* Check for _HID here to avoid deferring the enumeration of: +* 1. PCI devices. +* 2. ACPI nodes describing USB ports. +* Still, checking for _HID catches more then just these cases ... +*/ +if (!acpi_has_method (handle,"_DEP" ) || !acpi_has_method (handle,"_HID" )) +return count; + +if (!acpi_evaluate_reference (handle,"_DEP" ,NULL , &dep_devices)) { +acpi_handle_debug (handle,"Failed to evaluate _DEP.\n" ); +return count; + } + + count +=acpi_scan_add_dep (handle, &dep_devices);return count; }
include/acpi/acpi_bus.h +1 -0
@@ -993,6 +993,7 @@ static inline void acpi_put_acpi_dev(struct acpi_device *adev)int acpi_wait_for_acpi_ipmi (void ); +int acpi_scan_add_dep (acpi_handle handle,struct acpi_handle_list *dep_devices);#else /* CONFIG_ACPI */ static inline int register_acpi_bus_type (void *bus) {return 0 ; }
Signature · 1 line
2.40.1
Sunil V L
maintainerRFC PATCH v4 9/20 drivers/acpi/scan.c: Update _DEP honor list
In reply to Sunil V LRISC-V PLIC and APLIC will have _DEP from devices using GSI. So, add these devices into the honor list.
--- drivers/acpi/scan.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/acpi/scan.c +2 -0
@@ -832,6 +832,8 @@ static const char * const acpi_honor_dep_ids[] = {"INTC1095" ,/* IVSC (ADL) driver must be loaded to allow i2c access to camera sensors */ "INTC100A" ,/* IVSC (RPL) driver must be loaded to allow i2c access to camera sensors */ "INTC10CF" ,/* IVSC (MTL) driver must be loaded to allow i2c access to camera sensors */ +"RSCV0001" ,/* RISC-V PLIC */ +"RSCV0002" ,/* RISC-V APLIC */ NULL };
Signature · 1 line
2.40.1
Sunil V L
maintainerRFC PATCH v4 10/20 RISC-V: ACPI: Initialize GSI mapping structures
In reply to Sunil V LRISC-V has PLIC and APLIC in MADT as well as namespace devices. Initialize the list of those structures using MADT and namespace devices to create mapping between the ACPI handle and the GSI ranges. This is will be used later to add dependencies.
--- arch/riscv/include/asm/irq.h | 22 +++++ drivers/acpi/riscv/init.c | 2 + drivers/acpi/riscv/init.h | 4 + drivers/acpi/riscv/irq.c | 159 +++++++++++++++++++++++++++++++++++ 4 files changed, 187 insertions(+) create mode 100644 drivers/acpi/riscv/init.h
arch/riscv/include/asm/irq.h +22 -0
@@ -16,4 +16,26 @@ void riscv_set_intc_hwnode_fn(struct fwnode_handle *(*fn)(void));struct fwnode_handle *riscv_get_intc_hwnode (void ); +#ifdef CONFIG_ACPI + +enum riscv_irqchip_type { +ACPI_RISCV_IRQCHIP_INTC =0x00 , +ACPI_RISCV_IRQCHIP_IMSIC =0x01 , +ACPI_RISCV_IRQCHIP_PLIC =0x02 , +ACPI_RISCV_IRQCHIP_APLIC =0x03 , +}; + +int riscv_acpi_get_gsi_info (struct fwnode_handle *fwnode,u32 *gsi_base, +u32 *id,u32 *nr_irqs,u32 *nr_idcs); +struct fwnode_handle *riscv_acpi_get_gsi_domain_id (u32 gsi); + +#else +static inline int riscv_acpi_get_gsi_info (struct fwnode_handle *fwnode,u32 *gsi_base, +u32 *id,u32 *nr_irqs,u32 *nr_idcs) +{ +return 0 ; +} + +#endif /* CONFIG_ACPI */ +#endif /* _ASM_RISCV_IRQ_H */
drivers/acpi/riscv/init.c +2 -0
@@ -6,7 +6,9 @@*/ #include <linux/acpi.h> +#include "init.h" void __init acpi_riscv_init (void ) { +riscv_acpi_init_gsi_mapping (); }
drivers/acpi/riscv/init.h new file +4 -0
@@ -0,0 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#include <linux/init.h> + +int __init riscv_acpi_init_gsi_mapping (void );
drivers/acpi/riscv/irq.c +159 -0
168 lines not on this page · raw message
Signature · 1 line
2.40.1
Sunil V L
maintainerRFC PATCH v4 11/20 ACPI: scan.c: Define weak function to populate dependencies
In reply to Sunil V LSome architectures like RISC-V need to add dependencies without explicit _DEP. Define a weak function which can be implemented by the architecture.
--- drivers/acpi/scan.c | 11 +++++++++++ include/acpi/acpi_bus.h | 1 + 2 files changed, 12 insertions(+)
drivers/acpi/scan.c +11 -0
@@ -2073,11 +2073,22 @@ int acpi_scan_add_dep(acpi_handle handle, struct acpi_handle_list *dep_devices)return count; } +u32 __weak arch_acpi_add_auto_dep (acpi_handle handle) {return 0 ; } +static u32 acpi_scan_check_dep (acpi_handle handle) {struct acpi_handle_list dep_devices;u32 count =0 ; +/* +* Some architectures like RISC-V need to add dependencies for +* all devices which use GSI to the interrupt controller so that +* interrupt controller is probed before any of those devices. +* Instead of mandating _DEP on all the devices, detect the +* dependency and add automatically. +*/ + count +=arch_acpi_add_auto_dep (handle); +/* * Check for _HID here to avoid deferring the enumeration of: * 1. PCI devices.
include/acpi/acpi_bus.h +1 -0
@@ -994,6 +994,7 @@ static inline void acpi_put_acpi_dev(struct acpi_device *adev)int acpi_wait_for_acpi_ipmi (void );int acpi_scan_add_dep (acpi_handle handle,struct acpi_handle_list *dep_devices); +u32 arch_acpi_add_auto_dep (acpi_handle handle);#else /* CONFIG_ACPI */ static inline int register_acpi_bus_type (void *bus) {return 0 ; }
Signature · 1 line
2.40.1
Sunil V L
maintainerRFC PATCH v4 12/20 RISC-V: ACPI: Implement function to add implicit dependencies
In reply to Sunil V LRISC-V interrupt controllers for wired interrupts are platform devices and hence their driver will be probed late. Also, APLIC which is one such interrupt controller can not be probed early since it needs MSI services. This needs a probing order between the interrupt controller driver and the device drivers.
_DEP is typically used to indicate such dependencies. However, the dependency may be already available like GSI mapping. Hence, instead of an explicit _DEP, architecture can find the implicit dependencies and add to the dependency list.
For RISC-V, add the dependencies for below use cases.
1) For devices which has IRQ resource, find out the interrupt controller using GSI number map and add the dependency.
2) For PCI host bridges:
a) If _PRT indicate PCI link devices, add dependency on the link device.
b) If _PRT indicates GSI, find out the interrupt controller using GSI number map and add the dependency.
--- drivers/acpi/riscv/irq.c | 132 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+)
drivers/acpi/riscv/irq.c +132 -0
@@ -21,6 +21,12 @@ struct riscv_ext_intc_list {struct list_head list; }; +struct acpi_irq_dep_ctx { +int rc; +unsigned int index; +acpi_handle handle; +}; +LIST_HEAD (ext_intc_list);static int irqchip_cmp_func (const void *in0,const void *in1)
@@ -189,3 +195,129 @@ int __init riscv_acpi_init_gsi_mapping(void)acpi_get_devices ("RSCV0001" , riscv_acpi_create_gsi_map,NULL ,NULL );return 0 ; } + +static acpi_status riscv_acpi_irq_get_parent (struct acpi_resource *ares,void *context) +{ +struct acpi_irq_dep_ctx *ctx = context; +struct acpi_resource_irq *irq; +struct acpi_resource_extended_irq *eirq; + +switch (ares->type) { +case ACPI_RESOURCE_TYPE_IRQ : + irq = &ares->data.irq; +if (ctx->index >= irq->interrupt_count) { + ctx->index -= irq->interrupt_count; +return AE_OK ; + } + ctx->handle =riscv_acpi_get_gsi_handle (irq->interrupts[ctx->index]); +return AE_CTRL_TERMINATE ; +case ACPI_RESOURCE_TYPE_EXTENDED_IRQ : + eirq = &ares->data.extended_irq; +if (eirq->producer_consumer ==ACPI_PRODUCER ) +return AE_OK ; + +if (ctx->index >= eirq->interrupt_count) { + ctx->index -= eirq->interrupt_count; +return AE_OK ; + } + +/* Not supported */ +if (eirq->resource_source.string_length) +return AE_OK ; + + ctx->handle =riscv_acpi_get_gsi_handle (eirq->interrupts[ctx->index]); +return AE_CTRL_TERMINATE ; + } + +return AE_OK ; +} + +static int riscv_acpi_irq_get_dep (acpi_handle handle,unsigned int index,acpi_handle *gsi_handle) +{ +struct acpi_irq_dep_ctx ctx; + + ctx.rc = -EINVAL ; + ctx.index = index; +acpi_walk_resources (handle,METHOD_NAME__CRS , riscv_acpi_irq_get_parent, &ctx); + *gsi_handle = ctx.handle; +if (*gsi_handle) +return 1 ; + +return 0 ; +} + +static u32 riscv_acpi_add_prt_dep (acpi_handle handle) +{ +struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; +struct acpi_pci_routing_table *entry; +struct acpi_handle_list dep_devices; +acpi_handle gsi_handle; +acpi_handle link_handle; +acpi_status status; +u32 count =0 ; + + status =acpi_get_irq_routing_table (handle, &buffer); +if (ACPI_FAILURE (status)) { +kfree (buffer.pointer); +return 0 ; + } + + entry = buffer.pointer; +while (entry && (entry->length >0 )) { +if (entry->source[0 ]) { +acpi_get_handle (handle, entry->source, &link_handle); + dep_devices.count =1 ; + dep_devices.handles =kcalloc (1 ,sizeof (*dep_devices.handles),GFP_KERNEL ); +if (!dep_devices.handles) +continue ; + + dep_devices.handles[0 ] = link_handle; + count +=acpi_scan_add_dep (handle, &dep_devices); + }else { + gsi_handle =riscv_acpi_get_gsi_handle (entry->source_index); + dep_devices.count =1 ; + dep_devices.handles =kcalloc (1 ,sizeof (*dep_devices.handles),GFP_KERNEL ); +if (!dep_devices.handles) +continue ; + + dep_devices.handles[0 ] = gsi_handle; + count +=acpi_scan_add_dep (handle, &dep_devices); + } + + entry = (struct acpi_pci_routing_table *) + ((unsigned long )entry + entry->length); + } + +kfree (buffer.pointer); +return count; +} + +static u32 riscv_acpi_add_irq_dep (acpi_handle handle) +{ +struct acpi_handle_list dep_devices; +acpi_handle gsi_handle; +u32 count =0 ; +int i; + +for (i =0 ; +riscv_acpi_irq_get_dep (handle, i, &gsi_handle); + i++) { + dep_devices.count =1 ; + dep_devices.handles =kcalloc (1 ,sizeof (*dep_devices.handles),GFP_KERNEL ); +if (!dep_devices.handles) +continue ; + + dep_devices.handles[0 ] = gsi_handle; + count +=acpi_scan_add_dep (handle, &dep_devices); + } + +return count; +} + +u32 arch_acpi_add_auto_dep (acpi_handle handle) +{ +if (acpi_has_method (handle,"_PRT" )) +return riscv_acpi_add_prt_dep (handle); + +return riscv_acpi_add_irq_dep (handle); +}
Signature · 1 line
2.40.1
Sunil V L
maintainerRFC PATCH v4 13/20 ACPI/PNP: Initialize PNP devices skipped due to _DEP
In reply to Sunil V LWhen PNP devices have _DEP, they will not be enumerated in pnpacpi_init() unless the dependency is met. Hence, when such PNP device's supplier device is probed, the PNP device need to be added to the PNP data structures. So, introduce pnpacpi_init_2() for doing this which gets called as part of clearing the dependency.
This is currently required for RISC-V. Hence, restricted the code with a CONFIG option enabled for RISC-V.
Since pnpacpi_add_device() can be called now even after boot, __init attribute is removed from pnpacpi_add_device() and its dependent functions.
--- drivers/acpi/scan.c | 4 +++ drivers/pnp/pnpacpi/core.c | 24 ++++++++++--- drivers/pnp/pnpacpi/rsparser.c | 63 +++++++++++++++++----------------- include/linux/pnp.h | 7 ++++ 4 files changed, 62 insertions(+), 36 deletions(-)
drivers/acpi/scan.c +4 -0
@@ -19,6 +19,7 @@#include <linux/dma-map-ops.h> #include <linux/platform_data/x86/apple.h> #include <linux/pgtable.h> +#include <linux/pnp.h> #include <linux/crc32.h> #include <linux/dma-direct.h>
@@ -2370,6 +2371,9 @@ static void acpi_scan_clear_dep_fn(struct work_struct *work)acpi_bus_attach (cdw->adev, (void *)true);acpi_scan_lock_release (); +if (IS_ENABLED (CONFIG_ARCH_ACPI_DEFERRED_GSI ) &&IS_ENABLED (CONFIG_PNPACPI )) +pnpacpi_init_2 (cdw->adev); +acpi_dev_put (cdw->adev);kfree (cdw); }
drivers/pnp/pnpacpi/core.c +20 -4
@@ -26,7 +26,7 @@ static int num;#define TEST_ALPHA (c) \ if (!('A' <= (c) && (c) <= 'Z')) \ return 0 -static int __init ispnpidacpi (const char *id) +static int ispnpidacpi (const char *id) {TEST_ALPHA (id[0 ]);TEST_ALPHA (id[1 ]);
@@ -194,7 +194,7 @@ struct pnp_protocol pnpacpi_protocol = { };EXPORT_SYMBOL (pnpacpi_protocol); -static const char *__init pnpacpi_get_id (struct acpi_device *device) +static const char *pnpacpi_get_id (struct acpi_device *device) {struct acpi_hardware_id *id;
@@ -206,7 +206,7 @@ static const char *__init pnpacpi_get_id(struct acpi_device *device)return NULL ; } -static int __init pnpacpi_add_device (struct acpi_device *device) +static int pnpacpi_add_device (struct acpi_device *device) {struct pnp_dev *dev;const char *pnpid;
@@ -283,6 +283,23 @@ static int __init pnpacpi_add_device(struct acpi_device *device)return 0 ; } +int pnpacpi_disabled; + +#ifdef CONFIG_ARCH_ACPI_DEFERRED_GSI +void pnpacpi_init_2 (struct acpi_device *adev) +{ +if (acpi_disabled || pnpacpi_disabled) +return ; + +if (!adev) +return ; + +if (acpi_is_pnp_device (adev) &&acpi_dev_ready_for_enumeration (adev)) +pnpacpi_add_device (adev); +} + +#endif +static acpi_status __init pnpacpi_add_device_handler (acpi_handle handle,u32 lvl,void *context,void **rv)
@@ -296,7 +313,6 @@ static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle,return AE_OK ; } -int pnpacpi_disabled__initdata ;static int __init pnpacpi_init (void ) {if (acpi_disabled || pnpacpi_disabled) {
drivers/pnp/pnpacpi/rsparser.c +31 -32
134 lines not on this page · raw message
include/linux/pnp.h +7 -0
@@ -347,6 +347,7 @@ static inline struct acpi_device *pnp_acpi_device(struct pnp_dev *dev)return dev->data; return NULL; } +#else #define pnp_acpi_device (dev) 0#endif
@@ -514,4 +515,10 @@ static inline void pnp_unregister_driver(struct pnp_driver *drv) { }module_driver (__pnp_driver, pnp_register_driver, \ pnp_unregister_driver) +#ifdef CONFIG_ARCH_ACPI_DEFERRED_GSI +void pnpacpi_init_2 (struct acpi_device *adev); +#else +static inline void pnpacpi_init_2 (struct acpi_device *adev) { } +#endif +#endif /* _LINUX_PNP_H */
Signature · 1 line
2.40.1
Sunil V L
maintainerRFC PATCH v4 14/20 irqchip: riscv-intc: Add ACPI support for AIA
In reply to Sunil V LThe RINTC subtype structure in MADT also has information about other interrupt controllers. Save this information and provide interfaces to retrieve them when required by corresponding drivers.
--- arch/riscv/include/asm/irq.h | 35 ++++++++++++ drivers/irqchip/irq-riscv-intc.c | 97 +++++++++++++++++++++++++++++++- 2 files changed, 130 insertions(+), 2 deletions(-)
arch/riscv/include/asm/irq.h +35 -0
@@ -25,9 +25,22 @@ enum riscv_irqchip_type { ACPI_RISCV_IRQCHIP_APLIC = 0x03, }; +/* +* The ext_intc_id format is as follows: +* Bits [31:24] APLIC/PLIC ID +* Bits [15:0] APLIC IDC ID / PLIC S-Mode Context ID for this hart +*/ +#define APLIC_PLIC_ID (x) ((x) >> 24) +#define IDC_CONTEXT_ID (x) ((x) & 0x0000ffff) +int riscv_acpi_get_gsi_info (struct fwnode_handle *fwnode,u32 *gsi_base,u32 *id,u32 *nr_irqs,u32 *nr_idcs);struct fwnode_handle *riscv_acpi_get_gsi_domain_id (u32 gsi); +int __init acpi_get_intc_index_hartid (u32 index,unsigned long *hartid); +int acpi_get_ext_intc_parent_hartid (u8 id,u32 idx,unsigned long *hartid); +void acpi_get_plic_nr_contexts (u8 id,int *nr_contexts); +int acpi_get_plic_context (u8 id,u32 idx,int *context_id); +int __init acpi_get_imsic_mmio_info (u32 index,struct resource *res);#else static inline int riscv_acpi_get_gsi_info(struct fwnode_handle *fwnode, u32 *gsi_base,
@@ -36,6 +49,28 @@ static inline int riscv_acpi_get_gsi_info(struct fwnode_handle *fwnode, u32 *gsireturn 0 ; } +static inline int __init acpi_get_intc_index_hartid (u32 index,unsigned long *hartid) +{ +return -EINVAL ; +} + +static inline int acpi_get_ext_intc_parent_hartid (u8 id,u32 idx,unsigned long *hartid) +{ +return -EINVAL ; +} + +static inline void acpi_get_plic_nr_contexts (u8 id,int *nr_contexts) { } + +static inline int acpi_get_plic_context (u8 id,u32 idx,int *context_id) +{ +return -EINVAL ; +} + +static inline int __init acpi_get_imsic_mmio_info (u32 index,struct resource *res) +{ +return 0 ; +} +#endif /* CONFIG_ACPI */ #endif /* _ASM_RISCV_IRQ_H */
drivers/irqchip/irq-riscv-intc.c +95 -2
116 lines not on this page · raw message
Signature · 1 line
2.40.1
Sunil V L
maintainerRFC PATCH v4 15/20 irqchip: riscv-imsic: Add ACPI support
In reply to Sunil V LRISC-V IMSIC interrupt controller provides IPI and MSI support. Currently, DT based drivers setup the IPI feature early during boot but defer setting up the MSI functionality. However, in ACPI systems, PCI scan happens early during boot and PCI subsystem expects MSI controller is already setup. Hence, in case of ACPI, both IPI and MSI features are initialized early itself.
--- drivers/irqchip/irq-riscv-imsic-early.c | 52 +++++++++- drivers/irqchip/irq-riscv-imsic-platform.c | 32 ++++-- drivers/irqchip/irq-riscv-imsic-state.c | 115 ++++++++++----------- drivers/irqchip/irq-riscv-imsic-state.h | 2 +- include/linux/irqchip/riscv-imsic.h | 10 ++ 5 files changed, 144 insertions(+), 67 deletions(-)
drivers/irqchip/irq-riscv-imsic-early.c +51 -1
@@ -5,13 +5,16 @@*/ #define pr_fmt (fmt) "riscv-imsic: " fmt +#include <linux/acpi.h> #include <linux/cpu.h> #include <linux/interrupt.h> #include <linux/io.h> #include <linux/irq.h> #include <linux/irqchip.h> #include <linux/irqchip/chained_irq.h> +#include <linux/irqchip/riscv-imsic.h> #include <linux/module.h> +#include <linux/pci.h> #include <linux/spinlock.h> #include <linux/smp.h>
@@ -182,7 +185,7 @@ static int __init imsic_early_dt_init(struct device_node *node, struct device_noint rc;/* Setup IMSIC state */ - rc =imsic_setup_state (fwnode); + rc =imsic_setup_state (fwnode,NULL );if (rc) {pr_err ("%pfwP: failed to setup state (error %d)\n" , fwnode, rc);return rc;
@@ -199,3 +202,50 @@ static int __init imsic_early_dt_init(struct device_node *node, struct device_no }IRQCHIP_DECLARE (riscv_imsic,"riscv,imsics" , imsic_early_dt_init); + +#ifdef CONFIG_ACPI + +static struct fwnode_handle *imsic_acpi_fwnode; + +struct fwnode_handle *imsic_acpi_get_fwnode (struct device *dev) +{ +return imsic_acpi_fwnode; +} + +static int __init imsic_early_acpi_init (union acpi_subtable_headers *header, +const unsigned long end) +{ +struct acpi_madt_imsic *imsic = (struct acpi_madt_imsic *)header; +int rc; + + imsic_acpi_fwnode =irq_domain_alloc_named_fwnode ("imsic" ); +if (!imsic_acpi_fwnode) { +pr_err ("unable to allocate IMSIC FW node\n" ); +return -ENOMEM ; + } + +/* Setup IMSIC state */ + rc =imsic_setup_state (imsic_acpi_fwnode, (void *)imsic); +if (rc) { +pr_err ("%pfwP: failed to setup state (error %d)\n" , imsic_acpi_fwnode, rc); +return rc; + } + +/* Do early setup of IMSIC state and IPIs */ + rc =imsic_early_probe (imsic_acpi_fwnode); +if (rc) +return rc; + + rc =imsic_platform_acpi_probe (imsic_acpi_fwnode); + +#ifdef CONFIG_PCI +if (!rc) +pci_msi_register_fwnode_provider (&imsic_acpi_get_fwnode); +#endif + +return rc; +} + +IRQCHIP_ACPI_DECLARE (riscv_imsic,ACPI_MADT_TYPE_IMSIC ,NULL , +1 , imsic_early_acpi_init); +#endif
drivers/irqchip/irq-riscv-imsic-platform.c +26 -6
@@ -5,6 +5,7 @@*/ #define pr_fmt (fmt) "riscv-imsic: " fmt +#include <linux/acpi.h> #include <linux/bitmap.h> #include <linux/cpu.h> #include <linux/interrupt.h>
@@ -348,18 +349,37 @@ int imsic_irqdomain_init(void)return 0 ; } -static int imsic_platform_probe (struct platform_device *pdev) +static int imsic_platform_probe_common (struct fwnode_handle *fwnode) { -struct device *dev = &pdev->dev; - -if (imsic && imsic->fwnode != dev->fwnode) { -dev_err (dev,"fwnode mismatch\n" ); +if (imsic && imsic->fwnode != fwnode) { +pr_err ("%pfwP: fwnode mismatch\n" , fwnode);return -ENODEV ; }return imsic_irqdomain_init (); } +static int imsic_platform_dt_probe (struct platform_device *pdev) +{ +return imsic_platform_probe_common (pdev->dev.fwnode); +} + +#ifdef CONFIG_ACPI + +/* +* On ACPI based systems, PCI enumeration happens early during boot in +* acpi_scan_init(). PCI enumeration expects MSI domain setup before +* it calls pci_set_msi_domain(). Hence, unlike in DT where +* imsic-platform drive probe happens late during boot, ACPI based +* systems need to setup the MSI domain early. +*/ +int imsic_platform_acpi_probe (struct fwnode_handle *fwnode) +{ +return imsic_platform_probe_common (fwnode); +} + +#endif +static const struct of_device_id imsic_platform_match[] = { { .compatible ="riscv,imsics" }, {}
@@ -370,6 +390,6 @@ static struct platform_driver imsic_platform_driver = { .name = "riscv-imsic", .of_match_table = imsic_platform_match, }, - .probe = imsic_platform_probe, + .probe = imsic_platform_dt_probe, };builtin_platform_driver (imsic_platform_driver);
drivers/irqchip/irq-riscv-imsic-state.c +56 -59
171 lines not on this page · raw message
drivers/irqchip/irq-riscv-imsic-state.h +1 -1
@@ -102,7 +102,7 @@ void imsic_vector_debug_show_summary(struct seq_file *m, int ind);void imsic_state_online (void );void imsic_state_offline (void ); -int imsic_setup_state (struct fwnode_handle *fwnode); +int imsic_setup_state (struct fwnode_handle *fwnode,void *opaque);int imsic_irqdomain_init (void );#endif
include/linux/irqchip/riscv-imsic.h +10 -0
@@ -84,4 +84,14 @@ static inline const struct imsic_global_config *imsic_get_global_config(void)#endif +#ifdef CONFIG_ACPI +int imsic_platform_acpi_probe (struct fwnode_handle *fwnode); +struct fwnode_handle *imsic_acpi_get_fwnode (struct device *dev); +#else +static inline struct fwnode_handle *imsic_acpi_get_fwnode (struct device *dev) +{ +return NULL ; +} +#endif +#endif
Signature · 1 line
2.40.1
Sunil V L
maintainerRFC PATCH v4 16/20 irqchip: riscv-aplic: Add ACPI support
In reply to Sunil V LAdd ACPI support in APLIC drivers. It used the namespace device to probe and MADT to get other details required. Use the mapping created early during boot to get the details about the APLIC.
--- drivers/irqchip/irq-riscv-aplic-direct.c | 20 ++++--- drivers/irqchip/irq-riscv-aplic-main.c | 70 ++++++++++++++++-------- drivers/irqchip/irq-riscv-aplic-main.h | 1 + drivers/irqchip/irq-riscv-aplic-msi.c | 9 ++- 4 files changed, 67 insertions(+), 33 deletions(-)
drivers/irqchip/irq-riscv-aplic-direct.c +12 -8
@@ -4,6 +4,7 @@* Copyright (C) 2022 Ventana Micro Systems Inc. */ +#include <linux/acpi.h> #include <linux/bitfield.h> #include <linux/bitops.h> #include <linux/cpu.h>
@@ -192,17 +193,20 @@ static int aplic_direct_starting_cpu(unsigned int cpu) }static int aplic_direct_parse_parent_hwirq (struct device *dev,u32 index, -u32 *parent_hwirq,unsigned long *parent_hartid) +u32 *parent_hwirq,unsigned long *parent_hartid, +struct aplic_priv *priv) {struct of_phandle_args parent;int rc; -/* -* Currently, only OF fwnode is supported so extend this -* function for ACPI support. -*/ -if (!is_of_node (dev->fwnode)) -return -EINVAL ; +if (!is_of_node (dev->fwnode)) { + rc =acpi_get_ext_intc_parent_hartid (priv->id, index, parent_hartid); +if (rc) +return rc; + + *parent_hwirq =RV_IRQ_EXT ; +return 0 ; + } rc =of_irq_parse_one (to_of_node (dev->fwnode), index, &parent);if (rc)
@@ -240,7 +244,7 @@ int aplic_direct_setup(struct device *dev, void __iomem *regs)/* Setup per-CPU IDC and target CPU mask */ current_cpu =get_cpu ();for (i =0 ; i < priv->nr_idcs; i++) { - rc =aplic_direct_parse_parent_hwirq (dev, i, &hwirq, &hartid); + rc =aplic_direct_parse_parent_hwirq (dev, i, &hwirq, &hartid, priv);if (rc) {dev_warn (dev,"parent irq for IDC%d not found\n" , i);continue ;
drivers/irqchip/irq-riscv-aplic-main.c +46 -24
111 lines not on this page · raw message
drivers/irqchip/irq-riscv-aplic-main.h +1 -0
@@ -28,6 +28,7 @@ struct aplic_priv {u32 gsi_base;u32 nr_irqs;u32 nr_idcs; +u32 id;void __iomem *regs;struct aplic_msicfg msicfg; };
drivers/irqchip/irq-riscv-aplic-msi.c +8 -1
@@ -157,6 +157,7 @@ static const struct msi_domain_template aplic_msi_template = {int aplic_msi_setup (struct device *dev,void __iomem *regs) {const struct imsic_global_config *imsic_global; +struct irq_domain *msi_domain;struct aplic_priv *priv;struct aplic_msicfg *mc;phys_addr_t pa;
@@ -239,8 +240,14 @@ int aplic_msi_setup(struct device *dev, void __iomem *regs)* IMSIC and the IMSIC MSI domains are created later through * the platform driver probing so we set it explicitly here. */ -if (is_of_node (dev->fwnode)) +if (is_of_node (dev->fwnode)) {of_msi_configure (dev,to_of_node (dev->fwnode)); + }else { + msi_domain =irq_find_matching_fwnode (imsic_acpi_get_fwnode (dev), +DOMAIN_BUS_PLATFORM_MSI ); +if (msi_domain) +dev_set_msi_domain (dev, msi_domain); + } } if (!msi_create_device_irq_domain(dev, MSI_DEFAULT_DOMAIN, &aplic_msi_template,
Signature · 1 line
2.40.1
Sunil V L
maintainerRFC PATCH v4 17/20 irqchip: irq-sifive-plic: Add ACPI support
In reply to Sunil V LAdd ACPI support in PLIC driver. Use the mapping created early during boot to get details about the PLIC.
--- drivers/irqchip/irq-sifive-plic.c | 89 +++++++++++++++++++++++-------- 1 file changed, 68 insertions(+), 21 deletions(-)
drivers/irqchip/irq-sifive-plic.c +68 -21
@@ -3,6 +3,7 @@* Copyright (C) 2017 SiFive * Copyright (C) 2018 Christoph Hellwig */ +#include <linux/acpi.h> #include <linux/cpu.h> #include <linux/interrupt.h> #include <linux/io.h>
@@ -70,6 +71,8 @@ struct plic_priv {unsigned long plic_quirks;unsigned int nr_irqs;unsigned long *prio_save; +u32 gsi_base; +int id; };struct plic_handler {
@@ -327,6 +330,10 @@ static int plic_irq_domain_translate(struct irq_domain *d, {struct plic_priv *priv = d->host_data; +/* For DT, gsi_base is always zero. */ +if (fwspec->param[0 ] >= priv->gsi_base) + fwspec->param[0 ] = fwspec->param[0 ] - priv->gsi_base; +if (test_bit (PLIC_QUIRK_EDGE_INTERRUPT , &priv->plic_quirks))return irq_domain_translate_twocell (d, fwspec, hwirq, type);
@@ -427,18 +434,32 @@ static const struct of_device_id plic_match[] = { {} }; +#ifdef CONFIG_ACPI + +static const struct acpi_device_id plic_acpi_match[] = { + {"RSCV0001" ,0 }, + {} +}; +MODULE_DEVICE_TABLE (acpi, plic_acpi_match); + +#endif static int plic_parse_nr_irqs_and_contexts (struct platform_device *pdev, -u32 *nr_irqs,u32 *nr_contexts) +u32 *nr_irqs,u32 *nr_contexts, +u32 *gsi_base,u32 *id) {struct device *dev = &pdev->dev;int rc; -/* -* Currently, only OF fwnode is supported so extend this -* function for ACPI support. -*/ -if (!is_of_node (dev->fwnode)) -return -EINVAL ; +if (!is_of_node (dev->fwnode)) { +riscv_acpi_get_gsi_info (dev->fwnode, gsi_base, id, nr_irqs,NULL ); +acpi_get_plic_nr_contexts (*id, nr_contexts); +if (WARN_ON (!*nr_contexts)) { +dev_err (dev,"no PLIC context available\n" ); +return -EINVAL ; + } + +return 0 ; + } rc =of_property_read_u32 (to_of_node (dev->fwnode),"riscv,ndev" , nr_irqs);if (rc) {
@@ -452,23 +473,29 @@ static int plic_parse_nr_irqs_and_contexts(struct platform_device *pdev,return -EINVAL ; } + *gsi_base =0 ; + *id =0 ; +return 0 ; }static int plic_parse_context_parent (struct platform_device *pdev,u32 context, -u32 *parent_hwirq,int *parent_cpu) +u32 *parent_hwirq,int *parent_cpu,u32 id) {struct device *dev = &pdev->dev;struct of_phandle_args parent;unsigned long hartid;int rc; -/* -* Currently, only OF fwnode is supported so extend this -* function for ACPI support. -*/ -if (!is_of_node (dev->fwnode)) -return -EINVAL ; +if (!is_of_node (dev->fwnode)) { + rc =acpi_get_ext_intc_parent_hartid (id, context, &hartid); +if (rc) +return rc; + + *parent_cpu =riscv_hartid_to_cpuid (hartid); + *parent_hwirq =RV_IRQ_EXT ; +return 0 ; + } rc =of_irq_parse_one (to_of_node (dev->fwnode), context, &parent);if (rc)
@@ -493,7 +520,9 @@ static int plic_probe(struct platform_device *pdev)struct irq_domain *domain;struct plic_priv *priv;irq_hw_number_t hwirq; +int id, context_id;bool cpuhp_setup; +u32 gsi_base;if (is_of_node (dev->fwnode)) {const struct of_device_id *id;
@@ -503,7 +532,7 @@ static int plic_probe(struct platform_device *pdev) plic_quirks = (unsigned long )id->data; } - error =plic_parse_nr_irqs_and_contexts (pdev, &nr_irqs, &nr_contexts); + error =plic_parse_nr_irqs_and_contexts (pdev, &nr_irqs, &nr_contexts, &gsi_base, &id);if (error)return error;
@@ -514,6 +543,8 @@ static int plic_probe(struct platform_device *pdev) priv->dev = dev; priv->plic_quirks = plic_quirks; priv->nr_irqs = nr_irqs; + priv->gsi_base = gsi_base; + priv->id = id; priv->regs =devm_platform_ioremap_resource (pdev,0 );if (WARN_ON (!priv->regs))
@@ -524,12 +555,22 @@ static int plic_probe(struct platform_device *pdev)return -ENOMEM ;for (i =0 ; i < nr_contexts; i++) { - error =plic_parse_context_parent (pdev, i, &parent_hwirq, &cpu); + error =plic_parse_context_parent (pdev, i, &parent_hwirq, &cpu, priv->id);if (error) {dev_warn (dev,"hwirq for context%d not found\n" , i);continue ; } +if (is_of_node (dev->fwnode)) { + context_id = i; + }else { + error =acpi_get_plic_context (priv->id, i, &context_id); +if (error) { +dev_warn (dev,"invalid context id for context%d\n" , i); +continue ; + } + } +/* * Skip contexts other than external interrupts for our * privilege level.
@@ -575,10 +616,10 @@ static int plic_probe(struct platform_device *pdev)cpumask_set_cpu (cpu, &priv->lmask); handler->present = true; handler->hart_base = priv->regs +CONTEXT_BASE + - i *CONTEXT_SIZE ; + context_id *CONTEXT_SIZE ;raw_spin_lock_init (&handler->enable_lock); handler->enable_base = priv->regs +CONTEXT_ENABLE_BASE + - i *CONTEXT_ENABLE_SIZE ; + context_id *CONTEXT_ENABLE_SIZE ; handler->priv = priv; handler->enable_save = devm_kcalloc(dev, DIV_ROUND_UP(nr_irqs, 32),
@@ -594,8 +635,8 @@ static int plic_probe(struct platform_device *pdev) nr_handlers++; } - priv->irqdomain =irq_domain_add_linear (to_of_node (dev->fwnode), nr_irqs +1 , - &plic_irqdomain_ops, priv); + priv->irqdomain =irq_domain_create_linear (dev->fwnode, nr_irqs +1 , + &plic_irqdomain_ops, priv);if (WARN_ON (!priv->irqdomain)) goto fail_cleanup_contexts;
@@ -622,13 +663,18 @@ static int plic_probe(struct platform_device *pdev) } } +#ifdef CONFIG_ACPI +if (!acpi_disabled) +acpi_dev_clear_dependencies (ACPI_COMPANION (dev)); +#endif +dev_info (dev,"mapped %d interrupts with %d handlers for %d contexts.\n" , nr_irqs, nr_handlers, nr_contexts);return 0 ; fail_cleanup_contexts:for (i =0 ; i < nr_contexts; i++) { -if (plic_parse_context_parent (pdev, i, &parent_hwirq, &cpu)) +if (plic_parse_context_parent (pdev, i, &parent_hwirq, &cpu, priv->id))continue ;if (parent_hwirq !=RV_IRQ_EXT || cpu <0 )continue ;
@@ -647,6 +693,7 @@ static struct platform_driver plic_driver = { .driver = { .name = "riscv-plic", .of_match_table = plic_match, + .acpi_match_table = ACPI_PTR(plic_acpi_match), }, .probe = plic_probe, };
Signature · 1 line
2.40.1
Sunil V L
maintainerRFC PATCH v4 18/20 ACPI: bus: Add RINTC IRQ model for RISC-V
In reply to Sunil V LAdd the IRQ model for RISC-V INTC so that acpi_set_irq_model can use this for RISC-V.
--- drivers/acpi/bus.c | 3 +++ include/linux/acpi.h | 1 + 2 files changed, 4 insertions(+)
drivers/acpi/bus.c +3 -0
@@ -1190,6 +1190,9 @@ static int __init acpi_bus_init_irq(void)case ACPI_IRQ_MODEL_LPIC : message ="LPIC" ;break ; +case ACPI_IRQ_MODEL_RINTC : + message ="RINTC" ; +break ;default :pr_info ("Unknown interrupt routing model\n" );return -ENODEV ;
include/linux/acpi.h +1 -0
@@ -107,6 +107,7 @@ enum acpi_irq_model_id {ACPI_IRQ_MODEL_PLATFORM ,ACPI_IRQ_MODEL_GIC ,ACPI_IRQ_MODEL_LPIC , +ACPI_IRQ_MODEL_RINTC , ACPI_IRQ_MODEL_COUNT };
Signature · 1 line
2.40.1
Sunil V L
maintainerRFC PATCH v4 19/20 irqchip: riscv-intc: Set ACPI irqmodel
In reply to Sunil V LINTC being the root interrupt controller, set the ACPI irqmodel with callback function to get the GSI domain id.
--- drivers/irqchip/irq-riscv-intc.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/irqchip/irq-riscv-intc.c +5 -0
@@ -326,6 +326,10 @@ int acpi_get_imsic_mmio_info(u32 index, struct resource *res)return 0 ; } +static struct fwnode_handle *ext_entc_get_gsi_domain_id (u32 gsi) +{ +return riscv_acpi_get_gsi_domain_id (gsi); +}static int __init riscv_intc_acpi_init (union acpi_subtable_headers *header,const unsigned long end)
@@ -366,6 +370,7 @@ static int __init riscv_intc_acpi_init(union acpi_subtable_headers *header,return rc; } +acpi_set_irq_model (ACPI_IRQ_MODEL_RINTC , ext_entc_get_gsi_domain_id);return 0 ; }
Signature · 1 line
2.40.1
Sunil V L
maintainerRFC PATCH v4 20/20 ACPI: pci_link: Clear the dependencies after probe
In reply to Sunil V LRISC-V platforms need to use dependencies between PCI host bridge, Link devices and the interrupt controllers to ensure probe order. The dependency is like below.
Interrupt controller <-- Link Device <-- PCI Host bridge.
If there is no dependency added between Link device and PCI Host Bridge, then the PCI end points can get probed prior to link device unable to get mapping for INTx.
So, add the link device's HID to dependency honor list and also clear it after its probe.
--- drivers/acpi/pci_link.c | 3 +++ drivers/acpi/scan.c | 1 + 2 files changed, 4 insertions(+)
drivers/acpi/pci_link.c +3 -0
@@ -748,6 +748,9 @@ static int acpi_pci_link_add(struct acpi_device *device,if (result)kfree (link); +if (IS_ENABLED (CONFIG_ARCH_ACPI_DEFERRED_GSI )) +acpi_dev_clear_dependencies (device); +return result <0 ? result :1 ; }
drivers/acpi/scan.c +1 -0
@@ -835,6 +835,7 @@ static const char * const acpi_honor_dep_ids[] = {"INTC10CF" ,/* IVSC (MTL) driver must be loaded to allow i2c access to camera sensors */ "RSCV0001" ,/* RISC-V PLIC */ "RSCV0002" ,/* RISC-V APLIC */ +"PNP0C0F" ,/* PCI Link Device */ NULL };
Signature · 1 line
2.40.1
Re: [RFC PATCH v4 03/20] PCI: Make pci_create_root_bus() declare its reliance on MSI domains
In reply to Sunil V LQuoted 21 lines · Sunil V L
Similar to commit
9ec37efb8783("PCI/MSI: Makepci_host_common_probe()declare its reliance on MSI domains"), declare this dependency for PCI probe in ACPI based flow.This is required especially for RISC-V platforms where MSI controller can be absent. However, setting this for all architectures seem to cause issues on non RISC-V architectures [1]. Hence, enabled this only for RISC-V.
[1] - https://lore.kernel.org/oe-lkp/[email protected]
Signed-off-by Sunil V L <[email protected]>--- drivers/pci/probe.c | 3 +++ 1 file changed, 3 insertions(+)drivers/pci/probe.c +0
-0
drivers/pci/probe.c struct pci_bus *pci_create_root_bus(struct device *parent, int bus, · line 3053
Quoted 6 lines
drivers/pci/probe.c +3
-0@@ -3048,6 +3048,9 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus, bridge->sysdata = sysdata; bridge->busnr = bus; bridge->ops = ops; +#ifdef CONFIG_RISCV + bridge->msi_domain = true; +#endif
Ugh. I looked at [1], but that's not a very good justification for this #ifdef. The fault mentioned in [1] would need to be fixed, but not this way.
Quoted 5 lines
drivers/pci/probe.c +0
-0error =pci_register_host_bridge (bridge);if (error <0 )Signature · 1 line
2.40.1
Sunil V L
maintainerRe: [RFC PATCH v4 03/20] PCI: Make pci_create_root_bus() declare its reliance on MSI domains
Hi Bjorn,
Quoted 17 lines · Bjorn Helgaas
Quoted 16 lines · Sunil V L
Similar to commit
9ec37efb8783("PCI/MSI: Makepci_host_common_probe()declare its reliance on MSI domains"), declare this dependency for PCI probe in ACPI based flow.This is required especially for RISC-V platforms where MSI controller can be absent. However, setting this for all architectures seem to cause issues on non RISC-V architectures [1]. Hence, enabled this only for RISC-V.
[1] - https://lore.kernel.org/oe-lkp/[email protected]
Signed-off-by Sunil V L <[email protected]>--- drivers/pci/probe.c | 3 +++ 1 file changed, 3 insertions(+)
Quoted 16 lines
drivers/pci/probe.c struct pci_bus *pci_create_root_bus(struct device *parent, int bus, · line 3053
Quoted 11 lines
drivers/pci/probe.c +3
-0@@ -3048,6 +3048,9 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus, bridge->sysdata = sysdata; bridge->busnr = bus; bridge->ops = ops; +#ifdef CONFIG_RISCV + bridge->msi_domain = true; +#endif Ugh. I looked at [1], but that's not a very good justification for this #ifdef. The fault mentioned in [1] would need to be fixed, but not this way.
Thank you again for the feedback!
I agree. This is due to my limitation with knowledge and resources to debug the issue happening on non-UEFI x86 system with some particular PCIe RC. Also, I was worried that we get into a rat hole of assumptions/quirks with various architecture/PCIe RC combinations.
For ex: I think the issue is, somehow MSI domain is not set at the time of PCI host bridge registration in pci_register_host_bridge() causing PCI_BUS_FLAGS_NO_MSI to be set. This causes pci_alloc_irq_vectors() to fail. In portdrv.c, pcie_init_service_irqs() doesn't switch to INTx handling if MSI can not be used. It switches only if pcie_pme_no_msi() returns true. I couldn't find who actually sets up MSI domain bit late on this platform so that it somehow worked when we didn't set this flag.
Unfortunately, I don't have system to root cause and fix this issue with confidence. Also, I don't know if any other architectures have similar issues which are not caught yet. Hence, I thought it may be better just restrict the change to RISC-V.
Let me know your thoughts. If there are better ways, I will be happy to update.
Thanks,
Sunil
Re: [RFC PATCH v4 03/20] PCI: Make pci_create_root_bus() declare its reliance on MSI domains
Quoted 36 lines · Sunil V L
Hi Bjorn,
Quoted 17 lines · Bjorn Helgaas
Quoted 16 lines · Sunil V L
Similar to commit
9ec37efb8783("PCI/MSI: Makepci_host_common_probe()declare its reliance on MSI domains"), declare this dependency for PCI probe in ACPI based flow.This is required especially for RISC-V platforms where MSI controller can be absent. However, setting this for all architectures seem to cause issues on non RISC-V architectures [1]. Hence, enabled this only for RISC-V.
[1] - https://lore.kernel.org/oe-lkp/[email protected]
Signed-off-by Sunil V L <[email protected]>--- drivers/pci/probe.c | 3 +++ 1 file changed, 3 insertions(+)Quoted 15 lines
drivers/pci/probe.c struct pci_bus *pci_create_root_bus(struct device *parent, int bus, · line 3053
Quoted 11 lines
drivers/pci/probe.c +3
-0@@ -3048,6 +3048,9 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus, bridge->sysdata = sysdata; bridge->busnr = bus; bridge->ops = ops; +#ifdef CONFIG_RISCV + bridge->msi_domain = true; +#endif Ugh. I looked at [1], but that's not a very good justification for this #ifdef. The fault mentioned in [1] would need to be fixed, but not this way.
Quoted 6 lines
Thank you again for the feedback!
I agree. This is due to my limitation with knowledge and resources to debug the issue happening on non-UEFI x86 system with some particular PCIe RC. Also, I was worried that we get into a rat hole of assumptions/quirks with various architecture/PCIe RC combinations.
The problem is that adding #ifdefs like this leads to a rat hole itself. We need to understand and fix the underlying issue instead.
Quoted 8 lines
For ex: I think the issue is, somehow MSI domain is not set at the time of PCI host bridge registration in
pci_register_host_bridge()causingPCI_BUS_FLAGS_NO_MSIto be set. This causespci_alloc_irq_vectors()to fail. Inportdrv.c,pcie_init_service_irqs()doesn't switch to INTx handling if MSI can not be used. It switches only ifpcie_pme_no_msi()returns true. I couldn't find who actually sets up MSI domain bit late on this platform so that it somehow worked when we didn't set this flag.
Quoted 4 lines
Unfortunately, I don't have system to root cause and fix this issue with confidence. Also, I don't know if any other architectures have similar issues which are not caught yet. Hence, I thought it may be better just restrict the change to RISC-V.
It sounds like the above is a good start on analyzing the problem.
I don't quite understand your statement that pcie_init_service_irqs() doesn't fall back to INTx when MSI/MSI-X is not available.
I'm looking at this:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/pci/pcie/portdrv.c?id=v6.8#n177pcie_port_enable_irq_vec() attempts pci_alloc_irq_vectors(PCI_IRQ_MSIX | PCI_IRQ_MSI) and returns 0 if successful. If it returns failure, it looks like pcie_init_service_irqs() *does* fall through to trying INTx (PCI_IRQ_LEGACY).
Bjorn
Sunil V L
maintainerRe: [RFC PATCH v4 03/20] PCI: Make pci_create_root_bus() declare its reliance on MSI domains
Quoted 39 lines · Bjorn Helgaas
Quoted 38 lines · Sunil V L
Hi Bjorn,
Quoted 17 lines · Bjorn Helgaas
Quoted 16 lines · Sunil V L
Similar to commit
9ec37efb8783("PCI/MSI: Makepci_host_common_probe()declare its reliance on MSI domains"), declare this dependency for PCI probe in ACPI based flow.This is required especially for RISC-V platforms where MSI controller can be absent. However, setting this for all architectures seem to cause issues on non RISC-V architectures [1]. Hence, enabled this only for RISC-V.
[1] - https://lore.kernel.org/oe-lkp/[email protected]
Signed-off-by Sunil V L <[email protected]>--- drivers/pci/probe.c | 3 +++ 1 file changed, 3 insertions(+)Quoted 15 lines
drivers/pci/probe.c struct pci_bus *pci_create_root_bus(struct device *parent, int bus, · line 3053
Quoted 11 lines
drivers/pci/probe.c +3
-0@@ -3048,6 +3048,9 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus, bridge->sysdata = sysdata; bridge->busnr = bus; bridge->ops = ops; +#ifdef CONFIG_RISCV + bridge->msi_domain = true; +#endif Ugh. I looked at [1], but that's not a very good justification for this #ifdef. The fault mentioned in [1] would need to be fixed, but not this way.
Thank you again for the feedback!
Quoted 8 lines
Quoted 4 lines
I agree. This is due to my limitation with knowledge and resources to debug the issue happening on non-UEFI x86 system with some particular PCIe RC. Also, I was worried that we get into a rat hole of assumptions/quirks with various architecture/PCIe RC combinations.
The problem is that adding #ifdefs like this leads to a rat hole itself. We need to understand and fix the underlying issue instead.
Agree. Ideally, from my reading of code, this change should have worked across architectures.
Quoted 18 lines
Quoted 8 lines
For ex: I think the issue is, somehow MSI domain is not set at the time of PCI host bridge registration in
pci_register_host_bridge()causingPCI_BUS_FLAGS_NO_MSIto be set. This causespci_alloc_irq_vectors()to fail. Inportdrv.c,pcie_init_service_irqs()doesn't switch to INTx handling if MSI can not be used. It switches only ifpcie_pme_no_msi()returns true. I couldn't find who actually sets up MSI domain bit late on this platform so that it somehow worked when we didn't set this flag.Quoted 4 lines
Unfortunately, I don't have system to root cause and fix this issue with confidence. Also, I don't know if any other architectures have similar issues which are not caught yet. Hence, I thought it may be better just restrict the change to RISC-V.
It sounds like the above is a good start on analyzing the problem.
I don't quite understand your statement that
pcie_init_service_irqs()doesn't fall back to INTx when MSI/MSI-X is not available.
Quoted 8 lines
I'm looking at this:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/pci/pcie/portdrv.c?id=v6.8#n177pcie_port_enable_irq_vec()attemptspci_alloc_irq_vectors(PCI_IRQ_MSIX | PCI_IRQ_MSI)and returns 0 if successful. If it returns failure, it looks likepcie_init_service_irqs()*does* fall through to trying INTx (PCI_IRQ_LEGACY).
You are right. Not sure what I was looking at :-(.
I think fundamentally there are two issues here.
1) MSI domain should have been setup properly when pci_register_host_bridge() is called. I see that pci_arch_init() which is supposed to get called early calls x86_create_pci_msi_domain(). pci_register_host_bridge() also calls pci_set_bus_msi_domain() to setup the MSI domain which can walk up to host bridge to find. So, not sure why PCI_BUS_FLAGS_NO_MSI is getting set. Is there an issue in walking up the tree?
2) When it switches to legacy interrupt since MSI domain is not found, for some reason there is an interrupt enabled without a handler. I was suspecting PME since it was matching the IRQ#16 but it looks like PME handlers are present. I am unable to find anything suspicious from the log alone.
I really don't know how to proceed further. With my limited understanding, I don't get any hint what is happening from the log.
Thanks,
Sunil
Sunil V L
maintainerRe: [RFC PATCH v4 03/20] PCI: Make pci_create_root_bus() declare its reliance on MSI domains
Hi Bjorn,
On Wed, Apr 17, 2024 at 09:03:13PM +0530, Sunil V L wrote:
<snip>
Quoted 11 lines
I think fundamentally there are two issues here.
1) MSI domain should have been setup properly when
pci_register_host_bridge()is called. I see thatpci_arch_init()which is supposed to get called early callsx86_create_pci_msi_domain().pci_register_host_bridge()also callspci_set_bus_msi_domain()to setup the MSI domain which can walk up to host bridge to find. So, not sure whyPCI_BUS_FLAGS_NO_MSIis getting set. Is there an issue in walking up the tree?
I think I understand now why this is happening on X86. In X86, even though x86_create_pci_msi_domain() sets up the MSI domain, it never informs IRQ framework. Only later in pcibios_device_add(), the device's MSI domain will be set which is too late for this bridge logic. So, when pci_set_bus_msi_domain() is called from pci_register_host_bridge(), it will not get it.
It works in RISC-V (I guess ARM64 as well) because, the irqchip driver for MSI controller registers using pci_msi_register_fwnode_provider(). But, if we set bridge->msi_domain = true in X86, it will disable MSI even though it supports MSI which is really bad.
Please correct me if I am wrong with the analysis. If correct, what do you think the way forward if using CONFIG option is not good? I tried to register the domain in below commit but I don't feel it is a cleaner way.
https://github.com/vlsunil/linux/commit/d6cf76f10c225c94fffb286b7a3e803a4e37df54
Thanks,
Sunil
Quoted 48 lines · Sunil V L
This series adds support for the below ECR approved by ASWG.
1) MADT - https://drive.google.com/file/d/1oMGPyOD58JaPgMl1pKasT-VKsIKia7zR/view?usp=sharingThe series primarily enables irqchip drivers for RISC-V ACPI based platforms.
The series can be broadly categorized like below.
1) PCI ACPI related functions are migrated from arm64 to common file so that we don't need to duplicate them for RISC-V.
2) Added support for re-ordering the probe of interrupt controllers when
IRQCHIP_ACPI_DECLAREis used.3) To ensure probe order between interrupt controllers and devices, implicit dependency is created similar to when
_DEPis present.4) When PNP devices like Generic 16550A UART, have the dependency on the interrupt controller, they will not be added to PNP data structures. So, added second phase of
pnpacpi_initto handle this.5) ACPI support added in RISC-V interrupt controller drivers.
This series is still kept as RFC to seek feedback on above design changes. Looking forward for the feedback!
Changes since RFC v3:
1) Moved to_DEPmethod instead offw_devlink.
2) PLIC/APLIC driver probe using namespace devices.
3) Handling PNP devices as part of clearing dependency.
4) Rebased to latest linux-next to get AIA DT drivers.Changes since RFC v2:
1) Introducedfw_devlinkfor ACPI nodes for IRQ dependency.
2) Dropped patches in drivers which are not required due tofw_devlinksupport.
3) Droppedpci_set_msi()patch and added a patch inpci_create_root_bus().
4) Updatedpnp_irq()patch so that none of the actual PNP drivers need to change.Changes since RFC v1:
1) Abandoned swnode approach as per Marc's feedback.
2) To cope up with AIA series changes which changed irqchip driver probe fromcore_initcall()toplatform_driver, added patches to support deferred probing.
3) Rebased on top of Anup's AIA v11 and added tags.
Quoted 7 lines
To test the series,
1) Qemu should be built using the
riscv_acpi_namespace_v1branch at
https://github.com/vlsunil/qemu.git2) EDK2 should be built using the instructions at:
https://github.com/tianocore/edk2/blob/master/OvmfPkg/RiscVVirt/README.md
Hi Sunil,
I started playing with your work, and FYI: Using U-boot instead of EDK2 works out of the box (with acpi.config added to U-boot).
I changed my rootfs/boot tooling like [1], and it boots.
(For those who prefer working with U-boot UEFI instead of EDK2.)
Björn
[1] https://github.com/bjoto/riscv-rootfs-utils/commit/c0c620131f04d0c25df1504af4d0629a420b097e
Sunil V L
maintainerQuoted 58 lines · Björn Töpel
Quoted 48 lines · Sunil V L
This series adds support for the below ECR approved by ASWG.
1) MADT - https://drive.google.com/file/d/1oMGPyOD58JaPgMl1pKasT-VKsIKia7zR/view?usp=sharingThe series primarily enables irqchip drivers for RISC-V ACPI based platforms.
The series can be broadly categorized like below.
1) PCI ACPI related functions are migrated from arm64 to common file so that we don't need to duplicate them for RISC-V.
2) Added support for re-ordering the probe of interrupt controllers when
IRQCHIP_ACPI_DECLAREis used.3) To ensure probe order between interrupt controllers and devices, implicit dependency is created similar to when
_DEPis present.4) When PNP devices like Generic 16550A UART, have the dependency on the interrupt controller, they will not be added to PNP data structures. So, added second phase of
pnpacpi_initto handle this.5) ACPI support added in RISC-V interrupt controller drivers.
This series is still kept as RFC to seek feedback on above design changes. Looking forward for the feedback!
Changes since RFC v3:
1) Moved to_DEPmethod instead offw_devlink.
2) PLIC/APLIC driver probe using namespace devices.
3) Handling PNP devices as part of clearing dependency.
4) Rebased to latest linux-next to get AIA DT drivers.Changes since RFC v2:
1) Introducedfw_devlinkfor ACPI nodes for IRQ dependency.
2) Dropped patches in drivers which are not required due tofw_devlinksupport.
3) Droppedpci_set_msi()patch and added a patch inpci_create_root_bus().
4) Updatedpnp_irq()patch so that none of the actual PNP drivers need to change.Changes since RFC v1:
1) Abandoned swnode approach as per Marc's feedback.
2) To cope up with AIA series changes which changed irqchip driver probe fromcore_initcall()toplatform_driver, added patches to support deferred probing.
3) Rebased on top of Anup's AIA v11 and added tags.Quoted 7 lines
To test the series,
1) Qemu should be built using the
riscv_acpi_namespace_v1branch at
https://github.com/vlsunil/qemu.git2) EDK2 should be built using the instructions at:
https://github.com/tianocore/edk2/blob/master/OvmfPkg/RiscVVirt/README.md
Quoted 10 lines
Hi Sunil,
I started playing with your work, and FYI: Using U-boot instead of EDK2 works out of the box (with acpi.config added to U-boot).
I changed my rootfs/boot tooling like [1], and it boots.
(For those who prefer working with U-boot UEFI instead of EDK2.)
Hi Björn,
This is cool!. I was not aware that u-boot also supports ACPI on RISC-V. Many thanks!
Thanks,
Sunil
Quoted 7 lines · Sunil V L
Hi Björn,
This is cool!. I was not aware that u-boot also supports ACPI on RISC-V. Many thanks!
Thanks,
Sunil
For RISC-V and ARM we have
* pass-through for QEMU ACPI tables
* pass-through for QEMU SMBIOS tables
* generation of SMBIOS tables
Generation of ACPI tables in U-Boot has up now only been implemented for x86 but would be feasible for RISC-V boards too.
Cf. https://docs.u-boot.org/en/latest/board/emulation/acpi.html
Best regards
Heinrich
Rafael J. Wysocki
maintainerQuoted 18 lines · Sunil V L
This series adds support for the below ECR approved by ASWG.
1) MADT - https://drive.google.com/file/d/1oMGPyOD58JaPgMl1pKasT-VKsIKia7zR/view?usp=sharingThe series primarily enables irqchip drivers for RISC-V ACPI based platforms.
The series can be broadly categorized like below.
1) PCI ACPI related functions are migrated from arm64 to common file so that we don't need to duplicate them for RISC-V.
2) Added support for re-ordering the probe of interrupt controllers when
IRQCHIP_ACPI_DECLAREis used.3) To ensure probe order between interrupt controllers and devices, implicit dependency is created similar to when
_DEPis present.
Quoted 8 lines
4) When PNP devices like Generic 16550A UART, have the dependency on the interrupt controller, they will not be added to PNP data structures. So, added second phase of
pnpacpi_initto handle this.5) ACPI support added in RISC-V interrupt controller drivers.
This series is still kept as RFC to seek feedback on above design changes. Looking forward for the feedback!
I've looked at the patches and I don't see anything deeply concerning in them from the ACPI core code perspective.
The changes look reasonably straightforward to me.
Thanks!
Quoted 117 lines
Changes since RFC v3:
1) Moved to_DEPmethod instead offw_devlink.
2) PLIC/APLIC driver probe using namespace devices.
3) Handling PNP devices as part of clearing dependency.
4) Rebased to latest linux-next to get AIA DT drivers.Changes since RFC v2:
1) Introducedfw_devlinkfor ACPI nodes for IRQ dependency.
2) Dropped patches in drivers which are not required due tofw_devlinksupport.
3) Droppedpci_set_msi()patch and added a patch inpci_create_root_bus().
4) Updatedpnp_irq()patch so that none of the actual PNP drivers need to change.Changes since RFC v1:
1) Abandoned swnode approach as per Marc's feedback.
2) To cope up with AIA series changes which changed irqchip driver probe fromcore_initcall()toplatform_driver, added patches to support deferred probing.
3) Rebased on top of Anup's AIA v11 and added tags.To test the series,
1) Qemu should be built using the
riscv_acpi_namespace_v1branch at
https://github.com/vlsunil/qemu.git2) EDK2 should be built using the instructions at:
https://github.com/tianocore/edk2/blob/master/OvmfPkg/RiscVVirt/README.md3) Build Linux using this series.
Run Qemu:
qemu-system-riscv64 \
-M virt,pflash0=pflash0,pflash1=pflash1,aia=aplic-imsic \
-m 2G -smp 8 \
-serial mon:stdio \
-device virtio-gpu-pci -full-screen \
-device qemu-xhci \
-device usb-kbd \
-blockdev node-name=pflash0,driver=file,read-only=on,filename=RISCV_VIRT_CODE.fd \
-blockdev node-name=pflash1,driver=file,filename=RISCV_VIRT_VARS.fd \
-netdev user,id=net0 -device virtio-net-pci,netdev=net0 \
-kernelarch/riscv/boot/Image\
-initrd rootfs.cpio \
-append "root=/dev/ram ro console=ttyS0 rootwait earlycon=uart8250,mmio,0x10000000"To boot with APLIC only, use aia=aplic.
To boot with PLIC, remove aia= option.This series is also available in
acpi_b2_v4_autodep_v1branch at
https://github.com/vlsunil/linux.gitBased-on: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tag/?h=next-20240415
Sunil V L (20):
arm64: PCI: Migrate ACPI related functions topci-acpi.c
RISC-V: ACPI: Implement PCI related functionality
PCI: Makepci_create_root_bus()declare its reliance on MSI domains
ACPI:scan.c: Add weak arch specific function to reorder the IRQCHIP
probe
ACPI: RISC-V: Implement arch function to reorder irqchip probe entries
ACPI: bus: Addacpi_riscv_initfunction
RISC-V:Kconfig: Select deferred GSI probe for ACPI systems
ACPI: scan: Refactor dependency creationdrivers/acpi/scan.c: Update_DEPhonor list
RISC-V: ACPI: Initialize GSI mapping structures
ACPI:scan.c: Define weak function to populate dependencies
RISC-V: ACPI: Implement function to add implicit dependencies ACPI/PNP: Initialize PNP devices skipped due to_DEP
irqchip: riscv-intc: Add ACPI support for AIA
irqchip: riscv-imsic: Add ACPI support
irqchip: riscv-aplic: Add ACPI support
irqchip: irq-sifive-plic: Add ACPI support
ACPI: bus: Add RINTC IRQ model for RISC-V
irqchip: riscv-intc: Set ACPI irqmodel
ACPI:pci_link: Clear the dependencies after probearch/arm64/kernel/pci.c | 191 ------------ arch/riscv/Kconfig | 3 + arch/riscv/include/asm/irq.h | 57 ++++ arch/riscv/kernel/acpi.c | 31 +- drivers/acpi/Kconfig | 3 + drivers/acpi/bus.c | 4 + drivers/acpi/pci_link.c | 3 + drivers/acpi/riscv/Makefile | 2 +- drivers/acpi/riscv/init.c | 14 + drivers/acpi/riscv/init.h | 4 + drivers/acpi/riscv/irq.c | 323 +++++++++++++++++++++ drivers/acpi/scan.c | 69 +++-- drivers/irqchip/irq-riscv-aplic-direct.c | 20 +- drivers/irqchip/irq-riscv-aplic-main.c | 70 +++-- drivers/irqchip/irq-riscv-aplic-main.h | 1 + drivers/irqchip/irq-riscv-aplic-msi.c | 9 +- drivers/irqchip/irq-riscv-imsic-early.c | 52 +++- drivers/irqchip/irq-riscv-imsic-platform.c | 32 +- drivers/irqchip/irq-riscv-imsic-state.c | 115 ++++---- drivers/irqchip/irq-riscv-imsic-state.h | 2 +- drivers/irqchip/irq-riscv-intc.c | 102 ++++++- drivers/irqchip/irq-sifive-plic.c | 89 ++++-- drivers/pci/pci-acpi.c | 182 ++++++++++++ drivers/pci/probe.c | 3 + drivers/pnp/pnpacpi/core.c | 24 +- drivers/pnp/pnpacpi/rsparser.c | 63 ++-- include/acpi/acpi_bus.h | 2 + include/linux/acpi.h | 9 + include/linux/irqchip/riscv-imsic.h | 10 + include/linux/pnp.h | 7 + 30 files changed, 1108 insertions(+), 388 deletions(-) create mode 100644 drivers/acpi/riscv/init.c create mode 100644 drivers/acpi/riscv/init.h create mode 100644 drivers/acpi/riscv/irq.c--
2.40.1
Björn Töpel
Tested-byQuoted 25 lines · Rafael J. Wysocki
Quoted 24 lines · Sunil V L
This series adds support for the below ECR approved by ASWG.
1) MADT - https://drive.google.com/file/d/1oMGPyOD58JaPgMl1pKasT-VKsIKia7zR/view?usp=sharingThe series primarily enables irqchip drivers for RISC-V ACPI based platforms.
The series can be broadly categorized like below.
1) PCI ACPI related functions are migrated from arm64 to common file so that we don't need to duplicate them for RISC-V.
2) Added support for re-ordering the probe of interrupt controllers when
IRQCHIP_ACPI_DECLAREis used.3) To ensure probe order between interrupt controllers and devices, implicit dependency is created similar to when
_DEPis present.4) When PNP devices like Generic 16550A UART, have the dependency on the interrupt controller, they will not be added to PNP data structures. So, added second phase of
pnpacpi_initto handle this.5) ACPI support added in RISC-V interrupt controller drivers.
Quoted 7 lines
Quoted 2 lines
This series is still kept as RFC to seek feedback on above design changes. Looking forward for the feedback!
I've looked at the patches and I don't see anything deeply concerning in them from the ACPI core code perspective.
The changes look reasonably straightforward to me.
Sunil, given Rafael's input, it sounds like it's time for a patch proper. This is really the missing piece to make ACPI usable on RISC-V!
Thanks for the nice work!
Björn
FWIW,
Sunil V L
maintainerQuoted 35 lines · Björn Töpel
Quoted 25 lines · Rafael J. Wysocki
Quoted 24 lines · Sunil V L
This series adds support for the below ECR approved by ASWG.
1) MADT - https://drive.google.com/file/d/1oMGPyOD58JaPgMl1pKasT-VKsIKia7zR/view?usp=sharingThe series primarily enables irqchip drivers for RISC-V ACPI based platforms.
The series can be broadly categorized like below.
1) PCI ACPI related functions are migrated from arm64 to common file so that we don't need to duplicate them for RISC-V.
2) Added support for re-ordering the probe of interrupt controllers when
IRQCHIP_ACPI_DECLAREis used.3) To ensure probe order between interrupt controllers and devices, implicit dependency is created similar to when
_DEPis present.4) When PNP devices like Generic 16550A UART, have the dependency on the interrupt controller, they will not be added to PNP data structures. So, added second phase of
pnpacpi_initto handle this.5) ACPI support added in RISC-V interrupt controller drivers.
Quoted 7 lines
Quoted 2 lines
This series is still kept as RFC to seek feedback on above design changes. Looking forward for the feedback!
I've looked at the patches and I don't see anything deeply concerning in them from the ACPI core code perspective.
The changes look reasonably straightforward to me.
Quoted 9 lines
Sunil, given Rafael's input, it sounds like it's time for a patch proper. This is really the missing piece to make ACPI usable on RISC-V!
Thanks for the nice work!
BjörnFWIW,
Tested-by Björn Töpel <[email protected]>
Sorry for the delayed response. I was AFK last week.
Many thanks!!, Rafael. Let me send next version without RFC.
Thank you very much Björn for testing it.
Thanks,
Sunil