2004-06-03 22:46:20 +04:00
|
|
|
/*
|
2007-10-29 02:42:18 +03:00
|
|
|
* QEMU PowerMac CUDA device support
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2007-10-29 02:42:18 +03:00
|
|
|
* Copyright (c) 2004-2007 Fabrice Bellard
|
|
|
|
* Copyright (c) 2007 Jocelyn Mayer
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2004-06-03 22:46:20 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
2019-05-23 17:35:07 +03:00
|
|
|
|
2016-01-26 21:16:58 +03:00
|
|
|
#include "qemu/osdep.h"
|
2022-03-05 18:09:49 +03:00
|
|
|
#include "hw/irq.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/ppc/mac.h"
|
2019-08-12 08:23:51 +03:00
|
|
|
#include "hw/qdev-properties.h"
|
2019-08-12 08:23:45 +03:00
|
|
|
#include "migration/vmstate.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/input/adb.h"
|
2018-02-09 21:51:40 +03:00
|
|
|
#include "hw/misc/mos6522.h"
|
2018-02-09 21:51:41 +03:00
|
|
|
#include "hw/misc/macio/cuda.h"
|
sysbus: Convert qdev_set_parent_bus() use with Coccinelle, part 2
This is the same transformation as in the previous commit, except
sysbus_init_child_obj() and realize are too separated for the commit's
Coccinelle script to handle, typically because sysbus_init_child_obj()
is in a device's instance_init() method, and the matching realize is
in its realize() method.
Perhaps a Coccinelle wizard could make it transform that pattern, but
I'm just a bungler, and the best I can do is transforming the two
separate parts separately:
@@
expression errp;
expression child;
symbol true;
@@
- object_property_set_bool(OBJECT(child), true, "realized", errp);
+ sysbus_realize(SYS_BUS_DEVICE(child), errp);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression errp;
expression child;
symbol true;
@@
- object_property_set_bool(child, true, "realized", errp);
+ sysbus_realize(SYS_BUS_DEVICE(child), errp);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression child;
@@
- qdev_init_nofail(DEVICE(child));
+ sysbus_realize(SYS_BUS_DEVICE(child), &error_fatal);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression child;
expression dev;
@@
dev = DEVICE(child);
...
- qdev_init_nofail(dev);
+ sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression child;
identifier dev;
@@
DeviceState *dev = DEVICE(child);
...
- qdev_init_nofail(dev);
+ sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression parent, name, size, type;
expression child;
symbol true;
@@
- sysbus_init_child_obj(parent, name, child, size, type);
+ sysbus_init_child_XXX(parent, name, child, size, type);
@@
expression parent, propname, type;
expression child;
@@
- sysbus_init_child_XXX(parent, propname, child, sizeof(*child), type)
+ object_initialize_child(parent, propname, child, type)
@@
expression parent, propname, type;
expression child;
@@
- sysbus_init_child_XXX(parent, propname, &child, sizeof(child), type)
+ object_initialize_child(parent, propname, &child, type)
This script is *unsound*: we need to manually verify init and realize
conversions are properly paired.
This commit has only the pairs where object_initialize_child()'s
@child and sysbus_realize()'s @dev argument text match exactly within
the same source file.
Note that Coccinelle chokes on ARMSSE typedef vs. macro in
hw/arm/armsse.c. Worked around by temporarily renaming the macro for
the spatch run.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-49-armbru@redhat.com>
2020-06-10 08:32:37 +03:00
|
|
|
#include "qapi/error.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/timer.h"
|
2019-08-12 08:23:59 +03:00
|
|
|
#include "sysemu/runstate.h"
|
2021-11-29 23:55:05 +03:00
|
|
|
#include "sysemu/rtc.h"
|
macio: Fix to realize "mos6522-cuda" and "mos6522-pmu" devices
cuda_init() creates a "mos6522-cuda" device, but it's never realized.
Affects machines mac99 with via=cuda (default) and g3beige.
pmu_init() creates a "mos6522-pmu" device, but it's never realized.
Affects machine mac99 with via=pmu and via=pmu-adb,
In theory, a device becomes real only on realize. In practice, the
transition from unreal to real is a fuzzy one. The work to make a
device real can be spread between realize methods (fine),
instance_init methods (wrong), and board code wiring up the device
(fine as long as it effectively happens on realize). Depending on
what exactly is done where, a device can work even when we neglect
to realize it.
These two appear to work. Nevertheless, it's a clear misuse of the
interface. Even when it works today (more or less by chance), it can
break tomorrow.
Fix by realizing them in cuda_realize() and pmu_realize(),
respectively.
Fixes: 6dca62a0000f95e0b7020aa00d0ca9b2c421f341
Cc: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200609122339.937862-10-armbru@redhat.com>
2020-06-09 15:23:24 +03:00
|
|
|
#include "qapi/error.h"
|
2016-03-20 20:16:19 +03:00
|
|
|
#include "qemu/cutils.h"
|
2015-12-15 15:16:16 +03:00
|
|
|
#include "qemu/log.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2018-02-09 21:51:42 +03:00
|
|
|
#include "trace.h"
|
2008-12-24 12:38:16 +03:00
|
|
|
|
2004-06-03 22:46:20 +04:00
|
|
|
/* Bits in B data register: all active low */
|
2018-02-09 21:51:40 +03:00
|
|
|
#define TREQ 0x08 /* Transfer request (input) */
|
|
|
|
#define TACK 0x10 /* Transfer acknowledge (output) */
|
|
|
|
#define TIP 0x20 /* Transfer in progress (output) */
|
2004-06-03 22:46:20 +04:00
|
|
|
|
|
|
|
/* commands (1st byte) */
|
2018-02-09 21:51:40 +03:00
|
|
|
#define ADB_PACKET 0
|
|
|
|
#define CUDA_PACKET 1
|
|
|
|
#define ERROR_PACKET 2
|
|
|
|
#define TIMER_PACKET 3
|
|
|
|
#define POWER_PACKET 4
|
|
|
|
#define MACIIC_PACKET 5
|
|
|
|
#define PMU_PACKET 6
|
2004-06-03 22:46:20 +04:00
|
|
|
|
|
|
|
#define CUDA_TIMER_FREQ (4700000 / 6)
|
|
|
|
|
2005-02-09 03:07:08 +03:00
|
|
|
/* CUDA returns time_t's offset from Jan 1, 1904, not 1970 */
|
|
|
|
#define RTC_OFFSET 2082844800
|
|
|
|
|
2007-09-17 01:08:06 +04:00
|
|
|
static void cuda_receive_packet_from_host(CUDAState *s,
|
2004-06-03 22:46:20 +04:00
|
|
|
const uint8_t *data, int len);
|
|
|
|
|
2018-02-09 21:51:40 +03:00
|
|
|
/* MacOS uses timer 1 for calibration on startup, so we use
|
|
|
|
* the timebase frequency and cuda_get_counter_value() with
|
|
|
|
* cuda_get_load_time() to steer MacOS to calculate calibrate its timers
|
|
|
|
* correctly for both TCG and KVM (see commit b981289c49 "PPC: Cuda: Use cuda
|
|
|
|
* timer to expose tbfreq to guest" for more information) */
|
2004-06-03 22:46:20 +04:00
|
|
|
|
2018-02-09 21:51:40 +03:00
|
|
|
static uint64_t cuda_get_counter_value(MOS6522State *s, MOS6522Timer *ti)
|
2014-07-14 00:31:53 +04:00
|
|
|
{
|
2018-02-09 21:51:40 +03:00
|
|
|
MOS6522CUDAState *mcs = container_of(s, MOS6522CUDAState, parent_obj);
|
2018-06-07 20:17:49 +03:00
|
|
|
CUDAState *cs = container_of(mcs, CUDAState, mos6522_cuda);
|
2018-02-09 21:51:40 +03:00
|
|
|
|
2018-02-09 21:51:38 +03:00
|
|
|
/* Reverse of the tb calculation algorithm that Mac OS X uses on bootup */
|
|
|
|
uint64_t tb_diff = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
|
2018-02-09 21:51:40 +03:00
|
|
|
cs->tb_frequency, NANOSECONDS_PER_SECOND) -
|
2018-02-09 21:51:38 +03:00
|
|
|
ti->load_time;
|
|
|
|
|
2018-02-09 21:51:40 +03:00
|
|
|
return (tb_diff * 0xBF401675E5DULL) / (cs->tb_frequency << 24);
|
2018-02-09 21:51:38 +03:00
|
|
|
}
|
|
|
|
|
2018-02-09 21:51:40 +03:00
|
|
|
static uint64_t cuda_get_load_time(MOS6522State *s, MOS6522Timer *ti)
|
2018-02-09 21:51:38 +03:00
|
|
|
{
|
2018-02-09 21:51:40 +03:00
|
|
|
MOS6522CUDAState *mcs = container_of(s, MOS6522CUDAState, parent_obj);
|
2018-06-07 20:17:49 +03:00
|
|
|
CUDAState *cs = container_of(mcs, CUDAState, mos6522_cuda);
|
2018-02-09 21:51:40 +03:00
|
|
|
|
2018-02-09 21:51:38 +03:00
|
|
|
uint64_t load_time = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
|
2018-02-09 21:51:40 +03:00
|
|
|
cs->tb_frequency, NANOSECONDS_PER_SECOND);
|
2018-02-09 21:51:38 +03:00
|
|
|
return load_time;
|
2014-07-14 00:31:53 +04:00
|
|
|
}
|
|
|
|
|
2015-11-12 01:49:51 +03:00
|
|
|
static void cuda_set_sr_int(void *opaque)
|
|
|
|
{
|
|
|
|
CUDAState *s = opaque;
|
2018-06-07 20:17:49 +03:00
|
|
|
MOS6522CUDAState *mcs = &s->mos6522_cuda;
|
2018-02-09 21:51:40 +03:00
|
|
|
MOS6522State *ms = MOS6522(mcs);
|
2022-03-05 18:09:49 +03:00
|
|
|
qemu_irq irq = qdev_get_gpio_in(DEVICE(ms), SR_INT_BIT);
|
2015-11-12 01:49:51 +03:00
|
|
|
|
2022-03-05 18:09:49 +03:00
|
|
|
qemu_set_irq(irq, 1);
|
2015-11-12 01:49:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cuda_delay_set_sr_int(CUDAState *s)
|
|
|
|
{
|
|
|
|
int64_t expire;
|
|
|
|
|
2018-02-09 21:51:42 +03:00
|
|
|
trace_cuda_delay_set_sr_int();
|
2015-11-12 01:49:51 +03:00
|
|
|
|
2018-02-09 21:51:40 +03:00
|
|
|
expire = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + s->sr_delay_ns;
|
2015-11-12 01:49:51 +03:00
|
|
|
timer_mod(s->sr_delay_timer, expire);
|
|
|
|
}
|
|
|
|
|
2004-06-03 22:46:20 +04:00
|
|
|
/* NOTE: TIP and TREQ are negated */
|
|
|
|
static void cuda_update(CUDAState *s)
|
|
|
|
{
|
2018-06-07 20:17:49 +03:00
|
|
|
MOS6522CUDAState *mcs = &s->mos6522_cuda;
|
2018-02-09 21:51:40 +03:00
|
|
|
MOS6522State *ms = MOS6522(mcs);
|
2020-06-23 23:49:30 +03:00
|
|
|
ADBBusState *adb_bus = &s->adb_bus;
|
2004-06-21 20:47:13 +04:00
|
|
|
int packet_received, len;
|
|
|
|
|
|
|
|
packet_received = 0;
|
2018-02-09 21:51:40 +03:00
|
|
|
if (!(ms->b & TIP)) {
|
2004-06-21 20:47:13 +04:00
|
|
|
/* transfer requested from host */
|
2004-06-03 22:46:20 +04:00
|
|
|
|
2018-02-09 21:51:40 +03:00
|
|
|
if (ms->acr & SR_OUT) {
|
2004-06-21 20:47:13 +04:00
|
|
|
/* data output */
|
2018-02-09 21:51:40 +03:00
|
|
|
if ((ms->b & (TACK | TIP)) != (s->last_b & (TACK | TIP))) {
|
2004-06-21 20:47:13 +04:00
|
|
|
if (s->data_out_index < sizeof(s->data_out)) {
|
2020-06-23 23:49:30 +03:00
|
|
|
if (s->data_out_index == 0) {
|
|
|
|
adb_autopoll_block(adb_bus);
|
|
|
|
}
|
2018-02-09 21:51:42 +03:00
|
|
|
trace_cuda_data_send(ms->sr);
|
2018-02-09 21:51:40 +03:00
|
|
|
s->data_out[s->data_out_index++] = ms->sr;
|
2015-11-12 01:49:51 +03:00
|
|
|
cuda_delay_set_sr_int(s);
|
2004-06-21 20:47:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (s->data_in_index < s->data_in_size) {
|
|
|
|
/* data input */
|
2018-02-09 21:51:40 +03:00
|
|
|
if ((ms->b & (TACK | TIP)) != (s->last_b & (TACK | TIP))) {
|
|
|
|
ms->sr = s->data_in[s->data_in_index++];
|
2018-02-09 21:51:42 +03:00
|
|
|
trace_cuda_data_recv(ms->sr);
|
2004-06-21 20:47:13 +04:00
|
|
|
/* indicate end of transfer */
|
|
|
|
if (s->data_in_index >= s->data_in_size) {
|
2018-02-09 21:51:40 +03:00
|
|
|
ms->b = (ms->b | TREQ);
|
2020-06-23 23:49:30 +03:00
|
|
|
adb_autopoll_unblock(adb_bus);
|
2004-06-21 20:47:13 +04:00
|
|
|
}
|
2015-11-12 01:49:51 +03:00
|
|
|
cuda_delay_set_sr_int(s);
|
2004-06-21 20:47:13 +04:00
|
|
|
}
|
2004-06-03 22:46:20 +04:00
|
|
|
}
|
2004-06-21 20:47:13 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* no transfer requested: handle sync case */
|
2018-02-09 21:51:40 +03:00
|
|
|
if ((s->last_b & TIP) && (ms->b & TACK) != (s->last_b & TACK)) {
|
2004-06-21 20:47:13 +04:00
|
|
|
/* update TREQ state each time TACK change state */
|
2018-02-09 21:51:40 +03:00
|
|
|
if (ms->b & TACK) {
|
|
|
|
ms->b = (ms->b | TREQ);
|
|
|
|
} else {
|
|
|
|
ms->b = (ms->b & ~TREQ);
|
|
|
|
}
|
2015-11-12 01:49:51 +03:00
|
|
|
cuda_delay_set_sr_int(s);
|
2004-06-21 20:47:13 +04:00
|
|
|
} else {
|
|
|
|
if (!(s->last_b & TIP)) {
|
2007-06-03 17:35:16 +04:00
|
|
|
/* handle end of host to cuda transfer */
|
2004-06-21 20:47:13 +04:00
|
|
|
packet_received = (s->data_out_index > 0);
|
2007-06-03 17:35:16 +04:00
|
|
|
/* always an IRQ at the end of transfer */
|
2015-11-12 01:49:51 +03:00
|
|
|
cuda_delay_set_sr_int(s);
|
2004-06-21 20:47:13 +04:00
|
|
|
}
|
|
|
|
/* signal if there is data to read */
|
|
|
|
if (s->data_in_index < s->data_in_size) {
|
2018-02-09 21:51:40 +03:00
|
|
|
ms->b = (ms->b & ~TREQ);
|
2004-06-21 20:47:13 +04:00
|
|
|
}
|
2004-06-03 22:46:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-09 21:51:40 +03:00
|
|
|
s->last_acr = ms->acr;
|
|
|
|
s->last_b = ms->b;
|
2004-06-21 20:47:13 +04:00
|
|
|
|
|
|
|
/* NOTE: cuda_receive_packet_from_host() can call cuda_update()
|
|
|
|
recursively */
|
|
|
|
if (packet_received) {
|
|
|
|
len = s->data_out_index;
|
|
|
|
s->data_out_index = 0;
|
|
|
|
cuda_receive_packet_from_host(s, s->data_out, len);
|
|
|
|
}
|
2004-06-03 22:46:20 +04:00
|
|
|
}
|
|
|
|
|
2007-09-17 01:08:06 +04:00
|
|
|
static void cuda_send_packet_to_host(CUDAState *s,
|
2004-06-03 22:46:20 +04:00
|
|
|
const uint8_t *data, int len)
|
|
|
|
{
|
2018-02-09 21:51:42 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
trace_cuda_packet_send(len);
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
trace_cuda_packet_send_data(i, data[i]);
|
2004-06-21 20:47:13 +04:00
|
|
|
}
|
2018-02-09 21:51:42 +03:00
|
|
|
|
2004-06-03 22:46:20 +04:00
|
|
|
memcpy(s->data_in, data, len);
|
|
|
|
s->data_in_size = len;
|
|
|
|
s->data_in_index = 0;
|
|
|
|
cuda_update(s);
|
2015-11-12 01:49:51 +03:00
|
|
|
cuda_delay_set_sr_int(s);
|
2004-06-03 22:46:20 +04:00
|
|
|
}
|
|
|
|
|
2004-07-07 00:57:47 +04:00
|
|
|
static void cuda_adb_poll(void *opaque)
|
2004-06-22 02:46:10 +04:00
|
|
|
{
|
|
|
|
CUDAState *s = opaque;
|
2020-06-23 23:49:22 +03:00
|
|
|
ADBBusState *adb_bus = &s->adb_bus;
|
2004-06-22 02:46:10 +04:00
|
|
|
uint8_t obuf[ADB_MAX_OUT_LEN + 2];
|
|
|
|
int olen;
|
|
|
|
|
2020-06-23 23:49:22 +03:00
|
|
|
olen = adb_poll(adb_bus, obuf + 2, adb_bus->autopoll_mask);
|
2004-06-22 02:46:10 +04:00
|
|
|
if (olen > 0) {
|
|
|
|
obuf[0] = ADB_PACKET;
|
|
|
|
obuf[1] = 0x40; /* polled data */
|
|
|
|
cuda_send_packet_to_host(s, obuf, olen + 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-07 23:34:04 +03:00
|
|
|
/* description of commands */
|
|
|
|
typedef struct CudaCommand {
|
|
|
|
uint8_t command;
|
|
|
|
const char *name;
|
|
|
|
bool (*handler)(CUDAState *s,
|
|
|
|
const uint8_t *in_args, int in_len,
|
|
|
|
uint8_t *out_args, int *out_len);
|
|
|
|
} CudaCommand;
|
|
|
|
|
2016-02-07 23:34:06 +03:00
|
|
|
static bool cuda_cmd_autopoll(CUDAState *s,
|
|
|
|
const uint8_t *in_data, int in_len,
|
|
|
|
uint8_t *out_data, int *out_len)
|
|
|
|
{
|
2020-06-23 23:49:22 +03:00
|
|
|
ADBBusState *adb_bus = &s->adb_bus;
|
|
|
|
bool autopoll;
|
2016-02-07 23:34:06 +03:00
|
|
|
|
|
|
|
if (in_len != 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-23 23:49:22 +03:00
|
|
|
autopoll = (in_data[0] != 0) ? true : false;
|
|
|
|
|
|
|
|
adb_set_autopoll_enabled(adb_bus, autopoll);
|
2016-02-07 23:34:06 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-07 23:34:07 +03:00
|
|
|
static bool cuda_cmd_set_autorate(CUDAState *s,
|
|
|
|
const uint8_t *in_data, int in_len,
|
|
|
|
uint8_t *out_data, int *out_len)
|
|
|
|
{
|
2020-06-23 23:49:22 +03:00
|
|
|
ADBBusState *adb_bus = &s->adb_bus;
|
|
|
|
|
2016-02-07 23:34:07 +03:00
|
|
|
if (in_len != 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we don't want a period of 0 ms */
|
|
|
|
/* FIXME: check what real hardware does */
|
|
|
|
if (in_data[0] == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-23 23:49:22 +03:00
|
|
|
adb_set_autopoll_rate_ms(adb_bus, in_data[0]);
|
2016-02-07 23:34:07 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-07 23:34:08 +03:00
|
|
|
static bool cuda_cmd_set_device_list(CUDAState *s,
|
|
|
|
const uint8_t *in_data, int in_len,
|
|
|
|
uint8_t *out_data, int *out_len)
|
|
|
|
{
|
2020-06-23 23:49:22 +03:00
|
|
|
ADBBusState *adb_bus = &s->adb_bus;
|
|
|
|
uint16_t mask;
|
|
|
|
|
2016-02-07 23:34:08 +03:00
|
|
|
if (in_len != 2) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-23 23:49:22 +03:00
|
|
|
mask = (((uint16_t)in_data[0]) << 8) | in_data[1];
|
|
|
|
|
|
|
|
adb_set_autopoll_mask(adb_bus, mask);
|
2016-02-07 23:34:08 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-07 23:34:09 +03:00
|
|
|
static bool cuda_cmd_powerdown(CUDAState *s,
|
|
|
|
const uint8_t *in_data, int in_len,
|
|
|
|
uint8_t *out_data, int *out_len)
|
|
|
|
{
|
|
|
|
if (in_len != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-16 00:41:13 +03:00
|
|
|
qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
|
2016-02-07 23:34:09 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-07 23:34:10 +03:00
|
|
|
static bool cuda_cmd_reset_system(CUDAState *s,
|
|
|
|
const uint8_t *in_data, int in_len,
|
|
|
|
uint8_t *out_data, int *out_len)
|
|
|
|
{
|
|
|
|
if (in_len != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-16 00:41:13 +03:00
|
|
|
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
|
2016-02-07 23:34:10 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-07 23:34:11 +03:00
|
|
|
static bool cuda_cmd_set_file_server_flag(CUDAState *s,
|
|
|
|
const uint8_t *in_data, int in_len,
|
|
|
|
uint8_t *out_data, int *out_len)
|
|
|
|
{
|
|
|
|
if (in_len != 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
qemu_log_mask(LOG_UNIMP,
|
|
|
|
"CUDA: unimplemented command FILE_SERVER_FLAG %d\n",
|
|
|
|
in_data[0]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-07 23:34:12 +03:00
|
|
|
static bool cuda_cmd_set_power_message(CUDAState *s,
|
|
|
|
const uint8_t *in_data, int in_len,
|
|
|
|
uint8_t *out_data, int *out_len)
|
|
|
|
{
|
|
|
|
if (in_len != 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
qemu_log_mask(LOG_UNIMP,
|
|
|
|
"CUDA: unimplemented command SET_POWER_MESSAGE %d\n",
|
|
|
|
in_data[0]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-07 23:34:13 +03:00
|
|
|
static bool cuda_cmd_get_time(CUDAState *s,
|
|
|
|
const uint8_t *in_data, int in_len,
|
|
|
|
uint8_t *out_data, int *out_len)
|
|
|
|
{
|
|
|
|
uint32_t ti;
|
|
|
|
|
|
|
|
if (in_len != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ti = s->tick_offset + (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)
|
2016-03-21 19:02:30 +03:00
|
|
|
/ NANOSECONDS_PER_SECOND);
|
2016-02-07 23:34:13 +03:00
|
|
|
out_data[0] = ti >> 24;
|
|
|
|
out_data[1] = ti >> 16;
|
|
|
|
out_data[2] = ti >> 8;
|
|
|
|
out_data[3] = ti;
|
|
|
|
*out_len = 4;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-07 23:34:14 +03:00
|
|
|
static bool cuda_cmd_set_time(CUDAState *s,
|
|
|
|
const uint8_t *in_data, int in_len,
|
|
|
|
uint8_t *out_data, int *out_len)
|
|
|
|
{
|
|
|
|
uint32_t ti;
|
|
|
|
|
|
|
|
if (in_len != 4) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-18 11:07:45 +03:00
|
|
|
ti = (((uint32_t)in_data[0]) << 24) + (((uint32_t)in_data[1]) << 16)
|
|
|
|
+ (((uint32_t)in_data[2]) << 8) + in_data[3];
|
2016-02-07 23:34:14 +03:00
|
|
|
s->tick_offset = ti - (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)
|
2016-03-21 19:02:30 +03:00
|
|
|
/ NANOSECONDS_PER_SECOND);
|
2016-02-07 23:34:14 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-07 23:34:04 +03:00
|
|
|
static const CudaCommand handlers[] = {
|
2016-02-07 23:34:06 +03:00
|
|
|
{ CUDA_AUTOPOLL, "AUTOPOLL", cuda_cmd_autopoll },
|
2016-02-07 23:34:07 +03:00
|
|
|
{ CUDA_SET_AUTO_RATE, "SET_AUTO_RATE", cuda_cmd_set_autorate },
|
2016-02-07 23:34:08 +03:00
|
|
|
{ CUDA_SET_DEVICE_LIST, "SET_DEVICE_LIST", cuda_cmd_set_device_list },
|
2016-02-07 23:34:09 +03:00
|
|
|
{ CUDA_POWERDOWN, "POWERDOWN", cuda_cmd_powerdown },
|
2016-02-07 23:34:10 +03:00
|
|
|
{ CUDA_RESET_SYSTEM, "RESET_SYSTEM", cuda_cmd_reset_system },
|
2016-02-07 23:34:11 +03:00
|
|
|
{ CUDA_FILE_SERVER_FLAG, "FILE_SERVER_FLAG",
|
|
|
|
cuda_cmd_set_file_server_flag },
|
2016-02-07 23:34:12 +03:00
|
|
|
{ CUDA_SET_POWER_MESSAGES, "SET_POWER_MESSAGES",
|
|
|
|
cuda_cmd_set_power_message },
|
2016-02-07 23:34:13 +03:00
|
|
|
{ CUDA_GET_TIME, "GET_TIME", cuda_cmd_get_time },
|
2016-02-07 23:34:14 +03:00
|
|
|
{ CUDA_SET_TIME, "SET_TIME", cuda_cmd_set_time },
|
2016-02-07 23:34:04 +03:00
|
|
|
};
|
|
|
|
|
2007-09-17 01:08:06 +04:00
|
|
|
static void cuda_receive_packet(CUDAState *s,
|
2004-06-03 22:46:20 +04:00
|
|
|
const uint8_t *data, int len)
|
|
|
|
{
|
2015-11-12 01:49:43 +03:00
|
|
|
uint8_t obuf[16] = { CUDA_PACKET, 0, data[0] };
|
2016-02-07 23:34:04 +03:00
|
|
|
int i, out_len = 0;
|
2004-06-03 22:46:20 +04:00
|
|
|
|
2016-02-07 23:34:04 +03:00
|
|
|
for (i = 0; i < ARRAY_SIZE(handlers); i++) {
|
|
|
|
const CudaCommand *desc = &handlers[i];
|
|
|
|
if (desc->command == data[0]) {
|
2018-02-09 21:51:42 +03:00
|
|
|
trace_cuda_receive_packet_cmd(desc->name);
|
2016-02-07 23:34:04 +03:00
|
|
|
out_len = 0;
|
|
|
|
if (desc->handler(s, data + 1, len - 1, obuf + 3, &out_len)) {
|
|
|
|
cuda_send_packet_to_host(s, obuf, 3 + out_len);
|
|
|
|
} else {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"CUDA: %s: wrong parameters %d\n",
|
|
|
|
desc->name, len);
|
|
|
|
obuf[0] = ERROR_PACKET;
|
|
|
|
obuf[1] = 0x5; /* bad parameters */
|
|
|
|
obuf[2] = CUDA_PACKET;
|
|
|
|
obuf[3] = data[0];
|
|
|
|
cuda_send_packet_to_host(s, obuf, 4);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-07 23:34:05 +03:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "CUDA: unknown command 0x%02x\n", data[0]);
|
|
|
|
obuf[0] = ERROR_PACKET;
|
|
|
|
obuf[1] = 0x2; /* unknown command */
|
|
|
|
obuf[2] = CUDA_PACKET;
|
|
|
|
obuf[3] = data[0];
|
|
|
|
cuda_send_packet_to_host(s, obuf, 4);
|
2004-06-03 22:46:20 +04:00
|
|
|
}
|
|
|
|
|
2007-09-17 01:08:06 +04:00
|
|
|
static void cuda_receive_packet_from_host(CUDAState *s,
|
2004-06-03 22:46:20 +04:00
|
|
|
const uint8_t *data, int len)
|
|
|
|
{
|
2018-02-09 21:51:42 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
trace_cuda_packet_receive(len);
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
trace_cuda_packet_receive_data(i, data[i]);
|
2004-06-21 20:47:13 +04:00
|
|
|
}
|
2018-02-09 21:51:42 +03:00
|
|
|
|
2004-06-03 22:46:20 +04:00
|
|
|
switch(data[0]) {
|
|
|
|
case ADB_PACKET:
|
2004-06-22 02:46:10 +04:00
|
|
|
{
|
2015-11-12 01:49:42 +03:00
|
|
|
uint8_t obuf[ADB_MAX_OUT_LEN + 3];
|
2004-06-22 02:46:10 +04:00
|
|
|
int olen;
|
2013-01-24 03:04:05 +04:00
|
|
|
olen = adb_request(&s->adb_bus, obuf + 2, data + 1, len - 1);
|
2004-07-13 00:16:00 +04:00
|
|
|
if (olen > 0) {
|
2004-06-22 02:46:10 +04:00
|
|
|
obuf[0] = ADB_PACKET;
|
|
|
|
obuf[1] = 0x00;
|
2015-11-12 01:49:42 +03:00
|
|
|
cuda_send_packet_to_host(s, obuf, olen + 2);
|
2004-06-22 02:46:10 +04:00
|
|
|
} else {
|
2004-07-13 00:16:00 +04:00
|
|
|
/* error */
|
2004-06-22 02:46:10 +04:00
|
|
|
obuf[0] = ADB_PACKET;
|
2004-07-13 00:16:00 +04:00
|
|
|
obuf[1] = -olen;
|
2015-11-12 01:49:42 +03:00
|
|
|
obuf[2] = data[1];
|
2004-07-13 00:16:00 +04:00
|
|
|
olen = 0;
|
2015-11-12 01:49:42 +03:00
|
|
|
cuda_send_packet_to_host(s, obuf, olen + 3);
|
2004-06-22 02:46:10 +04:00
|
|
|
}
|
|
|
|
}
|
2004-06-03 22:46:20 +04:00
|
|
|
break;
|
|
|
|
case CUDA_PACKET:
|
|
|
|
cuda_receive_packet(s, data + 1, len - 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-09 21:51:40 +03:00
|
|
|
static uint64_t mos6522_cuda_read(void *opaque, hwaddr addr, unsigned size)
|
|
|
|
{
|
|
|
|
CUDAState *s = opaque;
|
2018-06-07 20:17:49 +03:00
|
|
|
MOS6522CUDAState *mcs = &s->mos6522_cuda;
|
2018-02-09 21:51:40 +03:00
|
|
|
MOS6522State *ms = MOS6522(mcs);
|
2004-06-03 22:46:20 +04:00
|
|
|
|
2018-02-09 21:51:40 +03:00
|
|
|
addr = (addr >> 9) & 0xf;
|
|
|
|
return mos6522_read(ms, addr, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mos6522_cuda_write(void *opaque, hwaddr addr, uint64_t val,
|
|
|
|
unsigned size)
|
2008-12-30 22:01:19 +03:00
|
|
|
{
|
2018-02-09 21:51:40 +03:00
|
|
|
CUDAState *s = opaque;
|
2018-06-07 20:17:49 +03:00
|
|
|
MOS6522CUDAState *mcs = &s->mos6522_cuda;
|
2018-02-09 21:51:40 +03:00
|
|
|
MOS6522State *ms = MOS6522(mcs);
|
2008-12-30 22:01:19 +03:00
|
|
|
|
2018-02-09 21:51:40 +03:00
|
|
|
addr = (addr >> 9) & 0xf;
|
|
|
|
mos6522_write(ms, addr, val, size);
|
2008-12-30 22:01:19 +03:00
|
|
|
}
|
|
|
|
|
2018-02-09 21:51:40 +03:00
|
|
|
static const MemoryRegionOps mos6522_cuda_ops = {
|
|
|
|
.read = mos6522_cuda_read,
|
|
|
|
.write = mos6522_cuda_write,
|
|
|
|
.endianness = DEVICE_BIG_ENDIAN,
|
|
|
|
.valid = {
|
|
|
|
.min_access_size = 1,
|
|
|
|
.max_access_size = 1,
|
|
|
|
},
|
2010-12-02 15:53:24 +03:00
|
|
|
};
|
2008-12-30 22:01:19 +03:00
|
|
|
|
2010-12-02 15:53:24 +03:00
|
|
|
static const VMStateDescription vmstate_cuda = {
|
|
|
|
.name = "cuda",
|
2020-06-23 23:49:22 +03:00
|
|
|
.version_id = 6,
|
|
|
|
.minimum_version_id = 6,
|
2014-04-16 18:01:33 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2018-06-07 20:17:49 +03:00
|
|
|
VMSTATE_STRUCT(mos6522_cuda.parent_obj, CUDAState, 0, vmstate_mos6522,
|
|
|
|
MOS6522State),
|
2016-01-06 23:37:26 +03:00
|
|
|
VMSTATE_UINT8(last_b, CUDAState),
|
|
|
|
VMSTATE_UINT8(last_acr, CUDAState),
|
2010-12-02 15:53:24 +03:00
|
|
|
VMSTATE_INT32(data_in_size, CUDAState),
|
|
|
|
VMSTATE_INT32(data_in_index, CUDAState),
|
|
|
|
VMSTATE_INT32(data_out_index, CUDAState),
|
|
|
|
VMSTATE_BUFFER(data_in, CUDAState),
|
|
|
|
VMSTATE_BUFFER(data_out, CUDAState),
|
|
|
|
VMSTATE_UINT32(tick_offset, CUDAState),
|
2016-01-06 23:37:26 +03:00
|
|
|
VMSTATE_TIMER_PTR(sr_delay_timer, CUDAState),
|
2010-12-02 15:53:24 +03:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
2008-12-30 22:01:19 +03:00
|
|
|
|
2013-01-24 03:04:02 +04:00
|
|
|
static void cuda_reset(DeviceState *dev)
|
2008-12-28 21:27:10 +03:00
|
|
|
{
|
2013-01-24 03:04:02 +04:00
|
|
|
CUDAState *s = CUDA(dev);
|
2020-06-23 23:49:22 +03:00
|
|
|
ADBBusState *adb_bus = &s->adb_bus;
|
2008-12-28 21:27:10 +03:00
|
|
|
|
|
|
|
s->data_in_size = 0;
|
|
|
|
s->data_in_index = 0;
|
|
|
|
s->data_out_index = 0;
|
2020-06-23 23:49:22 +03:00
|
|
|
|
|
|
|
adb_set_autopoll_enabled(adb_bus, false);
|
2008-12-28 21:27:10 +03:00
|
|
|
}
|
|
|
|
|
2018-02-09 21:51:40 +03:00
|
|
|
static void cuda_realize(DeviceState *dev, Error **errp)
|
2004-06-03 22:46:20 +04:00
|
|
|
{
|
2013-01-24 03:04:02 +04:00
|
|
|
CUDAState *s = CUDA(dev);
|
2018-02-09 21:51:40 +03:00
|
|
|
SysBusDevice *sbd;
|
2020-06-23 23:49:22 +03:00
|
|
|
ADBBusState *adb_bus = &s->adb_bus;
|
2009-01-15 21:57:15 +03:00
|
|
|
struct tm tm;
|
2004-06-21 20:47:13 +04:00
|
|
|
|
error: Eliminate error_propagate() with Coccinelle, part 1
When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away. Convert
if (!foo(..., &err)) {
...
error_propagate(errp, err);
...
return ...
}
to
if (!foo(..., errp)) {
...
...
return ...
}
where nothing else needs @err. Coccinelle script:
@rule1 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
binary operator op;
constant c1, c2;
symbol false;
@@
if (
(
- fun(args, &err, args2)
+ fun(args, errp, args2)
|
- !fun(args, &err, args2)
+ !fun(args, errp, args2)
|
- fun(args, &err, args2) op c1
+ fun(args, errp, args2) op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
)
}
@rule2 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
expression var;
binary operator op;
constant c1, c2;
symbol false;
@@
- var = fun(args, &err, args2);
+ var = fun(args, errp, args2);
... when != err
if (
(
var
|
!var
|
var op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
|
return var;
)
}
@depends on rule1 || rule2@
identifier err;
@@
- Error *err = NULL;
... when != err
Not exactly elegant, I'm afraid.
The "when != lbl:" is necessary to avoid transforming
if (fun(args, &err)) {
goto out
}
...
out:
error_propagate(errp, err);
even though other paths to label out still need the error_propagate().
For an actual example, see sclp_realize().
Without the "when strict", Coccinelle transforms vfio_msix_setup(),
incorrectly. I don't know what exactly "when strict" does, only that
it helps here.
The match of return is narrower than what I want, but I can't figure
out how to express "return where the operand doesn't use @err". For
an example where it's too narrow, see vfio_intx_enable().
Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
confused by ARMSSE being used both as typedef and function-like macro
there. Converted manually.
Line breaks tidied up manually. One nested declaration of @local_err
deleted manually. Preexisting unwanted blank line dropped in
hw/riscv/sifive_e.c.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-35-armbru@redhat.com>
2020-07-07 19:06:02 +03:00
|
|
|
if (!sysbus_realize(SYS_BUS_DEVICE(&s->mos6522_cuda), errp)) {
|
macio: Fix to realize "mos6522-cuda" and "mos6522-pmu" devices
cuda_init() creates a "mos6522-cuda" device, but it's never realized.
Affects machines mac99 with via=cuda (default) and g3beige.
pmu_init() creates a "mos6522-pmu" device, but it's never realized.
Affects machine mac99 with via=pmu and via=pmu-adb,
In theory, a device becomes real only on realize. In practice, the
transition from unreal to real is a fuzzy one. The work to make a
device real can be spread between realize methods (fine),
instance_init methods (wrong), and board code wiring up the device
(fine as long as it effectively happens on realize). Depending on
what exactly is done where, a device can work even when we neglect
to realize it.
These two appear to work. Nevertheless, it's a clear misuse of the
interface. Even when it works today (more or less by chance), it can
break tomorrow.
Fix by realizing them in cuda_realize() and pmu_realize(),
respectively.
Fixes: 6dca62a0000f95e0b7020aa00d0ca9b2c421f341
Cc: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200609122339.937862-10-armbru@redhat.com>
2020-06-09 15:23:24 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-09 21:51:40 +03:00
|
|
|
/* Pass IRQ from 6522 */
|
|
|
|
sbd = SYS_BUS_DEVICE(s);
|
macio: Fix to realize "mos6522-cuda" and "mos6522-pmu" devices
cuda_init() creates a "mos6522-cuda" device, but it's never realized.
Affects machines mac99 with via=cuda (default) and g3beige.
pmu_init() creates a "mos6522-pmu" device, but it's never realized.
Affects machine mac99 with via=pmu and via=pmu-adb,
In theory, a device becomes real only on realize. In practice, the
transition from unreal to real is a fuzzy one. The work to make a
device real can be spread between realize methods (fine),
instance_init methods (wrong), and board code wiring up the device
(fine as long as it effectively happens on realize). Depending on
what exactly is done where, a device can work even when we neglect
to realize it.
These two appear to work. Nevertheless, it's a clear misuse of the
interface. Even when it works today (more or less by chance), it can
break tomorrow.
Fix by realizing them in cuda_realize() and pmu_realize(),
respectively.
Fixes: 6dca62a0000f95e0b7020aa00d0ca9b2c421f341
Cc: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200609122339.937862-10-armbru@redhat.com>
2020-06-09 15:23:24 +03:00
|
|
|
sysbus_pass_irq(sbd, SYS_BUS_DEVICE(&s->mos6522_cuda));
|
2005-07-08 01:45:18 +04:00
|
|
|
|
2009-01-18 15:16:26 +03:00
|
|
|
qemu_get_timedate(&tm, 0);
|
|
|
|
s->tick_offset = (uint32_t)mktimegm(&tm) + RTC_OFFSET;
|
2009-01-15 21:57:15 +03:00
|
|
|
|
2018-02-09 21:51:40 +03:00
|
|
|
s->sr_delay_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, cuda_set_sr_int, s);
|
2019-02-10 20:44:21 +03:00
|
|
|
s->sr_delay_ns = 20 * SCALE_US;
|
2018-02-09 21:51:40 +03:00
|
|
|
|
2020-06-23 23:49:22 +03:00
|
|
|
adb_register_autopoll_callback(adb_bus, cuda_adb_poll, s);
|
2013-01-24 03:04:02 +04:00
|
|
|
}
|
|
|
|
|
2018-02-09 21:51:40 +03:00
|
|
|
static void cuda_init(Object *obj)
|
2013-01-24 03:04:02 +04:00
|
|
|
{
|
|
|
|
CUDAState *s = CUDA(obj);
|
2018-02-09 21:51:40 +03:00
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
2013-01-24 03:04:02 +04:00
|
|
|
|
sysbus: Convert qdev_set_parent_bus() use with Coccinelle, part 2
This is the same transformation as in the previous commit, except
sysbus_init_child_obj() and realize are too separated for the commit's
Coccinelle script to handle, typically because sysbus_init_child_obj()
is in a device's instance_init() method, and the matching realize is
in its realize() method.
Perhaps a Coccinelle wizard could make it transform that pattern, but
I'm just a bungler, and the best I can do is transforming the two
separate parts separately:
@@
expression errp;
expression child;
symbol true;
@@
- object_property_set_bool(OBJECT(child), true, "realized", errp);
+ sysbus_realize(SYS_BUS_DEVICE(child), errp);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression errp;
expression child;
symbol true;
@@
- object_property_set_bool(child, true, "realized", errp);
+ sysbus_realize(SYS_BUS_DEVICE(child), errp);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression child;
@@
- qdev_init_nofail(DEVICE(child));
+ sysbus_realize(SYS_BUS_DEVICE(child), &error_fatal);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression child;
expression dev;
@@
dev = DEVICE(child);
...
- qdev_init_nofail(dev);
+ sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression child;
identifier dev;
@@
DeviceState *dev = DEVICE(child);
...
- qdev_init_nofail(dev);
+ sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
// only correct with a matching sysbus_init_child_obj() transformation!
@@
expression parent, name, size, type;
expression child;
symbol true;
@@
- sysbus_init_child_obj(parent, name, child, size, type);
+ sysbus_init_child_XXX(parent, name, child, size, type);
@@
expression parent, propname, type;
expression child;
@@
- sysbus_init_child_XXX(parent, propname, child, sizeof(*child), type)
+ object_initialize_child(parent, propname, child, type)
@@
expression parent, propname, type;
expression child;
@@
- sysbus_init_child_XXX(parent, propname, &child, sizeof(child), type)
+ object_initialize_child(parent, propname, &child, type)
This script is *unsound*: we need to manually verify init and realize
conversions are properly paired.
This commit has only the pairs where object_initialize_child()'s
@child and sysbus_realize()'s @dev argument text match exactly within
the same source file.
Note that Coccinelle chokes on ARMSSE typedef vs. macro in
hw/arm/armsse.c. Worked around by temporarily renaming the macro for
the spatch run.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-49-armbru@redhat.com>
2020-06-10 08:32:37 +03:00
|
|
|
object_initialize_child(obj, "mos6522-cuda", &s->mos6522_cuda,
|
|
|
|
TYPE_MOS6522_CUDA);
|
2018-06-07 20:17:49 +03:00
|
|
|
|
2018-02-09 21:51:40 +03:00
|
|
|
memory_region_init_io(&s->mem, obj, &mos6522_cuda_ops, s, "cuda", 0x2000);
|
|
|
|
sysbus_init_mmio(sbd, &s->mem);
|
2013-01-24 03:04:03 +04:00
|
|
|
|
2021-09-23 15:11:51 +03:00
|
|
|
qbus_init(&s->adb_bus, sizeof(s->adb_bus), TYPE_ADB_BUS,
|
|
|
|
DEVICE(obj), "adb.0");
|
2013-01-24 03:04:02 +04:00
|
|
|
}
|
|
|
|
|
2014-07-14 00:31:53 +04:00
|
|
|
static Property cuda_properties[] = {
|
2018-02-09 21:51:35 +03:00
|
|
|
DEFINE_PROP_UINT64("timebase-frequency", CUDAState, tb_frequency, 0),
|
2014-07-14 00:31:53 +04:00
|
|
|
DEFINE_PROP_END_OF_LIST()
|
|
|
|
};
|
|
|
|
|
2013-01-24 03:04:02 +04:00
|
|
|
static void cuda_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
2011-09-08 20:51:17 +04:00
|
|
|
|
2018-02-09 21:51:40 +03:00
|
|
|
dc->realize = cuda_realize;
|
2013-01-24 03:04:02 +04:00
|
|
|
dc->reset = cuda_reset;
|
|
|
|
dc->vmsd = &vmstate_cuda;
|
2020-01-10 18:30:32 +03:00
|
|
|
device_class_set_props(dc, cuda_properties);
|
2015-09-26 19:22:07 +03:00
|
|
|
set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
|
2004-06-03 22:46:20 +04:00
|
|
|
}
|
2013-01-24 03:04:02 +04:00
|
|
|
|
|
|
|
static const TypeInfo cuda_type_info = {
|
|
|
|
.name = TYPE_CUDA,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(CUDAState),
|
2018-02-09 21:51:40 +03:00
|
|
|
.instance_init = cuda_init,
|
2013-01-24 03:04:02 +04:00
|
|
|
.class_init = cuda_class_init,
|
|
|
|
};
|
|
|
|
|
2018-02-09 21:51:40 +03:00
|
|
|
static void mos6522_cuda_portB_write(MOS6522State *s)
|
|
|
|
{
|
|
|
|
MOS6522CUDAState *mcs = container_of(s, MOS6522CUDAState, parent_obj);
|
2018-06-07 20:17:49 +03:00
|
|
|
CUDAState *cs = container_of(mcs, CUDAState, mos6522_cuda);
|
2018-02-09 21:51:40 +03:00
|
|
|
|
2018-06-07 20:17:49 +03:00
|
|
|
cuda_update(cs);
|
2018-02-09 21:51:40 +03:00
|
|
|
}
|
|
|
|
|
2018-06-07 20:17:50 +03:00
|
|
|
static void mos6522_cuda_reset(DeviceState *dev)
|
2018-02-09 21:51:40 +03:00
|
|
|
{
|
|
|
|
MOS6522State *ms = MOS6522(dev);
|
2020-08-25 22:20:41 +03:00
|
|
|
MOS6522DeviceClass *mdc = MOS6522_GET_CLASS(ms);
|
2018-02-09 21:51:40 +03:00
|
|
|
|
2018-06-07 20:17:50 +03:00
|
|
|
mdc->parent_reset(dev);
|
2018-02-09 21:51:40 +03:00
|
|
|
|
|
|
|
ms->timers[0].frequency = CUDA_TIMER_FREQ;
|
|
|
|
ms->timers[1].frequency = (SCALE_US * 6000) / 4700;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mos6522_cuda_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
2020-08-25 22:20:41 +03:00
|
|
|
MOS6522DeviceClass *mdc = MOS6522_CLASS(oc);
|
2018-02-09 21:51:40 +03:00
|
|
|
|
2022-03-05 18:09:51 +03:00
|
|
|
device_class_set_parent_reset(dc, mos6522_cuda_reset,
|
|
|
|
&mdc->parent_reset);
|
2018-02-09 21:51:40 +03:00
|
|
|
mdc->portB_write = mos6522_cuda_portB_write;
|
|
|
|
mdc->get_timer1_counter_value = cuda_get_counter_value;
|
|
|
|
mdc->get_timer2_counter_value = cuda_get_counter_value;
|
|
|
|
mdc->get_timer1_load_time = cuda_get_load_time;
|
|
|
|
mdc->get_timer2_load_time = cuda_get_load_time;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo mos6522_cuda_type_info = {
|
|
|
|
.name = TYPE_MOS6522_CUDA,
|
|
|
|
.parent = TYPE_MOS6522,
|
|
|
|
.instance_size = sizeof(MOS6522CUDAState),
|
|
|
|
.class_init = mos6522_cuda_class_init,
|
|
|
|
};
|
|
|
|
|
2013-01-24 03:04:02 +04:00
|
|
|
static void cuda_register_types(void)
|
|
|
|
{
|
2018-02-09 21:51:40 +03:00
|
|
|
type_register_static(&mos6522_cuda_type_info);
|
2013-01-24 03:04:02 +04:00
|
|
|
type_register_static(&cuda_type_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(cuda_register_types)
|