]>
Commit | Line | Data |
---|---|---|
96db255c BM |
1 | /******************************************************************************* |
2 | * | |
3c5f9be4 | 3 | * Module Name: utresrc - Resource management utilities |
96db255c BM |
4 | * |
5 | ******************************************************************************/ | |
6 | ||
7 | /* | |
7735ca0e | 8 | * Copyright (C) 2000 - 2017, Intel Corp. |
96db255c BM |
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 | ||
44 | #include <acpi/acpi.h> | |
e2f7a777 | 45 | #include "accommon.h" |
e0fe0a8d | 46 | #include "acresrc.h" |
96db255c BM |
47 | |
48 | #define _COMPONENT ACPI_UTILITIES | |
b229cf92 | 49 | ACPI_MODULE_NAME("utresrc") |
3334861b LZ |
50 | |
51 | #if defined(ACPI_DEBUG_OUTPUT) || defined (ACPI_DISASSEMBLER) || defined (ACPI_DEBUGGER) | |
defba1d8 BM |
52 | /* |
53 | * Strings used to decode resource descriptors. | |
70f23fd6 | 54 | * Used by both the disassembler and the debugger resource dump routines |
defba1d8 | 55 | */ |
b229cf92 BM |
56 | const char *acpi_gbl_bm_decode[] = { |
57 | "NotBusMaster", | |
58 | "BusMaster" | |
defba1d8 BM |
59 | }; |
60 | ||
b229cf92 | 61 | const char *acpi_gbl_config_decode[] = { |
defba1d8 BM |
62 | "0 - Good Configuration", |
63 | "1 - Acceptable Configuration", | |
64 | "2 - Suboptimal Configuration", | |
65 | "3 - ***Invalid Configuration***", | |
66 | }; | |
67 | ||
b229cf92 BM |
68 | const char *acpi_gbl_consume_decode[] = { |
69 | "ResourceProducer", | |
70 | "ResourceConsumer" | |
defba1d8 BM |
71 | }; |
72 | ||
b229cf92 BM |
73 | const char *acpi_gbl_dec_decode[] = { |
74 | "PosDecode", | |
75 | "SubDecode" | |
defba1d8 BM |
76 | }; |
77 | ||
b229cf92 | 78 | const char *acpi_gbl_he_decode[] = { |
defba1d8 BM |
79 | "Level", |
80 | "Edge" | |
81 | }; | |
82 | ||
b229cf92 | 83 | const char *acpi_gbl_io_decode[] = { |
defba1d8 BM |
84 | "Decode10", |
85 | "Decode16" | |
86 | }; | |
87 | ||
b229cf92 BM |
88 | const char *acpi_gbl_ll_decode[] = { |
89 | "ActiveHigh", | |
4cc0909e BM |
90 | "ActiveLow", |
91 | "ActiveBoth", | |
92 | "Reserved" | |
defba1d8 BM |
93 | }; |
94 | ||
b229cf92 BM |
95 | const char *acpi_gbl_max_decode[] = { |
96 | "MaxNotFixed", | |
97 | "MaxFixed" | |
defba1d8 BM |
98 | }; |
99 | ||
b229cf92 BM |
100 | const char *acpi_gbl_mem_decode[] = { |
101 | "NonCacheable", | |
defba1d8 | 102 | "Cacheable", |
b229cf92 | 103 | "WriteCombining", |
defba1d8 BM |
104 | "Prefetchable" |
105 | }; | |
106 | ||
b229cf92 BM |
107 | const char *acpi_gbl_min_decode[] = { |
108 | "MinNotFixed", | |
109 | "MinFixed" | |
defba1d8 BM |
110 | }; |
111 | ||
b229cf92 BM |
112 | const char *acpi_gbl_mtp_decode[] = { |
113 | "AddressRangeMemory", | |
114 | "AddressRangeReserved", | |
115 | "AddressRangeACPI", | |
116 | "AddressRangeNVS" | |
defba1d8 BM |
117 | }; |
118 | ||
b229cf92 BM |
119 | const char *acpi_gbl_rng_decode[] = { |
120 | "InvalidRanges", | |
121 | "NonISAOnlyRanges", | |
122 | "ISAOnlyRanges", | |
123 | "EntireRange" | |
defba1d8 BM |
124 | }; |
125 | ||
b229cf92 BM |
126 | const char *acpi_gbl_rw_decode[] = { |
127 | "ReadOnly", | |
128 | "ReadWrite" | |
defba1d8 BM |
129 | }; |
130 | ||
b229cf92 | 131 | const char *acpi_gbl_shr_decode[] = { |
defba1d8 | 132 | "Exclusive", |
1f06c921 BM |
133 | "Shared", |
134 | "ExclusiveAndWake", /* ACPI 5.0 */ | |
135 | "SharedAndWake" /* ACPI 5.0 */ | |
defba1d8 BM |
136 | }; |
137 | ||
b229cf92 | 138 | const char *acpi_gbl_siz_decode[] = { |
defba1d8 BM |
139 | "Transfer8", |
140 | "Transfer8_16", | |
141 | "Transfer16", | |
b229cf92 | 142 | "InvalidSize" |
defba1d8 BM |
143 | }; |
144 | ||
b229cf92 BM |
145 | const char *acpi_gbl_trs_decode[] = { |
146 | "DenseTranslation", | |
147 | "SparseTranslation" | |
defba1d8 BM |
148 | }; |
149 | ||
b229cf92 BM |
150 | const char *acpi_gbl_ttp_decode[] = { |
151 | "TypeStatic", | |
152 | "TypeTranslation" | |
defba1d8 BM |
153 | }; |
154 | ||
b229cf92 | 155 | const char *acpi_gbl_typ_decode[] = { |
defba1d8 | 156 | "Compatibility", |
b229cf92 BM |
157 | "TypeA", |
158 | "TypeB", | |
159 | "TypeF" | |
defba1d8 BM |
160 | }; |
161 | ||
e0fe0a8d LM |
162 | const char *acpi_gbl_ppc_decode[] = { |
163 | "PullDefault", | |
164 | "PullUp", | |
165 | "PullDown", | |
166 | "PullNone" | |
167 | }; | |
168 | ||
169 | const char *acpi_gbl_ior_decode[] = { | |
170 | "IoRestrictionNone", | |
171 | "IoRestrictionInputOnly", | |
172 | "IoRestrictionOutputOnly", | |
173 | "IoRestrictionNoneAndPreserve" | |
174 | }; | |
175 | ||
176 | const char *acpi_gbl_dts_decode[] = { | |
177 | "Width8bit", | |
178 | "Width16bit", | |
179 | "Width32bit", | |
180 | "Width64bit", | |
181 | "Width128bit", | |
182 | "Width256bit", | |
183 | }; | |
184 | ||
185 | /* GPIO connection type */ | |
186 | ||
187 | const char *acpi_gbl_ct_decode[] = { | |
188 | "Interrupt", | |
189 | "I/O" | |
190 | }; | |
191 | ||
192 | /* Serial bus type */ | |
193 | ||
194 | const char *acpi_gbl_sbt_decode[] = { | |
195 | "/* UNKNOWN serial bus type */", | |
196 | "I2C", | |
197 | "SPI", | |
198 | "UART" | |
199 | }; | |
200 | ||
201 | /* I2C serial bus access mode */ | |
202 | ||
203 | const char *acpi_gbl_am_decode[] = { | |
204 | "AddressingMode7Bit", | |
205 | "AddressingMode10Bit" | |
206 | }; | |
207 | ||
208 | /* I2C serial bus slave mode */ | |
209 | ||
210 | const char *acpi_gbl_sm_decode[] = { | |
211 | "ControllerInitiated", | |
212 | "DeviceInitiated" | |
213 | }; | |
214 | ||
215 | /* SPI serial bus wire mode */ | |
216 | ||
217 | const char *acpi_gbl_wm_decode[] = { | |
218 | "FourWireMode", | |
219 | "ThreeWireMode" | |
220 | }; | |
221 | ||
222 | /* SPI serial clock phase */ | |
223 | ||
224 | const char *acpi_gbl_cph_decode[] = { | |
225 | "ClockPhaseFirst", | |
226 | "ClockPhaseSecond" | |
227 | }; | |
228 | ||
229 | /* SPI serial bus clock polarity */ | |
230 | ||
231 | const char *acpi_gbl_cpo_decode[] = { | |
232 | "ClockPolarityLow", | |
233 | "ClockPolarityHigh" | |
234 | }; | |
235 | ||
236 | /* SPI serial bus device polarity */ | |
237 | ||
238 | const char *acpi_gbl_dp_decode[] = { | |
239 | "PolarityLow", | |
240 | "PolarityHigh" | |
241 | }; | |
242 | ||
243 | /* UART serial bus endian */ | |
244 | ||
245 | const char *acpi_gbl_ed_decode[] = { | |
246 | "LittleEndian", | |
247 | "BigEndian" | |
248 | }; | |
249 | ||
250 | /* UART serial bus bits per byte */ | |
251 | ||
252 | const char *acpi_gbl_bpb_decode[] = { | |
253 | "DataBitsFive", | |
254 | "DataBitsSix", | |
255 | "DataBitsSeven", | |
256 | "DataBitsEight", | |
257 | "DataBitsNine", | |
258 | "/* UNKNOWN Bits per byte */", | |
259 | "/* UNKNOWN Bits per byte */", | |
260 | "/* UNKNOWN Bits per byte */" | |
261 | }; | |
262 | ||
263 | /* UART serial bus stop bits */ | |
264 | ||
265 | const char *acpi_gbl_sb_decode[] = { | |
11811738 | 266 | "StopBitsZero", |
e0fe0a8d LM |
267 | "StopBitsOne", |
268 | "StopBitsOnePlusHalf", | |
269 | "StopBitsTwo" | |
270 | }; | |
271 | ||
272 | /* UART serial bus flow control */ | |
273 | ||
274 | const char *acpi_gbl_fc_decode[] = { | |
275 | "FlowControlNone", | |
276 | "FlowControlHardware", | |
277 | "FlowControlXON", | |
278 | "/* UNKNOWN flow control keyword */" | |
279 | }; | |
280 | ||
281 | /* UART serial bus parity type */ | |
282 | ||
283 | const char *acpi_gbl_pt_decode[] = { | |
284 | "ParityTypeNone", | |
285 | "ParityTypeEven", | |
286 | "ParityTypeOdd", | |
287 | "ParityTypeMark", | |
288 | "ParityTypeSpace", | |
289 | "/* UNKNOWN parity keyword */", | |
290 | "/* UNKNOWN parity keyword */", | |
291 | "/* UNKNOWN parity keyword */" | |
292 | }; | |
293 | ||
defba1d8 BM |
294 | #endif |
295 | ||
96db255c BM |
296 | /* |
297 | * Base sizes of the raw AML resource descriptors, indexed by resource type. | |
298 | * Zero indicates a reserved (and therefore invalid) resource type. | |
299 | */ | |
300 | const u8 acpi_gbl_resource_aml_sizes[] = { | |
301 | /* Small descriptors */ | |
302 | ||
303 | 0, | |
304 | 0, | |
305 | 0, | |
306 | 0, | |
307 | ACPI_AML_SIZE_SMALL(struct aml_resource_irq), | |
308 | ACPI_AML_SIZE_SMALL(struct aml_resource_dma), | |
309 | ACPI_AML_SIZE_SMALL(struct aml_resource_start_dependent), | |
310 | ACPI_AML_SIZE_SMALL(struct aml_resource_end_dependent), | |
311 | ACPI_AML_SIZE_SMALL(struct aml_resource_io), | |
312 | ACPI_AML_SIZE_SMALL(struct aml_resource_fixed_io), | |
e0fe0a8d | 313 | ACPI_AML_SIZE_SMALL(struct aml_resource_fixed_dma), |
96db255c BM |
314 | 0, |
315 | 0, | |
316 | 0, | |
317 | ACPI_AML_SIZE_SMALL(struct aml_resource_vendor_small), | |
318 | ACPI_AML_SIZE_SMALL(struct aml_resource_end_tag), | |
319 | ||
320 | /* Large descriptors */ | |
321 | ||
322 | 0, | |
323 | ACPI_AML_SIZE_LARGE(struct aml_resource_memory24), | |
324 | ACPI_AML_SIZE_LARGE(struct aml_resource_generic_register), | |
325 | 0, | |
326 | ACPI_AML_SIZE_LARGE(struct aml_resource_vendor_large), | |
327 | ACPI_AML_SIZE_LARGE(struct aml_resource_memory32), | |
328 | ACPI_AML_SIZE_LARGE(struct aml_resource_fixed_memory32), | |
329 | ACPI_AML_SIZE_LARGE(struct aml_resource_address32), | |
330 | ACPI_AML_SIZE_LARGE(struct aml_resource_address16), | |
331 | ACPI_AML_SIZE_LARGE(struct aml_resource_extended_irq), | |
332 | ACPI_AML_SIZE_LARGE(struct aml_resource_address64), | |
e0fe0a8d LM |
333 | ACPI_AML_SIZE_LARGE(struct aml_resource_extended_address64), |
334 | ACPI_AML_SIZE_LARGE(struct aml_resource_gpio), | |
335 | 0, | |
336 | ACPI_AML_SIZE_LARGE(struct aml_resource_common_serialbus), | |
337 | }; | |
338 | ||
339 | const u8 acpi_gbl_resource_aml_serial_bus_sizes[] = { | |
340 | 0, | |
341 | ACPI_AML_SIZE_LARGE(struct aml_resource_i2c_serialbus), | |
342 | ACPI_AML_SIZE_LARGE(struct aml_resource_spi_serialbus), | |
343 | ACPI_AML_SIZE_LARGE(struct aml_resource_uart_serialbus), | |
96db255c BM |
344 | }; |
345 | ||
346 | /* | |
347 | * Resource types, used to validate the resource length field. | |
348 | * The length of fixed-length types must match exactly, variable | |
349 | * lengths must meet the minimum required length, etc. | |
350 | * Zero indicates a reserved (and therefore invalid) resource type. | |
351 | */ | |
352 | static const u8 acpi_gbl_resource_types[] = { | |
353 | /* Small descriptors */ | |
354 | ||
355 | 0, | |
356 | 0, | |
357 | 0, | |
358 | 0, | |
e0fe0a8d LM |
359 | ACPI_SMALL_VARIABLE_LENGTH, /* 04 IRQ */ |
360 | ACPI_FIXED_LENGTH, /* 05 DMA */ | |
361 | ACPI_SMALL_VARIABLE_LENGTH, /* 06 start_dependent_functions */ | |
362 | ACPI_FIXED_LENGTH, /* 07 end_dependent_functions */ | |
363 | ACPI_FIXED_LENGTH, /* 08 IO */ | |
ba494bee BM |
364 | ACPI_FIXED_LENGTH, /* 09 fixed_IO */ |
365 | ACPI_FIXED_LENGTH, /* 0A fixed_DMA */ | |
96db255c BM |
366 | 0, |
367 | 0, | |
368 | 0, | |
ba494bee BM |
369 | ACPI_VARIABLE_LENGTH, /* 0E vendor_short */ |
370 | ACPI_FIXED_LENGTH, /* 0F end_tag */ | |
96db255c BM |
371 | |
372 | /* Large descriptors */ | |
373 | ||
374 | 0, | |
e0fe0a8d LM |
375 | ACPI_FIXED_LENGTH, /* 01 Memory24 */ |
376 | ACPI_FIXED_LENGTH, /* 02 generic_register */ | |
96db255c | 377 | 0, |
e0fe0a8d LM |
378 | ACPI_VARIABLE_LENGTH, /* 04 vendor_long */ |
379 | ACPI_FIXED_LENGTH, /* 05 Memory32 */ | |
380 | ACPI_FIXED_LENGTH, /* 06 memory32_fixed */ | |
381 | ACPI_VARIABLE_LENGTH, /* 07 Dword* address */ | |
382 | ACPI_VARIABLE_LENGTH, /* 08 Word* address */ | |
ba494bee BM |
383 | ACPI_VARIABLE_LENGTH, /* 09 extended_IRQ */ |
384 | ACPI_VARIABLE_LENGTH, /* 0A Qword* address */ | |
385 | ACPI_FIXED_LENGTH, /* 0B Extended* address */ | |
386 | ACPI_VARIABLE_LENGTH, /* 0C Gpio* */ | |
e0fe0a8d | 387 | 0, |
ba494bee | 388 | ACPI_VARIABLE_LENGTH /* 0E *serial_bus */ |
96db255c BM |
389 | }; |
390 | ||
61686124 BM |
391 | /******************************************************************************* |
392 | * | |
393 | * FUNCTION: acpi_ut_walk_aml_resources | |
394 | * | |
886308ec BM |
395 | * PARAMETERS: walk_state - Current walk info |
396 | * PARAMETERS: aml - Pointer to the raw AML resource template | |
397 | * aml_length - Length of the entire template | |
398 | * user_function - Called once for each descriptor found. If | |
399 | * NULL, a pointer to the end_tag is returned | |
400 | * context - Passed to user_function | |
61686124 BM |
401 | * |
402 | * RETURN: Status | |
403 | * | |
404 | * DESCRIPTION: Walk a raw AML resource list(buffer). User function called | |
405 | * once for each resource found. | |
406 | * | |
407 | ******************************************************************************/ | |
408 | ||
409 | acpi_status | |
886308ec BM |
410 | acpi_ut_walk_aml_resources(struct acpi_walk_state *walk_state, |
411 | u8 *aml, | |
61686124 | 412 | acpi_size aml_length, |
793c2388 | 413 | acpi_walk_aml_callback user_function, void **context) |
61686124 BM |
414 | { |
415 | acpi_status status; | |
416 | u8 *end_aml; | |
417 | u8 resource_index; | |
418 | u32 length; | |
419 | u32 offset = 0; | |
e0fe0a8d | 420 | u8 end_tag[2] = { 0x79, 0x00 }; |
61686124 | 421 | |
b229cf92 | 422 | ACPI_FUNCTION_TRACE(ut_walk_aml_resources); |
61686124 | 423 | |
57707a9a BM |
424 | /* |
425 | * The absolute minimum resource template is one end_tag descriptor. | |
426 | * However, we will treat a lone end_tag as just a simple buffer. | |
427 | */ | |
61686124 BM |
428 | if (aml_length < sizeof(struct aml_resource_end_tag)) { |
429 | return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG); | |
430 | } | |
431 | ||
432 | /* Point to the end of the resource template buffer */ | |
433 | ||
434 | end_aml = aml + aml_length; | |
435 | ||
436 | /* Walk the byte list, abort on any invalid descriptor type or length */ | |
437 | ||
438 | while (aml < end_aml) { | |
439 | ||
440 | /* Validate the Resource Type and Resource Length */ | |
441 | ||
886308ec BM |
442 | status = |
443 | acpi_ut_validate_resource(walk_state, aml, &resource_index); | |
61686124 | 444 | if (ACPI_FAILURE(status)) { |
e0fe0a8d | 445 | /* |
1fad8738 BM |
446 | * Exit on failure. Cannot continue because the descriptor |
447 | * length may be bogus also. | |
e0fe0a8d | 448 | */ |
61686124 BM |
449 | return_ACPI_STATUS(status); |
450 | } | |
451 | ||
452 | /* Get the length of this descriptor */ | |
453 | ||
454 | length = acpi_ut_get_descriptor_length(aml); | |
455 | ||
456 | /* Invoke the user function */ | |
457 | ||
458 | if (user_function) { | |
57707a9a BM |
459 | status = user_function(aml, length, offset, |
460 | resource_index, context); | |
61686124 | 461 | if (ACPI_FAILURE(status)) { |
e0fe0a8d | 462 | return_ACPI_STATUS(status); |
61686124 BM |
463 | } |
464 | } | |
465 | ||
466 | /* An end_tag descriptor terminates this resource template */ | |
467 | ||
468 | if (acpi_ut_get_resource_type(aml) == | |
469 | ACPI_RESOURCE_NAME_END_TAG) { | |
470 | /* | |
471 | * There must be at least one more byte in the buffer for | |
472 | * the 2nd byte of the end_tag | |
473 | */ | |
474 | if ((aml + 1) >= end_aml) { | |
475 | return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG); | |
476 | } | |
477 | ||
478 | /* Return the pointer to the end_tag if requested */ | |
479 | ||
480 | if (!user_function) { | |
793c2388 | 481 | *context = aml; |
61686124 BM |
482 | } |
483 | ||
57707a9a BM |
484 | /* Check if buffer is defined to be longer than the resource length */ |
485 | ||
486 | if (aml_length > (offset + length)) { | |
487 | return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG); | |
488 | } | |
489 | ||
61686124 BM |
490 | /* Normal exit */ |
491 | ||
492 | return_ACPI_STATUS(AE_OK); | |
493 | } | |
494 | ||
495 | aml += length; | |
496 | offset += length; | |
497 | } | |
498 | ||
499 | /* Did not find an end_tag descriptor */ | |
500 | ||
e0fe0a8d LM |
501 | if (user_function) { |
502 | ||
503 | /* Insert an end_tag anyway. acpi_rs_get_list_length always leaves room */ | |
504 | ||
886308ec BM |
505 | (void)acpi_ut_validate_resource(walk_state, end_tag, |
506 | &resource_index); | |
e0fe0a8d LM |
507 | status = |
508 | user_function(end_tag, 2, offset, resource_index, context); | |
509 | if (ACPI_FAILURE(status)) { | |
510 | return_ACPI_STATUS(status); | |
511 | } | |
512 | } | |
513 | ||
514 | return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG); | |
61686124 BM |
515 | } |
516 | ||
96db255c BM |
517 | /******************************************************************************* |
518 | * | |
519 | * FUNCTION: acpi_ut_validate_resource | |
520 | * | |
886308ec BM |
521 | * PARAMETERS: walk_state - Current walk info |
522 | * aml - Pointer to the raw AML resource descriptor | |
523 | * return_index - Where the resource index is returned. NULL | |
524 | * if the index is not required. | |
96db255c BM |
525 | * |
526 | * RETURN: Status, and optionally the Index into the global resource tables | |
527 | * | |
528 | * DESCRIPTION: Validate an AML resource descriptor by checking the Resource | |
529 | * Type and Resource Length. Returns an index into the global | |
530 | * resource information/dispatch tables for later use. | |
531 | * | |
532 | ******************************************************************************/ | |
533 | ||
886308ec BM |
534 | acpi_status |
535 | acpi_ut_validate_resource(struct acpi_walk_state *walk_state, | |
536 | void *aml, u8 *return_index) | |
96db255c | 537 | { |
e0fe0a8d | 538 | union aml_resource *aml_resource; |
96db255c BM |
539 | u8 resource_type; |
540 | u8 resource_index; | |
541 | acpi_rs_length resource_length; | |
542 | acpi_rs_length minimum_resource_length; | |
543 | ||
544 | ACPI_FUNCTION_ENTRY(); | |
545 | ||
546 | /* | |
547 | * 1) Validate the resource_type field (Byte 0) | |
548 | */ | |
c51a4de8 | 549 | resource_type = ACPI_GET8(aml); |
96db255c BM |
550 | |
551 | /* | |
552 | * Byte 0 contains the descriptor name (Resource Type) | |
553 | * Examine the large/small bit in the resource header | |
554 | */ | |
555 | if (resource_type & ACPI_RESOURCE_NAME_LARGE) { | |
52fc0b02 | 556 | |
96db255c BM |
557 | /* Verify the large resource type (name) against the max */ |
558 | ||
559 | if (resource_type > ACPI_RESOURCE_NAME_LARGE_MAX) { | |
e0fe0a8d | 560 | goto invalid_resource; |
96db255c BM |
561 | } |
562 | ||
563 | /* | |
564 | * Large Resource Type -- bits 6:0 contain the name | |
565 | * Translate range 0x80-0x8B to index range 0x10-0x1B | |
566 | */ | |
567 | resource_index = (u8) (resource_type - 0x70); | |
568 | } else { | |
569 | /* | |
570 | * Small Resource Type -- bits 6:3 contain the name | |
571 | * Shift range to index range 0x00-0x0F | |
572 | */ | |
573 | resource_index = (u8) | |
574 | ((resource_type & ACPI_RESOURCE_NAME_SMALL_MASK) >> 3); | |
575 | } | |
576 | ||
e0fe0a8d | 577 | /* |
1fad8738 BM |
578 | * Check validity of the resource type, via acpi_gbl_resource_types. |
579 | * Zero indicates an invalid resource. | |
e0fe0a8d | 580 | */ |
96db255c | 581 | if (!acpi_gbl_resource_types[resource_index]) { |
e0fe0a8d | 582 | goto invalid_resource; |
96db255c BM |
583 | } |
584 | ||
585 | /* | |
e0fe0a8d LM |
586 | * Validate the resource_length field. This ensures that the length |
587 | * is at least reasonable, and guarantees that it is non-zero. | |
96db255c BM |
588 | */ |
589 | resource_length = acpi_ut_get_resource_length(aml); | |
590 | minimum_resource_length = acpi_gbl_resource_aml_sizes[resource_index]; | |
591 | ||
592 | /* Validate based upon the type of resource - fixed length or variable */ | |
593 | ||
594 | switch (acpi_gbl_resource_types[resource_index]) { | |
595 | case ACPI_FIXED_LENGTH: | |
596 | ||
597 | /* Fixed length resource, length must match exactly */ | |
598 | ||
599 | if (resource_length != minimum_resource_length) { | |
e0fe0a8d | 600 | goto bad_resource_length; |
96db255c BM |
601 | } |
602 | break; | |
603 | ||
604 | case ACPI_VARIABLE_LENGTH: | |
605 | ||
606 | /* Variable length resource, length must be at least the minimum */ | |
607 | ||
608 | if (resource_length < minimum_resource_length) { | |
e0fe0a8d | 609 | goto bad_resource_length; |
96db255c BM |
610 | } |
611 | break; | |
612 | ||
613 | case ACPI_SMALL_VARIABLE_LENGTH: | |
614 | ||
615 | /* Small variable length resource, length can be (Min) or (Min-1) */ | |
616 | ||
617 | if ((resource_length > minimum_resource_length) || | |
618 | (resource_length < (minimum_resource_length - 1))) { | |
e0fe0a8d | 619 | goto bad_resource_length; |
96db255c BM |
620 | } |
621 | break; | |
622 | ||
623 | default: | |
624 | ||
625 | /* Shouldn't happen (because of validation earlier), but be sure */ | |
626 | ||
e0fe0a8d LM |
627 | goto invalid_resource; |
628 | } | |
629 | ||
630 | aml_resource = ACPI_CAST_PTR(union aml_resource, aml); | |
631 | if (resource_type == ACPI_RESOURCE_NAME_SERIAL_BUS) { | |
632 | ||
633 | /* Validate the bus_type field */ | |
634 | ||
635 | if ((aml_resource->common_serial_bus.type == 0) || | |
636 | (aml_resource->common_serial_bus.type > | |
637 | AML_RESOURCE_MAX_SERIALBUSTYPE)) { | |
886308ec BM |
638 | if (walk_state) { |
639 | ACPI_ERROR((AE_INFO, | |
640 | "Invalid/unsupported SerialBus resource descriptor: BusType 0x%2.2X", | |
641 | aml_resource->common_serial_bus. | |
642 | type)); | |
643 | } | |
e0fe0a8d LM |
644 | return (AE_AML_INVALID_RESOURCE_TYPE); |
645 | } | |
96db255c BM |
646 | } |
647 | ||
648 | /* Optionally return the resource table index */ | |
649 | ||
650 | if (return_index) { | |
651 | *return_index = resource_index; | |
652 | } | |
653 | ||
654 | return (AE_OK); | |
e0fe0a8d | 655 | |
10622bf8 | 656 | invalid_resource: |
e0fe0a8d | 657 | |
886308ec BM |
658 | if (walk_state) { |
659 | ACPI_ERROR((AE_INFO, | |
660 | "Invalid/unsupported resource descriptor: Type 0x%2.2X", | |
661 | resource_type)); | |
662 | } | |
e0fe0a8d LM |
663 | return (AE_AML_INVALID_RESOURCE_TYPE); |
664 | ||
10622bf8 | 665 | bad_resource_length: |
e0fe0a8d | 666 | |
886308ec BM |
667 | if (walk_state) { |
668 | ACPI_ERROR((AE_INFO, | |
669 | "Invalid resource descriptor length: Type " | |
670 | "0x%2.2X, Length 0x%4.4X, MinLength 0x%4.4X", | |
671 | resource_type, resource_length, | |
672 | minimum_resource_length)); | |
673 | } | |
e0fe0a8d | 674 | return (AE_AML_BAD_RESOURCE_LENGTH); |
96db255c BM |
675 | } |
676 | ||
677 | /******************************************************************************* | |
678 | * | |
679 | * FUNCTION: acpi_ut_get_resource_type | |
680 | * | |
ba494bee | 681 | * PARAMETERS: aml - Pointer to the raw AML resource descriptor |
96db255c BM |
682 | * |
683 | * RETURN: The Resource Type with no extraneous bits (except the | |
684 | * Large/Small descriptor bit -- this is left alone) | |
685 | * | |
686 | * DESCRIPTION: Extract the Resource Type/Name from the first byte of | |
687 | * a resource descriptor. | |
688 | * | |
689 | ******************************************************************************/ | |
690 | ||
691 | u8 acpi_ut_get_resource_type(void *aml) | |
692 | { | |
693 | ACPI_FUNCTION_ENTRY(); | |
694 | ||
695 | /* | |
696 | * Byte 0 contains the descriptor name (Resource Type) | |
697 | * Examine the large/small bit in the resource header | |
698 | */ | |
c51a4de8 | 699 | if (ACPI_GET8(aml) & ACPI_RESOURCE_NAME_LARGE) { |
52fc0b02 | 700 | |
96db255c BM |
701 | /* Large Resource Type -- bits 6:0 contain the name */ |
702 | ||
c51a4de8 | 703 | return (ACPI_GET8(aml)); |
96db255c BM |
704 | } else { |
705 | /* Small Resource Type -- bits 6:3 contain the name */ | |
706 | ||
c51a4de8 | 707 | return ((u8) (ACPI_GET8(aml) & ACPI_RESOURCE_NAME_SMALL_MASK)); |
96db255c BM |
708 | } |
709 | } | |
710 | ||
711 | /******************************************************************************* | |
712 | * | |
713 | * FUNCTION: acpi_ut_get_resource_length | |
714 | * | |
ba494bee | 715 | * PARAMETERS: aml - Pointer to the raw AML resource descriptor |
96db255c BM |
716 | * |
717 | * RETURN: Byte Length | |
718 | * | |
719 | * DESCRIPTION: Get the "Resource Length" of a raw AML descriptor. By | |
720 | * definition, this does not include the size of the descriptor | |
721 | * header or the length field itself. | |
722 | * | |
723 | ******************************************************************************/ | |
724 | ||
725 | u16 acpi_ut_get_resource_length(void *aml) | |
726 | { | |
727 | acpi_rs_length resource_length; | |
728 | ||
729 | ACPI_FUNCTION_ENTRY(); | |
730 | ||
731 | /* | |
732 | * Byte 0 contains the descriptor name (Resource Type) | |
733 | * Examine the large/small bit in the resource header | |
734 | */ | |
c51a4de8 | 735 | if (ACPI_GET8(aml) & ACPI_RESOURCE_NAME_LARGE) { |
52fc0b02 | 736 | |
96db255c BM |
737 | /* Large Resource type -- bytes 1-2 contain the 16-bit length */ |
738 | ||
c51a4de8 | 739 | ACPI_MOVE_16_TO_16(&resource_length, ACPI_ADD_PTR(u8, aml, 1)); |
96db255c BM |
740 | |
741 | } else { | |
742 | /* Small Resource type -- bits 2:0 of byte 0 contain the length */ | |
743 | ||
c51a4de8 | 744 | resource_length = (u16) (ACPI_GET8(aml) & |
96db255c BM |
745 | ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK); |
746 | } | |
747 | ||
748 | return (resource_length); | |
749 | } | |
750 | ||
751 | /******************************************************************************* | |
752 | * | |
753 | * FUNCTION: acpi_ut_get_resource_header_length | |
754 | * | |
ba494bee | 755 | * PARAMETERS: aml - Pointer to the raw AML resource descriptor |
96db255c BM |
756 | * |
757 | * RETURN: Length of the AML header (depends on large/small descriptor) | |
758 | * | |
759 | * DESCRIPTION: Get the length of the header for this resource. | |
760 | * | |
761 | ******************************************************************************/ | |
762 | ||
763 | u8 acpi_ut_get_resource_header_length(void *aml) | |
764 | { | |
765 | ACPI_FUNCTION_ENTRY(); | |
766 | ||
767 | /* Examine the large/small bit in the resource header */ | |
768 | ||
c51a4de8 | 769 | if (ACPI_GET8(aml) & ACPI_RESOURCE_NAME_LARGE) { |
96db255c BM |
770 | return (sizeof(struct aml_resource_large_header)); |
771 | } else { | |
772 | return (sizeof(struct aml_resource_small_header)); | |
773 | } | |
774 | } | |
775 | ||
776 | /******************************************************************************* | |
777 | * | |
778 | * FUNCTION: acpi_ut_get_descriptor_length | |
779 | * | |
ba494bee | 780 | * PARAMETERS: aml - Pointer to the raw AML resource descriptor |
96db255c BM |
781 | * |
782 | * RETURN: Byte length | |
783 | * | |
784 | * DESCRIPTION: Get the total byte length of a raw AML descriptor, including the | |
785 | * length of the descriptor header and the length field itself. | |
786 | * Used to walk descriptor lists. | |
787 | * | |
788 | ******************************************************************************/ | |
789 | ||
790 | u32 acpi_ut_get_descriptor_length(void *aml) | |
791 | { | |
792 | ACPI_FUNCTION_ENTRY(); | |
793 | ||
794 | /* | |
795 | * Get the Resource Length (does not include header length) and add | |
796 | * the header length (depends on if this is a small or large resource) | |
797 | */ | |
798 | return (acpi_ut_get_resource_length(aml) + | |
799 | acpi_ut_get_resource_header_length(aml)); | |
800 | } | |
801 | ||
802 | /******************************************************************************* | |
803 | * | |
804 | * FUNCTION: acpi_ut_get_resource_end_tag | |
805 | * | |
806 | * PARAMETERS: obj_desc - The resource template buffer object | |
c51a4de8 | 807 | * end_tag - Where the pointer to the end_tag is returned |
96db255c | 808 | * |
c51a4de8 | 809 | * RETURN: Status, pointer to the end tag |
96db255c BM |
810 | * |
811 | * DESCRIPTION: Find the end_tag resource descriptor in an AML resource template | |
b8e4d893 | 812 | * Note: allows a buffer length of zero. |
96db255c BM |
813 | * |
814 | ******************************************************************************/ | |
815 | ||
816 | acpi_status | |
3e8214e5 | 817 | acpi_ut_get_resource_end_tag(union acpi_operand_object *obj_desc, u8 **end_tag) |
96db255c BM |
818 | { |
819 | acpi_status status; | |
96db255c | 820 | |
b229cf92 | 821 | ACPI_FUNCTION_TRACE(ut_get_resource_end_tag); |
96db255c | 822 | |
b8e4d893 BM |
823 | /* Allow a buffer length of zero */ |
824 | ||
825 | if (!obj_desc->buffer.length) { | |
61686124 | 826 | *end_tag = obj_desc->buffer.pointer; |
b8e4d893 BM |
827 | return_ACPI_STATUS(AE_OK); |
828 | } | |
829 | ||
61686124 | 830 | /* Validate the template and get a pointer to the end_tag */ |
96db255c | 831 | |
886308ec | 832 | status = acpi_ut_walk_aml_resources(NULL, obj_desc->buffer.pointer, |
61686124 | 833 | obj_desc->buffer.length, NULL, |
793c2388 | 834 | (void **)end_tag); |
96db255c | 835 | |
61686124 | 836 | return_ACPI_STATUS(status); |
96db255c | 837 | } |