Saturday, April 2, 2016

PCI Scan

Sample Code Name
https://sourceforge.net/u/efipy/svn/HEAD/tree/Trunk/PciScan.py

Description

PCI Scan program is the sample for combination between EfiPy and CorePy.

PCI scan with EfiPy, it uses below functions, constants and structure in EfiPy.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

PCI scan with CorePy, it uses I/O port 0x0cf8, 0x0cfc for PCI generic register scanning by assembly language.
It also needs input parameter for assigning PCI bus, Device, function and registers.


EfiPy full package is from https://sourceforge.net/projects/efipy/

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)

No comments:

Post a Comment