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 typedef struct LasiState
{
58 PCIHostState parent_obj
;
71 MemoryRegion this_mem
;
74 static bool lasi_chip_mem_valid(void *opaque
, hwaddr addr
,
75 unsigned size
, bool is_write
,
87 case (LASI_LAN_HPA
- LASI_HPA
):
88 case (LASI_LPT_HPA
- LASI_HPA
):
89 case (LASI_UART_HPA
- LASI_HPA
):
90 case (LASI_RTC_HPA
- LASI_HPA
):
92 case LASI_PCR
... LASI_AMR
:
96 trace_lasi_chip_mem_valid(addr
, ret
);
100 static MemTxResult
lasi_chip_read_with_attrs(void *opaque
, hwaddr addr
,
101 uint64_t *data
, unsigned size
,
104 LasiState
*s
= opaque
;
105 MemTxResult ret
= MEMTX_OK
;
117 /* Any read to IPR clears the register. */
121 val
= s
->icr
& ICR_BUS_ERROR_BIT
; /* bus_error */
127 case (LASI_LAN_HPA
- LASI_HPA
):
128 case (LASI_LPT_HPA
- LASI_HPA
):
129 case (LASI_UART_HPA
- LASI_HPA
):
132 case (LASI_RTC_HPA
- LASI_HPA
):
138 case LASI_VER
: /* only version 0 existed. */
150 /* Controlled by lasi_chip_mem_valid above. */
151 g_assert_not_reached();
154 trace_lasi_chip_read(addr
, val
);
160 static MemTxResult
lasi_chip_write_with_attrs(void *opaque
, hwaddr addr
,
161 uint64_t val
, unsigned size
,
164 LasiState
*s
= opaque
;
166 trace_lasi_chip_write(addr
, val
);
173 s
->imr
= val
; /* 0x20 ?? */
174 assert((val
& LASI_IRQ_BITS
) == val
);
177 /* Any write to IPR clears the register. */
182 /* if (val & ICR_TOC_BIT) issue_toc(); */
188 case (LASI_LAN_HPA
- LASI_HPA
):
189 /* XXX: reset LAN card */
191 case (LASI_LPT_HPA
- LASI_HPA
):
192 /* XXX: reset parallel port */
194 case (LASI_UART_HPA
- LASI_HPA
):
195 /* XXX: reset serial port */
197 case (LASI_RTC_HPA
- LASI_HPA
):
198 s
->rtc_ref
= val
- time(NULL
);
202 if (val
== 0x02) /* immediately power off */
203 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN
);
212 break; /* XXX: TODO: Reset various devices. */
218 /* Controlled by lasi_chip_mem_valid above. */
219 g_assert_not_reached();
224 static const MemoryRegionOps lasi_chip_ops
= {
225 .read_with_attrs
= lasi_chip_read_with_attrs
,
226 .write_with_attrs
= lasi_chip_write_with_attrs
,
227 .endianness
= DEVICE_BIG_ENDIAN
,
229 .min_access_size
= 1,
230 .max_access_size
= 4,
231 .accepts
= lasi_chip_mem_valid
,
234 .min_access_size
= 1,
235 .max_access_size
= 4,
239 static const VMStateDescription vmstate_lasi
= {
242 .minimum_version_id
= 1,
243 .fields
= (VMStateField
[]) {
244 VMSTATE_UINT32(irr
, LasiState
),
245 VMSTATE_UINT32(imr
, LasiState
),
246 VMSTATE_UINT32(ipr
, LasiState
),
247 VMSTATE_UINT32(icr
, LasiState
),
248 VMSTATE_UINT32(iar
, LasiState
),
249 VMSTATE_UINT32(errlog
, LasiState
),
250 VMSTATE_UINT32(amr
, LasiState
),
251 VMSTATE_END_OF_LIST()
256 static void lasi_set_irq(void *opaque
, int irq
, int level
)
258 LasiState
*s
= opaque
;
259 uint32_t bit
= 1u << irq
;
264 uint32_t iar
= s
->iar
;
266 if ((s
->icr
& ICR_BUS_ERROR_BIT
) == 0) {
267 stl_be_phys(&address_space_memory
, iar
& -32, iar
& 31);
273 static int lasi_get_irq(unsigned long hpa
)
288 case LASI_PS2KBD_HPA
:
289 case LASI_PS2MOU_HPA
:
292 g_assert_not_reached();
296 DeviceState
*lasi_init(MemoryRegion
*address_space
)
301 dev
= qdev_new(TYPE_LASI_CHIP
);
303 s
->iar
= CPU_HPA
+ 3;
305 /* Lasi access from main memory. */
306 memory_region_init_io(&s
->this_mem
, OBJECT(s
), &lasi_chip_ops
,
307 s
, "lasi", 0x100000);
308 memory_region_add_subregion(address_space
, LASI_HPA
, &s
->this_mem
);
310 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
313 if (enable_lasi_lan()) {
314 qemu_irq lan_irq
= qemu_allocate_irq(lasi_set_irq
, s
,
315 lasi_get_irq(LASI_LAN_HPA
));
316 lasi_82596_init(address_space
, LASI_LAN_HPA
, lan_irq
);
320 qemu_irq lpt_irq
= qemu_allocate_irq(lasi_set_irq
, s
,
321 lasi_get_irq(LASI_LPT_HPA
));
322 parallel_mm_init(address_space
, LASI_LPT_HPA
+ 0x800, 0,
323 lpt_irq
, parallel_hds
[0]);
325 /* Real time clock (RTC), it's only one 32-bit counter @9000 */
332 qemu_irq serial_irq
= qemu_allocate_irq(lasi_set_irq
, s
,
333 lasi_get_irq(LASI_UART_HPA
));
334 serial_mm_init(address_space
, LASI_UART_HPA
+ 0x800, 0,
335 serial_irq
, 8000000 / 16,
336 serial_hd(0), DEVICE_NATIVE_ENDIAN
);
339 /* PS/2 Keyboard/Mouse */
340 qemu_irq ps2kbd_irq
= qemu_allocate_irq(lasi_set_irq
, s
,
341 lasi_get_irq(LASI_PS2KBD_HPA
));
342 lasips2_init(address_space
, LASI_PS2KBD_HPA
, ps2kbd_irq
);
347 static void lasi_class_init(ObjectClass
*klass
, void *data
)
349 DeviceClass
*dc
= DEVICE_CLASS(klass
);
351 dc
->vmsd
= &vmstate_lasi
;
354 static const TypeInfo lasi_pcihost_info
= {
355 .name
= TYPE_LASI_CHIP
,
356 .parent
= TYPE_SYS_BUS_DEVICE
,
357 .instance_size
= sizeof(LasiState
),
358 .class_init
= lasi_class_init
,
361 static void lasi_register_types(void)
363 type_register_static(&lasi_pcihost_info
);
366 type_init(lasi_register_types
)