diff options
author | Simon Glass <sjg@chromium.org> | 2020-07-07 13:11:59 -0600 |
---|---|---|
committer | Bin Meng <bmeng.cn@gmail.com> | 2020-07-17 14:32:24 +0800 |
commit | 9c70e7e556339ce9fa864782445f7927fafc5c03 (patch) | |
tree | c3c08bc5386ba2e22ec8e0d3540916775283db41 /lib/acpi/acpigen.c | |
parent | 06679000493a07eb643287d1adfa4ffe6c3fc87c (diff) | |
download | u-boot-9c70e7e556339ce9fa864782445f7927fafc5c03.tar.gz u-boot-9c70e7e556339ce9fa864782445f7927fafc5c03.tar.bz2 u-boot-9c70e7e556339ce9fa864782445f7927fafc5c03.zip |
acpi: Add support for various misc ACPI opcodes
Add more functions to handle some miscellaneous ACPI opcodes.
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 'lib/acpi/acpigen.c')
-rw-r--r-- | lib/acpi/acpigen.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/lib/acpi/acpigen.c b/lib/acpi/acpigen.c index 3e8374e65e..4fd29ccb81 100644 --- a/lib/acpi/acpigen.c +++ b/lib/acpi/acpigen.c @@ -72,6 +72,12 @@ void acpigen_pop_len(struct acpi_ctx *ctx) p[2] = len >> 12 & 0xff; } +void acpigen_emit_ext_op(struct acpi_ctx *ctx, uint op) +{ + acpigen_emit_byte(ctx, EXT_OP_PREFIX); + acpigen_emit_byte(ctx, op); +} + char *acpigen_write_package(struct acpi_ctx *ctx, int nr_el) { char *p; @@ -251,6 +257,40 @@ void acpigen_write_name(struct acpi_ctx *ctx, const char *namepath) acpigen_emit_namestring(ctx, namepath); } +static void acpigen_write_method_internal(struct acpi_ctx *ctx, + const char *name, uint flags) +{ + acpigen_emit_byte(ctx, METHOD_OP); + acpigen_write_len_f(ctx); + acpigen_emit_namestring(ctx, name); + acpigen_emit_byte(ctx, flags); +} + +/* Method (name, nargs, NotSerialized) */ +void acpigen_write_method(struct acpi_ctx *ctx, const char *name, int nargs) +{ + acpigen_write_method_internal(ctx, name, + nargs & ACPI_METHOD_NARGS_MASK); +} + +/* Method (name, nargs, Serialized) */ +void acpigen_write_method_serialized(struct acpi_ctx *ctx, const char *name, + int nargs) +{ + acpigen_write_method_internal(ctx, name, + (nargs & ACPI_METHOD_NARGS_MASK) | + ACPI_METHOD_SERIALIZED_MASK); +} + +void acpigen_write_sta(struct acpi_ctx *ctx, uint status) +{ + /* Method (_STA, 0, NotSerialized) { Return (status) } */ + acpigen_write_method(ctx, "_STA", 0); + acpigen_emit_byte(ctx, RETURN_OP); + acpigen_write_byte(ctx, status); + acpigen_pop_len(ctx); +} + /* * ToUUID(uuid) * @@ -287,3 +327,49 @@ int acpigen_write_uuid(struct acpi_ctx *ctx, const char *uuid) return 0; } + +/* Sleep (ms) */ +void acpigen_write_sleep(struct acpi_ctx *ctx, u64 sleep_ms) +{ + acpigen_emit_ext_op(ctx, SLEEP_OP); + acpigen_write_integer(ctx, sleep_ms); +} + +void acpigen_write_store(struct acpi_ctx *ctx) +{ + acpigen_emit_byte(ctx, STORE_OP); +} + +/* Or (arg1, arg2, res) */ +void acpigen_write_or(struct acpi_ctx *ctx, u8 arg1, u8 arg2, u8 res) +{ + acpigen_emit_byte(ctx, OR_OP); + acpigen_emit_byte(ctx, arg1); + acpigen_emit_byte(ctx, arg2); + acpigen_emit_byte(ctx, res); +} + +/* And (arg1, arg2, res) */ +void acpigen_write_and(struct acpi_ctx *ctx, u8 arg1, u8 arg2, u8 res) +{ + acpigen_emit_byte(ctx, AND_OP); + acpigen_emit_byte(ctx, arg1); + acpigen_emit_byte(ctx, arg2); + acpigen_emit_byte(ctx, res); +} + +/* Not (arg, res) */ +void acpigen_write_not(struct acpi_ctx *ctx, u8 arg, u8 res) +{ + acpigen_emit_byte(ctx, NOT_OP); + acpigen_emit_byte(ctx, arg); + acpigen_emit_byte(ctx, res); +} + +/* Store (str, DEBUG) */ +void acpigen_write_debug_string(struct acpi_ctx *ctx, const char *str) +{ + acpigen_write_store(ctx); + acpigen_write_string(ctx, str); + acpigen_emit_ext_op(ctx, DEBUG_OP); +} |