Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /******************************************************************************* |
2 | * | |
3 | * Module Name: utmisc - common utility procedures | |
4 | * | |
5 | ******************************************************************************/ | |
6 | ||
7 | /* | |
fbb7a2dc | 8 | * Copyright (C) 2000 - 2014, Intel Corp. |
1da177e4 LT |
9 | * All rights reserved. |
10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | |
15 | * notice, this list of conditions, and the following disclaimer, | |
16 | * without modification. | |
17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | |
18 | * substantially similar to the "NO WARRANTY" disclaimer below | |
19 | * ("Disclaimer") and any redistribution must be conditioned upon | |
20 | * including a substantially similar Disclaimer requirement for further | |
21 | * binary redistribution. | |
22 | * 3. Neither the names of the above-listed copyright holders nor the names | |
23 | * of any contributors may be used to endorse or promote products derived | |
24 | * from this software without specific prior written permission. | |
25 | * | |
26 | * Alternatively, this software may be distributed under the terms of the | |
27 | * GNU General Public License ("GPL") version 2 as published by the Free | |
28 | * Software Foundation. | |
29 | * | |
30 | * NO WARRANTY | |
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | |
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
41 | * POSSIBILITY OF SUCH DAMAGES. | |
42 | */ | |
43 | ||
1da177e4 | 44 | #include <acpi/acpi.h> |
e2f7a777 LB |
45 | #include "accommon.h" |
46 | #include "acnamesp.h" | |
1da177e4 | 47 | |
1da177e4 | 48 | #define _COMPONENT ACPI_UTILITIES |
4be44fcd | 49 | ACPI_MODULE_NAME("utmisc") |
44f6c012 | 50 | |
15b8dd53 BM |
51 | /******************************************************************************* |
52 | * | |
53 | * FUNCTION: acpi_ut_is_pci_root_bridge | |
54 | * | |
ba494bee | 55 | * PARAMETERS: id - The HID/CID in string format |
15b8dd53 BM |
56 | * |
57 | * RETURN: TRUE if the Id is a match for a PCI/PCI-Express Root Bridge | |
58 | * | |
59 | * DESCRIPTION: Determine if the input ID is a PCI Root Bridge ID. | |
60 | * | |
61 | ******************************************************************************/ | |
15b8dd53 BM |
62 | u8 acpi_ut_is_pci_root_bridge(char *id) |
63 | { | |
64 | ||
65 | /* | |
66 | * Check if this is a PCI root bridge. | |
67 | * ACPI 3.0+: check for a PCI Express root also. | |
68 | */ | |
69 | if (!(ACPI_STRCMP(id, | |
70 | PCI_ROOT_HID_STRING)) || | |
71 | !(ACPI_STRCMP(id, PCI_EXPRESS_ROOT_HID_STRING))) { | |
72 | return (TRUE); | |
73 | } | |
74 | ||
75 | return (FALSE); | |
76 | } | |
77 | ||
793c2388 BM |
78 | /******************************************************************************* |
79 | * | |
80 | * FUNCTION: acpi_ut_is_aml_table | |
81 | * | |
ba494bee | 82 | * PARAMETERS: table - An ACPI table |
793c2388 BM |
83 | * |
84 | * RETURN: TRUE if table contains executable AML; FALSE otherwise | |
85 | * | |
86 | * DESCRIPTION: Check ACPI Signature for a table that contains AML code. | |
87 | * Currently, these are DSDT,SSDT,PSDT. All other table types are | |
88 | * data tables that do not contain AML code. | |
89 | * | |
90 | ******************************************************************************/ | |
84fb2c97 | 91 | |
793c2388 BM |
92 | u8 acpi_ut_is_aml_table(struct acpi_table_header *table) |
93 | { | |
94 | ||
f6dd9221 | 95 | /* These are the only tables that contain executable AML */ |
793c2388 | 96 | |
f3d2e786 BM |
97 | if (ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT) || |
98 | ACPI_COMPARE_NAME(table->signature, ACPI_SIG_PSDT) || | |
99 | ACPI_COMPARE_NAME(table->signature, ACPI_SIG_SSDT)) { | |
793c2388 BM |
100 | return (TRUE); |
101 | } | |
102 | ||
103 | return (FALSE); | |
104 | } | |
105 | ||
1da177e4 LT |
106 | /******************************************************************************* |
107 | * | |
108 | * FUNCTION: acpi_ut_dword_byte_swap | |
109 | * | |
ba494bee | 110 | * PARAMETERS: value - Value to be converted |
1da177e4 | 111 | * |
44f6c012 RM |
112 | * RETURN: u32 integer with bytes swapped |
113 | * | |
1da177e4 LT |
114 | * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes) |
115 | * | |
116 | ******************************************************************************/ | |
117 | ||
4be44fcd | 118 | u32 acpi_ut_dword_byte_swap(u32 value) |
1da177e4 LT |
119 | { |
120 | union { | |
4be44fcd LB |
121 | u32 value; |
122 | u8 bytes[4]; | |
1da177e4 | 123 | } out; |
1da177e4 | 124 | union { |
4be44fcd LB |
125 | u32 value; |
126 | u8 bytes[4]; | |
1da177e4 LT |
127 | } in; |
128 | ||
4be44fcd | 129 | ACPI_FUNCTION_ENTRY(); |
1da177e4 LT |
130 | |
131 | in.value = value; | |
132 | ||
133 | out.bytes[0] = in.bytes[3]; | |
134 | out.bytes[1] = in.bytes[2]; | |
135 | out.bytes[2] = in.bytes[1]; | |
136 | out.bytes[3] = in.bytes[0]; | |
137 | ||
138 | return (out.value); | |
139 | } | |
140 | ||
1da177e4 LT |
141 | /******************************************************************************* |
142 | * | |
143 | * FUNCTION: acpi_ut_set_integer_width | |
144 | * | |
145 | * PARAMETERS: Revision From DSDT header | |
146 | * | |
147 | * RETURN: None | |
148 | * | |
149 | * DESCRIPTION: Set the global integer bit width based upon the revision | |
73a3090a BM |
150 | * of the DSDT. For Revision 1 and 0, Integers are 32 bits. |
151 | * For Revision 2 and above, Integers are 64 bits. Yes, this | |
1da177e4 LT |
152 | * makes a difference. |
153 | * | |
154 | ******************************************************************************/ | |
155 | ||
4be44fcd | 156 | void acpi_ut_set_integer_width(u8 revision) |
1da177e4 LT |
157 | { |
158 | ||
f3d2e786 | 159 | if (revision < 2) { |
f6dd9221 BM |
160 | |
161 | /* 32-bit case */ | |
162 | ||
1da177e4 LT |
163 | acpi_gbl_integer_bit_width = 32; |
164 | acpi_gbl_integer_nybble_width = 8; | |
165 | acpi_gbl_integer_byte_width = 4; | |
4be44fcd | 166 | } else { |
f6dd9221 BM |
167 | /* 64-bit case (ACPI 2.0+) */ |
168 | ||
1da177e4 LT |
169 | acpi_gbl_integer_bit_width = 64; |
170 | acpi_gbl_integer_nybble_width = 16; | |
171 | acpi_gbl_integer_byte_width = 8; | |
172 | } | |
173 | } | |
174 | ||
1da177e4 LT |
175 | /******************************************************************************* |
176 | * | |
177 | * FUNCTION: acpi_ut_create_update_state_and_push | |
178 | * | |
ba494bee BM |
179 | * PARAMETERS: object - Object to be added to the new state |
180 | * action - Increment/Decrement | |
1da177e4 LT |
181 | * state_list - List the state will be added to |
182 | * | |
44f6c012 | 183 | * RETURN: Status |
1da177e4 LT |
184 | * |
185 | * DESCRIPTION: Create a new state and push it | |
186 | * | |
187 | ******************************************************************************/ | |
188 | ||
189 | acpi_status | |
4be44fcd LB |
190 | acpi_ut_create_update_state_and_push(union acpi_operand_object *object, |
191 | u16 action, | |
192 | union acpi_generic_state **state_list) | |
1da177e4 | 193 | { |
4be44fcd | 194 | union acpi_generic_state *state; |
1da177e4 | 195 | |
4be44fcd | 196 | ACPI_FUNCTION_ENTRY(); |
1da177e4 LT |
197 | |
198 | /* Ignore null objects; these are expected */ | |
199 | ||
200 | if (!object) { | |
201 | return (AE_OK); | |
202 | } | |
203 | ||
4be44fcd | 204 | state = acpi_ut_create_update_state(object, action); |
1da177e4 LT |
205 | if (!state) { |
206 | return (AE_NO_MEMORY); | |
207 | } | |
208 | ||
4be44fcd | 209 | acpi_ut_push_generic_state(state_list, state); |
1da177e4 LT |
210 | return (AE_OK); |
211 | } | |
212 | ||
1da177e4 LT |
213 | /******************************************************************************* |
214 | * | |
215 | * FUNCTION: acpi_ut_walk_package_tree | |
216 | * | |
44f6c012 RM |
217 | * PARAMETERS: source_object - The package to walk |
218 | * target_object - Target object (if package is being copied) | |
219 | * walk_callback - Called once for each package element | |
ba494bee | 220 | * context - Passed to the callback function |
1da177e4 LT |
221 | * |
222 | * RETURN: Status | |
223 | * | |
224 | * DESCRIPTION: Walk through a package | |
225 | * | |
226 | ******************************************************************************/ | |
227 | ||
228 | acpi_status | |
6d33b6be | 229 | acpi_ut_walk_package_tree(union acpi_operand_object *source_object, |
4be44fcd LB |
230 | void *target_object, |
231 | acpi_pkg_callback walk_callback, void *context) | |
1da177e4 | 232 | { |
4be44fcd LB |
233 | acpi_status status = AE_OK; |
234 | union acpi_generic_state *state_list = NULL; | |
235 | union acpi_generic_state *state; | |
236 | u32 this_index; | |
237 | union acpi_operand_object *this_source_obj; | |
1da177e4 | 238 | |
b229cf92 | 239 | ACPI_FUNCTION_TRACE(ut_walk_package_tree); |
1da177e4 | 240 | |
4be44fcd | 241 | state = acpi_ut_create_pkg_state(source_object, target_object, 0); |
1da177e4 | 242 | if (!state) { |
4be44fcd | 243 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
244 | } |
245 | ||
246 | while (state) { | |
52fc0b02 | 247 | |
1da177e4 LT |
248 | /* Get one element of the package */ |
249 | ||
4be44fcd | 250 | this_index = state->pkg.index; |
1da177e4 | 251 | this_source_obj = (union acpi_operand_object *) |
4be44fcd | 252 | state->pkg.source_object->package.elements[this_index]; |
1da177e4 LT |
253 | |
254 | /* | |
255 | * Check for: | |
73a3090a | 256 | * 1) An uninitialized package element. It is completely |
1da177e4 LT |
257 | * legal to declare a package and leave it uninitialized |
258 | * 2) Not an internal object - can be a namespace node instead | |
73a3090a | 259 | * 3) Any type other than a package. Packages are handled in else |
1da177e4 LT |
260 | * case below. |
261 | */ | |
262 | if ((!this_source_obj) || | |
4be44fcd LB |
263 | (ACPI_GET_DESCRIPTOR_TYPE(this_source_obj) != |
264 | ACPI_DESC_TYPE_OPERAND) | |
3371c19c | 265 | || (this_source_obj->common.type != ACPI_TYPE_PACKAGE)) { |
4be44fcd LB |
266 | status = |
267 | walk_callback(ACPI_COPY_TYPE_SIMPLE, | |
268 | this_source_obj, state, context); | |
269 | if (ACPI_FAILURE(status)) { | |
270 | return_ACPI_STATUS(status); | |
1da177e4 LT |
271 | } |
272 | ||
273 | state->pkg.index++; | |
4be44fcd LB |
274 | while (state->pkg.index >= |
275 | state->pkg.source_object->package.count) { | |
1da177e4 LT |
276 | /* |
277 | * We've handled all of the objects at this level, This means | |
73a3090a | 278 | * that we have just completed a package. That package may |
1da177e4 LT |
279 | * have contained one or more packages itself. |
280 | * | |
281 | * Delete this state and pop the previous state (package). | |
282 | */ | |
4be44fcd LB |
283 | acpi_ut_delete_generic_state(state); |
284 | state = acpi_ut_pop_generic_state(&state_list); | |
1da177e4 LT |
285 | |
286 | /* Finished when there are no more states */ | |
287 | ||
288 | if (!state) { | |
289 | /* | |
290 | * We have handled all of the objects in the top level | |
291 | * package just add the length of the package objects | |
292 | * and exit | |
293 | */ | |
4be44fcd | 294 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
295 | } |
296 | ||
297 | /* | |
298 | * Go back up a level and move the index past the just | |
299 | * completed package object. | |
300 | */ | |
301 | state->pkg.index++; | |
302 | } | |
4be44fcd | 303 | } else { |
1da177e4 LT |
304 | /* This is a subobject of type package */ |
305 | ||
4be44fcd LB |
306 | status = |
307 | walk_callback(ACPI_COPY_TYPE_PACKAGE, | |
308 | this_source_obj, state, context); | |
309 | if (ACPI_FAILURE(status)) { | |
310 | return_ACPI_STATUS(status); | |
1da177e4 LT |
311 | } |
312 | ||
313 | /* | |
314 | * Push the current state and create a new one | |
315 | * The callback above returned a new target package object. | |
316 | */ | |
4be44fcd LB |
317 | acpi_ut_push_generic_state(&state_list, state); |
318 | state = acpi_ut_create_pkg_state(this_source_obj, | |
319 | state->pkg. | |
320 | this_target_obj, 0); | |
1da177e4 | 321 | if (!state) { |
cf058bd1 LM |
322 | |
323 | /* Free any stacked Update State objects */ | |
324 | ||
325 | while (state_list) { | |
326 | state = | |
327 | acpi_ut_pop_generic_state | |
328 | (&state_list); | |
329 | acpi_ut_delete_generic_state(state); | |
330 | } | |
4be44fcd | 331 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
332 | } |
333 | } | |
334 | } | |
335 | ||
336 | /* We should never get here */ | |
337 | ||
4be44fcd | 338 | return_ACPI_STATUS(AE_AML_INTERNAL); |
1da177e4 | 339 | } |
42f8fb75 BM |
340 | |
341 | #ifdef ACPI_DEBUG_OUTPUT | |
342 | /******************************************************************************* | |
343 | * | |
344 | * FUNCTION: acpi_ut_display_init_pathname | |
345 | * | |
346 | * PARAMETERS: type - Object type of the node | |
347 | * obj_handle - Handle whose pathname will be displayed | |
348 | * path - Additional path string to be appended. | |
349 | * (NULL if no extra path) | |
350 | * | |
351 | * RETURN: acpi_status | |
352 | * | |
353 | * DESCRIPTION: Display full pathname of an object, DEBUG ONLY | |
354 | * | |
355 | ******************************************************************************/ | |
356 | ||
357 | void | |
358 | acpi_ut_display_init_pathname(u8 type, | |
359 | struct acpi_namespace_node *obj_handle, | |
360 | char *path) | |
361 | { | |
362 | acpi_status status; | |
363 | struct acpi_buffer buffer; | |
364 | ||
365 | ACPI_FUNCTION_ENTRY(); | |
366 | ||
367 | /* Only print the path if the appropriate debug level is enabled */ | |
368 | ||
369 | if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) { | |
370 | return; | |
371 | } | |
372 | ||
373 | /* Get the full pathname to the node */ | |
374 | ||
375 | buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; | |
376 | status = acpi_ns_handle_to_pathname(obj_handle, &buffer); | |
377 | if (ACPI_FAILURE(status)) { | |
378 | return; | |
379 | } | |
380 | ||
381 | /* Print what we're doing */ | |
382 | ||
383 | switch (type) { | |
384 | case ACPI_TYPE_METHOD: | |
1d1ea1b7 | 385 | |
42f8fb75 BM |
386 | acpi_os_printf("Executing "); |
387 | break; | |
388 | ||
389 | default: | |
1d1ea1b7 | 390 | |
42f8fb75 BM |
391 | acpi_os_printf("Initializing "); |
392 | break; | |
393 | } | |
394 | ||
395 | /* Print the object type and pathname */ | |
396 | ||
397 | acpi_os_printf("%-12s %s", | |
398 | acpi_ut_get_type_name(type), (char *)buffer.pointer); | |
399 | ||
400 | /* Extra path is used to append names like _STA, _INI, etc. */ | |
401 | ||
402 | if (path) { | |
403 | acpi_os_printf(".%s", path); | |
404 | } | |
405 | acpi_os_printf("\n"); | |
406 | ||
407 | ACPI_FREE(buffer.pointer); | |
408 | } | |
409 | #endif |