Commit Graph

1392 Commits

Author SHA1 Message Date
Xue Bosheng
ca63f62af3 hv: move run_idle_thread to schedule file
move run_idle_thread and default_idle to schedule file as common
function.

Tracked-On: #8812
Signed-off-by: Xue Bosheng <bosheng.xue@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-30 12:31:07 +08:00
Haicheng Li
65927b4f03 hv: add arch_switch_to support for riscv
add stack_frame definition, and implement acrh_switch_to for riscv.

Tracked-On: #8812
Signed-off-by: Xue Bosheng <bosheng.xue@intel.com>
Signed-off-by: Haicheng Li <haicheng.li@outlook.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-30 12:31:07 +08:00
Xue Bosheng
d8970404e3 hv: move stack_frame out of vcpu
stack_frame is not only for vcpu thread, host thread needs
it, so move stack_frame out of vcpu file.

Tracked-On: #8812
Signed-off-by: Xue Bosheng <bosheng.xue@intel.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-30 12:31:07 +08:00
Xue Bosheng
e278b38ec4 hv: move percpu delivery mode and idle mode from common to x86
delivery mode and idle mode are x86 specific percpu, so move it from common to
x86 arch, also change the name of mode_to_idle to be idle_mode, change the name
of mode_to_kick_pcpu to be kick_pcpu_mode.

Tracked-On: #8812
Signed-off-by: Xue Bosheng <bosheng.xue@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-30 12:31:07 +08:00
Shiqing Gao
ca778139e6 hv: abstract IRQ related macros
Convert IRQ-related macros to static inline functions and introduce
wrappers for arch-specific implementations. This follows the style we
defined for multi-arch development.

This is a follow-up update for commit
a7239d126 ("[FIXME] hv: risc-v add denpended implementation in cpu.h").

CPU_IRQ_ENABLE_ON_CONFIG  -> local_irq_enable
CPU_IRQ_DISABLE_ON_CONFIG -> local_irq_disable
CPU_INT_ALL_DISABLE       -> local_irq_save
CPU_INT_ALL_RESTORE       -> local_irq_restore

Tracked-On: #8813
Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
2025-09-29 14:01:00 +08:00
Shiqing Gao
86b25ea9ac hv: riscv: fix strict-aliasing error in local_irq_save
Fix a compilation error that may occur in some environments due to an
inconsistent type cast. The compiler reports a strict-aliasing violation:
acrn-hypervisor/hypervisor/include/arch/riscv/asm/cpu.h:73:18:
error: dereferencing type-punned pointer will break strict-aliasing rules
[-Werror=strict-aliasing]
   73 |                 *(uint32_t *)(x) = val;
      |                  ^~~~~

Tracked-On: #8813
Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
2025-09-29 14:01:00 +08:00
Shiqing Gao
395a7c44bc hv: riscv: fix local_irq_save to only clear SIE bit
local_irq_save() is intended to read and clear the SIE bit in
sstatus (disabling interrupts). The current implementation mistakenly
clears all bits in sstatus.

This patch corrects the inline assembly so that only the SIE bit is affected,
ensuring proper interrupt save/disable semantics on RISC-V.

Fixes: a7239d126 ("[FIXME] hv: risc-v add denpended implementation in cpu.h")

Tracked-On: #8813
Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-29 14:01:00 +08:00
Haicheng Li
fc495b946a hv: riscv: irq: add interrupt initialization and handlers
This patch implements interrupt initialization and the basic
exception/interrupt handling flow on RISC-V.

init_interrupt() needs to be invoked during CPU initialization to
set up the trap vector and enable the interrupt.

RISC-V exception and interrupt handling includes:
- Saving and restoring CPU registers around traps
- Implementing handlers for:
  - Supervisor software interrupt
  - Supervisor timer interrupt
- Halting the CPU for all other interrupts and exceptions

------
TODOs:
1. add support for registering interrupt handlers via request_irq() and
   further adoption of the common IRQ framework.
2. add support for external interrupt.

Tracked-On: #8813
Signed-off-by: Haicheng Li <haicheng.li@intel.com>
Co-developed-by: Shiqing Gao <shiqing.gao@intel.com>
Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-29 14:01:00 +08:00
Haicheng Li
0fc843de84 hv: riscv: irq: add misc IRQ-dependent helpers
Introduce cpu_csr_clear() and cpu_dead(), which are required by
the exception and interrupt handler implementations.

Tracked-On: #8813
Signed-off-by: Haicheng Li <haicheng.li@intel.com>
Co-developed-by: Shiqing Gao <shiqing.gao@intel.com>
Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-29 14:01:00 +08:00
Haicheng Li
6276763cd5 hv: riscv: implement cpu_ctx_save and cpu_ctx_restore
Implement cpu_ctx_save and cpu_ctx_restore to save and restore CPU
registers around exception and interrupt handling on RISC-V.

Tracked-On: #8813
Signed-off-by: Haicheng Li <haicheng.li@intel.com>
Co-developed-by: Shiqing Gao <shiqing.gao@intel.com>
Signed-off-by: Yifan Liu <yifan1.liu@intel.com>
Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-29 14:01:00 +08:00
Jiaqing Zhao
5803232d83 hv: enable acrnlog in release builds
Enable acrnlog (memory logging) in release builds, default log level
is still controlled by DEBUG_OPTIONS/MEM_LOGLEVEL in scenario file.

Tracked-On: #8805
Signed-off-by: Jiaqing Zhao <jiaqing.zhao@linux.intel.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
2025-09-25 16:30:26 +08:00
Jian Jun Chen
17c9a4d7be hv: riscv: implement basic logic to bring up APs
This patch adds the basic logics to bring up all APs in the C
entry of BSP boot. The mapping between logcial CPU IDs and physical
hart IDs is setup based on the pre-generated data from config tool
by parsing the device tree. Logical CPU ID BSP_CPU_ID will always
map to the BSP hart ID. The per pCPU logic ID is saved in tp register.

Tracked-On: #8791
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-23 11:30:38 +08:00
Jian Jun Chen
43d6036694 hv: multi-arch: move SP_BOTTOM_MAGIC to common/cpu.h
Tracked-On: #8791
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-23 11:30:38 +08:00
Jian Jun Chen
0e6e6ca502 hv: riscv: add arch_asm_pause implementation
Extension Zihintpause (Pause hint) is mandatory for RVA23. asm_pause
is implemented based on "pause" instruction.

Tracked-On: #8791
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-23 11:30:38 +08:00
Jian Jun Chen
8d218c0b37 hv: multi-arch: move asm_pause to common
Tracked-On: #8791
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-23 11:30:38 +08:00
Jian Jun Chen
1949c0b52f hv: riscv: add get/set_pcpu_id and start_pcpus implementation
Use tp register to hold the current logical CPU ID. This follows the
same design as x86 which uses MSR_IA32_SYSENTER_CS for the same purpose.
riscv uses SBI HSM to start the APs.

Tracked-On: #8791
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-23 11:30:38 +08:00
Jian Jun Chen
033bb2e347 [FIXME] hv: riscv: add build dependencies temporarily
Add build dependencies temporarily for the followings:
- hva2hpa: include/arch/riscv/asm/pgtable.h

Tracked-On: #8791
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-23 11:30:38 +08:00
Jian Jun Chen
e5831fec1e hv: multi-arch: abstract some pcpu related interfaces and macros
The following pcpu related interfaces are moved into common:
- common/cpu.c::start_pcpus
- include/common/cpu.h::get_pcpu_id
- include/common/cpu.h::set_current_pcpu_id
Their arch specific implementations are moved into arch/$(ARCH):
- arch/$(ARCH)/cpu.c::arch_start_pcpu
- include/arch/$(ARCH)/asm/cpu.h::arch_get_pcpu_id
- include/arch/$(ARCH)/asm/cpu.h::arch_set_current_pcpu_id
The following interface is moved into common:
- pcpu_set_current_state (from arch/x86/cpu.c -> common/cpu.c)
The following MACROs are moved into include/common/cpu.h:
- CPU_UP_TIMEOUT
- CPU_DOWN_TIMEOUT
- BSP_CPU_ID
- INVALID_CPU_ID

Tracked-On: #8791
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-23 11:30:38 +08:00
Haicheng Li
b4092965a4 hv: riscv: add SBI HSM HART_START interface
Tracked-On: #8791
Signed-off-by: Haicheng Li <haicheng.li@intel.com>
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-23 11:30:38 +08:00
Haicheng Li
bb9817b866 hv: multi-arch add RISC-V bits library implementation
Follow multi-arch design, implement the mandatory arch bit ops
functions declared in common bits.h for risc-v support.

Tracked-On: #8803
Signed-off-by: Haicheng Li <haicheng.li@linux.intel.com>
Signed-off-by: Haoyu Tang <haoyu.tang@intel.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-22 10:52:06 +08:00
Haoyu Tang
a226b5f0ec hv: multi-arch reconstruct bits library
Extract common interface to include/lib/bits.h, and invoke the variant
implementation of arch.
Re-implement unlocked functions as C in common library.
Rename bitmap*lock() to bitmap*(), bitmap*nolock() to bitmap*non_atomic().

Tracked-On: #8803
Signed-off-by: Haoyu Tang <haoyu.tang@intel.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-22 10:52:06 +08:00
Haicheng Li
090aaf4c34 hv: multi-arch add RISC-V barrier library implementation
Follow multi-arch design, implement the mandatory arch barrier
functions declared in common barrier.h for risc-v support.

Tracked-On: #8803
Signed-off-by: Haicheng Li <haicheng.li@linux.intel.com>
Co-developed-by: Haoyu Tang <haoyu.tang@intel.com>
Signed-off-by: Haoyu Tang <haoyu.tang@intel.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-22 10:52:06 +08:00
Haoyu Tang
f67a437e5a hv: multi-arch construct barrier library
extract common barrier interface to include/lib/barrier.h,
and invoke the variant implementation of arch.

Tracked-On: #8803
Signed-off-by: Haoyu Tang <haoyu.tang@intel.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-22 10:52:06 +08:00
Haicheng Li
47944d975d hv: multi-arch add RISC-V atomic library implementation
Follow multi-arch design, implement the mandatory arch atomic
functions declared in common atomic.h for risc-v support.

Tracked-On: #8803
Signed-off-by: Haicheng Li <haicheng.li@linux.intel.com>
Co-developed-by: Haoyu Tang <haoyu.tang@intel.com>
Signed-off-by: Haoyu Tang <haoyu.tang@intel.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-22 10:52:06 +08:00
Haoyu Tang
286a7557bc hv: multi-arch reconstruct atomic library
extract common interface to include/lib/atomic.h,
and invoke the variant implementation of arch.

Tracked-On: #8803
Signed-off-by: Haoyu Tang <haoyu.tang@intel.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-22 10:52:06 +08:00
Haicheng Li
d22e21f484 hv: multi-arch add RISC-V spinlock library implementation
Follow multi-arch design, implement the mandatory arch spinlock
functions declared in common spinlock.h for risc-v support.

Tracked-On: #8803
Signed-off-by: Haicheng Li <haicheng.li@linux.intel.com>
Signed-off-by: Haoyu Tang <haoyu.tang@intel.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-22 10:52:06 +08:00
Haicheng Li
a7239d1268 [FIXME] hv: risc-v add denpended implementation in cpu.h
spinlock invokes CPU_INT_ALL_DISABLE & CPU_INT_ALL_RESTOE, bitops
invokes BITS_PER_LONG, add them to pass the build.

current implementation is macro, same as X86. later official mult-arch
change should refactor to static inline on both x86 and risc-v.

Tracked-On: #8803
Signed-off-by: Haicheng Li <haicheng.li@linux.intel.com>
Signed-off-by: Haoyu Tang <haoyu.tang@intel.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-22 10:52:06 +08:00
Haoyu Tang
3a74e62ec4 hv: multi-arch reconstruct spinlock library
Extract common interface to include/lib/spinlock.h, and invoke the
variant implementation of arch.
Refine assemble macro code in case that ASSEMBLER defined.

Tracked-On: #8803
Signed-off-by: Haoyu Tang <haoyu.tang@intel.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-22 10:52:06 +08:00
Haicheng Li
052a58d87d hv: multiarch: riscv: add two cpu interfaces
add wait_sync_change and arch_get_pcpu_num implementation for riscv.
MAX_PCPU_NUM comes from board_info.h generated by config tool.

v2->v3:
remove riscv cpu.c include asm/cpu.h

v1->v2:
implement arch_get_num_available_cpus();

Tracked-On: #8801
signed-off-by: Haicheng Li <haicheng.li@intel.com>
Co-developed-by: hangliu1 <hang1.liu@intel.com>
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Wang, Yu1 <yu1.wang@intel.com>
Reviewed-by: Liu, Yifan1 <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-19 15:04:55 +08:00
hangliu1
a72bd5e076 hv: multiarch: abstract pcpu related data from x86
Move phys_cpu_num and pcpu_active_bitmap to common, which could be
only accessed by interfaces provided by smp.h.

v2->v3:
1. move ALL_CPUS_MASK/AP_MASK to common cpu.h

v1->v2:
1. preserve phys_cpu_num in x86 but implement arch_get_num_available_cpus()
   to provide interface for common code to access.
2. change function name test_xx to check_xx

Tracked-On: #8801
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Wang, Yu1 <yu1.wang@intel.com>
Reviewed-by: Liu, Yifan1 <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-19 15:04:55 +08:00
hangliu1
0cd5567140 hv:multiarch:riscv: add dummy function
add dummy function bitmap_set_lock, need to be replaced
with real implementation.

Tracked-On: #8801
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Wang, Yu1 <yu1.wang@intel.com>
Reviewed-by: Liu, Yifan1 <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-19 15:04:55 +08:00
hangliu1
41f04b4e7a HV: abstract percpu structure from x86 arch
Move x86 architecture dependent per cpu data into a
seperate structure and embeded it in per_cpu_region.
caller could access architecture dependent member by
using prefix 'arch.'.

v2->v3:
move whose_iwkey, profiling_info and tsc_suspend to x86
v1->v2:
rebased on latest repo

Tracked-On: #8801
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Wang, Yu1 <yu1.wang@intel.com>
Reviewed-by: Liu, Yifan1 <yifan1.liu@intel.com>
Reviewed-by: Chen, Jian Jun<jian.jun.chen@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-19 15:04:55 +08:00
hangliu1
286c383b53 hv: multiarch: riscv: add dummy header for riscv
add dummy headrer file for early compile, should be replaced totally later.

Tracked-On: #8801
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Wang, Yu1 <yu1.wang@intel.com>
Reviewed-by: Liu, Yifan1 <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-19 15:04:55 +08:00
hangliu1
b5306f2a74 enable common code compile
enable riscv common file compile and add PAGE_SIZE
definition to make riscv compile pass.

Tracked-On: #8801
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Wang, Yu1 <yu1.wang@intel.com>
Reviewed-by: Liu, Yifan1 <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-19 15:04:55 +08:00
Shiqing Gao
037c479221 hv: ipi: drop arch_ prefix from IPI functions
Since there is no common IPI abstraction, the arch_ prefix is redundant.
This patch renames the functions as follows:
    - arch_send_dest_ipi_mask -> send_dest_ipi_mask
    - arch_send_single_ipi   -> send_single_ipi

Tracked-On: #8799
Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
2025-09-19 13:56:21 +08:00
Haicheng Li
f6bf0b809d risc-v: initial timer codes
This patch implements risc-v specific timer codes. Basically,
risc-v adapts to acrn timer framework with some specific
behaviors. So far, it enables sstc support in h-mode.

Tracked-On: #8792
Signed-off-by: Haicheng Li <haicheng.li@outlook.com>
Co-developed-by: Yong Li <yong.li@intel.com>
Signed-off-by: Yong Li <yong.li@intel.com>
Co-developed-by: Yi Y Sun <yi.y.sun@intel.com>
Signed-off-by: Yi Y Sun <yi.y.sun@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-17 08:55:12 +08:00
Haicheng Li
e09fc9a218 risc-v: add SBI timer interface
This patch adds sbi_set_timer() function to set timer through
SBI interface.

Tracked-On: #8792
Signed-off-by: Haicheng Li <haicheng.li@linux.intel.com>
Co-developed-by: Yi Y Sun <yi.y.sun@intel.com>
Signed-off-by: Yi Y Sun <yi.y.sun@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-17 08:55:12 +08:00
Haicheng Li
d074ce85eb hv: multi-arch add RISC-V memory library
RISC-V use common memory library.

Tracked-On: #8794
Signed-off-by: Haicheng Li <haicheng.li@linux.intel.com>
Co-developed-by: Haoyu Tang <haoyu.tang@intel.com>
Signed-off-by: Haoyu Tang <haoyu.tang@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-15 14:07:58 +08:00
Haicheng Li
7573e436a5 hv: multi-arch reconstruct memory library
Split common and X86 arch specific codes.
For arch without specific memory library,add common library
to use.

Tracked-On: #8794
Signed-off-by: Haicheng Li <haicheng.li@linux.intel.com>
Co-developed-by: Haoyu Tang <haoyu.tang@intel.com>
Signed-off-by: Haoyu Tang <haoyu.tang@intel.com>
Signed-off-by: Wang, Yu1 <yu1.wang@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-15 14:07:58 +08:00
Jian Jun Chen
b854a24109 hv: risc-v: add C entry function of BSP and APs
Tracked-On: #8788
Signed-off-by: Haicheng Li <haicheng.li@intel.com>
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-15 13:12:21 +08:00
Haicheng Li
f134e2b741 hv: smpcall: riscv: implement SMP call handlers
- Introduce arch/riscv/notify.c to implement RISC-V specific SMP call handlers.

Tracked-On: #8786
Signed-off-by: Haicheng Li <haicheng.li@intel.com>
Co-developed-by: Shiqing Gao <shiqing.gao@intel.com>
Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-09 16:37:04 +08:00
Shiqing Gao
b0a4c2d024 [FIXME] hv: smpcall: riscv: add placeholder implementations for dependent code
This patch provides dummy implementations of functions and data
structures required for the IPI and SMP call on RISC-V.
It serves as a placeholder to ensure RISC-V builds pass and
is not needed for the final merge.

Official implementations are still WIP by other engineers:

 - To be provided in the library patchset (by Haoyu):
    uint16_t ffs64(uint64_t value);
    bool bitmap_test(uint16_t nr, const volatile uint64_t *addr);
    void bitmap_clear_lock(uint16_t nr_arg, volatile uint64_t *addr);
    void bitmap_clear_nolock(uint16_t nr_arg, volatile uint64_t *addr);
    uint64_t atomic_cmpxchg64(volatile uint64_t *ptr, uint64_t old, uint64_t new);

 - To be provided in the platform initialization patchset (by Hang):
    void wait_sync_change(volatile const uint64_t *sync, uint64_t wake_sync);
    bool is_pcpu_active(uint16_t pcpu_id);
    uint16_t get_pcpu_id(void);

----------
Changelog:
 * Split per_cpu.h implementation into a separate commit.

Tracked-On: #8786
Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-09 16:37:04 +08:00
Haicheng Li
b8542f7def hv: riscv: per_cpu: add initial version
Since smpcall depends on the per_cpu_region data structure to access
smp_call_info_data, this patch adds the initial version of per_cpu
support on RISC-V. For now it only includes SMP call related info.

Further refinement will be done in the platform initialization patchset
(by Hang).

Tracked-On: #8786
Signed-off-by: Haicheng Li <haicheng.li@intel.com>
Co-developed-by: Shiqing Gao <shiqing.gao@intel.com>
Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-09 16:37:04 +08:00
Shiqing Gao
a5e46a70ff hv: smpcall: abstract a common SMP call framework
This patch:
 - abstracts the common logic from existing x86 implementation
 - moves x86-specific logic to arch/x86/notify.c

A new common/notify.{c,h} is introduced to provide a common SMP call framework for
multi-arch support in ACRN.
arch-specific files such as arch/{x86,riscv}/notify.c is aim to provide the
corresponding implementations respectively.

The framework provides the following common APIs:
 - init_smp_call(): initialize the SMP call support during pCPU initialization
 - handle_smp_call(): execute the SMP call notification handler
 - smp_call_function(): trigger the SMP call request to target pCPUs

Other SW modules should invoke these common APIs to perform arch-independent
SMP operations.

Two arch-specific hooks are abstracted:
 - arch_smp_call_kick_pcpu():
    - On x86, special handling is required when LAPIC is passthrough.
    - On RISC-V, a plain IPI is sufficient to kick the target pCPU.
 - arch_init_smp_call():
   - On x86, CPU initialization reserves dedicated vectors and
     registers callback handlers for purposes such as notifications
     or posted interrupts.
   - On RISC-V, no special handling is required at present; this
     can be extended in the future if needed.

----------
Changelog:
 * Merged the following two patches into one:
     [RFC PATCH v2 4/7] hv: introduce common/smp.{c,h}
     [RFC PATCH v2 5/7] hv: smpcall: x86: adapt to common SMP call
Tracked-On: #8786
Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-09 16:37:04 +08:00
Shiqing Gao
066d55c8c3 hv: ipi: x86: rename send_single_ipi() and send_dest_ipi_mask()
Rename send_single_ipi() and send_dest_ipi_mask() to
arch_send_single_ipi() and arch_send_dest_ipi_mask() in x86, to make the
naming consistent with the RISC-V implementation and reflect that these
functions are arch-specific.

Tracked-On: #8786
Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-09 16:37:04 +08:00
Shiqing Gao
89f0dc544c hv: ipi: x86: update send_dest_ipi_mask() prototype
Align the prototype of send_dest_ipi_mask() on x86 with the RISC-V
definition. dest_mask is updated from uint32_t to uint64_t:

    From: void send_dest_ipi_mask(uint32_t dest_mask, uint32_t vector)
    To:   void send_dest_ipi_mask(uint64_t dest_mask, uint32_t vector)

On RISC-V, send_dest_ipi_mask() is implemented using SBI interfaces,
where the dest_mask is defined as "unsigned long" in the SBI spec.

Tracked-On: #8786
Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-09 16:37:04 +08:00
Haicheng Li
0d630e8f37 hv: ipi: riscv: implement IPI using SBI interface
This patch implements the IPI for RISC-V using SBI interface.

There is no common IPI concept abstracted, due to the following reasons:
 - RISC-V:
   Software delivers an IPI to target CPUs via software interrupts.
   The interrupt number is fixed for each privilege mode (e.g.,
   Supervisor Software Interrupt = IRQ 1, Machine Software Interrupt = IRQ 3).
   The actual purpose of the IPI is indicated by an IPI message type,
   which is a software-level concept. When the IPI is received,
   the target CPU must check the message type to determine the required action.

 - x86:
   Software delivers an IPI to target CPUs using a specific vector number.
   During CPU initialization, software can assign dedicated vectors for
   particular purposes. When the IPI is received, the target CPU could
   directly invoke the handler bound to that vector.

Each architecture provides its own IPI implementation, and other SW modules
directly call these arch-specific functions.

------
Notes:
 * To ensure RISC-V builds pass, an empty `include/arch/riscv/asm/cpu.h`
   is added since `debug/logmsg.h` includes `asm/cpu.h`.
 * Implemented IPI functionality using the SBI IPI Extension (EID #0x735049).
   Legacy SBI extensions are not supported in ACRN.

----------
Changelog:
 * Updated commit message and code comments to state explicitly that
   legacy SBI extensions are not supported in ACRN.
 * Refined the prototype of sbi_send_ipi() to align with the SBI spec:
     From: int64_t sbi_send_ipi(uint64_t mask)
     To:   int64_t sbi_send_ipi(uint64_t mask, uint64_t mask_base)
   In ACRN it is invoked as sbi_send_ipi(dest_mask, 0UL), with mask_base
   set to 0UL.
 * Renamed send_single_ipi() and send_dest_ipi_mask() to
   arch_send_single_ipi() and arch_send_dest_ipi_mask() respectively.

Tracked-On: #8786
Signed-off-by: Haicheng Li <haicheng.li@intel.com>
Co-developed-by: Shiqing Gao <shiqing.gao@intel.com>
Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-09 16:37:04 +08:00
Haicheng Li
c4531e903c hv: riscv: implement SBI interfaces
This patch implements the common SBI interfaces, including
sbi_ecall(), common macros and data structures.

Changelog:
 * Renamed SBI_EXPERIMENTAL_x and SBI_VENDOR_x.
 * Added description for sbi_ecall().
 * Renamed SBI-related enums, macros, and data structures to align with
   the SBI specification.

Tracked-On: #8786
Signed-off-by: Haicheng Li <haicheng.li@intel.com>
Co-developed-by: Shiqing Gao <shiqing.gao@intel.com>
Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-09 16:37:04 +08:00
Jiaqing Zhao
1c7e1a192b hv: refactor hypervisor image size helper function
The hypervisor image size is determined at link time, but now it is
calculated and stored in a global variable during mmu initialization,
and the helper function reads from that variable. Change to calculate
it inside helper function to avoid inconsistency.

Tracked-On: #8738
Signed-off-by: Jiaqing Zhao <jiaqing.zhao@linux.intel.com>
Reviewed-by: Fei Li <fei1.li@intel.com>
2025-08-19 07:49:23 +00:00
Jiaqing Zhao
3c6aa23ab2 hv: instr_emul: Correct handling of instruction length
The VM-exit instruction length(VMX_EXIT_INSTR_LEN) in VMCS is undefined
on EPT violation, except during delivery of a software interrupt,
privileged software exception, or software exception[1]. Although CPU
is likely to set the field, it can be incorrect in certain cases, such
as cmp+jcc and test+jcc.

Since hypervisor does not know exactly how much bytes needed, and GVA
translation is costly, it first copies at most 15 (VIE_INST_SIZE) bytes
within the page, then decodes the instruction. If more bytes are needed
during decoding and copied length is less than 15, it copies remaining
bytes.

[1] 29.2.5, https://cdrdv2-public.intel.com/671200/325462-sdm-vol-1-2abcd-3abcd.pdf

Tracked-On: #8756
Signed-off-by: Jiaqing Zhao <jiaqing.zhao@linux.intel.com>
2025-08-19 07:49:23 +00:00