board_inspector: add object_type codes in Decls

Object type codes are used to identify, as the name suggests, type of
objects. Typical object types in AML include integers, strings, methods,
devices, buffers, packages and operation regions. In DefExternal terms the
object type codes help specify the type of the external objects so that an
AML parser can parse the code without knowing the concrete definition of
these objects.

The per-device AML templates in board XMLs need DefExternal terms to
declare the objects in other devices, as these templates are meant to be
parsed and integrated separately. This patch adds a static method to object
declaration classes to make it easier to generate such DefExternal terms
for a given declaration.

A complete definition of object type codes can be found in section 19.6.96
of ACPI specification 6.4.

v1 -> v2:
  * Remove the object_type of FieldDecl and OperationFieldDecl as 0x5 is
    not a proper object type for buffer fields.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
This commit is contained in:
Junjie Mao 2021-08-02 16:11:32 +08:00 committed by wenlingz
parent d58ef5e2aa
commit 6ccd7660a4
2 changed files with 17 additions and 1 deletions

View File

@ -11,6 +11,10 @@ from .exception import *
from .stream import Stream from .stream import Stream
class NamedDecl: class NamedDecl:
@staticmethod
def object_type():
return 0
def __init__(self, name, tree): def __init__(self, name, tree):
self.tree = tree self.tree = tree
self.name = name self.name = name
@ -66,6 +70,10 @@ class AliasDecl(NamedDecl):
print(f"{self.name}: {self.__class__.__name__}, aliasing {self.source}") print(f"{self.name}: {self.__class__.__name__}, aliasing {self.source}")
class MethodDecl(NamedDecl): class MethodDecl(NamedDecl):
@staticmethod
def object_type():
return 8
def __init__(self, name, nargs, tree): def __init__(self, name, nargs, tree):
super().__init__(name, tree) super().__init__(name, tree)
self.nargs = nargs self.nargs = nargs
@ -74,6 +82,10 @@ class MethodDecl(NamedDecl):
print(f"{self.name}: {self.__class__.__name__}, {self.nargs} args") print(f"{self.name}: {self.__class__.__name__}, {self.nargs} args")
class PredefinedMethodDecl(NamedDecl): class PredefinedMethodDecl(NamedDecl):
@staticmethod
def object_type():
return 8
def __init__(self, name, nargs, fn): def __init__(self, name, nargs, fn):
super().__init__(name, None) super().__init__(name, None)
self.nargs = nargs self.nargs = nargs
@ -83,6 +95,10 @@ class PredefinedMethodDecl(NamedDecl):
print(f"{self.name}: {self.__class__.__name__}, {self.nargs} args") print(f"{self.name}: {self.__class__.__name__}, {self.nargs} args")
class DeviceDecl(NamedDecl): class DeviceDecl(NamedDecl):
@staticmethod
def object_type():
return 6
def __init__(self, name, tree): def __init__(self, name, tree):
super().__init__(name, tree) super().__init__(name, tree)

View File

@ -501,7 +501,7 @@ def DefExternal_hook_post(context, tree):
ty = tree.ObjectType.value ty = tree.ObjectType.value
nargs = tree.ArgumentCount.value nargs = tree.ArgumentCount.value
if ty == 0x8: # an external method if ty == MethodDecl.object_type():
sym = MethodDecl(name, nargs, tree) sym = MethodDecl(name, nargs, tree)
else: else:
sym = NamedDecl(name, tree) sym = NamedDecl(name, tree)