Skip to content

Commit 32f9ac6

Browse files
buhenxihuanaarkegz
andauthored
Support rk3588 smp (#121)
- Adapt dcache for aarch64 - Support for rk3588 smp - Configure physical CPU ID for Rockchip 3588 VM and optimize vCPU startup logic - Add phys_cpu_ids configuration item in linux-rk3588-aarch64-smp.toml - Modify vcpu_run function to start corresponding vCPU according to configured physical CPU ID mapping - Optimize vCPU startup logic to improve system startup efficiency and stability - Move cache invalidators into `utils::arch` mod --------- Co-authored-by: Su Mingxian <aarkegz@gmail.com>
1 parent 0c9b89a commit 32f9ac6

18 files changed

+305
-6
lines changed

Cargo.lock

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ fs = ["axstd/fs"]
1515
[dependencies]
1616
log = "=0.4.21"
1717
bitflags = "2.2"
18+
cfg-if = "1.0"
1819
spin = "0.9"
1920
kspin = "0.1"
2021
lazyinit = "0.2"

Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# - `MODE`: Build mode: release, debug
99
# - `LOG:` Logging level: warn, error, info, debug, trace
1010
# - `V`: Verbose level: (empty), 1, 2
11+
# - `GICV3`: Enable GICv3 (default is n)
1112
# - `TARGET_DIR`: Artifact output directory (cargo target directory)
1213
# - `EXTRA_CONFIG`: Extra config specification file
1314
# - `OUT_CONFIG`: Final config file that takes effect
@@ -38,6 +39,7 @@ PLATFORM ?=
3839
SMP ?= 1
3940
MODE ?= release
4041
LOG ?= warn
42+
GICV3 ?= n
4143
V ?=
4244
EXTRA_CONFIG ?=
4345
OUT_CONFIG ?= $(PWD)/.axconfig.toml
@@ -108,6 +110,7 @@ export AX_LOG=$(LOG)
108110
export AX_TARGET=$(TARGET)
109111
export AX_IP=$(IP)
110112
export AX_GW=$(GW)
113+
export AX_GICV3=$(GICV3)
111114

112115
ifneq ($(filter $(MAKECMDGOALS),unittest unittest_no_fail_fast),)
113116
# When running unit tests, set `AX_CONFIG_PATH` to empty for dummy config
@@ -152,7 +155,7 @@ ifeq ($(PLAT_NAME), aarch64-raspi4)
152155
include scripts/make/raspi4.mk
153156
else ifeq ($(PLAT_NAME), aarch64-bsta1000b-virt-hv)
154157
include scripts/make/bsta1000b-fada.mk
155-
else ifeq ($(PLAT_NAME), aarch64-rk3588j)
158+
else ifeq ($(PLAT_NAME), aarch64-rk3588j-hv)
156159
include scripts/make/rk3588.mk
157160
endif
158161

configs/platforms/aarch64-qemu-virt-hv.toml

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ mmio-regions = [
3939
[0x0904_0000, 0x1000], # PL011 UART2
4040
[0x0910_0000, 0x1000], # PL031 RTC
4141
[0x0800_0000, 0x2_0000], # GICv2
42+
[0x080a_0000, 0xf6_0000], # GICv3 gicr
4243
[0x0a00_0000, 0x4000], # VirtIO
4344
[0x1000_0000, 0x2eff_0000], # PCI memory ranges (ranges 1: 32-bit MMIO space)
4445
[0x40_1000_0000, 0x1000_0000], # PCI config space
@@ -98,6 +99,9 @@ gicc-paddr = 0x0801_0000 # uint
9899
# GIC Distributor base address
99100
gicd-paddr = 0x0800_0000 # uint
100101

102+
# GIC Redistributor base address
103+
gicr-paddr = 0x080a_0000
104+
101105
# PSCI
102106
psci-method = "smc" # str
103107

configs/platforms/aarch64-rk3588j-hv.toml

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ uart-irq = 0x14d # uint
6262
gicd-paddr = 0xfe600000 # uint
6363
# GICR Address
6464
gicc-paddr = 0xfe680000 # uint
65+
# GICR Address
6566
gicr-paddr = 0xfe680000 # uint
6667

6768
# PSCI
+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# Vm base info configs
2+
#
3+
[base]
4+
# Guest vm id.
5+
id = 1
6+
# Guest vm name.
7+
name = "linux"
8+
# Virtualization type.
9+
vm_type = 1
10+
# The number of virtual CPUs.
11+
cpu_num = 4
12+
# Guest vm physical cpu sets.
13+
# phys_cpu_sets = [1, 2, 4, 8, 16, 32, 64, 128]
14+
phys_cpu_ids = [0x00, 0x100, 0x200, 0x300]
15+
phys_cpu_sets = [1, 2, 4, 8]
16+
17+
#
18+
# Vm kernel configs
19+
#
20+
[kernel]
21+
# The entry point of the kernel image.
22+
entry_point = 0x1008_0000
23+
# The load address of the kernel image.
24+
kernel_load_addr = 0x1008_0000
25+
# The load address of the device tree blob (DTB).
26+
dtb_load_addr = 0x1000_0000
27+
# The location of image: "memory" | "fs".
28+
# load from memory
29+
image_location = "memory"
30+
# The file path of the kernel image.
31+
kernel_path = "/path/to/linux-aarch64.bin"
32+
# The file path of the device tree blob (DTB).
33+
dtb_path = "/path/to/dtb"
34+
35+
# load from file system.
36+
# image_location = "fs".
37+
## The file path of the kernel image.
38+
# kernel_path = "linux-arceos-aarch64.bin"
39+
## The file path of the device tree blob (DTB).
40+
# dtb_path = "linux-rk3588.dtb"
41+
42+
## The file path of the ramdisk image.
43+
# ramdisk_path = ""
44+
## The load address of the ramdisk image.
45+
# ramdisk_load_addr = 0
46+
## The path of the disk image.
47+
# disk_path = "disk.img"
48+
49+
# Memory regions with format (`base_paddr`, `size`, `flags`, `map_type`).
50+
# For `map_type`, 0 means `MAP_ALLOC`, 1 means `MAP_IDENTICAL`.
51+
memory_regions = [
52+
# [0x0, 0x10_f000, 0x7, 1], # passthrough uncahed MAP_IDENTICAL
53+
[0x940_0000, 0xe6c00000, 0x7, 1], # ram 3G MAP_IDENTICAL
54+
# [0x4000_0000, 0x4000_0000, 0x7, 1], # ram 1G MAP_IDENTICAL
55+
]
56+
57+
#
58+
# Device specifications
59+
#
60+
[devices]
61+
# Emu_devices.
62+
# Name Base-Ipa Ipa_len Alloc-Irq Emu-Type EmuConfig.
63+
emu_devices = []
64+
65+
# Pass-through devices.
66+
# Name Base-Ipa Base-Pa Length Alloc-Irq.
67+
passthrough_devices = [
68+
[
69+
"ramoops",
70+
0x11_0000,
71+
0x11_0000,
72+
0xf_0000,
73+
0x17,
74+
],
75+
[
76+
"sram",
77+
0x10_f000,
78+
0x10_f000,
79+
0x1000,
80+
0x17,
81+
],
82+
[
83+
"gpu",
84+
0xfb00_0000,
85+
0xfb00_0000,
86+
0x20_0000,
87+
0x17,
88+
],
89+
[
90+
"uart8250 UART",
91+
0xfd00_0000,
92+
0xfd00_0000,
93+
0x200_0000,
94+
0x17,
95+
],
96+
[
97+
"usb",
98+
0xfc00_0000,
99+
0xfc00_0000,
100+
0x100_0000,
101+
0x17,
102+
],
103+
[
104+
"uncached",
105+
0x0,
106+
0x0,
107+
0x10_f000,
108+
0x17,
109+
],
110+
# [
111+
# "gicr",
112+
# 0xfe68_0000,
113+
# 0xfe68_0000,
114+
# 0x10_0000,
115+
# 0x1,
116+
# ],
117+
# [
118+
# "uncached",
119+
# 0xf300_0000,
120+
# 0xf300_0000,
121+
# 0x100_0000,
122+
# 0x17,
123+
# ],
124+
# [
125+
# "uncached",
126+
# 0xf400_0000,
127+
# 0xf400_0000,
128+
# 0x100_0000,
129+
# 0x17,
130+
# ],
131+
# [
132+
# "uncached",
133+
# 0xa_4100_0000,
134+
# 0xa_4100_0000,
135+
# 0x40_0000,
136+
# 0x17,
137+
# ],
138+
# [
139+
# "uncached",
140+
# 0xa_40c0_0000,
141+
# 0xa_40c0_0000,
142+
# 0x40_0000,
143+
# 0x17,
144+
# ],
145+
# [
146+
# "uncached",
147+
# 0x920_0000,
148+
# 0x920_0000,
149+
# 0x20_0000,
150+
# 0x17,
151+
# ],
152+
]
153+
154+
155+
# [0xfe600000, 0x10000], # gic-v3 gicd
156+
# [0xfe680000, 0x10_0000], # gic-v3 gicr
157+
158+
# [0xa41000000, 0x400000],
159+
# [0xa40c00000, 0x400000],
160+
# [0xf4000000,0x1000000],
161+
# [0xf3000000,0x1000000],

scripts/make/features.mk

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ ifeq ($(BUS),pci)
4848
ax_feat += bus-pci
4949
endif
5050

51+
ifeq ($(GICV3),y)
52+
ax_feat += gicv3
53+
endif
54+
5155
ifeq ($(shell test $(SMP) -gt 1; echo $$?),0)
5256
lib_feat += smp
5357
endif

scripts/make/qemu.mk

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ qemu_args-riscv64 := \
2424

2525
qemu_args-aarch64 := \
2626
-cpu cortex-a72 \
27-
-machine virt,virtualization=on,gic-version=2 \
2827
-kernel $(OUT_BIN)
2928

3029
qemu_args-y := -m $(MEM) -smp $(SMP) $(qemu_args-$(ARCH))
@@ -66,7 +65,11 @@ ifeq ($(GRAPHIC), n)
6665
endif
6766

6867
ifeq ($(ARCH), aarch64)
69-
qemu_args-y += -machine virtualization=on,gic-version=2
68+
ifeq ($(GICV3),y)
69+
qemu_args-y += -machine virt,virtualization=on,gic-version=3
70+
else
71+
qemu_args-y += -machine virt,virtualization=on,gic-version=2
72+
endif
7073
endif
7174

7275
ifeq ($(QEMU_LOG), y)

src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extern crate axstd as std;
1111
mod hal;
1212
mod logo;
1313
mod task;
14+
mod utils;
1415
mod vmm;
1516

1617
#[unsafe(no_mangle)]

src/utils/arch/aarch64/cache.S

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// void cache_invalidate_d(u64 start, u64 length);
2+
.global cache_invalidate_d
3+
cache_invalidate_d:
4+
add x2, x0, x1 /* calculate the end address */
5+
bic x0, x0, #(64 - 1) /* align the start with a cache line */
6+
1:
7+
dc ivac, x0 /* invalidate cache to PoC by VA */
8+
add x0, x0, #64
9+
cmp x0, x2
10+
blt 1b
11+
mov x0, xzr
12+
dsb sy
13+
ret
14+
15+
// void cache_clean_invalidate_d(u64 start, u64 length);
16+
.global cache_clean_invalidate_d
17+
cache_clean_invalidate_d:
18+
add x2, x0, x1 /* calculate the end address */
19+
bic x0, x0, #(64 - 1) /* align the start with a cache line */
20+
1:
21+
dc civac, x0 /* invalidate cache to PoC by VA */
22+
add x0, x0, #64
23+
cmp x0, x2
24+
blt 1b
25+
mov x0, xzr
26+
dsb sy
27+
ret

src/utils/arch/aarch64/cache.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use core::arch::global_asm;
2+
3+
global_asm!(include_str!("cache.S"));
4+
5+
unsafe extern "C" {
6+
/// Invalidate the data cache.
7+
pub unsafe fn cache_invalidate_d(start: usize, len: usize);
8+
/// Clean and invalidate the data cache.
9+
pub unsafe fn cache_clean_invalidate_d(start: usize, len: usize);
10+
}

src/utils/arch/aarch64/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/// Cache-related operations
2+
pub mod cache;

src/utils/arch/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//! Architecture-specific types and operations.
2+
3+
cfg_if::cfg_if! {
4+
if #[cfg(target_arch = "x86_64")] {
5+
mod x86_64;
6+
pub use self::x86_64::*;
7+
} else if #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] {
8+
mod riscv;
9+
pub use self::riscv::*;
10+
} else if #[cfg(target_arch = "aarch64")]{
11+
mod aarch64;
12+
pub use self::aarch64::*;
13+
}
14+
}

src/utils/arch/riscv/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// Cache-related operations
2+
pub mod cache {
3+
/// Invalidate the data cache.
4+
pub unsafe fn cache_invalidate_d(start: usize, len: usize) {
5+
// Dummy implementation
6+
}
7+
/// Clean and invalidate the data cache.
8+
pub unsafe fn cache_clean_invalidate_d(start: usize, len: usize) {
9+
// Dummy implementation
10+
}
11+
}

src/utils/arch/x86_64/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// Cache-related operations
2+
pub mod cache {
3+
/// Invalidate the data cache.
4+
pub unsafe fn cache_invalidate_d(start: usize, len: usize) {
5+
// Dummy implementation
6+
}
7+
/// Clean and invalidate the data cache.
8+
pub unsafe fn cache_clean_invalidate_d(start: usize, len: usize) {
9+
// Dummy implementation
10+
}
11+
}

src/utils/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
mod arch;
2+
3+
pub mod cache {
4+
/// Invalidate the data cache.
5+
pub unsafe fn cache_invalidate_d(start: usize, len: usize) {
6+
super::arch::cache::cache_invalidate_d(start, len);
7+
}
8+
/// Clean and invalidate the data cache.
9+
pub unsafe fn cache_clean_invalidate_d(start: usize, len: usize) {
10+
super::arch::cache::cache_clean_invalidate_d(start, len);
11+
}
12+
}

0 commit comments

Comments
 (0)