Skip to content

Commit 4e8798e

Browse files
mingqiangchilijinxia
authored andcommitted
hv:Replace vioapic pointer with instance in structure vm
-- rename struct vioapic --> struct acrn_vioapic -- update 'vioapic' field in 'struct arch_vm' from pointer to instance -- change vm_ioapic(vm) to inline, and move it to vm.h -- change vioapic_init to void type Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com> Reviewed-by: Anthony Xu <anthony.xu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 29dbd10 commit 4e8798e

File tree

5 files changed

+48
-60
lines changed

5 files changed

+48
-60
lines changed

hypervisor/arch/x86/guest/vm.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,8 @@ int create_vm(struct vm_description *vm_desc, struct vm **rtn_vm)
215215
/* vpic wire_mode default is INTR */
216216
vm->wire_mode = VPIC_WIRE_INTR;
217217

218-
/* Allocate full emulated vIOAPIC instance */
219-
vm->arch_vm.virt_ioapic = vioapic_init(vm);
220-
if (vm->arch_vm.virt_ioapic == NULL) {
221-
status = -ENODEV;
222-
goto err;
223-
}
218+
/* Init full emulated vIOAPIC instance */
219+
vioapic_init(vm);
224220

225221
/* Populate return VM handle */
226222
*rtn_vm = vm;
@@ -236,9 +232,8 @@ int create_vm(struct vm_description *vm_desc, struct vm **rtn_vm)
236232
return 0;
237233

238234
err:
239-
if (vm->arch_vm.virt_ioapic != NULL) {
240-
vioapic_cleanup(vm->arch_vm.virt_ioapic);
241-
}
235+
236+
vioapic_cleanup(vm_ioapic(vm));
242237

243238
if (vm->arch_vm.m2p != NULL) {
244239
free(vm->arch_vm.m2p);
@@ -284,8 +279,8 @@ int shutdown_vm(struct vm *vm)
284279

285280
ptdev_release_all_entries(vm);
286281

287-
/* cleanup and free vioapic */
288-
vioapic_cleanup(vm->arch_vm.virt_ioapic);
282+
/* cleanup vioapic */
283+
vioapic_cleanup(vm_ioapic(vm));
289284

290285
/* Destroy secure world */
291286
if (vm->sworld_control.flag.active) {
@@ -361,7 +356,7 @@ int reset_vm(struct vm *vm)
361356
vcpu->arch_vcpu.cpu_mode = CPU_MODE_REAL;
362357
}
363358

364-
vioapic_reset(vm->arch_vm.virt_ioapic);
359+
vioapic_reset(vm_ioapic(vm));
365360
destroy_secure_world(vm, false);
366361
vm->sworld_control.flag.active = 0UL;
367362

hypervisor/dm/vioapic.c

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,12 @@
3232

3333
#include <hypervisor.h>
3434

35-
#define REDIR_ENTRIES_HW 120U /* SOS align with native ioapic */
3635
#define RTBL_RO_BITS (uint32_t)(IOAPIC_RTE_REM_IRR | IOAPIC_RTE_DELIVS)
3736
#define NEED_TMR_UPDATE (IOAPIC_RTE_TRGRMOD | IOAPIC_RTE_DELMOD | IOAPIC_RTE_INTVEC)
3837

3938
#define ACRN_DBG_IOAPIC 6U
4039
#define ACRN_IOAPIC_VERSION 0x11U
4140

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-
5241
#define VIOAPIC_LOCK(vioapic) spinlock_obtain(&((vioapic)->mtx))
5342
#define VIOAPIC_UNLOCK(vioapic) spinlock_release(&((vioapic)->mtx))
5443

@@ -61,17 +50,11 @@ static inline const char *pinstate_str(bool asserted)
6150
return (asserted) ? "asserted" : "deasserted";
6251
}
6352

64-
static struct vioapic *
65-
vm_ioapic(struct vm *vm)
66-
{
67-
return (struct vioapic *)vm->arch_vm.virt_ioapic;
68-
}
69-
7053
/**
7154
* @pre pin < vioapic_pincount(vm)
7255
*/
7356
static void
74-
vioapic_send_intr(struct vioapic *vioapic, uint32_t pin)
57+
vioapic_send_intr(struct acrn_vioapic *vioapic, uint32_t pin)
7558
{
7659
uint32_t vector, dest, delmode;
7760
union ioapic_rte rte;
@@ -107,7 +90,7 @@ vioapic_send_intr(struct vioapic *vioapic, uint32_t pin)
10790
* @pre pin < vioapic_pincount(vm)
10891
*/
10992
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)
11194
{
11295
int oldcnt, newcnt;
11396
bool needintr;
@@ -152,7 +135,7 @@ enum irqstate {
152135
static void
153136
vioapic_set_irqstate(struct vm *vm, uint32_t irq, enum irqstate irqstate)
154137
{
155-
struct vioapic *vioapic;
138+
struct acrn_vioapic *vioapic;
156139
uint32_t pin = irq;
157140

158141
vioapic = vm_ioapic(vm);
@@ -199,7 +182,7 @@ vioapic_pulse_irq(struct vm *vm, uint32_t irq)
199182
void
200183
vioapic_update_tmr(struct vcpu *vcpu)
201184
{
202-
struct vioapic *vioapic;
185+
struct acrn_vioapic *vioapic;
203186
struct acrn_vlapic *vlapic;
204187
union ioapic_rte rte;
205188
uint32_t vector, delmode;
@@ -231,7 +214,7 @@ vioapic_update_tmr(struct vcpu *vcpu)
231214
}
232215

233216
static uint32_t
234-
vioapic_indirect_read(struct vioapic *vioapic, uint32_t addr)
217+
vioapic_indirect_read(struct acrn_vioapic *vioapic, uint32_t addr)
235218
{
236219
uint32_t regnum;
237220
uint32_t pin, pincount = vioapic_pincount(vioapic->vm);
@@ -275,7 +258,8 @@ vioapic_indirect_read(struct vioapic *vioapic, uint32_t addr)
275258
* VIOAPIC_UNLOCK(vioapic) by caller.
276259
*/
277260
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)
279263
{
280264
union ioapic_rte last, new;
281265
uint64_t changed;
@@ -405,7 +389,7 @@ vioapic_indirect_write(struct vioapic *vioapic, uint32_t addr, uint32_t data)
405389
}
406390

407391
static void
408-
vioapic_mmio_rw(struct vioapic *vioapic, uint64_t gpa,
392+
vioapic_mmio_rw(struct acrn_vioapic *vioapic, uint64_t gpa,
409393
uint32_t *data, bool do_read)
410394
{
411395
uint32_t offset;
@@ -447,7 +431,7 @@ vioapic_mmio_rw(struct vioapic *vioapic, uint64_t gpa,
447431
void
448432
vioapic_process_eoi(struct vm *vm, uint32_t vector)
449433
{
450-
struct vioapic *vioapic;
434+
struct acrn_vioapic *vioapic;
451435
uint32_t pin, pincount = vioapic_pincount(vm);
452436
union ioapic_rte rte;
453437

@@ -493,7 +477,7 @@ vioapic_process_eoi(struct vm *vm, uint32_t vector)
493477
}
494478

495479
void
496-
vioapic_reset(struct vioapic *vioapic)
480+
vioapic_reset(struct acrn_vioapic *vioapic)
497481
{
498482
uint32_t pin, pincount;
499483

@@ -506,35 +490,27 @@ vioapic_reset(struct vioapic *vioapic)
506490
vioapic->ioregsel = 0U;
507491
}
508492

509-
struct vioapic *
493+
void
510494
vioapic_init(struct vm *vm)
511495
{
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));
516498

517-
vioapic->vm = vm;
518-
spinlock_init(&vioapic->mtx);
519-
520-
vioapic_reset(vioapic);
499+
vioapic_reset(vm_ioapic(vm));
521500

522501
register_mmio_emulation_handler(vm,
523502
vioapic_mmio_access_handler,
524503
(uint64_t)VIOAPIC_BASE,
525504
(uint64_t)VIOAPIC_BASE + VIOAPIC_SIZE,
526505
NULL);
527-
528-
return vioapic;
529506
}
530507

531508
void
532-
vioapic_cleanup(struct vioapic *vioapic)
509+
vioapic_cleanup(struct acrn_vioapic *vioapic)
533510
{
534511
unregister_mmio_emulation_handler(vioapic->vm,
535512
(uint64_t)VIOAPIC_BASE,
536513
(uint64_t)VIOAPIC_BASE + VIOAPIC_SIZE);
537-
free(vioapic);
538514
}
539515

540516
uint32_t
@@ -551,7 +527,7 @@ int vioapic_mmio_access_handler(struct vcpu *vcpu, struct io_request *io_req,
551527
__unused void *handler_private_data)
552528
{
553529
struct vm *vm = vcpu->vm;
554-
struct vioapic *vioapic;
530+
struct acrn_vioapic *vioapic;
555531
struct mmio_request *mmio = &io_req->reqs.mmio;
556532
uint64_t gpa = mmio->address;
557533
int ret = 0;
@@ -580,12 +556,12 @@ int vioapic_mmio_access_handler(struct vcpu *vcpu, struct io_request *io_req,
580556
}
581557

582558
/**
583-
* @pre vm->arch_vm.virt_ioapic != NULL
559+
* @pre vm->arch_vm.vioapic != NULL
584560
* @pre rte != NULL
585561
*/
586562
void vioapic_get_rte(struct vm *vm, uint32_t pin, union ioapic_rte *rte)
587563
{
588-
struct vioapic *vioapic;
564+
struct acrn_vioapic *vioapic;
589565

590566
vioapic = vm_ioapic(vm);
591567
*rte = vioapic->rtbl[pin];

hypervisor/include/arch/x86/guest/vioapic.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,25 @@
3232
#define _VIOAPIC_H_
3333

3434
#include <apicreg.h>
35-
#include <vm.h>
3635

3736
#define VIOAPIC_BASE 0xFEC00000UL
3837
#define VIOAPIC_SIZE 4096UL
3938

40-
struct vioapic *vioapic_init(struct vm *vm);
41-
void vioapic_cleanup(struct vioapic *vioapic);
42-
void vioapic_reset(struct vioapic *vioapic);
39+
#define REDIR_ENTRIES_HW 120U /* SOS align with native ioapic */
40+
41+
struct acrn_vioapic {
42+
struct vm *vm;
43+
spinlock_t mtx;
44+
uint32_t id;
45+
uint32_t ioregsel;
46+
union ioapic_rte rtbl[REDIR_ENTRIES_HW];
47+
/* sum of pin asserts (+1) and deasserts (-1) */
48+
int32_t acnt[REDIR_ENTRIES_HW];
49+
};
50+
51+
void vioapic_init(struct vm *vm);
52+
void vioapic_cleanup(struct acrn_vioapic *vioapic);
53+
void vioapic_reset(struct acrn_vioapic *vioapic);
4354

4455
void vioapic_assert_irq(struct vm *vm, uint32_t irq);
4556
void vioapic_deassert_irq(struct vm *vm, uint32_t irq);

hypervisor/include/arch/x86/guest/vm.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ struct vm_arch {
9898
void *tmp_pg_array; /* Page array for tmp guest paging struct */
9999
void *iobitmap[2];/* IO bitmap page array base address for this VM */
100100
void *msr_bitmap; /* MSR bitmap page base address for this VM */
101-
void *virt_ioapic; /* Virtual IOAPIC base address */
101+
struct acrn_vioapic vioapic; /* Virtual IOAPIC base address */
102102
struct acrn_vpic vpic; /* Virtual PIC */
103103
/**
104104
* A link to the IO handler of this VM.
@@ -255,6 +255,12 @@ vm_pic(struct vm *vm)
255255
return (struct acrn_vpic *)&(vm->arch_vm.vpic);
256256
}
257257

258+
static inline struct acrn_vioapic *
259+
vm_ioapic(struct vm *vm)
260+
{
261+
return (struct acrn_vioapic *)&(vm->arch_vm.vioapic);
262+
}
263+
258264
int shutdown_vm(struct vm *vm);
259265
void pause_vm(struct vm *vm);
260266
void resume_vm(struct vm *vm);

hypervisor/include/arch/x86/hv_arch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <host_pm.h>
2424
#include <vpic.h>
2525
#include <vuart.h>
26+
#include <vioapic.h>
2627
#include <vm.h>
2728
#include <cpuid.h>
2829
#include <mmu.h>
@@ -35,7 +36,6 @@
3536
#include <vtd.h>
3637

3738
#include <vlapic.h>
38-
#include <vioapic.h>
3939
#include <guest.h>
4040
#include <vmexit.h>
4141
#include <cpufeatures.h>

0 commit comments

Comments
 (0)