PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
name.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdint.h>
4#include <sys/list.h>
5
6typedef struct aml_term_list_ctx aml_term_list_ctx_t;
7typedef struct aml_object aml_object_t;
8typedef struct aml_term_list_ctx aml_term_list_ctx_t;
9
10/**
11 * @brief Name Objects Encoding
12 * @defgroup modules_acpi_aml_encoding_name Name Objects
13 * @ingroup modules_acpi_aml
14 *
15 * Not to be confused with "ACPI AML Named Objects Encoding".
16 *
17 * @see Section 20.2.2 of the ACPI specification for more details.
18 *
19 * @{
20 */
21
22/**
23 * @brief Check if a token is a LeadNameChar structure.
24 *
25 * @param token The token to check.
26 * @return true if the token is a LeadNameChar structure, false otherwise.
27 */
28#define AML_IS_LEAD_NAME_CHAR(token) \
29 (((token)->num >= AML_NAME_CHAR_A && (token)->num <= AML_NAME_CHAR_Z) || (token)->num == AML_NAME_CHAR)
30
31/**
32 * @brief Check if a token is a DigitChar structure.
33 *
34 * @param token The token to check.
35 * @return true if the token is a DigitChar structure, false otherwise.
36 */
37#define AML_IS_DIGIT_CHAR(token) (((token)->num >= AML_DIGIT_CHAR_0 && (token)->num <= AML_DIGIT_CHAR_9))
38
39/**
40 * @brief Check if a token is a NameChar structure.
41 *
42 * @param token The token to check.
43 * @return true if the token is a NameChar structure, false otherwise.
44 */
45#define AML_IS_NAME_CHAR(token) (AML_IS_DIGIT_CHAR(token) || AML_IS_LEAD_NAME_CHAR(token))
46
47/**
48 * @brief A PrefixPath structure.
49 * @struct aml_prefix_path_t
50 */
51typedef struct
52{
53 uint16_t depth; ///< Number of parent prefixes ('^') in the prefix, each prefix means go back one level in the
54 /// namespace hierarchy.
56
57/**
58 * @brief A RootChar structure.
59 * @struct aml_root_char_t
60 */
61typedef struct
62{
63 bool present; ///< If the first character is a root character ('\\'), if yes, the name string is absolute.
65
66/**
67 * @brief A NameSeg strcture.
68 * @struct aml_name_seg_t
69 */
71
72/**
73 * @brief Represents the NamePath, DualNamePath, MultiNamePath and NullPath structures.
74 * @struct aml_name_path_t
75 */
76typedef struct
77{
78 uint64_t segmentCount; ///< Number of segments in the name path.
79 aml_name_seg_t* segments; ///< Array of segments in the name path.
81
82/**
83 * @brief A NameString structure.
84 * @struct aml_name_string_t
85 */
92
93/**
94 * @brief Reads the next data as a SegCount structure from the AML bytecode stream.
95 *
96 * A SegCount structure is defined as `SegCount := ByteData`.
97 *
98 * @param ctx The context of the TermList that this structure is part of.
99 * @param out Pointer to destination where the SegCount will be stored.
100 * @return On success, `0`. On failure, `ERR` and `errno` is set.
101 */
103
104/**
105 * @brief Reads the next data as a NameSeg from the AML bytecode stream.
106 *
107 * A NameSeg structure is defined as `NameSeg := <leadnamechar namechar namechar namechar>`.
108 *
109 * @param ctx The context of the TermList that this structure is part of.
110 * @param out Pointer to the destination where the pointer to the NameSeg will be stored. Will be located within the AML
111 * bytecode stream.
112 * @return On success, `0`. On failure, `ERR` and `errno` is set.
113 */
115
116/**
117 * @brief Reads the next data as a DualNamePath structure from the AML bytecode stream.
118 *
119 * A DualNamePath structure is defined as `DualNamePath := DualNamePrefix NameSeg NameSeg`.
120 *
121 * @param ctx The context of the TermList that this structure is part of.
122 * @param out Pointer to destination where the pointer to the array of two NameSeg will be stored. Will be located
123 * within the AML bytecode stream.
124 * @return On success, `0`. On failure, `ERR` and `errno` is set.
125 */
127
128/**
129 * @brief Reads the next data as a MultiNamePath structure from the AML bytecode stream.
130 *
131 * A MultiNamePath structure is defined as `MultiNamePath := MultiNamePrefix SegCount NameSeg(SegCount)`.
132 *
133 * @param ctx The context of the TermList that this structure is part of.
134 * @param outSegments Pointer to destination where the pointer to the array of NameSeg will be stored. Will be located
135 * within the AML bytecode stream.
136 * @param outSegCount Pointer to destination where the number of segments will be stored.
137 * @return On success, `0`. On failure, `ERR` and `errno` is set.
138 */
140
141/**
142 * Reads the next data as a NullName structure from the AML bytecode stream.
143 *
144 * A NullName structure is defined as `NullName := 0x00`.
145 *
146 * @param ctx The context of the TermList that this structure is part of.
147 * @return On success, `0`. On failure, `ERR` and `errno` is set.
148 */
150
151/**
152 * @brief Reads the next data as a NamePath structure from the AML bytecode stream.
153 *
154 * A NamePath structure is defined as `NamePath := NameSeg | DualNamePath | MultiNamePath | NullName`.
155 *
156 * @param ctx The context of the TermList that this structure is part of.
157 * @param out Pointer to destination where the NamePath will be stored.
158 * @return On success, `0`. On failure, `ERR` and `errno` is set.
159 */
161
162/**
163 * @brief Reads the next data as a PrefixPath structure from the AML bytecode stream.
164 *
165 * A PrefixPath structure is defined as `PrefixPath := Nothing | <'^' prefixpath>`.
166 *
167 * Note that `^` is just a `AML_PARENT_PREFIX_CHAR`.
168 *
169 * @param ctx The context of the TermList that this structure is part of.
170 * @param out Pointer to destination where the PrefixPath will be stored.
171 * @return On success, `0`. On failure, `ERR` and `errno` is set.
172 */
174
175/**
176 * @brief Reads the next data as a RootChar from the AML bytecode stream.
177 *
178 * A RootChar is defined as `RootChar := 0x5C`.
179 *
180 * @param ctx The context of the TermList that this structure is part of.
181 * @param out Pointer to destination where the RootChar will be stored.
182 * @return On success, `0`. On failure, `ERR` and `errno` is set.
183 */
185
186/**
187 * @brief Reads the next data as a NameString structure from the AML bytecode stream.
188 *
189 * A NameString structure is defined as `NameString := <rootchar namepath> | <prefixpath namepath>`.
190 *
191 * @param ctx The context of the TermList that this structure is part of.
192 * @param out Pointer to destination where the NameString will be stored.
193 * @return On success, `0`. On failure, `ERR` and `errno` is set.
194 */
196
197/**
198 * @brief Reads the next data as a NameString structure from the AML bytecode stream and resolves it to a object.
199 *
200 * Note that `errno` will only be set to `ENOENT` if the NameString is read correctly but fails to resolve, other values
201 * for `errno` might be set in other cases.
202 *
203 * If the name string points to a non-existing object, a integer object containing `0` will be created and returned.
204 * This is as always for the sake of compatibility, even if the specification does not specify this behavior.
205 *
206 * @see Section 5.3 of the ACPI specification for more details.
207 * @see aml_name_string_find_by_name_string() for details on how the resolution is performed.
208 *
209 * @param ctx The context of the TermList that this structure is part of.
210 * @return On success, a pointer to the resolved object. On failure, `NULL` and `errno` is set.
211 */
213
214/**
215 * @brief Reads a SimpleName structure from the AML byte stream and resolves it to a object.
216 *
217 * A SimpleName structure is defined as `SimpleName := NameString | ArgObj | LocalObj`.
218 *
219 * Note that `errno` will only be set to `ENOENT` if it is a NameString that fails to resolve, other values for `errno`
220 * might be set in other cases.
221 *
222 * @param ctx The context of the TermList that this structure is part of.
223 * @return On success, a pointer to the resolved object. On failure, `NULL` and `errno` is set.
224 */
226
227/**
228 * @brief Reads a SuperName structure from the AML byte stream and resolves it to a object.
229 *
230 * A SuperName structure is defined as `SuperName := SimpleName | DebugObj | ReferenceTypeOpcode`.
231 *
232 * @param ctx The context of the TermList that this structure is part of.
233 * @return On success, a pointer to the resolved object. On failure, `NULL` and `errno` is set.
234 */
236
237/**
238 * @brief Reads a Target structure from the AML byte stream and resolves it to a object.
239 *
240 * A Target structure is defined as `Target := SuperName | NullName`.
241 *
242 * If the Target is a NullName, then out will be set to point to `NULL` but its not considered an error.
243 *
244 * @param ctx The context of the TermList that this structure is part of.
245 * @param out Pointer to where the pointer to the resolved object will be stored, might be set to point to `NULL`.
246 * @return On success, `0`. On failure, `ERR` and `errno` is set.
247 */
249
250/** @} */
uint64_t aml_seg_count_read(aml_term_list_ctx_t *ctx, uint8_t *out)
Reads the next data as a SegCount structure from the AML bytecode stream.
Definition name.c:17
uint64_t aml_name_string_read(aml_term_list_ctx_t *ctx, aml_name_string_t *out)
Reads the next data as a NameString structure from the AML bytecode stream.
Definition name.c:189
uint32_t aml_name_seg_t
Definition name.h:70
aml_object_t * aml_name_string_read_and_resolve(aml_term_list_ctx_t *ctx)
Reads the next data as a NameString structure from the AML bytecode stream and resolves it to a objec...
Definition name.c:227
uint64_t aml_null_name_read(aml_term_list_ctx_t *ctx)
Definition name.c:113
uint64_t aml_multi_name_path_read(aml_term_list_ctx_t *ctx, aml_name_seg_t **outSegments, uint64_t *outSegCount)
Reads the next data as a MultiNamePath structure from the AML bytecode stream.
Definition name.c:80
aml_object_t * aml_simple_name_read_and_resolve(aml_term_list_ctx_t *ctx)
Reads a SimpleName structure from the AML byte stream and resolves it to a object.
Definition name.c:264
uint64_t aml_name_seg_read(aml_term_list_ctx_t *ctx, aml_name_seg_t **out)
Reads the next data as a NameSeg from the AML bytecode stream.
Definition name.c:27
uint64_t aml_name_path_read(aml_term_list_ctx_t *ctx, aml_name_path_t *out)
Reads the next data as a NamePath structure from the AML bytecode stream.
Definition name.c:124
aml_object_t * aml_super_name_read_and_resolve(aml_term_list_ctx_t *ctx)
Reads a SuperName structure from the AML byte stream and resolves it to a object.
Definition name.c:296
uint64_t aml_root_char_read(aml_term_list_ctx_t *ctx, aml_root_char_t *out)
Reads the next data as a RootChar from the AML bytecode stream.
Definition name.c:177
uint64_t aml_target_read_and_resolve(aml_term_list_ctx_t *ctx, aml_object_t **out)
Reads a Target structure from the AML byte stream and resolves it to a object.
Definition name.c:330
uint64_t aml_dual_name_path_read(aml_term_list_ctx_t *ctx, aml_name_seg_t **out)
Reads the next data as a DualNamePath structure from the AML bytecode stream.
Definition name.c:58
uint64_t aml_prefix_path_read(aml_term_list_ctx_t *ctx, aml_prefix_path_t *out)
Reads the next data as a PrefixPath structure from the AML bytecode stream.
Definition name.c:159
__UINT32_TYPE__ uint32_t
Definition stdint.h:15
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINT8_TYPE__ uint8_t
Definition stdint.h:11
__UINT16_TYPE__ uint16_t
Definition stdint.h:13
Represents the NamePath, DualNamePath, MultiNamePath and NullPath structures.
Definition name.h:77
aml_name_seg_t * segments
Array of segments in the name path.
Definition name.h:79
uint64_t segmentCount
Number of segments in the name path.
Definition name.h:78
A NameSeg strcture.
A NameString structure.
Definition name.h:87
aml_name_path_t namePath
Definition name.h:90
aml_prefix_path_t prefixPath
Definition name.h:89
aml_root_char_t rootChar
Definition name.h:88
ACPI object.
Definition object.h:447
A PrefixPath structure.
Definition name.h:52
uint16_t depth
Definition name.h:53
A RootChar structure.
Definition name.h:62
bool present
If the first character is a root character ('\'), if yes, the name string is absolute.
Definition name.h:63
Context for reading a TermList.
Definition term.h:37