1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Core ACPI (Advanced Configuration and Power Interface) support
5 * Copyright 2019 Google LLC
7 * Modified from coreboot file acpigen.h
10 #ifndef __ACPI_ACPIGEN_H
11 #define __ACPI_ACPIGEN_H
13 #include <linux/types.h>
17 /* Top 4 bits of the value used to indicate a three-byte length value */
18 #define ACPI_PKG_LEN_3_BYTES 0x80
20 /* ACPI Op/Prefix codes */
31 DUAL_NAME_PREFIX = 0x2e,
32 MULTI_NAME_PREFIX = 0x2f,
36 * acpigen_get_current() - Get the current ACPI code output pointer
38 * @ctx: ACPI context pointer
39 * @return output pointer
41 u8 *acpigen_get_current(struct acpi_ctx *ctx);
44 * acpigen_emit_byte() - Emit a byte to the ACPI code
46 * @ctx: ACPI context pointer
47 * @data: Value to output
49 void acpigen_emit_byte(struct acpi_ctx *ctx, uint data);
52 * acpigen_emit_word() - Emit a 16-bit word to the ACPI code
54 * @ctx: ACPI context pointer
55 * @data: Value to output
57 void acpigen_emit_word(struct acpi_ctx *ctx, uint data);
60 * acpigen_emit_dword() - Emit a 32-bit 'double word' to the ACPI code
62 * @ctx: ACPI context pointer
63 * @data: Value to output
65 void acpigen_emit_dword(struct acpi_ctx *ctx, uint data);
68 * acpigen_emit_stream() - Emit a stream of bytes
70 * @ctx: ACPI context pointer
71 * @data: Data to output
72 * @size: Size of data in bytes
74 void acpigen_emit_stream(struct acpi_ctx *ctx, const char *data, int size);
77 * acpigen_emit_string() - Emit a string
79 * Emit a string with a null terminator
81 * @ctx: ACPI context pointer
82 * @str: String to output, or NULL for an empty string
84 void acpigen_emit_string(struct acpi_ctx *ctx, const char *str);
87 * acpigen_write_len_f() - Write a 'forward' length placeholder
89 * This adds space for a length value in the ACPI stream and pushes the current
90 * position (before the length) on the stack. After calling this you can write
91 * some data and then call acpigen_pop_len() to update the length value.
95 * acpigen_write_len_f() ------\
96 * acpigen_write...() |
97 * acpigen_write...() |
98 * acpigen_write_len_f() --\ |
99 * acpigen_write...() | |
100 * acpigen_write...() | |
101 * acpigen_pop_len() ------/ |
102 * acpigen_write...() |
103 * acpigen_pop_len() ----------/
105 * See ACPI 6.3 section 20.2.4 Package Length Encoding
107 * This implementation always uses a 3-byte packet length for simplicity. It
108 * could be adjusted to support other lengths.
110 * @ctx: ACPI context pointer
112 void acpigen_write_len_f(struct acpi_ctx *ctx);
115 * acpigen_pop_len() - Update the previously stacked length placeholder
117 * Call this after the data for the block has been written. It updates the
118 * top length value in the stack and pops it off.
120 * @ctx: ACPI context pointer
122 void acpigen_pop_len(struct acpi_ctx *ctx);
125 * acpigen_write_package() - Start writing a package
127 * A package collects together a number of elements in the ACPI code. To write
130 * acpigen_write_package(ctx, 3);
134 * If you don't know the number of elements in advance, acpigen_write_package()
135 * returns a pointer to the value so you can update it later:
137 * char *num_elements = acpigen_write_package(ctx, 0);
139 * *num_elements += 1;
141 * *num_elements += 1;
144 * @ctx: ACPI context pointer
145 * @nr_el: Number of elements (0 if not known)
146 * @returns pointer to the number of elements, which can be updated by the
149 char *acpigen_write_package(struct acpi_ctx *ctx, int nr_el);
152 * acpigen_write_integer() - Write an integer
154 * This writes an operation (BYTE_OP, WORD_OP, DWORD_OP, QWORD_OP depending on
155 * the integer size) and an integer value. Note that WORD means 16 bits in ACPI.
157 * @ctx: ACPI context pointer
158 * @data: Integer to write
160 void acpigen_write_integer(struct acpi_ctx *ctx, u64 data);
163 * acpigen_write_string() - Write a string
165 * This writes a STRING_PREFIX followed by a null-terminated string
167 * @ctx: ACPI context pointer
168 * @str: String to write
170 void acpigen_write_string(struct acpi_ctx *ctx, const char *str);
173 * acpigen_emit_namestring() - Emit an ACPI name
175 * This writes out an ACPI name or path in the required special format. It does
176 * not add the NAME_OP prefix.
178 * @ctx: ACPI context pointer
179 * @namepath: Name / path to emit
181 void acpigen_emit_namestring(struct acpi_ctx *ctx, const char *namepath);
184 * acpigen_write_name() - Write out an ACPI name
186 * This writes out an ACPI name or path in the required special format with a
189 * @ctx: ACPI context pointer
190 * @namepath: Name / path to emit
192 void acpigen_write_name(struct acpi_ctx *ctx, const char *namepath);