2 * HP-PARISC Lasi chipset emulation.
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"
20 #include "sysemu/sysemu.h"
21 #include "sysemu/runstate.h"
23 #include "hw/net/lasi_82596.h"
24 #include "hw/char/parallel.h"
25 #include "hw/char/serial.h"
26 #include "hw/input/lasips2.h"
27 #include "exec/address-spaces.h"
28 #include "migration/vmstate.h"
29 #include "qom/object.h"
31 #define TYPE_LASI_CHIP "lasi-chip"
33 #define LASI_IRR 0x00 /* RO */
39 #define LASI_PCR 0x0C000 /* LASI Power Control register */
40 #define LASI_ERRLOG 0x0C004 /* LASI Error Logging register */
41 #define LASI_VER 0x0C008 /* LASI Version Control register */
42 #define LASI_IORESET 0x0C00C /* LASI I/O Reset register */
43 #define LASI_AMR 0x0C010 /* LASI Arbitration Mask register */
44 #define LASI_IO_CONF 0x7FFFE /* LASI primary configuration register */
45 #define LASI_IO_CONF2 0x7FFFF /* LASI secondary configuration register */
47 #define LASI_BIT(x) (1ul << (x))
48 #define LASI_IRQ_BITS (LASI_BIT(5) | LASI_BIT(7) | LASI_BIT(8) | LASI_BIT(9) \
49 | LASI_BIT(13) | LASI_BIT(14) | LASI_BIT(16) | LASI_BIT(17) \
50 | LASI_BIT(18) | LASI_BIT(19) | LASI_BIT(20) | LASI_BIT(21) \
53 #define ICR_BUS_ERROR_BIT LASI_BIT(8) /* bit 8 in ICR */
54 #define ICR_TOC_BIT LASI_BIT(1) /* bit 1 in ICR */
56 OBJECT_DECLARE_SIMPLE_TYPE(LasiState, LASI_CHIP)
59 PCIHostState parent_obj;
72 MemoryRegion this_mem;
75 static bool lasi_chip_mem_valid(void *opaque, hwaddr addr,
76 unsigned size, bool is_write,
88 case (LASI_LAN_HPA - LASI_HPA):
89 case (LASI_LPT_HPA - LASI_HPA):
90 case (LASI_UART_HPA - LASI_HPA):
91 case (LASI_RTC_HPA - LASI_HPA):
93 case LASI_PCR ... LASI_AMR:
97 trace_lasi_chip_mem_valid(addr, ret);
101 static MemTxResult lasi_chip_read_with_attrs(void *opaque, hwaddr addr,
102 uint64_t *data, unsigned size,
105 LasiState *s = opaque;
106 MemTxResult ret = MEMTX_OK;
118 /* Any read to IPR clears the register. */
122 val = s->icr & ICR_BUS_ERROR_BIT; /* bus_error */
128 case (LASI_LAN_HPA - LASI_HPA):
129 case (LASI_LPT_HPA - LASI_HPA):
130 case (LASI_UART_HPA - LASI_HPA):
133 case (LASI_RTC_HPA - LASI_HPA):
139 case LASI_VER: /* only version 0 existed. */
151 /* Controlled by lasi_chip_mem_valid above. */
152 g_assert_not_reached();
155 trace_lasi_chip_read(addr, val);
161 static MemTxResult lasi_chip_write_with_attrs(void *opaque, hwaddr addr,
162 uint64_t val, unsigned size,
165 LasiState *s = opaque;
167 trace_lasi_chip_write(addr, val);
175 if (((val & LASI_IRQ_BITS) != val) && (val != 0xffffffff))
176 qemu_log_mask(LOG_GUEST_ERROR,
177 "LASI: tried to set invalid %lx IMR value.\n",
178 (unsigned long) val);
181 /* Any write to IPR clears the register. */
186 /* if (val & ICR_TOC_BIT) issue_toc(); */
192 case (LASI_LAN_HPA - LASI_HPA):
193 /* XXX: reset LAN card */
195 case (LASI_LPT_HPA - LASI_HPA):
196 /* XXX: reset parallel port */
198 case (LASI_UART_HPA - LASI_HPA):
199 /* XXX: reset serial port */
201 case (LASI_RTC_HPA - LASI_HPA):
202 s->rtc_ref = val - time(NULL);
206 if (val == 0x02) /* immediately power off */
207 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
216 break; /* XXX: TODO: Reset various devices. */
222 /* Controlled by lasi_chip_mem_valid above. */
223 g_assert_not_reached();
228 static const MemoryRegionOps lasi_chip_ops = {
229 .read_with_attrs = lasi_chip_read_with_attrs,
230 .write_with_attrs = lasi_chip_write_with_attrs,
231 .endianness = DEVICE_BIG_ENDIAN,
233 .min_access_size = 1,
234 .max_access_size = 4,
235 .accepts = lasi_chip_mem_valid,
238 .min_access_size = 1,
239 .max_access_size = 4,
243 static const VMStateDescription vmstate_lasi = {
246 .minimum_version_id = 1,
247 .fields = (VMStateField[]) {
248 VMSTATE_UINT32(irr, LasiState),
249 VMSTATE_UINT32(imr, LasiState),
250 VMSTATE_UINT32(ipr, LasiState),
251 VMSTATE_UINT32(icr, LasiState),
252 VMSTATE_UINT32(iar, LasiState),
253 VMSTATE_UINT32(errlog, LasiState),
254 VMSTATE_UINT32(amr, LasiState),
255 VMSTATE_END_OF_LIST()
260 static void lasi_set_irq(void *opaque, int irq, int level)
262 LasiState *s = opaque;
263 uint32_t bit = 1u << irq;
268 uint32_t iar = s->iar;
270 if ((s->icr & ICR_BUS_ERROR_BIT) == 0) {
271 stl_be_phys(&address_space_memory, iar & -32, iar & 31);
277 static int lasi_get_irq(unsigned long hpa)
292 case LASI_PS2KBD_HPA:
293 case LASI_PS2MOU_HPA:
296 g_assert_not_reached();
300 DeviceState *lasi_init(MemoryRegion *address_space)
305 dev = qdev_new(TYPE_LASI_CHIP);
307 s->iar = CPU_HPA + 3;
309 /* Lasi access from main memory. */
310 memory_region_init_io(&s->this_mem, OBJECT(s), &lasi_chip_ops,
311 s, "lasi", 0x100000);
312 memory_region_add_subregion(address_space, LASI_HPA, &s->this_mem);
314 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
317 if (enable_lasi_lan()) {
318 qemu_irq lan_irq = qemu_allocate_irq(lasi_set_irq, s,
319 lasi_get_irq(LASI_LAN_HPA));
320 lasi_82596_init(address_space, LASI_LAN_HPA, lan_irq);
324 qemu_irq lpt_irq = qemu_allocate_irq(lasi_set_irq, s,
325 lasi_get_irq(LASI_LPT_HPA));
326 parallel_mm_init(address_space, LASI_LPT_HPA + 0x800, 0,
327 lpt_irq, parallel_hds[0]);
329 /* Real time clock (RTC), it's only one 32-bit counter @9000 */
336 qemu_irq serial_irq = qemu_allocate_irq(lasi_set_irq, s,
337 lasi_get_irq(LASI_UART_HPA));
338 serial_mm_init(address_space, LASI_UART_HPA + 0x800, 0,
339 serial_irq, 8000000 / 16,
340 serial_hd(0), DEVICE_NATIVE_ENDIAN);
343 /* PS/2 Keyboard/Mouse */
344 qemu_irq ps2kbd_irq = qemu_allocate_irq(lasi_set_irq, s,
345 lasi_get_irq(LASI_PS2KBD_HPA));
346 lasips2_init(address_space, LASI_PS2KBD_HPA, ps2kbd_irq);
351 static void lasi_class_init(ObjectClass *klass, void *data)
353 DeviceClass *dc = DEVICE_CLASS(klass);
355 dc->vmsd = &vmstate_lasi;
358 static const TypeInfo lasi_pcihost_info = {
359 .name = TYPE_LASI_CHIP,
360 .parent = TYPE_SYS_BUS_DEVICE,
361 .instance_size = sizeof(LasiState),
362 .class_init = lasi_class_init,
365 static void lasi_register_types(void)
367 type_register_static(&lasi_pcihost_info);
370 type_init(lasi_register_types)