Commit Graph

93 Commits

Author SHA1 Message Date
jackwhich c4d0eb3395 config-tools: update board inspector to update pci.ids before fetching PCI information
Add lspci -q Query PCI ID database via DNS for unknown ID‘s

Tracked-On: #7086
Signed-off-by: zhongzhenx.liu <zhongzhenx.liu@intel.com>
2022-02-17 14:59:52 +08:00
Kunhui-Li 4bf53e4b83 config_tools: category based on different log levels
category based on different log levels:
1) If the board inspector show CRITICAL error messages, it means that the
board inspector tool exit instantly and generate no file.
2) If the board inspector show ERROR messages, it means that the board
inspector will generate the board XML file successfully, but several conditions
may result in ACRN build or boot failure cannot continue execution due to the error.
3) If the board inspector show WARNING messages, this means that the board inspector
generate the board XML file successfully, but this board XML file is lack of
some feature which could still boot ACRN but loss some features.
4) If the board inspector show INFO messages, this means that board inspector
printed out some normal information.
5) If the board inspector show DEBUG messages, this means that it is used to
debug board inspector workflow.

v1->v2
1. Keep the assertions or exceptions under the acpiparser, inspectorlib
and smbiosparser directory.
2. Exit after all check_deps() completes instead of any unsatisfied dep
is identified.
3. As Amy's advice, Replace the message "{board_xml} saved successfully" with
the message "SUCCESS: Board configuration file <file name> generated successfully
and saved to <path>."

To do:
Print all messages using the colored font.

Tracked-On: #6689
Reviewed-by: Junjie Mao <junjie.mao@intel.com>
Signed-off-by: Kunhui-Li <kunhuix.li@intel.com>
2022-02-17 14:49:25 +08:00
Yang,Yu-chu 2e20494db1 config-tools: bring all cores online
Bring all the cores up in the beginning of the board_inspector.py
It is expected to run board_inspector in clean and native environment.
To resolve the issue that user may run other jobs which puts cores
offline, bringing up all cores online so tool can run cpuid to extract
all available cores information.

Tracked-On: #7119
Signed-off-by: Yang,Yu-chu <yu-chu.yang@intel.com>
Reviewed-by: Junjie Mao <junjie.mao@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
2022-02-17 14:11:49 +08:00
Junjie Mao 845c7dfa0a config_tools: fix illegal access to the level_types dictionary
In 10-processors.py, level_types is an unordered dictionary from level type
encodings to human-readable terms, not a list. It is thus illegal to access the
highest level using the `[-1]` notation.

This patch fixes this by calculating the highest level in level_types and use
that level as the index instead.

Tracked-On: #6689
Fixes: b5b22bf98 ("board_inspector: avoid hard-coded topo level names")
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2022-02-09 10:59:46 +08:00
Junjie Mao b5b22bf98b board_inspector: avoid hard-coded topo level names
While the terms to refer to CPU topology levels are originally borrowed
from MSR listings in SDMs (i.e. thread, core, die and package), we now
align the topology information with the CPUID topology enumeration
leaf (which does not have a "package" level) in the
implementation. However, some hard-coded level types are not updated
accordingly, leading to strangely organized nodes in the generated board
XML.

This patch refines the CPU extractor of the board inspector by removing
such hard code. Also the XPATH counting the total number of threads is
refined to tolerate the variance of reported intermediate levels.

Tracked-On: #6689
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2022-01-29 11:54:03 +08:00
Junjie Mao ed06539aae board_inspector: add index info to INTx pins from device objects
INTx routing can be specified in ACPI PRT (PCI Routing Table) in two ways:

    1. By an absolute interrupt line from the global interrupt pool.
    2. By a device object and an index to its interrupt resource.

The board inspector today only encodes the source object of an interrupt
pin routing in XML device resource descriptors, which is incomplete if the
source is a device object (i.e. case 2 above).

This patch adds the index from PRT to device resource nodes as well.

Tracked-On: #7058
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
2022-01-27 11:24:57 +08:00
Junjie Mao efb2860104 config_tools: skip directories without a "config" file
Today we assume a device node under /sys/devices/pciXXXX:XX/ always contain
a `config` file which shows the configuration space of the PCI
functions. This seems not the case for, at least, Non-Transparent
Bridge (or NTB).

This patch checks the existence of the `config` file and skips PCI
functions which do not contain one.

Tracked-On: #6902
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
2022-01-24 15:38:39 +08:00
Junjie Mao a7e06cec2f board_inspector: fix an inappropriate call to ord
The stream tracks the AML binary to be parsed as a list of bytes, not
characters. It makes no sense to call `ord` with a byte as the input
parameter.

This patch also adjust the format of the dump and print the formatted using
the logging module.

Tracked-On: #6504
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
Reviewed-by: Geoffroy Van Cutsem <geoffroy.vancutsem@intel.com>
2022-01-24 15:38:39 +08:00
Yang,Yu-chu 90c2df4a7e config-tools: add 40-acpi-tables.py to board_inspector/extractors
Add a new extractor 40-acpi-tables.py which extracts ioapics basic
information such as: ioapic id, address, gsi base and gsi number.

An example:
  <ioapics>
    <ioapic id="0x2">
      <address>0xfec00000</address>
      <gsi_base>0x0</gsi_base>
      <gsi_number>240</gsi_number>
    </ioapic>
  </ioapics>

Tracked-On: #6986
Signed-off-by: Yang,Yu-chu <yu-chu.yang@intel.com>
Reviewed-by: Junjie Mao <junjie.mao@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
2022-01-18 14:04:26 +08:00
Yang,Yu-chu ab00b15083 config-tools: rename 50-acpi.py
Rename 50-acpi.py to 50-acpi-namespace.py.

Tracked-On: #6986
Signed-off-by: Yang,Yu-chu <yu-chu.yang@intel.com>
Reviewed-by: Junjie Mao <junjie.mao@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
2022-01-18 14:04:26 +08:00
Junjie Mao d96ab7ec90 board_inspector/pcieparser: check config space size of PCIe devices
According to PCIe specification (since 2.0), absence of any extended
capabilities is required to be indicated by an extended capability header
with a capability ID of FFFFh and a next capability offset of 000h. Thus,
the board inspector today accesses the first extended capability header at
100h in the configuration space of a PCIe function unconditionally.

However, in practice we have seen real PCI functions which has a PCIe
capability but no extended capability header. This will cause the board
inspector to crash due to invalid configuration space accesses.

To fix that, this patch adds a check to the size of the configuration space
before walking the extended capabilities of a PCIe function.

Tracked-On: #6411
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
2022-01-07 19:32:20 +08:00
Yang,Yu-chu 30951f7a83 hv: rename CONFIG_GPU_SBDF to CONFIG_IGD_SBDF
The name CONFIG_IGD_SBDF indicates the bdf of an integrated GPU on platform.

Tracked-On: #6855
Signed-off-by: Yang,Yu-chu <yu-chu.yang@intel.com>
2021-11-28 14:23:29 +08:00
Hu Fenglin f65a87585b deb-pkg: add acrn-hypervisor and acrn-board-inspector into debian package
1. "make clean && make BOARD=nuc11tnbi5  SCENARIO=shared" will generate the acrn debian package.
 2. "make clean && make board_inspector" will generate the acrn board_inspector debian package

Tracked-On: #6688
Signed-off-by: Hu Fenglin <fenglin.hu@intel.com>
2021-11-02 15:31:18 +08:00
Hu Fenglin e6de236caa deb-pkg: load msr driver in board_parse.py
Tracked-On: #6688
Signed-off-by: Hu Fenglin <fenglin.hu@intel.com>
2021-10-29 14:50:48 +08:00
Geoffroy Van Cutsem 9bae63b941 config_tools: improve logging readability for the board inspector
Improve the logging readibility for the Board Inspector tool by adding
a space after "Error:" and "Warning:" instead of have the text directly
attached to it.

Tracked-On: #6736
Signed-off-by: Geoffroy Van Cutsem <geoffroy.vancutsem@intel.com>
2021-10-29 12:17:49 +08:00
Junjie Mao f64f253562 config_tools: always initialize hw_ignore when parsing DMAR
Commit 4a04fcc ("config_tools: skip remapping HW units with no devices under
scope") skips hardware remapping units without any device under its scope in the
config tools, which turns out to only work if the HV is not parsing the DMAR at
runtime.

This patch reverts the previous workaround and fixes the previous issue by
always initializing `dmar_hw_list.hw_ignore` when parsing DMAR. This ensures
that the DRHDx_IGNORE macro will always be emitted while DRHD_COUNT is not
impacted.

Fixes: 4a04fcc ("config_tools: skip remapping HW units with no devices under scope")
Tracked-On: #6709
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-10-28 19:36:41 +08:00
Geoffroy Van Cutsem 6ad9dcb262 config_tools: fix crash in board_inspector if cpuid is missing
Fix a crash in the 'board_inspector.py' tool in case 'cpuid' is not
installed on the system.

The tools crashes because 'cpuid' is used before the check for
dependencies is done in the code. That check for dependencies is
done in the 'legacy/board_parser.py' file. But the native_check()
function that is called before it also expects the cpuid tool to
be installed.

The fix is to move the check for dependencies in the main
'board_inspector.py' file, before any other operation is done.

Tracked-On: #6719
Signed-off-by: Geoffroy Van Cutsem <geoffroy.vancutsem@intel.com>
2021-10-27 10:17:31 +08:00
Junjie Mao 4a04fcc48f config_tools: skip remapping HW units with no devices under scope
It is seen on some platforms that the ACPI DMAR tables will report
remapping hardware units that does not have any device under its scope,
which is not expected by the board inspector previously and thus causes the
tool to generate inconsistent configuration data.

This patch makes the board inspector skip such remapping hardware units. It
does not impact the functionality of the hypervisor as no device is managed
by those skipped remapping units.

Tracked-On: #6709
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-10-25 15:31:54 +08:00
Junjie Mao ebee11ae11 board_inspector: add _CID to vACPI device objects
ACPI device drivers use both _HID and _CID to identify devices they
match. This patch copies _CID objects to vACPI devices so that guest
drivers can recognize the passthrough devices properly.

Tracked-On: #6288
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-10-21 12:58:43 +08:00
Kunhui-Li 9f5ef31c9f config_tools: add Board Inspector tool success message
add Board Inspector tool success message after users were successful
creating the board configuration file.

Tracked-On: #6670
Signed-off-by: Kunhui-Li <kunhuix.li@intel.com>
2021-10-17 15:35:39 +08:00
David B. Kinder bd57475854 doc: add iomem kernel parameter for board inspector
Without this ``iomem=relaxed`` kernel parameter, the generated board XML
is essentially the same as having ``--basic`` when executing the board
inspector, i.e. the ACPI namespace will not be parsed. The generated
board XML may still work, but some functionality (e.g. passthru of TPM
and other PCI devices that need INTx) will no longer work due to lack of
hardware information.

Replacing PR #6618

Tracked-On: #5692

Signed-off-by: zhongzhenx.liu <zhongzhenx.liu@intel.com>
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2021-09-24 11:40:24 -07:00
Kunhui-Li b420b3b52f config_tools: remove the log of sucessfully generating board XML
remove the log "<board>.xml has been generated successfully!" in
board_parser.py, because it only mean that the board xml file have
been created sucessfully here, not the all data have been appended
successfully and pretty formatted.

Tracked-On: #6315
Signed-off-by: Kunhui-Li <kunhuix.li@intel.com>
2021-08-23 14:50:23 +08:00
Kunhui-Li a860af24ba config_tools: rename python script
1. rename “cli.py” to “board_inspector.py”,
   and update the script name in README file.
2. rename “app.py” to “acrn_configurator.py”.

Tracked-On: #6417
Signed-off-by: Kunhui-Li <kunhuix.li@intel.com>
2021-08-20 07:58:23 +08:00
Yang,Yu-chu c10ac227cc config-tools: remove unused package and add nosec to subprocess
The subprocess module is needed for calling package from python script.
Add #nosec for subprocess module importing.

Tracked-On: #6342
Signed-off-by: Yang,Yu-chu <yu-chu.yang@intel.com>
2021-08-13 16:11:42 +08:00
Yang,Yu-chu a4be0aa57b config-tools: add native log area address
Extract the log area address from TPM2 acpi table and add node
log_area_start_address to board.xml. This emelment is used by host_pa of
mmiodevs.

Tracked-On: #6320
Signed-off-by: Yang,Yu-chu <yu-chu.yang@intel.com>
2021-08-13 11:09:01 +08:00
Yang,Yu-chu f3125e58ed config-tools: add tpm2 acpi parser to board_inspector
Create python script tpm2 which parse the tpm2 acpi table datas. Add
this parsed data to the <device id="MSFT0101" description="TPM 2.0 Device"> of board.xml.

Tracked-On: #6320
Signed-off-by: Yang,Yu-chu <yu-chu.yang@intel.com>
2021-08-11 14:45:55 +08:00
Junjie Mao 185b5d22e2 board-inspector: support buffer assignments and indexing
The ACPI specification allows both assigning to buffers and indexing to a
certain byte of a buffer using the Index operator. This patch adds the
implementation of these two operations in the interpreter.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-10 08:36:24 +08:00
Junjie Mao 50cd8e2558 board-inspector: fix the creation of packages
The PackageElementList builder takes variadic arguments, each of which is
an element of the package to be created, not a single argument being the
list of the elements. This patch fix the call to PackageElementList in
build_value() where the wrong type of argument was passed.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-10 08:36:24 +08:00
Junjie Mao 065316ba1e board-inspector: use the same _MIN and _MAX for 0-length regions
It is typical in AML resource descriptors to have 0-length region
descriptors which are typically templates of resources that are not
assigned on the current platform. For such regions, the `base + length - 1`
formula does not calculate the max of the region properly.

This patch updates the resource descriptor parsers to use max = min when
the length of the region is 0.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-10 08:36:24 +08:00
Junjie Mao bcc8358d93 board-inspector: fixes to issues when parsing host-bridge objects
When parsing an AML object representing a host bridge, the current board
inspector may encounter the following issues:

  1. The host DSDT may contain multiple host bridge instances, with some of
     them not being present. In this case the _BBN of these instances may
     evaluate to the same value that coincide with the bus assigned to an
     existing host bridge, leading to multiple PCI bus nodes with the same
     bus number and thus confusion in later information extraction phases.

  2. Methods of a host bridge may refer to the PCI configuration space of
     itself (which is typically Device 0, Function 0 under that
     bus). However, such objects may not have an _ADR object as the bus
     number is encoded by the _BBN object instead.

This patch fixes the issues above.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-10 08:36:24 +08:00
Junjie Mao 1e3b2a00b9 board-inspector: add interpretation of OnesOp, DefMatch and DefSizeOf
This patch enables the interpretation of the following AML objects.

  * OnesOp. A OnesOp object always evaluates to a 64-bit integer with all bits
    set to 1. It is assumed that the host DSDT is always revision 2 or above,
    which is typically the case on modern platforms.

  * DefMatch. A DefMatch object evaluates to the index of the first
    element (starting from a given index) in a package that matches the given
    two predicates. If a match is not found, the constant Ones is returned.

  * DefSizeOf. A DefSizeOf object evaluates to the byte length of a buffer, the
    length of a string (without the terminating NUL character) or the number of
    elements in a package.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-09 13:59:16 +08:00
Junjie Mao 4cb0d95fc0 board_inspector: try mroe type convertions when evaluating branch conditions
In commit e5ba06cbe8 ("board_inspector: a workaround to an incorrect
interpretation") a workaround is introduced to check the data type of
predicate operands. That commit assumes that both operands must be exactly
integers, which is not usually the case as operation fields or strings can
also be used in predicates.

This patch applies the following conversions on both operands when
evaluating a predicate:

  1. Try converting both operands to integers

  2. If either conversion in step 1 fails, try regarding both operands as
     strings.

  3. If either operand is not a string, return the default
     result (i.e. False).

Fixes: e5ba06cbe8 ("board_inspector: a workaround to an incorrect interpretation")
Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-09 13:59:16 +08:00
Junjie Mao 25cabe14db board-inspector: replace enter_scope with change_scope
The method `enter_scope` of class `Context` is a reduced implementation of
`change_scope` which assumes that the given name is simply a NameSeg. This
method is currently only used when a new named scope is opened by a
DefDevice object for historical reasons.

As the other named-scope-opening objects all use `change_scope` which can
handle arbitrary NameString, this patch unifies the code by removing
`enter_scope` and replacing the only occurrence with `change_scope`. This
also resolves the parsing of AML templates in board XMLs where device names
can be more than a simple NameSeg.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-09 13:59:16 +08:00
Junjie Mao 2dd9ec8612 board_inspector: do not use _MAX as the end of a memory region
According to the specification, the _MAX of memory address space resource
descriptors may not necessarily be _MIN + _LEN - 1. Typically the resource
locates at the low end of the region specified by _MIN and _MAX. This patch
makes the ACPI extractor always calculating the end of a memory region
using _MIN and _LEN instead.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-09 09:05:01 +08:00
Junjie Mao e5ba06cbe8 board_inspector: a workaround to an incorrect interpretation
The current design of AML parsing, objects are first defined in the
namespace and later dropped if they are in a False branch. This leads to
incorrect interpretation of the AML code where:

  1. A name T is defined in the root scope as an integer.

  2. A method M in an inner scope S references T.

  3. The name T is defined as a device, power resource or other named
     objects in scope S under conditions where M will not be called.

As a workaround, check if both the left and right hand sides are integers
first. If either is not the case,

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-09 09:05:01 +08:00
Junjie Mao edfac3ce62 board_inspector/cli: export PATH to the legacy board parser
Customized environment variables are not inherited to child processes
created by the subprocess module. As a result the legacy board parser may
not be able to locate the prerequisite utilities if they can be found only
with the customized PATH.

This patch passes the PATH of cli.py to the legacy parser so that both
scripts use the same PATH to search for utilities.

This patch is added in v2 of the series.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-09 09:05:01 +08:00
Junjie Mao 5223433a38 board_inspector/cli: replace `--advanced` with `--basic`
With a growing demand on host ACPI namespace for devices pass-through, it
is now important to parse the ACPI namespace when generating board
XMLs. This patch makes ACPI namespace parsing enabled by default by
replacing the `--advanced` option, which is designed to enable the parsing,
to `--basic` which disables it.

The option provides a reliable way to disable ACPI namespace parsing
completely in case the parsing blocks the generation of board XMLs, while
the ACPI namespace parser will gracefully stop without polluting the board
XML when it fails.

This patch is added in v2 of the patch series.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-09 09:05:01 +08:00
Junjie Mao 0f4275b041 board-inspector: collect address bits of processors
This patch updates the board inspector to collect the bits of physical and
linear addresses of the processors and generate this information to the
board XML for further uses at configuration phase.

Tracked-On: #6292
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-09 09:05:01 +08:00
Junjie Mao 3b41713c7e board_inspector: make filtering by device status optional
It is witnessed on some boards that the device status (as is reported by
the _STA object) returns 0 while the device object is still useful for
pass-through devices. The original implementation, however, assumes that
only a device is a non-zero status is useful as long as the _STA object
exists.

This patch makes this filtering disabled by default and adds a command-line
argument `--check-device-status` to enable this filtering. As disabled or
non-present devices can have empty resources, the sorting algorithm is
updated accordingly to gracefully handle such descriptors.

This patch is added in v3 of the series.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-09 09:05:01 +08:00
Junjie Mao 5d44640515 board_inspector: add conversion to hex string from buffer fields
Occasionally buffer fields (which are typically integers) are converted to
hexadecimal strings for debugging purposes. This patch adds the conversion
to suppress interpretation errors of these debugging calls.

This patch is added in v3 of the series.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-09 09:05:01 +08:00
Junjie Mao d66c62aad1 board_inspector: scanning all peer root hostbridges in domain 0
Servers typically have multiple peer host bridges that need to be scanned
separately. This patch extends the PCI information extractor to visit all
PCI host bridges by enumerating /sys/devices/pci* directories.

Tracked-On: #6292
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-09 09:05:01 +08:00
Junjie Mao ae496de9d8 board_inspector: allow ConstObj to be used as a TermObj
While not allowed by ACPI specification, using a ConstObj (e.g. OneOp) as a
term in a TermList IS witnessed in the DSDT of some BIOS. This patch allows
ConstObj to act as a TermObj so that a TermList can contain a ConstObj as a
statement (which is essentially no-op).

This patch is added in v2 of the series.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-09 09:05:01 +08:00
Junjie Mao 6be3f93173 board_inspector: resume a device if it is not in D0
It is seen that the BAR in the PCI configuration space of a device can be
cleared when the device is put to D3. This patch resumes a device not in D0
before parsing its configuration space in order to collect accurate
information.

This patch is added in v2 of the series.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-09 09:05:01 +08:00
Junjie Mao d6e47bcea5 board_inspector: collect inter-device dependency in board XMLs
AML allows devices defined in an ACPI namespace to have inter-dependency,
i.e. a method defined in one device can refer to objects in other
devices. While such inter-dependency is common in device manipulation
methods, device identification and configuration methods, such as _CRS, may
depend on other devices as well.

An example we have already met is a PCS (Physical Coding Sublayer) which
calculates resource descriptors by accessing the PCI configuration space of
the accompanying Ethernet controller. Without the ACPI object describing
the PCS, a driver of the Ethernet controller may refuse to initialize.

This patch adds a preliminary dependency analyzer to detect such
inter-device dependency. The analyzer walks through the reference chains of
an object, identifying whether the referenced objects are operation fields
of a device. Depending on the result of this analysis, the board XML is
refined as follows.

  * When an object (probably a method) references such fields, the original
    object definition in host DSDT/SSDTs will be copied in the AML template
    so that they still work in VMs where the operation fields may be
    virtualized. Such objects will be referred to as "copied objects"
    hereinafter.

  * The objects that are **directly** referenced by a copied object is
    added in the AML template as well. Such objects still belong to devices
    where they are originally defined in the host ACPI namespace. Their
    definition, however, may be copied or replaced with constant values,
    depending on the dependency analysis on these objects.

  * Nodes with the "dependency" tag are added under "device" nodes in the
    board XML, allowing the configuration tools to follow the device
    dependency chain when generating vACPI tables. These nodes only
    represent direct dependencies; indirect dependencies can be inferred by
    following those direct ones.

The current implementation does not allow objects being added to AML
templates if they refer to any of the following.

  * Global objects, i.e. objects not belonging to any device. Such objects
    tend to encode system-wide information, such as the ACPI
    NVS (Non-Volatile Storage) or its fields.

  * Methods with parameters.

Objects with such references are thus being hidden from guest software,
just like how they are invisible in the current implementation.

This patch is added in v2 of the series.

v2 -> v3:
  * Also collect dependencies due to providing or consuming resources.
  * Refactor the dependency detection logic for clarity.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-09 09:05:01 +08:00
Junjie Mao a2e9a05737 board_inspector: add GPIO and generic serial connection parsers
GPIO and generic serial connection resources in ACPI resource descriptors
usually encode resource sources which are important in detecting
cross-device dependencies. This patch adds parsers for GPIO and generic
serial connection descriptors.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-09 09:05:01 +08:00
Junjie Mao 52c3ed7e09 board_inspector: add AML templates to board XML
This patch adds AML template (in XML hexBinary format) for each device to
board XMLs. For now these templates contain the following objects if they
exists in the physical DSDT:

  - Device identification objects: _ADR, _HID, _UID and _STR
  - _CRS which encodes the current resources consumed by the device
  - _STA which encodes the status of the device

An AML template is always a DefScope with a single DefDevice so that they
can be appended anywhere in the vDSDT.

v1 -> v2:
  * Remove the temporary visitor that collects cross-device dependencies. Such
    check will be replaced with another visitor introduced in the next patch.

v2 -> v3:
  * The AML templates are now DefDevice objects with their names being the
    full namepath. The vDSDT generator will take care of this and organize
    the objects properly.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-09 09:05:01 +08:00
Junjie Mao 6ccd7660a4 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>
2021-08-09 09:05:01 +08:00
Junjie Mao d58ef5e2aa board_inspector: skip visiting DefMethod properly when unregistering symbols
The current implementation of the ConditionallyUnregisterSymbolVisitor
exits upon visiting a DefMethod node without unregistering that method. As
a result, methods in False branches in DSDT/SSDTs are not removed from the
parsed namespace, which can lead to further confusions when these methods
are referenced (e.g. a _CRS method visited by the board inspector).

This patch fixes this by always visiting a DefMethod node but stops
traversing its children.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-09 09:05:01 +08:00
Junjie Mao 5ad06e933a board_inspector: also try /usr/share/pci.ids.gz for PCI ID lookup
/usr/share/pci.ids.gz is another typical path to the pci.ids file of the
lspci tool which is used in Yocto-based systems. This patch adds this path
as another candidate when searching for pci.ids. The builtin gzip module is
used to open this file.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-09 09:05:01 +08:00
Junjie Mao 1e092a89d6 board_inspector: add default value to address space descriptors
Address space resource descriptors have an optional field to encode the
resource source, which is not commonly used when creating new resource
descriptors.

For modules which want to create a class to parse address space resource
descriptors without resource source, this patch sets the length of such
descriptors as the default value of the `_len` factory parameter so that
callers do not need to care about these lengths.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-08-09 09:05:01 +08:00