hw/m68k: add Apple Machintosh Quadra 800 machine
v3 cover hw/m68k: add Apple Machintosh Quadra 800 machine
I'm rebasing some of these patches for seven years now, too many years...
if you want to test the machine, I'm sorry, it doesn't boot a MacROM, but you can boot a linux kernel from the command line.
You can install your own disk using debian-installer, with:
...
-M q800 \
-serial none -serial mon:stdio \
-m 1000M -drive file=m68k.qcow2,format=qcow2 \
-net nic,model=dp83932,addr=09:00:07:12:34:57 \
-append "console=ttyS0 vga=off" \
-kernel vmlinux-4.15.0-2-m68k \
-initrd initrd.gz \
-drive file=debian-9.0-m68k-NETINST-1.iso \
-drive file=m68k.qcow2,format=qcow2 \
-nographicIf you use a graphic adapter instead of "-nographic", you can use "-g" to set the size of the display (I use "-g 1600x800x24").
You can get the ISO from:
https://cdimage.debian.org/mirror/cdimage/ports/9.0/m68k/iso-cd/debian-9.0-m68k-NETINST-1.iso
and extract the kernel and initrd.gz:
guestfish --add debian-9.0-m68k-NETINST-1.iso --ro \
--mount /dev/sda:/ <<_EOF_copy-out /install/cdrom/initrd.gz .
copy-out /install/kernels/vmlinux-4.15.0-2-m68k .
_EOF_
The mirror to use is: http://ftp.ports.debian.org/debian-ports/
when it fails, continue without boot loader.
In the same way, you can extract the kernel and the initramfs from the qcow2 image to use it with "-kernel" and "-initrd":
guestfish --add m68k.qcow2 --mount /dev/sda2:/ <<_EOF_ copy-out /boot/vmlinux-4.15.0-2-m68k . copy-out /boot/initrd.img-4.15.0-2-m68k . _EOF_
and boot with:
... -append "root=/dev/sda2 rw console=ttyS0 console=tty \ -kernel vmlinux-4.15.0-2-m68k \ -initrd initrd.img-4.15.0-2-m68k
v3: fix subject prefix "C" -> "RFC"
v2: remove the dp8393x fixes, because one of the patch breaks something
Update "dp8393x: manage big endian bus" with idea from Thomas Mark has reworked most of the patches:
- use mos6522
- some code move, renamings and cleanup
Laurent Vivier (10):
hw/m68k: add via support
ADB: VIA probes ADB bus when it is idle
escc: introduce a selector for the register bit
hw/m68k: add video card
hw/m68k: Apple Sound Chip (ASC) emulation
ESP: add pseudo-DMA as used by Macintosh
hw/m68k: add Nubus support
hw/m68k: add a dummy SWIM floppy controller
dp8393x: manage big endian bus
hw/m68k: define Macintosh Quadra 800
MAINTAINERS | 19 + arch_init.c | 4 + default-configs/m68k-softmmu.mak | 14 + hw/Makefile.objs | 1 + hw/audio/Makefile.objs | 1 + hw/audio/asc.c | 463 +++++++++++++++++++++++ hw/block/Makefile.objs | 1 + hw/block/swim.c | 284 ++++++++++++++ hw/char/escc.c | 30 +- hw/display/Makefile.objs | 1 + hw/display/macfb-template.h | 158 ++++++++ hw/display/macfb.c | 308 +++++++++++++++ hw/input/adb-kbd.c | 4 + hw/input/adb-mouse.c | 4 + hw/input/adb.c | 115 ++++++ hw/intc/Makefile.objs | 1 + hw/intc/q800_irq.c | 73 ++++ hw/m68k/Makefile.objs | 6 +- hw/m68k/bootinfo.h | 100 +++++ hw/m68k/q800.c | 385 +++++++++++++++++++ hw/mips/mips_jazz.c | 2 +- hw/misc/Makefile.objs | 1 + hw/misc/mac_via.c | 731 ++++++++++++++++++++++++++++++++++++ hw/net/dp8393x.c | 88 +++-- hw/nubus/Makefile.objs | 4 + hw/nubus/mac-nubus-bridge.c | 45 +++ hw/nubus/nubus-bridge.c | 34 ++ hw/nubus/nubus-bus.c | 111 ++++++ hw/nubus/nubus-device.c | 210 +++++++++++ hw/scsi/esp.c | 297 +++++++++++++-- include/hw/audio/asc.h | 48 +++ include/hw/block/swim.h | 53 +++ include/hw/char/escc.h | 1 + include/hw/display/macfb.h | 63 ++++ include/hw/input/adb.h | 10 + include/hw/intc/q800_irq.h | 39 ++ include/hw/misc/mac_via.h | 107 ++++++ include/hw/nubus/mac-nubus-bridge.h | 24 ++ include/hw/nubus/nubus.h | 69 ++++ include/hw/scsi/esp.h | 11 +- qemu-options.hx | 2 +- tests/qom-test.c | 5 + tests/test-hmp.c | 3 +- vl.c | 3 +- 44 files changed, 3857 insertions(+), 76 deletions(-) create mode 100644 hw/audio/asc.c create mode 100644 hw/block/swim.c create mode 100644 hw/display/macfb-template.h create mode 100644 hw/display/macfb.c create mode 100644 hw/intc/q800_irq.c create mode 100644 hw/m68k/bootinfo.h create mode 100644 hw/m68k/q800.c create mode 100644 hw/misc/mac_via.c create mode 100644 hw/nubus/Makefile.objs create mode 100644 hw/nubus/mac-nubus-bridge.c create mode 100644 hw/nubus/nubus-bridge.c create mode 100644 hw/nubus/nubus-bus.c create mode 100644 hw/nubus/nubus-device.c create mode 100644 include/hw/audio/asc.h create mode 100644 include/hw/block/swim.h create mode 100644 include/hw/display/macfb.h create mode 100644 include/hw/intc/q800_irq.h create mode 100644 include/hw/misc/mac_via.h create mode 100644 include/hw/nubus/mac-nubus-bridge.h create mode 100644 include/hw/nubus/nubus.h
Signature · 1 line
2.14.4
RFC v3 1/10 hw/m68k: add via support
--- hw/misc/Makefile.objs | 1 + hw/misc/mac_via.c | 675 ++++++++++++++++++++++++++++++++++++++++++++++ include/hw/misc/mac_via.h | 106 ++++++++ 3 files changed, 782 insertions(+) create mode 100644 hw/misc/mac_via.c create mode 100644 include/hw/misc/mac_via.h
hw/misc/Makefile.objs +1 -0
@@ -70,5 +70,6 @@ obj-$(CONFIG_PVPANIC) += pvpanic.o obj-$(CONFIG_HYPERV_TESTDEV) += hyperv_testdev.o obj-$(CONFIG_AUX) += auxbus.o obj-$(CONFIG_ASPEED_SOC) += aspeed_scu.o aspeed_sdmc.o +obj-$(CONFIG_MAC_VIA) += mac_via.o obj-y += mmio_interface.o obj-$(CONFIG_MSF2) += msf2-sysreg.o
hw/misc/mac_via.c new file +675 -0
675 lines not on this page · raw message
include/hw/misc/mac_via.h new file +106 -0
106 lines not on this page · raw message
Signature · 1 line
2.14.4
RFC v3 2/10 ADB: VIA probes ADB bus when it is idle
In reply to Laurent Vivier--- hw/input/adb-kbd.c | 4 ++ hw/input/adb-mouse.c | 4 ++ hw/input/adb.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++ hw/misc/mac_via.c | 56 ++++++++++++++++++++++ include/hw/input/adb.h | 10 ++++ include/hw/misc/mac_via.h | 1 + 6 files changed, 190 insertions(+)
hw/input/adb-kbd.c +4 -0
@@ -195,6 +195,10 @@ static int adb_kbd_poll(ADBDevice *d, uint8_t *obuf)int keycode;int olen; +if (obuf ==NULL ) { +return s->count; + } + olen =0 ;if (s->count ==0 ) {return 0 ;
hw/input/adb-mouse.c +4 -0
@@ -73,6 +73,10 @@ static int adb_mouse_poll(ADBDevice *d, uint8_t *obuf)return 0 ; } +if (obuf ==NULL ) { +return 2 ; + } + dx = s->dx;if (dx <-63 ) { dx =-63 ;
hw/input/adb.c +115 -0
127 lines not on this page · raw message
hw/misc/mac_via.c +56 -0
86 lines not on this page · raw message
include/hw/input/adb.h +10 -0
@@ -76,6 +76,12 @@ struct ADBBusState {ADBDevice *devices[MAX_ADB_DEVICES ];int nb_devices;int poll_index; +qemu_irq data_ready; +int data_in_size; +int data_in_index; +int data_out_index; +uint8_t data_in[128 ]; +uint8_t data_out[16 ]; }; int adb_request(ADBBusState *s, uint8_t *buf_out,
@@ -85,4 +91,8 @@ int adb_poll(ADBBusState *s, uint8_t *buf_out, uint16_t poll_mask);#define TYPE_ADB_KEYBOARD "adb-keyboard"#define TYPE_ADB_MOUSE "adb-mouse" +int adb_via_poll (ADBBusState *s,int state,uint8_t *data); +int adb_send (ADBBusState *adb,int state,uint8_t data); +int adb_receive (ADBBusState *adb,int state,uint8_t *data); +#endif /* ADB_H */
include/hw/misc/mac_via.h +1 -0
@@ -96,6 +96,7 @@ typedef struct MacVIAState {/* ADB */ ADBBusState adb_bus; +QEMUTimer *adb_poll_timer;/* external timers */ QEMUTimer *one_second_timer;
Signature · 1 line
2.14.4
Re: [Qemu-devel] [RFC v3 02/10] ADB: VIA probes ADB bus when it is idle
Quoted 32 lines · * Laurent Vivier ([email protected]) wrote:
Co-developed-by Mark Cave-Ayland <[email protected]>Signed-off-by Mark Cave-Ayland <[email protected]>Signed-off-by Laurent Vivier <[email protected]>--- hw/input/adb-kbd.c | 4 ++ hw/input/adb-mouse.c | 4 ++ hw/input/adb.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++ hw/misc/mac_via.c | 56 ++++++++++++++++++++++ include/hw/input/adb.h | 10 ++++ include/hw/misc/mac_via.h | 1 + 6 files changed, 190 insertions(+)hw/input/adb-kbd.c +4
-0@@ -195,6 +195,10 @@ static int adb_kbd_poll(ADBDevice *d, uint8_t *obuf)int keycode;int olen; +if (obuf ==NULL ) { +return s->count; + } + olen =0 ;if (s->count ==0 ) {return 0 ;hw/input/adb-mouse.c +0
-0
hw/input/adb-mouse.c static int adb_mouse_poll(ADBDevice *d, uint8_t *obuf) · line 79
Quoted 7 lines
hw/input/adb-mouse.c +4
-0@@ -73,6 +73,10 @@ static int adb_mouse_poll(ADBDevice *d, uint8_t *obuf)return 0 ; } +if (obuf ==NULL ) { +return 2 ; + } +
I guess that's not entirely obvious; but I guess
what you're doing is returning the amount that would be returned if someone passed you a buffer to return it in.
Quoted 8 lines
hw/input/adb-mouse.c +0
-0dx = s->dx;if (dx <-63 ) { dx =-63 ;hw/input/adb.c +0
-0
hw/input/adb.c line 30
Quoted 6 lines
hw/input/adb.c +3
-0@@ -25,6 +25,17 @@#include "hw/input/adb.h" #include "adb-internal.h" +#define ADB_POLL_FREQ 50 + +/* Apple Macintosh Family Hardware Refenece
^^^^
typo
Quoted 46 lines
hw/input/adb.c +39
-0+* Table 19-10 ADB transaction states +*/ + +#define STATE_NEW 0 +#define STATE_EVEN 1 +#define STATE_ODD 2 +#define STATE_IDLE 3 +/* error codes */ #define ADB_RET_NOTPRESENT (-2)@@ -84,6 +95,110 @@ int adb_poll(ADBBusState *s, uint8_t *obuf, uint16_t poll_mask)return olen; } +int adb_via_poll (ADBBusState *adb,int state,uint8_t *data) +{ +if (state !=STATE_IDLE ) { +return 0 ; + } +if (adb->data_in_size < adb->data_in_index) { +return 0 ; + } +if (adb->data_out_index !=0 ) { +return 0 ; + } + adb->data_in_index =0 ; + adb->data_out_index =0 ; + adb->data_in_size =adb_poll (adb, adb->data_in,0xffff ); +if (adb->data_in_size) { + *data = adb->data_in[adb->data_in_index++]; +qemu_irq_raise (adb->data_ready); + } +return adb->data_in_size; +} + +int adb_send (ADBBusState *adb,int state,uint8_t data) +{ +switch (state) { +case STATE_NEW : + adb->data_out_index =0 ; +break ; +case STATE_EVEN : +if ((adb->data_out_index &1 ) ==0 ) { +return 0 ; + }
hw/input/adb.c int adb_poll(ADBBusState *s, uint8_t *obuf, uint16_t poll_mask) · line 138
Quoted 10 lines
hw/input/adb.c +10
-0+break ; +case STATE_ODD : +if (adb->data_out_index &1 ) { +return 0 ; + } +break ; +case STATE_IDLE : +return 0 ; + } + adb->data_out[adb->data_out_index++] = data;
What guards that against running over the end of the buffer?
Quoted 166 lines
hw/input/adb.c +63
-0+qemu_irq_raise (adb->data_ready); +return 1 ; +} + +int adb_receive (ADBBusState *adb,int state,uint8_t *data) +{ +switch (state) { +case STATE_NEW : +return 0 ; +case STATE_EVEN : +if (adb->data_in_size <=0 ) { +qemu_irq_raise (adb->data_ready); +return 0 ; + } +if (adb->data_in_index >= adb->data_in_size) { + *data =0 ; +qemu_irq_raise (adb->data_ready); +return 1 ; + } +if ((adb->data_in_index &1 ) ==0 ) { +return 0 ; + } +break ; +case STATE_ODD : +if (adb->data_in_size <=0 ) { +qemu_irq_raise (adb->data_ready); +return 0 ; + } +if (adb->data_in_index >= adb->data_in_size) { + *data =0 ; +qemu_irq_raise (adb->data_ready); +return 1 ; + } +if (adb->data_in_index &1 ) { +return 0 ; + } +break ; +case STATE_IDLE : +if (adb->data_out_index ==0 ) { +return 0 ; + } + adb->data_in_size =adb_request (adb, adb->data_in, + adb->data_out, adb->data_out_index); + adb->data_out_index =0 ; + adb->data_in_index =0 ; +if (adb->data_in_size <0 ) { + *data =0xff ; +qemu_irq_raise (adb->data_ready); +return -1 ; + } +if (adb->data_in_size ==0 ) { +return 0 ; + } +break ; + } + *data = adb->data_in[adb->data_in_index++]; +qemu_irq_raise (adb->data_ready); +if (*data ==0xff || *data ==0 ) { +return 0 ; + } +return 1 ; +} +static const TypeInfo adb_bus_type_info = { .name =TYPE_ADB_BUS , .parent =TYPE_BUS ,hw/misc/mac_via.c +56
-0@@ -424,6 +424,53 @@ static void via1_rtc_update(MacVIAState *m) } } +static void via1_adb_update (MacVIAState *m) +{ +MOS6522Q800VIA1State *v1s =MOS6522_Q800_VIA1 (&m->mos6522_via1); +MOS6522State *s =MOS6522 (v1s); +int state; +int ret; + + state = (s->b & VIA1B_vADB_StateMask) >> VIA1B_vADB_StateShift; + +if (s->acr & VIA1ACR_vShiftOut) { +/* output mode */ + ret =adb_send (&m->adb_bus, state, s->sr); +if (ret >0 ) { + s->b &= ~VIA1B_vADBInt; + }else { + s->b |= VIA1B_vADBInt; + } + }else { +/* input mode */ + ret =adb_receive (&m->adb_bus, state, &s->sr); +if (ret >0 && s->sr !=0xff ) { + s->b &= ~VIA1B_vADBInt; + }else { + s->b |= VIA1B_vADBInt; + } + } +} + +static void via_adb_poll (void *opaque) +{ +MacVIAState *m = opaque; +MOS6522Q800VIA1State *v1s =MOS6522_Q800_VIA1 (&m->mos6522_via1); +MOS6522State *s =MOS6522 (v1s); +int state; + +if (s->b & VIA1B_vADBInt) { + state = (s->b & VIA1B_vADB_StateMask) >> VIA1B_vADB_StateShift; +if (adb_via_poll (&m->adb_bus, state, &s->sr)) { + s->b &= ~VIA1B_vADBInt; + } + } + +timer_mod (m->adb_poll_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + + (NANOSECONDS_PER_SECOND /VIA_ADB_POLL_FREQ )); +} +static uint64_t mos6522_q800_via1_read (void *opaque,hwaddr addr,unsigned size) {MOS6522Q800VIA1State *s = opaque;@@ -486,6 +533,10 @@ static void mac_via_reset(DeviceState *dev) {MacVIAState *m =MAC_VIA (dev); +timer_mod (m->adb_poll_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + + (NANOSECONDS_PER_SECOND /VIA_ADB_POLL_FREQ )); +timer_mod (m->VBL_timer, (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +16630 ) /16630 *16630 );@@ -504,6 +555,7 @@ static void mac_via_realize(DeviceState *dev, Error **errp)qemu_get_timedate (&tm,0 ); m->tick_offset = (uint32_t )mktimegm (&tm) +RTC_OFFSET ; + m->adb_poll_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , via_adb_poll, m); }static void mac_via_init (Object *obj)@@ -553,6 +605,9 @@ static void mac_via_init(Object *obj)/* ADB */ qbus_create_inplace ((BusState *)&m->adb_bus,sizeof (m->adb_bus),TYPE_ADB_BUS ,DEVICE (obj),"adb.0" ); + + m->adb_bus.data_ready =qdev_get_gpio_in_named (DEVICE (obj),"via1-irq" , +VIA1_IRQ_ADB_READY_BIT ); }static void mac_via_class_init (ObjectClass *oc,void *data)@@ -579,6 +634,7 @@ static void mos6522_q800_via1_portB_write(MOS6522State *s)MacVIAState *m =container_of (v1s, MacVIAState, mos6522_via1);via1_rtc_update (m); +via1_adb_update (m); v1s->last_b = s->b; }include/hw/input/adb.h +0
-0
include/hw/input/adb.h struct ADBBusState { · line 82
Quoted 7 lines
include/hw/input/adb.h +4
-0@@ -76,6 +76,12 @@ struct ADBBusState {ADBDevice *devices[MAX_ADB_DEVICES ];int nb_devices;int poll_index; +qemu_irq data_ready; +int data_in_size; +int data_in_index; +int data_out_index;
Given they're array indexes, unsigned?
Quoted 29 lines
include/hw/input/adb.h +6
-0+uint8_t data_in[128 ]; +uint8_t data_out[16 ]; }; int adb_request(ADBBusState *s, uint8_t *buf_out,@@ -85,4 +91,8 @@ int adb_poll(ADBBusState *s, uint8_t *buf_out, uint16_t poll_mask);#define TYPE_ADB_KEYBOARD "adb-keyboard"#define TYPE_ADB_MOUSE "adb-mouse" +int adb_via_poll (ADBBusState *s,int state,uint8_t *data); +int adb_send (ADBBusState *adb,int state,uint8_t data); +int adb_receive (ADBBusState *adb,int state,uint8_t *data); +#endif /* ADB_H */ include/hw/misc/mac_via.h +1
-0@@ -96,6 +96,7 @@ typedef struct MacVIAState {/* ADB */ ADBBusState adb_bus; +QEMUTimer *adb_poll_timer;/* external timers */ QEMUTimer *one_second_timer;Signature · 1 line
2.14.4
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [RFC v3 02/10] ADB: VIA probes ADB bus when it is idle
In reply to Laurent VivierQuoted 32 lines · Laurent Vivier
Co-developed-by Mark Cave-Ayland <[email protected]>Signed-off-by Mark Cave-Ayland <[email protected]>Signed-off-by Laurent Vivier <[email protected]>--- hw/input/adb-kbd.c | 4 ++ hw/input/adb-mouse.c | 4 ++ hw/input/adb.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++ hw/misc/mac_via.c | 56 ++++++++++++++++++++++ include/hw/input/adb.h | 10 ++++ include/hw/misc/mac_via.h | 1 + 6 files changed, 190 insertions(+)hw/input/adb-kbd.c +4
-0@@ -195,6 +195,10 @@ static int adb_kbd_poll(ADBDevice *d, uint8_t *obuf)int keycode;int olen; +if (obuf ==NULL ) { +return s->count; + } + olen =0 ;if (s->count ==0 ) {return 0 ;hw/input/adb-mouse.c +0
-0
hw/input/adb-mouse.c static int adb_mouse_poll(ADBDevice *d, uint8_t *obuf) · line 82
Quoted 10 lines
hw/input/adb-mouse.c +4
-0@@ -73,6 +73,10 @@ static int adb_mouse_poll(ADBDevice *d, uint8_t *obuf)return 0 ; } +if (obuf ==NULL ) { +return 2 ; + } + dx = s->dx;if (dx <-63 ) { dx =-63 ;
I think that these two hunks should be placed in a separate patch as they can potentially alter existing behaviour with the PPC Mac machines.
Quoted 123 lines
hw/input/adb.c +108
-0@@ -25,6 +25,17 @@#include "hw/input/adb.h" #include "adb-internal.h" +#define ADB_POLL_FREQ 50 + +/* Apple Macintosh Family Hardware Refenece +* Table 19-10 ADB transaction states +*/ + +#define STATE_NEW 0 +#define STATE_EVEN 1 +#define STATE_ODD 2 +#define STATE_IDLE 3 +/* error codes */ #define ADB_RET_NOTPRESENT (-2)@@ -84,6 +95,110 @@ int adb_poll(ADBBusState *s, uint8_t *obuf, uint16_t poll_mask)return olen; } +int adb_via_poll (ADBBusState *adb,int state,uint8_t *data) +{ +if (state !=STATE_IDLE ) { +return 0 ; + } +if (adb->data_in_size < adb->data_in_index) { +return 0 ; + } +if (adb->data_out_index !=0 ) { +return 0 ; + } + adb->data_in_index =0 ; + adb->data_out_index =0 ; + adb->data_in_size =adb_poll (adb, adb->data_in,0xffff ); +if (adb->data_in_size) { + *data = adb->data_in[adb->data_in_index++]; +qemu_irq_raise (adb->data_ready); + } +return adb->data_in_size; +} + +int adb_send (ADBBusState *adb,int state,uint8_t data) +{ +switch (state) { +case STATE_NEW : + adb->data_out_index =0 ; +break ; +case STATE_EVEN : +if ((adb->data_out_index &1 ) ==0 ) { +return 0 ; + } +break ; +case STATE_ODD : +if (adb->data_out_index &1 ) { +return 0 ; + } +break ; +case STATE_IDLE : +return 0 ; + } + adb->data_out[adb->data_out_index++] = data; +qemu_irq_raise (adb->data_ready); +return 1 ; +} + +int adb_receive (ADBBusState *adb,int state,uint8_t *data) +{ +switch (state) { +case STATE_NEW : +return 0 ; +case STATE_EVEN : +if (adb->data_in_size <=0 ) { +qemu_irq_raise (adb->data_ready); +return 0 ; + } +if (adb->data_in_index >= adb->data_in_size) { + *data =0 ; +qemu_irq_raise (adb->data_ready); +return 1 ; + } +if ((adb->data_in_index &1 ) ==0 ) { +return 0 ; + } +break ; +case STATE_ODD : +if (adb->data_in_size <=0 ) { +qemu_irq_raise (adb->data_ready); +return 0 ; + } +if (adb->data_in_index >= adb->data_in_size) { + *data =0 ; +qemu_irq_raise (adb->data_ready); +return 1 ; + } +if (adb->data_in_index &1 ) { +return 0 ; + } +break ; +case STATE_IDLE : +if (adb->data_out_index ==0 ) { +return 0 ; + } + adb->data_in_size =adb_request (adb, adb->data_in, + adb->data_out, adb->data_out_index); + adb->data_out_index =0 ; + adb->data_in_index =0 ; +if (adb->data_in_size <0 ) { + *data =0xff ; +qemu_irq_raise (adb->data_ready); +return -1 ; + } +if (adb->data_in_size ==0 ) { +return 0 ; + } +break ; + } + *data = adb->data_in[adb->data_in_index++];
hw/input/adb.c int adb_poll(ADBBusState *s, uint8_t *obuf, uint16_t poll_mask) · line 204
Quoted 10 lines
hw/input/adb.c +7
-0+qemu_irq_raise (adb->data_ready); +if (*data ==0xff || *data ==0 ) { +return 0 ; + } +return 1 ; +} +static const TypeInfo adb_bus_type_info = { .name =TYPE_ADB_BUS , .parent =TYPE_BUS ,
I'm not convinced that these changes should live in adb.c and would prefer them to live in mac_via.c.
For example with the CUDA/PMU PPC VIAs, the data is bit-banged over the port B pins and it is the responsibility of the CUDA/PMU device to maintain the state of transmission/reception itself and then just call adb_request().
I can see there is an argument here that the mac_via states are related to ADB physical wire states but my feeling is that this adds too much complexity within ADB itself.
Following on from this, I'd say that the comment in adb.c "/* XXX: move that to cuda ? */" is probably correct, because each different VIA will poll ADB in a slightly different way.
Quoted 127 lines
hw/misc/mac_via.c +56
-0@@ -424,6 +424,53 @@ static void via1_rtc_update(MacVIAState *m) } } +static void via1_adb_update (MacVIAState *m) +{ +MOS6522Q800VIA1State *v1s =MOS6522_Q800_VIA1 (&m->mos6522_via1); +MOS6522State *s =MOS6522 (v1s); +int state; +int ret; + + state = (s->b & VIA1B_vADB_StateMask) >> VIA1B_vADB_StateShift; + +if (s->acr & VIA1ACR_vShiftOut) { +/* output mode */ + ret =adb_send (&m->adb_bus, state, s->sr); +if (ret >0 ) { + s->b &= ~VIA1B_vADBInt; + }else { + s->b |= VIA1B_vADBInt; + } + }else { +/* input mode */ + ret =adb_receive (&m->adb_bus, state, &s->sr); +if (ret >0 && s->sr !=0xff ) { + s->b &= ~VIA1B_vADBInt; + }else { + s->b |= VIA1B_vADBInt; + } + } +} + +static void via_adb_poll (void *opaque) +{ +MacVIAState *m = opaque; +MOS6522Q800VIA1State *v1s =MOS6522_Q800_VIA1 (&m->mos6522_via1); +MOS6522State *s =MOS6522 (v1s); +int state; + +if (s->b & VIA1B_vADBInt) { + state = (s->b & VIA1B_vADB_StateMask) >> VIA1B_vADB_StateShift; +if (adb_via_poll (&m->adb_bus, state, &s->sr)) { + s->b &= ~VIA1B_vADBInt; + } + } + +timer_mod (m->adb_poll_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + + (NANOSECONDS_PER_SECOND /VIA_ADB_POLL_FREQ )); +} +static uint64_t mos6522_q800_via1_read (void *opaque,hwaddr addr,unsigned size) {MOS6522Q800VIA1State *s = opaque;@@ -486,6 +533,10 @@ static void mac_via_reset(DeviceState *dev) {MacVIAState *m =MAC_VIA (dev); +timer_mod (m->adb_poll_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + + (NANOSECONDS_PER_SECOND /VIA_ADB_POLL_FREQ )); +timer_mod (m->VBL_timer, (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +16630 ) /16630 *16630 );@@ -504,6 +555,7 @@ static void mac_via_realize(DeviceState *dev, Error **errp)qemu_get_timedate (&tm,0 ); m->tick_offset = (uint32_t )mktimegm (&tm) +RTC_OFFSET ; + m->adb_poll_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , via_adb_poll, m); }static void mac_via_init (Object *obj)@@ -553,6 +605,9 @@ static void mac_via_init(Object *obj)/* ADB */ qbus_create_inplace ((BusState *)&m->adb_bus,sizeof (m->adb_bus),TYPE_ADB_BUS ,DEVICE (obj),"adb.0" ); + + m->adb_bus.data_ready =qdev_get_gpio_in_named (DEVICE (obj),"via1-irq" , +VIA1_IRQ_ADB_READY_BIT ); }static void mac_via_class_init (ObjectClass *oc,void *data)@@ -579,6 +634,7 @@ static void mos6522_q800_via1_portB_write(MOS6522State *s)MacVIAState *m =container_of (v1s, MacVIAState, mos6522_via1);via1_rtc_update (m); +via1_adb_update (m); v1s->last_b = s->b; }include/hw/input/adb.h +10
-0@@ -76,6 +76,12 @@ struct ADBBusState {ADBDevice *devices[MAX_ADB_DEVICES ];int nb_devices;int poll_index; +qemu_irq data_ready; +int data_in_size; +int data_in_index; +int data_out_index; +uint8_t data_in[128 ]; +uint8_t data_out[16 ]; }; int adb_request(ADBBusState *s, uint8_t *buf_out,@@ -85,4 +91,8 @@ int adb_poll(ADBBusState *s, uint8_t *buf_out, uint16_t poll_mask);#define TYPE_ADB_KEYBOARD "adb-keyboard"#define TYPE_ADB_MOUSE "adb-mouse" +int adb_via_poll (ADBBusState *s,int state,uint8_t *data); +int adb_send (ADBBusState *adb,int state,uint8_t data); +int adb_receive (ADBBusState *adb,int state,uint8_t *data); +#endif /* ADB_H */ include/hw/misc/mac_via.h +0
-0
include/hw/misc/mac_via.h typedef struct MacVIAState { · line 102
Quoted 7 lines
include/hw/misc/mac_via.h +1
-0@@ -96,6 +96,7 @@ typedef struct MacVIAState {/* ADB */ ADBBusState adb_bus; +QEMUTimer *adb_poll_timer;/* external timers */ QEMUTimer *one_second_timer;
ATB,
Mark.
RFC v3 3/10 escc: introduce a selector for the register bit
In reply to Laurent VivierOn Sparc and PowerMac, the bit 0 of the address selects the register type (control or data) and bit 1 selects the channel (B or A).
On m68k Macintosh, the bit 0 selects the channel and bit 1 the register type.
This patch introduces a new parameter (bit_swap) to the device interface to indicate bits usage must be swapped between registers and channels.
For the moment all the machines use the bit 0, but this change will be needed to emulate Quadra 800.
--- hw/char/escc.c | 30 ++++++++++++++++++++++++------ include/hw/char/escc.h | 1 + 2 files changed, 25 insertions(+), 6 deletions(-)
hw/char/escc.c +24 -6
@@ -42,14 +42,21 @@* mouse and keyboard ports don't implement all functions and they are * only asynchronous. There is no DMA. * -* Z85C30 is also used on PowerMacs. There are some small differences -* between Sparc version (sunzilog) and PowerMac (pmac): +* Z85C30 is also used on PowerMacs and m68k Macs. +* +* There are some small differences between Sparc version (sunzilog) +* and PowerMac (pmac): * Offset between control and data registers * There is some kind of lockup bug, but we can ignore it * CTS is inverted * DMA on pmac using DBDMA chip * pmac can do IRDA and faster rates, sunzilog can only do 38400 * pmac baud rate generator clock is 3.6864 MHz, sunzilog 4.9152 MHz +* +* Linux driver for m68k Macs is the same as for PowerMac (pmac_zilog), +* but registers are grouped by type and not by channel: +* channel is selected by bit 0 of the address (instead of bit 1) +* and register is selected by bit 1 of the address (instead of bit 0). */ /*
@@ -169,6 +176,16 @@ static void handle_kbd_command(ESCCChannelState *s, int val);static int serial_can_receive (void *opaque);static void serial_receive_byte (ESCCChannelState *s,int ch); +static int reg_shift (ESCCState *s) +{ +return s->bit_swap ? s->it_shift +1 : s->it_shift; +} + +static int chn_shift (ESCCState *s) +{ +return s->bit_swap ? s->it_shift : s->it_shift +1 ; +} +static void clear_queue (void *opaque) {ESCCChannelState *s = opaque;
@@ -433,8 +450,8 @@ static void escc_mem_write(void *opaque, hwaddr addr,int newreg, channel; val &=0xff ; - saddr = (addr >> serial->it_shift) &1 ; - channel = (addr >> (serial->it_shift +1 )) &1 ; + saddr = (addr >>reg_shift (serial)) &1 ; + channel = (addr >>chn_shift (serial)) &1 ; s = &serial->chn[channel];switch (saddr) {case SERIAL_CTRL :
@@ -537,8 +554,8 @@ static uint64_t escc_mem_read(void *opaque, hwaddr addr,uint32_t ret;int channel; - saddr = (addr >> serial->it_shift) &1 ; - channel = (addr >> (serial->it_shift +1 )) &1 ; + saddr = (addr >>reg_shift (serial)) &1 ; + channel = (addr >>chn_shift (serial)) &1 ; s = &serial->chn[channel];switch (saddr) {case SERIAL_CTRL :
@@ -822,6 +839,7 @@ static void escc_realize(DeviceState *dev, Error **errp)static Property escc_properties[] = {DEFINE_PROP_UINT32 ("frequency" , ESCCState, frequency,0 ),DEFINE_PROP_UINT32 ("it_shift" , ESCCState, it_shift,0 ), +DEFINE_PROP_BOOL ("bit_swap" , ESCCState, bit_swap, false),DEFINE_PROP_UINT32 ("disabled" , ESCCState, disabled,0 ),DEFINE_PROP_UINT32 ("chnBtype" , ESCCState, chn[0 ].type,0 ),DEFINE_PROP_UINT32 ("chnAtype" , ESCCState, chn[1 ].type,0 ),
include/hw/char/escc.h +1 -0
@@ -50,6 +50,7 @@ typedef struct ESCCState {struct ESCCChannelState chn[2 ];uint32_t it_shift; +bool bit_swap;MemoryRegion mmio;uint32_t disabled;uint32_t frequency;
Signature · 1 line
2.14.4
RFC v3 4/10 hw/m68k: add video card
In reply to Laurent Vivier--- arch_init.c | 4 + hw/display/Makefile.objs | 1 + hw/display/macfb-template.h | 158 +++++++++++++++++++++++++++ hw/display/macfb.c | 252 ++++++++++++++++++++++++++++++++++++++++++++ include/hw/display/macfb.h | 42 ++++++++ qemu-options.hx | 2 +- vl.c | 3 +- 7 files changed, 460 insertions(+), 2 deletions(-) create mode 100644 hw/display/macfb-template.h create mode 100644 hw/display/macfb.c create mode 100644 include/hw/display/macfb.h
arch_init.c +4 -0
@@ -39,6 +39,10 @@int graphic_width =1024 ;int graphic_height =768 ;int graphic_depth =8 ; +#elif defined(TARGET_M68K ) +int graphic_width =800 ; +int graphic_height =600 ; +int graphic_depth =8 ;#else int graphic_width =800 ;int graphic_height =600 ;
hw/display/Makefile.objs +1 -0
@@ -22,6 +22,7 @@ common-obj-$(CONFIG_EXYNOS4) += exynos4210_fimd.o common-obj-$(CONFIG_FRAMEBUFFER) += framebuffer.o common-obj-$(CONFIG_MILKYMIST) += milkymist-vgafb.o common-obj-$(CONFIG_ZAURUS) += tc6393xb.o +common-obj-$(CONFIG_MACFB) += macfb.o common-obj-$(CONFIG_MILKYMIST_TMU2) += milkymist-tmu2.o milkymist-tmu2.o-cflags := $(X11_CFLAGS)
hw/display/macfb-template.h new file +158 -0
158 lines not on this page · raw message
hw/display/macfb.c new file +252 -0
252 lines not on this page · raw message
include/hw/display/macfb.h new file +42 -0
42 lines not on this page · raw message
qemu-options.hx +1 -1
@@ -1539,7 +1539,7 @@ ETEXI DEF("g", 1, QEMU_OPTION_g , "-g WxH[xDEPTH] Set the initial graphical resolution and depth\n", - QEMU_ARCH_PPC | QEMU_ARCH_SPARC) + QEMU_ARCH_PPC | QEMU_ARCH_SPARC | QEMU_ARCH_M68K) STEXI @item -g @var{width}x@var{height}[x@var{depth}] @findex -g
vl.c +2 -1
@@ -3310,7 +3310,8 @@ int main(int argc, char **argv, char **envp)if (*p =='x' ) { p++; depth =strtol (p, (char **)&p,10 ); -if (depth !=8 && depth !=15 && depth !=16 && +if (depth !=1 && depth !=2 && depth !=4 && + depth !=8 && depth !=15 && depth !=16 && depth !=24 && depth !=32 ) goto graphic_error; }else if (*p =='\0' ) {
Signature · 1 line
2.14.4
Re: [Qemu-devel] [RFC v3 04/10] hw/m68k: add video card
Quoted 373 lines · * Laurent Vivier ([email protected]) wrote:
Co-developed-by Mark Cave-Ayland <[email protected]>Signed-off-by Mark Cave-Ayland <[email protected]>Signed-off-by Laurent Vivier <[email protected]>--- arch_init.c | 4 + hw/display/Makefile.objs | 1 + hw/display/macfb-template.h | 158 +++++++++++++++++++++++++++ hw/display/macfb.c | 252 ++++++++++++++++++++++++++++++++++++++++++++ include/hw/display/macfb.h | 42 ++++++++ qemu-options.hx | 2 +- vl.c | 3 +- 7 files changed, 460 insertions(+), 2 deletions(-) create mode 100644 hw/display/macfb-template.h create mode 100644 hw/display/macfb.c create mode 100644 include/hw/display/macfb.harch_init.c +4
-0@@ -39,6 +39,10 @@int graphic_width =1024 ;int graphic_height =768 ;int graphic_depth =8 ; +#elif defined(TARGET_M68K ) +int graphic_width =800 ; +int graphic_height =600 ; +int graphic_depth =8 ;#else int graphic_width =800 ;int graphic_height =600 ;hw/display/Makefile.objs +1
-0@@ -22,6 +22,7 @@ common-obj-$(CONFIG_EXYNOS4) += exynos4210_fimd.o common-obj-$(CONFIG_FRAMEBUFFER) += framebuffer.o common-obj-$(CONFIG_MILKYMIST) += milkymist-vgafb.o common-obj-$(CONFIG_ZAURUS) += tc6393xb.o +common-obj-$(CONFIG_MACFB) += macfb.o common-obj-$(CONFIG_MILKYMIST_TMU2) += milkymist-tmu2.o milkymist-tmu2.o-cflags := $(X11_CFLAGS)hw/display/macfb-template.h new file +158
-0@@ -0,0 +1,158 @@ +#if defined(READ_BITS ) +#define PALETTE (i, r, g, b) \ + do { \ + r = s->color_palette[i * 3]; \ + g = s->color_palette[i * 3 + 1]; \ + b = s->color_palette[i * 3 + 2]; \ + } while (0) + +#if READ_BITS ==1 +#define READ_PIXEL (from, x, r, g, b) \ + do { \ + int bit = x & 7; \ + int idx = (*from >> (7 - bit)) & 1; \ + r = g = b = ((1 - idx) << 7); \ + from += (bit == 7); \ + } while (0) +#elif READ_BITS ==2 +#define READ_PIXEL (from, x, r, g, b) \ + do { \ + int bit = (x & 3); \ + int idx = (*from >> ((3 - bit) << 1)) & 3; \ + PALETTE(idx, r, g, b); \ + from += (bit == 3); \ + } while (0) +#elif READ_BITS ==4 +#define READ_PIXEL (from, x, r, g, b) \ + do { \ + int bit = x & 1; \ + int idx = (*from >> ((1 - bit) << 2)) & 15; \ + PALETTE(idx, r, g, b); \ + from += (bit == 1); \ + } while (0) +#elif READ_BITS ==8 +#define READ_PIXEL (from, x, r, g, b) \ + do { \ + PALETTE(*from, r, g, b); \ + from++; \ + } while (0) +#elif READ_BITS ==16 +#define READ_PIXEL (from, x, r, g, b) \ + do { \ + uint16_t pixel; \ + pixel = (from[0] << 8) | from[1]; \ + r = ((pixel >> 10) & 0x1f) << 3; \ + g = ((pixel >> 5) & 0x1f) << 3; \ + b = (pixel & 0x1f) << 3; \ + from += 2; \ + } while (0) +#elif READ_BITS ==24 +#define READ_PIXEL (from, x, r, g, b) \ + do { \ + r = *from++; \ + g = *from++; \ + b = *from++; \ + } while (0) +#else +#error unknown bit depth +#endif + +#if WRITE_BITS ==8 +#define WRITE_PIXEL (to, r, g, b) \ + do { \ + *to = rgb_to_pixel8(r, g, b); \ + to += 1; \ + } while (0) +#elif WRITE_BITS ==15 +#define WRITE_PIXEL (to, r, g, b) \ + do { \ + *(uint16_t *)to = rgb_to_pixel15(r, g, b); \ + to += 2; \ + } while (0) +#elif WRITE_BITS ==16 +#define WRITE_PIXEL (to, r, g, b) \ + do { \ + *(uint16_t *)to = rgb_to_pixel16(r, g, b); \ + to += 2; \ + } while (0) +#elif WRITE_BITS ==24 +#define WRITE_PIXEL (to, r, g, b) \ + do { \ + uint32_t tmp = rgb_to_pixel24(r, g, b); \ + *(to++) = tmp & 0xff; \ + *(to++) = (tmp >> 8) & 0xff; \ + *(to++) = (tmp >> 16) & 0xff; \ + } while (0) +#elif WRITE_BITS ==32 +#define WRITE_PIXEL (to, r, g, b) \ + do { \ + *(uint32_t *)to = rgb_to_pixel32(r, g, b); \ + to += 4; \ + } while (0) +#else +#error unknown bit depth +#endif + +static void glue (glue (glue (draw_line ,READ_BITS ),_ ),WRITE_BITS ) + (MacfbState *s,uint8_t *to,uint8_t *from,int width) +{ +uint8_t r, g, b; +int x; +for (x =0 ; x < width; x++) { +READ_PIXEL (from, x, r, g, b); +WRITE_PIXEL (to, r, g, b); + } +} +#undef READ_BITS +#undef READ_PIXEL +#undef WRITE_PIXEL + +#elif defined(WRITE_BITS ) + +#undef MACFB_RECLEVEL +#define MACFB_RECLEVEL 2 +#define READ_BITS 1 +#include "macfb-template.h" +#define READ_BITS 2 +#include "macfb-template.h" +#define READ_BITS 4 +#include "macfb-template.h" +#define READ_BITS 8 +#include "macfb-template.h" +#define READ_BITS 16 +#include "macfb-template.h" +#define READ_BITS 24 +#include "macfb-template.h" +#undef WRITE_BITS + +#else + +#define WRITE_BITS 8 +#include "macfb-template.h" + +#define WRITE_BITS 16 +#include "macfb-template.h" + +#define WRITE_BITS 24 +#include "macfb-template.h" + +#define WRITE_BITS 32 +#include "macfb-template.h" + +typedef void (*macfb_draw_line_func_t )(MacfbState *,uint8_t *,uint8_t *,int ); + +static macfb_draw_line_func_t macfb_draw_line[24 ][32 ] = { + [0 ] = { [7 ] = draw_line1_8, [15 ] = draw_line1_16, + [23 ] = draw_line1_24, [31 ] = draw_line1_32 }, + [1 ] = { [7 ] = draw_line2_8, [15 ] = draw_line2_16, + [23 ] = draw_line2_24, [31 ] = draw_line2_32 }, + [3 ] = { [7 ] = draw_line4_8, [15 ] = draw_line4_16, + [23 ] = draw_line4_24, [31 ] = draw_line4_32 }, + [7 ] = { [7 ] = draw_line8_8, [15 ] = draw_line8_16, + [23 ] = draw_line8_24, [31 ] = draw_line8_32 }, + [15 ] = { [7 ] = draw_line16_8, [15 ] = draw_line16_16, + [23 ] = draw_line16_24, [31 ] = draw_line16_32 }, + [23 ] = { [7 ] = draw_line24_8, [15 ] = draw_line24_16, + [23 ] = draw_line24_24, [31 ] = draw_line24_32 }, +}; +#endif hw/display/macfb.c new file +160
-0@@ -0,0 +1,252 @@ +/* +* QEMU Motorola 680x0 Macintosh Video Card Emulation +* Copyright (c) 2012-2018 Laurent Vivier +* +* some parts from QEMU G364 framebuffer Emulator. +* Copyright (c) 2007-2011 Herve Poussineau +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#include "qemu/osdep.h" +#include "hw/sysbus.h" +#include "ui/console.h" +#include "ui/pixel_ops.h" +#include "hw/display/macfb.h" + +#define VIDEO_BASE 0x00001000 +#define DAFB_BASE 0x00800000 + +#define MACFB_PAGE_SIZE 4096 +#define MACFB_VRAM_SIZE (4 * 1024 * 1024) + +#define DAFB_RESET 0x200 +#define DAFB_LUT 0x213 + +#include "macfb-template.h" + +static int macfb_check_dirty (MacfbState *s,DirtyBitmapSnapshot *snap, +ram_addr_t addr,int len) +{ +return memory_region_snapshot_get_dirty (&s->mem_vram, snap, addr, len); +} + +static void macfb_draw_graphic (MacfbState *s) +{ +DisplaySurface *surface =qemu_console_surface (s->con); +DirtyBitmapSnapshot *snap =NULL ; +ram_addr_t page; +int y, ymin; +int macfb_stride = (s->depth * s->width +7 ) /8 ; +macfb_draw_line_func_t draw_line; + +if (s->depth >24 ) { +hw_error ("macfb: unknown guest depth %d" , s->depth); +return ; + } +if (surface_bits_per_pixel (surface) >32 ) { +hw_error ("macfb: unknown host depth %d" , +surface_bits_per_pixel (surface)); +return ; + } + draw_line = macfb_draw_line[s->depth -1 ][surface_bits_per_pixel (surface) + -1 ]; + +if (draw_line ==NULL ) { +hw_error ("macfb: unknown guest/host depth combination %d/%d" , s->depth, +surface_bits_per_pixel (surface)); +return ; + } + + snap =memory_region_snapshot_and_clear_dirty (&s->mem_vram,0x0 , +memory_region_size (&s->mem_vram), +DIRTY_MEMORY_VGA ); + + ymin =-1 ; + page =0 ; +for (y =0 ; y < s->height; y++, page += macfb_stride) { +if (macfb_check_dirty (s, snap, page, macfb_stride)) { +uint8_t *data_display; + + data_display =surface_data (surface) + y *surface_stride (surface); +draw_line (s, data_display, s->vram + page, s->width); + +if (ymin <0 ) { + ymin = y; + } + }else { +if (ymin >=0 ) { +dpy_gfx_update (s->con,0 , ymin, s->width, y - ymin); + ymin =-1 ; + } + } + } + +if (ymin >=0 ) { +dpy_gfx_update (s->con,0 , ymin, s->width, y - ymin); + } + +g_free (snap); +} + +static void macfb_invalidate_display (void *opaque) +{ +MacfbState *s = opaque; + +memory_region_set_dirty (&s->mem_vram,0 ,MACFB_VRAM_SIZE ); +} + +static void macfb_update_display (void *opaque) +{ +MacfbState *s = opaque; +DisplaySurface *surface =qemu_console_surface (s->con); + +qemu_flush_coalesced_mmio_buffer (); + +if (s->width ==0 || s->height ==0 ) { +return ; + } + +if (s->width !=surface_width (surface) || + s->height !=surface_height (surface)) { +qemu_console_resize (s->con, s->width, s->height); + } + +macfb_draw_graphic (s); +} + +static void macfb_reset (MacfbState *s) +{ +int i; + + s->palette_current =0 ; +for (i =0 ; i <256 ; i++) { + s->color_palette[i *3 ] =255 - i; + s->color_palette[i *3 +1 ] =255 - i; + s->color_palette[i *3 +2 ] =255 - i; + } +memset (s->vram,0 ,MACFB_VRAM_SIZE ); +macfb_invalidate_display (s); +} + +static uint64_t macfb_ctrl_read (void *opaque, +hwaddr addr, +unsigned int size) +{ +return 0 ; +} + +static void macfb_ctrl_write (void *opaque, +hwaddr addr, +uint64_t val, +unsigned int size) +{ +MacfbState *s = opaque; +switch (addr) { +case DAFB_RESET : + s->palette_current =0 ; +break ; +case DAFB_LUT : + s->color_palette[s->palette_current++] = val; +if (s->palette_current %3 ) { +macfb_invalidate_display (s); + } +break ; + } +} + +static const MemoryRegionOps macfb_ctrl_ops = {
hw/display/macfb.c line 170
Quoted 10 lines
hw/display/macfb.c new file +10
-0+ .read = macfb_ctrl_read, + .write = macfb_ctrl_write, + .endianness = DEVICE_BIG_ENDIAN, + .impl.min_access_size = 1, + .impl.max_access_size = 4, +}; + +static int macfb_post_load (void *opaque,int version_id) +{ +macfb_invalidate_display (opaque);
You should probably validate palette_current, otherwise loading a stream with a bogus palette_current could crash if it got to macfb_ctrl_write/DAFB_LUT
Dave
hw/display/macfb.c line 181
Quoted 11 lines
hw/display/macfb.c new file +11
-0+return 0 ; +} + +static const VMStateDescription vmstate_macfb = { + .name ="macfb" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .post_load = macfb_post_load, + .fields = (VMStateField []) { +VMSTATE_BUFFER_UNSAFE (color_palette, MacfbState,0 ,256 *3 ),
Does:
VMSTATE_UINT8_ARRAY(color_palette, MacfbState, 256*3)
work there in a safer way?
Quoted 149 lines
hw/display/macfb.c new file +71
-0+VMSTATE_UINT32 (palette_current, MacfbState), + VMSTATE_END_OF_LIST() + } +}; + +static const GraphicHwOps macfb_ops = { + .invalidate = macfb_invalidate_display, + .gfx_update = macfb_update_display, +}; + +static void macfb_common_realize (DeviceState *dev,MacfbState *s) +{ + s->vram =g_malloc0 (MACFB_VRAM_SIZE ); + + s->con =graphic_console_init (dev,0 , &macfb_ops, s); + +memory_region_init_io (&s->mem_ctrl,NULL , &macfb_ctrl_ops, s,"macfb-ctrl" , +0x1000 ); +memory_region_init_ram_ptr (&s->mem_vram,NULL ,"macfb-vram" , +MACFB_VRAM_SIZE , s->vram); +vmstate_register_ram (&s->mem_vram, dev); +memory_region_set_coalescing (&s->mem_vram); +} + +static void macfb_sysbus_realize (DeviceState *dev,Error **errp) +{ +MacfbSysBusState *s =MACFB (dev); +MacfbState *ms = &s->macfb; + +macfb_common_realize (dev, ms); +sysbus_init_mmio (SYS_BUS_DEVICE (s), &ms->mem_ctrl); +sysbus_init_mmio (SYS_BUS_DEVICE (s), &ms->mem_vram); +} + +static void macfb_sysbus_reset (DeviceState *d) +{ +MacfbSysBusState *s =MACFB (d); +macfb_reset (&s->macfb); +} + +static Property macfb_sysbus_properties[] = { +DEFINE_PROP_UINT32 ("width" , MacfbSysBusState, macfb.width,640 ), +DEFINE_PROP_UINT32 ("height" , MacfbSysBusState, macfb.height,480 ), +DEFINE_PROP_UINT8 ("depth" , MacfbSysBusState, macfb.depth,8 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void macfb_sysbus_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = macfb_sysbus_realize; + dc->desc ="SysBus Macintosh framebuffer" ; + dc->reset = macfb_sysbus_reset; + dc->vmsd = &vmstate_macfb; + dc->props = macfb_sysbus_properties; +} + +static TypeInfo macfb_sysbus_info = { + .name =TYPE_MACFB , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (MacfbSysBusState), + .class_init = macfb_sysbus_class_init, +}; + +static void macfb_register_types (void ) +{ +type_register_static (&macfb_sysbus_info); +} + +type_init (macfb_register_types)include/hw/display/macfb.h new file +42
-0@@ -0,0 +1,42 @@ +/* +* QEMU Motorola 680x0 Macintosh Video Card Emulation +* Copyright (c) 2012-2018 Laurent Vivier +* +* some parts from QEMU G364 framebuffer Emulator. +* Copyright (c) 2007-2011 Herve Poussineau +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#ifndef MACFB_H +#define MACFB_H + +#include "qemu/osdep.h" +#include "exec/memory.h" +#include "ui/console.h" + +typedef struct MacfbState { +MemoryRegion mem_vram; +MemoryRegion mem_ctrl; +QemuConsole *con; + +uint8_t *vram; +uint32_t palette_current; +uint8_t color_palette[256 *3 ]; +uint32_t width, height;/* in pixels */ +uint8_t depth; +}MacfbState ; + +#define TYPE_MACFB "sysbus-macfb" +#define MACFB (obj) \ + OBJECT_CHECK(MacfbSysBusState, (obj), TYPE_MACFB) + +typedef struct { +SysBusDevice busdev; + +MacfbState macfb; +}MacfbSysBusState ; + +#endif qemu-options.hx +1
-1@@ -1539,7 +1539,7 @@ ETEXI DEF("g", 1, QEMU_OPTION_g , "-g WxH[xDEPTH] Set the initial graphical resolution and depth\n", - QEMU_ARCH_PPC | QEMU_ARCH_SPARC) + QEMU_ARCH_PPC | QEMU_ARCH_SPARC | QEMU_ARCH_M68K) STEXI @item -g @var{width}x@var{height}[x@var{depth}] @findex -gvl.c +2
-1@@ -3310,7 +3310,8 @@ int main(int argc, char **argv, char **envp)if (*p =='x' ) { p++; depth =strtol (p, (char **)&p,10 ); -if (depth !=8 && depth !=15 && depth !=16 && +if (depth !=1 && depth !=2 && depth !=4 && + depth !=8 && depth !=15 && depth !=16 && depth !=24 && depth !=32 ) goto graphic_error; }else if (*p =='\0' ) {Signature · 1 line
2.14.4
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [RFC v3 04/10] hw/m68k: add video card
In reply to Laurent VivierQuoted 4 lines · Laurent Vivier
Co-developed-by Mark Cave-Ayland <[email protected]>Signed-off-by Mark Cave-Ayland <[email protected]>Signed-off-by Laurent Vivier <[email protected]>---
[...]
Quoted 136 lines
hw/display/macfb-template.h new file +130
-0@@ -0,0 +1,158 @@ +#if defined(READ_BITS ) +#define PALETTE (i, r, g, b) \ + do { \ + r = s->color_palette[i * 3]; \ + g = s->color_palette[i * 3 + 1]; \ + b = s->color_palette[i * 3 + 2]; \ + } while (0) + +#if READ_BITS ==1 +#define READ_PIXEL (from, x, r, g, b) \ + do { \ + int bit = x & 7; \ + int idx = (*from >> (7 - bit)) & 1; \ + r = g = b = ((1 - idx) << 7); \ + from += (bit == 7); \ + } while (0) +#elif READ_BITS ==2 +#define READ_PIXEL (from, x, r, g, b) \ + do { \ + int bit = (x & 3); \ + int idx = (*from >> ((3 - bit) << 1)) & 3; \ + PALETTE(idx, r, g, b); \ + from += (bit == 3); \ + } while (0) +#elif READ_BITS ==4 +#define READ_PIXEL (from, x, r, g, b) \ + do { \ + int bit = x & 1; \ + int idx = (*from >> ((1 - bit) << 2)) & 15; \ + PALETTE(idx, r, g, b); \ + from += (bit == 1); \ + } while (0) +#elif READ_BITS ==8 +#define READ_PIXEL (from, x, r, g, b) \ + do { \ + PALETTE(*from, r, g, b); \ + from++; \ + } while (0) +#elif READ_BITS ==16 +#define READ_PIXEL (from, x, r, g, b) \ + do { \ + uint16_t pixel; \ + pixel = (from[0] << 8) | from[1]; \ + r = ((pixel >> 10) & 0x1f) << 3; \ + g = ((pixel >> 5) & 0x1f) << 3; \ + b = (pixel & 0x1f) << 3; \ + from += 2; \ + } while (0) +#elif READ_BITS ==24 +#define READ_PIXEL (from, x, r, g, b) \ + do { \ + r = *from++; \ + g = *from++; \ + b = *from++; \ + } while (0) +#else +#error unknown bit depth +#endif + +#if WRITE_BITS ==8 +#define WRITE_PIXEL (to, r, g, b) \ + do { \ + *to = rgb_to_pixel8(r, g, b); \ + to += 1; \ + } while (0) +#elif WRITE_BITS ==15 +#define WRITE_PIXEL (to, r, g, b) \ + do { \ + *(uint16_t *)to = rgb_to_pixel15(r, g, b); \ + to += 2; \ + } while (0) +#elif WRITE_BITS ==16 +#define WRITE_PIXEL (to, r, g, b) \ + do { \ + *(uint16_t *)to = rgb_to_pixel16(r, g, b); \ + to += 2; \ + } while (0) +#elif WRITE_BITS ==24 +#define WRITE_PIXEL (to, r, g, b) \ + do { \ + uint32_t tmp = rgb_to_pixel24(r, g, b); \ + *(to++) = tmp & 0xff; \ + *(to++) = (tmp >> 8) & 0xff; \ + *(to++) = (tmp >> 16) & 0xff; \ + } while (0) +#elif WRITE_BITS ==32 +#define WRITE_PIXEL (to, r, g, b) \ + do { \ + *(uint32_t *)to = rgb_to_pixel32(r, g, b); \ + to += 4; \ + } while (0) +#else +#error unknown bit depth +#endif + +static void glue (glue (glue (draw_line ,READ_BITS ),_ ),WRITE_BITS ) + (MacfbState *s,uint8_t *to,uint8_t *from,int width) +{ +uint8_t r, g, b; +int x; +for (x =0 ; x < width; x++) { +READ_PIXEL (from, x, r, g, b); +WRITE_PIXEL (to, r, g, b); + } +} +#undef READ_BITS +#undef READ_PIXEL +#undef WRITE_PIXEL + +#elif defined(WRITE_BITS ) + +#undef MACFB_RECLEVEL +#define MACFB_RECLEVEL 2 +#define READ_BITS 1 +#include "macfb-template.h" +#define READ_BITS 2 +#include "macfb-template.h" +#define READ_BITS 4 +#include "macfb-template.h" +#define READ_BITS 8 +#include "macfb-template.h" +#define READ_BITS 16 +#include "macfb-template.h" +#define READ_BITS 24 +#include "macfb-template.h" +#undef WRITE_BITS + +#else + +#define WRITE_BITS 8
hw/display/macfb-template.h line 140
Quoted 10 lines
hw/display/macfb-template.h new file +10
-0+#include "macfb-template.h" + +#define WRITE_BITS 16 +#include "macfb-template.h" + +#define WRITE_BITS 24 +#include "macfb-template.h" + +#define WRITE_BITS 32 +#include "macfb-template.h"
Not sure, but do we still need all these "destination" bit depth nowadays? I thought QEMU only supports 32 bit depths these days?
Thomas
Re: [Qemu-devel] [RFC v3 04/10] hw/m68k: add video card
Quoted 6 lines
Quoted 6 lines
hw/display/macfb-template.h new file +6
-0+#define WRITE_BITS 8 +#include "macfb-template.h" + +#define WRITE_BITS 16 +#include "macfb-template.h" +
Quoted 8 lines
hw/display/macfb-template.h line 140
Quoted 5 lines
hw/display/macfb-template.h new file +5
-0+#define WRITE_BITS 24 +#include "macfb-template.h" + +#define WRITE_BITS 32 +#include "macfb-template.h" Not sure, but do we still need all these "destination" bit depth nowadays? I thought QEMU only supports 32 bit depths these days?
Well, qemu UI code can handle non-32 bit depths too (pretty much anything pixman supports to be exact).
But, yes, qemu hands out 32bit DisplaySurfaces by default, i.e. when using qemu_console_resize() or qemu_create_displaysurface() in display device emulation.
You can ask for something else, using qemu_create_displaysurface_from(), which is typically used in case the backing storage for the DisplaySurface is guest memory, to avoid copying/converting display data. The code above probably doesn't look like it is doing that though.
HTH,
Gerd
RFC v3 5/10 hw/m68k: Apple Sound Chip (ASC) emulation
In reply to Laurent VivierThis is broken as the linux driver seems broken too...
--- hw/audio/Makefile.objs | 1 + hw/audio/asc.c | 463 +++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/audio/asc.h | 48 +++++ 3 files changed, 512 insertions(+) create mode 100644 hw/audio/asc.c create mode 100644 include/hw/audio/asc.h
hw/audio/Makefile.objs +1 -0
@@ -16,3 +16,4 @@ common-obj-$(CONFIG_MARVELL_88W8618) += marvell_88w8618.o common-obj-$(CONFIG_MILKYMIST) += milkymist-ac97.o common-obj-y += soundhw.o +common-obj-$(CONFIG_ASC) += asc.o
hw/audio/asc.c new file +463 -0
463 lines not on this page · raw message
include/hw/audio/asc.h new file +48 -0
48 lines not on this page · raw message
Signature · 1 line
2.14.4
Re: [Qemu-devel] [RFC v3 05/10] hw/m68k: Apple Sound Chip (ASC) emulation
hw/audio/asc.c line 383
Quoted 11 lines · * Laurent Vivier ([email protected]) wrote:
This is broken as the linux driver seems broken too...
Co-developed-by Mark Cave-Ayland <[email protected]>Signed-off-by Mark Cave-Ayland <[email protected]>Signed-off-by Laurent Vivier <[email protected]>---
hw/audio/asc.c new file +4
-0+static int asc_post_load (void *opaque,int version_id) +{ +return 0 ; +}
Why does that exist?
hw/audio/asc.c line 394
Quoted 10 lines
hw/audio/asc.c new file +10
-0+static const VMStateDescription vmstate_asc = { + .name ="apple-sound-chip" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .post_load = asc_post_load, + .fields = (VMStateField []) { +VMSTATE_END_OF_LIST () + } +};
Similarly, that doesn't have anything to migrate.
Dave
Quoted 125 lines
hw/audio/asc.c new file +68
-0+static void asc_reset (DeviceState *d) +{ +ASCState *s =ASC (d); + +AUD_set_active_out (s->channel,0 ); + +memset (s->regs,0 ,sizeof (s->regs)); + s->a_wptr =0 ; + s->a_rptr =0 ; + s->a_cnt =0 ; + s->b_wptr =0 ; + s->b_rptr =0 ; + s->b_cnt =0 ; +} + +static void asc_init (Object *obj) +{ +ASCState *s =ASC (obj); +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); +struct audsettings as; + +AUD_register_card ("Apple Sound Chip" , &s->card); + + as.freq =22257 ; + as.nchannels =2 ; + as.fmt =AUD_FMT_S8 ; + as.endianness =0 ; + + s->channel =AUD_open_out (&s->card, s->channel,"asc.out" , + s, asc_out_cb, &as); + + s->fifo =g_malloc0 (ASC_BUF_SIZE ); + +memory_region_init_io (&s->mem_regs,NULL , &asc_mmio_ops, s,"asc" , +ASC_LENGTH ); + +sysbus_init_irq (sbd, &s->irq); +sysbus_init_mmio (sbd, &s->mem_regs); +} + +static Property asc_properties[] = { +DEFINE_PROP_UINT8 ("asctype" , ASCState, type,ASC_TYPE_ASC ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void asc_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + + dc->reset = asc_reset; + dc->vmsd = &vmstate_asc; + dc->props = asc_properties; +} + +static TypeInfo asc_info = { + .name =TYPE_ASC , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (ASCState), + .instance_init = asc_init, + .class_init = asc_class_init, +}; + +static void asc_register_types (void ) +{ +type_register_static (&asc_info); +} + +type_init (asc_register_types)include/hw/audio/asc.h new file +48
-0@@ -0,0 +1,48 @@ +/* +* Copyright (c) 2012-2018 Laurent Vivier <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#ifndef HW_AUDIO_ASC_H +#define HW_AUDIO_ASC_H + +#include "qemu/osdep.h" +#include "hw/sysbus.h" +#include "audio/audio.h" + +enum { +ASC_TYPE_ASC =0 ,/* original discrete Apple Sound Chip */ +ASC_TYPE_EASC =1 ,/* discrete Enhanced Apple Sound Chip */ +ASC_TYPE_V8 =2 ,/* ASC included in the V8 ASIC (LC/LCII) */ +ASC_TYPE_EAGLE =3 ,/* ASC included in the Eagle ASIC (Classic II) */ +ASC_TYPE_SPICE =4 ,/* ASC included in the Spice ASIC (Color Classic) */ +ASC_TYPE_SONORA =5 ,/* ASC included in the Sonora ASIC (LCIII) */ +ASC_TYPE_VASP =6 ,/* ASC included in the VASP ASIC (IIvx/IIvi) */ +ASC_TYPE_ARDBEG =7 /* ASC included in the Ardbeg ASIC (LC520) */ +}; + +typedef struct ASCState { +SysBusDevice parent_obj; + +MemoryRegion mem_regs; +QEMUSoundCard card; +SWVoiceOut *channel; + +qemu_irq irq; + +uint8_t type; +int a_wptr, a_rptr, a_cnt; +int b_wptr, b_rptr, b_cnt; + +uint8_t *fifo; + +uint8_t regs[48 ]; +}ASCState ; + +#define TYPE_ASC "apple-sound-chip" +#define ASC (obj) OBJECT_CHECK(ASCState, (obj), TYPE_ASC) + +#endif Signature · 1 line
2.14.4
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
RFC v3 6/10 ESP: add pseudo-DMA as used by Macintosh
In reply to Laurent Vivier--- hw/mips/mips_jazz.c | 2 +- hw/scsi/esp.c | 297 ++++++++++++++++++++++++++++++++++++++++++++------ include/hw/scsi/esp.h | 11 +- 3 files changed, 276 insertions(+), 34 deletions(-)
hw/mips/mips_jazz.c +1 -1
@@ -282,7 +282,7 @@ static void mips_jazz_init(MachineState *machine,/* SCSI adapter */ esp =esp_init (0x80002000 ,0 , rc4030_dma_read, rc4030_dma_write, dmas[0 ], -qdev_get_gpio_in (rc4030,5 ), &esp_reset, &dma_enable); +qdev_get_gpio_in (rc4030,5 ),NULL , &esp_reset, &dma_enable);scsi_bus_legacy_handle_cmdline (&esp->bus);/* Floppy */
hw/scsi/esp.c +266 -31
440 lines not on this page · raw message
include/hw/scsi/esp.h +9 -2
@@ -18,6 +18,7 @@ struct ESPState {uint8_t rregs[ESP_REGS ];uint8_t wregs[ESP_REGS ];qemu_irq irq; +qemu_irq irq_data;uint8_t chip_id;bool tchi_written;int32_t ti_size;
@@ -46,6 +47,11 @@ struct ESPState {ESPDMAMemoryReadWriteFunc dma_memory_write;void *dma_opaque;void (*dma_cb)(ESPState *s); +uint8_t pdma_buf[32 ]; +uint32_t pdma_len; +uint8_t *pdma_start; +uint8_t *pdma_cur; +void (*pdma_cb)(ESPState *s); };#define TYPE_ESP "esp"
@@ -57,6 +63,7 @@ typedef struct {/*< public >*/ MemoryRegion iomem; +MemoryRegion pdma;uint32_t it_shift;ESPState esp; } SysBusESPState;
@@ -134,8 +141,8 @@ typedef struct {ESPState *esp_init (hwaddr espaddr,int it_shift,ESPDMAMemoryReadWriteFunc dma_memory_read,ESPDMAMemoryReadWriteFunc dma_memory_write, -void *dma_opaque,qemu_irq irq,qemu_irq *reset, -qemu_irq *dma_enable); +void *dma_opaque,qemu_irq irq,qemu_irq irq_data, +qemu_irq *reset,qemu_irq *dma_enable);void esp_dma_enable (ESPState *s,int irq,int level);void esp_request_cancelled (SCSIRequest *req);void esp_command_complete (SCSIRequest *req,uint32_t status,size_t resid);
Signature · 1 line
2.14.4
Re: [Qemu-devel] [RFC v3 06/10] ESP: add pseudo-DMA as used by Macintosh
include/hw/scsi/esp.h struct ESPState { · line 55
Quoted 11 lines · Laurent Vivier
int32_t ti_size;include/hw/scsi/esp.h +5
-0@@ -46,6 +47,11 @@ struct ESPState {ESPDMAMemoryReadWriteFunc dma_memory_write;void *dma_opaque;void (*dma_cb)(ESPState *s); +uint8_t pdma_buf[32 ]; +uint32_t pdma_len; +uint8_t *pdma_start; +uint8_t *pdma_cur; +void (*pdma_cb)(ESPState *s); };
I suppose migration of ESP is completely busted, since we're not migrating dma_cb? This patch is not making it any better, but perhaps at least pdma_start and pdma_cur could be indices instead of pointers.
Thanks,
Paolo
Re: [Qemu-devel] [RFC v3 06/10] ESP: add pseudo-DMA as used by Macintosh
Le 28/06/2018 à 10:13, Paolo Bonzini a écrit :
Quoted 8 lines · Laurent Vivier
Quoted 7 lines
int32_t ti_size;include/hw/scsi/esp.h +2
-0@@ -46,6 +47,11 @@ struct ESPState {ESPDMAMemoryReadWriteFunc dma_memory_write;void *dma_opaque;void (*dma_cb)(ESPState *s); +uint8_t pdma_buf[32 ]; +uint32_t pdma_len;
Quoted 8 lines
include/hw/scsi/esp.h struct ESPState { · line 55
Quoted 4 lines
include/hw/scsi/esp.h +3
-0+uint8_t *pdma_start; +uint8_t *pdma_cur; +void (*pdma_cb)(ESPState *s); };I suppose migration of ESP is completely busted, since we're not migrating
dma_cb? This patch is not making it any better, but perhaps at leastpdma_startandpdma_curcould be indices instead of pointers.
Thank you, I will try that.
Laurent
RFC v3 7/10 hw/m68k: add Nubus support
In reply to Laurent Vivier--- hw/Makefile.objs | 1 + hw/display/macfb.c | 56 ++++++++++ hw/nubus/Makefile.objs | 4 + hw/nubus/mac-nubus-bridge.c | 45 ++++++++ hw/nubus/nubus-bridge.c | 34 ++++++ hw/nubus/nubus-bus.c | 111 +++++++++++++++++++ hw/nubus/nubus-device.c | 210 ++++++++++++++++++++++++++++++++++++ include/hw/display/macfb.h | 21 ++++ include/hw/nubus/mac-nubus-bridge.h | 24 +++++ include/hw/nubus/nubus.h | 69 ++++++++++++ 10 files changed, 575 insertions(+) create mode 100644 hw/nubus/Makefile.objs create mode 100644 hw/nubus/mac-nubus-bridge.c create mode 100644 hw/nubus/nubus-bridge.c create mode 100644 hw/nubus/nubus-bus.c create mode 100644 hw/nubus/nubus-device.c create mode 100644 include/hw/nubus/mac-nubus-bridge.h create mode 100644 include/hw/nubus/nubus.h
hw/Makefile.objs +1 -0
@@ -35,6 +35,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += watchdog/ devices-dirs-$(CONFIG_SOFTMMU) += xen/ devices-dirs-$(CONFIG_MEM_HOTPLUG) += mem/ devices-dirs-$(CONFIG_SOFTMMU) += smbios/ +devices-dirs-$(CONFIG_NUBUS) += nubus/ devices-dirs-y += core/ common-obj-y += $(devices-dirs-y) obj-y += $(devices-dirs-y)
hw/display/macfb.c +56 -0
95 lines not on this page · raw message
hw/nubus/Makefile.objs new file +4 -0
@@ -0,0 +1,4 @@ +common-obj-y += nubus-device.o +common-obj-y += nubus-bus.o +common-obj-y += nubus-bridge.o +common-obj-$(CONFIG_MAC) += mac-nubus-bridge.o
hw/nubus/mac-nubus-bridge.c new file +45 -0
45 lines not on this page · raw message
hw/nubus/nubus-bridge.c new file +34 -0
@@ -0,0 +1,34 @@ +/* +* QEMU Macintosh Nubus +* +* Copyright (c) 2013-2018 Laurent Vivier <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#include "qemu/osdep.h" +#include "hw/sysbus.h" +#include "hw/nubus/nubus.h" + +static void nubus_bridge_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->fw_name ="nubus" ; +} + +static const TypeInfo nubus_bridge_info = { + .name =TYPE_NUBUS_BRIDGE , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (SysBusDevice), + .class_init = nubus_bridge_class_init, +}; + +static void nubus_register_types (void ) +{ +type_register_static (&nubus_bridge_info); +} + +type_init (nubus_register_types)
hw/nubus/nubus-bus.c new file +111 -0
111 lines not on this page · raw message
hw/nubus/nubus-device.c new file +210 -0
210 lines not on this page · raw message
include/hw/display/macfb.h +21 -0
@@ -39,4 +39,25 @@ typedef struct { MacfbState macfb; } MacfbSysBusState; +#define MACFB_NUBUS_DEVICE_CLASS (class) \ + OBJECT_CLASS_CHECK(MacfbNubusDeviceClass, (class), TYPE_NUBUS_MACFB) +#define MACFB_NUBUS_GET_CLASS (obj) \ + OBJECT_GET_CLASS(MacfbNubusDeviceClass, (obj), TYPE_NUBUS_MACFB) + +typedef struct MacfbNubusDeviceClass { +DeviceClass parent_class; + +DeviceRealize parent_realize; +}MacfbNubusDeviceClass ; + +#define TYPE_NUBUS_MACFB "nubus-macfb" +#define NUBUS_MACFB (obj) \ + OBJECT_CHECK(MacfbNubusState, (obj), TYPE_NUBUS_MACFB) + +typedef struct { +NubusDevice busdev; + +MacfbState macfb; +}MacfbNubusState ; +#endif
include/hw/nubus/mac-nubus-bridge.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* Copyright (c) 2013-2018 Laurent Vivier <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#ifndef HW_NUBUS_MAC_H +#define HW_NUBUS_MAC_H + +#include "hw/nubus/nubus.h" + +#define TYPE_MAC_NUBUS_BRIDGE "mac-nubus-bridge" +#define MAC_NUBUS_BRIDGE (obj) OBJECT_CHECK(MacNubusState, (obj), \ + TYPE_MAC_NUBUS_BRIDGE) + +typedef struct MacNubusState { +SysBusDevice sysbus_dev; + +NubusBus *bus; +}MacNubusState ; + +#endif
include/hw/nubus/nubus.h new file +69 -0
69 lines not on this page · raw message
Signature · 1 line
2.14.4
Re: [Qemu-devel] [RFC v3 07/10] hw/m68k: add Nubus support
Quoted 129 lines · Laurent Vivier
Co-developed-by Mark Cave-Ayland <[email protected]>Signed-off-by Mark Cave-Ayland <[email protected]>Signed-off-by Laurent Vivier <[email protected]>--- hw/Makefile.objs | 1 + hw/display/macfb.c | 56 ++++++++++ hw/nubus/Makefile.objs | 4 + hw/nubus/mac-nubus-bridge.c | 45 ++++++++ hw/nubus/nubus-bridge.c | 34 ++++++ hw/nubus/nubus-bus.c | 111 +++++++++++++++++++ hw/nubus/nubus-device.c | 210 ++++++++++++++++++++++++++++++++++++ include/hw/display/macfb.h | 21 ++++ include/hw/nubus/mac-nubus-bridge.h | 24 +++++ include/hw/nubus/nubus.h | 69 ++++++++++++ 10 files changed, 575 insertions(+)create mode 100644 hw/nubus/Makefile.objs create mode 100644
hw/nubus/mac-nubus-bridge.ccreate mode 100644hw/nubus/nubus-bridge.ccreate mode 100644hw/nubus/nubus-bus.ccreate mode 100644hw/nubus/nubus-device.ccreate mode 100644include/hw/nubus/mac-nubus-bridge.hcreate mode 100644include/hw/nubus/nubus.hhw/Makefile.objs +1
-0@@ -35,6 +35,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += watchdog/ devices-dirs-$(CONFIG_SOFTMMU) += xen/ devices-dirs-$(CONFIG_MEM_HOTPLUG) += mem/ devices-dirs-$(CONFIG_SOFTMMU) += smbios/ +devices-dirs-$(CONFIG_NUBUS) += nubus/ devices-dirs-y += core/ common-obj-y += $(devices-dirs-y) obj-y += $(devices-dirs-y)hw/display/macfb.c +52
-0@@ -14,6 +14,7 @@#include "hw/sysbus.h" #include "ui/console.h" #include "ui/pixel_ops.h" +#include "hw/nubus/nubus.h" #include "hw/display/macfb.h" #define VIDEO_BASE 0x00001000@@ -213,12 +214,38 @@ static void macfb_sysbus_realize(DeviceState *dev, Error **errp)sysbus_init_mmio (SYS_BUS_DEVICE (s), &ms->mem_vram); } +const uint8_t macfb_rom[] = { +255 ,0 ,0 ,0 , +}; + +static void macfb_nubus_realize (DeviceState *dev,Error **errp) +{ +NubusDevice *nd =NUBUS_DEVICE (dev); +MacfbNubusState *s =NUBUS_MACFB (dev); +MacfbNubusDeviceClass *ndc =MACFB_NUBUS_GET_CLASS (dev); +MacfbState *ms = &s->macfb; + + ndc->parent_realize (dev, errp); + +macfb_common_realize (dev, ms); +memory_region_add_subregion (&nd->slot_mem,DAFB_BASE , &ms->mem_ctrl); +memory_region_add_subregion (&nd->slot_mem,VIDEO_BASE , &ms->mem_vram); + +nubus_register_rom (nd, macfb_rom,sizeof (macfb_rom),1 ,9 ,0xf ); +} +static void macfb_sysbus_reset (DeviceState *d) {MacfbSysBusState *s =MACFB (d);macfb_reset (&s->macfb); } +static void macfb_nubus_reset (DeviceState *d) +{ +MacfbNubusState *s =NUBUS_MACFB (d); +macfb_reset (&s->macfb); +} +static Property macfb_sysbus_properties[] = {DEFINE_PROP_UINT32 ("width" , MacfbSysBusState, macfb.width,640 ),DEFINE_PROP_UINT32 ("height" , MacfbSysBusState, macfb.height,480 ),@@ -226,6 +253,13 @@ static Property macfb_sysbus_properties[] = { DEFINE_PROP_END_OF_LIST(), }; +static Property macfb_nubus_properties[] = { +DEFINE_PROP_UINT32 ("width" , MacfbNubusState, macfb.width,640 ), +DEFINE_PROP_UINT32 ("height" , MacfbNubusState, macfb.height,480 ), +DEFINE_PROP_UINT8 ("depth" , MacfbNubusState, macfb.depth,8 ), +DEFINE_PROP_END_OF_LIST (), +}; +static void macfb_sysbus_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);@@ -237,6 +271,19 @@ static void macfb_sysbus_class_init(ObjectClass *klass, void *data) dc->props = macfb_sysbus_properties; } +static void macfb_nubus_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +MacfbNubusDeviceClass *ndc =MACFB_NUBUS_DEVICE_CLASS (klass); + +device_class_set_parent_realize (dc, macfb_nubus_realize, + &ndc->parent_realize); + dc->desc ="Nubus Macintosh framebuffer" ; + dc->reset = macfb_nubus_reset; + dc->vmsd = &vmstate_macfb; + dc->props = macfb_nubus_properties; +} +static TypeInfo macfb_sysbus_info = { .name =TYPE_MACFB , .parent =TYPE_SYS_BUS_DEVICE ,@@ -244,9 +291,18 @@ static TypeInfo macfb_sysbus_info = { .class_init = macfb_sysbus_class_init, }; +static TypeInfo macfb_nubus_info = { + .name =TYPE_NUBUS_MACFB , + .parent =TYPE_NUBUS_DEVICE , + .instance_size =sizeof (MacfbNubusState), + .class_init = macfb_nubus_class_init,
hw/display/macfb.c static TypeInfo macfb_sysbus_info = { · line 308
Quoted 10 lines
hw/display/macfb.c +4
-0+ .class_size = sizeof(MacfbNubusDeviceClass), +}; +static void macfb_register_types (void ) {type_register_static (&macfb_sysbus_info); +type_register_static (&macfb_nubus_info); }type_init (macfb_register_types)
Can we split the macfb nubus parts into a follow-up patch from this one? I think it makes a nicer division, and also provides a single reference commit that can be used to show how adding NuBus support to other devices can be done in future.
Quoted 559 lines
hw/nubus/Makefile.objs new file +4
-0@@ -0,0 +1,4 @@ +common-obj-y += nubus-device.o +common-obj-y += nubus-bus.o +common-obj-y += nubus-bridge.o +common-obj-$(CONFIG_MAC) += mac-nubus-bridge.ohw/nubus/mac-nubus-bridge.c new file +45
-0@@ -0,0 +1,45 @@ +/* +* Copyright (c) 2013-2018 Laurent Vivier <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#include "qemu/osdep.h" +#include "hw/sysbus.h" +#include "hw/nubus/mac-nubus-bridge.h" + + +static void mac_nubus_bridge_init (Object *obj) +{ +MacNubusState *s =MAC_NUBUS_BRIDGE (obj); +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); + + s->bus =NUBUS_BUS (qbus_create (TYPE_NUBUS_BUS ,DEVICE (s),NULL )); + +sysbus_init_mmio (sbd, &s->bus->super_slot_io); +sysbus_init_mmio (sbd, &s->bus->slot_io); +} + +static void mac_nubus_bridge_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->desc ="Nubus bridge" ; +} + +static const TypeInfo mac_nubus_bridge_info = { + .name =TYPE_MAC_NUBUS_BRIDGE , + .parent =TYPE_NUBUS_BRIDGE , + .instance_init = mac_nubus_bridge_init, + .instance_size =sizeof (MacNubusState), + .class_init = mac_nubus_bridge_class_init, +}; + +static void mac_nubus_bridge_register_types (void ) +{ +type_register_static (&mac_nubus_bridge_info); +} + +type_init (mac_nubus_bridge_register_types)hw/nubus/nubus-bridge.c new file +34
-0@@ -0,0 +1,34 @@ +/* +* QEMU Macintosh Nubus +* +* Copyright (c) 2013-2018 Laurent Vivier <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#include "qemu/osdep.h" +#include "hw/sysbus.h" +#include "hw/nubus/nubus.h" + +static void nubus_bridge_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->fw_name ="nubus" ; +} + +static const TypeInfo nubus_bridge_info = { + .name =TYPE_NUBUS_BRIDGE , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (SysBusDevice), + .class_init = nubus_bridge_class_init, +}; + +static void nubus_register_types (void ) +{ +type_register_static (&nubus_bridge_info); +} + +type_init (nubus_register_types)hw/nubus/nubus-bus.c new file +111
-0@@ -0,0 +1,111 @@ +/* +* QEMU Macintosh Nubus +* +* Copyright (c) 2013-2018 Laurent Vivier <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#include "qemu/osdep.h" +#include "hw/nubus/nubus.h" +#include "hw/sysbus.h" +#include "qapi/error.h" + + +static NubusBus *nubus_find (void ) +{ +/* Returns NULL unless there is exactly one nubus device */ +return NUBUS_BUS (object_resolve_path_type ("" ,TYPE_NUBUS_BUS ,NULL )); +} + +static void nubus_slot_write (void *opaque,hwaddr addr,uint64_t val, +unsigned int size) +{ +return ; +} + + +static uint64_t nubus_slot_read (void *opaque,hwaddr addr, +unsigned int size) +{ +return 0 ; +} + +static const MemoryRegionOps nubus_slot_ops = { + .read = nubus_slot_read, + .write = nubus_slot_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .valid = { + .min_access_size =1 , + .max_access_size =1 , + }, +}; + +static void nubus_super_slot_write (void *opaque,hwaddr addr,uint64_t val, +unsigned int size) +{ +return ; +} + +static uint64_t nubus_super_slot_read (void *opaque,hwaddr addr, +unsigned int size) +{ +return 0 ; +} + +static const MemoryRegionOps nubus_super_slot_ops = { + .read = nubus_super_slot_read, + .write = nubus_super_slot_write, + .endianness =DEVICE_BIG_ENDIAN , + .valid = { + .min_access_size =1 , + .max_access_size =1 , + }, +}; + +static void nubus_realize (BusState *bus,Error **errp) +{ +if (!nubus_find ()) { +error_setg (errp,"at most one %s device is permitted" ,TYPE_NUBUS_BUS ); +return ; + } +} + +static void nubus_init (Object *obj) +{ +NubusBus *nubus =NUBUS_BUS (obj); + +memory_region_init_io (&nubus->super_slot_io, obj, &nubus_super_slot_ops, + nubus,"nubus-super-slots" , +NUBUS_SUPER_SLOT_NB *NUBUS_SUPER_SLOT_SIZE ); + +memory_region_init_io (&nubus->slot_io, obj, &nubus_slot_ops, + nubus,"nubus-slots" , +NUBUS_SLOT_NB *NUBUS_SLOT_SIZE ); + + nubus->current_slot =NUBUS_FIRST_SLOT ; +} + +static void nubus_class_init (ObjectClass *oc,void *data) +{ +BusClass *bc =BUS_CLASS (oc); + + bc->realize = nubus_realize; +} + +static const TypeInfo nubus_bus_info = { + .name =TYPE_NUBUS_BUS , + .parent =TYPE_BUS , + .instance_size =sizeof (NubusBus), + .instance_init = nubus_init, + .class_init = nubus_class_init, +}; + +static void nubus_register_types (void ) +{ +type_register_static (&nubus_bus_info); +} + +type_init (nubus_register_types)hw/nubus/nubus-device.c new file +210
-0@@ -0,0 +1,210 @@ +/* +* QEMU Macintosh Nubus +* +* Copyright (c) 2013-2018 Laurent Vivier <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#include "qemu/osdep.h" +#include "hw/nubus/nubus.h" +#include "qapi/error.h" + + +/* The Format Block Structure */ + +#define FBLOCK_DIRECTORY_OFFSET 0 +#define FBLOCK_LENGTH 4 +#define FBLOCK_CRC 8 +#define FBLOCK_REVISION_LEVEL 12 +#define FBLOCK_FORMAT 13 +#define FBLOCK_TEST_PATTERN 14 +#define FBLOCK_RESERVED 18 +#define FBLOCK_BYTE_LANES 19 + +#define FBLOCK_SIZE 20 + +# define FBLOCK_PATTERN_VAL 0x5a932bc7 + +static uint64_t nubus_fblock_read (void *opaque,hwaddr addr,unsigned int size) +{ +NubusDevice *dev = opaque; +uint64_t val; + +#define BYTE (v, b) (((v) >> (24 - 8 * (b))) & 0xff) +switch (addr) { +case FBLOCK_BYTE_LANES : + val = dev->byte_lanes; + val |= (val ^0xf ) <<4 ; +break ; +case FBLOCK_RESERVED : + val =0x00 ; +break ; + case FBLOCK_TEST_PATTERN...FBLOCK_TEST_PATTERN + 3: + val =BYTE (FBLOCK_PATTERN_VAL , addr -FBLOCK_TEST_PATTERN ); +break ; +case FBLOCK_FORMAT : + val = dev->rom_format; +break ; +case FBLOCK_REVISION_LEVEL : + val = dev->rom_rev; +break ; + case FBLOCK_CRC...FBLOCK_CRC + 3: + val =BYTE (dev->rom_crc, addr -FBLOCK_CRC ); +break ; + case FBLOCK_LENGTH...FBLOCK_LENGTH + 3: + val =BYTE (dev->rom_length, addr -FBLOCK_LENGTH ); +break ; + case FBLOCK_DIRECTORY_OFFSET...FBLOCK_DIRECTORY_OFFSET + 3: + val =BYTE (dev->directory_offset, addr -FBLOCK_DIRECTORY_OFFSET ); +break ; +default : + val =0 ; +break ; + } +return val; +} + +static void nubus_fblock_write (void *opaque,hwaddr addr,uint64_t val, +unsigned int size) +{ +/* READ-ONLY */ +} + +static const MemoryRegionOps nubus_format_block_ops = { + .read = nubus_fblock_read, + .write = nubus_fblock_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .valid = { + .min_access_size =1 , + .max_access_size =1 , + } +}; + +static void nubus_register_format_block (NubusDevice *dev) +{ +char fblock_name[27 ]; + +sprintf (fblock_name,"nubus-slot-%d-format-block" , dev->slot_nb); + +hwaddr fblock_offset =memory_region_size (&dev->slot_mem) -FBLOCK_SIZE ; +memory_region_init_io (&dev->fblock_io,NULL , &nubus_format_block_ops, + dev, fblock_name,FBLOCK_SIZE ); +memory_region_add_subregion (&dev->slot_mem, fblock_offset, + &dev->fblock_io); +} + +static void mac_nubus_rom_write (void *opaque,hwaddr addr,uint64_t val, +unsigned int size) +{ +} + +static uint64_t mac_nubus_rom_read (void *opaque,hwaddr addr, +unsigned int size) +{ +NubusDevice *dev = opaque; + +return dev->rom[addr]; +} + +static const MemoryRegionOps mac_nubus_rom_ops = { + .read = mac_nubus_rom_read, + .write = mac_nubus_rom_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .valid = { + .min_access_size =1 , + .max_access_size =1 , + }, +}; + + +void nubus_register_rom (NubusDevice *dev,const uint8_t *rom,uint32_t size, +int revision,int format,uint8_t byte_lanes) +{ +hwaddr rom_offset; +char rom_name[18 ]; + +/* FIXME : really compute CRC */ + dev->rom_length =0 ; + dev->rom_crc =0 ; + + dev->rom_rev = revision; + dev->rom_format = format; + + dev->byte_lanes = byte_lanes; + dev->directory_offset = -size; + +/* ROM */ + + dev->rom = rom; +sprintf (rom_name,"nubus-slot-%d-rom" , dev->slot_nb); +memory_region_init_io (&dev->rom_io,NULL , &mac_nubus_rom_ops, + dev, rom_name, size); +memory_region_set_readonly (&dev->rom_io, true); + + rom_offset =memory_region_size (&dev->slot_mem) -FBLOCK_SIZE + + dev->directory_offset; +memory_region_add_subregion (&dev->slot_mem, rom_offset, &dev->rom_io); + +} + +static void nubus_device_realize (DeviceState *dev,Error **errp) +{ +NubusBus *nubus =NUBUS_BUS (qdev_get_parent_bus (DEVICE (dev))); +NubusDevice *nd =NUBUS_DEVICE (dev); +char name[16 ]; +hwaddr slot_offset; + +if (nubus->current_slot <NUBUS_FIRST_SLOT || + nubus->current_slot >NUBUS_LAST_SLOT ) { +error_setg (errp,"Cannot register nubus card, not enough slots" ); +return ; + } + + nd->slot_nb = nubus->current_slot++; +snprintf (name,sizeof (name),"nubus-slot-%d" , nd->slot_nb); + +if (nd->slot_nb <NUBUS_FIRST_SLOT ) { +/* Super */ + slot_offset = (nd->slot_nb -6 ) *NUBUS_SUPER_SLOT_SIZE ; + +memory_region_init (&nd->slot_mem,OBJECT (dev), name, +NUBUS_SUPER_SLOT_SIZE ); +memory_region_add_subregion (&nubus->super_slot_io, slot_offset, + &nd->slot_mem); + }else { +/* Normal */ + slot_offset = nd->slot_nb *NUBUS_SLOT_SIZE ; + +memory_region_init (&nd->slot_mem,OBJECT (dev), name,NUBUS_SLOT_SIZE ); +memory_region_add_subregion (&nubus->slot_io, slot_offset, + &nd->slot_mem); + } + +nubus_register_format_block (nd); +} + +static void nubus_device_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + + dc->realize = nubus_device_realize; + dc->bus_type =TYPE_NUBUS_BUS ; +} + +static const TypeInfo nubus_device_type_info = { + .name =TYPE_NUBUS_DEVICE , + .parent =TYPE_DEVICE , + .abstract = true, + .instance_size =sizeof (NubusDevice), + .class_init = nubus_device_class_init, +}; + +static void nubus_register_types (void ) +{ +type_register_static (&nubus_device_type_info); +} + +type_init (nubus_register_types)include/hw/display/macfb.h +21
-0@@ -39,4 +39,25 @@ typedef struct { MacfbState macfb; } MacfbSysBusState; +#define MACFB_NUBUS_DEVICE_CLASS (class) \ + OBJECT_CLASS_CHECK(MacfbNubusDeviceClass, (class), TYPE_NUBUS_MACFB) +#define MACFB_NUBUS_GET_CLASS (obj) \ + OBJECT_GET_CLASS(MacfbNubusDeviceClass, (obj), TYPE_NUBUS_MACFB) + +typedef struct MacfbNubusDeviceClass { +DeviceClass parent_class; + +DeviceRealize parent_realize; +}MacfbNubusDeviceClass ; + +#define TYPE_NUBUS_MACFB "nubus-macfb" +#define NUBUS_MACFB (obj) \ + OBJECT_CHECK(MacfbNubusState, (obj), TYPE_NUBUS_MACFB) + +typedef struct { +NubusDevice busdev; + +MacfbState macfb; +}MacfbNubusState ; +#endif include/hw/nubus/mac-nubus-bridge.h new file +24
-0@@ -0,0 +1,24 @@ +/* +* Copyright (c) 2013-2018 Laurent Vivier <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#ifndef HW_NUBUS_MAC_H +#define HW_NUBUS_MAC_H + +#include "hw/nubus/nubus.h" + +#define TYPE_MAC_NUBUS_BRIDGE "mac-nubus-bridge" +#define MAC_NUBUS_BRIDGE (obj) OBJECT_CHECK(MacNubusState, (obj), \ + TYPE_MAC_NUBUS_BRIDGE) + +typedef struct MacNubusState { +SysBusDevice sysbus_dev; + +NubusBus *bus; +}MacNubusState ; + +#endif include/hw/nubus/nubus.h new file +59
-0@@ -0,0 +1,69 @@ +/* +* Copyright (c) 2013-2018 Laurent Vivier <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#ifndef HW_NUBUS_NUBUS_H +#define HW_NUBUS_NUBUS_H + +#include "hw/qdev.h" +#include "exec/address-spaces.h" + +#define NUBUS_SUPER_SLOT_SIZE 0x10000000U +#define NUBUS_SUPER_SLOT_NB 0x9 + +#define NUBUS_SLOT_SIZE 0x01000000 +#define NUBUS_SLOT_NB 0xF + +#define NUBUS_FIRST_SLOT 0x9 +#define NUBUS_LAST_SLOT 0xF + +#define TYPE_NUBUS_DEVICE "nubus-device" +#define NUBUS_DEVICE(obj) \ + OBJECT_CHECK(NubusDevice, (obj), TYPE_NUBUS_DEVICE) + +#define TYPE_NUBUS_BUS "nubus-bus" +#define NUBUS_BUS(obj) OBJECT_CHECK(NubusBus, (obj), TYPE_NUBUS_BUS) + +#define TYPE_NUBUS_BRIDGE "nubus-bridge" +#define NUBUS_BRIDGE(obj) OBJECT_CHECK(NubusBridge, (obj), TYPE_NUBUS_BRIDGE) + +typedef struct NubusBus { + BusState qbus; + + MemoryRegion super_slot_io; + MemoryRegion slot_io; + + int current_slot; +} NubusBus; + +typedef struct NubusDevice { + DeviceState qdev; + + int slot_nb; + MemoryRegion slot_mem; + + /* Format Block */ + + MemoryRegion fblock_io; + + uint32_t rom_length; + uint32_t rom_crc; + uint8_t rom_rev; + uint8_t rom_format; + uint8_t byte_lanes; + int32_t directory_offset; +
include/hw/nubus/nubus.h line 69
Quoted 10 lines
include/hw/nubus/nubus.h new file +10
-0+/* ROM */ + +MemoryRegion rom_io; + const uint8_t *rom; +} NubusDevice; + +void nubus_register_rom (NubusDevice *dev,const uint8_t *rom,uint32_t size, +int revision,int format,uint8_t byte_lanes); + +#endif
ATB,
Mark.
RFC v3 8/10 hw/m68k: add a dummy SWIM floppy controller
In reply to Laurent Vivier--- hw/block/Makefile.objs | 1 + hw/block/swim.c | 284 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/block/swim.h | 53 +++++++++ 3 files changed, 338 insertions(+) create mode 100644 hw/block/swim.c create mode 100644 include/hw/block/swim.h
hw/block/Makefile.objs +1 -0
@@ -8,6 +8,7 @@ common-obj-$(CONFIG_XEN) += xen_disk.o common-obj-$(CONFIG_ECC) += ecc.o common-obj-$(CONFIG_ONENAND) += onenand.o common-obj-$(CONFIG_NVME_PCI) += nvme.o +common-obj-$(CONFIG_SWIM) += swim.o obj-$(CONFIG_SH4) += tc58128.o
hw/block/swim.c new file +284 -0
284 lines not on this page · raw message
include/hw/block/swim.h new file +53 -0
53 lines not on this page · raw message
Signature · 1 line
2.14.4
Re: [Qemu-devel] [RFC v3 08/10] hw/m68k: add a dummy SWIM floppy controller
Le 28/06/2018 à 01:29, Laurent Vivier a écrit :
Quoted 180 lines
Co-developed-by Mark Cave-Ayland <[email protected]>Signed-off-by Mark Cave-Ayland <[email protected]>Signed-off-by Laurent Vivier <[email protected]>--- hw/block/Makefile.objs | 1 + hw/block/swim.c | 284 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/block/swim.h | 53 +++++++++ 3 files changed, 338 insertions(+)create mode 100644
hw/block/swim.c
create mode 100644include/hw/block/swim.hhw/block/Makefile.objs +1
-0@@ -8,6 +8,7 @@ common-obj-$(CONFIG_XEN) += xen_disk.o common-obj-$(CONFIG_ECC) += ecc.o common-obj-$(CONFIG_ONENAND) += onenand.o common-obj-$(CONFIG_NVME_PCI) += nvme.o +common-obj-$(CONFIG_SWIM) += swim.o obj-$(CONFIG_SH4) += tc58128.ohw/block/swim.c new file +151
-0@@ -0,0 +1,284 @@ +/* +* QEMU Macintosh floppy disk controller emulator (SWIM) +* +* Copyright (c) 2014-2018 Laurent Vivier <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +*/ + +#include "qemu/osdep.h" +#include "hw/sysbus.h" +#include "hw/block/swim.h" + +/* IWM registers */ + +#define IWM_PH0L 0 +#define IWM_PH0H 1 +#define IWM_PH1L 2 +#define IWM_PH1H 3 +#define IWM_PH2L 4 +#define IWM_PH2H 5 +#define IWM_PH3L 6 +#define IWM_PH3H 7 +#define IWM_MTROFF 8 +#define IWM_MTRON 9 +#define IWM_INTDRIVE 10 +#define IWM_EXTDRIVE 11 +#define IWM_Q6L 12 +#define IWM_Q6H 13 +#define IWM_Q7L 14 +#define IWM_Q7H 15 + +/* SWIM registers */ + +#define SWIM_WRITE_DATA 0 +#define SWIM_WRITE_MARK 1 +#define SWIM_WRITE_CRC 2 +#define SWIM_WRITE_PARAMETER 3 +#define SWIM_WRITE_PHASE 4 +#define SWIM_WRITE_SETUP 5 +#define SWIM_WRITE_MODE0 6 +#define SWIM_WRITE_MODE1 7 + +#define SWIM_READ_DATA 8 +#define SWIM_READ_MARK 9 +#define SWIM_READ_ERROR 10 +#define SWIM_READ_PARAMETER 11 +#define SWIM_READ_PHASE 12 +#define SWIM_READ_SETUP 13 +#define SWIM_READ_STATUS 14 +#define SWIM_READ_HANDSHAKE 15 + +#define REG_SHIFT 9 + +#define SWIM_MODE_IWM 0 +#define SWIM_MODE_SWIM 1 + +/* bits in phase register */ + +#define SWIM_SEEK_NEGATIVE 0x074 +#define SWIM_STEP 0x071 +#define SWIM_MOTOR_ON 0x072 +#define SWIM_MOTOR_OFF 0x076 +#define SWIM_INDEX 0x073 +#define SWIM_EJECT 0x077 +#define SWIM_SETMFM 0x171 +#define SWIM_SETGCR 0x175 +#define SWIM_RELAX 0x033 +#define SWIM_LSTRB 0x008 +#define SWIM_CA_MASK 0x077 + +/* Select values for swim_select and swim_readbit */ + +#define SWIM_READ_DATA_0 0x074 +#define SWIM_TWOMEG_DRIVE 0x075 +#define SWIM_SINGLE_SIDED 0x076 +#define SWIM_DRIVE_PRESENT 0x077 +#define SWIM_DISK_IN 0x170 +#define SWIM_WRITE_PROT 0x171 +#define SWIM_TRACK_ZERO 0x172 +#define SWIM_TACHO 0x173 +#define SWIM_READ_DATA_1 0x174 +#define SWIM_MFM_MODE 0x175 +#define SWIM_SEEK_COMPLETE 0x176 +#define SWIM_ONEMEG_MEDIA 0x177 + +/* Bits in handshake register */ + +#define SWIM_MARK_BYTE 0x01 +#define SWIM_CRC_ZERO 0x02 +#define SWIM_RDDATA 0x04 +#define SWIM_SENSE 0x08 +#define SWIM_MOTEN 0x10 +#define SWIM_ERROR 0x20 +#define SWIM_DAT2BYTE 0x40 +#define SWIM_DAT1BYTE 0x80 + +/* bits in setup register */ + +#define SWIM_S_INV_WDATA 0x01 +#define SWIM_S_3_5_SELECT 0x02 +#define SWIM_S_GCR 0x04 +#define SWIM_S_FCLK_DIV2 0x08 +#define SWIM_S_ERROR_CORR 0x10 +#define SWIM_S_IBM_DRIVE 0x20 +#define SWIM_S_GCR_WRITE 0x40 +#define SWIM_S_TIMEOUT 0x80 + +/* bits in mode register */ + +#define SWIM_CLFIFO 0x01 +#define SWIM_ENBL1 0x02 +#define SWIM_ENBL2 0x04 +#define SWIM_ACTION 0x08 +#define SWIM_WRITE_MODE 0x10 +#define SWIM_HEDSEL 0x20 +#define SWIM_MOTON 0x80 + + +static void iwmctrl_write (void *opaque,hwaddr reg,uint64_t value, +unsigned size) +{ +SWIMCtrl *swimctrl = opaque; + + reg >>=REG_SHIFT ; + + swimctrl->regs[reg >>1 ] = reg &1 ; + +if (swimctrl->regs[IWM_Q6 ] && + swimctrl->regs[IWM_Q7 ]) { +if (swimctrl->regs[IWM_MTR ]) { +/* data register */ + swimctrl->iwm_data = value; + }else { +/* mode register */ + swimctrl->iwm_mode = value; +/* detect sequence to switch from IWM mode to SWIM mode */ +switch (swimctrl->iwm_switch) { +case 0 : +if (value ==0x57 ) { + swimctrl->iwm_switch++; + } +break ; +case 1 : +if (value ==0x17 ) { + swimctrl->iwm_switch++; + } +break ; +case 2 : +if (value ==0x57 ) {
hw/block/swim.c line 161
Quoted 10 lines
hw/block/swim.c new file +10
-0+ swimctrl->iwm_switch++; + } +break ; +case 3 : +if (value ==0x57 ) { + swimctrl->mode =SWIM_MODE_SWIM ; + swimctrl->iwm_switch =0 ; + } +break ; + }
I assume that the values of the sequence must be contiguous. If you don't follow it, you have to restart from scratch. In that case, you're missing the "else { swimctrl->iwm_switch = 0; }" in the cases 1 to 3.
You may also use the following pattern:
static const uint8_t iwm_switch_sequence[] = { 0x57, 0x17, 0x57, 0x57 };
if (value == iwm_switch_sequence[swimctrl->iwm_switch]) {
swimctrl->iwm_switch++;
if (swimctrl->iwm_switch == ARRAY_SIZE(iwm_switch_sequence)) {
swimctrl->mode = SWIM_MODE_SWIM;
swimctrl->iwm_switch = 0;
}
} else {
swimctrl->iwm_switch = 0;
}Hervé
Quoted 183 lines
hw/block/swim.c new file +123
-0+ } + } +} + +static uint64_t iwmctrl_read (void *opaque,hwaddr reg,unsigned size) +{ +SWIMCtrl *swimctrl = opaque; + + reg >>=REG_SHIFT ; + + swimctrl->regs[reg >>1 ] = reg &1 ; + +return 0 ; +} + +static void swimctrl_write (void *opaque,hwaddr reg,uint64_t value, +unsigned size) +{ +SWIMCtrl *swimctrl = opaque; + +if (swimctrl->mode ==SWIM_MODE_IWM ) { +iwmctrl_write (opaque, reg, value, size); +return ; + } + + reg >>=REG_SHIFT ; + +switch (reg) { +case SWIM_WRITE_PHASE : + swimctrl->swim_phase = value; +break ; +case SWIM_WRITE_MODE0 : + swimctrl->swim_mode &= ~value; +break ; +case SWIM_WRITE_MODE1 : + swimctrl->swim_mode |= value; +break ; +case SWIM_WRITE_DATA : +case SWIM_WRITE_MARK : +case SWIM_WRITE_CRC : +case SWIM_WRITE_PARAMETER : +case SWIM_WRITE_SETUP : +break ; + } +} + +static uint64_t swimctrl_read (void *opaque,hwaddr reg,unsigned size) +{ +SWIMCtrl *swimctrl = opaque; +uint32_t value =0 ; + +if (swimctrl->mode ==SWIM_MODE_IWM ) { +return iwmctrl_read (opaque, reg, size); + } + + reg >>=REG_SHIFT ; + +switch (reg) { +case SWIM_READ_PHASE : + value = swimctrl->swim_phase; +break ; +case SWIM_READ_HANDSHAKE : +if (swimctrl->swim_phase ==SWIM_DRIVE_PRESENT ) { +/* always answer "no drive present" */ + value =SWIM_SENSE ; + } +break ; +case SWIM_READ_DATA : +case SWIM_READ_MARK : +case SWIM_READ_ERROR : +case SWIM_READ_PARAMETER : +case SWIM_READ_SETUP : +case SWIM_READ_STATUS : +break ; + } + +return value; +} + +static const MemoryRegionOps swimctrl_mem_ops = { + .write = swimctrl_write, + .read = swimctrl_read, + .endianness =DEVICE_NATIVE_ENDIAN , +}; + +static void swim_init (Object *obj) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); +SWIMCtrl *swimctrl =SWIM (obj); + +memory_region_init_io (&swimctrl->iomem, obj, &swimctrl_mem_ops, swimctrl, +"swim" ,0x2000 ); +sysbus_init_mmio (sbd, &swimctrl->iomem); +} + +static Property swim_properties[] = { +DEFINE_PROP_DRIVE ("driveA" , SWIMCtrl, drives[0 ].blk), +DEFINE_PROP_DRIVE ("driveB" , SWIMCtrl, drives[1 ].blk), +DEFINE_PROP_END_OF_LIST (), +}; + +static void swim_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + + dc->props = swim_properties; +set_bit (DEVICE_CATEGORY_STORAGE , dc->categories); +} + +static const TypeInfo swim_info = { + .name =TYPE_SWIM , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (SWIMCtrl), + .instance_init = swim_init, + .class_init = swim_class_init, +}; + +static void swim_register_types (void ) +{ +type_register_static (&swim_info); +} + +type_init (swim_register_types)include/hw/block/swim.h new file +53
-0@@ -0,0 +1,53 @@ +/* +* QEMU Macintosh floppy disk controller emulator (SWIM) +* +* Copyright (c) 2014-2018 Laurent Vivier <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +*/ + +#ifndef SWIM_H +#define SWIM_H + +#include "qemu/osdep.h" +#include "hw/sysbus.h" + +#define MAX_FD 2 + +typedef struct SWIMCtrl SWIMCtrl ; + +typedef struct FDrive { +SWIMCtrl *swimctrl; +BlockBackend *blk; +}FDrive ; + +#define TYPE_SWIM "swim" +#define SWIM (obj) OBJECT_CHECK(SWIMCtrl, (obj), TYPE_SWIM) + +typedef struct SWIMCtrl { +SysBusDevice parent_obj; + +MemoryRegion iomem; +FDrive drives[MAX_FD ]; +int mode; +/* IWM mode */ +int iwm_switch; +int regs[8 ]; +#define IWM_PH0 0 +#define IWM_PH1 1 +#define IWM_PH2 2 +#define IWM_PH3 3 +#define IWM_MTR 4 +#define IWM_DRIVE 5 +#define IWM_Q6 6 +#define IWM_Q7 7 +uint8_t iwm_data; +uint8_t iwm_mode; +/* SWIM mode */ +uint8_t swim_phase; +uint8_t swim_mode; +}SWIMCtrl ; + +#endif
RFC v3 9/10 dp8393x: manage big endian bus
In reply to Laurent VivierThis is needed by Quadra 800, this card can run on little-endian or big-endian bus.
--- hw/net/dp8393x.c | 88 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 31 deletions(-)
hw/net/dp8393x.c +57 -31
@@ -150,6 +150,7 @@ typedef struct dp8393xState {/* Hardware */ uint8_t it_shift; +bool big_endian;qemu_irq irq;#ifdef DEBUG_SONIC int irq_level;
@@ -220,6 +221,29 @@ static uint32_t dp8393x_wt(dp8393xState *s)return s->regs[SONIC_WT1 ] <<16 | s->regs[SONIC_WT0 ]; } +static uint16_t dp8393x_get (dp8393xState *s,int width,uint16_t *base, +int offset) +{ +uint16_t val; + +if (s->big_endian) { + val =be16_to_cpu (base[offset * width + width -1 ]); + }else { + val =le16_to_cpu (base[offset * width]); + } +return val; +} + +static void dp8393x_put (dp8393xState *s,int width,uint16_t *base,int offset, +uint16_t val) +{ +if (s->big_endian) { + base[offset * width + width -1 ] =cpu_to_be16 (val); + }else { + base[offset * width] =cpu_to_le16 (val); + } +} +static void dp8393x_update_irq (dp8393xState *s) {int level = (s->regs[SONIC_IMR ] & s->regs[SONIC_ISR ]) ?1 :0 ;
@@ -251,12 +275,12 @@ static void dp8393x_do_load_cam(dp8393xState *s)/* Fill current entry */ address_space_rw (&s->as,dp8393x_cdp (s),MEMTXATTRS_UNSPECIFIED , (uint8_t *)data, size,0 ); - s->cam[index][0 ] = data[1 * width] &0xff ; - s->cam[index][1 ] = data[1 * width] >>8 ; - s->cam[index][2 ] = data[2 * width] &0xff ; - s->cam[index][3 ] = data[2 * width] >>8 ; - s->cam[index][4 ] = data[3 * width] &0xff ; - s->cam[index][5 ] = data[3 * width] >>8 ; + s->cam[index][0 ] =dp8393x_get (s, width, data,1 ) &0xff ; + s->cam[index][1 ] =dp8393x_get (s, width, data,1 ) >>8 ; + s->cam[index][2 ] =dp8393x_get (s, width, data,2 ) &0xff ; + s->cam[index][3 ] =dp8393x_get (s, width, data,2 ) >>8 ; + s->cam[index][4 ] =dp8393x_get (s, width, data,3 ) &0xff ; + s->cam[index][5 ] =dp8393x_get (s, width, data,3 ) >>8 ;DPRINTF ("load cam[%d] with %02x%02x%02x%02x%02x%02x\n" , index, s->cam[index][0 ], s->cam[index][1 ], s->cam[index][2 ], s->cam[index][3 ], s->cam[index][4 ], s->cam[index][5 ]);
@@ -269,7 +293,7 @@ static void dp8393x_do_load_cam(dp8393xState *s)/* Read CAM enable */ address_space_rw (&s->as,dp8393x_cdp (s),MEMTXATTRS_UNSPECIFIED , (uint8_t *)data, size,0 ); - s->regs[SONIC_CE ] = data[0 * width]; + s->regs[SONIC_CE ] =dp8393x_get (s, width, data,0 );DPRINTF ("load cam done. cam enable mask 0x%04x\n" , s->regs[SONIC_CE ]);/* Done */
@@ -290,10 +314,10 @@ static void dp8393x_do_read_rra(dp8393xState *s) MEMTXATTRS_UNSPECIFIED, (uint8_t *)data, size, 0);/* Update SONIC registers */ - s->regs[SONIC_CRBA0 ] = data[0 * width]; - s->regs[SONIC_CRBA1 ] = data[1 * width]; - s->regs[SONIC_RBWC0 ] = data[2 * width]; - s->regs[SONIC_RBWC1 ] = data[3 * width]; + s->regs[SONIC_CRBA0 ] =dp8393x_get (s, width, data,0 ); + s->regs[SONIC_CRBA1 ] =dp8393x_get (s, width, data,1 ); + s->regs[SONIC_RBWC0 ] =dp8393x_get (s, width, data,2 ); + s->regs[SONIC_RBWC1 ] =dp8393x_get (s, width, data,3 );DPRINTF ("CRBA0/1: 0x%04x/0x%04x, RBWC0/1: 0x%04x/0x%04x\n" , s->regs[SONIC_CRBA0 ], s->regs[SONIC_CRBA1 ], s->regs[SONIC_RBWC0 ], s->regs[SONIC_RBWC1 ]);
@@ -408,12 +432,12 @@ static void dp8393x_do_transmit_packets(dp8393xState *s) tx_len =0 ;/* Update registers */ - s->regs[SONIC_TCR ] = data[0 * width] &0xf000 ; - s->regs[SONIC_TPS ] = data[1 * width]; - s->regs[SONIC_TFC ] = data[2 * width]; - s->regs[SONIC_TSA0 ] = data[3 * width]; - s->regs[SONIC_TSA1 ] = data[4 * width]; - s->regs[SONIC_TFS ] = data[5 * width]; + s->regs[SONIC_TCR ] =dp8393x_get (s, width, data,0 ) &0xf000 ; + s->regs[SONIC_TPS ] =dp8393x_get (s, width, data,1 ); + s->regs[SONIC_TFC ] =dp8393x_get (s, width, data,2 ); + s->regs[SONIC_TSA0 ] =dp8393x_get (s, width, data,3 ); + s->regs[SONIC_TSA1 ] =dp8393x_get (s, width, data,4 ); + s->regs[SONIC_TFS ] =dp8393x_get (s, width, data,5 );/* Handle programmable interrupt */ if (s->regs[SONIC_TCR ] &SONIC_TCR_PINT ) {
@@ -439,9 +463,9 @@ static void dp8393x_do_transmit_packets(dp8393xState *s)address_space_rw (&s->as,dp8393x_ttda (s) +sizeof (uint16_t ) * (4 +3 * i) * width,MEMTXATTRS_UNSPECIFIED , (uint8_t *)data, size,0 ); - s->regs[SONIC_TSA0 ] = data[0 * width]; - s->regs[SONIC_TSA1 ] = data[1 * width]; - s->regs[SONIC_TFS ] = data[2 * width]; + s->regs[SONIC_TSA0 ] =dp8393x_get (s, width, data,0 ); + s->regs[SONIC_TSA1 ] =dp8393x_get (s, width, data,1 ); + s->regs[SONIC_TFS ] =dp8393x_get (s, width, data,2 ); } }
@@ -468,7 +492,8 @@ static void dp8393x_do_transmit_packets(dp8393xState *s) s->regs[SONIC_TCR ] |=SONIC_TCR_PTX ;/* Write status */ - data[0 * width] = s->regs[SONIC_TCR ] &0x0fff ;/* status */ +dp8393x_put (s, width, data,0 , + s->regs[SONIC_TCR ] &0x0fff );/* status */ size =sizeof (uint16_t ) * width; address_space_rw(&s->as, dp8393x_ttda(s),
@@ -482,8 +507,8 @@ static void dp8393x_do_transmit_packets(dp8393xState *s)sizeof (uint16_t ) * (4 +3 * s->regs[SONIC_TFC ]) * width, MEMTXATTRS_UNSPECIFIED, (uint8_t *)data, size, 0); - s->regs[SONIC_CTDA ] = data[0 * width] & ~0x1 ; -if (data[0 * width] &0x1 ) { + s->regs[SONIC_CTDA ] =dp8393x_get (s, width, data,0 ) & ~0x1 ; +if (dp8393x_get (s, width, data,0 ) &0x1 ) {/* EOL detected */ break ; }
@@ -746,7 +771,7 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf, address =dp8393x_crda (s) +sizeof (uint16_t ) *5 * width;address_space_rw (&s->as, address,MEMTXATTRS_UNSPECIFIED , (uint8_t *)data, size,0 ); -if (data[0 * width] &0x1 ) { +if (dp8393x_get (s, width, data,0 ) &0x1 ) {/* Still EOL ; stop reception */ return -1 ; }else {
@@ -790,11 +815,11 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf,/* Write status to memory */ DPRINTF ("Write status at %08x\n" ,dp8393x_crda (s)); - data[0 * width] = s->regs[SONIC_RCR ];/* status */ - data[1 * width] = rx_len;/* byte count */ - data[2 * width] = s->regs[SONIC_TRBA0 ];/* pkt_ptr0 */ - data[3 * width] = s->regs[SONIC_TRBA1 ];/* pkt_ptr1 */ - data[4 * width] = s->regs[SONIC_RSC ];/* seq_no */ +dp8393x_put (s, width, data,0 , s->regs[SONIC_RCR ]);/* status */ +dp8393x_put (s, width, data,1 , rx_len);/* byte count */ +dp8393x_put (s, width, data,2 , s->regs[SONIC_TRBA0 ]);/* pkt_ptr0 */ +dp8393x_put (s, width, data,3 , s->regs[SONIC_TRBA1 ]);/* pkt_ptr1 */ +dp8393x_put (s, width, data,4 , s->regs[SONIC_RSC ]);/* seq_no */ size =sizeof (uint16_t ) *5 * width;address_space_rw (&s->as,dp8393x_crda (s),MEMTXATTRS_UNSPECIFIED , (uint8_t *)data, size,1 );
@@ -803,12 +828,12 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf, size =sizeof (uint16_t ) * width;address_space_rw (&s->as,dp8393x_crda (s) +sizeof (uint16_t ) *5 * width,MEMTXATTRS_UNSPECIFIED , (uint8_t *)data, size,0 ); - s->regs[SONIC_LLFA ] = data[0 * width]; + s->regs[SONIC_LLFA ] =dp8393x_get (s, width, data,0 );if (s->regs[SONIC_LLFA ] &0x1 ) {/* EOL detected */ s->regs[SONIC_ISR ] |=SONIC_ISR_RDE ; }else { - data[0 * width] =0 ;/* in_use */ +dp8393x_put (s, width, data,0 ,0 );/* in_use */ address_space_rw (&s->as,dp8393x_crda (s) +sizeof (uint16_t ) *6 * width,MEMTXATTRS_UNSPECIFIED , (uint8_t *)data,sizeof (uint16_t ),1 ); s->regs[SONIC_CRDA ] = s->regs[SONIC_LLFA ];
@@ -921,6 +946,7 @@ static Property dp8393x_properties[] = {DEFINE_NIC_PROPERTIES (dp8393xState, conf),DEFINE_PROP_PTR ("dma_mr" , dp8393xState, dma_mr),DEFINE_PROP_UINT8 ("it_shift" , dp8393xState, it_shift,0 ), +DEFINE_PROP_BOOL ("big_endian" , dp8393xState, big_endian, false), DEFINE_PROP_END_OF_LIST(), };
Signature · 1 line
2.14.4
Re: [Qemu-devel] [RFC v3 09/10] dp8393x: manage big endian bus
Quoted 57 lines · Laurent Vivier
This is needed by Quadra 800, this card can run on little-endian or big-endian bus.
Signed-off-by Laurent Vivier <[email protected]>Tested-by Hervé Poussineau <[email protected]>--- hw/net/dp8393x.c | 88 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 31 deletions(-)hw/net/dp8393x.c +24
-2@@ -150,6 +150,7 @@ typedef struct dp8393xState {/* Hardware */ uint8_t it_shift; +bool big_endian;qemu_irq irq;#ifdef DEBUG_SONIC int irq_level;@@ -220,6 +221,29 @@ static uint32_t dp8393x_wt(dp8393xState *s)return s->regs[SONIC_WT1 ] <<16 | s->regs[SONIC_WT0 ]; } +static uint16_t dp8393x_get (dp8393xState *s,int width,uint16_t *base, +int offset) +{ +uint16_t val; + +if (s->big_endian) { + val =be16_to_cpu (base[offset * width + width -1 ]); + }else { + val =le16_to_cpu (base[offset * width]); + } +return val; +} + +static void dp8393x_put (dp8393xState *s,int width,uint16_t *base,int offset, +uint16_t val) +{ +if (s->big_endian) { + base[offset * width + width -1 ] =cpu_to_be16 (val); + }else { + base[offset * width] =cpu_to_le16 (val); + } +} +static void dp8393x_update_irq (dp8393xState *s) {int level = (s->regs[SONIC_IMR ] & s->regs[SONIC_ISR ]) ?1 :0 ;@@ -251,12 +275,12 @@ static void dp8393x_do_load_cam(dp8393xState *s)/* Fill current entry */ address_space_rw (&s->as,dp8393x_cdp (s),MEMTXATTRS_UNSPECIFIED , (uint8_t *)data, size,0 ); - s->cam[index][0 ] = data[1 * width] &0xff ; - s->cam[index][1 ] = data[1 * width] >>8 ;
hw/net/dp8393x.c static void dp8393x_do_load_cam(dp8393xState *s) · line 283
Quoted 10 lines
hw/net/dp8393x.c +6
-4- s->cam[index][2 ] = data[2 * width] &0xff ; - s->cam[index][3 ] = data[2 * width] >>8 ; - s->cam[index][4 ] = data[3 * width] &0xff ; - s->cam[index][5 ] = data[3 * width] >>8 ; + s->cam[index][0 ] =dp8393x_get (s, width, data,1 ) &0xff ; + s->cam[index][1 ] =dp8393x_get (s, width, data,1 ) >>8 ; + s->cam[index][2 ] =dp8393x_get (s, width, data,2 ) &0xff ; + s->cam[index][3 ] =dp8393x_get (s, width, data,2 ) >>8 ; + s->cam[index][4 ] =dp8393x_get (s, width, data,3 ) &0xff ; + s->cam[index][5 ] =dp8393x_get (s, width, data,3 ) >>8 ;
The general pattern with the code in this device seems to be "load sizeof(uint16_t) * width * N bytes; then look at data[i * width], possibly with an endianness flip", where width is either 1 or 2 depending on a config register.
Maybe it would be clearer if the data was loaded by doing a loop of N iterations of address_space_ldl_le / address_space_ldw_le / address_space_ldl_be / address_space_ldw_be ? Then you're doing something more like what the device is doing (ie a series of bus accesses of a particular width and endianness), and the handling of width and endianness is in the code doing the data loads rather than in the code that is manipulating the loaded data.
Incidentally, the only other use of this device is in the mips 'jazz' boards. Those seem to be compiled for both mips64el and mips64 -- does anybody know if it actually works correctly in both those configurations ?
thanks
-- PMM
Re: [Qemu-devel] [RFC v3 09/10] dp8393x: manage big endian bus
Le 08/07/2018 à 23:11, Peter Maydell a écrit :
Quoted 83 lines · Laurent Vivier
Quoted 57 lines
This is needed by Quadra 800, this card can run on little-endian or big-endian bus.
Signed-off-by Laurent Vivier <[email protected]>Tested-by Hervé Poussineau <[email protected]>--- hw/net/dp8393x.c | 88 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 31 deletions(-)hw/net/dp8393x.c +24
-2@@ -150,6 +150,7 @@ typedef struct dp8393xState {/* Hardware */ uint8_t it_shift; +bool big_endian;qemu_irq irq;#ifdef DEBUG_SONIC int irq_level;@@ -220,6 +221,29 @@ static uint32_t dp8393x_wt(dp8393xState *s)return s->regs[SONIC_WT1 ] <<16 | s->regs[SONIC_WT0 ]; } +static uint16_t dp8393x_get (dp8393xState *s,int width,uint16_t *base, +int offset) +{ +uint16_t val; + +if (s->big_endian) { + val =be16_to_cpu (base[offset * width + width -1 ]); + }else { + val =le16_to_cpu (base[offset * width]); + } +return val; +} + +static void dp8393x_put (dp8393xState *s,int width,uint16_t *base,int offset, +uint16_t val) +{ +if (s->big_endian) { + base[offset * width + width -1 ] =cpu_to_be16 (val); + }else { + base[offset * width] =cpu_to_le16 (val); + } +} +static void dp8393x_update_irq (dp8393xState *s) {int level = (s->regs[SONIC_IMR ] & s->regs[SONIC_ISR ]) ?1 :0 ;@@ -251,12 +275,12 @@ static void dp8393x_do_load_cam(dp8393xState *s)/* Fill current entry */ address_space_rw (&s->as,dp8393x_cdp (s),MEMTXATTRS_UNSPECIFIED , (uint8_t *)data, size,0 ); - s->cam[index][0 ] = data[1 * width] &0xff ; - s->cam[index][1 ] = data[1 * width] >>8 ;hw/net/dp8393x.c static void dp8393x_do_load_cam(dp8393xState *s) · line 283
Quoted 10 lines
hw/net/dp8393x.c +6
-4- s->cam[index][2 ] = data[2 * width] &0xff ; - s->cam[index][3 ] = data[2 * width] >>8 ; - s->cam[index][4 ] = data[3 * width] &0xff ; - s->cam[index][5 ] = data[3 * width] >>8 ; + s->cam[index][0 ] =dp8393x_get (s, width, data,1 ) &0xff ; + s->cam[index][1 ] =dp8393x_get (s, width, data,1 ) >>8 ; + s->cam[index][2 ] =dp8393x_get (s, width, data,2 ) &0xff ; + s->cam[index][3 ] =dp8393x_get (s, width, data,2 ) >>8 ; + s->cam[index][4 ] =dp8393x_get (s, width, data,3 ) &0xff ; + s->cam[index][5 ] =dp8393x_get (s, width, data,3 ) >>8 ;The general pattern with the code in this device seems to be "load
sizeof(uint16_t)* width * N bytes; then look at data[i * width], possibly with an endianness flip", where width is either 1 or 2 depending on a config register.Maybe it would be clearer if the data was loaded by doing a loop of N iterations of
address_space_ldl_le/address_space_ldw_le/address_space_ldl_be/address_space_ldw_be? Then you're doing something more like what the device is doing (ie a series of bus accesses of a particular width and endianness), and the handling of width and endianness is in the code doing the data loads rather than in the code that is manipulating the loaded data.
Quoted 4 lines
Incidentally, the only other use of this device is in the mips 'jazz' boards. Those seem to be compiled for both mips64el and mips64 -- does anybody know if it actually works correctly in both those configurations ?
dp8393x in mips64el works well. mips64 is not testable.
Hervé
RFC v3 10/10 hw/m68k: define Macintosh Quadra 800
In reply to Laurent VivierFrom: Laurent Vivier <[email protected]>
--- MAINTAINERS | 19 ++ default-configs/m68k-softmmu.mak | 14 ++ hw/intc/Makefile.objs | 1 + hw/intc/q800_irq.c | 73 ++++++++ hw/m68k/Makefile.objs | 6 +- hw/m68k/bootinfo.h | 100 ++++++++++ hw/m68k/q800.c | 385 +++++++++++++++++++++++++++++++++++++++ include/hw/intc/q800_irq.h | 39 ++++ tests/qom-test.c | 5 + tests/test-hmp.c | 3 +- 10 files changed, 642 insertions(+), 3 deletions(-) create mode 100644 hw/intc/q800_irq.c create mode 100644 hw/m68k/bootinfo.h create mode 100644 hw/m68k/q800.c create mode 100644 include/hw/intc/q800_irq.h
MAINTAINERS +19 -0
@@ -693,6 +693,25 @@ F: hw/char/mcf_uart.c F: hw/net/mcf_fec.c F: include/hw/m68k/mcf*.h +q800 +M: Laurent Vivier <[email protected]> +S: Maintained +F: hw/audio/asc.c +F: hw/block/swim.c +F: hw/m68k/bootinfo.h +F: hw/display/macfb-template.h +F: hw/display/macfb.c +F: hw/intc/q800_irq.c +F: hw/m68k/q800.c +F: hw/misc/mac_via.c +F: hw/nubus/* +F: include/hw/audio/asc.h +F: include/hw/block/swim.h +F: include/hw/display/macfb.h +F: include/hw/intc/q800_irq.h +F: include/hw/misc/mac_via.h +F: include/hw/nubus/* + MicroBlaze Machines ------------------- petalogix_s3adsp1800
default-configs/m68k-softmmu.mak +14 -0
@@ -2,3 +2,17 @@ CONFIG_COLDFIRE=y CONFIG_PTIMER=y +CONFIG_ESCC=y +CONFIG_FRAMEBUFFER=y +CONFIG_ADB=y +CONFIG_MOS6522=y +CONFIG_MAC_VIA=y +CONFIG_Q800_IRQ=y +CONFIG_MAC=y +CONFIG_SCSI=y +CONFIG_ESP=y +CONFIG_ASC=y +CONFIG_MACFB=y +CONFIG_NUBUS=y +CONFIG_DP8393X=y +CONFIG_SWIM=y
hw/intc/Makefile.objs +1 -0
@@ -46,3 +46,4 @@ obj-$(CONFIG_ARM_GIC) += arm_gicv3_cpuif.o obj-$(CONFIG_MIPS_CPS) += mips_gic.o obj-$(CONFIG_NIOS2) += nios2_iic.o obj-$(CONFIG_OMPIC) += ompic.o +obj-$(CONFIG_Q800_IRQ) += q800_irq.o
hw/intc/q800_irq.c new file +73 -0
73 lines not on this page · raw message
hw/m68k/Makefile.objs +4 -2
@@ -1,2 +1,4 @@ -obj-y += an5206.o mcf5208.o -obj-y += mcf5206.o mcf_intc.o +obj-$(CONFIG_COLDFIRE) += an5206.o mcf5208.o +obj-$(CONFIG_MAC) += q800.o + +obj-$(CONFIG_COLDFIRE) += mcf5206.o mcf_intc.o
hw/m68k/bootinfo.h new file +100 -0
100 lines not on this page · raw message
hw/m68k/q800.c new file +385 -0
385 lines not on this page · raw message
include/hw/intc/q800_irq.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* QEMU Motorla 680x0 Macintosh hardware System Emulator +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#ifndef Q800_IRQ_H +#define Q800_IRQ_H + +#include "hw/sysbus.h" + +#define TYPE_Q800_IRQC "q800-irq-controller" +#define Q800_IRQC (obj) OBJECT_CHECK(Q800IRQControllerState, (obj), \ + TYPE_Q800_IRQC) + +typedef struct Q800IRQControllerState { +SysBusDevice parent_obj; + +M68kCPU *cpu; +uint8_t ipr; +}Q800IRQControllerState ; + +#endif
tests/qom-test.c +5 -0
@@ -19,12 +19,17 @@ static const char *blacklist_x86[] = { "xenfv", "xenpv", NULL }; +static const char *blacklist_m68k[] = { +"q800" ,NULL +}; +static const struct {const char *arch;const char **machine; } blacklists[] = { {"i386" , blacklist_x86 }, {"x86_64" , blacklist_x86 }, + {"m68k" , blacklist_m68k }, };static bool is_blacklisted (const char *arch,const char *mach)
tests/test-hmp.c +2 -1
@@ -139,7 +139,8 @@ static void add_machine_test_case(const char *mname)char *path;/* Ignore blacklisted machines that have known problems */ -if (!strcmp ("xenfv" , mname) || !strcmp ("xenpv" , mname)) { +if (!strcmp ("xenfv" , mname) || !strcmp ("xenpv" , mname) || + !strcmp ("q800" , mname)) {return ; }
Signature · 1 line
2.14.4
Quoted 130 lines · Laurent Vivier
I'm rebasing some of these patches for seven years now, too many years...
if you want to test the machine, I'm sorry, it doesn't boot a MacROM, but you can boot a linux kernel from the command line.
You can install your own disk using debian-installer, with:
... -M q800 \ -serial none -serial mon:stdio \ -m 1000M -drive file=m68k.qcow2,format=qcow2 \ -net nic,model=dp83932,addr=09:00:07:12:34:57 \ -append "console=ttyS0 vga=off" \ -kernel vmlinux-4.15.0-2-m68k \ -initrd initrd.gz \ -drive file=debian-9.0-m68k-NETINST-1.iso \ -drive file=m68k.qcow2,format=qcow2 \ -nographicIf you use a graphic adapter instead of "-nographic", you can use "-g" to set the size of the display (I use "-g 1600x800x24").
You can get the ISO from:
https://cdimage.debian.org/mirror/cdimage/ports/9.0/m68k/iso-cd/debian-9.0-m68k-NETINST-1.iso
and extract the kernel and initrd.gz:
guestfish --add debian-9.0-m68k-NETINST-1.iso --ro \ --mount /dev/sda:/ <<_EOF_copy-out /install/cdrom/initrd.gz .
copy-out /install/kernels/vmlinux-4.15.0-2-m68k .
_EOF_The mirror to use is: http://ftp.ports.debian.org/debian-ports/
when it fails, continue without boot loader.In the same way, you can extract the kernel and the initramfs from the qcow2 image to use it with "-kernel" and "-initrd":
guestfish --add m68k.qcow2 --mount /dev/sda2:/ <<_EOF_ copy-out
/boot/vmlinux-4.15.0-2-m68k. copy-out/boot/initrd.img-4.15.0-2-m68k. _EOF_and boot with:
... -append "root=/dev/sda2 rw console=ttyS0 console=tty \ -kernel vmlinux-4.15.0-2-m68k \ -initrd initrd.img-4.15.0-2-m68kv3: fix subject prefix "C" -> "RFC"
v2: remove the dp8393x fixes, because one of the patch breaks something
Update "dp8393x: manage big endian bus" with idea from Thomas Mark has reworked most of the patches:
- use mos6522
- some code move, renamings and cleanupLaurent Vivier (10):
hw/m68k: add via support
ADB: VIA probes ADB bus when it is idle
escc: introduce a selector for the register bit hw/m68k: add video card
hw/m68k: Apple Sound Chip (ASC) emulation
ESP: add pseudo-DMA as used by Macintosh hw/m68k: add Nubus support
hw/m68k: add a dummy SWIM floppy controller
dp8393x: manage big endian bus
hw/m68k: define Macintosh Quadra 800MAINTAINERS | 19 + arch_init.c | 4 + default-configs/m68k-softmmu.mak | 14 + hw/Makefile.objs | 1 + hw/audio/Makefile.objs | 1 + hw/audio/asc.c | 463 +++++++++++++++++++++++ hw/block/Makefile.objs | 1 + hw/block/swim.c | 284 ++++++++++++++ hw/char/escc.c | 30 +- hw/display/Makefile.objs | 1 + hw/display/macfb-template.h | 158 ++++++++ hw/display/macfb.c | 308 +++++++++++++++ hw/input/adb-kbd.c | 4 + hw/input/adb-mouse.c | 4 + hw/input/adb.c | 115 ++++++ hw/intc/Makefile.objs | 1 + hw/intc/q800_irq.c | 73 ++++ hw/m68k/Makefile.objs | 6 +- hw/m68k/bootinfo.h | 100 +++++ hw/m68k/q800.c | 385 +++++++++++++++++++ hw/mips/mips_jazz.c | 2 +- hw/misc/Makefile.objs | 1 + hw/misc/mac_via.c | 731 ++++++++++++++++++++++++++++++++++++ hw/net/dp8393x.c | 88 +++-- hw/nubus/Makefile.objs | 4 + hw/nubus/mac-nubus-bridge.c | 45 +++ hw/nubus/nubus-bridge.c | 34 ++ hw/nubus/nubus-bus.c | 111 ++++++ hw/nubus/nubus-device.c | 210 +++++++++++ hw/scsi/esp.c | 297 +++++++++++++-- include/hw/audio/asc.h | 48 +++ include/hw/block/swim.h | 53 +++ include/hw/char/escc.h | 1 + include/hw/display/macfb.h | 63 ++++ include/hw/input/adb.h | 10 + include/hw/intc/q800_irq.h | 39 ++ include/hw/misc/mac_via.h | 107 ++++++ include/hw/nubus/mac-nubus-bridge.h | 24 ++ include/hw/nubus/nubus.h | 69 ++++ include/hw/scsi/esp.h | 11 +- qemu-options.hx | 2 +- tests/qom-test.c | 5 + tests/test-hmp.c | 3 +- vl.c | 3 +- 44 files changed, 3857 insertions(+), 76 deletions(-)create mode 100644
hw/audio/asc.c
create mode 100644hw/block/swim.c
create mode 100644hw/display/macfb-template.h
create mode 100644hw/display/macfb.c
create mode 100644hw/intc/q800_irq.c
create mode 100644hw/m68k/bootinfo.h
create mode 100644hw/m68k/q800.c
create mode 100644hw/misc/mac_via.c
create mode 100644 hw/nubus/Makefile.objs
create mode 100644hw/nubus/mac-nubus-bridge.c
create mode 100644hw/nubus/nubus-bridge.c
create mode 100644hw/nubus/nubus-bus.c
Quoted 8 lines
create mode 100644
hw/nubus/nubus-device.ccreate mode 100644include/hw/audio/asc.hcreate mode 100644include/hw/block/swim.hcreate mode 100644include/hw/display/macfb.hcreate mode 100644include/hw/intc/q800_irq.hcreate mode 100644include/hw/misc/mac_via.hcreate mode 100644include/hw/nubus/mac-nubus-bridge.hcreate mode 100644include/hw/nubus/nubus.h
I'm fairly happy with the majority of these patches apart from 2 of them which I will reply to separately.
A couple of minor points around files/naming:
- mac_via.c seems a bit vague, for example we already have 2 mac VIAs for PPC Macs (CUDA and PMU). Should it be q800_via.c or have some other designation to show that it is for 68K macs?
- Same as above for mac-nubus-bridge.c and macfb.c, could we name them differently to indicate they are related to the 68K macs and not PPC macs?
- As part of the work I did, I turned the interrupt "controller" into a separate controller and also moved it to a separate file (q800_irq.c), but looking at it again it is really just a priority-based CPU interrupt.
If there is no other complexity other than prioritising the CPU interrupts, then perhaps the QOM Q800_INTC device should be moved into q800.c rather than living in a separate file?
ATB,
Mark.