diff --git a/hypervisor/dm/vpci/pci_pt.c b/hypervisor/dm/vpci/pci_pt.c index f08691d16..f482400a3 100644 --- a/hypervisor/dm/vpci/pci_pt.c +++ b/hypervisor/dm/vpci/pci_pt.c @@ -43,8 +43,10 @@ static inline uint32_t get_bar_base(uint32_t bar) /** * @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) { int32_t ret = -ENODEV; diff --git a/hypervisor/dm/vpci/vhostbridge.c b/hypervisor/dm/vpci/vhostbridge.c index 835f738c7..33fdbceec 100644 --- a/hypervisor/dm/vpci/vhostbridge.c +++ b/hypervisor/dm/vpci/vhostbridge.c @@ -102,7 +102,7 @@ void deinit_vhostbridge(__unused const struct pci_vdev *vdev) * @pre vdev->vpci != 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) { int32_t ret = -ENODEV; diff --git a/hypervisor/dm/vpci/vmsi.c b/hypervisor/dm/vpci/vmsi.c index 490797fb9..2044e36e3 100644 --- a/hypervisor/dm/vpci/vmsi.c +++ b/hypervisor/dm/vpci/vmsi.c @@ -115,7 +115,10 @@ static int32_t vmsi_remap(const struct pci_vdev *vdev, bool enable) 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; diff --git a/hypervisor/dm/vpci/vmsix.c b/hypervisor/dm/vpci/vmsix.c index 4ce9d239a..ec1ee9e28 100644 --- a/hypervisor/dm/vpci/vmsix.c +++ b/hypervisor/dm/vpci/vmsix.c @@ -158,7 +158,10 @@ static int32_t vmsix_remap_one_entry(const struct pci_vdev *vdev, uint32_t index 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; /* For PIO access, we emulate Capability Structures only */ diff --git a/hypervisor/dm/vpci/vpci.c b/hypervisor/dm/vpci/vpci.c index 620d5bb7a..4ec810c5f 100644 --- a/hypervisor/dm/vpci/vpci.c +++ b/hypervisor/dm/vpci/vpci.c @@ -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_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 @@ -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 (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) { @@ -125,11 +127,8 @@ static bool pci_cfgdata_io_read(struct acrn_vm *vm, struct acrn_vcpu *vcpu, uint switch (vm_config->load_order) { case PRE_LAUNCHED_VM: - partition_mode_cfgread(vpci, pi->cached_bdf, pi->cached_reg + offset, bytes, &val); - break; - 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; 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 */ @@ -362,22 +338,38 @@ static struct pci_vdev *find_vdev_for_sos(union pci_bdf bdf) /** * @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) { - 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 ((vmsi_cfgread(vdev, offset, bytes, val) != 0) - && (vmsix_cfgread(vdev, offset, bytes, val) != 0) + if ((vhostbridge_read_cfg(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 */ - *val = pci_pdev_read_cfg(vdev->pdev->bdf, offset, bytes); - } + /* Not handled by any handlers, passthru to physical device */ + *val = pci_pdev_read_cfg(vdev->pdev->bdf, offset, bytes); + } } } diff --git a/hypervisor/dm/vpci/vpci_priv.h b/hypervisor/dm/vpci/vpci_priv.h index cbe2cc8db..c84a4af08 100644 --- a/hypervisor/dm/vpci/vpci_priv.h +++ b/hypervisor/dm/vpci/vpci_priv.h @@ -84,23 +84,23 @@ static inline bool is_hostbridge(const 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); void deinit_vhostbridge(__unused const 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); 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); void deinit_vmsi(const struct pci_vdev *vdev); void init_vmsix(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_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); 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); -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, 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, uint32_t offset, uint32_t bytes, uint32_t val);