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