mirror of
https://github.com/u-boot/u-boot.git
synced 2024-12-05 02:23:31 +08:00
acpi: Support writing a string
ACPI supports storing a simple null-terminated string. Add support for this. 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:
parent
83b2bd5a74
commit
3df33bda5c
@ -24,6 +24,7 @@ enum {
|
|||||||
BYTE_PREFIX = 0x0a,
|
BYTE_PREFIX = 0x0a,
|
||||||
WORD_PREFIX = 0x0b,
|
WORD_PREFIX = 0x0b,
|
||||||
DWORD_PREFIX = 0x0c,
|
DWORD_PREFIX = 0x0c,
|
||||||
|
STRING_PREFIX = 0x0d,
|
||||||
QWORD_PREFIX = 0x0e,
|
QWORD_PREFIX = 0x0e,
|
||||||
PACKAGE_OP = 0x12,
|
PACKAGE_OP = 0x12,
|
||||||
};
|
};
|
||||||
@ -155,4 +156,13 @@ char *acpigen_write_package(struct acpi_ctx *ctx, int nr_el);
|
|||||||
*/
|
*/
|
||||||
void acpigen_write_integer(struct acpi_ctx *ctx, u64 data);
|
void acpigen_write_integer(struct acpi_ctx *ctx, u64 data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* acpigen_write_string() - Write a string
|
||||||
|
*
|
||||||
|
* This writes a STRING_PREFIX followed by a null-terminated string
|
||||||
|
*
|
||||||
|
* @ctx: ACPI context pointer
|
||||||
|
* @str: String to write
|
||||||
|
*/
|
||||||
|
void acpigen_write_string(struct acpi_ctx *ctx, const char *str);
|
||||||
#endif
|
#endif
|
||||||
|
@ -147,3 +147,9 @@ void acpigen_emit_string(struct acpi_ctx *ctx, const char *str)
|
|||||||
acpigen_emit_stream(ctx, str, str ? strlen(str) : 0);
|
acpigen_emit_stream(ctx, str, str ? strlen(str) : 0);
|
||||||
acpigen_emit_byte(ctx, '\0');
|
acpigen_emit_byte(ctx, '\0');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void acpigen_write_string(struct acpi_ctx *ctx, const char *str)
|
||||||
|
{
|
||||||
|
acpigen_emit_byte(ctx, STRING_PREFIX);
|
||||||
|
acpigen_emit_string(ctx, str);
|
||||||
|
}
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#define ACPI_CONTEXT_SIZE 150
|
#define ACPI_CONTEXT_SIZE 150
|
||||||
|
|
||||||
#define TEST_STRING "frogmore"
|
#define TEST_STRING "frogmore"
|
||||||
|
#define TEST_STRING2 "ranch"
|
||||||
#define TEST_STREAM2 "\xfa\xde"
|
#define TEST_STREAM2 "\xfa\xde"
|
||||||
|
|
||||||
#define TEST_INT8 0x7d
|
#define TEST_INT8 0x7d
|
||||||
@ -477,3 +478,30 @@ static int dm_test_acpi_integer(struct unit_test_state *uts)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
DM_TEST(dm_test_acpi_integer, 0);
|
DM_TEST(dm_test_acpi_integer, 0);
|
||||||
|
|
||||||
|
/* Test writing a string */
|
||||||
|
static int dm_test_acpi_string(struct unit_test_state *uts)
|
||||||
|
{
|
||||||
|
struct acpi_ctx *ctx;
|
||||||
|
u8 *ptr;
|
||||||
|
|
||||||
|
ut_assertok(alloc_context(&ctx));
|
||||||
|
|
||||||
|
ptr = acpigen_get_current(ctx);
|
||||||
|
|
||||||
|
acpigen_write_string(ctx, TEST_STRING);
|
||||||
|
acpigen_write_string(ctx, TEST_STRING2);
|
||||||
|
|
||||||
|
ut_asserteq(2 + sizeof(TEST_STRING) + sizeof(TEST_STRING2),
|
||||||
|
acpigen_get_current(ctx) - ptr);
|
||||||
|
ut_asserteq(STRING_PREFIX, ptr[0]);
|
||||||
|
ut_asserteq_str(TEST_STRING, (char *)ptr + 1);
|
||||||
|
ptr += 1 + sizeof(TEST_STRING);
|
||||||
|
ut_asserteq(STRING_PREFIX, ptr[0]);
|
||||||
|
ut_asserteq_str(TEST_STRING2, (char *)ptr + 1);
|
||||||
|
|
||||||
|
free_context(&ctx);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
DM_TEST(dm_test_acpi_string, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user