| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 |  | 
 | 2 | /****************************************************************************** | 
 | 3 |  * | 
 | 4 |  * Module Name: exnames - interpreter/scanner name load/execute | 
 | 5 |  * | 
 | 6 |  *****************************************************************************/ | 
 | 7 |  | 
 | 8 | /* | 
| Len Brown | 75a44ce | 2008-04-23 23:00:13 -0400 | [diff] [blame] | 9 |  * Copyright (C) 2000 - 2008, Intel Corp. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 |  * All rights reserved. | 
 | 11 |  * | 
 | 12 |  * Redistribution and use in source and binary forms, with or without | 
 | 13 |  * modification, are permitted provided that the following conditions | 
 | 14 |  * are met: | 
 | 15 |  * 1. Redistributions of source code must retain the above copyright | 
 | 16 |  *    notice, this list of conditions, and the following disclaimer, | 
 | 17 |  *    without modification. | 
 | 18 |  * 2. Redistributions in binary form must reproduce at minimum a disclaimer | 
 | 19 |  *    substantially similar to the "NO WARRANTY" disclaimer below | 
 | 20 |  *    ("Disclaimer") and any redistribution must be conditioned upon | 
 | 21 |  *    including a substantially similar Disclaimer requirement for further | 
 | 22 |  *    binary redistribution. | 
 | 23 |  * 3. Neither the names of the above-listed copyright holders nor the names | 
 | 24 |  *    of any contributors may be used to endorse or promote products derived | 
 | 25 |  *    from this software without specific prior written permission. | 
 | 26 |  * | 
 | 27 |  * Alternatively, this software may be distributed under the terms of the | 
 | 28 |  * GNU General Public License ("GPL") version 2 as published by the Free | 
 | 29 |  * Software Foundation. | 
 | 30 |  * | 
 | 31 |  * NO WARRANTY | 
 | 32 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
 | 33 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
 | 34 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | 
 | 35 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 
 | 36 |  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
 | 37 |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 
 | 38 |  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 
 | 39 |  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | 
 | 40 |  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | 
 | 41 |  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 
 | 42 |  * POSSIBILITY OF SUCH DAMAGES. | 
 | 43 |  */ | 
 | 44 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <acpi/acpi.h> | 
| Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 46 | #include "accommon.h" | 
 | 47 | #include "acinterp.h" | 
 | 48 | #include "amlcode.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 |  | 
 | 50 | #define _COMPONENT          ACPI_EXECUTER | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 51 | ACPI_MODULE_NAME("exnames") | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 53 | /* Local prototypes */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 54 | 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] | 55 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 56 | static acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 57 | acpi_ex_name_segment(u8 ** in_aml_address, char *name_string); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 |  | 
 | 59 | /******************************************************************************* | 
 | 60 |  * | 
 | 61 |  * FUNCTION:    acpi_ex_allocate_name_string | 
 | 62 |  * | 
 | 63 |  * PARAMETERS:  prefix_count        - Count of parent levels. Special cases: | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 64 |  *                                    (-1)==root,  0==none | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 |  *              num_name_segs       - count of 4-character name segments | 
 | 66 |  * | 
 | 67 |  * RETURN:      A pointer to the allocated string segment.  This segment must | 
 | 68 |  *              be deleted by the caller. | 
 | 69 |  * | 
 | 70 |  * DESCRIPTION: Allocate a buffer for a name string. Ensure allocated name | 
 | 71 |  *              string is long enough, and set up prefix if any. | 
 | 72 |  * | 
 | 73 |  ******************************************************************************/ | 
 | 74 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 75 | 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] | 76 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 77 | 	char *temp_ptr; | 
 | 78 | 	char *name_string; | 
 | 79 | 	u32 size_needed; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 81 | 	ACPI_FUNCTION_TRACE(ex_allocate_name_string); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 |  | 
 | 83 | 	/* | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 84 | 	 * 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] | 85 | 	 * Also, one byte for the null terminator. | 
 | 86 | 	 * This may actually be somewhat longer than needed. | 
 | 87 | 	 */ | 
 | 88 | 	if (prefix_count == ACPI_UINT32_MAX) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 89 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | 		/* Special case for root */ | 
 | 91 |  | 
 | 92 | 		size_needed = 1 + (ACPI_NAME_SIZE * num_name_segs) + 2 + 1; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 93 | 	} else { | 
 | 94 | 		size_needed = | 
 | 95 | 		    prefix_count + (ACPI_NAME_SIZE * num_name_segs) + 2 + 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | 	} | 
 | 97 |  | 
 | 98 | 	/* | 
 | 99 | 	 * Allocate a buffer for the name. | 
 | 100 | 	 * This buffer must be deleted by the caller! | 
 | 101 | 	 */ | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 102 | 	name_string = ACPI_ALLOCATE(size_needed); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | 	if (!name_string) { | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 104 | 		ACPI_ERROR((AE_INFO, | 
 | 105 | 			    "Could not allocate size %d", size_needed)); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 106 | 		return_PTR(NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | 	} | 
 | 108 |  | 
 | 109 | 	temp_ptr = name_string; | 
 | 110 |  | 
 | 111 | 	/* Set up Root or Parent prefixes if needed */ | 
 | 112 |  | 
 | 113 | 	if (prefix_count == ACPI_UINT32_MAX) { | 
 | 114 | 		*temp_ptr++ = AML_ROOT_PREFIX; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 115 | 	} else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | 		while (prefix_count--) { | 
 | 117 | 			*temp_ptr++ = AML_PARENT_PREFIX; | 
 | 118 | 		} | 
 | 119 | 	} | 
 | 120 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | 	/* Set up Dual or Multi prefixes if needed */ | 
 | 122 |  | 
 | 123 | 	if (num_name_segs > 2) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 124 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | 		/* Set up multi prefixes   */ | 
 | 126 |  | 
 | 127 | 		*temp_ptr++ = AML_MULTI_NAME_PREFIX_OP; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 128 | 		*temp_ptr++ = (char)num_name_segs; | 
 | 129 | 	} else if (2 == num_name_segs) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 130 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | 		/* Set up dual prefixes */ | 
 | 132 |  | 
 | 133 | 		*temp_ptr++ = AML_DUAL_NAME_PREFIX; | 
 | 134 | 	} | 
 | 135 |  | 
 | 136 | 	/* | 
 | 137 | 	 * Terminate string following prefixes. acpi_ex_name_segment() will | 
 | 138 | 	 * append the segment(s) | 
 | 139 | 	 */ | 
 | 140 | 	*temp_ptr = 0; | 
 | 141 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 142 | 	return_PTR(name_string); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } | 
 | 144 |  | 
 | 145 | /******************************************************************************* | 
 | 146 |  * | 
 | 147 |  * FUNCTION:    acpi_ex_name_segment | 
 | 148 |  * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 149 |  * PARAMETERS:  in_aml_address  - Pointer to the name in the AML code | 
 | 150 |  *              name_string     - Where to return the name. The name is appended | 
 | 151 |  *                                to any existing string to form a namepath | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 |  * | 
 | 153 |  * RETURN:      Status | 
 | 154 |  * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 155 |  * DESCRIPTION: Extract an ACPI name (4 bytes) from the AML byte stream | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 |  * | 
 | 157 |  ******************************************************************************/ | 
 | 158 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 159 | 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] | 160 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 161 | 	char *aml_address = (void *)*in_aml_address; | 
 | 162 | 	acpi_status status = AE_OK; | 
 | 163 | 	u32 index; | 
 | 164 | 	char char_buf[5]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 166 | 	ACPI_FUNCTION_TRACE(ex_name_segment); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 |  | 
 | 168 | 	/* | 
 | 169 | 	 * If first character is a digit, then we know that we aren't looking at a | 
 | 170 | 	 * valid name segment | 
 | 171 | 	 */ | 
 | 172 | 	char_buf[0] = *aml_address; | 
 | 173 |  | 
 | 174 | 	if ('0' <= char_buf[0] && char_buf[0] <= '9') { | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 175 | 		ACPI_ERROR((AE_INFO, "Invalid leading digit: %c", char_buf[0])); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 176 | 		return_ACPI_STATUS(AE_CTRL_PENDING); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | 	} | 
 | 178 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 179 | 	ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "Bytes from stream:\n")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 |  | 
| Len Brown | fd35094 | 2007-05-09 23:34:35 -0400 | [diff] [blame] | 181 | 	for (index = 0; (index < ACPI_NAME_SIZE) | 
| Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 182 | 	     && (acpi_ut_valid_acpi_char(*aml_address, 0)); index++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | 		char_buf[index] = *aml_address++; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 184 | 		ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "%c\n", char_buf[index])); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | 	} | 
 | 186 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | 	/* Valid name segment  */ | 
 | 188 |  | 
 | 189 | 	if (index == 4) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 190 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | 		/* Found 4 valid characters */ | 
 | 192 |  | 
 | 193 | 		char_buf[4] = '\0'; | 
 | 194 |  | 
 | 195 | 		if (name_string) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 196 | 			ACPI_STRCAT(name_string, char_buf); | 
 | 197 | 			ACPI_DEBUG_PRINT((ACPI_DB_NAMES, | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 198 | 					  "Appended to - %s\n", name_string)); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 199 | 		} else { | 
 | 200 | 			ACPI_DEBUG_PRINT((ACPI_DB_NAMES, | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 201 | 					  "No Name string - %s\n", char_buf)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | 		} | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 203 | 	} else if (index == 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | 		/* | 
 | 205 | 		 * First character was not a valid name character, | 
 | 206 | 		 * so we are looking at something other than a name. | 
 | 207 | 		 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 208 | 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
 | 209 | 				  "Leading character is not alpha: %02Xh (not a name)\n", | 
 | 210 | 				  char_buf[0])); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | 		status = AE_CTRL_PENDING; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 212 | 	} else { | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 213 | 		/* | 
 | 214 | 		 * Segment started with one or more valid characters, but fewer than | 
 | 215 | 		 * the required 4 | 
 | 216 | 		 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | 		status = AE_AML_BAD_NAME; | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 218 | 		ACPI_ERROR((AE_INFO, | 
 | 219 | 			    "Bad character %02x in name, at %p", | 
 | 220 | 			    *aml_address, aml_address)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | 	} | 
 | 222 |  | 
| Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 223 | 	*in_aml_address = ACPI_CAST_PTR(u8, aml_address); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 224 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | } | 
 | 226 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | /******************************************************************************* | 
 | 228 |  * | 
 | 229 |  * FUNCTION:    acpi_ex_get_name_string | 
 | 230 |  * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 231 |  * PARAMETERS:  data_type           - Object type to be associated with this | 
 | 232 |  *                                    name | 
 | 233 |  *              in_aml_address      - Pointer to the namestring in the AML code | 
 | 234 |  *              out_name_string     - Where the namestring is returned | 
 | 235 |  *              out_name_length     - Length of the returned string | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 |  * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 237 |  * RETURN:      Status, namestring and length | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 |  * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 239 |  * DESCRIPTION: Extract a full namepath from the AML byte stream, | 
 | 240 |  *              including any prefixes. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 |  * | 
 | 242 |  ******************************************************************************/ | 
 | 243 |  | 
 | 244 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 245 | acpi_ex_get_name_string(acpi_object_type data_type, | 
 | 246 | 			u8 * in_aml_address, | 
 | 247 | 			char **out_name_string, u32 * out_name_length) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 249 | 	acpi_status status = AE_OK; | 
 | 250 | 	u8 *aml_address = in_aml_address; | 
 | 251 | 	char *name_string = NULL; | 
 | 252 | 	u32 num_segments; | 
 | 253 | 	u32 prefix_count = 0; | 
 | 254 | 	u8 has_prefix = FALSE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 256 | 	ACPI_FUNCTION_TRACE_PTR(ex_get_name_string, aml_address); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 258 | 	if (ACPI_TYPE_LOCAL_REGION_FIELD == data_type || | 
 | 259 | 	    ACPI_TYPE_LOCAL_BANK_FIELD == data_type || | 
 | 260 | 	    ACPI_TYPE_LOCAL_INDEX_FIELD == data_type) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 261 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | 		/* Disallow prefixes for types associated with field_unit names */ | 
 | 263 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 264 | 		name_string = acpi_ex_allocate_name_string(0, 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | 		if (!name_string) { | 
 | 266 | 			status = AE_NO_MEMORY; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 267 | 		} else { | 
 | 268 | 			status = | 
 | 269 | 			    acpi_ex_name_segment(&aml_address, name_string); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | 		} | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 271 | 	} else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | 		/* | 
 | 273 | 		 * data_type is not a field name. | 
 | 274 | 		 * Examine first character of name for root or parent prefix operators | 
 | 275 | 		 */ | 
 | 276 | 		switch (*aml_address) { | 
 | 277 | 		case AML_ROOT_PREFIX: | 
 | 278 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 279 | 			ACPI_DEBUG_PRINT((ACPI_DB_LOAD, | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 280 | 					  "RootPrefix(\\) at %p\n", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 281 | 					  aml_address)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 |  | 
 | 283 | 			/* | 
 | 284 | 			 * Remember that we have a root_prefix -- | 
 | 285 | 			 * see comment in acpi_ex_allocate_name_string() | 
 | 286 | 			 */ | 
 | 287 | 			aml_address++; | 
 | 288 | 			prefix_count = ACPI_UINT32_MAX; | 
 | 289 | 			has_prefix = TRUE; | 
 | 290 | 			break; | 
 | 291 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | 		case AML_PARENT_PREFIX: | 
 | 293 |  | 
 | 294 | 			/* Increment past possibly multiple parent prefixes */ | 
 | 295 |  | 
 | 296 | 			do { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 297 | 				ACPI_DEBUG_PRINT((ACPI_DB_LOAD, | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 298 | 						  "ParentPrefix (^) at %p\n", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 299 | 						  aml_address)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 |  | 
 | 301 | 				aml_address++; | 
 | 302 | 				prefix_count++; | 
 | 303 |  | 
 | 304 | 			} while (*aml_address == AML_PARENT_PREFIX); | 
 | 305 |  | 
 | 306 | 			has_prefix = TRUE; | 
 | 307 | 			break; | 
 | 308 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | 		default: | 
 | 310 |  | 
 | 311 | 			/* Not a prefix character */ | 
 | 312 |  | 
 | 313 | 			break; | 
 | 314 | 		} | 
 | 315 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | 		/* Examine first character of name for name segment prefix operator */ | 
 | 317 |  | 
 | 318 | 		switch (*aml_address) { | 
 | 319 | 		case AML_DUAL_NAME_PREFIX: | 
 | 320 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 321 | 			ACPI_DEBUG_PRINT((ACPI_DB_LOAD, | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 322 | 					  "DualNamePrefix at %p\n", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 323 | 					  aml_address)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 |  | 
 | 325 | 			aml_address++; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 326 | 			name_string = | 
 | 327 | 			    acpi_ex_allocate_name_string(prefix_count, 2); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | 			if (!name_string) { | 
 | 329 | 				status = AE_NO_MEMORY; | 
 | 330 | 				break; | 
 | 331 | 			} | 
 | 332 |  | 
 | 333 | 			/* Indicate that we processed a prefix */ | 
 | 334 |  | 
 | 335 | 			has_prefix = TRUE; | 
 | 336 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 337 | 			status = | 
 | 338 | 			    acpi_ex_name_segment(&aml_address, name_string); | 
 | 339 | 			if (ACPI_SUCCESS(status)) { | 
 | 340 | 				status = | 
 | 341 | 				    acpi_ex_name_segment(&aml_address, | 
 | 342 | 							 name_string); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | 			} | 
 | 344 | 			break; | 
 | 345 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | 		case AML_MULTI_NAME_PREFIX_OP: | 
 | 347 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 348 | 			ACPI_DEBUG_PRINT((ACPI_DB_LOAD, | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 349 | 					  "MultiNamePrefix at %p\n", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 350 | 					  aml_address)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 |  | 
 | 352 | 			/* Fetch count of segments remaining in name path */ | 
 | 353 |  | 
 | 354 | 			aml_address++; | 
 | 355 | 			num_segments = *aml_address; | 
 | 356 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 357 | 			name_string = | 
 | 358 | 			    acpi_ex_allocate_name_string(prefix_count, | 
 | 359 | 							 num_segments); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | 			if (!name_string) { | 
 | 361 | 				status = AE_NO_MEMORY; | 
 | 362 | 				break; | 
 | 363 | 			} | 
 | 364 |  | 
 | 365 | 			/* Indicate that we processed a prefix */ | 
 | 366 |  | 
 | 367 | 			aml_address++; | 
 | 368 | 			has_prefix = TRUE; | 
 | 369 |  | 
 | 370 | 			while (num_segments && | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 371 | 			       (status = | 
 | 372 | 				acpi_ex_name_segment(&aml_address, | 
 | 373 | 						     name_string)) == AE_OK) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | 				num_segments--; | 
 | 375 | 			} | 
 | 376 |  | 
 | 377 | 			break; | 
 | 378 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | 		case 0: | 
 | 380 |  | 
 | 381 | 			/* null_name valid as of 8-12-98 ASL/AML Grammar Update */ | 
 | 382 |  | 
 | 383 | 			if (prefix_count == ACPI_UINT32_MAX) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 384 | 				ACPI_DEBUG_PRINT((ACPI_DB_EXEC, | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 385 | 						  "NameSeg is \"\\\" followed by NULL\n")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | 			} | 
 | 387 |  | 
 | 388 | 			/* Consume the NULL byte */ | 
 | 389 |  | 
 | 390 | 			aml_address++; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 391 | 			name_string = | 
 | 392 | 			    acpi_ex_allocate_name_string(prefix_count, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | 			if (!name_string) { | 
 | 394 | 				status = AE_NO_MEMORY; | 
 | 395 | 				break; | 
 | 396 | 			} | 
 | 397 |  | 
 | 398 | 			break; | 
 | 399 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | 		default: | 
 | 401 |  | 
 | 402 | 			/* Name segment string */ | 
 | 403 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 404 | 			name_string = | 
 | 405 | 			    acpi_ex_allocate_name_string(prefix_count, 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | 			if (!name_string) { | 
 | 407 | 				status = AE_NO_MEMORY; | 
 | 408 | 				break; | 
 | 409 | 			} | 
 | 410 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 411 | 			status = | 
 | 412 | 			    acpi_ex_name_segment(&aml_address, name_string); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | 			break; | 
 | 414 | 		} | 
 | 415 | 	} | 
 | 416 |  | 
 | 417 | 	if (AE_CTRL_PENDING == status && has_prefix) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 418 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | 		/* Ran out of segments after processing a prefix */ | 
 | 420 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 421 | 		ACPI_ERROR((AE_INFO, "Malformed Name at %p", name_string)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | 		status = AE_AML_BAD_NAME; | 
 | 423 | 	} | 
 | 424 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 425 | 	if (ACPI_FAILURE(status)) { | 
| Robert Moore | 88ac00f | 2005-05-26 00:00:00 -0400 | [diff] [blame] | 426 | 		if (name_string) { | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 427 | 			ACPI_FREE(name_string); | 
| Robert Moore | 88ac00f | 2005-05-26 00:00:00 -0400 | [diff] [blame] | 428 | 		} | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 429 | 		return_ACPI_STATUS(status); | 
| Robert Moore | 88ac00f | 2005-05-26 00:00:00 -0400 | [diff] [blame] | 430 | 	} | 
 | 431 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | 	*out_name_string = name_string; | 
 | 433 | 	*out_name_length = (u32) (aml_address - in_aml_address); | 
 | 434 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 435 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | } |