1 | The following changes since commit 3b14a767eaca3df5534a162851f04787b363670e: | 1 | The following changes since commit 3f8bcbba3b320c610689576fc47595f1076198dd: |
---|---|---|---|
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 'pull-request-2025-01-08' of https://gitlab.com/thuth/qemu into staging (2025-01-08 11:38:21 -0500) |
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-20250109 |
8 | 8 | ||
9 | for you to fetch changes up to f7c8ef7bad7495d8c84b262a8b243efe39e56b13: | 9 | for you to fetch changes up to c3afa714bcea4c8b014fec99881bd0bdbe8262b8: |
10 | 10 | ||
11 | hw/loongarch/fw_cfg: Build in common_ss[] (2024-09-29 16:22:56 +0800) | 11 | hw/intc/loongarch_extioi: Add irq routing support from physical id (2025-01-09 14:13:41 +0800) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | pull-loongarch-20240929 | 14 | pull-loongarch-20250109 |
15 | 15 | ||
16 | ---------------------------------------------------------------- | 16 | ---------------------------------------------------------------- |
17 | Bibo Mao (3): | 17 | Bibo Mao (4): |
18 | acpi: ged: Add macro for acpi sleep control register | 18 | target/loongarch: Only support 64bit pte width |
19 | hw/loongarch/virt: Add FDT table support with acpi ged pm register | 19 | hw/intc/loongarch_extioi: Get cpu number from possible_cpu_arch_ids |
20 | target/loongarch: Avoid bits shift exceeding width of bool type | 20 | hw/intc/loongarch_extioi: Remove num-cpu property |
21 | hw/intc/loongarch_extioi: Add irq routing support from physical id | ||
21 | 22 | ||
22 | Jiaxun Yang (2): | 23 | Jiaxun Yang (2): |
23 | hw/loongarch/boot: Refactor EFI booting protocol generation | 24 | hw/core/loader: Use ssize_t for efi zboot unpacker |
24 | hw/loongarch/boot: Rework boot code generation | 25 | hw/loongarch/boot: Support Linux raw boot image |
25 | 26 | ||
26 | Philippe Mathieu-Daudé (2): | 27 | hw/arm/boot.c | 2 +- |
27 | hw/loongarch/virt: Remove unnecessary 'cpu.h' inclusion | 28 | hw/core/loader.c | 4 +- |
28 | hw/loongarch/fw_cfg: Build in common_ss[] | 29 | hw/intc/loongarch_extioi.c | 36 +++++++---- |
29 | 30 | hw/intc/loongarch_extioi_common.c | 18 +++++- | |
30 | hw/acpi/generic_event_device.c | 6 +- | 31 | hw/loongarch/boot.c | 69 ++++++++++++++++++++++ |
31 | hw/loongarch/boot.c | 321 +++++++++++++++++++++------------ | 32 | hw/loongarch/virt.c | 1 - |
32 | hw/loongarch/meson.build | 2 +- | 33 | include/hw/intc/loongarch_extioi_common.h | 2 + |
33 | hw/loongarch/virt.c | 39 ++++ | 34 | include/hw/loader.h | 2 +- |
34 | include/hw/acpi/generic_event_device.h | 7 +- | 35 | target/loongarch/helper.h | 1 + |
35 | include/hw/loongarch/boot.h | 106 +++++++++-- | 36 | target/loongarch/tcg/csr_helper.c | 21 +++++++ |
36 | include/hw/loongarch/virt.h | 1 - | 37 | .../tcg/insn_trans/trans_privileged.c.inc | 2 +- |
37 | target/loongarch/arch_dump.c | 6 +- | 38 | target/loongarch/tcg/tlb_helper.c | 17 +----- |
38 | 8 files changed, 342 insertions(+), 146 deletions(-) | 39 | 12 files changed, 142 insertions(+), 33 deletions(-) |
39 | |||
40 | diff view generated by jsdifflib |
1 | From: Jiaxun Yang <jiaxun.yang@flygoat.com> | 1 | From: Jiaxun Yang <jiaxun.yang@flygoat.com> |
---|---|---|---|
2 | 2 | ||
3 | Use stl_p to write instructions so that host endian conversion | 3 | Convert to use sszie_t to represent size internally to avoid |
4 | will be performed. | 4 | large image overflowing the size. |
5 | 5 | ||
6 | Replace mailbox read/write on LoongArch32 systems with 32bit IOCSR | 6 | Suggested-by: Richard Henderson <richard.henderson@linaro.org> |
7 | instructions to prevent illegal instructions. | 7 | Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com> |
8 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | ||
9 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | ||
10 | --- | ||
11 | hw/arm/boot.c | 2 +- | ||
12 | hw/core/loader.c | 4 ++-- | ||
13 | include/hw/loader.h | 2 +- | ||
14 | 3 files changed, 4 insertions(+), 4 deletions(-) | ||
8 | 15 | ||
9 | Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com> | 16 | diff --git a/hw/arm/boot.c b/hw/arm/boot.c |
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 | 17 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/hw/loongarch/boot.c | 18 | --- a/hw/arm/boot.c |
20 | +++ b/hw/loongarch/boot.c | 19 | +++ b/hw/arm/boot.c |
21 | @@ -XXX,XX +XXX,XX @@ unsigned memmap_entries; | 20 | @@ -XXX,XX +XXX,XX @@ static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base, |
22 | ram_addr_t initrd_offset; | 21 | hwaddr kernel_load_offset = KERNEL64_LOAD_ADDR; |
23 | uint64_t initrd_size; | 22 | uint64_t kernel_size = 0; |
24 | 23 | uint8_t *buffer; | |
25 | -static const unsigned int slave_boot_code[] = { | 24 | - int size; |
26 | - /* Configure reset ebase. */ | 25 | + ssize_t size; |
27 | - 0x0400302c, /* csrwr $t0, LOONGARCH_CSR_EENTRY */ | 26 | |
28 | - | 27 | /* On aarch64, it's the bootloader's job to uncompress the kernel. */ |
29 | - /* Disable interrupt. */ | 28 | size = load_image_gzipped_buffer(filename, LOAD_IMAGE_MAX_GUNZIP_BYTES, |
30 | - 0x0380100c, /* ori $t0, $zero,0x4 */ | 29 | diff --git a/hw/core/loader.c b/hw/core/loader.c |
31 | - 0x04000180, /* csrxchg $zero, $t0, LOONGARCH_CSR_CRMD */ | 30 | index XXXXXXX..XXXXXXX 100644 |
32 | - | 31 | --- a/hw/core/loader.c |
33 | - /* Clear mailbox. */ | 32 | +++ b/hw/core/loader.c |
34 | - 0x1400002d, /* lu12i.w $t1, 1(0x1) */ | 33 | @@ -XXX,XX +XXX,XX @@ struct linux_efi_zboot_header { |
35 | - 0x038081ad, /* ori $t1, $t1, CORE_BUF_20 */ | 34 | * |
36 | - 0x06481da0, /* iocsrwr.d $zero, $t1 */ | 35 | * If the image is not a Linux EFI zboot image, do nothing and return success. |
37 | - | 36 | */ |
38 | - /* Enable IPI interrupt. */ | 37 | -ssize_t unpack_efi_zboot_image(uint8_t **buffer, int *size) |
39 | - 0x1400002c, /* lu12i.w $t0, 1(0x1) */ | 38 | +ssize_t unpack_efi_zboot_image(uint8_t **buffer, ssize_t *size) |
40 | - 0x0400118c, /* csrxchg $t0, $t0, LOONGARCH_CSR_ECFG */ | ||
41 | - 0x02fffc0c, /* addi.d $t0, $r0,-1(0xfff) */ | ||
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 | + | ||
76 | + /* Configure reset ebase. */ | ||
77 | + stl_p(p++, 0x0400302c); /* csrwr $t0, LOONGARCH_CSR_EENTRY */ | ||
78 | + | ||
79 | + /* Disable interrupt. */ | ||
80 | + stl_p(p++, 0x0380100c); /* ori $t0, $zero,0x4 */ | ||
81 | + stl_p(p++, 0x04000180); /* csrxchg $zero, $t0, LOONGARCH_CSR_CRMD */ | ||
82 | + | ||
83 | + /* Clear mailbox. */ | ||
84 | + stl_p(p++, 0x1400002d); /* lu12i.w $t1, 1(0x1) */ | ||
85 | + stl_p(p++, 0x038081ad); /* ori $t1, $t1, CORE_BUF_20 */ | ||
86 | + if (is_64bit) { | ||
87 | + stl_p(p++, 0x06481da0); /* iocsrwr.d $zero, $t1 */ | ||
88 | + } else { | ||
89 | + stl_p(p++, 0x064819a0); /* iocsrwr.w $zero, $t1 */ | ||
90 | + } | ||
91 | + | ||
92 | + /* Enable IPI interrupt. */ | ||
93 | + stl_p(p++, 0x1400002c); /* lu12i.w $t0, 1(0x1) */ | ||
94 | + stl_p(p++, 0x0400118c); /* csrxchg $t0, $t0, LOONGARCH_CSR_ECFG */ | ||
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 | + | ||
102 | + /* Wait for wakeup <.L11>: */ | ||
103 | + stl_p(p++, 0x06488000); /* idle 0x0 */ | ||
104 | + stl_p(p++, 0x03400000); /* andi $zero, $zero, 0x0 */ | ||
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 | { | 39 | { |
133 | @@ -XXX,XX +XXX,XX @@ static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info) | 40 | const struct linux_efi_zboot_header *header; |
134 | 41 | uint8_t *data = NULL; | |
135 | /* Load slave boot code at pflash0 . */ | 42 | - int ploff, plsize; |
136 | void *boot_code = g_malloc0(VIRT_FLASH0_SIZE); | 43 | + ssize_t ploff, plsize; |
137 | - memcpy(boot_code, &slave_boot_code, sizeof(slave_boot_code)); | 44 | ssize_t bytes; |
138 | + generate_secondary_boot_code(boot_code, is_la64(&lacpu->env)); | 45 | |
139 | rom_add_blob_fixed("boot_code", boot_code, VIRT_FLASH0_SIZE, VIRT_FLASH0_BASE); | 46 | /* ignore if this is too small to be a EFI zboot image */ |
140 | 47 | diff --git a/include/hw/loader.h b/include/hw/loader.h | |
141 | CPU_FOREACH(cs) { | 48 | index XXXXXXX..XXXXXXX 100644 |
49 | --- a/include/hw/loader.h | ||
50 | +++ b/include/hw/loader.h | ||
51 | @@ -XXX,XX +XXX,XX @@ ssize_t load_image_gzipped_buffer(const char *filename, uint64_t max_sz, | ||
52 | * Returns the size of the decompressed payload if decompression was performed | ||
53 | * successfully. | ||
54 | */ | ||
55 | -ssize_t unpack_efi_zboot_image(uint8_t **buffer, int *size); | ||
56 | +ssize_t unpack_efi_zboot_image(uint8_t **buffer, ssize_t *size); | ||
57 | |||
58 | #define ELF_LOAD_FAILED -1 | ||
59 | #define ELF_LOAD_NOT_ELF -2 | ||
142 | -- | 60 | -- |
143 | 2.34.1 | 61 | 2.43.5 | diff view generated by jsdifflib |
1 | From: Jiaxun Yang <jiaxun.yang@flygoat.com> | 1 | From: Jiaxun Yang <jiaxun.yang@flygoat.com> |
---|---|---|---|
2 | 2 | ||
3 | Refector EFI style booting data structure generation to | 3 | Support booting such image by parsing header as per Linux's |
4 | support 32bit EFI variant on LoongArch32 CPU. | 4 | specification [1]. |
5 | 5 | ||
6 | All data structs are filled with padding members if necessary | 6 | This enabled booting vmlinux.efi/vmlinuz.efi shipped by |
7 | and marked as QEMU_PACKED to avoid host ABI alignment impact. | 7 | distros without supplying BIOS. |
8 | 8 | ||
9 | Host endian is being cared as well. | 9 | [1]: https://docs.kernel.org/arch/loongarch/booting.html |
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 | 10 | ||
15 | Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com> | 11 | Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com> |
16 | Reviewed-by: Song Gao <gaosong@loongson.cn> | 12 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
17 | Message-Id: <20240914-loongarch-booting-v1-1-1517cae11c10@flygoat.com> | 13 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> |
18 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
19 | --- | 14 | --- |
20 | hw/loongarch/boot.c | 220 ++++++++++++++++++++++++------------ | 15 | hw/loongarch/boot.c | 69 +++++++++++++++++++++++++++++++++++++++++++++ |
21 | include/hw/loongarch/boot.h | 106 +++++++++++++---- | 16 | 1 file changed, 69 insertions(+) |
22 | 2 files changed, 237 insertions(+), 89 deletions(-) | ||
23 | 17 | ||
24 | diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c | 18 | diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c |
25 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/hw/loongarch/boot.c | 20 | --- a/hw/loongarch/boot.c |
27 | +++ b/hw/loongarch/boot.c | 21 | +++ b/hw/loongarch/boot.c |
28 | @@ -XXX,XX +XXX,XX @@ | 22 | @@ -XXX,XX +XXX,XX @@ |
29 | * Copyright (c) 2023 Loongson Technology Corporation Limited | 23 | #include "system/reset.h" |
30 | */ | 24 | #include "system/qtest.h" |
31 | 25 | ||
32 | +#include <zlib.h> | 26 | +/* |
33 | #include "qemu/osdep.h" | 27 | + * Linux Image Format |
34 | #include "qemu/units.h" | 28 | + * https://docs.kernel.org/arch/loongarch/booting.html |
35 | #include "target/loongarch/cpu.h" | 29 | + */ |
36 | @@ -XXX,XX +XXX,XX @@ static const unsigned int slave_boot_code[] = { | 30 | +#define LINUX_PE_MAGIC 0x818223cd |
37 | 31 | +#define MZ_MAGIC 0x5a4d /* "MZ" */ | |
38 | /* Clear mailbox. */ | ||
39 | 0x1400002d, /* lu12i.w $t1, 1(0x1) */ | ||
40 | - 0x038081ad, /* ori $t1, $t1, CORE_BUF_20 */ | ||
41 | + 0x038081ad, /* ori $t1, $t1, CORE_BUF_20 */ | ||
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 | } | ||
48 | |||
49 | -static void init_efi_boot_memmap(struct efi_system_table *systab, | ||
50 | - void *p, void *start) | ||
51 | +static void efi_hdr_crc32(efi_table_hdr_t *hdr) | ||
52 | { | ||
53 | - unsigned i; | ||
54 | - struct efi_boot_memmap *boot_memmap = p; | ||
55 | - efi_guid_t tbl_guid = LINUX_EFI_BOOT_MEMMAP_GUID; | ||
56 | - | ||
57 | - /* efi_configuration_table 1 */ | ||
58 | - guidcpy(&systab->tables[0].guid, &tbl_guid); | ||
59 | - systab->tables[0].table = (struct efi_configuration_table *)(p - start); | ||
60 | - systab->nr_tables = 1; | ||
61 | - | ||
62 | - boot_memmap->desc_size = sizeof(efi_memory_desc_t); | ||
63 | - boot_memmap->desc_ver = 1; | ||
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 | } | ||
80 | |||
81 | -static void init_efi_initrd_table(struct efi_system_table *systab, | ||
82 | - void *p, void *start) | ||
83 | +static void init_efi_vendor_string(void **p) | ||
84 | { | ||
85 | - efi_guid_t tbl_guid = LINUX_EFI_INITRD_MEDIA_GUID; | ||
86 | - struct efi_initrd *initrd_table = p; | ||
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 | } | ||
105 | |||
106 | -static void init_efi_fdt_table(struct efi_system_table *systab) | ||
107 | +static void memmap_write_descs(efi_memory_desc_t *map) | ||
108 | { | ||
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 | + | 32 | + |
129 | + switch (memmap_table[i].type) { | 33 | +struct loongarch_linux_hdr { |
130 | + case MEMMAP_TYPE_MEMORY: | 34 | + uint32_t mz_magic; |
131 | + efi_type = EFI_CONVENTIONAL_MEMORY; | 35 | + uint32_t res0; |
132 | + break; | 36 | + uint64_t kernel_entry; |
133 | + case MEMMAP_TYPE_RESERVED: | 37 | + uint64_t kernel_size; |
134 | + efi_type = EFI_RESERVED_TYPE; | 38 | + uint64_t load_offset; |
135 | + break; | 39 | + uint64_t res1; |
136 | + case MEMMAP_TYPE_ACPI: | 40 | + uint64_t res2; |
137 | + efi_type = EFI_ACPI_RECLAIM_MEMORY; | 41 | + uint64_t res3; |
138 | + break; | 42 | + uint32_t linux_pe_magic; |
139 | + case MEMMAP_TYPE_NVS: | 43 | + uint32_t pe_header_offset; |
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; | 44 | +} QEMU_PACKED; |
381 | + | 45 | + |
382 | +struct efi_system_table_32 { | 46 | struct memmap_entry *memmap_table; |
383 | + efi_table_hdr_t hdr; | 47 | unsigned memmap_entries; |
384 | + uint32_t fw_vendor; /* physical addr of CHAR16 vendor string */ | 48 | |
385 | + uint32_t fw_revision; | 49 | @@ -XXX,XX +XXX,XX @@ static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr) |
386 | + uint32_t con_in_handle; | 50 | return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS); |
387 | + uint32_t con_in; | 51 | } |
388 | + uint32_t con_out_handle; | 52 | |
389 | + uint32_t con_out; | 53 | +static int64_t load_loongarch_linux_image(const char *filename, |
390 | + uint32_t stderr_handle; | 54 | + uint64_t *kernel_entry, |
391 | + uint32_t stderr_placeholder; | 55 | + uint64_t *kernel_low, |
392 | + uint32_t runtime; | 56 | + uint64_t *kernel_high) |
393 | + uint32_t boottime; | 57 | +{ |
394 | + uint32_t nr_tables; | 58 | + gsize len; |
395 | + uint32_t tables; | 59 | + ssize_t size; |
396 | +} QEMU_PACKED; | 60 | + uint8_t *buffer; |
61 | + struct loongarch_linux_hdr *hdr; | ||
397 | + | 62 | + |
398 | +struct efi_system_table_64 { | 63 | + /* Load as raw file otherwise */ |
399 | efi_table_hdr_t hdr; | 64 | + if (!g_file_get_contents(filename, (char **)&buffer, &len, NULL)) { |
400 | uint64_t fw_vendor; /* physical addr of CHAR16 vendor string */ | 65 | + return -1; |
401 | uint32_t fw_revision; | 66 | + } |
402 | + uint32_t __pad1; | 67 | + size = len; |
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 | + | 68 | + |
434 | +struct efi_boot_memmap_32 { | 69 | + /* Unpack the image if it is a EFI zboot image */ |
435 | + uint32_t map_size; | 70 | + if (unpack_efi_zboot_image(&buffer, &size) < 0) { |
436 | + uint32_t desc_size; | 71 | + g_free(buffer); |
437 | + uint32_t desc_ver; | 72 | + return -1; |
438 | + uint32_t map_key; | 73 | + } |
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 | + | 74 | + |
456 | +struct efi_initrd_32 { | 75 | + hdr = (struct loongarch_linux_hdr *)buffer; |
457 | + uint32_t base; | 76 | + |
458 | + uint32_t size; | 77 | + if (extract32(le32_to_cpu(hdr->mz_magic), 0, 16) != MZ_MAGIC || |
459 | +} QEMU_PACKED; | 78 | + le32_to_cpu(hdr->linux_pe_magic) != LINUX_PE_MAGIC) { |
460 | 79 | + g_free(buffer); | |
461 | -struct efi_initrd { | 80 | + return -1; |
462 | +struct efi_initrd_64 { | 81 | + } |
463 | uint64_t base; | 82 | + |
464 | uint64_t size; | 83 | + /* Early kernel versions may have those fields in virtual address */ |
465 | -}; | 84 | + *kernel_entry = extract64(le64_to_cpu(hdr->kernel_entry), |
466 | +} QEMU_PACKED; | 85 | + 0, TARGET_PHYS_ADDR_SPACE_BITS); |
467 | 86 | + *kernel_low = extract64(le64_to_cpu(hdr->load_offset), | |
468 | struct loongarch_boot_info { | 87 | + 0, TARGET_PHYS_ADDR_SPACE_BITS); |
469 | uint64_t ram_size; | 88 | + *kernel_high = *kernel_low + size; |
470 | @@ -XXX,XX +XXX,XX @@ extern unsigned memmap_entries; | 89 | + |
471 | struct memmap_entry { | 90 | + rom_add_blob_fixed(filename, buffer, size, *kernel_low); |
472 | uint64_t address; | 91 | + |
473 | uint64_t length; | 92 | + g_free(buffer); |
474 | + /* E820 style type */ | 93 | + |
475 | +#define MEMMAP_TYPE_MEMORY 1 | 94 | + return size; |
476 | +#define MEMMAP_TYPE_RESERVED 2 | 95 | +} |
477 | +#define MEMMAP_TYPE_ACPI 3 | 96 | + |
478 | +#define MEMMAP_TYPE_NVS 4 | 97 | static int64_t load_kernel_info(struct loongarch_boot_info *info) |
479 | uint32_t type; | 98 | { |
480 | uint32_t reserved; | 99 | uint64_t kernel_entry, kernel_low, kernel_high; |
481 | }; | 100 | @@ -XXX,XX +XXX,XX @@ static int64_t load_kernel_info(struct loongarch_boot_info *info) |
101 | &kernel_entry, &kernel_low, | ||
102 | &kernel_high, NULL, 0, | ||
103 | EM_LOONGARCH, 1, 0); | ||
104 | + if (kernel_size < 0) { | ||
105 | + kernel_size = load_loongarch_linux_image(info->kernel_filename, | ||
106 | + &kernel_entry, &kernel_low, | ||
107 | + &kernel_high); | ||
108 | + } | ||
109 | |||
110 | if (kernel_size < 0) { | ||
111 | error_report("could not load kernel '%s': %s", | ||
482 | -- | 112 | -- |
483 | 2.34.1 | 113 | 2.43.5 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <philmd@linaro.org> | 1 | iFrom LoongArch Reference Manual pte width can be 64bit, 128bit |
---|---|---|---|
2 | or more. Instead real hardware only supports 64bit pte width. | ||
3 | For 12bit pte, there is no detail definition for all 128bit | ||
4 | from manual. | ||
2 | 5 | ||
3 | Nothing in LoongArch fw_cfg.c requires target specific definitions. | 6 | Here only 64bit pte width is supported for simplicity, will add |
7 | this in later if real hw support it and there is definition for | ||
8 | all the bits from manual. | ||
4 | 9 | ||
5 | Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 10 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
6 | Reviewed-by: Song Gao <gaosong@loongson.cn> | 11 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> |
7 | Message-Id: <20240927213254.17552-3-philmd@linaro.org> | ||
8 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
9 | --- | 12 | --- |
10 | hw/loongarch/meson.build | 2 +- | 13 | target/loongarch/helper.h | 1 + |
11 | 1 file changed, 1 insertion(+), 1 deletion(-) | 14 | target/loongarch/tcg/csr_helper.c | 21 +++++++++++++++++++ |
15 | .../tcg/insn_trans/trans_privileged.c.inc | 2 +- | ||
16 | target/loongarch/tcg/tlb_helper.c | 17 +++------------ | ||
17 | 4 files changed, 26 insertions(+), 15 deletions(-) | ||
12 | 18 | ||
13 | diff --git a/hw/loongarch/meson.build b/hw/loongarch/meson.build | 19 | diff --git a/target/loongarch/helper.h b/target/loongarch/helper.h |
14 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/hw/loongarch/meson.build | 21 | --- a/target/loongarch/helper.h |
16 | +++ b/hw/loongarch/meson.build | 22 | +++ b/target/loongarch/helper.h |
23 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_2(csrwr_estat, i64, env, tl) | ||
24 | DEF_HELPER_2(csrwr_asid, i64, env, tl) | ||
25 | DEF_HELPER_2(csrwr_tcfg, i64, env, tl) | ||
26 | DEF_HELPER_2(csrwr_ticlr, i64, env, tl) | ||
27 | +DEF_HELPER_2(csrwr_pwcl, i64, env, tl) | ||
28 | DEF_HELPER_2(iocsrrd_b, i64, env, tl) | ||
29 | DEF_HELPER_2(iocsrrd_h, i64, env, tl) | ||
30 | DEF_HELPER_2(iocsrrd_w, i64, env, tl) | ||
31 | diff --git a/target/loongarch/tcg/csr_helper.c b/target/loongarch/tcg/csr_helper.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/target/loongarch/tcg/csr_helper.c | ||
34 | +++ b/target/loongarch/tcg/csr_helper.c | ||
17 | @@ -XXX,XX +XXX,XX @@ | 35 | @@ -XXX,XX +XXX,XX @@ |
18 | loongarch_ss = ss.source_set() | 36 | */ |
19 | loongarch_ss.add(files( | 37 | |
20 | - 'fw_cfg.c', | 38 | #include "qemu/osdep.h" |
21 | 'boot.c', | 39 | +#include "qemu/log.h" |
22 | )) | 40 | #include "qemu/main-loop.h" |
23 | +common_ss.add(when: 'CONFIG_LOONGARCH_VIRT', if_true: files('fw_cfg.c')) | 41 | #include "cpu.h" |
24 | loongarch_ss.add(when: 'CONFIG_LOONGARCH_VIRT', if_true: files('virt.c')) | 42 | #include "internals.h" |
25 | loongarch_ss.add(when: 'CONFIG_ACPI', if_true: files('acpi-build.c')) | 43 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_csrwr_ticlr(CPULoongArchState *env, target_ulong val) |
26 | 44 | } | |
45 | return old_v; | ||
46 | } | ||
47 | + | ||
48 | +target_ulong helper_csrwr_pwcl(CPULoongArchState *env, target_ulong val) | ||
49 | +{ | ||
50 | + int shift; | ||
51 | + int64_t old_v = env->CSR_PWCL; | ||
52 | + | ||
53 | + /* | ||
54 | + * The real hardware only supports 64bit PTE width now, 128bit or others | ||
55 | + * treated as illegal. | ||
56 | + */ | ||
57 | + shift = FIELD_EX64(val, CSR_PWCL, PTEWIDTH); | ||
58 | + if (shift) { | ||
59 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
60 | + "Attempted set pte width with %d bit\n", 64 << shift); | ||
61 | + val = FIELD_DP64(val, CSR_PWCL, PTEWIDTH, 0); | ||
62 | + } | ||
63 | + | ||
64 | + env->CSR_PWCL = val; | ||
65 | + return old_v; | ||
66 | +} | ||
67 | diff --git a/target/loongarch/tcg/insn_trans/trans_privileged.c.inc b/target/loongarch/tcg/insn_trans/trans_privileged.c.inc | ||
68 | index XXXXXXX..XXXXXXX 100644 | ||
69 | --- a/target/loongarch/tcg/insn_trans/trans_privileged.c.inc | ||
70 | +++ b/target/loongarch/tcg/insn_trans/trans_privileged.c.inc | ||
71 | @@ -XXX,XX +XXX,XX @@ static const CSRInfo csr_info[] = { | ||
72 | CSR_OFF(PGDL), | ||
73 | CSR_OFF(PGDH), | ||
74 | CSR_OFF_FUNCS(PGD, CSRFL_READONLY, gen_helper_csrrd_pgd, NULL), | ||
75 | - CSR_OFF(PWCL), | ||
76 | + CSR_OFF_FUNCS(PWCL, 0, NULL, gen_helper_csrwr_pwcl), | ||
77 | CSR_OFF(PWCH), | ||
78 | CSR_OFF(STLBPS), | ||
79 | CSR_OFF(RVACFG), | ||
80 | diff --git a/target/loongarch/tcg/tlb_helper.c b/target/loongarch/tcg/tlb_helper.c | ||
81 | index XXXXXXX..XXXXXXX 100644 | ||
82 | --- a/target/loongarch/tcg/tlb_helper.c | ||
83 | +++ b/target/loongarch/tcg/tlb_helper.c | ||
84 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_lddir(CPULoongArchState *env, target_ulong base, | ||
85 | { | ||
86 | CPUState *cs = env_cpu(env); | ||
87 | target_ulong badvaddr, index, phys, ret; | ||
88 | - int shift; | ||
89 | uint64_t dir_base, dir_width; | ||
90 | |||
91 | if (unlikely((level == 0) || (level > 4))) { | ||
92 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_lddir(CPULoongArchState *env, target_ulong base, | ||
93 | |||
94 | badvaddr = env->CSR_TLBRBADV; | ||
95 | base = base & TARGET_PHYS_MASK; | ||
96 | - | ||
97 | - /* 0:64bit, 1:128bit, 2:192bit, 3:256bit */ | ||
98 | - shift = FIELD_EX64(env->CSR_PWCL, CSR_PWCL, PTEWIDTH); | ||
99 | - shift = (shift + 1) * 3; | ||
100 | - | ||
101 | get_dir_base_width(env, &dir_base, &dir_width, level); | ||
102 | index = (badvaddr >> dir_base) & ((1 << dir_width) - 1); | ||
103 | - phys = base | index << shift; | ||
104 | + phys = base | index << 3; | ||
105 | ret = ldq_phys(cs->as, phys) & TARGET_PHYS_MASK; | ||
106 | return ret; | ||
107 | } | ||
108 | @@ -XXX,XX +XXX,XX @@ void helper_ldpte(CPULoongArchState *env, target_ulong base, target_ulong odd, | ||
109 | { | ||
110 | CPUState *cs = env_cpu(env); | ||
111 | target_ulong phys, tmp0, ptindex, ptoffset0, ptoffset1, ps, badv; | ||
112 | - int shift; | ||
113 | uint64_t ptbase = FIELD_EX64(env->CSR_PWCL, CSR_PWCL, PTBASE); | ||
114 | uint64_t ptwidth = FIELD_EX64(env->CSR_PWCL, CSR_PWCL, PTWIDTH); | ||
115 | uint64_t dir_base, dir_width; | ||
116 | @@ -XXX,XX +XXX,XX @@ void helper_ldpte(CPULoongArchState *env, target_ulong base, target_ulong odd, | ||
117 | tmp0 += MAKE_64BIT_MASK(ps, 1); | ||
118 | } | ||
119 | } else { | ||
120 | - /* 0:64bit, 1:128bit, 2:192bit, 3:256bit */ | ||
121 | - shift = FIELD_EX64(env->CSR_PWCL, CSR_PWCL, PTEWIDTH); | ||
122 | - shift = (shift + 1) * 3; | ||
123 | badv = env->CSR_TLBRBADV; | ||
124 | |||
125 | ptindex = (badv >> ptbase) & ((1 << ptwidth) - 1); | ||
126 | ptindex = ptindex & ~0x1; /* clear bit 0 */ | ||
127 | - ptoffset0 = ptindex << shift; | ||
128 | - ptoffset1 = (ptindex + 1) << shift; | ||
129 | - | ||
130 | + ptoffset0 = ptindex << 3; | ||
131 | + ptoffset1 = (ptindex + 1) << 3; | ||
132 | phys = base | (odd ? ptoffset1 : ptoffset0); | ||
133 | tmp0 = ldq_phys(cs->as, phys) & TARGET_PHYS_MASK; | ||
134 | ps = ptbase; | ||
27 | -- | 135 | -- |
28 | 2.34.1 | 136 | 2.43.5 |
29 | |||
30 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <philmd@linaro.org> | 1 | Supported CPU number can be acquired from function |
---|---|---|---|
2 | possible_cpu_arch_ids(), cpu-num property is not necessary. | ||
2 | 3 | ||
3 | Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 4 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | Reviewed-by: Song Gao <gaosong@loongson.cn> | 5 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> |
5 | Message-Id: <20240927213254.17552-2-philmd@linaro.org> | ||
6 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
7 | --- | 6 | --- |
8 | include/hw/loongarch/virt.h | 1 - | 7 | hw/intc/loongarch_extioi.c | 6 ------ |
9 | 1 file changed, 1 deletion(-) | 8 | hw/intc/loongarch_extioi_common.c | 17 +++++++++++++++-- |
9 | include/hw/intc/loongarch_extioi_common.h | 2 ++ | ||
10 | 3 files changed, 17 insertions(+), 8 deletions(-) | ||
10 | 11 | ||
11 | diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h | 12 | diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c |
12 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/include/hw/loongarch/virt.h | 14 | --- a/hw/intc/loongarch_extioi.c |
14 | +++ b/include/hw/loongarch/virt.h | 15 | +++ b/hw/intc/loongarch_extioi.c |
16 | @@ -XXX,XX +XXX,XX @@ static void loongarch_extioi_realize(DeviceState *dev, Error **errp) | ||
17 | s->status |= BIT(EXTIOI_ENABLE); | ||
18 | } | ||
19 | |||
20 | - s->cpu = g_new0(ExtIOICore, s->num_cpu); | ||
21 | - if (s->cpu == NULL) { | ||
22 | - error_setg(errp, "Memory allocation for ExtIOICore faile"); | ||
23 | - return; | ||
24 | - } | ||
25 | - | ||
26 | for (i = 0; i < s->num_cpu; i++) { | ||
27 | for (pin = 0; pin < LS3A_INTC_IP; pin++) { | ||
28 | qdev_init_gpio_out(dev, &s->cpu[i].parent_irq[pin], 1); | ||
29 | diff --git a/hw/intc/loongarch_extioi_common.c b/hw/intc/loongarch_extioi_common.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/hw/intc/loongarch_extioi_common.c | ||
32 | +++ b/hw/intc/loongarch_extioi_common.c | ||
15 | @@ -XXX,XX +XXX,XX @@ | 33 | @@ -XXX,XX +XXX,XX @@ |
16 | #ifndef HW_LOONGARCH_H | 34 | static void loongarch_extioi_common_realize(DeviceState *dev, Error **errp) |
17 | #define HW_LOONGARCH_H | 35 | { |
18 | 36 | LoongArchExtIOICommonState *s = (LoongArchExtIOICommonState *)dev; | |
19 | -#include "target/loongarch/cpu.h" | 37 | + MachineState *machine = MACHINE(qdev_get_machine()); |
20 | #include "hw/boards.h" | 38 | + MachineClass *mc = MACHINE_GET_CLASS(machine); |
21 | #include "qemu/queue.h" | 39 | + const CPUArchIdList *id_list; |
22 | #include "hw/block/flash.h" | 40 | + int i; |
41 | |||
42 | - if (s->num_cpu == 0) { | ||
43 | - error_setg(errp, "num-cpu must be at least 1"); | ||
44 | + assert(mc->possible_cpu_arch_ids); | ||
45 | + id_list = mc->possible_cpu_arch_ids(machine); | ||
46 | + s->num_cpu = id_list->len; | ||
47 | + s->cpu = g_new0(ExtIOICore, s->num_cpu); | ||
48 | + if (s->cpu == NULL) { | ||
49 | + error_setg(errp, "Memory allocation for ExtIOICore faile"); | ||
50 | return; | ||
51 | } | ||
52 | + | ||
53 | + for (i = 0; i < s->num_cpu; i++) { | ||
54 | + s->cpu[i].arch_id = id_list->cpus[i].arch_id; | ||
55 | + s->cpu[i].cpu = CPU(id_list->cpus[i].cpu); | ||
56 | + } | ||
57 | } | ||
58 | |||
59 | static int loongarch_extioi_common_pre_save(void *opaque) | ||
60 | diff --git a/include/hw/intc/loongarch_extioi_common.h b/include/hw/intc/loongarch_extioi_common.h | ||
61 | index XXXXXXX..XXXXXXX 100644 | ||
62 | --- a/include/hw/intc/loongarch_extioi_common.h | ||
63 | +++ b/include/hw/intc/loongarch_extioi_common.h | ||
64 | @@ -XXX,XX +XXX,XX @@ typedef struct ExtIOICore { | ||
65 | uint32_t coreisr[EXTIOI_IRQS_GROUP_COUNT]; | ||
66 | DECLARE_BITMAP(sw_isr[LS3A_INTC_IP], EXTIOI_IRQS); | ||
67 | qemu_irq parent_irq[LS3A_INTC_IP]; | ||
68 | + uint64_t arch_id; | ||
69 | + CPUState *cpu; | ||
70 | } ExtIOICore; | ||
71 | |||
72 | struct LoongArchExtIOICommonState { | ||
23 | -- | 73 | -- |
24 | 2.34.1 | 74 | 2.43.5 |
25 | |||
26 | diff view generated by jsdifflib |
1 | From: Bibo Mao <maobibo@loongson.cn> | 1 | Since cpu number can be acquired from possible_cpu_arch_ids(), |
---|---|---|---|
2 | 2 | num-cpu property is not necessary. Here remove num-cpu property | |
3 | ACPI ged is used for power management on LoongArch virt platform, in | 3 | for object TYPE_LOONGARCH_EXTIOI_COMMON object. |
4 | general it is parsed from acpi table. However if system boot directly from | ||
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 | 4 | ||
11 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | 5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
12 | Reviewed-by: Song Gao <gaosong@loongson.cn> | 6 | 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 | --- | 7 | --- |
17 | hw/loongarch/virt.c | 39 +++++++++++++++++++++++++++++++++++++++ | 8 | hw/intc/loongarch_extioi_common.c | 1 - |
18 | 1 file changed, 39 insertions(+) | 9 | hw/loongarch/virt.c | 1 - |
10 | 2 files changed, 2 deletions(-) | ||
19 | 11 | ||
12 | diff --git a/hw/intc/loongarch_extioi_common.c b/hw/intc/loongarch_extioi_common.c | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/hw/intc/loongarch_extioi_common.c | ||
15 | +++ b/hw/intc/loongarch_extioi_common.c | ||
16 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_loongarch_extioi = { | ||
17 | }; | ||
18 | |||
19 | static const Property extioi_properties[] = { | ||
20 | - DEFINE_PROP_UINT32("num-cpu", LoongArchExtIOICommonState, num_cpu, 1), | ||
21 | DEFINE_PROP_BIT("has-virtualization-extension", LoongArchExtIOICommonState, | ||
22 | features, EXTIOI_HAS_VIRT_EXTENSION, 0), | ||
23 | }; | ||
20 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | 24 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c |
21 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/hw/loongarch/virt.c | 26 | --- a/hw/loongarch/virt.c |
23 | +++ b/hw/loongarch/virt.c | 27 | +++ b/hw/loongarch/virt.c |
24 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms, | 28 | @@ -XXX,XX +XXX,XX @@ static void virt_irq_init(LoongArchVirtMachineState *lvms) |
25 | g_free(nodename); | 29 | |
26 | } | 30 | /* Create EXTIOI device */ |
27 | 31 | extioi = qdev_new(TYPE_LOONGARCH_EXTIOI); | |
28 | +static void fdt_add_ged_reset(LoongArchVirtMachineState *lvms) | 32 | - qdev_prop_set_uint32(extioi, "num-cpu", ms->smp.cpus); |
29 | +{ | 33 | if (virt_is_veiointc_enabled(lvms)) { |
30 | + char *name; | 34 | qdev_prop_set_bit(extioi, "has-virtualization-extension", true); |
31 | + uint32_t ged_handle; | 35 | } |
32 | + MachineState *ms = MACHINE(lvms); | ||
33 | + hwaddr base = VIRT_GED_REG_ADDR; | ||
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 | +} | ||
65 | + | ||
66 | static void fdt_add_uart_node(LoongArchVirtMachineState *lvms, | ||
67 | uint32_t *pch_pic_phandle, hwaddr base, | ||
68 | int irq, bool chosen) | ||
69 | @@ -XXX,XX +XXX,XX @@ static void virt_devices_init(DeviceState *pch_pic, | ||
70 | qdev_get_gpio_in(pch_pic, | ||
71 | VIRT_RTC_IRQ - VIRT_GSI_BASE)); | ||
72 | fdt_add_rtc_node(lvms, pch_pic_phandle); | ||
73 | + fdt_add_ged_reset(lvms); | ||
74 | |||
75 | /* acpi ged */ | ||
76 | lvms->acpi_ged = create_acpi_ged(pch_pic, lvms); | ||
77 | -- | 36 | -- |
78 | 2.34.1 | 37 | 2.43.5 | diff view generated by jsdifflib |
1 | From: Bibo Mao <maobibo@loongson.cn> | 1 | The simliar with IPI interrupt controller, physical cpu id is used |
---|---|---|---|
2 | 2 | for irq routing for extioi interrupt controller. | |
3 | Macro definition is added for acpi sleep control register, ged emulation | ||
4 | driver can use the macro , also it can be used in FDT table if ged is | ||
5 | exposed with FDT table. | ||
6 | 3 | ||
7 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | 4 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
8 | Reviewed-by: Igor Mammedov <imammedo@redhat.com> | 5 | 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 | --- | 6 | --- |
12 | hw/acpi/generic_event_device.c | 6 +++--- | 7 | hw/intc/loongarch_extioi.c | 30 ++++++++++++++++++++++++++---- |
13 | include/hw/acpi/generic_event_device.h | 7 +++++-- | 8 | 1 file changed, 26 insertions(+), 4 deletions(-) |
14 | 2 files changed, 8 insertions(+), 5 deletions(-) | ||
15 | 9 | ||
16 | diff --git a/hw/acpi/generic_event_device.c b/hw/acpi/generic_event_device.c | 10 | diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c |
17 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/hw/acpi/generic_event_device.c | 12 | --- a/hw/intc/loongarch_extioi.c |
19 | +++ b/hw/acpi/generic_event_device.c | 13 | +++ b/hw/intc/loongarch_extioi.c |
20 | @@ -XXX,XX +XXX,XX @@ static void ged_regs_write(void *opaque, hwaddr addr, uint64_t data, | 14 | @@ -XXX,XX +XXX,XX @@ |
21 | 15 | #include "hw/intc/loongarch_extioi.h" | |
22 | switch (addr) { | 16 | #include "trace.h" |
23 | case ACPI_GED_REG_SLEEP_CTL: | 17 | |
24 | - slp_typ = (data >> 2) & 0x07; | 18 | +static int extioi_get_index_from_archid(LoongArchExtIOICommonState *s, |
25 | - slp_en = (data >> 5) & 0x01; | 19 | + uint64_t arch_id) |
26 | - if (slp_en && slp_typ == 5) { | 20 | +{ |
27 | + slp_typ = (data >> ACPI_GED_SLP_TYP_POS) & ACPI_GED_SLP_TYP_MASK; | 21 | + int i; |
28 | + slp_en = !!(data & ACPI_GED_SLP_EN); | 22 | + |
29 | + if (slp_en && slp_typ == ACPI_GED_SLP_TYP_S5) { | 23 | + for (i = 0; i < s->num_cpu; i++) { |
30 | qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); | 24 | + if (s->cpu[i].arch_id == arch_id) { |
25 | + break; | ||
26 | + } | ||
27 | + } | ||
28 | + | ||
29 | + if ((i < s->num_cpu) && s->cpu[i].cpu) { | ||
30 | + return i; | ||
31 | + } | ||
32 | + | ||
33 | + return -1; | ||
34 | +} | ||
35 | |||
36 | static void extioi_update_irq(LoongArchExtIOICommonState *s, int irq, int level) | ||
37 | { | ||
38 | @@ -XXX,XX +XXX,XX @@ static inline void extioi_enable_irq(LoongArchExtIOICommonState *s, int index,\ | ||
39 | static inline void extioi_update_sw_coremap(LoongArchExtIOICommonState *s, | ||
40 | int irq, uint64_t val, bool notify) | ||
41 | { | ||
42 | - int i, cpu; | ||
43 | + int i, cpu, cpuid; | ||
44 | |||
45 | /* | ||
46 | * loongarch only support little endian, | ||
47 | @@ -XXX,XX +XXX,XX @@ static inline void extioi_update_sw_coremap(LoongArchExtIOICommonState *s, | ||
48 | val = cpu_to_le64(val); | ||
49 | |||
50 | for (i = 0; i < 4; i++) { | ||
51 | - cpu = val & 0xff; | ||
52 | + cpuid = val & 0xff; | ||
53 | val = val >> 8; | ||
54 | |||
55 | if (!(s->status & BIT(EXTIOI_ENABLE_CPU_ENCODE))) { | ||
56 | - cpu = ctz32(cpu); | ||
57 | - cpu = (cpu >= 4) ? 0 : cpu; | ||
58 | + cpuid = ctz32(cpuid); | ||
59 | + cpuid = (cpuid >= 4) ? 0 : cpuid; | ||
60 | + } | ||
61 | + | ||
62 | + cpu = extioi_get_index_from_archid(s, cpuid); | ||
63 | + if (cpu < 0) { | ||
64 | + continue; | ||
31 | } | 65 | } |
32 | return; | 66 | |
33 | diff --git a/include/hw/acpi/generic_event_device.h b/include/hw/acpi/generic_event_device.h | 67 | if (s->sw_coremap[irq + i] == cpu) { |
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/include/hw/acpi/generic_event_device.h | ||
36 | +++ b/include/hw/acpi/generic_event_device.h | ||
37 | @@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED) | ||
38 | /* ACPI_GED_REG_RESET value for reset*/ | ||
39 | #define ACPI_GED_RESET_VALUE 0x42 | ||
40 | |||
41 | -/* ACPI_GED_REG_SLEEP_CTL.SLP_TYP value for S5 (aka poweroff) */ | ||
42 | -#define ACPI_GED_SLP_TYP_S5 0x05 | ||
43 | +/* [ACPI 5.0 Chapter 4.8.3.7] Sleep Control and Status Register */ | ||
44 | +#define ACPI_GED_SLP_TYP_POS 0x2 /* SLP_TYPx Bit Offset */ | ||
45 | +#define ACPI_GED_SLP_TYP_MASK 0x07 /* SLP_TYPx 3-bit mask */ | ||
46 | +#define ACPI_GED_SLP_TYP_S5 0x05 /* System _S5 State (Soft Off) */ | ||
47 | +#define ACPI_GED_SLP_EN 0x20 /* SLP_EN write-only bit */ | ||
48 | |||
49 | #define GED_DEVICE "GED" | ||
50 | #define AML_GED_EVT_REG "EREG" | ||
51 | -- | 68 | -- |
52 | 2.34.1 | 69 | 2.43.5 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Bibo Mao <maobibo@loongson.cn> | ||
2 | 1 | ||
3 | Variable env->cf[i] is defined as bool type, it is treated as int type | ||
4 | with shift operation. However the max possible width is 56 for the shift | ||
5 | operation, exceeding the width of int type. And there is existing api | ||
6 | read_fcc() which is converted to u64 type with bitwise shift, it can be | ||
7 | used to dump fp registers into coredump note segment. | ||
8 | |||
9 | Resolves: Coverity CID 1561133 | ||
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 | ||
20 | --- a/target/loongarch/arch_dump.c | ||
21 | +++ b/target/loongarch/arch_dump.c | ||
22 | @@ -XXX,XX +XXX,XX @@ static int loongarch_write_elf64_fprpreg(WriteCoreDumpFunction f, | ||
23 | |||
24 | loongarch_note_init(¬e, s, "CORE", 5, NT_PRFPREG, sizeof(note.fpu)); | ||
25 | note.fpu.fcsr = cpu_to_dump64(s, env->fcsr0); | ||
26 | - | ||
27 | - for (i = 0; i < 8; i++) { | ||
28 | - note.fpu.fcc |= env->cf[i] << (8 * i); | ||
29 | - } | ||
30 | - note.fpu.fcc = cpu_to_dump64(s, note.fpu.fcc); | ||
31 | + note.fpu.fcc = cpu_to_dump64(s, read_fcc(env)); | ||
32 | |||
33 | for (i = 0; i < 32; ++i) { | ||
34 | note.fpu.fpr[i] = cpu_to_dump64(s, env->fpr[i].vreg.UD[0]); | ||
35 | -- | ||
36 | 2.34.1 | diff view generated by jsdifflib |