hv: riscv: add check for other memory mode

Check whether SV48 is supported, panic if not.

Tracked-On: #8831
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Liu, Yifan1 <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
This commit is contained in:
hangliu1
2025-10-15 15:55:05 +08:00
committed by acrnsi-robot
parent a6e0cba89b
commit 47ed22bef8
2 changed files with 22 additions and 5 deletions

View File

@@ -7,6 +7,7 @@
#include <rtl.h>
#include <mmu.h>
#include <asm/qemu.h>
#include <logmsg.h>
void set_paging_supervisor(__unused uint64_t base, __unused uint64_t size)
{
@@ -92,13 +93,27 @@ static uint64_t get_board_hv_device_size(void)
return 0x80000000UL;
}
static bool switch_satp(uint64_t satp_value)
{
/**
* Here is to detect whether SV48 is supported
* by the platform by writing the MODE in satp
* register, which is a WARL field. According to
* The RISC-V Instruction Set Manual volume II,
* if satp is written with an unsupported MODE,
* the entire write has no effect; no fields in
* satp are modified.
*/
set_satp(satp_value);
return (cpu_csr_read(satp) == satp_value);
}
/**
* TODO: need to detect existence of svpbmt extension to support PAGE_ATTR_IO
* and PAGE_ATTR_PMA for mapping.
*/
static void init_hv_mapping(void)
{
uint64_t satp;
ppt_mmu_top_addr = (uint64_t *)alloc_page(&ppt_page_pool);
pgtable_add_map((uint64_t *)ppt_mmu_top_addr, get_board_hv_device_start(),
@@ -111,9 +126,11 @@ static void init_hv_mapping(void)
CONFIG_HV_RAM_START, (&_code_end - &_code_start),
PAGE_V | PAGE_X | PAGE_R | PAGE_W,
&ppt_pgtable);
satp = (uint64_t)ppt_mmu_top_addr;
init_satp = (satp >> 12) | SATP_MODE_SV48;
switch_satp(init_satp);
init_satp = ((uint64_t)ppt_mmu_top_addr >> PAGE_SHIFT) | SATP_MODE_SV48;
if (!switch_satp(init_satp)) {
panic("Only support SV48 mode !");
}
}
void init_paging(void)

View File

@@ -10,7 +10,7 @@
#include <asm/page.h>
#include <asm/pgtable.h>
static inline void switch_satp(uint64_t satp)
static inline void set_satp(uint64_t satp)
{
asm volatile (
"csrw satp, %0\n\t" \