hv: refine init_vdev_pt function

To support SRIOV capability initialization, add a new parameter
is_sriov_pf_vdev for init_vdev_pt function.

If parameter is_sriov_pf_vdev of function init_vdev_pt is true,
then function init_vdev_pt initializes the vdev's SRIOV capability.

Tracked-On: #4433

Signed-off-by: Yuan Liu <yuan1.liu@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Yuan Liu 2020-02-25 14:04:25 +08:00 committed by wenlingz
parent 58c0a47474
commit 298ef2f5c4
3 changed files with 30 additions and 4 deletions

View File

@ -220,12 +220,11 @@ void vdev_pt_write_vbar(struct pci_vdev *vdev, uint32_t idx, uint32_t val)
* @pre vdev->vpci->vm != NULL * @pre vdev->vpci->vm != NULL
* @pre vdev->pdev != NULL * @pre vdev->pdev != NULL
*/ */
void init_vdev_pt(struct pci_vdev *vdev) static void init_bars(struct pci_vdev *vdev)
{ {
enum pci_bar_type type; enum pci_bar_type type;
uint32_t idx; uint32_t idx;
struct pci_vbar *vbar; struct pci_vbar *vbar;
uint16_t pci_command;
uint32_t size32, offset, lo, hi = 0U; uint32_t size32, offset, lo, hi = 0U;
union pci_bdf pbdf; union pci_bdf pbdf;
uint64_t mask; uint64_t mask;
@ -293,7 +292,34 @@ void init_vdev_pt(struct pci_vdev *vdev)
} }
} }
} }
}
/*
* @brief Initialize a specified passthrough vdev structure.
*
* The function init_vdev_pt is used to initialize a vdev structure. If a vdev structure supports
* SRIOV capability that the vdev represents a SRIOV physical function(PF) virtual device, then
* function init_vdev_pt can initialize PF vdev SRIOV capability if parameter is_pf_vdev is true.
*
* @param vdev pointer to vdev data structure
* @param is_pf_vdev indicate the first parameter vdev is the data structure of a PF, which contains
* the SR-IOV capability
*
* @pre vdev != NULL
* @pre vdev->vpci != NULL
* @pre vdev->vpci->vm != NULL
* @pre vdev->pdev != NULL
*
* @return None
*/
void init_vdev_pt(struct pci_vdev *vdev, bool is_pf_vdev)
{
uint16_t pci_command;
/* SRIOV capability initialization implementaion in next patch */
(void) is_pf_vdev;
init_bars(vdev);
if (is_prelaunched_vm(vdev->vpci->vm)) { if (is_prelaunched_vm(vdev->vpci->vm)) {
pci_command = (uint16_t)pci_pdev_read_cfg(vdev->pdev->bdf, PCIR_COMMAND, 2U); pci_command = (uint16_t)pci_pdev_read_cfg(vdev->pdev->bdf, PCIR_COMMAND, 2U);

View File

@ -358,7 +358,7 @@ static void vpci_init_pt_dev(struct pci_vdev *vdev)
init_vmsi(vdev); init_vmsi(vdev);
init_vmsix(vdev); init_vmsix(vdev);
init_vsriov(vdev); init_vsriov(vdev);
init_vdev_pt(vdev); init_vdev_pt(vdev, false);
assign_vdev_pt_iommu_domain(vdev); assign_vdev_pt_iommu_domain(vdev);
} }

View File

@ -141,7 +141,7 @@ static inline bool msicap_access(const struct pci_vdev *vdev, uint32_t offset)
return (has_msi_cap(vdev) && in_range(offset, vdev->msi.capoff, vdev->msi.caplen)); return (has_msi_cap(vdev) && in_range(offset, vdev->msi.capoff, vdev->msi.caplen));
} }
void init_vdev_pt(struct pci_vdev *vdev); void init_vdev_pt(struct pci_vdev *vdev, bool is_pf_vdev);
void vdev_pt_write_vbar(struct pci_vdev *vdev, uint32_t idx, uint32_t val); void vdev_pt_write_vbar(struct pci_vdev *vdev, uint32_t idx, uint32_t val);
void vdev_pt_write_command(const struct pci_vdev *vdev, uint32_t bytes, uint16_t new_cmd); void vdev_pt_write_command(const struct pci_vdev *vdev, uint32_t bytes, uint16_t new_cmd);