@@ -275,6 +275,7 @@ class FakePCIDevice(object):
275
275
<product id='0x%(prod_id)s'>%(prod_name)s</product>
276
276
<vendor id='0x%(vend_id)s'>%(vend_name)s</vendor>
277
277
%(capability)s
278
+ %(vpd_capability)s
278
279
<iommuGroup number='%(iommu_group)d'>
279
280
<address domain='0x0000' bus='%(bus)#02x' slot='%(slot)#02x' function='0x%(function)d'/>
280
281
</iommuGroup>
@@ -293,13 +294,22 @@ class FakePCIDevice(object):
293
294
<availableInstances>%(instances)s</availableInstances>
294
295
</type>""" .strip ()) # noqa
295
296
297
+ vpd_cap_templ = textwrap .dedent ("""
298
+ <capability type='vpd'>
299
+ <name>%(name)s</name>
300
+ %(fields)s
301
+ </capability>""" .strip ())
302
+ vpd_fields_templ = textwrap .dedent ("""
303
+ <fields access='%(access)s'>%(section_fields)s</fields>""" .strip ())
304
+ vpd_field_templ = """<%(field_name)s>%(field_value)s</%(field_name)s>"""
305
+
296
306
is_capable_of_mdevs = False
297
307
298
308
def __init__ (
299
309
self , dev_type , bus , slot , function , iommu_group , numa_node , * ,
300
310
vf_ratio = None , multiple_gpu_types = False , generic_types = False ,
301
311
parent = None , vend_id = None , vend_name = None , prod_id = None ,
302
- prod_name = None , driver_name = None ,
312
+ prod_name = None , driver_name = None , vpd_fields = None
303
313
):
304
314
"""Populate pci devices
305
315
@@ -340,6 +350,8 @@ def __init__(
340
350
self .prod_name = prod_name
341
351
self .driver_name = driver_name
342
352
353
+ self .vpd_fields = vpd_fields
354
+
343
355
self .generate_xml ()
344
356
345
357
def generate_xml (self , skip_capability = False ):
@@ -447,6 +459,7 @@ def generate_xml(self, skip_capability=False):
447
459
'prod_name' : prod_name ,
448
460
'driver' : driver ,
449
461
'capability' : capability ,
462
+ 'vpd_capability' : self .format_vpd_cap (),
450
463
'iommu_group' : self .iommu_group ,
451
464
'numa_node' : self .numa_node ,
452
465
'parent' : parent ,
@@ -457,6 +470,30 @@ def generate_xml(self, skip_capability=False):
457
470
if self .numa_node == - 1 :
458
471
self .pci_device = self .pci_device .replace ("<numa node='-1'/>" , "" )
459
472
473
+ def format_vpd_cap (self ):
474
+ if not self .vpd_fields :
475
+ return ''
476
+ fields = []
477
+ for access_type in ('readonly' , 'readwrite' ):
478
+ section_fields = []
479
+ for field_name , field_value in self .vpd_fields .get (
480
+ access_type , {}).items ():
481
+ section_fields .append (self .vpd_field_templ % {
482
+ 'field_name' : field_name ,
483
+ 'field_value' : field_value ,
484
+ })
485
+ if section_fields :
486
+ fields .append (
487
+ self .vpd_fields_templ % {
488
+ 'access' : access_type ,
489
+ 'section_fields' : '\n ' .join (section_fields ),
490
+ }
491
+ )
492
+ return self .vpd_cap_templ % {
493
+ 'name' : self .vpd_fields .get ('name' , '' ),
494
+ 'fields' : '\n ' .join (fields )
495
+ }
496
+
460
497
def XMLDesc (self , flags ):
461
498
return self .pci_device
462
499
@@ -572,7 +609,7 @@ def add_device(
572
609
self , dev_type , bus , slot , function , iommu_group , numa_node ,
573
610
vf_ratio = None , multiple_gpu_types = False , generic_types = False ,
574
611
parent = None , vend_id = None , vend_name = None , prod_id = None ,
575
- prod_name = None , driver_name = None ,
612
+ prod_name = None , driver_name = None , vpd_fields = None ,
576
613
):
577
614
pci_dev_name = _get_libvirt_nodedev_name (bus , slot , function )
578
615
@@ -593,7 +630,9 @@ def add_device(
593
630
vend_name = vend_name ,
594
631
prod_id = prod_id ,
595
632
prod_name = prod_name ,
596
- driver_name = driver_name )
633
+ driver_name = driver_name ,
634
+ vpd_fields = vpd_fields ,
635
+ )
597
636
self .devices [pci_dev_name ] = dev
598
637
return dev
599
638
0 commit comments