acrn-hypervisor/misc/config_tools/target/acpiparser/__init__.py
Junjie Mao ba02583f2d config_tools/acpiparser: port the ACPI module from BITS
This patch ports the ACPI parsing module from BITS (BIOS Implementation
Test Suite) in order to ease the access to ACPI tables during board XML
generation. This library allows accessing ACPI table fields as Python class
members, getting rid of hard coding or calculating offsets within tables.

Compared to the original library, this port makes the following changes.

 * Extract only the scripts and functions that contribute to ACPI parsing.
 * Separate the parser of each ACPI table into different files.
 * Read raw ACPI tables from Linux sysfs.
 * Adapt to Python 3.

Tracked-On: #5649
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-01-27 16:39:24 +08:00

31 lines
809 B
Python

# Copyright (C) 2021 Intel Corporation. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import sys
from acpiparser.apic import APIC
from acpiparser.asf import ASF
from acpiparser.dmar import DMAR
from acpiparser.facp import FACP
from acpiparser.rtct import RTCT
def parse_table(signature, path=None):
if not path:
path = f"/sys/firmware/acpi/tables/{signature}"
signature = signature.rstrip("!")
fn = getattr(sys.modules[f"acpiparser.{signature.lower()}"], signature)
return fn(path)
def make_parser(signature):
def parse(path=None):
return parse_table(signature, path)
return parse
parse_apic = make_parser('APIC')
parse_asf = make_parser('ASF!')
parse_dmar = make_parser('DMAR')
parse_facp = make_parser('FACP')
parse_rtct = make_parser('RTCT')