board_inspector: maintain a mapping from cap names to cap struct

In order to ease the access of certain capability structure of a PCI config
space, this patch changes the class PCIConfigSpace to maintain a
_caps_as_dict dictionary that maps capability names (as specified in the
caps.py and extcaps.py) to the actual capability structures.

Tracked-On: #7301
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
This commit is contained in:
Junjie Mao 2022-04-16 00:16:03 +08:00 committed by acrnsi-robot
parent 844c6e0bbc
commit 0a77891f1c
1 changed files with 13 additions and 7 deletions

View File

@ -22,14 +22,20 @@ class PCIConfigSpace(namedtuple("PCIConfigSpace", ["header", "caps", "extcaps"])
acc += str(extcap)
return acc
def caps_as_dict(self):
if not hasattr(self, "_caps_as_dict"):
self._caps_as_dict = dict()
for cap in self.caps:
self._caps_as_dict[cap.name] = cap
for cap in self.extcaps:
self._caps_as_dict[cap.name] = cap
return self._caps_as_dict
def has_cap(self, cap_name):
for cap in self.caps:
if cap_name == cap.name:
return True
for cap in self.extcaps:
if cap_name == cap.name:
return True
return False
return cap_name in self.caps_as_dict().keys()
def get_cap(self, cap_name):
return self.caps_as_dict().get(cap_name)
def parse_config_space(path):
try: