1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
|
/*******************************************************************************
*
* Module Name: dbcmds - Miscellaneous debug commands and output routines
*
******************************************************************************/
/*
* Copyright (C) 2000 - 2013, Intel Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
* 3. Neither the names of the above-listed copyright holders nor the names
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*/
#include <contrib/dev/acpica/include/acpi.h>
#include <contrib/dev/acpica/include/accommon.h>
#include <contrib/dev/acpica/include/acevents.h>
#include <contrib/dev/acpica/include/acdebug.h>
#include <contrib/dev/acpica/include/acnamesp.h>
#include <contrib/dev/acpica/include/acresrc.h>
#include <contrib/dev/acpica/include/actables.h>
#ifdef ACPI_DEBUGGER
#define _COMPONENT ACPI_CA_DEBUGGER
ACPI_MODULE_NAME ("dbcmds")
/* Local prototypes */
static void
AcpiDmCompareAmlResources (
UINT8 *Aml1Buffer,
ACPI_RSDESC_SIZE Aml1BufferLength,
UINT8 *Aml2Buffer,
ACPI_RSDESC_SIZE Aml2BufferLength);
static ACPI_STATUS
AcpiDmTestResourceConversion (
ACPI_NAMESPACE_NODE *Node,
char *Name);
static ACPI_STATUS
AcpiDbResourceCallback (
ACPI_RESOURCE *Resource,
void *Context);
static ACPI_STATUS
AcpiDbDeviceResources (
ACPI_HANDLE ObjHandle,
UINT32 NestingLevel,
void *Context,
void **ReturnValue);
static void
AcpiDbDoOneSleepState (
UINT8 SleepState);
/*******************************************************************************
*
* FUNCTION: AcpiDbConvertToNode
*
* PARAMETERS: InString - String to convert
*
* RETURN: Pointer to a NS node
*
* DESCRIPTION: Convert a string to a valid NS pointer. Handles numeric or
* alphanumeric strings.
*
******************************************************************************/
ACPI_NAMESPACE_NODE *
AcpiDbConvertToNode (
char *InString)
{
ACPI_NAMESPACE_NODE *Node;
ACPI_SIZE Address;
if ((*InString >= 0x30) && (*InString <= 0x39))
{
/* Numeric argument, convert */
Address = ACPI_STRTOUL (InString, NULL, 16);
Node = ACPI_TO_POINTER (Address);
if (!AcpiOsReadable (Node, sizeof (ACPI_NAMESPACE_NODE)))
{
AcpiOsPrintf ("Address %p is invalid in this address space\n",
Node);
return (NULL);
}
/* Make sure pointer is valid NS node */
if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
{
AcpiOsPrintf ("Address %p is not a valid NS node [%s]\n",
Node, AcpiUtGetDescriptorName (Node));
return (NULL);
}
}
else
{
/*
* Alpha argument: The parameter is a name string that must be
* resolved to a Namespace object.
*/
Node = AcpiDbLocalNsLookup (InString);
if (!Node)
{
Node = AcpiGbl_RootNode;
}
}
return (Node);
}
/*******************************************************************************
*
* FUNCTION: AcpiDbSleep
*
* PARAMETERS: ObjectArg - Desired sleep state (0-5). NULL means
* invoke all possible sleep states.
*
* RETURN: Status
*
* DESCRIPTION: Simulate sleep/wake sequences
*
******************************************************************************/
ACPI_STATUS
AcpiDbSleep (
char *ObjectArg)
{
UINT8 SleepState;
UINT32 i;
ACPI_FUNCTION_TRACE (AcpiDbSleep);
/* Null input (no arguments) means to invoke all sleep states */
if (!ObjectArg)
{
AcpiOsPrintf ("Invoking all possible sleep states, 0-%d\n",
ACPI_S_STATES_MAX);
for (i = 0; i <= ACPI_S_STATES_MAX; i++)
{
AcpiDbDoOneSleepState ((UINT8) i);
}
return_ACPI_STATUS (AE_OK);
}
/* Convert argument to binary and invoke the sleep state */
SleepState = (UINT8) ACPI_STRTOUL (ObjectArg, NULL, 0);
AcpiDbDoOneSleepState (SleepState);
return_ACPI_STATUS (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiDbDoOneSleepState
*
* PARAMETERS: SleepState - Desired sleep state (0-5)
*
* RETURN: Status
*
* DESCRIPTION: Simulate a sleep/wake sequence
*
******************************************************************************/
static void
AcpiDbDoOneSleepState (
UINT8 SleepState)
{
ACPI_STATUS Status;
UINT8 SleepTypeA;
UINT8 SleepTypeB;
/* Validate parameter */
if (SleepState > ACPI_S_STATES_MAX)
{
AcpiOsPrintf ("Sleep state %d out of range (%d max)\n",
SleepState, ACPI_S_STATES_MAX);
return;
}
AcpiOsPrintf ("\n---- Invoking sleep state S%d (%s):\n",
SleepState, AcpiGbl_SleepStateNames[SleepState]);
/* Get the values for the sleep type registers (for display only) */
Status = AcpiGetSleepTypeData (SleepState, &SleepTypeA, &SleepTypeB);
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("Could not evaluate [%s] method, %s\n",
AcpiGbl_SleepStateNames[SleepState],
AcpiFormatException (Status));
return;
}
AcpiOsPrintf (
"Register values for sleep state S%d: Sleep-A: %.2X, Sleep-B: %.2X\n",
SleepState, SleepTypeA, SleepTypeB);
/* Invoke the various sleep/wake interfaces */
AcpiOsPrintf ("**** Sleep: Prepare to sleep (S%d) ****\n",
SleepState);
Status = AcpiEnterSleepStatePrep (SleepState);
if (ACPI_FAILURE (Status))
{
goto ErrorExit;
}
AcpiOsPrintf ("**** Sleep: Going to sleep (S%d) ****\n",
SleepState);
Status = AcpiEnterSleepState (SleepState);
if (ACPI_FAILURE (Status))
{
goto ErrorExit;
}
AcpiOsPrintf ("**** Wake: Prepare to return from sleep (S%d) ****\n",
SleepState);
Status = AcpiLeaveSleepStatePrep (SleepState);
if (ACPI_FAILURE (Status))
{
goto ErrorExit;
}
AcpiOsPrintf ("**** Wake: Return from sleep (S%d) ****\n",
SleepState);
Status = AcpiLeaveSleepState (SleepState);
if (ACPI_FAILURE (Status))
{
goto ErrorExit;
}
return;
ErrorExit:
ACPI_EXCEPTION ((AE_INFO, Status, "During invocation of sleep state S%d",
SleepState));
}
/*******************************************************************************
*
* FUNCTION: AcpiDbDisplayLocks
*
* PARAMETERS: None
*
* RETURN: None
*
* DESCRIPTION: Display information about internal mutexes.
*
******************************************************************************/
void
AcpiDbDisplayLocks (
void)
{
UINT32 i;
for (i = 0; i < ACPI_MAX_MUTEX; i++)
{
AcpiOsPrintf ("%26s : %s\n", AcpiUtGetMutexName (i),
AcpiGbl_MutexInfo[i].ThreadId == ACPI_MUTEX_NOT_ACQUIRED
? "Locked" : "Unlocked");
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDbDisplayTableInfo
*
* PARAMETERS: TableArg - Name of table to be displayed
*
* RETURN: None
*
* DESCRIPTION: Display information about loaded tables. Current
* implementation displays all loaded tables.
*
******************************************************************************/
void
AcpiDbDisplayTableInfo (
char *TableArg)
{
UINT32 i;
ACPI_TABLE_DESC *TableDesc;
ACPI_STATUS Status;
/* Header */
AcpiOsPrintf ("Idx ID Status Type Sig Address Len Header\n");
/* Walk the entire root table list */
for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
{
TableDesc = &AcpiGbl_RootTableList.Tables[i];
/* Index and Table ID */
AcpiOsPrintf ("%3u %.2u ", i, TableDesc->OwnerId);
/* Decode the table flags */
if (!(TableDesc->Flags & ACPI_TABLE_IS_LOADED))
{
AcpiOsPrintf ("NotLoaded ");
}
else
{
AcpiOsPrintf (" Loaded ");
}
switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK)
{
case ACPI_TABLE_ORIGIN_UNKNOWN:
AcpiOsPrintf ("Unknown ");
break;
case ACPI_TABLE_ORIGIN_MAPPED:
AcpiOsPrintf ("Mapped ");
break;
case ACPI_TABLE_ORIGIN_ALLOCATED:
AcpiOsPrintf ("Allocated ");
break;
case ACPI_TABLE_ORIGIN_OVERRIDE:
AcpiOsPrintf ("Override ");
break;
default:
AcpiOsPrintf ("INVALID ");
break;
}
/* Make sure that the table is mapped */
Status = AcpiTbVerifyTable (TableDesc);
if (ACPI_FAILURE (Status))
{
return;
}
/* Dump the table header */
if (TableDesc->Pointer)
{
AcpiTbPrintTableHeader (TableDesc->Address, TableDesc->Pointer);
}
else
{
/* If the pointer is null, the table has been unloaded */
ACPI_INFO ((AE_INFO, "%4.4s - Table has been unloaded",
TableDesc->Signature.Ascii));
}
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDbUnloadAcpiTable
*
* PARAMETERS: ObjectName - Namespace pathname for an object that
* is owned by the table to be unloaded
*
* RETURN: None
*
* DESCRIPTION: Unload an ACPI table, via any namespace node that is owned
* by the table.
*
******************************************************************************/
void
AcpiDbUnloadAcpiTable (
char *ObjectName)
{
ACPI_NAMESPACE_NODE *Node;
ACPI_STATUS Status;
/* Translate name to an Named object */
Node = AcpiDbConvertToNode (ObjectName);
if (!Node)
{
AcpiOsPrintf ("Could not find [%s] in namespace\n",
ObjectName);
return;
}
Status = AcpiUnloadParentTable (ACPI_CAST_PTR (ACPI_HANDLE, Node));
if (ACPI_SUCCESS (Status))
{
AcpiOsPrintf ("Parent of [%s] (%p) unloaded and uninstalled\n",
ObjectName, Node);
}
else
{
AcpiOsPrintf ("%s, while unloading parent table of [%s]\n",
AcpiFormatException (Status), ObjectName);
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDbSendNotify
*
* PARAMETERS: Name - Name of ACPI object where to send notify
* Value - Value of the notify to send.
*
* RETURN: None
*
* DESCRIPTION: Send an ACPI notification. The value specified is sent to the
* named object as an ACPI notify.
*
******************************************************************************/
void
AcpiDbSendNotify (
char *Name,
UINT32 Value)
{
ACPI_NAMESPACE_NODE *Node;
ACPI_STATUS Status;
/* Translate name to an Named object */
Node = AcpiDbConvertToNode (Name);
if (!Node)
{
return;
}
/* Dispatch the notify if legal */
if (AcpiEvIsNotifyObject (Node))
{
Status = AcpiEvQueueNotifyRequest (Node, Value);
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("Could not queue notify\n");
}
}
else
{
AcpiOsPrintf (
"Named object [%4.4s] Type %s, must be Device/Thermal/Processor type\n",
AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type));
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDbDisplayInterfaces
*
* PARAMETERS: ActionArg - Null, "install", or "remove"
* InterfaceNameArg - Name for install/remove options
*
* RETURN: None
*
* DESCRIPTION: Display or modify the global _OSI interface list
*
******************************************************************************/
void
AcpiDbDisplayInterfaces (
char *ActionArg,
char *InterfaceNameArg)
{
ACPI_INTERFACE_INFO *NextInterface;
char *SubString;
ACPI_STATUS Status;
/* If no arguments, just display current interface list */
if (!ActionArg)
{
(void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex,
ACPI_WAIT_FOREVER);
NextInterface = AcpiGbl_SupportedInterfaces;
while (NextInterface)
{
if (!(NextInterface->Flags & ACPI_OSI_INVALID))
{
AcpiOsPrintf ("%s\n", NextInterface->Name);
}
NextInterface = NextInterface->Next;
}
AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
return;
}
/* If ActionArg exists, so must InterfaceNameArg */
if (!InterfaceNameArg)
{
AcpiOsPrintf ("Missing Interface Name argument\n");
return;
}
/* Uppercase the action for match below */
AcpiUtStrupr (ActionArg);
/* Install - install an interface */
SubString = ACPI_STRSTR ("INSTALL", ActionArg);
if (SubString)
{
Status = AcpiInstallInterface (InterfaceNameArg);
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("%s, while installing \"%s\"\n",
AcpiFormatException (Status), InterfaceNameArg);
}
return;
}
/* Remove - remove an interface */
SubString = ACPI_STRSTR ("REMOVE", ActionArg);
if (SubString)
{
Status = AcpiRemoveInterface (InterfaceNameArg);
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("%s, while removing \"%s\"\n",
AcpiFormatException (Status), InterfaceNameArg);
}
return;
}
/* Invalid ActionArg */
AcpiOsPrintf ("Invalid action argument: %s\n", ActionArg);
return;
}
/*******************************************************************************
*
* FUNCTION: AcpiDbDisplayTemplate
*
* PARAMETERS: BufferArg - Buffer name or address
*
* RETURN: None
*
* DESCRIPTION: Dump a buffer that contains a resource template
*
******************************************************************************/
void
AcpiDbDisplayTemplate (
char *BufferArg)
{
ACPI_NAMESPACE_NODE *Node;
ACPI_STATUS Status;
ACPI_BUFFER ReturnBuffer;
/* Translate BufferArg to an Named object */
Node = AcpiDbConvertToNode (BufferArg);
if (!Node || (Node == AcpiGbl_RootNode))
{
AcpiOsPrintf ("Invalid argument: %s\n", BufferArg);
return;
}
/* We must have a buffer object */
if (Node->Type != ACPI_TYPE_BUFFER)
{
AcpiOsPrintf ("Not a Buffer object, cannot be a template: %s\n",
BufferArg);
return;
}
ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;
ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
/* Attempt to convert the raw buffer to a resource list */
Status = AcpiRsCreateResourceList (Node->Object, &ReturnBuffer);
AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
AcpiDbgLevel |= ACPI_LV_RESOURCES;
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("Could not convert Buffer to a resource list: %s, %s\n",
BufferArg, AcpiFormatException (Status));
goto DumpBuffer;
}
/* Now we can dump the resource list */
AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE,
ReturnBuffer.Pointer));
DumpBuffer:
AcpiOsPrintf ("\nRaw data buffer:\n");
AcpiUtDebugDumpBuffer ((UINT8 *) Node->Object->Buffer.Pointer,
Node->Object->Buffer.Length,
DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
return;
}
/*******************************************************************************
*
* FUNCTION: AcpiDmCompareAmlResources
*
* PARAMETERS: Aml1Buffer - Contains first resource list
* Aml1BufferLength - Length of first resource list
* Aml2Buffer - Contains second resource list
* Aml2BufferLength - Length of second resource list
*
* RETURN: None
*
* DESCRIPTION: Compare two AML resource lists, descriptor by descriptor (in
* order to isolate a miscompare to an individual resource)
*
******************************************************************************/
static void
AcpiDmCompareAmlResources (
UINT8 *Aml1Buffer,
ACPI_RSDESC_SIZE Aml1BufferLength,
UINT8 *Aml2Buffer,
ACPI_RSDESC_SIZE Aml2BufferLength)
{
UINT8 *Aml1;
UINT8 *Aml2;
UINT8 *Aml1End;
UINT8 *Aml2End;
ACPI_RSDESC_SIZE Aml1Length;
ACPI_RSDESC_SIZE Aml2Length;
ACPI_RSDESC_SIZE Offset = 0;
UINT8 ResourceType;
UINT32 Count = 0;
UINT32 i;
/* Compare overall buffer sizes (may be different due to size rounding) */
if (Aml1BufferLength != Aml2BufferLength)
{
AcpiOsPrintf (
"**** Buffer length mismatch in converted AML: Original %X, New %X ****\n",
Aml1BufferLength, Aml2BufferLength);
}
Aml1 = Aml1Buffer;
Aml2 = Aml2Buffer;
Aml1End = Aml1Buffer + Aml1BufferLength;
Aml2End = Aml2Buffer + Aml2BufferLength;
/* Walk the descriptor lists, comparing each descriptor */
while ((Aml1 < Aml1End) && (Aml2 < Aml2End))
{
/* Get the lengths of each descriptor */
Aml1Length = AcpiUtGetDescriptorLength (Aml1);
Aml2Length = AcpiUtGetDescriptorLength (Aml2);
ResourceType = AcpiUtGetResourceType (Aml1);
/* Check for descriptor length match */
if (Aml1Length != Aml2Length)
{
AcpiOsPrintf (
"**** Length mismatch in descriptor [%.2X] type %2.2X, Offset %8.8X Len1 %X, Len2 %X ****\n",
Count, ResourceType, Offset, Aml1Length, Aml2Length);
}
/* Check for descriptor byte match */
else if (ACPI_MEMCMP (Aml1, Aml2, Aml1Length))
{
AcpiOsPrintf (
"**** Data mismatch in descriptor [%.2X] type %2.2X, Offset %8.8X ****\n",
Count, ResourceType, Offset);
for (i = 0; i < Aml1Length; i++)
{
if (Aml1[i] != Aml2[i])
{
AcpiOsPrintf (
"Mismatch at byte offset %.2X: is %2.2X, should be %2.2X\n",
i, Aml2[i], Aml1[i]);
}
}
}
/* Exit on EndTag descriptor */
if (ResourceType == ACPI_RESOURCE_NAME_END_TAG)
{
return;
}
/* Point to next descriptor in each buffer */
Count++;
Offset += Aml1Length;
Aml1 += Aml1Length;
Aml2 += Aml2Length;
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmTestResourceConversion
*
* PARAMETERS: Node - Parent device node
* Name - resource method name (_CRS)
*
* RETURN: Status
*
* DESCRIPTION: Compare the original AML with a conversion of the AML to
* internal resource list, then back to AML.
*
******************************************************************************/
static ACPI_STATUS
AcpiDmTestResourceConversion (
ACPI_NAMESPACE_NODE *Node,
char *Name)
{
ACPI_STATUS Status;
ACPI_BUFFER ReturnBuffer;
ACPI_BUFFER ResourceBuffer;
ACPI_BUFFER NewAml;
ACPI_OBJECT *OriginalAml;
AcpiOsPrintf ("Resource Conversion Comparison:\n");
NewAml.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
ReturnBuffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
ResourceBuffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
/* Get the original _CRS AML resource template */
Status = AcpiEvaluateObject (Node, Name, NULL, &ReturnBuffer);
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("Could not obtain %s: %s\n",
Name, AcpiFormatException (Status));
return (Status);
}
/* Get the AML resource template, converted to internal resource structs */
Status = AcpiGetCurrentResources (Node, &ResourceBuffer);
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("AcpiGetCurrentResources failed: %s\n",
AcpiFormatException (Status));
goto Exit1;
}
/* Convert internal resource list to external AML resource template */
Status = AcpiRsCreateAmlResources (ResourceBuffer.Pointer, &NewAml);
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("AcpiRsCreateAmlResources failed: %s\n",
AcpiFormatException (Status));
goto Exit2;
}
/* Compare original AML to the newly created AML resource list */
OriginalAml = ReturnBuffer.Pointer;
AcpiDmCompareAmlResources (
OriginalAml->Buffer.Pointer, (ACPI_RSDESC_SIZE) OriginalAml->Buffer.Length,
NewAml.Pointer, (ACPI_RSDESC_SIZE) NewAml.Length);
/* Cleanup and exit */
ACPI_FREE (NewAml.Pointer);
Exit2:
ACPI_FREE (ResourceBuffer.Pointer);
Exit1:
ACPI_FREE (ReturnBuffer.Pointer);
return (Status);
}
/*******************************************************************************
*
* FUNCTION: AcpiDbResourceCallback
*
* PARAMETERS: ACPI_WALK_RESOURCE_CALLBACK
*
* RETURN: Status
*
* DESCRIPTION: Simple callback to exercise AcpiWalkResources and
* AcpiWalkResourceBuffer.
*
******************************************************************************/
static ACPI_STATUS
AcpiDbResourceCallback (
ACPI_RESOURCE *Resource,
void *Context)
{
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiDbDeviceResources
*
* PARAMETERS: ACPI_WALK_CALLBACK
*
* RETURN: Status
*
* DESCRIPTION: Display the _PRT/_CRS/_PRS resources for a device object.
*
******************************************************************************/
static ACPI_STATUS
AcpiDbDeviceResources (
ACPI_HANDLE ObjHandle,
UINT32 NestingLevel,
void *Context,
void **ReturnValue)
{
ACPI_NAMESPACE_NODE *Node;
ACPI_NAMESPACE_NODE *PrtNode = NULL;
ACPI_NAMESPACE_NODE *CrsNode = NULL;
ACPI_NAMESPACE_NODE *PrsNode = NULL;
ACPI_NAMESPACE_NODE *AeiNode = NULL;
char *ParentPath;
ACPI_BUFFER ReturnBuffer;
ACPI_STATUS Status;
Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
ParentPath = AcpiNsGetExternalPathname (Node);
if (!ParentPath)
{
return (AE_NO_MEMORY);
}
/* Get handles to the resource methods for this device */
(void) AcpiGetHandle (Node, METHOD_NAME__PRT, ACPI_CAST_PTR (ACPI_HANDLE, &PrtNode));
(void) AcpiGetHandle (Node, METHOD_NAME__CRS, ACPI_CAST_PTR (ACPI_HANDLE, &CrsNode));
(void) AcpiGetHandle (Node, METHOD_NAME__PRS, ACPI_CAST_PTR (ACPI_HANDLE, &PrsNode));
(void) AcpiGetHandle (Node, METHOD_NAME__AEI, ACPI_CAST_PTR (ACPI_HANDLE, &AeiNode));
if (!PrtNode && !CrsNode && !PrsNode && !AeiNode)
{
goto Cleanup; /* Nothing to do */
}
AcpiOsPrintf ("\nDevice: %s\n", ParentPath);
/* Prepare for a return object of arbitrary size */
ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;
/* _PRT */
if (PrtNode)
{
AcpiOsPrintf ("Evaluating _PRT\n");
Status = AcpiEvaluateObject (PrtNode, NULL, NULL, &ReturnBuffer);
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("Could not evaluate _PRT: %s\n",
AcpiFormatException (Status));
goto GetCrs;
}
ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;
Status = AcpiGetIrqRoutingTable (Node, &ReturnBuffer);
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("GetIrqRoutingTable failed: %s\n",
AcpiFormatException (Status));
goto GetCrs;
}
AcpiRsDumpIrqList (ACPI_CAST_PTR (UINT8, AcpiGbl_DbBuffer));
}
/* _CRS */
GetCrs:
if (CrsNode)
{
AcpiOsPrintf ("Evaluating _CRS\n");
ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;
Status = AcpiEvaluateObject (CrsNode, NULL, NULL, &ReturnBuffer);
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("Could not evaluate _CRS: %s\n",
AcpiFormatException (Status));
goto GetPrs;
}
/* This code exercises the AcpiWalkResources interface */
Status = AcpiWalkResources (Node, METHOD_NAME__CRS,
AcpiDbResourceCallback, NULL);
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("AcpiWalkResources failed: %s\n",
AcpiFormatException (Status));
goto GetPrs;
}
/* Get the _CRS resource list (test ALLOCATE buffer) */
ReturnBuffer.Pointer = NULL;
ReturnBuffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
Status = AcpiGetCurrentResources (Node, &ReturnBuffer);
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("AcpiGetCurrentResources failed: %s\n",
AcpiFormatException (Status));
goto GetPrs;
}
/* This code exercises the AcpiWalkResourceBuffer interface */
Status = AcpiWalkResourceBuffer (&ReturnBuffer,
AcpiDbResourceCallback, NULL);
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("AcpiWalkResourceBuffer failed: %s\n",
AcpiFormatException (Status));
goto EndCrs;
}
/* Dump the _CRS resource list */
AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE,
ReturnBuffer.Pointer));
/*
* Perform comparison of original AML to newly created AML. This
* tests both the AML->Resource conversion and the Resource->AML
* conversion.
*/
(void) AcpiDmTestResourceConversion (Node, METHOD_NAME__CRS);
/* Execute _SRS with the resource list */
AcpiOsPrintf ("Evaluating _SRS\n");
Status = AcpiSetCurrentResources (Node, &ReturnBuffer);
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("AcpiSetCurrentResources failed: %s\n",
AcpiFormatException (Status));
goto EndCrs;
}
EndCrs:
ACPI_FREE_BUFFER (ReturnBuffer);
}
/* _PRS */
GetPrs:
if (PrsNode)
{
AcpiOsPrintf ("Evaluating _PRS\n");
ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;
Status = AcpiEvaluateObject (PrsNode, NULL, NULL, &ReturnBuffer);
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("Could not evaluate _PRS: %s\n",
AcpiFormatException (Status));
goto GetAei;
}
ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;
Status = AcpiGetPossibleResources (Node, &ReturnBuffer);
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("AcpiGetPossibleResources failed: %s\n",
AcpiFormatException (Status));
goto GetAei;
}
AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE, AcpiGbl_DbBuffer));
}
/* _AEI */
GetAei:
if (AeiNode)
{
AcpiOsPrintf ("Evaluating _AEI\n");
ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;
Status = AcpiEvaluateObject (AeiNode, NULL, NULL, &ReturnBuffer);
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("Could not evaluate _AEI: %s\n",
AcpiFormatException (Status));
goto Cleanup;
}
ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;
Status = AcpiGetEventResources (Node, &ReturnBuffer);
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("AcpiGetEventResources failed: %s\n",
AcpiFormatException (Status));
goto Cleanup;
}
AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE, AcpiGbl_DbBuffer));
}
Cleanup:
ACPI_FREE (ParentPath);
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiDbDisplayResources
*
* PARAMETERS: ObjectArg - String object name or object pointer.
* NULL or "*" means "display resources for
* all devices"
*
* RETURN: None
*
* DESCRIPTION: Display the resource objects associated with a device.
*
******************************************************************************/
void
AcpiDbDisplayResources (
char *ObjectArg)
{
ACPI_NAMESPACE_NODE *Node;
AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
AcpiDbgLevel |= ACPI_LV_RESOURCES;
/* Asterisk means "display resources for all devices" */
if (!ObjectArg || (!ACPI_STRCMP (ObjectArg, "*")))
{
(void) AcpiWalkNamespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
ACPI_UINT32_MAX, AcpiDbDeviceResources, NULL, NULL, NULL);
}
else
{
/* Convert string to object pointer */
Node = AcpiDbConvertToNode (ObjectArg);
if (Node)
{
if (Node->Type != ACPI_TYPE_DEVICE)
{
AcpiOsPrintf ("%4.4s: Name is not a device object (%s)\n",
Node->Name.Ascii, AcpiUtGetTypeName (Node->Type));
}
else
{
(void) AcpiDbDeviceResources (Node, 0, NULL, NULL);
}
}
}
AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
}
#if (!ACPI_REDUCED_HARDWARE)
/*******************************************************************************
*
* FUNCTION: AcpiDbGenerateGpe
*
* PARAMETERS: GpeArg - Raw GPE number, ascii string
* BlockArg - GPE block number, ascii string
* 0 or 1 for FADT GPE blocks
*
* RETURN: None
*
* DESCRIPTION: Simulate firing of a GPE
*
******************************************************************************/
void
AcpiDbGenerateGpe (
char *GpeArg,
char *BlockArg)
{
UINT32 BlockNumber;
UINT32 GpeNumber;
ACPI_GPE_EVENT_INFO *GpeEventInfo;
GpeNumber = ACPI_STRTOUL (GpeArg, NULL, 0);
BlockNumber = ACPI_STRTOUL (BlockArg, NULL, 0);
GpeEventInfo = AcpiEvGetGpeEventInfo (ACPI_TO_POINTER (BlockNumber),
GpeNumber);
if (!GpeEventInfo)
{
AcpiOsPrintf ("Invalid GPE\n");
return;
}
(void) AcpiEvGpeDispatch (NULL, GpeEventInfo, GpeNumber);
}
void
AcpiDbGenerateSci (
void)
{
AcpiEvSciDispatch ();
}
#endif /* !ACPI_REDUCED_HARDWARE */
#endif /* ACPI_DEBUGGER */
|