diff options
author | Simon Glass <sjg@chromium.org> | 2020-07-07 13:11:50 -0600 |
---|---|---|
committer | Bin Meng <bmeng.cn@gmail.com> | 2020-07-17 14:32:24 +0800 |
commit | 7e148f2ed365c89f50701ed45acd6e36138de447 (patch) | |
tree | ba5c7a575add711589a21a5b1b1527094e42c8ca /include/acpi | |
parent | 70e5e67a4dc7cee0c69eaf9f5cc07b201a59cb59 (diff) | |
download | u-boot-7e148f2ed365c89f50701ed45acd6e36138de447.tar.gz |
acpigen: Support writing a length
It is convenient to write a length value for preceding a block of data.
Of course the length is not known or is hard to calculate a priori. So add
a way to mark the start on a stack, so the length can be updated when
known.
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Diffstat (limited to 'include/acpi')
-rw-r--r-- | include/acpi/acpigen.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/include/acpi/acpigen.h b/include/acpi/acpigen.h index 9c1faf7bf2..18409b613c 100644 --- a/include/acpi/acpigen.h +++ b/include/acpi/acpigen.h @@ -14,6 +14,9 @@ struct acpi_ctx; +/* Top 4 bits of the value used to indicate a three-byte length value */ +#define ACPI_PKG_LEN_3_BYTES 0x80 + /** * acpigen_get_current() - Get the current ACPI code output pointer * @@ -65,4 +68,42 @@ void acpigen_emit_stream(struct acpi_ctx *ctx, const char *data, int size); */ void acpigen_emit_string(struct acpi_ctx *ctx, const char *str); +/** + * acpigen_write_len_f() - Write a 'forward' length placeholder + * + * This adds space for a length value in the ACPI stream and pushes the current + * position (before the length) on the stack. After calling this you can write + * some data and then call acpigen_pop_len() to update the length value. + * + * Usage: + * + * acpigen_write_len_f() ------\ + * acpigen_write...() | + * acpigen_write...() | + * acpigen_write_len_f() --\ | + * acpigen_write...() | | + * acpigen_write...() | | + * acpigen_pop_len() ------/ | + * acpigen_write...() | + * acpigen_pop_len() ----------/ + * + * See ACPI 6.3 section 20.2.4 Package Length Encoding + * + * This implementation always uses a 3-byte packet length for simplicity. It + * could be adjusted to support other lengths. + * + * @ctx: ACPI context pointer + */ +void acpigen_write_len_f(struct acpi_ctx *ctx); + +/** + * acpigen_pop_len() - Update the previously stacked length placeholder + * + * Call this after the data for the block has been written. It updates the + * top length value in the stack and pops it off. + * + * @ctx: ACPI context pointer + */ +void acpigen_pop_len(struct acpi_ctx *ctx); + #endif |