Skip to content

Commit 8ec78f8

Browse files
lifeixjren1
authored andcommitted
hv: vlapic: coding refine
Using __func__ instead of function string name. Using tab instead of more whitespace. Using macro instead of numeric constants. Remove unnecessary function declaration. Signed-off-by: Li, Fei1 <fei1.li@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent b9971c2 commit 8ec78f8

File tree

2 files changed

+35
-50
lines changed

2 files changed

+35
-50
lines changed

hypervisor/arch/x86/guest/vlapic.c

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,11 @@ do { \
8686
#endif
8787

8888
/* TIMER_LVT bit[18:17] == 0x10 TSD DEADLINE mode */
89-
#define VLAPIC_TSCDEADLINE(lvt) (((lvt) & 0x60000) == 0x40000)
89+
#define VLAPIC_TSCDEADLINE(lvt) (((lvt) & APIC_LVTT_TM) == APIC_LVTT_TM_TSCDLT)
9090

9191
/*APIC-v APIC-access address */
9292
static void *apicv_apic_access_addr;
9393

94-
static int
95-
vlapic_write(struct vlapic *vlapic, int mmio_access, uint64_t offset,
96-
uint64_t data);
97-
static int
98-
vlapic_read(struct vlapic *vlapic, int mmio_access, uint64_t offset,
99-
uint64_t *data);
100-
10194
static int
10295
apicv_set_intr_ready(struct vlapic *vlapic, int vector, bool level);
10396

@@ -110,22 +103,12 @@ apicv_set_tmr(struct vlapic *vlapic, int vector, bool level);
110103
static void
111104
apicv_batch_set_tmr(struct vlapic *vlapic);
112105

113-
/*
114-
* Returns 1 if the vcpu needs to be notified of the interrupt and 0 otherwise.
115-
*/
116-
static int
117-
vlapic_set_intr_ready(struct vlapic *vlapic, int vector, bool level);
118-
119106
/*
120107
* Post an interrupt to the vcpu running on 'hostcpu'. This will use a
121108
* hardware assist if available (e.g. Posted Interrupt) or fall back to
122109
* sending an 'ipinum' to interrupt the 'hostcpu'.
123110
*/
124111
static void vlapic_set_error(struct vlapic *vlapic, uint32_t mask);
125-
static int vlapic_trigger_lvt(struct vlapic *vlapic, int vector);
126-
127-
static uint64_t vlapic_get_apicbase(struct vlapic *vlapic);
128-
static int vlapic_set_apicbase(struct vlapic *vlapic, uint64_t val);
129112

130113
static struct vlapic *
131114
vm_lapic_from_vcpu_id(struct vm *vm, int vcpu_id)
@@ -159,7 +142,7 @@ static int vm_apicid2vcpu_id(struct vm *vm, uint8_t lapicid)
159142
return vcpu->vcpu_id;
160143
}
161144

162-
pr_err("vm_apicid2vcpu_id: bad lapicid %d", lapicid);
145+
pr_err("%s: bad lapicid %d", __func__, lapicid);
163146

164147
return phy_cpu_num;
165148
}
@@ -197,7 +180,7 @@ vlapic_build_id(struct vlapic *vlapic)
197180
uint32_t id;
198181

199182
if (is_vm0(vcpu->vm)) {
200-
/* Get APIC ID sequence format from cpu_storage */
183+
/* Get APIC ID sequence format from cpu_storage */
201184
id = per_cpu(lapic_id, vcpu->vcpu_id);
202185
} else
203186
id = vcpu->vcpu_id;
@@ -267,6 +250,9 @@ vlapic_esr_write_handler(struct vlapic *vlapic)
267250
vlapic->esr_pending = 0;
268251
}
269252

253+
/*
254+
* Returns 1 if the vcpu needs to be notified of the interrupt and 0 otherwise.
255+
*/
270256
static int
271257
vlapic_set_intr_ready(struct vlapic *vlapic, int vector, bool level)
272258
{
@@ -289,8 +275,7 @@ vlapic_set_intr_ready(struct vlapic *vlapic, int vector, bool level)
289275
if (vector < 16) {
290276
vlapic_set_error(vlapic, APIC_ESR_RECEIVE_ILLEGAL_VECTOR);
291277
dev_dbg(ACRN_DBG_LAPIC,
292-
"vlapic ignoring interrupt to vector %d",
293-
vector);
278+
"vlapic ignoring interrupt to vector %d", vector);
294279
return 1;
295280
}
296281

@@ -368,8 +353,8 @@ lvt_off_to_idx(uint32_t offset)
368353
break;
369354
}
370355
ASSERT(index >= 0 && index <= VLAPIC_MAXLVT_INDEX,
371-
"lvt_off_to_idx: invalid lvt index %d for offset %#x",
372-
index, offset);
356+
"%s: invalid lvt index %d for offset %#x",
357+
__func__, index, offset);
373358

374359
return index;
375360
}
@@ -426,7 +411,7 @@ vlapic_lvt_write_handler(struct vlapic *vlapic, uint32_t offset)
426411
if (vlapic->vm->vpic_wire_mode == VPIC_WIRE_INTR ||
427412
vlapic->vm->vpic_wire_mode == VPIC_WIRE_NULL) {
428413
atomic_set_int(&vlapic->vm->vpic_wire_mode,
429-
VPIC_WIRE_LAPIC);
414+
VPIC_WIRE_LAPIC);
430415
dev_dbg(ACRN_DBG_LAPIC,
431416
"vpic wire mode -> LAPIC");
432417
} else {
@@ -587,7 +572,7 @@ vlapic_update_ppr(struct vlapic *vlapic)
587572
ppr = isrvec & 0xf0;
588573

589574
vlapic->apic_page->ppr = ppr;
590-
dev_dbg(ACRN_DBG_LAPIC, "vlapic_update_ppr 0x%02x", ppr);
575+
dev_dbg(ACRN_DBG_LAPIC, "%s 0x%02x", __func__, ppr);
591576
}
592577

593578
static void
@@ -605,7 +590,7 @@ vlapic_process_eoi(struct vlapic *vlapic)
605590
if (bitpos >= 0) {
606591
if (vlapic->isrvec_stk_top <= 0) {
607592
panic("invalid vlapic isrvec_stk_top %d",
608-
vlapic->isrvec_stk_top);
593+
vlapic->isrvec_stk_top);
609594
}
610595
isrptr[i].val &= ~(1 << bitpos);
611596
vector = i * 32 + bitpos;
@@ -666,7 +651,7 @@ vlapic_trigger_lvt(struct vlapic *vlapic, int vector)
666651
* When the local APIC is global/hardware disabled,
667652
* LINT[1:0] pins are configured as INTR and NMI pins,
668653
* respectively.
669-
*/
654+
*/
670655
switch (vector) {
671656
case APIC_LVT_LINT0:
672657
vcpu_inject_extint(vlapic->vcpu);
@@ -774,11 +759,11 @@ vlapic_calcdest(struct vm *vm, uint64_t *dmask, uint32_t dest,
774759
ldr = vlapic->apic_page->ldr;
775760

776761
if ((dfr & APIC_DFR_MODEL_MASK) ==
777-
APIC_DFR_MODEL_FLAT) {
762+
APIC_DFR_MODEL_FLAT) {
778763
ldest = ldr >> 24;
779764
mda_ldest = mda_flat_ldest;
780765
} else if ((dfr & APIC_DFR_MODEL_MASK) ==
781-
APIC_DFR_MODEL_CLUSTER) {
766+
APIC_DFR_MODEL_CLUSTER) {
782767

783768
cluster = ldr >> 28;
784769
ldest = (ldr >> 24) & 0xf;
@@ -1006,8 +991,8 @@ vlapic_pending_intr(struct vlapic *vlapic, int *vecptr)
1006991
{
1007992
struct lapic *lapic = vlapic->apic_page;
1008993
int i, bitpos;
1009-
uint32_t vector;
1010-
uint32_t val;
994+
uint32_t vector;
995+
uint32_t val;
1011996
struct lapic_reg *irrptr;
1012997

1013998
if (vlapic->ops.apicv_pending_intr)
@@ -1231,10 +1216,10 @@ vlapic_write(struct vlapic *vlapic, int mmio_access, uint64_t offset,
12311216
int retval;
12321217

12331218
ASSERT((offset & 0xf) == 0 && offset < CPU_PAGE_SIZE,
1234-
"vlapic_write: invalid offset %#lx", offset);
1219+
"%s: invalid offset %#lx", __func__, offset);
12351220

12361221
dev_dbg(ACRN_DBG_LAPIC, "vlapic write offset %#lx, data %#lx",
1237-
offset, data);
1222+
offset, data);
12381223

12391224
if (offset > sizeof(*lapic))
12401225
return 0;
@@ -1351,12 +1336,12 @@ vlapic_reset(struct vlapic *vlapic)
13511336
void
13521337
vlapic_init(struct vlapic *vlapic)
13531338
{
1354-
ASSERT(vlapic->vm != NULL, "vlapic_init: vm is not initialized");
1339+
ASSERT(vlapic->vm != NULL, "%s: vm is not initialized", __func__);
13551340
ASSERT(vlapic->vcpu->vcpu_id >= 0 &&
13561341
vlapic->vcpu->vcpu_id < phy_cpu_num,
1357-
"vlapic_init: vcpu_id is not initialized");
1342+
"%s: vcpu_id is not initialized", __func__);
13581343
ASSERT(vlapic->apic_page != NULL,
1359-
"vlapic_init: apic_page is not initialized");
1344+
"%s: apic_page is not initialized", __func__);
13601345

13611346
/*
13621347
* If the vlapic is configured in x2apic mode then it will be
@@ -1426,10 +1411,10 @@ vlapic_deliver_intr(struct vm *vm, bool level, uint32_t dest, bool phys,
14261411
struct vcpu *target_vcpu;
14271412

14281413
if (delmode != IOAPIC_RTE_DELFIXED &&
1429-
delmode != IOAPIC_RTE_DELLOPRI &&
1430-
delmode != IOAPIC_RTE_DELEXINT) {
1414+
delmode != IOAPIC_RTE_DELLOPRI &&
1415+
delmode != IOAPIC_RTE_DELEXINT) {
14311416
dev_dbg(ACRN_DBG_LAPIC,
1432-
"vlapic intr invalid delmode %#x", delmode);
1417+
"vlapic intr invalid delmode %#x", delmode);
14331418
return;
14341419
}
14351420
lowprio = (delmode == IOAPIC_RTE_DELLOPRI);
@@ -1462,8 +1447,8 @@ vlapic_enabled(struct vlapic *vlapic)
14621447
{
14631448
struct lapic *lapic = vlapic->apic_page;
14641449

1465-
if ((vlapic->msr_apicbase & APICBASE_ENABLED) != 0 &&
1466-
(lapic->svr & APIC_SVR_ENABLE) != 0)
1450+
if ((vlapic->msr_apicbase & APICBASE_ENABLED) &&
1451+
(lapic->svr & APIC_SVR_ENABLE))
14671452
return true;
14681453
else
14691454
return false;
@@ -1625,12 +1610,12 @@ vlapic_intr_msi(struct vm *vm, uint64_t addr, uint64_t msg)
16251610
*/
16261611
dest = (addr >> 12) & 0xff;
16271612
phys = ((addr & (MSI_ADDR_RH | MSI_ADDR_LOG)) !=
1628-
(MSI_ADDR_RH | MSI_ADDR_LOG));
1613+
(MSI_ADDR_RH | MSI_ADDR_LOG));
16291614
delmode = msg & APIC_DELMODE_MASK;
16301615
vec = msg & 0xff;
16311616

16321617
dev_dbg(ACRN_DBG_LAPIC, "lapic MSI %s dest %#x, vec %d",
1633-
phys ? "physical" : "logical", dest, vec);
1618+
phys ? "physical" : "logical", dest, vec);
16341619

16351620
vlapic_deliver_intr(vm, LAPIC_TRIG_EDGE, dest, phys, delmode, vec);
16361621
return 0;
@@ -1674,7 +1659,7 @@ static int tsc_periodic_time(void *data)
16741659

16751660
/* inject vcpu timer interrupt if existing */
16761661
if (VLAPIC_TSCDEADLINE(lapic->lvt_timer))
1677-
vlapic_intr_edge(vcpu, lapic->lvt_timer & 0xFF);
1662+
vlapic_intr_edge(vcpu, lapic->lvt_timer & APIC_LVTT_VECTOR);
16781663

16791664
return 0;
16801665
}
@@ -1786,7 +1771,7 @@ vlapic_mmio_read(struct vcpu *vcpu, uint64_t gpa, uint64_t *rval,
17861771

17871772
/*
17881773
* Memory mapped local apic accesses should be aligned on a
1789-
* 16-byte boundary. They are also suggested to be 4 bytes
1774+
* 16-byte boundary. They are also suggested to be 4 bytes
17901775
* wide, alas not all OSes follow suggestions.
17911776
*/
17921777
off &= ~3;
@@ -2102,7 +2087,7 @@ int apic_access_vmexit_handler(struct vcpu *vcpu)
21022087
uint64_t qual;
21032088
struct vlapic *vlapic;
21042089

2105-
qual = vcpu->arch_vcpu.exit_qualification;
2090+
qual = vcpu->arch_vcpu.exit_qualification;
21062091
access_type = APIC_ACCESS_TYPE(qual);
21072092

21082093
/*parse offset if linear access*/
@@ -2135,7 +2120,7 @@ int veoi_vmexit_handler(struct vcpu *vcpu)
21352120

21362121
VCPU_RETAIN_RIP(vcpu);
21372122

2138-
vlapic = vcpu->arch_vcpu.vlapic;
2123+
vlapic = vcpu->arch_vcpu.vlapic;
21392124
lapic = vlapic->apic_page;
21402125
vector = (vcpu->arch_vcpu.exit_qualification) & 0xFF;
21412126

@@ -2164,7 +2149,7 @@ int apic_write_vmexit_handler(struct vcpu *vcpu)
21642149

21652150
handled = 1;
21662151
VCPU_RETAIN_RIP(vcpu);
2167-
vlapic = vcpu->arch_vcpu.vlapic;
2152+
vlapic = vcpu->arch_vcpu.vlapic;
21682153

21692154
switch (offset) {
21702155
case APIC_OFFSET_ID:

hypervisor/arch/x86/guest/vlapic_priv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#define _VLAPIC_PRIV_H_
3232

3333
/*
34-
* APIC Register: Offset Description
34+
* APIC Register: Offset Description
3535
*/
3636
#define APIC_OFFSET_ID 0x20 /* Local APIC ID */
3737
#define APIC_OFFSET_VER 0x30 /* Local APIC Version */

0 commit comments

Comments
 (0)