2 * BCM2835 SOC MPHI emulation
4 * Very basic emulation, only providing the FIQ interrupt needed to
5 * allow the dwc-otg USB host controller driver in the Raspbian kernel
8 * Copyright (c) 2020 Paul Zimmerman <pauldzim@gmail.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include "qemu/osdep.h"
22 #include "qapi/error.h"
23 #include "hw/misc/bcm2835_mphi.h"
24 #include "migration/vmstate.h"
25 #include "qemu/error-report.h"
27 #include "qemu/main-loop.h"
29 static inline void mphi_raise_irq(BCM2835MphiState
*s
)
31 qemu_set_irq(s
->irq
, 1);
34 static inline void mphi_lower_irq(BCM2835MphiState
*s
)
36 qemu_set_irq(s
->irq
, 0);
39 static uint64_t mphi_reg_read(void *ptr
, hwaddr addr
, unsigned size
)
41 BCM2835MphiState
*s
= ptr
;
45 case 0x28: /* outdda */
48 case 0x2c: /* outddb */
55 case 0x50: /* intstat */
58 case 0x1f0: /* swirq_set */
61 case 0x1f4: /* swirq_clr */
65 qemu_log_mask(LOG_UNIMP
, "read from unknown register");
72 static void mphi_reg_write(void *ptr
, hwaddr addr
, uint64_t val
, unsigned size
)
74 BCM2835MphiState
*s
= ptr
;
78 case 0x28: /* outdda */
81 case 0x2c: /* outddb */
83 if (val
& (1 << 29)) {
89 if (val
& (1 << 16)) {
93 case 0x50: /* intstat */
95 if (val
& ((1 << 16) | (1 << 29))) {
99 case 0x1f0: /* swirq_set */
103 case 0x1f4: /* swirq_clr */
108 qemu_log_mask(LOG_UNIMP
, "write to unknown register");
114 } else if (do_irq
< 0) {
119 static const MemoryRegionOps mphi_mmio_ops
= {
120 .read
= mphi_reg_read
,
121 .write
= mphi_reg_write
,
122 .impl
.min_access_size
= 4,
123 .impl
.max_access_size
= 4,
124 .endianness
= DEVICE_LITTLE_ENDIAN
,
127 static void mphi_reset(DeviceState
*dev
)
129 BCM2835MphiState
*s
= BCM2835_MPHI(dev
);
138 static void mphi_realize(DeviceState
*dev
, Error
**errp
)
140 SysBusDevice
*sbd
= SYS_BUS_DEVICE(dev
);
141 BCM2835MphiState
*s
= BCM2835_MPHI(dev
);
143 sysbus_init_irq(sbd
, &s
->irq
);
146 static void mphi_init(Object
*obj
)
148 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
149 BCM2835MphiState
*s
= BCM2835_MPHI(obj
);
151 memory_region_init_io(&s
->iomem
, obj
, &mphi_mmio_ops
, s
, "mphi", MPHI_MMIO_SIZE
);
152 sysbus_init_mmio(sbd
, &s
->iomem
);
155 const VMStateDescription vmstate_mphi_state
= {
158 .minimum_version_id
= 1,
159 .fields
= (VMStateField
[]) {
160 VMSTATE_UINT32(outdda
, BCM2835MphiState
),
161 VMSTATE_UINT32(outddb
, BCM2835MphiState
),
162 VMSTATE_UINT32(ctrl
, BCM2835MphiState
),
163 VMSTATE_UINT32(intstat
, BCM2835MphiState
),
164 VMSTATE_UINT32(swirq
, BCM2835MphiState
),
165 VMSTATE_END_OF_LIST()
169 static void mphi_class_init(ObjectClass
*klass
, void *data
)
171 DeviceClass
*dc
= DEVICE_CLASS(klass
);
173 dc
->realize
= mphi_realize
;
174 dc
->reset
= mphi_reset
;
175 dc
->vmsd
= &vmstate_mphi_state
;
178 static const TypeInfo bcm2835_mphi_type_info
= {
179 .name
= TYPE_BCM2835_MPHI
,
180 .parent
= TYPE_SYS_BUS_DEVICE
,
181 .instance_size
= sizeof(BCM2835MphiState
),
182 .instance_init
= mphi_init
,
183 .class_init
= mphi_class_init
,
186 static void bcm2835_mphi_register_types(void)
188 type_register_static(&bcm2835_mphi_type_info
);
191 type_init(bcm2835_mphi_register_types
)