target/mips: Remove helpers accessing SAAR registers
[qemu/ar7.git] / hw / misc / iosb.c
blobe20305e801331a35e9f4aa44aa188c0e771701c3
1 /*
2 * QEMU IOSB emulation
4 * Copyright (c) 2019 Laurent Vivier
5 * Copyright (c) 2022 Mark Cave-Ayland
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
10 #include "qemu/osdep.h"
11 #include "qemu/log.h"
12 #include "migration/vmstate.h"
13 #include "hw/sysbus.h"
14 #include "hw/misc/iosb.h"
15 #include "trace.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,
29 unsigned size)
31 IOSBState *s = IOSB(opaque);
32 uint64_t val = 0;
34 switch (addr) {
35 case IOSB_CONFIG:
36 case IOSB_CONFIG2:
37 case IOSB_SONIC_SCSI:
38 case IOSB_REVISION:
39 case IOSB_SCSI_RESID:
40 case IOSB_BRIGHTNESS:
41 case IOSB_TIMEOUT:
42 val = s->regs[addr >> 8];
43 break;
44 default:
45 qemu_log_mask(LOG_UNIMP, "IOSB: unimplemented read addr=0x%"PRIx64
46 " val=0x%"PRIx64 " size=%d\n",
47 addr, val, size);
50 trace_iosb_read(addr, val, size);
51 return val;
54 static void iosb_write(void *opaque, hwaddr addr, uint64_t val,
55 unsigned size)
57 IOSBState *s = IOSB(opaque);
59 switch (addr) {
60 case IOSB_CONFIG:
61 case IOSB_CONFIG2:
62 case IOSB_SONIC_SCSI:
63 case IOSB_REVISION:
64 case IOSB_SCSI_RESID:
65 case IOSB_BRIGHTNESS:
66 case IOSB_TIMEOUT:
67 s->regs[addr >> 8] = val;
68 break;
69 default:
70 qemu_log_mask(LOG_UNIMP, "IOSB: unimplemented write addr=0x%"PRIx64
71 " val=0x%"PRIx64 " size=%d\n",
72 addr, val, size);
75 trace_iosb_write(addr, val, size);
78 static const MemoryRegionOps iosb_mmio_ops = {
79 .read = iosb_read,
80 .write = iosb_write,
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));
90 /* BCLK 33 MHz */
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",
100 IOSB_SIZE);
101 sysbus_init_mmio(sbd, &s->mem_regs);
104 static const VMStateDescription vmstate_iosb = {
105 .name = "IOSB",
106 .version_id = 1,
107 .minimum_version_id = 1,
108 .fields = (const 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[] = {
125 .name = TYPE_IOSB,
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)