32
32
33
33
#include <hypervisor.h>
34
34
35
- #define REDIR_ENTRIES_HW 120U /* SOS align with native ioapic */
36
35
#define RTBL_RO_BITS (uint32_t)(IOAPIC_RTE_REM_IRR | IOAPIC_RTE_DELIVS)
37
36
#define NEED_TMR_UPDATE (IOAPIC_RTE_TRGRMOD | IOAPIC_RTE_DELMOD | IOAPIC_RTE_INTVEC)
38
37
39
38
#define ACRN_DBG_IOAPIC 6U
40
39
#define ACRN_IOAPIC_VERSION 0x11U
41
40
42
- struct vioapic {
43
- struct vm * vm ;
44
- spinlock_t mtx ;
45
- uint32_t id ;
46
- uint32_t ioregsel ;
47
- union ioapic_rte rtbl [REDIR_ENTRIES_HW ];
48
- /* sum of pin asserts (+1) and deasserts (-1) */
49
- int32_t acnt [REDIR_ENTRIES_HW ];
50
- };
51
-
52
41
#define VIOAPIC_LOCK (vioapic ) spinlock_obtain(&((vioapic)->mtx))
53
42
#define VIOAPIC_UNLOCK (vioapic ) spinlock_release(&((vioapic)->mtx))
54
43
@@ -61,17 +50,11 @@ static inline const char *pinstate_str(bool asserted)
61
50
return (asserted ) ? "asserted" : "deasserted" ;
62
51
}
63
52
64
- static struct vioapic *
65
- vm_ioapic (struct vm * vm )
66
- {
67
- return (struct vioapic * )vm -> arch_vm .virt_ioapic ;
68
- }
69
-
70
53
/**
71
54
* @pre pin < vioapic_pincount(vm)
72
55
*/
73
56
static void
74
- vioapic_send_intr (struct vioapic * vioapic , uint32_t pin )
57
+ vioapic_send_intr (struct acrn_vioapic * vioapic , uint32_t pin )
75
58
{
76
59
uint32_t vector , dest , delmode ;
77
60
union ioapic_rte rte ;
@@ -107,7 +90,7 @@ vioapic_send_intr(struct vioapic *vioapic, uint32_t pin)
107
90
* @pre pin < vioapic_pincount(vm)
108
91
*/
109
92
static void
110
- vioapic_set_pinstate (struct vioapic * vioapic , uint32_t pin , bool newstate )
93
+ vioapic_set_pinstate (struct acrn_vioapic * vioapic , uint32_t pin , bool newstate )
111
94
{
112
95
int oldcnt , newcnt ;
113
96
bool needintr ;
@@ -152,7 +135,7 @@ enum irqstate {
152
135
static void
153
136
vioapic_set_irqstate (struct vm * vm , uint32_t irq , enum irqstate irqstate )
154
137
{
155
- struct vioapic * vioapic ;
138
+ struct acrn_vioapic * vioapic ;
156
139
uint32_t pin = irq ;
157
140
158
141
vioapic = vm_ioapic (vm );
@@ -199,7 +182,7 @@ vioapic_pulse_irq(struct vm *vm, uint32_t irq)
199
182
void
200
183
vioapic_update_tmr (struct vcpu * vcpu )
201
184
{
202
- struct vioapic * vioapic ;
185
+ struct acrn_vioapic * vioapic ;
203
186
struct acrn_vlapic * vlapic ;
204
187
union ioapic_rte rte ;
205
188
uint32_t vector , delmode ;
@@ -231,7 +214,7 @@ vioapic_update_tmr(struct vcpu *vcpu)
231
214
}
232
215
233
216
static uint32_t
234
- vioapic_indirect_read (struct vioapic * vioapic , uint32_t addr )
217
+ vioapic_indirect_read (struct acrn_vioapic * vioapic , uint32_t addr )
235
218
{
236
219
uint32_t regnum ;
237
220
uint32_t pin , pincount = vioapic_pincount (vioapic -> vm );
@@ -275,7 +258,8 @@ vioapic_indirect_read(struct vioapic *vioapic, uint32_t addr)
275
258
* VIOAPIC_UNLOCK(vioapic) by caller.
276
259
*/
277
260
static void
278
- vioapic_indirect_write (struct vioapic * vioapic , uint32_t addr , uint32_t data )
261
+ vioapic_indirect_write (struct acrn_vioapic * vioapic , uint32_t addr ,
262
+ uint32_t data )
279
263
{
280
264
union ioapic_rte last , new ;
281
265
uint64_t changed ;
@@ -405,7 +389,7 @@ vioapic_indirect_write(struct vioapic *vioapic, uint32_t addr, uint32_t data)
405
389
}
406
390
407
391
static void
408
- vioapic_mmio_rw (struct vioapic * vioapic , uint64_t gpa ,
392
+ vioapic_mmio_rw (struct acrn_vioapic * vioapic , uint64_t gpa ,
409
393
uint32_t * data , bool do_read )
410
394
{
411
395
uint32_t offset ;
@@ -447,7 +431,7 @@ vioapic_mmio_rw(struct vioapic *vioapic, uint64_t gpa,
447
431
void
448
432
vioapic_process_eoi (struct vm * vm , uint32_t vector )
449
433
{
450
- struct vioapic * vioapic ;
434
+ struct acrn_vioapic * vioapic ;
451
435
uint32_t pin , pincount = vioapic_pincount (vm );
452
436
union ioapic_rte rte ;
453
437
@@ -493,7 +477,7 @@ vioapic_process_eoi(struct vm *vm, uint32_t vector)
493
477
}
494
478
495
479
void
496
- vioapic_reset (struct vioapic * vioapic )
480
+ vioapic_reset (struct acrn_vioapic * vioapic )
497
481
{
498
482
uint32_t pin , pincount ;
499
483
@@ -506,35 +490,27 @@ vioapic_reset(struct vioapic *vioapic)
506
490
vioapic -> ioregsel = 0U ;
507
491
}
508
492
509
- struct vioapic *
493
+ void
510
494
vioapic_init (struct vm * vm )
511
495
{
512
- struct vioapic * vioapic ;
513
-
514
- vioapic = calloc (1U , sizeof (struct vioapic ));
515
- ASSERT (vioapic != NULL , "" );
496
+ vm -> arch_vm .vioapic .vm = vm ;
497
+ spinlock_init (& (vm -> arch_vm .vioapic .mtx ));
516
498
517
- vioapic -> vm = vm ;
518
- spinlock_init (& vioapic -> mtx );
519
-
520
- vioapic_reset (vioapic );
499
+ vioapic_reset (vm_ioapic (vm ));
521
500
522
501
register_mmio_emulation_handler (vm ,
523
502
vioapic_mmio_access_handler ,
524
503
(uint64_t )VIOAPIC_BASE ,
525
504
(uint64_t )VIOAPIC_BASE + VIOAPIC_SIZE ,
526
505
NULL );
527
-
528
- return vioapic ;
529
506
}
530
507
531
508
void
532
- vioapic_cleanup (struct vioapic * vioapic )
509
+ vioapic_cleanup (struct acrn_vioapic * vioapic )
533
510
{
534
511
unregister_mmio_emulation_handler (vioapic -> vm ,
535
512
(uint64_t )VIOAPIC_BASE ,
536
513
(uint64_t )VIOAPIC_BASE + VIOAPIC_SIZE );
537
- free (vioapic );
538
514
}
539
515
540
516
uint32_t
@@ -551,7 +527,7 @@ int vioapic_mmio_access_handler(struct vcpu *vcpu, struct io_request *io_req,
551
527
__unused void * handler_private_data )
552
528
{
553
529
struct vm * vm = vcpu -> vm ;
554
- struct vioapic * vioapic ;
530
+ struct acrn_vioapic * vioapic ;
555
531
struct mmio_request * mmio = & io_req -> reqs .mmio ;
556
532
uint64_t gpa = mmio -> address ;
557
533
int ret = 0 ;
@@ -580,12 +556,12 @@ int vioapic_mmio_access_handler(struct vcpu *vcpu, struct io_request *io_req,
580
556
}
581
557
582
558
/**
583
- * @pre vm->arch_vm.virt_ioapic != NULL
559
+ * @pre vm->arch_vm.vioapic != NULL
584
560
* @pre rte != NULL
585
561
*/
586
562
void vioapic_get_rte (struct vm * vm , uint32_t pin , union ioapic_rte * rte )
587
563
{
588
- struct vioapic * vioapic ;
564
+ struct acrn_vioapic * vioapic ;
589
565
590
566
vioapic = vm_ioapic (vm );
591
567
* rte = vioapic -> rtbl [pin ];
0 commit comments