From 71ce4c255e0b006a9e7e2808554f67c5bbaad240 Mon Sep 17 00:00:00 2001 From: dongshen Date: Wed, 6 Mar 2019 16:54:01 -0800 Subject: [PATCH] HV: unify the sharing mode and partition mode coding style for similar functions Both sharing mode and partition mode should follow the same coding logic/style for similar functions: vdev cfgread/cfgwrite: should all return -ENODEV if the pci reg access is not handled by it, but previously the partition mode code is not following this logic vpci cfgread/cfgwrite: if the vdev cfgread/cfgwrite does not handle this reg, pass on to next vdev cfgread/cfgwrite, if no vdev handles that req, passthru to physical pci device Tracked-On: #2534 Signed-off-by: dongshen Acked-by: Eddie Dong --- hypervisor/dm/vpci/msi.c | 4 +--- hypervisor/dm/vpci/msix.c | 8 ++------ hypervisor/dm/vpci/partition_mode.c | 6 ++++-- hypervisor/dm/vpci/pci_pt.c | 15 ++++++++------- hypervisor/dm/vpci/sharing_mode.c | 11 ++++------- 5 files changed, 19 insertions(+), 25 deletions(-) diff --git a/hypervisor/dm/vpci/msi.c b/hypervisor/dm/vpci/msi.c index f3adea379..b0ab3a3a1 100644 --- a/hypervisor/dm/vpci/msi.c +++ b/hypervisor/dm/vpci/msi.c @@ -117,14 +117,12 @@ static int32_t vmsi_remap(const struct pci_vdev *vdev, bool enable) int32_t vmsi_cfgread(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val) { - int32_t ret; + int32_t ret = -ENODEV; /* For PIO access, we emulate Capability Structures only */ if (msicap_access(vdev, offset)) { *val = pci_vdev_read_cfg(vdev, offset, bytes); ret = 0; - } else { - ret = -ENODEV; } return ret; diff --git a/hypervisor/dm/vpci/msix.c b/hypervisor/dm/vpci/msix.c index 558cd79dd..87aae3235 100644 --- a/hypervisor/dm/vpci/msix.c +++ b/hypervisor/dm/vpci/msix.c @@ -167,14 +167,12 @@ static int32_t vmsix_remap_one_entry(const struct pci_vdev *vdev, uint32_t index int32_t vmsix_cfgread(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val) { - int32_t ret; + int32_t ret = -ENODEV; /* For PIO access, we emulate Capability Structures only */ if (msixcap_access(vdev, offset)) { *val = pci_vdev_read_cfg(vdev, offset, bytes); ret = 0; - } else { - ret = -ENODEV; } return ret; @@ -183,7 +181,7 @@ int32_t vmsix_cfgread(const struct pci_vdev *vdev, uint32_t offset, uint32_t byt int32_t vmsix_cfgwrite(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val) { uint32_t msgctrl; - int32_t ret; + int32_t ret = -ENODEV; /* Writing MSI-X Capability Structure */ if (msixcap_access(vdev, offset)) { @@ -207,8 +205,6 @@ int32_t vmsix_cfgwrite(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, u } } ret = 0; - } else { - ret = -ENODEV; } return ret; diff --git a/hypervisor/dm/vpci/partition_mode.c b/hypervisor/dm/vpci/partition_mode.c index b85b2009d..72a520769 100644 --- a/hypervisor/dm/vpci/partition_mode.c +++ b/hypervisor/dm/vpci/partition_mode.c @@ -149,7 +149,8 @@ void partition_mode_cfgread(struct acrn_vpci *vpci, union pci_bdf vbdf, } } else { if (vdev_pt_cfgread(vdev, offset, bytes, val) != 0) { - pr_err("vdev_pt_cfgread failed!"); + /* Not handled by any handlers, passthru to physical device */ + *val = pci_pdev_read_cfg(vdev->pdev->bdf, offset, bytes); } } } @@ -167,7 +168,8 @@ void partition_mode_cfgwrite(struct acrn_vpci *vpci, union pci_bdf vbdf, } } else { if (vdev_pt_cfgwrite(vdev, offset, bytes, val) != 0){ - pr_err("vdev_pt_cfgwrite failed!"); + /* 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/pci_pt.c b/hypervisor/dm/vpci/pci_pt.c index df8d6e61c..8c761eaa8 100644 --- a/hypervisor/dm/vpci/pci_pt.c +++ b/hypervisor/dm/vpci/pci_pt.c @@ -105,14 +105,15 @@ void vdev_pt_deinit(const 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 ret = -ENODEV; + /* PCI BARs is emulated */ if (pci_bar_access(offset)) { *val = pci_vdev_read_cfg(vdev, offset, bytes); - } else { - *val = pci_pdev_read_cfg(vdev->pdev->bdf, offset, bytes); + ret = 0; } - return 0; + return ret; } static void vdev_pt_remap_bar(struct pci_vdev *vdev, uint32_t idx, @@ -178,14 +179,14 @@ static void vdev_pt_cfgwrite_bar(struct pci_vdev *vdev, uint32_t offset, int32_t vdev_pt_cfgwrite(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val) { + int32_t ret = -ENODEV; + /* PCI BARs are emulated */ if (pci_bar_access(offset)) { vdev_pt_cfgwrite_bar(vdev, offset, bytes, val); - } else { - /* Write directly to physical device's config space */ - pci_pdev_write_cfg(vdev->pdev->bdf, offset, bytes, val); + ret = 0; } - return 0; + return ret; } diff --git a/hypervisor/dm/vpci/sharing_mode.c b/hypervisor/dm/vpci/sharing_mode.c index 446e5fddd..ecd31f0d7 100644 --- a/hypervisor/dm/vpci/sharing_mode.c +++ b/hypervisor/dm/vpci/sharing_mode.c @@ -45,14 +45,12 @@ static struct pci_vdev *sharing_mode_find_vdev_sos(union pci_bdf pbdf) void sharing_mode_cfgread(__unused struct acrn_vpci *vpci, union pci_bdf bdf, uint32_t offset, uint32_t bytes, uint32_t *val) { - struct pci_vdev *vdev; + struct pci_vdev *vdev = sharing_mode_find_vdev_sos(bdf); - vdev = sharing_mode_find_vdev_sos(bdf); + *val = ~0U; /* vdev == NULL: Could be hit for PCI enumeration from guests */ - if (vdev == NULL) { - *val = ~0U; - } else { + if (vdev != NULL) { if ((vmsi_cfgread(vdev, offset, bytes, val) != 0) && (vmsix_cfgread(vdev, offset, bytes, val) != 0) ) { @@ -65,9 +63,8 @@ void sharing_mode_cfgread(__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) { - struct pci_vdev *vdev; + struct pci_vdev *vdev = sharing_mode_find_vdev_sos(bdf); - vdev = sharing_mode_find_vdev_sos(bdf); if (vdev != NULL) { if ((vmsi_cfgwrite(vdev, offset, bytes, val) != 0) && (vmsix_cfgwrite(vdev, offset, bytes, val) != 0)