diff options
author | Felix Held <felix-coreboot@felixheld.de> | 2023-11-13 14:50:35 +0100 |
---|---|---|
committer | Felix Held <felix-coreboot@felixheld.de> | 2023-11-15 13:52:59 +0000 |
commit | 575ee135d19263d293683a8b7f47377a3c043ae7 (patch) | |
tree | cffd0e46c117bf5ebc81eb52602828ac9bcb68ea /src/acpi | |
parent | a6f7459f38195377d7fddcf39d241bd7f0027a1c (diff) |
acpi/acpigen: introduce and use ACPIGEN_RSVD_PKGLEN_BYTES
Use a define instead of magic numbers.
Signed-off-by: Felix Held <felix-coreboot@felixheld.de>
Change-Id: I2c6d17bd78a0e207f9130102b43ba78aa55ce377
Reviewed-on: https://review.coreboot.org/c/coreboot/+/79046
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Matt DeVillier <matt.devillier@gmail.com>
Reviewed-by: Nico Huber <nico.h@gmx.de>
Diffstat (limited to 'src/acpi')
-rw-r--r-- | src/acpi/acpigen.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/acpi/acpigen.c b/src/acpi/acpigen.c index e5d76ba58e..7479dce7fe 100644 --- a/src/acpi/acpigen.c +++ b/src/acpi/acpigen.c @@ -3,12 +3,9 @@ /* How much nesting do we support? */ #define ACPIGEN_LENSTACK_SIZE 10 -/* - * If you need to change this, change acpigen_write_len_f and - * acpigen_pop_len - */ - -#define ACPIGEN_MAXLEN 0xfffff +/* If you need to change this, change acpigen_pop_len too */ +#define ACPIGEN_RSVD_PKGLEN_BYTES 3 +#define ACPIGEN_MAXLEN 0xfffff #include <lib.h> #include <string.h> @@ -29,11 +26,10 @@ void acpigen_write_len_f(void) { ASSERT(ltop < (ACPIGEN_LENSTACK_SIZE - 1)) len_stack[ltop++] = gencurrent; - /* Reserve 3 bytes for PkgLength. The actual byte values will be written later in the - acpigen_pop_len call. */ - acpigen_emit_byte(0); - acpigen_emit_byte(0); - acpigen_emit_byte(0); + /* Reserve ACPIGEN_RSVD_PKGLEN_BYTES bytes for PkgLength. The actual byte values will + be written later in the corresponding acpigen_pop_len call. */ + for (size_t i = 0; i < ACPIGEN_RSVD_PKGLEN_BYTES; i++) + acpigen_emit_byte(0); } void acpigen_pop_len(void) @@ -43,13 +39,14 @@ void acpigen_pop_len(void) char *p = len_stack[--ltop]; len = gencurrent - p; ASSERT(len <= ACPIGEN_MAXLEN) - const size_t payload_len = len - 3; + const size_t payload_len = len - ACPIGEN_RSVD_PKGLEN_BYTES; if (len <= 0x3f + 2) { /* PkgLength of up to 0x3f can be encoded in one PkgLength byte instead of the reserved 3 bytes. Since only 1 PkgLength byte will be written, the payload data needs to be moved by 2 bytes */ - memmove(&p[1], &p[3], payload_len); + memmove(&p[ACPIGEN_RSVD_PKGLEN_BYTES - 2], + &p[ACPIGEN_RSVD_PKGLEN_BYTES], payload_len); /* Adjust the PkgLength to take into account that we only use 1 of the 3 reserved bytes */ len -= 2; @@ -63,7 +60,8 @@ void acpigen_pop_len(void) /* PkgLength of up to 0xfff can be encoded in 2 PkgLength bytes instead of the reserved 3 bytes. Since only 2 PkgLength bytes will be written, the payload data needs to be moved by 1 byte */ - memmove(&p[2], &p[3], payload_len); + memmove(&p[ACPIGEN_RSVD_PKGLEN_BYTES - 1], + &p[ACPIGEN_RSVD_PKGLEN_BYTES], payload_len); /* Adjust the PkgLength to take into account that we only use 2 of the 3 reserved bytes */ len -= 1; |