m68k: add Virtual M68k Machine
cover m68k: add Virtual M68k Machine
The Quadra 800 machine is very limited to run linux, it manages only 1 GiB of memory and only some specific interfaces.
The Virtual M68k Machine is based on Goldfish interfaces defined by Google for Android simulator. It uses Goldfish-rtc (timer and RTC), Goldfish-pic (PIC) and Goldfish-tty (for serial port and early tty).
https://android.googlesource.com/platform/external/qemu/+/master/docs/GOLDFIS=
H-VIRTUAL-HARDWARE.TXT
The machine is created with 128 virtio-mmio busses, and they can be used to add serial console, GPU, disk, NIC, HID, ...
This series re-use the goldfish-rtc implemented for RISCV, and adds the two others based on the goldfish specs, the kernel driver and android simulator ones.
The machine can manage up to 3.2 GiB of memory, not because of an hardware limitation but because the kernel crashes after this value.
Simply configure qemu with:
.../configure --target-list=3Dm68k-softmmu
To run the machine you need a modified kernel you can find here:
https://github.com/vivier/linux/tree/m68k-virt
You need to compile the kernel with:
make virt_defconfig
make vmlinux
The disk must be installed using the q800 machine because the debian installer doesn't want to be used with a kernel that is not the one on the ISO.
And then you can run the machine with something like:
qemu-system-m68k -M virt \
-m 3399672K \
-chardev stdio,signal=3Doff,mux=3Don,id=3Dchar0 \
-mon chardev=3Dchar0,mode=3Dreadline \
-kernel vmlinux \
-append "console=3Dhvc0 root=3D/dev/vda2" \
-blockdev node-name=3Dsystem,driver=3Dfile,filename=3Ddebian-10.0.qcow2 \
-blockdev node-name=3Ddrive0,driver=3Dqcow2,file=3Dsystem \
-device virtio-blk-device,drive=3Ddrive0 \
-serial chardev:char0 \
-device virtio-net-device,netdev=3Dhostnet0 \
-netdev bridge,id=3Dhostnet0,br=3Dvirbr0 \
-device virtio-rng-device \
-device virtio-serial-device \
-device virtio-gpu-device \
-device virtconsole,chardev=3Dchar0 \
-device virtio-keyboard-device \
-device virtio-mouse-device
if you want to use Goldfish-tty for the console rather than virtconsole, you can add "console=3DttyGF".
To start the debian-installer, you can try by adding:
-device virtio-scsi-device \
-blockdev node-name=3Ddebian10,driver=3Dfile,filename=3Ddebian-10.0.0-m68k-=
NETINST-1.iso \
-blockdev node-name=3Dcdrom0,driver=3Draw,file=3Ddebian10 \
-device scsi-cd,drive=3Dcdrom0 \
-initrd installer-m68k/20200315/images/cdrom/initrd.gz
ISO: https://cdimage.debian.org/cdimage/ports/snapshots/2020-10-12/debian-=
10.0.0-m68k-NETINST-1.iso
initrd: https://cdimage.debian.org/cdimage/ports/debian-installer/2020-10-12/=
m68k/debian-installer-images_20200315_m68k.tar.gz
I think there are some endianness issues with virtio-gpu, because when the X server starts I have some errors in the kernel logs:
vmap allocation for size 3149824 failed: use vmalloc=3D<size> to increase s=
ize
I also tried virtiofsd but there is also an endianness problem and the server stops.
Have Fun,
Laurent
PS:
By reading the message to the end you have won the right to download the disk=
image
and the vmlinux.
http://vivier.eu/debian-10.0.qcow2 343 MiB
http://vivier.eu/vmlinux-virt-m68k 5.2 MiB
Laurent Vivier (4):
m68k: import bootinfo headers from linux
char: add goldfish-tty
intc: add goldfish-pic
m68k: add Virtual M68k Machine
default-configs/devices/m68k-softmmu.mak | 1 + hw/m68k/bootinfo.h | 55 ---- include/hw/char/goldfish_tty.h | 36 +++ include/hw/intc/goldfish_pic.h | 28 ++ .../standard-headers/asm-m68k/bootinfo-mac.h | 120 +++++++ .../standard-headers/asm-m68k/bootinfo-virt.h | 17 + include/standard-headers/asm-m68k/bootinfo.h | 166 ++++++++++ hw/char/goldfish_tty.c | 265 ++++++++++++++++ hw/intc/goldfish_pic.c | 178 +++++++++++ hw/m68k/q800.c | 20 +- hw/m68k/virt.c | 296 ++++++++++++++++++ MAINTAINERS | 11 + hw/char/Kconfig | 3 + hw/char/meson.build | 2 + hw/char/trace-events | 9 + hw/intc/Kconfig | 3 + hw/intc/meson.build | 1 + hw/intc/trace-events | 8 + hw/m68k/Kconfig | 8 + hw/m68k/meson.build | 1 + 20 files changed, 1160 insertions(+), 68 deletions(-) create mode 100644 include/hw/char/goldfish_tty.h create mode 100644 include/hw/intc/goldfish_pic.h create mode 100644 include/standard-headers/asm-m68k/bootinfo-mac.h create mode 100644 include/standard-headers/asm-m68k/bootinfo-virt.h create mode 100644 include/standard-headers/asm-m68k/bootinfo.h create mode 100644 hw/char/goldfish_tty.c create mode 100644 hw/intc/goldfish_pic.c create mode 100644 hw/m68k/virt.c
--=20
2.26.2
PATCH 1/4 m68k: import bootinfo headers from linux
Copy bootinfo.h and bootinfo-mac.h from arch/m68k/include/uapi/asm/ to include/standard-headers/asm-m68k/
Imported from linx v5.9 but didn't change since v4.14 (header update) and since v4.10 (content update).
--- hw/m68k/bootinfo.h | 55 ------ .../standard-headers/asm-m68k/bootinfo-mac.h | 120 +++++++++++++ include/standard-headers/asm-m68k/bootinfo.h | 166 ++++++++++++++++++ hw/m68k/q800.c | 20 +-- MAINTAINERS | 2 + 5 files changed, 295 insertions(+), 68 deletions(-) create mode 100644 include/standard-headers/asm-m68k/bootinfo-mac.h create mode 100644 include/standard-headers/asm-m68k/bootinfo.h
hw/m68k/bootinfo.h +0 -55
@@ -11,61 +11,6 @@#ifndef HW_M68K_BOOTINFO_H #define HW_M68K_BOOTINFO_H -struct bi_record { -uint16_t tag;/* tag ID */ -uint16_t size;/* size of record */ -uint32_t data[];/* data */ -}; - -/* machine independent tags */ - -#define BI_LAST 0x0000/* last record */ -#define BI_MACHTYPE 0x0001/* machine type (u_long) */ -#define BI_CPUTYPE 0x0002/* cpu type (u_long) */ -#define BI_FPUTYPE 0x0003/* fpu type (u_long) */ -#define BI_MMUTYPE 0x0004/* mmu type (u_long) */ -#define BI_MEMCHUNK 0x0005/* memory chunk address and size */ -/* (struct mem_info) */ -#define BI_RAMDISK 0x0006/* ramdisk address and size */ -/* (struct mem_info) */ -#define BI_COMMAND_LINE 0x0007/* kernel command line parameters */ -/* (string) */ - -/* Macintosh-specific tags (all u_long) */ - -#define BI_MAC_MODEL 0x8000/* Mac Gestalt ID (model type) */ -#define BI_MAC_VADDR 0x8001/* Mac video base address */ -#define BI_MAC_VDEPTH 0x8002/* Mac video depth */ -#define BI_MAC_VROW 0x8003/* Mac video rowbytes */ -#define BI_MAC_VDIM 0x8004/* Mac video dimensions */ -#define BI_MAC_VLOGICAL 0x8005/* Mac video logical base */ -#define BI_MAC_SCCBASE 0x8006/* Mac SCC base address */ -#define BI_MAC_BTIME 0x8007/* Mac boot time */ -#define BI_MAC_GMTBIAS 0x8008/* Mac GMT timezone offset */ -#define BI_MAC_MEMSIZE 0x8009/* Mac RAM size (sanity check) */ -#define BI_MAC_CPUID 0x800a/* Mac CPU type (sanity check) */ -#define BI_MAC_ROMBASE 0x800b/* Mac system ROM base address */ - -/* Macintosh hardware profile data */ - -#define BI_MAC_VIA1BASE 0x8010/* Mac VIA1 base address (always present) */ -#define BI_MAC_VIA2BASE 0x8011/* Mac VIA2 base address (type varies) */ -#define BI_MAC_VIA2TYPE 0x8012/* Mac VIA2 type (VIA, RBV, OSS) */ -#define BI_MAC_ADBTYPE 0x8013/* Mac ADB interface type */ -#define BI_MAC_ASCBASE 0x8014/* Mac Apple Sound Chip base address */ -#define BI_MAC_SCSI5380 0x8015/* Mac NCR 5380 SCSI (base address, multi) */ -#define BI_MAC_SCSIDMA 0x8016/* Mac SCSI DMA (base address) */ -#define BI_MAC_SCSI5396 0x8017/* Mac NCR 53C96 SCSI (base address, multi) */ -#define BI_MAC_IDETYPE 0x8018/* Mac IDE interface type */ -#define BI_MAC_IDEBASE 0x8019/* Mac IDE interface base address */ -#define BI_MAC_NUBUS 0x801a/* Mac Nubus type (none, regular, pseudo) */ -#define BI_MAC_SLOTMASK 0x801b/* Mac Nubus slots present */ -#define BI_MAC_SCCTYPE 0x801c/* Mac SCC serial type (normal, IOP) */ -#define BI_MAC_ETHTYPE 0x801d/* Mac builtin ethernet type (Sonic, MACE */ -#define BI_MAC_ETHBASE 0x801e/* Mac builtin ethernet base address */ -#define BI_MAC_PMU 0x801f/* Mac power management / poweroff hardware */ -#define BI_MAC_IOP_SWIM 0x8020/* Mac SWIM floppy IOP */ -#define BI_MAC_IOP_ADB 0x8021/* Mac ADB IOP */ #define BOOTINFO0 (as, base, id) \ do { \
include/standard-headers/asm-m68k/bootinfo-mac.h new file +120 -0
120 lines not on this page · raw message
include/standard-headers/asm-m68k/bootinfo.h new file +166 -0
166 lines not on this page · raw message
hw/m68k/q800.c +7 -13
@@ -35,6 +35,8 @@#include "hw/char/escc.h" #include "hw/sysbus.h" #include "hw/scsi/esp.h" +#include "standard-headers/asm-m68k/bootinfo.h" +#include "standard-headers/asm-m68k/bootinfo-mac.h" #include "bootinfo.h" #include "hw/misc/mac_via.h" #include "hw/input/adb.h"
@@ -52,14 +54,6 @@#define MACROM_FILENAME "MacROM.bin" -#define Q800_MACHINE_ID 35 -#define Q800_CPU_ID (1 << 2) -#define Q800_FPU_ID (1 << 2) -#define Q800_MMU_ID (1 << 2) - -#define MACH_MAC 3 -#define Q800_MAC_CPU_ID 2 -#define IO_BASE 0x50000000#define IO_SLICE 0x00040000#define IO_SIZE 0x04000000
@@ -348,11 +342,11 @@ static void q800_init(MachineState *machine) parameters_base = (high +1 ) & ~1 ;BOOTINFO1 (cs->as, parameters_base,BI_MACHTYPE ,MACH_MAC ); -BOOTINFO1 (cs->as, parameters_base,BI_FPUTYPE ,Q800_FPU_ID ); -BOOTINFO1 (cs->as, parameters_base,BI_MMUTYPE ,Q800_MMU_ID ); -BOOTINFO1 (cs->as, parameters_base,BI_CPUTYPE ,Q800_CPU_ID ); -BOOTINFO1 (cs->as, parameters_base,BI_MAC_CPUID ,Q800_MAC_CPU_ID ); -BOOTINFO1 (cs->as, parameters_base,BI_MAC_MODEL ,Q800_MACHINE_ID ); +BOOTINFO1 (cs->as, parameters_base,BI_FPUTYPE ,FPU_68040 ); +BOOTINFO1 (cs->as, parameters_base,BI_MMUTYPE ,MMU_68040 ); +BOOTINFO1 (cs->as, parameters_base,BI_CPUTYPE ,CPU_68040 ); +BOOTINFO1 (cs->as, parameters_base,BI_MAC_CPUID ,CPUB_68040 ); +BOOTINFO1 (cs->as, parameters_base,BI_MAC_MODEL ,MAC_MODEL_Q800 );BOOTINFO1 (cs->as, parameters_base,BI_MAC_MEMSIZE , ram_size >>20 );/* in MB */ BOOTINFO2 (cs->as, parameters_base,BI_MEMCHUNK ,0 , ram_size);
MAINTAINERS +2 -0
@@ -1094,6 +1094,8 @@ F: hw/nubus/* F: hw/display/macfb.c F: hw/block/swim.c F: hw/m68k/bootinfo.h +F: include/standard-headers/asm-m68k/bootinfo.h +F: include/standard-headers/asm-m68k/bootinfo-mac.h F: include/hw/misc/mac_via.h F: include/hw/nubus/* F: include/hw/display/macfb.h
Signature · 1 line
2.26.2
PATCH 2/4 char: add goldfish-tty
In reply to Laurent Vivier--- include/hw/char/goldfish_tty.h | 36 +++++ hw/char/goldfish_tty.c | 265 +++++++++++++++++++++++++++++++++ hw/char/Kconfig | 3 + hw/char/meson.build | 2 + hw/char/trace-events | 9 ++ 5 files changed, 315 insertions(+) create mode 100644 include/hw/char/goldfish_tty.h create mode 100644 hw/char/goldfish_tty.c
include/hw/char/goldfish_tty.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* SPDX-License-Identifer: GPL-2.0-or-later +* +* Goldfish TTY +* +* (c) 2020 Laurent Vivier <[email protected]> +* +*/ + +#ifndef HW_CHAR_GOLDFISH_TTY_H +#define HW_CHAR_GOLDFISH_TTY_H + +#include "chardev/char-fe.h" + +#define TYPE_GOLDFISH_TTY "goldfish_tty" +OBJECT_DECLARE_SIMPLE_TYPE(GoldfishTTYState, GOLDFISH_TTY) + +#define GOLFISH_TTY_BUFFER_SIZE 128 + +struct GoldfishTTYState { +SysBusDevice parent_obj; + +MemoryRegion iomem; +qemu_irq irq; +CharBackend chr; + +uint32_t data_len; +uint64_t data_ptr; +bool int_enabled; + +uint32_t data_in_count; +uint8_t data_in[GOLFISH_TTY_BUFFER_SIZE ]; +uint8_t data_out[GOLFISH_TTY_BUFFER_SIZE ]; +}; + +#endif
hw/char/goldfish_tty.c new file +265 -0
265 lines not on this page · raw message
hw/char/Kconfig +3 -0
@@ -61,3 +61,6 @@ config MCHP_PFSOC_MMUART config SIFIVE_UART bool + +config GOLDFISH_TTY + bool
hw/char/meson.build +2 -0
@@ -39,3 +39,5 @@ specific_ss.add(when: 'CONFIG_HTIF', if_true: files('riscv_htif.c')) specific_ss.add(when: 'CONFIG_TERMINAL3270', if_true: files('terminal3270.c')) specific_ss.add(when: 'CONFIG_VIRTIO', if_true: files('virtio-serial-bus.c')) specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_vty.c')) + +specific_ss.add(when: 'CONFIG_GOLDFISH_TTY', if_true: files('goldfish_tty.c'))
hw/char/trace-events +9 -0
@@ -20,6 +20,15 @@ virtio_console_flush_buf(unsigned int port, size_t len, ssize_t ret) "port %u, i virtio_console_chr_read(unsigned int port, int size) "port %u, size %d" virtio_console_chr_event(unsigned int port, int event) "port %u, event %d" +# goldfish_tty.c +goldfish_tty_read(void *dev, unsigned int addr, unsigned int size, uint64_t value) "tty: %p reg: 0x%02x size: %d value: 0x%"PRIx64 +goldfish_tty_write(void *dev, unsigned int addr, unsigned int size, uint64_t value) "tty: %p reg: 0x%02x size: %d value: 0x%"PRIx64 +goldfish_tty_can_receive(void *dev, unsigned int available) "tty: %p available: %u" +goldfish_tty_receive(void *dev, unsigned int size) "tty: %p size: %u" +goldfish_tty_reset(void *dev) "tty: %p" +goldfish_tty_realize(void *dev) "tty: %p" +goldfish_tty_instance_init(void *dev) "tty: %p" + # grlib_apbuart.c grlib_apbuart_event(int event) "event:%d" grlib_apbuart_writel_unknown(uint64_t addr, uint32_t value) "addr 0x%"PRIx64" value 0x%x"
Signature · 1 line
2.26.2
PATCH 3/4 intc: add goldfish-pic
In reply to Laurent Vivier--- include/hw/intc/goldfish_pic.h | 28 ++++++ hw/intc/goldfish_pic.c | 178 +++++++++++++++++++++++++++++++++ hw/intc/Kconfig | 3 + hw/intc/meson.build | 1 + hw/intc/trace-events | 8 ++ 5 files changed, 218 insertions(+) create mode 100644 include/hw/intc/goldfish_pic.h create mode 100644 hw/intc/goldfish_pic.c
include/hw/intc/goldfish_pic.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* SPDX-License-Identifer: GPL-2.0-or-later +* +* Goldfish PIC +* +* (c) 2020 Laurent Vivier <[email protected]> +* +*/ + +#ifndef HW_INTC_GOLDFISH_PIC_H +#define HW_INTC_GOLDFISH_PIC_H + +#define TYPE_GOLDFISH_PIC "goldfish_pic" +OBJECT_DECLARE_SIMPLE_TYPE(GoldfishPICState, GOLDFISH_PIC) + +#define GOLDFISH_PIC_IRQ_NB 32 + +struct GoldfishPICState { +SysBusDevice parent_obj; + +MemoryRegion iomem; +qemu_irq irq; + +uint32_t pending; +uint32_t enabled; +}; + +#endif
hw/intc/goldfish_pic.c new file +178 -0
178 lines not on this page · raw message
hw/intc/Kconfig +3 -0
@@ -73,3 +73,6 @@ config SIFIVE_CLINT config SIFIVE_PLIC bool + +config GOLDFISH_PIC + bool
hw/intc/meson.build +1 -0
@@ -55,3 +55,4 @@ specific_ss.add(when: 'CONFIG_XICS_SPAPR', if_true: files('xics_spapr.c')) specific_ss.add(when: 'CONFIG_XIVE', if_true: files('xive.c')) specific_ss.add(when: 'CONFIG_XIVE_KVM', if_true: files('spapr_xive_kvm.c')) specific_ss.add(when: 'CONFIG_XIVE_SPAPR', if_true: files('spapr_xive.c')) +specific_ss.add(when: 'CONFIG_GOLDFISH_PIC', if_true: files('goldfish_pic.c'))
hw/intc/trace-events +8 -0
@@ -199,3 +199,11 @@ nvic_sysreg_write(uint64_t addr, uint32_t value, unsigned size) "NVIC sysreg wri heathrow_write(uint64_t addr, unsigned int n, uint64_t value) "0x%"PRIx64" %u: 0x%"PRIx64 heathrow_read(uint64_t addr, unsigned int n, uint64_t value) "0x%"PRIx64" %u: 0x%"PRIx64 heathrow_set_irq(int num, int level) "set_irq: num=0x%02x level=%d" + +# # goldfish_pic.c +goldfish_irq_request(void *dev, int irq, int level) "pic: %p irq: %d level: %d" +goldfish_pic_read(void *dev, unsigned int addr, unsigned int size, uint64_t value) "pic: %p reg: 0x%02x size: %d value: 0x%"PRIx64 +goldfish_pic_write(void *dev, unsigned int addr, unsigned int size, uint64_t value) "pic: %p reg: 0x%02x size: %d value: 0x%"PRIx64 +goldfish_pic_reset(void *dev) "pic: %p" +goldfish_pic_realize(void *dev) "pic: %p" +goldfish_pic_instance_init(void *dev) "pic: %p"
Signature · 1 line
2.26.2
PATCH 4/4 m68k: add Virtual M68k Machine
In reply to Laurent VivierThe machine is based on Goldfish interfaces defined by Google for Android simulator. It uses Goldfish-rtc (timer and RTC), Goldfish-pic (PIC) and Goldfish-tty (for serial port and early tty).
The machine is created with 128 virtio-mmio bus, and they can be used to use serial console, GPU, disk, NIC, HID, ...
--- default-configs/devices/m68k-softmmu.mak | 1 + .../standard-headers/asm-m68k/bootinfo-virt.h | 17 + hw/m68k/virt.c | 296 ++++++++++++++++++ MAINTAINERS | 9 + hw/m68k/Kconfig | 8 + hw/m68k/meson.build | 1 + 6 files changed, 332 insertions(+) create mode 100644 include/standard-headers/asm-m68k/bootinfo-virt.h create mode 100644 hw/m68k/virt.c
default-configs/devices/m68k-softmmu.mak +1 -0
@@ -8,3 +8,4 @@ CONFIG_AN5206=y CONFIG_MCF5208=y CONFIG_NEXTCUBE=y CONFIG_Q800=y +CONFIG_M68K_VIRT=y
include/standard-headers/asm-m68k/bootinfo-virt.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* +** asm/bootinfo-virt.h -- Virtual-m68k-specific boot information definitions +*/ + +#ifndef _UAPI_ASM_M68K_BOOTINFO_VIRT_H +#define _UAPI_ASM_M68K_BOOTINFO_VIRT_H + +#define BI_VIRT_QEMU_VERSION 0x8000 +#define BI_VIRT_GF_PIC_BASE 0x8001 +#define BI_VIRT_GF_RTC_BASE 0x8002 +#define BI_VIRT_GF_TTY_BASE 0x8003 +#define BI_VIRT_VIRTIO_BASE 0x8004 + +#define VIRT_BOOTI_VERSION MK_BI_VERSION(2, 0) + +#endif /* _UAPI_ASM_M68K_BOOTINFO_MAC_H */
hw/m68k/virt.c new file +296 -0
296 lines not on this page · raw message
MAINTAINERS +9 -0
@@ -1101,6 +1101,15 @@ F: include/hw/nubus/* F: include/hw/display/macfb.h F: include/hw/block/swim.h +virt +M: Laurent Vivier <[email protected]> +S: Maintained +F: hw/m68k/virt.c +F: hw/char/goldfish_tty.c +F: hw/intc/goldfish_pic.c +F: include/hw/char/goldfish_tty.h +F: include/hw/intc/goldfish_pic.h + MicroBlaze Machines ------------------- petalogix_s3adsp1800
hw/m68k/Kconfig +8 -0
@@ -22,3 +22,11 @@ config Q800 select ESCC select ESP select DP8393X + +config M68K_VIRT + bool + select GOLDFISH_PIC + select GOLDFISH_TTY + select GOLDFISH_RTC + select VIRTIO + select VIRTIO_MMIO
hw/m68k/meson.build +1 -0
@@ -3,5 +3,6 @@ m68k_ss.add(when: 'CONFIG_AN5206', if_true: files('an5206.c', 'mcf5206.c')) m68k_ss.add(when: 'CONFIG_MCF5208', if_true: files('mcf5208.c', 'mcf_intc.c')) m68k_ss.add(when: 'CONFIG_NEXTCUBE', if_true: files('next-kbd.c', 'next-cube.c')) m68k_ss.add(when: 'CONFIG_Q800', if_true: files('q800.c')) +m68k_ss.add(when: 'CONFIG_M68K_VIRT', if_true: files('virt.c')) hw_arch += {'m68k': m68k_ss}
Signature · 1 line
2.26.2
Quoted 134 lines · Laurent Vivier
The machine is based on Goldfish interfaces defined by Google for Android simulator. It uses Goldfish-rtc (timer and RTC), Goldfish-pic (PIC) and Goldfish-tty (for serial port and early tty).
The machine is created with 128 virtio-mmio bus, and they can be used to use serial console, GPU, disk, NIC, HID, ...
Signed-off-by Laurent Vivier <[email protected]>--- default-configs/devices/m68k-softmmu.mak | 1 + .../standard-headers/asm-m68k/bootinfo-virt.h | 17 + hw/m68k/virt.c | 296 ++++++++++++++++++ MAINTAINERS | 9 + hw/m68k/Kconfig | 8 + hw/m68k/meson.build | 1 + 6 files changed, 332 insertions(+)create mode 100644
include/standard-headers/asm-m68k/bootinfo-virt.hcreate mode 100644hw/m68k/virt.cdefault-configs/devices/m68k-softmmu.mak +1
-0@@ -8,3 +8,4 @@ CONFIG_AN5206=y CONFIG_MCF5208=y CONFIG_NEXTCUBE=y CONFIG_Q800=y +CONFIG_M68K_VIRT=yinclude/standard-headers/asm-m68k/bootinfo-virt.h new file +17
-0@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* +** asm/bootinfo-virt.h -- Virtual-m68k-specific boot information definitions +*/ + +#ifndef _UAPI_ASM_M68K_BOOTINFO_VIRT_H +#define _UAPI_ASM_M68K_BOOTINFO_VIRT_H + +#define BI_VIRT_QEMU_VERSION 0x8000 +#define BI_VIRT_GF_PIC_BASE 0x8001 +#define BI_VIRT_GF_RTC_BASE 0x8002 +#define BI_VIRT_GF_TTY_BASE 0x8003 +#define BI_VIRT_VIRTIO_BASE 0x8004 + +#define VIRT_BOOTI_VERSION MK_BI_VERSION(2, 0) + +#endif /* _UAPI_ASM_M68K_BOOTINFO_MAC_H */ hw/m68k/virt.c new file +77
-0@@ -0,0 +1,296 @@ +/* +* SPDX-License-Identifer: GPL-2.0-or-later +* +* QEMU Vitual M68K Machine +* +* (c) 2020 Laurent Vivier <[email protected]> +* +*/ + +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "qemu-common.h" +#include "sysemu/sysemu.h" +#include "cpu.h" +#include "hw/hw.h" +#include "hw/boards.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" +#include "elf.h" +#include "hw/loader.h" +#include "ui/console.h" +#include "exec/address-spaces.h" +#include "hw/sysbus.h" +#include "standard-headers/asm-m68k/bootinfo.h" +#include "standard-headers/asm-m68k/bootinfo-virt.h" +#include "bootinfo.h" +#include "net/net.h" +#include "qapi/error.h" +#include "sysemu/qtest.h" +#include "sysemu/runstate.h" +#include "sysemu/reset.h" + +#include "hw/char/goldfish_tty.h" +#include "hw/rtc/goldfish_rtc.h" +#include "hw/intc/goldfish_pic.h" +#include "hw/virtio/virtio-mmio.h" +#include "hw/virtio/virtio-blk.h" + +/* +* 6 goldfish-pic for CPU IRQ #1 to IRQ #6 +* CPU IRQ #1 -> PIC #1 +* IRQ #1 to IRQ #31 -> unused +* IRQ #32 -> goldfish-tty +* CPU IRQ #2 -> PIC #2 +* IRQ #1 to IRQ #32 -> virtio-mmio from 1 to 32 +* CPU IRQ #3 -> PIC #3 +* IRQ #1 to IRQ #32 -> virtio-mmio from 33 to 64 +* CPU IRQ #4 -> PIC #4 +* IRQ #1 to IRQ #32 -> virtio-mmio from 65 to 96 +* CPU IRQ #5 -> PIC #5 +* IRQ #1 to IRQ #32 -> virtio-mmio from 97 to 128 +* CPU IRQ #6 -> PIC #5 +* IRQ #1 -> goldfish-rtc +* IRQ #2 to IRQ #32 -> unused +* CPU IRQ #7 -> NMI +*/ + +#define PIC_IRQ_BASE (num) (8 + (num - 1) * 32) +#define PIC_IRQ (num, irq) (PIC_IRQ_BASE(num) + irq - 1) +#define PIC_GPIO (pic_irq) (qdev_get_gpio_in(pic_dev[(pic_irq - 8) / 32], \ + (pic_irq - 8) % 32)) + +#define VIRT_GF_PIC_MMIO_BASE 0xff000000/* MMIO: 0xff000000 - 0xff005fff */ +#define VIRT_GF_PIC_IRQ_BASE 1/* IRQ: #1 -> #6 */ + +/* 1 goldfish-rtc (and timer) */ +#define VIRT_GF_RTC_MMIO_BASE 0xff006000/* MMIO: 0xff006000 - 0xff006fff */ +#define VIRT_GF_RTC_IRQ_BASE PIC_IRQ(6, 1)/* PIC: #6, IRQ: #1 */ + +/* 1 goldfish-tty */ +#define VIRT_GF_TTY_MMIO_BASE 0xff007000/* MMIO: 0xff007000 - 0xff007000 */ +#define VIRT_GF_TTY_IRQ_BASE PIC_IRQ(1, 32)/* PIC: #1, IRQ: #32 */ +/* +* virtio-mmio size is 0x200 bytes +* we use 4 goldfish-pic to attach them, +* we can attach 32 virtio devices / goldfish-pic +* -> we can manage 32 * 4 = 128 virtio devices
hw/m68k/virt.c line 87
Quoted 10 lines
hw/m68k/virt.c new file +10
-0+*/ +#define VIRT_VIRTIO_MMIO_BASE 0xff010000/* MMIO: 0xff010000 - 0xff01ffff */ +#define VIRT_VIRTIO_IRQ_BASE PIC_IRQ(2, 1)/* PIC: 2, 3, 4, 5, IRQ: ALL */ + +/* +* The GLUE (General Logic Unit) is an Apple custom integrated circuit chip +* that performs a variety of functions (RAM management, clock generation, ...). +* The GLUE chip receives interrupt requests from various devices, +* assign priority to each, and asserts one or more interrupt line to the +* CPU.
Does your virt machine really requires a GLUE? Or only another cascaded PIC?
Quoted 60 lines
hw/m68k/virt.c new file +60
-0+*/ + +typedef struct { +M68kCPU *cpu; +uint8_t ipr; +}GLUEState ; + +static void GLUE_set_irq (void *opaque,int irq,int level) +{ +GLUEState *s = opaque; +int i; + +if (level) { + s->ipr |=1 << irq; + }else { + s->ipr &= ~(1 << irq); + } + +for (i =7 ; i >=0 ; i--) { +if ((s->ipr >> i) &1 ) { +m68k_set_irq_level (s->cpu, i +1 , i +25 ); +return ; + } + } +m68k_set_irq_level (s->cpu,0 ,0 ); +} + +static void main_cpu_reset (void *opaque) +{ +M68kCPU *cpu = opaque; +CPUState *cs =CPU (cpu); + +cpu_reset (cs); + cpu->env.aregs[7 ] =ldl_phys (cs->as,0 ); + cpu->env.pc =ldl_phys (cs->as,4 ); +} + +static void virt_init (MachineState *machine) +{ +M68kCPU *cpu =NULL ; +int32_t kernel_size; +uint64_t elf_entry; +ram_addr_t initrd_base; +int32_t initrd_size; +ram_addr_t ram_size = machine->ram_size; +const char *kernel_filename = machine->kernel_filename; +const char *initrd_filename = machine->initrd_filename; +const char *kernel_cmdline = machine->kernel_cmdline; +hwaddr parameters_base; +DeviceState *dev; +DeviceState *pic_dev[7 ]; +GLUEState *irq; +qemu_irq *cpu_pic; +SysBusDevice *sysbus; +hwaddr io_base; +int i; + + +if (ram_size >3399672 * KiB) { +/*
hw/m68k/virt.c line 157
Quoted 10 lines
hw/m68k/virt.c new file +10
-0+* The physical memory can be up to 4 GiB - 16 MiB, but linux +* kernel crashes after this limit (~ 3.2 GiB) +*/ +error_report ("Too much memory for this machine: %" PRId64" KiB, " +"maximum 3399672 KiB" , ram_size / KiB); +exit (1 ); + } + +/* init CPUs */ + cpu =M68K_CPU (cpu_create (machine->cpu_type));
Due to BOOTINFO1(..., BI_CPUTYPE, CPU_68040) below, don't you need to check machine->cpu_type == M68K_CPU_TYPE_NAME("m68040")?
Quoted 65 lines
hw/m68k/virt.c new file +65
-0+qemu_register_reset (main_cpu_reset, cpu); + +/* RAM */ +memory_region_add_subregion (get_system_memory (),0 , machine->ram); + +/* IRQ Glue */ + + irq =g_new0 (GLUEState,1 ); + irq->cpu = cpu; + cpu_pic =qemu_allocate_irqs (GLUE_set_irq, irq,8 ); + +/* +* 6 goldfish-pic +* +* map: 0xff000000 - 0xff006fff = 28 KiB +* IRQ: #1 (lower priority) -> #6 (higher priority) +* +*/ + io_base =VIRT_GF_PIC_MMIO_BASE ; +for (i =0 ; i <6 ; i++) { + pic_dev[i] =qdev_new (TYPE_GOLDFISH_PIC ); + sysbus =SYS_BUS_DEVICE (pic_dev[i]); +sysbus_realize_and_unref (sysbus, &error_fatal); + +sysbus_mmio_map (sysbus,0 , io_base); +sysbus_connect_irq (sysbus,0 , cpu_pic[i]); + + io_base +=0x1000 ; + } + +/* goldfish-rtc */ + dev =qdev_new (TYPE_GOLDFISH_RTC ); + sysbus =SYS_BUS_DEVICE (dev); +sysbus_realize_and_unref (sysbus, &error_fatal); +sysbus_mmio_map (sysbus,0 ,VIRT_GF_RTC_MMIO_BASE ); +sysbus_connect_irq (sysbus,0 ,PIC_GPIO (VIRT_GF_RTC_IRQ_BASE )); + +/* goldfish-tty */ + dev =qdev_new (TYPE_GOLDFISH_TTY ); + sysbus =SYS_BUS_DEVICE (dev); +qdev_prop_set_chr (dev,"chardev" ,serial_hd (0 )); +sysbus_realize_and_unref (sysbus, &error_fatal); +sysbus_mmio_map (sysbus,0 ,VIRT_GF_TTY_MMIO_BASE ); +sysbus_connect_irq (sysbus,0 ,PIC_GPIO (VIRT_GF_TTY_IRQ_BASE )); + +/* virtio-mmio */ + io_base =VIRT_VIRTIO_MMIO_BASE ; +for (i =0 ; i <128 ; i++) { + dev =qdev_new (TYPE_VIRTIO_MMIO ); +qdev_prop_set_bit (dev,"force-legacy" , false); + sysbus =SYS_BUS_DEVICE (dev); +sysbus_realize_and_unref (sysbus, &error_fatal); +sysbus_connect_irq (sysbus,0 ,PIC_GPIO (VIRT_VIRTIO_IRQ_BASE + i)); +sysbus_mmio_map (sysbus,0 , io_base); + io_base +=0x200 ; + } + +if (kernel_filename) { +CPUState *cs =CPU (cpu); +uint64_t high; + + kernel_size =load_elf (kernel_filename,NULL ,NULL ,NULL , + &elf_entry,NULL , &high,NULL ,1 , +EM_68K ,0 ,0 ); +if (kernel_size <0 ) {
hw/m68k/virt.c line 232
Quoted 10 lines
hw/m68k/virt.c new file +10
-0+error_report ("could not load kernel '%s'" , kernel_filename); +exit (1 ); + } +stl_phys (cs->as,4 , elf_entry);/* reset initial PC */ + parameters_base = (high +1 ) & ~1 ; + +BOOTINFO1 (cs->as, parameters_base,BI_MACHTYPE ,MACH_VIRT ); +BOOTINFO1 (cs->as, parameters_base,BI_FPUTYPE ,FPU_68040 ); +BOOTINFO1 (cs->as, parameters_base,BI_MMUTYPE ,MMU_68040 ); +BOOTINFO1 (cs->as, parameters_base,BI_CPUTYPE ,CPU_68040 );
(see machine->cpu_type question earlier).
Quoted 69 lines
hw/m68k/virt.c new file +64
-0+BOOTINFO2 (cs->as, parameters_base,BI_MEMCHUNK ,0 , ram_size); + +BOOTINFO1 (cs->as, parameters_base,BI_VIRT_QEMU_VERSION , + ((QEMU_VERSION_MAJOR <<24 ) | (QEMU_VERSION_MICRO <<16 ) | + (QEMU_VERSION_MINOR <<8 ))); +BOOTINFO2 (cs->as, parameters_base,BI_VIRT_GF_PIC_BASE , +VIRT_GF_PIC_MMIO_BASE ,VIRT_GF_PIC_IRQ_BASE ); +BOOTINFO2 (cs->as, parameters_base,BI_VIRT_GF_RTC_BASE , +VIRT_GF_RTC_MMIO_BASE ,VIRT_GF_RTC_IRQ_BASE ); +BOOTINFO2 (cs->as, parameters_base,BI_VIRT_GF_TTY_BASE , +VIRT_GF_TTY_MMIO_BASE ,VIRT_GF_TTY_IRQ_BASE ); +BOOTINFO2 (cs->as, parameters_base,BI_VIRT_VIRTIO_BASE , +VIRT_VIRTIO_MMIO_BASE ,VIRT_VIRTIO_IRQ_BASE ); + +if (kernel_cmdline) { +BOOTINFOSTR (cs->as, parameters_base,BI_COMMAND_LINE , + kernel_cmdline); + } + +/* load initrd */ +if (initrd_filename) { + initrd_size =get_image_size (initrd_filename); +if (initrd_size <0 ) { +error_report ("could not load initial ram disk '%s'" , + initrd_filename); +exit (1 ); + } + + initrd_base = (ram_size - initrd_size) &TARGET_PAGE_MASK ; +load_image_targphys (initrd_filename, initrd_base, + ram_size - initrd_base); +BOOTINFO2 (cs->as, parameters_base,BI_RAMDISK , initrd_base, + initrd_size); + }else { + initrd_base =0 ; + initrd_size =0 ; + } +BOOTINFO0 (cs->as, parameters_base,BI_LAST ); + } +} + +static void virt_machine_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + mc->desc ="M68k Virtual Machine" ; + mc->init = virt_init; + mc->default_cpu_type =M68K_CPU_TYPE_NAME ("m68040" ); + mc->max_cpus =1 ; + mc->block_default_type =IF_SCSI ; + mc->default_ram_id ="m68k_virt.ram" ; +} + +static const TypeInfo virt_machine_typeinfo = { + .name =MACHINE_TYPE_NAME ("virt" ), + .parent =TYPE_MACHINE , + .class_init = virt_machine_class_init, +}; + +static void virt_machine_register_types (void ) +{ +type_register_static (&virt_machine_typeinfo); +} + +type_init (virt_machine_register_types)MAINTAINERS +0
-0
MAINTAINERS F: include/hw/nubus/* · line 1104
Quoted 4 lines
MAINTAINERS +1
-0@@ -1101,6 +1101,15 @@ F: include/hw/nubus/* F: include/hw/display/macfb.h F: include/hw/block/swim.h +virt
Maybe "m68k virt".
Quoted 39 lines
MAINTAINERS +8
-0+M: Laurent Vivier <[email protected]> +S: Maintained +F: hw/m68k/virt.c +F: hw/char/goldfish_tty.c +F: hw/intc/goldfish_pic.c +F: include/hw/char/goldfish_tty.h +F: include/hw/intc/goldfish_pic.h + MicroBlaze Machines ------------------- petalogix_s3adsp1800hw/m68k/Kconfig +8
-0@@ -22,3 +22,11 @@ config Q800 select ESCC select ESP select DP8393X + +config M68K_VIRT + bool + select GOLDFISH_PIC + select GOLDFISH_TTY + select GOLDFISH_RTC + select VIRTIO + select VIRTIO_MMIOhw/m68k/meson.build +1
-0@@ -3,5 +3,6 @@ m68k_ss.add(when: 'CONFIG_AN5206', if_true: files('an5206.c', 'mcf5206.c')) m68k_ss.add(when: 'CONFIG_MCF5208', if_true: files('mcf5208.c', 'mcf_intc.c')) m68k_ss.add(when: 'CONFIG_NEXTCUBE', if_true: files('next-kbd.c', 'next-cube.c')) m68k_ss.add(when: 'CONFIG_Q800', if_true: files('q800.c')) +m68k_ss.add(when: 'CONFIG_M68K_VIRT', if_true: files('virt.c')) hw_arch += {'m68k': m68k_ss}
Le 13/10/2020 à 19:56, Philippe Mathieu-Daudé a écrit :
Quoted 19 lines · Laurent Vivier
Quoted 18 lines
The machine is based on Goldfish interfaces defined by Google for Android simulator. It uses Goldfish-rtc (timer and RTC), Goldfish-pic (PIC) and Goldfish-tty (for serial port and early tty).
The machine is created with 128 virtio-mmio bus, and they can be used to use serial console, GPU, disk, NIC, HID, ...
Signed-off-by Laurent Vivier <[email protected]>---
default-configs/devices/m68k-softmmu.mak | 1 +.../standard-headers/asm-m68k/bootinfo-virt.h| 17 + hw/m68k/virt.c | 296 ++++++++++++++++++ MAINTAINERS | 9 + hw/m68k/Kconfig | 8 + hw/m68k/meson.build | 1 +6 files changed, 332 insertions(+)create mode 100644
include/standard-headers/asm-m68k/bootinfo-virt.hcreate mode 100644hw/m68k/virt.c
...
Quoted 10 lines
Quoted 9 lines
+/*
+ * The GLUE (General Logic Unit) is an Apple custom integrated circuit chip
+ * that performs a variety of functions (RAM management, clock generation, ...).
+ * The GLUE chip receives interrupt requests from various devices,
+ * assign priority to each, and asserts one or more interrupt line to the
+ * CPU.
Quoted 2 lines
Does your virt machine really requires a GLUE? Or only another cascaded PIC?
I agree code needs cleanup here.
We need something to set the ÌRQ level (priority) and vector (see m68k_set_irq_level()).
Quoted 66 lines
Quoted 66 lines
+ */
hw/m68k/virt.c new file +63
-0+ +typedef struct { + M68kCPU *cpu; + uint8_t ipr; +}GLUEState ; + +static void GLUE_set_irq (void *opaque,int irq,int level) +{ + GLUEState *s = opaque; + int i; + + if (level) { + s->ipr |= 1 << irq; + } else { + s->ipr &= ~(1 << irq); + } + + for (i = 7; i >= 0; i--) { + if ((s->ipr >> i) & 1) { + m68k_set_irq_level(s->cpu, i + 1, i + 25); + return; + } + } + m68k_set_irq_level(s->cpu, 0, 0); +} + +static void main_cpu_reset (void *opaque) +{ + M68kCPU *cpu = opaque; + CPUState *cs = CPU(cpu); + + cpu_reset(cs); + cpu->env.aregs[7] = ldl_phys(cs->as, 0); + cpu->env.pc = ldl_phys(cs->as, 4); +} + +static void virt_init(MachineState *machine) +{ + M68kCPU *cpu = NULL; + int32_t kernel_size; + uint64_t elf_entry; + ram_addr_t initrd_base; + int32_t initrd_size; + ram_addr_t ram_size = machine->ram_size; + const char *kernel_filename = machine->kernel_filename; + const char *initrd_filename = machine->initrd_filename; + const char *kernel_cmdline = machine->kernel_cmdline; + hwaddr parameters_base; + DeviceState *dev; + DeviceState *pic_dev[7]; + GLUEState *irq; + qemu_irq *cpu_pic; + SysBusDevice *sysbus; + hwaddr io_base; + int i; + + + if (ram_size > 3399672 * KiB) { + /* + * The physical memory can be up to 4 GiB - 16 MiB, but linux + * kernel crashes after this limit (~ 3.2 GiB) + */ + error_report("Too much memory for this machine: %" PRId64 "KiB, "
+ "maximum 3399672 KiB",ram_size/ KiB);
Quoted 8 lines
Quoted 5 lines
+ exit(1);
+ }
+
+ /* init CPUs */
+ cpu = M68K_CPU(cpu_create(machine->cpu_type));Due to
BOOTINFO1(..., BI_CPUTYPE, CPU_68040)below, don't you need to checkmachine->cpu_type==M68K_CPU_TYPE_NAME("m68040")?
Yes, you're right.
68030MMU is not implemented. So we can't use other CPU than 68040.
Quoted 71 lines
Quoted 71 lines
+
qemu_register_reset(main_cpu_reset, cpu);hw/m68k/virt.c new file +52
-0+ + /* RAM */ + memory_region_add_subregion(get_system_memory(), 0, machine->ram); + + /* IRQ Glue */ + + irq = g_new0(GLUEState, 1); + irq->cpu = cpu; + cpu_pic = qemu_allocate_irqs(GLUE_set_irq, irq, 8); + + /* + * 6 goldfish-pic + * + * map: 0xff000000 - 0xff006fff = 28 KiB + * IRQ: #1 (lower priority) -> #6 (higher priority) + * + */ + io_base = VIRT_GF_PIC_MMIO_BASE; + for (i = 0; i < 6; i++) { + pic_dev[i] = qdev_new(TYPE_GOLDFISH_PIC); + sysbus = SYS_BUS_DEVICE(pic_dev[i]); + sysbus_realize_and_unref(sysbus, &error_fatal); + + sysbus_mmio_map(sysbus, 0, io_base); + sysbus_connect_irq(sysbus, 0, cpu_pic[i]); + + io_base += 0x1000; + } + + /* goldfish-rtc */ + dev = qdev_new(TYPE_GOLDFISH_RTC); + sysbus = SYS_BUS_DEVICE(dev); + sysbus_realize_and_unref(sysbus, &error_fatal); + sysbus_mmio_map(sysbus, 0, VIRT_GF_RTC_MMIO_BASE); + sysbus_connect_irq(sysbus, 0, PIC_GPIO(VIRT_GF_RTC_IRQ_BASE)); + + /* goldfish-tty */ + dev = qdev_new(TYPE_GOLDFISH_TTY); + sysbus = SYS_BUS_DEVICE(dev); + qdev_prop_set_chr(dev, "chardev", serial_hd(0)); + sysbus_realize_and_unref(sysbus, &error_fatal); + sysbus_mmio_map(sysbus, 0, VIRT_GF_TTY_MMIO_BASE); + sysbus_connect_irq(sysbus, 0, PIC_GPIO(VIRT_GF_TTY_IRQ_BASE)); + + /* virtio-mmio */ + io_base = VIRT_VIRTIO_MMIO_BASE; + for (i = 0; i < 128; i++) { + dev = qdev_new(TYPE_VIRTIO_MMIO); + qdev_prop_set_bit(dev, "force-legacy", false); + sysbus = SYS_BUS_DEVICE(dev); + sysbus_realize_and_unref(sysbus, &error_fatal); + sysbus_connect_irq(sysbus, 0, PIC_GPIO(VIRT_VIRTIO_IRQ_BASE +i));
+sysbus_mmio_map(sysbus, 0, io_base);
+io_base+=0x200;
+ }hw/m68k/virt.c new file +13
-0+ + if (kernel_filename) { + CPUState *cs = CPU(cpu); + uint64_t high; + + kernel_size = load_elf(kernel_filename, NULL, NULL, NULL, + &elf_entry, NULL, &high, NULL, 1, + EM_68K, 0, 0); + if (kernel_size < 0) { + error_report("could not load kernel '%s'", kernel_filename); + exit(1); + } + stl_phys(cs->as, 4, elf_entry); /* reset initial PC */
Quoted 8 lines
Quoted 6 lines
+
parameters_base= (high + 1) & ~1;
+
+BOOTINFO1(cs->as, parameters_base, BI_MACHTYPE, MACH_VIRT); +BOOTINFO1(cs->as, parameters_base, BI_FPUTYPE, FPU_68040); +BOOTINFO1(cs->as, parameters_base, BI_MMUTYPE, MMU_68040); +BOOTINFO1(cs->as, parameters_base, BI_CPUTYPE, CPU_68040);(see
machine->cpu_typequestion earlier).
see answer above.
Quoted 10 lines
Quoted 8 lines
MAINTAINERS +0
-0@@ -1101,6 +1101,15 @@ F: include/hw/nubus/*F:
include/hw/display/macfb.h
F:include/hw/block/swim.h
+virtMaybe "m68k virt".
We have "virt" only for ARM, RISCV, Xtensa, ...
the m68k is implied by the qemu-system-m68k
Quoted 9 lines
MAINTAINERS F: include/hw/nubus/* · line 1112
Quoted 9 lines
MAINTAINERS +8
-0+M: Laurent Vivier <[email protected]> +S: Maintained +F: hw/m68k/virt.c +F: hw/char/goldfish_tty.c +F: hw/intc/goldfish_pic.c +F: include/hw/char/goldfish_tty.h +F: include/hw/intc/goldfish_pic.h +
Thanks,
Laurent