Skip to content

Commit 73cff9e

Browse files
donshengacrnsi
authored andcommitted
HV: predefine pci vbar's base address for pre-launched VMs in vm_config
For pre-launched VMs, currently we set all vbars to 0s initially in bar emulation code, guest OS will reprogram the bars when it sees the bars are uninited (0s). We consider this is not the right solution, change to populate the vbars (to non zero valid pci hole address) based on the vbar base addresses predefined in vm_config. Store a pointer to acrn_vm_pci_ptdev_config in struct pci_vdev Tracked-On: #3022 Signed-off-by: dongshen <dongsheng.x.zhang@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 4cdaa51 commit 73cff9e

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

hypervisor/dm/vpci/pci_pt.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ void init_vdev_pt(struct pci_vdev *vdev)
311311
pbar = &vdev->pdev->bar[idx];
312312
vbar = &vdev->bar[idx];
313313

314+
vbar->base = 0UL;
314315
if (is_bar_supported(pbar)) {
315316
/**
316317
* If vbar->base is 0 (unassigned), Linux kernel will reprogram the vbar on
@@ -324,6 +325,11 @@ void init_vdev_pt(struct pci_vdev *vdev)
324325
* are reported to guest as PCIBAR_MEM32
325326
*/
326327
vbar->type = PCIBAR_MEM32;
328+
329+
/* Set the new vbar base */
330+
if (vdev->ptdev_config->vbar[idx] != 0UL) {
331+
vdev_pt_write_vbar(vdev, pci_bar_offset(idx), 4U, (uint32_t)(vdev->ptdev_config->vbar[idx]));
332+
}
327333
} else {
328334
vbar->size = 0UL;
329335
vbar->type = PCIBAR_NONE;

hypervisor/dm/vpci/vpci.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ static void init_vdev_for_pdev(struct pci_pdev *pdev, const void *vm)
415415

416416
vdev->vpci = vpci;
417417
vdev->pdev = pdev;
418+
vdev->ptdev_config = ptdev_config;
418419

419420
if (ptdev_config != NULL) {
420421
/* vbdf is defined in vm_config */
@@ -425,10 +426,16 @@ static void init_vdev_for_pdev(struct pci_pdev *pdev, const void *vm)
425426
}
426427

427428
init_vhostbridge(vdev);
428-
init_vdev_pt(vdev);
429429
init_vmsi(vdev);
430430
init_vmsix(vdev);
431431

432+
/*
433+
* Here init_vdev_pt() needs to be called after init_vmsix() for the following reason:
434+
* init_vdev_pt() will indirectly call has_msix_cap(), which
435+
* requires init_vmsix() to be called first.
436+
*/
437+
init_vdev_pt(vdev);
438+
432439
if (has_msix_cap(vdev)) {
433440
vdev_pt_remap_msix_table_bar(vdev);
434441
}

hypervisor/include/arch/x86/vm_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct acrn_vm_os_config {
6868
struct acrn_vm_pci_ptdev_config {
6969
union pci_bdf vbdf; /* virtual BDF of PCI PT device */
7070
union pci_bdf pbdf; /* physical BDF of PCI PT device */
71+
uint64_t vbar[PCI_BAR_COUNT]; /* vbar base address of PCI PT device */
7172
} __aligned(8);
7273

7374
struct acrn_vm_config {

hypervisor/include/dm/vpci.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ struct pci_vdev {
7878

7979
struct pci_msi msi;
8080
struct pci_msix msix;
81+
82+
/* Pointer to corresponding PCI PT device's vm_config */
83+
struct acrn_vm_pci_ptdev_config *ptdev_config;
8184
};
8285

8386
struct pci_addr_info {

hypervisor/scenarios/logical_partition/pt_dev.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +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,
1720
VM0_STORAGE_CONTROLLER
1821
},
1922
{
2023
.vbdf.bits = {.b = 0x00U, .d = 0x02U, .f = 0x00U},
24+
.vbar[0] = 0xc0000000UL,
25+
.vbar[3] = 0xc0080000UL,
2126
VM0_NETWORK_CONTROLLER
2227
},
2328
};
@@ -29,6 +34,7 @@ struct acrn_vm_pci_ptdev_config vm1_pci_ptdevs[VM1_CONFIG_PCI_PTDEV_NUM] = {
2934
},
3035
{
3136
.vbdf.bits = {.b = 0x00U, .d = 0x01U, .f = 0x00U},
37+
.vbar[0] = 0xc0000000UL,
3238
VM1_STORAGE_CONTROLLER
3339
},
3440
#if defined(VM1_NETWORK_CONTROLLER)

0 commit comments

Comments
 (0)