aslopt.c revision 1.1.1.2.2.2 1 1.1.1.2.2.2 bouyer /******************************************************************************
2 1.1.1.2.2.2 bouyer *
3 1.1.1.2.2.2 bouyer * Module Name: aslopt- Compiler optimizations
4 1.1.1.2.2.2 bouyer *
5 1.1.1.2.2.2 bouyer *****************************************************************************/
6 1.1.1.2.2.2 bouyer
7 1.1.1.2.2.2 bouyer /*
8 1.1.1.2.2.2 bouyer * Copyright (C) 2000 - 2011, Intel Corp.
9 1.1.1.2.2.2 bouyer * All rights reserved.
10 1.1.1.2.2.2 bouyer *
11 1.1.1.2.2.2 bouyer * Redistribution and use in source and binary forms, with or without
12 1.1.1.2.2.2 bouyer * modification, are permitted provided that the following conditions
13 1.1.1.2.2.2 bouyer * are met:
14 1.1.1.2.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2.2.2 bouyer * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2.2.2 bouyer * without modification.
17 1.1.1.2.2.2 bouyer * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2.2.2 bouyer * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2.2.2 bouyer * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2.2.2 bouyer * including a substantially similar Disclaimer requirement for further
21 1.1.1.2.2.2 bouyer * binary redistribution.
22 1.1.1.2.2.2 bouyer * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2.2.2 bouyer * of any contributors may be used to endorse or promote products derived
24 1.1.1.2.2.2 bouyer * from this software without specific prior written permission.
25 1.1.1.2.2.2 bouyer *
26 1.1.1.2.2.2 bouyer * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2.2.2 bouyer * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2.2.2 bouyer * Software Foundation.
29 1.1.1.2.2.2 bouyer *
30 1.1.1.2.2.2 bouyer * NO WARRANTY
31 1.1.1.2.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2.2.2 bouyer * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2.2.2 bouyer * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2.2.2 bouyer * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2.2.2 bouyer * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2.2.2 bouyer * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2.2.2 bouyer * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2.2.2 bouyer */
43 1.1.1.2.2.2 bouyer
44 1.1.1.2.2.2 bouyer
45 1.1.1.2.2.2 bouyer #include "aslcompiler.h"
46 1.1.1.2.2.2 bouyer #include "aslcompiler.y.h"
47 1.1.1.2.2.2 bouyer
48 1.1.1.2.2.2 bouyer #include "acparser.h"
49 1.1.1.2.2.2 bouyer #include "amlcode.h"
50 1.1.1.2.2.2 bouyer #include "acnamesp.h"
51 1.1.1.2.2.2 bouyer
52 1.1.1.2.2.2 bouyer
53 1.1.1.2.2.2 bouyer #define _COMPONENT ACPI_COMPILER
54 1.1.1.2.2.2 bouyer ACPI_MODULE_NAME ("aslopt")
55 1.1.1.2.2.2 bouyer
56 1.1.1.2.2.2 bouyer
57 1.1.1.2.2.2 bouyer static UINT32 OptTotal = 0;
58 1.1.1.2.2.2 bouyer
59 1.1.1.2.2.2 bouyer /* Local prototypes */
60 1.1.1.2.2.2 bouyer
61 1.1.1.2.2.2 bouyer static ACPI_STATUS
62 1.1.1.2.2.2 bouyer OptSearchToRoot (
63 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op,
64 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState,
65 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *CurrentNode,
66 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *TargetNode,
67 1.1.1.2.2.2 bouyer ACPI_BUFFER *TargetPath,
68 1.1.1.2.2.2 bouyer char **NewPath);
69 1.1.1.2.2.2 bouyer
70 1.1.1.2.2.2 bouyer static ACPI_STATUS
71 1.1.1.2.2.2 bouyer OptBuildShortestPath (
72 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op,
73 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState,
74 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *CurrentNode,
75 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *TargetNode,
76 1.1.1.2.2.2 bouyer ACPI_BUFFER *CurrentPath,
77 1.1.1.2.2.2 bouyer ACPI_BUFFER *TargetPath,
78 1.1.1.2.2.2 bouyer ACPI_SIZE AmlNameStringLength,
79 1.1.1.2.2.2 bouyer UINT8 IsDeclaration,
80 1.1.1.2.2.2 bouyer char **ReturnNewPath);
81 1.1.1.2.2.2 bouyer
82 1.1.1.2.2.2 bouyer static ACPI_STATUS
83 1.1.1.2.2.2 bouyer OptOptimizeNameDeclaration (
84 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op,
85 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState,
86 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *CurrentNode,
87 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *TargetNode,
88 1.1.1.2.2.2 bouyer char *AmlNameString,
89 1.1.1.2.2.2 bouyer char **NewPath);
90 1.1.1.2.2.2 bouyer
91 1.1.1.2.2.2 bouyer
92 1.1.1.2.2.2 bouyer /*******************************************************************************
93 1.1.1.2.2.2 bouyer *
94 1.1.1.2.2.2 bouyer * FUNCTION: OptSearchToRoot
95 1.1.1.2.2.2 bouyer *
96 1.1.1.2.2.2 bouyer * PARAMETERS: Op - Current parser op
97 1.1.1.2.2.2 bouyer * WalkState - Current state
98 1.1.1.2.2.2 bouyer * CurrentNode - Where we are in the namespace
99 1.1.1.2.2.2 bouyer * TargetNode - Node to which we are referring
100 1.1.1.2.2.2 bouyer * TargetPath - External full path to the target node
101 1.1.1.2.2.2 bouyer * NewPath - Where the optimized path is returned
102 1.1.1.2.2.2 bouyer *
103 1.1.1.2.2.2 bouyer * RETURN: Status
104 1.1.1.2.2.2 bouyer *
105 1.1.1.2.2.2 bouyer * DESCRIPTION: Attempt to optimize a reference to a single 4-character ACPI
106 1.1.1.2.2.2 bouyer * name utilizing the search-to-root name resolution algorithm
107 1.1.1.2.2.2 bouyer * that is used by AML interpreters.
108 1.1.1.2.2.2 bouyer *
109 1.1.1.2.2.2 bouyer ******************************************************************************/
110 1.1.1.2.2.2 bouyer
111 1.1.1.2.2.2 bouyer static ACPI_STATUS
112 1.1.1.2.2.2 bouyer OptSearchToRoot (
113 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op,
114 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState,
115 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *CurrentNode,
116 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *TargetNode,
117 1.1.1.2.2.2 bouyer ACPI_BUFFER *TargetPath,
118 1.1.1.2.2.2 bouyer char **NewPath)
119 1.1.1.2.2.2 bouyer {
120 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *Node;
121 1.1.1.2.2.2 bouyer ACPI_GENERIC_STATE ScopeInfo;
122 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
123 1.1.1.2.2.2 bouyer char *Path;
124 1.1.1.2.2.2 bouyer
125 1.1.1.2.2.2 bouyer
126 1.1.1.2.2.2 bouyer ACPI_FUNCTION_NAME (OptSearchToRoot);
127 1.1.1.2.2.2 bouyer
128 1.1.1.2.2.2 bouyer
129 1.1.1.2.2.2 bouyer /*
130 1.1.1.2.2.2 bouyer * Check if search-to-root can be utilized. Use the last NameSeg of
131 1.1.1.2.2.2 bouyer * the NamePath and 1) See if can be found and 2) If found, make
132 1.1.1.2.2.2 bouyer * sure that it is the same node that we want. If there is another
133 1.1.1.2.2.2 bouyer * name in the search path before the one we want, the nodes will
134 1.1.1.2.2.2 bouyer * not match, and we cannot use this optimization.
135 1.1.1.2.2.2 bouyer */
136 1.1.1.2.2.2 bouyer Path = &(((char *) TargetPath->Pointer)[TargetPath->Length -
137 1.1.1.2.2.2 bouyer ACPI_NAME_SIZE]),
138 1.1.1.2.2.2 bouyer ScopeInfo.Scope.Node = CurrentNode;
139 1.1.1.2.2.2 bouyer
140 1.1.1.2.2.2 bouyer /* Lookup the NameSeg using SEARCH_PARENT (search-to-root) */
141 1.1.1.2.2.2 bouyer
142 1.1.1.2.2.2 bouyer Status = AcpiNsLookup (&ScopeInfo, Path, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
143 1.1.1.2.2.2 bouyer ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
144 1.1.1.2.2.2 bouyer WalkState, &(Node));
145 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
146 1.1.1.2.2.2 bouyer {
147 1.1.1.2.2.2 bouyer return (Status);
148 1.1.1.2.2.2 bouyer }
149 1.1.1.2.2.2 bouyer
150 1.1.1.2.2.2 bouyer /*
151 1.1.1.2.2.2 bouyer * We found the name, but we must check to make sure that the node
152 1.1.1.2.2.2 bouyer * matches. Otherwise, there is another identical name in the search
153 1.1.1.2.2.2 bouyer * path that precludes the use of this optimization.
154 1.1.1.2.2.2 bouyer */
155 1.1.1.2.2.2 bouyer if (Node != TargetNode)
156 1.1.1.2.2.2 bouyer {
157 1.1.1.2.2.2 bouyer /*
158 1.1.1.2.2.2 bouyer * This means that another object with the same name was found first,
159 1.1.1.2.2.2 bouyer * and we cannot use this optimization.
160 1.1.1.2.2.2 bouyer */
161 1.1.1.2.2.2 bouyer return (AE_NOT_FOUND);
162 1.1.1.2.2.2 bouyer }
163 1.1.1.2.2.2 bouyer
164 1.1.1.2.2.2 bouyer /* Found the node, we can use this optimization */
165 1.1.1.2.2.2 bouyer
166 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
167 1.1.1.2.2.2 bouyer "NAMESEG: %-24s", Path));
168 1.1.1.2.2.2 bouyer
169 1.1.1.2.2.2 bouyer /* We must allocate a new string for the name (TargetPath gets deleted) */
170 1.1.1.2.2.2 bouyer
171 1.1.1.2.2.2 bouyer *NewPath = ACPI_ALLOCATE_ZEROED (ACPI_NAME_SIZE + 1);
172 1.1.1.2.2.2 bouyer ACPI_STRCPY (*NewPath, Path);
173 1.1.1.2.2.2 bouyer
174 1.1.1.2.2.2 bouyer if (ACPI_STRNCMP (*NewPath, "_T_", 3))
175 1.1.1.2.2.2 bouyer {
176 1.1.1.2.2.2 bouyer AslError (ASL_OPTIMIZATION, ASL_MSG_SINGLE_NAME_OPTIMIZATION, Op,
177 1.1.1.2.2.2 bouyer *NewPath);
178 1.1.1.2.2.2 bouyer }
179 1.1.1.2.2.2 bouyer
180 1.1.1.2.2.2 bouyer return (AE_OK);
181 1.1.1.2.2.2 bouyer }
182 1.1.1.2.2.2 bouyer
183 1.1.1.2.2.2 bouyer
184 1.1.1.2.2.2 bouyer /*******************************************************************************
185 1.1.1.2.2.2 bouyer *
186 1.1.1.2.2.2 bouyer * FUNCTION: OptBuildShortestPath
187 1.1.1.2.2.2 bouyer *
188 1.1.1.2.2.2 bouyer * PARAMETERS: Op - Current parser op
189 1.1.1.2.2.2 bouyer * WalkState - Current state
190 1.1.1.2.2.2 bouyer * CurrentNode - Where we are in the namespace
191 1.1.1.2.2.2 bouyer * TargetNode - Node to which we are referring
192 1.1.1.2.2.2 bouyer * CurrentPath - External full path to the current node
193 1.1.1.2.2.2 bouyer * TargetPath - External full path to the target node
194 1.1.1.2.2.2 bouyer * AmlNameStringLength - Length of the original namepath
195 1.1.1.2.2.2 bouyer * IsDeclaration - TRUE for declaration, FALSE for reference
196 1.1.1.2.2.2 bouyer * ReturnNewPath - Where the optimized path is returned
197 1.1.1.2.2.2 bouyer *
198 1.1.1.2.2.2 bouyer * RETURN: Status
199 1.1.1.2.2.2 bouyer *
200 1.1.1.2.2.2 bouyer * DESCRIPTION: Build an optimal NamePath using carats
201 1.1.1.2.2.2 bouyer *
202 1.1.1.2.2.2 bouyer ******************************************************************************/
203 1.1.1.2.2.2 bouyer
204 1.1.1.2.2.2 bouyer static ACPI_STATUS
205 1.1.1.2.2.2 bouyer OptBuildShortestPath (
206 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op,
207 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState,
208 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *CurrentNode,
209 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *TargetNode,
210 1.1.1.2.2.2 bouyer ACPI_BUFFER *CurrentPath,
211 1.1.1.2.2.2 bouyer ACPI_BUFFER *TargetPath,
212 1.1.1.2.2.2 bouyer ACPI_SIZE AmlNameStringLength,
213 1.1.1.2.2.2 bouyer UINT8 IsDeclaration,
214 1.1.1.2.2.2 bouyer char **ReturnNewPath)
215 1.1.1.2.2.2 bouyer {
216 1.1.1.2.2.2 bouyer UINT32 NumCommonSegments;
217 1.1.1.2.2.2 bouyer UINT32 MaxCommonSegments;
218 1.1.1.2.2.2 bouyer UINT32 Index;
219 1.1.1.2.2.2 bouyer UINT32 NumCarats;
220 1.1.1.2.2.2 bouyer UINT32 i;
221 1.1.1.2.2.2 bouyer char *NewPath;
222 1.1.1.2.2.2 bouyer char *NewPathExternal;
223 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *Node;
224 1.1.1.2.2.2 bouyer ACPI_GENERIC_STATE ScopeInfo;
225 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
226 1.1.1.2.2.2 bouyer BOOLEAN SubPath = FALSE;
227 1.1.1.2.2.2 bouyer
228 1.1.1.2.2.2 bouyer
229 1.1.1.2.2.2 bouyer ACPI_FUNCTION_NAME (OptBuildShortestPath);
230 1.1.1.2.2.2 bouyer
231 1.1.1.2.2.2 bouyer
232 1.1.1.2.2.2 bouyer ScopeInfo.Scope.Node = CurrentNode;
233 1.1.1.2.2.2 bouyer
234 1.1.1.2.2.2 bouyer /*
235 1.1.1.2.2.2 bouyer * Determine the maximum number of NameSegs that the Target and Current paths
236 1.1.1.2.2.2 bouyer * can possibly have in common. (To optimize, we have to have at least 1)
237 1.1.1.2.2.2 bouyer *
238 1.1.1.2.2.2 bouyer * Note: The external NamePath string lengths are always a multiple of 5
239 1.1.1.2.2.2 bouyer * (ACPI_NAME_SIZE + separator)
240 1.1.1.2.2.2 bouyer */
241 1.1.1.2.2.2 bouyer MaxCommonSegments = TargetPath->Length / ACPI_PATH_SEGMENT_LENGTH;
242 1.1.1.2.2.2 bouyer if (CurrentPath->Length < TargetPath->Length)
243 1.1.1.2.2.2 bouyer {
244 1.1.1.2.2.2 bouyer MaxCommonSegments = CurrentPath->Length / ACPI_PATH_SEGMENT_LENGTH;
245 1.1.1.2.2.2 bouyer }
246 1.1.1.2.2.2 bouyer
247 1.1.1.2.2.2 bouyer /*
248 1.1.1.2.2.2 bouyer * Determine how many NameSegs the two paths have in common.
249 1.1.1.2.2.2 bouyer * (Starting from the root)
250 1.1.1.2.2.2 bouyer */
251 1.1.1.2.2.2 bouyer for (NumCommonSegments = 0;
252 1.1.1.2.2.2 bouyer NumCommonSegments < MaxCommonSegments;
253 1.1.1.2.2.2 bouyer NumCommonSegments++)
254 1.1.1.2.2.2 bouyer {
255 1.1.1.2.2.2 bouyer /* Compare two single NameSegs */
256 1.1.1.2.2.2 bouyer
257 1.1.1.2.2.2 bouyer if (ACPI_STRNCMP (
258 1.1.1.2.2.2 bouyer &((char *) TargetPath->Pointer)[(NumCommonSegments *
259 1.1.1.2.2.2 bouyer ACPI_PATH_SEGMENT_LENGTH) + 1],
260 1.1.1.2.2.2 bouyer &((char *) CurrentPath->Pointer)[(NumCommonSegments *
261 1.1.1.2.2.2 bouyer ACPI_PATH_SEGMENT_LENGTH) + 1],
262 1.1.1.2.2.2 bouyer ACPI_NAME_SIZE))
263 1.1.1.2.2.2 bouyer {
264 1.1.1.2.2.2 bouyer /* Mismatch */
265 1.1.1.2.2.2 bouyer
266 1.1.1.2.2.2 bouyer break;
267 1.1.1.2.2.2 bouyer }
268 1.1.1.2.2.2 bouyer }
269 1.1.1.2.2.2 bouyer
270 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " COMMON: %u",
271 1.1.1.2.2.2 bouyer NumCommonSegments));
272 1.1.1.2.2.2 bouyer
273 1.1.1.2.2.2 bouyer /* There must be at least 1 common NameSeg in order to optimize */
274 1.1.1.2.2.2 bouyer
275 1.1.1.2.2.2 bouyer if (NumCommonSegments == 0)
276 1.1.1.2.2.2 bouyer {
277 1.1.1.2.2.2 bouyer return (AE_NOT_FOUND);
278 1.1.1.2.2.2 bouyer }
279 1.1.1.2.2.2 bouyer
280 1.1.1.2.2.2 bouyer if (NumCommonSegments == MaxCommonSegments)
281 1.1.1.2.2.2 bouyer {
282 1.1.1.2.2.2 bouyer if (CurrentPath->Length == TargetPath->Length)
283 1.1.1.2.2.2 bouyer {
284 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " SAME PATH"));
285 1.1.1.2.2.2 bouyer return (AE_NOT_FOUND);
286 1.1.1.2.2.2 bouyer }
287 1.1.1.2.2.2 bouyer else
288 1.1.1.2.2.2 bouyer {
289 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " SUBPATH"));
290 1.1.1.2.2.2 bouyer SubPath = TRUE;
291 1.1.1.2.2.2 bouyer }
292 1.1.1.2.2.2 bouyer }
293 1.1.1.2.2.2 bouyer
294 1.1.1.2.2.2 bouyer /* Determine how many prefix Carats are required */
295 1.1.1.2.2.2 bouyer
296 1.1.1.2.2.2 bouyer NumCarats = (CurrentPath->Length / ACPI_PATH_SEGMENT_LENGTH) -
297 1.1.1.2.2.2 bouyer NumCommonSegments;
298 1.1.1.2.2.2 bouyer
299 1.1.1.2.2.2 bouyer /*
300 1.1.1.2.2.2 bouyer * Construct a new target string
301 1.1.1.2.2.2 bouyer */
302 1.1.1.2.2.2 bouyer NewPathExternal = ACPI_ALLOCATE_ZEROED (
303 1.1.1.2.2.2 bouyer TargetPath->Length + NumCarats + 1);
304 1.1.1.2.2.2 bouyer
305 1.1.1.2.2.2 bouyer /* Insert the Carats into the Target string */
306 1.1.1.2.2.2 bouyer
307 1.1.1.2.2.2 bouyer for (i = 0; i < NumCarats; i++)
308 1.1.1.2.2.2 bouyer {
309 1.1.1.2.2.2 bouyer NewPathExternal[i] = '^';
310 1.1.1.2.2.2 bouyer }
311 1.1.1.2.2.2 bouyer
312 1.1.1.2.2.2 bouyer /*
313 1.1.1.2.2.2 bouyer * Copy only the necessary (optimal) segments from the original
314 1.1.1.2.2.2 bouyer * target string
315 1.1.1.2.2.2 bouyer */
316 1.1.1.2.2.2 bouyer Index = (NumCommonSegments * ACPI_PATH_SEGMENT_LENGTH) + 1;
317 1.1.1.2.2.2 bouyer
318 1.1.1.2.2.2 bouyer /* Special handling for exact subpath in a name declaration */
319 1.1.1.2.2.2 bouyer
320 1.1.1.2.2.2 bouyer if (IsDeclaration && SubPath && (CurrentPath->Length > TargetPath->Length))
321 1.1.1.2.2.2 bouyer {
322 1.1.1.2.2.2 bouyer /*
323 1.1.1.2.2.2 bouyer * The current path is longer than the target, and the target is a
324 1.1.1.2.2.2 bouyer * subpath of the current path. We must include one more NameSeg of
325 1.1.1.2.2.2 bouyer * the target path
326 1.1.1.2.2.2 bouyer */
327 1.1.1.2.2.2 bouyer Index -= ACPI_PATH_SEGMENT_LENGTH;
328 1.1.1.2.2.2 bouyer
329 1.1.1.2.2.2 bouyer /* Special handling for Scope() operator */
330 1.1.1.2.2.2 bouyer
331 1.1.1.2.2.2 bouyer if (Op->Asl.AmlOpcode == AML_SCOPE_OP)
332 1.1.1.2.2.2 bouyer {
333 1.1.1.2.2.2 bouyer NewPathExternal[i] = '^';
334 1.1.1.2.2.2 bouyer i++;
335 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "(EXTRA ^)"));
336 1.1.1.2.2.2 bouyer }
337 1.1.1.2.2.2 bouyer }
338 1.1.1.2.2.2 bouyer
339 1.1.1.2.2.2 bouyer /* Make sure we haven't gone off the end of the target path */
340 1.1.1.2.2.2 bouyer
341 1.1.1.2.2.2 bouyer if (Index > TargetPath->Length)
342 1.1.1.2.2.2 bouyer {
343 1.1.1.2.2.2 bouyer Index = TargetPath->Length;
344 1.1.1.2.2.2 bouyer }
345 1.1.1.2.2.2 bouyer
346 1.1.1.2.2.2 bouyer ACPI_STRCPY (&NewPathExternal[i], &((char *) TargetPath->Pointer)[Index]);
347 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " %-24s", NewPathExternal));
348 1.1.1.2.2.2 bouyer
349 1.1.1.2.2.2 bouyer /*
350 1.1.1.2.2.2 bouyer * Internalize the new target string and check it against the original
351 1.1.1.2.2.2 bouyer * string to make sure that this is in fact an optimization. If the
352 1.1.1.2.2.2 bouyer * original string is already optimal, there is no point in continuing.
353 1.1.1.2.2.2 bouyer */
354 1.1.1.2.2.2 bouyer Status = AcpiNsInternalizeName (NewPathExternal, &NewPath);
355 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
356 1.1.1.2.2.2 bouyer {
357 1.1.1.2.2.2 bouyer AslCoreSubsystemError (Op, Status, "Internalizing new NamePath",
358 1.1.1.2.2.2 bouyer ASL_NO_ABORT);
359 1.1.1.2.2.2 bouyer ACPI_FREE (NewPathExternal);
360 1.1.1.2.2.2 bouyer return (Status);
361 1.1.1.2.2.2 bouyer }
362 1.1.1.2.2.2 bouyer
363 1.1.1.2.2.2 bouyer if (ACPI_STRLEN (NewPath) >= AmlNameStringLength)
364 1.1.1.2.2.2 bouyer {
365 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
366 1.1.1.2.2.2 bouyer " NOT SHORTER (New %u old %u)",
367 1.1.1.2.2.2 bouyer (UINT32) ACPI_STRLEN (NewPath), (UINT32) AmlNameStringLength));
368 1.1.1.2.2.2 bouyer ACPI_FREE (NewPathExternal);
369 1.1.1.2.2.2 bouyer return (AE_NOT_FOUND);
370 1.1.1.2.2.2 bouyer }
371 1.1.1.2.2.2 bouyer
372 1.1.1.2.2.2 bouyer /*
373 1.1.1.2.2.2 bouyer * Check to make sure that the optimization finds the node we are
374 1.1.1.2.2.2 bouyer * looking for. This is simply a sanity check on the new
375 1.1.1.2.2.2 bouyer * path that has been created.
376 1.1.1.2.2.2 bouyer */
377 1.1.1.2.2.2 bouyer Status = AcpiNsLookup (&ScopeInfo, NewPath,
378 1.1.1.2.2.2 bouyer ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
379 1.1.1.2.2.2 bouyer ACPI_NS_DONT_OPEN_SCOPE, WalkState, &(Node));
380 1.1.1.2.2.2 bouyer if (ACPI_SUCCESS (Status))
381 1.1.1.2.2.2 bouyer {
382 1.1.1.2.2.2 bouyer /* Found the namepath, but make sure the node is correct */
383 1.1.1.2.2.2 bouyer
384 1.1.1.2.2.2 bouyer if (Node == TargetNode)
385 1.1.1.2.2.2 bouyer {
386 1.1.1.2.2.2 bouyer /* The lookup matched the node, accept this optimization */
387 1.1.1.2.2.2 bouyer
388 1.1.1.2.2.2 bouyer AslError (ASL_OPTIMIZATION, ASL_MSG_NAME_OPTIMIZATION,
389 1.1.1.2.2.2 bouyer Op, NewPathExternal);
390 1.1.1.2.2.2 bouyer *ReturnNewPath = NewPath;
391 1.1.1.2.2.2 bouyer }
392 1.1.1.2.2.2 bouyer else
393 1.1.1.2.2.2 bouyer {
394 1.1.1.2.2.2 bouyer /* Node is not correct, do not use this optimization */
395 1.1.1.2.2.2 bouyer
396 1.1.1.2.2.2 bouyer Status = AE_NOT_FOUND;
397 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " ***** WRONG NODE"));
398 1.1.1.2.2.2 bouyer AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op,
399 1.1.1.2.2.2 bouyer "Not using optimized name - found wrong node");
400 1.1.1.2.2.2 bouyer }
401 1.1.1.2.2.2 bouyer }
402 1.1.1.2.2.2 bouyer else
403 1.1.1.2.2.2 bouyer {
404 1.1.1.2.2.2 bouyer /* The lookup failed, we obviously cannot use this optimization */
405 1.1.1.2.2.2 bouyer
406 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " ***** NOT FOUND"));
407 1.1.1.2.2.2 bouyer AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op,
408 1.1.1.2.2.2 bouyer "Not using optimized name - did not find node");
409 1.1.1.2.2.2 bouyer }
410 1.1.1.2.2.2 bouyer
411 1.1.1.2.2.2 bouyer ACPI_FREE (NewPathExternal);
412 1.1.1.2.2.2 bouyer return (Status);
413 1.1.1.2.2.2 bouyer }
414 1.1.1.2.2.2 bouyer
415 1.1.1.2.2.2 bouyer
416 1.1.1.2.2.2 bouyer /*******************************************************************************
417 1.1.1.2.2.2 bouyer *
418 1.1.1.2.2.2 bouyer * FUNCTION: OptOptimizeNameDeclaration
419 1.1.1.2.2.2 bouyer *
420 1.1.1.2.2.2 bouyer * PARAMETERS: Op - Current parser op
421 1.1.1.2.2.2 bouyer * WalkState - Current state
422 1.1.1.2.2.2 bouyer * CurrentNode - Where we are in the namespace
423 1.1.1.2.2.2 bouyer * AmlNameString - Unoptimized namepath
424 1.1.1.2.2.2 bouyer * NewPath - Where the optimized path is returned
425 1.1.1.2.2.2 bouyer *
426 1.1.1.2.2.2 bouyer * RETURN: Status. AE_OK If path is optimized
427 1.1.1.2.2.2 bouyer *
428 1.1.1.2.2.2 bouyer * DESCRIPTION: Perform a simple optimization of removing an extraneous
429 1.1.1.2.2.2 bouyer * backslash prefix if we are already at the root scope.
430 1.1.1.2.2.2 bouyer *
431 1.1.1.2.2.2 bouyer ******************************************************************************/
432 1.1.1.2.2.2 bouyer
433 1.1.1.2.2.2 bouyer static ACPI_STATUS
434 1.1.1.2.2.2 bouyer OptOptimizeNameDeclaration (
435 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op,
436 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState,
437 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *CurrentNode,
438 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *TargetNode,
439 1.1.1.2.2.2 bouyer char *AmlNameString,
440 1.1.1.2.2.2 bouyer char **NewPath)
441 1.1.1.2.2.2 bouyer {
442 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
443 1.1.1.2.2.2 bouyer char *NewPathExternal;
444 1.1.1.2.2.2 bouyer ACPI_GENERIC_STATE ScopeInfo;
445 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *Node;
446 1.1.1.2.2.2 bouyer
447 1.1.1.2.2.2 bouyer
448 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (OptOptimizeNameDeclaration);
449 1.1.1.2.2.2 bouyer
450 1.1.1.2.2.2 bouyer
451 1.1.1.2.2.2 bouyer if (((CurrentNode == AcpiGbl_RootNode) ||
452 1.1.1.2.2.2 bouyer (Op->Common.Parent->Asl.ParseOpcode == PARSEOP_DEFINITIONBLOCK)) &&
453 1.1.1.2.2.2 bouyer (AmlNameString[0] == '\\'))
454 1.1.1.2.2.2 bouyer {
455 1.1.1.2.2.2 bouyer /*
456 1.1.1.2.2.2 bouyer * The current scope is the root, and the namepath has a root prefix
457 1.1.1.2.2.2 bouyer * that is therefore extraneous. Remove it.
458 1.1.1.2.2.2 bouyer */
459 1.1.1.2.2.2 bouyer *NewPath = &AmlNameString[1];
460 1.1.1.2.2.2 bouyer
461 1.1.1.2.2.2 bouyer /* Debug output */
462 1.1.1.2.2.2 bouyer
463 1.1.1.2.2.2 bouyer Status = AcpiNsExternalizeName (ACPI_UINT32_MAX, *NewPath,
464 1.1.1.2.2.2 bouyer NULL, &NewPathExternal);
465 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
466 1.1.1.2.2.2 bouyer {
467 1.1.1.2.2.2 bouyer AslCoreSubsystemError (Op, Status, "Externalizing NamePath",
468 1.1.1.2.2.2 bouyer ASL_NO_ABORT);
469 1.1.1.2.2.2 bouyer return (Status);
470 1.1.1.2.2.2 bouyer }
471 1.1.1.2.2.2 bouyer
472 1.1.1.2.2.2 bouyer /*
473 1.1.1.2.2.2 bouyer * Check to make sure that the optimization finds the node we are
474 1.1.1.2.2.2 bouyer * looking for. This is simply a sanity check on the new
475 1.1.1.2.2.2 bouyer * path that has been created.
476 1.1.1.2.2.2 bouyer */
477 1.1.1.2.2.2 bouyer ScopeInfo.Scope.Node = CurrentNode;
478 1.1.1.2.2.2 bouyer Status = AcpiNsLookup (&ScopeInfo, *NewPath,
479 1.1.1.2.2.2 bouyer ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
480 1.1.1.2.2.2 bouyer ACPI_NS_DONT_OPEN_SCOPE, WalkState, &(Node));
481 1.1.1.2.2.2 bouyer if (ACPI_SUCCESS (Status))
482 1.1.1.2.2.2 bouyer {
483 1.1.1.2.2.2 bouyer /* Found the namepath, but make sure the node is correct */
484 1.1.1.2.2.2 bouyer
485 1.1.1.2.2.2 bouyer if (Node == TargetNode)
486 1.1.1.2.2.2 bouyer {
487 1.1.1.2.2.2 bouyer /* The lookup matched the node, accept this optimization */
488 1.1.1.2.2.2 bouyer
489 1.1.1.2.2.2 bouyer AslError (ASL_OPTIMIZATION, ASL_MSG_NAME_OPTIMIZATION,
490 1.1.1.2.2.2 bouyer Op, NewPathExternal);
491 1.1.1.2.2.2 bouyer
492 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
493 1.1.1.2.2.2 bouyer "AT ROOT: %-24s", NewPathExternal));
494 1.1.1.2.2.2 bouyer }
495 1.1.1.2.2.2 bouyer else
496 1.1.1.2.2.2 bouyer {
497 1.1.1.2.2.2 bouyer /* Node is not correct, do not use this optimization */
498 1.1.1.2.2.2 bouyer
499 1.1.1.2.2.2 bouyer Status = AE_NOT_FOUND;
500 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
501 1.1.1.2.2.2 bouyer " ***** WRONG NODE"));
502 1.1.1.2.2.2 bouyer AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op,
503 1.1.1.2.2.2 bouyer "Not using optimized name - found wrong node");
504 1.1.1.2.2.2 bouyer }
505 1.1.1.2.2.2 bouyer }
506 1.1.1.2.2.2 bouyer else
507 1.1.1.2.2.2 bouyer {
508 1.1.1.2.2.2 bouyer /* The lookup failed, we obviously cannot use this optimization */
509 1.1.1.2.2.2 bouyer
510 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
511 1.1.1.2.2.2 bouyer " ***** NOT FOUND"));
512 1.1.1.2.2.2 bouyer AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op,
513 1.1.1.2.2.2 bouyer "Not using optimized name - did not find node");
514 1.1.1.2.2.2 bouyer }
515 1.1.1.2.2.2 bouyer
516 1.1.1.2.2.2 bouyer ACPI_FREE (NewPathExternal);
517 1.1.1.2.2.2 bouyer return (Status);
518 1.1.1.2.2.2 bouyer }
519 1.1.1.2.2.2 bouyer
520 1.1.1.2.2.2 bouyer /* Could not optimize */
521 1.1.1.2.2.2 bouyer
522 1.1.1.2.2.2 bouyer return (AE_NOT_FOUND);
523 1.1.1.2.2.2 bouyer }
524 1.1.1.2.2.2 bouyer
525 1.1.1.2.2.2 bouyer
526 1.1.1.2.2.2 bouyer /*******************************************************************************
527 1.1.1.2.2.2 bouyer *
528 1.1.1.2.2.2 bouyer * FUNCTION: OptOptimizeNamePath
529 1.1.1.2.2.2 bouyer *
530 1.1.1.2.2.2 bouyer * PARAMETERS: Op - Current parser op
531 1.1.1.2.2.2 bouyer * Flags - Opcode info flags
532 1.1.1.2.2.2 bouyer * WalkState - Current state
533 1.1.1.2.2.2 bouyer * AmlNameString - Unoptimized namepath
534 1.1.1.2.2.2 bouyer * TargetNode - Node to which AmlNameString refers
535 1.1.1.2.2.2 bouyer *
536 1.1.1.2.2.2 bouyer * RETURN: None. If path is optimized, the Op is updated with new path
537 1.1.1.2.2.2 bouyer *
538 1.1.1.2.2.2 bouyer * DESCRIPTION: Optimize a Named Declaration or Reference to the minimal length.
539 1.1.1.2.2.2 bouyer * Must take into account both the current location in the
540 1.1.1.2.2.2 bouyer * namespace and the actual reference path.
541 1.1.1.2.2.2 bouyer *
542 1.1.1.2.2.2 bouyer ******************************************************************************/
543 1.1.1.2.2.2 bouyer
544 1.1.1.2.2.2 bouyer void
545 1.1.1.2.2.2 bouyer OptOptimizeNamePath (
546 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op,
547 1.1.1.2.2.2 bouyer UINT32 Flags,
548 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState,
549 1.1.1.2.2.2 bouyer char *AmlNameString,
550 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *TargetNode)
551 1.1.1.2.2.2 bouyer {
552 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
553 1.1.1.2.2.2 bouyer ACPI_BUFFER TargetPath;
554 1.1.1.2.2.2 bouyer ACPI_BUFFER CurrentPath;
555 1.1.1.2.2.2 bouyer ACPI_SIZE AmlNameStringLength;
556 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *CurrentNode;
557 1.1.1.2.2.2 bouyer char *ExternalNameString;
558 1.1.1.2.2.2 bouyer char *NewPath = NULL;
559 1.1.1.2.2.2 bouyer ACPI_SIZE HowMuchShorter;
560 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *NextOp;
561 1.1.1.2.2.2 bouyer
562 1.1.1.2.2.2 bouyer
563 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (OptOptimizeNamePath);
564 1.1.1.2.2.2 bouyer
565 1.1.1.2.2.2 bouyer
566 1.1.1.2.2.2 bouyer /* This is an optional optimization */
567 1.1.1.2.2.2 bouyer
568 1.1.1.2.2.2 bouyer if (!Gbl_ReferenceOptimizationFlag)
569 1.1.1.2.2.2 bouyer {
570 1.1.1.2.2.2 bouyer return_VOID;
571 1.1.1.2.2.2 bouyer }
572 1.1.1.2.2.2 bouyer
573 1.1.1.2.2.2 bouyer /* Various required items */
574 1.1.1.2.2.2 bouyer
575 1.1.1.2.2.2 bouyer if (!TargetNode || !WalkState || !AmlNameString || !Op->Common.Parent)
576 1.1.1.2.2.2 bouyer {
577 1.1.1.2.2.2 bouyer return_VOID;
578 1.1.1.2.2.2 bouyer }
579 1.1.1.2.2.2 bouyer
580 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "%5d [%12.12s] [%12.12s] ",
581 1.1.1.2.2.2 bouyer Op->Asl.LogicalLineNumber,
582 1.1.1.2.2.2 bouyer AcpiPsGetOpcodeName (Op->Common.Parent->Common.AmlOpcode),
583 1.1.1.2.2.2 bouyer AcpiPsGetOpcodeName (Op->Common.AmlOpcode)));
584 1.1.1.2.2.2 bouyer
585 1.1.1.2.2.2 bouyer if (!(Flags & (AML_NAMED | AML_CREATE)))
586 1.1.1.2.2.2 bouyer {
587 1.1.1.2.2.2 bouyer if (Op->Asl.CompileFlags & NODE_IS_NAME_DECLARATION)
588 1.1.1.2.2.2 bouyer {
589 1.1.1.2.2.2 bouyer /* We don't want to fuss with actual name declaration nodes here */
590 1.1.1.2.2.2 bouyer
591 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
592 1.1.1.2.2.2 bouyer "******* NAME DECLARATION\n"));
593 1.1.1.2.2.2 bouyer return_VOID;
594 1.1.1.2.2.2 bouyer }
595 1.1.1.2.2.2 bouyer }
596 1.1.1.2.2.2 bouyer
597 1.1.1.2.2.2 bouyer /*
598 1.1.1.2.2.2 bouyer * The original path must be longer than one NameSeg (4 chars) for there
599 1.1.1.2.2.2 bouyer * to be any possibility that it can be optimized to a shorter string
600 1.1.1.2.2.2 bouyer */
601 1.1.1.2.2.2 bouyer AmlNameStringLength = ACPI_STRLEN (AmlNameString);
602 1.1.1.2.2.2 bouyer if (AmlNameStringLength <= ACPI_NAME_SIZE)
603 1.1.1.2.2.2 bouyer {
604 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
605 1.1.1.2.2.2 bouyer "NAMESEG %4.4s\n", AmlNameString));
606 1.1.1.2.2.2 bouyer return_VOID;
607 1.1.1.2.2.2 bouyer }
608 1.1.1.2.2.2 bouyer
609 1.1.1.2.2.2 bouyer /*
610 1.1.1.2.2.2 bouyer * We need to obtain the node that represents the current scope -- where
611 1.1.1.2.2.2 bouyer * we are right now in the namespace. We will compare this path
612 1.1.1.2.2.2 bouyer * against the Namepath, looking for commonality.
613 1.1.1.2.2.2 bouyer */
614 1.1.1.2.2.2 bouyer CurrentNode = AcpiGbl_RootNode;
615 1.1.1.2.2.2 bouyer if (WalkState->ScopeInfo)
616 1.1.1.2.2.2 bouyer {
617 1.1.1.2.2.2 bouyer CurrentNode = WalkState->ScopeInfo->Scope.Node;
618 1.1.1.2.2.2 bouyer }
619 1.1.1.2.2.2 bouyer
620 1.1.1.2.2.2 bouyer if (Flags & (AML_NAMED | AML_CREATE))
621 1.1.1.2.2.2 bouyer {
622 1.1.1.2.2.2 bouyer /* This is the declaration of a new name */
623 1.1.1.2.2.2 bouyer
624 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "NAME"));
625 1.1.1.2.2.2 bouyer
626 1.1.1.2.2.2 bouyer /*
627 1.1.1.2.2.2 bouyer * The node of interest is the parent of this node
628 1.1.1.2.2.2 bouyer * (the containing scope)
629 1.1.1.2.2.2 bouyer */
630 1.1.1.2.2.2 bouyer CurrentNode = Op->Asl.Parent->Asl.Node;
631 1.1.1.2.2.2 bouyer if (!CurrentNode)
632 1.1.1.2.2.2 bouyer {
633 1.1.1.2.2.2 bouyer CurrentNode = AcpiGbl_RootNode;
634 1.1.1.2.2.2 bouyer }
635 1.1.1.2.2.2 bouyer }
636 1.1.1.2.2.2 bouyer else
637 1.1.1.2.2.2 bouyer {
638 1.1.1.2.2.2 bouyer /* This is a reference to an existing named object */
639 1.1.1.2.2.2 bouyer
640 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "REF "));
641 1.1.1.2.2.2 bouyer }
642 1.1.1.2.2.2 bouyer
643 1.1.1.2.2.2 bouyer /*
644 1.1.1.2.2.2 bouyer * Obtain the full paths to the two nodes that we are interested in
645 1.1.1.2.2.2 bouyer * (Target and current namespace location) in external
646 1.1.1.2.2.2 bouyer * format -- something we can easily manipulate
647 1.1.1.2.2.2 bouyer */
648 1.1.1.2.2.2 bouyer TargetPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
649 1.1.1.2.2.2 bouyer Status = AcpiNsHandleToPathname (TargetNode, &TargetPath);
650 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
651 1.1.1.2.2.2 bouyer {
652 1.1.1.2.2.2 bouyer AslCoreSubsystemError (Op, Status, "Getting Target NamePath",
653 1.1.1.2.2.2 bouyer ASL_NO_ABORT);
654 1.1.1.2.2.2 bouyer return_VOID;
655 1.1.1.2.2.2 bouyer }
656 1.1.1.2.2.2 bouyer TargetPath.Length--; /* Subtract one for null terminator */
657 1.1.1.2.2.2 bouyer
658 1.1.1.2.2.2 bouyer /* CurrentPath is the path to this scope (where we are in the namespace) */
659 1.1.1.2.2.2 bouyer
660 1.1.1.2.2.2 bouyer CurrentPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
661 1.1.1.2.2.2 bouyer Status = AcpiNsHandleToPathname (CurrentNode, &CurrentPath);
662 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
663 1.1.1.2.2.2 bouyer {
664 1.1.1.2.2.2 bouyer AslCoreSubsystemError (Op, Status, "Getting Current NamePath",
665 1.1.1.2.2.2 bouyer ASL_NO_ABORT);
666 1.1.1.2.2.2 bouyer return_VOID;
667 1.1.1.2.2.2 bouyer }
668 1.1.1.2.2.2 bouyer CurrentPath.Length--; /* Subtract one for null terminator */
669 1.1.1.2.2.2 bouyer
670 1.1.1.2.2.2 bouyer /* Debug output only */
671 1.1.1.2.2.2 bouyer
672 1.1.1.2.2.2 bouyer Status = AcpiNsExternalizeName (ACPI_UINT32_MAX, AmlNameString,
673 1.1.1.2.2.2 bouyer NULL, &ExternalNameString);
674 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
675 1.1.1.2.2.2 bouyer {
676 1.1.1.2.2.2 bouyer AslCoreSubsystemError (Op, Status, "Externalizing NamePath",
677 1.1.1.2.2.2 bouyer ASL_NO_ABORT);
678 1.1.1.2.2.2 bouyer return_VOID;
679 1.1.1.2.2.2 bouyer }
680 1.1.1.2.2.2 bouyer
681 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
682 1.1.1.2.2.2 bouyer "%37s (%2u) ==> %-32s(%2u) %-32s",
683 1.1.1.2.2.2 bouyer (char *) CurrentPath.Pointer, (UINT32) CurrentPath.Length,
684 1.1.1.2.2.2 bouyer (char *) TargetPath.Pointer, (UINT32) TargetPath.Length, ExternalNameString));
685 1.1.1.2.2.2 bouyer
686 1.1.1.2.2.2 bouyer ACPI_FREE (ExternalNameString);
687 1.1.1.2.2.2 bouyer
688 1.1.1.2.2.2 bouyer /*
689 1.1.1.2.2.2 bouyer * Attempt an optmization depending on the type of namepath
690 1.1.1.2.2.2 bouyer */
691 1.1.1.2.2.2 bouyer if (Flags & (AML_NAMED | AML_CREATE))
692 1.1.1.2.2.2 bouyer {
693 1.1.1.2.2.2 bouyer /*
694 1.1.1.2.2.2 bouyer * This is a named opcode and the namepath is a name declaration, not
695 1.1.1.2.2.2 bouyer * a reference.
696 1.1.1.2.2.2 bouyer */
697 1.1.1.2.2.2 bouyer Status = OptOptimizeNameDeclaration (Op, WalkState, CurrentNode,
698 1.1.1.2.2.2 bouyer TargetNode, AmlNameString, &NewPath);
699 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
700 1.1.1.2.2.2 bouyer {
701 1.1.1.2.2.2 bouyer /*
702 1.1.1.2.2.2 bouyer * 2) now attempt to
703 1.1.1.2.2.2 bouyer * optimize the namestring with carats (up-arrow)
704 1.1.1.2.2.2 bouyer */
705 1.1.1.2.2.2 bouyer Status = OptBuildShortestPath (Op, WalkState, CurrentNode,
706 1.1.1.2.2.2 bouyer TargetNode, &CurrentPath, &TargetPath,
707 1.1.1.2.2.2 bouyer AmlNameStringLength, 1, &NewPath);
708 1.1.1.2.2.2 bouyer }
709 1.1.1.2.2.2 bouyer }
710 1.1.1.2.2.2 bouyer else
711 1.1.1.2.2.2 bouyer {
712 1.1.1.2.2.2 bouyer /*
713 1.1.1.2.2.2 bouyer * This is a reference to an existing named object
714 1.1.1.2.2.2 bouyer *
715 1.1.1.2.2.2 bouyer * 1) Check if search-to-root can be utilized using the last
716 1.1.1.2.2.2 bouyer * NameSeg of the NamePath
717 1.1.1.2.2.2 bouyer */
718 1.1.1.2.2.2 bouyer Status = OptSearchToRoot (Op, WalkState, CurrentNode,
719 1.1.1.2.2.2 bouyer TargetNode, &TargetPath, &NewPath);
720 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
721 1.1.1.2.2.2 bouyer {
722 1.1.1.2.2.2 bouyer /*
723 1.1.1.2.2.2 bouyer * 2) Search-to-root could not be used, now attempt to
724 1.1.1.2.2.2 bouyer * optimize the namestring with carats (up-arrow)
725 1.1.1.2.2.2 bouyer */
726 1.1.1.2.2.2 bouyer Status = OptBuildShortestPath (Op, WalkState, CurrentNode,
727 1.1.1.2.2.2 bouyer TargetNode, &CurrentPath, &TargetPath,
728 1.1.1.2.2.2 bouyer AmlNameStringLength, 0, &NewPath);
729 1.1.1.2.2.2 bouyer }
730 1.1.1.2.2.2 bouyer }
731 1.1.1.2.2.2 bouyer
732 1.1.1.2.2.2 bouyer /*
733 1.1.1.2.2.2 bouyer * Success from above indicates that the NamePath was successfully
734 1.1.1.2.2.2 bouyer * optimized. We need to update the parse op with the new name
735 1.1.1.2.2.2 bouyer */
736 1.1.1.2.2.2 bouyer if (ACPI_SUCCESS (Status))
737 1.1.1.2.2.2 bouyer {
738 1.1.1.2.2.2 bouyer HowMuchShorter = (AmlNameStringLength - ACPI_STRLEN (NewPath));
739 1.1.1.2.2.2 bouyer OptTotal += HowMuchShorter;
740 1.1.1.2.2.2 bouyer
741 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " REDUCED %2u (%u)",
742 1.1.1.2.2.2 bouyer (UINT32) HowMuchShorter, OptTotal));
743 1.1.1.2.2.2 bouyer
744 1.1.1.2.2.2 bouyer if (Flags & AML_NAMED)
745 1.1.1.2.2.2 bouyer {
746 1.1.1.2.2.2 bouyer if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
747 1.1.1.2.2.2 bouyer {
748 1.1.1.2.2.2 bouyer /*
749 1.1.1.2.2.2 bouyer * ALIAS is the only oddball opcode, the name declaration
750 1.1.1.2.2.2 bouyer * (alias name) is the second operand
751 1.1.1.2.2.2 bouyer */
752 1.1.1.2.2.2 bouyer Op->Asl.Child->Asl.Next->Asl.Value.String = NewPath;
753 1.1.1.2.2.2 bouyer Op->Asl.Child->Asl.Next->Asl.AmlLength = ACPI_STRLEN (NewPath);
754 1.1.1.2.2.2 bouyer }
755 1.1.1.2.2.2 bouyer else
756 1.1.1.2.2.2 bouyer {
757 1.1.1.2.2.2 bouyer Op->Asl.Child->Asl.Value.String = NewPath;
758 1.1.1.2.2.2 bouyer Op->Asl.Child->Asl.AmlLength = ACPI_STRLEN (NewPath);
759 1.1.1.2.2.2 bouyer }
760 1.1.1.2.2.2 bouyer }
761 1.1.1.2.2.2 bouyer else if (Flags & AML_CREATE)
762 1.1.1.2.2.2 bouyer {
763 1.1.1.2.2.2 bouyer /* Name must appear as the last parameter */
764 1.1.1.2.2.2 bouyer
765 1.1.1.2.2.2 bouyer NextOp = Op->Asl.Child;
766 1.1.1.2.2.2 bouyer while (!(NextOp->Asl.CompileFlags & NODE_IS_NAME_DECLARATION))
767 1.1.1.2.2.2 bouyer {
768 1.1.1.2.2.2 bouyer NextOp = NextOp->Asl.Next;
769 1.1.1.2.2.2 bouyer }
770 1.1.1.2.2.2 bouyer /* Update the parse node with the new NamePath */
771 1.1.1.2.2.2 bouyer
772 1.1.1.2.2.2 bouyer NextOp->Asl.Value.String = NewPath;
773 1.1.1.2.2.2 bouyer NextOp->Asl.AmlLength = ACPI_STRLEN (NewPath);
774 1.1.1.2.2.2 bouyer }
775 1.1.1.2.2.2 bouyer else
776 1.1.1.2.2.2 bouyer {
777 1.1.1.2.2.2 bouyer /* Update the parse node with the new NamePath */
778 1.1.1.2.2.2 bouyer
779 1.1.1.2.2.2 bouyer Op->Asl.Value.String = NewPath;
780 1.1.1.2.2.2 bouyer Op->Asl.AmlLength = ACPI_STRLEN (NewPath);
781 1.1.1.2.2.2 bouyer }
782 1.1.1.2.2.2 bouyer }
783 1.1.1.2.2.2 bouyer else
784 1.1.1.2.2.2 bouyer {
785 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " ALREADY OPTIMAL"));
786 1.1.1.2.2.2 bouyer }
787 1.1.1.2.2.2 bouyer
788 1.1.1.2.2.2 bouyer /* Cleanup path buffers */
789 1.1.1.2.2.2 bouyer
790 1.1.1.2.2.2 bouyer ACPI_FREE (TargetPath.Pointer);
791 1.1.1.2.2.2 bouyer ACPI_FREE (CurrentPath.Pointer);
792 1.1.1.2.2.2 bouyer
793 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "\n"));
794 1.1.1.2.2.2 bouyer return_VOID;
795 1.1.1.2.2.2 bouyer }
796 1.1.1.2.2.2 bouyer
797