From 7437c16c27731b4e84a88d2daff294a4b197fef4 Mon Sep 17 00:00:00 2001 From: Felix Held Date: Wed, 26 Feb 2025 19:53:03 +0100 Subject: [PATCH] src/acpigen: support 0-initialized buffer in acpigen_write_byte_buffer Previously, the 'acpigen_write_byte_buffer' function required both the byte buffer length and the initialization data byte array 'arr'. The ACPI spec however allows buffer declarations with only the length, but without an initialization data byte array. In this case the AML interpreter will create a buffer of the given length with all bytes initialized to 0x00. In order to not need another function, allow the 'arr' parameter for the pointer to the initialization data byte array to be NULL and in that case don't write the optional buffer initialization byte array. TEST=Calling 'acpigen_write_byte_buffer' with 'NULL' as first parameter results in the AML code sequence being written which decompiles to ASL as expected. Change-Id: Ie756489e02f994c38d38907a97fb215d30f4a636 Signed-off-by: Felix Held Reviewed-on: https://review.coreboot.org/c/coreboot/+/86631 Reviewed-by: Matt DeVillier Tested-by: build bot (Jenkins) --- src/acpi/acpigen.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/acpi/acpigen.c b/src/acpi/acpigen.c index e577d8f96c..081fa2b25d 100644 --- a/src/acpi/acpigen.c +++ b/src/acpi/acpigen.c @@ -1775,6 +1775,8 @@ void acpigen_write_to_integer_from_namestring(const char *source, uint8_t dst_op acpigen_emit_byte(dst_op); } +/* The initializer byte array 'arr' is optional. When 'arr' is NULL, the AML interpreter will + create a 0-initialized byte buffer */ void acpigen_write_byte_buffer(uint8_t *arr, size_t size) { size_t i; @@ -1783,8 +1785,10 @@ void acpigen_write_byte_buffer(uint8_t *arr, size_t size) acpigen_write_len_f(); acpigen_write_integer(size); - for (i = 0; i < size; i++) - acpigen_emit_byte(arr[i]); + if (arr != NULL) { + for (i = 0; i < size; i++) + acpigen_emit_byte(arr[i]); + } acpigen_pop_len(); }