xref: /openbmc/qemu/hw/intc/loongson_ipi.c (revision 91d0b151)
1b4a12dfcSJiaxun Yang /* SPDX-License-Identifier: GPL-2.0-or-later */
2b4a12dfcSJiaxun Yang /*
3b4a12dfcSJiaxun Yang  * Loongson ipi interrupt support
4b4a12dfcSJiaxun Yang  *
5b4a12dfcSJiaxun Yang  * Copyright (C) 2021 Loongson Technology Corporation Limited
6b4a12dfcSJiaxun Yang  */
7b4a12dfcSJiaxun Yang 
8b4a12dfcSJiaxun Yang #include "qemu/osdep.h"
9b4a12dfcSJiaxun Yang #include "hw/boards.h"
10b4a12dfcSJiaxun Yang #include "hw/sysbus.h"
11b4a12dfcSJiaxun Yang #include "hw/intc/loongson_ipi.h"
12b4a12dfcSJiaxun Yang #include "hw/irq.h"
13b4a12dfcSJiaxun Yang #include "hw/qdev-properties.h"
14b4a12dfcSJiaxun Yang #include "qapi/error.h"
15b4a12dfcSJiaxun Yang #include "qemu/log.h"
16b4a12dfcSJiaxun Yang #include "exec/address-spaces.h"
17b4a12dfcSJiaxun Yang #include "migration/vmstate.h"
18*91d0b151SJiaxun Yang #ifdef TARGET_LOONGARCH64
19b4a12dfcSJiaxun Yang #include "target/loongarch/cpu.h"
20*91d0b151SJiaxun Yang #endif
21*91d0b151SJiaxun Yang #ifdef TARGET_MIPS
22*91d0b151SJiaxun Yang #include "target/mips/cpu.h"
23*91d0b151SJiaxun Yang #endif
24b4a12dfcSJiaxun Yang #include "trace.h"
25b4a12dfcSJiaxun Yang 
26b4a12dfcSJiaxun Yang static MemTxResult loongson_ipi_readl(void *opaque, hwaddr addr,
27b4a12dfcSJiaxun Yang                                        uint64_t *data,
28b4a12dfcSJiaxun Yang                                        unsigned size, MemTxAttrs attrs)
29b4a12dfcSJiaxun Yang {
30b4a12dfcSJiaxun Yang     IPICore *s;
31b4a12dfcSJiaxun Yang     LoongsonIPI *ipi = opaque;
32b4a12dfcSJiaxun Yang     uint64_t ret = 0;
33b4a12dfcSJiaxun Yang     int index = 0;
34b4a12dfcSJiaxun Yang 
35b4a12dfcSJiaxun Yang     s = &ipi->cpu[attrs.requester_id];
36b4a12dfcSJiaxun Yang     addr &= 0xff;
37b4a12dfcSJiaxun Yang     switch (addr) {
38b4a12dfcSJiaxun Yang     case CORE_STATUS_OFF:
39b4a12dfcSJiaxun Yang         ret = s->status;
40b4a12dfcSJiaxun Yang         break;
41b4a12dfcSJiaxun Yang     case CORE_EN_OFF:
42b4a12dfcSJiaxun Yang         ret = s->en;
43b4a12dfcSJiaxun Yang         break;
44b4a12dfcSJiaxun Yang     case CORE_SET_OFF:
45b4a12dfcSJiaxun Yang         ret = 0;
46b4a12dfcSJiaxun Yang         break;
47b4a12dfcSJiaxun Yang     case CORE_CLEAR_OFF:
48b4a12dfcSJiaxun Yang         ret = 0;
49b4a12dfcSJiaxun Yang         break;
50b4a12dfcSJiaxun Yang     case CORE_BUF_20 ... CORE_BUF_38 + 4:
51b4a12dfcSJiaxun Yang         index = (addr - CORE_BUF_20) >> 2;
52b4a12dfcSJiaxun Yang         ret = s->buf[index];
53b4a12dfcSJiaxun Yang         break;
54b4a12dfcSJiaxun Yang     default:
55b4a12dfcSJiaxun Yang         qemu_log_mask(LOG_UNIMP, "invalid read: %x", (uint32_t)addr);
56b4a12dfcSJiaxun Yang         break;
57b4a12dfcSJiaxun Yang     }
58b4a12dfcSJiaxun Yang 
59b4a12dfcSJiaxun Yang     trace_loongson_ipi_read(size, (uint64_t)addr, ret);
60b4a12dfcSJiaxun Yang     *data = ret;
61b4a12dfcSJiaxun Yang     return MEMTX_OK;
62b4a12dfcSJiaxun Yang }
63b4a12dfcSJiaxun Yang 
64*91d0b151SJiaxun Yang static AddressSpace *get_cpu_iocsr_as(CPUState *cpu)
65*91d0b151SJiaxun Yang {
66*91d0b151SJiaxun Yang #ifdef TARGET_LOONGARCH64
67*91d0b151SJiaxun Yang     return LOONGARCH_CPU(cpu)->env.address_space_iocsr;
68*91d0b151SJiaxun Yang #endif
69*91d0b151SJiaxun Yang #ifdef TARGET_MIPS
70*91d0b151SJiaxun Yang     if (ase_lcsr_available(&MIPS_CPU(cpu)->env)) {
71*91d0b151SJiaxun Yang         return &MIPS_CPU(cpu)->env.iocsr.as;
72*91d0b151SJiaxun Yang     }
73*91d0b151SJiaxun Yang #endif
74*91d0b151SJiaxun Yang     return NULL;
75*91d0b151SJiaxun Yang }
76*91d0b151SJiaxun Yang 
77*91d0b151SJiaxun Yang static MemTxResult send_ipi_data(CPUState *cpu, uint64_t val, hwaddr addr,
78b4a12dfcSJiaxun Yang                           MemTxAttrs attrs)
79b4a12dfcSJiaxun Yang {
80b4a12dfcSJiaxun Yang     int i, mask = 0, data = 0;
81*91d0b151SJiaxun Yang     AddressSpace *iocsr_as = get_cpu_iocsr_as(cpu);
82*91d0b151SJiaxun Yang 
83*91d0b151SJiaxun Yang     if (!iocsr_as) {
84*91d0b151SJiaxun Yang         return MEMTX_DECODE_ERROR;
85*91d0b151SJiaxun Yang     }
86b4a12dfcSJiaxun Yang 
87b4a12dfcSJiaxun Yang     /*
88b4a12dfcSJiaxun Yang      * bit 27-30 is mask for byte writing,
89b4a12dfcSJiaxun Yang      * if the mask is 0, we need not to do anything.
90b4a12dfcSJiaxun Yang      */
91b4a12dfcSJiaxun Yang     if ((val >> 27) & 0xf) {
92*91d0b151SJiaxun Yang         data = address_space_ldl(iocsr_as, addr, attrs, NULL);
93b4a12dfcSJiaxun Yang         for (i = 0; i < 4; i++) {
94b4a12dfcSJiaxun Yang             /* get mask for byte writing */
95b4a12dfcSJiaxun Yang             if (val & (0x1 << (27 + i))) {
96b4a12dfcSJiaxun Yang                 mask |= 0xff << (i * 8);
97b4a12dfcSJiaxun Yang             }
98b4a12dfcSJiaxun Yang         }
99b4a12dfcSJiaxun Yang     }
100b4a12dfcSJiaxun Yang 
101b4a12dfcSJiaxun Yang     data &= mask;
102b4a12dfcSJiaxun Yang     data |= (val >> 32) & ~mask;
103*91d0b151SJiaxun Yang     address_space_stl(iocsr_as, addr, data, attrs, NULL);
104*91d0b151SJiaxun Yang 
105*91d0b151SJiaxun Yang     return MEMTX_OK;
106b4a12dfcSJiaxun Yang }
107b4a12dfcSJiaxun Yang 
108b4a12dfcSJiaxun Yang static int archid_cmp(const void *a, const void *b)
109b4a12dfcSJiaxun Yang {
110b4a12dfcSJiaxun Yang    CPUArchId *archid_a = (CPUArchId *)a;
111b4a12dfcSJiaxun Yang    CPUArchId *archid_b = (CPUArchId *)b;
112b4a12dfcSJiaxun Yang 
113b4a12dfcSJiaxun Yang    return archid_a->arch_id - archid_b->arch_id;
114b4a12dfcSJiaxun Yang }
115b4a12dfcSJiaxun Yang 
116b4a12dfcSJiaxun Yang static CPUArchId *find_cpu_by_archid(MachineState *ms, uint32_t id)
117b4a12dfcSJiaxun Yang {
118b4a12dfcSJiaxun Yang     CPUArchId apic_id, *found_cpu;
119b4a12dfcSJiaxun Yang 
120b4a12dfcSJiaxun Yang     apic_id.arch_id = id;
121b4a12dfcSJiaxun Yang     found_cpu = bsearch(&apic_id, ms->possible_cpus->cpus,
122b4a12dfcSJiaxun Yang         ms->possible_cpus->len, sizeof(*ms->possible_cpus->cpus),
123b4a12dfcSJiaxun Yang         archid_cmp);
124b4a12dfcSJiaxun Yang 
125b4a12dfcSJiaxun Yang     return found_cpu;
126b4a12dfcSJiaxun Yang }
127b4a12dfcSJiaxun Yang 
128b4a12dfcSJiaxun Yang static CPUState *ipi_getcpu(int arch_id)
129b4a12dfcSJiaxun Yang {
130b4a12dfcSJiaxun Yang     MachineState *machine = MACHINE(qdev_get_machine());
131b4a12dfcSJiaxun Yang     CPUArchId *archid;
132b4a12dfcSJiaxun Yang 
133b4a12dfcSJiaxun Yang     archid = find_cpu_by_archid(machine, arch_id);
134b4a12dfcSJiaxun Yang     if (archid) {
135b4a12dfcSJiaxun Yang         return CPU(archid->cpu);
136b4a12dfcSJiaxun Yang     }
137b4a12dfcSJiaxun Yang 
138b4a12dfcSJiaxun Yang     return NULL;
139b4a12dfcSJiaxun Yang }
140b4a12dfcSJiaxun Yang 
141b4a12dfcSJiaxun Yang static MemTxResult mail_send(uint64_t val, MemTxAttrs attrs)
142b4a12dfcSJiaxun Yang {
143b4a12dfcSJiaxun Yang     uint32_t cpuid;
144b4a12dfcSJiaxun Yang     hwaddr addr;
145b4a12dfcSJiaxun Yang     CPUState *cs;
146b4a12dfcSJiaxun Yang 
147b4a12dfcSJiaxun Yang     cpuid = extract32(val, 16, 10);
148b4a12dfcSJiaxun Yang     cs = ipi_getcpu(cpuid);
149b4a12dfcSJiaxun Yang     if (cs == NULL) {
150b4a12dfcSJiaxun Yang         return MEMTX_DECODE_ERROR;
151b4a12dfcSJiaxun Yang     }
152b4a12dfcSJiaxun Yang 
153b4a12dfcSJiaxun Yang     /* override requester_id */
154b4a12dfcSJiaxun Yang     addr = SMP_IPI_MAILBOX + CORE_BUF_20 + (val & 0x1c);
155b4a12dfcSJiaxun Yang     attrs.requester_id = cs->cpu_index;
156*91d0b151SJiaxun Yang     return send_ipi_data(cs, val, addr, attrs);
157b4a12dfcSJiaxun Yang }
158b4a12dfcSJiaxun Yang 
159b4a12dfcSJiaxun Yang static MemTxResult any_send(uint64_t val, MemTxAttrs attrs)
160b4a12dfcSJiaxun Yang {
161b4a12dfcSJiaxun Yang     uint32_t cpuid;
162b4a12dfcSJiaxun Yang     hwaddr addr;
163b4a12dfcSJiaxun Yang     CPUState *cs;
164b4a12dfcSJiaxun Yang 
165b4a12dfcSJiaxun Yang     cpuid = extract32(val, 16, 10);
166b4a12dfcSJiaxun Yang     cs = ipi_getcpu(cpuid);
167b4a12dfcSJiaxun Yang     if (cs == NULL) {
168b4a12dfcSJiaxun Yang         return MEMTX_DECODE_ERROR;
169b4a12dfcSJiaxun Yang     }
170b4a12dfcSJiaxun Yang 
171b4a12dfcSJiaxun Yang     /* override requester_id */
172b4a12dfcSJiaxun Yang     addr = val & 0xffff;
173b4a12dfcSJiaxun Yang     attrs.requester_id = cs->cpu_index;
174*91d0b151SJiaxun Yang     return send_ipi_data(cs, val, addr, attrs);
175b4a12dfcSJiaxun Yang }
176b4a12dfcSJiaxun Yang 
177b4a12dfcSJiaxun Yang static MemTxResult loongson_ipi_writel(void *opaque, hwaddr addr, uint64_t val,
178b4a12dfcSJiaxun Yang                                         unsigned size, MemTxAttrs attrs)
179b4a12dfcSJiaxun Yang {
180b4a12dfcSJiaxun Yang     LoongsonIPI *ipi = opaque;
181b4a12dfcSJiaxun Yang     IPICore *s;
182b4a12dfcSJiaxun Yang     int index = 0;
183b4a12dfcSJiaxun Yang     uint32_t cpuid;
184b4a12dfcSJiaxun Yang     uint8_t vector;
185b4a12dfcSJiaxun Yang     CPUState *cs;
186b4a12dfcSJiaxun Yang 
187b4a12dfcSJiaxun Yang     s = &ipi->cpu[attrs.requester_id];
188b4a12dfcSJiaxun Yang     addr &= 0xff;
189b4a12dfcSJiaxun Yang     trace_loongson_ipi_write(size, (uint64_t)addr, val);
190b4a12dfcSJiaxun Yang     switch (addr) {
191b4a12dfcSJiaxun Yang     case CORE_STATUS_OFF:
192b4a12dfcSJiaxun Yang         qemu_log_mask(LOG_GUEST_ERROR, "can not be written");
193b4a12dfcSJiaxun Yang         break;
194b4a12dfcSJiaxun Yang     case CORE_EN_OFF:
195b4a12dfcSJiaxun Yang         s->en = val;
196b4a12dfcSJiaxun Yang         break;
197b4a12dfcSJiaxun Yang     case CORE_SET_OFF:
198b4a12dfcSJiaxun Yang         s->status |= val;
199b4a12dfcSJiaxun Yang         if (s->status != 0 && (s->status & s->en) != 0) {
200b4a12dfcSJiaxun Yang             qemu_irq_raise(s->irq);
201b4a12dfcSJiaxun Yang         }
202b4a12dfcSJiaxun Yang         break;
203b4a12dfcSJiaxun Yang     case CORE_CLEAR_OFF:
204b4a12dfcSJiaxun Yang         s->status &= ~val;
205b4a12dfcSJiaxun Yang         if (s->status == 0 && s->en != 0) {
206b4a12dfcSJiaxun Yang             qemu_irq_lower(s->irq);
207b4a12dfcSJiaxun Yang         }
208b4a12dfcSJiaxun Yang         break;
209b4a12dfcSJiaxun Yang     case CORE_BUF_20 ... CORE_BUF_38 + 4:
210b4a12dfcSJiaxun Yang         index = (addr - CORE_BUF_20) >> 2;
211b4a12dfcSJiaxun Yang         s->buf[index] = val;
212b4a12dfcSJiaxun Yang         break;
213b4a12dfcSJiaxun Yang     case IOCSR_IPI_SEND:
214b4a12dfcSJiaxun Yang         cpuid = extract32(val, 16, 10);
215b4a12dfcSJiaxun Yang         /* IPI status vector */
216b4a12dfcSJiaxun Yang         vector = extract8(val, 0, 5);
217b4a12dfcSJiaxun Yang         cs = ipi_getcpu(cpuid);
218b4a12dfcSJiaxun Yang         if (cs == NULL) {
219b4a12dfcSJiaxun Yang             return MEMTX_DECODE_ERROR;
220b4a12dfcSJiaxun Yang         }
221b4a12dfcSJiaxun Yang 
222b4a12dfcSJiaxun Yang         /* override requester_id */
223b4a12dfcSJiaxun Yang         attrs.requester_id = cs->cpu_index;
224b4a12dfcSJiaxun Yang         loongson_ipi_writel(ipi, CORE_SET_OFF, BIT(vector), 4, attrs);
225b4a12dfcSJiaxun Yang         break;
226b4a12dfcSJiaxun Yang     default:
227b4a12dfcSJiaxun Yang         qemu_log_mask(LOG_UNIMP, "invalid write: %x", (uint32_t)addr);
228b4a12dfcSJiaxun Yang         break;
229b4a12dfcSJiaxun Yang     }
230b4a12dfcSJiaxun Yang 
231b4a12dfcSJiaxun Yang     return MEMTX_OK;
232b4a12dfcSJiaxun Yang }
233b4a12dfcSJiaxun Yang 
234b4a12dfcSJiaxun Yang static const MemoryRegionOps loongson_ipi_ops = {
235b4a12dfcSJiaxun Yang     .read_with_attrs = loongson_ipi_readl,
236b4a12dfcSJiaxun Yang     .write_with_attrs = loongson_ipi_writel,
237b4a12dfcSJiaxun Yang     .impl.min_access_size = 4,
238b4a12dfcSJiaxun Yang     .impl.max_access_size = 4,
239b4a12dfcSJiaxun Yang     .valid.min_access_size = 4,
240b4a12dfcSJiaxun Yang     .valid.max_access_size = 8,
241b4a12dfcSJiaxun Yang     .endianness = DEVICE_LITTLE_ENDIAN,
242b4a12dfcSJiaxun Yang };
243b4a12dfcSJiaxun Yang 
244b4a12dfcSJiaxun Yang /* mail send and any send only support writeq */
245b4a12dfcSJiaxun Yang static MemTxResult loongson_ipi_writeq(void *opaque, hwaddr addr, uint64_t val,
246b4a12dfcSJiaxun Yang                                         unsigned size, MemTxAttrs attrs)
247b4a12dfcSJiaxun Yang {
248b4a12dfcSJiaxun Yang     MemTxResult ret = MEMTX_OK;
249b4a12dfcSJiaxun Yang 
250b4a12dfcSJiaxun Yang     addr &= 0xfff;
251b4a12dfcSJiaxun Yang     switch (addr) {
252b4a12dfcSJiaxun Yang     case MAIL_SEND_OFFSET:
253b4a12dfcSJiaxun Yang         ret = mail_send(val, attrs);
254b4a12dfcSJiaxun Yang         break;
255b4a12dfcSJiaxun Yang     case ANY_SEND_OFFSET:
256b4a12dfcSJiaxun Yang         ret = any_send(val, attrs);
257b4a12dfcSJiaxun Yang         break;
258b4a12dfcSJiaxun Yang     default:
259b4a12dfcSJiaxun Yang        break;
260b4a12dfcSJiaxun Yang     }
261b4a12dfcSJiaxun Yang 
262b4a12dfcSJiaxun Yang     return ret;
263b4a12dfcSJiaxun Yang }
264b4a12dfcSJiaxun Yang 
265b4a12dfcSJiaxun Yang static const MemoryRegionOps loongson_ipi64_ops = {
266b4a12dfcSJiaxun Yang     .write_with_attrs = loongson_ipi_writeq,
267b4a12dfcSJiaxun Yang     .impl.min_access_size = 8,
268b4a12dfcSJiaxun Yang     .impl.max_access_size = 8,
269b4a12dfcSJiaxun Yang     .valid.min_access_size = 8,
270b4a12dfcSJiaxun Yang     .valid.max_access_size = 8,
271b4a12dfcSJiaxun Yang     .endianness = DEVICE_LITTLE_ENDIAN,
272b4a12dfcSJiaxun Yang };
273b4a12dfcSJiaxun Yang 
274b4a12dfcSJiaxun Yang static void loongson_ipi_realize(DeviceState *dev, Error **errp)
275b4a12dfcSJiaxun Yang {
276b4a12dfcSJiaxun Yang     LoongsonIPI *s = LOONGSON_IPI(dev);
277b4a12dfcSJiaxun Yang     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
278b4a12dfcSJiaxun Yang     int i;
279b4a12dfcSJiaxun Yang 
280b4a12dfcSJiaxun Yang     if (s->num_cpu == 0) {
281b4a12dfcSJiaxun Yang         error_setg(errp, "num-cpu must be at least 1");
282b4a12dfcSJiaxun Yang         return;
283b4a12dfcSJiaxun Yang     }
284b4a12dfcSJiaxun Yang 
285b4a12dfcSJiaxun Yang     memory_region_init_io(&s->ipi_iocsr_mem, OBJECT(dev), &loongson_ipi_ops,
286b4a12dfcSJiaxun Yang                           s, "loongson_ipi_iocsr", 0x48);
287b4a12dfcSJiaxun Yang 
288b4a12dfcSJiaxun Yang     /* loongson_ipi_iocsr performs re-entrant IO through ipi_send */
289b4a12dfcSJiaxun Yang     s->ipi_iocsr_mem.disable_reentrancy_guard = true;
290b4a12dfcSJiaxun Yang 
291b4a12dfcSJiaxun Yang     sysbus_init_mmio(sbd, &s->ipi_iocsr_mem);
292b4a12dfcSJiaxun Yang 
293b4a12dfcSJiaxun Yang     memory_region_init_io(&s->ipi64_iocsr_mem, OBJECT(dev),
294b4a12dfcSJiaxun Yang                           &loongson_ipi64_ops,
295b4a12dfcSJiaxun Yang                           s, "loongson_ipi64_iocsr", 0x118);
296b4a12dfcSJiaxun Yang     sysbus_init_mmio(sbd, &s->ipi64_iocsr_mem);
297b4a12dfcSJiaxun Yang 
298b4a12dfcSJiaxun Yang     s->cpu = g_new0(IPICore, s->num_cpu);
299b4a12dfcSJiaxun Yang     if (s->cpu == NULL) {
300b4a12dfcSJiaxun Yang         error_setg(errp, "Memory allocation for ExtIOICore faile");
301b4a12dfcSJiaxun Yang         return;
302b4a12dfcSJiaxun Yang     }
303b4a12dfcSJiaxun Yang 
304b4a12dfcSJiaxun Yang     for (i = 0; i < s->num_cpu; i++) {
305b4a12dfcSJiaxun Yang         qdev_init_gpio_out(dev, &s->cpu[i].irq, 1);
306b4a12dfcSJiaxun Yang     }
307b4a12dfcSJiaxun Yang }
308b4a12dfcSJiaxun Yang 
309b4a12dfcSJiaxun Yang static const VMStateDescription vmstate_ipi_core = {
310b4a12dfcSJiaxun Yang     .name = "ipi-single",
311b4a12dfcSJiaxun Yang     .version_id = 2,
312b4a12dfcSJiaxun Yang     .minimum_version_id = 2,
313b4a12dfcSJiaxun Yang     .fields = (const VMStateField[]) {
314b4a12dfcSJiaxun Yang         VMSTATE_UINT32(status, IPICore),
315b4a12dfcSJiaxun Yang         VMSTATE_UINT32(en, IPICore),
316b4a12dfcSJiaxun Yang         VMSTATE_UINT32(set, IPICore),
317b4a12dfcSJiaxun Yang         VMSTATE_UINT32(clear, IPICore),
318b4a12dfcSJiaxun Yang         VMSTATE_UINT32_ARRAY(buf, IPICore, IPI_MBX_NUM * 2),
319b4a12dfcSJiaxun Yang         VMSTATE_END_OF_LIST()
320b4a12dfcSJiaxun Yang     }
321b4a12dfcSJiaxun Yang };
322b4a12dfcSJiaxun Yang 
323b4a12dfcSJiaxun Yang static const VMStateDescription vmstate_loongson_ipi = {
324b4a12dfcSJiaxun Yang     .name = TYPE_LOONGSON_IPI,
325b4a12dfcSJiaxun Yang     .version_id = 2,
326b4a12dfcSJiaxun Yang     .minimum_version_id = 2,
327b4a12dfcSJiaxun Yang     .fields = (const VMStateField[]) {
328b4a12dfcSJiaxun Yang         VMSTATE_STRUCT_VARRAY_POINTER_UINT32(cpu, LoongsonIPI, num_cpu,
329b4a12dfcSJiaxun Yang                          vmstate_ipi_core, IPICore),
330b4a12dfcSJiaxun Yang         VMSTATE_END_OF_LIST()
331b4a12dfcSJiaxun Yang     }
332b4a12dfcSJiaxun Yang };
333b4a12dfcSJiaxun Yang 
334b4a12dfcSJiaxun Yang static Property ipi_properties[] = {
335b4a12dfcSJiaxun Yang     DEFINE_PROP_UINT32("num-cpu", LoongsonIPI, num_cpu, 1),
336b4a12dfcSJiaxun Yang     DEFINE_PROP_END_OF_LIST(),
337b4a12dfcSJiaxun Yang };
338b4a12dfcSJiaxun Yang 
339b4a12dfcSJiaxun Yang static void loongson_ipi_class_init(ObjectClass *klass, void *data)
340b4a12dfcSJiaxun Yang {
341b4a12dfcSJiaxun Yang     DeviceClass *dc = DEVICE_CLASS(klass);
342b4a12dfcSJiaxun Yang 
343b4a12dfcSJiaxun Yang     dc->realize = loongson_ipi_realize;
344b4a12dfcSJiaxun Yang     device_class_set_props(dc, ipi_properties);
345b4a12dfcSJiaxun Yang     dc->vmsd = &vmstate_loongson_ipi;
346b4a12dfcSJiaxun Yang }
347b4a12dfcSJiaxun Yang 
348b4a12dfcSJiaxun Yang static void loongson_ipi_finalize(Object *obj)
349b4a12dfcSJiaxun Yang {
350b4a12dfcSJiaxun Yang     LoongsonIPI *s = LOONGSON_IPI(obj);
351b4a12dfcSJiaxun Yang 
352b4a12dfcSJiaxun Yang     g_free(s->cpu);
353b4a12dfcSJiaxun Yang }
354b4a12dfcSJiaxun Yang 
355b4a12dfcSJiaxun Yang static const TypeInfo loongson_ipi_info = {
356b4a12dfcSJiaxun Yang     .name          = TYPE_LOONGSON_IPI,
357b4a12dfcSJiaxun Yang     .parent        = TYPE_SYS_BUS_DEVICE,
358b4a12dfcSJiaxun Yang     .instance_size = sizeof(LoongsonIPI),
359b4a12dfcSJiaxun Yang     .class_init    = loongson_ipi_class_init,
360b4a12dfcSJiaxun Yang     .instance_finalize = loongson_ipi_finalize,
361b4a12dfcSJiaxun Yang };
362b4a12dfcSJiaxun Yang 
363b4a12dfcSJiaxun Yang static void loongson_ipi_register_types(void)
364b4a12dfcSJiaxun Yang {
365b4a12dfcSJiaxun Yang     type_register_static(&loongson_ipi_info);
366b4a12dfcSJiaxun Yang }
367b4a12dfcSJiaxun Yang 
368b4a12dfcSJiaxun Yang type_init(loongson_ipi_register_types)
369