mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-22 21:47:22 +00:00
HV: use is_prelaunched_vm/is_hostbridge to check if the code is only for pre-launched VMs
Currently host bridge emulation and bar emulation are only for pre-launched vms, use is_prelaunched_vm to check if it is for pre-launched vms when calling init/deinit/cfgread/cfgwrite, also use is_hostbridge() to check if the access if for host bridge, so that these functions can be unified for sos and pre-launched vm in subsequent commits. Move is_hostbridge function to vpci_priv.h so that it can be used by multiple files. vhostbridge_cfgread/vhostbridge_cfgwrite: return -ENODEV if the pci cfg access is not targeted for vhostbridge so that cfgread/cfgwrite functions can be unified for sos and pre-launched vm in subsequent commits Fix @pre for functions Tracked-On: #3056 Signed-off-by: dongshen <dongsheng.x.zhang@intel.com> Reviewed-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
parent
a97e6e6465
commit
cf48b9c38f
@ -50,7 +50,7 @@ int32_t vdev_pt_cfgread(const struct pci_vdev *vdev, uint32_t offset,
|
|||||||
int32_t ret = -ENODEV;
|
int32_t ret = -ENODEV;
|
||||||
|
|
||||||
/* PCI BARs is emulated */
|
/* PCI BARs is emulated */
|
||||||
if (pci_bar_access(offset)) {
|
if (is_prelaunched_vm(vdev->vpci->vm) && pci_bar_access(offset)) {
|
||||||
*val = pci_vdev_read_cfg(vdev, offset, bytes);
|
*val = pci_vdev_read_cfg(vdev, offset, bytes);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
@ -254,7 +254,7 @@ int32_t vdev_pt_cfgwrite(struct pci_vdev *vdev, uint32_t offset,
|
|||||||
int32_t ret = -ENODEV;
|
int32_t ret = -ENODEV;
|
||||||
|
|
||||||
/* PCI BARs are emulated */
|
/* PCI BARs are emulated */
|
||||||
if (pci_bar_access(offset)) {
|
if (is_prelaunched_vm(vdev->vpci->vm) && pci_bar_access(offset)) {
|
||||||
vdev_pt_cfgwrite_bar(vdev, offset, bytes, val);
|
vdev_pt_cfgwrite_bar(vdev, offset, bytes, val);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
@ -36,10 +36,18 @@
|
|||||||
|
|
||||||
#include <vm.h>
|
#include <vm.h>
|
||||||
#include <pci.h>
|
#include <pci.h>
|
||||||
|
#include <errno.h>
|
||||||
#include "vpci_priv.h"
|
#include "vpci_priv.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @pre vdev != NULL
|
||||||
|
* @pre vdev->vpci != NULL
|
||||||
|
* @pre vdev->vpci->vm != NULL
|
||||||
|
*/
|
||||||
void vhostbridge_init(struct pci_vdev *vdev)
|
void vhostbridge_init(struct pci_vdev *vdev)
|
||||||
{
|
{
|
||||||
|
if (is_hostbridge(vdev) && is_prelaunched_vm(vdev->vpci->vm)) {
|
||||||
/* PCI config space */
|
/* PCI config space */
|
||||||
pci_vdev_write_cfg_u16(vdev, PCIR_VENDOR, (uint16_t)0x8086U);
|
pci_vdev_write_cfg_u16(vdev, PCIR_VENDOR, (uint16_t)0x8086U);
|
||||||
pci_vdev_write_cfg_u16(vdev, PCIR_DEVICE, (uint16_t)0x5af0U);
|
pci_vdev_write_cfg_u16(vdev, PCIR_DEVICE, (uint16_t)0x5af0U);
|
||||||
@ -82,25 +90,49 @@ void vhostbridge_init(struct pci_vdev *vdev)
|
|||||||
pci_vdev_write_cfg_u8(vdev, 0xf6U, (uint8_t)0x1cU);
|
pci_vdev_write_cfg_u8(vdev, 0xf6U, (uint8_t)0x1cU);
|
||||||
pci_vdev_write_cfg_u8(vdev, 0xf7U, (uint8_t)0x1U);
|
pci_vdev_write_cfg_u8(vdev, 0xf7U, (uint8_t)0x1U);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void vhostbridge_deinit(__unused const struct pci_vdev *vdev)
|
void vhostbridge_deinit(__unused const struct pci_vdev *vdev)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @pre vdev != NULL
|
||||||
|
* @pre vdev->vpci != NULL
|
||||||
|
* @pre vdev->vpci->vm != NULL
|
||||||
|
*/
|
||||||
int32_t vhostbridge_cfgread(const struct pci_vdev *vdev, uint32_t offset,
|
int32_t vhostbridge_cfgread(const struct pci_vdev *vdev, uint32_t offset,
|
||||||
uint32_t bytes, uint32_t *val)
|
uint32_t bytes, uint32_t *val)
|
||||||
{
|
{
|
||||||
*val = pci_vdev_read_cfg(vdev, offset, bytes);
|
int32_t ret = -ENODEV;
|
||||||
|
|
||||||
return 0;
|
if (is_hostbridge(vdev) && is_prelaunched_vm(vdev->vpci->vm)) {
|
||||||
|
*val = pci_vdev_read_cfg(vdev, offset, bytes);
|
||||||
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @pre vdev != NULL
|
||||||
|
* @pre vdev->vpci != NULL
|
||||||
|
* @pre vdev->vpci->vm != NULL
|
||||||
|
*/
|
||||||
int32_t vhostbridge_cfgwrite(struct pci_vdev *vdev, uint32_t offset,
|
int32_t vhostbridge_cfgwrite(struct pci_vdev *vdev, uint32_t offset,
|
||||||
uint32_t bytes, uint32_t val)
|
uint32_t bytes, uint32_t val)
|
||||||
{
|
{
|
||||||
|
int32_t ret = -ENODEV;
|
||||||
|
|
||||||
|
if (is_hostbridge(vdev) && is_prelaunched_vm(vdev->vpci->vm)) {
|
||||||
if (!pci_bar_access(offset)) {
|
if (!pci_bar_access(offset)) {
|
||||||
pci_vdev_write_cfg(vdev, offset, bytes, val);
|
pci_vdev_write_cfg(vdev, offset, bytes, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
ret = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -260,14 +260,6 @@ void vpci_cleanup(const struct acrn_vm *vm)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @pre vdev != NULL
|
|
||||||
*/
|
|
||||||
static inline bool is_hostbridge(const struct pci_vdev *vdev)
|
|
||||||
{
|
|
||||||
return (vdev->vbdf.value == 0U);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @pre vdev != NULL
|
* @pre vdev != NULL
|
||||||
* @pre vdev->vpci != NULL
|
* @pre vdev->vpci != NULL
|
||||||
|
@ -75,6 +75,14 @@ static inline bool has_msix_cap(const struct pci_vdev *vdev)
|
|||||||
return (vdev->msix.capoff != 0U);
|
return (vdev->msix.capoff != 0U);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @pre vdev != NULL
|
||||||
|
*/
|
||||||
|
static inline bool is_hostbridge(const struct pci_vdev *vdev)
|
||||||
|
{
|
||||||
|
return (vdev->vbdf.value == 0U);
|
||||||
|
}
|
||||||
|
|
||||||
void vhostbridge_init(struct pci_vdev *vdev);
|
void vhostbridge_init(struct pci_vdev *vdev);
|
||||||
int32_t vhostbridge_cfgread(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val);
|
int32_t vhostbridge_cfgread(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val);
|
||||||
int32_t vhostbridge_cfgwrite(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val);
|
int32_t vhostbridge_cfgwrite(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val);
|
||||||
|
Loading…
Reference in New Issue
Block a user