mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-20 12:42:54 +00:00
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:
parent
844c6e0bbc
commit
0a77891f1c
@ -22,14 +22,20 @@ class PCIConfigSpace(namedtuple("PCIConfigSpace", ["header", "caps", "extcaps"])
|
|||||||
acc += str(extcap)
|
acc += str(extcap)
|
||||||
return acc
|
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):
|
def has_cap(self, cap_name):
|
||||||
for cap in self.caps:
|
return cap_name in self.caps_as_dict().keys()
|
||||||
if cap_name == cap.name:
|
|
||||||
return True
|
def get_cap(self, cap_name):
|
||||||
for cap in self.extcaps:
|
return self.caps_as_dict().get(cap_name)
|
||||||
if cap_name == cap.name:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def parse_config_space(path):
|
def parse_config_space(path):
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user