Skip to content

Commit 7635a68

Browse files
donshengacrnsi
authored andcommitted
HV: unify the sharing_mode_cfgread and partition_mode_cfgread code
Put the cfgread code in read_cfg() for both sos and pre-launched VMs, and remove sharing_mode_cfgread() and partition_mode_cfgread(). Rename functions used by read_cfg(): vhostbridge_cfgread --> vhostbridge_read_cfg vdev_pt_cfgread --> vdev_pt_read_cfg vmsi_cfgread --> vmsi_read_cfg vmsix_cfgread --> vmsix_read_cfg 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>
1 parent 19af3bc commit 7635a68

File tree

6 files changed

+47
-51
lines changed

6 files changed

+47
-51
lines changed

hypervisor/dm/vpci/pci_pt.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ static inline uint32_t get_bar_base(uint32_t bar)
4343

4444
/**
4545
* @pre vdev != NULL
46+
* @pre vdev->vpci != NULL
47+
* @pre vdev->vpci->vm != NULL
4648
*/
47-
int32_t vdev_pt_cfgread(const struct pci_vdev *vdev, uint32_t offset,
49+
int32_t vdev_pt_read_cfg(const struct pci_vdev *vdev, uint32_t offset,
4850
uint32_t bytes, uint32_t *val)
4951
{
5052
int32_t ret = -ENODEV;

hypervisor/dm/vpci/vhostbridge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void deinit_vhostbridge(__unused const struct pci_vdev *vdev)
102102
* @pre vdev->vpci != NULL
103103
* @pre vdev->vpci->vm != NULL
104104
*/
105-
int32_t vhostbridge_cfgread(const struct pci_vdev *vdev, uint32_t offset,
105+
int32_t vhostbridge_read_cfg(const struct pci_vdev *vdev, uint32_t offset,
106106
uint32_t bytes, uint32_t *val)
107107
{
108108
int32_t ret = -ENODEV;

hypervisor/dm/vpci/vmsi.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ static int32_t vmsi_remap(const struct pci_vdev *vdev, bool enable)
115115
return ret;
116116
}
117117

118-
int32_t vmsi_cfgread(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val)
118+
/**
119+
* @pre vdev != NULL
120+
*/
121+
int32_t vmsi_read_cfg(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val)
119122
{
120123
int32_t ret = -ENODEV;
121124

hypervisor/dm/vpci/vmsix.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ static int32_t vmsix_remap_one_entry(const struct pci_vdev *vdev, uint32_t index
158158
return ret;
159159
}
160160

161-
int32_t vmsix_cfgread(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val)
161+
/**
162+
* @pre vdev != NULL
163+
*/
164+
int32_t vmsix_read_cfg(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val)
162165
{
163166
int32_t ret = -ENODEV;
164167
/* For PIO access, we emulate Capability Structures only */

hypervisor/dm/vpci/vpci.c

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ static void init_vdev_for_pdev(struct pci_pdev *pdev, const void *vm);
3838
static void deinit_prelaunched_vm_vpci(const struct acrn_vm *vm);
3939
static void deinit_postlaunched_vm_vpci(const struct acrn_vm *vm);
4040

41+
static void read_cfg(const struct acrn_vpci *vpci, union pci_bdf bdf, uint32_t offset, uint32_t bytes, uint32_t *val);
4142

4243
/**
4344
* @pre pi != NULL
@@ -106,9 +107,10 @@ static inline bool vpci_is_valid_access(uint32_t offset, uint32_t bytes)
106107
}
107108

108109
/**
109-
* @pre vm != NULL && vcpu != NULL
110+
* @pre vm != NULL
111+
* @pre vcpu != NULL
110112
* @pre vm->vm_id < CONFIG_MAX_VM_NUM
111-
* @pre (get_vm_config(vm->vm_id)->type == PRE_LAUNCHED_VM) || (get_vm_config(vm->vm_id)->type == SOS_VM)
113+
* @pre (get_vm_config(vm->vm_id)->load_order == PRE_LAUNCHED_VM) || (get_vm_config(vm->vm_id)->load_order == SOS_VM)
112114
*/
113115
static bool pci_cfgdata_io_read(struct acrn_vm *vm, struct acrn_vcpu *vcpu, uint16_t addr, size_t bytes)
114116
{
@@ -125,11 +127,8 @@ static bool pci_cfgdata_io_read(struct acrn_vm *vm, struct acrn_vcpu *vcpu, uint
125127

126128
switch (vm_config->load_order) {
127129
case PRE_LAUNCHED_VM:
128-
partition_mode_cfgread(vpci, pi->cached_bdf, pi->cached_reg + offset, bytes, &val);
129-
break;
130-
131130
case SOS_VM:
132-
sharing_mode_cfgread(vpci, pi->cached_bdf, pi->cached_reg + offset, bytes, &val);
131+
read_cfg(vpci, pi->cached_bdf, pi->cached_reg + offset, bytes, &val);
133132
break;
134133

135134
default:
@@ -305,29 +304,6 @@ static void remove_vdev_pt_iommu_domain(const struct pci_vdev *vdev)
305304
}
306305
}
307306

308-
/**
309-
* @pre vpci != NULL
310-
*/
311-
void partition_mode_cfgread(const struct acrn_vpci *vpci, union pci_bdf vbdf,
312-
uint32_t offset, uint32_t bytes, uint32_t *val)
313-
{
314-
struct pci_vdev *vdev = pci_find_vdev_by_vbdf(vpci, vbdf);
315-
316-
if (vdev != NULL) {
317-
if (is_hostbridge(vdev)) {
318-
(void)vhostbridge_cfgread(vdev, offset, bytes, val);
319-
} else {
320-
if ((vdev_pt_cfgread(vdev, offset, bytes, val) != 0)
321-
&& (vmsi_cfgread(vdev, offset, bytes, val) != 0)
322-
&& (vmsix_cfgread(vdev, offset, bytes, val) != 0)
323-
) {
324-
/* Not handled by any handlers, passthru to physical device */
325-
*val = pci_pdev_read_cfg(vdev->pdev->bdf, offset, bytes);
326-
}
327-
}
328-
}
329-
}
330-
331307
/**
332308
* @pre vpci != NULL
333309
*/
@@ -362,22 +338,38 @@ static struct pci_vdev *find_vdev_for_sos(union pci_bdf bdf)
362338

363339
/**
364340
* @pre vpci != NULL
341+
* @pre vpci->vm != NULL
365342
*/
366-
void sharing_mode_cfgread(__unused struct acrn_vpci *vpci, union pci_bdf bdf,
367-
uint32_t offset, uint32_t bytes, uint32_t *val)
343+
static struct pci_vdev *find_vdev(const struct acrn_vpci *vpci, union pci_bdf bdf)
368344
{
369-
struct pci_vdev *vdev = find_vdev_for_sos(bdf);
345+
struct pci_vdev *vdev = NULL;
370346

371-
*val = ~0U;
347+
if (is_prelaunched_vm(vpci->vm)) {
348+
vdev = pci_find_vdev_by_vbdf(vpci, bdf);
349+
} else if (is_sos_vm(vpci->vm)){
350+
vdev = find_vdev_for_sos(bdf);
351+
}
352+
353+
return vdev;
354+
}
355+
356+
/**
357+
* @pre vpci != NULL
358+
*/
359+
static void read_cfg(const struct acrn_vpci *vpci, union pci_bdf bdf,
360+
uint32_t offset, uint32_t bytes, uint32_t *val)
361+
{
362+
struct pci_vdev *vdev = find_vdev(vpci, bdf);
372363

373-
/* vdev == NULL: Could be hit for PCI enumeration from guests */
374364
if (vdev != NULL) {
375-
if ((vmsi_cfgread(vdev, offset, bytes, val) != 0)
376-
&& (vmsix_cfgread(vdev, offset, bytes, val) != 0)
365+
if ((vhostbridge_read_cfg(vdev, offset, bytes, val) != 0)
366+
&& (vdev_pt_read_cfg(vdev, offset, bytes, val) != 0)
367+
&& (vmsi_read_cfg(vdev, offset, bytes, val) != 0)
368+
&& (vmsix_read_cfg(vdev, offset, bytes, val) != 0)
377369
) {
378-
/* Not handled by any handlers, passthru to physical device */
379-
*val = pci_pdev_read_cfg(vdev->pdev->bdf, offset, bytes);
380-
}
370+
/* Not handled by any handlers, passthru to physical device */
371+
*val = pci_pdev_read_cfg(vdev->pdev->bdf, offset, bytes);
372+
}
381373
}
382374
}
383375

hypervisor/dm/vpci/vpci_priv.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,23 @@ static inline bool is_hostbridge(const struct pci_vdev *vdev)
8484
}
8585

8686
void init_vhostbridge(struct pci_vdev *vdev);
87-
int32_t vhostbridge_cfgread(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val);
87+
int32_t vhostbridge_read_cfg(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val);
8888
int32_t vhostbridge_cfgwrite(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val);
8989
void deinit_vhostbridge(__unused const struct pci_vdev *vdev);
9090

9191
void init_vdev_pt(struct pci_vdev *vdev);
92-
int32_t vdev_pt_cfgread(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val);
92+
int32_t vdev_pt_read_cfg(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val);
9393
int32_t vdev_pt_cfgwrite(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val);
9494

9595
void init_vmsi(struct pci_vdev *vdev);
96-
int32_t vmsi_cfgread(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val);
96+
int32_t vmsi_read_cfg(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val);
9797
int32_t vmsi_cfgwrite(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val);
9898
void deinit_vmsi(const struct pci_vdev *vdev);
9999

100100
void init_vmsix(struct pci_vdev *vdev);
101101
void vdev_pt_remap_msix_table_bar(struct pci_vdev *vdev);
102102
int32_t vmsix_table_mmio_access_handler(struct io_request *io_req, void *handler_private_data);
103-
int32_t vmsix_cfgread(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val);
103+
int32_t vmsix_read_cfg(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val);
104104
int32_t vmsix_cfgwrite(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val);
105105
void deinit_vmsix(const struct pci_vdev *vdev);
106106

@@ -111,13 +111,9 @@ struct pci_vdev *pci_find_vdev_by_vbdf(const struct acrn_vpci *vpci, union pci_b
111111

112112
struct pci_vdev *pci_find_vdev_by_pbdf(const struct acrn_vpci *vpci, union pci_bdf pbdf);
113113

114-
void partition_mode_cfgread(const struct acrn_vpci *vpci, union pci_bdf vbdf,
115-
uint32_t offset, uint32_t bytes, uint32_t *val);
116114
void partition_mode_cfgwrite(const struct acrn_vpci *vpci, union pci_bdf vbdf,
117115
uint32_t offset, uint32_t bytes, uint32_t val);
118116

119-
void sharing_mode_cfgread(struct acrn_vpci *vpci, union pci_bdf bdf,
120-
uint32_t offset, uint32_t bytes, uint32_t *val);
121117
void sharing_mode_cfgwrite(__unused struct acrn_vpci *vpci, union pci_bdf bdf,
122118
uint32_t offset, uint32_t bytes, uint32_t val);
123119

0 commit comments

Comments
 (0)