1#pragma once
2
3#include <uacpi/types.h>
4#include <uacpi/status.h>
5#include <uacpi/kernel_api.h>
6#include <uacpi/namespace.h>
7
8#define UACPI_MAJOR 4
9#define UACPI_MINOR 0
10#define UACPI_PATCH 0
11
12#ifdef UACPI_REDUCED_HARDWARE
13#define UACPI_MAKE_STUB_FOR_REDUCED_HARDWARE(fn, ret) \
14 UACPI_NO_UNUSED_PARAMETER_WARNINGS_BEGIN \
15 static inline fn { return ret; } \
16 UACPI_NO_UNUSED_PARAMETER_WARNINGS_END
17
18#define UACPI_STUB_IF_REDUCED_HARDWARE(fn) \
19 UACPI_MAKE_STUB_FOR_REDUCED_HARDWARE(fn,)
20#define UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(fn) \
21 UACPI_MAKE_STUB_FOR_REDUCED_HARDWARE(fn, UACPI_STATUS_COMPILED_OUT)
22#define UACPI_ALWAYS_OK_FOR_REDUCED_HARDWARE(fn) \
23 UACPI_MAKE_STUB_FOR_REDUCED_HARDWARE(fn, UACPI_STATUS_OK)
24#else
25
26#define UACPI_STUB_IF_REDUCED_HARDWARE(fn) fn;
27#define UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(fn) fn;
28#define UACPI_ALWAYS_OK_FOR_REDUCED_HARDWARE(fn) fn;
29#endif
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35/**
36 * Set up early access to the table subsystem. What this means is:
37 * - uacpi_table_find() and similar API becomes usable before the call to
38 * uacpi_initialize().
39 * - No kernel API besides logging and map/unmap will be invoked at this stage,
40 * allowing for heap and scheduling to still be fully offline.
41 * - The provided 'temporary_buffer' will be used as a temporary storage for the
42 * internal metadata about the tables (list, reference count, addresses,
43 * sizes, etc).
44 * - The 'temporary_buffer' is replaced with a normal heap buffer allocated via
45 * uacpi_kernel_alloc() after the call to uacpi_initialize() and can therefore
46 * be reclaimed by the kernel.
47 *
48 * The 'temporary_buffer' is expected to be aligned on the native pointer size
49 * boundary (4 on a 32-bit system, 8 on a 64-bit system), although any
50 * misalignment is handled gracefully and does not result in an error.
51 *
52 * The approximate overhead per table is 56 bytes, so a buffer of 4096 bytes
53 * yields about 73 tables in terms of capacity. uACPI also has an internal
54 * static buffer for tables, "UACPI_STATIC_TABLE_ARRAY_LEN", which is configured
55 * as 16 descriptors in length by default.
56 *
57 * This function is used to initialize the barebones mode, see
58 * UACPI_BAREBONES_MODE in config.h for more information.
59 */
60uacpi_status uacpi_setup_early_table_access(
61 void *temporary_buffer, uacpi_size buffer_size
62);
63
64/**
65 * Returns UACPI_TRUE if the table subsystem is available for use by the kernel.
66 * This happens after a successful call to either uacpi_initialize(...) or
67 * uacpi_setup_early_table_access(...).
68 */
69uacpi_bool uacpi_table_subsystem_available(void);
70
71/**
72 * Bad table checksum should be considered a fatal error
73 * (table load is fully aborted in this case)
74 */
75#define UACPI_FLAG_BAD_CSUM_FATAL (1ull << 0)
76
77/**
78 * Unexpected table signature should be considered a fatal error
79 * (table load is fully aborted in this case)
80 */
81#define UACPI_FLAG_BAD_TBL_SIGNATURE_FATAL (1ull << 1)
82
83/**
84 * Force uACPI to use RSDT even for later revisions
85 */
86#define UACPI_FLAG_BAD_XSDT (1ull << 2)
87
88/**
89 * If this is set, ACPI mode is not entered during the call to
90 * uacpi_initialize. The caller is expected to enter it later at their own
91 * discretion by using uacpi_enter_acpi_mode().
92 */
93#define UACPI_FLAG_NO_ACPI_MODE (1ull << 3)
94
95/**
96 * Don't create the \_OSI method when building the namespace.
97 * Only enable this if you're certain that having this method breaks your AML
98 * blob, a more atomic/granular interface management is available via osi.h
99 */
100#define UACPI_FLAG_NO_OSI (1ull << 4)
101
102/**
103 * Validate table checksums at installation time instead of first use.
104 * Note that this makes uACPI map the entire table at once, which not all
105 * hosts are able to handle at early init.
106 */
107#define UACPI_FLAG_PROACTIVE_TBL_CSUM (1ull << 5)
108
109/**
110 * Returns UACPI_TRUE via 'out_value' if the current platform is reduced ACPI
111 * hardware, UACPI_FALSE otherwise.
112 *
113 * This getter becomes available along with the table subsystem, use
114 * uacpi_table_subsystem_available() to check.
115 */
116uacpi_status uacpi_is_platform_reduced_hardware(uacpi_bool *out_value);
117
118#ifndef UACPI_BAREBONES_MODE
119
120/**
121 * Initializes the uACPI subsystem, iterates & records all relevant RSDT/XSDT
122 * tables. Enters ACPI mode.
123 *
124 * 'flags' is any combination of UACPI_FLAG_* above
125 */
126uacpi_status uacpi_initialize(uacpi_u64 flags);
127
128/**
129 * Parses & executes all of the DSDT/SSDT tables.
130 * Initializes the event subsystem.
131 */
132uacpi_status uacpi_namespace_load(void);
133
134/**
135 * Initializes all the necessary objects in the namespaces by calling
136 * _STA/_INI etc.
137 */
138uacpi_status uacpi_namespace_initialize(void);
139
140// Returns the current subsystem initialization level
141uacpi_init_level uacpi_get_current_init_level(void);
142
143/**
144 * Evaluate an object within the namespace and get back its value.
145 * Either root or path must be valid.
146 * A value of NULL for 'parent' implies uacpi_namespace_root() relative
147 * lookups, unless 'path' is already absolute.
148 */
149uacpi_status uacpi_eval(
150 uacpi_namespace_node *parent, const uacpi_char *path,
151 const uacpi_object_array *args, uacpi_object **ret
152);
153uacpi_status uacpi_eval_simple(
154 uacpi_namespace_node *parent, const uacpi_char *path, uacpi_object **ret
155);
156
157/**
158 * Same as uacpi_eval() but without a return value.
159 */
160uacpi_status uacpi_execute(
161 uacpi_namespace_node *parent, const uacpi_char *path,
162 const uacpi_object_array *args
163);
164uacpi_status uacpi_execute_simple(
165 uacpi_namespace_node *parent, const uacpi_char *path
166);
167
168/**
169 * Same as uacpi_eval, but the return value type is validated against
170 * the 'ret_mask'. UACPI_STATUS_TYPE_MISMATCH is returned on error.
171 */
172uacpi_status uacpi_eval_typed(
173 uacpi_namespace_node *parent, const uacpi_char *path,
174 const uacpi_object_array *args, uacpi_object_type_bits ret_mask,
175 uacpi_object **ret
176);
177uacpi_status uacpi_eval_simple_typed(
178 uacpi_namespace_node *parent, const uacpi_char *path,
179 uacpi_object_type_bits ret_mask, uacpi_object **ret
180);
181
182/**
183 * A shorthand for uacpi_eval_typed with UACPI_OBJECT_INTEGER_BIT.
184 */
185uacpi_status uacpi_eval_integer(
186 uacpi_namespace_node *parent, const uacpi_char *path,
187 const uacpi_object_array *args, uacpi_u64 *out_value
188);
189uacpi_status uacpi_eval_simple_integer(
190 uacpi_namespace_node *parent, const uacpi_char *path, uacpi_u64 *out_value
191);
192
193/**
194 * A shorthand for uacpi_eval_typed with
195 * UACPI_OBJECT_BUFFER_BIT | UACPI_OBJECT_STRING_BIT
196 *
197 * Use uacpi_object_get_string_or_buffer to retrieve the resulting buffer data.
198 */
199uacpi_status uacpi_eval_buffer_or_string(
200 uacpi_namespace_node *parent, const uacpi_char *path,
201 const uacpi_object_array *args, uacpi_object **ret
202);
203uacpi_status uacpi_eval_simple_buffer_or_string(
204 uacpi_namespace_node *parent, const uacpi_char *path, uacpi_object **ret
205);
206
207/**
208 * A shorthand for uacpi_eval_typed with UACPI_OBJECT_STRING_BIT.
209 *
210 * Use uacpi_object_get_string to retrieve the resulting buffer data.
211 */
212uacpi_status uacpi_eval_string(
213 uacpi_namespace_node *parent, const uacpi_char *path,
214 const uacpi_object_array *args, uacpi_object **ret
215);
216uacpi_status uacpi_eval_simple_string(
217 uacpi_namespace_node *parent, const uacpi_char *path, uacpi_object **ret
218);
219
220/**
221 * A shorthand for uacpi_eval_typed with UACPI_OBJECT_BUFFER_BIT.
222 *
223 * Use uacpi_object_get_buffer to retrieve the resulting buffer data.
224 */
225uacpi_status uacpi_eval_buffer(
226 uacpi_namespace_node *parent, const uacpi_char *path,
227 const uacpi_object_array *args, uacpi_object **ret
228);
229uacpi_status uacpi_eval_simple_buffer(
230 uacpi_namespace_node *parent, const uacpi_char *path, uacpi_object **ret
231);
232
233/**
234 * A shorthand for uacpi_eval_typed with UACPI_OBJECT_PACKAGE_BIT.
235 *
236 * Use uacpi_object_get_package to retrieve the resulting object array.
237 */
238uacpi_status uacpi_eval_package(
239 uacpi_namespace_node *parent, const uacpi_char *path,
240 const uacpi_object_array *args, uacpi_object **ret
241);
242uacpi_status uacpi_eval_simple_package(
243 uacpi_namespace_node *parent, const uacpi_char *path, uacpi_object **ret
244);
245
246/**
247 * Get the bitness of the currently loaded AML code according to the DSDT.
248 *
249 * Returns either 32 or 64.
250 */
251uacpi_status uacpi_get_aml_bitness(uacpi_u8 *out_bitness);
252
253/**
254 * Helpers for entering & leaving ACPI mode. Note that ACPI mode is entered
255 * automatically during the call to uacpi_initialize().
256 */
257UACPI_ALWAYS_OK_FOR_REDUCED_HARDWARE(
258 uacpi_status uacpi_enter_acpi_mode(void)
259)
260UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
261 uacpi_status uacpi_leave_acpi_mode(void)
262)
263
264/**
265 * Attempt to acquire the global lock for 'timeout' milliseconds.
266 * 0xFFFF implies infinite wait.
267 *
268 * On success, 'out_seq' is set to a unique sequence number for the current
269 * acquire transaction. This number is used for validation during release.
270 */
271uacpi_status uacpi_acquire_global_lock(uacpi_u16 timeout, uacpi_u32 *out_seq);
272uacpi_status uacpi_release_global_lock(uacpi_u32 seq);
273
274#endif // !UACPI_BAREBONES_MODE
275
276/**
277 * Reset the global uACPI state by freeing all internally allocated data
278 * structures & resetting any global variables. After this call, uACPI must be
279 * re-initialized from scratch to be used again.
280 *
281 * This is called by uACPI automatically if a fatal error occurs during a call
282 * to uacpi_initialize/uacpi_namespace_load etc. in order to prevent accidental
283 * use of partially uninitialized subsystems.
284 */
285void uacpi_state_reset(void);
286
287#ifdef __cplusplus
288}
289#endif
290