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