From 37de8f0b993b20a36533685f1d8b37a49b2c0a1e Mon Sep 17 00:00:00 2001 From: Yin Fengwei Date: Thu, 11 Jul 2019 16:24:06 +0800 Subject: [PATCH] vbar:msi:msix: export vbar/msi/msix access checking Change vbar/msi/msix access checking from private to public. Tracked-On: #3241 Signed-off-by: Yin Fengwei Acked-by: Eddie Dong --- hypervisor/dm/vpci/vmsi.c | 22 ---------------------- hypervisor/dm/vpci/vmsix.c | 15 --------------- hypervisor/dm/vpci/vpci_priv.h | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 37 deletions(-) diff --git a/hypervisor/dm/vpci/vmsi.c b/hypervisor/dm/vpci/vmsi.c index 8a41e3ce63..4f5338e39b 100644 --- a/hypervisor/dm/vpci/vmsi.c +++ b/hypervisor/dm/vpci/vmsi.c @@ -35,28 +35,6 @@ #include "vpci_priv.h" -/** - * @pre vdev != NULL - */ -static inline bool has_msi_cap(const struct pci_vdev *vdev) -{ - return (vdev->msi.capoff != 0U); -} - -/** - * @pre vdev != NULL - */ -static inline bool msicap_access(const struct pci_vdev *vdev, uint32_t offset) -{ - bool ret = false; - - if (has_msi_cap(vdev)) { - ret = in_range(offset, vdev->msi.capoff, vdev->msi.caplen); - } - - return ret; -} - /** * @pre vdev != NULL * @pre vdev->vpci != NULL diff --git a/hypervisor/dm/vpci/vmsix.c b/hypervisor/dm/vpci/vmsix.c index 37573e3849..777a1e6b4d 100644 --- a/hypervisor/dm/vpci/vmsix.c +++ b/hypervisor/dm/vpci/vmsix.c @@ -38,21 +38,6 @@ #include #include "vpci_priv.h" - -/** - * @pre vdev != NULL - */ -static inline bool msixcap_access(const struct pci_vdev *vdev, uint32_t offset) -{ - bool ret = false; - - if (has_msix_cap(vdev)) { - ret = in_range(offset, vdev->msix.capoff, vdev->msix.caplen); - } - - return ret; -} - /** * @pre vdev != NULL */ diff --git a/hypervisor/dm/vpci/vpci_priv.h b/hypervisor/dm/vpci/vpci_priv.h index 1ae0ffa98a..e94667f874 100644 --- a/hypervisor/dm/vpci/vpci_priv.h +++ b/hypervisor/dm/vpci/vpci_priv.h @@ -93,6 +93,38 @@ static inline bool has_msix_cap(const struct pci_vdev *vdev) return (vdev->msix.capoff != 0U); } +/** + * @pre vdev != NULL + */ +static inline bool msixcap_access(const struct pci_vdev *vdev, uint32_t offset) +{ + return (has_msix_cap(vdev) && in_range(offset, vdev->msix.capoff, vdev->msix.caplen)); +} + +/** + * @pre vdev != NULL + */ +static inline bool vbar_access(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes) +{ + return (is_bar_offset(vdev->nr_bars, offset) && (bytes == 4U) && ((offset & 0x3U) == 0U)); +} + +/** + * @pre vdev != NULL + */ +static inline bool has_msi_cap(const struct pci_vdev *vdev) +{ + return (vdev->msi.capoff != 0U); +} + +/** + * @pre vdev != NULL + */ +static inline bool msicap_access(const struct pci_vdev *vdev, uint32_t offset) +{ + return (has_msi_cap(vdev) && in_range(offset, vdev->msi.capoff, vdev->msi.caplen)); +} + /** * @pre vdev != NULL */