@@ -38,6 +38,7 @@ static void init_vdev_for_pdev(struct pci_pdev *pdev, const void *vm);
38
38
static void deinit_prelaunched_vm_vpci (const struct acrn_vm * vm );
39
39
static void deinit_postlaunched_vm_vpci (const struct acrn_vm * vm );
40
40
41
+ static void read_cfg (const struct acrn_vpci * vpci , union pci_bdf bdf , uint32_t offset , uint32_t bytes , uint32_t * val );
41
42
42
43
/**
43
44
* @pre pi != NULL
@@ -106,9 +107,10 @@ static inline bool vpci_is_valid_access(uint32_t offset, uint32_t bytes)
106
107
}
107
108
108
109
/**
109
- * @pre vm != NULL && vcpu != NULL
110
+ * @pre vm != NULL
111
+ * @pre vcpu != NULL
110
112
* @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)
112
114
*/
113
115
static bool pci_cfgdata_io_read (struct acrn_vm * vm , struct acrn_vcpu * vcpu , uint16_t addr , size_t bytes )
114
116
{
@@ -125,11 +127,8 @@ static bool pci_cfgdata_io_read(struct acrn_vm *vm, struct acrn_vcpu *vcpu, uint
125
127
126
128
switch (vm_config -> load_order ) {
127
129
case PRE_LAUNCHED_VM :
128
- partition_mode_cfgread (vpci , pi -> cached_bdf , pi -> cached_reg + offset , bytes , & val );
129
- break ;
130
-
131
130
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 );
133
132
break ;
134
133
135
134
default :
@@ -305,29 +304,6 @@ static void remove_vdev_pt_iommu_domain(const struct pci_vdev *vdev)
305
304
}
306
305
}
307
306
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
-
331
307
/**
332
308
* @pre vpci != NULL
333
309
*/
@@ -362,22 +338,38 @@ static struct pci_vdev *find_vdev_for_sos(union pci_bdf bdf)
362
338
363
339
/**
364
340
* @pre vpci != NULL
341
+ * @pre vpci->vm != NULL
365
342
*/
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 )
368
344
{
369
- struct pci_vdev * vdev = find_vdev_for_sos ( bdf ) ;
345
+ struct pci_vdev * vdev = NULL ;
370
346
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 );
372
363
373
- /* vdev == NULL: Could be hit for PCI enumeration from guests */
374
364
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 )
377
369
) {
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
+ }
381
373
}
382
374
}
383
375
0 commit comments