Skip to content

Commit

Permalink
HV: extract common code blocks to has_msi_cap and has_msix_cap functions
Browse files Browse the repository at this point in the history
Define has_msi_cap and has_msix_cap inline functions to do sanity checking for
msi and msix ops, the corresponding code block in existing code is replaced with
a call to these new functions.

A few minor coding style fix.

Tracked-On: #2534
Signed-off-by: dongshen <dongsheng.x.zhang@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
  • Loading branch information
donsheng authored and wenlingz committed Mar 18, 2019
1 parent 79cfb1c commit 5767d1e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 23 deletions.
26 changes: 17 additions & 9 deletions hypervisor/dm/vpci/msi.c
Expand Up @@ -35,13 +35,22 @@
#include "pci_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;
bool ret = false;

if (vdev->msi.capoff == 0U) {
ret = 0;
} else {
if (has_msi_cap(vdev)) {
ret = in_range(offset, vdev->msi.capoff, vdev->msi.caplen);
}

Expand Down Expand Up @@ -160,7 +169,7 @@ int32_t vmsi_cfgwrite(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, ui

int32_t vmsi_deinit(struct pci_vdev *vdev)
{
if (vdev->msi.capoff != 0U) {
if (has_msi_cap(vdev)) {
ptirq_remove_msix_remapping(vdev->vpci->vm, vdev->vbdf.value, 1U);
}

Expand Down Expand Up @@ -194,11 +203,10 @@ int32_t vmsi_init(struct pci_vdev *vdev)
struct pci_pdev *pdev = vdev->pdev;
uint32_t val;

/* Copy MSI/MSI-X capability struct into virtual device */
if (pdev->msi.capoff != 0U) {
vdev->msi.capoff = pdev->msi.capoff;
vdev->msi.caplen = pdev->msi.caplen;
vdev->msi.capoff = pdev->msi.capoff;
vdev->msi.caplen = pdev->msi.caplen;

if (has_msi_cap(vdev)) {
(void)memcpy_s((void *)&vdev->cfgdata.data_8[pdev->msi.capoff], pdev->msi.caplen,
(void *)&pdev->msi.cap[0U], pdev->msi.caplen);

Expand Down
39 changes: 29 additions & 10 deletions hypervisor/dm/vpci/msix.c
Expand Up @@ -38,13 +38,22 @@
#include <logmsg.h>
#include "pci_priv.h"

/**
* @pre vdev != NULL
*/
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)
{
bool ret;
bool ret = false;

if (vdev->msix.capoff == 0U) {
ret = false;
} else {
if (has_msix_cap(vdev)) {
ret = in_range(offset, vdev->msix.capoff, vdev->msix.caplen);
}

Expand Down Expand Up @@ -383,15 +392,18 @@ static int32_t vmsix_init_helper(struct pci_vdev *vdev)
return ret;
}

/**
* @pre vdev != NULL
*/
int32_t vmsix_init(struct pci_vdev *vdev)
{
struct pci_pdev *pdev = vdev->pdev;
int32_t ret = 0;

if (pdev->msix.capoff != 0U) {
vdev->msix.capoff = pdev->msix.capoff;
vdev->msix.caplen = pdev->msix.caplen;
vdev->msix.capoff = pdev->msix.capoff;
vdev->msix.caplen = pdev->msix.caplen;

if (has_msix_cap(vdev)) {
(void)memcpy_s((void *)&vdev->cfgdata.data_8[pdev->msix.capoff], pdev->msix.caplen,
(void *)&pdev->msix.cap[0U], pdev->msix.caplen);

Expand All @@ -401,12 +413,19 @@ int32_t vmsix_init(struct pci_vdev *vdev)
return ret;
}

/**
* @pre vdev != NULL
* @pre vdev->vpci != NULL
* @pre vdev->vpci->vm != NULL
*/
int32_t vmsix_deinit(struct pci_vdev *vdev)
{
vdev->msix.intercepted_size = 0U;
if (has_msix_cap(vdev)) {
vdev->msix.intercepted_size = 0U;

if (vdev->msix.table_count != 0U) {
ptirq_remove_msix_remapping(vdev->vpci->vm, vdev->vbdf.value, vdev->msix.table_count);
if (vdev->msix.table_count != 0U) {
ptirq_remove_msix_remapping(vdev->vpci->vm, vdev->vbdf.value, vdev->msix.table_count);
}
}

return 0;
Expand Down
6 changes: 2 additions & 4 deletions hypervisor/dm/vpci/sharing_mode.c
Expand Up @@ -152,15 +152,13 @@ static int32_t sharing_mode_vpci_init(const struct acrn_vm *vm)
{
struct pci_vdev *vdev;
uint32_t i, j;
int32_t ret;
int32_t ret = -ENODEV;

/*
* Only set up IO bitmap for SOS.
* IO/MMIO requests from non-sos_vm guests will be injected to device model.
*/
if (!is_sos_vm(vm)) {
ret = -ENODEV;
} else {
if (is_sos_vm(vm)) {
/* Build up vdev array for sos_vm */
pci_pdev_foreach(init_vdev_for_pdev, vm);

Expand Down

0 comments on commit 5767d1e

Please sign in to comment.