dbnames.c revision 241973
12343Scsgr/*******************************************************************************
22343Scsgr *
32343Scsgr * Module Name: dbnames - Debugger commands for the acpi namespace
42343Scsgr *
52343Scsgr ******************************************************************************/
62343Scsgr
72343Scsgr/*
82343Scsgr * Copyright (C) 2000 - 2012, Intel Corp.
92343Scsgr * All rights reserved.
102343Scsgr *
112343Scsgr * Redistribution and use in source and binary forms, with or without
122343Scsgr * modification, are permitted provided that the following conditions
132343Scsgr * are met:
142343Scsgr * 1. Redistributions of source code must retain the above copyright
152343Scsgr *    notice, this list of conditions, and the following disclaimer,
162343Scsgr *    without modification.
172343Scsgr * 2. Redistributions in binary form must reproduce at minimum a disclaimer
182343Scsgr *    substantially similar to the "NO WARRANTY" disclaimer below
192343Scsgr *    ("Disclaimer") and any redistribution must be conditioned upon
202343Scsgr *    including a substantially similar Disclaimer requirement for further
212343Scsgr *    binary redistribution.
222343Scsgr * 3. Neither the names of the above-listed copyright holders nor the names
232343Scsgr *    of any contributors may be used to endorse or promote products derived
242343Scsgr *    from this software without specific prior written permission.
252343Scsgr *
262343Scsgr * Alternatively, this software may be distributed under the terms of the
272343Scsgr * GNU General Public License ("GPL") version 2 as published by the Free
282343Scsgr * Software Foundation.
292343Scsgr *
302343Scsgr * NO WARRANTY
312343Scsgr * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
322343Scsgr * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
332343Scsgr * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3495616Smarkm * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
352343Scsgr * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3695616Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3795616Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
382343Scsgr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
392343Scsgr * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4095616Smarkm * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
412343Scsgr * POSSIBILITY OF SUCH DAMAGES.
4227955Scharnier */
4395616Smarkm
442343Scsgr
452343Scsgr#include <contrib/dev/acpica/include/acpi.h>
4695616Smarkm#include <contrib/dev/acpica/include/accommon.h>
472343Scsgr#include <contrib/dev/acpica/include/acnamesp.h>
482343Scsgr#include <contrib/dev/acpica/include/acdebug.h>
4995616Smarkm
5095616Smarkm
5195616Smarkm#ifdef ACPI_DEBUGGER
5295616Smarkm
5395616Smarkm#define _COMPONENT          ACPI_CA_DEBUGGER
5495616Smarkm        ACPI_MODULE_NAME    ("dbnames")
5595616Smarkm
5695616Smarkm
5795616Smarkm/* Local prototypes */
5895616Smarkm
592343Scsgrstatic ACPI_STATUS
602343ScsgrAcpiDbWalkAndMatchName (
612343Scsgr    ACPI_HANDLE             ObjHandle,
622343Scsgr    UINT32                  NestingLevel,
632343Scsgr    void                    *Context,
642343Scsgr    void                    **ReturnValue);
652343Scsgr
6695616Smarkmstatic ACPI_STATUS
6795616SmarkmAcpiDbWalkForPredefinedNames (
682343Scsgr    ACPI_HANDLE             ObjHandle,
692343Scsgr    UINT32                  NestingLevel,
708874Srgrimes    void                    *Context,
712343Scsgr    void                    **ReturnValue);
722343Scsgr
732343Scsgrstatic ACPI_STATUS
742343ScsgrAcpiDbWalkForSpecificObjects (
752343Scsgr    ACPI_HANDLE             ObjHandle,
762343Scsgr    UINT32                  NestingLevel,
772343Scsgr    void                    *Context,
782343Scsgr    void                    **ReturnValue);
792343Scsgr
802343Scsgrstatic ACPI_STATUS
8195616SmarkmAcpiDbIntegrityWalk (
8295616Smarkm    ACPI_HANDLE             ObjHandle,
832343Scsgr    UINT32                  NestingLevel,
842343Scsgr    void                    *Context,
852343Scsgr    void                    **ReturnValue);
8627955Scharnier
8727955Scharnierstatic ACPI_STATUS
882343ScsgrAcpiDbWalkForReferences (
892343Scsgr    ACPI_HANDLE             ObjHandle,
902343Scsgr    UINT32                  NestingLevel,
912343Scsgr    void                    *Context,
922343Scsgr    void                    **ReturnValue);
93121545Speter
9474462Salfredstatic ACPI_STATUS
952343ScsgrAcpiDbBusWalk (
962343Scsgr    ACPI_HANDLE             ObjHandle,
972343Scsgr    UINT32                  NestingLevel,
982343Scsgr    void                    *Context,
992343Scsgr    void                    **ReturnValue);
1002343Scsgr
1012343Scsgr/*
1022343Scsgr * Arguments for the Objects command
1032343Scsgr * These object types map directly to the ACPI_TYPES
104153090Sphilip */
1052343Scsgrstatic ACPI_DB_ARGUMENT_INFO    AcpiDbObjectTypes [] =
1062343Scsgr{
1072343Scsgr    {"ANY"},
1088874Srgrimes    {"INTEGERS"},
1092343Scsgr    {"STRINGS"},
1102343Scsgr    {"BUFFERS"},
1112343Scsgr    {"PACKAGES"},
1122343Scsgr    {"FIELDS"},
1132343Scsgr    {"DEVICES"},
1142343Scsgr    {"EVENTS"},
1152343Scsgr    {"METHODS"},
1162343Scsgr    {"MUTEXES"},
1172343Scsgr    {"REGIONS"},
1182343Scsgr    {"POWERRESOURCES"},
1192343Scsgr    {"PROCESSORS"},
1202343Scsgr    {"THERMALZONES"},
1212343Scsgr    {"BUFFERFIELDS"},
122153090Sphilip    {"DDBHANDLES"},
123153090Sphilip    {"DEBUG"},
124153090Sphilip    {"REGIONFIELDS"},
1252343Scsgr    {"BANKFIELDS"},
126153090Sphilip    {"INDEXFIELDS"},
1272343Scsgr    {"REFERENCES"},
128153090Sphilip    {"ALIAS"},
129153090Sphilip    {NULL}           /* Must be null terminated */
130153090Sphilip};
131153090Sphilip
132153090Sphilip
133153090Sphilip/*******************************************************************************
134153090Sphilip *
1352343Scsgr * FUNCTION:    AcpiDbSetScope
136153090Sphilip *
137153090Sphilip * PARAMETERS:  Name                - New scope path
138153090Sphilip *
139153090Sphilip * RETURN:      Status
140153090Sphilip *
141153090Sphilip * DESCRIPTION: Set the "current scope" as maintained by this utility.
142153090Sphilip *              The scope is used as a prefix to ACPI paths.
14312445Swpaul *
1442343Scsgr ******************************************************************************/
14512445Swpaul
14612445Swpaulvoid
1472343ScsgrAcpiDbSetScope (
1482343Scsgr    char                    *Name)
1492343Scsgr{
1502343Scsgr    ACPI_STATUS             Status;
1512343Scsgr    ACPI_NAMESPACE_NODE     *Node;
1522343Scsgr
1532343Scsgr
1542343Scsgr    if (!Name || Name[0] == 0)
1552343Scsgr    {
15685039Sfenner        AcpiOsPrintf ("Current scope: %s\n", AcpiGbl_DbScopeBuf);
15785039Sfenner        return;
1582343Scsgr    }
1592343Scsgr
1602343Scsgr    AcpiDbPrepNamestring (Name);
1612343Scsgr
16234993Sdanny    if (Name[0] == '\\')
1632343Scsgr    {
1642343Scsgr        /* Validate new scope from the root */
1652343Scsgr
1662343Scsgr        Status = AcpiNsGetNode (AcpiGbl_RootNode, Name, ACPI_NS_NO_UPSEARCH,
1672343Scsgr                    &Node);
1682343Scsgr        if (ACPI_FAILURE (Status))
1692343Scsgr        {
1702343Scsgr            goto ErrorExit;
1712343Scsgr        }
1722343Scsgr
1732343Scsgr        ACPI_STRCPY (AcpiGbl_DbScopeBuf, Name);
1742343Scsgr        ACPI_STRCAT (AcpiGbl_DbScopeBuf, "\\");
17595616Smarkm    }
1762343Scsgr    else
1772343Scsgr    {
1782343Scsgr        /* Validate new scope relative to old scope */
1792343Scsgr
1802343Scsgr        Status = AcpiNsGetNode (AcpiGbl_DbScopeNode, Name, ACPI_NS_NO_UPSEARCH,
1812343Scsgr                    &Node);
18221093Speter        if (ACPI_FAILURE (Status))
1838874Srgrimes        {
1842343Scsgr            goto ErrorExit;
1852343Scsgr        }
18627955Scharnier
1872343Scsgr        ACPI_STRCAT (AcpiGbl_DbScopeBuf, Name);
1882343Scsgr        ACPI_STRCAT (AcpiGbl_DbScopeBuf, "\\");
1892343Scsgr    }
1902343Scsgr
1912343Scsgr    AcpiGbl_DbScopeNode = Node;
19227955Scharnier    AcpiOsPrintf ("New scope: %s\n", AcpiGbl_DbScopeBuf);
1932343Scsgr    return;
1942343Scsgr
1952343ScsgrErrorExit:
1962343Scsgr
19721093Speter    AcpiOsPrintf ("Could not attach scope: %s, %s\n",
19821093Speter        Name, AcpiFormatException (Status));
199121545Speter}
200121545Speter
201121545Speter
20227955Scharnier/*******************************************************************************
20378456Smikeh *
2042343Scsgr * FUNCTION:    AcpiDbDumpNamespace
2052343Scsgr *
2062343Scsgr * PARAMETERS:  StartArg        - Node to begin namespace dump
2072343Scsgr *              DepthArg        - Maximum tree depth to be dumped
20874462Salfred *
20978456Smikeh * RETURN:      None
21027955Scharnier *
2112343Scsgr * DESCRIPTION: Dump entire namespace or a subtree. Each node is displayed
2122343Scsgr *              with type and other information.
21395616Smarkm *
21495616Smarkm ******************************************************************************/
2152343Scsgr
2162343Scsgrvoid
2172343ScsgrAcpiDbDumpNamespace (
2182343Scsgr    char                    *StartArg,
2192343Scsgr    char                    *DepthArg)
220121545Speter{
221121545Speter    ACPI_HANDLE             SubtreeEntry = AcpiGbl_RootNode;
222121545Speter    UINT32                  MaxDepth = ACPI_UINT32_MAX;
22327955Scharnier
22427955Scharnier
2252343Scsgr    /* No argument given, just start at the root and dump entire namespace */
2262343Scsgr
22727955Scharnier    if (StartArg)
22895616Smarkm    {
2292343Scsgr        SubtreeEntry = AcpiDbConvertToNode (StartArg);
230146466Sru        if (!SubtreeEntry)
2312343Scsgr        {
2322343Scsgr            return;
2332343Scsgr        }
23427955Scharnier
2352343Scsgr        /* Now we can check for the depth argument */
2362343Scsgr
2372343Scsgr        if (DepthArg)
2382343Scsgr        {
2392343Scsgr            MaxDepth = ACPI_STRTOUL (DepthArg, NULL, 0);
2402343Scsgr        }
2412343Scsgr    }
2422343Scsgr
2432343Scsgr    AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
2442343Scsgr    AcpiOsPrintf ("ACPI Namespace (from %4.4s (%p) subtree):\n",
2458874Srgrimes        ((ACPI_NAMESPACE_NODE *) SubtreeEntry)->Name.Ascii, SubtreeEntry);
2462343Scsgr
2472343Scsgr    /* Display the subtree */
2482343Scsgr
2492343Scsgr    AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
2502343Scsgr    AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, MaxDepth,
2512343Scsgr        ACPI_OWNER_ID_MAX, SubtreeEntry);
2522343Scsgr    AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
2532343Scsgr}
2542343Scsgr
255
256/*******************************************************************************
257 *
258 * FUNCTION:    AcpiDbDumpNamespaceByOwner
259 *
260 * PARAMETERS:  OwnerArg        - Owner ID whose nodes will be displayed
261 *              DepthArg        - Maximum tree depth to be dumped
262 *
263 * RETURN:      None
264 *
265 * DESCRIPTION: Dump elements of the namespace that are owned by the OwnerId.
266 *
267 ******************************************************************************/
268
269void
270AcpiDbDumpNamespaceByOwner (
271    char                    *OwnerArg,
272    char                    *DepthArg)
273{
274    ACPI_HANDLE             SubtreeEntry = AcpiGbl_RootNode;
275    UINT32                  MaxDepth = ACPI_UINT32_MAX;
276    ACPI_OWNER_ID           OwnerId;
277
278
279    OwnerId = (ACPI_OWNER_ID) ACPI_STRTOUL (OwnerArg, NULL, 0);
280
281    /* Now we can check for the depth argument */
282
283    if (DepthArg)
284    {
285        MaxDepth = ACPI_STRTOUL (DepthArg, NULL, 0);
286    }
287
288    AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
289    AcpiOsPrintf ("ACPI Namespace by owner %X:\n", OwnerId);
290
291    /* Display the subtree */
292
293    AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
294    AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, MaxDepth, OwnerId,
295        SubtreeEntry);
296    AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
297}
298
299
300/*******************************************************************************
301 *
302 * FUNCTION:    AcpiDbWalkAndMatchName
303 *
304 * PARAMETERS:  Callback from WalkNamespace
305 *
306 * RETURN:      Status
307 *
308 * DESCRIPTION: Find a particular name/names within the namespace. Wildcards
309 *              are supported -- '?' matches any character.
310 *
311 ******************************************************************************/
312
313static ACPI_STATUS
314AcpiDbWalkAndMatchName (
315    ACPI_HANDLE             ObjHandle,
316    UINT32                  NestingLevel,
317    void                    *Context,
318    void                    **ReturnValue)
319{
320    ACPI_STATUS             Status;
321    char                    *RequestedName = (char *) Context;
322    UINT32                  i;
323    ACPI_BUFFER             Buffer;
324    ACPI_WALK_INFO          Info;
325
326
327    /* Check for a name match */
328
329    for (i = 0; i < 4; i++)
330    {
331        /* Wildcard support */
332
333        if ((RequestedName[i] != '?') &&
334            (RequestedName[i] != ((ACPI_NAMESPACE_NODE *) ObjHandle)->Name.Ascii[i]))
335        {
336            /* No match, just exit */
337
338            return (AE_OK);
339        }
340    }
341
342    /* Get the full pathname to this object */
343
344    Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
345    Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
346    if (ACPI_FAILURE (Status))
347    {
348        AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
349    }
350    else
351    {
352        Info.OwnerId = ACPI_OWNER_ID_MAX;
353        Info.DebugLevel = ACPI_UINT32_MAX;
354        Info.DisplayType = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT;
355
356        AcpiOsPrintf ("%32s", (char *) Buffer.Pointer);
357        (void) AcpiNsDumpOneObject (ObjHandle, NestingLevel, &Info, NULL);
358        ACPI_FREE (Buffer.Pointer);
359    }
360
361    return (AE_OK);
362}
363
364
365/*******************************************************************************
366 *
367 * FUNCTION:    AcpiDbFindNameInNamespace
368 *
369 * PARAMETERS:  NameArg         - The 4-character ACPI name to find.
370 *                                wildcards are supported.
371 *
372 * RETURN:      None
373 *
374 * DESCRIPTION: Search the namespace for a given name (with wildcards)
375 *
376 ******************************************************************************/
377
378ACPI_STATUS
379AcpiDbFindNameInNamespace (
380    char                    *NameArg)
381{
382    char                    AcpiName[5] = "____";
383    char                    *AcpiNamePtr = AcpiName;
384
385
386    if (ACPI_STRLEN (NameArg) > 4)
387    {
388        AcpiOsPrintf ("Name must be no longer than 4 characters\n");
389        return (AE_OK);
390    }
391
392    /* Pad out name with underscores as necessary to create a 4-char name */
393
394    AcpiUtStrupr (NameArg);
395    while (*NameArg)
396    {
397        *AcpiNamePtr = *NameArg;
398        AcpiNamePtr++;
399        NameArg++;
400    }
401
402    /* Walk the namespace from the root */
403
404    (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
405                        AcpiDbWalkAndMatchName, NULL, AcpiName, NULL);
406
407    AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
408    return (AE_OK);
409}
410
411
412/*******************************************************************************
413 *
414 * FUNCTION:    AcpiDbWalkForPredefinedNames
415 *
416 * PARAMETERS:  Callback from WalkNamespace
417 *
418 * RETURN:      Status
419 *
420 * DESCRIPTION: Detect and display predefined ACPI names (names that start with
421 *              an underscore)
422 *
423 ******************************************************************************/
424
425static ACPI_STATUS
426AcpiDbWalkForPredefinedNames (
427    ACPI_HANDLE             ObjHandle,
428    UINT32                  NestingLevel,
429    void                    *Context,
430    void                    **ReturnValue)
431{
432    ACPI_NAMESPACE_NODE         *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
433    UINT32                      *Count = (UINT32 *) Context;
434    const ACPI_PREDEFINED_INFO  *Predefined;
435    const ACPI_PREDEFINED_INFO  *Package = NULL;
436    char                        *Pathname;
437
438
439    Predefined = AcpiNsCheckForPredefinedName (Node);
440    if (!Predefined)
441    {
442        return (AE_OK);
443    }
444
445    Pathname = AcpiNsGetExternalPathname (Node);
446    if (!Pathname)
447    {
448        return (AE_OK);
449    }
450
451    /* If method returns a package, the info is in the next table entry */
452
453    if (Predefined->Info.ExpectedBtypes & ACPI_BTYPE_PACKAGE)
454    {
455        Package = Predefined + 1;
456    }
457
458    AcpiOsPrintf ("%-32s arg %X ret %2.2X", Pathname,
459        Predefined->Info.ParamCount, Predefined->Info.ExpectedBtypes);
460
461    if (Package)
462    {
463        AcpiOsPrintf (" PkgType %2.2X ObjType %2.2X Count %2.2X",
464            Package->RetInfo.Type, Package->RetInfo.ObjectType1,
465            Package->RetInfo.Count1);
466    }
467
468    AcpiOsPrintf("\n");
469
470    AcpiNsCheckParameterCount (Pathname, Node, ACPI_UINT32_MAX, Predefined);
471    ACPI_FREE (Pathname);
472    (*Count)++;
473
474    return (AE_OK);
475}
476
477
478/*******************************************************************************
479 *
480 * FUNCTION:    AcpiDbCheckPredefinedNames
481 *
482 * PARAMETERS:  None
483 *
484 * RETURN:      None
485 *
486 * DESCRIPTION: Validate all predefined names in the namespace
487 *
488 ******************************************************************************/
489
490void
491AcpiDbCheckPredefinedNames (
492    void)
493{
494    UINT32                  Count = 0;
495
496
497    /* Search all nodes in namespace */
498
499    (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
500                AcpiDbWalkForPredefinedNames, NULL, (void *) &Count, NULL);
501
502    AcpiOsPrintf ("Found %u predefined names in the namespace\n", Count);
503}
504
505
506/*******************************************************************************
507 *
508 * FUNCTION:    AcpiDbWalkForSpecificObjects
509 *
510 * PARAMETERS:  Callback from WalkNamespace
511 *
512 * RETURN:      Status
513 *
514 * DESCRIPTION: Display short info about objects in the namespace
515 *
516 ******************************************************************************/
517
518static ACPI_STATUS
519AcpiDbWalkForSpecificObjects (
520    ACPI_HANDLE             ObjHandle,
521    UINT32                  NestingLevel,
522    void                    *Context,
523    void                    **ReturnValue)
524{
525    ACPI_WALK_INFO          *Info = (ACPI_WALK_INFO *) Context;
526    ACPI_BUFFER             Buffer;
527    ACPI_STATUS             Status;
528
529
530    Info->Count++;
531
532    /* Get and display the full pathname to this object */
533
534    Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
535    Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
536    if (ACPI_FAILURE (Status))
537    {
538        AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
539        return (AE_OK);
540    }
541
542    AcpiOsPrintf ("%32s", (char *) Buffer.Pointer);
543    ACPI_FREE (Buffer.Pointer);
544
545    /* Dump short info about the object */
546
547    (void) AcpiNsDumpOneObject (ObjHandle, NestingLevel, Info, NULL);
548    return (AE_OK);
549}
550
551
552/*******************************************************************************
553 *
554 * FUNCTION:    AcpiDbDisplayObjects
555 *
556 * PARAMETERS:  ObjTypeArg          - Type of object to display
557 *              DisplayCountArg     - Max depth to display
558 *
559 * RETURN:      None
560 *
561 * DESCRIPTION: Display objects in the namespace of the requested type
562 *
563 ******************************************************************************/
564
565ACPI_STATUS
566AcpiDbDisplayObjects (
567    char                    *ObjTypeArg,
568    char                    *DisplayCountArg)
569{
570    ACPI_WALK_INFO          Info;
571    ACPI_OBJECT_TYPE        Type;
572
573
574    /* Get the object type */
575
576    Type = AcpiDbMatchArgument (ObjTypeArg, AcpiDbObjectTypes);
577    if (Type == ACPI_TYPE_NOT_FOUND)
578    {
579        AcpiOsPrintf ("Invalid or unsupported argument\n");
580        return (AE_OK);
581    }
582
583    AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
584    AcpiOsPrintf (
585        "Objects of type [%s] defined in the current ACPI Namespace:\n",
586        AcpiUtGetTypeName (Type));
587
588    AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
589
590    Info.Count = 0;
591    Info.OwnerId = ACPI_OWNER_ID_MAX;
592    Info.DebugLevel = ACPI_UINT32_MAX;
593    Info.DisplayType = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT;
594
595    /* Walk the namespace from the root */
596
597    (void) AcpiWalkNamespace (Type, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
598                AcpiDbWalkForSpecificObjects, NULL, (void *) &Info, NULL);
599
600    AcpiOsPrintf (
601        "\nFound %u objects of type [%s] in the current ACPI Namespace\n",
602        Info.Count, AcpiUtGetTypeName (Type));
603
604    AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
605    return (AE_OK);
606}
607
608
609/*******************************************************************************
610 *
611 * FUNCTION:    AcpiDbIntegrityWalk
612 *
613 * PARAMETERS:  Callback from WalkNamespace
614 *
615 * RETURN:      Status
616 *
617 * DESCRIPTION: Examine one NS node for valid values.
618 *
619 ******************************************************************************/
620
621static ACPI_STATUS
622AcpiDbIntegrityWalk (
623    ACPI_HANDLE             ObjHandle,
624    UINT32                  NestingLevel,
625    void                    *Context,
626    void                    **ReturnValue)
627{
628    ACPI_INTEGRITY_INFO     *Info = (ACPI_INTEGRITY_INFO *) Context;
629    ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
630    ACPI_OPERAND_OBJECT     *Object;
631    BOOLEAN                 Alias = TRUE;
632
633
634    Info->Nodes++;
635
636    /* Verify the NS node, and dereference aliases */
637
638    while (Alias)
639    {
640        if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
641        {
642            AcpiOsPrintf ("Invalid Descriptor Type for Node %p [%s] - is %2.2X should be %2.2X\n",
643                Node, AcpiUtGetDescriptorName (Node), ACPI_GET_DESCRIPTOR_TYPE (Node),
644                ACPI_DESC_TYPE_NAMED);
645            return (AE_OK);
646        }
647
648        if ((Node->Type == ACPI_TYPE_LOCAL_ALIAS)  ||
649            (Node->Type == ACPI_TYPE_LOCAL_METHOD_ALIAS))
650        {
651            Node = (ACPI_NAMESPACE_NODE *) Node->Object;
652        }
653        else
654        {
655            Alias = FALSE;
656        }
657    }
658
659    if (Node->Type > ACPI_TYPE_LOCAL_MAX)
660    {
661        AcpiOsPrintf ("Invalid Object Type for Node %p, Type = %X\n",
662            Node, Node->Type);
663        return (AE_OK);
664    }
665
666    if (!AcpiUtValidAcpiName (Node->Name.Integer))
667    {
668        AcpiOsPrintf ("Invalid AcpiName for Node %p\n", Node);
669        return (AE_OK);
670    }
671
672    Object = AcpiNsGetAttachedObject (Node);
673    if (Object)
674    {
675        Info->Objects++;
676        if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND)
677        {
678            AcpiOsPrintf ("Invalid Descriptor Type for Object %p [%s]\n",
679                Object, AcpiUtGetDescriptorName (Object));
680        }
681    }
682
683    return (AE_OK);
684}
685
686
687/*******************************************************************************
688 *
689 * FUNCTION:    AcpiDbCheckIntegrity
690 *
691 * PARAMETERS:  None
692 *
693 * RETURN:      None
694 *
695 * DESCRIPTION: Check entire namespace for data structure integrity
696 *
697 ******************************************************************************/
698
699void
700AcpiDbCheckIntegrity (
701    void)
702{
703    ACPI_INTEGRITY_INFO     Info = {0,0};
704
705    /* Search all nodes in namespace */
706
707    (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
708                    AcpiDbIntegrityWalk, NULL, (void *) &Info, NULL);
709
710    AcpiOsPrintf ("Verified %u namespace nodes with %u Objects\n",
711        Info.Nodes, Info.Objects);
712}
713
714
715/*******************************************************************************
716 *
717 * FUNCTION:    AcpiDbWalkForReferences
718 *
719 * PARAMETERS:  Callback from WalkNamespace
720 *
721 * RETURN:      Status
722 *
723 * DESCRIPTION: Check if this namespace object refers to the target object
724 *              that is passed in as the context value.
725 *
726 * Note: Currently doesn't check subobjects within the Node's object
727 *
728 ******************************************************************************/
729
730static ACPI_STATUS
731AcpiDbWalkForReferences (
732    ACPI_HANDLE             ObjHandle,
733    UINT32                  NestingLevel,
734    void                    *Context,
735    void                    **ReturnValue)
736{
737    ACPI_OPERAND_OBJECT     *ObjDesc = (ACPI_OPERAND_OBJECT  *) Context;
738    ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
739
740
741    /* Check for match against the namespace node itself */
742
743    if (Node == (void *) ObjDesc)
744    {
745        AcpiOsPrintf ("Object is a Node [%4.4s]\n",
746            AcpiUtGetNodeName (Node));
747    }
748
749    /* Check for match against the object attached to the node */
750
751    if (AcpiNsGetAttachedObject (Node) == ObjDesc)
752    {
753        AcpiOsPrintf ("Reference at Node->Object %p [%4.4s]\n",
754            Node, AcpiUtGetNodeName (Node));
755    }
756
757    return (AE_OK);
758}
759
760
761/*******************************************************************************
762 *
763 * FUNCTION:    AcpiDbFindReferences
764 *
765 * PARAMETERS:  ObjectArg       - String with hex value of the object
766 *
767 * RETURN:      None
768 *
769 * DESCRIPTION: Search namespace for all references to the input object
770 *
771 ******************************************************************************/
772
773void
774AcpiDbFindReferences (
775    char                    *ObjectArg)
776{
777    ACPI_OPERAND_OBJECT     *ObjDesc;
778
779
780    /* Convert string to object pointer */
781
782    ObjDesc = ACPI_TO_POINTER (ACPI_STRTOUL (ObjectArg, NULL, 16));
783
784    /* Search all nodes in namespace */
785
786    (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
787                    AcpiDbWalkForReferences, NULL, (void *) ObjDesc, NULL);
788}
789
790
791/*******************************************************************************
792 *
793 * FUNCTION:    AcpiDbBusWalk
794 *
795 * PARAMETERS:  Callback from WalkNamespace
796 *
797 * RETURN:      Status
798 *
799 * DESCRIPTION: Display info about device objects that have a corresponding
800 *              _PRT method.
801 *
802 ******************************************************************************/
803
804static ACPI_STATUS
805AcpiDbBusWalk (
806    ACPI_HANDLE             ObjHandle,
807    UINT32                  NestingLevel,
808    void                    *Context,
809    void                    **ReturnValue)
810{
811    ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
812    ACPI_STATUS             Status;
813    ACPI_BUFFER             Buffer;
814    ACPI_NAMESPACE_NODE     *TempNode;
815    ACPI_DEVICE_INFO        *Info;
816    UINT32                  i;
817
818
819    if ((Node->Type != ACPI_TYPE_DEVICE) &&
820        (Node->Type != ACPI_TYPE_PROCESSOR))
821    {
822        return (AE_OK);
823    }
824
825    /* Exit if there is no _PRT under this device */
826
827    Status = AcpiGetHandle (Node, METHOD_NAME__PRT,
828                ACPI_CAST_PTR (ACPI_HANDLE, &TempNode));
829    if (ACPI_FAILURE (Status))
830    {
831        return (AE_OK);
832    }
833
834    /* Get the full path to this device object */
835
836    Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
837    Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
838    if (ACPI_FAILURE (Status))
839    {
840        AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
841        return (AE_OK);
842    }
843
844    Status = AcpiGetObjectInfo (ObjHandle, &Info);
845    if (ACPI_FAILURE (Status))
846    {
847        return (AE_OK);
848    }
849
850    /* Display the full path */
851
852    AcpiOsPrintf ("%-32s Type %X", (char *) Buffer.Pointer, Node->Type);
853    ACPI_FREE (Buffer.Pointer);
854
855    if (Info->Flags & ACPI_PCI_ROOT_BRIDGE)
856    {
857        AcpiOsPrintf ("  - Is PCI Root Bridge");
858    }
859    AcpiOsPrintf ("\n");
860
861    /* _PRT info */
862
863    AcpiOsPrintf ("_PRT: %p\n", TempNode);
864
865    /* Dump _ADR, _HID, _UID, _CID */
866
867    if (Info->Valid & ACPI_VALID_ADR)
868    {
869        AcpiOsPrintf ("_ADR: %8.8X%8.8X\n", ACPI_FORMAT_UINT64 (Info->Address));
870    }
871    else
872    {
873        AcpiOsPrintf ("_ADR: <Not Present>\n");
874    }
875
876    if (Info->Valid & ACPI_VALID_HID)
877    {
878        AcpiOsPrintf ("_HID: %s\n", Info->HardwareId.String);
879    }
880    else
881    {
882        AcpiOsPrintf ("_HID: <Not Present>\n");
883    }
884
885    if (Info->Valid & ACPI_VALID_UID)
886    {
887        AcpiOsPrintf ("_UID: %s\n", Info->UniqueId.String);
888    }
889    else
890    {
891        AcpiOsPrintf ("_UID: <Not Present>\n");
892    }
893
894    if (Info->Valid & ACPI_VALID_CID)
895    {
896        for (i = 0; i < Info->CompatibleIdList.Count; i++)
897        {
898            AcpiOsPrintf ("_CID: %s\n",
899                Info->CompatibleIdList.Ids[i].String);
900        }
901    }
902    else
903    {
904        AcpiOsPrintf ("_CID: <Not Present>\n");
905    }
906
907    ACPI_FREE (Info);
908    return (AE_OK);
909}
910
911
912/*******************************************************************************
913 *
914 * FUNCTION:    AcpiDbGetBusInfo
915 *
916 * PARAMETERS:  None
917 *
918 * RETURN:      None
919 *
920 * DESCRIPTION: Display info about system busses.
921 *
922 ******************************************************************************/
923
924void
925AcpiDbGetBusInfo (
926    void)
927{
928    /* Search all nodes in namespace */
929
930    (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
931                    AcpiDbBusWalk, NULL, NULL, NULL);
932}
933
934#endif /* ACPI_DEBUGGER */
935