Add basic ACPI support for RISC-V
Subsystems (13)
Sunil V L
maintainerv4 cover Add basic ACPI support for RISC-V
This patch series enables the basic ACPI infrastructure for RISC-V. Supporting external interrupt controllers is in progress and hence it is tested using poll based HVC SBI console and RAM disk.
The first patch in this series is one of the patch from Jisheng's series [1] which is not merged yet. This patch is required to support ACPI since efi_init() which gets called before sbi_init() can enable static branches and hits a panic.
Patch 2 and 3 are ACPICA patches which are merged now into acpica but not yet pulled into the linux sources. They exist in this patch set as reference. This series can be merged only after those ACPICA patches are pulled into linux.
Below are two ECRs approved by ASWG.
RINTC - https://drive.google.com/file/d/1R6k4MshhN3WTT-hwqAquu5nX6xSEqK2l/view
RHCT - https://drive.google.com/file/d/1nP3nFiH4jkPMp6COOxP6123DCZKR-tia/view
Based-on: [email protected]
(https://lore.kernel.org/lkml/[email protected]/)
[1] https://lore.kernel.org/all/[email protected]/
Changes since V3:
1) Added two more driver patches to workaround allmodconfig build failure.
2) Separated removal of riscv_of_processor_hartid() to a different patch.
3) Addressed Conor's feedback.
4) Rebased to v6.3-rc5 and added latest tags
Changes since V2:
1) Dropped ACPI_PROCESSOR patch.
2) Added new patch to print debug info of RISC-V INTC in MADT
3) Addressed other comments from Drew.
4) Rebased and updated tags
Changes since V1:
1) Dropped PCI changes and instead added dummy interfaces just to enable building ACPI core when CONFIG_PCI is enabled. Actual PCI changes will be added in future along with external interrupt controller support in ACPI.
2) Squashed couple of patches so that new code added gets built in each commit.
3) Fixed the missing wake_cpu code in timer refactor patch as pointed by Conor
4) Fixed an issue with SMP disabled.
5) Addressed other comments from Conor.
6) Updated documentation patch as per feedback from Sanjaya.
7) Fixed W=1 and checkpatch --strict issues.
8) Added ACK/RB tags
These changes are available at
https://github.com/vlsunil/linux/commits/acpi_b1_us_review_ipi17_V4
Testing:
1) Build latest Qemu
2) Build EDK2 as per instructions in
https://github.com/vlsunil/riscv-uefi-edk2-docs/wiki/RISC-V-Qemu-Virt-support
3) Build Linux after enabling SBI HVC and SBI earlycon CONFIG_RISCV_SBI_V01=y CONFIG_SERIAL_EARLYCON_RISCV_SBI=y CONFIG_HVC_RISCV_SBI=y
4) Build buildroot.
Run with below command.
qemu-system-riscv64 -nographic \
-drive file=Build/RiscVVirtQemu/RELEASE_GCC5/FV/RISCV_VIRT.fd,if=pflash,format=raw,unit=1 \
-machine virt -smp 16 -m 2G \
-kernel arch/riscv/boot/Image \
-initrd buildroot/output/images/rootfs.cpio \
-append "root=/dev/ram ro console=hvc0 earlycon=sbi"
Jisheng Zhang (1):
riscv: move sbi_init() earlier before jump_label_init()
Sunil V L (22):
ACPICA: MADT: Add RISC-V INTC interrupt controller
ACPICA: Add structure definitions for RISC-V RHCT
ACPI: tables: Print RINTC information when MADT is parsed
ACPI: OSL: Make should_use_kmap() 0 for RISC-V
RISC-V: Add support to build the ACPI core
ACPI: processor_core: RISC-V: Enable mapping processor to the hartid
RISC-V: ACPI: Cache and retrieve the RINTC structure drivers/acpi: RISC-V: Add RHCT related code
RISC-V: smpboot: Create wrapper smp_setup()
RISC-V: smpboot: Add ACPI support in smp_setup()
RISC-V: cpufeature: Avoid calling riscv_of_processor_hartid()
RISC-V: cpufeature: Add ACPI support in riscv_fill_hwcap()
RISC-V: cpu: Enable cpuinfo for ACPI systems irqchip/riscv-intc: Add ACPI support clocksource/timer-riscv: Refactor riscv_timer_init_dt() clocksource/timer-riscv: Add ACPI support
RISC-V: time.c: Add ACPI support for time_init()
RISC-V: Add ACPI initialization in setup_arch()
RISC-V: Enable ACPI in defconfig
MAINTAINERS: Add entry for drivers/acpi/riscv platform/surface: Disable for RISC-V
crypto: hisilicon/qm: Workaround to enable build with RISC-V clang
.../admin-guide/kernel-parameters.txt | 8 +- MAINTAINERS | 8 + arch/riscv/Kconfig | 5 + arch/riscv/configs/defconfig | 1 + arch/riscv/include/asm/acenv.h | 11 + arch/riscv/include/asm/acpi.h | 77 +++++ arch/riscv/include/asm/cpu.h | 8 + arch/riscv/kernel/Makefile | 2 + arch/riscv/kernel/acpi.c | 266 ++++++++++++++++++ arch/riscv/kernel/cpu.c | 30 +- arch/riscv/kernel/cpufeature.c | 44 ++- arch/riscv/kernel/setup.c | 27 +- arch/riscv/kernel/smpboot.c | 77 ++++- arch/riscv/kernel/time.c | 25 +- drivers/acpi/Makefile | 2 + drivers/acpi/osl.c | 2 +- drivers/acpi/processor_core.c | 29 ++ drivers/acpi/riscv/Makefile | 2 + drivers/acpi/riscv/rhct.c | 83 ++++++ drivers/acpi/tables.c | 10 + drivers/clocksource/timer-riscv.c | 92 +++--- drivers/crypto/hisilicon/qm.c | 13 +- drivers/irqchip/irq-riscv-intc.c | 74 ++++- drivers/platform/surface/aggregator/Kconfig | 2 +- include/acpi/actbl2.h | 69 ++++- 25 files changed, 867 insertions(+), 100 deletions(-) create mode 100644 arch/riscv/include/asm/acenv.h create mode 100644 arch/riscv/include/asm/acpi.h create mode 100644 arch/riscv/include/asm/cpu.h create mode 100644 arch/riscv/kernel/acpi.c create mode 100644 drivers/acpi/riscv/Makefile create mode 100644 drivers/acpi/riscv/rhct.c
Signature · 1 line
2.34.1
Sunil V L
maintainerPATCH v4 1/23 riscv: move sbi_init() earlier before jump_label_init()
From: Jisheng Zhang <[email protected]>
We call jump_label_init() in setup_arch() is to use static key mechanism earlier, but riscv jump label relies on the sbi functions, If we enable static key before sbi_init(), the code path looks like:
static_branch_enable()
..
arch_jump_label_transform()
patch_text_nosync()
flush_icache_range()
flush_icache_all()
sbi_remote_fence_i() for CONFIG_RISCV_SBI case
__sbi_rfence()Since sbi isn't initialized, so NULL deference! Here is a typical panic log:
[ 0.000000] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 [ 0.000000] Oops [#1] [ 0.000000] Modules linked in: [ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 5.18.0-rc7+ #79 [ 0.000000] Hardware name: riscv-virtio,qemu (DT) [ 0.000000] epc : 0x0 [ 0.000000] ra : sbi_remote_fence_i+0x1e/0x26 [ 0.000000] epc : 0000000000000000 ra : ffffffff80005826 sp : ffffffff80c03d50 [ 0.000000] gp : ffffffff80ca6178 tp : ffffffff80c0ad80 t0 : 6200000000000000 [ 0.000000] t1 : 0000000000000000 t2 : 62203a6b746e6972 s0 : ffffffff80c03d60 [ 0.000000] s1 : ffffffff80001af6 a0 : 0000000000000000 a1 : 0000000000000000 [ 0.000000] a2 : 0000000000000000 a3 : 0000000000000000 a4 : 0000000000000000 [ 0.000000] a5 : 0000000000000000 a6 : 0000000000000000 a7 : 0000000000080200 [ 0.000000] s2 : ffffffff808b3e48 s3 : ffffffff808bf698 s4 : ffffffff80cb2818 [ 0.000000] s5 : 0000000000000001 s6 : ffffffff80c9c345 s7 : ffffffff80895aa0 [ 0.000000] s8 : 0000000000000001 s9 : 000000000000007f s10: 0000000000000000 [ 0.000000] s11: 0000000000000000 t3 : ffffffff80824d08 t4 : 0000000000000022 [ 0.000000] t5 : 000000000000003d t6 : 0000000000000000 [ 0.000000] status: 0000000000000100 badaddr: 0000000000000000 cause: 000000000000000c [ 0.000000] ---[ end trace 0000000000000000 ]--- [ 0.000000] Kernel panic - not syncing: Attempted to kill the idle task! [ 0.000000] ---[ end Kernel panic - not syncing: Attempted to kill the idle task! ]---
Fix this issue by moving sbi_init() earlier before jump_label_init()
--- arch/riscv/kernel/setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/setup.c +1 -1
@@ -270,6 +270,7 @@ void __init setup_arch(char **cmdline_p) *cmdline_p = boot_command_line;early_ioremap_setup (); +sbi_init ();jump_label_init ();parse_early_param ();
@@ -287,7 +288,6 @@ void __init setup_arch(char **cmdline_p)misc_mem_init ();init_resources (); -sbi_init ();#ifdef CONFIG_KASAN kasan_init ();
Signature · 1 line
2.34.1
Sunil V L
maintainerPATCH v4 2/23 ACPICA: MADT: Add RISC-V INTC interrupt controller
In reply to Sunil V LACPICA commit bd6d1ae1e13abe78e149c8b61b4bc7bc7feab015
The ECR to add RISC-V INTC interrupt controller is approved by the UEFI forum and will be available in the next revision of the ACPI specification.
Reference: Mantis ID: 2348
--- include/acpi/actbl2.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
include/acpi/actbl2.h +20 -1
@@ -891,7 +891,8 @@ enum acpi_madt_type {ACPI_MADT_TYPE_MSI_PIC =21 ,ACPI_MADT_TYPE_BIO_PIC =22 ,ACPI_MADT_TYPE_LPC_PIC =23 , -ACPI_MADT_TYPE_RESERVED =24 ,/* 24 to 0x7F are reserved */ +ACPI_MADT_TYPE_RINTC =24 , +ACPI_MADT_TYPE_RESERVED =25 ,/* 25 to 0x7F are reserved */ ACPI_MADT_TYPE_OEM_RESERVED = 0x80 /* 0x80 to 0xFF are reserved for OEM use */ };
@@ -1250,6 +1251,24 @@ enum acpi_madt_lpc_pic_version {ACPI_MADT_LPC_PIC_VERSION_RESERVED =2 /* 2 and greater are reserved */ }; +/* 24: RISC-V INTC */ +struct acpi_madt_rintc { +struct acpi_subtable_header header; +u8 version; +u8 reserved; +u32 flags; +u64 hart_id; +u32 uid;/* ACPI processor UID */ +}; + +/* Values for RISC-V INTC Version field above */ + +enum acpi_madt_rintc_version { +ACPI_MADT_RINTC_VERSION_NONE =0 , +ACPI_MADT_RINTC_VERSION_V1 =1 , +ACPI_MADT_RINTC_VERSION_RESERVED =2 /* 2 and greater are reserved */ +}; +/* 80: OEM data */ struct acpi_madt_oem_data {
Signature · 1 line
2.34.1
Sunil V L
maintainerPATCH v4 3/23 ACPICA: Add structure definitions for RISC-V RHCT
In reply to Sunil V LACPICA commit 82afd0434e79f74b96a6be88115ddc8343a1ba40
RISC-V Hart Capabilities Table (RHCT) is a new static table. The ECR to add RHCT is approved by the UEFI forum and will be available in the next version of the ACPI spec.
Reference: Mantis: 2349
--- include/acpi/actbl2.h | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
include/acpi/actbl2.h +48 -0
@@ -47,6 +47,7 @@#define ACPI_SIG_PRMT "PRMT"/* Platform Runtime Mechanism Table */ #define ACPI_SIG_RASF "RASF"/* RAS Feature table */ #define ACPI_SIG_RGRT "RGRT"/* Regulatory Graphics Resource Table */ +#define ACPI_SIG_RHCT "RHCT"/* RISC-V Hart Capabilities Table */ #define ACPI_SIG_SBST "SBST"/* Smart Battery Specification Table */ #define ACPI_SIG_SDEI "SDEI"/* Software Delegated Exception Interface Table */ #define ACPI_SIG_SDEV "SDEV"/* Secure Devices table */
@@ -2604,6 +2605,53 @@ enum acpi_rgrt_image_type { ACPI_RGRT_TYPE_RESERVED = 2 /* 2 and greater are reserved */ }; +/******************************************************************************* +* +* RHCT - RISC-V Hart Capabilities Table +* Version 1 +* +******************************************************************************/ + +struct acpi_table_rhct { +struct acpi_table_header header;/* Common ACPI table header */ +u32 reserved; +u64 time_base_freq; +u32 node_count; +u32 node_offset; +}; + +/* +* RHCT subtables +*/ +struct acpi_rhct_node_header { +u16 type; +u16 length; +u16 revision; +}; + +/* Values for RHCT subtable Type above */ + +enum acpi_rhct_node_type { +ACPI_RHCT_NODE_TYPE_ISA_STRING =0x0000 , +ACPI_RHCT_NODE_TYPE_HART_INFO =0xFFFF , +}; + +/* +* RHCT node specific subtables +*/ + +/* ISA string node structure */ +struct acpi_rhct_isa_string { +u16 isa_length; +char isa[]; +}; + +/* Hart Info node structure */ +struct acpi_rhct_hart_info { +u16 num_offsets; +u32 uid;/* ACPI processor UID */ +}; +/******************************************************************************* * * SBST - Smart Battery Specification Table
Signature · 1 line
2.34.1
Sunil V L
maintainerPATCH v4 4/23 ACPI: tables: Print RINTC information when MADT is parsed
In reply to Sunil V LWhen MADT is parsed, print RINTC information as below:
ACPI: RISC-V INTC (acpi_uid[0x0000] hart_id[0x0] enabled)
ACPI: RISC-V INTC (acpi_uid[0x0001] hart_id[0x1] enabled)
...
ACPI: RISC-V INTC (acpi_uid[0x000f] hart_id[0xf] enabled)
This debug information will be very helpful during bring up.
--- drivers/acpi/tables.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/acpi/tables.c +10 -0
@@ -220,6 +220,16 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header) }break ; +case ACPI_MADT_TYPE_RINTC : + { +struct acpi_madt_rintc *p = (struct acpi_madt_rintc *)header; + +pr_debug ("RISC-V INTC (acpi_uid[0x%04x] hart_id[0x%llx] %s)\n" , + p->uid, p->hart_id, + (p->flags &ACPI_MADT_ENABLED ) ?"enabled" :"disabled" ); + } +break ; +default :pr_warn ("Found unsupported MADT entry (type = 0x%x)\n" , header->type);
Signature · 1 line
2.34.1
Sunil V L
maintainerPATCH v4 5/23 ACPI: OSL: Make should_use_kmap() 0 for RISC-V
In reply to Sunil V LWithout this, if the tables are larger than 4K,acpi_map() will fail.
--- drivers/acpi/osl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/osl.c +1 -1
@@ -276,7 +276,7 @@ acpi_map_lookup_virt(void __iomem *virt, acpi_size size)return NULL ; } -#if defined(CONFIG_IA64 ) || defined(CONFIG_ARM64 ) +#if defined(CONFIG_IA64 ) || defined(CONFIG_ARM64 ) || defined(CONFIG_RISCV )/* ioremap will take care of cache attributes */ #define should_use_kmap (pfn) 0#else
Signature · 1 line
2.34.1
Re: [PATCH V4 05/23] ACPI: OSL: Make should_use_kmap() 0 for RISC-V
Quoted 14 lines · Sunil V L
Without this, if the tables are larger than 4K,
acpi_map()will fail.Signed-off-by Sunil V L <[email protected]>--- drivers/acpi/osl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/acpi/osl.c +0
-0
drivers/acpi/osl.c acpi_map_lookup_virt(void __iomem *virt, acpi_size size) · line 281
Quoted 7 lines
drivers/acpi/osl.c +1
-1@@ -276,7 +276,7 @@ acpi_map_lookup_virt(void __iomem *virt, acpi_size size)return NULL ; } -#if defined(CONFIG_IA64 ) || defined(CONFIG_ARM64 ) +#if defined(CONFIG_IA64 ) || defined(CONFIG_ARM64 ) || defined(CONFIG_RISCV )/* ioremap will take care of cache attributes */ #define should_use_kmap (pfn) 0
An observation, which can be addressed later; The acpi_os_ioremap() (called when the config above is enabled for RV), does not have an arch specific implementation for RISC-V. The generic one calls ioremap_cached(), which on RISC-V defaults to ioremap() -- caching disabled/_PAGE_IO.
That is probably not what we want, but rather something similar that arm64 does.
Björn
Sunil V L
maintainerRe: [PATCH V4 05/23] ACPI: OSL: Make should_use_kmap() 0 for RISC-V
Hi Bjorn,
Quoted 30 lines · Björn Töpel
Quoted 14 lines · Sunil V L
Without this, if the tables are larger than 4K,
acpi_map()will fail.Signed-off-by Sunil V L <[email protected]>--- drivers/acpi/osl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/acpi/osl.c +0
-0drivers/acpi/osl.c acpi_map_lookup_virt(void __iomem *virt, acpi_size size) · line 281
Quoted 7 lines
drivers/acpi/osl.c +1
-1@@ -276,7 +276,7 @@ acpi_map_lookup_virt(void __iomem *virt, acpi_size size)return NULL ; } -#if defined(CONFIG_IA64 ) || defined(CONFIG_ARM64 ) +#if defined(CONFIG_IA64 ) || defined(CONFIG_ARM64 ) || defined(CONFIG_RISCV )/* ioremap will take care of cache attributes */ #define should_use_kmap (pfn) 0An observation, which can be addressed later; The
acpi_os_ioremap()(called when the config above is enabled for RV), does not have an arch specific implementation for RISC-V. The generic one callsioremap_cached(), which on RISC-V defaults toioremap()-- caching disabled/_PAGE_IO.
Quoted 3 lines
That is probably not what we want, but rather something similar that arm64 does.
Actually, for RISC-V acpi_os_ioremap() is currently a wrapper around memremap(). Sure, this can be enhanced in future if required.
Thanks,
Sunil
Re: [PATCH V4 05/23] ACPI: OSL: Make should_use_kmap() 0 for RISC-V
Quoted 11 lines · Sunil V L
Quoted 9 lines
An observation, which can be addressed later; The
acpi_os_ioremap()(called when the config above is enabled for RV), does not have an arch specific implementation for RISC-V. The generic one callsioremap_cached(), which on RISC-V defaults toioremap()-- caching disabled/_PAGE_IO.That is probably not what we want, but rather something similar that arm64 does.
Actually, for RISC-V
acpi_os_ioremap()is currently a wrapper aroundmemremap(). Sure, this can be enhanced in future if required.
Yeah, realized that when I continued thru the series!
Thanks for clearing it up!
Sunil V L
maintainerPATCH v4 6/23 RISC-V: Add support to build the ACPI core
In reply to Sunil V LEnable ACPI core for RISC-V after adding architecture-specific interfaces and header files required to build the ACPI core.
1) Couple of header files are required unconditionally by the ACPI core. Add empty acenv.h and cpu.h header files.
2) If CONFIG_PCI is enabled, a few PCI related interfaces need to be provided by the architecture. Define dummy interfaces for now so that build succeeds. Actual implementation will be added when PCI support is added for ACPI along with external interrupt controller support.
3) A few globals and memory mapping related functions specific to the architecture need to be provided.
--- arch/riscv/Kconfig | 5 +++ arch/riscv/include/asm/acenv.h | 11 +++++ arch/riscv/include/asm/acpi.h | 61 ++++++++++++++++++++++++++ arch/riscv/include/asm/cpu.h | 8 ++++ arch/riscv/kernel/Makefile | 2 + arch/riscv/kernel/acpi.c | 80 ++++++++++++++++++++++++++++++++++ 6 files changed, 167 insertions(+) create mode 100644 arch/riscv/include/asm/acenv.h create mode 100644 arch/riscv/include/asm/acpi.h create mode 100644 arch/riscv/include/asm/cpu.h create mode 100644 arch/riscv/kernel/acpi.c
arch/riscv/Kconfig +5 -0
@@ -12,6 +12,8 @@ config 32BIT config RISCV def_bool y + select ACPI_GENERIC_GSI if ACPI + select ACPI_REDUCED_HARDWARE_ONLY if ACPI select ARCH_ENABLE_HUGEPAGE_MIGRATION if HUGETLB_PAGE && MIGRATION select ARCH_ENABLE_SPLIT_PMD_PTLOCK if PGTABLE_LEVELS > 2 select ARCH_ENABLE_THP_MIGRATION if TRANSPARENT_HUGEPAGE
@@ -639,6 +641,7 @@ config EFI depends on OF && !XIP_KERNEL depends on MMU default y + select ARCH_SUPPORTS_ACPI if 64BIT select EFI_GENERIC_STUB select EFI_PARAMS_FROM_FDT select EFI_RUNTIME_WRAPPERS
@@ -742,3 +745,5 @@ source "drivers/cpufreq/Kconfig" endmenu # "CPU Power Management" source "arch/riscv/kvm/Kconfig" + +source "drivers/acpi/Kconfig"
arch/riscv/include/asm/acenv.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* RISC-V specific ACPICA environments and implementation +*/ + +#ifndef _ASM_ACENV_H +#define _ASM_ACENV_H + +/* This header is required unconditionally by the ACPI core */ + +#endif /* _ASM_ACENV_H */
arch/riscv/include/asm/acpi.h new file +61 -0
61 lines not on this page · raw message
arch/riscv/include/asm/cpu.h new file +8 -0
@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _ASM_CPU_H +#define _ASM_CPU_H + +/* This header is required unconditionally by the ACPI core */ + +#endif /* _ASM_CPU_H */
arch/riscv/kernel/Makefile +2 -0
@@ -90,3 +90,5 @@ obj-$(CONFIG_EFI) += efi.o obj-$(CONFIG_COMPAT) += compat_syscall_table.o obj-$(CONFIG_COMPAT) += compat_signal.o obj-$(CONFIG_COMPAT) += compat_vdso/ + +obj-$(CONFIG_ACPI) += acpi.o
arch/riscv/kernel/acpi.c new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH V4 06/23] RISC-V: Add support to build the ACPI core
Quoted 243 lines · On Tue, 04 Apr 2023 11:20:20 PDT (-0700), [email protected] wrote:
Enable ACPI core for RISC-V after adding architecture-specific interfaces and header files required to build the ACPI core.
1) Couple of header files are required unconditionally by the ACPI core. Add empty
acenv.handcpu.hheader files.2) If
CONFIG_PCIis enabled, a few PCI related interfaces need to be provided by the architecture. Define dummy interfaces for now so that build succeeds. Actual implementation will be added when PCI support is added for ACPI along with external interrupt controller support.3) A few globals and memory mapping related functions specific to the architecture need to be provided.
Signed-off-by Sunil V L <[email protected]>Reviewed-by Andrew Jones <[email protected]>Reviewed-by Conor Dooley <[email protected]>--- arch/riscv/Kconfig | 5 +++ arch/riscv/include/asm/acenv.h | 11 +++++ arch/riscv/include/asm/acpi.h | 61 ++++++++++++++++++++++++++ arch/riscv/include/asm/cpu.h | 8 ++++ arch/riscv/kernel/Makefile | 2 + arch/riscv/kernel/acpi.c | 80 ++++++++++++++++++++++++++++++++++ 6 files changed, 167 insertions(+) create mode 100644 arch/riscv/include/asm/acenv.h create mode 100644 arch/riscv/include/asm/acpi.h create mode 100644 arch/riscv/include/asm/cpu.h create mode 100644 arch/riscv/kernel/acpi.carch/riscv/Kconfig +5
-0@@ -12,6 +12,8 @@ config 32BIT config RISCV def_bool y + select ACPI_GENERIC_GSI if ACPI + select ACPI_REDUCED_HARDWARE_ONLY if ACPI select ARCH_ENABLE_HUGEPAGE_MIGRATION if HUGETLB_PAGE && MIGRATION select ARCH_ENABLE_SPLIT_PMD_PTLOCK if PGTABLE_LEVELS > 2 select ARCH_ENABLE_THP_MIGRATION if TRANSPARENT_HUGEPAGE@@ -639,6 +641,7 @@ config EFI depends on OF && !XIP_KERNEL depends on MMU default y + select ARCH_SUPPORTS_ACPI if 64BIT select EFI_GENERIC_STUB select EFI_PARAMS_FROM_FDT select EFI_RUNTIME_WRAPPERS@@ -742,3 +745,5 @@ source "drivers/cpufreq/Kconfig" endmenu # "CPU Power Management" source "arch/riscv/kvm/Kconfig" + +source "drivers/acpi/Kconfig"arch/riscv/include/asm/acenv.h new file +11
-0@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* RISC-V specific ACPICA environments and implementation +*/ + +#ifndef _ASM_ACENV_H +#define _ASM_ACENV_H + +/* This header is required unconditionally by the ACPI core */ + +#endif /* _ASM_ACENV_H */ arch/riscv/include/asm/acpi.h new file +61
-0@@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (C) 2013-2014, Linaro Ltd. +* Author: Al Stone <[email protected]> +* Author: Graeme Gregory <[email protected]> +* Author: Hanjun Guo <[email protected]> +* +* Copyright (C) 2021-2023, Ventana Micro Systems Inc. +* Author: Sunil V L <[email protected]> +*/ + +#ifndef _ASM_ACPI_H +#define _ASM_ACPI_H + +/* Basic configuration for ACPI */ +#ifdef CONFIG_ACPI + +/* ACPI table mapping after acpi_permanent_mmap is set */ +void *acpi_os_ioremap (acpi_physical_address phys,acpi_size size); +#define acpi_os_ioremap acpi_os_ioremap + +#define acpi_strict 1/* No out-of-spec workarounds on RISC-V */ +extern int acpi_disabled; +extern int acpi_noirq; +extern int acpi_pci_disabled; + +static inline void disable_acpi (void ) +{ + acpi_disabled =1 ; + acpi_pci_disabled =1 ; + acpi_noirq =1 ; +} + +static inline void enable_acpi (void ) +{ + acpi_disabled =0 ; + acpi_pci_disabled =0 ; + acpi_noirq =0 ; +} + +/* +* The ACPI processor driver for ACPI core code needs this macro +* to find out whether this cpu was already mapped (mapping from CPU hardware +* ID to CPU logical ID) or not. +*/ +#define cpu_physical_id (cpu) cpuid_to_hartid_map(cpu) + +/* +* Since MADT must provide at least one RINTC structure, the +* CPU will be always available in MADT on RISC-V. +*/ +static inline bool acpi_has_cpu_in_madt (void ) +{ +return true; +} + +static inline void arch_fix_phys_package_id (int num,u32 slot) { } + +#endif /* CONFIG_ACPI */ + +#endif /*_ASM_ACPI_H*/ arch/riscv/include/asm/cpu.h new file +8
-0@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _ASM_CPU_H +#define _ASM_CPU_H + +/* This header is required unconditionally by the ACPI core */ + +#endif /* _ASM_CPU_H */ arch/riscv/kernel/Makefile +2
-0@@ -90,3 +90,5 @@ obj-$(CONFIG_EFI) += efi.o obj-$(CONFIG_COMPAT) += compat_syscall_table.o obj-$(CONFIG_COMPAT) += compat_signal.o obj-$(CONFIG_COMPAT) += compat_vdso/ + +obj-$(CONFIG_ACPI) += acpi.oarch/riscv/kernel/acpi.c new file +70
-0@@ -0,0 +1,80 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* RISC-V Specific Low-Level ACPI Boot Support +* +* Copyright (C) 2013-2014, Linaro Ltd. +* Author: Al Stone <[email protected]> +* Author: Graeme Gregory <[email protected]> +* Author: Hanjun Guo <[email protected]> +* Author: Tomasz Nowicki <[email protected]> +* Author: Naresh Bhat <[email protected]> +* +* Copyright (C) 2021-2023, Ventana Micro Systems Inc. +* Author: Sunil V L <[email protected]> +*/ + +#include <linux/acpi.h> +#include <linux/io.h> +#include <linux/pci.h> + +int acpi_noirq =1 ;/* skip ACPI IRQ initialization */ +int acpi_disabled =1 ; +EXPORT_SYMBOL (acpi_disabled); + +int acpi_pci_disabled =1 ;/* skip ACPI PCI scan and IRQ initialization */ +EXPORT_SYMBOL (acpi_pci_disabled); + +/* +* __acpi_map_table() will be called before paging_init(), so early_ioremap() +* or early_memremap() should be called here to for ACPI table mapping. +*/ +void __init __iomem *__acpi_map_table (unsigned long phys,unsigned long size) +{ +if (!size) +return NULL ; + +return early_memremap (phys, size); +} + +void __init __acpi_unmap_table (void __iomem *map,unsigned long size) +{ +if (!map || !size) +return ; + +early_memunmap (map, size); +} + +void *acpi_os_ioremap (acpi_physical_address phys,acpi_size size) +{ +return memremap (phys, size,MEMREMAP_WB ); +} + +#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. +*/ +int raw_pci_read (unsigned int domain,unsigned int bus,unsigned int devfn, +int reg,int len,u32 *val) +{ +return PCIBIOS_DEVICE_NOT_FOUND ; +} + +int raw_pci_write (unsigned int domain,unsigned int bus,unsigned int devfn, +int reg,int len,u32 val) +{ +return PCIBIOS_DEVICE_NOT_FOUND ; +} +
arch/riscv/kernel/acpi.c line 80
Quoted 10 lines
arch/riscv/kernel/acpi.c new file +10
-0+int acpi_pci_bus_find_domain_nr (struct pci_bus *bus) +{ +return -1 ; +} + +struct pci_bus *pci_acpi_scan_root (struct acpi_pci_root *root) +{ +return NULL ; +} +#endif /* CONFIG_PCI */
Sunil V L
maintainerPATCH v4 7/23 ACPI: processor_core: RISC-V: Enable mapping processor to the hartid
In reply to Sunil V Lprocessor_core needs arch-specific functions to map the ACPI ID to the physical ID. In RISC-V platforms, hartid is the physical id and RINTC structure in MADT provides this mapping. Add arch-specific function to get this mapping from RINTC.
--- arch/riscv/include/asm/acpi.h | 3 +++ drivers/acpi/processor_core.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+)
arch/riscv/include/asm/acpi.h +3 -0
@@ -15,6 +15,9 @@/* Basic configuration for ACPI */ #ifdef CONFIG_ACPI +typedef u64 phys_cpuid_t ; +#define PHYS_CPUID_INVALID INVALID_HARTID +/* ACPI table mapping after acpi_permanent_mmap is set */ void *acpi_os_ioremap (acpi_physical_address phys,acpi_size size);#define acpi_os_ioremap acpi_os_ioremap
drivers/acpi/processor_core.c +29 -0
@@ -106,6 +106,32 @@ static int map_gicc_mpidr(struct acpi_subtable_header *entry,return -EINVAL ; } +/* +* Retrieve the RISC-V hartid for the processor +*/ +static int map_rintc_hartid (struct acpi_subtable_header *entry, +int device_declaration,u32 acpi_id, +phys_cpuid_t *hartid) +{ +struct acpi_madt_rintc *rintc = + container_of(entry, struct acpi_madt_rintc, header); + +if (!(rintc->flags &ACPI_MADT_ENABLED )) +return -ENODEV ; + +/* device_declaration means Device object in DSDT, in the +* RISC-V, logical processors are required to +* have a Processor Device object in the DSDT, so we should +* check device_declaration here +*/ +if (device_declaration && rintc->uid == acpi_id) { + *hartid = rintc->hart_id; +return 0 ; + } + +return -EINVAL ; +} +static phys_cpuid_t map_madt_entry (struct acpi_table_madt *madt,int type,u32 acpi_id) {
@@ -136,6 +162,9 @@ static phys_cpuid_t map_madt_entry(struct acpi_table_madt *madt, }else if (header->type ==ACPI_MADT_TYPE_GENERIC_INTERRUPT ) {if (!map_gicc_mpidr (header, type, acpi_id, &phys_id))break ; + }else if (header->type ==ACPI_MADT_TYPE_RINTC ) { +if (!map_rintc_hartid (header, type, acpi_id, &phys_id)) +break ; } entry += header->length; }
Signature · 1 line
2.34.1
Sunil V L
maintainerPATCH v4 8/23 RISC-V: ACPI: Cache and retrieve the RINTC structure
In reply to Sunil V LRINTC structures in the MADT provide mapping between the hartid and the CPU. This is required many times even at run time like cpuinfo. So, instead of parsing the ACPI table every time, cache the RINTC structures and provide a function to get the correct RINTC structure for a given cpu.
--- arch/riscv/include/asm/acpi.h | 2 ++ arch/riscv/kernel/acpi.c | 60 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+)
arch/riscv/include/asm/acpi.h +2 -0
@@ -59,6 +59,8 @@ static inline bool acpi_has_cpu_in_madt(void)static inline void arch_fix_phys_package_id (int num,u32 slot) { } +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc (int cpu); +u32 get_acpi_id_for_cpu (int cpu);#endif /* CONFIG_ACPI */ #endif /*_ASM_ACPI_H*/
arch/riscv/kernel/acpi.c +60 -0
66 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH V4 08/23] RISC-V: ACPI: Cache and retrieve the RINTC structure
Quoted 49 lines · Sunil V L
RINTC structures in the MADT provide mapping between the hartid and the CPU. This is required many times even at run time like cpuinfo. So, instead of parsing the ACPI table every time, cache the RINTC structures and provide a function to get the correct RINTC structure for a given cpu.
Signed-off-by Sunil V L <[email protected]>--- arch/riscv/include/asm/acpi.h | 2 ++ arch/riscv/kernel/acpi.c | 60 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+)arch/riscv/include/asm/acpi.h +2
-0@@ -59,6 +59,8 @@ static inline bool acpi_has_cpu_in_madt(void)static inline void arch_fix_phys_package_id (int num,u32 slot) { } +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc (int cpu); +u32 get_acpi_id_for_cpu (int cpu);#endif /* CONFIG_ACPI */ #endif /*_ASM_ACPI_H*/ arch/riscv/kernel/acpi.c +15
-0@@ -24,6 +24,66 @@ EXPORT_SYMBOL(acpi_disabled);int acpi_pci_disabled =1 ;/* skip ACPI PCI scan and IRQ initialization */ EXPORT_SYMBOL (acpi_pci_disabled); +static struct acpi_madt_rintc cpu_madt_rintc[NR_CPUS ]; + +static int acpi_parse_madt_rintc (union acpi_subtable_headers *header,const unsigned long end) +{ +struct acpi_madt_rintc *rintc = (struct acpi_madt_rintc *)header; +int cpuid; + +if (!(rintc->flags &ACPI_MADT_ENABLED )) +return 0 ; + + cpuid =riscv_hartid_to_cpuid (rintc->hart_id); +/* +* When CONFIG_SMP is disabled, mapping won't be created for +* all cpus. +* CPUs more than NR_CPUS, will be ignored.
arch/riscv/kernel/acpi.c EXPORT_SYMBOL(acpi_disabled); · line 51
Quoted 10 lines
arch/riscv/kernel/acpi.c +10
-0+*/ +if (cpuid >=0 && cpuid <NR_CPUS ) + cpu_madt_rintc[cpuid] = *rintc; + +return 0 ; +} + +static int acpi_init_rintc_array (void ) +{ +if (acpi_table_parse_madt (ACPI_MADT_TYPE_RINTC , acpi_parse_madt_rintc,0 ) >0 )
Does this not return an actual ERRNO? Naïvely following the call chain, it looks like it should do. If it does, why not return that instead of always returning -ENODEV?
Quoted 46 lines
arch/riscv/kernel/acpi.c +35
-0+return 0 ; + +return -ENODEV ; +} + +/* +* Instead of parsing (and freeing) the ACPI table, cache +* the RINTC structures since they are frequently used +* like in cpuinfo. +*/ +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc (int cpu) +{ +static bool rintc_init_done; + +if (!rintc_init_done) { +if (acpi_init_rintc_array ()) { +pr_err ("No valid RINTC entries exist\n" ); +return NULL ; + } + + rintc_init_done = true; + } + +return &cpu_madt_rintc[cpu]; +} + +u32 get_acpi_id_for_cpu (int cpu) +{ +struct acpi_madt_rintc *rintc =acpi_cpu_get_madt_rintc (cpu); + +BUG_ON (!rintc); + +return rintc->uid; +} +/* * __acpi_map_table() will be called before paging_init(), so early_ioremap() * or early_memremap() should be called here to for ACPI table mapping. Signature · 7 lines
2.34.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH V4 08/23] RISC-V: ACPI: Cache and retrieve the RINTC structure
In reply to Sunil V LQuoted 52 lines · Sunil V L
RINTC structures in the MADT provide mapping between the hartid and the CPU. This is required many times even at run time like cpuinfo. So, instead of parsing the ACPI table every time, cache the RINTC structures and provide a function to get the correct RINTC structure for a given cpu.
Signed-off-by Sunil V L <[email protected]>--- arch/riscv/include/asm/acpi.h | 2 ++ arch/riscv/kernel/acpi.c | 60 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+)arch/riscv/include/asm/acpi.h +2
-0@@ -59,6 +59,8 @@ static inline bool acpi_has_cpu_in_madt(void)static inline void arch_fix_phys_package_id (int num,u32 slot) { } +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc (int cpu); +u32 get_acpi_id_for_cpu (int cpu);#endif /* CONFIG_ACPI */ #endif /*_ASM_ACPI_H*/ arch/riscv/kernel/acpi.c +18
-0@@ -24,6 +24,66 @@ EXPORT_SYMBOL(acpi_disabled);int acpi_pci_disabled =1 ;/* skip ACPI PCI scan and IRQ initialization */ EXPORT_SYMBOL (acpi_pci_disabled); +static struct acpi_madt_rintc cpu_madt_rintc[NR_CPUS ]; + +static int acpi_parse_madt_rintc (union acpi_subtable_headers *header,const unsigned long end) +{ +struct acpi_madt_rintc *rintc = (struct acpi_madt_rintc *)header; +int cpuid; + +if (!(rintc->flags &ACPI_MADT_ENABLED )) +return 0 ; + + cpuid =riscv_hartid_to_cpuid (rintc->hart_id); +/* +* When CONFIG_SMP is disabled, mapping won't be created for +* all cpus. +* CPUs more than NR_CPUS, will be ignored. +*/ +if (cpuid >=0 && cpuid <NR_CPUS ) + cpu_madt_rintc[cpuid] = *rintc;
arch/riscv/kernel/acpi.c EXPORT_SYMBOL(acpi_disabled); · line 54
Quoted 10 lines
arch/riscv/kernel/acpi.c +10
-0+ +return 0 ; +} + +static int acpi_init_rintc_array (void ) +{ +if (acpi_table_parse_madt (ACPI_MADT_TYPE_RINTC , acpi_parse_madt_rintc,0 ) >0 ) +return 0 ; + +return -ENODEV ;
As Conor pointed out, the errors could be propagated from acpi_table_parse_madt(), which could reduce this function to
return acpi_table_parse_madt(ACPI_MADT_TYPE_RINTC, acpi_parse_madt_rintc, 0);
where the '< 0' check would be in the caller below. That sounds good to me, but then I'd take that a step further and just drop this helper altogether.
arch/riscv/kernel/acpi.c EXPORT_SYMBOL(acpi_disabled); · line 60
Quoted 6 lines
arch/riscv/kernel/acpi.c +6
-0+} + +/* +* Instead of parsing (and freeing) the ACPI table, cache +* the RINTC structures since they are frequently used +* like in cpuinfo.
^ extra space
Quoted 32 lines
arch/riscv/kernel/acpi.c +26
-0+*/ +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc (int cpu) +{ +static bool rintc_init_done; + +if (!rintc_init_done) { +if (acpi_init_rintc_array ()) { +pr_err ("No valid RINTC entries exist\n" ); +return NULL ; + } + + rintc_init_done = true; + } + +return &cpu_madt_rintc[cpu]; +} + +u32 get_acpi_id_for_cpu (int cpu) +{ +struct acpi_madt_rintc *rintc =acpi_cpu_get_madt_rintc (cpu); + +BUG_ON (!rintc); + +return rintc->uid; +} +/* * __acpi_map_table() will be called before paging_init(), so early_ioremap() * or early_memremap() should be called here to for ACPI table mapping. Signature · 1 line
2.34.1
Otherwise,
Thanks,
drew
Sunil V L
maintainerRe: [PATCH V4 08/23] RISC-V: ACPI: Cache and retrieve the RINTC structure
Quoted 67 lines · Andrew Jones
Quoted 52 lines · Sunil V L
RINTC structures in the MADT provide mapping between the hartid and the CPU. This is required many times even at run time like cpuinfo. So, instead of parsing the ACPI table every time, cache the RINTC structures and provide a function to get the correct RINTC structure for a given cpu.
Signed-off-by Sunil V L <[email protected]>--- arch/riscv/include/asm/acpi.h | 2 ++ arch/riscv/kernel/acpi.c | 60 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+)arch/riscv/include/asm/acpi.h +2
-0@@ -59,6 +59,8 @@ static inline bool acpi_has_cpu_in_madt(void)static inline void arch_fix_phys_package_id (int num,u32 slot) { } +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc (int cpu); +u32 get_acpi_id_for_cpu (int cpu);#endif /* CONFIG_ACPI */ #endif /*_ASM_ACPI_H*/ arch/riscv/kernel/acpi.c +18
-0@@ -24,6 +24,66 @@ EXPORT_SYMBOL(acpi_disabled);int acpi_pci_disabled =1 ;/* skip ACPI PCI scan and IRQ initialization */ EXPORT_SYMBOL (acpi_pci_disabled); +static struct acpi_madt_rintc cpu_madt_rintc[NR_CPUS ]; + +static int acpi_parse_madt_rintc (union acpi_subtable_headers *header,const unsigned long end) +{ +struct acpi_madt_rintc *rintc = (struct acpi_madt_rintc *)header; +int cpuid; + +if (!(rintc->flags &ACPI_MADT_ENABLED )) +return 0 ; + + cpuid =riscv_hartid_to_cpuid (rintc->hart_id); +/* +* When CONFIG_SMP is disabled, mapping won't be created for +* all cpus. +* CPUs more than NR_CPUS, will be ignored. +*/ +if (cpuid >=0 && cpuid <NR_CPUS ) + cpu_madt_rintc[cpuid] = *rintc;arch/riscv/kernel/acpi.c EXPORT_SYMBOL(acpi_disabled); · line 54
Quoted 10 lines
arch/riscv/kernel/acpi.c +10
-0+ +return 0 ; +} + +static int acpi_init_rintc_array (void ) +{ +if (acpi_table_parse_madt (ACPI_MADT_TYPE_RINTC , acpi_parse_madt_rintc,0 ) >0 ) +return 0 ; + +return -ENODEV ;As Conor pointed out, the errors could be propagated from
acpi_table_parse_madt(), which could reduce this function to
Quoted 6 lines
return
acpi_table_parse_madt(ACPI_MADT_TYPE_RINTC, acpi_parse_madt_rintc, 0);where the '< 0' check would be in the caller below. That sounds good to me, but then I'd take that a step further and just drop this helper altogether.
Thanks, Conor, Drew. I used similar to how others have used acpi_table_parse_madt(). But your suggestion makes sense. Will remove the wrapper function also.
Thanks,
Sunil
Palmer Dabbelt
maintainerRe: [PATCH V4 08/23] RISC-V: ACPI: Cache and retrieve the RINTC structure
In reply to Sunil V LQuoted 35 lines · On Tue, 04 Apr 2023 11:20:22 PDT (-0700), [email protected] wrote:
RINTC structures in the MADT provide mapping between the hartid and the CPU. This is required many times even at run time like cpuinfo. So, instead of parsing the ACPI table every time, cache the RINTC structures and provide a function to get the correct RINTC structure for a given cpu.
Signed-off-by Sunil V L <[email protected]>--- arch/riscv/include/asm/acpi.h | 2 ++ arch/riscv/kernel/acpi.c | 60 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+)arch/riscv/include/asm/acpi.h +2
-0@@ -59,6 +59,8 @@ static inline bool acpi_has_cpu_in_madt(void)static inline void arch_fix_phys_package_id (int num,u32 slot) { } +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc (int cpu); +u32 get_acpi_id_for_cpu (int cpu);#endif /* CONFIG_ACPI */ #endif /*_ASM_ACPI_H*/ arch/riscv/kernel/acpi.c +1
-0@@ -24,6 +24,66 @@ EXPORT_SYMBOL(acpi_disabled);int acpi_pci_disabled =1 ;/* skip ACPI PCI scan and IRQ initialization */ EXPORT_SYMBOL (acpi_pci_disabled); +static struct acpi_madt_rintc cpu_madt_rintc[NR_CPUS ];
arch/riscv/kernel/acpi.c EXPORT_SYMBOL(acpi_disabled); · line 37
Quoted 10 lines
arch/riscv/kernel/acpi.c +10
-0+ +static int acpi_parse_madt_rintc (union acpi_subtable_headers *header,const unsigned long end) +{ +struct acpi_madt_rintc *rintc = (struct acpi_madt_rintc *)header; +int cpuid; + +if (!(rintc->flags &ACPI_MADT_ENABLED )) +return 0 ; + + cpuid =riscv_hartid_to_cpuid (rintc->hart_id);
Unless I'm missing something, this races with CPUs coming online. Maybe that's a rare enough case we don't care, but I think we'd also just have simpler logic if we fixed it...
Quoted 17 lines
arch/riscv/kernel/acpi.c +17
-0+/* +* When CONFIG_SMP is disabled, mapping won't be created for +* all cpus. +* CPUs more than NR_CPUS, will be ignored. +*/ +if (cpuid >=0 && cpuid <NR_CPUS ) + cpu_madt_rintc[cpuid] = *rintc; + +return 0 ; +} + +static int acpi_init_rintc_array (void ) +{ +if (acpi_table_parse_madt (ACPI_MADT_TYPE_RINTC , acpi_parse_madt_rintc,0 ) >0 ) +return 0 ; + +return -ENODEV ;
arch/riscv/kernel/acpi.c EXPORT_SYMBOL(acpi_disabled); · line 64
Quoted 10 lines
arch/riscv/kernel/acpi.c +10
-0+} + +/* +* Instead of parsing (and freeing) the ACPI table, cache +* the RINTC structures since they are frequently used +* like in cpuinfo. +*/ +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc (int cpu) +{ +static bool rintc_init_done;
... basically just get rid of this global variable, and instead have a
if (!&cpu_madt_rintc[cpu])
... parse ...
return &cpu_madt_rintc[cpu];
that'd probably let us get rid of a handful of these helpers too, as now it's just a call to the parsing bits.
Quoted 8 lines
arch/riscv/kernel/acpi.c +8
-0+ +if (!rintc_init_done) { +if (acpi_init_rintc_array ()) { +pr_err ("No valid RINTC entries exist\n" ); +return NULL ; + } + + rintc_init_done = true;
arch/riscv/kernel/acpi.c EXPORT_SYMBOL(acpi_disabled); · line 82
Quoted 10 lines
arch/riscv/kernel/acpi.c +10
-0+ } + +return &cpu_madt_rintc[cpu]; +} + +u32 get_acpi_id_for_cpu (int cpu) +{ +struct acpi_madt_rintc *rintc =acpi_cpu_get_madt_rintc (cpu); + +BUG_ON (!rintc);
We should have some better error reporting here. It looks like all the callerss of get_acpi_id_for_cpu() are tolerant of a nonsense ID being returned, so maybe we just pr_warn() something users can understand and then return -1 or something?
Quoted 7 lines
arch/riscv/kernel/acpi.c +4
-0+ +return rintc->uid; +} +/* * __acpi_map_table() will be called before paging_init(), so early_ioremap() * or early_memremap() should be called here to for ACPI table mapping.
Sunil V L
maintainerRe: [PATCH V4 08/23] RISC-V: ACPI: Cache and retrieve the RINTC structure
Hi Palmer,
Quoted 35 lines · Palmer Dabbelt
Quoted 34 lines · On Tue, 04 Apr 2023 11:20:22 PDT (-0700), [email protected] wrote:
RINTC structures in the MADT provide mapping between the hartid and the CPU. This is required many times even at run time like cpuinfo. So, instead of parsing the ACPI table every time, cache the RINTC structures and provide a function to get the correct RINTC structure for a given cpu.
Signed-off-by Sunil V L <[email protected]>--- arch/riscv/include/asm/acpi.h | 2 ++ arch/riscv/kernel/acpi.c | 60 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+)arch/riscv/include/asm/acpi.h +2
-0@@ -59,6 +59,8 @@ static inline bool acpi_has_cpu_in_madt(void)static inline void arch_fix_phys_package_id (int num,u32 slot) { } +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc (int cpu); +u32 get_acpi_id_for_cpu (int cpu);#endif /* CONFIG_ACPI */ #endif /*_ASM_ACPI_H*/ arch/riscv/kernel/acpi.c +0
-0@@ -24,6 +24,66 @@ EXPORT_SYMBOL(acpi_disabled);int acpi_pci_disabled =1 ;/* skip ACPI PCI scan and IRQ initialization */ EXPORT_SYMBOL (acpi_pci_disabled);
Quoted 16 lines
arch/riscv/kernel/acpi.c EXPORT_SYMBOL(acpi_disabled); · line 37
Quoted 11 lines
arch/riscv/kernel/acpi.c +11
-0+static struct acpi_madt_rintc cpu_madt_rintc[NR_CPUS ]; + +static int acpi_parse_madt_rintc (union acpi_subtable_headers *header,const unsigned long end) +{ +struct acpi_madt_rintc *rintc = (struct acpi_madt_rintc *)header; +int cpuid; + +if (!(rintc->flags &ACPI_MADT_ENABLED )) +return 0 ; + + cpuid =riscv_hartid_to_cpuid (rintc->hart_id);Unless I'm missing something, this races with CPUs coming online. Maybe that's a rare enough case we don't care, but I think we'd also just have simpler logic if we fixed it...
This depend only on cpuid_to_hartid_map filled up. I wish I could initialize this RINTC mapping in setup_smp() itself like ARM64. But in RISC-V, this file smpboot.c gets built only when CONFIG_SMP is enabled. Hence, we need to initialize this array outside of setup_smp().
I can update the code to initialize this from setup_arch() immediately after setup_smp() if ACPI is enabled. That should avoid the global variable check also. Let me know if you prefer this.
Quoted 30 lines
Quoted 17 lines
arch/riscv/kernel/acpi.c +17
-0+/* +* When CONFIG_SMP is disabled, mapping won't be created for +* all cpus. +* CPUs more than NR_CPUS, will be ignored. +*/ +if (cpuid >=0 && cpuid <NR_CPUS ) + cpu_madt_rintc[cpuid] = *rintc; + +return 0 ; +} + +static int acpi_init_rintc_array (void ) +{ +if (acpi_table_parse_madt (ACPI_MADT_TYPE_RINTC , acpi_parse_madt_rintc,0 ) >0 ) +return 0 ; + +return -ENODEV ;arch/riscv/kernel/acpi.c EXPORT_SYMBOL(acpi_disabled); · line 64
Quoted 10 lines
arch/riscv/kernel/acpi.c +10
-0+} + +/* +* Instead of parsing (and freeing) the ACPI table, cache +* the RINTC structures since they are frequently used +* like in cpuinfo. +*/ +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc (int cpu) +{ +static bool rintc_init_done;... basically just get rid of this global variable, and instead have a
Quoted 7 lines
if (!&cpu_madt_rintc[cpu]) ... parse ... return &cpu_madt_rintc[cpu];that'd probably let us get rid of a handful of these helpers too, as now it's just a call to the parsing bits.
I am afraid this (!&cpu_madt_rintc[cpu]) check won't work since we are not caching the RINTC pointers but actual contents itself. So, the address is always valid. However, as per Drew's earlier feedback I am going to reduce one helper. I am planning to send the next version of this patch once 6.4 rc1 is available since the ACPICA patches are merged now.
Quoted 15 lines
Quoted 15 lines
arch/riscv/kernel/acpi.c +15
-0+ +if (!rintc_init_done) { +if (acpi_init_rintc_array ()) { +pr_err ("No valid RINTC entries exist\n" ); +return NULL ; + } + + rintc_init_done = true; + } + +return &cpu_madt_rintc[cpu]; +} + +u32 get_acpi_id_for_cpu (int cpu) +{
Quoted 9 lines
arch/riscv/kernel/acpi.c EXPORT_SYMBOL(acpi_disabled); · line 82
Quoted 3 lines
arch/riscv/kernel/acpi.c +3
-0+struct acpi_madt_rintc *rintc =acpi_cpu_get_madt_rintc (cpu); + +BUG_ON (!rintc);We should have some better error reporting here. It looks like all the callerss of
get_acpi_id_for_cpu()are tolerant of a nonsense ID being returned, so maybe we justpr_warn()something users can understand and then return -1 or something?
RINTC is mandatory for ACPI systems. Also, all 32bit values are valid for UID. So, there is no bogus value we can return.
Actually, I just realized this check is redundant. It will never be NULL since it is a static array. So, we can just get rid of the BUG.
Thanks!
Sunil
Re: [PATCH V4 08/23] RISC-V: ACPI: Cache and retrieve the RINTC structure
Quoted 132 lines · Sunil V L
Hi Palmer,
Quoted 35 lines · Palmer Dabbelt
Quoted 34 lines · On Tue, 04 Apr 2023 11:20:22 PDT (-0700), [email protected] wrote:
RINTC structures in the MADT provide mapping between the hartid and the CPU. This is required many times even at run time like cpuinfo. So, instead of parsing the ACPI table every time, cache the RINTC structures and provide a function to get the correct RINTC structure for a given cpu.
Signed-off-by Sunil V L <[email protected]>--- arch/riscv/include/asm/acpi.h | 2 ++ arch/riscv/kernel/acpi.c | 60 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+)arch/riscv/include/asm/acpi.h +2
-0@@ -59,6 +59,8 @@ static inline bool acpi_has_cpu_in_madt(void)static inline void arch_fix_phys_package_id (int num,u32 slot) { } +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc (int cpu); +u32 get_acpi_id_for_cpu (int cpu);#endif /* CONFIG_ACPI */ #endif /*_ASM_ACPI_H*/ arch/riscv/kernel/acpi.c +0
-0@@ -24,6 +24,66 @@ EXPORT_SYMBOL(acpi_disabled);int acpi_pci_disabled =1 ;/* skip ACPI PCI scan and IRQ initialization */ EXPORT_SYMBOL (acpi_pci_disabled);Quoted 16 lines
arch/riscv/kernel/acpi.c EXPORT_SYMBOL(acpi_disabled); · line 37
Quoted 11 lines
arch/riscv/kernel/acpi.c +11
-0+static struct acpi_madt_rintc cpu_madt_rintc[NR_CPUS ]; + +static int acpi_parse_madt_rintc (union acpi_subtable_headers *header,const unsigned long end) +{ +struct acpi_madt_rintc *rintc = (struct acpi_madt_rintc *)header; +int cpuid; + +if (!(rintc->flags &ACPI_MADT_ENABLED )) +return 0 ; + + cpuid =riscv_hartid_to_cpuid (rintc->hart_id);Unless I'm missing something, this races with CPUs coming online. Maybe that's a rare enough case we don't care, but I think we'd also just have simpler logic if we fixed it...
This depend only on
cpuid_to_hartid_mapfilled up. I wish I could initialize this RINTC mapping insetup_smp()itself like ARM64. But in RISC-V, this filesmpboot.cgets built only whenCONFIG_SMPis enabled. Hence, we need to initialize this array outside ofsetup_smp().I can update the code to initialize this from
setup_arch()immediately aftersetup_smp()if ACPI is enabled. That should avoid the global variable check also. Let me know if you prefer this.Quoted 30 lines
Quoted 17 lines
arch/riscv/kernel/acpi.c +17
-0+/* +* When CONFIG_SMP is disabled, mapping won't be created for +* all cpus. +* CPUs more than NR_CPUS, will be ignored. +*/ +if (cpuid >=0 && cpuid <NR_CPUS ) + cpu_madt_rintc[cpuid] = *rintc; + +return 0 ; +} + +static int acpi_init_rintc_array (void ) +{ +if (acpi_table_parse_madt (ACPI_MADT_TYPE_RINTC , acpi_parse_madt_rintc,0 ) >0 ) +return 0 ; + +return -ENODEV ;arch/riscv/kernel/acpi.c EXPORT_SYMBOL(acpi_disabled); · line 64
Quoted 10 lines
arch/riscv/kernel/acpi.c +10
-0+} + +/* +* Instead of parsing (and freeing) the ACPI table, cache +* the RINTC structures since they are frequently used +* like in cpuinfo. +*/ +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc (int cpu) +{ +static bool rintc_init_done;... basically just get rid of this global variable, and instead have a
Quoted 7 lines
if (!&cpu_madt_rintc[cpu]) ... parse ... return &cpu_madt_rintc[cpu];that'd probably let us get rid of a handful of these helpers too, as now it's just a call to the parsing bits.
I am afraid this (!&cpu_madt_rintc[cpu]) check won't work since we are not caching the RINTC pointers but actual contents itself. So, the address is always valid. However, as per Drew's earlier feedback I am going to reduce one helper. I am planning to send the next version of this patch once 6.4 rc1 is available since the ACPICA patches are merged now.
Quoted 15 lines
Quoted 15 lines
arch/riscv/kernel/acpi.c +15
-0+ +if (!rintc_init_done) { +if (acpi_init_rintc_array ()) { +pr_err ("No valid RINTC entries exist\n" ); +return NULL ; + } + + rintc_init_done = true; + } + +return &cpu_madt_rintc[cpu]; +} + +u32 get_acpi_id_for_cpu (int cpu) +{Quoted 9 lines
arch/riscv/kernel/acpi.c EXPORT_SYMBOL(acpi_disabled); · line 82
Quoted 3 lines
arch/riscv/kernel/acpi.c +3
-0+struct acpi_madt_rintc *rintc =acpi_cpu_get_madt_rintc (cpu); + +BUG_ON (!rintc);We should have some better error reporting here. It looks like all the callerss of
get_acpi_id_for_cpu()are tolerant of a nonsense ID being returned, so maybe we justpr_warn()something users can understand and then return -1 or something?
Quoted 5 lines
RINTC is mandatory for ACPI systems. Also, all 32bit values are valid for UID. So, there is no bogus value we can return.
Actually, I just realized this check is redundant. It will never be NULL since it is a static array. So, we can just get rid of the BUG.
It can be NULL on the first call of acpi_cpu_get_madt_rintc(), which is a good time to BUG if there's isn't an RINTC.
Thanks,
drew
Sunil V L
maintainerRe: [PATCH V4 08/23] RISC-V: ACPI: Cache and retrieve the RINTC structure
Quoted 133 lines · Andrew Jones
Quoted 132 lines · Sunil V L
Hi Palmer,
Quoted 35 lines · Palmer Dabbelt
Quoted 34 lines · On Tue, 04 Apr 2023 11:20:22 PDT (-0700), [email protected] wrote:
RINTC structures in the MADT provide mapping between the hartid and the CPU. This is required many times even at run time like cpuinfo. So, instead of parsing the ACPI table every time, cache the RINTC structures and provide a function to get the correct RINTC structure for a given cpu.
Signed-off-by Sunil V L <[email protected]>--- arch/riscv/include/asm/acpi.h | 2 ++ arch/riscv/kernel/acpi.c | 60 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+)arch/riscv/include/asm/acpi.h +2
-0@@ -59,6 +59,8 @@ static inline bool acpi_has_cpu_in_madt(void)static inline void arch_fix_phys_package_id (int num,u32 slot) { } +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc (int cpu); +u32 get_acpi_id_for_cpu (int cpu);#endif /* CONFIG_ACPI */ #endif /*_ASM_ACPI_H*/ arch/riscv/kernel/acpi.c +0
-0@@ -24,6 +24,66 @@ EXPORT_SYMBOL(acpi_disabled);int acpi_pci_disabled =1 ;/* skip ACPI PCI scan and IRQ initialization */ EXPORT_SYMBOL (acpi_pci_disabled);Quoted 16 lines
arch/riscv/kernel/acpi.c EXPORT_SYMBOL(acpi_disabled); · line 37
Quoted 11 lines
arch/riscv/kernel/acpi.c +11
-0+static struct acpi_madt_rintc cpu_madt_rintc[NR_CPUS ]; + +static int acpi_parse_madt_rintc (union acpi_subtable_headers *header,const unsigned long end) +{ +struct acpi_madt_rintc *rintc = (struct acpi_madt_rintc *)header; +int cpuid; + +if (!(rintc->flags &ACPI_MADT_ENABLED )) +return 0 ; + + cpuid =riscv_hartid_to_cpuid (rintc->hart_id);Unless I'm missing something, this races with CPUs coming online. Maybe that's a rare enough case we don't care, but I think we'd also just have simpler logic if we fixed it...
This depend only on
cpuid_to_hartid_mapfilled up. I wish I could initialize this RINTC mapping insetup_smp()itself like ARM64. But in RISC-V, this filesmpboot.cgets built only whenCONFIG_SMPis enabled. Hence, we need to initialize this array outside ofsetup_smp().I can update the code to initialize this from
setup_arch()immediately aftersetup_smp()if ACPI is enabled. That should avoid the global variable check also. Let me know if you prefer this.Quoted 30 lines
Quoted 17 lines
arch/riscv/kernel/acpi.c +17
-0+/* +* When CONFIG_SMP is disabled, mapping won't be created for +* all cpus. +* CPUs more than NR_CPUS, will be ignored. +*/ +if (cpuid >=0 && cpuid <NR_CPUS ) + cpu_madt_rintc[cpuid] = *rintc; + +return 0 ; +} + +static int acpi_init_rintc_array (void ) +{ +if (acpi_table_parse_madt (ACPI_MADT_TYPE_RINTC , acpi_parse_madt_rintc,0 ) >0 ) +return 0 ; + +return -ENODEV ;arch/riscv/kernel/acpi.c EXPORT_SYMBOL(acpi_disabled); · line 64
Quoted 10 lines
arch/riscv/kernel/acpi.c +10
-0+} + +/* +* Instead of parsing (and freeing) the ACPI table, cache +* the RINTC structures since they are frequently used +* like in cpuinfo. +*/ +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc (int cpu) +{ +static bool rintc_init_done;... basically just get rid of this global variable, and instead have a
Quoted 7 lines
if (!&cpu_madt_rintc[cpu]) ... parse ... return &cpu_madt_rintc[cpu];that'd probably let us get rid of a handful of these helpers too, as now it's just a call to the parsing bits.
I am afraid this (!&cpu_madt_rintc[cpu]) check won't work since we are not caching the RINTC pointers but actual contents itself. So, the address is always valid. However, as per Drew's earlier feedback I am going to reduce one helper. I am planning to send the next version of this patch once 6.4 rc1 is available since the ACPICA patches are merged now.
Quoted 24 lines
Quoted 8 lines
arch/riscv/kernel/acpi.c +8
-0+ +if (!rintc_init_done) { +if (acpi_init_rintc_array ()) { +pr_err ("No valid RINTC entries exist\n" ); +return NULL ; + } + + rintc_init_done = true;arch/riscv/kernel/acpi.c EXPORT_SYMBOL(acpi_disabled); · line 82
Quoted 10 lines
arch/riscv/kernel/acpi.c +10
-0+ } + +return &cpu_madt_rintc[cpu]; +} + +u32 get_acpi_id_for_cpu (int cpu) +{ +struct acpi_madt_rintc *rintc =acpi_cpu_get_madt_rintc (cpu); + +BUG_ON (!rintc);We should have some better error reporting here. It looks like all the callerss of
get_acpi_id_for_cpu()are tolerant of a nonsense ID being returned, so maybe we justpr_warn()something users can understand and then return -1 or something?
Quoted 9 lines
Quoted 5 lines
RINTC is mandatory for ACPI systems. Also, all 32bit values are valid for UID. So, there is no bogus value we can return.
Actually, I just realized this check is redundant. It will never be NULL since it is a static array. So, we can just get rid of the BUG.
It can be NULL on the first call of
acpi_cpu_get_madt_rintc(), which is a good time to BUG if there's isn't an RINTC.
Sorry, I mean if we change the initialization to get called from setup_arch, then we can get rid of this check along with global variable check, correct?
Thanks,
Sunil
Re: [PATCH V4 08/23] RISC-V: ACPI: Cache and retrieve the RINTC structure
Quoted 140 lines · Sunil V L
Quoted 139 lines · Andrew Jones
Quoted 137 lines · Sunil V L
Hi Palmer,
Quoted 35 lines · Palmer Dabbelt
Quoted 34 lines · On Tue, 04 Apr 2023 11:20:22 PDT (-0700), [email protected] wrote:
RINTC structures in the MADT provide mapping between the hartid and the CPU. This is required many times even at run time like cpuinfo. So, instead of parsing the ACPI table every time, cache the RINTC structures and provide a function to get the correct RINTC structure for a given cpu.
Signed-off-by Sunil V L <[email protected]>--- arch/riscv/include/asm/acpi.h | 2 ++ arch/riscv/kernel/acpi.c | 60 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+)arch/riscv/include/asm/acpi.h +2
-0@@ -59,6 +59,8 @@ static inline bool acpi_has_cpu_in_madt(void)static inline void arch_fix_phys_package_id (int num,u32 slot) { } +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc (int cpu); +u32 get_acpi_id_for_cpu (int cpu);#endif /* CONFIG_ACPI */ #endif /*_ASM_ACPI_H*/ arch/riscv/kernel/acpi.c +0
-0@@ -24,6 +24,66 @@ EXPORT_SYMBOL(acpi_disabled);int acpi_pci_disabled =1 ;/* skip ACPI PCI scan and IRQ initialization */ EXPORT_SYMBOL (acpi_pci_disabled);Quoted 16 lines
arch/riscv/kernel/acpi.c EXPORT_SYMBOL(acpi_disabled); · line 37
Quoted 11 lines
arch/riscv/kernel/acpi.c +11
-0+static struct acpi_madt_rintc cpu_madt_rintc[NR_CPUS ]; + +static int acpi_parse_madt_rintc (union acpi_subtable_headers *header,const unsigned long end) +{ +struct acpi_madt_rintc *rintc = (struct acpi_madt_rintc *)header; +int cpuid; + +if (!(rintc->flags &ACPI_MADT_ENABLED )) +return 0 ; + + cpuid =riscv_hartid_to_cpuid (rintc->hart_id);Unless I'm missing something, this races with CPUs coming online. Maybe that's a rare enough case we don't care, but I think we'd also just have simpler logic if we fixed it...
This depend only on
cpuid_to_hartid_mapfilled up. I wish I could initialize this RINTC mapping insetup_smp()itself like ARM64. But in RISC-V, this filesmpboot.cgets built only whenCONFIG_SMPis enabled. Hence, we need to initialize this array outside ofsetup_smp().I can update the code to initialize this from
setup_arch()immediately aftersetup_smp()if ACPI is enabled. That should avoid the global variable check also. Let me know if you prefer this.Quoted 30 lines
Quoted 17 lines
arch/riscv/kernel/acpi.c +17
-0+/* +* When CONFIG_SMP is disabled, mapping won't be created for +* all cpus. +* CPUs more than NR_CPUS, will be ignored. +*/ +if (cpuid >=0 && cpuid <NR_CPUS ) + cpu_madt_rintc[cpuid] = *rintc; + +return 0 ; +} + +static int acpi_init_rintc_array (void ) +{ +if (acpi_table_parse_madt (ACPI_MADT_TYPE_RINTC , acpi_parse_madt_rintc,0 ) >0 ) +return 0 ; + +return -ENODEV ;arch/riscv/kernel/acpi.c EXPORT_SYMBOL(acpi_disabled); · line 64
Quoted 10 lines
arch/riscv/kernel/acpi.c +10
-0+} + +/* +* Instead of parsing (and freeing) the ACPI table, cache +* the RINTC structures since they are frequently used +* like in cpuinfo. +*/ +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc (int cpu) +{ +static bool rintc_init_done;... basically just get rid of this global variable, and instead have a
Quoted 7 lines
if (!&cpu_madt_rintc[cpu]) ... parse ... return &cpu_madt_rintc[cpu];that'd probably let us get rid of a handful of these helpers too, as now it's just a call to the parsing bits.
I am afraid this (!&cpu_madt_rintc[cpu]) check won't work since we are not caching the RINTC pointers but actual contents itself. So, the address is always valid. However, as per Drew's earlier feedback I am going to reduce one helper. I am planning to send the next version of this patch once 6.4 rc1 is available since the ACPICA patches are merged now.
Quoted 15 lines
Quoted 15 lines
arch/riscv/kernel/acpi.c +15
-0+ +if (!rintc_init_done) { +if (acpi_init_rintc_array ()) { +pr_err ("No valid RINTC entries exist\n" ); +return NULL ; + } + + rintc_init_done = true; + } + +return &cpu_madt_rintc[cpu]; +} + +u32 get_acpi_id_for_cpu (int cpu) +{Quoted 9 lines
arch/riscv/kernel/acpi.c EXPORT_SYMBOL(acpi_disabled); · line 82
Quoted 3 lines
arch/riscv/kernel/acpi.c +3
-0+struct acpi_madt_rintc *rintc =acpi_cpu_get_madt_rintc (cpu); + +BUG_ON (!rintc);We should have some better error reporting here. It looks like all the callerss of
get_acpi_id_for_cpu()are tolerant of a nonsense ID being returned, so maybe we justpr_warn()something users can understand and then return -1 or something?RINTC is mandatory for ACPI systems. Also, all 32bit values are valid for UID. So, there is no bogus value we can return.
Actually, I just realized this check is redundant. It will never be NULL since it is a static array. So, we can just get rid of the BUG.
Quoted 6 lines
Quoted 3 lines
It can be NULL on the first call of
acpi_cpu_get_madt_rintc(), which is a good time to BUG if there's isn't an RINTC.Sorry, I mean if we change the initialization to get called from
setup_arch, then we can get rid of this check along with global variable check, correct?
Sounds good to me, but now I think we're pushing the question of whether to BUG or not on a missing RINTC to that new init function, because otherwise we'll still end up in get_acpi_id_for_cpu() eventually with or without a valid rintc from which we get the uid (and the uid has no specified bogus value).
Thanks,
drew
Sunil V L
maintainerPATCH v4 9/23 drivers/acpi: RISC-V: Add RHCT related code
In reply to Sunil V LRHCT is a new table defined for RISC-V to communicate the features of the CPU to the OS. Create a new architecture folder in drivers/acpi and add RHCT parsing code.
--- arch/riscv/include/asm/acpi.h | 9 ++++ drivers/acpi/Makefile | 2 + drivers/acpi/riscv/Makefile | 2 + drivers/acpi/riscv/rhct.c | 83 +++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 drivers/acpi/riscv/Makefile create mode 100644 drivers/acpi/riscv/rhct.c
arch/riscv/include/asm/acpi.h +9 -0
@@ -61,6 +61,15 @@ static inline void arch_fix_phys_package_id(int num, u32 slot) { }struct acpi_madt_rintc *acpi_cpu_get_madt_rintc (int cpu);u32 get_acpi_id_for_cpu (int cpu); +int acpi_get_riscv_isa (struct acpi_table_header *table, +unsigned int cpu,const char **isa); +#else +static inline int acpi_get_riscv_isa (struct acpi_table_header *table, +unsigned int cpu,const char **isa) +{ +return -EINVAL ; +} +#endif /* CONFIG_ACPI */ #endif /*_ASM_ACPI_H*/
drivers/acpi/Makefile +2 -0
@@ -131,3 +131,5 @@ obj-y += dptf/ obj-$(CONFIG_ARM64) += arm64/ obj-$(CONFIG_ACPI_VIOT) += viot.o + +obj-$(CONFIG_RISCV) += riscv/
drivers/acpi/riscv/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-y += rhct.o
drivers/acpi/riscv/rhct.c new file +83 -0
83 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH V4 09/23] drivers/acpi: RISC-V: Add RHCT related code
Quoted 133 lines · On Tue, 04 Apr 2023 11:20:23 PDT (-0700), [email protected] wrote:
RHCT is a new table defined for RISC-V to communicate the features of the CPU to the OS. Create a new architecture folder in
drivers/acpiand add RHCT parsing code.Signed-off-by Sunil V L <[email protected]>Reviewed-by Andrew Jones <[email protected]>--- arch/riscv/include/asm/acpi.h | 9 ++++ drivers/acpi/Makefile | 2 + drivers/acpi/riscv/Makefile | 2 + drivers/acpi/riscv/rhct.c | 83 +++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 drivers/acpi/riscv/Makefile create mode 100644 drivers/acpi/riscv/rhct.carch/riscv/include/asm/acpi.h +9
-0@@ -61,6 +61,15 @@ static inline void arch_fix_phys_package_id(int num, u32 slot) { }struct acpi_madt_rintc *acpi_cpu_get_madt_rintc (int cpu);u32 get_acpi_id_for_cpu (int cpu); +int acpi_get_riscv_isa (struct acpi_table_header *table, +unsigned int cpu,const char **isa); +#else +static inline int acpi_get_riscv_isa (struct acpi_table_header *table, +unsigned int cpu,const char **isa) +{ +return -EINVAL ; +} +#endif /* CONFIG_ACPI */ #endif /*_ASM_ACPI_H*/ drivers/acpi/Makefile +2
-0@@ -131,3 +131,5 @@ obj-y += dptf/ obj-$(CONFIG_ARM64) += arm64/ obj-$(CONFIG_ACPI_VIOT) += viot.o + +obj-$(CONFIG_RISCV) += riscv/drivers/acpi/riscv/Makefile new file +2
-0@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-y += rhct.odrivers/acpi/riscv/rhct.c new file +73
-0@@ -0,0 +1,83 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2022-2023, Ventana Micro Systems Inc +* Author: Sunil V L <[email protected]> +* +*/ + +#define pr_fmt (fmt) "ACPI: RHCT: " fmt + +#include <linux/acpi.h> + +static struct acpi_table_header *acpi_get_rhct (void ) +{ +static struct acpi_table_header *rhct; +acpi_status status; + +/* +* RHCT will be used at runtime on every CPU, so we +* don't need to call acpi_put_table() to release the table mapping. +*/ +if (!rhct) { + status =acpi_get_table (ACPI_SIG_RHCT ,0 , &rhct); +if (ACPI_FAILURE (status)) { +pr_warn_once ("No RHCT table found\n" ); +return NULL ; + } + } + +return rhct; +} + +/* +* During early boot, the caller should call acpi_get_table() and pass its pointer to +* these functions(and free up later). At run time, since this table can be used +* multiple times, NULL may be passed in order to use the cached table. +*/ +int acpi_get_riscv_isa (struct acpi_table_header *table,unsigned int cpu,const char **isa) +{ +struct acpi_rhct_node_header *node, *ref_node, *end; +u32 size_hdr =sizeof (struct acpi_rhct_node_header ); +u32 size_hartinfo =sizeof (struct acpi_rhct_hart_info ); +struct acpi_rhct_hart_info *hart_info; +struct acpi_rhct_isa_string *isa_node; +struct acpi_table_rhct *rhct; +u32 *hart_info_node_offset; +u32 acpi_cpu_id =get_acpi_id_for_cpu (cpu); + +BUG_ON (acpi_disabled); + +if (!table) { + rhct = (struct acpi_table_rhct *)acpi_get_rhct (); +if (!rhct) +return -ENOENT ; + }else { + rhct = (struct acpi_table_rhct *)table; + } + + end = ACPI_ADD_PTR(struct acpi_rhct_node_header, rhct, rhct->header.length); + + for (node = ACPI_ADD_PTR(struct acpi_rhct_node_header, rhct, rhct->node_offset); + node < end; + node = ACPI_ADD_PTR(struct acpi_rhct_node_header, node, node->length)) { +if (node->type ==ACPI_RHCT_NODE_TYPE_HART_INFO ) { + hart_info = ACPI_ADD_PTR(struct acpi_rhct_hart_info, node, size_hdr); + hart_info_node_offset =ACPI_ADD_PTR (u32, hart_info, size_hartinfo); +if (acpi_cpu_id != hart_info->uid) +continue ; + +for (int i =0 ; i < hart_info->num_offsets; i++) { + ref_node = ACPI_ADD_PTR(struct acpi_rhct_node_header, + rhct, hart_info_node_offset[i]); +if (ref_node->type ==ACPI_RHCT_NODE_TYPE_ISA_STRING ) { + isa_node = ACPI_ADD_PTR(struct acpi_rhct_isa_string,
drivers/acpi/riscv/rhct.c line 83
Quoted 10 lines
drivers/acpi/riscv/rhct.c new file +10
-0+ ref_node, size_hdr); + *isa = isa_node->isa; +return 0 ; + } + } + } + } + +return -1 ; +}
Sunil V L
maintainerPATCH v4 10/23 RISC-V: smpboot: Create wrapper smp_setup()
In reply to Sunil V Lsmp_setup() currently assumes DT-based platforms. To enable ACPI, first make this a wrapper function and move existing code to a separate DT-specific function.
--- arch/riscv/kernel/smpboot.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/riscv/kernel/smpboot.c +6 -1
@@ -70,7 +70,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus) } } -void __init setup_smp (void ) +static void __init of_parse_and_init_cpus (void ) {struct device_node *dn;unsigned long hart;
@@ -116,6 +116,11 @@ void __init setup_smp(void) } } +void __init setup_smp (void ) +{ +of_parse_and_init_cpus (); +} +static int start_secondary_cpu (int cpu,struct task_struct *tidle) {if (cpu_ops[cpu]->cpu_start)
Signature · 1 line
2.34.1
Re: [PATCH V4 10/23] RISC-V: smpboot: Create wrapper smp_setup()
Quoted 27 lines · On Tue, 04 Apr 2023 11:20:24 PDT (-0700), [email protected] wrote:
smp_setup()currently assumes DT-based platforms. To enable ACPI, first make this a wrapper function and move existing code to a separate DT-specific function.Signed-off-by Sunil V L <[email protected]>Reviewed-by Conor Dooley <[email protected]>Reviewed-by Andrew Jones <[email protected]>--- arch/riscv/kernel/smpboot.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)arch/riscv/kernel/smpboot.c +1
-1@@ -70,7 +70,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus) } } -void __init setup_smp (void ) +static void __init of_parse_and_init_cpus (void ) {struct device_node *dn;unsigned long hart;@@ -116,6 +116,11 @@ void __init setup_smp(void) }
arch/riscv/kernel/smpboot.c void __init setup_smp(void) · line 126
Quoted 10 lines
arch/riscv/kernel/smpboot.c +5
-0} +void __init setup_smp (void ) +{ +of_parse_and_init_cpus (); +} +static int start_secondary_cpu (int cpu,struct task_struct *tidle) {if (cpu_ops[cpu]->cpu_start)
Sunil V L
maintainerPATCH v4 11/23 RISC-V: smpboot: Add ACPI support in smp_setup()
In reply to Sunil V LEnable SMP boot on ACPI based platforms by using the RINTC structures in the MADT table.
--- arch/riscv/include/asm/acpi.h | 2 + arch/riscv/kernel/smpboot.c | 72 ++++++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 1 deletion(-)
arch/riscv/include/asm/acpi.h +2 -0
@@ -63,6 +63,8 @@ struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu);u32 get_acpi_id_for_cpu (int cpu);int acpi_get_riscv_isa (struct acpi_table_header *table,unsigned int cpu,const char **isa); + +static inline int acpi_numa_get_nid (unsigned int cpu) {return NUMA_NO_NODE ; }#else static inline int acpi_get_riscv_isa (struct acpi_table_header *table,unsigned int cpu,const char **isa)
arch/riscv/kernel/smpboot.c +71 -1
90 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH V4 11/23] RISC-V: smpboot: Add ACPI support in smp_setup()
Quoted 11 lines · Sunil V L
Enable SMP boot on ACPI based platforms by using the RINTC structures in the MADT table.
Signed-off-by Sunil V L <[email protected]>Reviewed-by Conor Dooley <[email protected]>--- arch/riscv/include/asm/acpi.h | 2 + arch/riscv/kernel/smpboot.c | 72 ++++++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 1 deletion(-)
Sunil V L
maintainerPATCH v4 12/23 RISC-V: cpufeature: Avoid calling riscv_of_processor_hartid()
In reply to Sunil V Lriscv_fill_hwcap() finds hartid of each cpu but never really uses it. So, remove this unnecessary call.
--- arch/riscv/kernel/cpufeature.c | 5 ----- 1 file changed, 5 deletions(-)
arch/riscv/kernel/cpufeature.c +0 -5
@@ -91,7 +91,6 @@ void __init riscv_fill_hwcap(void)char print_str[NUM_ALPHA_EXTS +1 ];int i, j, rc;unsigned long isa2hwcap[26 ] = {0 }; -unsigned long hartid; isa2hwcap['i' -'a' ] =COMPAT_HWCAP_ISA_I ; isa2hwcap['m' -'a' ] =COMPAT_HWCAP_ISA_M ;
@@ -109,10 +108,6 @@ void __init riscv_fill_hwcap(void)DECLARE_BITMAP (this_isa,RISCV_ISA_EXT_MAX );const char *temp; - rc =riscv_of_processor_hartid (node, &hartid); -if (rc <0 ) -continue ; -if (of_property_read_string (node,"riscv,isa" , &isa)) {pr_warn ("Unable to find \"riscv,isa\" devicetree entry\n" );continue ;
Signature · 1 line
2.34.1
Re: [PATCH V4 12/23] RISC-V: cpufeature: Avoid calling riscv_of_processor_hartid()
Quoted 2 lines · Sunil V L
riscv_fill_hwcap()finds hartid of each cpu but never really uses it. So, remove this unnecessary call.
"Never uses it" or "never really uses it"?
This commit message misses the point though I think - is this here to get the hartid, or is it here to do all the property validation that riscv_of_processor_hartid() does for a cpu node?
This was added all the way back in 4.20 in commit 732e8e4130ff ("RISC-V:
properly determine hardware caps").
As the loop is a for_each_of_cpu_node(), I don't think this change is actually valid - there's no guarantee that the cpu we are iterating over is actually available and the riscv_of_processor_hartid() check is used to skip "bad" cpus AFAICT.
Perhaps I am missing something, I don't think you can do this until you switch the loop to use something that only uses cpus that you know are valid.
Cheers,
Conor.
Quoted 36 lines
Signed-off-by Sunil V L <[email protected]>--- arch/riscv/kernel/cpufeature.c | 5 ----- 1 file changed, 5 deletions(-)arch/riscv/kernel/cpufeature.c +0
-5@@ -91,7 +91,6 @@ void __init riscv_fill_hwcap(void)char print_str[NUM_ALPHA_EXTS +1 ];int i, j, rc;unsigned long isa2hwcap[26 ] = {0 }; -unsigned long hartid; isa2hwcap['i' -'a' ] =COMPAT_HWCAP_ISA_I ; isa2hwcap['m' -'a' ] =COMPAT_HWCAP_ISA_M ;@@ -109,10 +108,6 @@ void __init riscv_fill_hwcap(void)DECLARE_BITMAP (this_isa,RISCV_ISA_EXT_MAX );const char *temp; - rc =riscv_of_processor_hartid (node, &hartid); -if (rc <0 ) -continue ; -if (of_property_read_string (node,"riscv,isa" , &isa)) {pr_warn ("Unable to find \"riscv,isa\" devicetree entry\n" );continue ;Signature · 7 lines
2.34.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Sunil V L
maintainerPATCH v4 13/23 RISC-V: cpufeature: Add ACPI support in riscv_fill_hwcap()
In reply to Sunil V LOn ACPI based systems, the information about the hart like ISA is provided by the RISC-V Hart Capabilities Table (RHCT). Enable filling up hwcap structure based on the information in RHCT.
--- arch/riscv/kernel/cpufeature.c | 39 ++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-)
arch/riscv/kernel/cpufeature.c +35 -4
@@ -6,6 +6,7 @@* Copyright (C) 2017 SiFive */ +#include <linux/acpi.h> #include <linux/bitmap.h> #include <linux/ctype.h> #include <linux/libfdt.h>
@@ -13,6 +14,8 @@#include <linux/memory.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/of_device.h> +#include <asm/acpi.h> #include <asm/alternative.h> #include <asm/cacheflush.h> #include <asm/errata_list.h>
@@ -91,6 +94,9 @@ void __init riscv_fill_hwcap(void)char print_str[NUM_ALPHA_EXTS +1 ];int i, j, rc;unsigned long isa2hwcap[26 ] = {0 }; +struct acpi_table_header *rhct; +acpi_status status; +unsigned int cpu; isa2hwcap['i' -'a' ] =COMPAT_HWCAP_ISA_I ; isa2hwcap['m' -'a' ] =COMPAT_HWCAP_ISA_M ;
@@ -103,14 +109,36 @@ void __init riscv_fill_hwcap(void)bitmap_zero (riscv_isa,RISCV_ISA_EXT_MAX ); -for_each_of_cpu_node (node) { +if (!acpi_disabled) { + status =acpi_get_table (ACPI_SIG_RHCT ,0 , &rhct); +if (ACPI_FAILURE (status)) +return ; + } + +for_each_possible_cpu (cpu) {unsigned long this_hwcap =0 ;DECLARE_BITMAP (this_isa,RISCV_ISA_EXT_MAX );const char *temp; -if (of_property_read_string (node,"riscv,isa" , &isa)) { -pr_warn ("Unable to find \"riscv,isa\" devicetree entry\n" ); -continue ; +if (acpi_disabled) { + node =of_cpu_device_node_get (cpu); +if (node) { + rc =of_property_read_string (node,"riscv,isa" , &isa); +of_node_put (node); +if (rc) { +pr_warn ("Unable to find \"riscv,isa\" devicetree entry\n" ); +continue ; + } + }else { +pr_warn ("Unable to find cpu node\n" ); +continue ; + } + }else { + rc =acpi_get_riscv_isa (rhct, cpu, &isa); +if (rc <0 ) { +pr_warn ("Unable to get ISA for the hart - %d\n" , cpu); +continue ; + } } temp = isa;
@@ -243,6 +271,9 @@ void __init riscv_fill_hwcap(void)bitmap_and (riscv_isa, riscv_isa, this_isa,RISCV_ISA_EXT_MAX ); } +if (!acpi_disabled && rhct) +acpi_put_table ((struct acpi_table_header *)rhct); +/* We don't support systems with F but without D, so mask those out * here. */ if ((elf_hwcap &COMPAT_HWCAP_ISA_F ) && !(elf_hwcap &COMPAT_HWCAP_ISA_D )) {
Signature · 1 line
2.34.1
Re: [PATCH V4 13/23] RISC-V: cpufeature: Add ACPI support in riscv_fill_hwcap()
Quoted 55 lines · Sunil V L
On ACPI based systems, the information about the hart like ISA is provided by the RISC-V Hart Capabilities Table (RHCT). Enable filling up hwcap structure based on the information in RHCT.
Signed-off-by Sunil V L <[email protected]>Reviewed-by Andrew Jones <[email protected]>--- arch/riscv/kernel/cpufeature.c | 39 ++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-)arch/riscv/kernel/cpufeature.c +13
-1@@ -6,6 +6,7 @@* Copyright (C) 2017 SiFive */ +#include <linux/acpi.h> #include <linux/bitmap.h> #include <linux/ctype.h> #include <linux/libfdt.h> @@ -13,6 +14,8 @@#include <linux/memory.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/of_device.h> +#include <asm/acpi.h> #include <asm/alternative.h> #include <asm/cacheflush.h> #include <asm/errata_list.h> @@ -91,6 +94,9 @@ void __init riscv_fill_hwcap(void)char print_str[NUM_ALPHA_EXTS +1 ];int i, j, rc;unsigned long isa2hwcap[26 ] = {0 }; +struct acpi_table_header *rhct; +acpi_status status; +unsigned int cpu; isa2hwcap['i' -'a' ] =COMPAT_HWCAP_ISA_I ; isa2hwcap['m' -'a' ] =COMPAT_HWCAP_ISA_M ;@@ -103,14 +109,36 @@ void __init riscv_fill_hwcap(void)bitmap_zero (riscv_isa,RISCV_ISA_EXT_MAX ); -for_each_of_cpu_node (node) { +if (!acpi_disabled) { + status =acpi_get_table (ACPI_SIG_RHCT ,0 , &rhct); +if (ACPI_FAILURE (status)) +return ; + } + +for_each_possible_cpu (cpu) {unsigned long this_hwcap =0 ;
arch/riscv/kernel/cpufeature.c void __init riscv_fill_hwcap(void) · line 126
Quoted 10 lines
arch/riscv/kernel/cpufeature.c +4
-3DECLARE_BITMAP (this_isa,RISCV_ISA_EXT_MAX );const char *temp; -if (of_property_read_string (node,"riscv,isa" , &isa)) { -pr_warn ("Unable to find \"riscv,isa\" devicetree entry\n" ); -continue ; +if (acpi_disabled) { + node =of_cpu_device_node_get (cpu); +if (node) { + rc =of_property_read_string (node,"riscv,isa" , &isa);
Hmm, after digging in the previous patch, I think this is actually not possible to fail? We already validated it when setting up the mask of possible cpus, but I think leaving the error handling here makes things a lot more obvious.
I'd swear I gave you a (conditional) R-b on v3 though, no?
Cheers,
Conor.
Quoted 36 lines
arch/riscv/kernel/cpufeature.c +18
-0+of_node_put (node); +if (rc) { +pr_warn ("Unable to find \"riscv,isa\" devicetree entry\n" ); +continue ; + } + }else { +pr_warn ("Unable to find cpu node\n" ); +continue ; + } + }else { + rc =acpi_get_riscv_isa (rhct, cpu, &isa); +if (rc <0 ) { +pr_warn ("Unable to get ISA for the hart - %d\n" , cpu); +continue ; + } } temp = isa;@@ -243,6 +271,9 @@ void __init riscv_fill_hwcap(void)bitmap_and (riscv_isa, riscv_isa, this_isa,RISCV_ISA_EXT_MAX ); } +if (!acpi_disabled && rhct) +acpi_put_table ((struct acpi_table_header *)rhct); +/* We don't support systems with F but without D, so mask those out * here. */ if ((elf_hwcap &COMPAT_HWCAP_ISA_F ) && !(elf_hwcap &COMPAT_HWCAP_ISA_D )) {Signature · 7 lines
2.34.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Sunil V L
maintainerRe: [PATCH V4 13/23] RISC-V: cpufeature: Add ACPI support in riscv_fill_hwcap()
Quoted 59 lines · Conor Dooley
Quoted 58 lines · Sunil V L
On ACPI based systems, the information about the hart like ISA is provided by the RISC-V Hart Capabilities Table (RHCT). Enable filling up hwcap structure based on the information in RHCT.
Signed-off-by Sunil V L <[email protected]>Reviewed-by Andrew Jones <[email protected]>--- arch/riscv/kernel/cpufeature.c | 39 ++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-)arch/riscv/kernel/cpufeature.c +13
-1@@ -6,6 +6,7 @@* Copyright (C) 2017 SiFive */ +#include <linux/acpi.h> #include <linux/bitmap.h> #include <linux/ctype.h> #include <linux/libfdt.h> @@ -13,6 +14,8 @@#include <linux/memory.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/of_device.h> +#include <asm/acpi.h> #include <asm/alternative.h> #include <asm/cacheflush.h> #include <asm/errata_list.h> @@ -91,6 +94,9 @@ void __init riscv_fill_hwcap(void)char print_str[NUM_ALPHA_EXTS +1 ];int i, j, rc;unsigned long isa2hwcap[26 ] = {0 }; +struct acpi_table_header *rhct; +acpi_status status; +unsigned int cpu; isa2hwcap['i' -'a' ] =COMPAT_HWCAP_ISA_I ; isa2hwcap['m' -'a' ] =COMPAT_HWCAP_ISA_M ;@@ -103,14 +109,36 @@ void __init riscv_fill_hwcap(void)bitmap_zero (riscv_isa,RISCV_ISA_EXT_MAX ); -for_each_of_cpu_node (node) { +if (!acpi_disabled) { + status =acpi_get_table (ACPI_SIG_RHCT ,0 , &rhct); +if (ACPI_FAILURE (status)) +return ; + } + +for_each_possible_cpu (cpu) {unsigned long this_hwcap =0 ;DECLARE_BITMAP (this_isa,RISCV_ISA_EXT_MAX );const char *temp;
Quoted 13 lines
arch/riscv/kernel/cpufeature.c void __init riscv_fill_hwcap(void) · line 126
Quoted 7 lines
arch/riscv/kernel/cpufeature.c +4
-3-if (of_property_read_string (node,"riscv,isa" , &isa)) { -pr_warn ("Unable to find \"riscv,isa\" devicetree entry\n" ); -continue ; +if (acpi_disabled) { + node =of_cpu_device_node_get (cpu); +if (node) { + rc =of_property_read_string (node,"riscv,isa" , &isa);Hmm, after digging in the previous patch, I think this is actually not possible to fail? We already validated it when setting up the mask of possible cpus, but I think leaving the error handling here makes things a lot more obvious.
Yeah, do you prefer to merge these patches again since only in this patch, we change the loop to for_each_possible_cpu() from for_each_of_cpu_node() which actually makes riscv_of_processor_hartid() not useful?
Quoted 3 lines
I'd swear I gave you a (conditional) R-b on v3 though, no?
Reviewed-by Conor Dooley <[email protected]>
Thanks,
Sunil
Re: [PATCH V4 13/23] RISC-V: cpufeature: Add ACPI support in riscv_fill_hwcap()
Quoted 73 lines · Sunil V L
Quoted 59 lines · Conor Dooley
Quoted 58 lines · Sunil V L
On ACPI based systems, the information about the hart like ISA is provided by the RISC-V Hart Capabilities Table (RHCT). Enable filling up hwcap structure based on the information in RHCT.
Signed-off-by Sunil V L <[email protected]>Reviewed-by Andrew Jones <[email protected]>--- arch/riscv/kernel/cpufeature.c | 39 ++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-)arch/riscv/kernel/cpufeature.c +13
-1@@ -6,6 +6,7 @@* Copyright (C) 2017 SiFive */ +#include <linux/acpi.h> #include <linux/bitmap.h> #include <linux/ctype.h> #include <linux/libfdt.h> @@ -13,6 +14,8 @@#include <linux/memory.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/of_device.h> +#include <asm/acpi.h> #include <asm/alternative.h> #include <asm/cacheflush.h> #include <asm/errata_list.h> @@ -91,6 +94,9 @@ void __init riscv_fill_hwcap(void)char print_str[NUM_ALPHA_EXTS +1 ];int i, j, rc;unsigned long isa2hwcap[26 ] = {0 }; +struct acpi_table_header *rhct; +acpi_status status; +unsigned int cpu; isa2hwcap['i' -'a' ] =COMPAT_HWCAP_ISA_I ; isa2hwcap['m' -'a' ] =COMPAT_HWCAP_ISA_M ;@@ -103,14 +109,36 @@ void __init riscv_fill_hwcap(void)bitmap_zero (riscv_isa,RISCV_ISA_EXT_MAX ); -for_each_of_cpu_node (node) { +if (!acpi_disabled) { + status =acpi_get_table (ACPI_SIG_RHCT ,0 , &rhct); +if (ACPI_FAILURE (status)) +return ; + } + +for_each_possible_cpu (cpu) {unsigned long this_hwcap =0 ;DECLARE_BITMAP (this_isa,RISCV_ISA_EXT_MAX );const char *temp;Quoted 13 lines
arch/riscv/kernel/cpufeature.c void __init riscv_fill_hwcap(void) · line 126
Quoted 7 lines
arch/riscv/kernel/cpufeature.c +4
-3-if (of_property_read_string (node,"riscv,isa" , &isa)) { -pr_warn ("Unable to find \"riscv,isa\" devicetree entry\n" ); -continue ; +if (acpi_disabled) { + node =of_cpu_device_node_get (cpu); +if (node) { + rc =of_property_read_string (node,"riscv,isa" , &isa);Hmm, after digging in the previous patch, I think this is actually not possible to fail? We already validated it when setting up the mask of possible cpus, but I think leaving the error handling here makes things a lot more obvious.
Quoted 4 lines
Yeah, do you prefer to merge these patches again since only in this patch, we change the loop to
for_each_possible_cpu()fromfor_each_of_cpu_node()which actually makesriscv_of_processor_hartid()not useful?
Yah, all 3 of us mistakenly thought that that was an unrelated cleanup on the last revision, but clearly it is not.
Squash it back IMO, sorry for my part in the extra work generated.
Cheers,
Conor.
Quoted 3 lines
Quoted 3 lines
I'd swear I gave you a (conditional) R-b on v3 though, no?
Reviewed-by Conor Dooley <[email protected]>
Re: [PATCH V4 13/23] RISC-V: cpufeature: Add ACPI support in riscv_fill_hwcap()
Quoted 3 lines · Conor Dooley
Quoted 2 lines · Sunil V L
Quoted 1 line · Conor Dooley
On Tue, Apr 04, 2023 at 11:50:27PM +0530, Sunil V L wrote:
...
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
arch/riscv/kernel/cpufeature.c void __init riscv_fill_hwcap(void) · line 126
Quoted 7 lines
arch/riscv/kernel/cpufeature.c +4
-3-if (of_property_read_string (node,"riscv,isa" , &isa)) { -pr_warn ("Unable to find \"riscv,isa\" devicetree entry\n" ); -continue ; +if (acpi_disabled) { + node =of_cpu_device_node_get (cpu); +if (node) { + rc =of_property_read_string (node,"riscv,isa" , &isa);Hmm, after digging in the previous patch, I think this is actually not possible to fail? We already validated it when setting up the mask of possible cpus, but I think leaving the error handling here makes things a lot more obvious.
Quoted 8 lines
Quoted 4 lines
Yeah, do you prefer to merge these patches again since only in this patch, we change the loop to
for_each_possible_cpu()fromfor_each_of_cpu_node()which actually makesriscv_of_processor_hartid()not useful?Yah, all 3 of us mistakenly thought that that was an unrelated cleanup on the last revision, but clearly it is not.
Squash it back IMO, sorry for my part in the extra work generated.
Yup, please squash back in. Sorry about that, Sunil!
drew
Re: [PATCH V4 13/23] RISC-V: cpufeature: Add ACPI support in riscv_fill_hwcap()
In reply to Sunil V LHey Sunil,
Quoted 21 lines · Sunil V L
arch/riscv/kernel/cpufeature.c +9
-4@@ -103,14 +109,36 @@ void __init riscv_fill_hwcap(void)bitmap_zero (riscv_isa,RISCV_ISA_EXT_MAX ); -for_each_of_cpu_node (node) { +if (!acpi_disabled) { + status =acpi_get_table (ACPI_SIG_RHCT ,0 , &rhct); +if (ACPI_FAILURE (status)) +return ; + } + +for_each_possible_cpu (cpu) {unsigned long this_hwcap =0 ;DECLARE_BITMAP (this_isa,RISCV_ISA_EXT_MAX );const char *temp; -if (of_property_read_string (node,"riscv,isa" , &isa)) { -pr_warn ("Unable to find \"riscv,isa\" devicetree entry\n" ); -continue ; +if (acpi_disabled) { + node =of_cpu_device_node_get (cpu);
arch/riscv/kernel/cpufeature.c void __init riscv_fill_hwcap(void) · line 134
Quoted 10 lines
arch/riscv/kernel/cpufeature.c +10
-0+if (node) { + rc =of_property_read_string (node,"riscv,isa" , &isa); +of_node_put (node); +if (rc) { +pr_warn ("Unable to find \"riscv,isa\" devicetree entry\n" ); +continue ; + } + }else { +pr_warn ("Unable to find cpu node\n" ); +continue ;
I was poking at this the last few days and went back to look at the ACPI code again. Is there a reason we don't do early-return here? IOW:
node = of_cpu_device_node_get(cpu);
if (!node) {
pr_warn()
continue;
}
rc = of_property_read_string(node, "riscv,isa", &isa);
of_node_put(node);
if (rc) {
pr_warn();
continue;
}Cheers,
Conor.
Quoted 11 lines
arch/riscv/kernel/cpufeature.c +7
-0+ } + }else { + rc =acpi_get_riscv_isa (rhct, cpu, &isa); +if (rc <0 ) { +pr_warn ("Unable to get ISA for the hart - %d\n" , cpu); +continue ; + } } temp = isa;@@ -243,6 +271,9 @@ void __init riscv_fill_hwcap(void)
Sunil V L
maintainerRe: [PATCH V4 13/23] RISC-V: cpufeature: Add ACPI support in riscv_fill_hwcap()
Quoted 39 lines · Conor Dooley
Hey Sunil,
Quoted 21 lines · Sunil V L
arch/riscv/kernel/cpufeature.c +9
-4@@ -103,14 +109,36 @@ void __init riscv_fill_hwcap(void)bitmap_zero (riscv_isa,RISCV_ISA_EXT_MAX ); -for_each_of_cpu_node (node) { +if (!acpi_disabled) { + status =acpi_get_table (ACPI_SIG_RHCT ,0 , &rhct); +if (ACPI_FAILURE (status)) +return ; + } + +for_each_possible_cpu (cpu) {unsigned long this_hwcap =0 ;DECLARE_BITMAP (this_isa,RISCV_ISA_EXT_MAX );const char *temp; -if (of_property_read_string (node,"riscv,isa" , &isa)) { -pr_warn ("Unable to find \"riscv,isa\" devicetree entry\n" ); -continue ; +if (acpi_disabled) { + node =of_cpu_device_node_get (cpu);arch/riscv/kernel/cpufeature.c void __init riscv_fill_hwcap(void) · line 134
Quoted 10 lines
arch/riscv/kernel/cpufeature.c +10
-0+if (node) { + rc =of_property_read_string (node,"riscv,isa" , &isa); +of_node_put (node); +if (rc) { +pr_warn ("Unable to find \"riscv,isa\" devicetree entry\n" ); +continue ; + } + }else { +pr_warn ("Unable to find cpu node\n" ); +continue ;I was poking at this the last few days and went back to look at the ACPI code again. Is there a reason we don't do early-return here? IOW:
Quoted 13 lines
node = of_cpu_device_node_get(cpu);
if (!node) {
pr_warn()
continue;
}
rc = of_property_read_string(node, "riscv,isa", &isa);
of_node_put(node);
if (rc) {
pr_warn();
continue;
}This looks better. Will update when I send the next revision of the series. Thank you!, Conor.
Sunil V L
maintainerPATCH v4 14/23 RISC-V: cpu: Enable cpuinfo for ACPI systems
In reply to Sunil V LOn ACPI based platforms, few details like ISA need to be read from the ACPI table. Enable cpuinfo on ACPI based systems.
ACPI has nothing similar to DT compatible property for each CPU. SBI calls must be used to get vendor/arch/imp ID for any errata.
--- arch/riscv/kernel/cpu.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-)
arch/riscv/kernel/cpu.c +22 -8
@@ -3,10 +3,12 @@* Copyright (C) 2012 Regents of the University of California */ +#include <linux/acpi.h> #include <linux/cpu.h> #include <linux/init.h> #include <linux/seq_file.h> #include <linux/of.h> +#include <asm/acpi.h> #include <asm/csr.h> #include <asm/hwcap.h> #include <asm/sbi.h>
@@ -283,23 +285,35 @@ static void c_stop(struct seq_file *m, void *v)static int c_show (struct seq_file *m,void *v) {unsigned long cpu_id = (unsigned long )v -1 ; -struct device_node *node =of_get_cpu_node (cpu_id,NULL );struct riscv_cpuinfo *ci =per_cpu_ptr (&riscv_cpuinfo, cpu_id); +struct device_node *node;const char *compat, *isa;seq_printf (m,"processor\t: %lu\n" , cpu_id);seq_printf (m,"hart\t\t: %lu\n" ,cpuid_to_hartid_map (cpu_id)); -if (!of_property_read_string (node,"riscv,isa" , &isa)) -print_isa (m, isa); -print_mmu (m); -if (!of_property_read_string (node,"compatible" , &compat) - &&strcmp (compat,"riscv" )) -seq_printf (m,"uarch\t\t: %s\n" , compat); + +if (acpi_disabled) { + node =of_get_cpu_node (cpu_id,NULL ); +if (!of_property_read_string (node,"riscv,isa" , &isa)) +print_isa (m, isa); + +print_mmu (m); +if (!of_property_read_string (node,"compatible" , &compat) && +strcmp (compat,"riscv" )) +seq_printf (m,"uarch\t\t: %s\n" , compat); + +of_node_put (node); + }else { +if (!acpi_get_riscv_isa (NULL , cpu_id, &isa)) +print_isa (m, isa); + +print_mmu (m); + } +seq_printf (m,"mvendorid\t: 0x%lx\n" , ci->mvendorid);seq_printf (m,"marchid\t\t: 0x%lx\n" , ci->marchid);seq_printf (m,"mimpid\t\t: 0x%lx\n" , ci->mimpid);seq_puts (m,"\n" ); -of_node_put (node);return 0 ; }
Signature · 1 line
2.34.1
Re: [PATCH V4 14/23] RISC-V: cpu: Enable cpuinfo for ACPI systems
Quoted 6 lines · Sunil V L
On ACPI based platforms, few details like ISA need to be read from the ACPI table. Enable cpuinfo on ACPI based systems.
ACPI has nothing similar to DT compatible property for each CPU.
SBI calls must be used to get vendor/arch/imp ID for any errata.
ecalls are used on DT systems for this too FYI, vendorid/archid/impid are not contained in the DT.
Otherwise,
Should probably have given that conditionally last time, sorry about that.
Thanks,
Conor.
Quoted 77 lines
Signed-off-by Sunil V L <[email protected]>Reviewed-by Andrew Jones <[email protected]>--- arch/riscv/kernel/cpu.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-)arch/riscv/kernel/cpu.c +22
-8@@ -3,10 +3,12 @@* Copyright (C) 2012 Regents of the University of California */ +#include <linux/acpi.h> #include <linux/cpu.h> #include <linux/init.h> #include <linux/seq_file.h> #include <linux/of.h> +#include <asm/acpi.h> #include <asm/csr.h> #include <asm/hwcap.h> #include <asm/sbi.h> @@ -283,23 +285,35 @@ static void c_stop(struct seq_file *m, void *v)static int c_show (struct seq_file *m,void *v) {unsigned long cpu_id = (unsigned long )v -1 ; -struct device_node *node =of_get_cpu_node (cpu_id,NULL );struct riscv_cpuinfo *ci =per_cpu_ptr (&riscv_cpuinfo, cpu_id); +struct device_node *node;const char *compat, *isa;seq_printf (m,"processor\t: %lu\n" , cpu_id);seq_printf (m,"hart\t\t: %lu\n" ,cpuid_to_hartid_map (cpu_id)); -if (!of_property_read_string (node,"riscv,isa" , &isa)) -print_isa (m, isa); -print_mmu (m); -if (!of_property_read_string (node,"compatible" , &compat) - &&strcmp (compat,"riscv" )) -seq_printf (m,"uarch\t\t: %s\n" , compat); + +if (acpi_disabled) { + node =of_get_cpu_node (cpu_id,NULL ); +if (!of_property_read_string (node,"riscv,isa" , &isa)) +print_isa (m, isa); + +print_mmu (m); +if (!of_property_read_string (node,"compatible" , &compat) && +strcmp (compat,"riscv" )) +seq_printf (m,"uarch\t\t: %s\n" , compat); + +of_node_put (node); + }else { +if (!acpi_get_riscv_isa (NULL , cpu_id, &isa)) +print_isa (m, isa); + +print_mmu (m); + } +seq_printf (m,"mvendorid\t: 0x%lx\n" , ci->mvendorid);seq_printf (m,"marchid\t\t: 0x%lx\n" , ci->marchid);seq_printf (m,"mimpid\t\t: 0x%lx\n" , ci->mimpid);seq_puts (m,"\n" ); -of_node_put (node);return 0 ; }Signature · 7 lines
2.34.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Sunil V L
maintainerPATCH v4 15/23 irqchip/riscv-intc: Add ACPI support
In reply to Sunil V LAdd support for initializing the RISC-V INTC driver on ACPI platforms.
--- drivers/irqchip/irq-riscv-intc.c | 74 ++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 13 deletions(-)
drivers/irqchip/irq-riscv-intc.c +61 -13
@@ -6,6 +6,7 @@*/ #define pr_fmt (fmt) "riscv-intc: " fmt +#include <linux/acpi.h> #include <linux/atomic.h> #include <linux/bits.h> #include <linux/cpu.h>
@@ -112,6 +113,30 @@ static struct fwnode_handle *riscv_intc_hwnode(void)return intc_domain->fwnode; } +static int __init riscv_intc_init_common (struct fwnode_handle *fn) +{ +int rc; + + intc_domain =irq_domain_create_linear (fn,BITS_PER_LONG , + &riscv_intc_domain_ops,NULL ); +if (!intc_domain) { +pr_err ("unable to add IRQ domain\n" ); +return -ENXIO ; + } + + rc =set_handle_irq (&riscv_intc_irq); +if (rc) { +pr_err ("failed to set irq handler\n" ); +return rc; + } + +riscv_set_intc_hwnode_fn (riscv_intc_hwnode); + +pr_info ("%d local interrupts mapped\n" ,BITS_PER_LONG ); + +return 0 ; +} +static int __init riscv_intc_init (struct device_node *node,struct device_node *parent) {
@@ -133,24 +158,47 @@ static int __init riscv_intc_init(struct device_node *node,if (riscv_hartid_to_cpuid (hartid) !=smp_processor_id ())return 0 ; - intc_domain =irq_domain_add_linear (node,BITS_PER_LONG , - &riscv_intc_domain_ops,NULL ); -if (!intc_domain) { -pr_err ("unable to add IRQ domain\n" ); -return -ENXIO ; - } - - rc =set_handle_irq (&riscv_intc_irq); + rc =riscv_intc_init_common (of_node_to_fwnode (node));if (rc) { -pr_err ("failed to set irq handler\n" ); +pr_err ("failed to initialize INTC\n" );return rc; } -riscv_set_intc_hwnode_fn (riscv_intc_hwnode); - -pr_info ("%d local interrupts mapped\n" ,BITS_PER_LONG ); -return 0 ; }IRQCHIP_DECLARE (riscv,"riscv,cpu-intc" , riscv_intc_init); + +#ifdef CONFIG_ACPI + +static int __init riscv_intc_acpi_init (union acpi_subtable_headers *header, +const unsigned long end) +{ +int rc; +struct fwnode_handle *fn; +struct acpi_madt_rintc *rintc; + + rintc = (struct acpi_madt_rintc *)header; + +/* +* The ACPI MADT will have one INTC for each CPU (or HART) +* so riscv_intc_acpi_init() function will be called once +* for each INTC. We only do INTC initialization +* for the INTC belonging to the boot CPU (or boot HART). +*/ +if (riscv_hartid_to_cpuid (rintc->hart_id) !=smp_processor_id ()) +return 0 ; + + fn =irq_domain_alloc_named_fwnode ("RISCV-INTC" ); +if (!fn) { +pr_err ("unable to allocate INTC FW node\n" ); +return -ENOMEM ; + } + + rc =riscv_intc_init_common (fn); +return rc; +} + +IRQCHIP_ACPI_DECLARE (riscv_intc,ACPI_MADT_TYPE_RINTC ,NULL , +ACPI_MADT_RINTC_VERSION_V1 , riscv_intc_acpi_init); +#endif
Signature · 1 line
2.34.1
Re: [PATCH V4 15/23] irqchip/riscv-intc: Add ACPI support
Quoted 60 lines · Sunil V L
Add support for initializing the RISC-V INTC driver on ACPI platforms.
Signed-off-by Sunil V L <[email protected]>Reviewed-by Andrew Jones <[email protected]>Reviewed-by Conor Dooley <[email protected]>--- drivers/irqchip/irq-riscv-intc.c | 74 ++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 13 deletions(-)drivers/irqchip/irq-riscv-intc.c +25
-2@@ -6,6 +6,7 @@*/ #define pr_fmt (fmt) "riscv-intc: " fmt +#include <linux/acpi.h> #include <linux/atomic.h> #include <linux/bits.h> #include <linux/cpu.h> @@ -112,6 +113,30 @@ static struct fwnode_handle *riscv_intc_hwnode(void)return intc_domain->fwnode; } +static int __init riscv_intc_init_common (struct fwnode_handle *fn) +{ +int rc; + + intc_domain =irq_domain_create_linear (fn,BITS_PER_LONG , + &riscv_intc_domain_ops,NULL ); +if (!intc_domain) { +pr_err ("unable to add IRQ domain\n" ); +return -ENXIO ; + } + + rc =set_handle_irq (&riscv_intc_irq); +if (rc) { +pr_err ("failed to set irq handler\n" ); +return rc; + } + +riscv_set_intc_hwnode_fn (riscv_intc_hwnode); + +pr_info ("%d local interrupts mapped\n" ,BITS_PER_LONG ); + +return 0 ; +} +static int __init riscv_intc_init (struct device_node *node,struct device_node *parent) {@@ -133,24 +158,47 @@ static int __init riscv_intc_init(struct device_node *node,if (riscv_hartid_to_cpuid (hartid) !=smp_processor_id ())return 0 ; - intc_domain =irq_domain_add_linear (node,BITS_PER_LONG , - &riscv_intc_domain_ops,NULL );
drivers/irqchip/irq-riscv-intc.c static int __init riscv_intc_init(struct device_node *node, · line 163
Quoted 10 lines
drivers/irqchip/irq-riscv-intc.c +2
-7-if (!intc_domain) { -pr_err ("unable to add IRQ domain\n" ); -return -ENXIO ; - } - - rc =set_handle_irq (&riscv_intc_irq); + rc =riscv_intc_init_common (of_node_to_fwnode (node));if (rc) { -pr_err ("failed to set irq handler\n" ); +pr_err ("failed to initialize INTC\n" );
The ACPI version doesn't output this error when riscv_intc_init_common() fails. It should probably be consistent. Either removing it here, if the errors output within riscv_intc_init_common() are sufficient, or adding it to the ACPI version.
Quoted 30 lines
drivers/irqchip/irq-riscv-intc.c +19
-4return rc; } -riscv_set_intc_hwnode_fn (riscv_intc_hwnode); - -pr_info ("%d local interrupts mapped\n" ,BITS_PER_LONG ); -return 0 ; }IRQCHIP_DECLARE (riscv,"riscv,cpu-intc" , riscv_intc_init); + +#ifdef CONFIG_ACPI + +static int __init riscv_intc_acpi_init (union acpi_subtable_headers *header, +const unsigned long end) +{ +int rc; +struct fwnode_handle *fn; +struct acpi_madt_rintc *rintc; + + rintc = (struct acpi_madt_rintc *)header; + +/* +* The ACPI MADT will have one INTC for each CPU (or HART) +* so riscv_intc_acpi_init() function will be called once +* for each INTC. We only do INTC initialization +* for the INTC belonging to the boot CPU (or boot HART). +*/ +if (riscv_hartid_to_cpuid (rintc->hart_id) !=smp_processor_id ())
drivers/irqchip/irq-riscv-intc.c static int __init riscv_intc_init(struct device_node *node, · line 199
Quoted 10 lines
drivers/irqchip/irq-riscv-intc.c +10
-0+return 0 ; + + fn =irq_domain_alloc_named_fwnode ("RISCV-INTC" ); +if (!fn) { +pr_err ("unable to allocate INTC FW node\n" ); +return -ENOMEM ; + } + + rc =riscv_intc_init_common (fn); +return rc;
nit: If we don't add the error message here, then rc can be removed and we can just do
return riscv_intc_init_common(fn);
And, if we remove the error above, then we reduce the return there too.
Quoted 8 lines
drivers/irqchip/irq-riscv-intc.c +5
-0+} + +IRQCHIP_ACPI_DECLARE (riscv_intc,ACPI_MADT_TYPE_RINTC ,NULL , +ACPI_MADT_RINTC_VERSION_V1 , riscv_intc_acpi_init); +#endif Signature · 1 line
2.34.1
Thanks,
drew
Sunil V L
maintainerRe: [PATCH V4 15/23] irqchip/riscv-intc: Add ACPI support
Quoted 121 lines · Andrew Jones
Quoted 60 lines · Sunil V L
Add support for initializing the RISC-V INTC driver on ACPI platforms.
Signed-off-by Sunil V L <[email protected]>Reviewed-by Andrew Jones <[email protected]>Reviewed-by Conor Dooley <[email protected]>--- drivers/irqchip/irq-riscv-intc.c | 74 ++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 13 deletions(-)drivers/irqchip/irq-riscv-intc.c +25
-2@@ -6,6 +6,7 @@*/ #define pr_fmt (fmt) "riscv-intc: " fmt +#include <linux/acpi.h> #include <linux/atomic.h> #include <linux/bits.h> #include <linux/cpu.h> @@ -112,6 +113,30 @@ static struct fwnode_handle *riscv_intc_hwnode(void)return intc_domain->fwnode; } +static int __init riscv_intc_init_common (struct fwnode_handle *fn) +{ +int rc; + + intc_domain =irq_domain_create_linear (fn,BITS_PER_LONG , + &riscv_intc_domain_ops,NULL ); +if (!intc_domain) { +pr_err ("unable to add IRQ domain\n" ); +return -ENXIO ; + } + + rc =set_handle_irq (&riscv_intc_irq); +if (rc) { +pr_err ("failed to set irq handler\n" ); +return rc; + } + +riscv_set_intc_hwnode_fn (riscv_intc_hwnode); + +pr_info ("%d local interrupts mapped\n" ,BITS_PER_LONG ); + +return 0 ; +} +static int __init riscv_intc_init (struct device_node *node,struct device_node *parent) {@@ -133,24 +158,47 @@ static int __init riscv_intc_init(struct device_node *node,if (riscv_hartid_to_cpuid (hartid) !=smp_processor_id ())return 0 ; - intc_domain =irq_domain_add_linear (node,BITS_PER_LONG , - &riscv_intc_domain_ops,NULL );drivers/irqchip/irq-riscv-intc.c static int __init riscv_intc_init(struct device_node *node, · line 163
Quoted 10 lines
drivers/irqchip/irq-riscv-intc.c +2
-7-if (!intc_domain) { -pr_err ("unable to add IRQ domain\n" ); -return -ENXIO ; - } - - rc =set_handle_irq (&riscv_intc_irq); + rc =riscv_intc_init_common (of_node_to_fwnode (node));if (rc) { -pr_err ("failed to set irq handler\n" ); +pr_err ("failed to initialize INTC\n" );The ACPI version doesn't output this error when
riscv_intc_init_common()fails. It should probably be consistent. Either removing it here, if the errors output withinriscv_intc_init_common()are sufficient, or adding it to the ACPI version.Quoted 30 lines
drivers/irqchip/irq-riscv-intc.c +19
-4return rc; } -riscv_set_intc_hwnode_fn (riscv_intc_hwnode); - -pr_info ("%d local interrupts mapped\n" ,BITS_PER_LONG ); -return 0 ; }IRQCHIP_DECLARE (riscv,"riscv,cpu-intc" , riscv_intc_init); + +#ifdef CONFIG_ACPI + +static int __init riscv_intc_acpi_init (union acpi_subtable_headers *header, +const unsigned long end) +{ +int rc; +struct fwnode_handle *fn; +struct acpi_madt_rintc *rintc; + + rintc = (struct acpi_madt_rintc *)header; + +/* +* The ACPI MADT will have one INTC for each CPU (or HART) +* so riscv_intc_acpi_init() function will be called once +* for each INTC. We only do INTC initialization +* for the INTC belonging to the boot CPU (or boot HART). +*/ +if (riscv_hartid_to_cpuid (rintc->hart_id) !=smp_processor_id ())drivers/irqchip/irq-riscv-intc.c static int __init riscv_intc_init(struct device_node *node, · line 199
Quoted 10 lines
drivers/irqchip/irq-riscv-intc.c +10
-0+return 0 ; + + fn =irq_domain_alloc_named_fwnode ("RISCV-INTC" ); +if (!fn) { +pr_err ("unable to allocate INTC FW node\n" ); +return -ENOMEM ; + } + + rc =riscv_intc_init_common (fn); +return rc;nit: If we don't add the error message here, then rc can be removed and we can just do
Quoted 4 lines
return riscv_intc_init_common(fn);And, if we remove the error above, then we reduce the return there too.
Make sense. Thanks!. Will update in next revision.
Thanks,
Sunil
Sunil V L
maintainerPATCH v4 16/23 clocksource/timer-riscv: Refactor riscv_timer_init_dt()
In reply to Sunil V LRefactor the timer init function such that few things can be shared by both DT and ACPI based platforms.
--- drivers/clocksource/timer-riscv.c | 81 +++++++++++++++---------------- 1 file changed, 40 insertions(+), 41 deletions(-)
drivers/clocksource/timer-riscv.c +40 -41
@@ -124,61 +124,28 @@ static irqreturn_t riscv_timer_interrupt(int irq, void *dev_id)return IRQ_HANDLED ; } -static int __init riscv_timer_init_dt (struct device_node *n) +static int __init riscv_timer_init_common (void ) { -int cpuid, error; -unsigned long hartid; -struct device_node *child; +int error;struct irq_domain *domain; +struct fwnode_handle *intc_fwnode =riscv_get_intc_hwnode (); - error =riscv_of_processor_hartid (n, &hartid); -if (error <0 ) { -pr_warn ("Not valid hartid for node [%pOF] error = [%lu]\n" , - n, hartid); -return error; - } - - cpuid =riscv_hartid_to_cpuid (hartid); -if (cpuid <0 ) { -pr_warn ("Invalid cpuid for hartid [%lu]\n" , hartid); -return cpuid; - } - -if (cpuid !=smp_processor_id ()) -return 0 ; - - child =of_find_compatible_node (NULL ,NULL ,"riscv,timer" ); -if (child) { - riscv_timer_cannot_wake_cpu =of_property_read_bool (child, -"riscv,timer-cannot-wake-cpu" ); -of_node_put (child); - } - - domain =NULL ; - child =of_get_compatible_child (n,"riscv,cpu-intc" ); -if (!child) { -pr_err ("Failed to find INTC node [%pOF]\n" , n); -return -ENODEV ; - } - domain =irq_find_host (child); -of_node_put (child); + domain =irq_find_matching_fwnode (intc_fwnode,DOMAIN_BUS_ANY );if (!domain) { -pr_err ("Failed to find IRQ domain for node [%pOF]\n" , n); +pr_err ("Failed to find irq_domain for INTC node [%pfwP]\n" , + intc_fwnode);return -ENODEV ; } riscv_clock_event_irq =irq_create_mapping (domain,RV_IRQ_TIMER );if (!riscv_clock_event_irq) { -pr_err ("Failed to map timer interrupt for node [%pOF]\n" , n); +pr_err ("Failed to map timer interrupt for node [%pfwP]\n" , intc_fwnode);return -ENODEV ; } -pr_info ("%s: Registering clocksource cpuid [%d] hartid [%lu]\n" , - __func__, cpuid, hartid); error =clocksource_register_hz (&riscv_clocksource, riscv_timebase);if (error) { -pr_err ("RISCV timer register failed [%d] for cpu = [%d]\n" , - error, cpuid); +pr_err ("RISCV timer registration failed [%d]\n" , error);return error; }
@@ -207,4 +174,36 @@ static int __init riscv_timer_init_dt(struct device_node *n)return error; } +static int __init riscv_timer_init_dt (struct device_node *n) +{ +int cpuid, error; +unsigned long hartid; +struct device_node *child; + + error =riscv_of_processor_hartid (n, &hartid); +if (error <0 ) { +pr_warn ("Invalid hartid for node [%pOF] error = [%lu]\n" , + n, hartid); +return error; + } + + cpuid =riscv_hartid_to_cpuid (hartid); +if (cpuid <0 ) { +pr_warn ("Invalid cpuid for hartid [%lu]\n" , hartid); +return cpuid; + } + +if (cpuid !=smp_processor_id ()) +return 0 ; + + child =of_find_compatible_node (NULL ,NULL ,"riscv,timer" ); +if (child) { + riscv_timer_cannot_wake_cpu =of_property_read_bool (child, +"riscv,timer-cannot-wake-cpu" ); +of_node_put (child); + } + +return riscv_timer_init_common (); +} +TIMER_OF_DECLARE (riscv_timer,"riscv" , riscv_timer_init_dt);
Signature · 1 line
2.34.1
Re: [PATCH V4 16/23] clocksource/timer-riscv: Refactor riscv_timer_init_dt()
Quoted 8 lines · Sunil V L
Refactor the timer init function such that few things can be shared by both DT and ACPI based platforms.
Co-developed-by Anup Patel <[email protected]>Signed-off-by Anup Patel <[email protected]>Signed-off-by Sunil V L <[email protected]>Reviewed-by Andrew Jones <[email protected]>
Forget an R-b or drop it intentionally from v3?
https://lore.kernel.org/linux-riscv/c2c1bdb5-aee6-4f4c-9f7d-073917e75b88@spud/
Please say why if you drop or ignore tags between versions.
If this is in fact the same as v3, here's the missing tag:
Thanks,
Conor.
Quoted 123 lines
--- drivers/clocksource/timer-riscv.c | 81 +++++++++++++++---------------- 1 file changed, 40 insertions(+), 41 deletions(-)drivers/clocksource/timer-riscv.c +40
-41@@ -124,61 +124,28 @@ static irqreturn_t riscv_timer_interrupt(int irq, void *dev_id)return IRQ_HANDLED ; } -static int __init riscv_timer_init_dt (struct device_node *n) +static int __init riscv_timer_init_common (void ) { -int cpuid, error; -unsigned long hartid; -struct device_node *child; +int error;struct irq_domain *domain; +struct fwnode_handle *intc_fwnode =riscv_get_intc_hwnode (); - error =riscv_of_processor_hartid (n, &hartid); -if (error <0 ) { -pr_warn ("Not valid hartid for node [%pOF] error = [%lu]\n" , - n, hartid); -return error; - } - - cpuid =riscv_hartid_to_cpuid (hartid); -if (cpuid <0 ) { -pr_warn ("Invalid cpuid for hartid [%lu]\n" , hartid); -return cpuid; - } - -if (cpuid !=smp_processor_id ()) -return 0 ; - - child =of_find_compatible_node (NULL ,NULL ,"riscv,timer" ); -if (child) { - riscv_timer_cannot_wake_cpu =of_property_read_bool (child, -"riscv,timer-cannot-wake-cpu" ); -of_node_put (child); - } - - domain =NULL ; - child =of_get_compatible_child (n,"riscv,cpu-intc" ); -if (!child) { -pr_err ("Failed to find INTC node [%pOF]\n" , n); -return -ENODEV ; - } - domain =irq_find_host (child); -of_node_put (child); + domain =irq_find_matching_fwnode (intc_fwnode,DOMAIN_BUS_ANY );if (!domain) { -pr_err ("Failed to find IRQ domain for node [%pOF]\n" , n); +pr_err ("Failed to find irq_domain for INTC node [%pfwP]\n" , + intc_fwnode);return -ENODEV ; } riscv_clock_event_irq =irq_create_mapping (domain,RV_IRQ_TIMER );if (!riscv_clock_event_irq) { -pr_err ("Failed to map timer interrupt for node [%pOF]\n" , n); +pr_err ("Failed to map timer interrupt for node [%pfwP]\n" , intc_fwnode);return -ENODEV ; } -pr_info ("%s: Registering clocksource cpuid [%d] hartid [%lu]\n" , - __func__, cpuid, hartid); error =clocksource_register_hz (&riscv_clocksource, riscv_timebase);if (error) { -pr_err ("RISCV timer register failed [%d] for cpu = [%d]\n" , - error, cpuid); +pr_err ("RISCV timer registration failed [%d]\n" , error);return error; }@@ -207,4 +174,36 @@ static int __init riscv_timer_init_dt(struct device_node *n)return error; } +static int __init riscv_timer_init_dt (struct device_node *n) +{ +int cpuid, error; +unsigned long hartid; +struct device_node *child; + + error =riscv_of_processor_hartid (n, &hartid); +if (error <0 ) { +pr_warn ("Invalid hartid for node [%pOF] error = [%lu]\n" , + n, hartid); +return error; + } + + cpuid =riscv_hartid_to_cpuid (hartid); +if (cpuid <0 ) { +pr_warn ("Invalid cpuid for hartid [%lu]\n" , hartid); +return cpuid; + } + +if (cpuid !=smp_processor_id ()) +return 0 ; + + child =of_find_compatible_node (NULL ,NULL ,"riscv,timer" ); +if (child) { + riscv_timer_cannot_wake_cpu =of_property_read_bool (child, +"riscv,timer-cannot-wake-cpu" ); +of_node_put (child); + } + +return riscv_timer_init_common (); +} +TIMER_OF_DECLARE (riscv_timer,"riscv" , riscv_timer_init_dt);Signature · 7 lines
2.34.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Sunil V L
maintainerRe: [PATCH V4 16/23] clocksource/timer-riscv: Refactor riscv_timer_init_dt()
Quoted 10 lines · Conor Dooley
Quoted 8 lines · Sunil V L
Refactor the timer init function such that few things can be shared by both DT and ACPI based platforms.
Co-developed-by Anup Patel <[email protected]>Signed-off-by Anup Patel <[email protected]>Signed-off-by Sunil V L <[email protected]>Reviewed-by Andrew Jones <[email protected]>
Quoted 4 lines
Forget an R-b or drop it intentionally from v3?
https://lore.kernel.org/linux-riscv/c2c1bdb5-aee6-4f4c-9f7d-073917e75b88@spud/
Please say why if you drop or ignore tags between versions.
Sorry, missed those tags. Not intentional. Will update in next revision.
Thanks!
Sunil
Sunil V L
maintainerPATCH v4 17/23 clocksource/timer-riscv: Add ACPI support
In reply to Sunil V LInitialize the timer driver based on RHCT table on ACPI based platforms.
Currently, ACPI doesn't support a flag to indicate that the timer interrupt can wake up the cpu irrespective of its power state. It will be added in future update.
--- drivers/clocksource/timer-riscv.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/clocksource/timer-riscv.c +11 -0
@@ -10,6 +10,7 @@#define pr_fmt (fmt) "riscv-timer: " fmt +#include <linux/acpi.h> #include <linux/clocksource.h> #include <linux/clockchips.h> #include <linux/cpu.h>
@@ -207,3 +208,13 @@ static int __init riscv_timer_init_dt(struct device_node *n) }TIMER_OF_DECLARE (riscv_timer,"riscv" , riscv_timer_init_dt); + +#ifdef CONFIG_ACPI +static int __init riscv_timer_acpi_init (struct acpi_table_header *table) +{ +return riscv_timer_init_common (); +} + +TIMER_ACPI_DECLARE (aclint_mtimer,ACPI_SIG_RHCT , riscv_timer_acpi_init); + +#endif
Signature · 1 line
2.34.1
Re: [PATCH V4 17/23] clocksource/timer-riscv: Add ACPI support
Quoted 10 lines · Sunil V L
Initialize the timer driver based on RHCT table on ACPI based platforms.
Currently, ACPI doesn't support a flag to indicate that the timer interrupt can wake up the cpu irrespective of its power state. It will be added in future update.
Signed-off-by Sunil V L <[email protected]>Reviewed-by Andrew Jones <[email protected]>
My only comment on v3 was about the commit message & mentioning why there was no handling of the timer's ability to wake the cpu, so:
Thanks,
Conor.
Quoted 38 lines
--- drivers/clocksource/timer-riscv.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/clocksource/timer-riscv.c +11
-0@@ -10,6 +10,7 @@#define pr_fmt (fmt) "riscv-timer: " fmt +#include <linux/acpi.h> #include <linux/clocksource.h> #include <linux/clockchips.h> #include <linux/cpu.h> @@ -207,3 +208,13 @@ static int __init riscv_timer_init_dt(struct device_node *n) }TIMER_OF_DECLARE (riscv_timer,"riscv" , riscv_timer_init_dt); + +#ifdef CONFIG_ACPI +static int __init riscv_timer_acpi_init (struct acpi_table_header *table) +{ +return riscv_timer_init_common (); +} + +TIMER_ACPI_DECLARE (aclint_mtimer,ACPI_SIG_RHCT , riscv_timer_acpi_init); + +#endif Signature · 7 lines
2.34.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Sunil V L
maintainerPATCH v4 18/23 RISC-V: time.c: Add ACPI support for time_init()
In reply to Sunil V LOn ACPI based platforms, timer related information is available in RHCT. Add ACPI based probe support to the timer initialization.
--- arch/riscv/kernel/time.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
arch/riscv/kernel/time.c +19 -6
@@ -4,6 +4,7 @@* Copyright (C) 2017 SiFive */ +#include <linux/acpi.h> #include <linux/of_clk.h> #include <linux/clockchips.h> #include <linux/clocksource.h>
@@ -18,17 +19,29 @@ EXPORT_SYMBOL_GPL(riscv_timebase);void __init time_init (void ) {struct device_node *cpu; +struct acpi_table_rhct *rhct; +acpi_status status;u32 prop; - cpu =of_find_node_by_path ("/cpus" ); -if (!cpu ||of_property_read_u32 (cpu,"timebase-frequency" , &prop)) -panic (KERN_WARNING "RISC-V system with no 'timebase-frequency' in DTS\n" ); -of_node_put (cpu); - riscv_timebase = prop; +if (acpi_disabled) { + cpu =of_find_node_by_path ("/cpus" ); +if (!cpu ||of_property_read_u32 (cpu,"timebase-frequency" , &prop)) +panic ("RISC-V system with no 'timebase-frequency' in DTS\n" ); + +of_node_put (cpu); + riscv_timebase = prop; +of_clk_init (NULL ); + }else { + status =acpi_get_table (ACPI_SIG_RHCT ,0 , (struct acpi_table_header **)&rhct); +if (ACPI_FAILURE (status)) +panic ("RISC-V ACPI system with no RHCT table\n" ); + + riscv_timebase = rhct->time_base_freq; +acpi_put_table ((struct acpi_table_header *)rhct); + } lpj_fine = riscv_timebase /HZ ; -of_clk_init (NULL );timer_probe ();tick_setup_hrtimer_broadcast ();
Signature · 1 line
2.34.1
Sunil V L
maintainerPATCH v4 19/23 RISC-V: Add ACPI initialization in setup_arch()
In reply to Sunil V LInitialize the ACPI core for RISC-V during boot.
ACPI tables and interpreter are initialized based on the information passed from the firmware and the value of the kernel parameter 'acpi'.
With ACPI support added for RISC-V, the kernel parameter 'acpi' is also supported on RISC-V. Hence, update the documentation.
--- .../admin-guide/kernel-parameters.txt | 8 +- arch/riscv/kernel/acpi.c | 126 ++++++++++++++++++ arch/riscv/kernel/setup.c | 25 ++-- 3 files changed, 147 insertions(+), 12 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +4 -4
@@ -1,17 +1,17 @@ - acpi= [HW,ACPI,X86,ARM64] + acpi= [HW,ACPI,X86,ARM64,RISCV64] Advanced Configuration and Power Interface Format: { force | on | off | strict | noirq | rsdt | copy_dsdt } force -- enable ACPI if default was off - on -- enable ACPI but allow fallback to DT [arm64] + on -- enable ACPI but allow fallback to DT [arm64,riscv64] off -- disable ACPI if default was on noirq -- do not use ACPI for IRQ routing strict -- Be less tolerant of platforms that are not strictly ACPI specification compliant. rsdt -- prefer RSDT over (default) XSDT copy_dsdt -- copy DSDT to memory - For ARM64, ONLY "acpi=off", "acpi=on" or "acpi=force" - are available + For ARM64 and RISCV64, ONLY "acpi=off", "acpi=on" or + "acpi=force" are available See also Documentation/power/runtime_pm.rst, pci=noacpi
arch/riscv/kernel/acpi.c +126 -0
138 lines not on this page · raw message
arch/riscv/kernel/setup.c +17 -8
@@ -8,6 +8,7 @@* Nick Kossifidis <[email protected]> */ +#include <linux/acpi.h> #include <linux/init.h> #include <linux/mm.h> #include <linux/memblock.h>
@@ -276,14 +277,22 @@ void __init setup_arch(char **cmdline_p)efi_init ();paging_init (); -#if IS_ENABLED (CONFIG_BUILTIN_DTB ) -unflatten_and_copy_device_tree (); -#else -if (early_init_dt_verify (__va (XIP_FIXUP (dtb_early_pa)))) -unflatten_device_tree (); -else -pr_err ("No DTB found in kernel mappings\n" ); -#endif + +/* Parse the ACPI tables for possible boot-time configuration */ +acpi_boot_table_init (); +if (acpi_disabled) { +if (IS_ENABLED (CONFIG_BUILTIN_DTB )) { +unflatten_and_copy_device_tree (); + }else { +if (early_init_dt_verify (__va (XIP_FIXUP (dtb_early_pa)))) +unflatten_device_tree (); +else +pr_err ("No DTB found in kernel mappings\n" ); + } + }else { +early_init_dt_verify (__va (XIP_FIXUP (dtb_early_pa))); + } +early_init_fdt_scan_reserved_mem ();misc_mem_init ();
Signature · 1 line
2.34.1
Re: [PATCH V4 19/23] RISC-V: Add ACPI initialization in setup_arch()
Quoted 17 lines · Sunil V L
Initialize the ACPI core for RISC-V during boot.
ACPI tables and interpreter are initialized based on the information passed from the firmware and the value of the kernel parameter 'acpi'.
With ACPI support added for RISC-V, the kernel parameter 'acpi' is also supported on RISC-V. Hence, update the documentation.
Signed-off-by Sunil V L <[email protected]>Reviewed-by Andrew Jones <[email protected]>Acked-by Conor Dooley <[email protected]>arch/riscv/kernel/setup.c +3
-0+/* Parse the ACPI tables for possible boot-time configuration */ +acpi_boot_table_init (); +if (acpi_disabled) {
arch/riscv/kernel/setup.c void __init setup_arch(char **cmdline_p) · line 293
Quoted 10 lines
arch/riscv/kernel/setup.c +10
-0+if (IS_ENABLED (CONFIG_BUILTIN_DTB )) { +unflatten_and_copy_device_tree (); + }else { +if (early_init_dt_verify (__va (XIP_FIXUP (dtb_early_pa)))) +unflatten_device_tree (); +else +pr_err ("No DTB found in kernel mappings\n" ); + } + }else { +early_init_dt_verify (__va (XIP_FIXUP (dtb_early_pa)));
I'm probably forgetting something, but this seems very non-obvious to me:
Why are you running early_init_dt_verify() when ACPI is enabled? I think that one deserves a comment so that next time someone looks at this (that doesn't live in ACPI land) they've know exactly why this is like it is.
Doubly so since this is likely to change with some of Alex's bits moving the dtb back into the fixmap.
Cheers,
Conor.
Sunil V L
maintainerRe: [PATCH V4 19/23] RISC-V: Add ACPI initialization in setup_arch()
Quoted 36 lines · Conor Dooley
Quoted 17 lines · Sunil V L
Initialize the ACPI core for RISC-V during boot.
ACPI tables and interpreter are initialized based on the information passed from the firmware and the value of the kernel parameter 'acpi'.
With ACPI support added for RISC-V, the kernel parameter 'acpi' is also supported on RISC-V. Hence, update the documentation.
Signed-off-by Sunil V L <[email protected]>Reviewed-by Andrew Jones <[email protected]>Acked-by Conor Dooley <[email protected]>arch/riscv/kernel/setup.c +3
-0+/* Parse the ACPI tables for possible boot-time configuration */ +acpi_boot_table_init (); +if (acpi_disabled) {arch/riscv/kernel/setup.c void __init setup_arch(char **cmdline_p) · line 293
Quoted 10 lines
arch/riscv/kernel/setup.c +10
-0+if (IS_ENABLED (CONFIG_BUILTIN_DTB )) { +unflatten_and_copy_device_tree (); + }else { +if (early_init_dt_verify (__va (XIP_FIXUP (dtb_early_pa)))) +unflatten_device_tree (); +else +pr_err ("No DTB found in kernel mappings\n" ); + } + }else { +early_init_dt_verify (__va (XIP_FIXUP (dtb_early_pa)));I'm probably forgetting something, but this seems very non-obvious to me:
Why are you runningearly_init_dt_verify()when ACPI is enabled? I think that one deserves a comment so that next time someone looks at this (that doesn't live in ACPI land) they've know exactly why this is like it is.
Quoted 3 lines
Doubly so since this is likely to change with some of Alex's bits moving the dtb back into the fixmap.
Good question. The kernel creates a tiny DTB even when the FW didn't pass the FDT (ACPI systems). Please see update_fdt(). So, parse_dtb() would have set initial_boot_params to early VA and if we don't call early_init_dt_verify() again with __va, it panics since initial_boot_params can not be translated.
Thanks,
Sunil
Re: [PATCH V4 19/23] RISC-V: Add ACPI initialization in setup_arch()
Quoted 37 lines · Sunil V L
Quoted 36 lines · Conor Dooley
Quoted 17 lines · Sunil V L
Initialize the ACPI core for RISC-V during boot.
ACPI tables and interpreter are initialized based on the information passed from the firmware and the value of the kernel parameter 'acpi'.
With ACPI support added for RISC-V, the kernel parameter 'acpi' is also supported on RISC-V. Hence, update the documentation.
Signed-off-by Sunil V L <[email protected]>Reviewed-by Andrew Jones <[email protected]>Acked-by Conor Dooley <[email protected]>arch/riscv/kernel/setup.c +3
-0+/* Parse the ACPI tables for possible boot-time configuration */ +acpi_boot_table_init (); +if (acpi_disabled) {arch/riscv/kernel/setup.c void __init setup_arch(char **cmdline_p) · line 293
Quoted 10 lines
arch/riscv/kernel/setup.c +10
-0+if (IS_ENABLED (CONFIG_BUILTIN_DTB )) { +unflatten_and_copy_device_tree (); + }else { +if (early_init_dt_verify (__va (XIP_FIXUP (dtb_early_pa)))) +unflatten_device_tree (); +else +pr_err ("No DTB found in kernel mappings\n" ); + } + }else { +early_init_dt_verify (__va (XIP_FIXUP (dtb_early_pa)));I'm probably forgetting something, but this seems very non-obvious to me:
Why are you runningearly_init_dt_verify()when ACPI is enabled? I think that one deserves a comment so that next time someone looks at this (that doesn't live in ACPI land) they've know exactly why this is like it is.
Quoted 5 lines
Quoted 3 lines
Doubly so since this is likely to change with some of Alex's bits moving the dtb back into the fixmap.
Good question. The kernel creates a tiny DTB even when the FW didn't pass the FDT (ACPI systems). Please see
update_fdt().
Can you add a comment about this either on-location or in the commit message please?
I think this counts as non-obvious behaviour. At least to me it does!
Cheers,
Conor.
Sunil V L
maintainerPATCH v4 20/23 RISC-V: Enable ACPI in defconfig
In reply to Sunil V LAdd support to build ACPI subsystem in defconfig.
--- arch/riscv/configs/defconfig | 1 + 1 file changed, 1 insertion(+)
arch/riscv/configs/defconfig +1 -0
@@ -238,3 +238,4 @@ CONFIG_RCU_EQS_DEBUG=y # CONFIG_FTRACE is not set # CONFIG_RUNTIME_TESTING_MENU is not set CONFIG_MEMTEST=y +CONFIG_ACPI=y
Signature · 1 line
2.34.1
Re: [PATCH V4 20/23] RISC-V: Enable ACPI in defconfig
Quoted 5 lines · Sunil V L
Add support to build ACPI subsystem in defconfig.
Signed-off-by Sunil V L <[email protected]>Reviewed-by Andrew Jones <[email protected]>
Dropped another R-b?
https://lore.kernel.org/linux-riscv/91cf4ebd-f22c-4cf9-9fb4-fa6349ea00ab@spud/
That said...
arch/riscv/configs/defconfig CONFIG_RCU_EQS_DEBUG=y · line 241
Quoted 13 lines
--- arch/riscv/configs/defconfig | 1 + 1 file changed, 1 insertion(+)arch/riscv/configs/defconfig +1
-0@@ -238,3 +238,4 @@ CONFIG_RCU_EQS_DEBUG=y # CONFIG_FTRACE is not set # CONFIG_RUNTIME_TESTING_MENU is not set CONFIG_MEMTEST=y +CONFIG_ACPI=y
...this is not where savedefconfig puts this for me. Please move it there & then:
Thanks,
Conor.
Quoted 8 lines
Signature · 7 lines
2.34.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Sunil V L
maintainerRe: [PATCH V4 20/23] RISC-V: Enable ACPI in defconfig
Quoted 10 lines · Conor Dooley
Quoted 5 lines · Sunil V L
Add support to build ACPI subsystem in defconfig.
Signed-off-by Sunil V L <[email protected]>Reviewed-by Andrew Jones <[email protected]>Dropped another R-b?
https://lore.kernel.org/linux-riscv/91cf4ebd-f22c-4cf9-9fb4-fa6349ea00ab@spud/
Yeah, missed updating....
Quoted 18 lines
That said...
arch/riscv/configs/defconfig CONFIG_RCU_EQS_DEBUG=y · line 241
Quoted 13 lines
--- arch/riscv/configs/defconfig | 1 + 1 file changed, 1 insertion(+)arch/riscv/configs/defconfig +1
-0@@ -238,3 +238,4 @@ CONFIG_RCU_EQS_DEBUG=y # CONFIG_FTRACE is not set # CONFIG_RUNTIME_TESTING_MENU is not set CONFIG_MEMTEST=y +CONFIG_ACPI=y...this is not where savedefconfig puts this for me. Please move it there & then:
Quoted 2 lines
Reviewed-by Conor Dooley <[email protected]>
Okay. Will update.
Thanks!
Sunil
Sunil V L
maintainerPATCH v4 21/23 MAINTAINERS: Add entry for drivers/acpi/riscv
In reply to Sunil V LACPI defines few RISC-V specific tables which need parsing code added in drivers/acpi/riscv. Add maintainer entries for this newly created folder.
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -406,6 +406,14 @@ L: [email protected] (moderated for non-subscribers) S: Maintained F: drivers/acpi/arm64 +ACPI FOR RISC-V (ACPI/riscv) +M: Sunil V L <[email protected]> +L: [email protected] +L: [email protected] +S: Maintained +F: arch/riscv/kernel/acpi.c +F: drivers/acpi/riscv + ACPI SERIAL MULTI INSTANTIATE DRIVER M: Hans de Goede <[email protected]> L: [email protected]
Signature · 1 line
2.34.1
Sunil V L
maintainerPATCH v4 22/23 platform/surface: Disable for RISC-V
In reply to Sunil V LWith CONFIG_ACPI enabled for RISC-V, this driver gets enabled in allmodconfig build. However, RISC-V doesn't support sub-word atomics which is used by this driver. Due to this, the build fails with below error.
In function ‘ssh_seq_next’,
inlined from ‘ssam_request_write_data’ at drivers/platform/surface/aggregator/controller.c:1483:8:././include/linux/compiler_types.h:399:45: error: call to ‘__compiletime_assert_335’ declared with attribute error: BUILD_BUG failed
399 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^./include/linux/compiler.h:78:45: note: in definition of macro ‘unlikely’
78 | # define unlikely(x) __builtin_expect(!!(x), 0)
| ^././include/linux/compiler_types.h:387:9: note: in expansion of macro ‘__compiletime_assert’
387 | __compiletime_assert(condition, msg, prefix, suffix)
| ^~~~~~~~~~~~~~~~~~~~
././include/linux/compiler_types.h:399:9: note: in expansion of macro ‘_compiletime_assert’
399 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:59:21: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
59 | #define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed")
| ^~~~~~~~~~~~~~~~
./arch/riscv/include/asm/cmpxchg.h:335:17: note: in expansion of macro ‘BUILD_BUG’
335 | BUILD_BUG(); \
| ^~~~~~~~~./arch/riscv/include/asm/cmpxchg.h:344:30: note: in expansion of macro ‘__cmpxchg’
344 | (__typeof__(*(ptr))) __cmpxchg((ptr), \
| ^~~~~~~~~./include/linux/atomic/atomic-instrumented.h:1916:9: note: in expansion of macro ‘arch_cmpxchg’
1916 | arch_cmpxchg(__ai_ptr, __VA_ARGS__); \
| ^~~~~~~~~~~~drivers/platform/surface/aggregator/controller.c:61:32: note: in expansion of macro ‘cmpxchg’
61 | while (unlikely((ret = cmpxchg(&c->value, old, new)) != old)) {
| ^~~~~~~
So, disable this driver for RISC-V even when ACPI is enabled for now.
--- drivers/platform/surface/aggregator/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/surface/aggregator/Kconfig +1 -1
@@ -4,7 +4,7 @@ menuconfig SURFACE_AGGREGATOR tristate "Microsoft Surface System Aggregator Module Subsystem and Drivers" depends on SERIAL_DEV_BUS - depends on ACPI + depends on ACPI && !RISCV select CRC_CCITT help The Surface System Aggregator Module (Surface SAM or SSAM) is an
Signature · 1 line
2.34.1
Re: [PATCH V4 22/23] platform/surface: Disable for RISC-V
Quoted 4 lines · Sunil V L
With
CONFIG_ACPIenabled for RISC-V, this driver gets enabled in allmodconfig build. However, RISC-V doesn't support sub-word atomics which is used by this driver.
Why not? Compilers and libatomic do, so surely the Linux kernel should too.
Quoted 51 lines
Due to this, the build fails
with below error.In function ‘ssh_seq_next’,
inlined from ‘ssam_request_write_data’ atdrivers/platform/surface/aggregator/controller.c:1483:8:././include/linux/compiler_types.h:399:45: error: call to ‘__compiletime_assert_335’ declared with attribute error:BUILD_BUGfailed
399 |_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^./include/linux/compiler.h:78:45: note: in definition of macro ‘unlikely’
78 | # define unlikely(x)__builtin_expect(!!(x), 0)
| ^././include/linux/compiler_types.h:387:9: note: in expansion of macro ‘__compiletime_assert’387 | __compiletime_assert(condition, msg, prefix, suffix) | ^~~~~~~~~~~~~~~~~~~~ ././include/linux/compiler_types.h:399:9: note: in expansion of macro ‘_compiletime_assert’ 399 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) | ^~~~~~~~~~~~~~~~~~~ ./include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’ 39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) | ^~~~~~~~~~~~~~~~~~ ./include/linux/build_bug.h:59:21: note: in expansion of macro ‘BUILD_BUG_ON_MSG’ 59 | #define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed") | ^~~~~~~~~~~~~~~~ ./arch/riscv/include/asm/cmpxchg.h:335:17: note: in expansion of macro ‘BUILD_BUG’ 335 | BUILD_BUG(); \ | ^~~~~~~~~
./arch/riscv/include/asm/cmpxchg.h:344:30: note: in expansion of macro ‘__cmpxchg’
344 | (__typeof__(*(ptr))) __cmpxchg((ptr), \
| ^~~~~~~~~./include/linux/atomic/atomic-instrumented.h:1916:9: note: in expansion of macro ‘arch_cmpxchg’1916 | arch_cmpxchg(__ai_ptr, __VA_ARGS__); \ | ^~~~~~~~~~~~
drivers/platform/surface/aggregator/controller.c:61:32: note: in expansion of macro ‘cmpxchg’
61 | while (unlikely((ret = cmpxchg(&c->value, old, new)) != old)) {
| ^~~~~~~So, disable this driver for RISC-V even when ACPI is enabled for now.
Signed-off-by Sunil V L <[email protected]>---
drivers/platform/surface/aggregator/Kconfig| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/platform/surface/aggregator/Kconfig +0
-0@@ -4,7 +4,7 @@menuconfig
SURFACE_AGGREGATOR
tristate "Microsoft Surface System Aggregator Module Subsystem and Drivers" depends onSERIAL_DEV_BUS
drivers/platform/surface/aggregator/Kconfig line 7
Quoted 2 lines
drivers/platform/surface/aggregator/Kconfig +1
-1- depends on ACPI + depends on ACPI && !RISCV
If you insist on doing this, at least make it some new config variable that’s self-documenting and means this automatically gets re-enabled when arch/riscv fixes this deficiency? Hard-coding arch lists like this seems like a terrible anti-pattern.
Jess
Quoted 11 lines
select
CRC_CCITT
help
The Surface System Aggregator Module (Surface SAM or SSAM) is anSignature · 7 lines
2.34.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Sunil V L
maintainerRe: [PATCH V4 22/23] platform/surface: Disable for RISC-V
Hi Jess,
Quoted 9 lines · Jessica Clarke
Quoted 4 lines · Sunil V L
With
CONFIG_ACPIenabled for RISC-V, this driver gets enabled in allmodconfig build. However, RISC-V doesn't support sub-word atomics which is used by this driver.Why not? Compilers and libatomic do, so surely the Linux kernel should too.
I think you are probably right. But I don't want to combine that activity with this series. IMO, that should be separate activity.
Quoted 43 lines
Quoted 43 lines
Due to this, the build fails
with below error.In function ‘ssh_seq_next’,
inlined from ‘ssam_request_write_data’ atdrivers/platform/surface/aggregator/controller.c:1483:8:././include/linux/compiler_types.h:399:45: error: call to ‘__compiletime_assert_335’ declared with attribute error:BUILD_BUGfailed
399 |_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^./include/linux/compiler.h:78:45: note: in definition of macro ‘unlikely’
78 | # define unlikely(x)__builtin_expect(!!(x), 0)
| ^././include/linux/compiler_types.h:387:9: note: in expansion of macro ‘__compiletime_assert’387 | __compiletime_assert(condition, msg, prefix, suffix) | ^~~~~~~~~~~~~~~~~~~~ ././include/linux/compiler_types.h:399:9: note: in expansion of macro ‘_compiletime_assert’ 399 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) | ^~~~~~~~~~~~~~~~~~~ ./include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’ 39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) | ^~~~~~~~~~~~~~~~~~ ./include/linux/build_bug.h:59:21: note: in expansion of macro ‘BUILD_BUG_ON_MSG’ 59 | #define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed") | ^~~~~~~~~~~~~~~~ ./arch/riscv/include/asm/cmpxchg.h:335:17: note: in expansion of macro ‘BUILD_BUG’ 335 | BUILD_BUG(); \ | ^~~~~~~~~
./arch/riscv/include/asm/cmpxchg.h:344:30: note: in expansion of macro ‘__cmpxchg’
344 | (__typeof__(*(ptr))) __cmpxchg((ptr), \
| ^~~~~~~~~./include/linux/atomic/atomic-instrumented.h:1916:9: note: in expansion of macro ‘arch_cmpxchg’1916 | arch_cmpxchg(__ai_ptr, __VA_ARGS__); \ | ^~~~~~~~~~~~
drivers/platform/surface/aggregator/controller.c:61:32: note: in expansion of macro ‘cmpxchg’
61 | while (unlikely((ret = cmpxchg(&c->value, old, new)) != old)) {
| ^~~~~~~So, disable this driver for RISC-V even when ACPI is enabled for now.
Signed-off-by Sunil V L <[email protected]>---
drivers/platform/surface/aggregator/Kconfig| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
drivers/platform/surface/aggregator/Kconfig line 7
Quoted 10 lines
drivers/platform/surface/aggregator/Kconfig +0
-0@@ -4,7 +4,7 @@menuconfig
SURFACE_AGGREGATOR
tristate "Microsoft Surface System Aggregator Module Subsystem and Drivers" depends onSERIAL_DEV_BUSdrivers/platform/surface/aggregator/Kconfig +1
-1- depends on ACPI + depends on ACPI && !RISCVIf you insist on doing this, at least make it some new config variable that’s self-documenting and means this automatically gets re-enabled when
arch/riscvfixes this deficiency? Hard-coding arch lists like this seems like a terrible anti-pattern.
I understand your point. But given that this is currently only issue with a single driver from Microsoft and that too only in COMPILE_TEST builds, I think introducing a new config variable is overkill. If we support sub-word atomics in kernel, the option may not be useful much anyway.
There are patterns to disable an architecture for COMPILE_TEST builds.
Thanks,
Sunil
Re: [PATCH V4 22/23] platform/surface: Disable for RISC-V
In reply to Sunil V LQuoted 32 lines · Sunil V L
With
CONFIG_ACPIenabled for RISC-V, this driver gets enabled in allmodconfig build. However, RISC-V doesn't support sub-word atomics which is used by this driver. Due to this, the build fails with below error.In function ‘ssh_seq_next’,
inlined from ‘ssam_request_write_data’ atdrivers/platform/surface/aggregator/controller.c:1483:8:././include/linux/compiler_types.h:399:45: error: call to ‘__compiletime_assert_335’ declared with attribute error:BUILD_BUGfailed
399 |_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^./include/linux/compiler.h:78:45: note: in definition of macro ‘unlikely’78 | # define unlikely(x) __builtin_expect(!!(x), 0) | ^ ././include/linux/compiler_types.h:387:9: note: in expansion of macro ‘__compiletime_assert’ 387 | __compiletime_assert(condition, msg, prefix, suffix) | ^~~~~~~~~~~~~~~~~~~~ ././include/linux/compiler_types.h:399:9: note: in expansion of macro ‘_compiletime_assert’ 399 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) | ^~~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’
39 | #defineBUILD_BUG_ON_MSG(cond, msg)compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~./include/linux/build_bug.h:59:21: note: in expansion of macro ‘BUILD_BUG_ON_MSG’59 | #define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed") | ^~~~~~~~~~~~~~~~ ./arch/riscv/include/asm/cmpxchg.h:335:17: note: in expansion of macro ‘BUILD_BUG’ 335 | BUILD_BUG(); \ | ^~~~~~~~~
./arch/riscv/include/asm/cmpxchg.h:344:30: note: in expansion of macro ‘__cmpxchg’
344 | (__typeof__(*(ptr))) __cmpxchg((ptr), \
| ^~~~~~~~~./include/linux/atomic/atomic-instrumented.h:1916:9: note: in expansion of macro ‘arch_cmpxchg’
Quoted 7 lines
1916 | arch_cmpxchg(__ai_ptr, __VA_ARGS__); \ | ^~~~~~~~~~~~ drivers/platform/surface/aggregator/controller.c:61:32: note: in expansion of macro ‘cmpxchg’ 61 | while (unlikely((ret = cmpxchg(&c->value, old, new)) != old)) { | ^~~~~~~So, disable this driver for RISC-V even when ACPI is enabled for now.
CONFIG_SURFACE_PLATFORMS should be enabled for ARM64 || X86 || COMPILE_TEST only, so I guess the issue only happens when compiling with the latter enabled?
I'm not aware of any current plans of MS to release RISC-V-based Surface devices, so you could maybe also just explicitly disable CONFIG_SURFACE_PLATFORMS. In any case, I don't see any issues with disabling the whole platform/surface or only individual drivers for RISC-V, so for either solution:
Quoted 18 lines
Signed-off-by Sunil V L <[email protected]>--- drivers/platform/surface/aggregator/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/platform/surface/aggregator/Kconfig +1
-1@@ -4,7 +4,7 @@ menuconfig SURFACE_AGGREGATOR tristate "Microsoft Surface System Aggregator Module Subsystem and Drivers" depends on SERIAL_DEV_BUS - depends on ACPI + depends on ACPI && !RISCV select CRC_CCITT help The Surface System Aggregator Module (Surface SAM or SSAM) is an
Sunil V L
maintainerRe: [PATCH V4 22/23] platform/surface: Disable for RISC-V
Quoted 44 lines · Maximilian Luz
Quoted 32 lines · Sunil V L
With
CONFIG_ACPIenabled for RISC-V, this driver gets enabled in allmodconfig build. However, RISC-V doesn't support sub-word atomics which is used by this driver. Due to this, the build fails with below error.In function ‘ssh_seq_next’,
inlined from ‘ssam_request_write_data’ atdrivers/platform/surface/aggregator/controller.c:1483:8:././include/linux/compiler_types.h:399:45: error: call to ‘__compiletime_assert_335’ declared with attribute error:BUILD_BUGfailed
399 |_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^./include/linux/compiler.h:78:45: note: in definition of macro ‘unlikely’78 | # define unlikely(x) __builtin_expect(!!(x), 0) | ^ ././include/linux/compiler_types.h:387:9: note: in expansion of macro ‘__compiletime_assert’ 387 | __compiletime_assert(condition, msg, prefix, suffix) | ^~~~~~~~~~~~~~~~~~~~ ././include/linux/compiler_types.h:399:9: note: in expansion of macro ‘_compiletime_assert’ 399 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) | ^~~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’
39 | #defineBUILD_BUG_ON_MSG(cond, msg)compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~./include/linux/build_bug.h:59:21: note: in expansion of macro ‘BUILD_BUG_ON_MSG’59 | #define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed") | ^~~~~~~~~~~~~~~~ ./arch/riscv/include/asm/cmpxchg.h:335:17: note: in expansion of macro ‘BUILD_BUG’ 335 | BUILD_BUG(); \ | ^~~~~~~~~
./arch/riscv/include/asm/cmpxchg.h:344:30: note: in expansion of macro ‘__cmpxchg’
344 | (__typeof__(*(ptr))) __cmpxchg((ptr), \
| ^~~~~~~~~./include/linux/atomic/atomic-instrumented.h:1916:9: note: in expansion of macro ‘arch_cmpxchg’Quoted 7 lines
1916 | arch_cmpxchg(__ai_ptr, __VA_ARGS__); \ | ^~~~~~~~~~~~ drivers/platform/surface/aggregator/controller.c:61:32: note: in expansion of macro ‘cmpxchg’ 61 | while (unlikely((ret = cmpxchg(&c->value, old, new)) != old)) { | ^~~~~~~So, disable this driver for RISC-V even when ACPI is enabled for now.
CONFIG_SURFACE_PLATFORMSshould be enabled for ARM64 || X86 ||COMPILE_TESTonly, so I guess the issue only happens when compiling with the latter enabled?
Quoted 7 lines
I'm not aware of any current plans of MS to release RISC-V-based Surface devices, so you could maybe also just explicitly disable
CONFIG_SURFACE_PLATFORMS. In any case, I don't see any issues with disabling the whole platform/surface or only individual drivers for RISC-V, so for either solution:Acked-by Maximilian Luz <[email protected]>
Hi Maximilian,
Thanks!. Yes, COMPILE_TEST gets enabled for allmodconfig builds. Since the whole intention of COMPILE_TEST appears to be able to compile-test drivers on a platform than they are supposed to be used, I think it is better not to skip whole set of drivers but only that which can not build. So, I prefer to keep this change as is.
Thanks,
Sunil
Maximilian Luz
maintainerRe: [PATCH V4 22/23] platform/surface: Disable for RISC-V
Quoted 52 lines · Sunil V L
Quoted 44 lines · Maximilian Luz
Quoted 38 lines · Sunil V L
With
CONFIG_ACPIenabled for RISC-V, this driver gets enabled in allmodconfig build. However, RISC-V doesn't support sub-word atomics which is used by this driver. Due to this, the build fails with below error.In function ‘ssh_seq_next’,
inlined from ‘ssam_request_write_data’ atdrivers/platform/surface/aggregator/controller.c:1483:8:././include/linux/compiler_types.h:399:45: error: call to ‘__compiletime_assert_335’ declared with attribute error:BUILD_BUGfailed
399 |_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^./include/linux/compiler.h:78:45: note: in definition of macro ‘unlikely’78 | # define unlikely(x) __builtin_expect(!!(x), 0) | ^ ././include/linux/compiler_types.h:387:9: note: in expansion of macro ‘__compiletime_assert’ 387 | __compiletime_assert(condition, msg, prefix, suffix) | ^~~~~~~~~~~~~~~~~~~~ ././include/linux/compiler_types.h:399:9: note: in expansion of macro ‘_compiletime_assert’ 399 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) | ^~~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’
39 | #defineBUILD_BUG_ON_MSG(cond, msg)compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~./include/linux/build_bug.h:59:21: note: in expansion of macro ‘BUILD_BUG_ON_MSG’59 | #define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed") | ^~~~~~~~~~~~~~~~ ./arch/riscv/include/asm/cmpxchg.h:335:17: note: in expansion of macro ‘BUILD_BUG’ 335 | BUILD_BUG(); \ | ^~~~~~~~~ ./arch/riscv/include/asm/cmpxchg.h:344:30: note: in expansion of macro ‘__cmpxchg’ 344 | (__typeof__(*(ptr))) __cmpxchg((ptr), \ | ^~~~~~~~~ ./include/linux/atomic/atomic-instrumented.h:1916:9: note: in expansion of macro ‘arch_cmpxchg’ 1916 | arch_cmpxchg(__ai_ptr, __VA_ARGS__); \ | ^~~~~~~~~~~~ drivers/platform/surface/aggregator/controller.c:61:32: note: in expansion of macro ‘cmpxchg’ 61 | while (unlikely((ret = cmpxchg(&c->value, old, new)) != old)) { | ^~~~~~~Quoted 1 line
So, disable this driver for RISC-V even when ACPI is enabled for now.
CONFIG_SURFACE_PLATFORMSshould be enabled for ARM64 || X86 ||COMPILE_TESTonly, so I guess the issue only happens when compiling with the latter enabled?Quoted 7 lines
I'm not aware of any current plans of MS to release RISC-V-based Surface devices, so you could maybe also just explicitly disable
CONFIG_SURFACE_PLATFORMS. In any case, I don't see any issues with disabling the whole platform/surface or only individual drivers for RISC-V, so for either solution:Acked-by Maximilian Luz <[email protected]>
Quoted 7 lines
Hi Maximilian,
Thanks!. Yes,
COMPILE_TESTgets enabled for allmodconfig builds. Since the whole intention ofCOMPILE_TESTappears to be able to compile-test drivers on a platform than they are supposed to be used, I think it is better not to skip whole set of drivers but only that which can not build. So, I prefer to keep this change as is.
Hi Sunil,
What I wanted to say with my previous mail: I'm fairly confident that platform/surface drivers will not be actively used on RISC-V hardware any time soon (not sure if that came over in this way). But whatever you/others prefer, I'm happy with either.
Best regards,
Max
Sunil V L
maintainerPATCH v4 23/23 crypto: hisilicon/qm: Workaround to enable build with RISC-V clang
In reply to Sunil V LWith CONFIG_ACPI enabled for RISC-V, this driver gets enabled in allmodconfig build. The gcc tool chain builds this driver removing the inline arm64 assembly code. However, clang for RISC-V tries to build the arm64 assembly and below error is seen.
drivers/crypto/hisilicon/qm.c:627:10: error: invalid output constraint '+Q' in asm
"+Q" (*((char __iomem *)fun_base))
^It appears that RISC-V clang is not smart enough to detect IS_ENABLED(CONFIG_ARM64) and remove the dead code.
As a workaround, move this check to preprocessing stage which works with the RISC-V clang tool chain.
--- drivers/crypto/hisilicon/qm.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/crypto/hisilicon/qm.c +7 -6
@@ -611,13 +611,9 @@ EXPORT_SYMBOL_GPL(hisi_qm_wait_mb_ready);static void qm_mb_write (struct hisi_qm *qm,const void *src) {void __iomem *fun_base = qm->io_base +QM_MB_CMD_SEND_BASE ; -unsigned long tmp0 =0 , tmp1 =0 ; -if (!IS_ENABLED (CONFIG_ARM64 )) { -memcpy_toio (fun_base, src,16 ); -dma_wmb (); -return ; - } +#if IS_ENABLED (CONFIG_ARM64 ) +unsigned long tmp0 =0 , tmp1 =0 ; asmvolatile ("ldp %0, %1, %3\n" "stp %0, %1, %2\n"
@@ -627,6 +623,11 @@ static void qm_mb_write(struct hisi_qm *qm, const void *src) "+Q" (*((char __iomem *)fun_base)) : "Q" (*((char *)src)) : "memory"); +#else +memcpy_toio (fun_base, src,16 ); +dma_wmb (); +#endif + }static int qm_mb_nolock (struct hisi_qm *qm,struct qm_mailbox *mailbox)
Signature · 1 line
2.34.1
Re: [PATCH V4 23/23] crypto: hisilicon/qm: Workaround to enable build with RISC-V clang
Hey Sunil,
This one made me scratch my head for a bit..
Quoted 4 lines · Sunil V L
With
CONFIG_ACPIenabled for RISC-V, this driver gets enabled in allmodconfig build. The gcc tool chain builds this driver removing the inline arm64 assembly code. However, clang for RISC-V tries to build the arm64 assembly and below error is seen.
There's actually nothing RISC-V specific about that behaviour, that's just how clang works. Quoting Nathan:
"Clang performs semantic analysis (i.e., validates assembly) before dead code elimination, so IS_ENABLED() is not sufficient for avoiding that error."
Quoted 5 lines
drivers/crypto/hisilicon/qm.c:627:10: error: invalid output constraint '+Q' in asm"+Q" (*((char __iomem *)fun_base)) ^It appears that RISC-V clang is not smart enough to detect
IS_ENABLED(CONFIG_ARM64)and remove the dead code.
So I think this statement is just not true, it can remove dead code, but only after it has done the semantic analysis.
The reason that this has not been seen before, again quoting Nathan, is:
"arm64 and x86_64 both support the Q constraint, we cannot build LoongArch yet (although it does not have support for Q either so same boat as RISC-V), and ia64 is dead/unsupported in LLVM. Those are the only architectures that support ACPI, so I guess that explains why we have seen no issues aside from RISC-V so far."
Quoted 2 lines
As a workaround, move this check to preprocessing stage which works with the RISC-V clang tool chain.
I don't think there's much else you can do!
Perhaps it is also worth adding:
Cheers,
Conor.
Quoted 45 lines
Signed-off-by Sunil V L <[email protected]>--- drivers/crypto/hisilicon/qm.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)drivers/crypto/hisilicon/qm.c +7
-6@@ -611,13 +611,9 @@ EXPORT_SYMBOL_GPL(hisi_qm_wait_mb_ready);static void qm_mb_write (struct hisi_qm *qm,const void *src) {void __iomem *fun_base = qm->io_base +QM_MB_CMD_SEND_BASE ; -unsigned long tmp0 =0 , tmp1 =0 ; -if (!IS_ENABLED (CONFIG_ARM64 )) { -memcpy_toio (fun_base, src,16 ); -dma_wmb (); -return ; - } +#if IS_ENABLED (CONFIG_ARM64 ) +unsigned long tmp0 =0 , tmp1 =0 ; asmvolatile ("ldp %0, %1, %3\n" "stp %0, %1, %2\n"@@ -627,6 +623,11 @@ static void qm_mb_write(struct hisi_qm *qm, const void *src) "+Q" (*((char __iomem *)fun_base)) : "Q" (*((char *)src)) : "memory"); +#else +memcpy_toio (fun_base, src,16 ); +dma_wmb (); +#endif + }static int qm_mb_nolock (struct hisi_qm *qm,struct qm_mailbox *mailbox)Signature · 7 lines
2.34.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Sunil V L
maintainerRe: [PATCH V4 23/23] crypto: hisilicon/qm: Workaround to enable build with RISC-V clang
Hi Conor,
Quoted 10 lines · Conor Dooley
Hey Sunil,
This one made me scratch my head for a bit..
Quoted 4 lines · Sunil V L
With
CONFIG_ACPIenabled for RISC-V, this driver gets enabled in allmodconfig build. The gcc tool chain builds this driver removing the inline arm64 assembly code. However, clang for RISC-V tries to build the arm64 assembly and below error is seen.
Quoted 6 lines
There's actually nothing RISC-V specific about that behaviour, that's just how clang works. Quoting Nathan:
"Clang performs semantic analysis (i.e., validates assembly) before dead code elimination, soIS_ENABLED()is not sufficient for avoiding that error."
Huh, It never occurred to me that this issue could be known already since I always thought we are hitting this first time since ACPI is enabled only now for RISC-V. Thank you very much!.
Quoted 9 lines
Quoted 5 lines
drivers/crypto/hisilicon/qm.c:627:10: error: invalid output constraint '+Q' in asm"+Q" (*((char __iomem *)fun_base)) ^It appears that RISC-V clang is not smart enough to detect
IS_ENABLED(CONFIG_ARM64)and remove the dead code.So I think this statement is just not true, it can remove dead code, but only after it has done the semantic analysis.
Yes, with more details now, let me update the commit message.
Quoted 7 lines
The reason that this has not been seen before, again quoting Nathan, is:
"arm64 andx86_64both support the Q constraint, we cannot build LoongArch yet (although it does not have support for Q either so same boat as RISC-V), and ia64 is dead/unsupported in LLVM. Those are the only architectures that support ACPI, so I guess that explains why we have seen no issues aside from RISC-V so far."
Quoted 9 lines
Quoted 2 lines
As a workaround, move this check to preprocessing stage which works with the RISC-V clang tool chain.
I don't think there's much else you can do!
Reviewed-by Conor Dooley <[email protected]>Perhaps it is also worth adding:
Sure, Thank you very much for digging this!
Thanks,
Sunil
Re: [PATCH V4 23/23] crypto: hisilicon/qm: Workaround to enable build with RISC-V clang
In reply to Sunil V LQuoted 9 lines · Sunil V L
With
CONFIG_ACPIenabled for RISC-V, this driver gets enabled in allmodconfig build. The gcc tool chain builds this driver removing the inline arm64 assembly code. However, clang for RISC-V tries to build the arm64 assembly and below error is seen.
drivers/crypto/hisilicon/qm.c:627:10: error: invalid output constraint '+Q' in asm"+Q" (*((char __iomem *)fun_base)) ^
Quoted 7 lines
It appears that RISC-V clang is not smart enough to detect
IS_ENABLED(CONFIG_ARM64)and remove the dead code.As a workaround, move this check to preprocessing stage which works with the RISC-V clang tool chain.
Signed-off-by Sunil V L <[email protected]>
Your patch looks correct for this particular problem, but I see that there are a couple of other issues in the same function:
drivers/crypto/hisilicon/qm.c static void qm_mb_write(struct hisi_qm *qm, const · line 626
Quoted 11 lines
drivers/crypto/hisilicon/qm.c +2
-1- } +#if IS_ENABLED (CONFIG_ARM64 ) +unsigned long tmp0 =0 , tmp1 =0 ; asmvolatile ("ldp %0, %1, %3\n" "stp %0, %1, %2\n"@@ -627,6 +623,11 @@ static void qm_mb_write(struct hisi_qm *qm, const void *src) "+Q" (*((char __iomem *)fun_base)) : "Q" (*((char *)src)) : "memory");
For the arm64 version:
- the "dmb oshst" barrier needs to come before the stp, not after it, otherwise there is no guarantee that data written to memory is visible by the device when the mailbox gets triggered
- The input/output arguments need to be pointers to 128-bit types, either a struct or a __uint128_t
- this lacks a byteswap on big-endian kernels
drivers/crypto/hisilicon/qm.c static void qm_mb_write(struct hisi_qm *qm, const void *src) · line 629
Quoted 4 lines
drivers/crypto/hisilicon/qm.c +4
-0+#else +memcpy_toio (fun_base, src,16 ); +dma_wmb (); +#endif
This version has the same problems, plus the write is not actually atomic. I wonder if a pair of writeq() calls would just do the right thing here for both arm64 and others, or possibly a writeq() followed by a writeq_relaxed() to avoid the extra dmb() in the middle.
Arnd
Weili Qian
maintainerRe: [PATCH V4 23/23] crypto: hisilicon/qm: Workaround to enable build with RISC-V clang
Quoted 35 lines · Arnd Bergmann
Quoted 9 lines · Sunil V L
With
CONFIG_ACPIenabled for RISC-V, this driver gets enabled in allmodconfig build. The gcc tool chain builds this driver removing the inline arm64 assembly code. However, clang for RISC-V tries to build the arm64 assembly and below error is seen.
drivers/crypto/hisilicon/qm.c:627:10: error: invalid output constraint '+Q' in asm"+Q" (*((char __iomem *)fun_base)) ^Quoted 7 lines
It appears that RISC-V clang is not smart enough to detect
IS_ENABLED(CONFIG_ARM64)and remove the dead code.As a workaround, move this check to preprocessing stage which works with the RISC-V clang tool chain.
Signed-off-by Sunil V L <[email protected]>Your patch looks correct for this particular problem, but I see that there are a couple of other issues in the same function:
drivers/crypto/hisilicon/qm.c static void qm_mb_write(struct hisi_qm *qm, const · line 626
Quoted 11 lines
drivers/crypto/hisilicon/qm.c +2
-1- } +#if IS_ENABLED (CONFIG_ARM64 ) +unsigned long tmp0 =0 , tmp1 =0 ; asmvolatile ("ldp %0, %1, %3\n" "stp %0, %1, %2\n"@@ -627,6 +623,11 @@ static void qm_mb_write(struct hisi_qm *qm, const void *src) "+Q" (*((char __iomem *)fun_base)) : "Q" (*((char *)src)) : "memory");For the arm64 version:
Quoted 6 lines
- the "dmb oshst" barrier needs to come before the stp, not after it, otherwise there is no guarantee that data written to memory is visible by the device when the mailbox gets triggered
- The input/output arguments need to be pointers to 128-bit types, either a struct or a__uint128_t
- this lacks a byteswap on big-endian kernels
Sorry for the late reply.
- the execution order relies on the data dependency between ldp and stp:
load "src" to "tmp0" and "tmp1", then
store "tmp0" and "tmp1" to "fun_base";
The "dmb oshst" is used to ensure that the stp instruction has been executed before CPU checking mailbox status. Whether the execution order cannot be guaranteed via data dependency?
- The input argument "src" is struct "struct qm_mailbox".
- Before call this funcion, the data has been byteswapped.
mailbox->w0 = cpu_to_le16((cmd) | ((op) ? 0x1 << QM_MB_OP_SHIFT : 0) | (0x1 << QM_MB_BUSY_SHIFT)); mailbox->queue_num = cpu_to_le16(queue); mailbox->base_l = cpu_to_le32(lower_32_bits(base)); mailbox->base_h = cpu_to_le32(upper_32_bits(base)); mailbox->rsvd = 0;
Quoted 12 lines
drivers/crypto/hisilicon/qm.c static void qm_mb_write(struct hisi_qm *qm, const void *src) · line 629
Quoted 5 lines
drivers/crypto/hisilicon/qm.c +4
-0+#else +memcpy_toio (fun_base, src,16 ); +dma_wmb (); +#endif This version has the same problems, plus the write is not actually atomic. I wonder if a pair of
writeq()calls would just do the right thing here for both arm64 and others, or possibly awriteq()followed by awriteq_relaxed()to avoid the extradmb()in the middle.
Quoted 3 lines
Arnd
.
We have to do a 128bit atomic write here to trigger a mailbox. The reason is that the PF and related VFs of a hardware cannot write mailbox MMIO at the same time.
For this SoC(Kunpeng) which has QM, if the address is 128bit aligned, stp will be atomic. The offset of QM mailbox is 128bit aligned, so it is safe here.
Best regards,
Weili
Re: [PATCH V4 23/23] crypto: hisilicon/qm: Workaround to enable build with RISC-V clang
Quoted 42 lines · Weili Qian
Quoted 35 lines · Arnd Bergmann
Quoted 9 lines · Sunil V L
With
CONFIG_ACPIenabled for RISC-V, this driver gets enabled in allmodconfig build. The gcc tool chain builds this driver removing the inline arm64 assembly code. However, clang for RISC-V tries to build the arm64 assembly and below error is seen.
drivers/crypto/hisilicon/qm.c:627:10: error: invalid output constraint '+Q' in asm"+Q" (*((char __iomem *)fun_base)) ^Quoted 7 lines
It appears that RISC-V clang is not smart enough to detect
IS_ENABLED(CONFIG_ARM64)and remove the dead code.As a workaround, move this check to preprocessing stage which works with the RISC-V clang tool chain.
Signed-off-by Sunil V L <[email protected]>Your patch looks correct for this particular problem, but I see that there are a couple of other issues in the same function:
drivers/crypto/hisilicon/qm.c static void qm_mb_write(struct hisi_qm *qm, const · line 626
Quoted 11 lines
drivers/crypto/hisilicon/qm.c +2
-1- } +#if IS_ENABLED (CONFIG_ARM64 ) +unsigned long tmp0 =0 , tmp1 =0 ; asmvolatile ("ldp %0, %1, %3\n" "stp %0, %1, %2\n"@@ -627,6 +623,11 @@ static void qm_mb_write(struct hisi_qm *qm, const void *src) "+Q" (*((char __iomem *)fun_base)) : "Q" (*((char *)src)) : "memory");For the arm64 version:
Quoted 6 lines
- the "dmb oshst" barrier needs to come before the stp, not after it, otherwise there is no guarantee that data written to memory is visible by the device when the mailbox gets triggered
- The input/output arguments need to be pointers to 128-bit types, either a struct or a__uint128_t
- this lacks a byteswap on big-endian kernels
Quoted 5 lines
Sorry for the late reply.
- the execution order relies on the data dependency between ldp and stp:
load "src" to "tmp0" and "tmp1", then
store "tmp0" and "tmp1" to "fun_base";
Not entirely sure how that data dependency would help serialize the store into the DMA buffer against the device access. The problem here is not the qm_mailbox structure but the data pointed to by the 'u64 base' (e.g. struct qm_eqc *eqc) which may still be in a store buffer waiting to make it to physical memory at the time the mailbox store triggers the DMA from the device.
Quoted 3 lines
The "dmb oshst" is used to ensure that the stp instruction has been executed before CPU checking mailbox status. Whether the execution order cannot be guaranteed via data dependency?
There is no need to have barriers between MMIO operations, they are implicitly serialized already. In this case specifically, the read is even on the same address as the write. Note that the "dmb oshst" does not actually guarantee that the store has made it to the device, as (at least on PCIe semantics) it can be posted, but the read from the same address does guarantee that the write is completed first, and this may be required to ensure that it does not complete after the mutex_unlock().
Quoted 10 lines
- The input argument "src" is struct "struct
qm_mailbox".
- Before call this funcion, the data has been byteswapped.mailbox->w0 = cpu_to_le16((cmd) | ((op) ? 0x1 << QM_MB_OP_SHIFT : 0) | (0x1 << QM_MB_BUSY_SHIFT)); mailbox->queue_num = cpu_to_le16(queue); mailbox->base_l = cpu_to_le32(lower_32_bits(base)); mailbox->base_h = cpu_to_le32(upper_32_bits(base)); mailbox->rsvd = 0;
Right, this bit does look correct.
Arnd
Quoted 2 lines · Sunil V L
Changes since V3:
1) Added two more driver patches to workaround allmodconfig build failure.
btw, you need to fix the issues *before* you enable ACPI, not after.