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>
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
#include <common.h>
|
||||
#include <dm.h>
|
||||
#include <log.h>
|
||||
#include <acpi/acpigen.h>
|
||||
#include <dm/acpi.h>
|
||||
|
||||
@@ -38,6 +39,38 @@ void acpigen_emit_dword(struct acpi_ctx *ctx, uint data)
|
||||
acpigen_emit_byte(ctx, (data >> 24) & 0xff);
|
||||
}
|
||||
|
||||
/*
|
||||
* Maximum length for an ACPI object generated by this code,
|
||||
*
|
||||
* If you need to change this, change acpigen_write_len_f(ctx) and
|
||||
* acpigen_pop_len(ctx)
|
||||
*/
|
||||
#define ACPIGEN_MAXLEN 0xfffff
|
||||
|
||||
void acpigen_write_len_f(struct acpi_ctx *ctx)
|
||||
{
|
||||
assert(ctx->ltop < (ACPIGEN_LENSTACK_SIZE - 1));
|
||||
ctx->len_stack[ctx->ltop++] = ctx->current;
|
||||
acpigen_emit_byte(ctx, 0);
|
||||
acpigen_emit_byte(ctx, 0);
|
||||
acpigen_emit_byte(ctx, 0);
|
||||
}
|
||||
|
||||
void acpigen_pop_len(struct acpi_ctx *ctx)
|
||||
{
|
||||
int len;
|
||||
char *p;
|
||||
|
||||
assert(ctx->ltop > 0);
|
||||
p = ctx->len_stack[--ctx->ltop];
|
||||
len = ctx->current - (void *)p;
|
||||
assert(len <= ACPIGEN_MAXLEN);
|
||||
/* generate store length for 0xfffff max */
|
||||
p[0] = ACPI_PKG_LEN_3_BYTES | (len & 0xf);
|
||||
p[1] = len >> 4 & 0xff;
|
||||
p[2] = len >> 12 & 0xff;
|
||||
}
|
||||
|
||||
void acpigen_emit_stream(struct acpi_ctx *ctx, const char *data, int size)
|
||||
{
|
||||
int i;
|
||||
|
||||
Reference in New Issue
Block a user