Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/contrib/dev/acpica/components/dispatcher/dsmthdat.c
48521 views
1
/*******************************************************************************
2
*
3
* Module Name: dsmthdat - control method arguments and local variables
4
*
5
******************************************************************************/
6
7
/******************************************************************************
8
*
9
* 1. Copyright Notice
10
*
11
* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.
12
* All rights reserved.
13
*
14
* 2. License
15
*
16
* 2.1. This is your license from Intel Corp. under its intellectual property
17
* rights. You may have additional license terms from the party that provided
18
* you this software, covering your right to use that party's intellectual
19
* property rights.
20
*
21
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22
* copy of the source code appearing in this file ("Covered Code") an
23
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
24
* base code distributed originally by Intel ("Original Intel Code") to copy,
25
* make derivatives, distribute, use and display any portion of the Covered
26
* Code in any form, with the right to sublicense such rights; and
27
*
28
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29
* license (with the right to sublicense), under only those claims of Intel
30
* patents that are infringed by the Original Intel Code, to make, use, sell,
31
* offer to sell, and import the Covered Code and derivative works thereof
32
* solely to the minimum extent necessary to exercise the above copyright
33
* license, and in no event shall the patent license extend to any additions
34
* to or modifications of the Original Intel Code. No other license or right
35
* is granted directly or by implication, estoppel or otherwise;
36
*
37
* The above copyright and patent license is granted only if the following
38
* conditions are met:
39
*
40
* 3. Conditions
41
*
42
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
43
* Redistribution of source code of any substantial portion of the Covered
44
* Code or modification with rights to further distribute source must include
45
* the above Copyright Notice, the above License, this list of Conditions,
46
* and the following Disclaimer and Export Compliance provision. In addition,
47
* Licensee must cause all Covered Code to which Licensee contributes to
48
* contain a file documenting the changes Licensee made to create that Covered
49
* Code and the date of any change. Licensee must include in that file the
50
* documentation of any changes made by any predecessor Licensee. Licensee
51
* must include a prominent statement that the modification is derived,
52
* directly or indirectly, from Original Intel Code.
53
*
54
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55
* Redistribution of source code of any substantial portion of the Covered
56
* Code or modification without rights to further distribute source must
57
* include the following Disclaimer and Export Compliance provision in the
58
* documentation and/or other materials provided with distribution. In
59
* addition, Licensee may not authorize further sublicense of source of any
60
* portion of the Covered Code, and must include terms to the effect that the
61
* license from Licensee to its licensee is limited to the intellectual
62
* property embodied in the software Licensee provides to its licensee, and
63
* not to intellectual property embodied in modifications its licensee may
64
* make.
65
*
66
* 3.3. Redistribution of Executable. Redistribution in executable form of any
67
* substantial portion of the Covered Code or modification must reproduce the
68
* above Copyright Notice, and the following Disclaimer and Export Compliance
69
* provision in the documentation and/or other materials provided with the
70
* distribution.
71
*
72
* 3.4. Intel retains all right, title, and interest in and to the Original
73
* Intel Code.
74
*
75
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
76
* Intel shall be used in advertising or otherwise to promote the sale, use or
77
* other dealings in products derived from or relating to the Covered Code
78
* without prior written authorization from Intel.
79
*
80
* 4. Disclaimer and Export Compliance
81
*
82
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88
* PARTICULAR PURPOSE.
89
*
90
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97
* LIMITED REMEDY.
98
*
99
* 4.3. Licensee shall not export, either directly or indirectly, any of this
100
* software or system incorporating such software without first obtaining any
101
* required license or other approval from the U. S. Department of Commerce or
102
* any other agency or department of the United States Government. In the
103
* event Licensee exports any such software from the United States or
104
* re-exports any such software from a foreign destination, Licensee shall
105
* ensure that the distribution and export/re-export of the software is in
106
* compliance with all laws, regulations, orders, or other restrictions of the
107
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
108
* any of its subsidiaries will export/re-export any technical data, process,
109
* software, or service, directly or indirectly, to any country for which the
110
* United States government or any agency thereof requires an export license,
111
* other governmental approval, or letter of assurance, without first obtaining
112
* such license, approval or letter.
113
*
114
*****************************************************************************
115
*
116
* Alternatively, you may choose to be licensed under the terms of the
117
* following license:
118
*
119
* Redistribution and use in source and binary forms, with or without
120
* modification, are permitted provided that the following conditions
121
* are met:
122
* 1. Redistributions of source code must retain the above copyright
123
* notice, this list of conditions, and the following disclaimer,
124
* without modification.
125
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
126
* substantially similar to the "NO WARRANTY" disclaimer below
127
* ("Disclaimer") and any redistribution must be conditioned upon
128
* including a substantially similar Disclaimer requirement for further
129
* binary redistribution.
130
* 3. Neither the names of the above-listed copyright holders nor the names
131
* of any contributors may be used to endorse or promote products derived
132
* from this software without specific prior written permission.
133
*
134
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145
*
146
* Alternatively, you may choose to be licensed under the terms of the
147
* GNU General Public License ("GPL") version 2 as published by the Free
148
* Software Foundation.
149
*
150
*****************************************************************************/
151
152
#include <contrib/dev/acpica/include/acpi.h>
153
#include <contrib/dev/acpica/include/accommon.h>
154
#include <contrib/dev/acpica/include/acdispat.h>
155
#include <contrib/dev/acpica/include/acnamesp.h>
156
#include <contrib/dev/acpica/include/acinterp.h>
157
158
159
#define _COMPONENT ACPI_DISPATCHER
160
ACPI_MODULE_NAME ("dsmthdat")
161
162
/* Local prototypes */
163
164
static void
165
AcpiDsMethodDataDeleteValue (
166
UINT8 Type,
167
UINT32 Index,
168
ACPI_WALK_STATE *WalkState);
169
170
static ACPI_STATUS
171
AcpiDsMethodDataSetValue (
172
UINT8 Type,
173
UINT32 Index,
174
ACPI_OPERAND_OBJECT *Object,
175
ACPI_WALK_STATE *WalkState);
176
177
#ifdef ACPI_OBSOLETE_FUNCTIONS
178
ACPI_OBJECT_TYPE
179
AcpiDsMethodDataGetType (
180
UINT16 Opcode,
181
UINT32 Index,
182
ACPI_WALK_STATE *WalkState);
183
#endif
184
185
186
/*******************************************************************************
187
*
188
* FUNCTION: AcpiDsMethodDataInit
189
*
190
* PARAMETERS: WalkState - Current walk state object
191
*
192
* RETURN: Status
193
*
194
* DESCRIPTION: Initialize the data structures that hold the method's arguments
195
* and locals. The data struct is an array of namespace nodes for
196
* each - this allows RefOf and DeRefOf to work properly for these
197
* special data types.
198
*
199
* NOTES: WalkState fields are initialized to zero by the
200
* ACPI_ALLOCATE_ZEROED().
201
*
202
* A pseudo-Namespace Node is assigned to each argument and local
203
* so that RefOf() can return a pointer to the Node.
204
*
205
******************************************************************************/
206
207
void
208
AcpiDsMethodDataInit (
209
ACPI_WALK_STATE *WalkState)
210
{
211
UINT32 i;
212
213
214
ACPI_FUNCTION_TRACE (DsMethodDataInit);
215
216
217
/* Init the method arguments */
218
219
for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
220
{
221
ACPI_MOVE_32_TO_32 (&WalkState->Arguments[i].Name,
222
NAMEOF_ARG_NTE);
223
224
WalkState->Arguments[i].Name.Integer |= (i << 24);
225
WalkState->Arguments[i].DescriptorType = ACPI_DESC_TYPE_NAMED;
226
WalkState->Arguments[i].Type = ACPI_TYPE_ANY;
227
WalkState->Arguments[i].Flags = ANOBJ_METHOD_ARG;
228
}
229
230
/* Init the method locals */
231
232
for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++)
233
{
234
ACPI_MOVE_32_TO_32 (&WalkState->LocalVariables[i].Name,
235
NAMEOF_LOCAL_NTE);
236
237
WalkState->LocalVariables[i].Name.Integer |= (i << 24);
238
WalkState->LocalVariables[i].DescriptorType = ACPI_DESC_TYPE_NAMED;
239
WalkState->LocalVariables[i].Type = ACPI_TYPE_ANY;
240
WalkState->LocalVariables[i].Flags = ANOBJ_METHOD_LOCAL;
241
}
242
243
return_VOID;
244
}
245
246
247
/*******************************************************************************
248
*
249
* FUNCTION: AcpiDsMethodDataDeleteAll
250
*
251
* PARAMETERS: WalkState - Current walk state object
252
*
253
* RETURN: None
254
*
255
* DESCRIPTION: Delete method locals and arguments. Arguments are only
256
* deleted if this method was called from another method.
257
*
258
******************************************************************************/
259
260
void
261
AcpiDsMethodDataDeleteAll (
262
ACPI_WALK_STATE *WalkState)
263
{
264
UINT32 Index;
265
266
267
ACPI_FUNCTION_TRACE (DsMethodDataDeleteAll);
268
269
270
/* Detach the locals */
271
272
for (Index = 0; Index < ACPI_METHOD_NUM_LOCALS; Index++)
273
{
274
if (WalkState->LocalVariables[Index].Object)
275
{
276
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Local%u=%p\n",
277
Index, WalkState->LocalVariables[Index].Object));
278
279
/* Detach object (if present) and remove a reference */
280
281
AcpiNsDetachObject (&WalkState->LocalVariables[Index]);
282
}
283
}
284
285
/* Detach the arguments */
286
287
for (Index = 0; Index < ACPI_METHOD_NUM_ARGS; Index++)
288
{
289
if (WalkState->Arguments[Index].Object)
290
{
291
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Arg%u=%p\n",
292
Index, WalkState->Arguments[Index].Object));
293
294
/* Detach object (if present) and remove a reference */
295
296
AcpiNsDetachObject (&WalkState->Arguments[Index]);
297
}
298
}
299
300
return_VOID;
301
}
302
303
304
/*******************************************************************************
305
*
306
* FUNCTION: AcpiDsMethodDataInitArgs
307
*
308
* PARAMETERS: *Params - Pointer to a parameter list for the method
309
* MaxParamCount - The arg count for this method
310
* WalkState - Current walk state object
311
*
312
* RETURN: Status
313
*
314
* DESCRIPTION: Initialize arguments for a method. The parameter list is a list
315
* of ACPI operand objects, either null terminated or whose length
316
* is defined by MaxParamCount.
317
*
318
******************************************************************************/
319
320
ACPI_STATUS
321
AcpiDsMethodDataInitArgs (
322
ACPI_OPERAND_OBJECT **Params,
323
UINT32 MaxParamCount,
324
ACPI_WALK_STATE *WalkState)
325
{
326
ACPI_STATUS Status;
327
UINT32 Index = 0;
328
329
330
ACPI_FUNCTION_TRACE_PTR (DsMethodDataInitArgs, Params);
331
332
333
if (!Params)
334
{
335
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
336
"No parameter list passed to method\n"));
337
return_ACPI_STATUS (AE_OK);
338
}
339
340
/* Copy passed parameters into the new method stack frame */
341
342
while ((Index < ACPI_METHOD_NUM_ARGS) &&
343
(Index < MaxParamCount) &&
344
Params[Index])
345
{
346
/*
347
* A valid parameter.
348
* Store the argument in the method/walk descriptor.
349
* Do not copy the arg in order to implement call by reference
350
*/
351
Status = AcpiDsMethodDataSetValue (
352
ACPI_REFCLASS_ARG, Index, Params[Index], WalkState);
353
if (ACPI_FAILURE (Status))
354
{
355
return_ACPI_STATUS (Status);
356
}
357
358
Index++;
359
}
360
AcpiExTraceArgs(Params, Index);
361
362
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%u args passed to method\n", Index));
363
return_ACPI_STATUS (AE_OK);
364
}
365
366
367
/*******************************************************************************
368
*
369
* FUNCTION: AcpiDsMethodDataGetNode
370
*
371
* PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
372
* ACPI_REFCLASS_ARG
373
* Index - Which Local or Arg whose type to get
374
* WalkState - Current walk state object
375
* Node - Where the node is returned.
376
*
377
* RETURN: Status and node
378
*
379
* DESCRIPTION: Get the Node associated with a local or arg.
380
*
381
******************************************************************************/
382
383
ACPI_STATUS
384
AcpiDsMethodDataGetNode (
385
UINT8 Type,
386
UINT32 Index,
387
ACPI_WALK_STATE *WalkState,
388
ACPI_NAMESPACE_NODE **Node)
389
{
390
ACPI_FUNCTION_TRACE (DsMethodDataGetNode);
391
392
393
/*
394
* Method Locals and Arguments are supported
395
*/
396
switch (Type)
397
{
398
case ACPI_REFCLASS_LOCAL:
399
400
if (Index > ACPI_METHOD_MAX_LOCAL)
401
{
402
ACPI_ERROR ((AE_INFO,
403
"Local index %u is invalid (max %u)",
404
Index, ACPI_METHOD_MAX_LOCAL));
405
return_ACPI_STATUS (AE_AML_INVALID_INDEX);
406
}
407
408
/* Return a pointer to the pseudo-node */
409
410
*Node = &WalkState->LocalVariables[Index];
411
break;
412
413
case ACPI_REFCLASS_ARG:
414
415
if (Index > ACPI_METHOD_MAX_ARG)
416
{
417
ACPI_ERROR ((AE_INFO,
418
"Arg index %u is invalid (max %u)",
419
Index, ACPI_METHOD_MAX_ARG));
420
return_ACPI_STATUS (AE_AML_INVALID_INDEX);
421
}
422
423
/* Return a pointer to the pseudo-node */
424
425
*Node = &WalkState->Arguments[Index];
426
break;
427
428
default:
429
430
ACPI_ERROR ((AE_INFO, "Type %u is invalid", Type));
431
return_ACPI_STATUS (AE_TYPE);
432
}
433
434
return_ACPI_STATUS (AE_OK);
435
}
436
437
438
/*******************************************************************************
439
*
440
* FUNCTION: AcpiDsMethodDataSetValue
441
*
442
* PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
443
* ACPI_REFCLASS_ARG
444
* Index - Which Local or Arg to get
445
* Object - Object to be inserted into the stack entry
446
* WalkState - Current walk state object
447
*
448
* RETURN: Status
449
*
450
* DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index.
451
* Note: There is no "implicit conversion" for locals.
452
*
453
******************************************************************************/
454
455
static ACPI_STATUS
456
AcpiDsMethodDataSetValue (
457
UINT8 Type,
458
UINT32 Index,
459
ACPI_OPERAND_OBJECT *Object,
460
ACPI_WALK_STATE *WalkState)
461
{
462
ACPI_STATUS Status;
463
ACPI_NAMESPACE_NODE *Node;
464
465
466
ACPI_FUNCTION_TRACE (DsMethodDataSetValue);
467
468
469
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
470
"NewObj %p Type %2.2X, Refs=%u [%s]\n", Object,
471
Type, Object->Common.ReferenceCount,
472
AcpiUtGetTypeName (Object->Common.Type)));
473
474
/* Get the namespace node for the arg/local */
475
476
Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
477
if (ACPI_FAILURE (Status))
478
{
479
return_ACPI_STATUS (Status);
480
}
481
482
/*
483
* Increment ref count so object can't be deleted while installed.
484
* NOTE: We do not copy the object in order to preserve the call by
485
* reference semantics of ACPI Control Method invocation.
486
* (See ACPI Specification 2.0C)
487
*/
488
AcpiUtAddReference (Object);
489
490
/* Install the object */
491
492
Node->Object = Object;
493
return_ACPI_STATUS (Status);
494
}
495
496
497
/*******************************************************************************
498
*
499
* FUNCTION: AcpiDsMethodDataGetValue
500
*
501
* PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
502
* ACPI_REFCLASS_ARG
503
* Index - Which localVar or argument to get
504
* WalkState - Current walk state object
505
* DestDesc - Where Arg or Local value is returned
506
*
507
* RETURN: Status
508
*
509
* DESCRIPTION: Retrieve value of selected Arg or Local for this method
510
* Used only in AcpiExResolveToValue().
511
*
512
******************************************************************************/
513
514
ACPI_STATUS
515
AcpiDsMethodDataGetValue (
516
UINT8 Type,
517
UINT32 Index,
518
ACPI_WALK_STATE *WalkState,
519
ACPI_OPERAND_OBJECT **DestDesc)
520
{
521
ACPI_STATUS Status;
522
ACPI_NAMESPACE_NODE *Node;
523
ACPI_OPERAND_OBJECT *Object;
524
525
526
ACPI_FUNCTION_TRACE (DsMethodDataGetValue);
527
528
529
/* Validate the object descriptor */
530
531
if (!DestDesc)
532
{
533
ACPI_ERROR ((AE_INFO, "Null object descriptor pointer"));
534
return_ACPI_STATUS (AE_BAD_PARAMETER);
535
}
536
537
/* Get the namespace node for the arg/local */
538
539
Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
540
if (ACPI_FAILURE (Status))
541
{
542
return_ACPI_STATUS (Status);
543
}
544
545
/* Get the object from the node */
546
547
Object = Node->Object;
548
549
/* Examine the returned object, it must be valid. */
550
551
if (!Object)
552
{
553
/*
554
* Index points to uninitialized object.
555
* This means that either 1) The expected argument was
556
* not passed to the method, or 2) A local variable
557
* was referenced by the method (via the ASL)
558
* before it was initialized. Either case is an error.
559
*/
560
561
/* If slack enabled, init the LocalX/ArgX to an Integer of value zero */
562
563
if (AcpiGbl_EnableInterpreterSlack)
564
{
565
Object = AcpiUtCreateIntegerObject ((UINT64) 0);
566
if (!Object)
567
{
568
return_ACPI_STATUS (AE_NO_MEMORY);
569
}
570
571
Node->Object = Object;
572
}
573
574
/* Otherwise, return the error */
575
576
else switch (Type)
577
{
578
case ACPI_REFCLASS_ARG:
579
580
ACPI_ERROR ((AE_INFO,
581
"Uninitialized Arg[%u] at node %p",
582
Index, Node));
583
584
return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG);
585
586
case ACPI_REFCLASS_LOCAL:
587
/*
588
* No error message for this case, will be trapped again later to
589
* detect and ignore cases of Store(LocalX,LocalX)
590
*/
591
return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL);
592
593
default:
594
595
ACPI_ERROR ((AE_INFO, "Not a Arg/Local opcode: 0x%X", Type));
596
return_ACPI_STATUS (AE_AML_INTERNAL);
597
}
598
}
599
600
/*
601
* The Index points to an initialized and valid object.
602
* Return an additional reference to the object
603
*/
604
*DestDesc = Object;
605
AcpiUtAddReference (Object);
606
607
return_ACPI_STATUS (AE_OK);
608
}
609
610
611
/*******************************************************************************
612
*
613
* FUNCTION: AcpiDsMethodDataDeleteValue
614
*
615
* PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
616
* ACPI_REFCLASS_ARG
617
* Index - Which localVar or argument to delete
618
* WalkState - Current walk state object
619
*
620
* RETURN: None
621
*
622
* DESCRIPTION: Delete the entry at Opcode:Index. Inserts
623
* a null into the stack slot after the object is deleted.
624
*
625
******************************************************************************/
626
627
static void
628
AcpiDsMethodDataDeleteValue (
629
UINT8 Type,
630
UINT32 Index,
631
ACPI_WALK_STATE *WalkState)
632
{
633
ACPI_STATUS Status;
634
ACPI_NAMESPACE_NODE *Node;
635
ACPI_OPERAND_OBJECT *Object;
636
637
638
ACPI_FUNCTION_TRACE (DsMethodDataDeleteValue);
639
640
641
/* Get the namespace node for the arg/local */
642
643
Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
644
if (ACPI_FAILURE (Status))
645
{
646
return_VOID;
647
}
648
649
/* Get the associated object */
650
651
Object = AcpiNsGetAttachedObject (Node);
652
653
/*
654
* Undefine the Arg or Local by setting its descriptor
655
* pointer to NULL. Locals/Args can contain both
656
* ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
657
*/
658
Node->Object = NULL;
659
660
if ((Object) &&
661
(ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_OPERAND))
662
{
663
/*
664
* There is a valid object.
665
* Decrement the reference count by one to balance the
666
* increment when the object was stored.
667
*/
668
AcpiUtRemoveReference (Object);
669
}
670
671
return_VOID;
672
}
673
674
675
/*******************************************************************************
676
*
677
* FUNCTION: AcpiDsStoreObjectToLocal
678
*
679
* PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
680
* ACPI_REFCLASS_ARG
681
* Index - Which Local or Arg to set
682
* ObjDesc - Value to be stored
683
* WalkState - Current walk state
684
*
685
* RETURN: Status
686
*
687
* DESCRIPTION: Store a value in an Arg or Local. The ObjDesc is installed
688
* as the new value for the Arg or Local and the reference count
689
* for ObjDesc is incremented.
690
*
691
******************************************************************************/
692
693
ACPI_STATUS
694
AcpiDsStoreObjectToLocal (
695
UINT8 Type,
696
UINT32 Index,
697
ACPI_OPERAND_OBJECT *ObjDesc,
698
ACPI_WALK_STATE *WalkState)
699
{
700
ACPI_STATUS Status;
701
ACPI_NAMESPACE_NODE *Node;
702
ACPI_OPERAND_OBJECT *CurrentObjDesc;
703
ACPI_OPERAND_OBJECT *NewObjDesc;
704
705
706
ACPI_FUNCTION_TRACE (DsStoreObjectToLocal);
707
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Type=%2.2X Index=%u Obj=%p\n",
708
Type, Index, ObjDesc));
709
710
/* Parameter validation */
711
712
if (!ObjDesc)
713
{
714
return_ACPI_STATUS (AE_BAD_PARAMETER);
715
}
716
717
/* Get the namespace node for the arg/local */
718
719
Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
720
if (ACPI_FAILURE (Status))
721
{
722
return_ACPI_STATUS (Status);
723
}
724
725
CurrentObjDesc = AcpiNsGetAttachedObject (Node);
726
if (CurrentObjDesc == ObjDesc)
727
{
728
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p already installed!\n",
729
ObjDesc));
730
return_ACPI_STATUS (Status);
731
}
732
733
/*
734
* If the reference count on the object is more than one, we must
735
* take a copy of the object before we store. A reference count
736
* of exactly 1 means that the object was just created during the
737
* evaluation of an expression, and we can safely use it since it
738
* is not used anywhere else.
739
*/
740
NewObjDesc = ObjDesc;
741
if (ObjDesc->Common.ReferenceCount > 1)
742
{
743
Status = AcpiUtCopyIobjectToIobject (
744
ObjDesc, &NewObjDesc, WalkState);
745
if (ACPI_FAILURE (Status))
746
{
747
return_ACPI_STATUS (Status);
748
}
749
}
750
751
/*
752
* If there is an object already in this slot, we either
753
* have to delete it, or if this is an argument and there
754
* is an object reference stored there, we have to do
755
* an indirect store!
756
*/
757
if (CurrentObjDesc)
758
{
759
/*
760
* Check for an indirect store if an argument
761
* contains an object reference (stored as an Node).
762
* We don't allow this automatic dereferencing for
763
* locals, since a store to a local should overwrite
764
* anything there, including an object reference.
765
*
766
* If both Arg0 and Local0 contain RefOf (Local4):
767
*
768
* Store (1, Arg0) - Causes indirect store to local4
769
* Store (1, Local0) - Stores 1 in local0, overwriting
770
* the reference to local4
771
* Store (1, DeRefof (Local0)) - Causes indirect store to local4
772
*
773
* Weird, but true.
774
*/
775
if (Type == ACPI_REFCLASS_ARG)
776
{
777
/*
778
* If we have a valid reference object that came from RefOf(),
779
* do the indirect store
780
*/
781
if ((ACPI_GET_DESCRIPTOR_TYPE (CurrentObjDesc) ==
782
ACPI_DESC_TYPE_OPERAND) &&
783
(CurrentObjDesc->Common.Type ==
784
ACPI_TYPE_LOCAL_REFERENCE) &&
785
(CurrentObjDesc->Reference.Class ==
786
ACPI_REFCLASS_REFOF))
787
{
788
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
789
"Arg (%p) is an ObjRef(Node), storing in node %p\n",
790
NewObjDesc, CurrentObjDesc));
791
792
/*
793
* Store this object to the Node (perform the indirect store)
794
* NOTE: No implicit conversion is performed, as per the ACPI
795
* specification rules on storing to Locals/Args.
796
*/
797
Status = AcpiExStoreObjectToNode (NewObjDesc,
798
CurrentObjDesc->Reference.Object, WalkState,
799
ACPI_NO_IMPLICIT_CONVERSION);
800
801
/* Remove local reference if we copied the object above */
802
803
if (NewObjDesc != ObjDesc)
804
{
805
AcpiUtRemoveReference (NewObjDesc);
806
}
807
808
return_ACPI_STATUS (Status);
809
}
810
}
811
812
/* Delete the existing object before storing the new one */
813
814
AcpiDsMethodDataDeleteValue (Type, Index, WalkState);
815
}
816
817
/*
818
* Install the Obj descriptor (*NewObjDesc) into
819
* the descriptor for the Arg or Local.
820
* (increments the object reference count by one)
821
*/
822
Status = AcpiDsMethodDataSetValue (Type, Index, NewObjDesc, WalkState);
823
824
/* Remove local reference if we copied the object above */
825
826
if (NewObjDesc != ObjDesc)
827
{
828
AcpiUtRemoveReference (NewObjDesc);
829
}
830
831
return_ACPI_STATUS (Status);
832
}
833
834
835
#ifdef ACPI_OBSOLETE_FUNCTIONS
836
/*******************************************************************************
837
*
838
* FUNCTION: AcpiDsMethodDataGetType
839
*
840
* PARAMETERS: Opcode - Either AML_FIRST LOCAL_OP or
841
* AML_FIRST_ARG_OP
842
* Index - Which Local or Arg whose type to get
843
* WalkState - Current walk state object
844
*
845
* RETURN: Data type of current value of the selected Arg or Local
846
*
847
* DESCRIPTION: Get the type of the object stored in the Local or Arg
848
*
849
******************************************************************************/
850
851
ACPI_OBJECT_TYPE
852
AcpiDsMethodDataGetType (
853
UINT16 Opcode,
854
UINT32 Index,
855
ACPI_WALK_STATE *WalkState)
856
{
857
ACPI_STATUS Status;
858
ACPI_NAMESPACE_NODE *Node;
859
ACPI_OPERAND_OBJECT *Object;
860
861
862
ACPI_FUNCTION_TRACE (DsMethodDataGetType);
863
864
865
/* Get the namespace node for the arg/local */
866
867
Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
868
if (ACPI_FAILURE (Status))
869
{
870
return_VALUE ((ACPI_TYPE_NOT_FOUND));
871
}
872
873
/* Get the object */
874
875
Object = AcpiNsGetAttachedObject (Node);
876
if (!Object)
877
{
878
/* Uninitialized local/arg, return TYPE_ANY */
879
880
return_VALUE (ACPI_TYPE_ANY);
881
}
882
883
/* Get the object type */
884
885
return_VALUE (Object->Type);
886
}
887
#endif
888
889