From 0991f7f03bb543b57652cabd9c71521eee1c501d Mon Sep 17 00:00:00 2001 From: Junjie Mao Date: Sat, 3 Jul 2021 08:31:53 +0800 Subject: [PATCH] board_inspector: add a parser of PCI routing tables This patch adds a parser to the PCI routing tables returned by _PRT objects of platform devices. The parsed result is a list of PRTMappingPackage instances, each of which is a named tuple with the following fields: * address: a dword with higher 16 bits being the function number and lower 16 bits all 1's. * pin: a byte representing the mapped pin. * source: either a DeviceDecl of the device that allocates the interrupt line, or the byte 0. * source_index: - If `source` is a DeviceDecl, this is the index of the interrupt source within that device. - If `source` is 0, this is the interrupt line connected to the pin. Tracked-On: #6287 Signed-off-by: Junjie Mao --- .../board_inspector/acpiparser/__init__.py | 2 ++ .../board_inspector/acpiparser/prt.py | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 misc/config_tools/board_inspector/acpiparser/prt.py diff --git a/misc/config_tools/board_inspector/acpiparser/__init__.py b/misc/config_tools/board_inspector/acpiparser/__init__.py index e8fcbe093..e13060c94 100644 --- a/misc/config_tools/board_inspector/acpiparser/__init__.py +++ b/misc/config_tools/board_inspector/acpiparser/__init__.py @@ -11,6 +11,8 @@ from acpiparser.dmar import DMAR from acpiparser.dsdt import DSDT from acpiparser.facp import FACP from acpiparser.rtct import RTCT +from acpiparser.rdt import parse_resource_data +from acpiparser.prt import parse_pci_routing def parse_table(signature, path=None): if not path: diff --git a/misc/config_tools/board_inspector/acpiparser/prt.py b/misc/config_tools/board_inspector/acpiparser/prt.py new file mode 100644 index 000000000..29cf3bb4c --- /dev/null +++ b/misc/config_tools/board_inspector/acpiparser/prt.py @@ -0,0 +1,34 @@ +# Copyright (C) 2021 Intel Corporation. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# + +from collections import namedtuple +from .aml import datatypes, context + +class PRTMappingPackage(namedtuple("PRTMappingPackage", ["address", "pin", "source", "source_index"])): + def __repr__(self): + if isinstance(self.source, context.DeviceDecl): + s = self.source.name + else: + s = str(self.source) + return "address=0x{0:08x}, pin=0x{1:02x}, source={2}, source_index=0x{3:08x}".format( + self.address, self.pin, s, self.source_index) + +def parse_prt_mapping(x): + address = x.elements[0].get() + pin = x.elements[1].get() + source = x.elements[2] + if isinstance(source, datatypes.Device): + source = source.get_sym() + elif isinstance(source, datatypes.Integer): + source = source.get() + else: + source = "unknown" + source_index = x.elements[3].get() + + return PRTMappingPackage(address, pin, source, source_index) + +def parse_pci_routing(package): + """Parse ACPI PCI routing table returned by _PRT control methods.""" + return list(map(parse_prt_mapping, package.elements))