Skip to content

Commit a91a9ff

Browse files
vlsunilpalmer-dabbelt
authored andcommitted
RISC-V: Add support to build the ACPI core
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.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. Signed-off-by: Sunil V L <[email protected]> Acked-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Conor Dooley <[email protected]> Reviewed-by: Palmer Dabbelt <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 214c236 commit a91a9ff

File tree

6 files changed

+166
-0
lines changed

6 files changed

+166
-0
lines changed

arch/riscv/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ config 32BIT
1212

1313
config RISCV
1414
def_bool y
15+
select ACPI_GENERIC_GSI if ACPI
16+
select ACPI_REDUCED_HARDWARE_ONLY if ACPI
1517
select ARCH_DMA_DEFAULT_COHERENT
1618
select ARCH_ENABLE_HUGEPAGE_MIGRATION if HUGETLB_PAGE && MIGRATION
1719
select ARCH_ENABLE_SPLIT_PMD_PTLOCK if PGTABLE_LEVELS > 2
@@ -707,6 +709,7 @@ config EFI
707709
depends on OF && !XIP_KERNEL
708710
depends on MMU
709711
default y
712+
select ARCH_SUPPORTS_ACPI if 64BIT
710713
select EFI_GENERIC_STUB
711714
select EFI_PARAMS_FROM_FDT
712715
select EFI_RUNTIME_WRAPPERS
@@ -816,3 +819,5 @@ source "drivers/cpufreq/Kconfig"
816819
endmenu # "CPU Power Management"
817820

818821
source "arch/riscv/kvm/Kconfig"
822+
823+
source "drivers/acpi/Kconfig"

arch/riscv/include/asm/acenv.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* RISC-V specific ACPICA environments and implementation
4+
*/
5+
6+
#ifndef _ASM_ACENV_H
7+
#define _ASM_ACENV_H
8+
9+
/* This header is required unconditionally by the ACPI core */
10+
11+
#endif /* _ASM_ACENV_H */

arch/riscv/include/asm/acpi.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Copyright (C) 2013-2014, Linaro Ltd.
4+
* Author: Al Stone <[email protected]>
5+
* Author: Graeme Gregory <[email protected]>
6+
* Author: Hanjun Guo <[email protected]>
7+
*
8+
* Copyright (C) 2021-2023, Ventana Micro Systems Inc.
9+
* Author: Sunil V L <[email protected]>
10+
*/
11+
12+
#ifndef _ASM_ACPI_H
13+
#define _ASM_ACPI_H
14+
15+
/* Basic configuration for ACPI */
16+
#ifdef CONFIG_ACPI
17+
18+
/* ACPI table mapping after acpi_permanent_mmap is set */
19+
void *acpi_os_ioremap(acpi_physical_address phys, acpi_size size);
20+
#define acpi_os_ioremap acpi_os_ioremap
21+
22+
#define acpi_strict 1 /* No out-of-spec workarounds on RISC-V */
23+
extern int acpi_disabled;
24+
extern int acpi_noirq;
25+
extern int acpi_pci_disabled;
26+
27+
static inline void disable_acpi(void)
28+
{
29+
acpi_disabled = 1;
30+
acpi_pci_disabled = 1;
31+
acpi_noirq = 1;
32+
}
33+
34+
static inline void enable_acpi(void)
35+
{
36+
acpi_disabled = 0;
37+
acpi_pci_disabled = 0;
38+
acpi_noirq = 0;
39+
}
40+
41+
/*
42+
* The ACPI processor driver for ACPI core code needs this macro
43+
* to find out whether this cpu was already mapped (mapping from CPU hardware
44+
* ID to CPU logical ID) or not.
45+
*/
46+
#define cpu_physical_id(cpu) cpuid_to_hartid_map(cpu)
47+
48+
/*
49+
* Since MADT must provide at least one RINTC structure, the
50+
* CPU will be always available in MADT on RISC-V.
51+
*/
52+
static inline bool acpi_has_cpu_in_madt(void)
53+
{
54+
return true;
55+
}
56+
57+
static inline void arch_fix_phys_package_id(int num, u32 slot) { }
58+
59+
#endif /* CONFIG_ACPI */
60+
61+
#endif /*_ASM_ACPI_H*/

arch/riscv/include/asm/cpu.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
3+
#ifndef _ASM_CPU_H
4+
#define _ASM_CPU_H
5+
6+
/* This header is required unconditionally by the ACPI core */
7+
8+
#endif /* _ASM_CPU_H */

arch/riscv/kernel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,4 @@ obj-$(CONFIG_COMPAT) += compat_signal.o
9292
obj-$(CONFIG_COMPAT) += compat_vdso/
9393

9494
obj-$(CONFIG_64BIT) += pi/
95+
obj-$(CONFIG_ACPI) += acpi.o

arch/riscv/kernel/acpi.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* RISC-V Specific Low-Level ACPI Boot Support
4+
*
5+
* Copyright (C) 2013-2014, Linaro Ltd.
6+
* Author: Al Stone <[email protected]>
7+
* Author: Graeme Gregory <[email protected]>
8+
* Author: Hanjun Guo <[email protected]>
9+
* Author: Tomasz Nowicki <[email protected]>
10+
* Author: Naresh Bhat <[email protected]>
11+
*
12+
* Copyright (C) 2021-2023, Ventana Micro Systems Inc.
13+
* Author: Sunil V L <[email protected]>
14+
*/
15+
16+
#include <linux/acpi.h>
17+
#include <linux/io.h>
18+
#include <linux/pci.h>
19+
20+
int acpi_noirq = 1; /* skip ACPI IRQ initialization */
21+
int acpi_disabled = 1;
22+
EXPORT_SYMBOL(acpi_disabled);
23+
24+
int acpi_pci_disabled = 1; /* skip ACPI PCI scan and IRQ initialization */
25+
EXPORT_SYMBOL(acpi_pci_disabled);
26+
27+
/*
28+
* __acpi_map_table() will be called before paging_init(), so early_ioremap()
29+
* or early_memremap() should be called here to for ACPI table mapping.
30+
*/
31+
void __init __iomem *__acpi_map_table(unsigned long phys, unsigned long size)
32+
{
33+
if (!size)
34+
return NULL;
35+
36+
return early_memremap(phys, size);
37+
}
38+
39+
void __init __acpi_unmap_table(void __iomem *map, unsigned long size)
40+
{
41+
if (!map || !size)
42+
return;
43+
44+
early_memunmap(map, size);
45+
}
46+
47+
void *acpi_os_ioremap(acpi_physical_address phys, acpi_size size)
48+
{
49+
return memremap(phys, size, MEMREMAP_WB);
50+
}
51+
52+
#ifdef CONFIG_PCI
53+
54+
/*
55+
* These interfaces are defined just to enable building ACPI core.
56+
* TODO: Update it with actual implementation when external interrupt
57+
* controller support is added in RISC-V ACPI.
58+
*/
59+
int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
60+
int reg, int len, u32 *val)
61+
{
62+
return PCIBIOS_DEVICE_NOT_FOUND;
63+
}
64+
65+
int raw_pci_write(unsigned int domain, unsigned int bus, unsigned int devfn,
66+
int reg, int len, u32 val)
67+
{
68+
return PCIBIOS_DEVICE_NOT_FOUND;
69+
}
70+
71+
int acpi_pci_bus_find_domain_nr(struct pci_bus *bus)
72+
{
73+
return -1;
74+
}
75+
76+
struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
77+
{
78+
return NULL;
79+
}
80+
#endif /* CONFIG_PCI */

0 commit comments

Comments
 (0)