Commit Graph

4085 Commits

Author SHA1 Message Date
Saket Dumbre a597e3b247 Add support for _DSC as per ACPI 6.5 2023-04-25 10:52:21 -07:00
Philip Prindeville aea0a5cfce Fix GCC 12 dangling-pointer warning
We're storing a persistent pointer to an ephemeral local variable
which technically is a dangling pointer and the compiler is correct.
However, since we never indirect the pointer, this is a safe
operation and we can suppress the warning.

Also, some C run-times (like MUSL) aren't including <stdint.h>
indirectly so we must include it explicitly or we won't have the
type definition for uintptr_t.

Fixes issue #867.

Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
2023-04-13 17:43:07 -06:00
Robert Moore 4578e0e94d Update version to 20230331,
Version 20230331.
2023-03-31 10:39:09 -07:00
Robert Moore a7a4a51ca6 Automated cleanup.
Remove tabs, indentation fixes, etc.
2023-03-31 08:42:00 -07:00
Najumon 463d30f0a8 add os specific support for Zephyr RTOS
The acpica will be integrated as module into Zephyr project for
enable acpi bus driver. This patch is for enable os specific
support layer for Zephyr.

Signed-off-by: Najumon <najumon.ba@intel.com>
2023-03-30 10:42:12 +05:30
Robert Moore f98909b792 Fixes for ACPI_FLEX_ARRAY, to eliminate warnings on MSVC
Saket Dumbre.
2023-03-24 11:48:40 -07:00
Saket Dumbre b93300b237
Merge pull request #846 from tamird/ub-linux-nonkernel
Avoid undefined behavior: member access within null pointer
2023-03-22 15:37:53 -07:00
Saket Dumbre 01f11f2671
Merge pull request #804 from vlsunil/riscv_b1_ecr
Add first batch of RISC-V related definitions
2023-03-22 15:27:56 -07:00
Saket Dumbre 3a91cb5877
Merge pull request #856 from kees/flex-array-take2
Flex array transformations, take 2
2023-03-22 15:22:37 -07:00
Robert Moore 51aff5169e
Merge pull request #794 from jrtc27/aest-pointer
Headers: Delete bogus NodeArray array of pointers from AEST table
2023-03-22 12:55:37 -07:00
Kees Cook bfdd3446e7 ACPI_RESOURCE_IRQ: Replace 1-element arrays with flexible array
Similar to commit 7ba2f3d91a ("Replace one-element array with
flexible-array"), replace the 1-element array with a proper
flexible array member as defined by C99. This allows the code to
operate without tripping compile-time and run-time bounds checkers
(e.g. via __builtin_object_size(), -fsanitize=bounds, and/or
-fstrict-flex-arrays=3). Note that the spec requires there be at least
one interrupt, so use a union to keep space allocated for this.

The only binary change in .text and .data sections is some rearrangement
by the compiler of AcpiDmAddressCommon(), but appears to be harmless.
2023-03-02 11:03:42 -08:00
Kees Cook e7f6d8c1b7 ACPI_MADT_OEM_DATA: Fix flexible array member definition
Use ACPI_FLEX_ARRAY() helper to define flexible array member alone in a
struct. Fixes issue #812.

No binary changes appear in the .text nor .data sections.
2023-03-02 11:03:42 -08:00
Kees Cook 3c19ae7042 ACPI_DMAR_ANDD: Replace 1-element array with flexible array
Similar to commit 7ba2f3d91a ("Replace one-element array with
flexible-array"), replace the 1-element array with a proper
flexible array member as defined by C99. This allows the code to
operate without tripping compile-time and run-time bounds checkers
(e.g. via __builtin_object_size(), -fsanitize=bounds, and/or
-fstrict-flex-arrays=3).

The handling of ACPI_DMAR_ANDD by AcpiDmDumpDmar() appears to expect a
single trailing char for calculating table offsets. Keep a char in the
union to avoid any code changes appearing in the .text or .data
sections.

Signed-off-by: Kees Cook <kees@outflux.net>
2023-03-02 11:03:42 -08:00
Kees Cook f4a3afd78c ACPI_PCI_ROUTING_TABLE: Replace fixed-size array with flex array member
The "Source" array is actually a dynamically sized array, but it
is defined as a fixed-size 4 byte array. This results in tripping
both compile-time and run-time bounds checkers (e.g. via either
__builtin_object_size() or -fsanitize=bounds).

To retain the padding, create a union with an unused Pad variable of
size 4, and redefine Source as a proper flexible array member.

No binary changes appear in the .text nor .data sections.
2023-03-02 11:03:42 -08:00
Kees Cook 8409bb869a ACPI_RESOURCE_DMA: Replace 1-element array with flexible array
Similar to commit 7ba2f3d91a ("Replace one-element array with
flexible-array"), replace the 1-element array with a proper flexible array
member as defined by C99, but without changing the structure size. This
allows the code to operate without tripping compile-time and run-time
bounds checkers (e.g. via __builtin_object_size(), -fsanitize=bounds,
and/or -fstrict-flex-arrays=3). As with IRQs, leave a single element in
a union.

No binary changes appear in the .text nor .data sections.
2023-03-02 11:03:42 -08:00
Kees Cook e73b227e8e Introduce ACPI_FLEX_ARRAY
In order to enable using -fstrict-flex-arrays with GCC and Clang in the
Linux kernel, each trailing dynamically sized array must be defined as
proper C99 "flexible array members" (FAM). Unfortunately, ACPICA has a
bunch of technical debt, dating back to before even the GNU extension of
0-length arrays, meaning the code base has many 1-element and 0-length
arrays defined at the end of structures that should actually be FAMs.

One limitation of the C99 FAM specification is the accidental requirement
that they cannot be in unions or alone in structs. There is no real-world
reason for this, though, and, actually, the existing GNU extension
permits this for 0-length arrays (which get treated as FAMs).

Add the ACPI_FLEX_ARRAY() helper macro to work around this requirement
so that FAMs can be defined in unions or alone in structs. Since this
behavior still depends on GNU extensions, keep the macro specific to GCC
(and Clang) builds. In this way, MSVC will continue to use 0-length
arrays (since it does not support the union work-around). When MSVC
grows support for this in the future, the macro can be updated.
2023-03-02 11:03:42 -08:00
Kees Cook e66decc6fc ACPI_NFIT_INTERLEAVE: Replace 1-element array with flexible array
Similar to commit 7ba2f3d91a ("Replace one-element array with
flexible-array"), replace the 1-element array with a proper
flexible array member as defined by C99. This allows the code to
operate without tripping compile-time and run-time bounds checkers
(e.g. via __builtin_object_size(), -fsanitize=bounds, and/or
-fstrict-flex-arrays=3).

Unlike ACPI_NFIT_FLUSH_ADDRESS and ACPI_NFIT_SMBIOS, which had their
sizeof() uses adjusted in code, ACPI_NFIT_INTERLEAVE did not. This appears
to have been a bug. After this change, there is a binary difference in
AcpiDmDumpNfit() since the size of the structure now has the correct size,
as the prior result was including the trailing U32:

-       mov    $0x14,%ebp
+       mov    $0x10,%ebp

Signed-off-by: Kees Cook <kees@outflux.net>
2023-03-02 11:03:42 -08:00
Kees Cook 44f1af0664 actbl2: Replace 1-element arrays with flexible arrays
Similar to commit 7ba2f3d91a ("Replace one-element array with
flexible-array"), replace the 1-element array with a proper
flexible array member as defined by C99. This allows the code to
operate without tripping compile-time and run-time bounds checkers
(e.g. via __builtin_object_size(), -fsanitize=bounds, and/or
-fstrict-flex-arrays=3).

The sizeof() uses with ACPI_NFIT_FLUSH_ADDRESS and ACPI_NFIT_SMBIOS have
been adjusted to drop the open-coded subtraction of the trailing single
element. The result is no binary differences in .text nor .data sections.
2023-03-02 11:03:42 -08:00
Kees Cook 8c9bd5d151 actbl1: Replace 1-element arrays with flexible arrays
Similar to commit 7ba2f3d91a ("Replace one-element array with
flexible-array"), replace the 1-element array with a proper
flexible array member as defined by C99. This allows the code to
operate without tripping compile-time and run-time bounds checkers
(e.g. via __builtin_object_size(), -fsanitize=bounds, and/or
-fstrict-flex-arrays=3).

No .text nor .data differences result from this change.
2023-03-02 11:03:42 -08:00
Kees Cook 151a44c5da ACPI_EFI_FILE_INFO: Replace 1-element array with flexible array
Similar to commit 7ba2f3d91a ("Replace one-element array with
flexible-array"), replace the 1-element array with a proper
flexible array member as defined by C99. This allows the code to
operate without tripping compile-time and run-time bounds checkers
(e.g. via __builtin_object_size(), -fsanitize=bounds, and/or
-fstrict-flex-arrays=3).

No binary changes appear in the .text nor .data sections.
2023-03-02 11:02:28 -08:00
Kees Cook 446d05d5ea ACPI_RESOURCE_VENDOR: Replace 1-element array with flexible array
Similar to commit 7ba2f3d91a ("Replace one-element array with
flexible-array"), replace the 1-element array with a proper
flexible array member as defined by C99. This allows the code to
operate without tripping compile-time and run-time bounds checkers
(e.g. via __builtin_object_size(), -fsanitize=bounds, and/or
-fstrict-flex-arrays=3).

No binary changes appear in the .text nor .data sections.
2023-03-02 11:02:28 -08:00
Tamir Duberstein 2411e11ef8
Avoid undefined behavior: member access within null pointer
84449c1eef fixed this for Linux kernel
builds, but not Linux userspace builds.

Before this change we see the following UBSAN stack trace in Fuchsia:

  ../../third_party/acpica/source/components/tables/tbfadt.c:536:39: runtime error: member access within null pointer of type 'ACPI_TABLE_FADT' (aka 'struct acpi_table_fadt')
      #0 0x564860b5ee9b in AcpiTbConvertFadt ../../third_party/acpica/source/components/tables/tbfadt.c:536:39
      #1 0x564860b5edb4 in AcpiTbCreateLocalFadt ../../third_party/acpica/source/components/tables/tbfadt.c:461:5
      #2 0x564860b5e5c6 in AcpiTbParseFadt ../../third_party/acpica/source/components/tables/tbfadt.c:371:5
      #3 0x564860b5c485 in AcpiTbParseRootTable ../../third_party/acpica/source/components/tables/tbutils.c:407:13
      #4 0x564860b6401a in AcpiInitializeTables ../../third_party/acpica/source/components/tables/tbxface.c:160:14
      #5 0x5648608fb417 in acpi_host_test::AcpiHostTest::InitAcpiWithTables(char const*) ../../src/devices/board/tests/acpi-host-tests/acpi-host-test.cc:36:5
      #6 0x5648608f9095 in acpi_host_test::AcpiHostTest_DeviceIsChildOfScopeTest_Test::TestBody() ../../src/devices/board/tests/acpi-host-tests/acpi-host-test.cc:85:3
      #7 0x564860c6007e in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) ../../third_party/googletest/src/googletest/src/gtest.cc:2609:10
      #8 0x564860bbd5df in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) ../../third_party/googletest/src/googletest/src/gtest.cc:2664:12    #9 0x564860bbd141 in testing::Test::Run() ../../third_party/googletest/src/googletest/src/gtest.cc:2684:5    #10 0x564860bbff0a in testing::TestInfo::Run() ../../third_party/googletest/src/googletest/src/gtest.cc:2864:11    #11 0x564860bc40f1 in testing::TestSuite::Run() ../../third_party/googletest/src/googletest/src/gtest.cc:3023:30    #12 0x564860beba40 in testing::internal::UnitTestImpl::RunAllTests() ../../third_party/googletest/src/googletest/src/gtest.cc:5882:44
      #13 0x564860c7db6e in bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) ../../third_party/googletest/src/googletest/src/gtest.cc:2609:10
      #14 0x564860bea71f in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) ../../third_party/googletest/src/googletest/src/gtest.cc:2664:12    #15 0x564860bea1c5 in testing::UnitTest::Run() ../../third_party/googletest/src/googletest/src/gtest.cc:5456:10    #16 0x5648608fccc0 in RUN_ALL_TESTS() ../../third_party/googletest/src/googletest/include/gtest/gtest.h:2304:73    #17 0x5648608fcb7e in main ../../src/devices/board/tests/acpi-host-tests/acpi-host-test.cc:121:10    #18 0x7f6defa2d189  (/lib/x86_64-linux-gnu/libc.so.6+0x27189) (BuildId: c4f6727c560b1c33527ff9e0ca0cef13a7db64d2)
      #19 0x7f6defa2d244 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x27244) (BuildId: c4f6727c560b1c33527ff9e0ca0cef13a7db64d2)
      #20 0x56486082e598  (/usr/local/google/home/tamird/src/fuchsia/out/core.x64/host_x64/acpi-host-test-bin+0x359598) (BuildId: 851423b0e664df6a)
2023-02-27 13:56:34 -05:00
Robert Moore 15b939b034
Merge pull request #829 from jepio/aspt-support
Add support for AMD Secure Processor Table (ASPT) version 1
2023-02-17 12:33:38 -08:00
Robert Moore c9e01891e1
Merge pull request #834 from ElyesH/prototypes
Remove extern prototypes in achaiku.h file
2023-02-14 08:15:11 -08:00
Sunil V L 82afd0434e Add structure definitions for RISC-V RHCT
RISC-V Hart Capabilities Table (RHCT) is a new static table.
The ECR to add RHCT is approved by the UEFI forum and will be
available in the next version of the ACPI spec.

Reference: Mantis: 2349
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
2023-02-13 10:49:15 +05:30
Sunil V L bd6d1ae1e1 MADT: Add RISC-V INTC interrupt controller
The ECR to add RISC-V INTC interrupt controller is approved by
the UEFI forum and will be available in the next revision of
the ACPI specification.

Reference: Mantis ID: 2348

Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
2023-02-13 10:48:59 +05:30
Niyas Sait 661feab5ee add support for ClockInput resource (v6.5) 2023-02-08 11:20:04 +00:00
Robert Moore 0c9616eed6
Merge pull request #822 from heatd/acpisrc-linux-fix
acpisrc Linux generation fix
2023-02-07 12:45:00 -08:00
Robert Moore 801ccce4d9 Backout use of flexible array with no other structure elements:
actbl2.h:1555:29: error: flexible array member in a struct with no named members
2023-02-07 12:25:29 -08:00
Robert Moore 6dd672d342
Revert "Replace fake flexible arrays with actual flexible array members" 2023-02-07 10:55:00 -08:00
Robert Moore 09483630ae
Revert "Headers: Replace zero-length array with flexible-array member" 2023-02-07 10:42:28 -08:00
Robert Moore f6734e2407
Revert "Fix dangling pointer warning for AcpiUtInitStackPtrTrace" 2023-02-07 10:35:35 -08:00
Robert Moore 8e305d43ea
Merge pull request #776 from t-8ch/dangling-pointer
Fix dangling pointer warning for AcpiUtInitStackPtrTrace
2023-02-07 10:26:47 -08:00
Robert Moore 77c550223c
Merge pull request #773 from s-ailus/master
Constify AcpiGetHandle pathname argument
2023-02-07 10:23:28 -08:00
Robert Moore 2b00f7329b
Merge pull request #786 from jwrdegoede/split-acpi_install_address_space_handler
Make AddressSpaceHandler Install and _REG execution 2 separate steps
2023-02-07 10:20:43 -08:00
Robert Moore 26691f7adc
Merge pull request #805 from fenghust/master
ACPI 6.5: MADT: add support for trace buffer extension in GICC
2023-02-07 10:19:00 -08:00
Robert Moore c05f747c8d
Merge pull request #819 from heshamelmatary/mpam
Add support for Arm's MPAM ACPI table version 2
2023-02-07 10:13:24 -08:00
Robert Moore cf3220db5f
Merge pull request #813 from kees/flex-array
Replace fake flexible arrays with actual flexible array members
2023-02-07 10:09:04 -08:00
Robert Moore 5156a72859
Merge pull request #830 from l1k/master
Fix typo in CDAT DSMAS struct definition
2023-02-07 09:47:15 -08:00
Robert Moore 25bddd1824 Update all copyrights/signons to 2023
Copyright updates to 2023.
2023-02-07 09:33:27 -08:00
Elyes Haouas 5fe9e69b32 Remove extern prototypes in achaiku.h file
Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
2023-02-07 07:04:33 +01:00
Hesham Almatary 005e24bcaa Add support for Arm's MPAM ACPI table version 2
Complies with ACPI for Memory System Resource Partitioning and
Monitoring 2.0 [1]. Document number: DEN0065, as of December 2022.

Support for all types of MPAM resources. No support yet for:
1) MPAM PCC Interface Type
2) The optional Resource-specific data per MSC node, introduced in v2 of the
MPAM ACPI spec.

[1] https://developer.arm.com/documentation/den0065/latest

Signed-off-by: Hesham Almatary <hesham.almatary@huawei.com>
2023-01-31 09:30:53 +00:00
Lukas Wunner 9d8bd58d5f Fix typo in CDAT DSMAS struct definition
Signed-off-by: Lukas Wunner <lukas@wunner.de>
2023-01-28 07:27:19 +01:00
Jeremi Piotrowski 6771f8b758 Add support for ASPT table in disassembler
ASPT is the AMD Secure Processor table, found in Hyper-V VMs when SNP
isolation is exposed to the VM and in some high-end AMD servers. This
commit adds support for rev 1 of the ASPT spec in the disassembler.
2023-01-24 15:11:41 +00:00
Huacai Chen d809b69cf4 Add support for 64 bit LoongArch compilation
Add 64 bit LoongArch architecture by defining ACPI_MACHINE_WIDTH to 64.
Useful for acpica tools and incorporating ACPICA into the Firmware Test
Suite.

Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
2023-01-03 12:35:31 +08:00
Pedro Falcato d4a2c93198 acpisrc: Add missing tables to astable
Also renames ACPI_DATA_TABLE_MAPPING's struct to
acpi_data_table_mapping, just so conversion goes smoothly.

Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com>
2022-12-21 02:45:45 +00:00
Pedro Falcato 974cc668fc actbl2: Fix inconsistent indentation on some typedefs
This indirectly fixes acpisrc -l failures for these typedef structs.

Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com>
2022-12-21 00:27:19 +00:00
Kees Cook b1c7901e10 ACPI_PCI_ROUTING_TABLE: Replace fixed-size array with flex array member
The "Source" array is actually a dynamically sized array, but it
is defined as a fixed-size 4 byte array. This results in tripping
both compile-time and run-time bounds checkers (e.g. via either
__builtin_object_size() or -fsanitize=bounds).

To retain the padding, create a union with an unused Pad variable of
size 4, and redefine Source as a proper flexible array member.
2022-11-18 09:51:01 -08:00
Kees Cook 8a8443112b ACPI_RESOURCE_EXTENDED_IRQ: Replace 1-element array with flexible array
Similar to commit 7ba2f3d91a ("Replace one-element array with
flexible-array"), replace the 1-element array with a proper
flexible array member as defined by C99. This allows the code to
operate without tripping compile-time and run-time bounds checkers
(e.g. via __builtin_object_size(), -fsanitize=bounds, and/or
-fstrict-flex-arrays=3).
2022-11-18 09:50:48 -08:00
Kees Cook cc3a0ab278 ACPI_MADT_OEM_DATA: Fix flexible array member definition
Use ACPI_FLEX_ARRAY() helper to define flexible array member alone in a
struct. Fixes issue #812.
2022-11-18 09:50:48 -08:00