blob: 24aec7fad6f557c6a6aa12f01b3e98419031ddc4 [file] [log] [blame]
Simon Glass98528d42020-07-07 13:11:42 -06001/* 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
15struct acpi_ctx;
16
Simon Glass0f277632020-07-07 13:11:50 -060017/* Top 4 bits of the value used to indicate a three-byte length value */
18#define ACPI_PKG_LEN_3_BYTES 0x80
19
Simon Glassedc26802020-07-07 13:11:51 -060020/* ACPI Op/Prefix codes */
21enum {
Simon Glass8715ce02020-07-07 13:11:52 -060022 ZERO_OP = 0x00,
23 ONE_OP = 0x01,
Simon Glass0dc3d512020-07-07 13:11:54 -060024 NAME_OP = 0x08,
Simon Glass8715ce02020-07-07 13:11:52 -060025 BYTE_PREFIX = 0x0a,
26 WORD_PREFIX = 0x0b,
27 DWORD_PREFIX = 0x0c,
Simon Glass45d6d952020-07-07 13:11:53 -060028 STRING_PREFIX = 0x0d,
Simon Glass8715ce02020-07-07 13:11:52 -060029 QWORD_PREFIX = 0x0e,
Simon Glassedc26802020-07-07 13:11:51 -060030 PACKAGE_OP = 0x12,
Simon Glass0dc3d512020-07-07 13:11:54 -060031 DUAL_NAME_PREFIX = 0x2e,
32 MULTI_NAME_PREFIX = 0x2f,
Simon Glassedc26802020-07-07 13:11:51 -060033};
34
Simon Glass98528d42020-07-07 13:11:42 -060035/**
36 * acpigen_get_current() - Get the current ACPI code output pointer
37 *
38 * @ctx: ACPI context pointer
39 * @return output pointer
40 */
41u8 *acpigen_get_current(struct acpi_ctx *ctx);
42
43/**
44 * acpigen_emit_byte() - Emit a byte to the ACPI code
45 *
46 * @ctx: ACPI context pointer
47 * @data: Value to output
48 */
49void acpigen_emit_byte(struct acpi_ctx *ctx, uint data);
50
51/**
52 * acpigen_emit_word() - Emit a 16-bit word to the ACPI code
53 *
54 * @ctx: ACPI context pointer
55 * @data: Value to output
56 */
57void acpigen_emit_word(struct acpi_ctx *ctx, uint data);
58
59/**
60 * acpigen_emit_dword() - Emit a 32-bit 'double word' to the ACPI code
61 *
62 * @ctx: ACPI context pointer
63 * @data: Value to output
64 */
65void acpigen_emit_dword(struct acpi_ctx *ctx, uint data);
66
Simon Glass071c4a52020-07-07 13:11:45 -060067/**
68 * acpigen_emit_stream() - Emit a stream of bytes
69 *
70 * @ctx: ACPI context pointer
71 * @data: Data to output
72 * @size: Size of data in bytes
73 */
74void acpigen_emit_stream(struct acpi_ctx *ctx, const char *data, int size);
75
76/**
77 * acpigen_emit_string() - Emit a string
78 *
79 * Emit a string with a null terminator
80 *
81 * @ctx: ACPI context pointer
82 * @str: String to output, or NULL for an empty string
83 */
84void acpigen_emit_string(struct acpi_ctx *ctx, const char *str);
85
Simon Glass0f277632020-07-07 13:11:50 -060086/**
87 * acpigen_write_len_f() - Write a 'forward' length placeholder
88 *
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.
92 *
93 * Usage:
94 *
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() ----------/
104 *
105 * See ACPI 6.3 section 20.2.4 Package Length Encoding
106 *
107 * This implementation always uses a 3-byte packet length for simplicity. It
108 * could be adjusted to support other lengths.
109 *
110 * @ctx: ACPI context pointer
111 */
112void acpigen_write_len_f(struct acpi_ctx *ctx);
113
114/**
115 * acpigen_pop_len() - Update the previously stacked length placeholder
116 *
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.
119 *
120 * @ctx: ACPI context pointer
121 */
122void acpigen_pop_len(struct acpi_ctx *ctx);
123
Simon Glassedc26802020-07-07 13:11:51 -0600124/**
125 * acpigen_write_package() - Start writing a package
126 *
127 * A package collects together a number of elements in the ACPI code. To write
128 * a package use:
129 *
130 * acpigen_write_package(ctx, 3);
131 * ...write things
132 * acpigen_pop_len()
133 *
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:
136 *
137 * char *num_elements = acpigen_write_package(ctx, 0);
138 * ...write things
139 * *num_elements += 1;
140 * ...write things
141 * *num_elements += 1;
142 * acpigen_pop_len()
143 *
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
147 * caller if needed
148 */
149char *acpigen_write_package(struct acpi_ctx *ctx, int nr_el);
150
Simon Glass8715ce02020-07-07 13:11:52 -0600151/**
152 * acpigen_write_integer() - Write an integer
153 *
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.
156 *
157 * @ctx: ACPI context pointer
158 * @data: Integer to write
159 */
160void acpigen_write_integer(struct acpi_ctx *ctx, u64 data);
161
Simon Glass45d6d952020-07-07 13:11:53 -0600162/**
163 * acpigen_write_string() - Write a string
164 *
165 * This writes a STRING_PREFIX followed by a null-terminated string
166 *
167 * @ctx: ACPI context pointer
168 * @str: String to write
169 */
170void acpigen_write_string(struct acpi_ctx *ctx, const char *str);
Simon Glass0dc3d512020-07-07 13:11:54 -0600171
172/**
173 * acpigen_emit_namestring() - Emit an ACPI name
174 *
175 * This writes out an ACPI name or path in the required special format. It does
176 * not add the NAME_OP prefix.
177 *
178 * @ctx: ACPI context pointer
179 * @namepath: Name / path to emit
180 */
181void acpigen_emit_namestring(struct acpi_ctx *ctx, const char *namepath);
182
183/**
184 * acpigen_write_name() - Write out an ACPI name
185 *
186 * This writes out an ACPI name or path in the required special format with a
187 * NAME_OP prefix.
188 *
189 * @ctx: ACPI context pointer
190 * @namepath: Name / path to emit
191 */
192void acpigen_write_name(struct acpi_ctx *ctx, const char *namepath);
Simon Glass98528d42020-07-07 13:11:42 -0600193#endif