diff --git a/misc/acrn-config/target/dmar.py b/misc/acrn-config/target/dmar.py index 044f3f2c5..ca3cad94e 100644 --- a/misc/acrn-config/target/dmar.py +++ b/misc/acrn-config/target/dmar.py @@ -51,23 +51,6 @@ class DmarHeader(ctypes.Structure): self._pack_ = 0 -class DmarSubtblHeader(ctypes.Structure): - """DMAR Sub Table Header""" - _pack_ = 1 - _fields_ = [ - ('type', ctypes.c_uint16), - ('length', ctypes.c_uint16), - ] - - def style_check_1(self): - """Style check if have public method""" - self._pack_ = 0 - - def style_check_2(self): - """Style check if have public method""" - self._pack_ = 0 - - class DmarDevScope(ctypes.Structure): """DMAR Device Scope""" _pack_ = 1 @@ -92,7 +75,8 @@ class DmarHwUnit(ctypes.Structure): """DMAR Hardware Unit""" _pack_ = 1 _fields_ = [ - ('sub_header', DmarSubtblHeader), + ('type', ctypes.c_uint16), + ('length', ctypes.c_uint16), ('flags', ctypes.c_uint8), ('reserved', ctypes.c_uint8), ('segment', ctypes.c_uint16), @@ -125,14 +109,6 @@ class DevScopePath(ctypes.Structure): self._pack_ = 0 -def map_file(sysnode): - """Map sys node to memory address""" - data = open(sysnode, 'rb').read() - buf = ctypes.create_string_buffer(data, len(data)) - addr = ctypes.addressof(buf) - - return addr - class DmarHwList: """DMAR HW List""" def __init__(self): @@ -171,7 +147,7 @@ class DmarDevList: class DmarTbl: """DMAR TBL""" def __init__(self): - self.sub_tbl_offset = 0 + self.drhd_offset = 0 self.dmar_drhd = 0 self.dmar_dev_scope = 0 self.dev_scope_offset = 0 @@ -208,21 +184,21 @@ class PathDevFun: self.path = 0 -def walk_pci_bus(tmp_pdf, dmar_tbl, dmar_hw_list, n_cnt, drhd_cnt): +def walk_pci_bus(tmp_pdf, dmar_tbl, dmar_hw_list, drhd_cnt): """Walk Pci bus :param tmp_pdf: it is a class what contains path,device,function in dmar device scope region :param dmar_tbl: it is a class to describe dmar which contains Device Scope and DRHD :param dmar_hw_list: it is a class to describe hardware scope in DMAR table - :param n_cnt: the number of device in device scope :param drhd_cnt: it is a counter to calculate the DRHD in DMAR table """ + # path offset is in end of device spcope + dmar_tbl.path_offset = dmar_tbl.dev_scope_offset + ctypes.sizeof(DmarDevScope) + n_cnt = (dmar_tbl.dmar_dev_scope.scope_length - ctypes.sizeof(DmarDevScope)) // 2 while n_cnt: scope_path = DevScopePath.from_address(dmar_tbl.path_offset) tmp_pdf.device = scope_path.device tmp_pdf.function = scope_path.function tmp_pdf.path = (((tmp_pdf.device & 0x1F) << 3) | ((tmp_pdf.function & 0x7))) - dmar_tbl.path_offset += ctypes.sizeof(DevScopePath) - n_cnt -= 1 if ((dmar_tbl.dmar_drhd.segment << 16) | ( dmar_tbl.dmar_dev_scope.bus << 8) | tmp_pdf.path) == CONFIG_GPU_SBDF: @@ -230,7 +206,8 @@ def walk_pci_bus(tmp_pdf, dmar_tbl, dmar_hw_list, n_cnt, drhd_cnt): else: dmar_hw_list.hw_ignore[drhd_cnt] = 'false' - return (tmp_pdf, dmar_tbl, dmar_hw_list) + dmar_tbl.path_offset += ctypes.sizeof(DevScopePath) + n_cnt -= 1 def walk_dev_scope(dmar_tbl, dmar_dev_list, dmar_hw_list, drhd_cnt): @@ -240,8 +217,8 @@ def walk_dev_scope(dmar_tbl, dmar_dev_list, dmar_hw_list, drhd_cnt): :param dmar_hw_list: it is a class to describe DRHD in DMAR table :param drhd_cnt: it is a counter to calculate the DRHD in DMAR table """ - dmar_tbl.dev_scope_offset = dmar_tbl.sub_tbl_offset + ctypes.sizeof(DmarHwUnit) - scope_end = dmar_tbl.dev_scope_offset + dmar_tbl.dmar_drhd.sub_header.length + dmar_tbl.dev_scope_offset = dmar_tbl.drhd_offset + ctypes.sizeof(DmarHwUnit) + scope_end = dmar_tbl.dev_scope_offset + dmar_tbl.dmar_drhd.length dmar_tbl.dev_scope_cnt = 0 while dmar_tbl.dev_scope_offset < scope_end: @@ -258,20 +235,14 @@ def walk_dev_scope(dmar_tbl, dmar_dev_list, dmar_hw_list, drhd_cnt): dmar_dev_list.dev_scope_type_list.append(dmar_tbl.dmar_dev_scope.entry_type) dmar_dev_list.dev_scope_id_list.append(dmar_tbl.dmar_dev_scope.enumeration_id) - # path offset is in end of device spcope - dmar_tbl.path_offset = dmar_tbl.dev_scope_offset + ctypes.sizeof(DmarDevScope) # walk the pci bus with path deep, and find the {Device,Function} tmp_pdf = PathDevFun() - n_cnt = (dmar_tbl.dmar_dev_scope.scope_length - ctypes.sizeof(DmarDevScope)) // 2 - (tmp_pdf, dmar_tbl, dmar_hw_list) = walk_pci_bus(tmp_pdf, dmar_tbl, dmar_hw_list, - n_cnt, drhd_cnt) + walk_pci_bus(tmp_pdf, dmar_tbl, dmar_hw_list, drhd_cnt) dmar_dev_list.dev_bus_list.append(dmar_tbl.dmar_dev_scope.bus) dmar_dev_list.dev_path_list.append(tmp_pdf.path) dmar_tbl.dev_scope_offset += dmar_tbl.dmar_dev_scope.scope_length - return (dmar_tbl, dmar_dev_list, dmar_hw_list) - def walk_dmar_table(dmar_tbl, dmar_hw_list, dmar_dev_list, sysnode): """Walk dmar table and get information @@ -289,33 +260,31 @@ def walk_dmar_table(dmar_tbl, dmar_hw_list, dmar_dev_list, sysnode): # cytpes.c_int16.from_address(addr) reade int16 from ad1 # in end of tbl header is remapping structure(DRHD/sub tbl) - dmar_tbl.sub_tbl_offset = addr + ctypes.sizeof(DmarHeader) + dmar_tbl.drhd_offset = addr + ctypes.sizeof(DmarHeader) drhd_cnt = 0 while True: - sub_dmar = DmarSubtblHeader.from_address(dmar_tbl.sub_tbl_offset) - sub_dmar_type = sub_dmar.type - sub_dmar_len = sub_dmar.length + # get one DRHD type in sub table + dmar_tbl.dmar_drhd = DmarHwUnit.from_address(dmar_tbl.drhd_offset) + dmar_type = dmar_tbl.dmar_drhd.type + dmar_len = dmar_tbl.dmar_drhd.length - if dmar_tbl.sub_tbl_offset - addr >= dmar_tbl_header.length: + if dmar_tbl.drhd_offset - addr >= dmar_tbl_header.length: break - if sub_dmar_type != ACPI_DMAR_TYPE['ACPI_DMAR_TYPE_HARDWARE_UNIT']: - dmar_tbl.sub_tbl_offset += sub_dmar.length + if dmar_type != ACPI_DMAR_TYPE['ACPI_DMAR_TYPE_HARDWARE_UNIT']: + dmar_tbl.drhd_offset += dmar_len continue - # get one DRHD type in sub table - dmar_tbl.dmar_drhd = DmarHwUnit.from_address(dmar_tbl.sub_tbl_offset) dmar_hw_list.hw_segment_list.append(dmar_tbl.dmar_drhd.segment) dmar_hw_list.hw_flags_list.append(dmar_tbl.dmar_drhd.flags) dmar_hw_list.hw_address_list.append(dmar_tbl.dmar_drhd.address) # in end of DRHD/sub tbl header is dev scope, then enumerate the device scope - (dmar_tbl, dmar_dev_list, dmar_hw_list) = walk_dev_scope( - dmar_tbl, dmar_dev_list, dmar_hw_list, drhd_cnt) - + walk_dev_scope(dmar_tbl, dmar_dev_list, dmar_hw_list, drhd_cnt) dmar_dev_list.dev_scope_cnt_list.append(dmar_tbl.dev_scope_cnt) + drhd_cnt += 1 - dmar_tbl.sub_tbl_offset += sub_dmar_len + dmar_tbl.drhd_offset += dmar_len return (dmar_tbl, dmar_hw_list, dmar_dev_list, drhd_cnt)