Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/contrib/dev/acpica/components/dispatcher/dswstate.c
48521 views
1
/******************************************************************************
2
*
3
* Module Name: dswstate - Dispatcher parse tree walk management routines
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/acparser.h>
155
#include <contrib/dev/acpica/include/acdispat.h>
156
#include <contrib/dev/acpica/include/acnamesp.h>
157
158
#define _COMPONENT ACPI_DISPATCHER
159
ACPI_MODULE_NAME ("dswstate")
160
161
/* Local prototypes */
162
163
static ACPI_STATUS
164
AcpiDsResultStackPush (
165
ACPI_WALK_STATE *WalkState);
166
167
static ACPI_STATUS
168
AcpiDsResultStackPop (
169
ACPI_WALK_STATE *WalkState);
170
171
172
/*******************************************************************************
173
*
174
* FUNCTION: AcpiDsResultPop
175
*
176
* PARAMETERS: Object - Where to return the popped object
177
* WalkState - Current Walk state
178
*
179
* RETURN: Status
180
*
181
* DESCRIPTION: Pop an object off the top of this walk's result stack
182
*
183
******************************************************************************/
184
185
ACPI_STATUS
186
AcpiDsResultPop (
187
ACPI_OPERAND_OBJECT **Object,
188
ACPI_WALK_STATE *WalkState)
189
{
190
UINT32 Index;
191
ACPI_GENERIC_STATE *State;
192
ACPI_STATUS Status;
193
194
195
ACPI_FUNCTION_NAME (DsResultPop);
196
197
198
State = WalkState->Results;
199
200
/* Incorrect state of result stack */
201
202
if (State && !WalkState->ResultCount)
203
{
204
ACPI_ERROR ((AE_INFO, "No results on result stack"));
205
return (AE_AML_INTERNAL);
206
}
207
208
if (!State && WalkState->ResultCount)
209
{
210
ACPI_ERROR ((AE_INFO, "No result state for result stack"));
211
return (AE_AML_INTERNAL);
212
}
213
214
/* Empty result stack */
215
216
if (!State)
217
{
218
ACPI_ERROR ((AE_INFO, "Result stack is empty! State=%p", WalkState));
219
return (AE_AML_NO_RETURN_VALUE);
220
}
221
222
/* Return object of the top element and clean that top element result stack */
223
224
WalkState->ResultCount--;
225
Index = (UINT32) WalkState->ResultCount % ACPI_RESULTS_FRAME_OBJ_NUM;
226
227
*Object = State->Results.ObjDesc [Index];
228
if (!*Object)
229
{
230
ACPI_ERROR ((AE_INFO, "No result objects on result stack, State=%p",
231
WalkState));
232
return (AE_AML_NO_RETURN_VALUE);
233
}
234
235
State->Results.ObjDesc [Index] = NULL;
236
if (Index == 0)
237
{
238
Status = AcpiDsResultStackPop (WalkState);
239
if (ACPI_FAILURE (Status))
240
{
241
return (Status);
242
}
243
}
244
245
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
246
"Obj=%p [%s] Index=%X State=%p Num=%X\n", *Object,
247
AcpiUtGetObjectTypeName (*Object),
248
Index, WalkState, WalkState->ResultCount));
249
250
return (AE_OK);
251
}
252
253
254
/*******************************************************************************
255
*
256
* FUNCTION: AcpiDsResultPush
257
*
258
* PARAMETERS: Object - Where to return the popped object
259
* WalkState - Current Walk state
260
*
261
* RETURN: Status
262
*
263
* DESCRIPTION: Push an object onto the current result stack
264
*
265
******************************************************************************/
266
267
ACPI_STATUS
268
AcpiDsResultPush (
269
ACPI_OPERAND_OBJECT *Object,
270
ACPI_WALK_STATE *WalkState)
271
{
272
ACPI_GENERIC_STATE *State;
273
ACPI_STATUS Status;
274
UINT32 Index;
275
276
277
ACPI_FUNCTION_NAME (DsResultPush);
278
279
280
if (WalkState->ResultCount > WalkState->ResultSize)
281
{
282
ACPI_ERROR ((AE_INFO, "Result stack is full"));
283
return (AE_AML_INTERNAL);
284
}
285
else if (WalkState->ResultCount == WalkState->ResultSize)
286
{
287
/* Extend the result stack */
288
289
Status = AcpiDsResultStackPush (WalkState);
290
if (ACPI_FAILURE (Status))
291
{
292
ACPI_ERROR ((AE_INFO, "Failed to extend the result stack"));
293
return (Status);
294
}
295
}
296
297
if (!(WalkState->ResultCount < WalkState->ResultSize))
298
{
299
ACPI_ERROR ((AE_INFO, "No free elements in result stack"));
300
return (AE_AML_INTERNAL);
301
}
302
303
State = WalkState->Results;
304
if (!State)
305
{
306
ACPI_ERROR ((AE_INFO, "No result stack frame during push"));
307
return (AE_AML_INTERNAL);
308
}
309
310
if (!Object)
311
{
312
ACPI_ERROR ((AE_INFO,
313
"Null Object! State=%p Num=%u",
314
WalkState, WalkState->ResultCount));
315
return (AE_BAD_PARAMETER);
316
}
317
318
/* Assign the address of object to the top free element of result stack */
319
320
Index = (UINT32) WalkState->ResultCount % ACPI_RESULTS_FRAME_OBJ_NUM;
321
State->Results.ObjDesc [Index] = Object;
322
WalkState->ResultCount++;
323
324
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
325
Object, AcpiUtGetObjectTypeName ((ACPI_OPERAND_OBJECT *) Object),
326
WalkState, WalkState->ResultCount, WalkState->CurrentResult));
327
328
return (AE_OK);
329
}
330
331
332
/*******************************************************************************
333
*
334
* FUNCTION: AcpiDsResultStackPush
335
*
336
* PARAMETERS: WalkState - Current Walk state
337
*
338
* RETURN: Status
339
*
340
* DESCRIPTION: Push an object onto the WalkState result stack
341
*
342
******************************************************************************/
343
344
static ACPI_STATUS
345
AcpiDsResultStackPush (
346
ACPI_WALK_STATE *WalkState)
347
{
348
ACPI_GENERIC_STATE *State;
349
350
351
ACPI_FUNCTION_NAME (DsResultStackPush);
352
353
354
/* Check for stack overflow */
355
356
if (((UINT32) WalkState->ResultSize + ACPI_RESULTS_FRAME_OBJ_NUM) >
357
ACPI_RESULTS_OBJ_NUM_MAX)
358
{
359
ACPI_ERROR ((AE_INFO, "Result stack overflow: State=%p Num=%u",
360
WalkState, WalkState->ResultSize));
361
return (AE_STACK_OVERFLOW);
362
}
363
364
State = AcpiUtCreateGenericState ();
365
if (!State)
366
{
367
return (AE_NO_MEMORY);
368
}
369
370
State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_RESULT;
371
AcpiUtPushGenericState (&WalkState->Results, State);
372
373
/* Increase the length of the result stack by the length of frame */
374
375
WalkState->ResultSize += ACPI_RESULTS_FRAME_OBJ_NUM;
376
377
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Results=%p State=%p\n",
378
State, WalkState));
379
380
return (AE_OK);
381
}
382
383
384
/*******************************************************************************
385
*
386
* FUNCTION: AcpiDsResultStackPop
387
*
388
* PARAMETERS: WalkState - Current Walk state
389
*
390
* RETURN: Status
391
*
392
* DESCRIPTION: Pop an object off of the WalkState result stack
393
*
394
******************************************************************************/
395
396
static ACPI_STATUS
397
AcpiDsResultStackPop (
398
ACPI_WALK_STATE *WalkState)
399
{
400
ACPI_GENERIC_STATE *State;
401
402
403
ACPI_FUNCTION_NAME (DsResultStackPop);
404
405
406
/* Check for stack underflow */
407
408
if (WalkState->Results == NULL)
409
{
410
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
411
"Result stack underflow - State=%p\n", WalkState));
412
return (AE_AML_NO_OPERAND);
413
}
414
415
if (WalkState->ResultSize < ACPI_RESULTS_FRAME_OBJ_NUM)
416
{
417
ACPI_ERROR ((AE_INFO, "Insufficient result stack size"));
418
return (AE_AML_INTERNAL);
419
}
420
421
State = AcpiUtPopGenericState (&WalkState->Results);
422
AcpiUtDeleteGenericState (State);
423
424
/* Decrease the length of result stack by the length of frame */
425
426
WalkState->ResultSize -= ACPI_RESULTS_FRAME_OBJ_NUM;
427
428
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
429
"Result=%p RemainingResults=%X State=%p\n",
430
State, WalkState->ResultCount, WalkState));
431
432
return (AE_OK);
433
}
434
435
436
/*******************************************************************************
437
*
438
* FUNCTION: AcpiDsObjStackPush
439
*
440
* PARAMETERS: Object - Object to push
441
* WalkState - Current Walk state
442
*
443
* RETURN: Status
444
*
445
* DESCRIPTION: Push an object onto this walk's object/operand stack
446
*
447
******************************************************************************/
448
449
ACPI_STATUS
450
AcpiDsObjStackPush (
451
void *Object,
452
ACPI_WALK_STATE *WalkState)
453
{
454
ACPI_FUNCTION_NAME (DsObjStackPush);
455
456
457
/* Check for stack overflow */
458
459
if (WalkState->NumOperands >= ACPI_OBJ_NUM_OPERANDS)
460
{
461
ACPI_ERROR ((AE_INFO,
462
"Object stack overflow! Obj=%p State=%p #Ops=%u",
463
Object, WalkState, WalkState->NumOperands));
464
return (AE_STACK_OVERFLOW);
465
}
466
467
/* Put the object onto the stack */
468
469
WalkState->Operands [WalkState->OperandIndex] = Object;
470
WalkState->NumOperands++;
471
472
/* For the usual order of filling the operand stack */
473
474
WalkState->OperandIndex++;
475
476
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
477
Object, AcpiUtGetObjectTypeName ((ACPI_OPERAND_OBJECT *) Object),
478
WalkState, WalkState->NumOperands));
479
480
return (AE_OK);
481
}
482
483
484
/*******************************************************************************
485
*
486
* FUNCTION: AcpiDsObjStackPop
487
*
488
* PARAMETERS: PopCount - Number of objects/entries to pop
489
* WalkState - Current Walk state
490
*
491
* RETURN: Status
492
*
493
* DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
494
* deleted by this routine.
495
*
496
******************************************************************************/
497
498
ACPI_STATUS
499
AcpiDsObjStackPop (
500
UINT32 PopCount,
501
ACPI_WALK_STATE *WalkState)
502
{
503
UINT32 i;
504
505
506
ACPI_FUNCTION_NAME (DsObjStackPop);
507
508
509
for (i = 0; i < PopCount; i++)
510
{
511
/* Check for stack underflow */
512
513
if (WalkState->NumOperands == 0)
514
{
515
ACPI_ERROR ((AE_INFO,
516
"Object stack underflow! Count=%X State=%p #Ops=%u",
517
PopCount, WalkState, WalkState->NumOperands));
518
return (AE_STACK_UNDERFLOW);
519
}
520
521
/* Just set the stack entry to null */
522
523
WalkState->NumOperands--;
524
WalkState->Operands [WalkState->NumOperands] = NULL;
525
}
526
527
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%u\n",
528
PopCount, WalkState, WalkState->NumOperands));
529
530
return (AE_OK);
531
}
532
533
534
/*******************************************************************************
535
*
536
* FUNCTION: AcpiDsObjStackPopAndDelete
537
*
538
* PARAMETERS: PopCount - Number of objects/entries to pop
539
* WalkState - Current Walk state
540
*
541
* RETURN: Status
542
*
543
* DESCRIPTION: Pop this walk's object stack and delete each object that is
544
* popped off.
545
*
546
******************************************************************************/
547
548
void
549
AcpiDsObjStackPopAndDelete (
550
UINT32 PopCount,
551
ACPI_WALK_STATE *WalkState)
552
{
553
INT32 i;
554
ACPI_OPERAND_OBJECT *ObjDesc;
555
556
557
ACPI_FUNCTION_NAME (DsObjStackPopAndDelete);
558
559
560
if (PopCount == 0)
561
{
562
return;
563
}
564
565
for (i = (INT32) PopCount - 1; i >= 0; i--)
566
{
567
if (WalkState->NumOperands == 0)
568
{
569
return;
570
}
571
572
/* Pop the stack and delete an object if present in this stack entry */
573
574
WalkState->NumOperands--;
575
ObjDesc = WalkState->Operands [i];
576
if (ObjDesc)
577
{
578
AcpiUtRemoveReference (WalkState->Operands [i]);
579
WalkState->Operands [i] = NULL;
580
}
581
}
582
583
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
584
PopCount, WalkState, WalkState->NumOperands));
585
}
586
587
588
/*******************************************************************************
589
*
590
* FUNCTION: AcpiDsGetCurrentWalkState
591
*
592
* PARAMETERS: Thread - Get current active state for this Thread
593
*
594
* RETURN: Pointer to the current walk state
595
*
596
* DESCRIPTION: Get the walk state that is at the head of the list (the "current"
597
* walk state.)
598
*
599
******************************************************************************/
600
601
ACPI_WALK_STATE *
602
AcpiDsGetCurrentWalkState (
603
ACPI_THREAD_STATE *Thread)
604
{
605
ACPI_FUNCTION_NAME (DsGetCurrentWalkState);
606
607
608
if (!Thread)
609
{
610
return (NULL);
611
}
612
613
ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Current WalkState %p\n",
614
Thread->WalkStateList));
615
616
return (Thread->WalkStateList);
617
}
618
619
620
/*******************************************************************************
621
*
622
* FUNCTION: AcpiDsPushWalkState
623
*
624
* PARAMETERS: WalkState - State to push
625
* Thread - Thread state object
626
*
627
* RETURN: None
628
*
629
* DESCRIPTION: Place the Thread state at the head of the state list
630
*
631
******************************************************************************/
632
633
void
634
AcpiDsPushWalkState (
635
ACPI_WALK_STATE *WalkState,
636
ACPI_THREAD_STATE *Thread)
637
{
638
ACPI_FUNCTION_TRACE (DsPushWalkState);
639
640
641
WalkState->Next = Thread->WalkStateList;
642
Thread->WalkStateList = WalkState;
643
644
return_VOID;
645
}
646
647
648
/*******************************************************************************
649
*
650
* FUNCTION: AcpiDsPopWalkState
651
*
652
* PARAMETERS: Thread - Current thread state
653
*
654
* RETURN: A WalkState object popped from the thread's stack
655
*
656
* DESCRIPTION: Remove and return the walkstate object that is at the head of
657
* the walk stack for the given walk list. NULL indicates that
658
* the list is empty.
659
*
660
******************************************************************************/
661
662
ACPI_WALK_STATE *
663
AcpiDsPopWalkState (
664
ACPI_THREAD_STATE *Thread)
665
{
666
ACPI_WALK_STATE *WalkState;
667
668
669
ACPI_FUNCTION_TRACE (DsPopWalkState);
670
671
672
WalkState = Thread->WalkStateList;
673
674
if (WalkState)
675
{
676
/* Next walk state becomes the current walk state */
677
678
Thread->WalkStateList = WalkState->Next;
679
680
/*
681
* Don't clear the NEXT field, this serves as an indicator
682
* that there is a parent WALK STATE
683
* Do Not: WalkState->Next = NULL;
684
*/
685
}
686
687
return_PTR (WalkState);
688
}
689
690
691
/*******************************************************************************
692
*
693
* FUNCTION: AcpiDsCreateWalkState
694
*
695
* PARAMETERS: OwnerId - ID for object creation
696
* Origin - Starting point for this walk
697
* MethodDesc - Method object
698
* Thread - Current thread state
699
*
700
* RETURN: Pointer to the new walk state.
701
*
702
* DESCRIPTION: Allocate and initialize a new walk state. The current walk
703
* state is set to this new state.
704
*
705
******************************************************************************/
706
707
ACPI_WALK_STATE *
708
AcpiDsCreateWalkState (
709
ACPI_OWNER_ID OwnerId,
710
ACPI_PARSE_OBJECT *Origin,
711
ACPI_OPERAND_OBJECT *MethodDesc,
712
ACPI_THREAD_STATE *Thread)
713
{
714
ACPI_WALK_STATE *WalkState;
715
716
717
ACPI_FUNCTION_TRACE (DsCreateWalkState);
718
719
720
WalkState = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_WALK_STATE));
721
if (!WalkState)
722
{
723
return_PTR (NULL);
724
}
725
726
WalkState->DescriptorType = ACPI_DESC_TYPE_WALK;
727
WalkState->MethodDesc = MethodDesc;
728
WalkState->OwnerId = OwnerId;
729
WalkState->Origin = Origin;
730
WalkState->Thread = Thread;
731
732
WalkState->ParserState.StartOp = Origin;
733
734
/* Init the method args/local */
735
736
#ifndef ACPI_CONSTANT_EVAL_ONLY
737
AcpiDsMethodDataInit (WalkState);
738
#endif
739
740
/* Put the new state at the head of the walk list */
741
742
if (Thread)
743
{
744
AcpiDsPushWalkState (WalkState, Thread);
745
}
746
747
return_PTR (WalkState);
748
}
749
750
751
/*******************************************************************************
752
*
753
* FUNCTION: AcpiDsInitAmlWalk
754
*
755
* PARAMETERS: WalkState - New state to be initialized
756
* Op - Current parse op
757
* MethodNode - Control method NS node, if any
758
* AmlStart - Start of AML
759
* AmlLength - Length of AML
760
* Info - Method info block (params, etc.)
761
* PassNumber - 1, 2, or 3
762
*
763
* RETURN: Status
764
*
765
* DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk
766
*
767
******************************************************************************/
768
769
ACPI_STATUS
770
AcpiDsInitAmlWalk (
771
ACPI_WALK_STATE *WalkState,
772
ACPI_PARSE_OBJECT *Op,
773
ACPI_NAMESPACE_NODE *MethodNode,
774
UINT8 *AmlStart,
775
UINT32 AmlLength,
776
ACPI_EVALUATE_INFO *Info,
777
UINT8 PassNumber)
778
{
779
ACPI_STATUS Status;
780
ACPI_PARSE_STATE *ParserState = &WalkState->ParserState;
781
ACPI_PARSE_OBJECT *ExtraOp;
782
783
784
ACPI_FUNCTION_TRACE (DsInitAmlWalk);
785
786
787
WalkState->ParserState.Aml =
788
WalkState->ParserState.AmlStart =
789
WalkState->ParserState.AmlEnd =
790
WalkState->ParserState.PkgEnd = AmlStart;
791
/* Avoid undefined behavior: applying zero offset to null pointer */
792
if (AmlLength != 0) {
793
WalkState->ParserState.AmlEnd += AmlLength;
794
WalkState->ParserState.PkgEnd += AmlLength;
795
}
796
797
/* The NextOp of the NextWalk will be the beginning of the method */
798
799
WalkState->NextOp = NULL;
800
WalkState->PassNumber = PassNumber;
801
802
if (Info)
803
{
804
WalkState->Params = Info->Parameters;
805
WalkState->CallerReturnDesc = &Info->ReturnObject;
806
}
807
808
Status = AcpiPsInitScope (&WalkState->ParserState, Op);
809
if (ACPI_FAILURE (Status))
810
{
811
return_ACPI_STATUS (Status);
812
}
813
814
if (MethodNode)
815
{
816
WalkState->ParserState.StartNode = MethodNode;
817
WalkState->WalkType = ACPI_WALK_METHOD;
818
WalkState->MethodNode = MethodNode;
819
WalkState->MethodDesc = AcpiNsGetAttachedObject (MethodNode);
820
821
/* Push start scope on scope stack and make it current */
822
823
Status = AcpiDsScopeStackPush (
824
MethodNode, ACPI_TYPE_METHOD, WalkState);
825
if (ACPI_FAILURE (Status))
826
{
827
return_ACPI_STATUS (Status);
828
}
829
830
/* Init the method arguments */
831
832
Status = AcpiDsMethodDataInitArgs (WalkState->Params,
833
ACPI_METHOD_NUM_ARGS, WalkState);
834
if (ACPI_FAILURE (Status))
835
{
836
return_ACPI_STATUS (Status);
837
}
838
}
839
else
840
{
841
/*
842
* Setup the current scope.
843
* Find a Named Op that has a namespace node associated with it.
844
* search upwards from this Op. Current scope is the first
845
* Op with a namespace node.
846
*/
847
ExtraOp = ParserState->StartOp;
848
while (ExtraOp && !ExtraOp->Common.Node)
849
{
850
ExtraOp = ExtraOp->Common.Parent;
851
}
852
853
if (!ExtraOp)
854
{
855
ParserState->StartNode = NULL;
856
}
857
else
858
{
859
ParserState->StartNode = ExtraOp->Common.Node;
860
}
861
862
if (ParserState->StartNode)
863
{
864
/* Push start scope on scope stack and make it current */
865
866
Status = AcpiDsScopeStackPush (ParserState->StartNode,
867
ParserState->StartNode->Type, WalkState);
868
if (ACPI_FAILURE (Status))
869
{
870
return_ACPI_STATUS (Status);
871
}
872
}
873
}
874
875
Status = AcpiDsInitCallbacks (WalkState, PassNumber);
876
return_ACPI_STATUS (Status);
877
}
878
879
880
/*******************************************************************************
881
*
882
* FUNCTION: AcpiDsDeleteWalkState
883
*
884
* PARAMETERS: WalkState - State to delete
885
*
886
* RETURN: Status
887
*
888
* DESCRIPTION: Delete a walk state including all internal data structures
889
*
890
******************************************************************************/
891
892
void
893
AcpiDsDeleteWalkState (
894
ACPI_WALK_STATE *WalkState)
895
{
896
ACPI_GENERIC_STATE *State;
897
898
899
ACPI_FUNCTION_TRACE_PTR (DsDeleteWalkState, WalkState);
900
901
902
if (!WalkState)
903
{
904
return_VOID;
905
}
906
907
if (WalkState->DescriptorType != ACPI_DESC_TYPE_WALK)
908
{
909
ACPI_ERROR ((AE_INFO, "%p is not a valid walk state",
910
WalkState));
911
return_VOID;
912
}
913
914
/* There should not be any open scopes */
915
916
if (WalkState->ParserState.Scope)
917
{
918
ACPI_ERROR ((AE_INFO, "%p walk still has a scope list",
919
WalkState));
920
AcpiPsCleanupScope (&WalkState->ParserState);
921
}
922
923
/* Always must free any linked control states */
924
925
while (WalkState->ControlState)
926
{
927
State = WalkState->ControlState;
928
WalkState->ControlState = State->Common.Next;
929
930
AcpiUtDeleteGenericState (State);
931
}
932
933
/* Always must free any linked parse states */
934
935
while (WalkState->ScopeInfo)
936
{
937
State = WalkState->ScopeInfo;
938
WalkState->ScopeInfo = State->Common.Next;
939
940
AcpiUtDeleteGenericState (State);
941
}
942
943
/* Always must free any stacked result states */
944
945
while (WalkState->Results)
946
{
947
State = WalkState->Results;
948
WalkState->Results = State->Common.Next;
949
950
AcpiUtDeleteGenericState (State);
951
}
952
953
ACPI_FREE (WalkState);
954
return_VOID;
955
}
956
957