mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-04 21:29:43 +00:00
This patch adds a parser and interpreter of ACPI DSDT/SSDT tables in AML (ACPI Machine Language) in order to understand the complete device layout and resource allocation. Kindly note that the interpreter is still experimental and not yet complete. Tracked-On: #5922 Signed-off-by: Junjie Mao <junjie.mao@intel.com>
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
# Copyright (C) 2021 Intel Corporation. All rights reserved.
|
|
#
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
#
|
|
|
|
import os
|
|
import logging
|
|
|
|
from acpiparser.aml.stream import Stream
|
|
from acpiparser.aml.parser import AMLCode, DeferredExpansion
|
|
from acpiparser.aml.tree import Tree, FlattenTransformer
|
|
from acpiparser.aml.context import Context
|
|
from acpiparser.aml.interpreter import ConcreteInterpreter
|
|
from acpiparser.aml.visitors import ConditionallyUnregisterSymbolVisitor
|
|
|
|
def DSDT(val):
|
|
table_dir = os.path.dirname(val)
|
|
if not table_dir:
|
|
table_dir = "."
|
|
ssdt = filter(lambda x: x.startswith("SSDT"), os.listdir(table_dir))
|
|
tables = [val] + list(map(lambda x: os.path.join(table_dir, x), ssdt))
|
|
|
|
context = Context()
|
|
trees = []
|
|
try:
|
|
for t in tables:
|
|
logging.info(f"Loading {t}")
|
|
context.switch_stream(t)
|
|
tree = Tree()
|
|
AMLCode.parse(context, tree)
|
|
tree = DeferredExpansion(context).transform_topdown(tree)
|
|
tree = FlattenTransformer().transform_bottomup(tree)
|
|
trees.append(tree)
|
|
except Exception as e:
|
|
context.current_stream.dump()
|
|
raise
|
|
|
|
context.skip_external_on_lookup()
|
|
visitor = ConditionallyUnregisterSymbolVisitor(ConcreteInterpreter(context))
|
|
for tree in trees:
|
|
visitor.visit_topdown(tree)
|
|
return context
|