HV: unify the sharing_mode_cfgread and partition_mode_cfgread code
Put the cfgread code in read_cfg() for both sos and pre-launched VMs, and remove sharing_mode_cfgread() and partition_mode_cfgread(). Rename functions used by read_cfg(): vhostbridge_cfgread --> vhostbridge_read_cfg vdev_pt_cfgread --> vdev_pt_read_cfg vmsi_cfgread --> vmsi_read_cfg vmsix_cfgread --> vmsix_read_cfg Tracked-On: #3056 Signed-off-by: dongshen <dongsheng.x.zhang@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com> Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>
This commit is contained in:
parent
19af3bc8aa
commit
7635a68f38
|
@ -43,8 +43,10 @@ static inline uint32_t get_bar_base(uint32_t bar)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @pre vdev != NULL
|
* @pre vdev != NULL
|
||||||
|
* @pre vdev->vpci != NULL
|
||||||
|
* @pre vdev->vpci->vm != NULL
|
||||||
*/
|
*/
|
||||||
int32_t vdev_pt_cfgread(const struct pci_vdev *vdev, uint32_t offset,
|
int32_t vdev_pt_read_cfg(const struct pci_vdev *vdev, uint32_t offset,
|
||||||
uint32_t bytes, uint32_t *val)
|
uint32_t bytes, uint32_t *val)
|
||||||
{
|
{
|
||||||
int32_t ret = -ENODEV;
|
int32_t ret = -ENODEV;
|
||||||
|
|
|
@ -102,7 +102,7 @@ void deinit_vhostbridge(__unused const struct pci_vdev *vdev)
|
||||||
* @pre vdev->vpci != NULL
|
* @pre vdev->vpci != NULL
|
||||||
* @pre vdev->vpci->vm != NULL
|
* @pre vdev->vpci->vm != NULL
|
||||||
*/
|
*/
|
||||||
int32_t vhostbridge_cfgread(const struct pci_vdev *vdev, uint32_t offset,
|
int32_t vhostbridge_read_cfg(const struct pci_vdev *vdev, uint32_t offset,
|
||||||
uint32_t bytes, uint32_t *val)
|
uint32_t bytes, uint32_t *val)
|
||||||
{
|
{
|
||||||
int32_t ret = -ENODEV;
|
int32_t ret = -ENODEV;
|
||||||
|
|
|
@ -115,7 +115,10 @@ static int32_t vmsi_remap(const struct pci_vdev *vdev, bool enable)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vmsi_cfgread(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val)
|
/**
|
||||||
|
* @pre vdev != NULL
|
||||||
|
*/
|
||||||
|
int32_t vmsi_read_cfg(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val)
|
||||||
{
|
{
|
||||||
int32_t ret = -ENODEV;
|
int32_t ret = -ENODEV;
|
||||||
|
|
||||||
|
|
|
@ -158,7 +158,10 @@ static int32_t vmsix_remap_one_entry(const struct pci_vdev *vdev, uint32_t index
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vmsix_cfgread(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val)
|
/**
|
||||||
|
* @pre vdev != NULL
|
||||||
|
*/
|
||||||
|
int32_t vmsix_read_cfg(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val)
|
||||||
{
|
{
|
||||||
int32_t ret = -ENODEV;
|
int32_t ret = -ENODEV;
|
||||||
/* For PIO access, we emulate Capability Structures only */
|
/* For PIO access, we emulate Capability Structures only */
|
||||||
|
|
|
@ -38,6 +38,7 @@ static void init_vdev_for_pdev(struct pci_pdev *pdev, const void *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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @pre pi != NULL
|
* @pre pi != NULL
|
||||||
|
@ -106,9 +107,10 @@ static inline bool vpci_is_valid_access(uint32_t offset, uint32_t bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @pre vm != NULL && vcpu != NULL
|
* @pre vm != NULL
|
||||||
|
* @pre vcpu != NULL
|
||||||
* @pre vm->vm_id < CONFIG_MAX_VM_NUM
|
* @pre vm->vm_id < CONFIG_MAX_VM_NUM
|
||||||
* @pre (get_vm_config(vm->vm_id)->type == PRE_LAUNCHED_VM) || (get_vm_config(vm->vm_id)->type == SOS_VM)
|
* @pre (get_vm_config(vm->vm_id)->load_order == PRE_LAUNCHED_VM) || (get_vm_config(vm->vm_id)->load_order == SOS_VM)
|
||||||
*/
|
*/
|
||||||
static bool pci_cfgdata_io_read(struct acrn_vm *vm, struct acrn_vcpu *vcpu, uint16_t addr, size_t bytes)
|
static bool pci_cfgdata_io_read(struct acrn_vm *vm, struct acrn_vcpu *vcpu, uint16_t addr, size_t bytes)
|
||||||
{
|
{
|
||||||
|
@ -125,11 +127,8 @@ static bool pci_cfgdata_io_read(struct acrn_vm *vm, struct acrn_vcpu *vcpu, uint
|
||||||
|
|
||||||
switch (vm_config->load_order) {
|
switch (vm_config->load_order) {
|
||||||
case PRE_LAUNCHED_VM:
|
case PRE_LAUNCHED_VM:
|
||||||
partition_mode_cfgread(vpci, pi->cached_bdf, pi->cached_reg + offset, bytes, &val);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SOS_VM:
|
case SOS_VM:
|
||||||
sharing_mode_cfgread(vpci, pi->cached_bdf, pi->cached_reg + offset, bytes, &val);
|
read_cfg(vpci, pi->cached_bdf, pi->cached_reg + offset, bytes, &val);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -305,29 +304,6 @@ static void remove_vdev_pt_iommu_domain(const struct pci_vdev *vdev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @pre vpci != NULL
|
|
||||||
*/
|
|
||||||
void partition_mode_cfgread(const struct acrn_vpci *vpci, union pci_bdf vbdf,
|
|
||||||
uint32_t offset, uint32_t bytes, uint32_t *val)
|
|
||||||
{
|
|
||||||
struct pci_vdev *vdev = pci_find_vdev_by_vbdf(vpci, vbdf);
|
|
||||||
|
|
||||||
if (vdev != NULL) {
|
|
||||||
if (is_hostbridge(vdev)) {
|
|
||||||
(void)vhostbridge_cfgread(vdev, offset, bytes, val);
|
|
||||||
} else {
|
|
||||||
if ((vdev_pt_cfgread(vdev, offset, bytes, val) != 0)
|
|
||||||
&& (vmsi_cfgread(vdev, offset, bytes, val) != 0)
|
|
||||||
&& (vmsix_cfgread(vdev, offset, bytes, val) != 0)
|
|
||||||
) {
|
|
||||||
/* Not handled by any handlers, passthru to physical device */
|
|
||||||
*val = pci_pdev_read_cfg(vdev->pdev->bdf, offset, bytes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @pre vpci != NULL
|
* @pre vpci != NULL
|
||||||
*/
|
*/
|
||||||
|
@ -362,22 +338,38 @@ static struct pci_vdev *find_vdev_for_sos(union pci_bdf bdf)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @pre vpci != NULL
|
* @pre vpci != NULL
|
||||||
|
* @pre vpci->vm != NULL
|
||||||
*/
|
*/
|
||||||
void sharing_mode_cfgread(__unused struct acrn_vpci *vpci, union pci_bdf bdf,
|
static struct pci_vdev *find_vdev(const struct acrn_vpci *vpci, union pci_bdf bdf)
|
||||||
|
{
|
||||||
|
struct pci_vdev *vdev = NULL;
|
||||||
|
|
||||||
|
if (is_prelaunched_vm(vpci->vm)) {
|
||||||
|
vdev = pci_find_vdev_by_vbdf(vpci, bdf);
|
||||||
|
} else if (is_sos_vm(vpci->vm)){
|
||||||
|
vdev = find_vdev_for_sos(bdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
return vdev;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @pre vpci != NULL
|
||||||
|
*/
|
||||||
|
static void read_cfg(const struct acrn_vpci *vpci, union pci_bdf bdf,
|
||||||
uint32_t offset, uint32_t bytes, uint32_t *val)
|
uint32_t offset, uint32_t bytes, uint32_t *val)
|
||||||
{
|
{
|
||||||
struct pci_vdev *vdev = find_vdev_for_sos(bdf);
|
struct pci_vdev *vdev = find_vdev(vpci, bdf);
|
||||||
|
|
||||||
*val = ~0U;
|
|
||||||
|
|
||||||
/* vdev == NULL: Could be hit for PCI enumeration from guests */
|
|
||||||
if (vdev != NULL) {
|
if (vdev != NULL) {
|
||||||
if ((vmsi_cfgread(vdev, offset, bytes, val) != 0)
|
if ((vhostbridge_read_cfg(vdev, offset, bytes, val) != 0)
|
||||||
&& (vmsix_cfgread(vdev, offset, bytes, val) != 0)
|
&& (vdev_pt_read_cfg(vdev, offset, bytes, val) != 0)
|
||||||
|
&& (vmsi_read_cfg(vdev, offset, bytes, val) != 0)
|
||||||
|
&& (vmsix_read_cfg(vdev, offset, bytes, val) != 0)
|
||||||
) {
|
) {
|
||||||
/* Not handled by any handlers, passthru to physical device */
|
/* Not handled by any handlers, passthru to physical device */
|
||||||
*val = pci_pdev_read_cfg(vdev->pdev->bdf, offset, bytes);
|
*val = pci_pdev_read_cfg(vdev->pdev->bdf, offset, bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,23 +84,23 @@ static inline bool is_hostbridge(const struct pci_vdev *vdev)
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_vhostbridge(struct pci_vdev *vdev);
|
void init_vhostbridge(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_read_cfg(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);
|
||||||
void deinit_vhostbridge(__unused const struct pci_vdev *vdev);
|
void deinit_vhostbridge(__unused const struct pci_vdev *vdev);
|
||||||
|
|
||||||
void init_vdev_pt(struct pci_vdev *vdev);
|
void init_vdev_pt(struct pci_vdev *vdev);
|
||||||
int32_t vdev_pt_cfgread(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val);
|
int32_t vdev_pt_read_cfg(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val);
|
||||||
int32_t vdev_pt_cfgwrite(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val);
|
int32_t vdev_pt_cfgwrite(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val);
|
||||||
|
|
||||||
void init_vmsi(struct pci_vdev *vdev);
|
void init_vmsi(struct pci_vdev *vdev);
|
||||||
int32_t vmsi_cfgread(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val);
|
int32_t vmsi_read_cfg(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val);
|
||||||
int32_t vmsi_cfgwrite(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val);
|
int32_t vmsi_cfgwrite(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val);
|
||||||
void deinit_vmsi(const struct pci_vdev *vdev);
|
void deinit_vmsi(const struct pci_vdev *vdev);
|
||||||
|
|
||||||
void init_vmsix(struct pci_vdev *vdev);
|
void init_vmsix(struct pci_vdev *vdev);
|
||||||
void vdev_pt_remap_msix_table_bar(struct pci_vdev *vdev);
|
void vdev_pt_remap_msix_table_bar(struct pci_vdev *vdev);
|
||||||
int32_t vmsix_table_mmio_access_handler(struct io_request *io_req, void *handler_private_data);
|
int32_t vmsix_table_mmio_access_handler(struct io_request *io_req, void *handler_private_data);
|
||||||
int32_t vmsix_cfgread(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val);
|
int32_t vmsix_read_cfg(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val);
|
||||||
int32_t vmsix_cfgwrite(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val);
|
int32_t vmsix_cfgwrite(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val);
|
||||||
void deinit_vmsix(const struct pci_vdev *vdev);
|
void deinit_vmsix(const struct pci_vdev *vdev);
|
||||||
|
|
||||||
|
@ -111,13 +111,9 @@ struct pci_vdev *pci_find_vdev_by_vbdf(const struct acrn_vpci *vpci, union pci_b
|
||||||
|
|
||||||
struct pci_vdev *pci_find_vdev_by_pbdf(const struct acrn_vpci *vpci, union pci_bdf pbdf);
|
struct pci_vdev *pci_find_vdev_by_pbdf(const struct acrn_vpci *vpci, union pci_bdf pbdf);
|
||||||
|
|
||||||
void partition_mode_cfgread(const struct acrn_vpci *vpci, union pci_bdf vbdf,
|
|
||||||
uint32_t offset, uint32_t bytes, uint32_t *val);
|
|
||||||
void partition_mode_cfgwrite(const struct acrn_vpci *vpci, union pci_bdf vbdf,
|
void partition_mode_cfgwrite(const 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);
|
||||||
|
|
||||||
void sharing_mode_cfgread(struct acrn_vpci *vpci, union pci_bdf bdf,
|
|
||||||
uint32_t offset, uint32_t bytes, uint32_t *val);
|
|
||||||
void sharing_mode_cfgwrite(__unused struct acrn_vpci *vpci, union pci_bdf bdf,
|
void sharing_mode_cfgwrite(__unused struct acrn_vpci *vpci, union pci_bdf bdf,
|
||||||
uint32_t offset, uint32_t bytes, uint32_t val);
|
uint32_t offset, uint32_t bytes, uint32_t val);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue