Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Module Name: utresrc - Resource management utilities
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <acpi/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include "accommon.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "acresrc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #define _COMPONENT          ACPI_UTILITIES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) ACPI_MODULE_NAME("utresrc")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * Base sizes of the raw AML resource descriptors, indexed by resource type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * Zero indicates a reserved (and therefore invalid) resource type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) const u8 acpi_gbl_resource_aml_sizes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	/* Small descriptors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	ACPI_AML_SIZE_SMALL(struct aml_resource_irq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	ACPI_AML_SIZE_SMALL(struct aml_resource_dma),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	ACPI_AML_SIZE_SMALL(struct aml_resource_start_dependent),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	ACPI_AML_SIZE_SMALL(struct aml_resource_end_dependent),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	ACPI_AML_SIZE_SMALL(struct aml_resource_io),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	ACPI_AML_SIZE_SMALL(struct aml_resource_fixed_io),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	ACPI_AML_SIZE_SMALL(struct aml_resource_fixed_dma),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	ACPI_AML_SIZE_SMALL(struct aml_resource_vendor_small),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	ACPI_AML_SIZE_SMALL(struct aml_resource_end_tag),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	/* Large descriptors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	ACPI_AML_SIZE_LARGE(struct aml_resource_memory24),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	ACPI_AML_SIZE_LARGE(struct aml_resource_generic_register),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	ACPI_AML_SIZE_LARGE(struct aml_resource_vendor_large),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	ACPI_AML_SIZE_LARGE(struct aml_resource_memory32),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	ACPI_AML_SIZE_LARGE(struct aml_resource_fixed_memory32),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	ACPI_AML_SIZE_LARGE(struct aml_resource_address32),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	ACPI_AML_SIZE_LARGE(struct aml_resource_address16),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	ACPI_AML_SIZE_LARGE(struct aml_resource_extended_irq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	ACPI_AML_SIZE_LARGE(struct aml_resource_address64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	ACPI_AML_SIZE_LARGE(struct aml_resource_extended_address64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	ACPI_AML_SIZE_LARGE(struct aml_resource_gpio),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	ACPI_AML_SIZE_LARGE(struct aml_resource_pin_function),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	ACPI_AML_SIZE_LARGE(struct aml_resource_common_serialbus),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	ACPI_AML_SIZE_LARGE(struct aml_resource_pin_config),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	ACPI_AML_SIZE_LARGE(struct aml_resource_pin_group),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	ACPI_AML_SIZE_LARGE(struct aml_resource_pin_group_function),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	ACPI_AML_SIZE_LARGE(struct aml_resource_pin_group_config),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) const u8 acpi_gbl_resource_aml_serial_bus_sizes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	ACPI_AML_SIZE_LARGE(struct aml_resource_i2c_serialbus),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	ACPI_AML_SIZE_LARGE(struct aml_resource_spi_serialbus),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	ACPI_AML_SIZE_LARGE(struct aml_resource_uart_serialbus),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * Resource types, used to validate the resource length field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * The length of fixed-length types must match exactly, variable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  * lengths must meet the minimum required length, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  * Zero indicates a reserved (and therefore invalid) resource type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static const u8 acpi_gbl_resource_types[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	/* Small descriptors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	ACPI_SMALL_VARIABLE_LENGTH,	/* 04 IRQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	ACPI_FIXED_LENGTH,	/* 05 DMA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	ACPI_SMALL_VARIABLE_LENGTH,	/* 06 start_dependent_functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	ACPI_FIXED_LENGTH,	/* 07 end_dependent_functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	ACPI_FIXED_LENGTH,	/* 08 IO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	ACPI_FIXED_LENGTH,	/* 09 fixed_IO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	ACPI_FIXED_LENGTH,	/* 0A fixed_DMA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	ACPI_VARIABLE_LENGTH,	/* 0E vendor_short */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	ACPI_FIXED_LENGTH,	/* 0F end_tag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	/* Large descriptors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	ACPI_FIXED_LENGTH,	/* 01 Memory24 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	ACPI_FIXED_LENGTH,	/* 02 generic_register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	ACPI_VARIABLE_LENGTH,	/* 04 vendor_long */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	ACPI_FIXED_LENGTH,	/* 05 Memory32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	ACPI_FIXED_LENGTH,	/* 06 memory32_fixed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	ACPI_VARIABLE_LENGTH,	/* 07 Dword* address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	ACPI_VARIABLE_LENGTH,	/* 08 Word* address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	ACPI_VARIABLE_LENGTH,	/* 09 extended_IRQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	ACPI_VARIABLE_LENGTH,	/* 0A Qword* address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	ACPI_FIXED_LENGTH,	/* 0B Extended* address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	ACPI_VARIABLE_LENGTH,	/* 0C Gpio* */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	ACPI_VARIABLE_LENGTH,	/* 0D pin_function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	ACPI_VARIABLE_LENGTH,	/* 0E *serial_bus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	ACPI_VARIABLE_LENGTH,	/* 0F pin_config */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	ACPI_VARIABLE_LENGTH,	/* 10 pin_group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	ACPI_VARIABLE_LENGTH,	/* 11 pin_group_function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	ACPI_VARIABLE_LENGTH,	/* 12 pin_group_config */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  * FUNCTION:    acpi_ut_walk_aml_resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * PARAMETERS:  walk_state          - Current walk info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  * PARAMETERS:  aml                 - Pointer to the raw AML resource template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  *              aml_length          - Length of the entire template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  *              user_function       - Called once for each descriptor found. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  *                                    NULL, a pointer to the end_tag is returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  *              context             - Passed to user_function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  * RETURN:      Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  * DESCRIPTION: Walk a raw AML resource list(buffer). User function called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)  *              once for each resource found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) acpi_ut_walk_aml_resources(struct acpi_walk_state *walk_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			   u8 *aml,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			   acpi_size aml_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			   acpi_walk_aml_callback user_function, void **context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	u8 *end_aml;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	u8 resource_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	u32 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	u32 offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	u8 end_tag[2] = { 0x79, 0x00 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	ACPI_FUNCTION_TRACE(ut_walk_aml_resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	/* The absolute minimum resource template is one end_tag descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	if (aml_length < sizeof(struct aml_resource_end_tag)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	/* Point to the end of the resource template buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	end_aml = aml + aml_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	/* Walk the byte list, abort on any invalid descriptor type or length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	while (aml < end_aml) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		/* Validate the Resource Type and Resource Length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		    acpi_ut_validate_resource(walk_state, aml, &resource_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			 * Exit on failure. Cannot continue because the descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			 * length may be bogus also.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		/* Get the length of this descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		length = acpi_ut_get_descriptor_length(aml);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		/* Invoke the user function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		if (user_function) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 			    user_function(aml, length, offset, resource_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 					  context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 				return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		/* An end_tag descriptor terminates this resource template */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		if (acpi_ut_get_resource_type(aml) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		    ACPI_RESOURCE_NAME_END_TAG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			 * There must be at least one more byte in the buffer for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			 * the 2nd byte of the end_tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			if ((aml + 1) >= end_aml) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 				return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			 * Don't attempt to perform any validation on the 2nd byte.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			 * Although all known ASL compilers insert a zero for the 2nd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			 * byte, it can also be a checksum (as per the ACPI spec),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			 * and this is occasionally seen in the field. July 2017.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			/* Return the pointer to the end_tag if requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			if (!user_function) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 				*context = aml;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			/* Normal exit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		aml += length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		offset += length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	/* Did not find an end_tag descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	if (user_function) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		/* Insert an end_tag anyway. acpi_rs_get_list_length always leaves room */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		(void)acpi_ut_validate_resource(walk_state, end_tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 						&resource_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		    user_function(end_tag, 2, offset, resource_index, context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  * FUNCTION:    acpi_ut_validate_resource
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  * PARAMETERS:  walk_state          - Current walk info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  *              aml                 - Pointer to the raw AML resource descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)  *              return_index        - Where the resource index is returned. NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  *                                    if the index is not required.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)  * RETURN:      Status, and optionally the Index into the global resource tables
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)  * DESCRIPTION: Validate an AML resource descriptor by checking the Resource
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)  *              Type and Resource Length. Returns an index into the global
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)  *              resource information/dispatch tables for later use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)  ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) acpi_ut_validate_resource(struct acpi_walk_state *walk_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			  void *aml, u8 *return_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	union aml_resource *aml_resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	u8 resource_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	u8 resource_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	acpi_rs_length resource_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	acpi_rs_length minimum_resource_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	ACPI_FUNCTION_ENTRY();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	 * 1) Validate the resource_type field (Byte 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	resource_type = ACPI_GET8(aml);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	 * Byte 0 contains the descriptor name (Resource Type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	 * Examine the large/small bit in the resource header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	if (resource_type & ACPI_RESOURCE_NAME_LARGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		/* Verify the large resource type (name) against the max */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		if (resource_type > ACPI_RESOURCE_NAME_LARGE_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			goto invalid_resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		 * Large Resource Type -- bits 6:0 contain the name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		 * Translate range 0x80-0x8B to index range 0x10-0x1B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		resource_index = (u8) (resource_type - 0x70);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		 * Small Resource Type -- bits 6:3 contain the name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		 * Shift range to index range 0x00-0x0F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		resource_index = (u8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		    ((resource_type & ACPI_RESOURCE_NAME_SMALL_MASK) >> 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	 * Check validity of the resource type, via acpi_gbl_resource_types.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	 * Zero indicates an invalid resource.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	if (!acpi_gbl_resource_types[resource_index]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		goto invalid_resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	 * Validate the resource_length field. This ensures that the length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	 * is at least reasonable, and guarantees that it is non-zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	resource_length = acpi_ut_get_resource_length(aml);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	minimum_resource_length = acpi_gbl_resource_aml_sizes[resource_index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	/* Validate based upon the type of resource - fixed length or variable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	switch (acpi_gbl_resource_types[resource_index]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	case ACPI_FIXED_LENGTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		/* Fixed length resource, length must match exactly */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		if (resource_length != minimum_resource_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 			goto bad_resource_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	case ACPI_VARIABLE_LENGTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		/* Variable length resource, length must be at least the minimum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		if (resource_length < minimum_resource_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			goto bad_resource_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	case ACPI_SMALL_VARIABLE_LENGTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		/* Small variable length resource, length can be (Min) or (Min-1) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		if ((resource_length > minimum_resource_length) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		    (resource_length < (minimum_resource_length - 1))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 			goto bad_resource_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		/* Shouldn't happen (because of validation earlier), but be sure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		goto invalid_resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	aml_resource = ACPI_CAST_PTR(union aml_resource, aml);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	if (resource_type == ACPI_RESOURCE_NAME_SERIAL_BUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		/* Validate the bus_type field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		if ((aml_resource->common_serial_bus.type == 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		    (aml_resource->common_serial_bus.type >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		     AML_RESOURCE_MAX_SERIALBUSTYPE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 			if (walk_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 				ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 					    "Invalid/unsupported SerialBus resource descriptor: BusType 0x%2.2X",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 					    aml_resource->common_serial_bus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 					    type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 			return (AE_AML_INVALID_RESOURCE_TYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	/* Optionally return the resource table index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	if (return_index) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		*return_index = resource_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) invalid_resource:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	if (walk_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 			    "Invalid/unsupported resource descriptor: Type 0x%2.2X",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 			    resource_type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	return (AE_AML_INVALID_RESOURCE_TYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) bad_resource_length:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	if (walk_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 			    "Invalid resource descriptor length: Type "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 			    "0x%2.2X, Length 0x%4.4X, MinLength 0x%4.4X",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 			    resource_type, resource_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 			    minimum_resource_length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	return (AE_AML_BAD_RESOURCE_LENGTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)  * FUNCTION:    acpi_ut_get_resource_type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)  * PARAMETERS:  aml             - Pointer to the raw AML resource descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)  * RETURN:      The Resource Type with no extraneous bits (except the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)  *              Large/Small descriptor bit -- this is left alone)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)  * DESCRIPTION: Extract the Resource Type/Name from the first byte of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)  *              a resource descriptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)  ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) u8 acpi_ut_get_resource_type(void *aml)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	ACPI_FUNCTION_ENTRY();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	 * Byte 0 contains the descriptor name (Resource Type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	 * Examine the large/small bit in the resource header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	if (ACPI_GET8(aml) & ACPI_RESOURCE_NAME_LARGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		/* Large Resource Type -- bits 6:0 contain the name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		return (ACPI_GET8(aml));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		/* Small Resource Type -- bits 6:3 contain the name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		return ((u8) (ACPI_GET8(aml) & ACPI_RESOURCE_NAME_SMALL_MASK));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)  * FUNCTION:    acpi_ut_get_resource_length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)  * PARAMETERS:  aml             - Pointer to the raw AML resource descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)  * RETURN:      Byte Length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)  * DESCRIPTION: Get the "Resource Length" of a raw AML descriptor. By
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)  *              definition, this does not include the size of the descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)  *              header or the length field itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)  ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) u16 acpi_ut_get_resource_length(void *aml)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	acpi_rs_length resource_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	ACPI_FUNCTION_ENTRY();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	 * Byte 0 contains the descriptor name (Resource Type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	 * Examine the large/small bit in the resource header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	if (ACPI_GET8(aml) & ACPI_RESOURCE_NAME_LARGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		/* Large Resource type -- bytes 1-2 contain the 16-bit length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		ACPI_MOVE_16_TO_16(&resource_length, ACPI_ADD_PTR(u8, aml, 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		/* Small Resource type -- bits 2:0 of byte 0 contain the length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		resource_length = (u16) (ACPI_GET8(aml) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 					 ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	return (resource_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)  * FUNCTION:    acpi_ut_get_resource_header_length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)  * PARAMETERS:  aml             - Pointer to the raw AML resource descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)  * RETURN:      Length of the AML header (depends on large/small descriptor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)  * DESCRIPTION: Get the length of the header for this resource.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)  ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) u8 acpi_ut_get_resource_header_length(void *aml)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	ACPI_FUNCTION_ENTRY();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	/* Examine the large/small bit in the resource header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	if (ACPI_GET8(aml) & ACPI_RESOURCE_NAME_LARGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		return (sizeof(struct aml_resource_large_header));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		return (sizeof(struct aml_resource_small_header));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)  * FUNCTION:    acpi_ut_get_descriptor_length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)  * PARAMETERS:  aml             - Pointer to the raw AML resource descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)  * RETURN:      Byte length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)  * DESCRIPTION: Get the total byte length of a raw AML descriptor, including the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)  *              length of the descriptor header and the length field itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)  *              Used to walk descriptor lists.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)  ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) u32 acpi_ut_get_descriptor_length(void *aml)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	ACPI_FUNCTION_ENTRY();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	 * Get the Resource Length (does not include header length) and add
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	 * the header length (depends on if this is a small or large resource)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	return (acpi_ut_get_resource_length(aml) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		acpi_ut_get_resource_header_length(aml));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)  * FUNCTION:    acpi_ut_get_resource_end_tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)  * PARAMETERS:  obj_desc        - The resource template buffer object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)  *              end_tag         - Where the pointer to the end_tag is returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)  * RETURN:      Status, pointer to the end tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)  * DESCRIPTION: Find the end_tag resource descriptor in an AML resource template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)  *              Note: allows a buffer length of zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)  ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) acpi_ut_get_resource_end_tag(union acpi_operand_object *obj_desc, u8 **end_tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	ACPI_FUNCTION_TRACE(ut_get_resource_end_tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	/* Allow a buffer length of zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	if (!obj_desc->buffer.length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		*end_tag = obj_desc->buffer.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 		return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	/* Validate the template and get a pointer to the end_tag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	status = acpi_ut_walk_aml_resources(NULL, obj_desc->buffer.pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 					    obj_desc->buffer.length, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 					    (void **)end_tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) }