Skip to content

Commit 0b54946

Browse files
mingqiangchilijinxia
authored andcommitted
hv:Replace vpic pointer with instance in structure vm
-- update 'vpic' field in 'struct vm' from pointer to instance, and move it from 'struct vm' to 'struct arch_vm' -- replace MACRO with inline function for vm_pic, and move it to vm.h -- changed vpic_init to void type -- removed vpic_cleanup -- move struct acrn_vpic/i8259_reg_state from vpic.c to vpic.h 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 de53964 commit 0b54946

File tree

7 files changed

+48
-69
lines changed

7 files changed

+48
-69
lines changed

hypervisor/arch/x86/guest/vm.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ int create_vm(struct vm_description *vm_desc, struct vm **rtn_vm)
201201
/* Create virtual uart */
202202
vm->vuart = vuart_init(vm);
203203
}
204-
vm->vpic = vpic_init(vm);
204+
vpic_init(vm);
205205

206206
#ifdef CONFIG_PARTITION_MODE
207207
/* Create virtual uart */
@@ -240,10 +240,6 @@ int create_vm(struct vm_description *vm_desc, struct vm **rtn_vm)
240240
vioapic_cleanup(vm->arch_vm.virt_ioapic);
241241
}
242242

243-
if (vm->vpic != NULL) {
244-
vpic_cleanup(vm);
245-
}
246-
247243
if (vm->arch_vm.m2p != NULL) {
248244
free(vm->arch_vm.m2p);
249245
}
@@ -314,9 +310,6 @@ int shutdown_vm(struct vm *vm)
314310
free_vm_id(vm);
315311
#endif
316312

317-
if (vm->vpic != NULL) {
318-
vpic_cleanup(vm);
319-
}
320313

321314
#ifdef CONFIG_PARTITION_MODE
322315
vpci_cleanup(vm);

hypervisor/arch/x86/virq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static int vcpu_do_pending_extint(struct vcpu *vcpu)
156156
/* check if there is valid interrupt from vPIC, if yes just inject it */
157157
/* PIC only connect with primary CPU */
158158
primary = get_primary_vcpu(vm);
159-
if ((vm->vpic != NULL) && vcpu == primary) {
159+
if (vcpu == primary) {
160160

161161
vpic_pending_intr(vcpu->vm, &vector);
162162
if (vector <= NR_MAX_VECTOR) {

hypervisor/debug/vuart.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,11 @@ static void vuart_toggle_intr(struct vuart *vu)
125125
intr_reason = vuart_intr_reason(vu);
126126

127127
if (intr_reason != IIR_NOPEND) {
128-
if (vu->vm->vpic != NULL) {
129-
vpic_assert_irq(vu->vm, COM1_IRQ);
130-
}
128+
vpic_assert_irq(vu->vm, COM1_IRQ);
131129

132130
vioapic_assert_irq(vu->vm, COM1_IRQ);
133-
if (vu->vm->vpic != NULL) {
134-
vpic_deassert_irq(vu->vm, COM1_IRQ);
135-
}
131+
132+
vpic_deassert_irq(vu->vm, COM1_IRQ);
136133

137134
vioapic_deassert_irq(vu->vm, COM1_IRQ);
138135
}

hypervisor/dm/vpic.c

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
/* TODO: add spinlock_locked support? */
3636
/*#define VPIC_LOCKED(vpic) spinlock_locked(&((vpic)->lock))*/
3737

38-
#define vm_pic(vm) (vm->vpic)
39-
4038
#define ACRN_DBG_PIC 6U
4139

4240
enum irqstate {
@@ -45,34 +43,6 @@ enum irqstate {
4543
IRQSTATE_PULSE
4644
};
4745

48-
struct i8259_reg_state {
49-
bool ready;
50-
uint8_t icw_num;
51-
uint8_t rd_cmd_reg;
52-
53-
bool aeoi;
54-
bool poll;
55-
bool rotate;
56-
bool sfn; /* special fully-nested mode */
57-
58-
uint32_t irq_base;
59-
uint8_t request; /* Interrupt Request Register (IIR) */
60-
uint8_t service; /* Interrupt Service (ISR) */
61-
uint8_t mask; /* Interrupt Mask Register (IMR) */
62-
uint8_t smm; /* special mask mode */
63-
64-
int acnt[8]; /* sum of pin asserts and deasserts */
65-
uint8_t lowprio; /* lowest priority irq */
66-
67-
bool intr_raised;
68-
uint8_t elc;
69-
};
70-
71-
struct acrn_vpic {
72-
struct vm *vm;
73-
spinlock_t lock;
74-
struct i8259_reg_state i8259[2];
75-
};
7646

7747
#define NR_VPIC_PINS_PER_CHIP 8U
7848
#define NR_VPIC_PINS_TOTAL 16U
@@ -921,27 +891,13 @@ static void vpic_register_io_handler(struct vm *vm)
921891
&vpic_elc_io_read, &vpic_elc_io_write);
922892
}
923893

924-
void *vpic_init(struct vm *vm)
894+
void vpic_init(struct vm *vm)
925895
{
926-
struct acrn_vpic *vpic;
927-
896+
struct acrn_vpic *vpic = vm_pic(vm);
928897
vpic_register_io_handler(vm);
929-
930-
vpic = calloc(1U, sizeof(struct acrn_vpic));
931-
ASSERT(vpic != NULL, "");
932-
vpic->vm = vm;
933-
vpic->i8259[0].mask = 0xffU;
934-
vpic->i8259[1].mask = 0xffU;
898+
vm->arch_vm.vpic.vm = vm;
899+
vm->arch_vm.vpic.i8259[0].mask = 0xffU;
900+
vm->arch_vm.vpic.i8259[1].mask = 0xffU;
935901

936902
VPIC_LOCK_INIT(vpic);
937-
938-
return vpic;
939-
}
940-
941-
void vpic_cleanup(struct vm *vm)
942-
{
943-
if (vm->vpic != NULL) {
944-
free(vm->vpic);
945-
vm->vpic = NULL;
946-
}
947903
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ struct vm_arch {
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 */
101101
void *virt_ioapic; /* Virtual IOAPIC base address */
102+
struct acrn_vpic vpic; /* Virtual PIC */
102103
/**
103104
* A link to the IO handler of this VM.
104105
* We only register io handle to this link
@@ -125,7 +126,6 @@ struct vcpuid_entry {
125126
uint32_t padding;
126127
};
127128

128-
struct acrn_vpic;
129129
struct vm {
130130
uint16_t vm_id; /* Virtual machine identifier */
131131
struct vm_hw_info hw; /* Reference to this VM's HW information */
@@ -134,7 +134,6 @@ struct vm {
134134
struct vm_arch arch_vm; /* Reference to this VM's arch information */
135135
enum vm_state state; /* VM state */
136136
void *vuart; /* Virtual UART */
137-
struct acrn_vpic *vpic; /* Virtual PIC */
138137
enum vpic_wire_mode wire_mode;
139138
struct iommu_domain *iommu; /* iommu domain of this VM */
140139
struct list_head list; /* list of VM */
@@ -244,6 +243,12 @@ static inline struct vcpu *get_primary_vcpu(struct vm *vm)
244243
return NULL;
245244
}
246245

246+
static inline struct acrn_vpic *
247+
vm_pic(struct vm *vm)
248+
{
249+
return (struct acrn_vpic *)&(vm->arch_vm.vpic);
250+
}
251+
247252
int shutdown_vm(struct vm *vm);
248253
void pause_vm(struct vm *vm);
249254
void resume_vm(struct vm *vm);

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,36 @@ enum vpic_trigger {
9090
LEVEL_TRIGGER
9191
};
9292

93-
void *vpic_init(struct vm *vm);
94-
void vpic_cleanup(struct vm *vm);
93+
struct i8259_reg_state {
94+
bool ready;
95+
uint8_t icw_num;
96+
uint8_t rd_cmd_reg;
97+
98+
bool aeoi;
99+
bool poll;
100+
bool rotate;
101+
bool sfn; /* special fully-nested mode */
102+
103+
uint32_t irq_base;
104+
uint8_t request; /* Interrupt Request Register (IIR) */
105+
uint8_t service; /* Interrupt Service (ISR) */
106+
uint8_t mask; /* Interrupt Mask Register (IMR) */
107+
uint8_t smm; /* special mask mode */
108+
109+
int acnt[8]; /* sum of pin asserts and deasserts */
110+
uint8_t lowprio; /* lowest priority irq */
111+
112+
bool intr_raised;
113+
uint8_t elc;
114+
};
115+
116+
struct acrn_vpic {
117+
struct vm *vm;
118+
spinlock_t lock;
119+
struct i8259_reg_state i8259[2];
120+
};
121+
122+
void vpic_init(struct vm *vm);
95123

96124
void vpic_assert_irq(struct vm *vm, uint32_t irq);
97125
void vpic_deassert_irq(struct vm *vm, uint32_t irq);

hypervisor/include/arch/x86/hv_arch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <trusty.h>
2222
#include <guest_pm.h>
2323
#include <host_pm.h>
24+
#include <vpic.h>
2425
#include <vm.h>
2526
#include <cpuid.h>
2627
#include <mmu.h>
@@ -32,7 +33,6 @@
3233
#include <assign.h>
3334
#include <vtd.h>
3435

35-
#include <vpic.h>
3636
#include <vlapic.h>
3737
#include <vioapic.h>
3838
#include <guest.h>

0 commit comments

Comments
 (0)