From b95780216452027487459f3fd3a81c1f60376416 Mon Sep 17 00:00:00 2001 From: dongshen Date: Tue, 14 May 2019 15:56:13 -0700 Subject: [PATCH] HV: unify the sharing_mode_cfgwrite and partition_mode_cfgwrite code Put the cfgwrite code in write_cfg() for both sos and pre-launched VMs, and remove sharing_mode_cfgwrite() and partition_mode_cfgwrite(). Rename functions used by write_cfg(): vhostbridge_cfgwrite --> vhostbridge_write_cfg vdev_pt_cfgwrite --> vdev_pt_write_cfg vmsi_cfgwrite --> vmsi_write_cfg vmsix_cfgwrite --> vmsix_write_cfg Fix @pre for functions Tracked-On: #3056 Signed-off-by: dongshen Acked-by: Eddie Dong Reviewed-by: Yin Fengwei --- hypervisor/dm/vpci/pci_pt.c | 4 ++- hypervisor/dm/vpci/vhostbridge.c | 2 +- hypervisor/dm/vpci/vmsi.c | 5 +++- hypervisor/dm/vpci/vmsix.c | 6 ++++- hypervisor/dm/vpci/vpci.c | 42 +++++++------------------------- hypervisor/dm/vpci/vpci_priv.h | 14 +++-------- 6 files changed, 26 insertions(+), 47 deletions(-) diff --git a/hypervisor/dm/vpci/pci_pt.c b/hypervisor/dm/vpci/pci_pt.c index f482400a3..b5cbc66d9 100644 --- a/hypervisor/dm/vpci/pci_pt.c +++ b/hypervisor/dm/vpci/pci_pt.c @@ -251,8 +251,10 @@ static void vdev_pt_cfgwrite_bar(struct pci_vdev *vdev, uint32_t offset, /** * @pre vdev != NULL + * @pre vdev->vpci != NULL + * @pre vdev->vpci->vm != NULL */ -int32_t vdev_pt_cfgwrite(struct pci_vdev *vdev, uint32_t offset, +int32_t vdev_pt_write_cfg(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 33fdbceec..b68ae5923 100644 --- a/hypervisor/dm/vpci/vhostbridge.c +++ b/hypervisor/dm/vpci/vhostbridge.c @@ -121,7 +121,7 @@ int32_t vhostbridge_read_cfg(const struct pci_vdev *vdev, uint32_t offset, * @pre vdev->vpci != NULL * @pre vdev->vpci->vm != NULL */ -int32_t vhostbridge_cfgwrite(struct pci_vdev *vdev, uint32_t offset, +int32_t vhostbridge_write_cfg(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 2044e36e3..eb95bf743 100644 --- a/hypervisor/dm/vpci/vmsi.c +++ b/hypervisor/dm/vpci/vmsi.c @@ -131,7 +131,10 @@ int32_t vmsi_read_cfg(const struct pci_vdev *vdev, uint32_t offset, uint32_t byt return ret; } -int32_t vmsi_cfgwrite(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val) +/** + * @pre vdev != NULL + */ +int32_t vmsi_write_cfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val) { bool message_changed = false; bool enable; diff --git a/hypervisor/dm/vpci/vmsix.c b/hypervisor/dm/vpci/vmsix.c index ec1ee9e28..58f8e6cce 100644 --- a/hypervisor/dm/vpci/vmsix.c +++ b/hypervisor/dm/vpci/vmsix.c @@ -174,7 +174,11 @@ int32_t vmsix_read_cfg(const struct pci_vdev *vdev, uint32_t offset, uint32_t by return ret; } -int32_t vmsix_cfgwrite(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val) +/** + * @pre vdev != NULL + * @pre vdev->pdev != NULL + */ +int32_t vmsix_write_cfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val) { uint32_t msgctrl; int32_t ret = -ENODEV; diff --git a/hypervisor/dm/vpci/vpci.c b/hypervisor/dm/vpci/vpci.c index 4ec810c5f..229fd48fe 100644 --- a/hypervisor/dm/vpci/vpci.c +++ b/hypervisor/dm/vpci/vpci.c @@ -37,8 +37,8 @@ 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); +static void write_cfg(const struct acrn_vpci *vpci, union pci_bdf bdf, uint32_t offset, uint32_t bytes, uint32_t val); /** * @pre pi != NULL @@ -163,11 +163,8 @@ static bool pci_cfgdata_io_write(struct acrn_vm *vm, uint16_t addr, size_t bytes switch (vm_config->load_order) { case PRE_LAUNCHED_VM: - partition_mode_cfgwrite(vpci, pi->cached_bdf, pi->cached_reg + offset, bytes, val); - break; - case SOS_VM: - sharing_mode_cfgwrite(vpci, pi->cached_bdf, pi->cached_reg + offset, bytes, val); + write_cfg(vpci, pi->cached_bdf, pi->cached_reg + offset, bytes, val); break; default: @@ -304,29 +301,6 @@ static void remove_vdev_pt_iommu_domain(const struct pci_vdev *vdev) } } -/** - * @pre vpci != NULL - */ -void partition_mode_cfgwrite(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_cfgwrite(vdev, offset, bytes, val); - } else { - if ((vdev_pt_cfgwrite(vdev, offset, bytes, val) != 0) - && (vmsi_cfgwrite(vdev, offset, bytes, val) != 0) - && (vmsix_cfgwrite(vdev, offset, bytes, val) != 0) - ) { - /* Not handled by any handlers, passthru to physical device */ - pci_pdev_write_cfg(vdev->pdev->bdf, offset, bytes, val); - } - } - } -} - static struct pci_vdev *find_vdev_for_sos(union pci_bdf bdf) { struct acrn_vm *vm; @@ -346,7 +320,7 @@ static struct pci_vdev *find_vdev(const struct acrn_vpci *vpci, union pci_bdf bd if (is_prelaunched_vm(vpci->vm)) { vdev = pci_find_vdev_by_vbdf(vpci, bdf); - } else if (is_sos_vm(vpci->vm)){ + } else if (is_sos_vm(vpci->vm)) { vdev = find_vdev_for_sos(bdf); } @@ -376,14 +350,16 @@ static void read_cfg(const struct acrn_vpci *vpci, union pci_bdf bdf, /** * @pre vpci != NULL */ -void sharing_mode_cfgwrite(__unused struct acrn_vpci *vpci, union pci_bdf bdf, +static void write_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); if (vdev != NULL) { - if ((vmsi_cfgwrite(vdev, offset, bytes, val) != 0) - && (vmsix_cfgwrite(vdev, offset, bytes, val) != 0) + if ((vhostbridge_write_cfg(vdev, offset, bytes, val) != 0) + && (vdev_pt_write_cfg(vdev, offset, bytes, val) != 0) + && (vmsi_write_cfg(vdev, offset, bytes, val) != 0) + && (vmsix_write_cfg(vdev, offset, bytes, val) != 0) ) { /* Not handled by any handlers, passthru to physical device */ pci_pdev_write_cfg(vdev->pdev->bdf, offset, bytes, val); diff --git a/hypervisor/dm/vpci/vpci_priv.h b/hypervisor/dm/vpci/vpci_priv.h index c84a4af08..7a0ce14cc 100644 --- a/hypervisor/dm/vpci/vpci_priv.h +++ b/hypervisor/dm/vpci/vpci_priv.h @@ -85,23 +85,23 @@ static inline bool is_hostbridge(const struct pci_vdev *vdev) void init_vhostbridge(struct pci_vdev *vdev); 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_write_cfg(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_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_write_cfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val); void init_vmsi(struct pci_vdev *vdev); 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_write_cfg(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_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_write_cfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val); void deinit_vmsix(const struct pci_vdev *vdev); uint32_t pci_vdev_read_cfg(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes); @@ -111,10 +111,4 @@ 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_cfgwrite(const struct acrn_vpci *vpci, union pci_bdf vbdf, - 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); - #endif /* VPCI_PRIV_H_ */