https://github.com/EfiPy/EfiPy2/blob/main/Efi/Apps/EfiPy2Sample/PciScan.py
Description
PCI Scanning program is the sample of how data returned by CorePy then transfer to EfiPy2.
It uses below functions, constants and structure in EfiPy2
EfiPy2.MdePkg.IndustryStandard.Pci
Structure PCI_TYPE_GENERIC
Structure PCI_CONFIG_ACCESS_CF8
PCI_MAX_BUS
PCI_MAX_DEVICE
PCI_MAX_FUNC
IS_PCI_MULTI_FUNC
CorePy code in PCI scanning script, it uses I/O port 0x0cf8, 0x0cfc for scanning PCI generic register.
Structure PCI_TYPE_GENERIC
Structure PCI_CONFIG_ACCESS_CF8
PCI_MAX_BUS
PCI_MAX_DEVICE
PCI_MAX_FUNC
IS_PCI_MULTI_FUNC
CorePy code in PCI scanning script, it uses I/O port 0x0cf8, 0x0cfc for scanning PCI generic register.
It also needs input parameter for assigning PCI bus, Device, function and registers.
EfiPy2 full package is from https://github.com/EfiPy/EfiPy2
EfiPy2 full package is from https://github.com/EfiPy/EfiPy2
Pseudo Sample Code
class PciScan:
#
# Prebuild assembly code
#
def __init__ (self):
self.code.add(x86.mov(reg.rax, mem.MemRef(reg.rbp, 16)))
self.code.add(x86.mov(reg.dx, 0x0cf8))
self.code.add(x86.out(reg.dx, reg.eax))
self.code.add(x86.mov(reg.dx, 0x0cfc))
self.code.add(x86.in_(reg.eax, reg.dx))
#
# Get PCI register entry, return UINT32 value
#
def scan (self, Bus = 0, Dev = 0, Func = 0, Reg = 0):
reg = pci.PCI_CONFIG_ACCESS_CF8((Reg & 0xFC, Func, Dev, Bus, 0, 1))
self.params.p1 = reg.Uint32
ret = self.proc.execute(self.code,
params = self.params,
mode = 'int')
return ret
if __name__ == '__main__':
PciDev = PciScan()
ret = PciDev.scan(Bus, Dev, Func, Reg)
Result
No comments:
Post a Comment