@@ -328,74 +328,71 @@ static int32_t vmsix_table_mmio_access_handler(struct io_request *io_req, void *
328
328
return ret ;
329
329
}
330
330
331
- static int32_t vmsix_init_helper (struct pci_vdev * vdev )
331
+
332
+ /**
333
+ * @pre vdev != NULL
334
+ * @pre vdev->pdev != NULL
335
+ * @pre vdev->pdev->msix.table_bar < (PCI_BAR_COUNT - 1U)
336
+ */
337
+ static void vmsix_init_helper (struct pci_vdev * vdev )
332
338
{
333
339
uint32_t i ;
334
340
uint64_t addr_hi , addr_lo ;
335
341
struct pci_msix * msix = & vdev -> msix ;
336
342
struct pci_pdev * pdev = vdev -> pdev ;
337
343
struct pci_bar * bar ;
338
- int32_t ret ;
344
+
345
+ ASSERT (vdev -> pdev -> msix .table_bar < (PCI_BAR_COUNT - 1U ), "msix->table_bar out of range" );
339
346
340
347
msix -> table_bar = pdev -> msix .table_bar ;
341
348
msix -> table_offset = pdev -> msix .table_offset ;
342
349
msix -> table_count = pdev -> msix .table_count ;
343
350
344
- if (msix -> table_bar < (PCI_BAR_COUNT - 1U )) {
345
- /* Mask all table entries */
346
- for (i = 0U ; i < msix -> table_count ; i ++ ) {
347
- msix -> tables [i ].vector_control = PCIM_MSIX_VCTRL_MASK ;
348
- msix -> tables [i ].addr = 0U ;
349
- msix -> tables [i ].data = 0U ;
350
- }
351
-
352
- bar = & pdev -> bar [msix -> table_bar ];
353
- if (bar != NULL ) {
354
- vdev -> msix .mmio_hpa = bar -> base ;
355
- vdev -> msix .mmio_gpa = sos_vm_hpa2gpa (bar -> base );
356
- vdev -> msix .mmio_size = bar -> size ;
357
- }
351
+ /* Mask all table entries */
352
+ for (i = 0U ; i < msix -> table_count ; i ++ ) {
353
+ msix -> tables [i ].vector_control = PCIM_MSIX_VCTRL_MASK ;
354
+ msix -> tables [i ].addr = 0U ;
355
+ msix -> tables [i ].data = 0U ;
356
+ }
358
357
359
- if (msix -> mmio_gpa != 0U ) {
360
- /*
361
- * PCI Spec: a BAR may also map other usable address space that is not associated
362
- * with MSI-X structures, but it must not share any naturally aligned 4 KB
363
- * address range with one where either MSI-X structure resides.
364
- * The MSI-X Table and MSI-X PBA are permitted to co-reside within a naturally
365
- * aligned 4 KB address range.
366
- *
367
- * If PBA or others reside in the same BAR with MSI-X Table, devicemodel could
368
- * emulate them and maps these memory range at the 4KB boundary. Here, we should
369
- * make sure only intercept the minimum number of 4K pages needed for MSI-X table.
370
- */
371
-
372
- /* The higher boundary of the 4KB aligned address range for MSI-X table */
373
- addr_hi = msix -> mmio_gpa + msix -> table_offset + (msix -> table_count * MSIX_TABLE_ENTRY_SIZE );
374
- addr_hi = round_page_up (addr_hi );
375
-
376
- /* The lower boundary of the 4KB aligned address range for MSI-X table */
377
- addr_lo = round_page_down (msix -> mmio_gpa + msix -> table_offset );
378
-
379
- (void )register_mmio_emulation_handler (vdev -> vpci -> vm , vmsix_table_mmio_access_handler ,
380
- addr_lo , addr_hi , vdev );
381
- }
382
- ret = 0 ;
383
- } else {
384
- pr_err ("%s, MSI-X device (%x) invalid table BIR %d" , __func__ , vdev -> pdev -> bdf .value , msix -> table_bar );
385
- vdev -> msix .capoff = 0U ;
386
- ret = - EIO ;
358
+ bar = & pdev -> bar [msix -> table_bar ];
359
+ if (bar != NULL ) {
360
+ vdev -> msix .mmio_hpa = bar -> base ;
361
+ vdev -> msix .mmio_gpa = sos_vm_hpa2gpa (bar -> base );
362
+ vdev -> msix .mmio_size = bar -> size ;
387
363
}
388
364
389
- return ret ;
365
+ if (msix -> mmio_gpa != 0U ) {
366
+ /*
367
+ * PCI Spec: a BAR may also map other usable address space that is not associated
368
+ * with MSI-X structures, but it must not share any naturally aligned 4 KB
369
+ * address range with one where either MSI-X structure resides.
370
+ * The MSI-X Table and MSI-X PBA are permitted to co-reside within a naturally
371
+ * aligned 4 KB address range.
372
+ *
373
+ * If PBA or others reside in the same BAR with MSI-X Table, devicemodel could
374
+ * emulate them and maps these memory range at the 4KB boundary. Here, we should
375
+ * make sure only intercept the minimum number of 4K pages needed for MSI-X table.
376
+ */
377
+
378
+ /* The higher boundary of the 4KB aligned address range for MSI-X table */
379
+ addr_hi = msix -> mmio_gpa + msix -> table_offset + (msix -> table_count * MSIX_TABLE_ENTRY_SIZE );
380
+ addr_hi = round_page_up (addr_hi );
381
+
382
+ /* The lower boundary of the 4KB aligned address range for MSI-X table */
383
+ addr_lo = round_page_down (msix -> mmio_gpa + msix -> table_offset );
384
+
385
+ (void )register_mmio_emulation_handler (vdev -> vpci -> vm , vmsix_table_mmio_access_handler ,
386
+ addr_lo , addr_hi , vdev );
387
+ }
390
388
}
391
389
392
390
/**
393
391
* @pre vdev != NULL
394
392
*/
395
- int32_t vmsix_init (struct pci_vdev * vdev )
393
+ void vmsix_init (struct pci_vdev * vdev )
396
394
{
397
395
struct pci_pdev * pdev = vdev -> pdev ;
398
- int32_t ret = 0 ;
399
396
400
397
vdev -> msix .capoff = pdev -> msix .capoff ;
401
398
vdev -> msix .caplen = pdev -> msix .caplen ;
@@ -404,31 +401,20 @@ int32_t vmsix_init(struct pci_vdev *vdev)
404
401
(void )memcpy_s ((void * )& vdev -> cfgdata .data_8 [pdev -> msix .capoff ], pdev -> msix .caplen ,
405
402
(void * )& pdev -> msix .cap [0U ], pdev -> msix .caplen );
406
403
407
- ret = vmsix_init_helper (vdev );
404
+ vmsix_init_helper (vdev );
408
405
}
409
-
410
- return ret ;
411
406
}
412
407
413
408
/**
414
409
* @pre vdev != NULL
415
410
* @pre vdev->vpci != NULL
416
411
* @pre vdev->vpci->vm != NULL
417
412
*/
418
- int32_t vmsix_deinit (const struct pci_vdev * vdev )
413
+ void vmsix_deinit (const struct pci_vdev * vdev )
419
414
{
420
415
if (has_msix_cap (vdev )) {
421
416
if (vdev -> msix .table_count != 0U ) {
422
417
ptirq_remove_msix_remapping (vdev -> vpci -> vm , vdev -> vbdf .value , vdev -> msix .table_count );
423
418
}
424
419
}
425
-
426
- return 0 ;
427
420
}
428
-
429
- const struct pci_vdev_ops pci_ops_vdev_msix = {
430
- .init = vmsix_init ,
431
- .deinit = vmsix_deinit ,
432
- .cfgwrite = vmsix_cfgwrite ,
433
- .cfgread = vmsix_cfgread ,
434
- };
0 commit comments