Re: [PATCH V19 3/5] hw/mips: Add Loongson-3 boot parameter helpers

2021-01-01 Thread Philippe Mathieu-Daudé
On 12/21/20 12:05 PM, Huacai Chen wrote:
> Preparing to add Loongson-3 machine support, add Loongson-3's LEFI (a
> UEFI-like interface for BIOS-Kernel boot parameters) helpers first.
> 
> Reviewed-by: Philippe Mathieu-Daudé 
> Signed-off-by: Huacai Chen 
> Co-developed-by: Jiaxun Yang 
> Signed-off-by: Jiaxun Yang 
> ---
>  MAINTAINERS   |   2 +
>  hw/mips/loongson3_bootp.c | 151 
>  hw/mips/loongson3_bootp.h | 241 ++
>  hw/mips/meson.build   |   1 +
>  4 files changed, 395 insertions(+)
>  create mode 100644 hw/mips/loongson3_bootp.c
>  create mode 100644 hw/mips/loongson3_bootp.h
...

> +struct MemmapEntry {
> +hwaddr base;
> +hwaddr size;
> +};
> +
> +extern const struct MemmapEntry virt_memmap[];

I'd rather avoid this extern (pass MemmapEntry as argument?).
Anyhow, not a big deal ;)
Reviewed-by: Philippe Mathieu-Daudé 



[PATCH V19 3/5] hw/mips: Add Loongson-3 boot parameter helpers

2020-12-21 Thread Huacai Chen
Preparing to add Loongson-3 machine support, add Loongson-3's LEFI (a
UEFI-like interface for BIOS-Kernel boot parameters) helpers first.

Reviewed-by: Philippe Mathieu-Daudé 
Signed-off-by: Huacai Chen 
Co-developed-by: Jiaxun Yang 
Signed-off-by: Jiaxun Yang 
---
 MAINTAINERS   |   2 +
 hw/mips/loongson3_bootp.c | 151 
 hw/mips/loongson3_bootp.h | 241 ++
 hw/mips/meson.build   |   1 +
 4 files changed, 395 insertions(+)
 create mode 100644 hw/mips/loongson3_bootp.c
 create mode 100644 hw/mips/loongson3_bootp.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 1e7c8f0488..da64918652 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1159,6 +1159,8 @@ M: Huacai Chen 
 R: Jiaxun Yang 
 S: Maintained
 F: hw/intc/loongson_liointc.c
+F: hw/mips/loongson3_bootp.c
+F: hw/mips/loongson3_bootp.h
 
 Boston
 M: Paul Burton 
diff --git a/hw/mips/loongson3_bootp.c b/hw/mips/loongson3_bootp.c
new file mode 100644
index 00..f99af22932
--- /dev/null
+++ b/hw/mips/loongson3_bootp.c
@@ -0,0 +1,151 @@
+/*
+ * LEFI (a UEFI-like interface for BIOS-Kernel boot parameters) helpers
+ *
+ * Copyright (c) 2018-2020 Huacai Chen (che...@lemote.com)
+ * Copyright (c) 2018-2020 Jiaxun Yang 
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/units.h"
+#include "qemu/cutils.h"
+#include "cpu.h"
+#include "hw/boards.h"
+#include "hw/mips/loongson3_bootp.h"
+
+#define LOONGSON3_CORE_PER_NODE 4
+
+static void init_cpu_info(void *g_cpuinfo, uint64_t cpu_freq)
+{
+struct efi_cpuinfo_loongson *c = g_cpuinfo;
+
+c->cputype = cpu_to_le32(Loongson_3A);
+c->processor_id = cpu_to_le32(MIPS_CPU(first_cpu)->env.CP0_PRid);
+if (cpu_freq > UINT_MAX) {
+c->cpu_clock_freq = cpu_to_le32(UINT_MAX);
+} else {
+c->cpu_clock_freq = cpu_to_le32(cpu_freq);
+}
+
+c->cpu_startup_core_id = cpu_to_le16(0);
+c->nr_cpus = cpu_to_le32(current_machine->smp.cpus);
+c->total_node = cpu_to_le32(DIV_ROUND_UP(current_machine->smp.cpus,
+ LOONGSON3_CORE_PER_NODE));
+}
+
+static void init_memory_map(void *g_map, uint64_t ram_size)
+{
+struct efi_memory_map_loongson *emap = g_map;
+
+emap->nr_map = cpu_to_le32(2);
+emap->mem_freq = cpu_to_le32(3);
+
+emap->map[0].node_id = cpu_to_le32(0);
+emap->map[0].mem_type = cpu_to_le32(1);
+emap->map[0].mem_start = cpu_to_le64(0x0);
+emap->map[0].mem_size = cpu_to_le32(240);
+
+emap->map[1].node_id = cpu_to_le32(0);
+emap->map[1].mem_type = cpu_to_le32(2);
+emap->map[1].mem_start = cpu_to_le64(0x9000);
+emap->map[1].mem_size = cpu_to_le32((ram_size / MiB) - 256);
+}
+
+static void init_system_loongson(void *g_system)
+{
+struct system_loongson *s = g_system;
+
+s->ccnuma_smp = cpu_to_le32(0);
+s->sing_double_channel = cpu_to_le32(1);
+s->nr_uarts = cpu_to_le32(1);
+s->uarts[0].iotype = cpu_to_le32(2);
+s->uarts[0].int_offset = cpu_to_le32(2);
+s->uarts[0].uartclk = cpu_to_le32(2500); /* Random value */
+s->uarts[0].uart_base = cpu_to_le64(virt_memmap[VIRT_UART].base);
+}
+
+static void init_irq_source(void *g_irq_source)
+{
+struct irq_source_routing_table *irq_info = g_irq_source;
+
+irq_info->node_id = cpu_to_le32(0);
+irq_info->PIC_type = cpu_to_le32(0);
+irq_info->dma_mask_bits = cpu_to_le16(64);
+irq_info->pci_mem_start_addr = 
cpu_to_le64(virt_memmap[VIRT_PCIE_MMIO].base);
+irq_info->pci_mem_end_addr = cpu_to_le64(virt_memmap[VIRT_PCIE_MMIO].base +
+ virt_memmap[VIRT_PCIE_MMIO].size 
- 1);
+irq_info->pci_io_start_addr = cpu_to_le64(virt_memmap[VIRT_PCIE_PIO].base);
+}
+
+static void init_interface_info(void *g_interface)
+{
+struct interface_info *interface = g_interface;
+
+interface->vers = cpu_to_le16(0x01);
+strpadcpy(interface->description, 64, "UEFI_Version_v1.0", '\0');
+}
+
+static void board_devices_info(void *g_board)
+{
+struct board_devices *bd = g_board;
+
+strpadcpy(bd->name, 64, "Loongson-3A-VIRT-1w-V1.00-demo", '\0');
+}
+
+static void init_special_info(void *g_special)
+{
+struct loongson_special_attribute *special = g_special;
+
+strpadcpy(special->special_name, 64, "2018-05-01", '\0');
+}
+
+void init_loongson