10
10
#include "qemu/log.h"
11
11
#include "qapi/error.h"
12
12
#include "hw/irq.h"
13
- #include "hw/sysbus.h"
14
13
#include "hw/loongarch/virt.h"
15
- #include "hw/qdev-properties.h"
16
14
#include "exec/address-spaces.h"
17
15
#include "hw/intc/loongarch_extioi.h"
18
- #include "migration/vmstate.h"
19
16
#include "trace.h"
20
17
21
18
22
- static void extioi_update_irq (LoongArchExtIOI * s , int irq , int level )
19
+ static void extioi_update_irq (LoongArchExtIOICommonState * s , int irq , int level )
23
20
{
24
21
int ipnum , cpu , found , irq_index , irq_mask ;
25
22
@@ -54,7 +51,7 @@ static void extioi_update_irq(LoongArchExtIOI *s, int irq, int level)
54
51
55
52
static void extioi_setirq (void * opaque , int irq , int level )
56
53
{
57
- LoongArchExtIOI * s = LOONGARCH_EXTIOI (opaque );
54
+ LoongArchExtIOICommonState * s = LOONGARCH_EXTIOI_COMMON (opaque );
58
55
trace_loongarch_extioi_setirq (irq , level );
59
56
if (level ) {
60
57
set_bit32 (irq , s -> isr );
@@ -67,7 +64,7 @@ static void extioi_setirq(void *opaque, int irq, int level)
67
64
static MemTxResult extioi_readw (void * opaque , hwaddr addr , uint64_t * data ,
68
65
unsigned size , MemTxAttrs attrs )
69
66
{
70
- LoongArchExtIOI * s = LOONGARCH_EXTIOI (opaque );
67
+ LoongArchExtIOICommonState * s = LOONGARCH_EXTIOI_COMMON (opaque );
71
68
unsigned long offset = addr & 0xffff ;
72
69
uint32_t index , cpu ;
73
70
@@ -106,7 +103,7 @@ static MemTxResult extioi_readw(void *opaque, hwaddr addr, uint64_t *data,
106
103
return MEMTX_OK ;
107
104
}
108
105
109
- static inline void extioi_enable_irq (LoongArchExtIOI * s , int index ,\
106
+ static inline void extioi_enable_irq (LoongArchExtIOICommonState * s , int index ,\
110
107
uint32_t mask , int level )
111
108
{
112
109
uint32_t val ;
@@ -125,8 +122,8 @@ static inline void extioi_enable_irq(LoongArchExtIOI *s, int index,\
125
122
}
126
123
}
127
124
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 )
130
127
{
131
128
int i , cpu ;
132
129
@@ -162,8 +159,8 @@ static inline void extioi_update_sw_coremap(LoongArchExtIOI *s, int irq,
162
159
}
163
160
}
164
161
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 )
167
164
{
168
165
int i ;
169
166
uint8_t ipnum ;
@@ -186,7 +183,7 @@ static MemTxResult extioi_writew(void *opaque, hwaddr addr,
186
183
uint64_t val , unsigned size ,
187
184
MemTxAttrs attrs )
188
185
{
189
- LoongArchExtIOI * s = LOONGARCH_EXTIOI (opaque );
186
+ LoongArchExtIOICommonState * s = LOONGARCH_EXTIOI_COMMON (opaque );
190
187
int cpu , index , old_data , irq ;
191
188
uint32_t offset ;
192
189
@@ -266,7 +263,7 @@ static const MemoryRegionOps extioi_ops = {
266
263
static MemTxResult extioi_virt_readw (void * opaque , hwaddr addr , uint64_t * data ,
267
264
unsigned size , MemTxAttrs attrs )
268
265
{
269
- LoongArchExtIOI * s = LOONGARCH_EXTIOI (opaque );
266
+ LoongArchExtIOICommonState * s = LOONGARCH_EXTIOI_COMMON (opaque );
270
267
271
268
switch (addr ) {
272
269
case EXTIOI_VIRT_FEATURES :
@@ -286,7 +283,7 @@ static MemTxResult extioi_virt_writew(void *opaque, hwaddr addr,
286
283
uint64_t val , unsigned size ,
287
284
MemTxAttrs attrs )
288
285
{
289
- LoongArchExtIOI * s = LOONGARCH_EXTIOI (opaque );
286
+ LoongArchExtIOICommonState * s = LOONGARCH_EXTIOI_COMMON (opaque );
290
287
291
288
switch (addr ) {
292
289
case EXTIOI_VIRT_FEATURES :
@@ -320,12 +317,15 @@ static const MemoryRegionOps extioi_virt_ops = {
320
317
321
318
static void loongarch_extioi_realize (DeviceState * dev , Error * * errp )
322
319
{
323
- LoongArchExtIOI * s = LOONGARCH_EXTIOI (dev );
320
+ LoongArchExtIOICommonState * s = LOONGARCH_EXTIOI_COMMON (dev );
321
+ LoongArchExtIOIClass * lec = LOONGARCH_EXTIOI_GET_CLASS (dev );
324
322
SysBusDevice * sbd = SYS_BUS_DEVICE (dev );
323
+ Error * local_err = NULL ;
325
324
int i , pin ;
326
325
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 );
329
329
return ;
330
330
}
331
331
@@ -360,23 +360,23 @@ static void loongarch_extioi_realize(DeviceState *dev, Error **errp)
360
360
}
361
361
}
362
362
363
- static void loongarch_extioi_finalize ( Object * obj )
363
+ static void loongarch_extioi_unrealize ( DeviceState * dev )
364
364
{
365
- LoongArchExtIOI * s = LOONGARCH_EXTIOI ( obj );
365
+ LoongArchExtIOICommonState * s = LOONGARCH_EXTIOI_COMMON ( dev );
366
366
367
367
g_free (s -> cpu );
368
368
}
369
369
370
370
static void loongarch_extioi_reset (DeviceState * d )
371
371
{
372
- LoongArchExtIOI * s = LOONGARCH_EXTIOI (d );
372
+ LoongArchExtIOICommonState * s = LOONGARCH_EXTIOI_COMMON (d );
373
373
374
374
s -> status = 0 ;
375
375
}
376
376
377
377
static int vmstate_extioi_post_load (void * opaque , int version_id )
378
378
{
379
- LoongArchExtIOI * s = LOONGARCH_EXTIOI (opaque );
379
+ LoongArchExtIOICommonState * s = LOONGARCH_EXTIOI_COMMON (opaque );
380
380
int i , start_irq ;
381
381
382
382
for (i = 0 ; i < (EXTIOI_IRQS / 4 ); i ++ ) {
@@ -391,66 +391,28 @@ static int vmstate_extioi_post_load(void *opaque, int version_id)
391
391
return 0 ;
392
392
}
393
393
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
-
433
394
static void loongarch_extioi_class_init (ObjectClass * klass , void * data )
434
395
{
435
396
DeviceClass * dc = DEVICE_CLASS (klass );
397
+ LoongArchExtIOIClass * lec = LOONGARCH_EXTIOI_CLASS (klass );
398
+ LoongArchExtIOICommonClass * lecc = LOONGARCH_EXTIOI_COMMON_CLASS (klass );
436
399
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 );
438
404
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 ;
441
406
}
442
407
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
+ }
449
416
};
450
417
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 )
0 commit comments