Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /****************************************************************************** |
| 3 | * |
| 4 | * Module Name: exnames - interpreter/scanner name load/execute |
| 5 | * |
Bob Moore | 4441e55 | 2021-01-15 10:48:25 -0800 | [diff] [blame] | 6 | * Copyright (C) 2000 - 2021, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 8 | *****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 11 | #include "accommon.h" |
| 12 | #include "acinterp.h" |
| 13 | #include "amlcode.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
| 15 | #define _COMPONENT ACPI_EXECUTER |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 16 | ACPI_MODULE_NAME("exnames") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 18 | /* Local prototypes */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 19 | static char *acpi_ex_allocate_name_string(u32 prefix_count, u32 num_name_segs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Lv Zheng | 1f86e8c | 2012-10-31 02:25:45 +0000 | [diff] [blame] | 21 | static acpi_status acpi_ex_name_segment(u8 **in_aml_address, char *name_string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | /******************************************************************************* |
| 24 | * |
| 25 | * FUNCTION: acpi_ex_allocate_name_string |
| 26 | * |
| 27 | * PARAMETERS: prefix_count - Count of parent levels. Special cases: |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 28 | * (-1)==root, 0==none |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | * num_name_segs - count of 4-character name segments |
| 30 | * |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 31 | * RETURN: A pointer to the allocated string segment. This segment must |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | * be deleted by the caller. |
| 33 | * |
| 34 | * DESCRIPTION: Allocate a buffer for a name string. Ensure allocated name |
| 35 | * string is long enough, and set up prefix if any. |
| 36 | * |
| 37 | ******************************************************************************/ |
| 38 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 39 | static char *acpi_ex_allocate_name_string(u32 prefix_count, u32 num_name_segs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 41 | char *temp_ptr; |
| 42 | char *name_string; |
| 43 | u32 size_needed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 45 | ACPI_FUNCTION_TRACE(ex_allocate_name_string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | /* |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 48 | * Allow room for all \ and ^ prefixes, all segments and a multi_name_prefix. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | * Also, one byte for the null terminator. |
| 50 | * This may actually be somewhat longer than needed. |
| 51 | */ |
| 52 | if (prefix_count == ACPI_UINT32_MAX) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | /* Special case for root */ |
| 55 | |
Bob Moore | 3278675 | 2019-04-08 13:42:25 -0700 | [diff] [blame] | 56 | size_needed = 1 + (ACPI_NAMESEG_SIZE * num_name_segs) + 2 + 1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 57 | } else { |
| 58 | size_needed = |
Bob Moore | 3278675 | 2019-04-08 13:42:25 -0700 | [diff] [blame] | 59 | prefix_count + (ACPI_NAMESEG_SIZE * num_name_segs) + 2 + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /* |
| 63 | * Allocate a buffer for the name. |
| 64 | * This buffer must be deleted by the caller! |
| 65 | */ |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 66 | name_string = ACPI_ALLOCATE(size_needed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | if (!name_string) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 68 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 69 | "Could not allocate size %u", size_needed)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 70 | return_PTR(NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | temp_ptr = name_string; |
| 74 | |
| 75 | /* Set up Root or Parent prefixes if needed */ |
| 76 | |
| 77 | if (prefix_count == ACPI_UINT32_MAX) { |
| 78 | *temp_ptr++ = AML_ROOT_PREFIX; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 79 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | while (prefix_count--) { |
| 81 | *temp_ptr++ = AML_PARENT_PREFIX; |
| 82 | } |
| 83 | } |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | /* Set up Dual or Multi prefixes if needed */ |
| 86 | |
| 87 | if (num_name_segs > 2) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | /* Set up multi prefixes */ |
| 90 | |
Bob Moore | 9ff5a21a | 2017-04-26 16:18:40 +0800 | [diff] [blame] | 91 | *temp_ptr++ = AML_MULTI_NAME_PREFIX; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 92 | *temp_ptr++ = (char)num_name_segs; |
| 93 | } else if (2 == num_name_segs) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | /* Set up dual prefixes */ |
| 96 | |
| 97 | *temp_ptr++ = AML_DUAL_NAME_PREFIX; |
| 98 | } |
| 99 | |
| 100 | /* |
| 101 | * Terminate string following prefixes. acpi_ex_name_segment() will |
| 102 | * append the segment(s) |
| 103 | */ |
| 104 | *temp_ptr = 0; |
| 105 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 106 | return_PTR(name_string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /******************************************************************************* |
| 110 | * |
| 111 | * FUNCTION: acpi_ex_name_segment |
| 112 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 113 | * PARAMETERS: in_aml_address - Pointer to the name in the AML code |
| 114 | * name_string - Where to return the name. The name is appended |
| 115 | * to any existing string to form a namepath |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | * |
| 117 | * RETURN: Status |
| 118 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 119 | * DESCRIPTION: Extract an ACPI name (4 bytes) from the AML byte stream |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | * |
| 121 | ******************************************************************************/ |
| 122 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 123 | static acpi_status acpi_ex_name_segment(u8 ** in_aml_address, char *name_string) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 125 | char *aml_address = (void *)*in_aml_address; |
| 126 | acpi_status status = AE_OK; |
| 127 | u32 index; |
| 128 | char char_buf[5]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 130 | ACPI_FUNCTION_TRACE(ex_name_segment); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
| 132 | /* |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 133 | * If first character is a digit, then we know that we aren't looking |
| 134 | * at a valid name segment |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | */ |
| 136 | char_buf[0] = *aml_address; |
| 137 | |
| 138 | if ('0' <= char_buf[0] && char_buf[0] <= '9') { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 139 | ACPI_ERROR((AE_INFO, "Invalid leading digit: %c", char_buf[0])); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 140 | return_ACPI_STATUS(AE_CTRL_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Lv Zheng | 1f86e8c | 2012-10-31 02:25:45 +0000 | [diff] [blame] | 143 | for (index = 0; |
Bob Moore | 3278675 | 2019-04-08 13:42:25 -0700 | [diff] [blame] | 144 | (index < ACPI_NAMESEG_SIZE) |
Bob Moore | 6a0df32 | 2016-05-05 13:00:36 +0800 | [diff] [blame] | 145 | && (acpi_ut_valid_name_char(*aml_address, 0)); index++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | char_buf[index] = *aml_address++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | /* Valid name segment */ |
| 150 | |
| 151 | if (index == 4) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | /* Found 4 valid characters */ |
| 154 | |
| 155 | char_buf[4] = '\0'; |
| 156 | |
| 157 | if (name_string) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 158 | ACPI_DEBUG_PRINT((ACPI_DB_NAMES, |
Bob Moore | 1ef6323 | 2018-02-15 13:09:28 -0800 | [diff] [blame] | 159 | "Appending NameSeg %s\n", char_buf)); |
| 160 | strcat(name_string, char_buf); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 161 | } else { |
| 162 | ACPI_DEBUG_PRINT((ACPI_DB_NAMES, |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 163 | "No Name string - %s\n", char_buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 165 | } else if (index == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | /* |
| 167 | * First character was not a valid name character, |
| 168 | * so we are looking at something other than a name. |
| 169 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 170 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 171 | "Leading character is not alpha: %02Xh (not a name)\n", |
| 172 | char_buf[0])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | status = AE_CTRL_PENDING; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 174 | } else { |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 175 | /* |
| 176 | * Segment started with one or more valid characters, but fewer than |
| 177 | * the required 4 |
| 178 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | status = AE_AML_BAD_NAME; |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 180 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 181 | "Bad character 0x%02x in name, at %p", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 182 | *aml_address, aml_address)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 185 | *in_aml_address = ACPI_CAST_PTR(u8, aml_address); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 186 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | /******************************************************************************* |
| 190 | * |
| 191 | * FUNCTION: acpi_ex_get_name_string |
| 192 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 193 | * PARAMETERS: data_type - Object type to be associated with this |
| 194 | * name |
| 195 | * in_aml_address - Pointer to the namestring in the AML code |
| 196 | * out_name_string - Where the namestring is returned |
| 197 | * out_name_length - Length of the returned string |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 199 | * RETURN: Status, namestring and length |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 201 | * DESCRIPTION: Extract a full namepath from the AML byte stream, |
| 202 | * including any prefixes. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | * |
| 204 | ******************************************************************************/ |
| 205 | |
| 206 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 207 | acpi_ex_get_name_string(acpi_object_type data_type, |
| 208 | u8 * in_aml_address, |
| 209 | char **out_name_string, u32 * out_name_length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 211 | acpi_status status = AE_OK; |
| 212 | u8 *aml_address = in_aml_address; |
| 213 | char *name_string = NULL; |
| 214 | u32 num_segments; |
| 215 | u32 prefix_count = 0; |
| 216 | u8 has_prefix = FALSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 218 | ACPI_FUNCTION_TRACE_PTR(ex_get_name_string, aml_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 220 | if (ACPI_TYPE_LOCAL_REGION_FIELD == data_type || |
| 221 | ACPI_TYPE_LOCAL_BANK_FIELD == data_type || |
| 222 | ACPI_TYPE_LOCAL_INDEX_FIELD == data_type) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 223 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | /* Disallow prefixes for types associated with field_unit names */ |
| 225 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 226 | name_string = acpi_ex_allocate_name_string(0, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | if (!name_string) { |
| 228 | status = AE_NO_MEMORY; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 229 | } else { |
| 230 | status = |
| 231 | acpi_ex_name_segment(&aml_address, name_string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 233 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | /* |
| 235 | * data_type is not a field name. |
| 236 | * Examine first character of name for root or parent prefix operators |
| 237 | */ |
| 238 | switch (*aml_address) { |
| 239 | case AML_ROOT_PREFIX: |
| 240 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 241 | ACPI_DEBUG_PRINT((ACPI_DB_LOAD, |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 242 | "RootPrefix(\\) at %p\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 243 | aml_address)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
| 245 | /* |
| 246 | * Remember that we have a root_prefix -- |
| 247 | * see comment in acpi_ex_allocate_name_string() |
| 248 | */ |
| 249 | aml_address++; |
| 250 | prefix_count = ACPI_UINT32_MAX; |
| 251 | has_prefix = TRUE; |
| 252 | break; |
| 253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | case AML_PARENT_PREFIX: |
| 255 | |
| 256 | /* Increment past possibly multiple parent prefixes */ |
| 257 | |
| 258 | do { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 259 | ACPI_DEBUG_PRINT((ACPI_DB_LOAD, |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 260 | "ParentPrefix (^) at %p\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 261 | aml_address)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
| 263 | aml_address++; |
| 264 | prefix_count++; |
| 265 | |
| 266 | } while (*aml_address == AML_PARENT_PREFIX); |
| 267 | |
| 268 | has_prefix = TRUE; |
| 269 | break; |
| 270 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | default: |
| 272 | |
| 273 | /* Not a prefix character */ |
| 274 | |
| 275 | break; |
| 276 | } |
| 277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | /* Examine first character of name for name segment prefix operator */ |
| 279 | |
| 280 | switch (*aml_address) { |
| 281 | case AML_DUAL_NAME_PREFIX: |
| 282 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 283 | ACPI_DEBUG_PRINT((ACPI_DB_LOAD, |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 284 | "DualNamePrefix at %p\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 285 | aml_address)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
| 287 | aml_address++; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 288 | name_string = |
| 289 | acpi_ex_allocate_name_string(prefix_count, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | if (!name_string) { |
| 291 | status = AE_NO_MEMORY; |
| 292 | break; |
| 293 | } |
| 294 | |
| 295 | /* Indicate that we processed a prefix */ |
| 296 | |
| 297 | has_prefix = TRUE; |
| 298 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 299 | status = |
| 300 | acpi_ex_name_segment(&aml_address, name_string); |
| 301 | if (ACPI_SUCCESS(status)) { |
| 302 | status = |
| 303 | acpi_ex_name_segment(&aml_address, |
| 304 | name_string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | } |
| 306 | break; |
| 307 | |
Bob Moore | 9ff5a21a | 2017-04-26 16:18:40 +0800 | [diff] [blame] | 308 | case AML_MULTI_NAME_PREFIX: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 310 | ACPI_DEBUG_PRINT((ACPI_DB_LOAD, |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 311 | "MultiNamePrefix at %p\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 312 | aml_address)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
| 314 | /* Fetch count of segments remaining in name path */ |
| 315 | |
| 316 | aml_address++; |
| 317 | num_segments = *aml_address; |
| 318 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 319 | name_string = |
| 320 | acpi_ex_allocate_name_string(prefix_count, |
| 321 | num_segments); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | if (!name_string) { |
| 323 | status = AE_NO_MEMORY; |
| 324 | break; |
| 325 | } |
| 326 | |
| 327 | /* Indicate that we processed a prefix */ |
| 328 | |
| 329 | aml_address++; |
| 330 | has_prefix = TRUE; |
| 331 | |
| 332 | while (num_segments && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 333 | (status = |
| 334 | acpi_ex_name_segment(&aml_address, |
| 335 | name_string)) == AE_OK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | num_segments--; |
| 337 | } |
| 338 | |
| 339 | break; |
| 340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | case 0: |
| 342 | |
| 343 | /* null_name valid as of 8-12-98 ASL/AML Grammar Update */ |
| 344 | |
| 345 | if (prefix_count == ACPI_UINT32_MAX) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 346 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 347 | "NameSeg is \"\\\" followed by NULL\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | /* Consume the NULL byte */ |
| 351 | |
| 352 | aml_address++; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 353 | name_string = |
| 354 | acpi_ex_allocate_name_string(prefix_count, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | if (!name_string) { |
| 356 | status = AE_NO_MEMORY; |
| 357 | break; |
| 358 | } |
| 359 | |
| 360 | break; |
| 361 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | default: |
| 363 | |
| 364 | /* Name segment string */ |
| 365 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 366 | name_string = |
| 367 | acpi_ex_allocate_name_string(prefix_count, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | if (!name_string) { |
| 369 | status = AE_NO_MEMORY; |
| 370 | break; |
| 371 | } |
| 372 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 373 | status = |
| 374 | acpi_ex_name_segment(&aml_address, name_string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | break; |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | if (AE_CTRL_PENDING == status && has_prefix) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | /* Ran out of segments after processing a prefix */ |
| 382 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 383 | ACPI_ERROR((AE_INFO, "Malformed Name at %p", name_string)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | status = AE_AML_BAD_NAME; |
| 385 | } |
| 386 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 387 | if (ACPI_FAILURE(status)) { |
Robert Moore | 88ac00f | 2005-05-26 00:00:00 -0400 | [diff] [blame] | 388 | if (name_string) { |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 389 | ACPI_FREE(name_string); |
Robert Moore | 88ac00f | 2005-05-26 00:00:00 -0400 | [diff] [blame] | 390 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 391 | return_ACPI_STATUS(status); |
Robert Moore | 88ac00f | 2005-05-26 00:00:00 -0400 | [diff] [blame] | 392 | } |
| 393 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | *out_name_string = name_string; |
| 395 | *out_name_length = (u32) (aml_address - in_aml_address); |
| 396 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 397 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | } |