HV: move pci_vdevs[] array from vm.h to vpci.h

pci_vdevs is vpci stuff so it would be better to make it managed by vpci rather than by vm.h,
both sharing mode and partition mode can use pci_vdevs[] to maintain its own
per vm vdev list.

Tracked-On: #2534
Signed-off-by: dongshen <dongsheng.x.zhang@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
dongshen 2019-02-25 13:34:02 -08:00 committed by Eddie Dong
parent 8c3cfe62aa
commit 00f9b85072
3 changed files with 31 additions and 17 deletions

View File

@ -33,15 +33,18 @@
#include <logmsg.h>
#include "pci_priv.h"
static struct pci_vdev *partition_mode_find_vdev(struct acrn_vpci *vpci, union pci_bdf vbdf)
/**
* @pre tmp != NULL
*/
static struct pci_vdev *partition_mode_find_vdev(const struct acrn_vpci *vpci, union pci_bdf vbdf)
{
struct pci_vdev *vdev, *tmp;
struct acrn_vm_config *vm_config = get_vm_config(vpci->vm->vm_id);
int32_t i;
uint32_t i;
vdev = NULL;
for (i = 0; i < vm_config->pci_ptdev_num; i++) {
tmp = &vpci->vm->pci_vdevs[i];
for (i = 0U; i < vpci->pci_vdev_cnt; i++) {
tmp = (struct pci_vdev *)&(vpci->pci_vdevs[i]);
if (bdf_is_equal(&(tmp->vbdf), &vbdf)) {
vdev = tmp;
@ -95,18 +98,27 @@ static void partition_mode_pdev_init(struct pci_vdev *vdev, union pci_bdf pbdf)
}
}
/**
* @pre vm != NULL
* @pre vm->vpci->pci_vdev_cnt <= CONFIG_MAX_PCI_DEV_NUM
* @pre vm_config != NULL
* @pre vdev != NULL
* @pre ptdev_config != NULL
*/
static int32_t partition_mode_vpci_init(const struct acrn_vm *vm)
{
const struct acrn_vpci *vpci = &vm->vpci;
struct acrn_vpci *vpci = (struct acrn_vpci *)&(vm->vpci);
struct pci_vdev *vdev;
struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id);
struct acrn_vm_pci_ptdev_config *ptdev_config;
int32_t i;
uint32_t i;
for (i = 0; i < vm_config->pci_ptdev_num; i++) {
vdev = (struct pci_vdev *)&vm->pci_vdevs[i];
ptdev_config = vm_config->pci_ptdevs + i;
vpci->pci_vdev_cnt = vm_config->pci_ptdev_num;
for (i = 0U; i < vpci->pci_vdev_cnt; i++) {
vdev = &vpci->pci_vdevs[i];
vdev->vpci = vpci;
ptdev_config = &vm_config->pci_ptdevs[i];
vdev->vbdf.value = ptdev_config->vbdf.value;
if (vdev->vbdf.value != 0U) {
@ -127,14 +139,16 @@ static int32_t partition_mode_vpci_init(const struct acrn_vm *vm)
return 0;
}
/**
* @pre vdev != NULL
*/
static void partition_mode_vpci_deinit(const struct acrn_vm *vm)
{
struct pci_vdev *vdev;
struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id);
int32_t i;
uint32_t i;
for (i = 0; i < vm_config->pci_ptdev_num; i++) {
vdev = (struct pci_vdev *)&vm->pci_vdevs[i];
for (i = 0U; i < vm->vpci.pci_vdev_cnt; i++) {
vdev = (struct pci_vdev *) &(vm->vpci.pci_vdevs[i]);
if ((vdev->ops != NULL) && (vdev->ops->deinit != NULL)) {
if (vdev->ops->deinit(vdev) != 0) {
pr_err("vdev->ops->deinit failed!");

View File

@ -146,10 +146,9 @@ struct acrn_vm {
uint32_t vcpuid_entry_nr, vcpuid_level, vcpuid_xlevel;
struct vcpuid_entry vcpuid_entries[MAX_VM_VCPUID_ENTRIES];
struct acrn_vpci vpci;
#ifdef CONFIG_PARTITION_MODE
struct mptable_info mptable;
struct pci_vdev pci_vdevs[CONFIG_MAX_PCI_DEV_NUM];
/* the valid number of pci_vdevs[] is vm_config->pci_ptdev_num */
uint8_t vrtc_offset;
#endif

View File

@ -119,11 +119,12 @@ struct vpci_ops {
uint32_t bytes, uint32_t val);
};
struct acrn_vpci {
struct acrn_vm *vm;
struct pci_addr_info addr_info;
const struct vpci_ops *ops;
uint32_t pci_vdev_cnt;
struct pci_vdev pci_vdevs[CONFIG_MAX_PCI_DEV_NUM];
};
#ifdef CONFIG_PARTITION_MODE