Skip to content

Commit d67d053

Browse files
yliu80wenlingz
authored andcommitted
hv: initialize VF BARs
The VF BARs are initialized by its PF SRIOV capability Tracked-On: #4433 Signed-off-by: Yuan Liu <yuan1.liu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent ddd6253 commit d67d053

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

hypervisor/dm/vpci/pci_pt.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static void vdev_pt_unmap_msix(struct pci_vdev *vdev)
6666
* @pre vdev->vpci != NULL
6767
* @pre vdev->vpci->vm != NULL
6868
*/
69-
static void vdev_pt_map_msix(struct pci_vdev *vdev, bool hold_lock)
69+
void vdev_pt_map_msix(struct pci_vdev *vdev, bool hold_lock)
7070
{
7171
struct pci_vbar *vbar;
7272
uint64_t addr_hi, addr_lo;
@@ -262,10 +262,6 @@ static void init_bars(struct pci_vdev *vdev, bool is_sriov_bar)
262262
}
263263
pbdf.value = vdev->pdev->bdf.value;
264264

265-
for (offset = 0U; offset < PCI_CFG_HEADER_LENGTH; offset += 4U) {
266-
pci_vdev_write_vcfg(vdev, offset, 4U, pci_pdev_read_cfg(pbdf, offset, 4U));
267-
}
268-
269265
for (idx = 0U; idx < bar_cnt; idx++) {
270266
if (is_sriov_bar) {
271267
vbar = &vdev->sriov.vbars[idx];
@@ -375,10 +371,14 @@ static void init_bars(struct pci_vdev *vdev, bool is_sriov_bar)
375371
void init_vdev_pt(struct pci_vdev *vdev, bool is_pf_vdev)
376372
{
377373
uint16_t pci_command;
374+
uint32_t offset;
378375

379-
if (vdev->phyfun != NULL) {
380-
init_sriov_vf_vdev(vdev);
381-
} else {
376+
for (offset = 0U; offset < PCI_CFG_HEADER_LENGTH; offset += 4U) {
377+
pci_vdev_write_vcfg(vdev, offset, 4U, pci_pdev_read_cfg(vdev->pdev->bdf, offset, 4U));
378+
}
379+
380+
/* Initialize the vdev BARs except SRIOV VF, VF BARs are initialized directly from create_vf function */
381+
if (vdev->phyfun == NULL) {
382382
init_bars(vdev, is_pf_vdev);
383383
if (is_prelaunched_vm(vdev->vpci->vm) && (!is_pf_vdev)) {
384384
pci_command = (uint16_t)pci_pdev_read_cfg(vdev->pdev->bdf, PCIR_COMMAND, 2U);

hypervisor/dm/vpci/vpci_priv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ static inline bool msicap_access(const struct pci_vdev *vdev, uint32_t offset)
103103

104104
void init_vdev_pt(struct pci_vdev *vdev, bool is_pf_vdev);
105105
void vdev_pt_write_vbar(struct pci_vdev *vdev, uint32_t idx, uint32_t val);
106+
void vdev_pt_map_msix(struct pci_vdev *vdev, bool hold_lock);
106107

107108
void init_vmsi(struct pci_vdev *vdev);
108109
void vmsi_read_cfg(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val);
@@ -119,7 +120,6 @@ void init_vsriov(struct pci_vdev *vdev);
119120
void read_sriov_cap_reg(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val);
120121
void write_sriov_cap_reg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val);
121122
uint32_t sriov_bar_offset(const struct pci_vdev *vdev, uint32_t bar_idx);
122-
void init_sriov_vf_vdev(struct pci_vdev *vdev);
123123

124124
uint32_t pci_vdev_read_vcfg(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes);
125125
void pci_vdev_write_vcfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val);

hypervisor/dm/vpci/vsriov.c

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static void init_sriov_vf_bar(struct pci_vdev *pf_vdev)
8181
/**
8282
* @pre pf_vdev != NULL
8383
*/
84-
static void create_vf(struct pci_vdev *pf_vdev, union pci_bdf vf_bdf)
84+
static void create_vf(struct pci_vdev *pf_vdev, union pci_bdf vf_bdf, uint16_t vf_id)
8585
{
8686
struct pci_pdev *vf_pdev;
8787
struct pci_vdev *vf_vdev = NULL;
@@ -112,6 +112,31 @@ static void create_vf(struct pci_vdev *pf_vdev, union pci_bdf vf_bdf)
112112
pci_pdev_write_cfg(pf_vdev->bdf, pf_vdev->sriov.capoff + PCIR_SRIOV_CONTROL, 2U, control);
113113
pr_err("PF %x:%x.%x can't creat VF, unset VF_ENABLE",
114114
pf_vdev->bdf.bits.b, pf_vdev->bdf.bits.d, pf_vdev->bdf.bits.f);
115+
} else {
116+
uint16_t bar_idx;
117+
struct pci_vbar *vf_vbar;
118+
119+
/* VF bars information from its PF SRIOV capability, no need to access physical device */
120+
vf_vdev->nr_bars = PCI_BAR_COUNT;
121+
for (bar_idx = 0U; bar_idx < PCI_BAR_COUNT; bar_idx++) {
122+
vf_vbar = &vf_vdev->vbars[bar_idx];
123+
*vf_vbar = vf_vdev->phyfun->sriov.vbars[bar_idx];
124+
vf_vbar->base_hpa += (vf_vbar->size * vf_id);
125+
vf_vbar->base = vf_vbar->base_hpa;
126+
if (has_msix_cap(vf_vdev) && (bar_idx == vf_vdev->msix.table_bar)) {
127+
vf_vdev->msix.mmio_hpa = vf_vbar->base_hpa;
128+
vf_vdev->msix.mmio_size = vf_vbar->size;
129+
}
130+
/*
131+
* VF BARs value are zero and read only, according to PCI Express
132+
* Base 4.0 chapter 9.3.4.1.11, the VF
133+
*/
134+
pci_vdev_write_vcfg(vf_vdev, pci_bar_offset(bar_idx), 4U, 0U);
135+
}
136+
137+
if (has_msix_cap(vf_vdev)) {
138+
vdev_pt_map_msix(vf_vdev, false);
139+
}
115140
}
116141
}
117142

@@ -170,7 +195,7 @@ static void enable_vf(struct pci_vdev *pf_vdev)
170195

171196
/* if one VF has never been created then create new pdev/vdev for this VF */
172197
if (pci_find_vdev(&pf_vdev->vpci->vm->vpci, vf_bdf) == NULL) {
173-
create_vf(pf_vdev, vf_bdf);
198+
create_vf(pf_vdev, vf_bdf, idx);
174199
}
175200
}
176201
} else {
@@ -270,12 +295,3 @@ uint32_t sriov_bar_offset(const struct pci_vdev *vdev, uint32_t bar_idx)
270295
{
271296
return (vdev->sriov.capoff + PCIR_SRIOV_VF_BAR_OFF + (bar_idx << 2U));
272297
}
273-
274-
/**
275-
* @pre vdev != NULL
276-
*/
277-
void init_sriov_vf_vdev(struct pci_vdev *vdev)
278-
{
279-
/* Implementation in next path */
280-
(void)vdev;
281-
}

0 commit comments

Comments
 (0)