Skip to contentSkip to conversation

RISC-V: ACPI improvements

PATCH Applied Sunil V L 7 participants 18 messages Sep 27, 2023 – Oct 27, 2023

Subsystems (4)

v2 of 4 Applied Latest is v4 →

lore
Share & tools
lore

Sunil V L

author maintainer
#0 lore raw

v2 cover RISC-V: ACPI improvements

This series is a set of patches which were originally part of RFC v1 series
[1] to add ACPI support in RISC-V interrupt controllers. Since these patches are independent of the interrupt controllers, creating this new series which helps to merge instead of waiting for big series.

This set of patches primarily adds support below ECR [2] which is approved by the ASWG and adds below features.

- Get CBO block sizes from RHCT on ACPI based systems.
- Set timer_can_not_wakeup in timer driver based on the flag in RHCT.

Additionally, the series contains a patch to improve acpi_os_ioremap().

[1] - https://lore.kernel.org/lkml/[email protected]/
[2] - https://drive.google.com/file/d/1sKbOa8m1UZw1JkquZYe3F1zQBN1xXsaf/view?usp=sharing

Changes since RFC v1:
1) Separated the patches from interrupt controller support series.
2) Addressed feedback from Andy and Drew.
3) Rebased to Palmer's for-next tree.
4) Added RB tags received on RFC v1.

Sunil V L (4):
RISC-V: ACPI: Enhance acpi_os_ioremap with MMIO remapping
RISC-V: ACPI: RHCT: Add function to get CBO block sizes
RISC-V: cacheflush: Initialize CBO variables on ACPI systems clocksource/timer-riscv: ACPI: Add timer_cannot_wakeup_cpu

 arch/riscv/Kconfig                |  1 +
 arch/riscv/include/asm/acpi.h     |  9 ++++
 arch/riscv/kernel/acpi.c          | 87 ++++++++++++++++++++++++++++++-
 arch/riscv/mm/cacheflush.c        | 37 ++++++++++---
 drivers/acpi/riscv/rhct.c         | 72 ++++++++++++++++++++++++-
 drivers/clocksource/timer-riscv.c |  4 ++
 6 files changed, 201 insertions(+), 9 deletions(-)
Signature · 1 line
2.39.2
author maintainer
#1 lore raw

PATCH v2 1/4 RISC-V: ACPI: Enhance acpi_os_ioremap with MMIO remapping

Enhance the acpi_os_ioremap() to support opregions in MMIO space. Also, have strict checks using EFI memory map to allow remapping the RAM similar to arm64.

---
 arch/riscv/Kconfig       |  1 +
 arch/riscv/kernel/acpi.c | 87 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 86 insertions(+), 2 deletions(-)
arch/riscv/Kconfig +1 -0
index d607ab0f7c6d..ac039cf8af7a 100644
@@ -39,6 +39,7 @@ config RISCV
 	select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
 	select ARCH_HAS_UBSAN_SANITIZE_ALL
 	select ARCH_HAS_VDSO_DATA
+	select ARCH_KEEP_MEMBLOCK
 	select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX
 	select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT
 	select ARCH_STACKWALK
arch/riscv/kernel/acpi.c +85 -2

101 lines not on this page · raw message

Signature · 1 line
2.39.2
Acked-by on v2 1/4
#2 lore raw

Re: [PATCH v2 -next 1/4] RISC-V: ACPI: Enhance acpi_os_ioremap with MMIO remapping

Quoted 6 lines · Sunil V L

Enhance the acpi_os_ioremap() to support opregions in MMIO space. Also, have strict checks using EFI memory map to allow remapping the RAM similar to arm64.

Thanks for resending this. If you respin, I think it would be worth mentioning here that you are aligning things with arm64.

Cheer,
Conor.

Quoted 127 lines
---
 arch/riscv/Kconfig       |  1 +
 arch/riscv/kernel/acpi.c | 87 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 86 insertions(+), 2 deletions(-)
arch/riscv/Kconfig +1 -0
index d607ab0f7c6d..ac039cf8af7a 100644
@@ -39,6 +39,7 @@ config RISCV
 	select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
 	select ARCH_HAS_UBSAN_SANITIZE_ALL
 	select ARCH_HAS_VDSO_DATA
+	select ARCH_KEEP_MEMBLOCK
 	select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX
 	select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT
 	select ARCH_STACKWALK
arch/riscv/kernel/acpi.c +85 -2
index 56cb2c986c48..e619edc8b0cc 100644
@@ -14,9 +14,10 @@
  */
 
 #include <linux/acpi.h>
+#include <linux/efi.h>
 #include <linux/io.h>
+#include <linux/memblock.h>
 #include <linux/pci.h>
-#include <linux/efi.h>
 
 int acpi_noirq = 1;		/* skip ACPI IRQ initialization */
 int acpi_disabled = 1;
@@ -217,7 +218,89 @@ void __init __acpi_unmap_table(void __iomem *map, unsigned long size)
 
 void __iomem *acpi_os_ioremap(acpi_physical_address phys, acpi_size size)
 {
-	return (void __iomem *)memremap(phys, size, MEMREMAP_WB);
+	efi_memory_desc_t *md, *region = NULL;
+	pgprot_t prot;
+
+	if (WARN_ON_ONCE(!efi_enabled(EFI_MEMMAP)))
+		return NULL;
+
+	for_each_efi_memory_desc(md) {
+		u64 end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT);
+
+		if (phys < md->phys_addr || phys >= end)
+			continue;
+
+		if (phys + size > end) {
+			pr_warn(FW_BUG "requested region covers multiple EFI memory regions\n");
+			return NULL;
+		}
+		region = md;
+		break;
+	}
+
+	/*
+	 * It is fine for AML to remap regions that are not represented in the
+	 * EFI memory map at all, as it only describes normal memory, and MMIO
+	 * regions that require a virtual mapping to make them accessible to
+	 * the EFI runtime services.
+	 */
+	prot = PAGE_KERNEL_IO;
+	if (region) {
+		switch (region->type) {
+		case EFI_LOADER_CODE:
+		case EFI_LOADER_DATA:
+		case EFI_BOOT_SERVICES_CODE:
+		case EFI_BOOT_SERVICES_DATA:
+		case EFI_CONVENTIONAL_MEMORY:
+		case EFI_PERSISTENT_MEMORY:
+			if (memblock_is_map_memory(phys) ||
+			    !memblock_is_region_memory(phys, size)) {
+				pr_warn(FW_BUG "requested region covers kernel memory\n");
+				return NULL;
+			}
+
+			/*
+			 * Mapping kernel memory is permitted if the region in
+			 * question is covered by a single memblock with the
+			 * NOMAP attribute set: this enables the use of ACPI
+			 * table overrides passed via initramfs.
+			 * This particular use case only requires read access.
+			 */
+			fallthrough;
+
+		case EFI_RUNTIME_SERVICES_CODE:
+			/*
+			 * This would be unusual, but not problematic per se,
+			 * as long as we take care not to create a writable
+			 * mapping for executable code.
+			 */
+			prot = PAGE_KERNEL_RO;
+			break;
+
+		case EFI_ACPI_RECLAIM_MEMORY:
+			/*
+			 * ACPI reclaim memory is used to pass firmware tables
+			 * and other data that is intended for consumption by
+			 * the OS only, which may decide it wants to reclaim
+			 * that memory and use it for something else. We never
+			 * do that, but we usually add it to the linear map
+			 * anyway, in which case we should use the existing
+			 * mapping.
+			 */
+			if (memblock_is_map_memory(phys))
+				return (void __iomem *)__va(phys);
+			fallthrough;
+
+		default:
+			if (region->attribute & EFI_MEMORY_WB)
+				prot = PAGE_KERNEL;
+			else if ((region->attribute & EFI_MEMORY_WC) ||
+				 (region->attribute & EFI_MEMORY_WT))
+				prot = pgprot_writecombine(PAGE_KERNEL);
+		}
+	}
+
+	return ioremap_prot(phys, size, pgprot_val(prot));
 }
 
 #ifdef CONFIG_PCI
Signature · 1 line
2.39.2
Reviewed-by on v2 1/4
#3 lore raw

Re: [PATCH v2 -next 1/4] RISC-V: ACPI: Enhance acpi_os_ioremap with MMIO remapping

In reply to Sunil V L

Hi Sunil,

Quoted 17 lines · Sunil V L

Enhance the acpi_os_ioremap() to support opregions in MMIO space. Also, have strict checks using EFI memory map to allow remapping the RAM similar to arm64.

---
 arch/riscv/Kconfig       |  1 +
 arch/riscv/kernel/acpi.c | 87 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 86 insertions(+), 2 deletions(-)
arch/riscv/Kconfig +0 -0
index d607ab0f7c6d..ac039cf8af7a 100644

arch/riscv/Kconfig config RISCV · line 42

Quoted 4 lines
arch/riscv/Kconfig +1 -0
@@ -39,6 +39,7 @@ config RISCV
        select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
        select ARCH_HAS_UBSAN_SANITIZE_ALL
        select ARCH_HAS_VDSO_DATA
+       select ARCH_KEEP_MEMBLOCK

Shouldn't we restrict this to ACPI?

Quoted 93 lines
arch/riscv/Kconfig +0 -0
        select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX
        select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT
        select ARCH_STACKWALK
arch/riscv/kernel/acpi.c +71 -2
index 56cb2c986c48..e619edc8b0cc 100644
@@ -14,9 +14,10 @@
  */
 
 #include <linux/acpi.h>
+#include <linux/efi.h>
 #include <linux/io.h>
+#include <linux/memblock.h>
 #include <linux/pci.h>
-#include <linux/efi.h>
 
 int acpi_noirq = 1;            /* skip ACPI IRQ initialization */
 int acpi_disabled = 1;
@@ -217,7 +218,89 @@ void __init __acpi_unmap_table(void __iomem *map, unsigned long size)
 
 void __iomem *acpi_os_ioremap(acpi_physical_address phys, acpi_size size)
 {
-       return (void __iomem *)memremap(phys, size, MEMREMAP_WB);
+       efi_memory_desc_t *md, *region = NULL;
+       pgprot_t prot;
+
+       if (WARN_ON_ONCE(!efi_enabled(EFI_MEMMAP)))
+               return NULL;
+
+       for_each_efi_memory_desc(md) {
+               u64 end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT);
+
+               if (phys < md->phys_addr || phys >= end)
+                       continue;
+
+               if (phys + size > end) {
+                       pr_warn(FW_BUG "requested region covers multiple EFI memory regions\n");
+                       return NULL;
+               }
+               region = md;
+               break;
+       }
+
+       /*
+        * It is fine for AML to remap regions that are not represented in the
+        * EFI memory map at all, as it only describes normal memory, and MMIO
+        * regions that require a virtual mapping to make them accessible to
+        * the EFI runtime services.
+        */
+       prot = PAGE_KERNEL_IO;
+       if (region) {
+               switch (region->type) {
+               case EFI_LOADER_CODE:
+               case EFI_LOADER_DATA:
+               case EFI_BOOT_SERVICES_CODE:
+               case EFI_BOOT_SERVICES_DATA:
+               case EFI_CONVENTIONAL_MEMORY:
+               case EFI_PERSISTENT_MEMORY:
+                       if (memblock_is_map_memory(phys) ||
+                           !memblock_is_region_memory(phys, size)) {
+                               pr_warn(FW_BUG "requested region covers kernel memory\n");
+                               return NULL;
+                       }
+
+                       /*
+                        * Mapping kernel memory is permitted if the region in
+                        * question is covered by a single memblock with the
+                        * NOMAP attribute set: this enables the use of ACPI
+                        * table overrides passed via initramfs.
+                        * This particular use case only requires read access.
+                        */
+                       fallthrough;
+
+               case EFI_RUNTIME_SERVICES_CODE:
+                       /*
+                        * This would be unusual, but not problematic per se,
+                        * as long as we take care not to create a writable
+                        * mapping for executable code.
+                        */
+                       prot = PAGE_KERNEL_RO;
+                       break;
+
+               case EFI_ACPI_RECLAIM_MEMORY:
+                       /*
+                        * ACPI reclaim memory is used to pass firmware tables
+                        * and other data that is intended for consumption by
+                        * the OS only, which may decide it wants to reclaim
+                        * that memory and use it for something else. We never
+                        * do that, but we usually add it to the linear map
+                        * anyway, in which case we should use the existing
+                        * mapping.
+                        */

arch/riscv/kernel/acpi.c void __init __acpi_unmap_table(void __iomem *map, unsigned long size) · line 299

Quoted 10 lines
arch/riscv/kernel/acpi.c +10 -0
+                       if (memblock_is_map_memory(phys))
+                               return (void __iomem *)__va(phys);
+                       fallthrough;
+
+               default:
+                       if (region->attribute & EFI_MEMORY_WB)
+                               prot = PAGE_KERNEL;
+                       else if ((region->attribute & EFI_MEMORY_WC) ||
+                                (region->attribute & EFI_MEMORY_WT))
+                               prot = pgprot_writecombine(PAGE_KERNEL);

I have to ask: why is write-through mapped to write-combined here?

Quoted 10 lines
arch/riscv/kernel/acpi.c +4 -1
+               }
+       }
+
+       return ioremap_prot(phys, size, pgprot_val(prot));
 }
 
 #ifdef CONFIG_PCI
--

2.39.2

Like Andrew said in v1, too bad we can't merge that with arm64 instead of duplicating.

But otherwise, you can add:

Thanks,

Alex

author maintainer
#4 lore raw

Re: [PATCH v2 -next 1/4] RISC-V: ACPI: Enhance acpi_os_ioremap with MMIO remapping

Hi Alex,

Quoted 15 lines · Alexandre Ghiti

Hi Sunil,

Quoted 12 lines · Sunil V L

Enhance the acpi_os_ioremap() to support opregions in MMIO space. Also, have strict checks using EFI memory map to allow remapping the RAM similar to arm64.

---
 arch/riscv/Kconfig       |  1 +
 arch/riscv/kernel/acpi.c | 87 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 86 insertions(+), 2 deletions(-)
Quoted 12 lines

arch/riscv/Kconfig config RISCV · line 42

Quoted 9 lines
arch/riscv/Kconfig +1 -0
index d607ab0f7c6d..ac039cf8af7a 100644
@@ -39,6 +39,7 @@ config RISCV
        select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
        select ARCH_HAS_UBSAN_SANITIZE_ALL
        select ARCH_HAS_VDSO_DATA
+       select ARCH_KEEP_MEMBLOCK

Shouldn't we restrict this to ACPI?

Sure, Let me update.

Quoted 97 lines
Quoted 97 lines
arch/riscv/Kconfig +0 -0
        select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX
        select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT
        select ARCH_STACKWALK
arch/riscv/kernel/acpi.c +75 -2
index 56cb2c986c48..e619edc8b0cc 100644
@@ -14,9 +14,10 @@
  */
 
 #include <linux/acpi.h>
+#include <linux/efi.h>
 #include <linux/io.h>
+#include <linux/memblock.h>
 #include <linux/pci.h>
-#include <linux/efi.h>
 
 int acpi_noirq = 1;            /* skip ACPI IRQ initialization */
 int acpi_disabled = 1;
@@ -217,7 +218,89 @@ void __init __acpi_unmap_table(void __iomem *map, unsigned long size)
 
 void __iomem *acpi_os_ioremap(acpi_physical_address phys, acpi_size size)
 {
-       return (void __iomem *)memremap(phys, size, MEMREMAP_WB);
+       efi_memory_desc_t *md, *region = NULL;
+       pgprot_t prot;
+
+       if (WARN_ON_ONCE(!efi_enabled(EFI_MEMMAP)))
+               return NULL;
+
+       for_each_efi_memory_desc(md) {
+               u64 end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT);
+
+               if (phys < md->phys_addr || phys >= end)
+                       continue;
+
+               if (phys + size > end) {
+                       pr_warn(FW_BUG "requested region covers multiple EFI memory regions\n");
+                       return NULL;
+               }
+               region = md;
+               break;
+       }
+
+       /*
+        * It is fine for AML to remap regions that are not represented in the
+        * EFI memory map at all, as it only describes normal memory, and MMIO
+        * regions that require a virtual mapping to make them accessible to
+        * the EFI runtime services.
+        */
+       prot = PAGE_KERNEL_IO;
+       if (region) {
+               switch (region->type) {
+               case EFI_LOADER_CODE:
+               case EFI_LOADER_DATA:
+               case EFI_BOOT_SERVICES_CODE:
+               case EFI_BOOT_SERVICES_DATA:
+               case EFI_CONVENTIONAL_MEMORY:
+               case EFI_PERSISTENT_MEMORY:
+                       if (memblock_is_map_memory(phys) ||
+                           !memblock_is_region_memory(phys, size)) {
+                               pr_warn(FW_BUG "requested region covers kernel memory\n");
+                               return NULL;
+                       }
+
+                       /*
+                        * Mapping kernel memory is permitted if the region in
+                        * question is covered by a single memblock with the
+                        * NOMAP attribute set: this enables the use of ACPI
+                        * table overrides passed via initramfs.
+                        * This particular use case only requires read access.
+                        */
+                       fallthrough;
+
+               case EFI_RUNTIME_SERVICES_CODE:
+                       /*
+                        * This would be unusual, but not problematic per se,
+                        * as long as we take care not to create a writable
+                        * mapping for executable code.
+                        */
+                       prot = PAGE_KERNEL_RO;
+                       break;
+
+               case EFI_ACPI_RECLAIM_MEMORY:
+                       /*
+                        * ACPI reclaim memory is used to pass firmware tables
+                        * and other data that is intended for consumption by
+                        * the OS only, which may decide it wants to reclaim
+                        * that memory and use it for something else. We never
+                        * do that, but we usually add it to the linear map
+                        * anyway, in which case we should use the existing
+                        * mapping.
+                        */
+                       if (memblock_is_map_memory(phys))
+                               return (void __iomem *)__va(phys);
+                       fallthrough;
+
Quoted 9 lines

arch/riscv/kernel/acpi.c void __init __acpi_unmap_table(void __iomem *map, unsigned long size) · line 299

Quoted 6 lines
arch/riscv/kernel/acpi.c +6 -0
+               default:
+                       if (region->attribute & EFI_MEMORY_WB)
+                               prot = PAGE_KERNEL;
+                       else if ((region->attribute & EFI_MEMORY_WC) ||
+                                (region->attribute & EFI_MEMORY_WT))
+                               prot = pgprot_writecombine(PAGE_KERNEL);

I have to ask: why is write-through mapped to write-combined here?

IIUC, write-through ensures the copy in the cache and memory are always in sync. So, instead of using WB, non-cacheable WC is used as RISC-V doesn't really define these attributes. Let me know if this is not correct.

Quoted 6 lines
Quoted 6 lines
arch/riscv/kernel/acpi.c +4 -0
+               }
+       }
+
+       return ioremap_prot(phys, size, pgprot_val(prot));
 }
 
Quoted 8 lines
Quoted 4 lines
arch/riscv/kernel/acpi.c +0 -1
 #ifdef CONFIG_PCI
--

2.39.2

Like Andrew said in v1, too bad we can't merge that with arm64 instead of duplicating.

I agree. But since acpi_os_ioremap() is supposed to be arch function, I kept is separate. Also, I need feedback from Ard whether we should make it common and where to add this common function.

Quoted 4 lines

But otherwise, you can add:

Thanks!
Sunil

author maintainer
#5 lore raw

PATCH v2 2/4 RISC-V: ACPI: RHCT: Add function to get CBO block sizes

In reply to Sunil V L

Cache Block Operation (CBO) related block size in ACPI is provided by RHCT. Add support to read the CMO node in RHCT to get this information.

---
 arch/riscv/include/asm/acpi.h |  9 +++++
 drivers/acpi/riscv/rhct.c     | 72 ++++++++++++++++++++++++++++++++++-
 2 files changed, 80 insertions(+), 1 deletion(-)
arch/riscv/include/asm/acpi.h +9 -0
index d5604d2073bc..0c4e8b35103e 100644
@@ -66,6 +66,8 @@ 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; }
+int acpi_get_cbo_block_size(struct acpi_table_header *table, unsigned int cpu, u32 *cbom_size,
+			    u32 *cboz_size, u32 *cbop_size);
 #else
 static inline void acpi_init_rintc_map(void) { }
 static inline struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu)
@@ -79,6 +81,13 @@ static inline int acpi_get_riscv_isa(struct acpi_table_header *table,
 	return -EINVAL;
 }
 
+static inline int acpi_get_cbo_block_size(struct acpi_table_header *table,
+					  unsigned int cpu, u32 *cbom_size,
+					  u32 *cboz_size, u32 *cbop_size)
+{
+	return -EINVAL;
+}
+
 #endif /* CONFIG_ACPI */
 
 #endif /*_ASM_ACPI_H*/
drivers/acpi/riscv/rhct.c +71 -1

87 lines not on this page · raw message

Signature · 1 line
2.39.2
author maintainer
#6 lore raw

PATCH v2 3/4 RISC-V: cacheflush: Initialize CBO variables on ACPI systems

In reply to Sunil V L

Using new interface to get the CBO block size information in RHCT, initialize the variables on ACPI platforms.

---
 arch/riscv/mm/cacheflush.c | 37 +++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)
arch/riscv/mm/cacheflush.c +31 -6
index f1387272a551..8e59644e473c 100644
@@ -3,7 +3,9 @@
  * Copyright (C) 2017 SiFive
  */
 
+#include <linux/acpi.h>
 #include <linux/of.h>
+#include <asm/acpi.h>
 #include <asm/cacheflush.h>
 
 #ifdef CONFIG_SMP
@@ -124,15 +126,38 @@ void __init riscv_init_cbo_blocksizes(void)
 	unsigned long cbom_hartid, cboz_hartid;
 	u32 cbom_block_size = 0, cboz_block_size = 0;
 	struct device_node *node;
+	struct acpi_table_header *rhct;
+	acpi_status status;
+	unsigned int cpu;
+
+	if (!acpi_disabled) {
+		status = acpi_get_table(ACPI_SIG_RHCT, 0, &rhct);
+		if (ACPI_FAILURE(status))
+			return;
+	}
 
-	for_each_of_cpu_node(node) {
-		/* set block-size for cbom and/or cboz extension if available */
-		cbo_get_block_size(node, "riscv,cbom-block-size",
-				   &cbom_block_size, &cbom_hartid);
-		cbo_get_block_size(node, "riscv,cboz-block-size",
-				   &cboz_block_size, &cboz_hartid);
+	for_each_possible_cpu(cpu) {
+		if (acpi_disabled) {
+			node = of_cpu_device_node_get(cpu);
+			if (!node) {
+				pr_warn("Unable to find cpu node\n");
+				continue;
+			}
+
+			/* set block-size for cbom and/or cboz extension if available */
+			cbo_get_block_size(node, "riscv,cbom-block-size",
+					   &cbom_block_size, &cbom_hartid);
+			cbo_get_block_size(node, "riscv,cboz-block-size",
+					   &cboz_block_size, &cboz_hartid);
+		} else {
+			acpi_get_cbo_block_size(rhct, cpu, &cbom_block_size,
+						&cboz_block_size, NULL);
+		}
 	}
 
+	if (!acpi_disabled && rhct)
+		acpi_put_table((struct acpi_table_header *)rhct);
+
 	if (cbom_block_size)
 		riscv_cbom_block_size = cbom_block_size;
 
Signature · 1 line
2.39.2
Reviewed-by on v2 3/4
#7 lore raw

Re: [PATCH v2 -next 3/4] RISC-V: cacheflush: Initialize CBO variables on ACPI systems

Quoted 4 lines · Sunil V L

Using new interface to get the CBO block size information in RHCT, initialize the variables on ACPI platforms.

Otherwise,

Thanks,
Conor.

Quoted 66 lines
---
 arch/riscv/mm/cacheflush.c | 37 +++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)
arch/riscv/mm/cacheflush.c +31 -6
index f1387272a551..8e59644e473c 100644
@@ -3,7 +3,9 @@
  * Copyright (C) 2017 SiFive
  */
 
+#include <linux/acpi.h>
 #include <linux/of.h>
+#include <asm/acpi.h>
 #include <asm/cacheflush.h>
 
 #ifdef CONFIG_SMP
@@ -124,15 +126,38 @@ void __init riscv_init_cbo_blocksizes(void)
 	unsigned long cbom_hartid, cboz_hartid;
 	u32 cbom_block_size = 0, cboz_block_size = 0;
 	struct device_node *node;
+	struct acpi_table_header *rhct;
+	acpi_status status;
+	unsigned int cpu;
+
+	if (!acpi_disabled) {
+		status = acpi_get_table(ACPI_SIG_RHCT, 0, &rhct);
+		if (ACPI_FAILURE(status))
+			return;
+	}
 
-	for_each_of_cpu_node(node) {
-		/* set block-size for cbom and/or cboz extension if available */
-		cbo_get_block_size(node, "riscv,cbom-block-size",
-				   &cbom_block_size, &cbom_hartid);
-		cbo_get_block_size(node, "riscv,cboz-block-size",
-				   &cboz_block_size, &cboz_hartid);
+	for_each_possible_cpu(cpu) {
+		if (acpi_disabled) {
+			node = of_cpu_device_node_get(cpu);
+			if (!node) {
+				pr_warn("Unable to find cpu node\n");
+				continue;
+			}
+
+			/* set block-size for cbom and/or cboz extension if available */
+			cbo_get_block_size(node, "riscv,cbom-block-size",
+					   &cbom_block_size, &cbom_hartid);
+			cbo_get_block_size(node, "riscv,cboz-block-size",
+					   &cboz_block_size, &cboz_hartid);
+		} else {
+			acpi_get_cbo_block_size(rhct, cpu, &cbom_block_size,
+						&cboz_block_size, NULL);
+		}
 	}
 
+	if (!acpi_disabled && rhct)
+		acpi_put_table((struct acpi_table_header *)rhct);
+
 	if (cbom_block_size)
 		riscv_cbom_block_size = cbom_block_size;
 
Signature · 1 line
2.39.2
#8 lore raw

Re: [PATCH v2 -next 3/4] RISC-V: cacheflush: Initialize CBO variables on ACPI systems

In reply to Sunil V L
Quoted 45 lines · Sunil V L

Using new interface to get the CBO block size information in RHCT, initialize the variables on ACPI platforms.

---
 arch/riscv/mm/cacheflush.c | 37 +++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)
arch/riscv/mm/cacheflush.c +14 -6
index f1387272a551..8e59644e473c 100644
@@ -3,7 +3,9 @@
  * Copyright (C) 2017 SiFive
  */
 
+#include <linux/acpi.h>
 #include <linux/of.h>
+#include <asm/acpi.h>
 #include <asm/cacheflush.h>
 
 #ifdef CONFIG_SMP
@@ -124,15 +126,38 @@ void __init riscv_init_cbo_blocksizes(void)
 	unsigned long cbom_hartid, cboz_hartid;
 	u32 cbom_block_size = 0, cboz_block_size = 0;
 	struct device_node *node;
+	struct acpi_table_header *rhct;
+	acpi_status status;
+	unsigned int cpu;
+
+	if (!acpi_disabled) {
+		status = acpi_get_table(ACPI_SIG_RHCT, 0, &rhct);
+		if (ACPI_FAILURE(status))
+			return;
+	}
 
-	for_each_of_cpu_node(node) {
-		/* set block-size for cbom and/or cboz extension if available */
-		cbo_get_block_size(node, "riscv,cbom-block-size",
-				   &cbom_block_size, &cbom_hartid);
-		cbo_get_block_size(node, "riscv,cboz-block-size",
-				   &cboz_block_size, &cboz_hartid);
+	for_each_possible_cpu(cpu) {
+		if (acpi_disabled) {
+			node = of_cpu_device_node_get(cpu);

arch/riscv/mm/cacheflush.c void __init riscv_init_cbo_blocksizes(void) · line 151

Quoted 10 lines
arch/riscv/mm/cacheflush.c +10 -0
+			if (!node) {
+				pr_warn("Unable to find cpu node\n");
+				continue;
+			}
+
+			/* set block-size for cbom and/or cboz extension if available */
+			cbo_get_block_size(node, "riscv,cbom-block-size",
+					   &cbom_block_size, &cbom_hartid);
+			cbo_get_block_size(node, "riscv,cboz-block-size",
+					   &cboz_block_size, &cboz_hartid);

This leaks a reference to the device node.

arch/riscv/mm/cacheflush.c void __init riscv_init_cbo_blocksizes(void) · line 154

Quoted 3 lines
arch/riscv/mm/cacheflush.c +3 -0
+		} else {
+			acpi_get_cbo_block_size(rhct, cpu, &cbom_block_size,
+						&cboz_block_size, NULL);

This function loops through the whole RHCT already. Why do we need to call it for each CPU? Can't we just call it once, and have it do the same consistency checks as cbo_get_block_size()?

In that case, the DT path could keep the for_each_of_cpu_node() loop.

Regards,
Samuel

Quoted 9 lines
arch/riscv/mm/cacheflush.c +4 -0
+		}
 	}
 
+	if (!acpi_disabled && rhct)
+		acpi_put_table((struct acpi_table_header *)rhct);
+
 	if (cbom_block_size)
 		riscv_cbom_block_size = cbom_block_size;
 
author maintainer
#9 lore raw

Re: [PATCH v2 -next 3/4] RISC-V: cacheflush: Initialize CBO variables on ACPI systems

Quoted 50 lines · Samuel Holland
Quoted 49 lines · Sunil V L

Using new interface to get the CBO block size information in RHCT, initialize the variables on ACPI platforms.

---
 arch/riscv/mm/cacheflush.c | 37 +++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)
arch/riscv/mm/cacheflush.c +18 -6
index f1387272a551..8e59644e473c 100644
@@ -3,7 +3,9 @@
  * Copyright (C) 2017 SiFive
  */
 
+#include <linux/acpi.h>
 #include <linux/of.h>
+#include <asm/acpi.h>
 #include <asm/cacheflush.h>
 
 #ifdef CONFIG_SMP
@@ -124,15 +126,38 @@ void __init riscv_init_cbo_blocksizes(void)
 	unsigned long cbom_hartid, cboz_hartid;
 	u32 cbom_block_size = 0, cboz_block_size = 0;
 	struct device_node *node;
+	struct acpi_table_header *rhct;
+	acpi_status status;
+	unsigned int cpu;
+
+	if (!acpi_disabled) {
+		status = acpi_get_table(ACPI_SIG_RHCT, 0, &rhct);
+		if (ACPI_FAILURE(status))
+			return;
+	}
 
-	for_each_of_cpu_node(node) {
-		/* set block-size for cbom and/or cboz extension if available */
-		cbo_get_block_size(node, "riscv,cbom-block-size",
-				   &cbom_block_size, &cbom_hartid);
-		cbo_get_block_size(node, "riscv,cboz-block-size",
-				   &cboz_block_size, &cboz_hartid);
+	for_each_possible_cpu(cpu) {
+		if (acpi_disabled) {
+			node = of_cpu_device_node_get(cpu);
+			if (!node) {
+				pr_warn("Unable to find cpu node\n");
+				continue;
+			}
Quoted 9 lines

arch/riscv/mm/cacheflush.c void __init riscv_init_cbo_blocksizes(void) · line 151

Quoted 6 lines
arch/riscv/mm/cacheflush.c +6 -0
+
+			/* set block-size for cbom and/or cboz extension if available */
+			cbo_get_block_size(node, "riscv,cbom-block-size",
+					   &cbom_block_size, &cbom_hartid);
+			cbo_get_block_size(node, "riscv,cboz-block-size",
+					   &cboz_block_size, &cboz_hartid);

This leaks a reference to the device node.

Yep!. I missed of_node_put(). Let me add in next revision. Thanks!

Quoted 10 lines

arch/riscv/mm/cacheflush.c void __init riscv_init_cbo_blocksizes(void) · line 154

Quoted 3 lines
arch/riscv/mm/cacheflush.c +3 -0
+		} else {
+			acpi_get_cbo_block_size(rhct, cpu, &cbom_block_size,
+						&cboz_block_size, NULL);

This function loops through the whole RHCT already. Why do we need to call it for each CPU? Can't we just call it once, and have it do the same consistency checks as cbo_get_block_size()?

In that case, the DT path could keep the for_each_of_cpu_node() loop.

I kept the same logic as DT. Basically, by passing the cpu node, we will fetch the exact CPU's CBO property from RHCT. It is not clear to me why we overwrite the same variable with value from another cpu and whether we can return as soon as we get the CBO size for one CPU.

Drew, can we exit the loop if we get the CBO size for one CPU?

Thanks!
Sunil

#10 lore raw

Re: [PATCH v2 -next 3/4] RISC-V: cacheflush: Initialize CBO variables on ACPI systems

Quoted 70 lines · Sunil V L
Quoted 50 lines · Samuel Holland
Quoted 49 lines · Sunil V L

Using new interface to get the CBO block size information in RHCT, initialize the variables on ACPI platforms.

---
 arch/riscv/mm/cacheflush.c | 37 +++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)
arch/riscv/mm/cacheflush.c +18 -6
index f1387272a551..8e59644e473c 100644
@@ -3,7 +3,9 @@
  * Copyright (C) 2017 SiFive
  */
 
+#include <linux/acpi.h>
 #include <linux/of.h>
+#include <asm/acpi.h>
 #include <asm/cacheflush.h>
 
 #ifdef CONFIG_SMP
@@ -124,15 +126,38 @@ void __init riscv_init_cbo_blocksizes(void)
 	unsigned long cbom_hartid, cboz_hartid;
 	u32 cbom_block_size = 0, cboz_block_size = 0;
 	struct device_node *node;
+	struct acpi_table_header *rhct;
+	acpi_status status;
+	unsigned int cpu;
+
+	if (!acpi_disabled) {
+		status = acpi_get_table(ACPI_SIG_RHCT, 0, &rhct);
+		if (ACPI_FAILURE(status))
+			return;
+	}
 
-	for_each_of_cpu_node(node) {
-		/* set block-size for cbom and/or cboz extension if available */
-		cbo_get_block_size(node, "riscv,cbom-block-size",
-				   &cbom_block_size, &cbom_hartid);
-		cbo_get_block_size(node, "riscv,cboz-block-size",
-				   &cboz_block_size, &cboz_hartid);
+	for_each_possible_cpu(cpu) {
+		if (acpi_disabled) {
+			node = of_cpu_device_node_get(cpu);
+			if (!node) {
+				pr_warn("Unable to find cpu node\n");
+				continue;
+			}
Quoted 9 lines

arch/riscv/mm/cacheflush.c void __init riscv_init_cbo_blocksizes(void) · line 151

Quoted 6 lines
arch/riscv/mm/cacheflush.c +6 -0
+
+			/* set block-size for cbom and/or cboz extension if available */
+			cbo_get_block_size(node, "riscv,cbom-block-size",
+					   &cbom_block_size, &cbom_hartid);
+			cbo_get_block_size(node, "riscv,cboz-block-size",
+					   &cboz_block_size, &cboz_hartid);

This leaks a reference to the device node.

Yep!. I missed of_node_put(). Let me add in next revision. Thanks!

Quoted 8 lines

arch/riscv/mm/cacheflush.c void __init riscv_init_cbo_blocksizes(void) · line 154

Quoted 3 lines
arch/riscv/mm/cacheflush.c +3 -0
+		} else {
+			acpi_get_cbo_block_size(rhct, cpu, &cbom_block_size,
+						&cboz_block_size, NULL);

This function loops through the whole RHCT already. Why do we need to call it for each CPU? Can't we just call it once, and have it do the same consistency checks as cbo_get_block_size()?

Quoted 8 lines
Quoted 2 lines

In that case, the DT path could keep the for_each_of_cpu_node() loop.

I kept the same logic as DT. Basically, by passing the cpu node, we will fetch the exact CPU's CBO property from RHCT. It is not clear to me why we overwrite the same variable with value from another cpu and whether we can return as soon as we get the CBO size for one CPU.

Drew, can we exit the loop if we get the CBO size for one CPU?

We want to compare the values for each CPU with the first one we find in order to ensure they are consistent. I think Samuel is suggesting that we leave the DT path here the same, i.e. keep the for_each_of_cpu_node() loop, and then change acpi_get_cbo_block_size() to *not* take a cpu as input, but rather follow the same pattern as DT, which is to loop over all cpus doing a consistency check against the first cpu's CBO info.

Thanks,
drew

author maintainer
#11 lore raw

Re: [PATCH v2 -next 3/4] RISC-V: cacheflush: Initialize CBO variables on ACPI systems

Quoted 78 lines · Andrew Jones
Quoted 77 lines · Sunil V L
Quoted 50 lines · Samuel Holland
Quoted 49 lines · Sunil V L

Using new interface to get the CBO block size information in RHCT, initialize the variables on ACPI platforms.

---
 arch/riscv/mm/cacheflush.c | 37 +++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)
arch/riscv/mm/cacheflush.c +18 -6
index f1387272a551..8e59644e473c 100644
@@ -3,7 +3,9 @@
  * Copyright (C) 2017 SiFive
  */
 
+#include <linux/acpi.h>
 #include <linux/of.h>
+#include <asm/acpi.h>
 #include <asm/cacheflush.h>
 
 #ifdef CONFIG_SMP
@@ -124,15 +126,38 @@ void __init riscv_init_cbo_blocksizes(void)
 	unsigned long cbom_hartid, cboz_hartid;
 	u32 cbom_block_size = 0, cboz_block_size = 0;
 	struct device_node *node;
+	struct acpi_table_header *rhct;
+	acpi_status status;
+	unsigned int cpu;
+
+	if (!acpi_disabled) {
+		status = acpi_get_table(ACPI_SIG_RHCT, 0, &rhct);
+		if (ACPI_FAILURE(status))
+			return;
+	}
 
-	for_each_of_cpu_node(node) {
-		/* set block-size for cbom and/or cboz extension if available */
-		cbo_get_block_size(node, "riscv,cbom-block-size",
-				   &cbom_block_size, &cbom_hartid);
-		cbo_get_block_size(node, "riscv,cboz-block-size",
-				   &cboz_block_size, &cboz_hartid);
+	for_each_possible_cpu(cpu) {
+		if (acpi_disabled) {
+			node = of_cpu_device_node_get(cpu);
+			if (!node) {
+				pr_warn("Unable to find cpu node\n");
+				continue;
+			}
Quoted 9 lines

arch/riscv/mm/cacheflush.c void __init riscv_init_cbo_blocksizes(void) · line 151

Quoted 6 lines
arch/riscv/mm/cacheflush.c +6 -0
+
+			/* set block-size for cbom and/or cboz extension if available */
+			cbo_get_block_size(node, "riscv,cbom-block-size",
+					   &cbom_block_size, &cbom_hartid);
+			cbo_get_block_size(node, "riscv,cboz-block-size",
+					   &cboz_block_size, &cboz_hartid);

This leaks a reference to the device node.

Yep!. I missed of_node_put(). Let me add in next revision. Thanks!

Quoted 10 lines

arch/riscv/mm/cacheflush.c void __init riscv_init_cbo_blocksizes(void) · line 154

Quoted 3 lines
arch/riscv/mm/cacheflush.c +3 -0
+		} else {
+			acpi_get_cbo_block_size(rhct, cpu, &cbom_block_size,
+						&cboz_block_size, NULL);

This function loops through the whole RHCT already. Why do we need to call it for each CPU? Can't we just call it once, and have it do the same consistency checks as cbo_get_block_size()?

In that case, the DT path could keep the for_each_of_cpu_node() loop.

I kept the same logic as DT. Basically, by passing the cpu node, we will fetch the exact CPU's CBO property from RHCT. It is not clear to me why we overwrite the same variable with value from another cpu and whether we can return as soon as we get the CBO size for one CPU.

Quoted 9 lines
Quoted 1 line

Drew, can we exit the loop if we get the CBO size for one CPU?

We want to compare the values for each CPU with the first one we find in order to ensure they are consistent. I think Samuel is suggesting that we leave the DT path here the same, i.e. keep the for_each_of_cpu_node() loop, and then change acpi_get_cbo_block_size() to *not* take a cpu as input, but rather follow the same pattern as DT, which is to loop over all cpus doing a consistency check against the first cpu's CBO info.

Ahh OK. Thanks Drew and Samuel. Let me update as you suggested.

Thanks!
Sunil

author maintainer
#12 lore raw

PATCH v2 4/4 clocksource/timer-riscv: ACPI: Add timer_cannot_wakeup_cpu

In reply to Sunil V L

The timer capability to wakeup the cpu irrespective of its idle state is provided by the flag in RHCT. Update the timer code to set this flag.

---
 drivers/clocksource/timer-riscv.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/clocksource/timer-riscv.c +4 -0
index 9c8f3e2decc2..06f5bad3c3e0 100644
@@ -225,6 +225,10 @@ 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)
 {
+	struct acpi_table_rhct *rhct = (struct acpi_table_rhct *)table;
+
+	riscv_timer_cannot_wake_cpu = rhct->flags & ACPI_RHCT_TIMER_CANNOT_WAKEUP_CPU;
+
 	return riscv_timer_init_common();
 }
 
Signature · 1 line
2.39.2
Reviewed-by on v2 4/4
#13 lore raw

Re: [PATCH v2 -next 4/4] clocksource/timer-riscv: ACPI: Add timer_cannot_wakeup_cpu

Quoted 7 lines · Sunil V L

The timer capability to wakeup the cpu irrespective of its idle state is provided by the flag in RHCT. Update the timer code to set this flag.

---
 drivers/clocksource/timer-riscv.c | 4 ++++
 1 file changed, 4 insertions(+)
Reviewed-by on v2 4/4
#14 lore raw

Re: [PATCH v2 -next 4/4] clocksource/timer-riscv: ACPI: Add timer_cannot_wakeup_cpu

In reply to Sunil V L
Quoted 4 lines · Sunil V L

The timer capability to wakeup the cpu irrespective of its idle state is provided by the flag in RHCT. Update the timer code to set this flag.

Thanks,
Conor.

Quoted 27 lines
---
 drivers/clocksource/timer-riscv.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/clocksource/timer-riscv.c +4 -0
index 9c8f3e2decc2..06f5bad3c3e0 100644
@@ -225,6 +225,10 @@ 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)
 {
+	struct acpi_table_rhct *rhct = (struct acpi_table_rhct *)table;
+
+	riscv_timer_cannot_wake_cpu = rhct->flags & ACPI_RHCT_TIMER_CANNOT_WAKEUP_CPU;
+
 	return riscv_timer_init_common();
 }
 
Signature · 7 lines
2.39.2


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Reviewed-by on v2 4/4
#15 lore raw

Re: [PATCH v2 -next 4/4] clocksource/timer-riscv: ACPI: Add timer_cannot_wakeup_cpu

In reply to Sunil V L
Quoted 26 lines · Sunil V L

The timer capability to wakeup the cpu irrespective of its idle state is provided by the flag in RHCT. Update the timer code to set this flag.

---
 drivers/clocksource/timer-riscv.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/clocksource/timer-riscv.c +4 -0
index 9c8f3e2decc2..06f5bad3c3e0 100644
@@ -225,6 +225,10 @@ 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)
 {
+	struct acpi_table_rhct *rhct = (struct acpi_table_rhct *)table;
+
+	riscv_timer_cannot_wake_cpu = rhct->flags & ACPI_RHCT_TIMER_CANNOT_WAKEUP_CPU;
+
 	return riscv_timer_init_common();
 }
 
Signature · 1 line
2.39.2
#16 lore raw

Re: [PATCH v2 -next 4/4] clocksource/timer-riscv: ACPI: Add timer_cannot_wakeup_cpu

In reply to Sunil V L
Quoted 5 lines · Sunil V L

The timer capability to wakeup the cpu irrespective of its idle state is provided by the flag in RHCT. Update the timer code to set this flag.

---

Applied, thanks

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
merge bot Applied
#17 lore raw

[tip: timers/core] clocksource/timer-riscv: ACPI: Add timer_cannot_wakeup_cpu

In reply to Sunil V L
The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     d7f546c751e8c873302331af6a203ee61f894e9d
Gitweb:        https://git.kernel.org/tip/d7f546c751e8c873302331af6a203ee61f894e9d
Author:        Sunil V L <[email protected]>
AuthorDate:    Wed, 27 Sep 2023 22:30:15 +05:30
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Wed, 11 Oct 2023 12:06:41 +02:00

clocksource/timer-riscv: ACPI: Add timer_cannot_wakeup_cpu

The timer capability to wakeup the cpu irrespective of its idle state is provided by the flag in RHCT. Update the timer code to set this flag.

---
 drivers/clocksource/timer-riscv.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/clocksource/timer-riscv.c +4 -0
index da3071b..5019865 100644
@@ -212,6 +212,10 @@ 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)
 {
+	struct acpi_table_rhct *rhct = (struct acpi_table_rhct *)table;
+
+	riscv_timer_cannot_wake_cpu = rhct->flags & ACPI_RHCT_TIMER_CANNOT_WAKEUP_CPU;
+
 	return riscv_timer_init_common();
 }