2 * HP-PARISC Lasi chipset emulation.
4 * (C) 2019 by Helge Deller <deller@gmx.de>
6 * This work is licensed under the GNU GPL license version 2 or later.
8 * Documentation available at:
9 * https://parisc.wiki.kernel.org/images-parisc/7/79/Lasi_ers.pdf
12 #include "qemu/osdep.h"
13 #include "qemu/units.h"
15 #include "qapi/error.h"
18 #include "sysemu/sysemu.h"
19 #include "sysemu/runstate.h"
20 #include "migration/vmstate.h"
21 #include "qom/object.h"
22 #include "hw/misc/lasi.h"
25 static bool lasi_chip_mem_valid(void *opaque
, hwaddr addr
,
26 unsigned size
, bool is_write
,
43 case LASI_LAN
+ 12: /* LASI LAN MAC */
47 case LASI_PCR
... LASI_AMR
:
51 trace_lasi_chip_mem_valid(addr
, ret
);
55 static MemTxResult
lasi_chip_read_with_attrs(void *opaque
, hwaddr addr
,
56 uint64_t *data
, unsigned size
,
59 LasiState
*s
= opaque
;
60 MemTxResult ret
= MEMTX_OK
;
72 /* Any read to IPR clears the register. */
76 val
= s
->icr
& ICR_BUS_ERROR_BIT
; /* bus_error */
95 case LASI_VER
: /* only version 0 existed. */
107 /* Controlled by lasi_chip_mem_valid above. */
108 g_assert_not_reached();
111 trace_lasi_chip_read(addr
, val
);
117 static MemTxResult
lasi_chip_write_with_attrs(void *opaque
, hwaddr addr
,
118 uint64_t val
, unsigned size
,
121 LasiState
*s
= opaque
;
123 trace_lasi_chip_write(addr
, val
);
131 if (((val
& LASI_IRQ_BITS
) != val
) && (val
!= 0xffffffff)) {
132 qemu_log_mask(LOG_GUEST_ERROR
,
133 "LASI: tried to set invalid %lx IMR value.\n",
134 (unsigned long) val
);
138 /* Any write to IPR clears the register. */
143 /* if (val & ICR_TOC_BIT) issue_toc(); */
150 /* XXX: reset parallel port */
154 /* XXX: reset audio port */
157 /* XXX: reset serial port */
160 /* XXX: reset LAN card */
163 /* XXX: reset Floppy controller */
166 s
->rtc_ref
= val
- time(NULL
);
170 if (val
== 0x02) { /* immediately power off */
171 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN
);
181 break; /* XXX: TODO: Reset various devices. */
187 /* Controlled by lasi_chip_mem_valid above. */
188 g_assert_not_reached();
193 static const MemoryRegionOps lasi_chip_ops
= {
194 .read_with_attrs
= lasi_chip_read_with_attrs
,
195 .write_with_attrs
= lasi_chip_write_with_attrs
,
196 .endianness
= DEVICE_BIG_ENDIAN
,
198 .min_access_size
= 1,
199 .max_access_size
= 4,
200 .accepts
= lasi_chip_mem_valid
,
203 .min_access_size
= 1,
204 .max_access_size
= 4,
208 static const VMStateDescription vmstate_lasi
= {
211 .minimum_version_id
= 1,
212 .fields
= (const VMStateField
[]) {
213 VMSTATE_UINT32(irr
, LasiState
),
214 VMSTATE_UINT32(imr
, LasiState
),
215 VMSTATE_UINT32(ipr
, LasiState
),
216 VMSTATE_UINT32(icr
, LasiState
),
217 VMSTATE_UINT32(iar
, LasiState
),
218 VMSTATE_UINT32(errlog
, LasiState
),
219 VMSTATE_UINT32(amr
, LasiState
),
220 VMSTATE_UINT32_V(rtc_ref
, LasiState
, 2),
221 VMSTATE_END_OF_LIST()
226 static void lasi_set_irq(void *opaque
, int irq
, int level
)
228 LasiState
*s
= opaque
;
229 uint32_t bit
= 1u << irq
;
234 uint32_t iar
= s
->iar
;
236 if ((s
->icr
& ICR_BUS_ERROR_BIT
) == 0) {
237 stl_be_phys(&address_space_memory
, iar
& -32, iar
& 31);
243 static void lasi_reset(DeviceState
*dev
)
245 LasiState
*s
= LASI_CHIP(dev
);
247 s
->iar
= 0xFFFB0000 + 3; /* CPU_HPA + 3 */
249 /* Real time clock (RTC), it's only one 32-bit counter @9000 */
253 static void lasi_init(Object
*obj
)
255 LasiState
*s
= LASI_CHIP(obj
);
256 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
258 memory_region_init_io(&s
->this_mem
, OBJECT(s
), &lasi_chip_ops
,
259 s
, "lasi", 0x100000);
261 sysbus_init_mmio(sbd
, &s
->this_mem
);
263 qdev_init_gpio_in(DEVICE(obj
), lasi_set_irq
, LASI_IRQS
);
266 static void lasi_class_init(ObjectClass
*klass
, void *data
)
268 DeviceClass
*dc
= DEVICE_CLASS(klass
);
270 device_class_set_legacy_reset(dc
, lasi_reset
);
271 dc
->vmsd
= &vmstate_lasi
;
274 static const TypeInfo lasi_pcihost_info
= {
275 .name
= TYPE_LASI_CHIP
,
276 .parent
= TYPE_SYS_BUS_DEVICE
,
277 .instance_init
= lasi_init
,
278 .instance_size
= sizeof(LasiState
),
279 .class_init
= lasi_class_init
,
282 static void lasi_register_types(void)
284 type_register_static(&lasi_pcihost_info
);
287 type_init(lasi_register_types
)