forked from Mirrors/opensbi

This reverts commit 6966ad0abe
("platform/lib: Allow the OS to map the
regions that are protected by PMP").
It was thought at the time of this commit that allowing the kernel to map
PMP protected regions was safe but it is actually not: for example, the
hibernation process will try to access any linear mapping page and then
will fault on such mapped PMP regions [1]. Another issue is that the
device tree specification [2] states that a !no-map region must be
declared as EfiBootServicesData/Code in the EFI memory map which would make
the PMP protected regions reclaimable by the kernel. And to circumvent
this, RISC-V edk2 diverges from the DT specification to declare those
regions as EfiReserved.
The no-map attribute was removed to allow the kernel to use hugepages
larger than 2MB to map the linear mapping to improve the performance but
actually a recent talk from Mike Rapoport [3] stated that the
performance benefit was marginal.
For all those reasons, let's mark all the PMP protected regions as "no-map".
[1] https://lore.kernel.org/linux-riscv/CAAYs2=gQvkhTeioMmqRDVGjdtNF_vhB+vm_1dHJxPNi75YDQ_Q@mail.gmail.com/
[2] "3.5.4 /reserved-memory and UEFI" https://github.com/devicetree-org/devicetree-specification/releases/download/v0.4-rc1/devicetree-specification-v0.4-rc1.pdf
[3] https://lwn.net/Articles/931406/
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Reviewed-by: Atish Patra <atishp@rivosinc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
112 lines
3.2 KiB
C
112 lines
3.2 KiB
C
// SPDX-License-Identifier: BSD-2-Clause
|
|
/*
|
|
* fdt_fixup.h - Flat Device Tree manipulation helper routines
|
|
* Implement platform specific DT fixups on top of libfdt.
|
|
*
|
|
* Copyright (C) 2020 Bin Meng <bmeng.cn@gmail.com>
|
|
*/
|
|
|
|
#ifndef __FDT_FIXUP_H__
|
|
#define __FDT_FIXUP_H__
|
|
|
|
struct sbi_cpu_idle_state {
|
|
const char *name;
|
|
uint32_t suspend_param;
|
|
bool local_timer_stop;
|
|
uint32_t entry_latency_us;
|
|
uint32_t exit_latency_us;
|
|
uint32_t min_residency_us;
|
|
uint32_t wakeup_latency_us;
|
|
};
|
|
|
|
/**
|
|
* Add CPU idle states to cpu nodes in the DT
|
|
*
|
|
* Add information about CPU idle states to the devicetree. This function
|
|
* assumes that CPU idle states are not already present in the devicetree, and
|
|
* that all CPU states are equally applicable to all CPUs.
|
|
*
|
|
* @param fdt: device tree blob
|
|
* @param states: array of idle state descriptions, ending with empty element
|
|
* @return zero on success and -ve on failure
|
|
*/
|
|
int fdt_add_cpu_idle_states(void *dtb, const struct sbi_cpu_idle_state *state);
|
|
|
|
/**
|
|
* Fix up the CPU node in the device tree
|
|
*
|
|
* This routine updates the "status" property of a CPU node in the device tree
|
|
* to "disabled" if that hart is in disabled state in OpenSBI.
|
|
*
|
|
* It is recommended that platform codes call this helper in their final_init()
|
|
*
|
|
* @param fdt: device tree blob
|
|
*/
|
|
void fdt_cpu_fixup(void *fdt);
|
|
|
|
/**
|
|
* Fix up the APLIC nodes in the device tree
|
|
*
|
|
* This routine disables APLIC nodes which are not accessible to the next
|
|
* booting stage based on currently assigned domain.
|
|
*
|
|
* It is recommended that platform codes call this helper in their final_init()
|
|
*
|
|
* @param fdt: device tree blob
|
|
*/
|
|
void fdt_aplic_fixup(void *fdt);
|
|
|
|
/**
|
|
* Fix up the IMSIC nodes in the device tree
|
|
*
|
|
* This routine disables IMSIC nodes which are not accessible to the next
|
|
* booting stage based on currently assigned domain.
|
|
*
|
|
* It is recommended that platform codes call this helper in their final_init()
|
|
*
|
|
* @param fdt: device tree blob
|
|
*/
|
|
void fdt_imsic_fixup(void *fdt);
|
|
|
|
/**
|
|
* Fix up the PLIC node in the device tree
|
|
*
|
|
* This routine updates the "interrupt-extended" property of the PLIC node in
|
|
* the device tree to hide the M-mode external interrupt from CPUs.
|
|
*
|
|
* It is recommended that platform codes call this helper in their final_init()
|
|
*
|
|
* @param fdt: device tree blob
|
|
*/
|
|
void fdt_plic_fixup(void *fdt);
|
|
|
|
/**
|
|
* Fix up the reserved memory node in the device tree
|
|
*
|
|
* This routine inserts a child node of the reserved memory node in the device
|
|
* tree that describes the protected memory region done by OpenSBI via PMP.
|
|
*
|
|
* It is recommended that platform codes call this helper in their final_init()
|
|
*
|
|
* @param fdt: device tree blob
|
|
* @return zero on success and -ve on failure
|
|
*/
|
|
int fdt_reserved_memory_fixup(void *fdt);
|
|
|
|
/**
|
|
* General device tree fix-up
|
|
*
|
|
* This routine do all required device tree fix-ups for a typical platform.
|
|
* It fixes up the PLIC node, IMSIC nodes, APLIC nodes, and the reserved
|
|
* memory node in the device tree by calling the corresponding helper
|
|
* routines to accomplish the task.
|
|
*
|
|
* It is recommended that platform codes call this helper in their final_init()
|
|
*
|
|
* @param fdt: device tree blob
|
|
*/
|
|
void fdt_fixups(void *fdt);
|
|
|
|
#endif /* __FDT_FIXUP_H__ */
|
|
|