HV: init ptdev bar during runtime for partition mode

Current pt devices bar info for partion mode is hardcoded in
vm_description.c, now we remove the hardcoded info and parse the bar
info during pt devices init.

Tracked-On: #2431
Signed-off-by: Victor Sun <victor.sun@intel.com>
Signed-off-by: dongshen <dongsheng.x.zhang@intel.com>
Reviewed-by: Anthony Xu <anthony.xu@intel.com>
This commit is contained in:
Victor Sun 2019-01-15 15:28:40 +08:00 committed by ACRN System Integration
parent 983b717a61
commit f082176df0
3 changed files with 65 additions and 0 deletions

View File

@ -50,6 +50,49 @@ static struct pci_vdev *partition_mode_find_vdev(struct acrn_vpci *vpci, union p
return NULL; return NULL;
} }
static inline bool is_valid_bar_type(const struct pci_bar *bar)
{
return (bar->type == PCIBAR_MEM32) || (bar->type == PCIBAR_MEM64);
}
static inline bool is_valid_bar_size(const struct pci_bar *bar)
{
return (bar->size > 0UL) && (bar->size <= 0xffffffffU);
}
/* Only MMIO is supported and bar size cannot be greater than 4GB */
static inline bool is_valid_bar(const struct pci_bar *bar)
{
return (is_valid_bar_type(bar) && is_valid_bar_size(bar));
}
static void partition_mode_pdev_init(struct pci_vdev *vdev)
{
struct pci_pdev *pdev_ref;
uint32_t idx;
struct pci_bar *pbar, *vbar;
pdev_ref = find_pci_pdev(vdev->pdev.bdf);
if (pdev_ref != NULL) {
(void)memcpy_s((void *)&vdev->pdev, sizeof(struct pci_pdev), (void *)pdev_ref, sizeof(struct pci_pdev));
/* Sanity checking for vbar */
for (idx = 0U; idx < (uint32_t)PCI_BAR_COUNT; idx++) {
pbar = &vdev->pdev.bar[idx];
vbar = &vdev->bar[idx];
if (is_valid_bar(pbar)) {
vbar->size = (pbar->size < 0x1000U) ? 0x1000U : pbar->size;
vbar->type = PCIBAR_MEM32;
} else {
/* Mark this vbar as invalid */
vbar->size = 0UL;
vbar->type = PCIBAR_NONE;
}
}
}
}
static int32_t partition_mode_vpci_init(const struct acrn_vm *vm) static int32_t partition_mode_vpci_init(const struct acrn_vm *vm)
{ {
struct vpci_vdev_array *vdev_array; struct vpci_vdev_array *vdev_array;
@ -64,6 +107,11 @@ static int32_t partition_mode_vpci_init(const struct acrn_vm *vm)
vdev = &vdev_array->vpci_vdev_list[i]; vdev = &vdev_array->vpci_vdev_list[i];
vdev->vpci = vpci; vdev->vpci = vpci;
/* Exclude hostbridge */
if (vdev->vbdf.value != 0U) {
partition_mode_pdev_init(vdev);
}
if ((vdev->ops != NULL) && (vdev->ops->init != NULL)) { if ((vdev->ops != NULL) && (vdev->ops->init != NULL)) {
if (vdev->ops->init(vdev) != 0) { if (vdev->ops->init(vdev) != 0) {
pr_err("%s() failed at PCI device (bdf %x)!", __func__, pr_err("%s() failed at PCI device (bdf %x)!", __func__,
@ -98,6 +146,7 @@ static void partition_mode_cfgread(struct acrn_vpci *vpci, union pci_bdf vbdf,
uint32_t offset, uint32_t bytes, uint32_t *val) uint32_t offset, uint32_t bytes, uint32_t *val)
{ {
struct pci_vdev *vdev = partition_mode_find_vdev(vpci, vbdf); struct pci_vdev *vdev = partition_mode_find_vdev(vpci, vbdf);
if ((vdev != NULL) && (vdev->ops != NULL) if ((vdev != NULL) && (vdev->ops != NULL)
&& (vdev->ops->cfgread != NULL)) { && (vdev->ops->cfgread != NULL)) {
(void)vdev->ops->cfgread(vdev, offset, bytes, val); (void)vdev->ops->cfgread(vdev, offset, bytes, val);
@ -108,6 +157,7 @@ static void partition_mode_cfgwrite(struct acrn_vpci *vpci, union pci_bdf vbdf,
uint32_t offset, uint32_t bytes, uint32_t val) uint32_t offset, uint32_t bytes, uint32_t val)
{ {
struct pci_vdev *vdev = partition_mode_find_vdev(vpci, vbdf); struct pci_vdev *vdev = partition_mode_find_vdev(vpci, vbdf);
if ((vdev != NULL) && (vdev->ops != NULL) if ((vdev != NULL) && (vdev->ops != NULL)
&& (vdev->ops->cfgwrite != NULL)) { && (vdev->ops->cfgwrite != NULL)) {
(void)vdev->ops->cfgwrite(vdev, offset, bytes, val); (void)vdev->ops->cfgwrite(vdev, offset, bytes, val);

View File

@ -401,3 +401,17 @@ void pci_pdev_foreach(pci_pdev_enumeration_cb cb_func, const void *ctx)
} }
} }
struct pci_pdev *find_pci_pdev(union pci_bdf pbdf)
{
struct pci_pdev *pdev = NULL;
uint32_t i;
for (i = 0U; i < num_pci_pdev; i++) {
if (pci_pdev_array[i].bdf.value == pbdf.value) {
pdev = &pci_pdev_array[i];
break;
}
}
return pdev;
}

View File

@ -225,6 +225,7 @@ void pci_pdev_write_cfg(union pci_bdf bdf, uint32_t offset, uint32_t bytes, uint
void enable_disable_pci_intx(union pci_bdf bdf, bool enable); void enable_disable_pci_intx(union pci_bdf bdf, bool enable);
void pci_pdev_foreach(pci_pdev_enumeration_cb cb, const void *ctx); void pci_pdev_foreach(pci_pdev_enumeration_cb cb, const void *ctx);
struct pci_pdev *find_pci_pdev(union pci_bdf pbdf);
void init_pci_pdev_list(void); void init_pci_pdev_list(void);