Skip to content

Commit 9863d46

Browse files
committed
Merge tag 'pull-loongarch-20241219' of https://gitlab.com/bibo-mao/qemu into staging
loongarch queue # -----BEGIN PGP SIGNATURE----- # # iHUEABYKAB0WIQQNhkKjomWfgLCz0aQfewwSUazn0QUCZ2PKBQAKCRAfewwSUazn # 0QAZAQCxbLnvzOb9TPORlg5w0n/xFaKCL7dJbJE4WjlM7dhLkAEA5G8JVoP5Ju2B # mcK7wbymyXNX1ocsukL/JM2JavHS+AI= # =JoSk # -----END PGP SIGNATURE----- # gpg: Signature made Thu 19 Dec 2024 02:23:49 EST # gpg: using EDDSA key 0D8642A3A2659F80B0B3D1A41F7B0C1251ACE7D1 # gpg: Good signature from "bibo mao <[email protected]>" [unknown] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: 7044 3A00 19C0 E97A 31C7 13C4 8E86 8FB7 A176 9D4C # Subkey fingerprint: 0D86 42A3 A265 9F80 B0B3 D1A4 1F7B 0C12 51AC E7D1 * tag 'pull-loongarch-20241219' of https://gitlab.com/bibo-mao/qemu: hw/intc/loongarch_extioi: Code cleanup about loongarch_extioi hw/intc/loongarch_extioi: Add pre_save interface hw/intc/loongarch_extioi: Inherit from loongarch_extioi_common hw/intc/loongarch_extioi: Add common file loongarch_extioi_common hw/intc/loongarch_extioi: Add unrealize interface hw/intc/loongarch_extioi: Add common realize interface hw/intc/loongarch_extioi: Rename LoongArchExtIOI with LoongArchExtIOICommonState include: Rename LoongArchExtIOI with LoongArchExtIOICommonState include: Move struct LoongArchExtIOI to header file loongarch_extioi_common include: Add loongarch_extioi_common header file hw/intc/loongarch_pch: Code cleanup about loongarch_pch_pic hw/intc/loongarch_pch: Add pre_save and post_load interfaces hw/intc/loongarch_pch: Inherit from loongarch_pic_common hw/intc/loongarch_pch: Move some functions to file loongarch_pic_common hw/intc/loongarch_pch: Rename LoongArchPCHPIC with LoongArchPICCommonState hw/intc/loongarch_pch: Merge instance_init() into realize() include: Move struct LoongArchPCHPIC to loongarch_pic_common header file include: Add loongarch_pic_common header file Signed-off-by: Stefan Hajnoczi <[email protected]>
2 parents 3e9793a + 6f6006a commit 9863d46

File tree

10 files changed

+490
-278
lines changed

10 files changed

+490
-278
lines changed

hw/intc/loongarch_extioi.c

Lines changed: 37 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@
1010
#include "qemu/log.h"
1111
#include "qapi/error.h"
1212
#include "hw/irq.h"
13-
#include "hw/sysbus.h"
1413
#include "hw/loongarch/virt.h"
15-
#include "hw/qdev-properties.h"
1614
#include "exec/address-spaces.h"
1715
#include "hw/intc/loongarch_extioi.h"
18-
#include "migration/vmstate.h"
1916
#include "trace.h"
2017

2118

22-
static void extioi_update_irq(LoongArchExtIOI *s, int irq, int level)
19+
static void extioi_update_irq(LoongArchExtIOICommonState *s, int irq, int level)
2320
{
2421
int ipnum, cpu, found, irq_index, irq_mask;
2522

@@ -54,7 +51,7 @@ static void extioi_update_irq(LoongArchExtIOI *s, int irq, int level)
5451

5552
static void extioi_setirq(void *opaque, int irq, int level)
5653
{
57-
LoongArchExtIOI *s = LOONGARCH_EXTIOI(opaque);
54+
LoongArchExtIOICommonState *s = LOONGARCH_EXTIOI_COMMON(opaque);
5855
trace_loongarch_extioi_setirq(irq, level);
5956
if (level) {
6057
set_bit32(irq, s->isr);
@@ -67,7 +64,7 @@ static void extioi_setirq(void *opaque, int irq, int level)
6764
static MemTxResult extioi_readw(void *opaque, hwaddr addr, uint64_t *data,
6865
unsigned size, MemTxAttrs attrs)
6966
{
70-
LoongArchExtIOI *s = LOONGARCH_EXTIOI(opaque);
67+
LoongArchExtIOICommonState *s = LOONGARCH_EXTIOI_COMMON(opaque);
7168
unsigned long offset = addr & 0xffff;
7269
uint32_t index, cpu;
7370

@@ -106,7 +103,7 @@ static MemTxResult extioi_readw(void *opaque, hwaddr addr, uint64_t *data,
106103
return MEMTX_OK;
107104
}
108105

109-
static inline void extioi_enable_irq(LoongArchExtIOI *s, int index,\
106+
static inline void extioi_enable_irq(LoongArchExtIOICommonState *s, int index,\
110107
uint32_t mask, int level)
111108
{
112109
uint32_t val;
@@ -125,8 +122,8 @@ static inline void extioi_enable_irq(LoongArchExtIOI *s, int index,\
125122
}
126123
}
127124

128-
static inline void extioi_update_sw_coremap(LoongArchExtIOI *s, int irq,
129-
uint64_t val, bool notify)
125+
static inline void extioi_update_sw_coremap(LoongArchExtIOICommonState *s,
126+
int irq, uint64_t val, bool notify)
130127
{
131128
int i, cpu;
132129

@@ -162,8 +159,8 @@ static inline void extioi_update_sw_coremap(LoongArchExtIOI *s, int irq,
162159
}
163160
}
164161

165-
static inline void extioi_update_sw_ipmap(LoongArchExtIOI *s, int index,
166-
uint64_t val)
162+
static inline void extioi_update_sw_ipmap(LoongArchExtIOICommonState *s,
163+
int index, uint64_t val)
167164
{
168165
int i;
169166
uint8_t ipnum;
@@ -186,7 +183,7 @@ static MemTxResult extioi_writew(void *opaque, hwaddr addr,
186183
uint64_t val, unsigned size,
187184
MemTxAttrs attrs)
188185
{
189-
LoongArchExtIOI *s = LOONGARCH_EXTIOI(opaque);
186+
LoongArchExtIOICommonState *s = LOONGARCH_EXTIOI_COMMON(opaque);
190187
int cpu, index, old_data, irq;
191188
uint32_t offset;
192189

@@ -266,7 +263,7 @@ static const MemoryRegionOps extioi_ops = {
266263
static MemTxResult extioi_virt_readw(void *opaque, hwaddr addr, uint64_t *data,
267264
unsigned size, MemTxAttrs attrs)
268265
{
269-
LoongArchExtIOI *s = LOONGARCH_EXTIOI(opaque);
266+
LoongArchExtIOICommonState *s = LOONGARCH_EXTIOI_COMMON(opaque);
270267

271268
switch (addr) {
272269
case EXTIOI_VIRT_FEATURES:
@@ -286,7 +283,7 @@ static MemTxResult extioi_virt_writew(void *opaque, hwaddr addr,
286283
uint64_t val, unsigned size,
287284
MemTxAttrs attrs)
288285
{
289-
LoongArchExtIOI *s = LOONGARCH_EXTIOI(opaque);
286+
LoongArchExtIOICommonState *s = LOONGARCH_EXTIOI_COMMON(opaque);
290287

291288
switch (addr) {
292289
case EXTIOI_VIRT_FEATURES:
@@ -320,12 +317,15 @@ static const MemoryRegionOps extioi_virt_ops = {
320317

321318
static void loongarch_extioi_realize(DeviceState *dev, Error **errp)
322319
{
323-
LoongArchExtIOI *s = LOONGARCH_EXTIOI(dev);
320+
LoongArchExtIOICommonState *s = LOONGARCH_EXTIOI_COMMON(dev);
321+
LoongArchExtIOIClass *lec = LOONGARCH_EXTIOI_GET_CLASS(dev);
324322
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
323+
Error *local_err = NULL;
325324
int i, pin;
326325

327-
if (s->num_cpu == 0) {
328-
error_setg(errp, "num-cpu must be at least 1");
326+
lec->parent_realize(dev, &local_err);
327+
if (local_err) {
328+
error_propagate(errp, local_err);
329329
return;
330330
}
331331

@@ -360,23 +360,23 @@ static void loongarch_extioi_realize(DeviceState *dev, Error **errp)
360360
}
361361
}
362362

363-
static void loongarch_extioi_finalize(Object *obj)
363+
static void loongarch_extioi_unrealize(DeviceState *dev)
364364
{
365-
LoongArchExtIOI *s = LOONGARCH_EXTIOI(obj);
365+
LoongArchExtIOICommonState *s = LOONGARCH_EXTIOI_COMMON(dev);
366366

367367
g_free(s->cpu);
368368
}
369369

370370
static void loongarch_extioi_reset(DeviceState *d)
371371
{
372-
LoongArchExtIOI *s = LOONGARCH_EXTIOI(d);
372+
LoongArchExtIOICommonState *s = LOONGARCH_EXTIOI_COMMON(d);
373373

374374
s->status = 0;
375375
}
376376

377377
static int vmstate_extioi_post_load(void *opaque, int version_id)
378378
{
379-
LoongArchExtIOI *s = LOONGARCH_EXTIOI(opaque);
379+
LoongArchExtIOICommonState *s = LOONGARCH_EXTIOI_COMMON(opaque);
380380
int i, start_irq;
381381

382382
for (i = 0; i < (EXTIOI_IRQS / 4); i++) {
@@ -391,66 +391,28 @@ static int vmstate_extioi_post_load(void *opaque, int version_id)
391391
return 0;
392392
}
393393

394-
static const VMStateDescription vmstate_extioi_core = {
395-
.name = "extioi-core",
396-
.version_id = 1,
397-
.minimum_version_id = 1,
398-
.fields = (const VMStateField[]) {
399-
VMSTATE_UINT32_ARRAY(coreisr, ExtIOICore, EXTIOI_IRQS_GROUP_COUNT),
400-
VMSTATE_END_OF_LIST()
401-
}
402-
};
403-
404-
static const VMStateDescription vmstate_loongarch_extioi = {
405-
.name = TYPE_LOONGARCH_EXTIOI,
406-
.version_id = 3,
407-
.minimum_version_id = 3,
408-
.post_load = vmstate_extioi_post_load,
409-
.fields = (const VMStateField[]) {
410-
VMSTATE_UINT32_ARRAY(bounce, LoongArchExtIOI, EXTIOI_IRQS_GROUP_COUNT),
411-
VMSTATE_UINT32_ARRAY(nodetype, LoongArchExtIOI,
412-
EXTIOI_IRQS_NODETYPE_COUNT / 2),
413-
VMSTATE_UINT32_ARRAY(enable, LoongArchExtIOI, EXTIOI_IRQS / 32),
414-
VMSTATE_UINT32_ARRAY(isr, LoongArchExtIOI, EXTIOI_IRQS / 32),
415-
VMSTATE_UINT32_ARRAY(ipmap, LoongArchExtIOI, EXTIOI_IRQS_IPMAP_SIZE / 4),
416-
VMSTATE_UINT32_ARRAY(coremap, LoongArchExtIOI, EXTIOI_IRQS / 4),
417-
418-
VMSTATE_STRUCT_VARRAY_POINTER_UINT32(cpu, LoongArchExtIOI, num_cpu,
419-
vmstate_extioi_core, ExtIOICore),
420-
VMSTATE_UINT32(features, LoongArchExtIOI),
421-
VMSTATE_UINT32(status, LoongArchExtIOI),
422-
VMSTATE_END_OF_LIST()
423-
}
424-
};
425-
426-
static const Property extioi_properties[] = {
427-
DEFINE_PROP_UINT32("num-cpu", LoongArchExtIOI, num_cpu, 1),
428-
DEFINE_PROP_BIT("has-virtualization-extension", LoongArchExtIOI, features,
429-
EXTIOI_HAS_VIRT_EXTENSION, 0),
430-
DEFINE_PROP_END_OF_LIST(),
431-
};
432-
433394
static void loongarch_extioi_class_init(ObjectClass *klass, void *data)
434395
{
435396
DeviceClass *dc = DEVICE_CLASS(klass);
397+
LoongArchExtIOIClass *lec = LOONGARCH_EXTIOI_CLASS(klass);
398+
LoongArchExtIOICommonClass *lecc = LOONGARCH_EXTIOI_COMMON_CLASS(klass);
436399

437-
dc->realize = loongarch_extioi_realize;
400+
device_class_set_parent_realize(dc, loongarch_extioi_realize,
401+
&lec->parent_realize);
402+
device_class_set_parent_unrealize(dc, loongarch_extioi_unrealize,
403+
&lec->parent_unrealize);
438404
device_class_set_legacy_reset(dc, loongarch_extioi_reset);
439-
device_class_set_props(dc, extioi_properties);
440-
dc->vmsd = &vmstate_loongarch_extioi;
405+
lecc->post_load = vmstate_extioi_post_load;
441406
}
442407

443-
static const TypeInfo loongarch_extioi_info = {
444-
.name = TYPE_LOONGARCH_EXTIOI,
445-
.parent = TYPE_SYS_BUS_DEVICE,
446-
.instance_size = sizeof(struct LoongArchExtIOI),
447-
.class_init = loongarch_extioi_class_init,
448-
.instance_finalize = loongarch_extioi_finalize,
408+
static const TypeInfo loongarch_extioi_types[] = {
409+
{
410+
.name = TYPE_LOONGARCH_EXTIOI,
411+
.parent = TYPE_LOONGARCH_EXTIOI_COMMON,
412+
.instance_size = sizeof(LoongArchExtIOIState),
413+
.class_size = sizeof(LoongArchExtIOIClass),
414+
.class_init = loongarch_extioi_class_init,
415+
}
449416
};
450417

451-
static void loongarch_extioi_register_types(void)
452-
{
453-
type_register_static(&loongarch_extioi_info);
454-
}
455-
456-
type_init(loongarch_extioi_register_types)
418+
DEFINE_TYPES(loongarch_extioi_types)

hw/intc/loongarch_extioi_common.c

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/*
3+
* Loongson extioi interrupt controller emulation
4+
* Copyright (C) 2024 Loongson Technology Corporation Limited
5+
*/
6+
#include "qemu/osdep.h"
7+
#include "qemu/module.h"
8+
#include "qapi/error.h"
9+
#include "hw/qdev-properties.h"
10+
#include "hw/intc/loongarch_extioi_common.h"
11+
#include "migration/vmstate.h"
12+
13+
static void loongarch_extioi_common_realize(DeviceState *dev, Error **errp)
14+
{
15+
LoongArchExtIOICommonState *s = (LoongArchExtIOICommonState *)dev;
16+
17+
if (s->num_cpu == 0) {
18+
error_setg(errp, "num-cpu must be at least 1");
19+
return;
20+
}
21+
}
22+
23+
static int loongarch_extioi_common_pre_save(void *opaque)
24+
{
25+
LoongArchExtIOICommonState *s = (LoongArchExtIOICommonState *)opaque;
26+
LoongArchExtIOICommonClass *lecc = LOONGARCH_EXTIOI_COMMON_GET_CLASS(s);
27+
28+
if (lecc->pre_save) {
29+
return lecc->pre_save(s);
30+
}
31+
32+
return 0;
33+
}
34+
35+
static int loongarch_extioi_common_post_load(void *opaque, int version_id)
36+
{
37+
LoongArchExtIOICommonState *s = (LoongArchExtIOICommonState *)opaque;
38+
LoongArchExtIOICommonClass *lecc = LOONGARCH_EXTIOI_COMMON_GET_CLASS(s);
39+
40+
if (lecc->post_load) {
41+
return lecc->post_load(s, version_id);
42+
}
43+
44+
return 0;
45+
}
46+
47+
static const VMStateDescription vmstate_extioi_core = {
48+
.name = "extioi-core",
49+
.version_id = 1,
50+
.minimum_version_id = 1,
51+
.fields = (const VMStateField[]) {
52+
VMSTATE_UINT32_ARRAY(coreisr, ExtIOICore, EXTIOI_IRQS_GROUP_COUNT),
53+
VMSTATE_END_OF_LIST()
54+
}
55+
};
56+
57+
static const VMStateDescription vmstate_loongarch_extioi = {
58+
.name = "loongarch.extioi",
59+
.version_id = 3,
60+
.minimum_version_id = 3,
61+
.pre_save = loongarch_extioi_common_pre_save,
62+
.post_load = loongarch_extioi_common_post_load,
63+
.fields = (const VMStateField[]) {
64+
VMSTATE_UINT32_ARRAY(bounce, LoongArchExtIOICommonState,
65+
EXTIOI_IRQS_GROUP_COUNT),
66+
VMSTATE_UINT32_ARRAY(nodetype, LoongArchExtIOICommonState,
67+
EXTIOI_IRQS_NODETYPE_COUNT / 2),
68+
VMSTATE_UINT32_ARRAY(enable, LoongArchExtIOICommonState,
69+
EXTIOI_IRQS / 32),
70+
VMSTATE_UINT32_ARRAY(isr, LoongArchExtIOICommonState,
71+
EXTIOI_IRQS / 32),
72+
VMSTATE_UINT32_ARRAY(ipmap, LoongArchExtIOICommonState,
73+
EXTIOI_IRQS_IPMAP_SIZE / 4),
74+
VMSTATE_UINT32_ARRAY(coremap, LoongArchExtIOICommonState,
75+
EXTIOI_IRQS / 4),
76+
VMSTATE_STRUCT_VARRAY_POINTER_UINT32(cpu, LoongArchExtIOICommonState,
77+
num_cpu, vmstate_extioi_core, ExtIOICore),
78+
VMSTATE_UINT32(features, LoongArchExtIOICommonState),
79+
VMSTATE_UINT32(status, LoongArchExtIOICommonState),
80+
VMSTATE_END_OF_LIST()
81+
}
82+
};
83+
84+
static const Property extioi_properties[] = {
85+
DEFINE_PROP_UINT32("num-cpu", LoongArchExtIOICommonState, num_cpu, 1),
86+
DEFINE_PROP_BIT("has-virtualization-extension", LoongArchExtIOICommonState,
87+
features, EXTIOI_HAS_VIRT_EXTENSION, 0),
88+
DEFINE_PROP_END_OF_LIST(),
89+
};
90+
91+
static void loongarch_extioi_common_class_init(ObjectClass *klass, void *data)
92+
{
93+
DeviceClass *dc = DEVICE_CLASS(klass);
94+
LoongArchExtIOICommonClass *lecc = LOONGARCH_EXTIOI_COMMON_CLASS(klass);
95+
96+
device_class_set_parent_realize(dc, loongarch_extioi_common_realize,
97+
&lecc->parent_realize);
98+
device_class_set_props(dc, extioi_properties);
99+
dc->vmsd = &vmstate_loongarch_extioi;
100+
}
101+
102+
static const TypeInfo loongarch_extioi_common_types[] = {
103+
{
104+
.name = TYPE_LOONGARCH_EXTIOI_COMMON,
105+
.parent = TYPE_SYS_BUS_DEVICE,
106+
.instance_size = sizeof(LoongArchExtIOICommonState),
107+
.class_size = sizeof(LoongArchExtIOICommonClass),
108+
.class_init = loongarch_extioi_common_class_init,
109+
.abstract = true,
110+
}
111+
};
112+
113+
DEFINE_TYPES(loongarch_extioi_common_types)

0 commit comments

Comments
 (0)