* [PATCH v6 00/17] Add boot LoongArch elf kernel with FDT
@ 2024-03-07 16:48 Song Gao
2024-03-07 16:48 ` [PATCH v6 01/17] hw/loongarch: Move boot fucntions to boot.c Song Gao
` (16 more replies)
0 siblings, 17 replies; 46+ messages in thread
From: Song Gao @ 2024-03-07 16:48 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, maobibo
Hi, All
We already support boot efi kernel with bios, but not support boot elf kernel.
This series adds boot elf kernel with FDT.
'LoongArch supports ACPI and FDT. The information that needs to be passed
to the kernel includes the memmap, the initrd, the command line, optionally
the ACPI/FDT tables, and so on' see [1].
Patch 2-8 : Create efi system table, and three efi configuration table
boot_memmap, initd, FDT.
Patch 9-17 : Fixes FDT problems.
Test:
- Start kernel
See [2] start_kernel.sh
- Start qcow2
See [2] start_qcow2.sh
V6:
- Fixes test/compilation failures;
V5:
- Rebase;
V4:
- patch 3 change slave_boot_code[] to const, and 'static void *p ' to
'void *p';
- patch 4 fixes build error;
- patch 10-13, add project and commit link.
V3:
- Load initrd at kernel_high + 4 * kernel_size;
- Load 'boot_rom' at [0 - 1M], the 'boot_rom' includes
slave_boot_code, cmdline_buf and systab_tables;
- R-b and rebase.
V2:
- FDT pcie node adds cells 'msi-map';
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/arch/loongarch/booting.rst?h=v6.7-rc4
[2]: https://github.com/gaosong-loongson/loongarch-binary/releases
Please review!
Thanks.
Song Gao
Song Gao (17):
hw/loongarch: Move boot fucntions to boot.c
hw/loongarch: Add load initrd
hw/loongarch: Add slave cpu boot_code
hw/loongarch: Add init_cmdline
hw/loongarch: Init efi_system_table
hw/loongarch: Init efi_boot_memmap table
hw/loongarch: Init efi_initrd table
hw/loongarch: Init efi_fdt table
hw/loongarch: Fix fdt memory node wrong 'reg'
hw/loongarch: fdt adds cpu interrupt controller node
hw/loongarch: fdt adds Extend I/O Interrupt Controller
hw/loongarch: fdt adds pch_pic Controller
hw/loongarch: fdt adds pch_msi Controller
hw/loongarch: fdt adds pcie irq_map node
hw/loongarch: fdt remove unused irqchip node
hw/loongarch: Add cells missing from uart node
hw/loongarch: Add cells missing from rtc node
hw/loongarch/boot.c | 333 ++++++++++++++++++++++++++
hw/loongarch/meson.build | 1 +
hw/loongarch/virt.c | 363 ++++++++++++++++-------------
include/hw/intc/loongarch_extioi.h | 1 +
include/hw/loongarch/boot.h | 109 +++++++++
include/hw/loongarch/virt.h | 14 ++
include/hw/pci-host/ls7a.h | 2 +
target/loongarch/cpu.h | 2 +
8 files changed, 665 insertions(+), 160 deletions(-)
create mode 100644 hw/loongarch/boot.c
create mode 100644 include/hw/loongarch/boot.h
--
2.34.1
^ permalink raw reply [flat|nested] 46+ messages in thread
* [PATCH v6 01/17] hw/loongarch: Move boot fucntions to boot.c
2024-03-07 16:48 [PATCH v6 00/17] Add boot LoongArch elf kernel with FDT Song Gao
@ 2024-03-07 16:48 ` Song Gao
2024-03-08 8:18 ` maobibo
2024-03-08 8:31 ` Philippe Mathieu-Daudé
2024-03-07 16:48 ` [PATCH v6 02/17] hw/loongarch: Add load initrd Song Gao
` (15 subsequent siblings)
16 siblings, 2 replies; 46+ messages in thread
From: Song Gao @ 2024-03-07 16:48 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, maobibo
Move some boot functions to boot.c and struct
loongarch_boot_info into struct LoongArchMachineState.
Signed-off-by: Song Gao <gaosong@loongson.cn>
Message-Id: <20240301093839.663947-2-gaosong@loongson.cn>
---
hw/loongarch/boot.c | 128 ++++++++++++++++++++++++++++++++++++
hw/loongarch/meson.build | 1 +
hw/loongarch/virt.c | 121 +++-------------------------------
include/hw/loongarch/boot.h | 21 ++++++
include/hw/loongarch/virt.h | 2 +
5 files changed, 160 insertions(+), 113 deletions(-)
create mode 100644 hw/loongarch/boot.c
create mode 100644 include/hw/loongarch/boot.h
diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
new file mode 100644
index 0000000000..a8a725a0a8
--- /dev/null
+++ b/hw/loongarch/boot.c
@@ -0,0 +1,128 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * LoongArch boot helper functions.
+ *
+ * Copyright (c) 2023 Loongson Technology Corporation Limited
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/units.h"
+#include "target/loongarch/cpu.h"
+#include "hw/loongarch/virt.h"
+#include "hw/loader.h"
+#include "elf.h"
+#include "qemu/error-report.h"
+#include "sysemu/reset.h"
+#include "sysemu/qtest.h"
+
+static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
+{
+ return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
+}
+
+static int64_t load_kernel_info(struct loongarch_boot_info *info)
+{
+ uint64_t kernel_entry, kernel_low, kernel_high;
+ ssize_t kernel_size;
+
+ kernel_size = load_elf(info->kernel_filename, NULL,
+ cpu_loongarch_virt_to_phys, NULL,
+ &kernel_entry, &kernel_low,
+ &kernel_high, NULL, 0,
+ EM_LOONGARCH, 1, 0);
+
+ if (kernel_size < 0) {
+ error_report("could not load kernel '%s': %s",
+ info->kernel_filename,
+ load_elf_strerror(kernel_size));
+ exit(1);
+ }
+ return kernel_entry;
+}
+
+static void reset_load_elf(void *opaque)
+{
+ LoongArchCPU *cpu = opaque;
+ CPULoongArchState *env = &cpu->env;
+
+ cpu_reset(CPU(cpu));
+ if (env->load_elf) {
+ cpu_set_pc(CPU(cpu), env->elf_address);
+ }
+}
+
+static void fw_cfg_add_kernel_info(struct loongarch_boot_info *info,
+ FWCfgState *fw_cfg)
+{
+ /*
+ * Expose the kernel, the command line, and the initrd in fw_cfg.
+ * We don't process them here at all, it's all left to the
+ * firmware.
+ */
+ load_image_to_fw_cfg(fw_cfg,
+ FW_CFG_KERNEL_SIZE, FW_CFG_KERNEL_DATA,
+ info->kernel_filename,
+ false);
+
+ if (info->initrd_filename) {
+ load_image_to_fw_cfg(fw_cfg,
+ FW_CFG_INITRD_SIZE, FW_CFG_INITRD_DATA,
+ info->initrd_filename, false);
+ }
+
+ if (info->kernel_cmdline) {
+ fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
+ strlen(info->kernel_cmdline) + 1);
+ fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA,
+ info->kernel_cmdline);
+ }
+}
+
+static void loongarch_firmware_boot(LoongArchMachineState *lams,
+ struct loongarch_boot_info *info)
+{
+ fw_cfg_add_kernel_info(info, lams->fw_cfg);
+}
+
+static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info)
+{
+ int64_t kernel_addr = 0;
+ LoongArchCPU *lacpu;
+ CPUState *cs;
+
+ if (info->kernel_filename) {
+ kernel_addr = load_kernel_info(info);
+ } else {
+ if (!qtest_enabled()) {
+ error_report("Need kernel filename\n");
+ exit(1);
+ }
+ }
+
+ CPU_FOREACH(cs) {
+ lacpu = LOONGARCH_CPU(cs);
+ lacpu->env.load_elf = true;
+ lacpu->env.elf_address = kernel_addr;
+ }
+}
+
+void loongarch_load_kernel(MachineState *ms, struct loongarch_boot_info *info)
+{
+ LoongArchMachineState *lams = LOONGARCH_MACHINE(ms);
+ int i;
+
+ /* register reset function */
+ for (i = 0; i < ms->smp.cpus; i++) {
+ qemu_register_reset(reset_load_elf, LOONGARCH_CPU(qemu_get_cpu(i)));
+ }
+
+ info->kernel_filename = ms->kernel_filename;
+ info->kernel_cmdline = ms->kernel_cmdline;
+ info->initrd_filename = ms->initrd_filename;
+
+ if (lams->bios_loaded) {
+ loongarch_firmware_boot(lams, info);
+ } else {
+ loongarch_direct_kernel_boot(info);
+ }
+}
diff --git a/hw/loongarch/meson.build b/hw/loongarch/meson.build
index c0421502ab..d306d82c2e 100644
--- a/hw/loongarch/meson.build
+++ b/hw/loongarch/meson.build
@@ -1,6 +1,7 @@
loongarch_ss = ss.source_set()
loongarch_ss.add(files(
'fw_cfg.c',
+ 'boot.c',
))
loongarch_ss.add(when: 'CONFIG_LOONGARCH_VIRT', if_true: [files('virt.c'), fdt])
loongarch_ss.add(when: 'CONFIG_ACPI', if_true: files('acpi-build.c'))
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index 1e98d8bda5..bbd5cc1d4d 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -46,14 +46,6 @@
#include "hw/block/flash.h"
#include "qemu/error-report.h"
-
-struct loaderparams {
- uint64_t ram_size;
- const char *kernel_filename;
- const char *kernel_cmdline;
- const char *initrd_filename;
-};
-
static PFlashCFI01 *virt_flash_create1(LoongArchMachineState *lams,
const char *name,
const char *alias_prop_name)
@@ -411,31 +403,6 @@ static void memmap_add_entry(uint64_t address, uint64_t length, uint32_t type)
memmap_entries++;
}
-static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
-{
- return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
-}
-
-static int64_t load_kernel_info(const struct loaderparams *loaderparams)
-{
- uint64_t kernel_entry, kernel_low, kernel_high;
- ssize_t kernel_size;
-
- kernel_size = load_elf(loaderparams->kernel_filename, NULL,
- cpu_loongarch_virt_to_phys, NULL,
- &kernel_entry, &kernel_low,
- &kernel_high, NULL, 0,
- EM_LOONGARCH, 1, 0);
-
- if (kernel_size < 0) {
- error_report("could not load kernel '%s': %s",
- loaderparams->kernel_filename,
- load_elf_strerror(kernel_size));
- exit(1);
- }
- return kernel_entry;
-}
-
static DeviceState *create_acpi_ged(DeviceState *pch_pic, LoongArchMachineState *lams)
{
DeviceState *dev;
@@ -716,67 +683,6 @@ static void loongarch_firmware_init(LoongArchMachineState *lams)
}
}
-static void reset_load_elf(void *opaque)
-{
- LoongArchCPU *cpu = opaque;
- CPULoongArchState *env = &cpu->env;
-
- cpu_reset(CPU(cpu));
- if (env->load_elf) {
- cpu_set_pc(CPU(cpu), env->elf_address);
- }
-}
-
-static void fw_cfg_add_kernel_info(const struct loaderparams *loaderparams,
- FWCfgState *fw_cfg)
-{
- /*
- * Expose the kernel, the command line, and the initrd in fw_cfg.
- * We don't process them here at all, it's all left to the
- * firmware.
- */
- load_image_to_fw_cfg(fw_cfg,
- FW_CFG_KERNEL_SIZE, FW_CFG_KERNEL_DATA,
- loaderparams->kernel_filename,
- false);
-
- if (loaderparams->initrd_filename) {
- load_image_to_fw_cfg(fw_cfg,
- FW_CFG_INITRD_SIZE, FW_CFG_INITRD_DATA,
- loaderparams->initrd_filename, false);
- }
-
- if (loaderparams->kernel_cmdline) {
- fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
- strlen(loaderparams->kernel_cmdline) + 1);
- fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA,
- loaderparams->kernel_cmdline);
- }
-}
-
-static void loongarch_firmware_boot(LoongArchMachineState *lams,
- const struct loaderparams *loaderparams)
-{
- fw_cfg_add_kernel_info(loaderparams, lams->fw_cfg);
-}
-
-static void loongarch_direct_kernel_boot(LoongArchMachineState *lams,
- const struct loaderparams *loaderparams)
-{
- MachineState *machine = MACHINE(lams);
- int64_t kernel_addr = 0;
- LoongArchCPU *lacpu;
- int i;
-
- kernel_addr = load_kernel_info(loaderparams);
- if (!machine->firmware) {
- for (i = 0; i < machine->smp.cpus; i++) {
- lacpu = LOONGARCH_CPU(qemu_get_cpu(i));
- lacpu->env.load_elf = true;
- lacpu->env.elf_address = kernel_addr;
- }
- }
-}
static void loongarch_qemu_write(void *opaque, hwaddr addr,
uint64_t val, unsigned size)
@@ -832,7 +738,6 @@ static void loongarch_init(MachineState *machine)
MachineClass *mc = MACHINE_GET_CLASS(machine);
CPUState *cpu;
char *ramName = NULL;
- struct loaderparams loaderparams = { };
if (!cpu_model) {
cpu_model = LOONGARCH_CPU_TYPE_NAME("la464");
@@ -935,24 +840,8 @@ static void loongarch_init(MachineState *machine)
sizeof(struct memmap_entry) * (memmap_entries));
}
fdt_add_fw_cfg_node(lams);
- loaderparams.ram_size = ram_size;
- loaderparams.kernel_filename = machine->kernel_filename;
- loaderparams.kernel_cmdline = machine->kernel_cmdline;
- loaderparams.initrd_filename = machine->initrd_filename;
- /* load the kernel. */
- if (loaderparams.kernel_filename) {
- if (lams->bios_loaded) {
- loongarch_firmware_boot(lams, &loaderparams);
- } else {
- loongarch_direct_kernel_boot(lams, &loaderparams);
- }
- }
fdt_add_flash_node(lams);
- /* register reset function */
- for (i = 0; i < machine->smp.cpus; i++) {
- lacpu = LOONGARCH_CPU(qemu_get_cpu(i));
- qemu_register_reset(reset_load_elf, lacpu);
- }
+
/* Initialize the IO interrupt subsystem */
loongarch_irq_init(lams);
fdt_add_irqchip_node(lams);
@@ -976,7 +865,13 @@ static void loongarch_init(MachineState *machine)
*/
fdt_base = 1 * MiB;
qemu_fdt_dumpdtb(machine->fdt, lams->fdt_size);
- rom_add_blob_fixed("fdt", machine->fdt, lams->fdt_size, fdt_base);
+ rom_add_blob_fixed_as("fdt", machine->fdt, lams->fdt_size, fdt_base,
+ &address_space_memory);
+ qemu_register_reset_nosnapshotload(qemu_fdt_randomize_seeds,
+ rom_ptr_for_as(&address_space_memory, fdt_base, lams->fdt_size));
+
+ lams->bootinfo.ram_size = ram_size;
+ loongarch_load_kernel(machine, &lams->bootinfo);
}
bool loongarch_is_acpi_enabled(LoongArchMachineState *lams)
diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h
new file mode 100644
index 0000000000..3275c1e295
--- /dev/null
+++ b/include/hw/loongarch/boot.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Definitions for LoongArch boot.
+ *
+ * Copyright (C) 2023 Loongson Technology Corporation Limited
+ */
+
+#ifndef HW_LOONGARCH_BOOT_H
+#define HW_LOONGARCH_BOOT_H
+
+struct loongarch_boot_info {
+ uint64_t ram_size;
+ const char *kernel_filename;
+ const char *kernel_cmdline;
+ const char *initrd_filename;
+ uint64_t a0, a1, a2;
+};
+
+void loongarch_load_kernel(MachineState *ms, struct loongarch_boot_info *info);
+
+#endif /* HW_LOONGARCH_BOOT_H */
diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h
index 252f7df7f4..cf2f2bfb19 100644
--- a/include/hw/loongarch/virt.h
+++ b/include/hw/loongarch/virt.h
@@ -13,6 +13,7 @@
#include "qemu/queue.h"
#include "hw/intc/loongarch_ipi.h"
#include "hw/block/flash.h"
+#include "hw/loongarch/boot.h"
#define LOONGARCH_MAX_CPUS 256
@@ -55,6 +56,7 @@ struct LoongArchMachineState {
MemoryRegion system_iocsr;
MemoryRegion iocsr_mem;
AddressSpace as_iocsr;
+ struct loongarch_boot_info bootinfo;
};
#define TYPE_LOONGARCH_MACHINE MACHINE_TYPE_NAME("virt")
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v6 02/17] hw/loongarch: Add load initrd
2024-03-07 16:48 [PATCH v6 00/17] Add boot LoongArch elf kernel with FDT Song Gao
2024-03-07 16:48 ` [PATCH v6 01/17] hw/loongarch: Move boot fucntions to boot.c Song Gao
@ 2024-03-07 16:48 ` Song Gao
2024-03-08 8:19 ` maobibo
2024-03-07 16:48 ` [PATCH v6 03/17] hw/loongarch: Add slave cpu boot_code Song Gao
` (14 subsequent siblings)
16 siblings, 1 reply; 46+ messages in thread
From: Song Gao @ 2024-03-07 16:48 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, maobibo
we load initrd ramdisk after kernel_high address
Signed-off-by: Song Gao <gaosong@loongson.cn>
Message-Id: <20240301093839.663947-3-gaosong@loongson.cn>
---
hw/loongarch/boot.c | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
index a8a725a0a8..149deb2e01 100644
--- a/hw/loongarch/boot.c
+++ b/hw/loongarch/boot.c
@@ -22,7 +22,8 @@ static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
static int64_t load_kernel_info(struct loongarch_boot_info *info)
{
- uint64_t kernel_entry, kernel_low, kernel_high;
+ uint64_t kernel_entry, kernel_low, kernel_high, initrd_size;
+ ram_addr_t initrd_offset;
ssize_t kernel_size;
kernel_size = load_elf(info->kernel_filename, NULL,
@@ -37,6 +38,32 @@ static int64_t load_kernel_info(struct loongarch_boot_info *info)
load_elf_strerror(kernel_size));
exit(1);
}
+
+ if (info->initrd_filename) {
+ initrd_size = get_image_size(info->initrd_filename);
+ if (initrd_size > 0) {
+ initrd_offset = ROUND_UP(kernel_high + 4 * kernel_size, 64 * KiB);
+
+ if (initrd_offset + initrd_size > info->ram_size) {
+ error_report("memory too small for initial ram disk '%s'",
+ info->initrd_filename);
+ exit(1);
+ }
+
+ initrd_size = load_image_targphys(info->initrd_filename, initrd_offset,
+ info->ram_size - initrd_offset);
+ }
+
+ if (initrd_size == (target_ulong)-1) {
+ error_report("could not load initial ram disk '%s'",
+ info->initrd_filename);
+ exit(1);
+ }
+ } else {
+ error_report("Need initrd!");
+ exit(1);
+ }
+
return kernel_entry;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v6 03/17] hw/loongarch: Add slave cpu boot_code
2024-03-07 16:48 [PATCH v6 00/17] Add boot LoongArch elf kernel with FDT Song Gao
2024-03-07 16:48 ` [PATCH v6 01/17] hw/loongarch: Move boot fucntions to boot.c Song Gao
2024-03-07 16:48 ` [PATCH v6 02/17] hw/loongarch: Add load initrd Song Gao
@ 2024-03-07 16:48 ` Song Gao
2024-03-08 8:27 ` maobibo
2024-03-14 2:28 ` chen huacai
2024-03-07 16:48 ` [PATCH v6 04/17] hw/loongarch: Add init_cmdline Song Gao
` (13 subsequent siblings)
16 siblings, 2 replies; 46+ messages in thread
From: Song Gao @ 2024-03-07 16:48 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, maobibo
Signed-off-by: Song Gao <gaosong@loongson.cn>
Message-Id: <20240301093839.663947-4-gaosong@loongson.cn>
---
hw/loongarch/boot.c | 70 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 69 insertions(+), 1 deletion(-)
diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
index 149deb2e01..e560ac178a 100644
--- a/hw/loongarch/boot.c
+++ b/hw/loongarch/boot.c
@@ -15,6 +15,54 @@
#include "sysemu/reset.h"
#include "sysemu/qtest.h"
+static const unsigned int slave_boot_code[] = {
+ /* Configure reset ebase. */
+ 0x0400302c, /* csrwr $r12,0xc */
+
+ /* Disable interrupt. */
+ 0x0380100c, /* ori $r12,$r0,0x4 */
+ 0x04000180, /* csrxchg $r0,$r12,0x0 */
+
+ /* Clear mailbox. */
+ 0x1400002d, /* lu12i.w $r13,1(0x1) */
+ 0x038081ad, /* ori $r13,$r13,0x20 */
+ 0x06481da0, /* iocsrwr.d $r0,$r13 */
+
+ /* Enable IPI interrupt. */
+ 0x1400002c, /* lu12i.w $r12,1(0x1) */
+ 0x0400118c, /* csrxchg $r12,$r12,0x4 */
+ 0x02fffc0c, /* addi.d $r12,$r0,-1(0xfff) */
+ 0x1400002d, /* lu12i.w $r13,1(0x1) */
+ 0x038011ad, /* ori $r13,$r13,0x4 */
+ 0x064819ac, /* iocsrwr.w $r12,$r13 */
+ 0x1400002d, /* lu12i.w $r13,1(0x1) */
+ 0x038081ad, /* ori $r13,$r13,0x20 */
+
+ /* Wait for wakeup <.L11>: */
+ 0x06488000, /* idle 0x0 */
+ 0x03400000, /* andi $r0,$r0,0x0 */
+ 0x064809ac, /* iocsrrd.w $r12,$r13 */
+ 0x43fff59f, /* beqz $r12,-12(0x7ffff4) # 48 <.L11> */
+
+ /* Read and clear IPI interrupt. */
+ 0x1400002d, /* lu12i.w $r13,1(0x1) */
+ 0x064809ac, /* iocsrrd.w $r12,$r13 */
+ 0x1400002d, /* lu12i.w $r13,1(0x1) */
+ 0x038031ad, /* ori $r13,$r13,0xc */
+ 0x064819ac, /* iocsrwr.w $r12,$r13 */
+
+ /* Disable IPI interrupt. */
+ 0x1400002c, /* lu12i.w $r12,1(0x1) */
+ 0x04001180, /* csrxchg $r0,$r12,0x4 */
+
+ /* Read mail buf and jump to specified entry */
+ 0x1400002d, /* lu12i.w $r13,1(0x1) */
+ 0x038081ad, /* ori $r13,$r13,0x20 */
+ 0x06480dac, /* iocsrrd.d $r12,$r13 */
+ 0x00150181, /* move $r1,$r12 */
+ 0x4c000020, /* jirl $r0,$r1,0 */
+};
+
static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
{
return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
@@ -111,8 +159,15 @@ static void loongarch_firmware_boot(LoongArchMachineState *lams,
fw_cfg_add_kernel_info(info, lams->fw_cfg);
}
+static void init_boot_rom(struct loongarch_boot_info *info, void *p)
+{
+ memcpy(p, &slave_boot_code, sizeof(slave_boot_code));
+ p += sizeof(slave_boot_code);
+}
+
static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info)
{
+ void *p, *bp;
int64_t kernel_addr = 0;
LoongArchCPU *lacpu;
CPUState *cs;
@@ -126,11 +181,24 @@ static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info)
}
}
+ /* Load 'boot_rom' at [0 - 1MiB] */
+ p = g_malloc0(1 * MiB);
+ bp = p;
+ init_boot_rom(info, p);
+ rom_add_blob_fixed("boot_rom", bp, 1 * MiB, 0);
+
CPU_FOREACH(cs) {
lacpu = LOONGARCH_CPU(cs);
lacpu->env.load_elf = true;
- lacpu->env.elf_address = kernel_addr;
+ if (cs == first_cpu) {
+ lacpu->env.elf_address = kernel_addr;
+ } else {
+ lacpu->env.elf_address = 0;
+ }
+ lacpu->env.boot_info = info;
}
+
+ g_free(bp);
}
void loongarch_load_kernel(MachineState *ms, struct loongarch_boot_info *info)
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v6 04/17] hw/loongarch: Add init_cmdline
2024-03-07 16:48 [PATCH v6 00/17] Add boot LoongArch elf kernel with FDT Song Gao
` (2 preceding siblings ...)
2024-03-07 16:48 ` [PATCH v6 03/17] hw/loongarch: Add slave cpu boot_code Song Gao
@ 2024-03-07 16:48 ` Song Gao
2024-03-08 8:28 ` maobibo
2024-03-07 16:48 ` [PATCH v6 05/17] hw/loongarch: Init efi_system_table Song Gao
` (12 subsequent siblings)
16 siblings, 1 reply; 46+ messages in thread
From: Song Gao @ 2024-03-07 16:48 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, maobibo
Add init_cmline and set boot_info->a0, a1
Signed-off-by: Song Gao <gaosong@loongson.cn>
Message-Id: <20240301093839.663947-5-gaosong@loongson.cn>
---
hw/loongarch/boot.c | 19 +++++++++++++++++++
include/hw/loongarch/virt.h | 2 ++
target/loongarch/cpu.h | 2 ++
3 files changed, 23 insertions(+)
diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
index e560ac178a..ca65dfde07 100644
--- a/hw/loongarch/boot.c
+++ b/hw/loongarch/boot.c
@@ -63,6 +63,16 @@ static const unsigned int slave_boot_code[] = {
0x4c000020, /* jirl $r0,$r1,0 */
};
+static void init_cmdline(struct loongarch_boot_info *info, void *p, void *start)
+{
+ hwaddr cmdline_addr = (hwaddr)p - (hwaddr)start;
+
+ info->a0 = 1;
+ info->a1 = cmdline_addr;
+
+ memcpy(p, info->kernel_cmdline, COMMAND_LINE_SIZE);
+}
+
static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
{
return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
@@ -122,6 +132,10 @@ static void reset_load_elf(void *opaque)
cpu_reset(CPU(cpu));
if (env->load_elf) {
+ if (cpu == LOONGARCH_CPU(first_cpu)) {
+ env->gpr[4] = env->boot_info->a0;
+ env->gpr[5] = env->boot_info->a1;
+ }
cpu_set_pc(CPU(cpu), env->elf_address);
}
}
@@ -161,8 +175,13 @@ static void loongarch_firmware_boot(LoongArchMachineState *lams,
static void init_boot_rom(struct loongarch_boot_info *info, void *p)
{
+ void *start = p;
+
memcpy(p, &slave_boot_code, sizeof(slave_boot_code));
p += sizeof(slave_boot_code);
+
+ init_cmdline(info, p, start);
+ p += COMMAND_LINE_SIZE;
}
static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info)
diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h
index cf2f2bfb19..d7a074d69f 100644
--- a/include/hw/loongarch/virt.h
+++ b/include/hw/loongarch/virt.h
@@ -33,6 +33,8 @@
#define VIRT_GED_MEM_ADDR (VIRT_GED_EVT_ADDR + ACPI_GED_EVT_SEL_LEN)
#define VIRT_GED_REG_ADDR (VIRT_GED_MEM_ADDR + MEMORY_HOTPLUG_IO_LEN)
+#define COMMAND_LINE_SIZE 512
+
struct LoongArchMachineState {
/*< private >*/
MachineState parent_obj;
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
index ec37579fd6..ce02ef3979 100644
--- a/target/loongarch/cpu.h
+++ b/target/loongarch/cpu.h
@@ -361,6 +361,8 @@ typedef struct CPUArchState {
uint32_t mp_state;
/* Store ipistate to access from this struct */
DeviceState *ipistate;
+
+ struct loongarch_boot_info *boot_info;
#endif
} CPULoongArchState;
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v6 05/17] hw/loongarch: Init efi_system_table
2024-03-07 16:48 [PATCH v6 00/17] Add boot LoongArch elf kernel with FDT Song Gao
` (3 preceding siblings ...)
2024-03-07 16:48 ` [PATCH v6 04/17] hw/loongarch: Add init_cmdline Song Gao
@ 2024-03-07 16:48 ` Song Gao
2024-03-08 8:29 ` maobibo
2024-03-08 8:33 ` Philippe Mathieu-Daudé
2024-03-07 16:48 ` [PATCH v6 06/17] hw/loongarch: Init efi_boot_memmap table Song Gao
` (11 subsequent siblings)
16 siblings, 2 replies; 46+ messages in thread
From: Song Gao @ 2024-03-07 16:48 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, maobibo
Add init_systab and set boot_info->a2
Signed-off-by: Song Gao <gaosong@loongson.cn>
Message-Id: <20240301093839.663947-6-gaosong@loongson.cn>
---
hw/loongarch/boot.c | 22 +++++++++++++++++
include/hw/loongarch/boot.h | 48 +++++++++++++++++++++++++++++++++++++
2 files changed, 70 insertions(+)
diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
index ca65dfde07..1e31e2a59f 100644
--- a/hw/loongarch/boot.c
+++ b/hw/loongarch/boot.c
@@ -63,6 +63,25 @@ static const unsigned int slave_boot_code[] = {
0x4c000020, /* jirl $r0,$r1,0 */
};
+static void init_systab(struct loongarch_boot_info *info, void *p, void *start)
+{
+ struct efi_system_table *systab = p;
+
+ info->a2 = (uint64_t)p - (uint64_t)start;
+
+ systab->hdr.signature = EFI_SYSTEM_TABLE_SIGNATURE;
+ systab->hdr.revision = EFI_SPECIFICATION_VERSION;
+ systab->hdr.revision = sizeof(struct efi_system_table),
+ systab->fw_revision = FW_VERSION << 16 | FW_PATCHLEVEL << 8;
+ systab->runtime = 0;
+ systab->boottime = 0;
+ systab->nr_tables = 0;
+
+ p += ROUND_UP(sizeof(struct efi_system_table), 64);
+
+ systab->tables = p;
+}
+
static void init_cmdline(struct loongarch_boot_info *info, void *p, void *start)
{
hwaddr cmdline_addr = (hwaddr)p - (hwaddr)start;
@@ -135,6 +154,7 @@ static void reset_load_elf(void *opaque)
if (cpu == LOONGARCH_CPU(first_cpu)) {
env->gpr[4] = env->boot_info->a0;
env->gpr[5] = env->boot_info->a1;
+ env->gpr[6] = env->boot_info->a2;
}
cpu_set_pc(CPU(cpu), env->elf_address);
}
@@ -182,6 +202,8 @@ static void init_boot_rom(struct loongarch_boot_info *info, void *p)
init_cmdline(info, p, start);
p += COMMAND_LINE_SIZE;
+
+ init_systab(info, p, start);
}
static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info)
diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h
index 3275c1e295..65ad406f02 100644
--- a/include/hw/loongarch/boot.h
+++ b/include/hw/loongarch/boot.h
@@ -8,6 +8,54 @@
#ifndef HW_LOONGARCH_BOOT_H
#define HW_LOONGARCH_BOOT_H
+/* UEFI 2.10 */
+#define EFI_SYSTEM_TABLE_SIGNATURE 0x5453595320494249
+#define EFI_2_100_SYSTEM_TABLE_REVISION ((2<<16) | (100))
+#define EFI_SPECIFICATION_VERSION EFI_SYSTEM_TABLE_REVISION
+#define EFI_SYSTEM_TABLE_REVISION EFI_2_100_SYSTEM_TABLE_REVISION
+
+#define FW_VERSION 0x1
+#define FW_PATCHLEVEL 0x0
+
+typedef struct {
+ uint8_t b[16];
+} efi_guid_t __attribute__((aligned(8)));
+
+struct efi_config_table {
+ efi_guid_t guid;
+ uint64_t *ptr;
+ const char name[16];
+};
+
+typedef struct {
+ uint64_t signature;
+ uint32_t revision;
+ uint32_t headersize;
+ uint32_t crc32;
+ uint32_t reserved;
+} efi_table_hdr_t;
+
+struct efi_configuration_table {
+ efi_guid_t guid;
+ void *table;
+};
+
+struct efi_system_table {
+ efi_table_hdr_t hdr;
+ uint64_t fw_vendor; /* physical addr of CHAR16 vendor string */
+ uint32_t fw_revision;
+ uint64_t con_in_handle;
+ uint64_t *con_in;
+ uint64_t con_out_handle;
+ uint64_t *con_out;
+ uint64_t stderr_handle;
+ uint64_t stderr_placeholder;
+ uint64_t *runtime;
+ uint64_t *boottime;
+ uint64_t nr_tables;
+ struct efi_configuration_table *tables;
+};
+
struct loongarch_boot_info {
uint64_t ram_size;
const char *kernel_filename;
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v6 06/17] hw/loongarch: Init efi_boot_memmap table
2024-03-07 16:48 [PATCH v6 00/17] Add boot LoongArch elf kernel with FDT Song Gao
` (4 preceding siblings ...)
2024-03-07 16:48 ` [PATCH v6 05/17] hw/loongarch: Init efi_system_table Song Gao
@ 2024-03-07 16:48 ` Song Gao
2024-03-08 8:37 ` maobibo
2024-03-07 16:48 ` [PATCH v6 07/17] hw/loongarch: Init efi_initrd table Song Gao
` (10 subsequent siblings)
16 siblings, 1 reply; 46+ messages in thread
From: Song Gao @ 2024-03-07 16:48 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, maobibo
Signed-off-by: Song Gao <gaosong@loongson.cn>
Message-Id: <20240301093839.663947-7-gaosong@loongson.cn>
---
hw/loongarch/boot.c | 39 +++++++++++++++++++++++++++++++++++++
hw/loongarch/virt.c | 11 ++---------
include/hw/loongarch/boot.h | 27 +++++++++++++++++++++++++
include/hw/loongarch/virt.h | 10 ++++++++++
4 files changed, 78 insertions(+), 9 deletions(-)
diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
index 1e31e2a59f..2896c1ea40 100644
--- a/hw/loongarch/boot.c
+++ b/hw/loongarch/boot.c
@@ -63,8 +63,40 @@ static const unsigned int slave_boot_code[] = {
0x4c000020, /* jirl $r0,$r1,0 */
};
+static inline void *guidcpy(void *dst, const void *src)
+{
+ return memcpy(dst, src, sizeof(efi_guid_t));
+}
+
+static void init_efi_boot_memmap(struct efi_system_table *systab,
+ void *p, void *start)
+{
+ unsigned i;
+ struct efi_boot_memmap *boot_memmap = p;
+ efi_guid_t tbl_guid = LINUX_EFI_BOOT_MEMMAP_GUID;
+
+ /* efi_configuration_table 1 */
+ guidcpy(&systab->tables[0].guid, &tbl_guid);
+ systab->tables[0].table = (struct efi_configuration_table *)(p - start);
+ systab->nr_tables = 1;
+
+ boot_memmap->desc_size = sizeof(efi_memory_desc_t);
+ boot_memmap->desc_ver = 1;
+ boot_memmap->map_size = 0;
+
+ efi_memory_desc_t *map = p + sizeof(struct efi_boot_memmap);
+ for (i = 0; i < memmap_entries; i++) {
+ map = (void *)boot_memmap + sizeof(*map);
+ map[i].type = memmap_table[i].type;
+ map[i].phys_addr = memmap_table[i].address;
+ map[i].num_pages = memmap_table[i].length >> 16; /* 64KB align*/
+ p += sizeof(efi_memory_desc_t);
+ }
+}
+
static void init_systab(struct loongarch_boot_info *info, void *p, void *start)
{
+ void *bp_tables_start;
struct efi_system_table *systab = p;
info->a2 = (uint64_t)p - (uint64_t)start;
@@ -80,6 +112,13 @@ static void init_systab(struct loongarch_boot_info *info, void *p, void *start)
p += ROUND_UP(sizeof(struct efi_system_table), 64);
systab->tables = p;
+ bp_tables_start = p;
+
+ init_efi_boot_memmap(systab, p, start);
+ p += ROUND_UP(sizeof(struct efi_boot_memmap) +
+ sizeof(efi_memory_desc_t) * memmap_entries, 64);
+
+ systab->tables = (struct efi_configuration_table *)(bp_tables_start - start);
}
static void init_cmdline(struct loongarch_boot_info *info, void *p, void *start)
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index bbd5cc1d4d..8981b57b12 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -377,15 +377,8 @@ static void virt_powerdown_req(Notifier *notifier, void *opaque)
acpi_send_event(s->acpi_ged, ACPI_POWER_DOWN_STATUS);
}
-struct memmap_entry {
- uint64_t address;
- uint64_t length;
- uint32_t type;
- uint32_t reserved;
-};
-
-static struct memmap_entry *memmap_table;
-static unsigned memmap_entries;
+struct memmap_entry *memmap_table;
+unsigned memmap_entries;
static void memmap_add_entry(uint64_t address, uint64_t length, uint32_t type)
{
diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h
index 65ad406f02..f71c693f43 100644
--- a/include/hw/loongarch/boot.h
+++ b/include/hw/loongarch/boot.h
@@ -21,6 +21,15 @@ typedef struct {
uint8_t b[16];
} efi_guid_t __attribute__((aligned(8)));
+#define EFI_GUID(a, b, c, d...) (efi_guid_t){ { \
+ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
+ (b) & 0xff, ((b) >> 8) & 0xff, \
+ (c) & 0xff, ((c) >> 8) & 0xff, d } }
+
+#define LINUX_EFI_BOOT_MEMMAP_GUID \
+ EFI_GUID(0x800f683f, 0xd08b, 0x423a, 0xa2, 0x93, \
+ 0x96, 0x5c, 0x3c, 0x6f, 0xe2, 0xb4)
+
struct efi_config_table {
efi_guid_t guid;
uint64_t *ptr;
@@ -56,6 +65,24 @@ struct efi_system_table {
struct efi_configuration_table *tables;
};
+typedef struct {
+ uint32_t type;
+ uint32_t pad;
+ uint64_t phys_addr;
+ uint64_t virt_addr;
+ uint64_t num_pages;
+ uint64_t attribute;
+} efi_memory_desc_t;
+
+struct efi_boot_memmap {
+ uint64_t map_size;
+ uint64_t desc_size;
+ uint32_t desc_ver;
+ uint64_t map_key;
+ uint64_t buff_size;
+ efi_memory_desc_t map[32];
+};
+
struct loongarch_boot_info {
uint64_t ram_size;
const char *kernel_filename;
diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h
index d7a074d69f..8a9fe4053d 100644
--- a/include/hw/loongarch/virt.h
+++ b/include/hw/loongarch/virt.h
@@ -35,6 +35,16 @@
#define COMMAND_LINE_SIZE 512
+extern struct memmap_entry *memmap_table;
+extern unsigned memmap_entries;
+
+struct memmap_entry {
+ uint64_t address;
+ uint64_t length;
+ uint32_t type;
+ uint32_t reserved;
+};
+
struct LoongArchMachineState {
/*< private >*/
MachineState parent_obj;
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v6 07/17] hw/loongarch: Init efi_initrd table
2024-03-07 16:48 [PATCH v6 00/17] Add boot LoongArch elf kernel with FDT Song Gao
` (5 preceding siblings ...)
2024-03-07 16:48 ` [PATCH v6 06/17] hw/loongarch: Init efi_boot_memmap table Song Gao
@ 2024-03-07 16:48 ` Song Gao
2024-03-08 8:36 ` Philippe Mathieu-Daudé
2024-03-08 8:37 ` maobibo
2024-03-07 16:48 ` [PATCH v6 08/17] hw/loongarch: Init efi_fdt table Song Gao
` (9 subsequent siblings)
16 siblings, 2 replies; 46+ messages in thread
From: Song Gao @ 2024-03-07 16:48 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, maobibo
Signed-off-by: Song Gao <gaosong@loongson.cn>
Message-Id: <20240301093839.663947-8-gaosong@loongson.cn>
---
hw/loongarch/boot.c | 23 +++++++++++++++++++++--
include/hw/loongarch/boot.h | 9 +++++++++
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
index 2896c1ea40..6126a37858 100644
--- a/hw/loongarch/boot.c
+++ b/hw/loongarch/boot.c
@@ -15,6 +15,9 @@
#include "sysemu/reset.h"
#include "sysemu/qtest.h"
+ram_addr_t initrd_offset;
+uint64_t initrd_size;
+
static const unsigned int slave_boot_code[] = {
/* Configure reset ebase. */
0x0400302c, /* csrwr $r12,0xc */
@@ -94,6 +97,21 @@ static void init_efi_boot_memmap(struct efi_system_table *systab,
}
}
+static void init_efi_initrd_table(struct efi_system_table *systab,
+ void *p, void *start)
+{
+ efi_guid_t tbl_guid = LINUX_EFI_INITRD_MEDIA_GUID;
+ struct efi_initrd *initrd_table = p;
+
+ /* efi_configuration_table 2 */
+ guidcpy(&systab->tables[1].guid, &tbl_guid);
+ systab->tables[1].table = (struct efi_configuration_table *)(p - start);
+ systab->nr_tables = 2;
+
+ initrd_table->base = initrd_offset;
+ initrd_table->size = initrd_size;
+}
+
static void init_systab(struct loongarch_boot_info *info, void *p, void *start)
{
void *bp_tables_start;
@@ -117,6 +135,8 @@ static void init_systab(struct loongarch_boot_info *info, void *p, void *start)
init_efi_boot_memmap(systab, p, start);
p += ROUND_UP(sizeof(struct efi_boot_memmap) +
sizeof(efi_memory_desc_t) * memmap_entries, 64);
+ init_efi_initrd_table(systab, p, start);
+ p += ROUND_UP(sizeof(struct efi_initrd), 64);
systab->tables = (struct efi_configuration_table *)(bp_tables_start - start);
}
@@ -138,8 +158,7 @@ static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
static int64_t load_kernel_info(struct loongarch_boot_info *info)
{
- uint64_t kernel_entry, kernel_low, kernel_high, initrd_size;
- ram_addr_t initrd_offset;
+ uint64_t kernel_entry, kernel_low, kernel_high;
ssize_t kernel_size;
kernel_size = load_elf(info->kernel_filename, NULL,
diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h
index f71c693f43..ddcb279874 100644
--- a/include/hw/loongarch/boot.h
+++ b/include/hw/loongarch/boot.h
@@ -30,6 +30,10 @@ typedef struct {
EFI_GUID(0x800f683f, 0xd08b, 0x423a, 0xa2, 0x93, \
0x96, 0x5c, 0x3c, 0x6f, 0xe2, 0xb4)
+#define LINUX_EFI_INITRD_MEDIA_GUID \
+ EFI_GUID(0x5568e427, 0x68fc, 0x4f3d, 0xac, 0x74, \
+ 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68)
+
struct efi_config_table {
efi_guid_t guid;
uint64_t *ptr;
@@ -83,6 +87,11 @@ struct efi_boot_memmap {
efi_memory_desc_t map[32];
};
+struct efi_initrd {
+ uint64_t base;
+ uint64_t size;
+};
+
struct loongarch_boot_info {
uint64_t ram_size;
const char *kernel_filename;
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v6 08/17] hw/loongarch: Init efi_fdt table
2024-03-07 16:48 [PATCH v6 00/17] Add boot LoongArch elf kernel with FDT Song Gao
` (6 preceding siblings ...)
2024-03-07 16:48 ` [PATCH v6 07/17] hw/loongarch: Init efi_initrd table Song Gao
@ 2024-03-07 16:48 ` Song Gao
2024-03-08 8:39 ` maobibo
2024-03-07 16:48 ` [PATCH v6 09/17] hw/loongarch: Fix fdt memory node wrong 'reg' Song Gao
` (8 subsequent siblings)
16 siblings, 1 reply; 46+ messages in thread
From: Song Gao @ 2024-03-07 16:48 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, maobibo
Signed-off-by: Song Gao <gaosong@loongson.cn>
Message-Id: <20240301093839.663947-9-gaosong@loongson.cn>
---
hw/loongarch/boot.c | 11 +++++++++++
include/hw/loongarch/boot.h | 4 ++++
2 files changed, 15 insertions(+)
diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
index 6126a37858..c6c6e6d194 100644
--- a/hw/loongarch/boot.c
+++ b/hw/loongarch/boot.c
@@ -112,6 +112,16 @@ static void init_efi_initrd_table(struct efi_system_table *systab,
initrd_table->size = initrd_size;
}
+static void init_efi_fdt_table(struct efi_system_table *systab)
+{
+ efi_guid_t tbl_guid = DEVICE_TREE_GUID;
+
+ /* efi_configuration_table 3 */
+ guidcpy(&systab->tables[2].guid, &tbl_guid);
+ systab->tables[2].table = (void *)0x100000; /* fdt_base 1MiB */
+ systab->nr_tables = 3;
+}
+
static void init_systab(struct loongarch_boot_info *info, void *p, void *start)
{
void *bp_tables_start;
@@ -137,6 +147,7 @@ static void init_systab(struct loongarch_boot_info *info, void *p, void *start)
sizeof(efi_memory_desc_t) * memmap_entries, 64);
init_efi_initrd_table(systab, p, start);
p += ROUND_UP(sizeof(struct efi_initrd), 64);
+ init_efi_fdt_table(systab);
systab->tables = (struct efi_configuration_table *)(bp_tables_start - start);
}
diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h
index ddcb279874..9de673a0fd 100644
--- a/include/hw/loongarch/boot.h
+++ b/include/hw/loongarch/boot.h
@@ -34,6 +34,10 @@ typedef struct {
EFI_GUID(0x5568e427, 0x68fc, 0x4f3d, 0xac, 0x74, \
0xca, 0x55, 0x52, 0x31, 0xcc, 0x68)
+#define DEVICE_TREE_GUID \
+ EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, 0x83, 0x0b, \
+ 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0)
+
struct efi_config_table {
efi_guid_t guid;
uint64_t *ptr;
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v6 09/17] hw/loongarch: Fix fdt memory node wrong 'reg'
2024-03-07 16:48 [PATCH v6 00/17] Add boot LoongArch elf kernel with FDT Song Gao
` (7 preceding siblings ...)
2024-03-07 16:48 ` [PATCH v6 08/17] hw/loongarch: Init efi_fdt table Song Gao
@ 2024-03-07 16:48 ` Song Gao
2024-03-08 8:39 ` maobibo
2024-03-07 16:48 ` [PATCH v6 10/17] hw/loongarch: fdt adds cpu interrupt controller node Song Gao
` (7 subsequent siblings)
16 siblings, 1 reply; 46+ messages in thread
From: Song Gao @ 2024-03-07 16:48 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, maobibo
The right fdt memory node like [1], not [2]
[1]
memory@0 {
device_type = "memory";
reg = <0x00 0x00 0x00 0x10000000>;
};
[2]
memory@0 {
device_type = "memory";
reg = <0x02 0x00 0x02 0x10000000>;
};
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Song Gao <gaosong@loongson.cn>
Message-Id: <20240301093839.663947-10-gaosong@loongson.cn>
---
hw/loongarch/virt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index 8981b57b12..10fdfec5dd 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -325,7 +325,7 @@ static void fdt_add_memory_node(MachineState *ms,
char *nodename = g_strdup_printf("/memory@%" PRIx64, base);
qemu_fdt_add_subnode(ms->fdt, nodename);
- qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 2, base, 2, size);
+ qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 0, base, 0, size);
qemu_fdt_setprop_string(ms->fdt, nodename, "device_type", "memory");
if (ms->numa_state && ms->numa_state->num_nodes) {
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v6 10/17] hw/loongarch: fdt adds cpu interrupt controller node
2024-03-07 16:48 [PATCH v6 00/17] Add boot LoongArch elf kernel with FDT Song Gao
` (8 preceding siblings ...)
2024-03-07 16:48 ` [PATCH v6 09/17] hw/loongarch: Fix fdt memory node wrong 'reg' Song Gao
@ 2024-03-07 16:48 ` Song Gao
2024-03-08 8:40 ` maobibo
2024-03-07 16:48 ` [PATCH v6 11/17] hw/loongarch: fdt adds Extend I/O Interrupt Controller Song Gao
` (6 subsequent siblings)
16 siblings, 1 reply; 46+ messages in thread
From: Song Gao @ 2024-03-07 16:48 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, maobibo
fdt adds cpu interrupt controller node,
we use 'loongson,cpu-interrupt-controller'.
See:
https://github.com/torvalds/linux/blob/v6.7/drivers/irqchip/irq-loongarch-cpu.c
https://lore.kernel.org/r/20221114113824.1880-2-liupeibao@loongson.cn
Signed-off-by: Song Gao <gaosong@loongson.cn>
Message-Id: <20240301093839.663947-11-gaosong@loongson.cn>
---
hw/loongarch/virt.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index 10fdfec5dd..d260f933a5 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -106,6 +106,23 @@ static void virt_flash_map(LoongArchMachineState *lams,
virt_flash_map1(flash1, VIRT_FLASH1_BASE, VIRT_FLASH1_SIZE, sysmem);
}
+static void fdt_add_cpuic_node(LoongArchMachineState *lams,
+ uint32_t *cpuintc_phandle)
+{
+ MachineState *ms = MACHINE(lams);
+ char *nodename;
+
+ *cpuintc_phandle = qemu_fdt_alloc_phandle(ms->fdt);
+ nodename = g_strdup_printf("/cpuic");
+ qemu_fdt_add_subnode(ms->fdt, nodename);
+ qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle", *cpuintc_phandle);
+ qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
+ "loongson,cpu-interrupt-controller");
+ qemu_fdt_setprop(ms->fdt, nodename, "interrupt-controller", NULL, 0);
+ qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 1);
+ g_free(nodename);
+}
+
static void fdt_add_flash_node(LoongArchMachineState *lams)
{
MachineState *ms = MACHINE(lams);
@@ -527,6 +544,7 @@ static void loongarch_irq_init(LoongArchMachineState *lams)
CPULoongArchState *env;
CPUState *cpu_state;
int cpu, pin, i, start, num;
+ uint32_t cpuintc_phandle;
/*
* The connection of interrupts:
@@ -561,6 +579,9 @@ static void loongarch_irq_init(LoongArchMachineState *lams)
memory_region_add_subregion(&lams->system_iocsr, MAIL_SEND_ADDR,
sysbus_mmio_get_region(SYS_BUS_DEVICE(ipi), 1));
+ /* Add cpu interrupt-controller */
+ fdt_add_cpuic_node(lams, &cpuintc_phandle);
+
for (cpu = 0; cpu < ms->smp.cpus; cpu++) {
cpu_state = qemu_get_cpu(cpu);
cpudev = DEVICE(cpu_state);
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v6 11/17] hw/loongarch: fdt adds Extend I/O Interrupt Controller
2024-03-07 16:48 [PATCH v6 00/17] Add boot LoongArch elf kernel with FDT Song Gao
` (9 preceding siblings ...)
2024-03-07 16:48 ` [PATCH v6 10/17] hw/loongarch: fdt adds cpu interrupt controller node Song Gao
@ 2024-03-07 16:48 ` Song Gao
2024-03-08 8:40 ` maobibo
2024-03-07 16:48 ` [PATCH v6 12/17] hw/loongarch: fdt adds pch_pic Controller Song Gao
` (5 subsequent siblings)
16 siblings, 1 reply; 46+ messages in thread
From: Song Gao @ 2024-03-07 16:48 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, maobibo
fdt adds Extend I/O Interrupt Controller,
we use 'loongson,ls2k2000-eiointc'.
See:
https://github.com/torvalds/linux/blob/v6.7/drivers/irqchip/irq-loongson-eiointc.c
https://lore.kernel.org/r/764e02d924094580ac0f1d15535f4b98308705c6.1683279769.git.zhoubinbin@loongson.cn
Signed-off-by: Song Gao <gaosong@loongson.cn>
Message-Id: <20240301093839.663947-12-gaosong@loongson.cn>
---
hw/loongarch/virt.c | 30 +++++++++++++++++++++++++++++-
include/hw/intc/loongarch_extioi.h | 1 +
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index d260f933a5..822f070c45 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -123,6 +123,31 @@ static void fdt_add_cpuic_node(LoongArchMachineState *lams,
g_free(nodename);
}
+static void fdt_add_eiointc_node(LoongArchMachineState *lams,
+ uint32_t *cpuintc_phandle,
+ uint32_t *eiointc_phandle)
+{
+ MachineState *ms = MACHINE(lams);
+ char *nodename;
+ hwaddr extioi_base = APIC_BASE;
+ hwaddr extioi_size = EXTIOI_SIZE;
+
+ *eiointc_phandle = qemu_fdt_alloc_phandle(ms->fdt);
+ nodename = g_strdup_printf("/eiointc@%" PRIx64, extioi_base);
+ qemu_fdt_add_subnode(ms->fdt, nodename);
+ qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle", *eiointc_phandle);
+ qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
+ "loongson,ls2k2000-eiointc");
+ qemu_fdt_setprop(ms->fdt, nodename, "interrupt-controller", NULL, 0);
+ qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 1);
+ qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
+ *cpuintc_phandle);
+ qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupts", 3);
+ qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 0x0,
+ extioi_base, 0x0, extioi_size);
+ g_free(nodename);
+}
+
static void fdt_add_flash_node(LoongArchMachineState *lams)
{
MachineState *ms = MACHINE(lams);
@@ -544,7 +569,7 @@ static void loongarch_irq_init(LoongArchMachineState *lams)
CPULoongArchState *env;
CPUState *cpu_state;
int cpu, pin, i, start, num;
- uint32_t cpuintc_phandle;
+ uint32_t cpuintc_phandle, eiointc_phandle;
/*
* The connection of interrupts:
@@ -613,6 +638,9 @@ static void loongarch_irq_init(LoongArchMachineState *lams)
}
}
+ /* Add Extend I/O Interrupt Controller node */
+ fdt_add_eiointc_node(lams, &cpuintc_phandle, &eiointc_phandle);
+
pch_pic = qdev_new(TYPE_LOONGARCH_PCH_PIC);
num = VIRT_PCH_PIC_IRQ_NUM;
qdev_prop_set_uint32(pch_pic, "pch_pic_irq_num", num);
diff --git a/include/hw/intc/loongarch_extioi.h b/include/hw/intc/loongarch_extioi.h
index a0a46b888c..410c6e1121 100644
--- a/include/hw/intc/loongarch_extioi.h
+++ b/include/hw/intc/loongarch_extioi.h
@@ -39,6 +39,7 @@
#define EXTIOI_COREISR_END (0xB20 - APIC_OFFSET)
#define EXTIOI_COREMAP_START (0xC00 - APIC_OFFSET)
#define EXTIOI_COREMAP_END (0xD00 - APIC_OFFSET)
+#define EXTIOI_SIZE 0x800
typedef struct ExtIOICore {
uint32_t coreisr[EXTIOI_IRQS_GROUP_COUNT];
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v6 12/17] hw/loongarch: fdt adds pch_pic Controller
2024-03-07 16:48 [PATCH v6 00/17] Add boot LoongArch elf kernel with FDT Song Gao
` (10 preceding siblings ...)
2024-03-07 16:48 ` [PATCH v6 11/17] hw/loongarch: fdt adds Extend I/O Interrupt Controller Song Gao
@ 2024-03-07 16:48 ` Song Gao
2024-03-08 8:41 ` maobibo
2024-03-07 16:48 ` [PATCH v6 13/17] hw/loongarch: fdt adds pch_msi Controller Song Gao
` (4 subsequent siblings)
16 siblings, 1 reply; 46+ messages in thread
From: Song Gao @ 2024-03-07 16:48 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, maobibo
fdt adds pch pic controller, we use 'loongson,pch-pic-1.0'
See:
https://github.com/torvalds/linux/blob/v6.7/drivers/irqchip/irq-loongson-pch-pic.c
https://lore.kernel.org/r/20200528152757.1028711-4-jiaxun.yang@flygoat.com
Signed-off-by: Song Gao <gaosong@loongson.cn>
Message-Id: <20240301093839.663947-13-gaosong@loongson.cn>
---
hw/loongarch/virt.c | 30 +++++++++++++++++++++++++++++-
include/hw/pci-host/ls7a.h | 1 +
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index 822f070c45..2b7b653fc1 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -148,6 +148,31 @@ static void fdt_add_eiointc_node(LoongArchMachineState *lams,
g_free(nodename);
}
+static void fdt_add_pch_pic_node(LoongArchMachineState *lams,
+ uint32_t *eiointc_phandle,
+ uint32_t *pch_pic_phandle)
+{
+ MachineState *ms = MACHINE(lams);
+ char *nodename;
+ hwaddr pch_pic_base = VIRT_PCH_REG_BASE;
+ hwaddr pch_pic_size = VIRT_PCH_REG_SIZE;
+
+ *pch_pic_phandle = qemu_fdt_alloc_phandle(ms->fdt);
+ nodename = g_strdup_printf("/platic@%" PRIx64, pch_pic_base);
+ qemu_fdt_add_subnode(ms->fdt, nodename);
+ qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle", *pch_pic_phandle);
+ qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
+ "loongson,pch-pic-1.0");
+ qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 0,
+ pch_pic_base, 0, pch_pic_size);
+ qemu_fdt_setprop(ms->fdt, nodename, "interrupt-controller", NULL, 0);
+ qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 2);
+ qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
+ *eiointc_phandle);
+ qemu_fdt_setprop_cell(ms->fdt, nodename, "loongson,pic-base-vec", 0);
+ g_free(nodename);
+}
+
static void fdt_add_flash_node(LoongArchMachineState *lams)
{
MachineState *ms = MACHINE(lams);
@@ -569,7 +594,7 @@ static void loongarch_irq_init(LoongArchMachineState *lams)
CPULoongArchState *env;
CPUState *cpu_state;
int cpu, pin, i, start, num;
- uint32_t cpuintc_phandle, eiointc_phandle;
+ uint32_t cpuintc_phandle, eiointc_phandle, pch_pic_phandle;
/*
* The connection of interrupts:
@@ -660,6 +685,9 @@ static void loongarch_irq_init(LoongArchMachineState *lams)
qdev_connect_gpio_out(DEVICE(d), i, qdev_get_gpio_in(extioi, i));
}
+ /* Add PCH PIC node */
+ fdt_add_pch_pic_node(lams, &eiointc_phandle, &pch_pic_phandle);
+
pch_msi = qdev_new(TYPE_LOONGARCH_PCH_MSI);
start = num;
num = EXTIOI_IRQS - start;
diff --git a/include/hw/pci-host/ls7a.h b/include/hw/pci-host/ls7a.h
index e753449593..fe260f0183 100644
--- a/include/hw/pci-host/ls7a.h
+++ b/include/hw/pci-host/ls7a.h
@@ -24,6 +24,7 @@
#define VIRT_PCH_REG_BASE 0x10000000UL
#define VIRT_IOAPIC_REG_BASE (VIRT_PCH_REG_BASE)
#define VIRT_PCH_MSI_ADDR_LOW 0x2FF00000UL
+#define VIRT_PCH_REG_SIZE 0x400
/*
* GSI_BASE is hard-coded with 64 in linux kernel, else kernel fails to boot
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v6 13/17] hw/loongarch: fdt adds pch_msi Controller
2024-03-07 16:48 [PATCH v6 00/17] Add boot LoongArch elf kernel with FDT Song Gao
` (11 preceding siblings ...)
2024-03-07 16:48 ` [PATCH v6 12/17] hw/loongarch: fdt adds pch_pic Controller Song Gao
@ 2024-03-07 16:48 ` Song Gao
2024-03-08 8:41 ` maobibo
2024-03-07 16:48 ` [PATCH v6 14/17] hw/loongarch: fdt adds pcie irq_map node Song Gao
` (3 subsequent siblings)
16 siblings, 1 reply; 46+ messages in thread
From: Song Gao @ 2024-03-07 16:48 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, maobibo
fdt adds pch msi controller, we use 'loongson,pch-msi-1.0'.
See:
https://github.com/torvalds/linux/blob/v6.7/drivers/irqchip/irq-loongson-pch-msi.c
https://lore.kernel.org/r/20200528152757.1028711-6-jiaxun.yang@flygoat.com
Signed-off-by: Song Gao <gaosong@loongson.cn>
Message-Id: <20240301093839.663947-14-gaosong@loongson.cn>
---
hw/loongarch/virt.c | 33 ++++++++++++++++++++++++++++++++-
include/hw/pci-host/ls7a.h | 1 +
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index 2b7b653fc1..1e767c49f8 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -173,6 +173,34 @@ static void fdt_add_pch_pic_node(LoongArchMachineState *lams,
g_free(nodename);
}
+static void fdt_add_pch_msi_node(LoongArchMachineState *lams,
+ uint32_t *eiointc_phandle,
+ uint32_t *pch_msi_phandle)
+{
+ MachineState *ms = MACHINE(lams);
+ char *nodename;
+ hwaddr pch_msi_base = VIRT_PCH_MSI_ADDR_LOW;
+ hwaddr pch_msi_size = VIRT_PCH_MSI_SIZE;
+
+ *pch_msi_phandle = qemu_fdt_alloc_phandle(ms->fdt);
+ nodename = g_strdup_printf("/msi@%" PRIx64, pch_msi_base);
+ qemu_fdt_add_subnode(ms->fdt, nodename);
+ qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle", *pch_msi_phandle);
+ qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
+ "loongson,pch-msi-1.0");
+ qemu_fdt_setprop_cells(ms->fdt, nodename, "reg",
+ 0, pch_msi_base,
+ 0, pch_msi_size);
+ qemu_fdt_setprop(ms->fdt, nodename, "interrupt-controller", NULL, 0);
+ qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
+ *eiointc_phandle);
+ qemu_fdt_setprop_cell(ms->fdt, nodename, "loongson,msi-base-vec",
+ VIRT_PCH_PIC_IRQ_NUM);
+ qemu_fdt_setprop_cell(ms->fdt, nodename, "loongson,msi-num-vecs",
+ EXTIOI_IRQS - VIRT_PCH_PIC_IRQ_NUM);
+ g_free(nodename);
+}
+
static void fdt_add_flash_node(LoongArchMachineState *lams)
{
MachineState *ms = MACHINE(lams);
@@ -594,7 +622,7 @@ static void loongarch_irq_init(LoongArchMachineState *lams)
CPULoongArchState *env;
CPUState *cpu_state;
int cpu, pin, i, start, num;
- uint32_t cpuintc_phandle, eiointc_phandle, pch_pic_phandle;
+ uint32_t cpuintc_phandle, eiointc_phandle, pch_pic_phandle, pch_msi_phandle;
/*
* The connection of interrupts:
@@ -702,6 +730,9 @@ static void loongarch_irq_init(LoongArchMachineState *lams)
qdev_get_gpio_in(extioi, i + start));
}
+ /* Add PCH MSI node */
+ fdt_add_pch_msi_node(lams, &eiointc_phandle, &pch_msi_phandle);
+
loongarch_devices_init(pch_pic, lams);
}
diff --git a/include/hw/pci-host/ls7a.h b/include/hw/pci-host/ls7a.h
index fe260f0183..cd7c9ec7bc 100644
--- a/include/hw/pci-host/ls7a.h
+++ b/include/hw/pci-host/ls7a.h
@@ -25,6 +25,7 @@
#define VIRT_IOAPIC_REG_BASE (VIRT_PCH_REG_BASE)
#define VIRT_PCH_MSI_ADDR_LOW 0x2FF00000UL
#define VIRT_PCH_REG_SIZE 0x400
+#define VIRT_PCH_MSI_SIZE 0x8
/*
* GSI_BASE is hard-coded with 64 in linux kernel, else kernel fails to boot
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v6 14/17] hw/loongarch: fdt adds pcie irq_map node
2024-03-07 16:48 [PATCH v6 00/17] Add boot LoongArch elf kernel with FDT Song Gao
` (12 preceding siblings ...)
2024-03-07 16:48 ` [PATCH v6 13/17] hw/loongarch: fdt adds pch_msi Controller Song Gao
@ 2024-03-07 16:48 ` Song Gao
2024-03-08 8:44 ` maobibo
2024-03-07 16:48 ` [PATCH v6 15/17] hw/loongarch: fdt remove unused irqchip node Song Gao
` (2 subsequent siblings)
16 siblings, 1 reply; 46+ messages in thread
From: Song Gao @ 2024-03-07 16:48 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, maobibo
Signed-off-by: Song Gao <gaosong@loongson.cn>
Message-Id: <20240301093839.663947-15-gaosong@loongson.cn>
---
hw/loongarch/virt.c | 73 ++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 69 insertions(+), 4 deletions(-)
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index 1e767c49f8..d00343f0c2 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -352,7 +352,62 @@ static void fdt_add_fw_cfg_node(const LoongArchMachineState *lams)
g_free(nodename);
}
-static void fdt_add_pcie_node(const LoongArchMachineState *lams)
+static void fdt_add_pcie_irq_map_node(const LoongArchMachineState *lams,
+ char *nodename,
+ uint32_t *pch_pic_phandle)
+{
+ int pin, dev;
+ uint32_t irq_map_stride = 0;
+ uint32_t full_irq_map[GPEX_NUM_IRQS *GPEX_NUM_IRQS * 10] = {};
+ uint32_t *irq_map = full_irq_map;
+ const MachineState *ms = MACHINE(lams);
+
+ /* This code creates a standard swizzle of interrupts such that
+ * each device's first interrupt is based on it's PCI_SLOT number.
+ * (See pci_swizzle_map_irq_fn())
+ *
+ * We only need one entry per interrupt in the table (not one per
+ * possible slot) seeing the interrupt-map-mask will allow the table
+ * to wrap to any number of devices.
+ */
+
+ for (dev = 0; dev < GPEX_NUM_IRQS; dev++) {
+ int devfn = dev * 0x8;
+
+ for (pin = 0; pin < GPEX_NUM_IRQS; pin++) {
+ int irq_nr = 16 + ((pin + PCI_SLOT(devfn)) % GPEX_NUM_IRQS);
+ int i = 0;
+
+ /* Fill PCI address cells */
+ irq_map[i] = cpu_to_be32(devfn << 8);
+ i += 3;
+
+ /* Fill PCI Interrupt cells */
+ irq_map[i] = cpu_to_be32(pin + 1);
+ i += 1;
+
+ /* Fill interrupt controller phandle and cells */
+ irq_map[i++] = cpu_to_be32(*pch_pic_phandle);
+ irq_map[i++] = cpu_to_be32(irq_nr);
+
+ if (!irq_map_stride) {
+ irq_map_stride = i;
+ }
+ irq_map += irq_map_stride;
+ }
+ }
+
+
+ qemu_fdt_setprop(ms->fdt, nodename, "interrupt-map", full_irq_map,
+ GPEX_NUM_IRQS * GPEX_NUM_IRQS *
+ irq_map_stride * sizeof(uint32_t));
+ qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupt-map-mask",
+ 0x1800, 0, 0, 0x7);
+}
+
+static void fdt_add_pcie_node(const LoongArchMachineState *lams,
+ uint32_t *pch_pic_phandle,
+ uint32_t *pch_msi_phandle)
{
char *nodename;
hwaddr base_mmio = VIRT_PCI_MEM_BASE;
@@ -383,6 +438,11 @@ static void fdt_add_pcie_node(const LoongArchMachineState *lams)
2, base_pio, 2, size_pio,
1, FDT_PCI_RANGE_MMIO, 2, base_mmio,
2, base_mmio, 2, size_mmio);
+ qemu_fdt_setprop_cells(ms->fdt, nodename, "msi-map",
+ 0, *pch_msi_phandle, 0, 0x10000);
+
+ fdt_add_pcie_irq_map_node(lams, nodename, pch_pic_phandle);
+
g_free(nodename);
}
@@ -541,7 +601,10 @@ static DeviceState *create_platform_bus(DeviceState *pch_pic)
return dev;
}
-static void loongarch_devices_init(DeviceState *pch_pic, LoongArchMachineState *lams)
+static void loongarch_devices_init(DeviceState *pch_pic,
+ LoongArchMachineState *lams,
+ uint32_t *pch_pic_phandle,
+ uint32_t *pch_msi_phandle)
{
MachineClass *mc = MACHINE_GET_CLASS(lams);
DeviceState *gpex_dev;
@@ -587,6 +650,9 @@ static void loongarch_devices_init(DeviceState *pch_pic, LoongArchMachineState *
gpex_set_irq_num(GPEX_HOST(gpex_dev), i, 16 + i);
}
+ /* Add pcie node */
+ fdt_add_pcie_node(lams, pch_pic_phandle, pch_msi_phandle);
+
serial_mm_init(get_system_memory(), VIRT_UART_BASE, 0,
qdev_get_gpio_in(pch_pic,
VIRT_UART_IRQ - VIRT_GSI_BASE),
@@ -733,7 +799,7 @@ static void loongarch_irq_init(LoongArchMachineState *lams)
/* Add PCH MSI node */
fdt_add_pch_msi_node(lams, &eiointc_phandle, &pch_msi_phandle);
- loongarch_devices_init(pch_pic, lams);
+ loongarch_devices_init(pch_pic, lams, &pch_pic_phandle, &pch_msi_phandle);
}
static void loongarch_firmware_init(LoongArchMachineState *lams)
@@ -956,7 +1022,6 @@ static void loongarch_init(MachineState *machine)
lams->powerdown_notifier.notify = virt_powerdown_req;
qemu_register_powerdown_notifier(&lams->powerdown_notifier);
- fdt_add_pcie_node(lams);
/*
* Since lowmem region starts from 0 and Linux kernel legacy start address
* at 2 MiB, FDT base address is located at 1 MiB to avoid NULL pointer
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v6 15/17] hw/loongarch: fdt remove unused irqchip node
2024-03-07 16:48 [PATCH v6 00/17] Add boot LoongArch elf kernel with FDT Song Gao
` (13 preceding siblings ...)
2024-03-07 16:48 ` [PATCH v6 14/17] hw/loongarch: fdt adds pcie irq_map node Song Gao
@ 2024-03-07 16:48 ` Song Gao
2024-03-08 8:44 ` maobibo
2024-03-07 16:48 ` [PATCH v6 16/17] hw/loongarch: Add cells missing from uart node Song Gao
2024-03-07 16:48 ` [PATCH v6 17/17] hw/loongarch: Add cells missing from rtc node Song Gao
16 siblings, 1 reply; 46+ messages in thread
From: Song Gao @ 2024-03-07 16:48 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, maobibo
Signed-off-by: Song Gao <gaosong@loongson.cn>
Message-Id: <20240301093839.663947-16-gaosong@loongson.cn>
---
hw/loongarch/virt.c | 31 +------------------------------
1 file changed, 1 insertion(+), 30 deletions(-)
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index d00343f0c2..c80732a223 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -446,34 +446,6 @@ static void fdt_add_pcie_node(const LoongArchMachineState *lams,
g_free(nodename);
}
-static void fdt_add_irqchip_node(LoongArchMachineState *lams)
-{
- MachineState *ms = MACHINE(lams);
- char *nodename;
- uint32_t irqchip_phandle;
-
- irqchip_phandle = qemu_fdt_alloc_phandle(ms->fdt);
- qemu_fdt_setprop_cell(ms->fdt, "/", "interrupt-parent", irqchip_phandle);
-
- nodename = g_strdup_printf("/intc@%lx", VIRT_IOAPIC_REG_BASE);
- qemu_fdt_add_subnode(ms->fdt, nodename);
- qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 3);
- qemu_fdt_setprop(ms->fdt, nodename, "interrupt-controller", NULL, 0);
- qemu_fdt_setprop_cell(ms->fdt, nodename, "#address-cells", 0x2);
- qemu_fdt_setprop_cell(ms->fdt, nodename, "#size-cells", 0x2);
- qemu_fdt_setprop(ms->fdt, nodename, "ranges", NULL, 0);
-
- qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
- "loongarch,ls7a");
-
- qemu_fdt_setprop_sized_cells(ms->fdt, nodename, "reg",
- 2, VIRT_IOAPIC_REG_BASE,
- 2, PCH_PIC_ROUTE_ENTRY_OFFSET);
-
- qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle", irqchip_phandle);
- g_free(nodename);
-}
-
static void fdt_add_memory_node(MachineState *ms,
uint64_t base, uint64_t size, int node_id)
{
@@ -1011,8 +983,7 @@ static void loongarch_init(MachineState *machine)
/* Initialize the IO interrupt subsystem */
loongarch_irq_init(lams);
- fdt_add_irqchip_node(lams);
- platform_bus_add_all_fdt_nodes(machine->fdt, "/intc",
+ platform_bus_add_all_fdt_nodes(machine->fdt, "/platic",
VIRT_PLATFORM_BUS_BASEADDRESS,
VIRT_PLATFORM_BUS_SIZE,
VIRT_PLATFORM_BUS_IRQ);
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v6 16/17] hw/loongarch: Add cells missing from uart node
2024-03-07 16:48 [PATCH v6 00/17] Add boot LoongArch elf kernel with FDT Song Gao
` (14 preceding siblings ...)
2024-03-07 16:48 ` [PATCH v6 15/17] hw/loongarch: fdt remove unused irqchip node Song Gao
@ 2024-03-07 16:48 ` Song Gao
2024-03-08 8:44 ` maobibo
2024-03-07 16:48 ` [PATCH v6 17/17] hw/loongarch: Add cells missing from rtc node Song Gao
16 siblings, 1 reply; 46+ messages in thread
From: Song Gao @ 2024-03-07 16:48 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, maobibo
uart node need interrupts and interrupt-parent cells.
Signed-off-by: Song Gao <gaosong@loongson.cn>
Message-Id: <20240301093839.663947-17-gaosong@loongson.cn>
---
hw/loongarch/virt.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index c80732a223..58957a8d9a 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -245,7 +245,8 @@ static void fdt_add_rtc_node(LoongArchMachineState *lams)
g_free(nodename);
}
-static void fdt_add_uart_node(LoongArchMachineState *lams)
+static void fdt_add_uart_node(LoongArchMachineState *lams,
+ uint32_t *pch_pic_phandle)
{
char *nodename;
hwaddr base = VIRT_UART_BASE;
@@ -258,6 +259,10 @@ static void fdt_add_uart_node(LoongArchMachineState *lams)
qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 0x0, base, 0x0, size);
qemu_fdt_setprop_cell(ms->fdt, nodename, "clock-frequency", 100000000);
qemu_fdt_setprop_string(ms->fdt, "/chosen", "stdout-path", nodename);
+ qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts",
+ VIRT_UART_IRQ - VIRT_GSI_BASE, 0x4);
+ qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
+ *pch_pic_phandle);
g_free(nodename);
}
@@ -629,7 +634,7 @@ static void loongarch_devices_init(DeviceState *pch_pic,
qdev_get_gpio_in(pch_pic,
VIRT_UART_IRQ - VIRT_GSI_BASE),
115200, serial_hd(0), DEVICE_LITTLE_ENDIAN);
- fdt_add_uart_node(lams);
+ fdt_add_uart_node(lams, pch_pic_phandle);
/* Network init */
pci_init_nic_devices(pci_bus, mc->default_nic);
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v6 17/17] hw/loongarch: Add cells missing from rtc node
2024-03-07 16:48 [PATCH v6 00/17] Add boot LoongArch elf kernel with FDT Song Gao
` (15 preceding siblings ...)
2024-03-07 16:48 ` [PATCH v6 16/17] hw/loongarch: Add cells missing from uart node Song Gao
@ 2024-03-07 16:48 ` Song Gao
2024-03-08 8:45 ` maobibo
16 siblings, 1 reply; 46+ messages in thread
From: Song Gao @ 2024-03-07 16:48 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, maobibo
rtc node need interrupts and interrupt-parent cells.
Signed-off-by: Song Gao <gaosong@loongson.cn>
Message-Id: <20240301093839.663947-18-gaosong@loongson.cn>
---
hw/loongarch/virt.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index 58957a8d9a..676f1f5227 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -231,7 +231,8 @@ static void fdt_add_flash_node(LoongArchMachineState *lams)
g_free(nodename);
}
-static void fdt_add_rtc_node(LoongArchMachineState *lams)
+static void fdt_add_rtc_node(LoongArchMachineState *lams,
+ uint32_t *pch_pic_phandle)
{
char *nodename;
hwaddr base = VIRT_RTC_REG_BASE;
@@ -240,8 +241,13 @@ static void fdt_add_rtc_node(LoongArchMachineState *lams)
nodename = g_strdup_printf("/rtc@%" PRIx64, base);
qemu_fdt_add_subnode(ms->fdt, nodename);
- qemu_fdt_setprop_string(ms->fdt, nodename, "compatible", "loongson,ls7a-rtc");
+ qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
+ "loongson,ls7a-rtc");
qemu_fdt_setprop_sized_cells(ms->fdt, nodename, "reg", 2, base, 2, size);
+ qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts",
+ VIRT_RTC_IRQ - VIRT_GSI_BASE , 0x4);
+ qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
+ *pch_pic_phandle);
g_free(nodename);
}
@@ -647,7 +653,7 @@ static void loongarch_devices_init(DeviceState *pch_pic,
sysbus_create_simple("ls7a_rtc", VIRT_RTC_REG_BASE,
qdev_get_gpio_in(pch_pic,
VIRT_RTC_IRQ - VIRT_GSI_BASE));
- fdt_add_rtc_node(lams);
+ fdt_add_rtc_node(lams, pch_pic_phandle);
/* acpi ged */
lams->acpi_ged = create_acpi_ged(pch_pic, lams);
--
2.34.1
^ permalink raw reply related [flat|nested] 46+ messages in thread
* Re: [PATCH v6 01/17] hw/loongarch: Move boot fucntions to boot.c
2024-03-07 16:48 ` [PATCH v6 01/17] hw/loongarch: Move boot fucntions to boot.c Song Gao
@ 2024-03-08 8:18 ` maobibo
2024-03-08 8:31 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 46+ messages in thread
From: maobibo @ 2024-03-08 8:18 UTC (permalink / raw)
To: Song Gao, qemu-devel; +Cc: peter.maydell
On 2024/3/8 上午12:48, Song Gao wrote:
> Move some boot functions to boot.c and struct
> loongarch_boot_info into struct LoongArchMachineState.
>
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> Message-Id: <20240301093839.663947-2-gaosong@loongson.cn>
> ---
> hw/loongarch/boot.c | 128 ++++++++++++++++++++++++++++++++++++
> hw/loongarch/meson.build | 1 +
> hw/loongarch/virt.c | 121 +++-------------------------------
> include/hw/loongarch/boot.h | 21 ++++++
> include/hw/loongarch/virt.h | 2 +
> 5 files changed, 160 insertions(+), 113 deletions(-)
> create mode 100644 hw/loongarch/boot.c
> create mode 100644 include/hw/loongarch/boot.h
>
> diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
> new file mode 100644
> index 0000000000..a8a725a0a8
> --- /dev/null
> +++ b/hw/loongarch/boot.c
> @@ -0,0 +1,128 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * LoongArch boot helper functions.
> + *
> + * Copyright (c) 2023 Loongson Technology Corporation Limited
> + */
> +
> +#include "qemu/osdep.h"
> +#include "qemu/units.h"
> +#include "target/loongarch/cpu.h"
> +#include "hw/loongarch/virt.h"
> +#include "hw/loader.h"
> +#include "elf.h"
> +#include "qemu/error-report.h"
> +#include "sysemu/reset.h"
> +#include "sysemu/qtest.h"
> +
> +static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
> +{
> + return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
> +}
> +
> +static int64_t load_kernel_info(struct loongarch_boot_info *info)
> +{
> + uint64_t kernel_entry, kernel_low, kernel_high;
> + ssize_t kernel_size;
> +
> + kernel_size = load_elf(info->kernel_filename, NULL,
> + cpu_loongarch_virt_to_phys, NULL,
> + &kernel_entry, &kernel_low,
> + &kernel_high, NULL, 0,
> + EM_LOONGARCH, 1, 0);
> +
> + if (kernel_size < 0) {
> + error_report("could not load kernel '%s': %s",
> + info->kernel_filename,
> + load_elf_strerror(kernel_size));
> + exit(1);
> + }
> + return kernel_entry;
> +}
> +
> +static void reset_load_elf(void *opaque)
> +{
> + LoongArchCPU *cpu = opaque;
> + CPULoongArchState *env = &cpu->env;
> +
> + cpu_reset(CPU(cpu));
> + if (env->load_elf) {
> + cpu_set_pc(CPU(cpu), env->elf_address);
> + }
> +}
> +
> +static void fw_cfg_add_kernel_info(struct loongarch_boot_info *info,
> + FWCfgState *fw_cfg)
> +{
> + /*
> + * Expose the kernel, the command line, and the initrd in fw_cfg.
> + * We don't process them here at all, it's all left to the
> + * firmware.
> + */
> + load_image_to_fw_cfg(fw_cfg,
> + FW_CFG_KERNEL_SIZE, FW_CFG_KERNEL_DATA,
> + info->kernel_filename,
> + false);
> +
> + if (info->initrd_filename) {
> + load_image_to_fw_cfg(fw_cfg,
> + FW_CFG_INITRD_SIZE, FW_CFG_INITRD_DATA,
> + info->initrd_filename, false);
> + }
> +
> + if (info->kernel_cmdline) {
> + fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
> + strlen(info->kernel_cmdline) + 1);
> + fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA,
> + info->kernel_cmdline);
> + }
> +}
> +
> +static void loongarch_firmware_boot(LoongArchMachineState *lams,
> + struct loongarch_boot_info *info)
> +{
> + fw_cfg_add_kernel_info(info, lams->fw_cfg);
> +}
> +
> +static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info)
> +{
> + int64_t kernel_addr = 0;
> + LoongArchCPU *lacpu;
> + CPUState *cs;
> +
> + if (info->kernel_filename) {
> + kernel_addr = load_kernel_info(info);
> + } else {
> + if (!qtest_enabled()) {
> + error_report("Need kernel filename\n");
> + exit(1);
> + }
> + }
> +
> + CPU_FOREACH(cs) {
> + lacpu = LOONGARCH_CPU(cs);
> + lacpu->env.load_elf = true;
> + lacpu->env.elf_address = kernel_addr;
> + }
> +}
> +
> +void loongarch_load_kernel(MachineState *ms, struct loongarch_boot_info *info)
> +{
> + LoongArchMachineState *lams = LOONGARCH_MACHINE(ms);
> + int i;
> +
> + /* register reset function */
> + for (i = 0; i < ms->smp.cpus; i++) {
> + qemu_register_reset(reset_load_elf, LOONGARCH_CPU(qemu_get_cpu(i)));
> + }
> +
> + info->kernel_filename = ms->kernel_filename;
> + info->kernel_cmdline = ms->kernel_cmdline;
> + info->initrd_filename = ms->initrd_filename;
> +
> + if (lams->bios_loaded) {
> + loongarch_firmware_boot(lams, info);
> + } else {
> + loongarch_direct_kernel_boot(info);
> + }
> +}
> diff --git a/hw/loongarch/meson.build b/hw/loongarch/meson.build
> index c0421502ab..d306d82c2e 100644
> --- a/hw/loongarch/meson.build
> +++ b/hw/loongarch/meson.build
> @@ -1,6 +1,7 @@
> loongarch_ss = ss.source_set()
> loongarch_ss.add(files(
> 'fw_cfg.c',
> + 'boot.c',
> ))
> loongarch_ss.add(when: 'CONFIG_LOONGARCH_VIRT', if_true: [files('virt.c'), fdt])
> loongarch_ss.add(when: 'CONFIG_ACPI', if_true: files('acpi-build.c'))
> diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
> index 1e98d8bda5..bbd5cc1d4d 100644
> --- a/hw/loongarch/virt.c
> +++ b/hw/loongarch/virt.c
> @@ -46,14 +46,6 @@
> #include "hw/block/flash.h"
> #include "qemu/error-report.h"
>
> -
> -struct loaderparams {
> - uint64_t ram_size;
> - const char *kernel_filename;
> - const char *kernel_cmdline;
> - const char *initrd_filename;
> -};
> -
> static PFlashCFI01 *virt_flash_create1(LoongArchMachineState *lams,
> const char *name,
> const char *alias_prop_name)
> @@ -411,31 +403,6 @@ static void memmap_add_entry(uint64_t address, uint64_t length, uint32_t type)
> memmap_entries++;
> }
>
> -static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
> -{
> - return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
> -}
> -
> -static int64_t load_kernel_info(const struct loaderparams *loaderparams)
> -{
> - uint64_t kernel_entry, kernel_low, kernel_high;
> - ssize_t kernel_size;
> -
> - kernel_size = load_elf(loaderparams->kernel_filename, NULL,
> - cpu_loongarch_virt_to_phys, NULL,
> - &kernel_entry, &kernel_low,
> - &kernel_high, NULL, 0,
> - EM_LOONGARCH, 1, 0);
> -
> - if (kernel_size < 0) {
> - error_report("could not load kernel '%s': %s",
> - loaderparams->kernel_filename,
> - load_elf_strerror(kernel_size));
> - exit(1);
> - }
> - return kernel_entry;
> -}
> -
> static DeviceState *create_acpi_ged(DeviceState *pch_pic, LoongArchMachineState *lams)
> {
> DeviceState *dev;
> @@ -716,67 +683,6 @@ static void loongarch_firmware_init(LoongArchMachineState *lams)
> }
> }
>
> -static void reset_load_elf(void *opaque)
> -{
> - LoongArchCPU *cpu = opaque;
> - CPULoongArchState *env = &cpu->env;
> -
> - cpu_reset(CPU(cpu));
> - if (env->load_elf) {
> - cpu_set_pc(CPU(cpu), env->elf_address);
> - }
> -}
> -
> -static void fw_cfg_add_kernel_info(const struct loaderparams *loaderparams,
> - FWCfgState *fw_cfg)
> -{
> - /*
> - * Expose the kernel, the command line, and the initrd in fw_cfg.
> - * We don't process them here at all, it's all left to the
> - * firmware.
> - */
> - load_image_to_fw_cfg(fw_cfg,
> - FW_CFG_KERNEL_SIZE, FW_CFG_KERNEL_DATA,
> - loaderparams->kernel_filename,
> - false);
> -
> - if (loaderparams->initrd_filename) {
> - load_image_to_fw_cfg(fw_cfg,
> - FW_CFG_INITRD_SIZE, FW_CFG_INITRD_DATA,
> - loaderparams->initrd_filename, false);
> - }
> -
> - if (loaderparams->kernel_cmdline) {
> - fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
> - strlen(loaderparams->kernel_cmdline) + 1);
> - fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA,
> - loaderparams->kernel_cmdline);
> - }
> -}
> -
> -static void loongarch_firmware_boot(LoongArchMachineState *lams,
> - const struct loaderparams *loaderparams)
> -{
> - fw_cfg_add_kernel_info(loaderparams, lams->fw_cfg);
> -}
> -
> -static void loongarch_direct_kernel_boot(LoongArchMachineState *lams,
> - const struct loaderparams *loaderparams)
> -{
> - MachineState *machine = MACHINE(lams);
> - int64_t kernel_addr = 0;
> - LoongArchCPU *lacpu;
> - int i;
> -
> - kernel_addr = load_kernel_info(loaderparams);
> - if (!machine->firmware) {
> - for (i = 0; i < machine->smp.cpus; i++) {
> - lacpu = LOONGARCH_CPU(qemu_get_cpu(i));
> - lacpu->env.load_elf = true;
> - lacpu->env.elf_address = kernel_addr;
> - }
> - }
> -}
>
> static void loongarch_qemu_write(void *opaque, hwaddr addr,
> uint64_t val, unsigned size)
> @@ -832,7 +738,6 @@ static void loongarch_init(MachineState *machine)
> MachineClass *mc = MACHINE_GET_CLASS(machine);
> CPUState *cpu;
> char *ramName = NULL;
> - struct loaderparams loaderparams = { };
>
> if (!cpu_model) {
> cpu_model = LOONGARCH_CPU_TYPE_NAME("la464");
> @@ -935,24 +840,8 @@ static void loongarch_init(MachineState *machine)
> sizeof(struct memmap_entry) * (memmap_entries));
> }
> fdt_add_fw_cfg_node(lams);
> - loaderparams.ram_size = ram_size;
> - loaderparams.kernel_filename = machine->kernel_filename;
> - loaderparams.kernel_cmdline = machine->kernel_cmdline;
> - loaderparams.initrd_filename = machine->initrd_filename;
> - /* load the kernel. */
> - if (loaderparams.kernel_filename) {
> - if (lams->bios_loaded) {
> - loongarch_firmware_boot(lams, &loaderparams);
> - } else {
> - loongarch_direct_kernel_boot(lams, &loaderparams);
> - }
> - }
> fdt_add_flash_node(lams);
> - /* register reset function */
> - for (i = 0; i < machine->smp.cpus; i++) {
> - lacpu = LOONGARCH_CPU(qemu_get_cpu(i));
> - qemu_register_reset(reset_load_elf, lacpu);
> - }
> +
> /* Initialize the IO interrupt subsystem */
> loongarch_irq_init(lams);
> fdt_add_irqchip_node(lams);
> @@ -976,7 +865,13 @@ static void loongarch_init(MachineState *machine)
> */
> fdt_base = 1 * MiB;
> qemu_fdt_dumpdtb(machine->fdt, lams->fdt_size);
> - rom_add_blob_fixed("fdt", machine->fdt, lams->fdt_size, fdt_base);
> + rom_add_blob_fixed_as("fdt", machine->fdt, lams->fdt_size, fdt_base,
> + &address_space_memory);
> + qemu_register_reset_nosnapshotload(qemu_fdt_randomize_seeds,
> + rom_ptr_for_as(&address_space_memory, fdt_base, lams->fdt_size));
> +
> + lams->bootinfo.ram_size = ram_size;
> + loongarch_load_kernel(machine, &lams->bootinfo);
> }
>
> bool loongarch_is_acpi_enabled(LoongArchMachineState *lams)
> diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h
> new file mode 100644
> index 0000000000..3275c1e295
> --- /dev/null
> +++ b/include/hw/loongarch/boot.h
> @@ -0,0 +1,21 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Definitions for LoongArch boot.
> + *
> + * Copyright (C) 2023 Loongson Technology Corporation Limited
> + */
> +
> +#ifndef HW_LOONGARCH_BOOT_H
> +#define HW_LOONGARCH_BOOT_H
> +
> +struct loongarch_boot_info {
> + uint64_t ram_size;
> + const char *kernel_filename;
> + const char *kernel_cmdline;
> + const char *initrd_filename;
> + uint64_t a0, a1, a2;
> +};
> +
> +void loongarch_load_kernel(MachineState *ms, struct loongarch_boot_info *info);
> +
> +#endif /* HW_LOONGARCH_BOOT_H */
> diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h
> index 252f7df7f4..cf2f2bfb19 100644
> --- a/include/hw/loongarch/virt.h
> +++ b/include/hw/loongarch/virt.h
> @@ -13,6 +13,7 @@
> #include "qemu/queue.h"
> #include "hw/intc/loongarch_ipi.h"
> #include "hw/block/flash.h"
> +#include "hw/loongarch/boot.h"
>
> #define LOONGARCH_MAX_CPUS 256
>
> @@ -55,6 +56,7 @@ struct LoongArchMachineState {
> MemoryRegion system_iocsr;
> MemoryRegion iocsr_mem;
> AddressSpace as_iocsr;
> + struct loongarch_boot_info bootinfo;
> };
>
> #define TYPE_LOONGARCH_MACHINE MACHINE_TYPE_NAME("virt")
>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 02/17] hw/loongarch: Add load initrd
2024-03-07 16:48 ` [PATCH v6 02/17] hw/loongarch: Add load initrd Song Gao
@ 2024-03-08 8:19 ` maobibo
0 siblings, 0 replies; 46+ messages in thread
From: maobibo @ 2024-03-08 8:19 UTC (permalink / raw)
To: Song Gao, qemu-devel; +Cc: peter.maydell
On 2024/3/8 上午12:48, Song Gao wrote:
> we load initrd ramdisk after kernel_high address
>
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> Message-Id: <20240301093839.663947-3-gaosong@loongson.cn>
> ---
> hw/loongarch/boot.c | 29 ++++++++++++++++++++++++++++-
> 1 file changed, 28 insertions(+), 1 deletion(-)
>
> diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
> index a8a725a0a8..149deb2e01 100644
> --- a/hw/loongarch/boot.c
> +++ b/hw/loongarch/boot.c
> @@ -22,7 +22,8 @@ static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
>
> static int64_t load_kernel_info(struct loongarch_boot_info *info)
> {
> - uint64_t kernel_entry, kernel_low, kernel_high;
> + uint64_t kernel_entry, kernel_low, kernel_high, initrd_size;
> + ram_addr_t initrd_offset;
> ssize_t kernel_size;
>
> kernel_size = load_elf(info->kernel_filename, NULL,
> @@ -37,6 +38,32 @@ static int64_t load_kernel_info(struct loongarch_boot_info *info)
> load_elf_strerror(kernel_size));
> exit(1);
> }
> +
> + if (info->initrd_filename) {
> + initrd_size = get_image_size(info->initrd_filename);
> + if (initrd_size > 0) {
> + initrd_offset = ROUND_UP(kernel_high + 4 * kernel_size, 64 * KiB);
> +
> + if (initrd_offset + initrd_size > info->ram_size) {
> + error_report("memory too small for initial ram disk '%s'",
> + info->initrd_filename);
> + exit(1);
> + }
> +
> + initrd_size = load_image_targphys(info->initrd_filename, initrd_offset,
> + info->ram_size - initrd_offset);
> + }
> +
> + if (initrd_size == (target_ulong)-1) {
> + error_report("could not load initial ram disk '%s'",
> + info->initrd_filename);
> + exit(1);
> + }
> + } else {
> + error_report("Need initrd!");
> + exit(1);
> + }
> +
> return kernel_entry;
> }
>
>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 03/17] hw/loongarch: Add slave cpu boot_code
2024-03-07 16:48 ` [PATCH v6 03/17] hw/loongarch: Add slave cpu boot_code Song Gao
@ 2024-03-08 8:27 ` maobibo
2024-03-08 9:36 ` gaosong
2024-03-14 2:28 ` chen huacai
1 sibling, 1 reply; 46+ messages in thread
From: maobibo @ 2024-03-08 8:27 UTC (permalink / raw)
To: Song Gao, qemu-devel; +Cc: peter.maydell
On 2024/3/8 上午12:48, Song Gao wrote:
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> Message-Id: <20240301093839.663947-4-gaosong@loongson.cn>
> ---
> hw/loongarch/boot.c | 70 ++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 69 insertions(+), 1 deletion(-)
>
> diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
> index 149deb2e01..e560ac178a 100644
> --- a/hw/loongarch/boot.c
> +++ b/hw/loongarch/boot.c
> @@ -15,6 +15,54 @@
> #include "sysemu/reset.h"
> #include "sysemu/qtest.h"
>
> +static const unsigned int slave_boot_code[] = {
> + /* Configure reset ebase. */
> + 0x0400302c, /* csrwr $r12,0xc */
> +
> + /* Disable interrupt. */
> + 0x0380100c, /* ori $r12,$r0,0x4 */
> + 0x04000180, /* csrxchg $r0,$r12,0x0 */
> +
> + /* Clear mailbox. */
> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
> + 0x038081ad, /* ori $r13,$r13,0x20 */
> + 0x06481da0, /* iocsrwr.d $r0,$r13 */
> +
> + /* Enable IPI interrupt. */
> + 0x1400002c, /* lu12i.w $r12,1(0x1) */
> + 0x0400118c, /* csrxchg $r12,$r12,0x4 */
> + 0x02fffc0c, /* addi.d $r12,$r0,-1(0xfff) */
> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
> + 0x038011ad, /* ori $r13,$r13,0x4 */
> + 0x064819ac, /* iocsrwr.w $r12,$r13 */
> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
> + 0x038081ad, /* ori $r13,$r13,0x20 */
> +
> + /* Wait for wakeup <.L11>: */
> + 0x06488000, /* idle 0x0 */
> + 0x03400000, /* andi $r0,$r0,0x0 */
> + 0x064809ac, /* iocsrrd.w $r12,$r13 */
> + 0x43fff59f, /* beqz $r12,-12(0x7ffff4) # 48 <.L11> */
> +
> + /* Read and clear IPI interrupt. */
> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
> + 0x064809ac, /* iocsrrd.w $r12,$r13 */
> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
> + 0x038031ad, /* ori $r13,$r13,0xc */
> + 0x064819ac, /* iocsrwr.w $r12,$r13 */
> +
> + /* Disable IPI interrupt. */
> + 0x1400002c, /* lu12i.w $r12,1(0x1) */
> + 0x04001180, /* csrxchg $r0,$r12,0x4 */
> +
> + /* Read mail buf and jump to specified entry */
> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
> + 0x038081ad, /* ori $r13,$r13,0x20 */
> + 0x06480dac, /* iocsrrd.d $r12,$r13 */
> + 0x00150181, /* move $r1,$r12 */
> + 0x4c000020, /* jirl $r0,$r1,0 */
> +};
> +
> static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
> {
> return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
> @@ -111,8 +159,15 @@ static void loongarch_firmware_boot(LoongArchMachineState *lams,
> fw_cfg_add_kernel_info(info, lams->fw_cfg);
> }
>
> +static void init_boot_rom(struct loongarch_boot_info *info, void *p)
> +{
> + memcpy(p, &slave_boot_code, sizeof(slave_boot_code));
> + p += sizeof(slave_boot_code);
> +}
> +
> static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info)
> {
> + void *p, *bp;
> int64_t kernel_addr = 0;
> LoongArchCPU *lacpu;
> CPUState *cs;
> @@ -126,11 +181,24 @@ static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info)
> }
> }
>
> + /* Load 'boot_rom' at [0 - 1MiB] */
> + p = g_malloc0(1 * MiB);
> + bp = p;
> + init_boot_rom(info, p);
> + rom_add_blob_fixed("boot_rom", bp, 1 * MiB, 0);
> +
The secondary cpu waiting on the bootrom located memory address
0x0-0x100000.
Is it possible that primary cpu clears the memory located at bootrom
and then wakeup the secondary cpu?
Regards
Bibo Mao
> CPU_FOREACH(cs) {
> lacpu = LOONGARCH_CPU(cs);
> lacpu->env.load_elf = true;
> - lacpu->env.elf_address = kernel_addr;
> + if (cs == first_cpu) {
> + lacpu->env.elf_address = kernel_addr;
> + } else {
> + lacpu->env.elf_address = 0;
> + }
> + lacpu->env.boot_info = info;
> }
> +
> + g_free(bp);
> }
>
> void loongarch_load_kernel(MachineState *ms, struct loongarch_boot_info *info)
>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 04/17] hw/loongarch: Add init_cmdline
2024-03-07 16:48 ` [PATCH v6 04/17] hw/loongarch: Add init_cmdline Song Gao
@ 2024-03-08 8:28 ` maobibo
0 siblings, 0 replies; 46+ messages in thread
From: maobibo @ 2024-03-08 8:28 UTC (permalink / raw)
To: Song Gao, qemu-devel; +Cc: peter.maydell
On 2024/3/8 上午12:48, Song Gao wrote:
> Add init_cmline and set boot_info->a0, a1
>
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> Message-Id: <20240301093839.663947-5-gaosong@loongson.cn>
> ---
> hw/loongarch/boot.c | 19 +++++++++++++++++++
> include/hw/loongarch/virt.h | 2 ++
> target/loongarch/cpu.h | 2 ++
> 3 files changed, 23 insertions(+)
>
> diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
> index e560ac178a..ca65dfde07 100644
> --- a/hw/loongarch/boot.c
> +++ b/hw/loongarch/boot.c
> @@ -63,6 +63,16 @@ static const unsigned int slave_boot_code[] = {
> 0x4c000020, /* jirl $r0,$r1,0 */
> };
>
> +static void init_cmdline(struct loongarch_boot_info *info, void *p, void *start)
> +{
> + hwaddr cmdline_addr = (hwaddr)p - (hwaddr)start;
> +
> + info->a0 = 1;
> + info->a1 = cmdline_addr;
> +
> + memcpy(p, info->kernel_cmdline, COMMAND_LINE_SIZE);
> +}
> +
> static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
> {
> return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
> @@ -122,6 +132,10 @@ static void reset_load_elf(void *opaque)
>
> cpu_reset(CPU(cpu));
> if (env->load_elf) {
> + if (cpu == LOONGARCH_CPU(first_cpu)) {
> + env->gpr[4] = env->boot_info->a0;
> + env->gpr[5] = env->boot_info->a1;
> + }
> cpu_set_pc(CPU(cpu), env->elf_address);
> }
> }
> @@ -161,8 +175,13 @@ static void loongarch_firmware_boot(LoongArchMachineState *lams,
>
> static void init_boot_rom(struct loongarch_boot_info *info, void *p)
> {
> + void *start = p;
> +
> memcpy(p, &slave_boot_code, sizeof(slave_boot_code));
> p += sizeof(slave_boot_code);
> +
> + init_cmdline(info, p, start);
> + p += COMMAND_LINE_SIZE;
> }
>
> static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info)
> diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h
> index cf2f2bfb19..d7a074d69f 100644
> --- a/include/hw/loongarch/virt.h
> +++ b/include/hw/loongarch/virt.h
> @@ -33,6 +33,8 @@
> #define VIRT_GED_MEM_ADDR (VIRT_GED_EVT_ADDR + ACPI_GED_EVT_SEL_LEN)
> #define VIRT_GED_REG_ADDR (VIRT_GED_MEM_ADDR + MEMORY_HOTPLUG_IO_LEN)
>
> +#define COMMAND_LINE_SIZE 512
> +
> struct LoongArchMachineState {
> /*< private >*/
> MachineState parent_obj;
> diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
> index ec37579fd6..ce02ef3979 100644
> --- a/target/loongarch/cpu.h
> +++ b/target/loongarch/cpu.h
> @@ -361,6 +361,8 @@ typedef struct CPUArchState {
> uint32_t mp_state;
> /* Store ipistate to access from this struct */
> DeviceState *ipistate;
> +
> + struct loongarch_boot_info *boot_info;
> #endif
> } CPULoongArchState;
>
>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 05/17] hw/loongarch: Init efi_system_table
2024-03-07 16:48 ` [PATCH v6 05/17] hw/loongarch: Init efi_system_table Song Gao
@ 2024-03-08 8:29 ` maobibo
2024-03-08 8:33 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 46+ messages in thread
From: maobibo @ 2024-03-08 8:29 UTC (permalink / raw)
To: Song Gao, qemu-devel; +Cc: peter.maydell
On 2024/3/8 上午12:48, Song Gao wrote:
> Add init_systab and set boot_info->a2
>
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> Message-Id: <20240301093839.663947-6-gaosong@loongson.cn>
> ---
> hw/loongarch/boot.c | 22 +++++++++++++++++
> include/hw/loongarch/boot.h | 48 +++++++++++++++++++++++++++++++++++++
> 2 files changed, 70 insertions(+)
>
> diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
> index ca65dfde07..1e31e2a59f 100644
> --- a/hw/loongarch/boot.c
> +++ b/hw/loongarch/boot.c
> @@ -63,6 +63,25 @@ static const unsigned int slave_boot_code[] = {
> 0x4c000020, /* jirl $r0,$r1,0 */
> };
>
> +static void init_systab(struct loongarch_boot_info *info, void *p, void *start)
> +{
> + struct efi_system_table *systab = p;
> +
> + info->a2 = (uint64_t)p - (uint64_t)start;
> +
> + systab->hdr.signature = EFI_SYSTEM_TABLE_SIGNATURE;
> + systab->hdr.revision = EFI_SPECIFICATION_VERSION;
> + systab->hdr.revision = sizeof(struct efi_system_table),
> + systab->fw_revision = FW_VERSION << 16 | FW_PATCHLEVEL << 8;
> + systab->runtime = 0;
> + systab->boottime = 0;
> + systab->nr_tables = 0;
> +
> + p += ROUND_UP(sizeof(struct efi_system_table), 64);
> +
> + systab->tables = p;
> +}
> +
> static void init_cmdline(struct loongarch_boot_info *info, void *p, void *start)
> {
> hwaddr cmdline_addr = (hwaddr)p - (hwaddr)start;
> @@ -135,6 +154,7 @@ static void reset_load_elf(void *opaque)
> if (cpu == LOONGARCH_CPU(first_cpu)) {
> env->gpr[4] = env->boot_info->a0;
> env->gpr[5] = env->boot_info->a1;
> + env->gpr[6] = env->boot_info->a2;
> }
> cpu_set_pc(CPU(cpu), env->elf_address);
> }
> @@ -182,6 +202,8 @@ static void init_boot_rom(struct loongarch_boot_info *info, void *p)
>
> init_cmdline(info, p, start);
> p += COMMAND_LINE_SIZE;
> +
> + init_systab(info, p, start);
> }
>
> static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info)
> diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h
> index 3275c1e295..65ad406f02 100644
> --- a/include/hw/loongarch/boot.h
> +++ b/include/hw/loongarch/boot.h
> @@ -8,6 +8,54 @@
> #ifndef HW_LOONGARCH_BOOT_H
> #define HW_LOONGARCH_BOOT_H
>
> +/* UEFI 2.10 */
> +#define EFI_SYSTEM_TABLE_SIGNATURE 0x5453595320494249
> +#define EFI_2_100_SYSTEM_TABLE_REVISION ((2<<16) | (100))
> +#define EFI_SPECIFICATION_VERSION EFI_SYSTEM_TABLE_REVISION
> +#define EFI_SYSTEM_TABLE_REVISION EFI_2_100_SYSTEM_TABLE_REVISION
> +
> +#define FW_VERSION 0x1
> +#define FW_PATCHLEVEL 0x0
> +
> +typedef struct {
> + uint8_t b[16];
> +} efi_guid_t __attribute__((aligned(8)));
> +
> +struct efi_config_table {
> + efi_guid_t guid;
> + uint64_t *ptr;
> + const char name[16];
> +};
> +
> +typedef struct {
> + uint64_t signature;
> + uint32_t revision;
> + uint32_t headersize;
> + uint32_t crc32;
> + uint32_t reserved;
> +} efi_table_hdr_t;
> +
> +struct efi_configuration_table {
> + efi_guid_t guid;
> + void *table;
> +};
> +
> +struct efi_system_table {
> + efi_table_hdr_t hdr;
> + uint64_t fw_vendor; /* physical addr of CHAR16 vendor string */
> + uint32_t fw_revision;
> + uint64_t con_in_handle;
> + uint64_t *con_in;
> + uint64_t con_out_handle;
> + uint64_t *con_out;
> + uint64_t stderr_handle;
> + uint64_t stderr_placeholder;
> + uint64_t *runtime;
> + uint64_t *boottime;
> + uint64_t nr_tables;
> + struct efi_configuration_table *tables;
> +};
> +
> struct loongarch_boot_info {
> uint64_t ram_size;
> const char *kernel_filename;
>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 01/17] hw/loongarch: Move boot fucntions to boot.c
2024-03-07 16:48 ` [PATCH v6 01/17] hw/loongarch: Move boot fucntions to boot.c Song Gao
2024-03-08 8:18 ` maobibo
@ 2024-03-08 8:31 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 46+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-03-08 8:31 UTC (permalink / raw)
To: Song Gao, qemu-devel; +Cc: peter.maydell, maobibo
On 7/3/24 17:48, Song Gao wrote:
> Move some boot functions to boot.c and struct
> loongarch_boot_info into struct LoongArchMachineState.
>
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> Message-Id: <20240301093839.663947-2-gaosong@loongson.cn>
> ---
> hw/loongarch/boot.c | 128 ++++++++++++++++++++++++++++++++++++
> hw/loongarch/meson.build | 1 +
> hw/loongarch/virt.c | 121 +++-------------------------------
> include/hw/loongarch/boot.h | 21 ++++++
> include/hw/loongarch/virt.h | 2 +
> 5 files changed, 160 insertions(+), 113 deletions(-)
> create mode 100644 hw/loongarch/boot.c
> create mode 100644 include/hw/loongarch/boot.h
Consider enabling scripts/git.orderfile.
Typo "functions" in patch subject.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 05/17] hw/loongarch: Init efi_system_table
2024-03-07 16:48 ` [PATCH v6 05/17] hw/loongarch: Init efi_system_table Song Gao
2024-03-08 8:29 ` maobibo
@ 2024-03-08 8:33 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 46+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-03-08 8:33 UTC (permalink / raw)
To: Song Gao, qemu-devel; +Cc: peter.maydell, maobibo
On 7/3/24 17:48, Song Gao wrote:
> Add init_systab and set boot_info->a2
>
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> Message-Id: <20240301093839.663947-6-gaosong@loongson.cn>
> ---
> hw/loongarch/boot.c | 22 +++++++++++++++++
> include/hw/loongarch/boot.h | 48 +++++++++++++++++++++++++++++++++++++
> 2 files changed, 70 insertions(+)
> diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h
> index 3275c1e295..65ad406f02 100644
> --- a/include/hw/loongarch/boot.h
> +++ b/include/hw/loongarch/boot.h
> @@ -8,6 +8,54 @@
> #ifndef HW_LOONGARCH_BOOT_H
> #define HW_LOONGARCH_BOOT_H
>
> +/* UEFI 2.10 */
> +#define EFI_SYSTEM_TABLE_SIGNATURE 0x5453595320494249
> +#define EFI_2_100_SYSTEM_TABLE_REVISION ((2<<16) | (100))
> +#define EFI_SPECIFICATION_VERSION EFI_SYSTEM_TABLE_REVISION
> +#define EFI_SYSTEM_TABLE_REVISION EFI_2_100_SYSTEM_TABLE_REVISION
> +
> +#define FW_VERSION 0x1
> +#define FW_PATCHLEVEL 0x0
> +
> +typedef struct {
> + uint8_t b[16];
> +} efi_guid_t __attribute__((aligned(8)));
QEMU_ALIGNED(8)
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 07/17] hw/loongarch: Init efi_initrd table
2024-03-07 16:48 ` [PATCH v6 07/17] hw/loongarch: Init efi_initrd table Song Gao
@ 2024-03-08 8:36 ` Philippe Mathieu-Daudé
2024-03-08 9:20 ` gaosong
2024-03-08 8:37 ` maobibo
1 sibling, 1 reply; 46+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-03-08 8:36 UTC (permalink / raw)
To: Song Gao, qemu-devel; +Cc: peter.maydell, maobibo
Hi Song,
On 7/3/24 17:48, Song Gao wrote:
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> Message-Id: <20240301093839.663947-8-gaosong@loongson.cn>
> ---
> hw/loongarch/boot.c | 23 +++++++++++++++++++++--
> include/hw/loongarch/boot.h | 9 +++++++++
> 2 files changed, 30 insertions(+), 2 deletions(-)
>
> diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
> index 2896c1ea40..6126a37858 100644
> --- a/hw/loongarch/boot.c
> +++ b/hw/loongarch/boot.c
> @@ -15,6 +15,9 @@
> #include "sysemu/reset.h"
> #include "sysemu/qtest.h"
>
> +ram_addr_t initrd_offset;
> +uint64_t initrd_size;
Where is that used?
> static const unsigned int slave_boot_code[] = {
> /* Configure reset ebase. */
> 0x0400302c, /* csrwr $r12,0xc */
> @@ -94,6 +97,21 @@ static void init_efi_boot_memmap(struct efi_system_table *systab,
> }
> }
>
> +static void init_efi_initrd_table(struct efi_system_table *systab,
> + void *p, void *start)
> +{
> + efi_guid_t tbl_guid = LINUX_EFI_INITRD_MEDIA_GUID;
> + struct efi_initrd *initrd_table = p;
> +
> + /* efi_configuration_table 2 */
> + guidcpy(&systab->tables[1].guid, &tbl_guid);
> + systab->tables[1].table = (struct efi_configuration_table *)(p - start);
> + systab->nr_tables = 2;
> +
> + initrd_table->base = initrd_offset;
> + initrd_table->size = initrd_size;
> +}
> +
> static void init_systab(struct loongarch_boot_info *info, void *p, void *start)
> {
> void *bp_tables_start;
> @@ -117,6 +135,8 @@ static void init_systab(struct loongarch_boot_info *info, void *p, void *start)
> init_efi_boot_memmap(systab, p, start);
> p += ROUND_UP(sizeof(struct efi_boot_memmap) +
> sizeof(efi_memory_desc_t) * memmap_entries, 64);
> + init_efi_initrd_table(systab, p, start);
> + p += ROUND_UP(sizeof(struct efi_initrd), 64);
>
> systab->tables = (struct efi_configuration_table *)(bp_tables_start - start);
> }
> @@ -138,8 +158,7 @@ static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
>
> static int64_t load_kernel_info(struct loongarch_boot_info *info)
> {
> - uint64_t kernel_entry, kernel_low, kernel_high, initrd_size;
> - ram_addr_t initrd_offset;
> + uint64_t kernel_entry, kernel_low, kernel_high;
> ssize_t kernel_size;
>
> kernel_size = load_elf(info->kernel_filename, NULL,
> diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h
> index f71c693f43..ddcb279874 100644
> --- a/include/hw/loongarch/boot.h
> +++ b/include/hw/loongarch/boot.h
> @@ -30,6 +30,10 @@ typedef struct {
> EFI_GUID(0x800f683f, 0xd08b, 0x423a, 0xa2, 0x93, \
> 0x96, 0x5c, 0x3c, 0x6f, 0xe2, 0xb4)
>
> +#define LINUX_EFI_INITRD_MEDIA_GUID \
> + EFI_GUID(0x5568e427, 0x68fc, 0x4f3d, 0xac, 0x74, \
> + 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68)
> +
> struct efi_config_table {
> efi_guid_t guid;
> uint64_t *ptr;
> @@ -83,6 +87,11 @@ struct efi_boot_memmap {
> efi_memory_desc_t map[32];
> };
>
> +struct efi_initrd {
> + uint64_t base;
> + uint64_t size;
> +};
> +
> struct loongarch_boot_info {
> uint64_t ram_size;
> const char *kernel_filename;
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 06/17] hw/loongarch: Init efi_boot_memmap table
2024-03-07 16:48 ` [PATCH v6 06/17] hw/loongarch: Init efi_boot_memmap table Song Gao
@ 2024-03-08 8:37 ` maobibo
2024-03-08 10:09 ` gaosong
0 siblings, 1 reply; 46+ messages in thread
From: maobibo @ 2024-03-08 8:37 UTC (permalink / raw)
To: Song Gao, qemu-devel; +Cc: peter.maydell
On 2024/3/8 上午12:48, Song Gao wrote:
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> Message-Id: <20240301093839.663947-7-gaosong@loongson.cn>
> ---
> hw/loongarch/boot.c | 39 +++++++++++++++++++++++++++++++++++++
> hw/loongarch/virt.c | 11 ++---------
> include/hw/loongarch/boot.h | 27 +++++++++++++++++++++++++
> include/hw/loongarch/virt.h | 10 ++++++++++
> 4 files changed, 78 insertions(+), 9 deletions(-)
>
> diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
> index 1e31e2a59f..2896c1ea40 100644
> --- a/hw/loongarch/boot.c
> +++ b/hw/loongarch/boot.c
> @@ -63,8 +63,40 @@ static const unsigned int slave_boot_code[] = {
> 0x4c000020, /* jirl $r0,$r1,0 */
> };
>
> +static inline void *guidcpy(void *dst, const void *src)
> +{
> + return memcpy(dst, src, sizeof(efi_guid_t));
> +}
> +
> +static void init_efi_boot_memmap(struct efi_system_table *systab,
> + void *p, void *start)
> +{
> + unsigned i;
> + struct efi_boot_memmap *boot_memmap = p;
> + efi_guid_t tbl_guid = LINUX_EFI_BOOT_MEMMAP_GUID;
> +
> + /* efi_configuration_table 1 */
> + guidcpy(&systab->tables[0].guid, &tbl_guid);
> + systab->tables[0].table = (struct efi_configuration_table *)(p - start);
> + systab->nr_tables = 1;
> +
> + boot_memmap->desc_size = sizeof(efi_memory_desc_t);
> + boot_memmap->desc_ver = 1;
> + boot_memmap->map_size = 0;
> +
> + efi_memory_desc_t *map = p + sizeof(struct efi_boot_memmap);
> + for (i = 0; i < memmap_entries; i++) {
> + map = (void *)boot_memmap + sizeof(*map);
> + map[i].type = memmap_table[i].type;
> + map[i].phys_addr = memmap_table[i].address;
> + map[i].num_pages = memmap_table[i].length >> 16; /* 64KB align*/
64KB aligned or 64KB page size? In generic page size is 4K by EFI spec IIRC.
Regards
Bibo Mao
> + p += sizeof(efi_memory_desc_t);
> + }
> +}
> +
> static void init_systab(struct loongarch_boot_info *info, void *p, void *start)
> {
> + void *bp_tables_start;
> struct efi_system_table *systab = p;
>
> info->a2 = (uint64_t)p - (uint64_t)start;
> @@ -80,6 +112,13 @@ static void init_systab(struct loongarch_boot_info *info, void *p, void *start)
> p += ROUND_UP(sizeof(struct efi_system_table), 64);
>
> systab->tables = p;
> + bp_tables_start = p;
> +
> + init_efi_boot_memmap(systab, p, start);
> + p += ROUND_UP(sizeof(struct efi_boot_memmap) +
> + sizeof(efi_memory_desc_t) * memmap_entries, 64);
> +
> + systab->tables = (struct efi_configuration_table *)(bp_tables_start - start);
> }
>
> static void init_cmdline(struct loongarch_boot_info *info, void *p, void *start)
> diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
> index bbd5cc1d4d..8981b57b12 100644
> --- a/hw/loongarch/virt.c
> +++ b/hw/loongarch/virt.c
> @@ -377,15 +377,8 @@ static void virt_powerdown_req(Notifier *notifier, void *opaque)
> acpi_send_event(s->acpi_ged, ACPI_POWER_DOWN_STATUS);
> }
>
> -struct memmap_entry {
> - uint64_t address;
> - uint64_t length;
> - uint32_t type;
> - uint32_t reserved;
> -};
> -
> -static struct memmap_entry *memmap_table;
> -static unsigned memmap_entries;
> +struct memmap_entry *memmap_table;
> +unsigned memmap_entries;
>
> static void memmap_add_entry(uint64_t address, uint64_t length, uint32_t type)
> {
> diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h
> index 65ad406f02..f71c693f43 100644
> --- a/include/hw/loongarch/boot.h
> +++ b/include/hw/loongarch/boot.h
> @@ -21,6 +21,15 @@ typedef struct {
> uint8_t b[16];
> } efi_guid_t __attribute__((aligned(8)));
>
> +#define EFI_GUID(a, b, c, d...) (efi_guid_t){ { \
> + (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
> + (b) & 0xff, ((b) >> 8) & 0xff, \
> + (c) & 0xff, ((c) >> 8) & 0xff, d } }
> +
> +#define LINUX_EFI_BOOT_MEMMAP_GUID \
> + EFI_GUID(0x800f683f, 0xd08b, 0x423a, 0xa2, 0x93, \
> + 0x96, 0x5c, 0x3c, 0x6f, 0xe2, 0xb4)
> +
> struct efi_config_table {
> efi_guid_t guid;
> uint64_t *ptr;
> @@ -56,6 +65,24 @@ struct efi_system_table {
> struct efi_configuration_table *tables;
> };
>
> +typedef struct {
> + uint32_t type;
> + uint32_t pad;
> + uint64_t phys_addr;
> + uint64_t virt_addr;
> + uint64_t num_pages;
> + uint64_t attribute;
> +} efi_memory_desc_t;
> +
> +struct efi_boot_memmap {
> + uint64_t map_size;
> + uint64_t desc_size;
> + uint32_t desc_ver;
> + uint64_t map_key;
> + uint64_t buff_size;
> + efi_memory_desc_t map[32];
> +};
> +
> struct loongarch_boot_info {
> uint64_t ram_size;
> const char *kernel_filename;
> diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h
> index d7a074d69f..8a9fe4053d 100644
> --- a/include/hw/loongarch/virt.h
> +++ b/include/hw/loongarch/virt.h
> @@ -35,6 +35,16 @@
>
> #define COMMAND_LINE_SIZE 512
>
> +extern struct memmap_entry *memmap_table;
> +extern unsigned memmap_entries;
> +
> +struct memmap_entry {
> + uint64_t address;
> + uint64_t length;
> + uint32_t type;
> + uint32_t reserved;
> +};
> +
> struct LoongArchMachineState {
> /*< private >*/
> MachineState parent_obj;
>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 07/17] hw/loongarch: Init efi_initrd table
2024-03-07 16:48 ` [PATCH v6 07/17] hw/loongarch: Init efi_initrd table Song Gao
2024-03-08 8:36 ` Philippe Mathieu-Daudé
@ 2024-03-08 8:37 ` maobibo
1 sibling, 0 replies; 46+ messages in thread
From: maobibo @ 2024-03-08 8:37 UTC (permalink / raw)
To: Song Gao, qemu-devel; +Cc: peter.maydell
On 2024/3/8 上午12:48, Song Gao wrote:
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> Message-Id: <20240301093839.663947-8-gaosong@loongson.cn>
> ---
> hw/loongarch/boot.c | 23 +++++++++++++++++++++--
> include/hw/loongarch/boot.h | 9 +++++++++
> 2 files changed, 30 insertions(+), 2 deletions(-)
>
> diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
> index 2896c1ea40..6126a37858 100644
> --- a/hw/loongarch/boot.c
> +++ b/hw/loongarch/boot.c
> @@ -15,6 +15,9 @@
> #include "sysemu/reset.h"
> #include "sysemu/qtest.h"
>
> +ram_addr_t initrd_offset;
> +uint64_t initrd_size;
> +
> static const unsigned int slave_boot_code[] = {
> /* Configure reset ebase. */
> 0x0400302c, /* csrwr $r12,0xc */
> @@ -94,6 +97,21 @@ static void init_efi_boot_memmap(struct efi_system_table *systab,
> }
> }
>
> +static void init_efi_initrd_table(struct efi_system_table *systab,
> + void *p, void *start)
> +{
> + efi_guid_t tbl_guid = LINUX_EFI_INITRD_MEDIA_GUID;
> + struct efi_initrd *initrd_table = p;
> +
> + /* efi_configuration_table 2 */
> + guidcpy(&systab->tables[1].guid, &tbl_guid);
> + systab->tables[1].table = (struct efi_configuration_table *)(p - start);
> + systab->nr_tables = 2;
> +
> + initrd_table->base = initrd_offset;
> + initrd_table->size = initrd_size;
> +}
> +
> static void init_systab(struct loongarch_boot_info *info, void *p, void *start)
> {
> void *bp_tables_start;
> @@ -117,6 +135,8 @@ static void init_systab(struct loongarch_boot_info *info, void *p, void *start)
> init_efi_boot_memmap(systab, p, start);
> p += ROUND_UP(sizeof(struct efi_boot_memmap) +
> sizeof(efi_memory_desc_t) * memmap_entries, 64);
> + init_efi_initrd_table(systab, p, start);
> + p += ROUND_UP(sizeof(struct efi_initrd), 64);
>
> systab->tables = (struct efi_configuration_table *)(bp_tables_start - start);
> }
> @@ -138,8 +158,7 @@ static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
>
> static int64_t load_kernel_info(struct loongarch_boot_info *info)
> {
> - uint64_t kernel_entry, kernel_low, kernel_high, initrd_size;
> - ram_addr_t initrd_offset;
> + uint64_t kernel_entry, kernel_low, kernel_high;
> ssize_t kernel_size;
>
> kernel_size = load_elf(info->kernel_filename, NULL,
> diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h
> index f71c693f43..ddcb279874 100644
> --- a/include/hw/loongarch/boot.h
> +++ b/include/hw/loongarch/boot.h
> @@ -30,6 +30,10 @@ typedef struct {
> EFI_GUID(0x800f683f, 0xd08b, 0x423a, 0xa2, 0x93, \
> 0x96, 0x5c, 0x3c, 0x6f, 0xe2, 0xb4)
>
> +#define LINUX_EFI_INITRD_MEDIA_GUID \
> + EFI_GUID(0x5568e427, 0x68fc, 0x4f3d, 0xac, 0x74, \
> + 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68)
> +
> struct efi_config_table {
> efi_guid_t guid;
> uint64_t *ptr;
> @@ -83,6 +87,11 @@ struct efi_boot_memmap {
> efi_memory_desc_t map[32];
> };
>
> +struct efi_initrd {
> + uint64_t base;
> + uint64_t size;
> +};
> +
> struct loongarch_boot_info {
> uint64_t ram_size;
> const char *kernel_filename;
>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 08/17] hw/loongarch: Init efi_fdt table
2024-03-07 16:48 ` [PATCH v6 08/17] hw/loongarch: Init efi_fdt table Song Gao
@ 2024-03-08 8:39 ` maobibo
0 siblings, 0 replies; 46+ messages in thread
From: maobibo @ 2024-03-08 8:39 UTC (permalink / raw)
To: Song Gao, qemu-devel; +Cc: peter.maydell
On 2024/3/8 上午12:48, Song Gao wrote:
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> Message-Id: <20240301093839.663947-9-gaosong@loongson.cn>
> ---
> hw/loongarch/boot.c | 11 +++++++++++
> include/hw/loongarch/boot.h | 4 ++++
> 2 files changed, 15 insertions(+)
>
> diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
> index 6126a37858..c6c6e6d194 100644
> --- a/hw/loongarch/boot.c
> +++ b/hw/loongarch/boot.c
> @@ -112,6 +112,16 @@ static void init_efi_initrd_table(struct efi_system_table *systab,
> initrd_table->size = initrd_size;
> }
>
> +static void init_efi_fdt_table(struct efi_system_table *systab)
> +{
> + efi_guid_t tbl_guid = DEVICE_TREE_GUID;
> +
> + /* efi_configuration_table 3 */
> + guidcpy(&systab->tables[2].guid, &tbl_guid);
> + systab->tables[2].table = (void *)0x100000; /* fdt_base 1MiB */
Can we use macro for 0x100000?
otherwise LGTM
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
> + systab->nr_tables = 3;
> +}
> +
> static void init_systab(struct loongarch_boot_info *info, void *p, void *start)
> {
> void *bp_tables_start;
> @@ -137,6 +147,7 @@ static void init_systab(struct loongarch_boot_info *info, void *p, void *start)
> sizeof(efi_memory_desc_t) * memmap_entries, 64);
> init_efi_initrd_table(systab, p, start);
> p += ROUND_UP(sizeof(struct efi_initrd), 64);
> + init_efi_fdt_table(systab);
>
> systab->tables = (struct efi_configuration_table *)(bp_tables_start - start);
> }
> diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h
> index ddcb279874..9de673a0fd 100644
> --- a/include/hw/loongarch/boot.h
> +++ b/include/hw/loongarch/boot.h
> @@ -34,6 +34,10 @@ typedef struct {
> EFI_GUID(0x5568e427, 0x68fc, 0x4f3d, 0xac, 0x74, \
> 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68)
>
> +#define DEVICE_TREE_GUID \
> + EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, 0x83, 0x0b, \
> + 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0)
> +
> struct efi_config_table {
> efi_guid_t guid;
> uint64_t *ptr;
>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 09/17] hw/loongarch: Fix fdt memory node wrong 'reg'
2024-03-07 16:48 ` [PATCH v6 09/17] hw/loongarch: Fix fdt memory node wrong 'reg' Song Gao
@ 2024-03-08 8:39 ` maobibo
0 siblings, 0 replies; 46+ messages in thread
From: maobibo @ 2024-03-08 8:39 UTC (permalink / raw)
To: Song Gao, qemu-devel; +Cc: peter.maydell
On 2024/3/8 上午12:48, Song Gao wrote:
> The right fdt memory node like [1], not [2]
>
> [1]
> memory@0 {
> device_type = "memory";
> reg = <0x00 0x00 0x00 0x10000000>;
> };
> [2]
> memory@0 {
> device_type = "memory";
> reg = <0x02 0x00 0x02 0x10000000>;
> };
>
> Reviewed-by: Bibo Mao <maobibo@loongson.cn>
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> Message-Id: <20240301093839.663947-10-gaosong@loongson.cn>
> ---
> hw/loongarch/virt.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
> index 8981b57b12..10fdfec5dd 100644
> --- a/hw/loongarch/virt.c
> +++ b/hw/loongarch/virt.c
> @@ -325,7 +325,7 @@ static void fdt_add_memory_node(MachineState *ms,
> char *nodename = g_strdup_printf("/memory@%" PRIx64, base);
>
> qemu_fdt_add_subnode(ms->fdt, nodename);
> - qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 2, base, 2, size);
> + qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 0, base, 0, size);
> qemu_fdt_setprop_string(ms->fdt, nodename, "device_type", "memory");
>
> if (ms->numa_state && ms->numa_state->num_nodes) {
>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 10/17] hw/loongarch: fdt adds cpu interrupt controller node
2024-03-07 16:48 ` [PATCH v6 10/17] hw/loongarch: fdt adds cpu interrupt controller node Song Gao
@ 2024-03-08 8:40 ` maobibo
0 siblings, 0 replies; 46+ messages in thread
From: maobibo @ 2024-03-08 8:40 UTC (permalink / raw)
To: Song Gao, qemu-devel; +Cc: peter.maydell
On 2024/3/8 上午12:48, Song Gao wrote:
> fdt adds cpu interrupt controller node,
> we use 'loongson,cpu-interrupt-controller'.
>
> See:
> https://github.com/torvalds/linux/blob/v6.7/drivers/irqchip/irq-loongarch-cpu.c
> https://lore.kernel.org/r/20221114113824.1880-2-liupeibao@loongson.cn
>
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> Message-Id: <20240301093839.663947-11-gaosong@loongson.cn>
> ---
> hw/loongarch/virt.c | 21 +++++++++++++++++++++
> 1 file changed, 21 insertions(+)
>
> diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
> index 10fdfec5dd..d260f933a5 100644
> --- a/hw/loongarch/virt.c
> +++ b/hw/loongarch/virt.c
> @@ -106,6 +106,23 @@ static void virt_flash_map(LoongArchMachineState *lams,
> virt_flash_map1(flash1, VIRT_FLASH1_BASE, VIRT_FLASH1_SIZE, sysmem);
> }
>
> +static void fdt_add_cpuic_node(LoongArchMachineState *lams,
> + uint32_t *cpuintc_phandle)
> +{
> + MachineState *ms = MACHINE(lams);
> + char *nodename;
> +
> + *cpuintc_phandle = qemu_fdt_alloc_phandle(ms->fdt);
> + nodename = g_strdup_printf("/cpuic");
> + qemu_fdt_add_subnode(ms->fdt, nodename);
> + qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle", *cpuintc_phandle);
> + qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
> + "loongson,cpu-interrupt-controller");
> + qemu_fdt_setprop(ms->fdt, nodename, "interrupt-controller", NULL, 0);
> + qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 1);
> + g_free(nodename);
> +}
> +
> static void fdt_add_flash_node(LoongArchMachineState *lams)
> {
> MachineState *ms = MACHINE(lams);
> @@ -527,6 +544,7 @@ static void loongarch_irq_init(LoongArchMachineState *lams)
> CPULoongArchState *env;
> CPUState *cpu_state;
> int cpu, pin, i, start, num;
> + uint32_t cpuintc_phandle;
>
> /*
> * The connection of interrupts:
> @@ -561,6 +579,9 @@ static void loongarch_irq_init(LoongArchMachineState *lams)
> memory_region_add_subregion(&lams->system_iocsr, MAIL_SEND_ADDR,
> sysbus_mmio_get_region(SYS_BUS_DEVICE(ipi), 1));
>
> + /* Add cpu interrupt-controller */
> + fdt_add_cpuic_node(lams, &cpuintc_phandle);
> +
> for (cpu = 0; cpu < ms->smp.cpus; cpu++) {
> cpu_state = qemu_get_cpu(cpu);
> cpudev = DEVICE(cpu_state);
>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 11/17] hw/loongarch: fdt adds Extend I/O Interrupt Controller
2024-03-07 16:48 ` [PATCH v6 11/17] hw/loongarch: fdt adds Extend I/O Interrupt Controller Song Gao
@ 2024-03-08 8:40 ` maobibo
0 siblings, 0 replies; 46+ messages in thread
From: maobibo @ 2024-03-08 8:40 UTC (permalink / raw)
To: Song Gao, qemu-devel; +Cc: peter.maydell
On 2024/3/8 上午12:48, Song Gao wrote:
> fdt adds Extend I/O Interrupt Controller,
> we use 'loongson,ls2k2000-eiointc'.
>
> See:
> https://github.com/torvalds/linux/blob/v6.7/drivers/irqchip/irq-loongson-eiointc.c
> https://lore.kernel.org/r/764e02d924094580ac0f1d15535f4b98308705c6.1683279769.git.zhoubinbin@loongson.cn
>
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> Message-Id: <20240301093839.663947-12-gaosong@loongson.cn>
> ---
> hw/loongarch/virt.c | 30 +++++++++++++++++++++++++++++-
> include/hw/intc/loongarch_extioi.h | 1 +
> 2 files changed, 30 insertions(+), 1 deletion(-)
>
> diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
> index d260f933a5..822f070c45 100644
> --- a/hw/loongarch/virt.c
> +++ b/hw/loongarch/virt.c
> @@ -123,6 +123,31 @@ static void fdt_add_cpuic_node(LoongArchMachineState *lams,
> g_free(nodename);
> }
>
> +static void fdt_add_eiointc_node(LoongArchMachineState *lams,
> + uint32_t *cpuintc_phandle,
> + uint32_t *eiointc_phandle)
> +{
> + MachineState *ms = MACHINE(lams);
> + char *nodename;
> + hwaddr extioi_base = APIC_BASE;
> + hwaddr extioi_size = EXTIOI_SIZE;
> +
> + *eiointc_phandle = qemu_fdt_alloc_phandle(ms->fdt);
> + nodename = g_strdup_printf("/eiointc@%" PRIx64, extioi_base);
> + qemu_fdt_add_subnode(ms->fdt, nodename);
> + qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle", *eiointc_phandle);
> + qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
> + "loongson,ls2k2000-eiointc");
> + qemu_fdt_setprop(ms->fdt, nodename, "interrupt-controller", NULL, 0);
> + qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 1);
> + qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
> + *cpuintc_phandle);
> + qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupts", 3);
> + qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 0x0,
> + extioi_base, 0x0, extioi_size);
> + g_free(nodename);
> +}
> +
> static void fdt_add_flash_node(LoongArchMachineState *lams)
> {
> MachineState *ms = MACHINE(lams);
> @@ -544,7 +569,7 @@ static void loongarch_irq_init(LoongArchMachineState *lams)
> CPULoongArchState *env;
> CPUState *cpu_state;
> int cpu, pin, i, start, num;
> - uint32_t cpuintc_phandle;
> + uint32_t cpuintc_phandle, eiointc_phandle;
>
> /*
> * The connection of interrupts:
> @@ -613,6 +638,9 @@ static void loongarch_irq_init(LoongArchMachineState *lams)
> }
> }
>
> + /* Add Extend I/O Interrupt Controller node */
> + fdt_add_eiointc_node(lams, &cpuintc_phandle, &eiointc_phandle);
> +
> pch_pic = qdev_new(TYPE_LOONGARCH_PCH_PIC);
> num = VIRT_PCH_PIC_IRQ_NUM;
> qdev_prop_set_uint32(pch_pic, "pch_pic_irq_num", num);
> diff --git a/include/hw/intc/loongarch_extioi.h b/include/hw/intc/loongarch_extioi.h
> index a0a46b888c..410c6e1121 100644
> --- a/include/hw/intc/loongarch_extioi.h
> +++ b/include/hw/intc/loongarch_extioi.h
> @@ -39,6 +39,7 @@
> #define EXTIOI_COREISR_END (0xB20 - APIC_OFFSET)
> #define EXTIOI_COREMAP_START (0xC00 - APIC_OFFSET)
> #define EXTIOI_COREMAP_END (0xD00 - APIC_OFFSET)
> +#define EXTIOI_SIZE 0x800
>
> typedef struct ExtIOICore {
> uint32_t coreisr[EXTIOI_IRQS_GROUP_COUNT];
>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 12/17] hw/loongarch: fdt adds pch_pic Controller
2024-03-07 16:48 ` [PATCH v6 12/17] hw/loongarch: fdt adds pch_pic Controller Song Gao
@ 2024-03-08 8:41 ` maobibo
0 siblings, 0 replies; 46+ messages in thread
From: maobibo @ 2024-03-08 8:41 UTC (permalink / raw)
To: Song Gao, qemu-devel; +Cc: peter.maydell
On 2024/3/8 上午12:48, Song Gao wrote:
> fdt adds pch pic controller, we use 'loongson,pch-pic-1.0'
>
> See:
> https://github.com/torvalds/linux/blob/v6.7/drivers/irqchip/irq-loongson-pch-pic.c
> https://lore.kernel.org/r/20200528152757.1028711-4-jiaxun.yang@flygoat.com
>
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> Message-Id: <20240301093839.663947-13-gaosong@loongson.cn>
> ---
> hw/loongarch/virt.c | 30 +++++++++++++++++++++++++++++-
> include/hw/pci-host/ls7a.h | 1 +
> 2 files changed, 30 insertions(+), 1 deletion(-)
>
> diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
> index 822f070c45..2b7b653fc1 100644
> --- a/hw/loongarch/virt.c
> +++ b/hw/loongarch/virt.c
> @@ -148,6 +148,31 @@ static void fdt_add_eiointc_node(LoongArchMachineState *lams,
> g_free(nodename);
> }
>
> +static void fdt_add_pch_pic_node(LoongArchMachineState *lams,
> + uint32_t *eiointc_phandle,
> + uint32_t *pch_pic_phandle)
> +{
> + MachineState *ms = MACHINE(lams);
> + char *nodename;
> + hwaddr pch_pic_base = VIRT_PCH_REG_BASE;
> + hwaddr pch_pic_size = VIRT_PCH_REG_SIZE;
> +
> + *pch_pic_phandle = qemu_fdt_alloc_phandle(ms->fdt);
> + nodename = g_strdup_printf("/platic@%" PRIx64, pch_pic_base);
> + qemu_fdt_add_subnode(ms->fdt, nodename);
> + qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle", *pch_pic_phandle);
> + qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
> + "loongson,pch-pic-1.0");
> + qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 0,
> + pch_pic_base, 0, pch_pic_size);
> + qemu_fdt_setprop(ms->fdt, nodename, "interrupt-controller", NULL, 0);
> + qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 2);
> + qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
> + *eiointc_phandle);
> + qemu_fdt_setprop_cell(ms->fdt, nodename, "loongson,pic-base-vec", 0);
> + g_free(nodename);
> +}
> +
> static void fdt_add_flash_node(LoongArchMachineState *lams)
> {
> MachineState *ms = MACHINE(lams);
> @@ -569,7 +594,7 @@ static void loongarch_irq_init(LoongArchMachineState *lams)
> CPULoongArchState *env;
> CPUState *cpu_state;
> int cpu, pin, i, start, num;
> - uint32_t cpuintc_phandle, eiointc_phandle;
> + uint32_t cpuintc_phandle, eiointc_phandle, pch_pic_phandle;
>
> /*
> * The connection of interrupts:
> @@ -660,6 +685,9 @@ static void loongarch_irq_init(LoongArchMachineState *lams)
> qdev_connect_gpio_out(DEVICE(d), i, qdev_get_gpio_in(extioi, i));
> }
>
> + /* Add PCH PIC node */
> + fdt_add_pch_pic_node(lams, &eiointc_phandle, &pch_pic_phandle);
> +
> pch_msi = qdev_new(TYPE_LOONGARCH_PCH_MSI);
> start = num;
> num = EXTIOI_IRQS - start;
> diff --git a/include/hw/pci-host/ls7a.h b/include/hw/pci-host/ls7a.h
> index e753449593..fe260f0183 100644
> --- a/include/hw/pci-host/ls7a.h
> +++ b/include/hw/pci-host/ls7a.h
> @@ -24,6 +24,7 @@
> #define VIRT_PCH_REG_BASE 0x10000000UL
> #define VIRT_IOAPIC_REG_BASE (VIRT_PCH_REG_BASE)
> #define VIRT_PCH_MSI_ADDR_LOW 0x2FF00000UL
> +#define VIRT_PCH_REG_SIZE 0x400
>
> /*
> * GSI_BASE is hard-coded with 64 in linux kernel, else kernel fails to boot
>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 13/17] hw/loongarch: fdt adds pch_msi Controller
2024-03-07 16:48 ` [PATCH v6 13/17] hw/loongarch: fdt adds pch_msi Controller Song Gao
@ 2024-03-08 8:41 ` maobibo
0 siblings, 0 replies; 46+ messages in thread
From: maobibo @ 2024-03-08 8:41 UTC (permalink / raw)
To: Song Gao, qemu-devel; +Cc: peter.maydell
On 2024/3/8 上午12:48, Song Gao wrote:
> fdt adds pch msi controller, we use 'loongson,pch-msi-1.0'.
>
> See:
> https://github.com/torvalds/linux/blob/v6.7/drivers/irqchip/irq-loongson-pch-msi.c
> https://lore.kernel.org/r/20200528152757.1028711-6-jiaxun.yang@flygoat.com
>
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> Message-Id: <20240301093839.663947-14-gaosong@loongson.cn>
> ---
> hw/loongarch/virt.c | 33 ++++++++++++++++++++++++++++++++-
> include/hw/pci-host/ls7a.h | 1 +
> 2 files changed, 33 insertions(+), 1 deletion(-)
>
> diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
> index 2b7b653fc1..1e767c49f8 100644
> --- a/hw/loongarch/virt.c
> +++ b/hw/loongarch/virt.c
> @@ -173,6 +173,34 @@ static void fdt_add_pch_pic_node(LoongArchMachineState *lams,
> g_free(nodename);
> }
>
> +static void fdt_add_pch_msi_node(LoongArchMachineState *lams,
> + uint32_t *eiointc_phandle,
> + uint32_t *pch_msi_phandle)
> +{
> + MachineState *ms = MACHINE(lams);
> + char *nodename;
> + hwaddr pch_msi_base = VIRT_PCH_MSI_ADDR_LOW;
> + hwaddr pch_msi_size = VIRT_PCH_MSI_SIZE;
> +
> + *pch_msi_phandle = qemu_fdt_alloc_phandle(ms->fdt);
> + nodename = g_strdup_printf("/msi@%" PRIx64, pch_msi_base);
> + qemu_fdt_add_subnode(ms->fdt, nodename);
> + qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle", *pch_msi_phandle);
> + qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
> + "loongson,pch-msi-1.0");
> + qemu_fdt_setprop_cells(ms->fdt, nodename, "reg",
> + 0, pch_msi_base,
> + 0, pch_msi_size);
> + qemu_fdt_setprop(ms->fdt, nodename, "interrupt-controller", NULL, 0);
> + qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
> + *eiointc_phandle);
> + qemu_fdt_setprop_cell(ms->fdt, nodename, "loongson,msi-base-vec",
> + VIRT_PCH_PIC_IRQ_NUM);
> + qemu_fdt_setprop_cell(ms->fdt, nodename, "loongson,msi-num-vecs",
> + EXTIOI_IRQS - VIRT_PCH_PIC_IRQ_NUM);
> + g_free(nodename);
> +}
> +
> static void fdt_add_flash_node(LoongArchMachineState *lams)
> {
> MachineState *ms = MACHINE(lams);
> @@ -594,7 +622,7 @@ static void loongarch_irq_init(LoongArchMachineState *lams)
> CPULoongArchState *env;
> CPUState *cpu_state;
> int cpu, pin, i, start, num;
> - uint32_t cpuintc_phandle, eiointc_phandle, pch_pic_phandle;
> + uint32_t cpuintc_phandle, eiointc_phandle, pch_pic_phandle, pch_msi_phandle;
>
> /*
> * The connection of interrupts:
> @@ -702,6 +730,9 @@ static void loongarch_irq_init(LoongArchMachineState *lams)
> qdev_get_gpio_in(extioi, i + start));
> }
>
> + /* Add PCH MSI node */
> + fdt_add_pch_msi_node(lams, &eiointc_phandle, &pch_msi_phandle);
> +
> loongarch_devices_init(pch_pic, lams);
> }
>
> diff --git a/include/hw/pci-host/ls7a.h b/include/hw/pci-host/ls7a.h
> index fe260f0183..cd7c9ec7bc 100644
> --- a/include/hw/pci-host/ls7a.h
> +++ b/include/hw/pci-host/ls7a.h
> @@ -25,6 +25,7 @@
> #define VIRT_IOAPIC_REG_BASE (VIRT_PCH_REG_BASE)
> #define VIRT_PCH_MSI_ADDR_LOW 0x2FF00000UL
> #define VIRT_PCH_REG_SIZE 0x400
> +#define VIRT_PCH_MSI_SIZE 0x8
>
> /*
> * GSI_BASE is hard-coded with 64 in linux kernel, else kernel fails to boot
>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 14/17] hw/loongarch: fdt adds pcie irq_map node
2024-03-07 16:48 ` [PATCH v6 14/17] hw/loongarch: fdt adds pcie irq_map node Song Gao
@ 2024-03-08 8:44 ` maobibo
0 siblings, 0 replies; 46+ messages in thread
From: maobibo @ 2024-03-08 8:44 UTC (permalink / raw)
To: Song Gao, qemu-devel; +Cc: peter.maydell
On 2024/3/8 上午12:48, Song Gao wrote:
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> Message-Id: <20240301093839.663947-15-gaosong@loongson.cn>
> ---
> hw/loongarch/virt.c | 73 ++++++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 69 insertions(+), 4 deletions(-)
>
> diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
> index 1e767c49f8..d00343f0c2 100644
> --- a/hw/loongarch/virt.c
> +++ b/hw/loongarch/virt.c
> @@ -352,7 +352,62 @@ static void fdt_add_fw_cfg_node(const LoongArchMachineState *lams)
> g_free(nodename);
> }
>
> -static void fdt_add_pcie_node(const LoongArchMachineState *lams)
> +static void fdt_add_pcie_irq_map_node(const LoongArchMachineState *lams,
> + char *nodename,
> + uint32_t *pch_pic_phandle)
> +{
> + int pin, dev;
> + uint32_t irq_map_stride = 0;
> + uint32_t full_irq_map[GPEX_NUM_IRQS *GPEX_NUM_IRQS * 10] = {};
> + uint32_t *irq_map = full_irq_map;
> + const MachineState *ms = MACHINE(lams);
> +
> + /* This code creates a standard swizzle of interrupts such that
> + * each device's first interrupt is based on it's PCI_SLOT number.
> + * (See pci_swizzle_map_irq_fn())
> + *
> + * We only need one entry per interrupt in the table (not one per
> + * possible slot) seeing the interrupt-map-mask will allow the table
> + * to wrap to any number of devices.
> + */
> +
> + for (dev = 0; dev < GPEX_NUM_IRQS; dev++) {
> + int devfn = dev * 0x8;
> +
> + for (pin = 0; pin < GPEX_NUM_IRQS; pin++) {
> + int irq_nr = 16 + ((pin + PCI_SLOT(devfn)) % GPEX_NUM_IRQS);
> + int i = 0;
> +
> + /* Fill PCI address cells */
> + irq_map[i] = cpu_to_be32(devfn << 8);
> + i += 3;
> +
> + /* Fill PCI Interrupt cells */
> + irq_map[i] = cpu_to_be32(pin + 1);
> + i += 1;
> +
> + /* Fill interrupt controller phandle and cells */
> + irq_map[i++] = cpu_to_be32(*pch_pic_phandle);
> + irq_map[i++] = cpu_to_be32(irq_nr);
> +
> + if (!irq_map_stride) {
> + irq_map_stride = i;
> + }
> + irq_map += irq_map_stride;
> + }
> + }
> +
> +
> + qemu_fdt_setprop(ms->fdt, nodename, "interrupt-map", full_irq_map,
> + GPEX_NUM_IRQS * GPEX_NUM_IRQS *
> + irq_map_stride * sizeof(uint32_t));
> + qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupt-map-mask",
> + 0x1800, 0, 0, 0x7);
> +}
> +
> +static void fdt_add_pcie_node(const LoongArchMachineState *lams,
> + uint32_t *pch_pic_phandle,
> + uint32_t *pch_msi_phandle)
> {
> char *nodename;
> hwaddr base_mmio = VIRT_PCI_MEM_BASE;
> @@ -383,6 +438,11 @@ static void fdt_add_pcie_node(const LoongArchMachineState *lams)
> 2, base_pio, 2, size_pio,
> 1, FDT_PCI_RANGE_MMIO, 2, base_mmio,
> 2, base_mmio, 2, size_mmio);
> + qemu_fdt_setprop_cells(ms->fdt, nodename, "msi-map",
> + 0, *pch_msi_phandle, 0, 0x10000);
> +
> + fdt_add_pcie_irq_map_node(lams, nodename, pch_pic_phandle);
> +
> g_free(nodename);
> }
>
> @@ -541,7 +601,10 @@ static DeviceState *create_platform_bus(DeviceState *pch_pic)
> return dev;
> }
>
> -static void loongarch_devices_init(DeviceState *pch_pic, LoongArchMachineState *lams)
> +static void loongarch_devices_init(DeviceState *pch_pic,
> + LoongArchMachineState *lams,
> + uint32_t *pch_pic_phandle,
> + uint32_t *pch_msi_phandle)
> {
> MachineClass *mc = MACHINE_GET_CLASS(lams);
> DeviceState *gpex_dev;
> @@ -587,6 +650,9 @@ static void loongarch_devices_init(DeviceState *pch_pic, LoongArchMachineState *
> gpex_set_irq_num(GPEX_HOST(gpex_dev), i, 16 + i);
> }
>
> + /* Add pcie node */
> + fdt_add_pcie_node(lams, pch_pic_phandle, pch_msi_phandle);
> +
> serial_mm_init(get_system_memory(), VIRT_UART_BASE, 0,
> qdev_get_gpio_in(pch_pic,
> VIRT_UART_IRQ - VIRT_GSI_BASE),
> @@ -733,7 +799,7 @@ static void loongarch_irq_init(LoongArchMachineState *lams)
> /* Add PCH MSI node */
> fdt_add_pch_msi_node(lams, &eiointc_phandle, &pch_msi_phandle);
>
> - loongarch_devices_init(pch_pic, lams);
> + loongarch_devices_init(pch_pic, lams, &pch_pic_phandle, &pch_msi_phandle);
> }
>
> static void loongarch_firmware_init(LoongArchMachineState *lams)
> @@ -956,7 +1022,6 @@ static void loongarch_init(MachineState *machine)
> lams->powerdown_notifier.notify = virt_powerdown_req;
> qemu_register_powerdown_notifier(&lams->powerdown_notifier);
>
> - fdt_add_pcie_node(lams);
> /*
> * Since lowmem region starts from 0 and Linux kernel legacy start address
> * at 2 MiB, FDT base address is located at 1 MiB to avoid NULL pointer
>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 15/17] hw/loongarch: fdt remove unused irqchip node
2024-03-07 16:48 ` [PATCH v6 15/17] hw/loongarch: fdt remove unused irqchip node Song Gao
@ 2024-03-08 8:44 ` maobibo
0 siblings, 0 replies; 46+ messages in thread
From: maobibo @ 2024-03-08 8:44 UTC (permalink / raw)
To: Song Gao, qemu-devel; +Cc: peter.maydell
On 2024/3/8 上午12:48, Song Gao wrote:
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> Message-Id: <20240301093839.663947-16-gaosong@loongson.cn>
> ---
> hw/loongarch/virt.c | 31 +------------------------------
> 1 file changed, 1 insertion(+), 30 deletions(-)
>
> diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
> index d00343f0c2..c80732a223 100644
> --- a/hw/loongarch/virt.c
> +++ b/hw/loongarch/virt.c
> @@ -446,34 +446,6 @@ static void fdt_add_pcie_node(const LoongArchMachineState *lams,
> g_free(nodename);
> }
>
> -static void fdt_add_irqchip_node(LoongArchMachineState *lams)
> -{
> - MachineState *ms = MACHINE(lams);
> - char *nodename;
> - uint32_t irqchip_phandle;
> -
> - irqchip_phandle = qemu_fdt_alloc_phandle(ms->fdt);
> - qemu_fdt_setprop_cell(ms->fdt, "/", "interrupt-parent", irqchip_phandle);
> -
> - nodename = g_strdup_printf("/intc@%lx", VIRT_IOAPIC_REG_BASE);
> - qemu_fdt_add_subnode(ms->fdt, nodename);
> - qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 3);
> - qemu_fdt_setprop(ms->fdt, nodename, "interrupt-controller", NULL, 0);
> - qemu_fdt_setprop_cell(ms->fdt, nodename, "#address-cells", 0x2);
> - qemu_fdt_setprop_cell(ms->fdt, nodename, "#size-cells", 0x2);
> - qemu_fdt_setprop(ms->fdt, nodename, "ranges", NULL, 0);
> -
> - qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
> - "loongarch,ls7a");
> -
> - qemu_fdt_setprop_sized_cells(ms->fdt, nodename, "reg",
> - 2, VIRT_IOAPIC_REG_BASE,
> - 2, PCH_PIC_ROUTE_ENTRY_OFFSET);
> -
> - qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle", irqchip_phandle);
> - g_free(nodename);
> -}
> -
> static void fdt_add_memory_node(MachineState *ms,
> uint64_t base, uint64_t size, int node_id)
> {
> @@ -1011,8 +983,7 @@ static void loongarch_init(MachineState *machine)
>
> /* Initialize the IO interrupt subsystem */
> loongarch_irq_init(lams);
> - fdt_add_irqchip_node(lams);
> - platform_bus_add_all_fdt_nodes(machine->fdt, "/intc",
> + platform_bus_add_all_fdt_nodes(machine->fdt, "/platic",
> VIRT_PLATFORM_BUS_BASEADDRESS,
> VIRT_PLATFORM_BUS_SIZE,
> VIRT_PLATFORM_BUS_IRQ);
>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 16/17] hw/loongarch: Add cells missing from uart node
2024-03-07 16:48 ` [PATCH v6 16/17] hw/loongarch: Add cells missing from uart node Song Gao
@ 2024-03-08 8:44 ` maobibo
0 siblings, 0 replies; 46+ messages in thread
From: maobibo @ 2024-03-08 8:44 UTC (permalink / raw)
To: Song Gao, qemu-devel; +Cc: peter.maydell
On 2024/3/8 上午12:48, Song Gao wrote:
> uart node need interrupts and interrupt-parent cells.
>
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> Message-Id: <20240301093839.663947-17-gaosong@loongson.cn>
> ---
> hw/loongarch/virt.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
> index c80732a223..58957a8d9a 100644
> --- a/hw/loongarch/virt.c
> +++ b/hw/loongarch/virt.c
> @@ -245,7 +245,8 @@ static void fdt_add_rtc_node(LoongArchMachineState *lams)
> g_free(nodename);
> }
>
> -static void fdt_add_uart_node(LoongArchMachineState *lams)
> +static void fdt_add_uart_node(LoongArchMachineState *lams,
> + uint32_t *pch_pic_phandle)
> {
> char *nodename;
> hwaddr base = VIRT_UART_BASE;
> @@ -258,6 +259,10 @@ static void fdt_add_uart_node(LoongArchMachineState *lams)
> qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 0x0, base, 0x0, size);
> qemu_fdt_setprop_cell(ms->fdt, nodename, "clock-frequency", 100000000);
> qemu_fdt_setprop_string(ms->fdt, "/chosen", "stdout-path", nodename);
> + qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts",
> + VIRT_UART_IRQ - VIRT_GSI_BASE, 0x4);
> + qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
> + *pch_pic_phandle);
> g_free(nodename);
> }
>
> @@ -629,7 +634,7 @@ static void loongarch_devices_init(DeviceState *pch_pic,
> qdev_get_gpio_in(pch_pic,
> VIRT_UART_IRQ - VIRT_GSI_BASE),
> 115200, serial_hd(0), DEVICE_LITTLE_ENDIAN);
> - fdt_add_uart_node(lams);
> + fdt_add_uart_node(lams, pch_pic_phandle);
>
> /* Network init */
> pci_init_nic_devices(pci_bus, mc->default_nic);
>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 17/17] hw/loongarch: Add cells missing from rtc node
2024-03-07 16:48 ` [PATCH v6 17/17] hw/loongarch: Add cells missing from rtc node Song Gao
@ 2024-03-08 8:45 ` maobibo
0 siblings, 0 replies; 46+ messages in thread
From: maobibo @ 2024-03-08 8:45 UTC (permalink / raw)
To: Song Gao, qemu-devel; +Cc: peter.maydell
On 2024/3/8 上午12:48, Song Gao wrote:
> rtc node need interrupts and interrupt-parent cells.
>
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> Message-Id: <20240301093839.663947-18-gaosong@loongson.cn>
> ---
> hw/loongarch/virt.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
> index 58957a8d9a..676f1f5227 100644
> --- a/hw/loongarch/virt.c
> +++ b/hw/loongarch/virt.c
> @@ -231,7 +231,8 @@ static void fdt_add_flash_node(LoongArchMachineState *lams)
> g_free(nodename);
> }
>
> -static void fdt_add_rtc_node(LoongArchMachineState *lams)
> +static void fdt_add_rtc_node(LoongArchMachineState *lams,
> + uint32_t *pch_pic_phandle)
> {
> char *nodename;
> hwaddr base = VIRT_RTC_REG_BASE;
> @@ -240,8 +241,13 @@ static void fdt_add_rtc_node(LoongArchMachineState *lams)
>
> nodename = g_strdup_printf("/rtc@%" PRIx64, base);
> qemu_fdt_add_subnode(ms->fdt, nodename);
> - qemu_fdt_setprop_string(ms->fdt, nodename, "compatible", "loongson,ls7a-rtc");
> + qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
> + "loongson,ls7a-rtc");
> qemu_fdt_setprop_sized_cells(ms->fdt, nodename, "reg", 2, base, 2, size);
> + qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts",
> + VIRT_RTC_IRQ - VIRT_GSI_BASE , 0x4);
> + qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
> + *pch_pic_phandle);
> g_free(nodename);
> }
>
> @@ -647,7 +653,7 @@ static void loongarch_devices_init(DeviceState *pch_pic,
> sysbus_create_simple("ls7a_rtc", VIRT_RTC_REG_BASE,
> qdev_get_gpio_in(pch_pic,
> VIRT_RTC_IRQ - VIRT_GSI_BASE));
> - fdt_add_rtc_node(lams);
> + fdt_add_rtc_node(lams, pch_pic_phandle);
>
> /* acpi ged */
> lams->acpi_ged = create_acpi_ged(pch_pic, lams);
>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 07/17] hw/loongarch: Init efi_initrd table
2024-03-08 8:36 ` Philippe Mathieu-Daudé
@ 2024-03-08 9:20 ` gaosong
0 siblings, 0 replies; 46+ messages in thread
From: gaosong @ 2024-03-08 9:20 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel; +Cc: peter.maydell, maobibo
在 2024/3/8 16:36, Philippe Mathieu-Daudé 写道:
> Hi Song,
>
> On 7/3/24 17:48, Song Gao wrote:
>> Signed-off-by: Song Gao <gaosong@loongson.cn>
>> Message-Id: <20240301093839.663947-8-gaosong@loongson.cn>
>> ---
>> hw/loongarch/boot.c | 23 +++++++++++++++++++++--
>> include/hw/loongarch/boot.h | 9 +++++++++
>> 2 files changed, 30 insertions(+), 2 deletions(-)
>>
>> diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
>> index 2896c1ea40..6126a37858 100644
>> --- a/hw/loongarch/boot.c
>> +++ b/hw/loongarch/boot.c
>> @@ -15,6 +15,9 @@
>> #include "sysemu/reset.h"
>> #include "sysemu/qtest.h"
>> +ram_addr_t initrd_offset;
>> +uint64_t initrd_size;
>
> Where is that used?
>
patch1 load_kernel_info() and patch7 init_efi_initrd_table()
Thanks.
Song Gao
>> static const unsigned int slave_boot_code[] = {
>> /* Configure reset ebase. */
>> 0x0400302c, /* csrwr $r12,0xc */
>> @@ -94,6 +97,21 @@ static void init_efi_boot_memmap(struct
>> efi_system_table *systab,
>> }
>> }
>> +static void init_efi_initrd_table(struct efi_system_table *systab,
>> + void *p, void *start)
>> +{
>> + efi_guid_t tbl_guid = LINUX_EFI_INITRD_MEDIA_GUID;
>> + struct efi_initrd *initrd_table = p;
>> +
>> + /* efi_configuration_table 2 */
>> + guidcpy(&systab->tables[1].guid, &tbl_guid);
>> + systab->tables[1].table = (struct efi_configuration_table *)(p -
>> start);
>> + systab->nr_tables = 2;
>> +
>> + initrd_table->base = initrd_offset;
>> + initrd_table->size = initrd_size;
>> +}
>> +
>> static void init_systab(struct loongarch_boot_info *info, void *p,
>> void *start)
>> {
>> void *bp_tables_start;
>> @@ -117,6 +135,8 @@ static void init_systab(struct loongarch_boot_info
>> *info, void *p, void *start)
>> init_efi_boot_memmap(systab, p, start);
>> p += ROUND_UP(sizeof(struct efi_boot_memmap) +
>> sizeof(efi_memory_desc_t) * memmap_entries, 64);
>> + init_efi_initrd_table(systab, p, start);
>> + p += ROUND_UP(sizeof(struct efi_initrd), 64);
>> systab->tables = (struct efi_configuration_table
>> *)(bp_tables_start - start);
>> }
>> @@ -138,8 +158,7 @@ static uint64_t cpu_loongarch_virt_to_phys(void
>> *opaque, uint64_t addr)
>> static int64_t load_kernel_info(struct loongarch_boot_info *info)
>> {
>> - uint64_t kernel_entry, kernel_low, kernel_high, initrd_size;
>> - ram_addr_t initrd_offset;
>> + uint64_t kernel_entry, kernel_low, kernel_high;
>> ssize_t kernel_size;
>> kernel_size = load_elf(info->kernel_filename, NULL,
>> diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h
>> index f71c693f43..ddcb279874 100644
>> --- a/include/hw/loongarch/boot.h
>> +++ b/include/hw/loongarch/boot.h
>> @@ -30,6 +30,10 @@ typedef struct {
>> EFI_GUID(0x800f683f, 0xd08b, 0x423a, 0xa2, 0x93, \
>> 0x96, 0x5c, 0x3c, 0x6f, 0xe2, 0xb4)
>> +#define LINUX_EFI_INITRD_MEDIA_GUID \
>> + EFI_GUID(0x5568e427, 0x68fc, 0x4f3d, 0xac, 0x74, \
>> + 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68)
>> +
>> struct efi_config_table {
>> efi_guid_t guid;
>> uint64_t *ptr;
>> @@ -83,6 +87,11 @@ struct efi_boot_memmap {
>> efi_memory_desc_t map[32];
>> };
>> +struct efi_initrd {
>> + uint64_t base;
>> + uint64_t size;
>> +};
>> +
>> struct loongarch_boot_info {
>> uint64_t ram_size;
>> const char *kernel_filename;
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 03/17] hw/loongarch: Add slave cpu boot_code
2024-03-08 8:27 ` maobibo
@ 2024-03-08 9:36 ` gaosong
2024-03-11 6:50 ` maobibo
0 siblings, 1 reply; 46+ messages in thread
From: gaosong @ 2024-03-08 9:36 UTC (permalink / raw)
To: maobibo, qemu-devel; +Cc: peter.maydell
在 2024/3/8 16:27, maobibo 写道:
>
>
> On 2024/3/8 上午12:48, Song Gao wrote:
>> Signed-off-by: Song Gao <gaosong@loongson.cn>
>> Message-Id: <20240301093839.663947-4-gaosong@loongson.cn>
>> ---
>> hw/loongarch/boot.c | 70 ++++++++++++++++++++++++++++++++++++++++++++-
>> 1 file changed, 69 insertions(+), 1 deletion(-)
>>
>> diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
>> index 149deb2e01..e560ac178a 100644
>> --- a/hw/loongarch/boot.c
>> +++ b/hw/loongarch/boot.c
>> @@ -15,6 +15,54 @@
>> #include "sysemu/reset.h"
>> #include "sysemu/qtest.h"
>> +static const unsigned int slave_boot_code[] = {
>> + /* Configure reset ebase. */
>> + 0x0400302c, /* csrwr $r12,0xc */
>> +
>> + /* Disable interrupt. */
>> + 0x0380100c, /* ori $r12,$r0,0x4 */
>> + 0x04000180, /* csrxchg $r0,$r12,0x0 */
>> +
>> + /* Clear mailbox. */
>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>> + 0x038081ad, /* ori $r13,$r13,0x20 */
>> + 0x06481da0, /* iocsrwr.d $r0,$r13 */
>> +
>> + /* Enable IPI interrupt. */
>> + 0x1400002c, /* lu12i.w $r12,1(0x1) */
>> + 0x0400118c, /* csrxchg $r12,$r12,0x4 */
>> + 0x02fffc0c, /* addi.d $r12,$r0,-1(0xfff) */
>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>> + 0x038011ad, /* ori $r13,$r13,0x4 */
>> + 0x064819ac, /* iocsrwr.w $r12,$r13 */
>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>> + 0x038081ad, /* ori $r13,$r13,0x20 */
>> +
>> + /* Wait for wakeup <.L11>: */
>> + 0x06488000, /* idle 0x0 */
>> + 0x03400000, /* andi $r0,$r0,0x0 */
>> + 0x064809ac, /* iocsrrd.w $r12,$r13 */
>> + 0x43fff59f, /* beqz $r12,-12(0x7ffff4) # 48 <.L11> */
>> +
>> + /* Read and clear IPI interrupt. */
>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>> + 0x064809ac, /* iocsrrd.w $r12,$r13 */
>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>> + 0x038031ad, /* ori $r13,$r13,0xc */
>> + 0x064819ac, /* iocsrwr.w $r12,$r13 */
>> +
>> + /* Disable IPI interrupt. */
>> + 0x1400002c, /* lu12i.w $r12,1(0x1) */
>> + 0x04001180, /* csrxchg $r0,$r12,0x4 */
>> +
>> + /* Read mail buf and jump to specified entry */
>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>> + 0x038081ad, /* ori $r13,$r13,0x20 */
>> + 0x06480dac, /* iocsrrd.d $r12,$r13 */
>> + 0x00150181, /* move $r1,$r12 */
>> + 0x4c000020, /* jirl $r0,$r1,0 */
>> +};
>> +
>> static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
>> {
>> return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
>> @@ -111,8 +159,15 @@ static void
>> loongarch_firmware_boot(LoongArchMachineState *lams,
>> fw_cfg_add_kernel_info(info, lams->fw_cfg);
>> }
>> +static void init_boot_rom(struct loongarch_boot_info *info, void *p)
>> +{
>> + memcpy(p, &slave_boot_code, sizeof(slave_boot_code));
>> + p += sizeof(slave_boot_code);
>> +}
>> +
>> static void loongarch_direct_kernel_boot(struct loongarch_boot_info
>> *info)
>> {
>> + void *p, *bp;
>> int64_t kernel_addr = 0;
>> LoongArchCPU *lacpu;
>> CPUState *cs;
>> @@ -126,11 +181,24 @@ static void loongarch_direct_kernel_boot(struct
>> loongarch_boot_info *info)
>> }
>> }
>> + /* Load 'boot_rom' at [0 - 1MiB] */
>> + p = g_malloc0(1 * MiB);
>> + bp = p;
>> + init_boot_rom(info, p);
>> + rom_add_blob_fixed("boot_rom", bp, 1 * MiB, 0);
>> +
> The secondary cpu waiting on the bootrom located memory address
> 0x0-0x100000.
>
> Is it possible that primary cpu clears the memory located at bootrom
> and then wakeup the secondary cpu?
>
I think it impossible,0-1M is ROM。
Thanks.
Song Gao
> Regards
> Bibo Mao
>
>> CPU_FOREACH(cs) {
>> lacpu = LOONGARCH_CPU(cs);
>> lacpu->env.load_elf = true;
>> - lacpu->env.elf_address = kernel_addr;
>> + if (cs == first_cpu) {
>> + lacpu->env.elf_address = kernel_addr;
>> + } else {
>> + lacpu->env.elf_address = 0;
>> + }
>> + lacpu->env.boot_info = info;
>> }
>> +
>> + g_free(bp);
>> }
>> void loongarch_load_kernel(MachineState *ms, struct
>> loongarch_boot_info *info)
>>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 06/17] hw/loongarch: Init efi_boot_memmap table
2024-03-08 8:37 ` maobibo
@ 2024-03-08 10:09 ` gaosong
0 siblings, 0 replies; 46+ messages in thread
From: gaosong @ 2024-03-08 10:09 UTC (permalink / raw)
To: maobibo, qemu-devel; +Cc: peter.maydell
在 2024/3/8 16:37, maobibo 写道:
>
>
> On 2024/3/8 上午12:48, Song Gao wrote:
>> Signed-off-by: Song Gao <gaosong@loongson.cn>
>> Message-Id: <20240301093839.663947-7-gaosong@loongson.cn>
>> ---
>> hw/loongarch/boot.c | 39 +++++++++++++++++++++++++++++++++++++
>> hw/loongarch/virt.c | 11 ++---------
>> include/hw/loongarch/boot.h | 27 +++++++++++++++++++++++++
>> include/hw/loongarch/virt.h | 10 ++++++++++
>> 4 files changed, 78 insertions(+), 9 deletions(-)
>>
>> diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
>> index 1e31e2a59f..2896c1ea40 100644
>> --- a/hw/loongarch/boot.c
>> +++ b/hw/loongarch/boot.c
>> @@ -63,8 +63,40 @@ static const unsigned int slave_boot_code[] = {
>> 0x4c000020, /* jirl $r0,$r1,0 */
>> };
>> +static inline void *guidcpy(void *dst, const void *src)
>> +{
>> + return memcpy(dst, src, sizeof(efi_guid_t));
>> +}
>> +
>> +static void init_efi_boot_memmap(struct efi_system_table *systab,
>> + void *p, void *start)
>> +{
>> + unsigned i;
>> + struct efi_boot_memmap *boot_memmap = p;
>> + efi_guid_t tbl_guid = LINUX_EFI_BOOT_MEMMAP_GUID;
>> +
>> + /* efi_configuration_table 1 */
>> + guidcpy(&systab->tables[0].guid, &tbl_guid);
>> + systab->tables[0].table = (struct efi_configuration_table *)(p -
>> start);
>> + systab->nr_tables = 1;
>> +
>> + boot_memmap->desc_size = sizeof(efi_memory_desc_t);
>> + boot_memmap->desc_ver = 1;
>> + boot_memmap->map_size = 0;
>> +
>> + efi_memory_desc_t *map = p + sizeof(struct efi_boot_memmap);
>> + for (i = 0; i < memmap_entries; i++) {
>> + map = (void *)boot_memmap + sizeof(*map);
>> + map[i].type = memmap_table[i].type;
>> + map[i].phys_addr = memmap_table[i].address;
>> + map[i].num_pages = memmap_table[i].length >> 16; /* 64KB align*/
> 64KB aligned or 64KB page size? In generic page size is 4K by EFI spec
> IIRC.
>
Thank you for pointing it out., I will correct it on v7.
> Regards
> Bibo Mao
>
>> + p += sizeof(efi_memory_desc_t);
>> + }
>> +}
>> +
>> static void init_systab(struct loongarch_boot_info *info, void *p,
>> void *start)
>> {
>> + void *bp_tables_start;
>> struct efi_system_table *systab = p;
>> info->a2 = (uint64_t)p - (uint64_t)start;
>> @@ -80,6 +112,13 @@ static void init_systab(struct loongarch_boot_info
>> *info, void *p, void *start)
>> p += ROUND_UP(sizeof(struct efi_system_table), 64);
>> systab->tables = p;
>> + bp_tables_start = p;
>> +
>> + init_efi_boot_memmap(systab, p, start);
>> + p += ROUND_UP(sizeof(struct efi_boot_memmap) +
>> + sizeof(efi_memory_desc_t) * memmap_entries, 64);
>> +
>> + systab->tables = (struct efi_configuration_table
>> *)(bp_tables_start - start);
>> }
>> static void init_cmdline(struct loongarch_boot_info *info, void *p,
>> void *start)
>> diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
>> index bbd5cc1d4d..8981b57b12 100644
>> --- a/hw/loongarch/virt.c
>> +++ b/hw/loongarch/virt.c
>> @@ -377,15 +377,8 @@ static void virt_powerdown_req(Notifier
>> *notifier, void *opaque)
>> acpi_send_event(s->acpi_ged, ACPI_POWER_DOWN_STATUS);
>> }
>> -struct memmap_entry {
>> - uint64_t address;
>> - uint64_t length;
>> - uint32_t type;
>> - uint32_t reserved;
>> -};
>> -
>> -static struct memmap_entry *memmap_table;
>> -static unsigned memmap_entries;
>> +struct memmap_entry *memmap_table;
>> +unsigned memmap_entries;
>> static void memmap_add_entry(uint64_t address, uint64_t length,
>> uint32_t type)
>> {
>> diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h
>> index 65ad406f02..f71c693f43 100644
>> --- a/include/hw/loongarch/boot.h
>> +++ b/include/hw/loongarch/boot.h
>> @@ -21,6 +21,15 @@ typedef struct {
>> uint8_t b[16];
>> } efi_guid_t __attribute__((aligned(8)));
>> +#define EFI_GUID(a, b, c, d...) (efi_guid_t){
>> { \
>> + (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >>
>> 24) & 0xff, \
>> + (b) & 0xff, ((b) >> 8) &
>> 0xff, \
>> + (c) & 0xff, ((c) >> 8) & 0xff, d } }
>> +
>> +#define LINUX_EFI_BOOT_MEMMAP_GUID \
>> + EFI_GUID(0x800f683f, 0xd08b, 0x423a, 0xa2, 0x93, \
>> + 0x96, 0x5c, 0x3c, 0x6f, 0xe2, 0xb4)
>> +
>> struct efi_config_table {
>> efi_guid_t guid;
>> uint64_t *ptr;
>> @@ -56,6 +65,24 @@ struct efi_system_table {
>> struct efi_configuration_table *tables;
>> };
>> +typedef struct {
>> + uint32_t type;
>> + uint32_t pad;
>> + uint64_t phys_addr;
>> + uint64_t virt_addr;
>> + uint64_t num_pages;
>> + uint64_t attribute;
>> +} efi_memory_desc_t;
>> +
>> +struct efi_boot_memmap {
>> + uint64_t map_size;
>> + uint64_t desc_size;
>> + uint32_t desc_ver;
>> + uint64_t map_key;
>> + uint64_t buff_size;
>> + efi_memory_desc_t map[32];
>> +};
>> +
>> struct loongarch_boot_info {
>> uint64_t ram_size;
>> const char *kernel_filename;
>> diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h
>> index d7a074d69f..8a9fe4053d 100644
>> --- a/include/hw/loongarch/virt.h
>> +++ b/include/hw/loongarch/virt.h
>> @@ -35,6 +35,16 @@
>> #define COMMAND_LINE_SIZE 512
>> +extern struct memmap_entry *memmap_table;
>> +extern unsigned memmap_entries;
>> +
>> +struct memmap_entry {
>> + uint64_t address;
>> + uint64_t length;
>> + uint32_t type;
>> + uint32_t reserved;
>> +};
>> +
>> struct LoongArchMachineState {
>> /*< private >*/
>> MachineState parent_obj;
>>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 03/17] hw/loongarch: Add slave cpu boot_code
2024-03-08 9:36 ` gaosong
@ 2024-03-11 6:50 ` maobibo
2024-03-14 1:31 ` maobibo
0 siblings, 1 reply; 46+ messages in thread
From: maobibo @ 2024-03-11 6:50 UTC (permalink / raw)
To: gaosong, qemu-devel; +Cc: peter.maydell
On 2024/3/8 下午5:36, gaosong wrote:
>
>
> 在 2024/3/8 16:27, maobibo 写道:
>>
>>
>> On 2024/3/8 上午12:48, Song Gao wrote:
>>> Signed-off-by: Song Gao <gaosong@loongson.cn>
>>> Message-Id: <20240301093839.663947-4-gaosong@loongson.cn>
>>> ---
>>> hw/loongarch/boot.c | 70 ++++++++++++++++++++++++++++++++++++++++++++-
>>> 1 file changed, 69 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
>>> index 149deb2e01..e560ac178a 100644
>>> --- a/hw/loongarch/boot.c
>>> +++ b/hw/loongarch/boot.c
>>> @@ -15,6 +15,54 @@
>>> #include "sysemu/reset.h"
>>> #include "sysemu/qtest.h"
>>> +static const unsigned int slave_boot_code[] = {
>>> + /* Configure reset ebase. */
>>> + 0x0400302c, /* csrwr $r12,0xc */
>>> +
>>> + /* Disable interrupt. */
>>> + 0x0380100c, /* ori $r12,$r0,0x4 */
>>> + 0x04000180, /* csrxchg $r0,$r12,0x0 */
>>> +
>>> + /* Clear mailbox. */
>>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>>> + 0x038081ad, /* ori $r13,$r13,0x20 */
>>> + 0x06481da0, /* iocsrwr.d $r0,$r13 */
>>> +
>>> + /* Enable IPI interrupt. */
>>> + 0x1400002c, /* lu12i.w $r12,1(0x1) */
>>> + 0x0400118c, /* csrxchg $r12,$r12,0x4 */
>>> + 0x02fffc0c, /* addi.d $r12,$r0,-1(0xfff) */
>>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>>> + 0x038011ad, /* ori $r13,$r13,0x4 */
>>> + 0x064819ac, /* iocsrwr.w $r12,$r13 */
>>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>>> + 0x038081ad, /* ori $r13,$r13,0x20 */
>>> +
>>> + /* Wait for wakeup <.L11>: */
>>> + 0x06488000, /* idle 0x0 */
>>> + 0x03400000, /* andi $r0,$r0,0x0 */
>>> + 0x064809ac, /* iocsrrd.w $r12,$r13 */
>>> + 0x43fff59f, /* beqz $r12,-12(0x7ffff4) # 48 <.L11> */
>>> +
>>> + /* Read and clear IPI interrupt. */
>>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>>> + 0x064809ac, /* iocsrrd.w $r12,$r13 */
>>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>>> + 0x038031ad, /* ori $r13,$r13,0xc */
>>> + 0x064819ac, /* iocsrwr.w $r12,$r13 */
>>> +
>>> + /* Disable IPI interrupt. */
>>> + 0x1400002c, /* lu12i.w $r12,1(0x1) */
>>> + 0x04001180, /* csrxchg $r0,$r12,0x4 */
>>> +
>>> + /* Read mail buf and jump to specified entry */
>>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>>> + 0x038081ad, /* ori $r13,$r13,0x20 */
>>> + 0x06480dac, /* iocsrrd.d $r12,$r13 */
>>> + 0x00150181, /* move $r1,$r12 */
>>> + 0x4c000020, /* jirl $r0,$r1,0 */
>>> +};
>>> +
>>> static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t
>>> addr)
>>> {
>>> return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
>>> @@ -111,8 +159,15 @@ static void
>>> loongarch_firmware_boot(LoongArchMachineState *lams,
>>> fw_cfg_add_kernel_info(info, lams->fw_cfg);
>>> }
>>> +static void init_boot_rom(struct loongarch_boot_info *info, void *p)
>>> +{
>>> + memcpy(p, &slave_boot_code, sizeof(slave_boot_code));
>>> + p += sizeof(slave_boot_code);
>>> +}
>>> +
>>> static void loongarch_direct_kernel_boot(struct loongarch_boot_info
>>> *info)
>>> {
>>> + void *p, *bp;
>>> int64_t kernel_addr = 0;
>>> LoongArchCPU *lacpu;
>>> CPUState *cs;
>>> @@ -126,11 +181,24 @@ static void loongarch_direct_kernel_boot(struct
>>> loongarch_boot_info *info)
>>> }
>>> }
>>> + /* Load 'boot_rom' at [0 - 1MiB] */
>>> + p = g_malloc0(1 * MiB);
>>> + bp = p;
>>> + init_boot_rom(info, p);
>>> + rom_add_blob_fixed("boot_rom", bp, 1 * MiB, 0);
>>> +
>> The secondary cpu waiting on the bootrom located memory address
>> 0x0-0x100000.
>>
>> Is it possible that primary cpu clears the memory located at bootrom
>> and then wakeup the secondary cpu?
>>
> I think it impossible,0-1M is ROM。
I am not sure whether it is ok if area between 0-1M is ROM.
For the memory map table, low memory area (0 - 256M) is still ddr ram.
And it is passed to kernel with fdt system table, rather than
area(1-256M). Is that right?
There are some lines like this:
/* Node0 memory */
memmap_add_entry(VIRT_LOWMEM_BASE, VIRT_LOWMEM_SIZE, 1);
Regards
Bibo Mao
>
> Thanks.
> Song Gao
>> Regards
>> Bibo Mao
>>
>>> CPU_FOREACH(cs) {
>>> lacpu = LOONGARCH_CPU(cs);
>>> lacpu->env.load_elf = true;
>>> - lacpu->env.elf_address = kernel_addr;
>>> + if (cs == first_cpu) {
>>> + lacpu->env.elf_address = kernel_addr;
>>> + } else {
>>> + lacpu->env.elf_address = 0;
>>> + }
>>> + lacpu->env.boot_info = info;
>>> }
>>> +
>>> + g_free(bp);
>>> }
>>> void loongarch_load_kernel(MachineState *ms, struct
>>> loongarch_boot_info *info)
>>>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 03/17] hw/loongarch: Add slave cpu boot_code
2024-03-11 6:50 ` maobibo
@ 2024-03-14 1:31 ` maobibo
2024-03-14 9:03 ` gaosong
0 siblings, 1 reply; 46+ messages in thread
From: maobibo @ 2024-03-14 1:31 UTC (permalink / raw)
To: gaosong, qemu-devel; +Cc: peter.maydell
On 2024/3/11 下午2:50, maobibo wrote:
>
>
> On 2024/3/8 下午5:36, gaosong wrote:
>>
>>
>> 在 2024/3/8 16:27, maobibo 写道:
>>>
>>>
>>> On 2024/3/8 上午12:48, Song Gao wrote:
>>>> Signed-off-by: Song Gao <gaosong@loongson.cn>
>>>> Message-Id: <20240301093839.663947-4-gaosong@loongson.cn>
>>>> ---
>>>> hw/loongarch/boot.c | 70
>>>> ++++++++++++++++++++++++++++++++++++++++++++-
>>>> 1 file changed, 69 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
>>>> index 149deb2e01..e560ac178a 100644
>>>> --- a/hw/loongarch/boot.c
>>>> +++ b/hw/loongarch/boot.c
>>>> @@ -15,6 +15,54 @@
>>>> #include "sysemu/reset.h"
>>>> #include "sysemu/qtest.h"
>>>> +static const unsigned int slave_boot_code[] = {
>>>> + /* Configure reset ebase. */
>>>> + 0x0400302c, /* csrwr $r12,0xc */
>>>> +
>>>> + /* Disable interrupt. */
>>>> + 0x0380100c, /* ori $r12,$r0,0x4 */
>>>> + 0x04000180, /* csrxchg $r0,$r12,0x0 */
>>>> +
>>>> + /* Clear mailbox. */
>>>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>>>> + 0x038081ad, /* ori $r13,$r13,0x20 */
>>>> + 0x06481da0, /* iocsrwr.d $r0,$r13 */
>>>> +
>>>> + /* Enable IPI interrupt. */
>>>> + 0x1400002c, /* lu12i.w $r12,1(0x1) */
>>>> + 0x0400118c, /* csrxchg $r12,$r12,0x4 */
>>>> + 0x02fffc0c, /* addi.d $r12,$r0,-1(0xfff) */
>>>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>>>> + 0x038011ad, /* ori $r13,$r13,0x4 */
>>>> + 0x064819ac, /* iocsrwr.w $r12,$r13 */
>>>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>>>> + 0x038081ad, /* ori $r13,$r13,0x20 */
>>>> +
>>>> + /* Wait for wakeup <.L11>: */
>>>> + 0x06488000, /* idle 0x0 */
>>>> + 0x03400000, /* andi $r0,$r0,0x0 */
>>>> + 0x064809ac, /* iocsrrd.w $r12,$r13 */
>>>> + 0x43fff59f, /* beqz $r12,-12(0x7ffff4) # 48 <.L11> */
>>>> +
>>>> + /* Read and clear IPI interrupt. */
>>>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>>>> + 0x064809ac, /* iocsrrd.w $r12,$r13 */
>>>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>>>> + 0x038031ad, /* ori $r13,$r13,0xc */
>>>> + 0x064819ac, /* iocsrwr.w $r12,$r13 */
>>>> +
>>>> + /* Disable IPI interrupt. */
>>>> + 0x1400002c, /* lu12i.w $r12,1(0x1) */
>>>> + 0x04001180, /* csrxchg $r0,$r12,0x4 */
>>>> +
>>>> + /* Read mail buf and jump to specified entry */
>>>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>>>> + 0x038081ad, /* ori $r13,$r13,0x20 */
>>>> + 0x06480dac, /* iocsrrd.d $r12,$r13 */
>>>> + 0x00150181, /* move $r1,$r12 */
>>>> + 0x4c000020, /* jirl $r0,$r1,0 */
>>>> +};
>>>> +
>>>> static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t
>>>> addr)
>>>> {
>>>> return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
>>>> @@ -111,8 +159,15 @@ static void
>>>> loongarch_firmware_boot(LoongArchMachineState *lams,
>>>> fw_cfg_add_kernel_info(info, lams->fw_cfg);
>>>> }
>>>> +static void init_boot_rom(struct loongarch_boot_info *info, void *p)
>>>> +{
>>>> + memcpy(p, &slave_boot_code, sizeof(slave_boot_code));
>>>> + p += sizeof(slave_boot_code);
>>>> +}
>>>> +
>>>> static void loongarch_direct_kernel_boot(struct
>>>> loongarch_boot_info *info)
>>>> {
>>>> + void *p, *bp;
>>>> int64_t kernel_addr = 0;
>>>> LoongArchCPU *lacpu;
>>>> CPUState *cs;
>>>> @@ -126,11 +181,24 @@ static void
>>>> loongarch_direct_kernel_boot(struct loongarch_boot_info *info)
>>>> }
>>>> }
>>>> + /* Load 'boot_rom' at [0 - 1MiB] */
>>>> + p = g_malloc0(1 * MiB);
>>>> + bp = p;
>>>> + init_boot_rom(info, p);
>>>> + rom_add_blob_fixed("boot_rom", bp, 1 * MiB, 0);
>>>> +
>>> The secondary cpu waiting on the bootrom located memory address
>>> 0x0-0x100000.
>>>
>>> Is it possible that primary cpu clears the memory located at bootrom
>>> and then wakeup the secondary cpu?
>>>
>> I think it impossible,0-1M is ROM。
> I am not sure whether it is ok if area between 0-1M is ROM.
>
> For the memory map table, low memory area (0 - 256M) is still ddr ram.
> And it is passed to kernel with fdt system table, rather than
> area(1-256M). Is that right?
>
> There are some lines like this:
> /* Node0 memory */
> memmap_add_entry(VIRT_LOWMEM_BASE, VIRT_LOWMEM_SIZE, 1);
Song,
Can the base memory address of bootrom for secondary cpus be set as base
address of flash like bios, such as VIRT_FLASH0_BASE/VIRT_FLASH1_BASE?
And ddr memory map area is kept unchanged.
Regards
Bibo Mao
>
> Regards
> Bibo Mao
>
>>
>> Thanks.
>> Song Gao
>>> Regards
>>> Bibo Mao
>>>
>>>> CPU_FOREACH(cs) {
>>>> lacpu = LOONGARCH_CPU(cs);
>>>> lacpu->env.load_elf = true;
>>>> - lacpu->env.elf_address = kernel_addr;
>>>> + if (cs == first_cpu) {
>>>> + lacpu->env.elf_address = kernel_addr;
>>>> + } else {
>>>> + lacpu->env.elf_address = 0;
>>>> + }
>>>> + lacpu->env.boot_info = info;
>>>> }
>>>> +
>>>> + g_free(bp);
>>>> }
>>>> void loongarch_load_kernel(MachineState *ms, struct
>>>> loongarch_boot_info *info)
>>>>
>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 03/17] hw/loongarch: Add slave cpu boot_code
2024-03-07 16:48 ` [PATCH v6 03/17] hw/loongarch: Add slave cpu boot_code Song Gao
2024-03-08 8:27 ` maobibo
@ 2024-03-14 2:28 ` chen huacai
2024-03-14 9:04 ` gaosong
1 sibling, 1 reply; 46+ messages in thread
From: chen huacai @ 2024-03-14 2:28 UTC (permalink / raw)
To: Song Gao; +Cc: qemu-devel, peter.maydell, maobibo
Song,
On Fri, Mar 8, 2024 at 12:51 AM Song Gao <gaosong@loongson.cn> wrote:
>
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> Message-Id: <20240301093839.663947-4-gaosong@loongson.cn>
> ---
> hw/loongarch/boot.c | 70 ++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 69 insertions(+), 1 deletion(-)
>
> diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
> index 149deb2e01..e560ac178a 100644
> --- a/hw/loongarch/boot.c
> +++ b/hw/loongarch/boot.c
> @@ -15,6 +15,54 @@
> #include "sysemu/reset.h"
> #include "sysemu/qtest.h"
>
> +static const unsigned int slave_boot_code[] = {
> + /* Configure reset ebase. */
> + 0x0400302c, /* csrwr $r12,0xc */
Use reg-names may be a little better than reg-nums.
Huacai
> +
> + /* Disable interrupt. */
> + 0x0380100c, /* ori $r12,$r0,0x4 */
> + 0x04000180, /* csrxchg $r0,$r12,0x0 */
> +
> + /* Clear mailbox. */
> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
> + 0x038081ad, /* ori $r13,$r13,0x20 */
> + 0x06481da0, /* iocsrwr.d $r0,$r13 */
> +
> + /* Enable IPI interrupt. */
> + 0x1400002c, /* lu12i.w $r12,1(0x1) */
> + 0x0400118c, /* csrxchg $r12,$r12,0x4 */
> + 0x02fffc0c, /* addi.d $r12,$r0,-1(0xfff) */
> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
> + 0x038011ad, /* ori $r13,$r13,0x4 */
> + 0x064819ac, /* iocsrwr.w $r12,$r13 */
> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
> + 0x038081ad, /* ori $r13,$r13,0x20 */
> +
> + /* Wait for wakeup <.L11>: */
> + 0x06488000, /* idle 0x0 */
> + 0x03400000, /* andi $r0,$r0,0x0 */
> + 0x064809ac, /* iocsrrd.w $r12,$r13 */
> + 0x43fff59f, /* beqz $r12,-12(0x7ffff4) # 48 <.L11> */
> +
> + /* Read and clear IPI interrupt. */
> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
> + 0x064809ac, /* iocsrrd.w $r12,$r13 */
> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
> + 0x038031ad, /* ori $r13,$r13,0xc */
> + 0x064819ac, /* iocsrwr.w $r12,$r13 */
> +
> + /* Disable IPI interrupt. */
> + 0x1400002c, /* lu12i.w $r12,1(0x1) */
> + 0x04001180, /* csrxchg $r0,$r12,0x4 */
> +
> + /* Read mail buf and jump to specified entry */
> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
> + 0x038081ad, /* ori $r13,$r13,0x20 */
> + 0x06480dac, /* iocsrrd.d $r12,$r13 */
> + 0x00150181, /* move $r1,$r12 */
> + 0x4c000020, /* jirl $r0,$r1,0 */
> +};
> +
> static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
> {
> return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
> @@ -111,8 +159,15 @@ static void loongarch_firmware_boot(LoongArchMachineState *lams,
> fw_cfg_add_kernel_info(info, lams->fw_cfg);
> }
>
> +static void init_boot_rom(struct loongarch_boot_info *info, void *p)
> +{
> + memcpy(p, &slave_boot_code, sizeof(slave_boot_code));
> + p += sizeof(slave_boot_code);
> +}
> +
> static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info)
> {
> + void *p, *bp;
> int64_t kernel_addr = 0;
> LoongArchCPU *lacpu;
> CPUState *cs;
> @@ -126,11 +181,24 @@ static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info)
> }
> }
>
> + /* Load 'boot_rom' at [0 - 1MiB] */
> + p = g_malloc0(1 * MiB);
> + bp = p;
> + init_boot_rom(info, p);
> + rom_add_blob_fixed("boot_rom", bp, 1 * MiB, 0);
> +
> CPU_FOREACH(cs) {
> lacpu = LOONGARCH_CPU(cs);
> lacpu->env.load_elf = true;
> - lacpu->env.elf_address = kernel_addr;
> + if (cs == first_cpu) {
> + lacpu->env.elf_address = kernel_addr;
> + } else {
> + lacpu->env.elf_address = 0;
> + }
> + lacpu->env.boot_info = info;
> }
> +
> + g_free(bp);
> }
>
> void loongarch_load_kernel(MachineState *ms, struct loongarch_boot_info *info)
> --
> 2.34.1
>
>
--
Huacai Chen
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 03/17] hw/loongarch: Add slave cpu boot_code
2024-03-14 1:31 ` maobibo
@ 2024-03-14 9:03 ` gaosong
0 siblings, 0 replies; 46+ messages in thread
From: gaosong @ 2024-03-14 9:03 UTC (permalink / raw)
To: maobibo, qemu-devel; +Cc: peter.maydell
在 2024/3/14 9:31, maobibo 写道:
>
>
> On 2024/3/11 下午2:50, maobibo wrote:
>>
>>
>> On 2024/3/8 下午5:36, gaosong wrote:
>>>
>>>
>>> 在 2024/3/8 16:27, maobibo 写道:
>>>>
>>>>
>>>> On 2024/3/8 上午12:48, Song Gao wrote:
>>>>> Signed-off-by: Song Gao <gaosong@loongson.cn>
>>>>> Message-Id: <20240301093839.663947-4-gaosong@loongson.cn>
>>>>> ---
>>>>> hw/loongarch/boot.c | 70
>>>>> ++++++++++++++++++++++++++++++++++++++++++++-
>>>>> 1 file changed, 69 insertions(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
>>>>> index 149deb2e01..e560ac178a 100644
>>>>> --- a/hw/loongarch/boot.c
>>>>> +++ b/hw/loongarch/boot.c
>>>>> @@ -15,6 +15,54 @@
>>>>> #include "sysemu/reset.h"
>>>>> #include "sysemu/qtest.h"
>>>>> +static const unsigned int slave_boot_code[] = {
>>>>> + /* Configure reset ebase. */
>>>>> + 0x0400302c, /* csrwr $r12,0xc */
>>>>> +
>>>>> + /* Disable interrupt. */
>>>>> + 0x0380100c, /* ori $r12,$r0,0x4 */
>>>>> + 0x04000180, /* csrxchg $r0,$r12,0x0 */
>>>>> +
>>>>> + /* Clear mailbox. */
>>>>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>>>>> + 0x038081ad, /* ori $r13,$r13,0x20 */
>>>>> + 0x06481da0, /* iocsrwr.d $r0,$r13 */
>>>>> +
>>>>> + /* Enable IPI interrupt. */
>>>>> + 0x1400002c, /* lu12i.w $r12,1(0x1) */
>>>>> + 0x0400118c, /* csrxchg $r12,$r12,0x4 */
>>>>> + 0x02fffc0c, /* addi.d $r12,$r0,-1(0xfff) */
>>>>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>>>>> + 0x038011ad, /* ori $r13,$r13,0x4 */
>>>>> + 0x064819ac, /* iocsrwr.w $r12,$r13 */
>>>>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>>>>> + 0x038081ad, /* ori $r13,$r13,0x20 */
>>>>> +
>>>>> + /* Wait for wakeup <.L11>: */
>>>>> + 0x06488000, /* idle 0x0 */
>>>>> + 0x03400000, /* andi $r0,$r0,0x0 */
>>>>> + 0x064809ac, /* iocsrrd.w $r12,$r13 */
>>>>> + 0x43fff59f, /* beqz $r12,-12(0x7ffff4) # 48 <.L11> */
>>>>> +
>>>>> + /* Read and clear IPI interrupt. */
>>>>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>>>>> + 0x064809ac, /* iocsrrd.w $r12,$r13 */
>>>>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>>>>> + 0x038031ad, /* ori $r13,$r13,0xc */
>>>>> + 0x064819ac, /* iocsrwr.w $r12,$r13 */
>>>>> +
>>>>> + /* Disable IPI interrupt. */
>>>>> + 0x1400002c, /* lu12i.w $r12,1(0x1) */
>>>>> + 0x04001180, /* csrxchg $r0,$r12,0x4 */
>>>>> +
>>>>> + /* Read mail buf and jump to specified entry */
>>>>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>>>>> + 0x038081ad, /* ori $r13,$r13,0x20 */
>>>>> + 0x06480dac, /* iocsrrd.d $r12,$r13 */
>>>>> + 0x00150181, /* move $r1,$r12 */
>>>>> + 0x4c000020, /* jirl $r0,$r1,0 */
>>>>> +};
>>>>> +
>>>>> static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t
>>>>> addr)
>>>>> {
>>>>> return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
>>>>> @@ -111,8 +159,15 @@ static void
>>>>> loongarch_firmware_boot(LoongArchMachineState *lams,
>>>>> fw_cfg_add_kernel_info(info, lams->fw_cfg);
>>>>> }
>>>>> +static void init_boot_rom(struct loongarch_boot_info *info, void *p)
>>>>> +{
>>>>> + memcpy(p, &slave_boot_code, sizeof(slave_boot_code));
>>>>> + p += sizeof(slave_boot_code);
>>>>> +}
>>>>> +
>>>>> static void loongarch_direct_kernel_boot(struct
>>>>> loongarch_boot_info *info)
>>>>> {
>>>>> + void *p, *bp;
>>>>> int64_t kernel_addr = 0;
>>>>> LoongArchCPU *lacpu;
>>>>> CPUState *cs;
>>>>> @@ -126,11 +181,24 @@ static void
>>>>> loongarch_direct_kernel_boot(struct loongarch_boot_info *info)
>>>>> }
>>>>> }
>>>>> + /* Load 'boot_rom' at [0 - 1MiB] */
>>>>> + p = g_malloc0(1 * MiB);
>>>>> + bp = p;
>>>>> + init_boot_rom(info, p);
>>>>> + rom_add_blob_fixed("boot_rom", bp, 1 * MiB, 0);
>>>>> +
>>>> The secondary cpu waiting on the bootrom located memory address
>>>> 0x0-0x100000.
>>>>
>>>> Is it possible that primary cpu clears the memory located at bootrom
>>>> and then wakeup the secondary cpu?
>>>>
>>> I think it impossible,0-1M is ROM。
>> I am not sure whether it is ok if area between 0-1M is ROM.
>>
>> For the memory map table, low memory area (0 - 256M) is still ddr ram.
>> And it is passed to kernel with fdt system table, rather than
>> area(1-256M). Is that right?
>>
>> There are some lines like this:
>> /* Node0 memory */
>> memmap_add_entry(VIRT_LOWMEM_BASE, VIRT_LOWMEM_SIZE, 1);
> Song,
>
> Can the base memory address of bootrom for secondary cpus be set as base
> address of flash like bios, such as VIRT_FLASH0_BASE/VIRT_FLASH1_BASE?
> > And ddr memory map area is kept unchanged.
>
Good suggestions, I wil do this on v7.
Thanks.
Song Gao
> Regards
> Bibo Mao
>
>>
>> Regards
>> Bibo Mao
>>
>>>
>>> Thanks.
>>> Song Gao
>>>> Regards
>>>> Bibo Mao
>>>>
>>>>> CPU_FOREACH(cs) {
>>>>> lacpu = LOONGARCH_CPU(cs);
>>>>> lacpu->env.load_elf = true;
>>>>> - lacpu->env.elf_address = kernel_addr;
>>>>> + if (cs == first_cpu) {
>>>>> + lacpu->env.elf_address = kernel_addr;
>>>>> + } else {
>>>>> + lacpu->env.elf_address = 0;
>>>>> + }
>>>>> + lacpu->env.boot_info = info;
>>>>> }
>>>>> +
>>>>> + g_free(bp);
>>>>> }
>>>>> void loongarch_load_kernel(MachineState *ms, struct
>>>>> loongarch_boot_info *info)
>>>>>
>>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v6 03/17] hw/loongarch: Add slave cpu boot_code
2024-03-14 2:28 ` chen huacai
@ 2024-03-14 9:04 ` gaosong
0 siblings, 0 replies; 46+ messages in thread
From: gaosong @ 2024-03-14 9:04 UTC (permalink / raw)
To: chen huacai; +Cc: qemu-devel, peter.maydell, maobibo
在 2024/3/14 10:28, chen huacai 写道:
> Song,
>
> On Fri, Mar 8, 2024 at 12:51 AM Song Gao <gaosong@loongson.cn> wrote:
>>
>> Signed-off-by: Song Gao <gaosong@loongson.cn>
>> Message-Id: <20240301093839.663947-4-gaosong@loongson.cn>
>> ---
>> hw/loongarch/boot.c | 70 ++++++++++++++++++++++++++++++++++++++++++++-
>> 1 file changed, 69 insertions(+), 1 deletion(-)
>>
>> diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
>> index 149deb2e01..e560ac178a 100644
>> --- a/hw/loongarch/boot.c
>> +++ b/hw/loongarch/boot.c
>> @@ -15,6 +15,54 @@
>> #include "sysemu/reset.h"
>> #include "sysemu/qtest.h"
>>
>> +static const unsigned int slave_boot_code[] = {
>> + /* Configure reset ebase. */
>> + 0x0400302c, /* csrwr $r12,0xc */
> Use reg-names may be a little better than reg-nums.
>
Got it.
Thanks.
Song Gao
> Huacai
>
>> +
>> + /* Disable interrupt. */
>> + 0x0380100c, /* ori $r12,$r0,0x4 */
>> + 0x04000180, /* csrxchg $r0,$r12,0x0 */
>> +
>> + /* Clear mailbox. */
>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>> + 0x038081ad, /* ori $r13,$r13,0x20 */
>> + 0x06481da0, /* iocsrwr.d $r0,$r13 */
>> +
>> + /* Enable IPI interrupt. */
>> + 0x1400002c, /* lu12i.w $r12,1(0x1) */
>> + 0x0400118c, /* csrxchg $r12,$r12,0x4 */
>> + 0x02fffc0c, /* addi.d $r12,$r0,-1(0xfff) */
>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>> + 0x038011ad, /* ori $r13,$r13,0x4 */
>> + 0x064819ac, /* iocsrwr.w $r12,$r13 */
>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>> + 0x038081ad, /* ori $r13,$r13,0x20 */
>> +
>> + /* Wait for wakeup <.L11>: */
>> + 0x06488000, /* idle 0x0 */
>> + 0x03400000, /* andi $r0,$r0,0x0 */
>> + 0x064809ac, /* iocsrrd.w $r12,$r13 */
>> + 0x43fff59f, /* beqz $r12,-12(0x7ffff4) # 48 <.L11> */
>> +
>> + /* Read and clear IPI interrupt. */
>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>> + 0x064809ac, /* iocsrrd.w $r12,$r13 */
>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>> + 0x038031ad, /* ori $r13,$r13,0xc */
>> + 0x064819ac, /* iocsrwr.w $r12,$r13 */
>> +
>> + /* Disable IPI interrupt. */
>> + 0x1400002c, /* lu12i.w $r12,1(0x1) */
>> + 0x04001180, /* csrxchg $r0,$r12,0x4 */
>> +
>> + /* Read mail buf and jump to specified entry */
>> + 0x1400002d, /* lu12i.w $r13,1(0x1) */
>> + 0x038081ad, /* ori $r13,$r13,0x20 */
>> + 0x06480dac, /* iocsrrd.d $r12,$r13 */
>> + 0x00150181, /* move $r1,$r12 */
>> + 0x4c000020, /* jirl $r0,$r1,0 */
>> +};
>> +
>> static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
>> {
>> return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
>> @@ -111,8 +159,15 @@ static void loongarch_firmware_boot(LoongArchMachineState *lams,
>> fw_cfg_add_kernel_info(info, lams->fw_cfg);
>> }
>>
>> +static void init_boot_rom(struct loongarch_boot_info *info, void *p)
>> +{
>> + memcpy(p, &slave_boot_code, sizeof(slave_boot_code));
>> + p += sizeof(slave_boot_code);
>> +}
>> +
>> static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info)
>> {
>> + void *p, *bp;
>> int64_t kernel_addr = 0;
>> LoongArchCPU *lacpu;
>> CPUState *cs;
>> @@ -126,11 +181,24 @@ static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info)
>> }
>> }
>>
>> + /* Load 'boot_rom' at [0 - 1MiB] */
>> + p = g_malloc0(1 * MiB);
>> + bp = p;
>> + init_boot_rom(info, p);
>> + rom_add_blob_fixed("boot_rom", bp, 1 * MiB, 0);
>> +
>> CPU_FOREACH(cs) {
>> lacpu = LOONGARCH_CPU(cs);
>> lacpu->env.load_elf = true;
>> - lacpu->env.elf_address = kernel_addr;
>> + if (cs == first_cpu) {
>> + lacpu->env.elf_address = kernel_addr;
>> + } else {
>> + lacpu->env.elf_address = 0;
>> + }
>> + lacpu->env.boot_info = info;
>> }
>> +
>> + g_free(bp);
>> }
>>
>> void loongarch_load_kernel(MachineState *ms, struct loongarch_boot_info *info)
>> --
>> 2.34.1
>>
>>
>
>
^ permalink raw reply [flat|nested] 46+ messages in thread
end of thread, other threads:[~2024-03-14 9:05 UTC | newest]
Thread overview: 46+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-07 16:48 [PATCH v6 00/17] Add boot LoongArch elf kernel with FDT Song Gao
2024-03-07 16:48 ` [PATCH v6 01/17] hw/loongarch: Move boot fucntions to boot.c Song Gao
2024-03-08 8:18 ` maobibo
2024-03-08 8:31 ` Philippe Mathieu-Daudé
2024-03-07 16:48 ` [PATCH v6 02/17] hw/loongarch: Add load initrd Song Gao
2024-03-08 8:19 ` maobibo
2024-03-07 16:48 ` [PATCH v6 03/17] hw/loongarch: Add slave cpu boot_code Song Gao
2024-03-08 8:27 ` maobibo
2024-03-08 9:36 ` gaosong
2024-03-11 6:50 ` maobibo
2024-03-14 1:31 ` maobibo
2024-03-14 9:03 ` gaosong
2024-03-14 2:28 ` chen huacai
2024-03-14 9:04 ` gaosong
2024-03-07 16:48 ` [PATCH v6 04/17] hw/loongarch: Add init_cmdline Song Gao
2024-03-08 8:28 ` maobibo
2024-03-07 16:48 ` [PATCH v6 05/17] hw/loongarch: Init efi_system_table Song Gao
2024-03-08 8:29 ` maobibo
2024-03-08 8:33 ` Philippe Mathieu-Daudé
2024-03-07 16:48 ` [PATCH v6 06/17] hw/loongarch: Init efi_boot_memmap table Song Gao
2024-03-08 8:37 ` maobibo
2024-03-08 10:09 ` gaosong
2024-03-07 16:48 ` [PATCH v6 07/17] hw/loongarch: Init efi_initrd table Song Gao
2024-03-08 8:36 ` Philippe Mathieu-Daudé
2024-03-08 9:20 ` gaosong
2024-03-08 8:37 ` maobibo
2024-03-07 16:48 ` [PATCH v6 08/17] hw/loongarch: Init efi_fdt table Song Gao
2024-03-08 8:39 ` maobibo
2024-03-07 16:48 ` [PATCH v6 09/17] hw/loongarch: Fix fdt memory node wrong 'reg' Song Gao
2024-03-08 8:39 ` maobibo
2024-03-07 16:48 ` [PATCH v6 10/17] hw/loongarch: fdt adds cpu interrupt controller node Song Gao
2024-03-08 8:40 ` maobibo
2024-03-07 16:48 ` [PATCH v6 11/17] hw/loongarch: fdt adds Extend I/O Interrupt Controller Song Gao
2024-03-08 8:40 ` maobibo
2024-03-07 16:48 ` [PATCH v6 12/17] hw/loongarch: fdt adds pch_pic Controller Song Gao
2024-03-08 8:41 ` maobibo
2024-03-07 16:48 ` [PATCH v6 13/17] hw/loongarch: fdt adds pch_msi Controller Song Gao
2024-03-08 8:41 ` maobibo
2024-03-07 16:48 ` [PATCH v6 14/17] hw/loongarch: fdt adds pcie irq_map node Song Gao
2024-03-08 8:44 ` maobibo
2024-03-07 16:48 ` [PATCH v6 15/17] hw/loongarch: fdt remove unused irqchip node Song Gao
2024-03-08 8:44 ` maobibo
2024-03-07 16:48 ` [PATCH v6 16/17] hw/loongarch: Add cells missing from uart node Song Gao
2024-03-08 8:44 ` maobibo
2024-03-07 16:48 ` [PATCH v6 17/17] hw/loongarch: Add cells missing from rtc node Song Gao
2024-03-08 8:45 ` maobibo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).