docs/interop: Delete qmp-intro.txt
[qemu/ar7.git] / hw / misc / lasi.c
blobff9dc893ae6582b4a5c82e115892dead3369eae5
1 /*
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 "qemu/log.h"
15 #include "qapi/error.h"
16 #include "trace.h"
17 #include "hw/irq.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,
27 MemTxAttrs attrs)
29 bool ret = false;
31 switch (addr) {
32 case LASI_IRR:
33 case LASI_IMR:
34 case LASI_IPR:
35 case LASI_ICR:
36 case LASI_IAR:
38 case LASI_LPT:
39 case LASI_UART:
40 case LASI_LAN:
41 case LASI_RTC:
43 case LASI_PCR ... LASI_AMR:
44 ret = true;
47 trace_lasi_chip_mem_valid(addr, ret);
48 return ret;
51 static MemTxResult lasi_chip_read_with_attrs(void *opaque, hwaddr addr,
52 uint64_t *data, unsigned size,
53 MemTxAttrs attrs)
55 LasiState *s = opaque;
56 MemTxResult ret = MEMTX_OK;
57 uint32_t val;
59 switch (addr) {
60 case LASI_IRR:
61 val = s->irr;
62 break;
63 case LASI_IMR:
64 val = s->imr;
65 break;
66 case LASI_IPR:
67 val = s->ipr;
68 /* Any read to IPR clears the register. */
69 s->ipr = 0;
70 break;
71 case LASI_ICR:
72 val = s->icr & ICR_BUS_ERROR_BIT; /* bus_error */
73 break;
74 case LASI_IAR:
75 val = s->iar;
76 break;
78 case LASI_LPT:
79 case LASI_UART:
80 case LASI_LAN:
81 val = 0;
82 break;
83 case LASI_RTC:
84 val = time(NULL);
85 val += s->rtc_ref;
86 break;
88 case LASI_PCR:
89 case LASI_VER: /* only version 0 existed. */
90 case LASI_IORESET:
91 val = 0;
92 break;
93 case LASI_ERRLOG:
94 val = s->errlog;
95 break;
96 case LASI_AMR:
97 val = s->amr;
98 break;
100 default:
101 /* Controlled by lasi_chip_mem_valid above. */
102 g_assert_not_reached();
105 trace_lasi_chip_read(addr, val);
107 *data = val;
108 return ret;
111 static MemTxResult lasi_chip_write_with_attrs(void *opaque, hwaddr addr,
112 uint64_t val, unsigned size,
113 MemTxAttrs attrs)
115 LasiState *s = opaque;
117 trace_lasi_chip_write(addr, val);
119 switch (addr) {
120 case LASI_IRR:
121 /* read-only. */
122 break;
123 case LASI_IMR:
124 s->imr = val;
125 if (((val & LASI_IRQ_BITS) != val) && (val != 0xffffffff)) {
126 qemu_log_mask(LOG_GUEST_ERROR,
127 "LASI: tried to set invalid %lx IMR value.\n",
128 (unsigned long) val);
130 break;
131 case LASI_IPR:
132 /* Any write to IPR clears the register. */
133 s->ipr = 0;
134 break;
135 case LASI_ICR:
136 s->icr = val;
137 /* if (val & ICR_TOC_BIT) issue_toc(); */
138 break;
139 case LASI_IAR:
140 s->iar = val;
141 break;
143 case LASI_LPT:
144 /* XXX: reset parallel port */
145 break;
146 case LASI_UART:
147 /* XXX: reset serial port */
148 break;
149 case LASI_LAN:
150 /* XXX: reset LAN card */
151 break;
152 case LASI_RTC:
153 s->rtc_ref = val - time(NULL);
154 break;
156 case LASI_PCR:
157 if (val == 0x02) { /* immediately power off */
158 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
160 break;
161 case LASI_ERRLOG:
162 s->errlog = val;
163 break;
164 case LASI_VER:
165 /* read-only. */
166 break;
167 case LASI_IORESET:
168 break; /* XXX: TODO: Reset various devices. */
169 case LASI_AMR:
170 s->amr = val;
171 break;
173 default:
174 /* Controlled by lasi_chip_mem_valid above. */
175 g_assert_not_reached();
177 return MEMTX_OK;
180 static const MemoryRegionOps lasi_chip_ops = {
181 .read_with_attrs = lasi_chip_read_with_attrs,
182 .write_with_attrs = lasi_chip_write_with_attrs,
183 .endianness = DEVICE_BIG_ENDIAN,
184 .valid = {
185 .min_access_size = 1,
186 .max_access_size = 4,
187 .accepts = lasi_chip_mem_valid,
189 .impl = {
190 .min_access_size = 1,
191 .max_access_size = 4,
195 static const VMStateDescription vmstate_lasi = {
196 .name = "Lasi",
197 .version_id = 2,
198 .minimum_version_id = 1,
199 .fields = (VMStateField[]) {
200 VMSTATE_UINT32(irr, LasiState),
201 VMSTATE_UINT32(imr, LasiState),
202 VMSTATE_UINT32(ipr, LasiState),
203 VMSTATE_UINT32(icr, LasiState),
204 VMSTATE_UINT32(iar, LasiState),
205 VMSTATE_UINT32(errlog, LasiState),
206 VMSTATE_UINT32(amr, LasiState),
207 VMSTATE_UINT32_V(rtc_ref, LasiState, 2),
208 VMSTATE_END_OF_LIST()
213 static void lasi_set_irq(void *opaque, int irq, int level)
215 LasiState *s = opaque;
216 uint32_t bit = 1u << irq;
218 if (level) {
219 s->ipr |= bit;
220 if (bit & s->imr) {
221 uint32_t iar = s->iar;
222 s->irr |= bit;
223 if ((s->icr & ICR_BUS_ERROR_BIT) == 0) {
224 stl_be_phys(&address_space_memory, iar & -32, iar & 31);
230 static void lasi_reset(DeviceState *dev)
232 LasiState *s = LASI_CHIP(dev);
234 s->iar = 0xFFFB0000 + 3; /* CPU_HPA + 3 */
236 /* Real time clock (RTC), it's only one 32-bit counter @9000 */
237 s->rtc_ref = 0;
240 static void lasi_init(Object *obj)
242 LasiState *s = LASI_CHIP(obj);
243 SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
245 memory_region_init_io(&s->this_mem, OBJECT(s), &lasi_chip_ops,
246 s, "lasi", 0x100000);
248 sysbus_init_mmio(sbd, &s->this_mem);
250 qdev_init_gpio_in(DEVICE(obj), lasi_set_irq, LASI_IRQS);
253 static void lasi_class_init(ObjectClass *klass, void *data)
255 DeviceClass *dc = DEVICE_CLASS(klass);
257 dc->reset = lasi_reset;
258 dc->vmsd = &vmstate_lasi;
261 static const TypeInfo lasi_pcihost_info = {
262 .name = TYPE_LASI_CHIP,
263 .parent = TYPE_SYS_BUS_DEVICE,
264 .instance_init = lasi_init,
265 .instance_size = sizeof(LasiState),
266 .class_init = lasi_class_init,
269 static void lasi_register_types(void)
271 type_register_static(&lasi_pcihost_info);
274 type_init(lasi_register_types)