board_inspector: resume a device if it is not in D0

It is seen that the BAR in the PCI configuration space of a device can be
cleared when the device is put to D3. This patch resumes a device not in D0
before parsing its configuration space in order to collect accurate
information.

This patch is added in v2 of the series.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
This commit is contained in:
Junjie Mao 2021-08-03 15:01:19 +08:00 committed by wenlingz
parent d6e47bcea5
commit 6be3f93173
2 changed files with 12 additions and 2 deletions

View File

@ -66,6 +66,16 @@ def parse_device(bus_node, device_path):
device_node = add_child(bus_node, "device", None, address=adr)
cfg = parse_config_space(device_path)
for cap in cfg.caps:
# If the device is not in D0, power it on and reparse its configuration space.
if cap.name == "Power Management" and cap.power_state != 0:
logging.info(f"Try resuming {device_path}")
try:
with open(os.path.join(device_path, "power", "control"), "w") as f:
f.write("on")
cfg = parse_config_space(device_path)
except Exception as e:
logging.info(f"Resuming {device_path} failed: {str(e)}")
# Device identifiers
vendor_id = "0x{:04x}".format(cfg.header.vendor_id)

View File

@ -67,8 +67,8 @@ class PowerManagement(cdata.Struct, Capability):
('data_select', ctypes.c_uint16, 4),
('data_scale', ctypes.c_uint16, 2),
('pme_status', ctypes.c_uint16, 1),
('reserved3', ctypes.c_uint16, 6),
('undefined', ctypes.c_uint16, 2),
('reserved3', ctypes.c_uint8, 6),
('undefined', ctypes.c_uint8, 2),
('data', ctypes.c_uint8),
]