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"
21 #include "hw/net/lasi_82596.h"
22 #include "hw/char/parallel.h"
23 #include "hw/char/serial.h"
24 #include "hw/input/lasips2.h"
25 #include "migration/vmstate.h"
26 #include "qom/object.h"
28 #define TYPE_LASI_CHIP "lasi-chip"
30 #define LASI_IRR 0x00 /* RO */
36 #define LASI_PCR 0x0C000 /* LASI Power Control register */
37 #define LASI_ERRLOG 0x0C004 /* LASI Error Logging register */
38 #define LASI_VER 0x0C008 /* LASI Version Control register */
39 #define LASI_IORESET 0x0C00C /* LASI I/O Reset register */
40 #define LASI_AMR 0x0C010 /* LASI Arbitration Mask register */
41 #define LASI_IO_CONF 0x7FFFE /* LASI primary configuration register */
42 #define LASI_IO_CONF2 0x7FFFF /* LASI secondary configuration register */
44 #define LASI_BIT(x) (1ul << (x))
45 #define LASI_IRQ_BITS (LASI_BIT(5) | LASI_BIT(7) | LASI_BIT(8) | LASI_BIT(9) \
46 | LASI_BIT(13) | LASI_BIT(14) | LASI_BIT(16) | LASI_BIT(17) \
47 | LASI_BIT(18) | LASI_BIT(19) | LASI_BIT(20) | LASI_BIT(21) \
50 #define ICR_BUS_ERROR_BIT LASI_BIT(8) /* bit 8 in ICR */
51 #define ICR_TOC_BIT LASI_BIT(1) /* bit 1 in ICR */
53 OBJECT_DECLARE_SIMPLE_TYPE(LasiState
, LASI_CHIP
)
56 PCIHostState parent_obj
;
69 MemoryRegion this_mem
;
72 static bool lasi_chip_mem_valid(void *opaque
, hwaddr addr
,
73 unsigned size
, bool is_write
,
85 case (LASI_LAN_HPA
- LASI_HPA
):
86 case (LASI_LPT_HPA
- LASI_HPA
):
87 case (LASI_UART_HPA
- LASI_HPA
):
88 case (LASI_RTC_HPA
- LASI_HPA
):
90 case LASI_PCR
... LASI_AMR
:
94 trace_lasi_chip_mem_valid(addr
, ret
);
98 static MemTxResult
lasi_chip_read_with_attrs(void *opaque
, hwaddr addr
,
99 uint64_t *data
, unsigned size
,
102 LasiState
*s
= opaque
;
103 MemTxResult ret
= MEMTX_OK
;
115 /* Any read to IPR clears the register. */
119 val
= s
->icr
& ICR_BUS_ERROR_BIT
; /* bus_error */
125 case (LASI_LAN_HPA
- LASI_HPA
):
126 case (LASI_LPT_HPA
- LASI_HPA
):
127 case (LASI_UART_HPA
- LASI_HPA
):
130 case (LASI_RTC_HPA
- LASI_HPA
):
136 case LASI_VER
: /* only version 0 existed. */
148 /* Controlled by lasi_chip_mem_valid above. */
149 g_assert_not_reached();
152 trace_lasi_chip_read(addr
, val
);
158 static MemTxResult
lasi_chip_write_with_attrs(void *opaque
, hwaddr addr
,
159 uint64_t val
, unsigned size
,
162 LasiState
*s
= opaque
;
164 trace_lasi_chip_write(addr
, val
);
172 if (((val
& LASI_IRQ_BITS
) != val
) && (val
!= 0xffffffff))
173 qemu_log_mask(LOG_GUEST_ERROR
,
174 "LASI: tried to set invalid %lx IMR value.\n",
175 (unsigned long) val
);
178 /* Any write to IPR clears the register. */
183 /* if (val & ICR_TOC_BIT) issue_toc(); */
189 case (LASI_LAN_HPA
- LASI_HPA
):
190 /* XXX: reset LAN card */
192 case (LASI_LPT_HPA
- LASI_HPA
):
193 /* XXX: reset parallel port */
195 case (LASI_UART_HPA
- LASI_HPA
):
196 /* XXX: reset serial port */
198 case (LASI_RTC_HPA
- LASI_HPA
):
199 s
->rtc_ref
= val
- time(NULL
);
203 if (val
== 0x02) /* immediately power off */
204 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN
);
213 break; /* XXX: TODO: Reset various devices. */
219 /* Controlled by lasi_chip_mem_valid above. */
220 g_assert_not_reached();
225 static const MemoryRegionOps lasi_chip_ops
= {
226 .read_with_attrs
= lasi_chip_read_with_attrs
,
227 .write_with_attrs
= lasi_chip_write_with_attrs
,
228 .endianness
= DEVICE_BIG_ENDIAN
,
230 .min_access_size
= 1,
231 .max_access_size
= 4,
232 .accepts
= lasi_chip_mem_valid
,
235 .min_access_size
= 1,
236 .max_access_size
= 4,
240 static const VMStateDescription vmstate_lasi
= {
243 .minimum_version_id
= 1,
244 .fields
= (VMStateField
[]) {
245 VMSTATE_UINT32(irr
, LasiState
),
246 VMSTATE_UINT32(imr
, LasiState
),
247 VMSTATE_UINT32(ipr
, LasiState
),
248 VMSTATE_UINT32(icr
, LasiState
),
249 VMSTATE_UINT32(iar
, LasiState
),
250 VMSTATE_UINT32(errlog
, LasiState
),
251 VMSTATE_UINT32(amr
, LasiState
),
252 VMSTATE_END_OF_LIST()
257 static void lasi_set_irq(void *opaque
, int irq
, int level
)
259 LasiState
*s
= opaque
;
260 uint32_t bit
= 1u << irq
;
265 uint32_t iar
= s
->iar
;
267 if ((s
->icr
& ICR_BUS_ERROR_BIT
) == 0) {
268 stl_be_phys(&address_space_memory
, iar
& -32, iar
& 31);
274 static int lasi_get_irq(unsigned long hpa
)
289 case LASI_PS2KBD_HPA
:
290 case LASI_PS2MOU_HPA
:
293 g_assert_not_reached();
297 DeviceState
*lasi_init(MemoryRegion
*address_space
)
302 dev
= qdev_new(TYPE_LASI_CHIP
);
304 s
->iar
= CPU_HPA
+ 3;
306 /* Lasi access from main memory. */
307 memory_region_init_io(&s
->this_mem
, OBJECT(s
), &lasi_chip_ops
,
308 s
, "lasi", 0x100000);
309 memory_region_add_subregion(address_space
, LASI_HPA
, &s
->this_mem
);
311 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
314 if (enable_lasi_lan()) {
315 qemu_irq lan_irq
= qemu_allocate_irq(lasi_set_irq
, s
,
316 lasi_get_irq(LASI_LAN_HPA
));
317 lasi_82596_init(address_space
, LASI_LAN_HPA
, lan_irq
);
321 qemu_irq lpt_irq
= qemu_allocate_irq(lasi_set_irq
, s
,
322 lasi_get_irq(LASI_LPT_HPA
));
323 parallel_mm_init(address_space
, LASI_LPT_HPA
+ 0x800, 0,
324 lpt_irq
, parallel_hds
[0]);
326 /* Real time clock (RTC), it's only one 32-bit counter @9000 */
333 qemu_irq serial_irq
= qemu_allocate_irq(lasi_set_irq
, s
,
334 lasi_get_irq(LASI_UART_HPA
));
335 serial_mm_init(address_space
, LASI_UART_HPA
+ 0x800, 0,
336 serial_irq
, 8000000 / 16,
337 serial_hd(0), DEVICE_NATIVE_ENDIAN
);
340 /* PS/2 Keyboard/Mouse */
341 qemu_irq ps2kbd_irq
= qemu_allocate_irq(lasi_set_irq
, s
,
342 lasi_get_irq(LASI_PS2KBD_HPA
));
343 lasips2_init(address_space
, LASI_PS2KBD_HPA
, ps2kbd_irq
);
348 static void lasi_class_init(ObjectClass
*klass
, void *data
)
350 DeviceClass
*dc
= DEVICE_CLASS(klass
);
352 dc
->vmsd
= &vmstate_lasi
;
355 static const TypeInfo lasi_pcihost_info
= {
356 .name
= TYPE_LASI_CHIP
,
357 .parent
= TYPE_SYS_BUS_DEVICE
,
358 .instance_size
= sizeof(LasiState
),
359 .class_init
= lasi_class_init
,
362 static void lasi_register_types(void)
364 type_register_static(&lasi_pcihost_info
);
367 type_init(lasi_register_types
)