ReactOS 0.4.15-dev-8100-g1887773
excreate.c
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Module Name: excreate - Named object creation
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2022, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#include "acpi.h"
45#include "accommon.h"
46#include "acinterp.h"
47#include "amlcode.h"
48#include "acnamesp.h"
49
50
51#define _COMPONENT ACPI_EXECUTER
52 ACPI_MODULE_NAME ("excreate")
53
54
55/*******************************************************************************
56 *
57 * FUNCTION: AcpiExCreateAlias
58 *
59 * PARAMETERS: WalkState - Current state, contains operands
60 *
61 * RETURN: Status
62 *
63 * DESCRIPTION: Create a new named alias
64 *
65 ******************************************************************************/
66
69 ACPI_WALK_STATE *WalkState)
70{
71 ACPI_NAMESPACE_NODE *TargetNode;
72 ACPI_NAMESPACE_NODE *AliasNode;
74
75
76 ACPI_FUNCTION_TRACE (ExCreateAlias);
77
78
79 /* Get the source/alias operands (both namespace nodes) */
80
81 AliasNode = (ACPI_NAMESPACE_NODE *) WalkState->Operands[0];
82 TargetNode = (ACPI_NAMESPACE_NODE *) WalkState->Operands[1];
83
84 if ((TargetNode->Type == ACPI_TYPE_LOCAL_ALIAS) ||
85 (TargetNode->Type == ACPI_TYPE_LOCAL_METHOD_ALIAS))
86 {
87 /*
88 * Dereference an existing alias so that we don't create a chain
89 * of aliases. With this code, we guarantee that an alias is
90 * always exactly one level of indirection away from the
91 * actual aliased name.
92 */
93 TargetNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, TargetNode->Object);
94 }
95
96 /* Ensure that the target node is valid */
97
98 if (!TargetNode)
99 {
101 }
102
103 /* Construct the alias object (a namespace node) */
104
105 switch (TargetNode->Type)
106 {
107 case ACPI_TYPE_METHOD:
108 /*
109 * Control method aliases need to be differentiated with
110 * a special type
111 */
113 break;
114
115 default:
116 /*
117 * All other object types.
118 *
119 * The new alias has the type ALIAS and points to the original
120 * NS node, not the object itself.
121 */
122 AliasNode->Type = ACPI_TYPE_LOCAL_ALIAS;
123 AliasNode->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);
124 break;
125 }
126
127 /* Since both operands are Nodes, we don't need to delete them */
128
129 AliasNode->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);
131}
132
133
134/*******************************************************************************
135 *
136 * FUNCTION: AcpiExCreateEvent
137 *
138 * PARAMETERS: WalkState - Current state
139 *
140 * RETURN: Status
141 *
142 * DESCRIPTION: Create a new event object
143 *
144 ******************************************************************************/
145
148 ACPI_WALK_STATE *WalkState)
149{
151 ACPI_OPERAND_OBJECT *ObjDesc;
152
153
154 ACPI_FUNCTION_TRACE (ExCreateEvent);
155
156
158 if (!ObjDesc)
159 {
161 goto Cleanup;
162 }
163
164 /*
165 * Create the actual OS semaphore, with zero initial units -- meaning
166 * that the event is created in an unsignalled state
167 */
169 &ObjDesc->Event.OsSemaphore);
170 if (ACPI_FAILURE (Status))
171 {
172 goto Cleanup;
173 }
174
175 /* Attach object to the Node */
176
178 (ACPI_NAMESPACE_NODE *) WalkState->Operands[0],
179 ObjDesc, ACPI_TYPE_EVENT);
180
181Cleanup:
182 /*
183 * Remove local reference to the object (on error, will cause deletion
184 * of both object and semaphore if present.)
185 */
186 AcpiUtRemoveReference (ObjDesc);
188}
189
190
191/*******************************************************************************
192 *
193 * FUNCTION: AcpiExCreateMutex
194 *
195 * PARAMETERS: WalkState - Current state
196 *
197 * RETURN: Status
198 *
199 * DESCRIPTION: Create a new mutex object
200 *
201 * Mutex (Name[0], SyncLevel[1])
202 *
203 ******************************************************************************/
204
207 ACPI_WALK_STATE *WalkState)
208{
210 ACPI_OPERAND_OBJECT *ObjDesc;
211
212
214
215
216 /* Create the new mutex object */
217
219 if (!ObjDesc)
220 {
222 goto Cleanup;
223 }
224
225 /* Create the actual OS Mutex */
226
228 if (ACPI_FAILURE (Status))
229 {
230 goto Cleanup;
231 }
232
233 /* Init object and attach to NS node */
234
235 ObjDesc->Mutex.SyncLevel = (UINT8) WalkState->Operands[1]->Integer.Value;
236 ObjDesc->Mutex.Node = (ACPI_NAMESPACE_NODE *) WalkState->Operands[0];
237
239 ObjDesc->Mutex.Node, ObjDesc, ACPI_TYPE_MUTEX);
240
241
242Cleanup:
243 /*
244 * Remove local reference to the object (on error, will cause deletion
245 * of both object and semaphore if present.)
246 */
247 AcpiUtRemoveReference (ObjDesc);
249}
250
251
252/*******************************************************************************
253 *
254 * FUNCTION: AcpiExCreateRegion
255 *
256 * PARAMETERS: AmlStart - Pointer to the region declaration AML
257 * AmlLength - Max length of the declaration AML
258 * SpaceId - Address space ID for the region
259 * WalkState - Current state
260 *
261 * RETURN: Status
262 *
263 * DESCRIPTION: Create a new operation region object
264 *
265 ******************************************************************************/
266
269 UINT8 *AmlStart,
270 UINT32 AmlLength,
272 ACPI_WALK_STATE *WalkState)
273{
275 ACPI_OPERAND_OBJECT *ObjDesc;
277 ACPI_OPERAND_OBJECT *RegionObj2;
278
279
280 ACPI_FUNCTION_TRACE (ExCreateRegion);
281
282
283 /* Get the Namespace Node */
284
285 Node = WalkState->Op->Common.Node;
286
287 /*
288 * If the region object is already attached to this node,
289 * just return
290 */
292 {
294 }
295
296 /*
297 * Space ID must be one of the predefined IDs, or in the user-defined
298 * range
299 */
301 {
302 /*
303 * Print an error message, but continue. We don't want to abort
304 * a table load for this exception. Instead, if the region is
305 * actually used at runtime, abort the executing method.
306 */
308 "Invalid/unknown Address Space ID: 0x%2.2X", SpaceId));
309 }
310
311 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "Region Type - %s (0x%X)\n",
313
314 /* Create the region descriptor */
315
317 if (!ObjDesc)
318 {
320 goto Cleanup;
321 }
322
323 /*
324 * Remember location in AML stream of address & length
325 * operands since they need to be evaluated at run time.
326 */
327 RegionObj2 = AcpiNsGetSecondaryObject (ObjDesc);
328 RegionObj2->Extra.AmlStart = AmlStart;
329 RegionObj2->Extra.AmlLength = AmlLength;
330 RegionObj2->Extra.Method_REG = NULL;
331 if (WalkState->ScopeInfo)
332 {
333 RegionObj2->Extra.ScopeNode = WalkState->ScopeInfo->Scope.Node;
334 }
335 else
336 {
337 RegionObj2->Extra.ScopeNode = Node;
338 }
339
340 /* Init the region from the operands */
341
342 ObjDesc->Region.SpaceId = SpaceId;
343 ObjDesc->Region.Address = 0;
344 ObjDesc->Region.Length = 0;
345 ObjDesc->Region.Pointer = NULL;
346 ObjDesc->Region.Node = Node;
347 ObjDesc->Region.Handler = NULL;
348 ObjDesc->Common.Flags &=
351
352 /* Install the new region object in the parent Node */
353
355
356
357Cleanup:
358
359 /* Remove local reference to the object */
360
361 AcpiUtRemoveReference (ObjDesc);
363}
364
365
366/*******************************************************************************
367 *
368 * FUNCTION: AcpiExCreateProcessor
369 *
370 * PARAMETERS: WalkState - Current state
371 *
372 * RETURN: Status
373 *
374 * DESCRIPTION: Create a new processor object and populate the fields
375 *
376 * Processor (Name[0], CpuID[1], PblockAddr[2], PblockLength[3])
377 *
378 ******************************************************************************/
379
382 ACPI_WALK_STATE *WalkState)
383{
384 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
385 ACPI_OPERAND_OBJECT *ObjDesc;
387
388
389 ACPI_FUNCTION_TRACE_PTR (ExCreateProcessor, WalkState);
390
391
392 /* Create the processor object */
393
395 if (!ObjDesc)
396 {
398 }
399
400 /* Initialize the processor object from the operands */
401
402 ObjDesc->Processor.ProcId = (UINT8) Operand[1]->Integer.Value;
403 ObjDesc->Processor.Length = (UINT8) Operand[3]->Integer.Value;
404 ObjDesc->Processor.Address = (ACPI_IO_ADDRESS) Operand[2]->Integer.Value;
405
406 /* Install the processor object in the parent Node */
407
409 ObjDesc, ACPI_TYPE_PROCESSOR);
410
411 /* Remove local reference to the object */
412
413 AcpiUtRemoveReference (ObjDesc);
415}
416
417
418/*******************************************************************************
419 *
420 * FUNCTION: AcpiExCreatePowerResource
421 *
422 * PARAMETERS: WalkState - Current state
423 *
424 * RETURN: Status
425 *
426 * DESCRIPTION: Create a new PowerResource object and populate the fields
427 *
428 * PowerResource (Name[0], SystemLevel[1], ResourceOrder[2])
429 *
430 ******************************************************************************/
431
434 ACPI_WALK_STATE *WalkState)
435{
436 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
438 ACPI_OPERAND_OBJECT *ObjDesc;
439
440
441 ACPI_FUNCTION_TRACE_PTR (ExCreatePowerResource, WalkState);
442
443
444 /* Create the power resource object */
445
447 if (!ObjDesc)
448 {
450 }
451
452 /* Initialize the power object from the operands */
453
454 ObjDesc->PowerResource.SystemLevel = (UINT8) Operand[1]->Integer.Value;
455 ObjDesc->PowerResource.ResourceOrder = (UINT16) Operand[2]->Integer.Value;
456
457 /* Install the power resource object in the parent Node */
458
460 ObjDesc, ACPI_TYPE_POWER);
461
462 /* Remove local reference to the object */
463
464 AcpiUtRemoveReference (ObjDesc);
466}
467
468
469/*******************************************************************************
470 *
471 * FUNCTION: AcpiExCreateMethod
472 *
473 * PARAMETERS: AmlStart - First byte of the method's AML
474 * AmlLength - AML byte count for this method
475 * WalkState - Current state
476 *
477 * RETURN: Status
478 *
479 * DESCRIPTION: Create a new method object
480 *
481 ******************************************************************************/
482
485 UINT8 *AmlStart,
486 UINT32 AmlLength,
487 ACPI_WALK_STATE *WalkState)
488{
489 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
490 ACPI_OPERAND_OBJECT *ObjDesc;
492 UINT8 MethodFlags;
493
494
495 ACPI_FUNCTION_TRACE_PTR (ExCreateMethod, WalkState);
496
497
498 /* Create a new method object */
499
501 if (!ObjDesc)
502 {
504 goto Exit;
505 }
506
507 /* Save the method's AML pointer and length */
508
509 ObjDesc->Method.AmlStart = AmlStart;
510 ObjDesc->Method.AmlLength = AmlLength;
511 ObjDesc->Method.Node = Operand[0];
512
513 /*
514 * Disassemble the method flags. Split off the ArgCount, Serialized
515 * flag, and SyncLevel for efficiency.
516 */
517 MethodFlags = (UINT8) Operand[1]->Integer.Value;
518 ObjDesc->Method.ParamCount = (UINT8)
519 (MethodFlags & AML_METHOD_ARG_COUNT);
520
521 /*
522 * Get the SyncLevel. If method is serialized, a mutex will be
523 * created for this method when it is parsed.
524 */
525 if (MethodFlags & AML_METHOD_SERIALIZED)
526 {
528
529 /*
530 * ACPI 1.0: SyncLevel = 0
531 * ACPI 2.0: SyncLevel = SyncLevel in method declaration
532 */
533 ObjDesc->Method.SyncLevel = (UINT8)
534 ((MethodFlags & AML_METHOD_SYNC_LEVEL) >> 4);
535 }
536
537 /* Attach the new object to the method Node */
538
540 ObjDesc, ACPI_TYPE_METHOD);
541
542 /* Remove local reference to the object */
543
544 AcpiUtRemoveReference (ObjDesc);
545
546Exit:
547 /* Remove a reference to the operand */
548
549 AcpiUtRemoveReference (Operand[1]);
551}
unsigned short UINT16
unsigned char UINT8
unsigned int UINT32
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define AE_NULL_OBJECT
Definition: acexcep.h:117
#define AE_NO_MEMORY
Definition: acexcep.h:112
#define AE_OK
Definition: acexcep.h:97
#define ACPI_WALK_OPERANDS
Definition: acinterp.h:48
ACPI_OPERAND_OBJECT * AcpiNsGetSecondaryObject(ACPI_OPERAND_OBJECT *ObjDesc)
Definition: nsobject.c:346
ACPI_OPERAND_OBJECT * AcpiNsGetAttachedObject(ACPI_NAMESPACE_NODE *Node)
Definition: nsobject.c:308
ACPI_STATUS AcpiNsAttachObject(ACPI_NAMESPACE_NODE *Node, ACPI_OPERAND_OBJECT *Object, ACPI_OBJECT_TYPE Type)
Definition: nsobject.c:76
#define AOPOBJ_REG_CONNECTED
Definition: acobject.h:98
#define AOPOBJ_OBJECT_INITIALIZED
Definition: acobject.h:97
#define AOPOBJ_SETUP_COMPLETE
Definition: acobject.h:99
#define ACPI_METHOD_SERIALIZED
Definition: acobject.h:238
#define ACPI_DEBUG_PRINT(pl)
Definition: acoutput.h:475
#define ACPI_MODULE_NAME(Name)
Definition: acoutput.h:216
#define ACPI_FUNCTION_TRACE_PTR(a, b)
Definition: acoutput.h:481
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
#define ACPI_ERROR(plist)
Definition: acoutput.h:240
#define ACPI_DB_LOAD
Definition: acoutput.h:164
#define AE_INFO
Definition: acoutput.h:230
ACPI_STATUS AcpiOsCreateSemaphore(UINT32 MaxUnits, UINT32 InitialUnits, ACPI_SEMAPHORE *OutHandle)
Definition: osl.c:352
#define ACPI_NO_UNIT_LIMIT
Definition: acpiosxf.h:67
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn UINT32 *TableIdx UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE ACPI_HANDLE ACPI_HANDLE *OutHandle ACPI_HANDLE *OutHandle void *Context void *Context ACPI_EVENT_HANDLER Handler UINT32 UINT32 ACPI_GPE_HANDLER void *Context UINT32 ACPI_NOTIFY_HANDLER void *Context ACPI_ADR_SPACE_TYPE SpaceId
Definition: acpixf.h:832
#define ACPI_TYPE_EVENT
Definition: actypes.h:694
#define ACPI_TYPE_PROCESSOR
Definition: actypes.h:699
#define ACPI_TYPE_MUTEX
Definition: actypes.h:696
#define ACPI_TYPE_LOCAL_ALIAS
Definition: actypes.h:720
#define ACPI_TYPE_REGION
Definition: actypes.h:697
#define ACPI_TYPE_POWER
Definition: actypes.h:698
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_CAST_PTR(t, p)
Definition: actypes.h:544
#define ACPI_TYPE_LOCAL_METHOD_ALIAS
Definition: actypes.h:721
#define AcpiOsCreateMutex(OutHandle)
Definition: actypes.h:274
#define ACPI_TYPE_METHOD
Definition: actypes.h:695
#define AcpiUtCreateInternalObject(t)
Definition: acutils.h:681
const char * AcpiUtGetRegionName(UINT8 SpaceId)
Definition: utdecode.c:125
void AcpiUtRemoveReference(ACPI_OPERAND_OBJECT *Object)
Definition: utdelete.c:790
#define AML_METHOD_ARG_COUNT
Definition: amlcode.h:505
#define AML_METHOD_SERIALIZED
Definition: amlcode.h:506
#define AML_METHOD_SYNC_LEVEL
Definition: amlcode.h:507
#define NULL
Definition: types.h:112
union node Node
Definition: types.h:1255
static const WCHAR Cleanup[]
Definition: register.c:80
ACPI_STATUS AcpiExCreateRegion(UINT8 *AmlStart, UINT32 AmlLength, UINT8 SpaceId, ACPI_WALK_STATE *WalkState)
Definition: excreate.c:268
ACPI_STATUS AcpiExCreateAlias(ACPI_WALK_STATE *WalkState)
Definition: excreate.c:68
ACPI_STATUS AcpiExCreateMutex(ACPI_WALK_STATE *WalkState)
Definition: excreate.c:206
ACPI_STATUS AcpiExCreateEvent(ACPI_WALK_STATE *WalkState)
Definition: excreate.c:147
ACPI_STATUS AcpiExCreateProcessor(ACPI_WALK_STATE *WalkState)
Definition: excreate.c:381
ACPI_STATUS AcpiExCreatePowerResource(ACPI_WALK_STATE *WalkState)
Definition: excreate.c:433
ACPI_STATUS AcpiExCreateMethod(UINT8 *AmlStart, UINT32 AmlLength, ACPI_WALK_STATE *WalkState)
Definition: excreate.c:484
BOOLEAN AcpiIsValidSpaceId(UINT8 SpaceId)
Definition: exutils.c:494
Status
Definition: gdiplustypes.h:25
static void Exit(void)
Definition: sock.c:1330
union acpi_operand_object * Object
Definition: aclocal.h:187
ACPI_OBJECT_COMMON_HEADER ACPI_SEMAPHORE OsSemaphore
Definition: acobject.h:178
ACPI_OBJECT_COMMON_HEADER ACPI_NAMESPACE_NODE * Method_REG
Definition: acobject.h:481
UINT32 AmlLength
Definition: acobject.h:485
ACPI_NAMESPACE_NODE * ScopeNode
Definition: acobject.h:482
UINT8 * AmlStart
Definition: acobject.h:484
UINT8 * AmlStart
Definition: acobject.h:221
ACPI_OBJECT_COMMON_HEADER UINT8 InfoFlags
Definition: acobject.h:216
union acpi_operand_object * Node
Definition: acobject.h:220
ACPI_OBJECT_COMMON_HEADER UINT8 SyncLevel
Definition: acobject.h:186
ACPI_NAMESPACE_NODE * Node
Definition: acobject.h:193
ACPI_MUTEX OsMutex
Definition: acobject.h:188
ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_NOTIFY_INFO UINT32 SystemLevel
Definition: acobject.h:280
ACPI_COMMON_NOTIFY_INFO ACPI_IO_ADDRESS Address
Definition: acobject.h:295
ACPI_OBJECT_COMMON_HEADER UINT8 ProcId
Definition: acobject.h:292
ACPI_NAMESPACE_NODE * Node
Definition: acobject.h:203
ACPI_OBJECT_COMMON_HEADER UINT8 SpaceId
Definition: acobject.h:202
ACPI_PHYSICAL_ADDRESS Address
Definition: acobject.h:206
union acpi_operand_object * Handler
Definition: acobject.h:204
ACPI_STATE_COMMON ACPI_NAMESPACE_NODE * Node
Definition: aclocal.h:740
union acpi_operand_object * Operands[ACPI_OBJ_NUM_OPERANDS+1]
Definition: acstruct.h:105
ACPI_PARSE_OBJECT * Op
Definition: acstruct.h:118
ACPI_GENERIC_STATE * ScopeInfo
Definition: acstruct.h:124
ACPI_SCOPE_STATE Scope
Definition: aclocal.h:825
ACPI_OBJECT_PROCESSOR Processor
Definition: acobject.h:531
ACPI_OBJECT_EVENT Event
Definition: acobject.h:524
ACPI_OBJECT_METHOD Method
Definition: acobject.h:525
ACPI_OBJECT_REGION Region
Definition: acobject.h:527
ACPI_OBJECT_POWER_RESOURCE PowerResource
Definition: acobject.h:530
ACPI_OBJECT_MUTEX Mutex
Definition: acobject.h:526
ACPI_OBJECT_EXTRA Extra
Definition: acobject.h:541
ACPI_OBJECT_INTEGER Integer
Definition: acobject.h:520
ACPI_OBJECT_COMMON Common
Definition: acobject.h:519
ACPI_PARSE_OBJ_COMMON Common
Definition: aclocal.h:1078
Definition: dlist.c:348