Skip to content

Commit 0247c0b

Browse files
donshengacrnsi
authored andcommitted
Hv: minor cosmetic fix
Define/Use variable in place of code to improve readability: Define new local variable struct pci_bar *vbar, and use vbar-> in place of vdev->bar[idx]. Define new local variable uint64_t vbar_base in init_vdev_pt Rename uint64_t vbar[PCI_BAR_COUNT] of struct acrn_vm_pci_ptdev_config to uint64_t vbar_base[PCI_BAR_COUNT] Tracked-On: #3241 Signed-off-by: dongshen <dongsheng.x.zhang@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent f0244b2 commit 0247c0b

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

hypervisor/dm/vpci/pci_pt.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ int32_t vdev_pt_read_cfg(const struct pci_vdev *vdev, uint32_t offset, uint32_t
152152
void vdev_pt_remap_msix_table_bar(struct pci_vdev *vdev)
153153
{
154154
uint32_t i;
155-
uint64_t addr_hi, addr_lo;
156155
struct pci_msix *msix = &vdev->msix;
157156
struct pci_pdev *pdev = vdev->pdev;
158157
struct pci_bar *pbar;
@@ -221,6 +220,8 @@ void vdev_pt_remap_msix_table_bar(struct pci_vdev *vdev)
221220

222221

223222
if (msix->mmio_gpa != 0UL) {
223+
uint64_t addr_hi, addr_lo;
224+
224225
if (is_prelaunched_vm(vdev->vpci->vm)) {
225226
addr_hi = msix->mmio_gpa + msix->mmio_size;
226227
addr_lo = msix->mmio_gpa;
@@ -265,13 +266,16 @@ void vdev_pt_remap_msix_table_bar(struct pci_vdev *vdev)
265266
static void vdev_pt_remap_generic_mem_vbar(struct pci_vdev *vdev, uint32_t idx)
266267
{
267268
struct acrn_vm *vm = vdev->vpci->vm;
269+
struct pci_bar *vbar;
268270
uint64_t vbar_base = get_vbar_base(vdev, idx); /* vbar (gpa) */
269271

272+
vbar = &vdev->bar[idx];
273+
270274
/* If the old vbar is mapped before, unmap it first */
271275
if (vdev->bar_base_mapped[idx] != 0UL) {
272276
ept_del_mr(vm, (uint64_t *)(vm->arch_vm.nworld_eptp),
273277
vdev->bar_base_mapped[idx], /* GPA (old vbar) */
274-
vdev->bar[idx].size);
278+
vbar->size);
275279
vdev->bar_base_mapped[idx] = 0UL;
276280
}
277281

@@ -283,7 +287,7 @@ static void vdev_pt_remap_generic_mem_vbar(struct pci_vdev *vdev, uint32_t idx)
283287
ept_add_mr(vm, (uint64_t *)(vm->arch_vm.nworld_eptp),
284288
pbar_base, /* HPA (pbar) */
285289
vbar_base, /* GPA (new vbar) */
286-
vdev->bar[idx].size,
290+
vbar->size,
287291
EPT_WR | EPT_RD | EPT_UNCACHED);
288292

289293
/* Remember the previously mapped MMIO vbar */
@@ -419,6 +423,7 @@ void init_vdev_pt(struct pci_vdev *vdev)
419423
uint32_t idx;
420424
struct pci_bar *pbar, *vbar;
421425
uint16_t pci_command;
426+
uint64_t vbar_base;
422427

423428
vdev->nr_bars = vdev->pdev->nr_bars;
424429

@@ -451,10 +456,11 @@ void init_vdev_pt(struct pci_vdev *vdev)
451456
*/
452457
vbar->type = PCIBAR_MEM32;
453458

459+
/* For pre-launched VMs: vbar base is predefined in vm_config */
460+
vbar_base = vdev->ptdev_config->vbar_base[idx];
461+
454462
/* Set the new vbar base */
455-
if (vdev->ptdev_config->vbar[idx] != 0UL) {
456-
vdev_pt_write_vbar(vdev, pci_bar_offset(idx), (uint32_t)(vdev->ptdev_config->vbar[idx]));
457-
}
463+
vdev_pt_write_vbar(vdev, pci_bar_offset(idx), (uint32_t)vbar_base);
458464
} else {
459465
vbar->reg.value = 0x0U;
460466
vbar->size = 0UL;

hypervisor/include/arch/x86/vm_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct acrn_vm_os_config {
8181
struct acrn_vm_pci_ptdev_config {
8282
union pci_bdf vbdf; /* virtual BDF of PCI PT device */
8383
union pci_bdf pbdf; /* physical BDF of PCI PT device */
84-
uint64_t vbar[PCI_BAR_COUNT]; /* vbar base address of PCI PT device */
84+
uint64_t vbar_base[PCI_BAR_COUNT]; /* vbar base address of PCI PT device */
8585
} __aligned(8);
8686

8787
struct acrn_vm_config {

hypervisor/scenarios/logical_partition/pt_dev.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ struct acrn_vm_pci_ptdev_config vm0_pci_ptdevs[VM0_CONFIG_PCI_PTDEV_NUM] = {
1414
},
1515
{
1616
.vbdf.bits = {.b = 0x00U, .d = 0x01U, .f = 0x00U},
17-
.vbar[0] = 0xc0084000UL,
18-
.vbar[1] = 0xc0086000UL,
19-
.vbar[5] = 0xc0087000UL,
17+
.vbar_base[0] = 0xc0084000UL,
18+
.vbar_base[1] = 0xc0086000UL,
19+
.vbar_base[5] = 0xc0087000UL,
2020
VM0_STORAGE_CONTROLLER
2121
},
2222
{
2323
.vbdf.bits = {.b = 0x00U, .d = 0x02U, .f = 0x00U},
24-
.vbar[0] = 0xc0000000UL,
25-
.vbar[3] = 0xc0080000UL,
24+
.vbar_base[0] = 0xc0000000UL,
25+
.vbar_base[3] = 0xc0080000UL,
2626
VM0_NETWORK_CONTROLLER
2727
},
2828
};
@@ -34,7 +34,7 @@ struct acrn_vm_pci_ptdev_config vm1_pci_ptdevs[VM1_CONFIG_PCI_PTDEV_NUM] = {
3434
},
3535
{
3636
.vbdf.bits = {.b = 0x00U, .d = 0x01U, .f = 0x00U},
37-
.vbar[0] = 0xc0000000UL,
37+
.vbar_base[0] = 0xc0000000UL,
3838
VM1_STORAGE_CONTROLLER
3939
},
4040
#if defined(VM1_NETWORK_CONTROLLER)

0 commit comments

Comments
 (0)