+Paolo for question at the end. On 12/21/20 12:05 PM, Huacai Chen wrote: > Add Loongson-3 based machine support, it use liointc as the interrupt > controler and use GPEX as the pci controller. Currently it can work with > both TCG and KVM. > > As the machine model is not based on any exiting physical hardware, the > name of the machine is "loongson3-virt". It may be superseded in future > by a real machine model. If this happens, then a regular deprecation > procedure shall occur for "loongson3-virt" machine. > > We now already have a full functional Linux kernel (based on Linux-5.4.x > LTS) here: > > https://github.com/chenhuacai/linux > > Of course the upstream kernel is also usable (the kvm host side and > guest side have both been upstream in Linux-5.9): > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git > > How to use QEMU/Loongson-3? > 1, Download kernel source from the above URL; > 2, Build a kernel with arch/mips/configs/loongson3_defconfig; > 3, Boot a Loongson-3A4000 host with this kernel (for KVM mode); > 4, Build QEMU-master with this patchset; > 5, modprobe kvm (only necessary for KVM mode); > 6, Use QEMU with TCG: > qemu-system-mips64el -M loongson3-virt,accel=tcg -cpu Loongson-3A1000 > -kernel <path_to_kernel> -append ... > Use QEMU with KVM: > qemu-system-mips64el -M loongson3-virt,accel=kvm -cpu Loongson-3A4000 > -kernel <path_to_kernel> -append ... > > The "-cpu" parameter is optional here and QEMU will use the correct type > for TCG/KVM automatically. > > Signed-off-by: Huacai Chen <chenhua...@kernel.org> > Co-developed-by: Jiaxun Yang <jiaxun.y...@flygoat.com> > Signed-off-by: Jiaxun Yang <jiaxun.y...@flygoat.com> > --- > MAINTAINERS | 1 + > default-configs/devices/mips64el-softmmu.mak | 1 + > hw/mips/Kconfig | 11 + > hw/mips/loongson3_virt.c | 621 +++++++++++++++++++ > hw/mips/meson.build | 2 +- > 5 files changed, 635 insertions(+), 1 deletion(-) > create mode 100644 hw/mips/loongson3_virt.c ...
> +static inline void loongson3_virt_devices_init(MachineState *machine, > DeviceState *pic) > +{ > + int i; > + qemu_irq irq; > + PCIBus *pci_bus; > + DeviceState *dev; > + MemoryRegion *mmio_reg, *ecam_reg; > + LoongsonMachineState *s = LOONGSON_MACHINE(machine); > + > + dev = qdev_new(TYPE_GPEX_HOST); > + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); > + pci_bus = PCI_HOST_BRIDGE(dev)->bus; > + > + s->ecam_alias = g_new0(MemoryRegion, 1); > + ecam_reg = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0); > + memory_region_init_alias(s->ecam_alias, OBJECT(dev), "pcie-ecam", > + ecam_reg, 0, virt_memmap[VIRT_PCIE_ECAM].size); > + memory_region_add_subregion(get_system_memory(), > + virt_memmap[VIRT_PCIE_ECAM].base, > s->ecam_alias); > + > + s->mmio_alias = g_new0(MemoryRegion, 1); > + mmio_reg = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 1); > + memory_region_init_alias(s->mmio_alias, OBJECT(dev), "pcie-mmio", > + mmio_reg, virt_memmap[VIRT_PCIE_MMIO].base, > + virt_memmap[VIRT_PCIE_MMIO].size); > + memory_region_add_subregion(get_system_memory(), > + virt_memmap[VIRT_PCIE_MMIO].base, > s->mmio_alias); > + > + s->pio_alias = g_new0(MemoryRegion, 1); > + memory_region_init_alias(s->pio_alias, OBJECT(dev), "pcie-pio", > + get_system_io(), 0, > virt_memmap[VIRT_PCIE_PIO].size); > + memory_region_add_subregion(get_system_memory(), > + virt_memmap[VIRT_PCIE_PIO].base, > s->pio_alias); > + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, virt_memmap[VIRT_PCIE_PIO].base); > + > + for (i = 0; i < GPEX_NUM_IRQS; i++) { > + irq = qdev_get_gpio_in(pic, PCIE_IRQ_BASE + i); > + sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, irq); > + gpex_set_irq_num(GPEX_HOST(dev), i, PCIE_IRQ_BASE + i); > + } > + msi_nonbroken = true; > + > + pci_vga_init(pci_bus); > + > + if (defaults_enabled()) { > + pci_create_simple(pci_bus, -1, "pci-ohci"); > + usb_create_simple(usb_bus_find(-1), "usb-kbd"); > + usb_create_simple(usb_bus_find(-1), "usb-tablet"); > + } Configured using --without-default-devices I get: $ qemu-system-mips64el -M loongson3-virt -accel qtest ** ERROR:qom/object.c:711:object_new_with_type: assertion failed: (type != NULL) Bail out! ERROR:qom/object.c:711:object_new_with_type: assertion failed: (type != NULL) Aborted (core dumped) (gdb) bt #0 0x00007f97d73de9e5 in raise () at /lib64/libc.so.6 #1 0x00007f97d73c7895 in abort () at /lib64/libc.so.6 #2 0x00007f97d95aab6c in g_assertion_message_expr.cold () at /lib64/libglib-2.0.so.0 #3 0x00007f97d96089ff in g_assertion_message_expr () at /lib64/libglib-2.0.so.0 #4 0x00005563b44cb391 in object_new_with_type (type=<optimized out>) at qom/object.c:711 #5 0x00005563b44cb3e9 in object_new (typename=typename@entry=0x5563b469e139 "pci-ohci") at qom/object.c:744 #6 0x00005563b4570d86 in qdev_new (name=name@entry=0x5563b469e139 "pci-ohci") at hw/core/qdev.c:153 #7 0x00005563b4323d51 in pci_new_multifunction (devfn=devfn@entry=-1, multifunction=multifunction@entry=false, name=name@entry=0x5563b469e139 "pci-ohci") at hw/pci/pci.c:2178 #8 0x00005563b4324167 in pci_create_simple_multifunction (bus=bus@entry=0x5563b5150640, devfn=devfn@entry=-1, multifunction=multifunction@entry=false, name=name@entry=0x5563b469e139 "pci-ohci") at hw/pci/pci.c:2198 #9 0x00005563b432419a in pci_create_simple (bus=bus@entry=0x5563b5150640, devfn=devfn@entry=-1, name=name@entry=0x5563b469e139 "pci-ohci") at hw/pci/pci.c:2205 #10 0x00005563b436dc4c in loongson3_virt_devices_init (pic=0x5563b5100200, machine=<optimized out>) at hw/mips/loongson3_virt.c:455 #11 mips_loongson3_virt_init (machine=<optimized out>) at hw/mips/loongson3_virt.c:612 #12 0x00005563b42e9ebb in machine_run_board_init (machine=machine@entry=0x5563b4c80400) at hw/core/machine.c:1169 #13 0x00005563b44ab639 in qemu_init_board () at softmmu/vl.c:2455 #14 qmp_x_exit_preconfig (errp=<optimized out>) at softmmu/vl.c:2526 #15 qmp_x_exit_preconfig (errp=<optimized out>) at softmmu/vl.c:2519 #16 0x00005563b44af199 in qemu_init (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at softmmu/vl.c:3534 #17 0x00005563b41d0549 in main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at softmmu/main.c:49 But this works: $ qemu-system-mips64el -M loongson3-virt -accel qtest -nodefaults So I guess we are good. Paolo, shouldn't we abort() if configured using --without-default-devices but not using -nodefaults? That would avoid this kind of debugging. Thanks, Phil.