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"
14 #include "qapi/error.h"
19 #include "sysemu/sysemu.h"
20 #include "sysemu/runstate.h"
22 #include "hw/net/lasi_82596.h"
23 #include "hw/char/parallel.h"
24 #include "hw/char/serial.h"
25 #include "hw/input/lasips2.h"
26 #include "exec/address-spaces.h"
27 #include "migration/vmstate.h"
29 #define TYPE_LASI_CHIP "lasi-chip"
31 #define LASI_IRR 0x00 /* RO */
37 #define LASI_PCR 0x0C000 /* LASI Power Control register */
38 #define LASI_ERRLOG 0x0C004 /* LASI Error Logging register */
39 #define LASI_VER 0x0C008 /* LASI Version Control register */
40 #define LASI_IORESET 0x0C00C /* LASI I/O Reset register */
41 #define LASI_AMR 0x0C010 /* LASI Arbitration Mask register */
42 #define LASI_IO_CONF 0x7FFFE /* LASI primary configuration register */
43 #define LASI_IO_CONF2 0x7FFFF /* LASI secondary configuration register */
45 #define LASI_BIT(x) (1ul << (x))
46 #define LASI_IRQ_BITS (LASI_BIT(5) | LASI_BIT(7) | LASI_BIT(8) | LASI_BIT(9) \
47 | LASI_BIT(13) | LASI_BIT(14) | LASI_BIT(16) | LASI_BIT(17) \
48 | LASI_BIT(18) | LASI_BIT(19) | LASI_BIT(20) | LASI_BIT(21) \
51 #define ICR_BUS_ERROR_BIT LASI_BIT(8) /* bit 8 in ICR */
52 #define ICR_TOC_BIT LASI_BIT(1) /* bit 1 in ICR */
54 #define LASI_CHIP(obj) \
55 OBJECT_CHECK(LasiState, (obj), TYPE_LASI_CHIP)
57 #define LASI_RTC_HPA (LASI_HPA + 0x9000)
59 typedef struct LasiState
{
60 PCIHostState parent_obj
;
73 MemoryRegion this_mem
;
76 static bool lasi_chip_mem_valid(void *opaque
, hwaddr addr
,
77 unsigned size
, bool is_write
,
89 case (LASI_LAN_HPA
- LASI_HPA
):
90 case (LASI_LPT_HPA
- LASI_HPA
):
91 case (LASI_UART_HPA
- LASI_HPA
):
92 case (LASI_RTC_HPA
- LASI_HPA
):
94 case LASI_PCR
... LASI_AMR
:
98 trace_lasi_chip_mem_valid(addr
, ret
);
102 static MemTxResult
lasi_chip_read_with_attrs(void *opaque
, hwaddr addr
,
103 uint64_t *data
, unsigned size
,
106 LasiState
*s
= opaque
;
107 MemTxResult ret
= MEMTX_OK
;
119 /* Any read to IPR clears the register. */
123 val
= s
->icr
& ICR_BUS_ERROR_BIT
; /* bus_error */
129 case (LASI_LAN_HPA
- LASI_HPA
):
130 case (LASI_LPT_HPA
- LASI_HPA
):
131 case (LASI_UART_HPA
- LASI_HPA
):
134 case (LASI_RTC_HPA
- LASI_HPA
):
140 case LASI_VER
: /* only version 0 existed. */
152 /* Controlled by lasi_chip_mem_valid above. */
153 g_assert_not_reached();
156 trace_lasi_chip_read(addr
, val
);
162 static MemTxResult
lasi_chip_write_with_attrs(void *opaque
, hwaddr addr
,
163 uint64_t val
, unsigned size
,
166 LasiState
*s
= opaque
;
168 trace_lasi_chip_write(addr
, val
);
175 s
->imr
= val
; /* 0x20 ?? */
176 assert((val
& LASI_IRQ_BITS
) == val
);
179 /* Any write to IPR clears the register. */
184 /* if (val & ICR_TOC_BIT) issue_toc(); */
190 case (LASI_LAN_HPA
- LASI_HPA
):
191 /* XXX: reset LAN card */
193 case (LASI_LPT_HPA
- LASI_HPA
):
194 /* XXX: reset parallel port */
196 case (LASI_UART_HPA
- LASI_HPA
):
197 /* XXX: reset serial port */
199 case (LASI_RTC_HPA
- LASI_HPA
):
200 s
->rtc_ref
= val
- time(NULL
);
204 if (val
== 0x02) /* immediately power off */
205 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN
);
214 break; /* XXX: TODO: Reset various devices. */
220 /* Controlled by lasi_chip_mem_valid above. */
221 g_assert_not_reached();
226 static const MemoryRegionOps lasi_chip_ops
= {
227 .read_with_attrs
= lasi_chip_read_with_attrs
,
228 .write_with_attrs
= lasi_chip_write_with_attrs
,
229 .endianness
= DEVICE_BIG_ENDIAN
,
231 .min_access_size
= 1,
232 .max_access_size
= 4,
233 .accepts
= lasi_chip_mem_valid
,
236 .min_access_size
= 1,
237 .max_access_size
= 4,
241 static const VMStateDescription vmstate_lasi
= {
244 .minimum_version_id
= 1,
245 .fields
= (VMStateField
[]) {
246 VMSTATE_UINT32(irr
, LasiState
),
247 VMSTATE_UINT32(imr
, LasiState
),
248 VMSTATE_UINT32(ipr
, LasiState
),
249 VMSTATE_UINT32(icr
, LasiState
),
250 VMSTATE_UINT32(iar
, LasiState
),
251 VMSTATE_UINT32(errlog
, LasiState
),
252 VMSTATE_UINT32(amr
, LasiState
),
253 VMSTATE_END_OF_LIST()
258 static void lasi_set_irq(void *opaque
, int irq
, int level
)
260 LasiState
*s
= opaque
;
261 uint32_t bit
= 1u << irq
;
266 uint32_t iar
= s
->iar
;
268 if ((s
->icr
& ICR_BUS_ERROR_BIT
) == 0) {
269 stl_be_phys(&address_space_memory
, iar
& -32, iar
& 31);
275 static int lasi_get_irq(unsigned long hpa
)
290 case LASI_PS2KBD_HPA
:
291 case LASI_PS2MOU_HPA
:
294 g_assert_not_reached();
298 DeviceState
*lasi_init(MemoryRegion
*address_space
)
303 dev
= qdev_new(TYPE_LASI_CHIP
);
305 s
->iar
= CPU_HPA
+ 3;
307 /* Lasi access from main memory. */
308 memory_region_init_io(&s
->this_mem
, OBJECT(s
), &lasi_chip_ops
,
309 s
, "lasi", 0x100000);
310 memory_region_add_subregion(address_space
, LASI_HPA
, &s
->this_mem
);
312 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
315 if (enable_lasi_lan()) {
316 qemu_irq lan_irq
= qemu_allocate_irq(lasi_set_irq
, s
,
317 lasi_get_irq(LASI_LAN_HPA
));
318 lasi_82596_init(address_space
, LASI_LAN_HPA
, lan_irq
);
322 qemu_irq lpt_irq
= qemu_allocate_irq(lasi_set_irq
, s
,
323 lasi_get_irq(LASI_LPT_HPA
));
324 parallel_mm_init(address_space
, LASI_LPT_HPA
+ 0x800, 0,
325 lpt_irq
, parallel_hds
[0]);
327 /* Real time clock (RTC), it's only one 32-bit counter @9000 */
334 qemu_irq serial_irq
= qemu_allocate_irq(lasi_set_irq
, s
,
335 lasi_get_irq(LASI_UART_HPA
));
336 serial_mm_init(address_space
, LASI_UART_HPA
+ 0x800, 0,
337 serial_irq
, 8000000 / 16,
338 serial_hd(0), DEVICE_NATIVE_ENDIAN
);
341 /* PS/2 Keyboard/Mouse */
342 qemu_irq ps2kbd_irq
= qemu_allocate_irq(lasi_set_irq
, s
,
343 lasi_get_irq(LASI_PS2KBD_HPA
));
344 lasips2_init(address_space
, LASI_PS2KBD_HPA
, ps2kbd_irq
);
349 static void lasi_class_init(ObjectClass
*klass
, void *data
)
351 DeviceClass
*dc
= DEVICE_CLASS(klass
);
353 dc
->vmsd
= &vmstate_lasi
;
356 static const TypeInfo lasi_pcihost_info
= {
357 .name
= TYPE_LASI_CHIP
,
358 .parent
= TYPE_SYS_BUS_DEVICE
,
359 .instance_size
= sizeof(LasiState
),
360 .class_init
= lasi_class_init
,
363 static void lasi_register_types(void)
365 type_register_static(&lasi_pcihost_info
);
368 type_init(lasi_register_types
)