mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-20 12:42:54 +00:00
HV: extract common code blocks to has_msi_cap and has_msix_cap functions
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>
This commit is contained in:
parent
79cfb1cf58
commit
5767d1e141
@ -35,13 +35,22 @@
|
|||||||
#include "pci_priv.h"
|
#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)
|
static inline bool msicap_access(const struct pci_vdev *vdev, uint32_t offset)
|
||||||
{
|
{
|
||||||
bool ret;
|
bool ret = false;
|
||||||
|
|
||||||
if (vdev->msi.capoff == 0U) {
|
if (has_msi_cap(vdev)) {
|
||||||
ret = 0;
|
|
||||||
} else {
|
|
||||||
ret = in_range(offset, vdev->msi.capoff, vdev->msi.caplen);
|
ret = in_range(offset, vdev->msi.capoff, vdev->msi.caplen);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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)
|
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);
|
ptirq_remove_msix_remapping(vdev->vpci->vm, vdev->vbdf.value, 1U);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,11 +203,10 @@ int32_t vmsi_init(struct pci_vdev *vdev)
|
|||||||
struct pci_pdev *pdev = vdev->pdev;
|
struct pci_pdev *pdev = vdev->pdev;
|
||||||
uint32_t val;
|
uint32_t val;
|
||||||
|
|
||||||
/* Copy MSI/MSI-X capability struct into virtual device */
|
vdev->msi.capoff = pdev->msi.capoff;
|
||||||
if (pdev->msi.capoff != 0U) {
|
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)memcpy_s((void *)&vdev->cfgdata.data_8[pdev->msi.capoff], pdev->msi.caplen,
|
||||||
(void *)&pdev->msi.cap[0U], pdev->msi.caplen);
|
(void *)&pdev->msi.cap[0U], pdev->msi.caplen);
|
||||||
|
|
||||||
|
@ -38,13 +38,22 @@
|
|||||||
#include <logmsg.h>
|
#include <logmsg.h>
|
||||||
#include "pci_priv.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)
|
static inline bool msixcap_access(const struct pci_vdev *vdev, uint32_t offset)
|
||||||
{
|
{
|
||||||
bool ret;
|
bool ret = false;
|
||||||
|
|
||||||
if (vdev->msix.capoff == 0U) {
|
if (has_msix_cap(vdev)) {
|
||||||
ret = false;
|
|
||||||
} else {
|
|
||||||
ret = in_range(offset, vdev->msix.capoff, vdev->msix.caplen);
|
ret = in_range(offset, vdev->msix.capoff, vdev->msix.caplen);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -383,15 +392,18 @@ static int32_t vmsix_init_helper(struct pci_vdev *vdev)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @pre vdev != NULL
|
||||||
|
*/
|
||||||
int32_t vmsix_init(struct pci_vdev *vdev)
|
int32_t vmsix_init(struct pci_vdev *vdev)
|
||||||
{
|
{
|
||||||
struct pci_pdev *pdev = vdev->pdev;
|
struct pci_pdev *pdev = vdev->pdev;
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
|
|
||||||
if (pdev->msix.capoff != 0U) {
|
vdev->msix.capoff = pdev->msix.capoff;
|
||||||
vdev->msix.capoff = pdev->msix.capoff;
|
vdev->msix.caplen = pdev->msix.caplen;
|
||||||
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)memcpy_s((void *)&vdev->cfgdata.data_8[pdev->msix.capoff], pdev->msix.caplen,
|
||||||
(void *)&pdev->msix.cap[0U], pdev->msix.caplen);
|
(void *)&pdev->msix.cap[0U], pdev->msix.caplen);
|
||||||
|
|
||||||
@ -401,12 +413,19 @@ int32_t vmsix_init(struct pci_vdev *vdev)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @pre vdev != NULL
|
||||||
|
* @pre vdev->vpci != NULL
|
||||||
|
* @pre vdev->vpci->vm != NULL
|
||||||
|
*/
|
||||||
int32_t vmsix_deinit(struct pci_vdev *vdev)
|
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) {
|
if (vdev->msix.table_count != 0U) {
|
||||||
ptirq_remove_msix_remapping(vdev->vpci->vm, vdev->vbdf.value, vdev->msix.table_count);
|
ptirq_remove_msix_remapping(vdev->vpci->vm, vdev->vbdf.value, vdev->msix.table_count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -152,15 +152,13 @@ static int32_t sharing_mode_vpci_init(const struct acrn_vm *vm)
|
|||||||
{
|
{
|
||||||
struct pci_vdev *vdev;
|
struct pci_vdev *vdev;
|
||||||
uint32_t i, j;
|
uint32_t i, j;
|
||||||
int32_t ret;
|
int32_t ret = -ENODEV;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Only set up IO bitmap for SOS.
|
* Only set up IO bitmap for SOS.
|
||||||
* IO/MMIO requests from non-sos_vm guests will be injected to device model.
|
* IO/MMIO requests from non-sos_vm guests will be injected to device model.
|
||||||
*/
|
*/
|
||||||
if (!is_sos_vm(vm)) {
|
if (is_sos_vm(vm)) {
|
||||||
ret = -ENODEV;
|
|
||||||
} else {
|
|
||||||
/* Build up vdev array for sos_vm */
|
/* Build up vdev array for sos_vm */
|
||||||
pci_pdev_foreach(init_vdev_for_pdev, vm);
|
pci_pdev_foreach(init_vdev_for_pdev, vm);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user