1# Copyright (C) 2021-2022 Intel Corporation.
2#
3# SPDX-License-Identifier: BSD-3-Clause
4#
5
6import sys, os
7
8from acpiparser.apic import APIC
9from acpiparser.asf import ASF
10from acpiparser.dmar import DMAR
11from acpiparser.dsdt import DSDT
12from acpiparser.facp import FACP
13from acpiparser.rtct import RTCT
14from acpiparser.rdt import parse_resource_data
15from acpiparser.prt import parse_pci_routing
16from acpiparser.tpm2 import TPM2
17
18def parse_table(signature, path=None):
19    if not path:
20        path = f"/sys/firmware/acpi/tables/{signature}"
21    signature = signature.rstrip("!")
22    fn = getattr(sys.modules[f"acpiparser.{signature.lower()}"], signature)
23    return fn(path)
24
25def make_parser(signature):
26    def parse(path=None):
27        return parse_table(signature, path)
28    return parse
29
30parse_apic = make_parser('APIC')
31parse_asf = make_parser('ASF!')
32parse_dsdt = make_parser('DSDT')
33parse_dmar = make_parser('DMAR')
34parse_facp = make_parser('FACP')
35parse_tpm2 = make_parser('TPM2')
36
37def parse_rtct(path=None):
38    if not path:
39        path = f"/sys/firmware/acpi/tables/RTCT"
40        if not os.path.exists(path):
41            path = f"/sys/firmware/acpi/tables/PTCT"
42    fn = getattr(sys.modules[f"acpiparser.rtct"], "RTCT")
43    return fn(path)
44