xref: /freebsd/sys/contrib/dev/acpica/components/debugger/dbcmds.c (revision a90b9d0159070121c221b966469c3e36d912bf82)
1 /*******************************************************************************
2  *
3  * Module Name: dbcmds - Miscellaneous debug commands and output routines
4  *
5  ******************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2023, 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/acevents.h>
155 #include <contrib/dev/acpica/include/acdebug.h>
156 #include <contrib/dev/acpica/include/acnamesp.h>
157 #include <contrib/dev/acpica/include/acresrc.h>
158 #include <contrib/dev/acpica/include/actables.h>
159 
160 #define _COMPONENT          ACPI_CA_DEBUGGER
161         ACPI_MODULE_NAME    ("dbcmds")
162 
163 
164 /* Local prototypes */
165 
166 static void
167 AcpiDmCompareAmlResources (
168     UINT8                   *Aml1Buffer,
169     ACPI_RSDESC_SIZE        Aml1BufferLength,
170     UINT8                   *Aml2Buffer,
171     ACPI_RSDESC_SIZE        Aml2BufferLength);
172 
173 static ACPI_STATUS
174 AcpiDmTestResourceConversion (
175     ACPI_NAMESPACE_NODE     *Node,
176     char                    *Name);
177 
178 static ACPI_STATUS
179 AcpiDbResourceCallback (
180     ACPI_RESOURCE           *Resource,
181     void                    *Context);
182 
183 static ACPI_STATUS
184 AcpiDbDeviceResources (
185     ACPI_HANDLE             ObjHandle,
186     UINT32                  NestingLevel,
187     void                    *Context,
188     void                    **ReturnValue);
189 
190 static void
191 AcpiDbDoOneSleepState (
192     UINT8                   SleepState);
193 
194 
195 static char                 *AcpiDbTraceMethodName = NULL;
196 
197 
198 /*******************************************************************************
199  *
200  * FUNCTION:    AcpiDbConvertToNode
201  *
202  * PARAMETERS:  InString            - String to convert
203  *
204  * RETURN:      Pointer to a NS node
205  *
206  * DESCRIPTION: Convert a string to a valid NS pointer. Handles numeric or
207  *              alphanumeric strings.
208  *
209  ******************************************************************************/
210 
211 ACPI_NAMESPACE_NODE *
212 AcpiDbConvertToNode (
213     char                    *InString)
214 {
215     ACPI_NAMESPACE_NODE     *Node;
216     ACPI_SIZE               Address;
217 
218 
219     if ((*InString >= 0x30) && (*InString <= 0x39))
220     {
221         /* Numeric argument, convert */
222 
223         Address = strtoul (InString, NULL, 16);
224         Node = ACPI_TO_POINTER (Address);
225         if (!AcpiOsReadable (Node, sizeof (ACPI_NAMESPACE_NODE)))
226         {
227             AcpiOsPrintf ("Address %p is invalid", Node);
228             return (NULL);
229         }
230 
231         /* Make sure pointer is valid NS node */
232 
233         if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
234         {
235             AcpiOsPrintf ("Address %p is not a valid namespace node [%s]\n",
236                 Node, AcpiUtGetDescriptorName (Node));
237             return (NULL);
238         }
239     }
240     else
241     {
242         /*
243          * Alpha argument: The parameter is a name string that must be
244          * resolved to a Namespace object.
245          */
246         Node = AcpiDbLocalNsLookup (InString);
247         if (!Node)
248         {
249             AcpiOsPrintf (
250                 "Could not find [%s] in namespace, defaulting to root node\n",
251                 InString);
252             Node = AcpiGbl_RootNode;
253         }
254     }
255 
256     return (Node);
257 }
258 
259 
260 /*******************************************************************************
261  *
262  * FUNCTION:    AcpiDbSleep
263  *
264  * PARAMETERS:  ObjectArg           - Desired sleep state (0-5). NULL means
265  *                                    invoke all possible sleep states.
266  *
267  * RETURN:      Status
268  *
269  * DESCRIPTION: Simulate sleep/wake sequences
270  *
271  ******************************************************************************/
272 
273 ACPI_STATUS
274 AcpiDbSleep (
275     char                    *ObjectArg)
276 {
277     UINT8                   SleepState;
278     UINT32                  i;
279 
280 
281     ACPI_FUNCTION_TRACE (AcpiDbSleep);
282 
283 
284     /* Null input (no arguments) means to invoke all sleep states */
285 
286     if (!ObjectArg)
287     {
288         AcpiOsPrintf ("Invoking all possible sleep states, 0-%d\n",
289             ACPI_S_STATES_MAX);
290 
291         for (i = 0; i <= ACPI_S_STATES_MAX; i++)
292         {
293             AcpiDbDoOneSleepState ((UINT8) i);
294         }
295 
296         return_ACPI_STATUS (AE_OK);
297     }
298 
299     /* Convert argument to binary and invoke the sleep state */
300 
301     SleepState = (UINT8) strtoul (ObjectArg, NULL, 0);
302     AcpiDbDoOneSleepState (SleepState);
303     return_ACPI_STATUS (AE_OK);
304 }
305 
306 
307 /*******************************************************************************
308  *
309  * FUNCTION:    AcpiDbDoOneSleepState
310  *
311  * PARAMETERS:  SleepState          - Desired sleep state (0-5)
312  *
313  * RETURN:      None
314  *
315  * DESCRIPTION: Simulate a sleep/wake sequence
316  *
317  ******************************************************************************/
318 
319 static void
320 AcpiDbDoOneSleepState (
321     UINT8                   SleepState)
322 {
323     ACPI_STATUS             Status;
324     UINT8                   SleepTypeA;
325     UINT8                   SleepTypeB;
326 
327 
328     /* Validate parameter */
329 
330     if (SleepState > ACPI_S_STATES_MAX)
331     {
332         AcpiOsPrintf ("Sleep state %d out of range (%d max)\n",
333             SleepState, ACPI_S_STATES_MAX);
334         return;
335     }
336 
337     AcpiOsPrintf ("\n---- Invoking sleep state S%d (%s):\n",
338         SleepState, AcpiGbl_SleepStateNames[SleepState]);
339 
340     /* Get the values for the sleep type registers (for display only) */
341 
342     Status = AcpiGetSleepTypeData (SleepState, &SleepTypeA, &SleepTypeB);
343     if (ACPI_FAILURE (Status))
344     {
345         AcpiOsPrintf ("Could not evaluate [%s] method, %s\n",
346             AcpiGbl_SleepStateNames[SleepState],
347             AcpiFormatException (Status));
348         return;
349     }
350 
351     AcpiOsPrintf (
352         "Register values for sleep state S%d: Sleep-A: %.2X, Sleep-B: %.2X\n",
353         SleepState, SleepTypeA, SleepTypeB);
354 
355     /* Invoke the various sleep/wake interfaces */
356 
357     AcpiOsPrintf ("**** Sleep: Prepare to sleep (S%d) ****\n",
358         SleepState);
359     Status = AcpiEnterSleepStatePrep (SleepState);
360     if (ACPI_FAILURE (Status))
361     {
362         goto ErrorExit;
363     }
364 
365     AcpiOsPrintf ("**** Sleep: Going to sleep (S%d) ****\n",
366         SleepState);
367     Status = AcpiEnterSleepState (SleepState);
368     if (ACPI_FAILURE (Status))
369     {
370         goto ErrorExit;
371     }
372 
373     AcpiOsPrintf ("**** Wake: Prepare to return from sleep (S%d) ****\n",
374         SleepState);
375     Status = AcpiLeaveSleepStatePrep (SleepState);
376     if (ACPI_FAILURE (Status))
377     {
378         goto ErrorExit;
379     }
380 
381     AcpiOsPrintf ("**** Wake: Return from sleep (S%d) ****\n",
382         SleepState);
383     Status = AcpiLeaveSleepState (SleepState);
384     if (ACPI_FAILURE (Status))
385     {
386         goto ErrorExit;
387     }
388 
389     return;
390 
391 
392 ErrorExit:
393     ACPI_EXCEPTION ((AE_INFO, Status, "During invocation of sleep state S%d",
394         SleepState));
395 }
396 
397 
398 /*******************************************************************************
399  *
400  * FUNCTION:    AcpiDbDisplayLocks
401  *
402  * PARAMETERS:  None
403  *
404  * RETURN:      None
405  *
406  * DESCRIPTION: Display information about internal mutexes.
407  *
408  ******************************************************************************/
409 
410 void
411 AcpiDbDisplayLocks (
412     void)
413 {
414     UINT32                  i;
415 
416 
417     for (i = 0; i < ACPI_MAX_MUTEX; i++)
418     {
419         AcpiOsPrintf ("%26s : %s\n", AcpiUtGetMutexName (i),
420             AcpiGbl_MutexInfo[i].ThreadId == ACPI_MUTEX_NOT_ACQUIRED
421                 ? "Locked" : "Unlocked");
422     }
423 }
424 
425 
426 /*******************************************************************************
427  *
428  * FUNCTION:    AcpiDbDisplayTableInfo
429  *
430  * PARAMETERS:  TableArg            - Name of table to be displayed
431  *
432  * RETURN:      None
433  *
434  * DESCRIPTION: Display information about loaded tables. Current
435  *              implementation displays all loaded tables.
436  *
437  ******************************************************************************/
438 
439 void
440 AcpiDbDisplayTableInfo (
441     char                    *TableArg)
442 {
443     UINT32                  i;
444     ACPI_TABLE_DESC         *TableDesc;
445     ACPI_STATUS             Status;
446 
447 
448     /* Header */
449 
450     AcpiOsPrintf ("Idx ID    Status Type                    "
451         "TableHeader (Sig, Address, Length, Misc)\n");
452 
453     /* Walk the entire root table list */
454 
455     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
456     {
457         TableDesc = &AcpiGbl_RootTableList.Tables[i];
458 
459         /* Index and Table ID */
460 
461         AcpiOsPrintf ("%3u %.2u ", i, TableDesc->OwnerId);
462 
463         /* Decode the table flags */
464 
465         if (!(TableDesc->Flags & ACPI_TABLE_IS_LOADED))
466         {
467             AcpiOsPrintf ("NotLoaded ");
468         }
469         else
470         {
471             AcpiOsPrintf ("   Loaded ");
472         }
473 
474         switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK)
475         {
476         case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
477 
478             AcpiOsPrintf ("External/virtual  ");
479             break;
480 
481         case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
482 
483             AcpiOsPrintf ("Internal/physical ");
484             break;
485 
486         case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
487 
488             AcpiOsPrintf ("Internal/virtual  ");
489             break;
490 
491         default:
492 
493             AcpiOsPrintf ("INVALID TYPE      ");
494             break;
495         }
496 
497         /* Make sure that the table is mapped */
498 
499         Status = AcpiTbValidateTable (TableDesc);
500         if (ACPI_FAILURE (Status))
501         {
502             return;
503         }
504 
505         /* Dump the table header */
506 
507         if (TableDesc->Pointer)
508         {
509             AcpiTbPrintTableHeader (TableDesc->Address, TableDesc->Pointer);
510         }
511         else
512         {
513             /* If the pointer is null, the table has been unloaded */
514 
515             ACPI_INFO (("%4.4s - Table has been unloaded",
516                 TableDesc->Signature.Ascii));
517         }
518     }
519 }
520 
521 
522 /*******************************************************************************
523  *
524  * FUNCTION:    AcpiDbUnloadAcpiTable
525  *
526  * PARAMETERS:  ObjectName          - Namespace pathname for an object that
527  *                                    is owned by the table to be unloaded
528  *
529  * RETURN:      None
530  *
531  * DESCRIPTION: Unload an ACPI table, via any namespace node that is owned
532  *              by the table.
533  *
534  ******************************************************************************/
535 
536 void
537 AcpiDbUnloadAcpiTable (
538     char                    *ObjectName)
539 {
540     ACPI_NAMESPACE_NODE     *Node;
541     ACPI_STATUS             Status;
542 
543 
544     /* Translate name to an Named object */
545 
546     Node = AcpiDbConvertToNode (ObjectName);
547     if (!Node)
548     {
549         return;
550     }
551 
552     Status = AcpiUnloadParentTable (ACPI_CAST_PTR (ACPI_HANDLE, Node));
553     if (ACPI_SUCCESS (Status))
554     {
555         AcpiOsPrintf ("Parent of [%s] (%p) unloaded and uninstalled\n",
556             ObjectName, Node);
557     }
558     else
559     {
560         AcpiOsPrintf ("%s, while unloading parent table of [%s]\n",
561             AcpiFormatException (Status), ObjectName);
562     }
563 }
564 
565 
566 /*******************************************************************************
567  *
568  * FUNCTION:    AcpiDbSendNotify
569  *
570  * PARAMETERS:  Name                - Name of ACPI object where to send notify
571  *              Value               - Value of the notify to send.
572  *
573  * RETURN:      None
574  *
575  * DESCRIPTION: Send an ACPI notification. The value specified is sent to the
576  *              named object as an ACPI notify.
577  *
578  ******************************************************************************/
579 
580 void
581 AcpiDbSendNotify (
582     char                    *Name,
583     UINT32                  Value)
584 {
585     ACPI_NAMESPACE_NODE     *Node;
586     ACPI_STATUS             Status;
587 
588 
589     /* Translate name to an Named object */
590 
591     Node = AcpiDbConvertToNode (Name);
592     if (!Node)
593     {
594         return;
595     }
596 
597     /* Dispatch the notify if legal */
598 
599     if (AcpiEvIsNotifyObject (Node))
600     {
601         Status = AcpiEvQueueNotifyRequest (Node, Value);
602         if (ACPI_FAILURE (Status))
603         {
604             AcpiOsPrintf ("Could not queue notify\n");
605         }
606     }
607     else
608     {
609         AcpiOsPrintf (
610             "Named object [%4.4s] Type %s, "
611             "must be Device/Thermal/Processor type\n",
612             AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type));
613     }
614 }
615 
616 
617 /*******************************************************************************
618  *
619  * FUNCTION:    AcpiDbDisplayInterfaces
620  *
621  * PARAMETERS:  ActionArg           - Null, "install", or "remove"
622  *              InterfaceNameArg    - Name for install/remove options
623  *
624  * RETURN:      None
625  *
626  * DESCRIPTION: Display or modify the global _OSI interface list
627  *
628  ******************************************************************************/
629 
630 void
631 AcpiDbDisplayInterfaces (
632     char                    *ActionArg,
633     char                    *InterfaceNameArg)
634 {
635     ACPI_INTERFACE_INFO     *NextInterface;
636     char                    *SubString;
637     ACPI_STATUS             Status;
638 
639 
640     /* If no arguments, just display current interface list */
641 
642     if (!ActionArg)
643     {
644         (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
645 
646         NextInterface = AcpiGbl_SupportedInterfaces;
647         while (NextInterface)
648         {
649             if (!(NextInterface->Flags & ACPI_OSI_INVALID))
650             {
651                 AcpiOsPrintf ("%s\n", NextInterface->Name);
652             }
653 
654             NextInterface = NextInterface->Next;
655         }
656 
657         AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
658         return;
659     }
660 
661     /* If ActionArg exists, so must InterfaceNameArg */
662 
663     if (!InterfaceNameArg)
664     {
665         AcpiOsPrintf ("Missing Interface Name argument\n");
666         return;
667     }
668 
669     /* Uppercase the action for match below */
670 
671     AcpiUtStrupr (ActionArg);
672 
673     /* Install - install an interface */
674 
675     SubString = strstr ("INSTALL", ActionArg);
676     if (SubString)
677     {
678         Status = AcpiInstallInterface (InterfaceNameArg);
679         if (ACPI_FAILURE (Status))
680         {
681             AcpiOsPrintf ("%s, while installing \"%s\"\n",
682                 AcpiFormatException (Status), InterfaceNameArg);
683         }
684         return;
685     }
686 
687     /* Remove - remove an interface */
688 
689     SubString = strstr ("REMOVE", ActionArg);
690     if (SubString)
691     {
692         Status = AcpiRemoveInterface (InterfaceNameArg);
693         if (ACPI_FAILURE (Status))
694         {
695             AcpiOsPrintf ("%s, while removing \"%s\"\n",
696                 AcpiFormatException (Status), InterfaceNameArg);
697         }
698         return;
699     }
700 
701     /* Invalid ActionArg */
702 
703     AcpiOsPrintf ("Invalid action argument: %s\n", ActionArg);
704     return;
705 }
706 
707 
708 /*******************************************************************************
709  *
710  * FUNCTION:    AcpiDbDisplayTemplate
711  *
712  * PARAMETERS:  BufferArg           - Buffer name or address
713  *
714  * RETURN:      None
715  *
716  * DESCRIPTION: Dump a buffer that contains a resource template
717  *
718  ******************************************************************************/
719 
720 void
721 AcpiDbDisplayTemplate (
722     char                    *BufferArg)
723 {
724     ACPI_NAMESPACE_NODE     *Node;
725     ACPI_STATUS             Status;
726     ACPI_BUFFER             ReturnBuffer;
727 
728 
729     /* Translate BufferArg to an Named object */
730 
731     Node = AcpiDbConvertToNode (BufferArg);
732     if (!Node || (Node == AcpiGbl_RootNode))
733     {
734         AcpiOsPrintf ("Invalid argument: %s\n", BufferArg);
735         return;
736     }
737 
738     /* We must have a buffer object */
739 
740     if (Node->Type != ACPI_TYPE_BUFFER)
741     {
742         AcpiOsPrintf ("Not a Buffer object, cannot be a template: %s\n",
743             BufferArg);
744         return;
745     }
746 
747     ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;
748     ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
749 
750     /* Attempt to convert the raw buffer to a resource list */
751 
752     Status = AcpiRsCreateResourceList (Node->Object, &ReturnBuffer);
753 
754     AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
755     AcpiDbgLevel |= ACPI_LV_RESOURCES;
756 
757     if (ACPI_FAILURE (Status))
758     {
759         AcpiOsPrintf (
760             "Could not convert Buffer to a resource list: %s, %s\n",
761             BufferArg, AcpiFormatException (Status));
762         goto DumpBuffer;
763     }
764 
765     /* Now we can dump the resource list */
766 
767     AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE,
768         ReturnBuffer.Pointer));
769 
770 DumpBuffer:
771     AcpiOsPrintf ("\nRaw data buffer:\n");
772     AcpiUtDebugDumpBuffer ((UINT8 *) Node->Object->Buffer.Pointer,
773         Node->Object->Buffer.Length,
774         DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
775 
776     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
777     return;
778 }
779 
780 
781 /*******************************************************************************
782  *
783  * FUNCTION:    AcpiDmCompareAmlResources
784  *
785  * PARAMETERS:  Aml1Buffer          - Contains first resource list
786  *              Aml1BufferLength    - Length of first resource list
787  *              Aml2Buffer          - Contains second resource list
788  *              Aml2BufferLength    - Length of second resource list
789  *
790  * RETURN:      None
791  *
792  * DESCRIPTION: Compare two AML resource lists, descriptor by descriptor (in
793  *              order to isolate a miscompare to an individual resource)
794  *
795  ******************************************************************************/
796 
797 static void
798 AcpiDmCompareAmlResources (
799     UINT8                   *Aml1Buffer,
800     ACPI_RSDESC_SIZE        Aml1BufferLength,
801     UINT8                   *Aml2Buffer,
802     ACPI_RSDESC_SIZE        Aml2BufferLength)
803 {
804     UINT8                   *Aml1;
805     UINT8                   *Aml2;
806     UINT8                   *Aml1End;
807     UINT8                   *Aml2End;
808     ACPI_RSDESC_SIZE        Aml1Length;
809     ACPI_RSDESC_SIZE        Aml2Length;
810     ACPI_RSDESC_SIZE        Offset = 0;
811     UINT8                   ResourceType;
812     UINT32                  Count = 0;
813     UINT32                  i;
814 
815 
816     /* Compare overall buffer sizes (may be different due to size rounding) */
817 
818     if (Aml1BufferLength != Aml2BufferLength)
819     {
820         AcpiOsPrintf (
821             "**** Buffer length mismatch in converted "
822             "AML: Original %X, New %X ****\n",
823             Aml1BufferLength, Aml2BufferLength);
824     }
825 
826     Aml1 = Aml1Buffer;
827     Aml2 = Aml2Buffer;
828     Aml1End = Aml1Buffer + Aml1BufferLength;
829     Aml2End = Aml2Buffer + Aml2BufferLength;
830 
831     /* Walk the descriptor lists, comparing each descriptor */
832 
833     while ((Aml1 < Aml1End) && (Aml2 < Aml2End))
834     {
835         /* Get the lengths of each descriptor */
836 
837         Aml1Length = AcpiUtGetDescriptorLength (Aml1);
838         Aml2Length = AcpiUtGetDescriptorLength (Aml2);
839         ResourceType = AcpiUtGetResourceType (Aml1);
840 
841         /* Check for descriptor length match */
842 
843         if (Aml1Length != Aml2Length)
844         {
845             AcpiOsPrintf (
846                 "**** Length mismatch in descriptor [%.2X] type %2.2X, "
847                 "Offset %8.8X Len1 %X, Len2 %X ****\n",
848                 Count, ResourceType, Offset, Aml1Length, Aml2Length);
849         }
850 
851         /* Check for descriptor byte match */
852 
853         else if (memcmp (Aml1, Aml2, Aml1Length))
854         {
855             AcpiOsPrintf (
856                 "**** Data mismatch in descriptor [%.2X] type %2.2X, "
857                 "Offset %8.8X ****\n",
858                 Count, ResourceType, Offset);
859 
860             for (i = 0; i < Aml1Length; i++)
861             {
862                 if (Aml1[i] != Aml2[i])
863                 {
864                     AcpiOsPrintf (
865                         "Mismatch at byte offset %.2X: is %2.2X, "
866                         "should be %2.2X\n",
867                         i, Aml2[i], Aml1[i]);
868                 }
869             }
870         }
871 
872         /* Exit on EndTag descriptor */
873 
874         if (ResourceType == ACPI_RESOURCE_NAME_END_TAG)
875         {
876             return;
877         }
878 
879         /* Point to next descriptor in each buffer */
880 
881         Count++;
882         Offset += Aml1Length;
883         Aml1 += Aml1Length;
884         Aml2 += Aml2Length;
885     }
886 }
887 
888 
889 /*******************************************************************************
890  *
891  * FUNCTION:    AcpiDmTestResourceConversion
892  *
893  * PARAMETERS:  Node                - Parent device node
894  *              Name                - resource method name (_CRS)
895  *
896  * RETURN:      Status
897  *
898  * DESCRIPTION: Compare the original AML with a conversion of the AML to
899  *              internal resource list, then back to AML.
900  *
901  ******************************************************************************/
902 
903 static ACPI_STATUS
904 AcpiDmTestResourceConversion (
905     ACPI_NAMESPACE_NODE     *Node,
906     char                    *Name)
907 {
908     ACPI_STATUS             Status;
909     ACPI_BUFFER             ReturnBuffer;
910     ACPI_BUFFER             ResourceBuffer;
911     ACPI_BUFFER             NewAml;
912     ACPI_OBJECT             *OriginalAml;
913 
914 
915     AcpiOsPrintf ("Resource Conversion Comparison:\n");
916 
917     NewAml.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
918     ReturnBuffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
919     ResourceBuffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
920 
921     /* Get the original _CRS AML resource template */
922 
923     Status = AcpiEvaluateObject (Node, Name, NULL, &ReturnBuffer);
924     if (ACPI_FAILURE (Status))
925     {
926         AcpiOsPrintf ("Could not obtain %s: %s\n",
927             Name, AcpiFormatException (Status));
928         return (Status);
929     }
930 
931     /* Get the AML resource template, converted to internal resource structs */
932 
933     Status = AcpiGetCurrentResources (Node, &ResourceBuffer);
934     if (ACPI_FAILURE (Status))
935     {
936         AcpiOsPrintf ("AcpiGetCurrentResources failed: %s\n",
937             AcpiFormatException (Status));
938         goto Exit1;
939     }
940 
941     /* Convert internal resource list to external AML resource template */
942 
943     Status = AcpiRsCreateAmlResources (&ResourceBuffer, &NewAml);
944     if (ACPI_FAILURE (Status))
945     {
946         AcpiOsPrintf ("AcpiRsCreateAmlResources failed: %s\n",
947             AcpiFormatException (Status));
948         goto Exit2;
949     }
950 
951     /* Compare original AML to the newly created AML resource list */
952 
953     OriginalAml = ReturnBuffer.Pointer;
954 
955     AcpiDmCompareAmlResources (OriginalAml->Buffer.Pointer,
956         (ACPI_RSDESC_SIZE) OriginalAml->Buffer.Length,
957         NewAml.Pointer, (ACPI_RSDESC_SIZE) NewAml.Length);
958 
959     /* Cleanup and exit */
960 
961     ACPI_FREE (NewAml.Pointer);
962 Exit2:
963     ACPI_FREE (ResourceBuffer.Pointer);
964 Exit1:
965     ACPI_FREE (ReturnBuffer.Pointer);
966     return (Status);
967 }
968 
969 
970 /*******************************************************************************
971  *
972  * FUNCTION:    AcpiDbResourceCallback
973  *
974  * PARAMETERS:  ACPI_WALK_RESOURCE_CALLBACK
975  *
976  * RETURN:      Status
977  *
978  * DESCRIPTION: Simple callback to exercise AcpiWalkResources and
979  *              AcpiWalkResourceBuffer.
980  *
981  ******************************************************************************/
982 
983 static ACPI_STATUS
984 AcpiDbResourceCallback (
985     ACPI_RESOURCE           *Resource,
986     void                    *Context)
987 {
988 
989     return (AE_OK);
990 }
991 
992 
993 /*******************************************************************************
994  *
995  * FUNCTION:    AcpiDbDeviceResources
996  *
997  * PARAMETERS:  ACPI_WALK_CALLBACK
998  *
999  * RETURN:      Status
1000  *
1001  * DESCRIPTION: Display the _PRT/_CRS/_PRS resources for a device object.
1002  *
1003  ******************************************************************************/
1004 
1005 static ACPI_STATUS
1006 AcpiDbDeviceResources (
1007     ACPI_HANDLE             ObjHandle,
1008     UINT32                  NestingLevel,
1009     void                    *Context,
1010     void                    **ReturnValue)
1011 {
1012     ACPI_NAMESPACE_NODE     *Node;
1013     ACPI_NAMESPACE_NODE     *PrtNode = NULL;
1014     ACPI_NAMESPACE_NODE     *CrsNode = NULL;
1015     ACPI_NAMESPACE_NODE     *PrsNode = NULL;
1016     ACPI_NAMESPACE_NODE     *AeiNode = NULL;
1017     char                    *ParentPath;
1018     ACPI_BUFFER             ReturnBuffer;
1019     ACPI_STATUS             Status;
1020 
1021 
1022     Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
1023     ParentPath = AcpiNsGetNormalizedPathname (Node, TRUE);
1024     if (!ParentPath)
1025     {
1026         return (AE_NO_MEMORY);
1027     }
1028 
1029     /* Get handles to the resource methods for this device */
1030 
1031     (void) AcpiGetHandle (Node, METHOD_NAME__PRT,
1032         ACPI_CAST_PTR (ACPI_HANDLE, &PrtNode));
1033     (void) AcpiGetHandle (Node, METHOD_NAME__CRS,
1034         ACPI_CAST_PTR (ACPI_HANDLE, &CrsNode));
1035     (void) AcpiGetHandle (Node, METHOD_NAME__PRS,
1036         ACPI_CAST_PTR (ACPI_HANDLE, &PrsNode));
1037     (void) AcpiGetHandle (Node, METHOD_NAME__AEI,
1038         ACPI_CAST_PTR (ACPI_HANDLE, &AeiNode));
1039 
1040     if (!PrtNode && !CrsNode && !PrsNode && !AeiNode)
1041     {
1042         goto Cleanup;   /* Nothing to do */
1043     }
1044 
1045     AcpiOsPrintf ("\nDevice: %s\n", ParentPath);
1046 
1047     /* Prepare for a return object of arbitrary size */
1048 
1049     ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
1050     ReturnBuffer.Length  = ACPI_DEBUG_BUFFER_SIZE;
1051 
1052 
1053     /* _PRT */
1054 
1055     if (PrtNode)
1056     {
1057         AcpiOsPrintf ("Evaluating _PRT\n");
1058 
1059         Status = AcpiEvaluateObject (PrtNode, NULL, NULL, &ReturnBuffer);
1060         if (ACPI_FAILURE (Status))
1061         {
1062             AcpiOsPrintf ("Could not evaluate _PRT: %s\n",
1063                 AcpiFormatException (Status));
1064             goto GetCrs;
1065         }
1066 
1067         ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
1068         ReturnBuffer.Length  = ACPI_DEBUG_BUFFER_SIZE;
1069 
1070         Status = AcpiGetIrqRoutingTable (Node, &ReturnBuffer);
1071         if (ACPI_FAILURE (Status))
1072         {
1073             AcpiOsPrintf ("GetIrqRoutingTable failed: %s\n",
1074                 AcpiFormatException (Status));
1075             goto GetCrs;
1076         }
1077 
1078         AcpiRsDumpIrqList (ACPI_CAST_PTR (UINT8, AcpiGbl_DbBuffer));
1079     }
1080 
1081 
1082     /* _CRS */
1083 
1084 GetCrs:
1085     if (CrsNode)
1086     {
1087         AcpiOsPrintf ("Evaluating _CRS\n");
1088 
1089         ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
1090         ReturnBuffer.Length  = ACPI_DEBUG_BUFFER_SIZE;
1091 
1092         Status = AcpiEvaluateObject (CrsNode, NULL, NULL, &ReturnBuffer);
1093         if (ACPI_FAILURE (Status))
1094         {
1095             AcpiOsPrintf ("Could not evaluate _CRS: %s\n",
1096                 AcpiFormatException (Status));
1097             goto GetPrs;
1098         }
1099 
1100         /* This code exercises the AcpiWalkResources interface */
1101 
1102         Status = AcpiWalkResources (Node, METHOD_NAME__CRS,
1103             AcpiDbResourceCallback, NULL);
1104         if (ACPI_FAILURE (Status))
1105         {
1106             AcpiOsPrintf ("AcpiWalkResources failed: %s\n",
1107                 AcpiFormatException (Status));
1108             goto GetPrs;
1109         }
1110 
1111         /* Get the _CRS resource list (test ALLOCATE buffer) */
1112 
1113         ReturnBuffer.Pointer = NULL;
1114         ReturnBuffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
1115 
1116         Status = AcpiGetCurrentResources (Node, &ReturnBuffer);
1117         if (ACPI_FAILURE (Status))
1118         {
1119             AcpiOsPrintf ("AcpiGetCurrentResources failed: %s\n",
1120                 AcpiFormatException (Status));
1121             goto GetPrs;
1122         }
1123 
1124         /* This code exercises the AcpiWalkResourceBuffer interface */
1125 
1126         Status = AcpiWalkResourceBuffer (&ReturnBuffer,
1127             AcpiDbResourceCallback, NULL);
1128         if (ACPI_FAILURE (Status))
1129         {
1130             AcpiOsPrintf ("AcpiWalkResourceBuffer failed: %s\n",
1131                 AcpiFormatException (Status));
1132             goto EndCrs;
1133         }
1134 
1135         /* Dump the _CRS resource list */
1136 
1137         AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE,
1138             ReturnBuffer.Pointer));
1139 
1140         /*
1141          * Perform comparison of original AML to newly created AML. This
1142          * tests both the AML->Resource conversion and the Resource->AML
1143          * conversion.
1144          */
1145         (void) AcpiDmTestResourceConversion (Node, METHOD_NAME__CRS);
1146 
1147         /* Execute _SRS with the resource list */
1148 
1149         AcpiOsPrintf ("Evaluating _SRS\n");
1150 
1151         Status = AcpiSetCurrentResources (Node, &ReturnBuffer);
1152         if (ACPI_FAILURE (Status))
1153         {
1154             AcpiOsPrintf ("AcpiSetCurrentResources failed: %s\n",
1155                 AcpiFormatException (Status));
1156             goto EndCrs;
1157         }
1158 
1159 EndCrs:
1160         ACPI_FREE (ReturnBuffer.Pointer);
1161     }
1162 
1163 
1164     /* _PRS */
1165 
1166 GetPrs:
1167     if (PrsNode)
1168     {
1169         AcpiOsPrintf ("Evaluating _PRS\n");
1170 
1171         ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
1172         ReturnBuffer.Length  = ACPI_DEBUG_BUFFER_SIZE;
1173 
1174         Status = AcpiEvaluateObject (PrsNode, NULL, NULL, &ReturnBuffer);
1175         if (ACPI_FAILURE (Status))
1176         {
1177             AcpiOsPrintf ("Could not evaluate _PRS: %s\n",
1178                 AcpiFormatException (Status));
1179             goto GetAei;
1180         }
1181 
1182         ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
1183         ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;
1184 
1185         Status = AcpiGetPossibleResources (Node, &ReturnBuffer);
1186         if (ACPI_FAILURE (Status))
1187         {
1188             AcpiOsPrintf ("AcpiGetPossibleResources failed: %s\n",
1189                 AcpiFormatException (Status));
1190             goto GetAei;
1191         }
1192 
1193         AcpiRsDumpResourceList (ACPI_CAST_PTR (
1194             ACPI_RESOURCE, AcpiGbl_DbBuffer));
1195     }
1196 
1197 
1198     /* _AEI */
1199 
1200 GetAei:
1201     if (AeiNode)
1202     {
1203         AcpiOsPrintf ("Evaluating _AEI\n");
1204 
1205         ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
1206         ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;
1207 
1208         Status = AcpiEvaluateObject (AeiNode, NULL, NULL, &ReturnBuffer);
1209         if (ACPI_FAILURE (Status))
1210         {
1211             AcpiOsPrintf ("Could not evaluate _AEI: %s\n",
1212                 AcpiFormatException (Status));
1213             goto Cleanup;
1214         }
1215 
1216         ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
1217         ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;
1218 
1219         Status = AcpiGetEventResources (Node, &ReturnBuffer);
1220         if (ACPI_FAILURE (Status))
1221         {
1222             AcpiOsPrintf ("AcpiGetEventResources failed: %s\n",
1223                 AcpiFormatException (Status));
1224             goto Cleanup;
1225         }
1226 
1227         AcpiRsDumpResourceList (ACPI_CAST_PTR (
1228             ACPI_RESOURCE, AcpiGbl_DbBuffer));
1229     }
1230 
1231 
1232 Cleanup:
1233     ACPI_FREE (ParentPath);
1234     return (AE_OK);
1235 }
1236 
1237 
1238 /*******************************************************************************
1239  *
1240  * FUNCTION:    AcpiDbDisplayResources
1241  *
1242  * PARAMETERS:  ObjectArg           - String object name or object pointer.
1243  *                                    NULL or "*" means "display resources for
1244  *                                    all devices"
1245  *
1246  * RETURN:      None
1247  *
1248  * DESCRIPTION: Display the resource objects associated with a device.
1249  *
1250  ******************************************************************************/
1251 
1252 void
1253 AcpiDbDisplayResources (
1254     char                    *ObjectArg)
1255 {
1256     ACPI_NAMESPACE_NODE     *Node;
1257 
1258 
1259     AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
1260     AcpiDbgLevel |= ACPI_LV_RESOURCES;
1261 
1262     /* Asterisk means "display resources for all devices" */
1263 
1264     if (!ObjectArg || (!strcmp (ObjectArg, "*")))
1265     {
1266         (void) AcpiWalkNamespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
1267             ACPI_UINT32_MAX, AcpiDbDeviceResources, NULL, NULL, NULL);
1268     }
1269     else
1270     {
1271         /* Convert string to object pointer */
1272 
1273         Node = AcpiDbConvertToNode (ObjectArg);
1274         if (Node)
1275         {
1276             if (Node->Type != ACPI_TYPE_DEVICE)
1277             {
1278                 AcpiOsPrintf (
1279                     "%4.4s: Name is not a device object (%s)\n",
1280                     Node->Name.Ascii, AcpiUtGetTypeName (Node->Type));
1281             }
1282             else
1283             {
1284                 (void) AcpiDbDeviceResources (Node, 0, NULL, NULL);
1285             }
1286         }
1287     }
1288 
1289     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
1290 }
1291 
1292 
1293 /*******************************************************************************
1294  *
1295  * FUNCTION:    AcpiDbGenerateGed
1296  *
1297  * PARAMETERS:  GedArg              - Raw GED number, ascii string
1298  *
1299  * RETURN:      None
1300  *
1301  * DESCRIPTION: Simulate firing of a GED
1302  *
1303  ******************************************************************************/
1304 
1305 void
1306 AcpiDbGenerateInterrupt (
1307     char *GsivArg)
1308 {
1309     UINT32      GsivNumber;
1310     ACPI_GED_HANDLER_INFO *GedInfo = AcpiGbl_GedHandlerList;
1311 
1312 	if (!GedInfo) {
1313 		AcpiOsPrintf ("No GED handling present\n");
1314 	}
1315 
1316     GsivNumber = strtoul (GsivArg, NULL, 0);
1317 
1318 	while (GedInfo) {
1319 
1320 		if (GedInfo->IntId == GsivNumber) {
1321 			ACPI_OBJECT_LIST ArgList;
1322 			ACPI_OBJECT Arg0;
1323 			ACPI_HANDLE EvtHandle = GedInfo->EvtMethod;
1324 			ACPI_STATUS Status;
1325 
1326 			AcpiOsPrintf ("Evaluate GED _EVT (GSIV=%d)\n", GsivNumber);
1327 
1328 			if (!EvtHandle) {
1329 				AcpiOsPrintf ("Undefined _EVT method\n");
1330 				return;
1331 			}
1332 
1333 			Arg0.Integer.Type = ACPI_TYPE_INTEGER;
1334 			Arg0.Integer.Value = GsivNumber;
1335 
1336 			ArgList.Count = 1;
1337 			ArgList.Pointer = &Arg0;
1338 
1339 			Status = AcpiEvaluateObject (EvtHandle, NULL, &ArgList, NULL);
1340 			if (ACPI_FAILURE (Status))
1341 			{
1342 				AcpiOsPrintf ("Could not evaluate _EVT\n");
1343 				return;
1344 			}
1345 
1346 		}
1347 		GedInfo = GedInfo->Next;
1348 	}
1349 }
1350 
1351 #if (!ACPI_REDUCED_HARDWARE)
1352 /*******************************************************************************
1353  *
1354  * FUNCTION:    AcpiDbGenerateGpe
1355  *
1356  * PARAMETERS:  GpeArg              - Raw GPE number, ascii string
1357  *              BlockArg            - GPE block number, ascii string
1358  *                                    0 or 1 for FADT GPE blocks
1359  *
1360  * RETURN:      None
1361  *
1362  * DESCRIPTION: Simulate firing of a GPE
1363  *
1364  ******************************************************************************/
1365 
1366 void
1367 AcpiDbGenerateGpe (
1368     char                    *GpeArg,
1369     char                    *BlockArg)
1370 {
1371     UINT32                  BlockNumber = 0;
1372     UINT32                  GpeNumber;
1373     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
1374 
1375 
1376     GpeNumber = strtoul (GpeArg, NULL, 0);
1377 
1378     /*
1379      * If no block arg, or block arg == 0 or 1, use the FADT-defined
1380      * GPE blocks.
1381      */
1382     if (BlockArg)
1383     {
1384         BlockNumber = strtoul (BlockArg, NULL, 0);
1385         if (BlockNumber == 1)
1386         {
1387             BlockNumber = 0;
1388         }
1389     }
1390 
1391     GpeEventInfo = AcpiEvGetGpeEventInfo (
1392         ACPI_TO_POINTER (BlockNumber), GpeNumber);
1393     if (!GpeEventInfo)
1394     {
1395         AcpiOsPrintf ("Invalid GPE\n");
1396         return;
1397     }
1398 
1399     (void) AcpiEvGpeDispatch (NULL, GpeEventInfo, GpeNumber);
1400 }
1401 
1402 
1403 /*******************************************************************************
1404  *
1405  * FUNCTION:    AcpiDbGenerateSci
1406  *
1407  * PARAMETERS:  None
1408  *
1409  * RETURN:      None
1410  *
1411  * DESCRIPTION: Simulate an SCI -- just call the SCI dispatch.
1412  *
1413  ******************************************************************************/
1414 
1415 void
1416 AcpiDbGenerateSci (
1417     void)
1418 {
1419     AcpiEvSciDispatch ();
1420 }
1421 
1422 #endif /* !ACPI_REDUCED_HARDWARE */
1423 
1424 
1425 /*******************************************************************************
1426  *
1427  * FUNCTION:    AcpiDbTrace
1428  *
1429  * PARAMETERS:  EnableArg           - ENABLE/AML to enable tracer
1430  *                                    DISABLE to disable tracer
1431  *              MethodArg           - Method to trace
1432  *              OnceArg             - Whether trace once
1433  *
1434  * RETURN:      None
1435  *
1436  * DESCRIPTION: Control method tracing facility
1437  *
1438  ******************************************************************************/
1439 
1440 void
1441 AcpiDbTrace (
1442     char                    *EnableArg,
1443     char                    *MethodArg,
1444     char                    *OnceArg)
1445 {
1446     UINT32                  DebugLevel = 0;
1447     UINT32                  DebugLayer = 0;
1448     UINT32                  Flags = 0;
1449 
1450 
1451     AcpiUtStrupr (EnableArg);
1452     AcpiUtStrupr (OnceArg);
1453 
1454     if (MethodArg)
1455     {
1456         if (AcpiDbTraceMethodName)
1457         {
1458             ACPI_FREE (AcpiDbTraceMethodName);
1459             AcpiDbTraceMethodName = NULL;
1460         }
1461 
1462         AcpiDbTraceMethodName = ACPI_ALLOCATE (strlen (MethodArg) + 1);
1463         if (!AcpiDbTraceMethodName)
1464         {
1465             AcpiOsPrintf ("Failed to allocate method name (%s)\n",
1466                 MethodArg);
1467             return;
1468         }
1469 
1470         strcpy (AcpiDbTraceMethodName, MethodArg);
1471     }
1472 
1473     if (!strcmp (EnableArg, "ENABLE") ||
1474         !strcmp (EnableArg, "METHOD") ||
1475         !strcmp (EnableArg, "OPCODE"))
1476     {
1477         if (!strcmp (EnableArg, "ENABLE"))
1478         {
1479             /* Inherit current console settings */
1480 
1481             DebugLevel = AcpiGbl_DbConsoleDebugLevel;
1482             DebugLayer = AcpiDbgLayer;
1483         }
1484         else
1485         {
1486             /* Restrict console output to trace points only */
1487 
1488             DebugLevel = ACPI_LV_TRACE_POINT;
1489             DebugLayer = ACPI_EXECUTER;
1490         }
1491 
1492         Flags = ACPI_TRACE_ENABLED;
1493 
1494         if (!strcmp (EnableArg, "OPCODE"))
1495         {
1496             Flags |= ACPI_TRACE_OPCODE;
1497         }
1498 
1499         if (OnceArg && !strcmp (OnceArg, "ONCE"))
1500         {
1501             Flags |= ACPI_TRACE_ONESHOT;
1502         }
1503     }
1504 
1505     (void) AcpiDebugTrace (AcpiDbTraceMethodName,
1506         DebugLevel, DebugLayer, Flags);
1507 }
1508