mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-02 09:25:17 +00:00
hv: vpci: refine init_vdevs
Now almost the vPCI device information could be obtain from PCI device configure in VM configure. init_vdevs could make things more easier. And rename init_vdevs to vpci_init_vdevs, init_vdev to vpci_init_vdevs to avoid MISRA-C violations. Tracked-On: #3475 Signed-off-by: Li, Fei1 <fei1.li@intel.com> Reviewed-by: Eddie Dong <eddie.dong@intel.com> Reviewed-by: Dongsheng Zhang <dongsheng.x.zhang@intel.com>
This commit is contained in:
committed by
ACRN System Integration
parent
eb21f205e4
commit
599a058403
@@ -33,8 +33,9 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <logmsg.h>
|
#include <logmsg.h>
|
||||||
#include "vpci_priv.h"
|
#include "vpci_priv.h"
|
||||||
|
#include "pci_dev.h"
|
||||||
|
|
||||||
static void init_vdevs(const struct acrn_vm *vm);
|
static void vpci_init_vdevs(struct acrn_vm *vm);
|
||||||
static void deinit_prelaunched_vm_vpci(const struct acrn_vm *vm);
|
static void deinit_prelaunched_vm_vpci(const struct acrn_vm *vm);
|
||||||
static void deinit_postlaunched_vm_vpci(const struct acrn_vm *vm);
|
static void deinit_postlaunched_vm_vpci(const struct acrn_vm *vm);
|
||||||
static void read_cfg(const struct acrn_vpci *vpci, union pci_bdf bdf, uint32_t offset, uint32_t bytes, uint32_t *val);
|
static void read_cfg(const struct acrn_vpci *vpci, union pci_bdf bdf, uint32_t offset, uint32_t bytes, uint32_t *val);
|
||||||
@@ -209,7 +210,7 @@ void vpci_init(struct acrn_vm *vm)
|
|||||||
case SOS_VM:
|
case SOS_VM:
|
||||||
vm->iommu = create_iommu_domain(vm->vm_id, hva2hpa(vm->arch_vm.nworld_eptp), 48U);
|
vm->iommu = create_iommu_domain(vm->vm_id, hva2hpa(vm->arch_vm.nworld_eptp), 48U);
|
||||||
/* Build up vdev list for vm */
|
/* Build up vdev list for vm */
|
||||||
init_vdevs(vm);
|
vpci_init_vdevs(vm);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -419,79 +420,42 @@ static void write_cfg(const struct acrn_vpci *vpci, union pci_bdf bdf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @pre vm_config != NULL
|
* @pre vpci != NULL
|
||||||
* @pre vm_config->pci_dev_num <= CONFIG_MAX_PCI_DEV_NUM
|
* @pre vpci.pci_vdev_cnt <= CONFIG_MAX_PCI_DEV_NUM
|
||||||
*/
|
*/
|
||||||
static struct acrn_vm_pci_dev_config *find_pci_dev_config(const struct acrn_vm_config *vm_config,
|
static void vpci_init_vdev(struct acrn_vpci *vpci, struct acrn_vm_pci_dev_config *dev_config)
|
||||||
union pci_bdf pbdf)
|
|
||||||
{
|
{
|
||||||
struct acrn_vm_pci_dev_config *pci_dev_config, *tmp;
|
struct pci_vdev *vdev = &vpci->pci_vdevs[vpci->pci_vdev_cnt];
|
||||||
uint16_t i;
|
|
||||||
|
|
||||||
pci_dev_config = NULL;
|
vpci->pci_vdev_cnt++;
|
||||||
for (i = 0U; i < vm_config->pci_dev_num; i++) {
|
vdev->vpci = vpci;
|
||||||
tmp = &vm_config->pci_devs[i];
|
vdev->bdf.value = dev_config->vbdf.value;
|
||||||
|
vdev->pdev = dev_config->pdev;
|
||||||
|
vdev->pci_dev_config = dev_config;
|
||||||
|
|
||||||
if (bdf_is_equal(&tmp->pbdf, &pbdf)) {
|
if (dev_config->emu_type == PCI_DEV_TYPE_PTDEV) {
|
||||||
pci_dev_config = tmp;
|
vdev->vdev_ops = &pci_pt_dev_ops;
|
||||||
break;
|
ASSERT(dev_config->pdev != NULL,
|
||||||
}
|
"PCI PTDev %x:%x.%x is not present in the platform!",
|
||||||
|
dev_config->pbdf.b, dev_config->pbdf.d, dev_config->pbdf.f);
|
||||||
|
} else {
|
||||||
|
vdev->vdev_ops = get_vhostbridge_ops();
|
||||||
}
|
}
|
||||||
|
|
||||||
return pci_dev_config;
|
vdev->vdev_ops->init_vdev(vdev);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @pre pdev != NULL
|
|
||||||
* @pre vm != NULL
|
|
||||||
* @pre vm->vpci.pci_vdev_cnt <= CONFIG_MAX_PCI_DEV_NUM
|
|
||||||
*/
|
|
||||||
static void init_vdev_for_pdev(struct pci_pdev *pdev, const struct acrn_vm *vm)
|
|
||||||
{
|
|
||||||
const struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id);
|
|
||||||
struct acrn_vpci *vpci = &(((struct acrn_vm *)vm)->vpci);
|
|
||||||
struct acrn_vm_pci_dev_config *pci_dev_config;
|
|
||||||
|
|
||||||
pci_dev_config = find_pci_dev_config(vm_config, pdev->bdf);
|
|
||||||
|
|
||||||
if (((is_prelaunched_vm(vm) && (pci_dev_config != NULL)) || is_sos_vm(vm))
|
|
||||||
&& (vpci->pci_vdev_cnt < CONFIG_MAX_PCI_DEV_NUM)) {
|
|
||||||
struct pci_vdev *vdev;
|
|
||||||
|
|
||||||
vdev = &vpci->pci_vdevs[vpci->pci_vdev_cnt];
|
|
||||||
vpci->pci_vdev_cnt++;
|
|
||||||
|
|
||||||
vdev->vpci = vpci;
|
|
||||||
vdev->pdev = pdev;
|
|
||||||
vdev->pci_dev_config = pci_dev_config;
|
|
||||||
|
|
||||||
if (pci_dev_config != NULL) {
|
|
||||||
/* vbdf is defined in vm_config */
|
|
||||||
vdev->bdf.value = pci_dev_config->vbdf.value;
|
|
||||||
} else {
|
|
||||||
/* vbdf is not defined in vm_config, set it to equal to pbdf */
|
|
||||||
vdev->bdf.value = pdev->bdf.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_hostbridge(vdev)) {
|
|
||||||
vdev->vdev_ops = get_vhostbridge_ops();
|
|
||||||
} else {
|
|
||||||
vdev->vdev_ops = &pci_pt_dev_ops;
|
|
||||||
}
|
|
||||||
|
|
||||||
vdev->vdev_ops->init_vdev(vdev);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @pre vm != NULL
|
* @pre vm != NULL
|
||||||
*/
|
*/
|
||||||
static void init_vdevs(const struct acrn_vm *vm)
|
static void vpci_init_vdevs(struct acrn_vm *vm)
|
||||||
{
|
{
|
||||||
uint32_t idx;
|
uint32_t idx;
|
||||||
|
struct acrn_vpci *vpci = &(vm->vpci);
|
||||||
|
const struct acrn_vm_config *vm_config = get_vm_config(vpci->vm->vm_id);
|
||||||
|
|
||||||
for (idx = 0U; idx < num_pci_pdev; idx++) {
|
for (idx = 0U; idx < vm_config->pci_dev_num; idx++) {
|
||||||
init_vdev_for_pdev(&pci_pdev_array[idx], vm);
|
vpci_init_vdev(vpci, &vm_config->pci_devs[idx]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -125,14 +125,6 @@ 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @pre vdev != NULL
|
|
||||||
*/
|
|
||||||
static inline bool is_hostbridge(const struct pci_vdev *vdev)
|
|
||||||
{
|
|
||||||
return (vdev->bdf.value == 0U);
|
|
||||||
}
|
|
||||||
|
|
||||||
void init_vdev_pt(struct pci_vdev *vdev);
|
void init_vdev_pt(struct pci_vdev *vdev);
|
||||||
void vdev_pt_read_cfg(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val);
|
void vdev_pt_read_cfg(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val);
|
||||||
void vdev_pt_write_cfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val);
|
void vdev_pt_write_cfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val);
|
||||||
|
@@ -37,8 +37,8 @@
|
|||||||
#include <pci_dev.h>
|
#include <pci_dev.h>
|
||||||
|
|
||||||
static spinlock_t pci_device_lock;
|
static spinlock_t pci_device_lock;
|
||||||
uint32_t num_pci_pdev;
|
static uint32_t num_pci_pdev;
|
||||||
struct pci_pdev pci_pdev_array[CONFIG_MAX_PCI_DEV_NUM];
|
static struct pci_pdev pci_pdev_array[CONFIG_MAX_PCI_DEV_NUM];
|
||||||
|
|
||||||
static void init_pdev(uint16_t pbdf);
|
static void init_pdev(uint16_t pbdf);
|
||||||
|
|
||||||
|
@@ -218,10 +218,6 @@ struct pci_pdev {
|
|||||||
struct pci_msix_cap msix;
|
struct pci_msix_cap msix;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern uint32_t num_pci_pdev;
|
|
||||||
extern struct pci_pdev pci_pdev_array[CONFIG_MAX_PCI_DEV_NUM];
|
|
||||||
|
|
||||||
|
|
||||||
static inline uint32_t pci_bar_offset(uint32_t idx)
|
static inline uint32_t pci_bar_offset(uint32_t idx)
|
||||||
{
|
{
|
||||||
return PCIR_BARS + (idx << 2U);
|
return PCIR_BARS + (idx << 2U);
|
||||||
|
Reference in New Issue
Block a user