blob: 31fa20a806f3895e9bed06bb47fd6b8f2eddc8b6 [file] [log] [blame]
Simon Glass61cc9332020-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 Glass7e148f22020-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 Glass03967ce2020-07-07 13:11:51 -060020/* ACPI Op/Prefix codes */
21enum {
Simon Glass83b2bd52020-07-07 13:11:52 -060022 ZERO_OP = 0x00,
23 ONE_OP = 0x01,
Simon Glass7aed90d2020-07-07 13:11:54 -060024 NAME_OP = 0x08,
Simon Glass83b2bd52020-07-07 13:11:52 -060025 BYTE_PREFIX = 0x0a,
26 WORD_PREFIX = 0x0b,
27 DWORD_PREFIX = 0x0c,
Simon Glass3df33bd2020-07-07 13:11:53 -060028 STRING_PREFIX = 0x0d,
Simon Glass83b2bd52020-07-07 13:11:52 -060029 QWORD_PREFIX = 0x0e,
Simon Glass29df8452020-07-07 13:11:55 -060030 BUFFER_OP = 0x11,
Simon Glass03967ce2020-07-07 13:11:51 -060031 PACKAGE_OP = 0x12,
Simon Glass7aed90d2020-07-07 13:11:54 -060032 DUAL_NAME_PREFIX = 0x2e,
33 MULTI_NAME_PREFIX = 0x2f,
Simon Glass03967ce2020-07-07 13:11:51 -060034};
35
Simon Glass61cc9332020-07-07 13:11:42 -060036/**
37 * acpigen_get_current() - Get the current ACPI code output pointer
38 *
39 * @ctx: ACPI context pointer
40 * @return output pointer
41 */
42u8 *acpigen_get_current(struct acpi_ctx *ctx);
43
44/**
45 * acpigen_emit_byte() - Emit a byte to the ACPI code
46 *
47 * @ctx: ACPI context pointer
48 * @data: Value to output
49 */
50void acpigen_emit_byte(struct acpi_ctx *ctx, uint data);
51
52/**
53 * acpigen_emit_word() - Emit a 16-bit word to the ACPI code
54 *
55 * @ctx: ACPI context pointer
56 * @data: Value to output
57 */
58void acpigen_emit_word(struct acpi_ctx *ctx, uint data);
59
60/**
61 * acpigen_emit_dword() - Emit a 32-bit 'double word' to the ACPI code
62 *
63 * @ctx: ACPI context pointer
64 * @data: Value to output
65 */
66void acpigen_emit_dword(struct acpi_ctx *ctx, uint data);
67
Simon Glass7fb8da42020-07-07 13:11:45 -060068/**
69 * acpigen_emit_stream() - Emit a stream of bytes
70 *
71 * @ctx: ACPI context pointer
72 * @data: Data to output
73 * @size: Size of data in bytes
74 */
75void acpigen_emit_stream(struct acpi_ctx *ctx, const char *data, int size);
76
77/**
78 * acpigen_emit_string() - Emit a string
79 *
80 * Emit a string with a null terminator
81 *
82 * @ctx: ACPI context pointer
83 * @str: String to output, or NULL for an empty string
84 */
85void acpigen_emit_string(struct acpi_ctx *ctx, const char *str);
86
Simon Glass7e148f22020-07-07 13:11:50 -060087/**
88 * acpigen_write_len_f() - Write a 'forward' length placeholder
89 *
90 * This adds space for a length value in the ACPI stream and pushes the current
91 * position (before the length) on the stack. After calling this you can write
92 * some data and then call acpigen_pop_len() to update the length value.
93 *
94 * Usage:
95 *
96 * acpigen_write_len_f() ------\
97 * acpigen_write...() |
98 * acpigen_write...() |
99 * acpigen_write_len_f() --\ |
100 * acpigen_write...() | |
101 * acpigen_write...() | |
102 * acpigen_pop_len() ------/ |
103 * acpigen_write...() |
104 * acpigen_pop_len() ----------/
105 *
106 * See ACPI 6.3 section 20.2.4 Package Length Encoding
107 *
108 * This implementation always uses a 3-byte packet length for simplicity. It
109 * could be adjusted to support other lengths.
110 *
111 * @ctx: ACPI context pointer
112 */
113void acpigen_write_len_f(struct acpi_ctx *ctx);
114
115/**
116 * acpigen_pop_len() - Update the previously stacked length placeholder
117 *
118 * Call this after the data for the block has been written. It updates the
119 * top length value in the stack and pops it off.
120 *
121 * @ctx: ACPI context pointer
122 */
123void acpigen_pop_len(struct acpi_ctx *ctx);
124
Simon Glass03967ce2020-07-07 13:11:51 -0600125/**
126 * acpigen_write_package() - Start writing a package
127 *
128 * A package collects together a number of elements in the ACPI code. To write
129 * a package use:
130 *
131 * acpigen_write_package(ctx, 3);
132 * ...write things
133 * acpigen_pop_len()
134 *
135 * If you don't know the number of elements in advance, acpigen_write_package()
136 * returns a pointer to the value so you can update it later:
137 *
138 * char *num_elements = acpigen_write_package(ctx, 0);
139 * ...write things
140 * *num_elements += 1;
141 * ...write things
142 * *num_elements += 1;
143 * acpigen_pop_len()
144 *
145 * @ctx: ACPI context pointer
146 * @nr_el: Number of elements (0 if not known)
147 * @returns pointer to the number of elements, which can be updated by the
148 * caller if needed
149 */
150char *acpigen_write_package(struct acpi_ctx *ctx, int nr_el);
151
Simon Glass83b2bd52020-07-07 13:11:52 -0600152/**
153 * acpigen_write_integer() - Write an integer
154 *
155 * This writes an operation (BYTE_OP, WORD_OP, DWORD_OP, QWORD_OP depending on
156 * the integer size) and an integer value. Note that WORD means 16 bits in ACPI.
157 *
158 * @ctx: ACPI context pointer
159 * @data: Integer to write
160 */
161void acpigen_write_integer(struct acpi_ctx *ctx, u64 data);
162
Simon Glass3df33bd2020-07-07 13:11:53 -0600163/**
164 * acpigen_write_string() - Write a string
165 *
166 * This writes a STRING_PREFIX followed by a null-terminated string
167 *
168 * @ctx: ACPI context pointer
169 * @str: String to write
170 */
171void acpigen_write_string(struct acpi_ctx *ctx, const char *str);
Simon Glass7aed90d2020-07-07 13:11:54 -0600172
173/**
174 * acpigen_emit_namestring() - Emit an ACPI name
175 *
176 * This writes out an ACPI name or path in the required special format. It does
177 * not add the NAME_OP prefix.
178 *
179 * @ctx: ACPI context pointer
180 * @namepath: Name / path to emit
181 */
182void acpigen_emit_namestring(struct acpi_ctx *ctx, const char *namepath);
183
184/**
185 * acpigen_write_name() - Write out an ACPI name
186 *
187 * This writes out an ACPI name or path in the required special format with a
188 * NAME_OP prefix.
189 *
190 * @ctx: ACPI context pointer
191 * @namepath: Name / path to emit
192 */
193void acpigen_write_name(struct acpi_ctx *ctx, const char *namepath);
Simon Glass29df8452020-07-07 13:11:55 -0600194
195/**
196 * acpigen_write_uuid() - Write a UUID
197 *
198 * This writes out a UUID in the format used by ACPI, with a BUFFER_OP prefix.
199 *
200 * @ctx: ACPI context pointer
201 * @uuid: UUID to write in the form aabbccdd-eeff-gghh-iijj-kkllmmnnoopp
202 * @return 0 if OK, -EINVAL if the format is incorrect
203 */
204int acpigen_write_uuid(struct acpi_ctx *ctx, const char *uuid);
205
Simon Glass61cc9332020-07-07 13:11:42 -0600206#endif