1
The following changes since commit 3b14a767eaca3df5534a162851f04787b363670e:
1
The following changes since commit b69801dd6b1eb4d107f7c2f643adf0a4e3ec9124:
2
2
3
Merge tag 'qemu-openbios-20240924' of https://github.com/mcayland/qemu into staging (2024-09-28 12:34:44 +0100)
3
Merge tag 'for_upstream' of https://git.kernel.org/pub/scm/virt/kvm/mst/qemu into staging (2025-02-22 05:06:39 +0800)
4
4
5
are available in the Git repository at:
5
are available in the Git repository at:
6
6
7
https://gitlab.com/gaosong/qemu.git tags/pull-loongarch-20240929
7
https://gitlab.com/bibo-mao/qemu.git tags/pull-loongarch-20250225
8
8
9
for you to fetch changes up to f7c8ef7bad7495d8c84b262a8b243efe39e56b13:
9
for you to fetch changes up to db369c11c90b35f3a6ab59ad78564aea5b30c3da:
10
10
11
hw/loongarch/fw_cfg: Build in common_ss[] (2024-09-29 16:22:56 +0800)
11
target/loongarch: Enable virtual extioi feature (2025-02-25 16:05:31 +0800)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
pull-loongarch-20240929
14
pull-loongarch-20250225 queue
15
15
16
----------------------------------------------------------------
16
----------------------------------------------------------------
17
Bibo Mao (3):
17
Bibo Mao (10):
18
acpi: ged: Add macro for acpi sleep control register
18
target/loongarch/gdbstub: Fix gdbstub incorrectly handling some registers
19
hw/loongarch/virt: Add FDT table support with acpi ged pm register
19
target/loongarch: Correct maximum physical address in KVM mode
20
target/loongarch: Avoid bits shift exceeding width of bool type
20
target/loongarch: Add post init function for kvm mode
21
target/loongarch: Move kvm specified vCPU property to kvm directory
22
target/loongarch: Add vCPU property for paravirt ipi feature
23
target/loongarch: Add paravirt ipi feature detection
24
target/loongarch: Enable paravirt ipi feature
25
target/loongarch: Add vCPU property for kvm steal time feature
26
target/loongarch: Add kvm steal time feature detection
27
target/loongarch: Enable virtual extioi feature
21
28
22
Jiaxun Yang (2):
29
Xianglai Li (1):
23
hw/loongarch/boot: Refactor EFI booting protocol generation
30
target/loongarch: fix vcpu reset command word issue
24
hw/loongarch/boot: Rework boot code generation
25
31
26
Philippe Mathieu-Daudé (2):
32
hw/loongarch/virt.c | 8 --
27
hw/loongarch/virt: Remove unnecessary 'cpu.h' inclusion
33
include/hw/loongarch/virt.h | 9 ++
28
hw/loongarch/fw_cfg: Build in common_ss[]
34
target/loongarch/cpu.c | 52 ++--------
29
35
target/loongarch/cpu.h | 13 +++
30
hw/acpi/generic_event_device.c | 6 +-
36
target/loongarch/gdbstub.c | 11 +-
31
hw/loongarch/boot.c | 321 +++++++++++++++++++++------------
37
target/loongarch/kvm/kvm.c | 186 +++++++++++++++++++++++++++++++++-
32
hw/loongarch/meson.build | 2 +-
38
target/loongarch/loongarch-qmp-cmds.c | 2 +-
33
hw/loongarch/virt.c | 39 ++++
39
7 files changed, 224 insertions(+), 57 deletions(-)
34
include/hw/acpi/generic_event_device.h | 7 +-
35
include/hw/loongarch/boot.h | 106 +++++++++--
36
include/hw/loongarch/virt.h | 1 -
37
target/loongarch/arch_dump.c | 6 +-
38
8 files changed, 342 insertions(+), 146 deletions(-)
39
40
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
1
From: Xianglai Li <lixianglai@loongson.cn>
2
2
3
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
3
When the KVM_REG_LOONGARCH_VCPU_RESET command word
4
Reviewed-by: Song Gao <gaosong@loongson.cn>
4
is sent to the kernel through the kvm_set_one_reg interface,
5
Message-Id: <20240927213254.17552-2-philmd@linaro.org>
5
the parameter source needs to be a legal address,
6
Signed-off-by: Song Gao <gaosong@loongson.cn>
6
otherwise the kernel will return an error and the command word
7
will fail to be sent.
8
9
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
10
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
11
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
7
---
12
---
8
include/hw/loongarch/virt.h | 1 -
13
target/loongarch/kvm/kvm.c | 9 ++++++++-
9
1 file changed, 1 deletion(-)
14
1 file changed, 8 insertions(+), 1 deletion(-)
10
15
11
diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h
16
diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
12
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
13
--- a/include/hw/loongarch/virt.h
18
--- a/target/loongarch/kvm/kvm.c
14
+++ b/include/hw/loongarch/virt.h
19
+++ b/target/loongarch/kvm/kvm.c
15
@@ -XXX,XX +XXX,XX @@
20
@@ -XXX,XX +XXX,XX @@ static int kvm_loongarch_get_lbt(CPUState *cs)
16
#ifndef HW_LOONGARCH_H
21
void kvm_arch_reset_vcpu(CPUState *cs)
17
#define HW_LOONGARCH_H
22
{
18
23
CPULoongArchState *env = cpu_env(cs);
19
-#include "target/loongarch/cpu.h"
24
+ int ret = 0;
20
#include "hw/boards.h"
25
+ uint64_t unused = 0;
21
#include "qemu/queue.h"
26
22
#include "hw/block/flash.h"
27
env->mp_state = KVM_MP_STATE_RUNNABLE;
28
- kvm_set_one_reg(cs, KVM_REG_LOONGARCH_VCPU_RESET, 0);
29
+ ret = kvm_set_one_reg(cs, KVM_REG_LOONGARCH_VCPU_RESET, &unused);
30
+ if (ret) {
31
+ error_report("Failed to set KVM_REG_LOONGARCH_VCPU_RESET: %s",
32
+ strerror(errno));
33
+ exit(EXIT_FAILURE);
34
+ }
35
}
36
37
static int kvm_loongarch_get_mpstate(CPUState *cs)
23
--
38
--
24
2.34.1
39
2.43.5
25
40
26
41
diff view generated by jsdifflib
New patch
1
Write operation with R32 (orig_a0) and R34 (CSR_BADV) is discarded on
2
gdbstub implementation for LoongArch system. And return value should
3
be register size rather than 0, since it is used to calculate offset of
4
next register such as R33 (PC) in function handle_write_all_regs().
1
5
6
Cc: qemu-stable@nongnu.org
7
Fixes: ca61e75071c6 ("target/loongarch: Add gdb support.")
8
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
9
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
10
---
11
target/loongarch/gdbstub.c | 11 ++++++-----
12
1 file changed, 6 insertions(+), 5 deletions(-)
13
14
diff --git a/target/loongarch/gdbstub.c b/target/loongarch/gdbstub.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/target/loongarch/gdbstub.c
17
+++ b/target/loongarch/gdbstub.c
18
@@ -XXX,XX +XXX,XX @@ int loongarch_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
19
{
20
CPULoongArchState *env = cpu_env(cs);
21
target_ulong tmp;
22
- int read_length;
23
int length = 0;
24
25
+ if (n < 0 || n > 34) {
26
+ return 0;
27
+ }
28
+
29
if (is_la64(env)) {
30
tmp = ldq_le_p(mem_buf);
31
- read_length = 8;
32
+ length = 8;
33
} else {
34
tmp = ldl_le_p(mem_buf);
35
- read_length = 4;
36
+ length = 4;
37
}
38
39
if (0 <= n && n < 32) {
40
env->gpr[n] = tmp;
41
- length = read_length;
42
} else if (n == 33) {
43
set_pc(env, tmp);
44
- length = read_length;
45
}
46
return length;
47
}
48
--
49
2.43.5
diff view generated by jsdifflib
New patch
1
On 3A5000 system, the physical address space width for host is 48,
2
however 47 bit for KVM VM. For KVM VM, size of physical address space is
3
the same with that of virtual user space address.
1
4
5
Here modify physical address space width with 47 bit in KVM mode.
6
7
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
8
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
9
---
10
target/loongarch/cpu.c | 10 ++++++++--
11
1 file changed, 8 insertions(+), 2 deletions(-)
12
13
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/target/loongarch/cpu.c
16
+++ b/target/loongarch/cpu.c
17
@@ -XXX,XX +XXX,XX @@ static void loongarch_la464_initfn(Object *obj)
18
{
19
LoongArchCPU *cpu = LOONGARCH_CPU(obj);
20
CPULoongArchState *env = &cpu->env;
21
- uint32_t data = 0;
22
+ uint32_t data = 0, field;
23
int i;
24
25
for (i = 0; i < 21; i++) {
26
@@ -XXX,XX +XXX,XX @@ static void loongarch_la464_initfn(Object *obj)
27
data = FIELD_DP32(data, CPUCFG1, ARCH, 2);
28
data = FIELD_DP32(data, CPUCFG1, PGMMU, 1);
29
data = FIELD_DP32(data, CPUCFG1, IOCSR, 1);
30
- data = FIELD_DP32(data, CPUCFG1, PALEN, 0x2f);
31
+ if (kvm_enabled()) {
32
+ /* GPA address width of VM is 47, field value is 47 - 1 */
33
+ field = 0x2e;
34
+ } else {
35
+ field = 0x2f; /* 48 bit - 1 */
36
+ }
37
+ data = FIELD_DP32(data, CPUCFG1, PALEN, field);
38
data = FIELD_DP32(data, CPUCFG1, VALEN, 0x2f);
39
data = FIELD_DP32(data, CPUCFG1, UAL, 1);
40
data = FIELD_DP32(data, CPUCFG1, RI, 1);
41
--
42
2.43.5
diff view generated by jsdifflib
New patch
1
Some features such as LBT and PMU are implemented in kvm mode,
2
With paravirt features in future, post init function is added
3
for kvm mode, so that property for these features will be created
4
in kvm post init function.
1
5
6
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
7
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
8
---
9
target/loongarch/cpu.c | 2 +-
10
target/loongarch/cpu.h | 8 ++++++++
11
target/loongarch/kvm/kvm.c | 4 ++++
12
3 files changed, 13 insertions(+), 1 deletion(-)
13
14
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/target/loongarch/cpu.c
17
+++ b/target/loongarch/cpu.c
18
@@ -XXX,XX +XXX,XX @@ void loongarch_cpu_post_init(Object *obj)
19
loongarch_set_pmu);
20
object_property_set_description(obj, "pmu",
21
"Set off to performance monitor unit.");
22
-
23
+ kvm_loongarch_cpu_post_init(cpu);
24
} else {
25
cpu->lbt = ON_OFF_AUTO_OFF;
26
cpu->pmu = ON_OFF_AUTO_OFF;
27
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
28
index XXXXXXX..XXXXXXX 100644
29
--- a/target/loongarch/cpu.h
30
+++ b/target/loongarch/cpu.h
31
@@ -XXX,XX +XXX,XX @@ static inline void cpu_get_tb_cpu_state(CPULoongArchState *env, vaddr *pc,
32
33
void loongarch_cpu_post_init(Object *obj);
34
35
+#ifdef CONFIG_KVM
36
+void kvm_loongarch_cpu_post_init(LoongArchCPU *cpu);
37
+#else
38
+static inline void kvm_loongarch_cpu_post_init(LoongArchCPU *cpu)
39
+{
40
+}
41
+#endif
42
+
43
#endif /* LOONGARCH_CPU_H */
44
diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
45
index XXXXXXX..XXXXXXX 100644
46
--- a/target/loongarch/kvm/kvm.c
47
+++ b/target/loongarch/kvm/kvm.c
48
@@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs)
49
return ret;
50
}
51
52
+void kvm_loongarch_cpu_post_init(LoongArchCPU *cpu)
53
+{
54
+}
55
+
56
int kvm_arch_destroy_vcpu(CPUState *cs)
57
{
58
return 0;
59
--
60
2.43.5
diff view generated by jsdifflib
1
From: Bibo Mao <maobibo@loongson.cn>
1
LBT and PMU feature is supported only in kvm mode, move property
2
about these two features to function kvm_loongarch_cpu_post_init().
2
3
3
Variable env->cf[i] is defined as bool type, it is treated as int type
4
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
4
with shift operation. However the max possible width is 56 for the shift
5
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
5
operation, exceeding the width of int type. And there is existing api
6
---
6
read_fcc() which is converted to u64 type with bitwise shift, it can be
7
target/loongarch/cpu.c | 40 ++------------------------------------
7
used to dump fp registers into coredump note segment.
8
target/loongarch/kvm/kvm.c | 35 +++++++++++++++++++++++++++++++++
9
2 files changed, 37 insertions(+), 38 deletions(-)
8
10
9
Resolves: Coverity CID 1561133
11
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
10
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-Id: <20240914064645.2099169-1-maobibo@loongson.cn>
13
Signed-off-by: Song Gao <gaosong@loongson.cn>
14
---
15
target/loongarch/arch_dump.c | 6 +-----
16
1 file changed, 1 insertion(+), 5 deletions(-)
17
18
diff --git a/target/loongarch/arch_dump.c b/target/loongarch/arch_dump.c
19
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
20
--- a/target/loongarch/arch_dump.c
13
--- a/target/loongarch/cpu.c
21
+++ b/target/loongarch/arch_dump.c
14
+++ b/target/loongarch/cpu.c
22
@@ -XXX,XX +XXX,XX @@ static int loongarch_write_elf64_fprpreg(WriteCoreDumpFunction f,
15
@@ -XXX,XX +XXX,XX @@ static void loongarch_set_lasx(Object *obj, bool value, Error **errp)
23
16
cpu->env.cpucfg[2] = FIELD_DP32(val, CPUCFG2, LASX, value);
24
loongarch_note_init(&note, s, "CORE", 5, NT_PRFPREG, sizeof(note.fpu));
17
}
25
note.fpu.fcsr = cpu_to_dump64(s, env->fcsr0);
18
19
-static bool loongarch_get_lbt(Object *obj, Error **errp)
20
-{
21
- return LOONGARCH_CPU(obj)->lbt != ON_OFF_AUTO_OFF;
22
-}
26
-
23
-
27
- for (i = 0; i < 8; i++) {
24
-static void loongarch_set_lbt(Object *obj, bool value, Error **errp)
28
- note.fpu.fcc |= env->cf[i] << (8 * i);
25
-{
29
- }
26
- LoongArchCPU *cpu = LOONGARCH_CPU(obj);
30
- note.fpu.fcc = cpu_to_dump64(s, note.fpu.fcc);
27
-
31
+ note.fpu.fcc = cpu_to_dump64(s, read_fcc(env));
28
- cpu->lbt = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
32
29
-}
33
for (i = 0; i < 32; ++i) {
30
-
34
note.fpu.fpr[i] = cpu_to_dump64(s, env->fpr[i].vreg.UD[0]);
31
-static bool loongarch_get_pmu(Object *obj, Error **errp)
32
-{
33
- return LOONGARCH_CPU(obj)->pmu != ON_OFF_AUTO_OFF;
34
-}
35
-
36
-static void loongarch_set_pmu(Object *obj, bool value, Error **errp)
37
-{
38
- LoongArchCPU *cpu = LOONGARCH_CPU(obj);
39
-
40
- cpu->pmu = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
41
-}
42
-
43
void loongarch_cpu_post_init(Object *obj)
44
{
45
LoongArchCPU *cpu = LOONGARCH_CPU(obj);
46
47
+ cpu->lbt = ON_OFF_AUTO_OFF;
48
+ cpu->pmu = ON_OFF_AUTO_OFF;
49
cpu->lsx = ON_OFF_AUTO_AUTO;
50
cpu->lasx = ON_OFF_AUTO_AUTO;
51
object_property_add_bool(obj, "lsx", loongarch_get_lsx,
52
@@ -XXX,XX +XXX,XX @@ void loongarch_cpu_post_init(Object *obj)
53
loongarch_set_lasx);
54
/* lbt is enabled only in kvm mode, not supported in tcg mode */
55
if (kvm_enabled()) {
56
- cpu->lbt = ON_OFF_AUTO_AUTO;
57
- object_property_add_bool(obj, "lbt", loongarch_get_lbt,
58
- loongarch_set_lbt);
59
- object_property_set_description(obj, "lbt",
60
- "Set off to disable Binary Tranlation.");
61
-
62
- cpu->pmu = ON_OFF_AUTO_AUTO;
63
- object_property_add_bool(obj, "pmu", loongarch_get_pmu,
64
- loongarch_set_pmu);
65
- object_property_set_description(obj, "pmu",
66
- "Set off to performance monitor unit.");
67
kvm_loongarch_cpu_post_init(cpu);
68
- } else {
69
- cpu->lbt = ON_OFF_AUTO_OFF;
70
- cpu->pmu = ON_OFF_AUTO_OFF;
71
}
72
}
73
74
diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
75
index XXXXXXX..XXXXXXX 100644
76
--- a/target/loongarch/kvm/kvm.c
77
+++ b/target/loongarch/kvm/kvm.c
78
@@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs)
79
return ret;
80
}
81
82
+static bool loongarch_get_lbt(Object *obj, Error **errp)
83
+{
84
+ return LOONGARCH_CPU(obj)->lbt != ON_OFF_AUTO_OFF;
85
+}
86
+
87
+static void loongarch_set_lbt(Object *obj, bool value, Error **errp)
88
+{
89
+ LoongArchCPU *cpu = LOONGARCH_CPU(obj);
90
+
91
+ cpu->lbt = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
92
+}
93
+
94
+static bool loongarch_get_pmu(Object *obj, Error **errp)
95
+{
96
+ return LOONGARCH_CPU(obj)->pmu != ON_OFF_AUTO_OFF;
97
+}
98
+
99
+static void loongarch_set_pmu(Object *obj, bool value, Error **errp)
100
+{
101
+ LoongArchCPU *cpu = LOONGARCH_CPU(obj);
102
+
103
+ cpu->pmu = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
104
+}
105
+
106
void kvm_loongarch_cpu_post_init(LoongArchCPU *cpu)
107
{
108
+ cpu->lbt = ON_OFF_AUTO_AUTO;
109
+ object_property_add_bool(OBJECT(cpu), "lbt", loongarch_get_lbt,
110
+ loongarch_set_lbt);
111
+ object_property_set_description(OBJECT(cpu), "lbt",
112
+ "Set off to disable Binary Tranlation.");
113
+
114
+ cpu->pmu = ON_OFF_AUTO_AUTO;
115
+ object_property_add_bool(OBJECT(cpu), "pmu", loongarch_get_pmu,
116
+ loongarch_set_pmu);
117
+ object_property_set_description(OBJECT(cpu), "pmu",
118
+ "Set off to disable performance monitor unit.");
119
}
120
121
int kvm_arch_destroy_vcpu(CPUState *cs)
35
--
122
--
36
2.34.1
123
2.43.5
diff view generated by jsdifflib
New patch
1
Property kvm-pv-ipi is added to paravirt ipi feature, it is specially
2
for kvm mode.
1
3
4
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
5
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
6
---
7
target/loongarch/cpu.h | 1 +
8
target/loongarch/kvm/kvm.c | 18 ++++++++++++++++++
9
target/loongarch/loongarch-qmp-cmds.c | 2 +-
10
3 files changed, 20 insertions(+), 1 deletion(-)
11
12
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
13
index XXXXXXX..XXXXXXX 100644
14
--- a/target/loongarch/cpu.h
15
+++ b/target/loongarch/cpu.h
16
@@ -XXX,XX +XXX,XX @@ struct ArchCPU {
17
OnOffAuto pmu;
18
OnOffAuto lsx;
19
OnOffAuto lasx;
20
+ OnOffAuto kvm_pv_ipi;
21
22
/* 'compatible' string for this CPU for Linux device trees */
23
const char *dtb_compatible;
24
diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
25
index XXXXXXX..XXXXXXX 100644
26
--- a/target/loongarch/kvm/kvm.c
27
+++ b/target/loongarch/kvm/kvm.c
28
@@ -XXX,XX +XXX,XX @@ static void loongarch_set_pmu(Object *obj, bool value, Error **errp)
29
cpu->pmu = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
30
}
31
32
+static bool kvm_pv_ipi_get(Object *obj, Error **errp)
33
+{
34
+ return LOONGARCH_CPU(obj)->kvm_pv_ipi != ON_OFF_AUTO_OFF;
35
+}
36
+
37
+static void kvm_pv_ipi_set(Object *obj, bool value, Error **errp)
38
+{
39
+ LoongArchCPU *cpu = LOONGARCH_CPU(obj);
40
+
41
+ cpu->kvm_pv_ipi = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
42
+}
43
+
44
void kvm_loongarch_cpu_post_init(LoongArchCPU *cpu)
45
{
46
cpu->lbt = ON_OFF_AUTO_AUTO;
47
@@ -XXX,XX +XXX,XX @@ void kvm_loongarch_cpu_post_init(LoongArchCPU *cpu)
48
loongarch_set_pmu);
49
object_property_set_description(OBJECT(cpu), "pmu",
50
"Set off to disable performance monitor unit.");
51
+
52
+ cpu->kvm_pv_ipi = ON_OFF_AUTO_AUTO;
53
+ object_property_add_bool(OBJECT(cpu), "kvm-pv-ipi", kvm_pv_ipi_get,
54
+ kvm_pv_ipi_set);
55
+ object_property_set_description(OBJECT(cpu), "kvm-pv-ipi",
56
+ "Set off to disable KVM paravirt IPI.");
57
}
58
59
int kvm_arch_destroy_vcpu(CPUState *cs)
60
diff --git a/target/loongarch/loongarch-qmp-cmds.c b/target/loongarch/loongarch-qmp-cmds.c
61
index XXXXXXX..XXXXXXX 100644
62
--- a/target/loongarch/loongarch-qmp-cmds.c
63
+++ b/target/loongarch/loongarch-qmp-cmds.c
64
@@ -XXX,XX +XXX,XX @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
65
}
66
67
static const char *cpu_model_advertised_features[] = {
68
- "lsx", "lasx", "lbt", "pmu", NULL
69
+ "lsx", "lasx", "lbt", "pmu", "kvm-pv-ipi", NULL
70
};
71
72
CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
73
--
74
2.43.5
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
1
Paravirt ipi feature is OnOffAuto type, feature detection is added
2
to check whether it is supported by KVM host.
2
3
3
Nothing in LoongArch fw_cfg.c requires target specific definitions.
4
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
5
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
6
---
7
target/loongarch/cpu.h | 2 ++
8
target/loongarch/kvm/kvm.c | 36 +++++++++++++++++++++++++++++++++++-
9
2 files changed, 37 insertions(+), 1 deletion(-)
4
10
5
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
11
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
6
Reviewed-by: Song Gao <gaosong@loongson.cn>
7
Message-Id: <20240927213254.17552-3-philmd@linaro.org>
8
Signed-off-by: Song Gao <gaosong@loongson.cn>
9
---
10
hw/loongarch/meson.build | 2 +-
11
1 file changed, 1 insertion(+), 1 deletion(-)
12
13
diff --git a/hw/loongarch/meson.build b/hw/loongarch/meson.build
14
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/loongarch/meson.build
13
--- a/target/loongarch/cpu.h
16
+++ b/hw/loongarch/meson.build
14
+++ b/target/loongarch/cpu.h
15
@@ -XXX,XX +XXX,XX @@ enum loongarch_features {
16
LOONGARCH_FEATURE_LASX,
17
LOONGARCH_FEATURE_LBT, /* loongson binary translation extension */
18
LOONGARCH_FEATURE_PMU,
19
+ LOONGARCH_FEATURE_PV_IPI,
20
};
21
22
typedef struct LoongArchBT {
23
@@ -XXX,XX +XXX,XX @@ typedef struct CPUArchState {
24
lbt_t lbt;
25
26
uint32_t cpucfg[21];
27
+ uint32_t pv_features;
28
29
/* LoongArch CSRs */
30
uint64_t CSR_CRMD;
31
diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
32
index XXXXXXX..XXXXXXX 100644
33
--- a/target/loongarch/kvm/kvm.c
34
+++ b/target/loongarch/kvm/kvm.c
17
@@ -XXX,XX +XXX,XX @@
35
@@ -XXX,XX +XXX,XX @@
18
loongarch_ss = ss.source_set()
36
#include "qemu/osdep.h"
19
loongarch_ss.add(files(
37
#include <sys/ioctl.h>
20
- 'fw_cfg.c',
38
#include <linux/kvm.h>
21
'boot.c',
39
-
22
))
40
+#include "asm-loongarch/kvm_para.h"
23
+common_ss.add(when: 'CONFIG_LOONGARCH_VIRT', if_true: files('fw_cfg.c'))
41
#include "qapi/error.h"
24
loongarch_ss.add(when: 'CONFIG_LOONGARCH_VIRT', if_true: files('virt.c'))
42
#include "qemu/timer.h"
25
loongarch_ss.add(when: 'CONFIG_ACPI', if_true: files('acpi-build.c'))
43
#include "qemu/error-report.h"
44
@@ -XXX,XX +XXX,XX @@ static bool kvm_feature_supported(CPUState *cs, enum loongarch_features feature)
45
ret = kvm_vm_ioctl(kvm_state, KVM_HAS_DEVICE_ATTR, &attr);
46
return (ret == 0);
47
48
+ case LOONGARCH_FEATURE_PV_IPI:
49
+ attr.group = KVM_LOONGARCH_VM_FEAT_CTRL;
50
+ attr.attr = KVM_LOONGARCH_VM_FEAT_PV_IPI;
51
+ ret = kvm_vm_ioctl(kvm_state, KVM_HAS_DEVICE_ATTR, &attr);
52
+ return (ret == 0);
53
+
54
default:
55
return false;
56
}
57
@@ -XXX,XX +XXX,XX @@ static int kvm_cpu_check_pmu(CPUState *cs, Error **errp)
58
return 0;
59
}
60
61
+static int kvm_cpu_check_pv_features(CPUState *cs, Error **errp)
62
+{
63
+ LoongArchCPU *cpu = LOONGARCH_CPU(cs);
64
+ CPULoongArchState *env = cpu_env(cs);
65
+ bool kvm_supported;
66
+
67
+ kvm_supported = kvm_feature_supported(cs, LOONGARCH_FEATURE_PV_IPI);
68
+ if (cpu->kvm_pv_ipi == ON_OFF_AUTO_ON) {
69
+ if (!kvm_supported) {
70
+ error_setg(errp, "'pv_ipi' feature not supported by KVM host");
71
+ return -ENOTSUP;
72
+ }
73
+ } else if (cpu->kvm_pv_ipi != ON_OFF_AUTO_AUTO) {
74
+ kvm_supported = false;
75
+ }
76
+
77
+ if (kvm_supported) {
78
+ env->pv_features |= BIT(KVM_FEATURE_IPI);
79
+ }
80
+
81
+ return 0;
82
+}
83
+
84
int kvm_arch_init_vcpu(CPUState *cs)
85
{
86
uint64_t val;
87
@@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs)
88
error_report_err(local_err);
89
}
90
91
+ ret = kvm_cpu_check_pv_features(cs, &local_err);
92
+ if (ret < 0) {
93
+ error_report_err(local_err);
94
+ }
95
+
96
return ret;
97
}
26
98
27
--
99
--
28
2.34.1
100
2.43.5
29
30
diff view generated by jsdifflib
1
From: Bibo Mao <maobibo@loongson.cn>
1
The similiar with cpucfg register, paravirt ipi feature is set in
2
2
function kvm_arch_put_registers(). Instead the paravirt feature can
3
Macro definition is added for acpi sleep control register, ged emulation
3
be enabled only once, it cannot be changed dynamically.
4
driver can use the macro , also it can be used in FDT table if ged is
5
exposed with FDT table.
6
4
7
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
5
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
8
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
6
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
9
Message-Id: <20240918014206.2165821-2-maobibo@loongson.cn>
10
Signed-off-by: Song Gao <gaosong@loongson.cn>
11
---
7
---
12
hw/acpi/generic_event_device.c | 6 +++---
8
target/loongarch/kvm/kvm.c | 36 ++++++++++++++++++++++++++++++++++++
13
include/hw/acpi/generic_event_device.h | 7 +++++--
9
1 file changed, 36 insertions(+)
14
2 files changed, 8 insertions(+), 5 deletions(-)
15
10
16
diff --git a/hw/acpi/generic_event_device.c b/hw/acpi/generic_event_device.c
11
diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
17
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/acpi/generic_event_device.c
13
--- a/target/loongarch/kvm/kvm.c
19
+++ b/hw/acpi/generic_event_device.c
14
+++ b/target/loongarch/kvm/kvm.c
20
@@ -XXX,XX +XXX,XX @@ static void ged_regs_write(void *opaque, hwaddr addr, uint64_t data,
15
@@ -XXX,XX +XXX,XX @@ static int kvm_set_stealtime(CPUState *cs)
21
16
return 0;
22
switch (addr) {
17
}
23
case ACPI_GED_REG_SLEEP_CTL:
18
24
- slp_typ = (data >> 2) & 0x07;
19
+static int kvm_set_pv_features(CPUState *cs)
25
- slp_en = (data >> 5) & 0x01;
20
+{
26
- if (slp_en && slp_typ == 5) {
21
+ CPULoongArchState *env = cpu_env(cs);
27
+ slp_typ = (data >> ACPI_GED_SLP_TYP_POS) & ACPI_GED_SLP_TYP_MASK;
22
+ int err;
28
+ slp_en = !!(data & ACPI_GED_SLP_EN);
23
+ uint64_t val;
29
+ if (slp_en && slp_typ == ACPI_GED_SLP_TYP_S5) {
24
+ struct kvm_device_attr attr = {
30
qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
25
+ .group = KVM_LOONGARCH_VCPU_CPUCFG,
31
}
26
+ .attr = CPUCFG_KVM_FEATURE,
32
return;
27
+ .addr = (uint64_t)&val,
33
diff --git a/include/hw/acpi/generic_event_device.h b/include/hw/acpi/generic_event_device.h
28
+ };
34
index XXXXXXX..XXXXXXX 100644
29
+
35
--- a/include/hw/acpi/generic_event_device.h
30
+ err = kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, attr);
36
+++ b/include/hw/acpi/generic_event_device.h
31
+ if (err) {
37
@@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED)
32
+ return 0;
38
/* ACPI_GED_REG_RESET value for reset*/
33
+ }
39
#define ACPI_GED_RESET_VALUE 0x42
34
+
40
35
+ val = env->pv_features;
41
-/* ACPI_GED_REG_SLEEP_CTL.SLP_TYP value for S5 (aka poweroff) */
36
+ err = kvm_vcpu_ioctl(cs, KVM_SET_DEVICE_ATTR, attr);
42
-#define ACPI_GED_SLP_TYP_S5 0x05
37
+ if (err) {
43
+/* [ACPI 5.0 Chapter 4.8.3.7] Sleep Control and Status Register */
38
+ error_report("Fail to set pv feature "TARGET_FMT_lx " with error %s",
44
+#define ACPI_GED_SLP_TYP_POS 0x2 /* SLP_TYPx Bit Offset */
39
+ val, strerror(errno));
45
+#define ACPI_GED_SLP_TYP_MASK 0x07 /* SLP_TYPx 3-bit mask */
40
+ return err;
46
+#define ACPI_GED_SLP_TYP_S5 0x05 /* System _S5 State (Soft Off) */
41
+ }
47
+#define ACPI_GED_SLP_EN 0x20 /* SLP_EN write-only bit */
42
+
48
43
+ return 0;
49
#define GED_DEVICE "GED"
44
+}
50
#define AML_GED_EVT_REG "EREG"
45
+
46
static int kvm_loongarch_get_regs_core(CPUState *cs)
47
{
48
int ret = 0;
49
@@ -XXX,XX +XXX,XX @@ int kvm_arch_get_registers(CPUState *cs, Error **errp)
50
int kvm_arch_put_registers(CPUState *cs, int level, Error **errp)
51
{
52
int ret;
53
+ static int once;
54
55
ret = kvm_loongarch_put_regs_core(cs);
56
if (ret) {
57
@@ -XXX,XX +XXX,XX @@ int kvm_arch_put_registers(CPUState *cs, int level, Error **errp)
58
return ret;
59
}
60
61
+ if (!once) {
62
+ ret = kvm_set_pv_features(cs);
63
+ if (ret) {
64
+ return ret;
65
+ }
66
+ once = 1;
67
+ }
68
+
69
if (level >= KVM_PUT_FULL_STATE) {
70
/*
71
* only KVM_PUT_FULL_STATE is required, kvm kernel will clear
51
--
72
--
52
2.34.1
73
2.43.5
diff view generated by jsdifflib
1
From: Jiaxun Yang <jiaxun.yang@flygoat.com>
1
Property kvm-steal-time is added for kvm steal time feature, it is
2
specially for kvm mode.
2
3
3
Refector EFI style booting data structure generation to
4
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
4
support 32bit EFI variant on LoongArch32 CPU.
5
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
6
---
7
target/loongarch/cpu.h | 1 +
8
target/loongarch/kvm/kvm.c | 18 ++++++++++++++++++
9
target/loongarch/loongarch-qmp-cmds.c | 2 +-
10
3 files changed, 20 insertions(+), 1 deletion(-)
5
11
6
All data structs are filled with padding members if necessary
12
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
7
and marked as QEMU_PACKED to avoid host ABI alignment impact.
8
9
Host endian is being cared as well.
10
11
It also fixed various problems in old implementation such
12
as null pointer on empty string, memory desc map_size not set,
13
incorrect memory map definition and so on.
14
15
Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
16
Reviewed-by: Song Gao <gaosong@loongson.cn>
17
Message-Id: <20240914-loongarch-booting-v1-1-1517cae11c10@flygoat.com>
18
Signed-off-by: Song Gao <gaosong@loongson.cn>
19
---
20
hw/loongarch/boot.c | 220 ++++++++++++++++++++++++------------
21
include/hw/loongarch/boot.h | 106 +++++++++++++----
22
2 files changed, 237 insertions(+), 89 deletions(-)
23
24
diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
25
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
26
--- a/hw/loongarch/boot.c
14
--- a/target/loongarch/cpu.h
27
+++ b/hw/loongarch/boot.c
15
+++ b/target/loongarch/cpu.h
28
@@ -XXX,XX +XXX,XX @@
16
@@ -XXX,XX +XXX,XX @@ struct ArchCPU {
29
* Copyright (c) 2023 Loongson Technology Corporation Limited
17
OnOffAuto lsx;
30
*/
18
OnOffAuto lasx;
31
19
OnOffAuto kvm_pv_ipi;
32
+#include <zlib.h>
20
+ OnOffAuto kvm_steal_time;
33
#include "qemu/osdep.h"
21
34
#include "qemu/units.h"
22
/* 'compatible' string for this CPU for Linux device trees */
35
#include "target/loongarch/cpu.h"
23
const char *dtb_compatible;
36
@@ -XXX,XX +XXX,XX @@ static const unsigned int slave_boot_code[] = {
24
diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
37
25
index XXXXXXX..XXXXXXX 100644
38
/* Clear mailbox. */
26
--- a/target/loongarch/kvm/kvm.c
39
0x1400002d, /* lu12i.w $t1, 1(0x1) */
27
+++ b/target/loongarch/kvm/kvm.c
40
- 0x038081ad, /* ori $t1, $t1, CORE_BUF_20 */
28
@@ -XXX,XX +XXX,XX @@ static void kvm_pv_ipi_set(Object *obj, bool value, Error **errp)
41
+ 0x038081ad, /* ori $t1, $t1, CORE_BUF_20 */
29
cpu->kvm_pv_ipi = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
42
0x06481da0, /* iocsrwr.d $zero, $t1 */
43
44
/* Enable IPI interrupt. */
45
@@ -XXX,XX +XXX,XX @@ static inline void *guidcpy(void *dst, const void *src)
46
return memcpy(dst, src, sizeof(efi_guid_t));
47
}
30
}
48
31
49
-static void init_efi_boot_memmap(struct efi_system_table *systab,
32
+static bool kvm_steal_time_get(Object *obj, Error **errp)
50
- void *p, void *start)
33
+{
51
+static void efi_hdr_crc32(efi_table_hdr_t *hdr)
34
+ return LOONGARCH_CPU(obj)->kvm_steal_time != ON_OFF_AUTO_OFF;
35
+}
36
+
37
+static void kvm_steal_time_set(Object *obj, bool value, Error **errp)
38
+{
39
+ LoongArchCPU *cpu = LOONGARCH_CPU(obj);
40
+
41
+ cpu->kvm_steal_time = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
42
+}
43
+
44
void kvm_loongarch_cpu_post_init(LoongArchCPU *cpu)
52
{
45
{
53
- unsigned i;
46
cpu->lbt = ON_OFF_AUTO_AUTO;
54
- struct efi_boot_memmap *boot_memmap = p;
47
@@ -XXX,XX +XXX,XX @@ void kvm_loongarch_cpu_post_init(LoongArchCPU *cpu)
55
- efi_guid_t tbl_guid = LINUX_EFI_BOOT_MEMMAP_GUID;
48
kvm_pv_ipi_set);
56
-
49
object_property_set_description(OBJECT(cpu), "kvm-pv-ipi",
57
- /* efi_configuration_table 1 */
50
"Set off to disable KVM paravirt IPI.");
58
- guidcpy(&systab->tables[0].guid, &tbl_guid);
51
+
59
- systab->tables[0].table = (struct efi_configuration_table *)(p - start);
52
+ cpu->kvm_steal_time = ON_OFF_AUTO_AUTO;
60
- systab->nr_tables = 1;
53
+ object_property_add_bool(OBJECT(cpu), "kvm-steal-time", kvm_steal_time_get,
61
-
54
+ kvm_steal_time_set);
62
- boot_memmap->desc_size = sizeof(efi_memory_desc_t);
55
+ object_property_set_description(OBJECT(cpu), "kvm-steal-time",
63
- boot_memmap->desc_ver = 1;
56
+ "Set off to disable KVM steal time.");
64
- boot_memmap->map_size = 0;
65
+ uint32_t val;
66
67
- efi_memory_desc_t *map = p + sizeof(struct efi_boot_memmap);
68
- for (i = 0; i < memmap_entries; i++) {
69
- map = (void *)boot_memmap + sizeof(*map);
70
- map[i].type = memmap_table[i].type;
71
- map[i].phys_addr = ROUND_UP(memmap_table[i].address, 64 * KiB);
72
- map[i].num_pages = ROUND_DOWN(memmap_table[i].address +
73
- memmap_table[i].length - map[i].phys_addr, 64 * KiB);
74
- p += sizeof(efi_memory_desc_t);
75
- }
76
+ hdr->crc32 = 0;
77
+ val = crc32(0, (const unsigned char *)hdr, hdr->headersize);
78
+ hdr->crc32 = cpu_to_le32(val);
79
}
57
}
80
58
81
-static void init_efi_initrd_table(struct efi_system_table *systab,
59
int kvm_arch_destroy_vcpu(CPUState *cs)
82
- void *p, void *start)
60
diff --git a/target/loongarch/loongarch-qmp-cmds.c b/target/loongarch/loongarch-qmp-cmds.c
83
+static void init_efi_vendor_string(void **p)
61
index XXXXXXX..XXXXXXX 100644
84
{
62
--- a/target/loongarch/loongarch-qmp-cmds.c
85
- efi_guid_t tbl_guid = LINUX_EFI_INITRD_MEDIA_GUID;
63
+++ b/target/loongarch/loongarch-qmp-cmds.c
86
- struct efi_initrd *initrd_table = p;
64
@@ -XXX,XX +XXX,XX @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
87
+ uint16_t *vendor_str = *p;
88
89
- /* efi_configuration_table 2 */
90
- guidcpy(&systab->tables[1].guid, &tbl_guid);
91
- systab->tables[1].table = (struct efi_configuration_table *)(p - start);
92
- systab->nr_tables = 2;
93
+ /* QEMU in UTF16-LE */
94
+ stw_le_p(vendor_str++, 0x0051); /* Q */
95
+ stw_le_p(vendor_str++, 0x0045); /* E */
96
+ stw_le_p(vendor_str++, 0x004D); /* M */
97
+ stw_le_p(vendor_str++, 0x0055); /* U */
98
+ stw_le_p(vendor_str++, 0x0000); /* \0 */
99
100
- initrd_table->base = initrd_offset;
101
- initrd_table->size = initrd_size;
102
+ *p = vendor_str;
103
+ *p = QEMU_ALIGN_PTR_UP(*p, sizeof(target_long));
104
}
65
}
105
66
106
-static void init_efi_fdt_table(struct efi_system_table *systab)
67
static const char *cpu_model_advertised_features[] = {
107
+static void memmap_write_descs(efi_memory_desc_t *map)
68
- "lsx", "lasx", "lbt", "pmu", "kvm-pv-ipi", NULL
108
{
69
+ "lsx", "lasx", "lbt", "pmu", "kvm-pv-ipi", "kvm-steal-time", NULL
109
- efi_guid_t tbl_guid = DEVICE_TREE_GUID;
110
-
111
- /* efi_configuration_table 3 */
112
- guidcpy(&systab->tables[2].guid, &tbl_guid);
113
- systab->tables[2].table = (void *)FDT_BASE;
114
- systab->nr_tables = 3;
115
-}
116
-
117
-static void init_systab(struct loongarch_boot_info *info, void *p, void *start)
118
-{
119
- void *bp_tables_start;
120
- struct efi_system_table *systab = p;
121
+ int i;
122
123
- info->a2 = p - start;
124
+ for (i = 0; i < memmap_entries; i++) {
125
+ uint32_t efi_type;
126
+ hwaddr start = memmap_table[i].address;
127
+ hwaddr end = memmap_table[i].address + memmap_table[i].length;
128
+
129
+ switch (memmap_table[i].type) {
130
+ case MEMMAP_TYPE_MEMORY:
131
+ efi_type = EFI_CONVENTIONAL_MEMORY;
132
+ break;
133
+ case MEMMAP_TYPE_RESERVED:
134
+ efi_type = EFI_RESERVED_TYPE;
135
+ break;
136
+ case MEMMAP_TYPE_ACPI:
137
+ efi_type = EFI_ACPI_RECLAIM_MEMORY;
138
+ break;
139
+ case MEMMAP_TYPE_NVS:
140
+ efi_type = EFI_ACPI_MEMORY_NVS;
141
+ break;
142
+ default:
143
+ efi_type = EFI_RESERVED_TYPE;
144
+ break;
145
+ }
146
147
- systab->hdr.signature = EFI_SYSTEM_TABLE_SIGNATURE;
148
- systab->hdr.revision = EFI_SPECIFICATION_VERSION;
149
- systab->hdr.revision = sizeof(struct efi_system_table),
150
- systab->fw_revision = FW_VERSION << 16 | FW_PATCHLEVEL << 8;
151
- systab->runtime = 0;
152
- systab->boottime = 0;
153
- systab->nr_tables = 0;
154
+ if (memmap_table[i].reserved) {
155
+ start = QEMU_ALIGN_DOWN(start, EFI_PAGE_SIZE);
156
+ end = QEMU_ALIGN_UP(end, EFI_PAGE_SIZE);
157
+ } else {
158
+ start = QEMU_ALIGN_UP(start, EFI_PAGE_SIZE);
159
+ end = QEMU_ALIGN_DOWN(end, EFI_PAGE_SIZE);
160
+ }
161
162
- p += ROUND_UP(sizeof(struct efi_system_table), 64 * KiB);
163
+ map[i].type = cpu_to_le32(efi_type);
164
+ map[i].phys_addr = cpu_to_le64(start);
165
+ map[i].virt_addr = cpu_to_le64(start);
166
+ map[i].num_pages = cpu_to_le64((end - start) >> EFI_PAGE_SHIFT);
167
+ }
168
+}
169
170
- systab->tables = p;
171
- bp_tables_start = p;
172
+#define EFI_BOOT_MEMMAP_TABLE_GEN(type) \
173
+static void init_efi_boot_memmap_##type(void *guidp, void **p) \
174
+{ \
175
+ struct efi_boot_memmap_##type *boot_memmap = *p; \
176
+ efi_guid_t tbl_guid = LINUX_EFI_BOOT_MEMMAP_GUID; \
177
+ \
178
+ /* efi_configuration_table 1 */ \
179
+ guidcpy(guidp, &tbl_guid); \
180
+ \
181
+ boot_memmap->desc_size = cpu_to_le##type(sizeof(efi_memory_desc_t)); \
182
+ boot_memmap->desc_ver = cpu_to_le32(1); \
183
+ boot_memmap->map_size = cpu_to_le##type(boot_memmap->desc_size * \
184
+ memmap_entries); \
185
+ memmap_write_descs(boot_memmap->map); \
186
+ *p += sizeof(struct efi_boot_memmap_##type); \
187
+}
188
189
- init_efi_boot_memmap(systab, p, start);
190
- p += ROUND_UP(sizeof(struct efi_boot_memmap) +
191
- sizeof(efi_memory_desc_t) * memmap_entries, 64 * KiB);
192
- init_efi_initrd_table(systab, p, start);
193
- p += ROUND_UP(sizeof(struct efi_initrd), 64 * KiB);
194
- init_efi_fdt_table(systab);
195
+#define EFI_INITRD_TABLE_GEN(type) \
196
+static void init_efi_initrd_table_##type(void *guidp, void **p) \
197
+{ \
198
+ efi_guid_t tbl_guid = LINUX_EFI_INITRD_MEDIA_GUID; \
199
+ struct efi_initrd_##type *initrd_table = *p; \
200
+ \
201
+ /* efi_configuration_table */ \
202
+ guidcpy(guidp, &tbl_guid); \
203
+ \
204
+ initrd_table->base = cpu_to_le##type(initrd_offset); \
205
+ initrd_table->size = cpu_to_le##type(initrd_size); \
206
+ *p += sizeof(struct efi_initrd_##type); \
207
+}
208
209
- systab->tables = (struct efi_configuration_table *)(bp_tables_start - start);
210
+#define BOOTP_ALIGN_PTR_UP(p, s, n) \
211
+ ((typeof(p))((uintptr_t)(s) + \
212
+ QEMU_ALIGN_UP((uintptr_t)(p) - (uintptr_t)(s), n)))
213
+
214
+#define EFI_INIT_SYSTAB_GEN(type) \
215
+ EFI_BOOT_MEMMAP_TABLE_GEN(type) \
216
+ EFI_INITRD_TABLE_GEN(type) \
217
+static void init_systab_##type(struct loongarch_boot_info *info, \
218
+ void *p, void *start) \
219
+{ \
220
+ uint32_t nr_tables = 0; \
221
+ const efi_guid_t fdt_guid = DEVICE_TREE_GUID; \
222
+ struct efi_system_table_##type *systab; \
223
+ struct efi_configuration_table_##type *cfg_tabs; \
224
+ \
225
+ p = BOOTP_ALIGN_PTR_UP(p, start, EFI_TABLE_ALIGN); \
226
+ systab = p; \
227
+ info->a2 = p - start; \
228
+ \
229
+ systab->hdr.signature = cpu_to_le64(EFI_SYSTEM_TABLE_SIGNATURE); \
230
+ systab->hdr.revision = cpu_to_le32(EFI_SPECIFICATION_VERSION); \
231
+ systab->hdr.headersize = \
232
+ cpu_to_le32(sizeof(struct efi_system_table_##type)); \
233
+ systab->fw_revision = \
234
+ cpu_to_le32(FW_VERSION << 16 | FW_PATCHLEVEL << 8); \
235
+ systab->runtime = 0; \
236
+ systab->boottime = 0; \
237
+ systab->nr_tables = 0; \
238
+ \
239
+ p += sizeof(struct efi_system_table_##type); \
240
+ systab->fw_vendor = cpu_to_le##type(p - start); \
241
+ init_efi_vendor_string(&p); \
242
+ \
243
+ p = BOOTP_ALIGN_PTR_UP(p, start, EFI_TABLE_ALIGN); \
244
+ systab->tables = cpu_to_le##type(p - start); \
245
+ cfg_tabs = p; \
246
+ p += sizeof(struct efi_configuration_table_##type) * 3; \
247
+ \
248
+ p = BOOTP_ALIGN_PTR_UP(p, start, EFI_TABLE_ALIGN); \
249
+ cfg_tabs[nr_tables].table = cpu_to_le##type(p - start); \
250
+ init_efi_boot_memmap_##type(&cfg_tabs[nr_tables].guid, &p); \
251
+ nr_tables++; \
252
+ \
253
+ if (initrd_size > 0) { \
254
+ cfg_tabs[nr_tables].table = cpu_to_le##type(p - start); \
255
+ init_efi_initrd_table_##type(&cfg_tabs[nr_tables].guid, &p); \
256
+ nr_tables++; \
257
+ } \
258
+ \
259
+ guidcpy(&cfg_tabs[nr_tables].guid, &fdt_guid); \
260
+ cfg_tabs[nr_tables].table = cpu_to_le##type(FDT_BASE); \
261
+ nr_tables++; \
262
+ \
263
+ systab->nr_tables = cpu_to_le32(nr_tables); \
264
+ efi_hdr_crc32(&systab->hdr); \
265
}
266
267
+EFI_INIT_SYSTAB_GEN(32)
268
+EFI_INIT_SYSTAB_GEN(64)
269
+
270
static void init_cmdline(struct loongarch_boot_info *info, void *p, void *start)
271
{
272
hwaddr cmdline_addr = p - start;
273
@@ -XXX,XX +XXX,XX @@ static void reset_load_elf(void *opaque)
274
275
cpu_reset(CPU(cpu));
276
if (env->load_elf) {
277
-    if (cpu == LOONGARCH_CPU(first_cpu)) {
278
+ if (cpu == LOONGARCH_CPU(first_cpu)) {
279
env->gpr[4] = env->boot_info->a0;
280
env->gpr[5] = env->boot_info->a1;
281
env->gpr[6] = env->boot_info->a2;
282
@@ -XXX,XX +XXX,XX @@ static void loongarch_firmware_boot(LoongArchVirtMachineState *lvms,
283
fw_cfg_add_kernel_info(info, lvms->fw_cfg);
284
}
285
286
-static void init_boot_rom(struct loongarch_boot_info *info, void *p)
287
+static void init_boot_rom(struct loongarch_boot_info *info, void *p,
288
+ bool is_64bit)
289
{
290
void *start = p;
291
292
init_cmdline(info, p, start);
293
p += COMMAND_LINE_SIZE;
294
295
- init_systab(info, p, start);
296
+ if (is_64bit)
297
+ init_systab_64(info, p, start);
298
+ else
299
+ init_systab_32(info, p, start);
300
}
301
302
static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info)
303
{
304
void *p, *bp;
305
int64_t kernel_addr = 0;
306
- LoongArchCPU *lacpu;
307
+ LoongArchCPU *lacpu = LOONGARCH_CPU(first_cpu);
308
CPUState *cs;
309
310
if (info->kernel_filename) {
311
@@ -XXX,XX +XXX,XX @@ static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info)
312
/* Load cmdline and system tables at [0 - 1 MiB] */
313
p = g_malloc0(1 * MiB);
314
bp = p;
315
- init_boot_rom(info, p);
316
+ init_boot_rom(info, p, is_la64(&lacpu->env));
317
rom_add_blob_fixed_as("boot_info", bp, 1 * MiB, 0, &address_space_memory);
318
319
/* Load slave boot code at pflash0 . */
320
diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h
321
index XXXXXXX..XXXXXXX 100644
322
--- a/include/hw/loongarch/boot.h
323
+++ b/include/hw/loongarch/boot.h
324
@@ -XXX,XX +XXX,XX @@ typedef struct {
325
EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, 0x83, 0x0b, \
326
0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0)
327
328
+/* Memory types: */
329
+#define EFI_RESERVED_TYPE 0
330
+#define EFI_LOADER_CODE 1
331
+#define EFI_LOADER_DATA 2
332
+#define EFI_BOOT_SERVICES_CODE 3
333
+#define EFI_BOOT_SERVICES_DATA 4
334
+#define EFI_RUNTIME_SERVICES_CODE 5
335
+#define EFI_RUNTIME_SERVICES_DATA 6
336
+#define EFI_CONVENTIONAL_MEMORY 7
337
+#define EFI_UNUSABLE_MEMORY 8
338
+#define EFI_ACPI_RECLAIM_MEMORY 9
339
+#define EFI_ACPI_MEMORY_NVS 10
340
+#define EFI_MEMORY_MAPPED_IO 11
341
+#define EFI_MEMORY_MAPPED_IO_PORT_SPACE 12
342
+#define EFI_PAL_CODE 13
343
+#define EFI_PERSISTENT_MEMORY 14
344
+#define EFI_UNACCEPTED_MEMORY 15
345
+#define EFI_MAX_MEMORY_TYPE 16
346
+
347
+#define EFI_PAGE_SHIFT 12
348
+#define EFI_PAGE_SIZE (1UL << EFI_PAGE_SHIFT)
349
+
350
+#define EFI_TABLE_ALIGN (64 * KiB)
351
+
352
struct efi_config_table {
353
efi_guid_t guid;
354
uint64_t *ptr;
355
const char name[16];
356
-};
357
+} QEMU_PACKED;
358
359
typedef struct {
360
uint64_t signature;
361
@@ -XXX,XX +XXX,XX @@ typedef struct {
362
uint32_t headersize;
363
uint32_t crc32;
364
uint32_t reserved;
365
-} efi_table_hdr_t;
366
+} QEMU_PACKED efi_table_hdr_t;
367
368
-struct efi_configuration_table {
369
+struct efi_configuration_table_32 {
370
efi_guid_t guid;
371
- void *table;
372
-};
373
+ uint32_t table;
374
+} QEMU_PACKED;
375
376
-struct efi_system_table {
377
+struct efi_configuration_table_64 {
378
+ efi_guid_t guid;
379
+ uint64_t table;
380
+} QEMU_PACKED;
381
+
382
+struct efi_system_table_32 {
383
+ efi_table_hdr_t hdr;
384
+ uint32_t fw_vendor; /* physical addr of CHAR16 vendor string */
385
+ uint32_t fw_revision;
386
+ uint32_t con_in_handle;
387
+ uint32_t con_in;
388
+ uint32_t con_out_handle;
389
+ uint32_t con_out;
390
+ uint32_t stderr_handle;
391
+ uint32_t stderr_placeholder;
392
+ uint32_t runtime;
393
+ uint32_t boottime;
394
+ uint32_t nr_tables;
395
+ uint32_t tables;
396
+} QEMU_PACKED;
397
+
398
+struct efi_system_table_64 {
399
efi_table_hdr_t hdr;
400
uint64_t fw_vendor; /* physical addr of CHAR16 vendor string */
401
uint32_t fw_revision;
402
+ uint32_t __pad1;
403
uint64_t con_in_handle;
404
- uint64_t *con_in;
405
+ uint64_t con_in;
406
uint64_t con_out_handle;
407
- uint64_t *con_out;
408
+ uint64_t con_out;
409
uint64_t stderr_handle;
410
uint64_t stderr_placeholder;
411
- uint64_t *runtime;
412
- uint64_t *boottime;
413
- uint64_t nr_tables;
414
- struct efi_configuration_table *tables;
415
-};
416
+ uint64_t runtime;
417
+ uint64_t boottime;
418
+ uint32_t nr_tables;
419
+ uint32_t __pad2;
420
+ uint64_t tables;
421
+} QEMU_PACKED;
422
423
typedef struct {
424
uint32_t type;
425
- uint32_t pad;
426
+ uint32_t __pad;
427
uint64_t phys_addr;
428
uint64_t virt_addr;
429
uint64_t num_pages;
430
uint64_t attribute;
431
-} efi_memory_desc_t;
432
+} QEMU_PACKED efi_memory_desc_t;
433
+
434
+struct efi_boot_memmap_32 {
435
+ uint32_t map_size;
436
+ uint32_t desc_size;
437
+ uint32_t desc_ver;
438
+ uint32_t map_key;
439
+ uint32_t buff_size;
440
+ uint32_t __pad;
441
+ efi_memory_desc_t map[32];
442
+} QEMU_PACKED;
443
444
-struct efi_boot_memmap {
445
+struct efi_boot_memmap_64 {
446
uint64_t map_size;
447
uint64_t desc_size;
448
uint32_t desc_ver;
449
+ uint32_t __pad;
450
uint64_t map_key;
451
uint64_t buff_size;
452
efi_memory_desc_t map[32];
453
-};
454
+} QEMU_PACKED;
455
+
456
+struct efi_initrd_32 {
457
+ uint32_t base;
458
+ uint32_t size;
459
+} QEMU_PACKED;
460
461
-struct efi_initrd {
462
+struct efi_initrd_64 {
463
uint64_t base;
464
uint64_t size;
465
-};
466
+} QEMU_PACKED;
467
468
struct loongarch_boot_info {
469
uint64_t ram_size;
470
@@ -XXX,XX +XXX,XX @@ extern unsigned memmap_entries;
471
struct memmap_entry {
472
uint64_t address;
473
uint64_t length;
474
+ /* E820 style type */
475
+#define MEMMAP_TYPE_MEMORY 1
476
+#define MEMMAP_TYPE_RESERVED 2
477
+#define MEMMAP_TYPE_ACPI 3
478
+#define MEMMAP_TYPE_NVS 4
479
uint32_t type;
480
uint32_t reserved;
481
};
70
};
71
72
CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
482
--
73
--
483
2.34.1
74
2.43.5
diff view generated by jsdifflib
1
From: Jiaxun Yang <jiaxun.yang@flygoat.com>
1
Paravirt steal time feature is OnOffAuto type, feature detection is added
2
to check whether it is supported on KVM host.
2
3
3
Use stl_p to write instructions so that host endian conversion
4
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
4
will be performed.
5
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
6
---
7
target/loongarch/cpu.h | 1 +
8
target/loongarch/kvm/kvm.c | 20 ++++++++++++++++++++
9
2 files changed, 21 insertions(+)
5
10
6
Replace mailbox read/write on LoongArch32 systems with 32bit IOCSR
11
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
7
instructions to prevent illegal instructions.
8
9
Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
10
Reviewed-by: Song Gao <gaosong@loongson.cn>
11
Message-Id: <20240914-loongarch-booting-v1-2-1517cae11c10@flygoat.com>
12
Signed-off-by: Song Gao <gaosong@loongson.cn>
13
---
14
hw/loongarch/boot.c | 107 ++++++++++++++++++++++++--------------------
15
1 file changed, 59 insertions(+), 48 deletions(-)
16
17
diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
18
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/loongarch/boot.c
13
--- a/target/loongarch/cpu.h
20
+++ b/hw/loongarch/boot.c
14
+++ b/target/loongarch/cpu.h
21
@@ -XXX,XX +XXX,XX @@ unsigned memmap_entries;
15
@@ -XXX,XX +XXX,XX @@ enum loongarch_features {
22
ram_addr_t initrd_offset;
16
LOONGARCH_FEATURE_LBT, /* loongson binary translation extension */
23
uint64_t initrd_size;
17
LOONGARCH_FEATURE_PMU,
24
18
LOONGARCH_FEATURE_PV_IPI,
25
-static const unsigned int slave_boot_code[] = {
19
+ LOONGARCH_FEATURE_STEALTIME,
26
- /* Configure reset ebase. */
20
};
27
- 0x0400302c, /* csrwr $t0, LOONGARCH_CSR_EENTRY */
21
28
-
22
typedef struct LoongArchBT {
29
- /* Disable interrupt. */
23
diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
30
- 0x0380100c, /* ori $t0, $zero,0x4 */
24
index XXXXXXX..XXXXXXX 100644
31
- 0x04000180, /* csrxchg $zero, $t0, LOONGARCH_CSR_CRMD */
25
--- a/target/loongarch/kvm/kvm.c
32
-
26
+++ b/target/loongarch/kvm/kvm.c
33
- /* Clear mailbox. */
27
@@ -XXX,XX +XXX,XX @@ static bool kvm_feature_supported(CPUState *cs, enum loongarch_features feature)
34
- 0x1400002d, /* lu12i.w $t1, 1(0x1) */
28
ret = kvm_vm_ioctl(kvm_state, KVM_HAS_DEVICE_ATTR, &attr);
35
- 0x038081ad, /* ori $t1, $t1, CORE_BUF_20 */
29
return (ret == 0);
36
- 0x06481da0, /* iocsrwr.d $zero, $t1 */
30
37
-
31
+ case LOONGARCH_FEATURE_STEALTIME:
38
- /* Enable IPI interrupt. */
32
+ attr.group = KVM_LOONGARCH_VM_FEAT_CTRL;
39
- 0x1400002c, /* lu12i.w $t0, 1(0x1) */
33
+ attr.attr = KVM_LOONGARCH_VM_FEAT_PV_STEALTIME;
40
- 0x0400118c, /* csrxchg $t0, $t0, LOONGARCH_CSR_ECFG */
34
+ ret = kvm_vm_ioctl(kvm_state, KVM_HAS_DEVICE_ATTR, &attr);
41
- 0x02fffc0c, /* addi.d $t0, $r0,-1(0xfff) */
35
+ return (ret == 0);
42
- 0x1400002d, /* lu12i.w $t1, 1(0x1) */
43
- 0x038011ad, /* ori $t1, $t1, CORE_EN_OFF */
44
- 0x064819ac, /* iocsrwr.w $t0, $t1 */
45
- 0x1400002d, /* lu12i.w $t1, 1(0x1) */
46
- 0x038081ad, /* ori $t1, $t1, CORE_BUF_20 */
47
-
48
- /* Wait for wakeup <.L11>: */
49
- 0x06488000, /* idle 0x0 */
50
- 0x03400000, /* andi $zero, $zero, 0x0 */
51
- 0x064809ac, /* iocsrrd.w $t0, $t1 */
52
- 0x43fff59f, /* beqz $t0, -12(0x7ffff4) # 48 <.L11> */
53
-
54
- /* Read and clear IPI interrupt. */
55
- 0x1400002d, /* lu12i.w $t1, 1(0x1) */
56
- 0x064809ac, /* iocsrrd.w $t0, $t1 */
57
- 0x1400002d, /* lu12i.w $t1, 1(0x1) */
58
- 0x038031ad, /* ori $t1, $t1, CORE_CLEAR_OFF */
59
- 0x064819ac, /* iocsrwr.w $t0, $t1 */
60
-
61
- /* Disable IPI interrupt. */
62
- 0x1400002c, /* lu12i.w $t0, 1(0x1) */
63
- 0x04001180, /* csrxchg $zero, $t0, LOONGARCH_CSR_ECFG */
64
-
65
- /* Read mail buf and jump to specified entry */
66
- 0x1400002d, /* lu12i.w $t1, 1(0x1) */
67
- 0x038081ad, /* ori $t1, $t1, CORE_BUF_20 */
68
- 0x06480dac, /* iocsrrd.d $t0, $t1 */
69
- 0x00150181, /* move $ra, $t0 */
70
- 0x4c000020, /* jirl $zero, $ra,0 */
71
-};
72
+static void generate_secondary_boot_code(void *boot_code, bool is_64bit)
73
+{
74
+ uint32_t *p = boot_code;
75
+
36
+
76
+ /* Configure reset ebase. */
37
default:
77
+ stl_p(p++, 0x0400302c); /* csrwr $t0, LOONGARCH_CSR_EENTRY */
38
return false;
78
+
39
}
79
+ /* Disable interrupt. */
40
@@ -XXX,XX +XXX,XX @@ static int kvm_cpu_check_pv_features(CPUState *cs, Error **errp)
80
+ stl_p(p++, 0x0380100c); /* ori $t0, $zero,0x4 */
41
env->pv_features |= BIT(KVM_FEATURE_IPI);
81
+ stl_p(p++, 0x04000180); /* csrxchg $zero, $t0, LOONGARCH_CSR_CRMD */
42
}
82
+
43
83
+ /* Clear mailbox. */
44
+ kvm_supported = kvm_feature_supported(cs, LOONGARCH_FEATURE_STEALTIME);
84
+ stl_p(p++, 0x1400002d); /* lu12i.w $t1, 1(0x1) */
45
+ if (cpu->kvm_steal_time == ON_OFF_AUTO_ON) {
85
+ stl_p(p++, 0x038081ad); /* ori $t1, $t1, CORE_BUF_20 */
46
+ if (!kvm_supported) {
86
+ if (is_64bit) {
47
+ error_setg(errp, "'kvm stealtime' feature not supported by KVM host");
87
+ stl_p(p++, 0x06481da0); /* iocsrwr.d $zero, $t1 */
48
+ return -ENOTSUP;
88
+ } else {
49
+ }
89
+ stl_p(p++, 0x064819a0); /* iocsrwr.w $zero, $t1 */
50
+ } else if (cpu->kvm_steal_time != ON_OFF_AUTO_AUTO) {
51
+ kvm_supported = false;
90
+ }
52
+ }
91
+
53
+
92
+ /* Enable IPI interrupt. */
54
+ if (kvm_supported) {
93
+ stl_p(p++, 0x1400002c); /* lu12i.w $t0, 1(0x1) */
55
+ env->pv_features |= BIT(KVM_FEATURE_STEAL_TIME);
94
+ stl_p(p++, 0x0400118c); /* csrxchg $t0, $t0, LOONGARCH_CSR_ECFG */
56
+ }
95
+ stl_p(p++, 0x02fffc0c); /* addi.d $t0, $r0, -1(0xfff) */
96
+ stl_p(p++, 0x1400002d); /* lu12i.w $t1, 1(0x1) */
97
+ stl_p(p++, 0x038011ad); /* ori $t1, $t1, CORE_EN_OFF */
98
+ stl_p(p++, 0x064819ac); /* iocsrwr.w $t0, $t1 */
99
+ stl_p(p++, 0x1400002d); /* lu12i.w $t1, 1(0x1) */
100
+ stl_p(p++, 0x038081ad); /* ori $t1, $t1, CORE_BUF_20 */
101
+
57
+
102
+ /* Wait for wakeup <.L11>: */
58
return 0;
103
+ stl_p(p++, 0x06488000); /* idle 0x0 */
59
}
104
+ stl_p(p++, 0x03400000); /* andi $zero, $zero, 0x0 */
60
105
+ stl_p(p++, 0x064809ac); /* iocsrrd.w $t0, $t1 */
106
+ stl_p(p++, 0x43fff59f); /* beqz $t0, -12(0x7ffff4) # 48 <.L11> */
107
+
108
+ /* Read and clear IPI interrupt. */
109
+ stl_p(p++, 0x1400002d); /* lu12i.w $t1, 1(0x1) */
110
+ stl_p(p++, 0x064809ac); /* iocsrrd.w $t0, $t1 */
111
+ stl_p(p++, 0x1400002d); /* lu12i.w $t1, 1(0x1) */
112
+ stl_p(p++, 0x038031ad); /* ori $t1, $t1, CORE_CLEAR_OFF */
113
+ stl_p(p++, 0x064819ac); /* iocsrwr.w $t0, $t1 */
114
+
115
+ /* Disable IPI interrupt. */
116
+ stl_p(p++, 0x1400002c); /* lu12i.w $t0, 1(0x1) */
117
+ stl_p(p++, 0x04001180); /* csrxchg $zero, $t0, LOONGARCH_CSR_ECFG */
118
+
119
+ /* Read mail buf and jump to specified entry. */
120
+ stl_p(p++, 0x1400002d); /* lu12i.w $t1, 1(0x1) */
121
+ stl_p(p++, 0x038081ad); /* ori $t1, $t1, CORE_BUF_20 */
122
+ if (is_64bit) {
123
+ stl_p(p++, 0x06480dac); /* iocsrrd.d $t0, $t1 */
124
+ } else {
125
+ stl_p(p++, 0x064809ac); /* iocsrrd.w $t0, $t1 */
126
+ }
127
+ stl_p(p++, 0x00150181); /* move $ra, $t0 */
128
+ stl_p(p++, 0x4c000020); /* jirl $zero, $ra, 0 */
129
+}
130
131
static inline void *guidcpy(void *dst, const void *src)
132
{
133
@@ -XXX,XX +XXX,XX @@ static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info)
134
135
/* Load slave boot code at pflash0 . */
136
void *boot_code = g_malloc0(VIRT_FLASH0_SIZE);
137
- memcpy(boot_code, &slave_boot_code, sizeof(slave_boot_code));
138
+ generate_secondary_boot_code(boot_code, is_la64(&lacpu->env));
139
rom_add_blob_fixed("boot_code", boot_code, VIRT_FLASH0_SIZE, VIRT_FLASH0_BASE);
140
141
CPU_FOREACH(cs) {
142
--
61
--
143
2.34.1
62
2.43.5
diff view generated by jsdifflib
1
From: Bibo Mao <maobibo@loongson.cn>
1
Feature virtual extioi is loongArch virt machine property rather than
2
2
vCPU property in qemu side. However it is vCPU property in KVM kernel
3
ACPI ged is used for power management on LoongArch virt platform, in
3
side, here add loongArch virt machine property checking and enable virt
4
general it is parsed from acpi table. However if system boot directly from
4
extioi feature when vCPU is created.
5
elf kernel, no UEFI bios is provided and acpi table cannot be used also.
6
7
Here acpi ged pm register is exposed with FDT table, it is compatbile
8
with syscon method in FDT table, only that acpi ged pm register is accessed
9
with 8-bit mode, rather with 32-bit mode.
10
5
11
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
6
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
12
Reviewed-by: Song Gao <gaosong@loongson.cn>
7
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
13
Tested-by: Song Gao <gaosong@loongson.cn>
14
Message-Id: <20240918014206.2165821-3-maobibo@loongson.cn>
15
Signed-off-by: Song Gao <gaosong@loongson.cn>
16
---
8
---
17
hw/loongarch/virt.c | 39 +++++++++++++++++++++++++++++++++++++++
9
hw/loongarch/virt.c | 8 --------
18
1 file changed, 39 insertions(+)
10
include/hw/loongarch/virt.h | 9 +++++++++
11
target/loongarch/kvm/kvm.c | 10 ++++++++++
12
3 files changed, 19 insertions(+), 8 deletions(-)
19
13
20
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
14
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
21
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/loongarch/virt.c
16
--- a/hw/loongarch/virt.c
23
+++ b/hw/loongarch/virt.c
17
+++ b/hw/loongarch/virt.c
24
@@ -XXX,XX +XXX,XX @@ static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms,
18
@@ -XXX,XX +XXX,XX @@
25
g_free(nodename);
19
#include "hw/virtio/virtio-iommu.h"
26
}
20
#include "qemu/error-report.h"
27
21
28
+static void fdt_add_ged_reset(LoongArchVirtMachineState *lvms)
22
-static bool virt_is_veiointc_enabled(LoongArchVirtMachineState *lvms)
23
-{
24
- if (lvms->veiointc == ON_OFF_AUTO_OFF) {
25
- return false;
26
- }
27
- return true;
28
-}
29
-
30
static void virt_get_veiointc(Object *obj, Visitor *v, const char *name,
31
void *opaque, Error **errp)
32
{
33
diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h
34
index XXXXXXX..XXXXXXX 100644
35
--- a/include/hw/loongarch/virt.h
36
+++ b/include/hw/loongarch/virt.h
37
@@ -XXX,XX +XXX,XX @@ struct LoongArchVirtMachineState {
38
OBJECT_DECLARE_SIMPLE_TYPE(LoongArchVirtMachineState, LOONGARCH_VIRT_MACHINE)
39
void virt_acpi_setup(LoongArchVirtMachineState *lvms);
40
void virt_fdt_setup(LoongArchVirtMachineState *lvms);
41
+
42
+static inline bool virt_is_veiointc_enabled(LoongArchVirtMachineState *lvms)
29
+{
43
+{
30
+ char *name;
44
+ if (lvms->veiointc == ON_OFF_AUTO_OFF) {
31
+ uint32_t ged_handle;
45
+ return false;
32
+ MachineState *ms = MACHINE(lvms);
46
+ }
33
+ hwaddr base = VIRT_GED_REG_ADDR;
47
+ return true;
34
+ hwaddr size = ACPI_GED_REG_COUNT;
35
+
36
+ ged_handle = qemu_fdt_alloc_phandle(ms->fdt);
37
+ name = g_strdup_printf("/ged@%" PRIx64, base);
38
+ qemu_fdt_add_subnode(ms->fdt, name);
39
+ qemu_fdt_setprop_string(ms->fdt, name, "compatible", "syscon");
40
+ qemu_fdt_setprop_cells(ms->fdt, name, "reg", 0x0, base, 0x0, size);
41
+ /* 8 bit registers */
42
+ qemu_fdt_setprop_cell(ms->fdt, name, "reg-shift", 0);
43
+ qemu_fdt_setprop_cell(ms->fdt, name, "reg-io-width", 1);
44
+ qemu_fdt_setprop_cell(ms->fdt, name, "phandle", ged_handle);
45
+ ged_handle = qemu_fdt_get_phandle(ms->fdt, name);
46
+ g_free(name);
47
+
48
+ name = g_strdup_printf("/reboot");
49
+ qemu_fdt_add_subnode(ms->fdt, name);
50
+ qemu_fdt_setprop_string(ms->fdt, name, "compatible", "syscon-reboot");
51
+ qemu_fdt_setprop_cell(ms->fdt, name, "regmap", ged_handle);
52
+ qemu_fdt_setprop_cell(ms->fdt, name, "offset", ACPI_GED_REG_RESET);
53
+ qemu_fdt_setprop_cell(ms->fdt, name, "value", ACPI_GED_RESET_VALUE);
54
+ g_free(name);
55
+
56
+ name = g_strdup_printf("/poweroff");
57
+ qemu_fdt_add_subnode(ms->fdt, name);
58
+ qemu_fdt_setprop_string(ms->fdt, name, "compatible", "syscon-poweroff");
59
+ qemu_fdt_setprop_cell(ms->fdt, name, "regmap", ged_handle);
60
+ qemu_fdt_setprop_cell(ms->fdt, name, "offset", ACPI_GED_REG_SLEEP_CTL);
61
+ qemu_fdt_setprop_cell(ms->fdt, name, "value", ACPI_GED_SLP_EN |
62
+ (ACPI_GED_SLP_TYP_S5 << ACPI_GED_SLP_TYP_POS));
63
+ g_free(name);
64
+}
48
+}
65
+
49
+
66
static void fdt_add_uart_node(LoongArchVirtMachineState *lvms,
50
#endif
67
uint32_t *pch_pic_phandle, hwaddr base,
51
diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
68
int irq, bool chosen)
52
index XXXXXXX..XXXXXXX 100644
69
@@ -XXX,XX +XXX,XX @@ static void virt_devices_init(DeviceState *pch_pic,
53
--- a/target/loongarch/kvm/kvm.c
70
qdev_get_gpio_in(pch_pic,
54
+++ b/target/loongarch/kvm/kvm.c
71
VIRT_RTC_IRQ - VIRT_GSI_BASE));
55
@@ -XXX,XX +XXX,XX @@
72
fdt_add_rtc_node(lvms, pch_pic_phandle);
56
#include "exec/address-spaces.h"
73
+ fdt_add_ged_reset(lvms);
57
#include "hw/boards.h"
74
58
#include "hw/irq.h"
75
/* acpi ged */
59
+#include "hw/loongarch/virt.h"
76
lvms->acpi_ged = create_acpi_ged(pch_pic, lvms);
60
#include "qemu/log.h"
61
#include "hw/loader.h"
62
#include "system/runstate.h"
63
@@ -XXX,XX +XXX,XX @@ static int kvm_cpu_check_pmu(CPUState *cs, Error **errp)
64
65
static int kvm_cpu_check_pv_features(CPUState *cs, Error **errp)
66
{
67
+ MachineState *ms = MACHINE(qdev_get_machine());
68
LoongArchCPU *cpu = LOONGARCH_CPU(cs);
69
CPULoongArchState *env = cpu_env(cs);
70
bool kvm_supported;
71
@@ -XXX,XX +XXX,XX @@ static int kvm_cpu_check_pv_features(CPUState *cs, Error **errp)
72
env->pv_features |= BIT(KVM_FEATURE_STEAL_TIME);
73
}
74
75
+ if (object_dynamic_cast(OBJECT(ms), TYPE_LOONGARCH_VIRT_MACHINE)) {
76
+ LoongArchVirtMachineState *lvms = LOONGARCH_VIRT_MACHINE(ms);
77
+
78
+ if (virt_is_veiointc_enabled(lvms)) {
79
+ env->pv_features |= BIT(KVM_FEATURE_VIRT_EXTIOI);
80
+ }
81
+ }
82
+
83
return 0;
84
}
85
77
--
86
--
78
2.34.1
87
2.43.5
diff view generated by jsdifflib