4 * Copyright (c) 2019 Laurent Vivier
5 * Copyright (c) 2022 Mark Cave-Ayland
7 * SPDX-License-Identifier: GPL-2.0-or-later
10 #include "qemu/osdep.h"
12 #include "migration/vmstate.h"
13 #include "hw/sysbus.h"
14 #include "hw/misc/iosb.h"
17 #define IOSB_SIZE 0x2000
19 #define IOSB_CONFIG 0x0
20 #define IOSB_CONFIG2 0x100
21 #define IOSB_SONIC_SCSI 0x200
22 #define IOSB_REVISION 0x300
23 #define IOSB_SCSI_RESID 0x400
24 #define IOSB_BRIGHTNESS 0x500
25 #define IOSB_TIMEOUT 0x600
28 static uint64_t iosb_read(void *opaque
, hwaddr addr
,
31 IOSBState
*s
= IOSB(opaque
);
42 val
= s
->regs
[addr
>> 8];
45 qemu_log_mask(LOG_UNIMP
, "IOSB: unimplemented read addr=0x%"PRIx64
46 " val=0x%"PRIx64
" size=%d\n",
50 trace_iosb_read(addr
, val
, size
);
54 static void iosb_write(void *opaque
, hwaddr addr
, uint64_t val
,
57 IOSBState
*s
= IOSB(opaque
);
67 s
->regs
[addr
>> 8] = val
;
70 qemu_log_mask(LOG_UNIMP
, "IOSB: unimplemented write addr=0x%"PRIx64
71 " val=0x%"PRIx64
" size=%d\n",
75 trace_iosb_write(addr
, val
, size
);
78 static const MemoryRegionOps iosb_mmio_ops
= {
81 .endianness
= DEVICE_BIG_ENDIAN
,
84 static void iosb_reset_hold(Object
*obj
)
86 IOSBState
*s
= IOSB(obj
);
88 memset(s
->regs
, 0, sizeof(s
->regs
));
91 s
->regs
[IOSB_CONFIG
>> 8] = 1;
94 static void iosb_init(Object
*obj
)
96 IOSBState
*s
= IOSB(obj
);
97 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
99 memory_region_init_io(&s
->mem_regs
, obj
, &iosb_mmio_ops
, s
, "IOSB",
101 sysbus_init_mmio(sbd
, &s
->mem_regs
);
104 static const VMStateDescription vmstate_iosb
= {
107 .minimum_version_id
= 1,
108 .fields
= (VMStateField
[]) {
109 VMSTATE_UINT32_ARRAY(regs
, IOSBState
, IOSB_REGS
),
110 VMSTATE_END_OF_LIST()
114 static void iosb_class_init(ObjectClass
*oc
, void *data
)
116 DeviceClass
*dc
= DEVICE_CLASS(oc
);
117 ResettableClass
*rc
= RESETTABLE_CLASS(oc
);
119 dc
->vmsd
= &vmstate_iosb
;
120 rc
->phases
.hold
= iosb_reset_hold
;
123 static const TypeInfo iosb_info_types
[] = {
126 .parent
= TYPE_SYS_BUS_DEVICE
,
127 .instance_size
= sizeof(IOSBState
),
128 .instance_init
= iosb_init
,
129 .class_init
= iosb_class_init
,
133 DEFINE_TYPES(iosb_info_types
)