[Qemu-devel] [RFC 01/13] hw/m68k: add via support
Signed-off-by: Laurent Vivier --- hw/input/adb.c| 99 - hw/misc/Makefile.objs | 1 + hw/misc/mac_via.c | 940 ++ include/hw/input/adb.h| 8 + include/hw/misc/mac_via.h | 45 +++ 5 files changed, 1092 insertions(+), 1 deletion(-) create mode 100644 hw/misc/mac_via.c create mode 100644 include/hw/misc/mac_via.h diff --git a/hw/input/adb.c b/hw/input/adb.c index 23ae6f0d75..2e5460730c 100644 --- a/hw/input/adb.c +++ b/hw/input/adb.c @@ -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) @@ -57,7 +68,6 @@ int adb_request(ADBBusState *s, uint8_t *obuf, const uint8_t *buf, int len) return ADB_RET_NOTPRESENT; } -/* XXX: move that to cuda ? */ int adb_poll(ADBBusState *s, uint8_t *obuf, uint16_t poll_mask) { ADBDevice *d; @@ -84,6 +94,93 @@ int adb_poll(ADBBusState *s, uint8_t *obuf, uint16_t poll_mask) return olen; } +int adb_send(ADBBusState *adb, int state, uint8_t data) +{ +switch (state) { +case STATE_NEW: +adb->data_out[0] = data; +adb->data_out_index = 1; +break; +case STATE_EVEN: +if ((adb->data_out_index & 1) == 0) { +return 0; +} +adb->data_out[adb->data_out_index++] = data; +break; +case STATE_ODD: +if (adb->data_out_index & 1) { +return 0; +} +adb->data_out[adb->data_out_index++] = data; +break; +case STATE_IDLE: +return 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; +} +*data = adb->data_in[adb->data_in_index++]; +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; +} +*data = adb->data_in[adb->data_in_index++]; +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; +if (adb->data_in_size < 0) { +*data = 0xff; +qemu_irq_raise(adb->data_ready); +return -1; +} +if (adb->data_in_size == 0) { +return 0; +} +*data = adb->data_in[0]; +adb->data_in_index = 1; +break; +} +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, diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs index 00e834d0f0..2cd8941faa 100644 --- a/hw/misc/Makefile.objs +++ b/hw/misc/Makefile.objs @@ -68,5 +68,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 diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c new file mode 100644 index 00..a6a11c5b3d --- /dev/null +++ b/hw/misc/mac_via.c @@ -0,0 +1,940 @@ +/* + * QEMU m68k Macintosh VIA device support + * + * Copyright (c) 2011-2018 Laurent Vivier + * + * Some parts from hw/cuda.c + * + * Copyright (c) 2004-2007 Fabrice Bellard + * Copyright (c) 2007 Jocelyn Mayer + * + * some parts from linux-2.6.29, arch/m68k/include/asm/mac_via.h + * + * 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 "qemu/timer.h" +#include "hw/misc/mac_via.h" +#include "hw/input/adb.h" +#include "sysemu/sysemu.h" +#include "qemu/cutils.h" + +/* debug VIA */ +#undef DEBUG_VIA + +#ifdef DEBUG_VIA +#define VIA_DPRINTF(fmt, ...)
Re: [Qemu-devel] [RFC 01/13] hw/m68k: add via support
On 08/06/18 21:05, Laurent Vivier wrote: Signed-off-by: Laurent Vivier --- hw/input/adb.c| 99 - hw/misc/Makefile.objs | 1 + hw/misc/mac_via.c | 940 ++ include/hw/input/adb.h| 8 + include/hw/misc/mac_via.h | 45 +++ 5 files changed, 1092 insertions(+), 1 deletion(-) create mode 100644 hw/misc/mac_via.c create mode 100644 include/hw/misc/mac_via.h diff --git a/hw/input/adb.c b/hw/input/adb.c index 23ae6f0d75..2e5460730c 100644 --- a/hw/input/adb.c +++ b/hw/input/adb.c @@ -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) @@ -57,7 +68,6 @@ int adb_request(ADBBusState *s, uint8_t *obuf, const uint8_t *buf, int len) return ADB_RET_NOTPRESENT; } -/* XXX: move that to cuda ? */ int adb_poll(ADBBusState *s, uint8_t *obuf, uint16_t poll_mask) { ADBDevice *d; @@ -84,6 +94,93 @@ int adb_poll(ADBBusState *s, uint8_t *obuf, uint16_t poll_mask) return olen; } +int adb_send(ADBBusState *adb, int state, uint8_t data) +{ +switch (state) { +case STATE_NEW: +adb->data_out[0] = data; +adb->data_out_index = 1; +break; +case STATE_EVEN: +if ((adb->data_out_index & 1) == 0) { +return 0; +} +adb->data_out[adb->data_out_index++] = data; +break; +case STATE_ODD: +if (adb->data_out_index & 1) { +return 0; +} +adb->data_out[adb->data_out_index++] = data; +break; +case STATE_IDLE: +return 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; +} +*data = adb->data_in[adb->data_in_index++]; +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; +} +*data = adb->data_in[adb->data_in_index++]; +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; +if (adb->data_in_size < 0) { +*data = 0xff; +qemu_irq_raise(adb->data_ready); +return -1; +} +if (adb->data_in_size == 0) { +return 0; +} +*data = adb->data_in[0]; +adb->data_in_index = 1; +break; +} +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 completely convinced by this part: from working on Mac PMU patches my feeling is that any buffering should be handled by the level above the ADB bus, since once you've sent/received something the supporting logic appears completely different. Having said that, the ADB bus state part is new so I'm not sure I understand why this is currently needed? diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs index 00e834d0f0..2cd8941faa 100644 --- a/hw/misc/Makefile.objs +++ b/hw/misc/Makefile.objs @@ -68,5 +68,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 diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c new file mode 100644 index 00..a6a11c5b3d --- /dev/null +++ b/hw/misc/mac_via.c @@ -0,0 +1,940 @@ +/* + * QEMU m68k Macintosh VIA device support + * + * Copyright (c) 2011-2018 Laurent Vivier + * + * Some parts from hw/cuda.c + * + * Copyright (c) 2004-2007 Fabrice Bellard + * Copyright (c) 2007 Jocelyn Mayer + * + * some parts from linux-2.6.29, arch/m68k/include/
Re: [Qemu-devel] [RFC 01/13] hw/m68k: add via support
On 09/06/18 11:01, Mark Cave-Ayland wrote: Yeah, we can certainly remove a huge chunk of this by converting over to the mos6522 device. My last set of updates to CUDA a couple of days ago are probably the best reference, but I can probably find some time to do the basic conversion for you at some point... BTW is there a particular github branch I should be working from in order to attempt this? ATB, Mark.
Re: [Qemu-devel] [RFC 01/13] hw/m68k: add via support
Le 09/06/2018 à 17:48, Mark Cave-Ayland a écrit : > On 09/06/18 11:01, Mark Cave-Ayland wrote: > >> Yeah, we can certainly remove a huge chunk of this by converting over >> to the mos6522 device. My last set of updates to CUDA a couple of days >> ago are probably the best reference, but I can probably find some time >> to do the basic conversion for you at some point... > > BTW is there a particular github branch I should be working from in > order to attempt this? > You can use q800-dev-part1 from git://github.com/vivier/qemu-m68k.git Thanks, Laurent