Skip to content

Commit

Permalink
Quite the pci enum func when --hal flag is set
Browse files Browse the repository at this point in the history
Signed-off-by: Nathaniel Mitchell <[email protected]>
  • Loading branch information
npmitche committed Jul 16, 2024
1 parent 8925f98 commit 1eae6e0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions chipsec/hal/pci.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,24 +237,28 @@ class Pci:
def __init__(self, cs):
self.cs = cs
self.helper = cs.helper
self.hal_log_every_read = True

#
# Access to PCI configuration registers
#

def read_dword(self, bus: int, device: int, function: int, address: int) -> int:
value = self.helper.read_pci_reg(bus, device, function, address, 4)
logger().log_hal(f'[pci] reading B/D/F: {bus:d}/{device:d}/{function:d}, offset: 0x{address:02X}, value: 0x{value:08X}')
if self.hal_log_every_read or value != 0xFFFFFFFF:
logger().log_hal(f'[pci] reading B/D/F: {bus:d}/{device:d}/{function:d}, offset: 0x{address:02X}, value: 0x{value:08X}')
return value

def read_word(self, bus: int, device: int, function: int, address: int) -> int:
word_value = self.helper.read_pci_reg(bus, device, function, address, 2)
logger().log_hal(f'[pci] reading B/D/F: {bus:d}/{device:d}/{function:d}, offset: 0x{address:02X}, value: 0x{word_value:04X}')
if self.hal_log_every_read or word_value != 0xFFFF:
logger().log_hal(f'[pci] reading B/D/F: {bus:d}/{device:d}/{function:d}, offset: 0x{address:02X}, value: 0x{word_value:04X}')
return word_value

def read_byte(self, bus: int, device: int, function: int, address: int) -> int:
byte_value = self.helper.read_pci_reg(bus, device, function, address, 1)
logger().log_hal(f'[pci] reading B/D/F: {bus:d}/{device:d}/{function:d}, offset: 0x{address:02X}, value: 0x{byte_value:02X}')
if self.hal_log_every_read or byte_value != 0xFF:
logger().log_hal(f'[pci] reading B/D/F: {bus:d}/{device:d}/{function:d}, offset: 0x{address:02X}, value: 0x{byte_value:02X}')
return byte_value

def write_byte(self, bus: int, device: int, function: int, address: int, byte_value: int) -> None:
Expand All @@ -278,7 +282,7 @@ def write_dword(self, bus: int, device: int, function: int, address: int, dword_

def enumerate_devices(self, bus: Optional[int] = None, device: Optional[int] = None, function: Optional[int] = None, spec: Optional[bool] = True) -> List[Tuple[int, int, int, int, int, int]]:
devices = []

self.hal_log_every_read = False
if bus is not None:
bus_range = [bus]
else:
Expand All @@ -305,6 +309,7 @@ def enumerate_devices(self, bus: Optional[int] = None, device: Optional[int] = N
break
except OsHelperError:
logger().log_hal(f"[pci] unable to access B/D/F: {b:d}/{d:d}/{f:d}")
self.hal_log_every_read = True
return devices

def dump_pci_config(self, bus: int, device: int, function: int) -> List[int]:
Expand Down

0 comments on commit 1eae6e0

Please sign in to comment.