acpigen: Support writing a length
[platform/kernel/u-boot.git] / include / acpi / acpigen.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Core ACPI (Advanced Configuration and Power Interface) support
4  *
5  * Copyright 2019 Google LLC
6  *
7  * Modified from coreboot file acpigen.h
8  */
9
10 #ifndef __ACPI_ACPIGEN_H
11 #define __ACPI_ACPIGEN_H
12
13 #include <linux/types.h>
14
15 struct acpi_ctx;
16
17 /* Top 4 bits of the value used to indicate a three-byte length value */
18 #define ACPI_PKG_LEN_3_BYTES    0x80
19
20 /**
21  * acpigen_get_current() - Get the current ACPI code output pointer
22  *
23  * @ctx: ACPI context pointer
24  * @return output pointer
25  */
26 u8 *acpigen_get_current(struct acpi_ctx *ctx);
27
28 /**
29  * acpigen_emit_byte() - Emit a byte to the ACPI code
30  *
31  * @ctx: ACPI context pointer
32  * @data: Value to output
33  */
34 void acpigen_emit_byte(struct acpi_ctx *ctx, uint data);
35
36 /**
37  * acpigen_emit_word() - Emit a 16-bit word to the ACPI code
38  *
39  * @ctx: ACPI context pointer
40  * @data: Value to output
41  */
42 void acpigen_emit_word(struct acpi_ctx *ctx, uint data);
43
44 /**
45  * acpigen_emit_dword() - Emit a 32-bit 'double word' to the ACPI code
46  *
47  * @ctx: ACPI context pointer
48  * @data: Value to output
49  */
50 void acpigen_emit_dword(struct acpi_ctx *ctx, uint data);
51
52 /**
53  * acpigen_emit_stream() - Emit a stream of bytes
54  *
55  * @ctx: ACPI context pointer
56  * @data: Data to output
57  * @size: Size of data in bytes
58  */
59 void acpigen_emit_stream(struct acpi_ctx *ctx, const char *data, int size);
60
61 /**
62  * acpigen_emit_string() - Emit a string
63  *
64  * Emit a string with a null terminator
65  *
66  * @ctx: ACPI context pointer
67  * @str: String to output, or NULL for an empty string
68  */
69 void acpigen_emit_string(struct acpi_ctx *ctx, const char *str);
70
71 /**
72  * acpigen_write_len_f() - Write a 'forward' length placeholder
73  *
74  * This adds space for a length value in the ACPI stream and pushes the current
75  * position (before the length) on the stack. After calling this you can write
76  * some data and then call acpigen_pop_len() to update the length value.
77  *
78  * Usage:
79  *
80  *    acpigen_write_len_f() ------\
81  *    acpigen_write...()          |
82  *    acpigen_write...()          |
83  *      acpigen_write_len_f() --\ |
84  *      acpigen_write...()      | |
85  *      acpigen_write...()      | |
86  *      acpigen_pop_len() ------/ |
87  *    acpigen_write...()          |
88  *    acpigen_pop_len() ----------/
89  *
90  * See ACPI 6.3 section 20.2.4 Package Length Encoding
91  *
92  * This implementation always uses a 3-byte packet length for simplicity. It
93  * could be adjusted to support other lengths.
94  *
95  * @ctx: ACPI context pointer
96  */
97 void acpigen_write_len_f(struct acpi_ctx *ctx);
98
99 /**
100  * acpigen_pop_len() - Update the previously stacked length placeholder
101  *
102  * Call this after the data for the block has been written. It updates the
103  * top length value in the stack and pops it off.
104  *
105  * @ctx: ACPI context pointer
106  */
107 void acpigen_pop_len(struct acpi_ctx *ctx);
108
109 #endif