Deleted Added
full compact
nsalloc.c (114237) nsalloc.c (115351)
1/*******************************************************************************
2 *
3 * Module Name: nsalloc - Namespace allocation and deletion utilities
1/*******************************************************************************
2 *
3 * Module Name: nsalloc - Namespace allocation and deletion utilities
4 * $Revision: 79 $
4 * $Revision: 82 $
5 *
6 ******************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
13 * All rights reserved.
14 *
15 * 2. License
16 *
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
21 *
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
28 *
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
37 *
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
40 *
41 * 3. Conditions
42 *
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
54 *
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
66 *
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
75 *
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
80 *
81 * 4. Disclaimer and Export Compliance
82 *
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
90 *
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
99 *
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
114 *
115 *****************************************************************************/
116
117
118#define __NSALLOC_C__
119
120#include "acpi.h"
121#include "acnamesp.h"
122
123
124#define _COMPONENT ACPI_NAMESPACE
125 ACPI_MODULE_NAME ("nsalloc")
126
127
128/*******************************************************************************
129 *
130 * FUNCTION: AcpiNsCreateNode
131 *
132 * PARAMETERS: AcpiName - Name of the new node
133 *
134 * RETURN: None
135 *
136 * DESCRIPTION: Create a namespace node
137 *
138 ******************************************************************************/
139
140ACPI_NAMESPACE_NODE *
141AcpiNsCreateNode (
142 UINT32 Name)
143{
144 ACPI_NAMESPACE_NODE *Node;
145
146
147 ACPI_FUNCTION_TRACE ("NsCreateNode");
148
149
150 Node = ACPI_MEM_CALLOCATE (sizeof (ACPI_NAMESPACE_NODE));
151 if (!Node)
152 {
153 return_PTR (NULL);
154 }
155
156 ACPI_MEM_TRACKING (AcpiGbl_MemoryLists[ACPI_MEM_LIST_NSNODE].TotalAllocated++);
157
158 Node->Name.Integer = Name;
159 Node->ReferenceCount = 1;
160 ACPI_SET_DESCRIPTOR_TYPE (Node, ACPI_DESC_TYPE_NAMED);
161
162 return_PTR (Node);
163}
164
165
166/*******************************************************************************
167 *
168 * FUNCTION: AcpiNsDeleteNode
169 *
170 * PARAMETERS: Node - Node to be deleted
171 *
172 * RETURN: None
173 *
174 * DESCRIPTION: Delete a namespace node
175 *
176 ******************************************************************************/
177
178void
179AcpiNsDeleteNode (
180 ACPI_NAMESPACE_NODE *Node)
181{
182 ACPI_NAMESPACE_NODE *ParentNode;
183 ACPI_NAMESPACE_NODE *PrevNode;
184 ACPI_NAMESPACE_NODE *NextNode;
185
186
187 ACPI_FUNCTION_TRACE_PTR ("NsDeleteNode", Node);
188
189
190 ParentNode = AcpiNsGetParentNode (Node);
191
192 PrevNode = NULL;
193 NextNode = ParentNode->Child;
194
5 *
6 ******************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
13 * All rights reserved.
14 *
15 * 2. License
16 *
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
21 *
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
28 *
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
37 *
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
40 *
41 * 3. Conditions
42 *
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
54 *
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
66 *
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
75 *
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
80 *
81 * 4. Disclaimer and Export Compliance
82 *
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
90 *
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
99 *
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
114 *
115 *****************************************************************************/
116
117
118#define __NSALLOC_C__
119
120#include "acpi.h"
121#include "acnamesp.h"
122
123
124#define _COMPONENT ACPI_NAMESPACE
125 ACPI_MODULE_NAME ("nsalloc")
126
127
128/*******************************************************************************
129 *
130 * FUNCTION: AcpiNsCreateNode
131 *
132 * PARAMETERS: AcpiName - Name of the new node
133 *
134 * RETURN: None
135 *
136 * DESCRIPTION: Create a namespace node
137 *
138 ******************************************************************************/
139
140ACPI_NAMESPACE_NODE *
141AcpiNsCreateNode (
142 UINT32 Name)
143{
144 ACPI_NAMESPACE_NODE *Node;
145
146
147 ACPI_FUNCTION_TRACE ("NsCreateNode");
148
149
150 Node = ACPI_MEM_CALLOCATE (sizeof (ACPI_NAMESPACE_NODE));
151 if (!Node)
152 {
153 return_PTR (NULL);
154 }
155
156 ACPI_MEM_TRACKING (AcpiGbl_MemoryLists[ACPI_MEM_LIST_NSNODE].TotalAllocated++);
157
158 Node->Name.Integer = Name;
159 Node->ReferenceCount = 1;
160 ACPI_SET_DESCRIPTOR_TYPE (Node, ACPI_DESC_TYPE_NAMED);
161
162 return_PTR (Node);
163}
164
165
166/*******************************************************************************
167 *
168 * FUNCTION: AcpiNsDeleteNode
169 *
170 * PARAMETERS: Node - Node to be deleted
171 *
172 * RETURN: None
173 *
174 * DESCRIPTION: Delete a namespace node
175 *
176 ******************************************************************************/
177
178void
179AcpiNsDeleteNode (
180 ACPI_NAMESPACE_NODE *Node)
181{
182 ACPI_NAMESPACE_NODE *ParentNode;
183 ACPI_NAMESPACE_NODE *PrevNode;
184 ACPI_NAMESPACE_NODE *NextNode;
185
186
187 ACPI_FUNCTION_TRACE_PTR ("NsDeleteNode", Node);
188
189
190 ParentNode = AcpiNsGetParentNode (Node);
191
192 PrevNode = NULL;
193 NextNode = ParentNode->Child;
194
195 /* Find the node that is the previous peer in the parent's child list */
196
195 while (NextNode != Node)
196 {
197 PrevNode = NextNode;
198 NextNode = PrevNode->Peer;
199 }
200
201 if (PrevNode)
202 {
197 while (NextNode != Node)
198 {
199 PrevNode = NextNode;
200 NextNode = PrevNode->Peer;
201 }
202
203 if (PrevNode)
204 {
205 /* Node is not first child, unlink it */
206
203 PrevNode->Peer = NextNode->Peer;
204 if (NextNode->Flags & ANOBJ_END_OF_PEER_LIST)
205 {
206 PrevNode->Flags |= ANOBJ_END_OF_PEER_LIST;
207 }
208 }
209 else
210 {
207 PrevNode->Peer = NextNode->Peer;
208 if (NextNode->Flags & ANOBJ_END_OF_PEER_LIST)
209 {
210 PrevNode->Flags |= ANOBJ_END_OF_PEER_LIST;
211 }
212 }
213 else
214 {
211 ParentNode->Child = NextNode->Peer;
215 /* Node is first child (has no previous peer) */
216
217 if (NextNode->Flags & ANOBJ_END_OF_PEER_LIST)
218 {
219 /* No peers at all */
220
221 ParentNode->Child = NULL;
222 }
223 else
224 { /* Link peer list to parent */
225
226 ParentNode->Child = NextNode->Peer;
227 }
212 }
213
214
215 ACPI_MEM_TRACKING (AcpiGbl_MemoryLists[ACPI_MEM_LIST_NSNODE].TotalFreed++);
216
217 /*
218 * Detach an object if there is one then delete the node
219 */
220 AcpiNsDetachObject (Node);
221 ACPI_MEM_FREE (Node);
222 return_VOID;
223}
224
225
226#ifdef ACPI_ALPHABETIC_NAMESPACE
227/*******************************************************************************
228 *
229 * FUNCTION: AcpiNsCompareNames
230 *
231 * PARAMETERS: Name1 - First name to compare
232 * Name2 - Second name to compare
233 *
234 * RETURN: value from strncmp
235 *
236 * DESCRIPTION: Compare two ACPI names. Names that are prefixed with an
237 * underscore are forced to be alphabetically first.
238 *
239 ******************************************************************************/
240
241int
242AcpiNsCompareNames (
243 char *Name1,
244 char *Name2)
245{
246 char ReversedName1[ACPI_NAME_SIZE];
247 char ReversedName2[ACPI_NAME_SIZE];
248 UINT32 i;
249 UINT32 j;
250
251
252 /*
253 * Replace all instances of "underscore" with a value that is smaller so
254 * that all names that are prefixed with underscore(s) are alphabetically
255 * first.
256 *
257 * Reverse the name bytewise so we can just do a 32-bit compare instead
258 * of a strncmp.
259 */
260 for (i = 0, j= (ACPI_NAME_SIZE - 1); i < ACPI_NAME_SIZE; i++, j--)
261 {
262 ReversedName1[j] = Name1[i];
263 if (Name1[i] == '_')
264 {
265 ReversedName1[j] = '*';
266 }
267
268 ReversedName2[j] = Name2[i];
269 if (Name2[i] == '_')
270 {
271 ReversedName2[j] = '*';
272 }
273 }
274
275 return (*(int *) ReversedName1 - *(int *) ReversedName2);
276}
277#endif
278
279
280/*******************************************************************************
281 *
282 * FUNCTION: AcpiNsInstallNode
283 *
284 * PARAMETERS: WalkState - Current state of the walk
285 * ParentNode - The parent of the new Node
286 * Node - The new Node to install
287 * Type - ACPI object type of the new Node
288 *
289 * RETURN: None
290 *
291 * DESCRIPTION: Initialize a new namespace node and install it amongst
292 * its peers.
293 *
294 * Note: Current namespace lookup is linear search. However, the
295 * nodes are linked in alphabetical order to 1) put all reserved
296 * names (start with underscore) first, and to 2) make a readable
297 * namespace dump.
298 *
299 ******************************************************************************/
300
301void
302AcpiNsInstallNode (
303 ACPI_WALK_STATE *WalkState,
304 ACPI_NAMESPACE_NODE *ParentNode, /* Parent */
305 ACPI_NAMESPACE_NODE *Node, /* New Child*/
306 ACPI_OBJECT_TYPE Type)
307{
228 }
229
230
231 ACPI_MEM_TRACKING (AcpiGbl_MemoryLists[ACPI_MEM_LIST_NSNODE].TotalFreed++);
232
233 /*
234 * Detach an object if there is one then delete the node
235 */
236 AcpiNsDetachObject (Node);
237 ACPI_MEM_FREE (Node);
238 return_VOID;
239}
240
241
242#ifdef ACPI_ALPHABETIC_NAMESPACE
243/*******************************************************************************
244 *
245 * FUNCTION: AcpiNsCompareNames
246 *
247 * PARAMETERS: Name1 - First name to compare
248 * Name2 - Second name to compare
249 *
250 * RETURN: value from strncmp
251 *
252 * DESCRIPTION: Compare two ACPI names. Names that are prefixed with an
253 * underscore are forced to be alphabetically first.
254 *
255 ******************************************************************************/
256
257int
258AcpiNsCompareNames (
259 char *Name1,
260 char *Name2)
261{
262 char ReversedName1[ACPI_NAME_SIZE];
263 char ReversedName2[ACPI_NAME_SIZE];
264 UINT32 i;
265 UINT32 j;
266
267
268 /*
269 * Replace all instances of "underscore" with a value that is smaller so
270 * that all names that are prefixed with underscore(s) are alphabetically
271 * first.
272 *
273 * Reverse the name bytewise so we can just do a 32-bit compare instead
274 * of a strncmp.
275 */
276 for (i = 0, j= (ACPI_NAME_SIZE - 1); i < ACPI_NAME_SIZE; i++, j--)
277 {
278 ReversedName1[j] = Name1[i];
279 if (Name1[i] == '_')
280 {
281 ReversedName1[j] = '*';
282 }
283
284 ReversedName2[j] = Name2[i];
285 if (Name2[i] == '_')
286 {
287 ReversedName2[j] = '*';
288 }
289 }
290
291 return (*(int *) ReversedName1 - *(int *) ReversedName2);
292}
293#endif
294
295
296/*******************************************************************************
297 *
298 * FUNCTION: AcpiNsInstallNode
299 *
300 * PARAMETERS: WalkState - Current state of the walk
301 * ParentNode - The parent of the new Node
302 * Node - The new Node to install
303 * Type - ACPI object type of the new Node
304 *
305 * RETURN: None
306 *
307 * DESCRIPTION: Initialize a new namespace node and install it amongst
308 * its peers.
309 *
310 * Note: Current namespace lookup is linear search. However, the
311 * nodes are linked in alphabetical order to 1) put all reserved
312 * names (start with underscore) first, and to 2) make a readable
313 * namespace dump.
314 *
315 ******************************************************************************/
316
317void
318AcpiNsInstallNode (
319 ACPI_WALK_STATE *WalkState,
320 ACPI_NAMESPACE_NODE *ParentNode, /* Parent */
321 ACPI_NAMESPACE_NODE *Node, /* New Child*/
322 ACPI_OBJECT_TYPE Type)
323{
308 UINT16 OwnerId = TABLE_ID_DSDT;
324 UINT16 OwnerId = 0;
309 ACPI_NAMESPACE_NODE *ChildNode;
310#ifdef ACPI_ALPHABETIC_NAMESPACE
311
312 ACPI_NAMESPACE_NODE *PreviousChildNode;
313#endif
314
315
316 ACPI_FUNCTION_TRACE ("NsInstallNode");
317
318
319 /*
320 * Get the owner ID from the Walk state
321 * The owner ID is used to track table deletion and
322 * deletion of objects created by methods
323 */
324 if (WalkState)
325 {
326 OwnerId = WalkState->OwnerId;
327 }
328
329 /* Link the new entry into the parent and existing children */
330
331 ChildNode = ParentNode->Child;
332 if (!ChildNode)
333 {
334 ParentNode->Child = Node;
335 Node->Flags |= ANOBJ_END_OF_PEER_LIST;
336 Node->Peer = ParentNode;
337 }
338 else
339 {
340#ifdef ACPI_ALPHABETIC_NAMESPACE
341 /*
342 * Walk the list whilst searching for the the correct
343 * alphabetic placement.
344 */
345 PreviousChildNode = NULL;
346 while (AcpiNsCompareNames (ChildNode->Name.Ascii, Node->Name.Ascii) < 0)
347 {
348 if (ChildNode->Flags & ANOBJ_END_OF_PEER_LIST)
349 {
350 /* Last peer; Clear end-of-list flag */
351
352 ChildNode->Flags &= ~ANOBJ_END_OF_PEER_LIST;
353
354 /* This node is the new peer to the child node */
355
356 ChildNode->Peer = Node;
357
358 /* This node is the new end-of-list */
359
360 Node->Flags |= ANOBJ_END_OF_PEER_LIST;
361 Node->Peer = ParentNode;
362 break;
363 }
364
365 /* Get next peer */
366
367 PreviousChildNode = ChildNode;
368 ChildNode = ChildNode->Peer;
369 }
370
371 /* Did the node get inserted at the end-of-list? */
372
373 if (!(Node->Flags & ANOBJ_END_OF_PEER_LIST))
374 {
375 /*
376 * Loop above terminated without reaching the end-of-list.
377 * Insert the new node at the current location
378 */
379 if (PreviousChildNode)
380 {
381 /* Insert node alphabetically */
382
383 Node->Peer = ChildNode;
384 PreviousChildNode->Peer = Node;
385 }
386 else
387 {
388 /* Insert node alphabetically at start of list */
389
390 Node->Peer = ChildNode;
391 ParentNode->Child = Node;
392 }
393 }
394#else
395 while (!(ChildNode->Flags & ANOBJ_END_OF_PEER_LIST))
396 {
397 ChildNode = ChildNode->Peer;
398 }
399
400 ChildNode->Peer = Node;
401
402 /* Clear end-of-list flag */
403
404 ChildNode->Flags &= ~ANOBJ_END_OF_PEER_LIST;
405 Node->Flags |= ANOBJ_END_OF_PEER_LIST;
406 Node->Peer = ParentNode;
407#endif
408 }
409
410 /* Init the new entry */
411
412 Node->OwnerId = OwnerId;
413 Node->Type = (UINT8) Type;
414
415 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%4.4s (%s) added to %4.4s (%s) %p at %p\n",
416 Node->Name.Ascii, AcpiUtGetTypeName (Node->Type),
417 ParentNode->Name.Ascii, AcpiUtGetTypeName (ParentNode->Type), ParentNode, Node));
418
419 /*
420 * Increment the reference count(s) of all parents up to
421 * the root!
422 */
423 while ((Node = AcpiNsGetParentNode (Node)) != NULL)
424 {
425 Node->ReferenceCount++;
426 }
427
428 return_VOID;
429}
430
431
432/*******************************************************************************
433 *
434 * FUNCTION: AcpiNsDeleteChildren
435 *
436 * PARAMETERS: ParentNode - Delete this objects children
437 *
438 * RETURN: None.
439 *
440 * DESCRIPTION: Delete all children of the parent object. In other words,
441 * deletes a "scope".
442 *
443 ******************************************************************************/
444
445void
446AcpiNsDeleteChildren (
447 ACPI_NAMESPACE_NODE *ParentNode)
448{
449 ACPI_NAMESPACE_NODE *ChildNode;
450 ACPI_NAMESPACE_NODE *NextNode;
325 ACPI_NAMESPACE_NODE *ChildNode;
326#ifdef ACPI_ALPHABETIC_NAMESPACE
327
328 ACPI_NAMESPACE_NODE *PreviousChildNode;
329#endif
330
331
332 ACPI_FUNCTION_TRACE ("NsInstallNode");
333
334
335 /*
336 * Get the owner ID from the Walk state
337 * The owner ID is used to track table deletion and
338 * deletion of objects created by methods
339 */
340 if (WalkState)
341 {
342 OwnerId = WalkState->OwnerId;
343 }
344
345 /* Link the new entry into the parent and existing children */
346
347 ChildNode = ParentNode->Child;
348 if (!ChildNode)
349 {
350 ParentNode->Child = Node;
351 Node->Flags |= ANOBJ_END_OF_PEER_LIST;
352 Node->Peer = ParentNode;
353 }
354 else
355 {
356#ifdef ACPI_ALPHABETIC_NAMESPACE
357 /*
358 * Walk the list whilst searching for the the correct
359 * alphabetic placement.
360 */
361 PreviousChildNode = NULL;
362 while (AcpiNsCompareNames (ChildNode->Name.Ascii, Node->Name.Ascii) < 0)
363 {
364 if (ChildNode->Flags & ANOBJ_END_OF_PEER_LIST)
365 {
366 /* Last peer; Clear end-of-list flag */
367
368 ChildNode->Flags &= ~ANOBJ_END_OF_PEER_LIST;
369
370 /* This node is the new peer to the child node */
371
372 ChildNode->Peer = Node;
373
374 /* This node is the new end-of-list */
375
376 Node->Flags |= ANOBJ_END_OF_PEER_LIST;
377 Node->Peer = ParentNode;
378 break;
379 }
380
381 /* Get next peer */
382
383 PreviousChildNode = ChildNode;
384 ChildNode = ChildNode->Peer;
385 }
386
387 /* Did the node get inserted at the end-of-list? */
388
389 if (!(Node->Flags & ANOBJ_END_OF_PEER_LIST))
390 {
391 /*
392 * Loop above terminated without reaching the end-of-list.
393 * Insert the new node at the current location
394 */
395 if (PreviousChildNode)
396 {
397 /* Insert node alphabetically */
398
399 Node->Peer = ChildNode;
400 PreviousChildNode->Peer = Node;
401 }
402 else
403 {
404 /* Insert node alphabetically at start of list */
405
406 Node->Peer = ChildNode;
407 ParentNode->Child = Node;
408 }
409 }
410#else
411 while (!(ChildNode->Flags & ANOBJ_END_OF_PEER_LIST))
412 {
413 ChildNode = ChildNode->Peer;
414 }
415
416 ChildNode->Peer = Node;
417
418 /* Clear end-of-list flag */
419
420 ChildNode->Flags &= ~ANOBJ_END_OF_PEER_LIST;
421 Node->Flags |= ANOBJ_END_OF_PEER_LIST;
422 Node->Peer = ParentNode;
423#endif
424 }
425
426 /* Init the new entry */
427
428 Node->OwnerId = OwnerId;
429 Node->Type = (UINT8) Type;
430
431 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%4.4s (%s) added to %4.4s (%s) %p at %p\n",
432 Node->Name.Ascii, AcpiUtGetTypeName (Node->Type),
433 ParentNode->Name.Ascii, AcpiUtGetTypeName (ParentNode->Type), ParentNode, Node));
434
435 /*
436 * Increment the reference count(s) of all parents up to
437 * the root!
438 */
439 while ((Node = AcpiNsGetParentNode (Node)) != NULL)
440 {
441 Node->ReferenceCount++;
442 }
443
444 return_VOID;
445}
446
447
448/*******************************************************************************
449 *
450 * FUNCTION: AcpiNsDeleteChildren
451 *
452 * PARAMETERS: ParentNode - Delete this objects children
453 *
454 * RETURN: None.
455 *
456 * DESCRIPTION: Delete all children of the parent object. In other words,
457 * deletes a "scope".
458 *
459 ******************************************************************************/
460
461void
462AcpiNsDeleteChildren (
463 ACPI_NAMESPACE_NODE *ParentNode)
464{
465 ACPI_NAMESPACE_NODE *ChildNode;
466 ACPI_NAMESPACE_NODE *NextNode;
467 ACPI_NAMESPACE_NODE *Node;
451 UINT8 Flags;
452
453
454 ACPI_FUNCTION_TRACE_PTR ("NsDeleteChildren", ParentNode);
455
456
457 if (!ParentNode)
458 {
459 return_VOID;
460 }
461
462 /* If no children, all done! */
463
464 ChildNode = ParentNode->Child;
465 if (!ChildNode)
466 {
467 return_VOID;
468 }
469
470 /*
471 * Deallocate all children at this level
472 */
473 do
474 {
475 /* Get the things we need */
476
477 NextNode = ChildNode->Peer;
478 Flags = ChildNode->Flags;
479
480 /* Grandchildren should have all been deleted already */
481
482 if (ChildNode->Child)
483 {
484 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Found a grandchild! P=%p C=%p\n",
485 ParentNode, ChildNode));
486 }
487
488 /* Now we can free this child object */
489
490 ACPI_MEM_TRACKING (AcpiGbl_MemoryLists[ACPI_MEM_LIST_NSNODE].TotalFreed++);
491
492 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Object %p, Remaining %X\n",
493 ChildNode, AcpiGbl_CurrentNodeCount));
494
495 /*
496 * Detach an object if there is one, then free the child node
497 */
498 AcpiNsDetachObject (ChildNode);
468 UINT8 Flags;
469
470
471 ACPI_FUNCTION_TRACE_PTR ("NsDeleteChildren", ParentNode);
472
473
474 if (!ParentNode)
475 {
476 return_VOID;
477 }
478
479 /* If no children, all done! */
480
481 ChildNode = ParentNode->Child;
482 if (!ChildNode)
483 {
484 return_VOID;
485 }
486
487 /*
488 * Deallocate all children at this level
489 */
490 do
491 {
492 /* Get the things we need */
493
494 NextNode = ChildNode->Peer;
495 Flags = ChildNode->Flags;
496
497 /* Grandchildren should have all been deleted already */
498
499 if (ChildNode->Child)
500 {
501 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Found a grandchild! P=%p C=%p\n",
502 ParentNode, ChildNode));
503 }
504
505 /* Now we can free this child object */
506
507 ACPI_MEM_TRACKING (AcpiGbl_MemoryLists[ACPI_MEM_LIST_NSNODE].TotalFreed++);
508
509 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Object %p, Remaining %X\n",
510 ChildNode, AcpiGbl_CurrentNodeCount));
511
512 /*
513 * Detach an object if there is one, then free the child node
514 */
515 AcpiNsDetachObject (ChildNode);
516
517 /*
518 * Decrement the reference count(s) of all parents up to
519 * the root! (counts were incremented when the node was created)
520 */
521 Node = ChildNode;
522 while ((Node = AcpiNsGetParentNode (Node)) != NULL)
523 {
524 Node->ReferenceCount--;
525 }
526
527 /* There should be only one reference remaining on this node */
528
529 if (ChildNode->ReferenceCount != 1)
530 {
531 ACPI_REPORT_WARNING (("Existing references (%d) on node being deleted (%p)\n",
532 ChildNode->ReferenceCount, ChildNode));
533 }
534
535 /* Now we can delete the node */
536
499 ACPI_MEM_FREE (ChildNode);
500
501 /* And move on to the next child in the list */
502
503 ChildNode = NextNode;
504
505 } while (!(Flags & ANOBJ_END_OF_PEER_LIST));
506
507
508 /* Clear the parent's child pointer */
509
510 ParentNode->Child = NULL;
511
512 return_VOID;
513}
514
515
516/*******************************************************************************
517 *
518 * FUNCTION: AcpiNsDeleteNamespaceSubtree
519 *
520 * PARAMETERS: ParentNode - Root of the subtree to be deleted
521 *
522 * RETURN: None.
523 *
524 * DESCRIPTION: Delete a subtree of the namespace. This includes all objects
525 * stored within the subtree.
526 *
527 ******************************************************************************/
528
529void
530AcpiNsDeleteNamespaceSubtree (
531 ACPI_NAMESPACE_NODE *ParentNode)
532{
533 ACPI_NAMESPACE_NODE *ChildNode = NULL;
534 UINT32 Level = 1;
535
536
537 ACPI_FUNCTION_TRACE ("NsDeleteNamespaceSubtree");
538
539
540 if (!ParentNode)
541 {
542 return_VOID;
543 }
544
545 /*
546 * Traverse the tree of objects until we bubble back up
547 * to where we started.
548 */
549 while (Level > 0)
550 {
551 /* Get the next node in this scope (NULL if none) */
552
553 ChildNode = AcpiNsGetNextNode (ACPI_TYPE_ANY, ParentNode,
554 ChildNode);
555 if (ChildNode)
556 {
557 /* Found a child node - detach any attached object */
558
559 AcpiNsDetachObject (ChildNode);
560
561 /* Check if this node has any children */
562
563 if (AcpiNsGetNextNode (ACPI_TYPE_ANY, ChildNode, 0))
564 {
565 /*
566 * There is at least one child of this node,
567 * visit the node
568 */
569 Level++;
570 ParentNode = ChildNode;
571 ChildNode = 0;
572 }
573 }
574 else
575 {
576 /*
577 * No more children of this parent node.
578 * Move up to the grandparent.
579 */
580 Level--;
581
582 /*
583 * Now delete all of the children of this parent
584 * all at the same time.
585 */
586 AcpiNsDeleteChildren (ParentNode);
587
588 /* New "last child" is this parent node */
589
590 ChildNode = ParentNode;
591
592 /* Move up the tree to the grandparent */
593
594 ParentNode = AcpiNsGetParentNode (ParentNode);
595 }
596 }
597
598 return_VOID;
599}
600
601
602/*******************************************************************************
603 *
604 * FUNCTION: AcpiNsRemoveReference
605 *
606 * PARAMETERS: Node - Named node whose reference count is to be
607 * decremented
608 *
609 * RETURN: None.
610 *
611 * DESCRIPTION: Remove a Node reference. Decrements the reference count
612 * of all parent Nodes up to the root. Any node along
613 * the way that reaches zero references is freed.
614 *
615 ******************************************************************************/
616
537 ACPI_MEM_FREE (ChildNode);
538
539 /* And move on to the next child in the list */
540
541 ChildNode = NextNode;
542
543 } while (!(Flags & ANOBJ_END_OF_PEER_LIST));
544
545
546 /* Clear the parent's child pointer */
547
548 ParentNode->Child = NULL;
549
550 return_VOID;
551}
552
553
554/*******************************************************************************
555 *
556 * FUNCTION: AcpiNsDeleteNamespaceSubtree
557 *
558 * PARAMETERS: ParentNode - Root of the subtree to be deleted
559 *
560 * RETURN: None.
561 *
562 * DESCRIPTION: Delete a subtree of the namespace. This includes all objects
563 * stored within the subtree.
564 *
565 ******************************************************************************/
566
567void
568AcpiNsDeleteNamespaceSubtree (
569 ACPI_NAMESPACE_NODE *ParentNode)
570{
571 ACPI_NAMESPACE_NODE *ChildNode = NULL;
572 UINT32 Level = 1;
573
574
575 ACPI_FUNCTION_TRACE ("NsDeleteNamespaceSubtree");
576
577
578 if (!ParentNode)
579 {
580 return_VOID;
581 }
582
583 /*
584 * Traverse the tree of objects until we bubble back up
585 * to where we started.
586 */
587 while (Level > 0)
588 {
589 /* Get the next node in this scope (NULL if none) */
590
591 ChildNode = AcpiNsGetNextNode (ACPI_TYPE_ANY, ParentNode,
592 ChildNode);
593 if (ChildNode)
594 {
595 /* Found a child node - detach any attached object */
596
597 AcpiNsDetachObject (ChildNode);
598
599 /* Check if this node has any children */
600
601 if (AcpiNsGetNextNode (ACPI_TYPE_ANY, ChildNode, 0))
602 {
603 /*
604 * There is at least one child of this node,
605 * visit the node
606 */
607 Level++;
608 ParentNode = ChildNode;
609 ChildNode = 0;
610 }
611 }
612 else
613 {
614 /*
615 * No more children of this parent node.
616 * Move up to the grandparent.
617 */
618 Level--;
619
620 /*
621 * Now delete all of the children of this parent
622 * all at the same time.
623 */
624 AcpiNsDeleteChildren (ParentNode);
625
626 /* New "last child" is this parent node */
627
628 ChildNode = ParentNode;
629
630 /* Move up the tree to the grandparent */
631
632 ParentNode = AcpiNsGetParentNode (ParentNode);
633 }
634 }
635
636 return_VOID;
637}
638
639
640/*******************************************************************************
641 *
642 * FUNCTION: AcpiNsRemoveReference
643 *
644 * PARAMETERS: Node - Named node whose reference count is to be
645 * decremented
646 *
647 * RETURN: None.
648 *
649 * DESCRIPTION: Remove a Node reference. Decrements the reference count
650 * of all parent Nodes up to the root. Any node along
651 * the way that reaches zero references is freed.
652 *
653 ******************************************************************************/
654
617static void
655void
618AcpiNsRemoveReference (
619 ACPI_NAMESPACE_NODE *Node)
620{
621 ACPI_NAMESPACE_NODE *ParentNode;
622 ACPI_NAMESPACE_NODE *ThisNode;
623
624
625 ACPI_FUNCTION_ENTRY ();
626
627
628 /*
629 * Decrement the reference count(s) of this node and all
630 * nodes up to the root, Delete anything with zero remaining references.
631 */
632 ThisNode = Node;
633 while (ThisNode)
634 {
635 /* Prepare to move up to parent */
636
637 ParentNode = AcpiNsGetParentNode (ThisNode);
638
639 /* Decrement the reference count on this node */
640
641 ThisNode->ReferenceCount--;
642
643 /* Delete the node if no more references */
644
645 if (!ThisNode->ReferenceCount)
646 {
647 /* Delete all children and delete the node */
648
649 AcpiNsDeleteChildren (ThisNode);
650 AcpiNsDeleteNode (ThisNode);
651 }
652
653 ThisNode = ParentNode;
654 }
655}
656
657
658/*******************************************************************************
659 *
660 * FUNCTION: AcpiNsDeleteNamespaceByOwner
661 *
662 * PARAMETERS: OwnerId - All nodes with this owner will be deleted
663 *
664 * RETURN: Status
665 *
666 * DESCRIPTION: Delete entries within the namespace that are owned by a
667 * specific ID. Used to delete entire ACPI tables. All
668 * reference counts are updated.
669 *
670 ******************************************************************************/
671
672void
673AcpiNsDeleteNamespaceByOwner (
674 UINT16 OwnerId)
675{
676 ACPI_NAMESPACE_NODE *ChildNode;
677 ACPI_NAMESPACE_NODE *DeletionNode;
678 UINT32 Level;
679 ACPI_NAMESPACE_NODE *ParentNode;
680
681
682 ACPI_FUNCTION_TRACE_U32 ("NsDeleteNamespaceByOwner", OwnerId);
683
684
685 ParentNode = AcpiGbl_RootNode;
686 ChildNode = NULL;
687 DeletionNode = NULL;
688 Level = 1;
689
690 /*
691 * Traverse the tree of nodes until we bubble back up
692 * to where we started.
693 */
694 while (Level > 0)
695 {
696 /*
697 * Get the next child of this parent node. When ChildNode is NULL,
698 * the first child of the parent is returned
699 */
700 ChildNode = AcpiNsGetNextNode (ACPI_TYPE_ANY, ParentNode, ChildNode);
701
702 if (DeletionNode)
703 {
704 AcpiNsRemoveReference (DeletionNode);
705 DeletionNode = NULL;
706 }
707
708 if (ChildNode)
709 {
710 if (ChildNode->OwnerId == OwnerId)
711 {
712 /* Found a matching child node - detach any attached object */
713
714 AcpiNsDetachObject (ChildNode);
715 }
716
717 /* Check if this node has any children */
718
719 if (AcpiNsGetNextNode (ACPI_TYPE_ANY, ChildNode, NULL))
720 {
721 /*
722 * There is at least one child of this node,
723 * visit the node
724 */
725 Level++;
726 ParentNode = ChildNode;
727 ChildNode = NULL;
728 }
729 else if (ChildNode->OwnerId == OwnerId)
730 {
731 DeletionNode = ChildNode;
732 }
733 }
734 else
735 {
736 /*
737 * No more children of this parent node.
738 * Move up to the grandparent.
739 */
740 Level--;
741 if (Level != 0)
742 {
743 if (ParentNode->OwnerId == OwnerId)
744 {
745 DeletionNode = ParentNode;
746 }
747 }
748
749 /* New "last child" is this parent node */
750
751 ChildNode = ParentNode;
752
753 /* Move up the tree to the grandparent */
754
755 ParentNode = AcpiNsGetParentNode (ParentNode);
756 }
757 }
758
759 return_VOID;
760}
761
762
656AcpiNsRemoveReference (
657 ACPI_NAMESPACE_NODE *Node)
658{
659 ACPI_NAMESPACE_NODE *ParentNode;
660 ACPI_NAMESPACE_NODE *ThisNode;
661
662
663 ACPI_FUNCTION_ENTRY ();
664
665
666 /*
667 * Decrement the reference count(s) of this node and all
668 * nodes up to the root, Delete anything with zero remaining references.
669 */
670 ThisNode = Node;
671 while (ThisNode)
672 {
673 /* Prepare to move up to parent */
674
675 ParentNode = AcpiNsGetParentNode (ThisNode);
676
677 /* Decrement the reference count on this node */
678
679 ThisNode->ReferenceCount--;
680
681 /* Delete the node if no more references */
682
683 if (!ThisNode->ReferenceCount)
684 {
685 /* Delete all children and delete the node */
686
687 AcpiNsDeleteChildren (ThisNode);
688 AcpiNsDeleteNode (ThisNode);
689 }
690
691 ThisNode = ParentNode;
692 }
693}
694
695
696/*******************************************************************************
697 *
698 * FUNCTION: AcpiNsDeleteNamespaceByOwner
699 *
700 * PARAMETERS: OwnerId - All nodes with this owner will be deleted
701 *
702 * RETURN: Status
703 *
704 * DESCRIPTION: Delete entries within the namespace that are owned by a
705 * specific ID. Used to delete entire ACPI tables. All
706 * reference counts are updated.
707 *
708 ******************************************************************************/
709
710void
711AcpiNsDeleteNamespaceByOwner (
712 UINT16 OwnerId)
713{
714 ACPI_NAMESPACE_NODE *ChildNode;
715 ACPI_NAMESPACE_NODE *DeletionNode;
716 UINT32 Level;
717 ACPI_NAMESPACE_NODE *ParentNode;
718
719
720 ACPI_FUNCTION_TRACE_U32 ("NsDeleteNamespaceByOwner", OwnerId);
721
722
723 ParentNode = AcpiGbl_RootNode;
724 ChildNode = NULL;
725 DeletionNode = NULL;
726 Level = 1;
727
728 /*
729 * Traverse the tree of nodes until we bubble back up
730 * to where we started.
731 */
732 while (Level > 0)
733 {
734 /*
735 * Get the next child of this parent node. When ChildNode is NULL,
736 * the first child of the parent is returned
737 */
738 ChildNode = AcpiNsGetNextNode (ACPI_TYPE_ANY, ParentNode, ChildNode);
739
740 if (DeletionNode)
741 {
742 AcpiNsRemoveReference (DeletionNode);
743 DeletionNode = NULL;
744 }
745
746 if (ChildNode)
747 {
748 if (ChildNode->OwnerId == OwnerId)
749 {
750 /* Found a matching child node - detach any attached object */
751
752 AcpiNsDetachObject (ChildNode);
753 }
754
755 /* Check if this node has any children */
756
757 if (AcpiNsGetNextNode (ACPI_TYPE_ANY, ChildNode, NULL))
758 {
759 /*
760 * There is at least one child of this node,
761 * visit the node
762 */
763 Level++;
764 ParentNode = ChildNode;
765 ChildNode = NULL;
766 }
767 else if (ChildNode->OwnerId == OwnerId)
768 {
769 DeletionNode = ChildNode;
770 }
771 }
772 else
773 {
774 /*
775 * No more children of this parent node.
776 * Move up to the grandparent.
777 */
778 Level--;
779 if (Level != 0)
780 {
781 if (ParentNode->OwnerId == OwnerId)
782 {
783 DeletionNode = ParentNode;
784 }
785 }
786
787 /* New "last child" is this parent node */
788
789 ChildNode = ParentNode;
790
791 /* Move up the tree to the grandparent */
792
793 ParentNode = AcpiNsGetParentNode (ParentNode);
794 }
795 }
796
797 return_VOID;
798}
799
800