1 /******************************************************************************
2 *
3 * Module Name: excreate - Named object creation
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2011, 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.
96 TargetNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, TargetNode->Object);
97 }
98
99 /*
100 * For objects that can never change (i.e., the NS node will
101 * permanently point to the same object), we can simply attach
102 * the object to the new NS node. For other objects (such as
103 * Integers, buffers, etc.), we have to point the Alias node
104 * to the original Node.
105 */
106 switch (TargetNode->Type)
107 {
108
109 /* For these types, the sub-object can change dynamically via a Store */
110
111 case ACPI_TYPE_INTEGER:
112 case ACPI_TYPE_STRING:
113 case ACPI_TYPE_BUFFER:
114 case ACPI_TYPE_PACKAGE:
115 case ACPI_TYPE_BUFFER_FIELD:
116
117 /*
118 * These types open a new scope, so we need the NS node in order to access
119 * any children.
120 */
121 case ACPI_TYPE_DEVICE:
122 case ACPI_TYPE_POWER:
123 case ACPI_TYPE_PROCESSOR:
124 case ACPI_TYPE_THERMAL:
125 case ACPI_TYPE_LOCAL_SCOPE:
126
127 /*
128 * The new alias has the type ALIAS and points to the original
129 * NS node, not the object itself.
130 */
131 AliasNode->Type = ACPI_TYPE_LOCAL_ALIAS;
132 AliasNode->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);
133 break;
134
135 case ACPI_TYPE_METHOD:
136
137 /*
138 * Control method aliases need to be differentiated
139 */
140 AliasNode->Type = ACPI_TYPE_LOCAL_METHOD_ALIAS;
141 AliasNode->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);
142 break;
143
144 default:
145
146 /* Attach the original source object to the new Alias Node */
147
148 /*
149 * The new alias assumes the type of the target, and it points
150 * to the same object. The reference count of the object has an
151 * additional reference to prevent deletion out from under either the
152 * target node or the alias Node
153 */
154 Status = AcpiNsAttachObject (AliasNode,
155 AcpiNsGetAttachedObject (TargetNode), TargetNode->Type);
156 break;
267
268 Status = AcpiNsAttachObject (ObjDesc->Mutex.Node, ObjDesc, ACPI_TYPE_MUTEX);
269
270
271 Cleanup:
272 /*
273 * Remove local reference to the object (on error, will cause deletion
274 * of both object and semaphore if present.)
275 */
276 AcpiUtRemoveReference (ObjDesc);
277 return_ACPI_STATUS (Status);
278 }
279
280
281 /*******************************************************************************
282 *
283 * FUNCTION: AcpiExCreateRegion
284 *
285 * PARAMETERS: AmlStart - Pointer to the region declaration AML
286 * AmlLength - Max length of the declaration AML
287 * RegionSpace - SpaceID for the region
288 * WalkState - Current state
289 *
290 * RETURN: Status
291 *
292 * DESCRIPTION: Create a new operation region object
293 *
294 ******************************************************************************/
295
296 ACPI_STATUS
297 AcpiExCreateRegion (
298 UINT8 *AmlStart,
299 UINT32 AmlLength,
300 UINT8 RegionSpace,
301 ACPI_WALK_STATE *WalkState)
302 {
303 ACPI_STATUS Status;
304 ACPI_OPERAND_OBJECT *ObjDesc;
305 ACPI_NAMESPACE_NODE *Node;
306 ACPI_OPERAND_OBJECT *RegionObj2;
307
308
309 ACPI_FUNCTION_TRACE (ExCreateRegion);
310
311
312 /* Get the Namespace Node */
313
314 Node = WalkState->Op->Common.Node;
315
316 /*
317 * If the region object is already attached to this node,
318 * just return
319 */
320 if (AcpiNsGetAttachedObject (Node))
321 {
322 return_ACPI_STATUS (AE_OK);
323 }
324
325 /*
326 * Space ID must be one of the predefined IDs, or in the user-defined
327 * range
328 */
329 if ((RegionSpace >= ACPI_NUM_PREDEFINED_REGIONS) &&
330 (RegionSpace < ACPI_USER_REGION_BEGIN) &&
331 (RegionSpace != ACPI_ADR_SPACE_DATA_TABLE))
332 {
333 ACPI_ERROR ((AE_INFO, "Invalid AddressSpace type 0x%X", RegionSpace));
334 return_ACPI_STATUS (AE_AML_INVALID_SPACE_ID);
335 }
336
337 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "Region Type - %s (0x%X)\n",
338 AcpiUtGetRegionName (RegionSpace), RegionSpace));
339
340 /* Create the region descriptor */
341
342 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_REGION);
343 if (!ObjDesc)
344 {
345 Status = AE_NO_MEMORY;
346 goto Cleanup;
347 }
348
349 /*
350 * Remember location in AML stream of address & length
351 * operands since they need to be evaluated at run time.
352 */
353 RegionObj2 = ObjDesc->Common.NextObject;
354 RegionObj2->Extra.AmlStart = AmlStart;
355 RegionObj2->Extra.AmlLength = AmlLength;
356
357 /* Init the region from the operands */
358
359 ObjDesc->Region.SpaceId = RegionSpace;
360 ObjDesc->Region.Address = 0;
361 ObjDesc->Region.Length = 0;
362 ObjDesc->Region.Node = Node;
363
364 /* Install the new region object in the parent Node */
365
366 Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_REGION);
367
368
369 Cleanup:
370
371 /* Remove local reference to the object */
372
373 AcpiUtRemoveReference (ObjDesc);
374 return_ACPI_STATUS (Status);
375 }
376
377
378 /*******************************************************************************
379 *
543 */
544 ObjDesc->Method.SyncLevel = (UINT8)
545 ((MethodFlags & AML_METHOD_SYNC_LEVEL) >> 4);
546 }
547
548 /* Attach the new object to the method Node */
549
550 Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) Operand[0],
551 ObjDesc, ACPI_TYPE_METHOD);
552
553 /* Remove local reference to the object */
554
555 AcpiUtRemoveReference (ObjDesc);
556
557 Exit:
558 /* Remove a reference to the operand */
559
560 AcpiUtRemoveReference (Operand[1]);
561 return_ACPI_STATUS (Status);
562 }
563
564
|
1 /******************************************************************************
2 *
3 * Module Name: excreate - Named object creation
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2014, 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.
96 TargetNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, TargetNode->Object);
97 }
98
99 /*
100 * For objects that can never change (i.e., the NS node will
101 * permanently point to the same object), we can simply attach
102 * the object to the new NS node. For other objects (such as
103 * Integers, buffers, etc.), we have to point the Alias node
104 * to the original Node.
105 */
106 switch (TargetNode->Type)
107 {
108
109 /* For these types, the sub-object can change dynamically via a Store */
110
111 case ACPI_TYPE_INTEGER:
112 case ACPI_TYPE_STRING:
113 case ACPI_TYPE_BUFFER:
114 case ACPI_TYPE_PACKAGE:
115 case ACPI_TYPE_BUFFER_FIELD:
116 /*
117 * These types open a new scope, so we need the NS node in order to access
118 * any children.
119 */
120 case ACPI_TYPE_DEVICE:
121 case ACPI_TYPE_POWER:
122 case ACPI_TYPE_PROCESSOR:
123 case ACPI_TYPE_THERMAL:
124 case ACPI_TYPE_LOCAL_SCOPE:
125 /*
126 * The new alias has the type ALIAS and points to the original
127 * NS node, not the object itself.
128 */
129 AliasNode->Type = ACPI_TYPE_LOCAL_ALIAS;
130 AliasNode->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);
131 break;
132
133 case ACPI_TYPE_METHOD:
134 /*
135 * Control method aliases need to be differentiated
136 */
137 AliasNode->Type = ACPI_TYPE_LOCAL_METHOD_ALIAS;
138 AliasNode->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);
139 break;
140
141 default:
142
143 /* Attach the original source object to the new Alias Node */
144
145 /*
146 * The new alias assumes the type of the target, and it points
147 * to the same object. The reference count of the object has an
148 * additional reference to prevent deletion out from under either the
149 * target node or the alias Node
150 */
151 Status = AcpiNsAttachObject (AliasNode,
152 AcpiNsGetAttachedObject (TargetNode), TargetNode->Type);
153 break;
264
265 Status = AcpiNsAttachObject (ObjDesc->Mutex.Node, ObjDesc, ACPI_TYPE_MUTEX);
266
267
268 Cleanup:
269 /*
270 * Remove local reference to the object (on error, will cause deletion
271 * of both object and semaphore if present.)
272 */
273 AcpiUtRemoveReference (ObjDesc);
274 return_ACPI_STATUS (Status);
275 }
276
277
278 /*******************************************************************************
279 *
280 * FUNCTION: AcpiExCreateRegion
281 *
282 * PARAMETERS: AmlStart - Pointer to the region declaration AML
283 * AmlLength - Max length of the declaration AML
284 * SpaceId - Address space ID for the region
285 * WalkState - Current state
286 *
287 * RETURN: Status
288 *
289 * DESCRIPTION: Create a new operation region object
290 *
291 ******************************************************************************/
292
293 ACPI_STATUS
294 AcpiExCreateRegion (
295 UINT8 *AmlStart,
296 UINT32 AmlLength,
297 UINT8 SpaceId,
298 ACPI_WALK_STATE *WalkState)
299 {
300 ACPI_STATUS Status;
301 ACPI_OPERAND_OBJECT *ObjDesc;
302 ACPI_NAMESPACE_NODE *Node;
303 ACPI_OPERAND_OBJECT *RegionObj2;
304
305
306 ACPI_FUNCTION_TRACE (ExCreateRegion);
307
308
309 /* Get the Namespace Node */
310
311 Node = WalkState->Op->Common.Node;
312
313 /*
314 * If the region object is already attached to this node,
315 * just return
316 */
317 if (AcpiNsGetAttachedObject (Node))
318 {
319 return_ACPI_STATUS (AE_OK);
320 }
321
322 /*
323 * Space ID must be one of the predefined IDs, or in the user-defined
324 * range
325 */
326 if (!AcpiIsValidSpaceId (SpaceId))
327 {
328 /*
329 * Print an error message, but continue. We don't want to abort
330 * a table load for this exception. Instead, if the region is
331 * actually used at runtime, abort the executing method.
332 */
333 ACPI_ERROR ((AE_INFO, "Invalid/unknown Address Space ID: 0x%2.2X", SpaceId));
334 }
335
336 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "Region Type - %s (0x%X)\n",
337 AcpiUtGetRegionName (SpaceId), SpaceId));
338
339 /* Create the region descriptor */
340
341 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_REGION);
342 if (!ObjDesc)
343 {
344 Status = AE_NO_MEMORY;
345 goto Cleanup;
346 }
347
348 /*
349 * Remember location in AML stream of address & length
350 * operands since they need to be evaluated at run time.
351 */
352 RegionObj2 = ObjDesc->Common.NextObject;
353 RegionObj2->Extra.AmlStart = AmlStart;
354 RegionObj2->Extra.AmlLength = AmlLength;
355 if (WalkState->ScopeInfo)
356 {
357 RegionObj2->Extra.ScopeNode = WalkState->ScopeInfo->Scope.Node;
358 }
359 else
360 {
361 RegionObj2->Extra.ScopeNode = Node;
362 }
363
364 /* Init the region from the operands */
365
366 ObjDesc->Region.SpaceId = SpaceId;
367 ObjDesc->Region.Address = 0;
368 ObjDesc->Region.Length = 0;
369 ObjDesc->Region.Node = Node;
370
371 /* Install the new region object in the parent Node */
372
373 Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_REGION);
374
375
376 Cleanup:
377
378 /* Remove local reference to the object */
379
380 AcpiUtRemoveReference (ObjDesc);
381 return_ACPI_STATUS (Status);
382 }
383
384
385 /*******************************************************************************
386 *
550 */
551 ObjDesc->Method.SyncLevel = (UINT8)
552 ((MethodFlags & AML_METHOD_SYNC_LEVEL) >> 4);
553 }
554
555 /* Attach the new object to the method Node */
556
557 Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) Operand[0],
558 ObjDesc, ACPI_TYPE_METHOD);
559
560 /* Remove local reference to the object */
561
562 AcpiUtRemoveReference (ObjDesc);
563
564 Exit:
565 /* Remove a reference to the operand */
566
567 AcpiUtRemoveReference (Operand[1]);
568 return_ACPI_STATUS (Status);
569 }
|