FreeBSD/sys/contrib/dev/acpica/common/dmrestag.c
/*******************************************************************************
 *
 * FUNCTION:    AcpiGetTagPathname
 *
 * PARAMETERS:  BufferNode          - Node for the parent buffer
 *              ResourceNode        - Node for a resource descriptor
 *              BitIndex            - Index into the resource descriptor
 *
 * RETURN:      Full pathname for a resource tag. NULL if no match.
 *              Path is returned in AML (packed) format.
 *
 * DESCRIPTION: Convert a BitIndex into a symbolic resource tag (full pathname)
 *
 ******************************************************************************/
AcpiGetTagPathname
PARAMETERS:  BufferNode          - Node for the parent buffer
ResourceNode        - Node for a resource descriptor
BitIndex            - Index into the resource descriptor

Full pathname for a resource tag. NULL if no match.
Path is returned in AML (packed) format.

Convert a BitIndex into a symbolic resource tag (full pathname)
AcpiGetTagPathname PARAMETERS : BufferNode - Node for the parent buffer ResourceNode - Node for a resource descriptor BitIndex - Index into the resource descriptor Full pathname for a resource tag . NULL if no match . Path is returned in AML ( packed ) format . Convert a BitIndex into a symbolic resource tag ( full pathname )
static char *
AcpiGetTagPathname (
    ACPI_PARSE_OBJECT       *IndexOp,
    ACPI_NAMESPACE_NODE     *BufferNode,
    ACPI_NAMESPACE_NODE     *ResourceNode,
    UINT32                  BitIndex)
{
    ACPI_STATUS             Status;
    UINT32                  ResourceBitIndex;
    UINT8                   ResourceTableIndex;
    ACPI_SIZE               RequiredSize;
    char                    *Pathname;
    AML_RESOURCE            *Aml;
    ACPI_PARSE_OBJECT       *Op;
    char                    *InternalPath;
    char                    *Tag;
    Op = BufferNode->Op->Common.Value.Arg;
    Op = Op->Common.Next;
    if (!Op)
    {
        return (NULL);
    }
    Aml = ACPI_CAST_PTR (
        AML_RESOURCE, &Op->Named.Data[ResourceNode->Value]);
    Status = AcpiUtValidateResource (NULL, Aml, &ResourceTableIndex);
    if (ACPI_FAILURE (Status))
    {
        return (NULL);
    }
    ResourceBitIndex = BitIndex - ACPI_MUL_8 (ResourceNode->Value);
    Tag = AcpiDmGetResourceTag (ResourceBitIndex, Aml, ResourceTableIndex);
    if (!Tag)
    {
        return (NULL);
    }
    AcpiDmUpdateResourceName (ResourceNode);
    RequiredSize = AcpiNsBuildNormalizedPath (BufferNode, NULL, 0, FALSE);
    if (!RequiredSize)
    {
        return (NULL);
    }
    Pathname = ACPI_ALLOCATE_ZEROED (RequiredSize + ACPI_PATH_SEGMENT_LENGTH);
    if (!Pathname)
    {
        return (NULL);
    }
    (void) AcpiNsBuildNormalizedPath (BufferNode, Pathname,
        RequiredSize, FALSE);
    Pathname[strlen (Pathname) - ACPI_NAME_SIZE] = 0;
    strncat (Pathname, ResourceNode->Name.Ascii, ACPI_NAME_SIZE);
    strcat (Pathname, ".");
    strncat (Pathname, Tag, ACPI_NAME_SIZE);
    AcpiNsInternalizeName (Pathname, &InternalPath);
    ACPI_FREE (Pathname);
    AcpiPsInitOp (IndexOp, AML_INT_NAMEPATH_OP);
    IndexOp->Common.Value.String = InternalPath;
    IndexOp->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Tag);
    return (InternalPath);
}
static char * AcpiGetTagPathname ( ACPI_PARSE_OBJECT * IndexOp , ACPI_NAMESPACE_NODE * BufferNode , ACPI_NAMESPACE_NODE * ResourceNode , UINT32 BitIndex ) { ACPI_STATUS Status ; UINT32 ResourceBitIndex ; UINT8 ResourceTableIndex ; ACPI_SIZE RequiredSize ; char * Pathname ; AML_RESOURCE * Aml ; ACPI_PARSE_OBJECT * Op ; char * InternalPath ; char * Tag ; Op = BufferNode -> Op -> Common . Value . Arg ; Op = Op -> Common . Next ; if ( ! Op ) { return ( NULL ) ; } Aml = ACPI_CAST_PTR ( AML_RESOURCE , & Op -> Named . Data [ ResourceNode -> Value ] ) ; Status = AcpiUtValidateResource ( NULL , Aml , & ResourceTableIndex ) ; if ( ACPI_FAILURE ( Status ) ) { return ( NULL ) ; } ResourceBitIndex = BitIndex - ACPI_MUL_8 ( ResourceNode -> Value ) ; Tag = AcpiDmGetResourceTag ( ResourceBitIndex , Aml , ResourceTableIndex ) ; if ( ! Tag ) { return ( NULL ) ; } AcpiDmUpdateResourceName ( ResourceNode ) ; RequiredSize = AcpiNsBuildNormalizedPath ( BufferNode , NULL , 0 , FALSE ) ; if ( ! RequiredSize ) { return ( NULL ) ; } Pathname = ACPI_ALLOCATE_ZEROED ( RequiredSize + ACPI_PATH_SEGMENT_LENGTH ) ; if ( ! Pathname ) { return ( NULL ) ; } ( void ) AcpiNsBuildNormalizedPath ( BufferNode , Pathname , RequiredSize , FALSE ) ; Pathname [ strlen ( Pathname ) - ACPI_NAME_SIZE ] = 0 ; strncat ( Pathname , ResourceNode -> Name . Ascii , ACPI_NAME_SIZE ) ; strcat ( Pathname , " " ) ; strncat ( Pathname , Tag , ACPI_NAME_SIZE ) ; AcpiNsInternalizeName ( Pathname , & InternalPath ) ; ACPI_FREE ( Pathname ) ; AcpiPsInitOp ( IndexOp , AML_INT_NAMEPATH_OP ) ; IndexOp -> Common . Value . String = InternalPath ; IndexOp -> Common . Node = ACPI_CAST_PTR ( ACPI_NAMESPACE_NODE , Tag ) ; return ( InternalPath ) ; }
FUNCTION:    AcpiGetTagPathname
 PARAMETERS:  BufferNode          - Node for the parent buffer
              ResourceNode        - Node for a resource descriptor
              BitIndex            - Index into the resource descriptor
FUNCTION : AcpiGetTagPathname PARAMETERS : BufferNode - Node for the parent buffer ResourceNode - Node for a resource descriptor BitIndex - Index into the resource descriptor
/* Get the Op that contains the actual buffer data */ /* Get the individual resource descriptor and validate it */ /* Get offset into this descriptor (from offset into entire buffer) */ /* Get the tag associated with this resource descriptor and offset */ /*
     * Now that we know that we have a reference that can be converted to a
     * symbol, change the name of the resource to a unique name.
     */ /* Get the full pathname to the parent buffer */ /*
     * Create the full path to the resource and tag by: remove the buffer name,
     * append the resource descriptor name, append a dot, append the tag name.
     *
     * TBD: Always using the full path is a bit brute force, the path can be
     * often be optimized with carats (if the original buffer namepath is a
     * single nameseg). This doesn't really matter, because these paths do not
     * end up in the final compiled AML, it's just an appearance issue for the
     * disassembled code.
     */ /* Internalize the namepath to AML format */ /* Update the Op with the symbol */ /* We will need the tag later. Cheat by putting it in the Node field */