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 <dongsheng.x.zhang@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>
This commit is contained in:
dongshen 2019-05-14 15:56:13 -07:00 committed by ACRN System Integration
parent 7635a68f38
commit b957802164
6 changed files with 26 additions and 47 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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_ */