@@ -215,26 +215,46 @@ void vdev_pt_write_vbar(struct pci_vdev *vdev, uint32_t idx, uint32_t val)
215
215
* Hypervisor traps guest changes to the mmio vbar (gpa) to establish ept mapping
216
216
* between vbar(gpa) and pbar(hpa). pbar should always align on 4K boundary.
217
217
*
218
+ * @param vdev Pointer to a vdev structure
219
+ * @param is_sriov_bar When the first parameter vdev is a SRIOV PF vdev, the function
220
+ * init_bars is used to initialize normal PCIe BARs of PF vdev if the
221
+ * parameter is_sriov_bar is false, the function init_bars is used to
222
+ * initialize SRIOV VF BARs of PF vdev if parameter is_sriov_bar is true
223
+ * Otherwise, the parameter is_sriov_bar should be false if the first
224
+ * parameter vdev is not SRIOV PF vdev
225
+ *
218
226
* @pre vdev != NULL
219
227
* @pre vdev->vpci != NULL
220
228
* @pre vdev->vpci->vm != NULL
221
229
* @pre vdev->pdev != NULL
230
+ *
231
+ * @return None
222
232
*/
223
- static void init_bars (struct pci_vdev * vdev )
233
+ static void init_bars (struct pci_vdev * vdev , bool is_sriov_bar )
224
234
{
225
235
enum pci_bar_type type ;
226
- uint32_t idx ;
236
+ uint32_t idx , bar_cnt ;
227
237
struct pci_vbar * vbar ;
228
238
uint32_t size32 , offset , lo , hi = 0U ;
229
239
union pci_bdf pbdf ;
230
240
uint64_t mask ;
231
241
232
- vdev -> nr_bars = vdev -> pdev -> nr_bars ;
242
+ if (is_sriov_bar ) {
243
+ bar_cnt = PCI_BAR_COUNT ;
244
+ } else {
245
+ vdev -> nr_bars = vdev -> pdev -> nr_bars ;
246
+ bar_cnt = vdev -> nr_bars ;
247
+ }
233
248
pbdf .value = vdev -> pdev -> bdf .value ;
234
249
235
- for (idx = 0U ; idx < vdev -> nr_bars ; idx ++ ) {
236
- vbar = & vdev -> vbars [idx ];
237
- offset = pci_bar_offset (idx );
250
+ for (idx = 0U ; idx < bar_cnt ; idx ++ ) {
251
+ if (is_sriov_bar ) {
252
+ vbar = & vdev -> sriov .vbars [idx ];
253
+ offset = sriov_bar_offset (vdev , idx );
254
+ } else {
255
+ vbar = & vdev -> vbars [idx ];
256
+ offset = pci_bar_offset (idx );
257
+ }
238
258
lo = pci_pdev_read_cfg (pbdf , offset , 4U );
239
259
240
260
type = pci_get_bar_type (lo );
@@ -265,7 +285,11 @@ static void init_bars(struct pci_vdev *vdev)
265
285
266
286
if (type == PCIBAR_MEM64 ) {
267
287
idx ++ ;
268
- offset = pci_bar_offset (idx );
288
+ if (is_sriov_bar ) {
289
+ offset = sriov_bar_offset (vdev , idx );
290
+ } else {
291
+ offset = pci_bar_offset (idx );
292
+ }
269
293
pci_pdev_write_cfg (pbdf , offset , 4U , ~0U );
270
294
size32 = pci_pdev_read_cfg (pbdf , offset , 4U );
271
295
pci_pdev_write_cfg (pbdf , offset , 4U , hi );
@@ -274,21 +298,32 @@ static void init_bars(struct pci_vdev *vdev)
274
298
vbar -> size = vbar -> size & ~(vbar -> size - 1UL );
275
299
vbar -> size = round_page_up (vbar -> size );
276
300
277
- vbar = & vdev -> vbars [idx ];
301
+ if (is_sriov_bar ) {
302
+ vbar = & vdev -> sriov .vbars [idx ];
303
+ } else {
304
+ vbar = & vdev -> vbars [idx ];
305
+ }
306
+
278
307
vbar -> mask = size32 ;
279
308
vbar -> type = PCIBAR_MEM64HI ;
280
309
281
310
if (is_prelaunched_vm (vdev -> vpci -> vm )) {
282
311
hi = (uint32_t )(vdev -> pci_dev_config -> vbar_base [idx - 1U ] >> 32U );
283
312
}
284
- pci_vdev_write_bar (vdev , idx - 1U , lo );
285
- pci_vdev_write_bar (vdev , idx , hi );
313
+ /* if it is parsing SRIOV VF BARs, no need to write vdev bars */
314
+ if (!is_sriov_bar ) {
315
+ pci_vdev_write_bar (vdev , idx - 1U , lo );
316
+ pci_vdev_write_bar (vdev , idx , hi );
317
+ }
286
318
} else {
287
319
vbar -> size = vbar -> size & ~(vbar -> size - 1UL );
288
320
if (type == PCIBAR_MEM32 ) {
289
321
vbar -> size = round_page_up (vbar -> size );
290
322
}
291
- pci_vdev_write_bar (vdev , idx , lo );
323
+ /* if it is parsing SRIOV VF BARs, no need to write vdev bar */
324
+ if (!is_sriov_bar ) {
325
+ pci_vdev_write_bar (vdev , idx , lo );
326
+ }
292
327
}
293
328
}
294
329
}
@@ -316,11 +351,8 @@ void init_vdev_pt(struct pci_vdev *vdev, bool is_pf_vdev)
316
351
{
317
352
uint16_t pci_command ;
318
353
319
- /* SRIOV capability initialization implementaion in next patch */
320
- (void ) is_pf_vdev ;
321
-
322
- init_bars (vdev );
323
- if (is_prelaunched_vm (vdev -> vpci -> vm )) {
354
+ init_bars (vdev , is_pf_vdev );
355
+ if (is_prelaunched_vm (vdev -> vpci -> vm ) && (!is_pf_vdev )) {
324
356
pci_command = (uint16_t )pci_pdev_read_cfg (vdev -> pdev -> bdf , PCIR_COMMAND , 2U );
325
357
326
358
/* Disable INTX */
0 commit comments