Skip to content

Commit b0997e7

Browse files
Sainath Grandhiwenlingz
authored andcommitted
hv: Pass address of vioapic struct to register_mmio_emulation_handler
Changes the mmio handler data from that of the acrn_vm struct to the acrn_vioapic. Add nr_pins and base_addr to the acrn_vioapic data structure. Tracked-On: #4151 Signed-off-by: Sainath Grandhi <sainath.grandhi@intel.com> Acked-by: Eddie Dong <eddie.dong@Intel.com>
1 parent 9e21c5b commit b0997e7

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

hypervisor/dm/vioapic.c

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ vioapic_set_pinstate(struct acrn_vioapic *vioapic, uint32_t pin, uint32_t level)
9292
uint32_t old_lvl;
9393
union ioapic_rte rte;
9494

95-
if (pin < REDIR_ENTRIES_HW) {
95+
if (pin < vioapic->nr_pins) {
9696
rte = vioapic->rtbl[pin];
9797
old_lvl = (uint32_t)bitmap_test((uint16_t)(pin & 0x3FU), &vioapic->pin_state[pin >> 6U]);
9898
if (level == 0U) {
@@ -232,11 +232,9 @@ static inline bool vioapic_need_intr(const struct acrn_vioapic *vioapic, uint16_
232232
{
233233
uint32_t lvl;
234234
union ioapic_rte rte;
235-
bool ret;
235+
bool ret = false;
236236

237-
if (pin >= REDIR_ENTRIES_HW) {
238-
ret = false;
239-
} else {
237+
if (pin < vioapic->nr_pins) {
240238
rte = vioapic->rtbl[pin];
241239
lvl = (uint32_t)bitmap_test(pin & 0x3FU, &vioapic->pin_state[pin >> 6U]);
242240
ret = !!(((rte.bits.intr_polarity == IOAPIC_RTE_INTPOL_ALO) && lvl == 0U) ||
@@ -359,7 +357,7 @@ vioapic_mmio_rw(struct acrn_vioapic *vioapic, uint64_t gpa,
359357
uint32_t offset;
360358
uint64_t rflags;
361359

362-
offset = (uint32_t)(gpa - VIOAPIC_BASE);
360+
offset = (uint32_t)(gpa - vioapic->base_addr);
363361

364362
spinlock_irqsave_obtain(&(vioapic->mtx), &rflags);
365363

@@ -466,30 +464,29 @@ vioapic_init(struct acrn_vm *vm)
466464
vm->arch_vm.vioapic.vm = vm;
467465
spinlock_init(&(vm->arch_vm.vioapic.mtx));
468466

467+
vm->arch_vm.vioapic.base_addr = VIOAPIC_BASE;
468+
if (is_sos_vm(vm)) {
469+
vm->arch_vm.vioapic.nr_pins = REDIR_ENTRIES_HW;
470+
} else {
471+
vm->arch_vm.vioapic.nr_pins = VIOAPIC_RTE_NUM;
472+
}
473+
469474
vioapic_reset(vm);
470475

471476
register_mmio_emulation_handler(vm,
472477
vioapic_mmio_access_handler,
473-
(uint64_t)VIOAPIC_BASE,
474-
(uint64_t)VIOAPIC_BASE + VIOAPIC_SIZE,
475-
vm, false);
478+
(uint64_t)vm->arch_vm.vioapic.base_addr,
479+
(uint64_t)vm->arch_vm.vioapic.base_addr + VIOAPIC_SIZE,
480+
(void *)&vm->arch_vm.vioapic, false);
476481
ept_del_mr(vm, (uint64_t *)vm->arch_vm.nworld_eptp,
477-
(uint64_t)VIOAPIC_BASE, (uint64_t)VIOAPIC_SIZE);
482+
(uint64_t)vm->arch_vm.vioapic.base_addr, VIOAPIC_SIZE);
478483
vm->arch_vm.vioapic.ready = true;
479484
}
480485

481486
uint32_t
482487
vioapic_pincount(const struct acrn_vm *vm)
483488
{
484-
uint32_t ret;
485-
486-
if (is_sos_vm(vm)) {
487-
ret = REDIR_ENTRIES_HW;
488-
} else {
489-
ret = VIOAPIC_RTE_NUM;
490-
}
491-
492-
return ret;
489+
return vm->arch_vm.vioapic.nr_pins;
493490
}
494491

495492
/*
@@ -498,14 +495,11 @@ vioapic_pincount(const struct acrn_vm *vm)
498495
*/
499496
int32_t vioapic_mmio_access_handler(struct io_request *io_req, void *handler_private_data)
500497
{
501-
struct acrn_vm *vm = (struct acrn_vm *)handler_private_data;
502-
struct acrn_vioapic *vioapic;
498+
struct acrn_vioapic *vioapic = (struct acrn_vioapic *)handler_private_data;
503499
struct mmio_request *mmio = &io_req->reqs.mmio;
504500
uint64_t gpa = mmio->address;
505501
int32_t ret = 0;
506502

507-
vioapic = vm_ioapic(vm);
508-
509503
/* Note all RW to IOAPIC are 32-Bit in size */
510504
if (mmio->size == 4UL) {
511505
uint32_t data = (uint32_t)mmio->value;

hypervisor/include/dm/vioapic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
struct acrn_vioapic {
5252
struct acrn_vm *vm;
5353
spinlock_t mtx;
54+
uint32_t base_addr;
55+
uint32_t nr_pins;
5456
uint32_t id;
5557
bool ready;
5658
uint32_t ioregsel;

0 commit comments

Comments
 (0)