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>
This commit is contained in:
parent
a6f7459f38
commit
575ee135d1
|
@ -3,11 +3,8 @@
|
||||||
/* How much nesting do we support? */
|
/* How much nesting do we support? */
|
||||||
#define ACPIGEN_LENSTACK_SIZE 10
|
#define ACPIGEN_LENSTACK_SIZE 10
|
||||||
|
|
||||||
/*
|
/* If you need to change this, change acpigen_pop_len too */
|
||||||
* If you need to change this, change acpigen_write_len_f and
|
#define ACPIGEN_RSVD_PKGLEN_BYTES 3
|
||||||
* acpigen_pop_len
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define ACPIGEN_MAXLEN 0xfffff
|
#define ACPIGEN_MAXLEN 0xfffff
|
||||||
|
|
||||||
#include <lib.h>
|
#include <lib.h>
|
||||||
|
@ -29,10 +26,9 @@ void acpigen_write_len_f(void)
|
||||||
{
|
{
|
||||||
ASSERT(ltop < (ACPIGEN_LENSTACK_SIZE - 1))
|
ASSERT(ltop < (ACPIGEN_LENSTACK_SIZE - 1))
|
||||||
len_stack[ltop++] = gencurrent;
|
len_stack[ltop++] = gencurrent;
|
||||||
/* Reserve 3 bytes for PkgLength. The actual byte values will be written later in the
|
/* Reserve ACPIGEN_RSVD_PKGLEN_BYTES bytes for PkgLength. The actual byte values will
|
||||||
acpigen_pop_len call. */
|
be written later in the corresponding acpigen_pop_len call. */
|
||||||
acpigen_emit_byte(0);
|
for (size_t i = 0; i < ACPIGEN_RSVD_PKGLEN_BYTES; i++)
|
||||||
acpigen_emit_byte(0);
|
|
||||||
acpigen_emit_byte(0);
|
acpigen_emit_byte(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,13 +39,14 @@ void acpigen_pop_len(void)
|
||||||
char *p = len_stack[--ltop];
|
char *p = len_stack[--ltop];
|
||||||
len = gencurrent - p;
|
len = gencurrent - p;
|
||||||
ASSERT(len <= ACPIGEN_MAXLEN)
|
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) {
|
if (len <= 0x3f + 2) {
|
||||||
/* PkgLength of up to 0x3f can be encoded in one PkgLength byte instead of the
|
/* 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
|
reserved 3 bytes. Since only 1 PkgLength byte will be written, the payload
|
||||||
data needs to be moved by 2 bytes */
|
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
|
/* Adjust the PkgLength to take into account that we only use 1 of the 3
|
||||||
reserved bytes */
|
reserved bytes */
|
||||||
len -= 2;
|
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
|
/* 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
|
reserved 3 bytes. Since only 2 PkgLength bytes will be written, the payload
|
||||||
data needs to be moved by 1 byte */
|
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
|
/* Adjust the PkgLength to take into account that we only use 2 of the 3
|
||||||
reserved bytes */
|
reserved bytes */
|
||||||
len -= 1;
|
len -= 1;
|
||||||
|
|
Loading…
Reference in New Issue