Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/drivers/acpica/rscreate.c need to be fixed.

0001 /*******************************************************************************
0002  *
0003  * Module Name: rscreate - Create resource lists/tables
0004  *
0005  ******************************************************************************/
0006 
0007 /******************************************************************************
0008  *
0009  * 1. Copyright Notice
0010  *
0011  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
0012  * All rights reserved.
0013  *
0014  * 2. License
0015  *
0016  * 2.1. This is your license from Intel Corp. under its intellectual property
0017  * rights.  You may have additional license terms from the party that provided
0018  * you this software, covering your right to use that party's intellectual
0019  * property rights.
0020  *
0021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0022  * copy of the source code appearing in this file ("Covered Code") an
0023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0024  * base code distributed originally by Intel ("Original Intel Code") to copy,
0025  * make derivatives, distribute, use and display any portion of the Covered
0026  * Code in any form, with the right to sublicense such rights; and
0027  *
0028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0029  * license (with the right to sublicense), under only those claims of Intel
0030  * patents that are infringed by the Original Intel Code, to make, use, sell,
0031  * offer to sell, and import the Covered Code and derivative works thereof
0032  * solely to the minimum extent necessary to exercise the above copyright
0033  * license, and in no event shall the patent license extend to any additions
0034  * to or modifications of the Original Intel Code.  No other license or right
0035  * is granted directly or by implication, estoppel or otherwise;
0036  *
0037  * The above copyright and patent license is granted only if the following
0038  * conditions are met:
0039  *
0040  * 3. Conditions
0041  *
0042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0043  * Redistribution of source code of any substantial portion of the Covered
0044  * Code or modification with rights to further distribute source must include
0045  * the above Copyright Notice, the above License, this list of Conditions,
0046  * and the following Disclaimer and Export Compliance provision.  In addition,
0047  * Licensee must cause all Covered Code to which Licensee contributes to
0048  * contain a file documenting the changes Licensee made to create that Covered
0049  * Code and the date of any change.  Licensee must include in that file the
0050  * documentation of any changes made by any predecessor Licensee.  Licensee
0051  * must include a prominent statement that the modification is derived,
0052  * directly or indirectly, from Original Intel Code.
0053  *
0054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0055  * Redistribution of source code of any substantial portion of the Covered
0056  * Code or modification without rights to further distribute source must
0057  * include the following Disclaimer and Export Compliance provision in the
0058  * documentation and/or other materials provided with distribution.  In
0059  * addition, Licensee may not authorize further sublicense of source of any
0060  * portion of the Covered Code, and must include terms to the effect that the
0061  * license from Licensee to its licensee is limited to the intellectual
0062  * property embodied in the software Licensee provides to its licensee, and
0063  * not to intellectual property embodied in modifications its licensee may
0064  * make.
0065  *
0066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0067  * substantial portion of the Covered Code or modification must reproduce the
0068  * above Copyright Notice, and the following Disclaimer and Export Compliance
0069  * provision in the documentation and/or other materials provided with the
0070  * distribution.
0071  *
0072  * 3.4. Intel retains all right, title, and interest in and to the Original
0073  * Intel Code.
0074  *
0075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0076  * Intel shall be used in advertising or otherwise to promote the sale, use or
0077  * other dealings in products derived from or relating to the Covered Code
0078  * without prior written authorization from Intel.
0079  *
0080  * 4. Disclaimer and Export Compliance
0081  *
0082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0083  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
0085  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
0086  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
0087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0088  * PARTICULAR PURPOSE.
0089  *
0090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
0096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0097  * LIMITED REMEDY.
0098  *
0099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0100  * software or system incorporating such software without first obtaining any
0101  * required license or other approval from the U. S. Department of Commerce or
0102  * any other agency or department of the United States Government.  In the
0103  * event Licensee exports any such software from the United States or
0104  * re-exports any such software from a foreign destination, Licensee shall
0105  * ensure that the distribution and export/re-export of the software is in
0106  * compliance with all laws, regulations, orders, or other restrictions of the
0107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0108  * any of its subsidiaries will export/re-export any technical data, process,
0109  * software, or service, directly or indirectly, to any country for which the
0110  * United States government or any agency thereof requires an export license,
0111  * other governmental approval, or letter of assurance, without first obtaining
0112  * such license, approval or letter.
0113  *
0114  *****************************************************************************/
0115 
0116 #define __RSCREATE_C__
0117 
0118 #include "acpi.h"
0119 #include "accommon.h"
0120 #include "acresrc.h"
0121 #include "acnamesp.h"
0122 
0123 #define _COMPONENT          ACPI_RESOURCES
0124         ACPI_MODULE_NAME    ("rscreate")
0125 
0126 
0127 /*******************************************************************************
0128  *
0129  * FUNCTION:    AcpiRsCreateResourceList
0130  *
0131  * PARAMETERS:  AmlBuffer           - Pointer to the resource byte stream
0132  *              OutputBuffer        - Pointer to the user's buffer
0133  *
0134  * RETURN:      Status: AE_OK if okay, else a valid ACPI_STATUS code
0135  *              If OutputBuffer is not large enough, OutputBufferLength
0136  *              indicates how large OutputBuffer should be, else it
0137  *              indicates how may UINT8 elements of OutputBuffer are valid.
0138  *
0139  * DESCRIPTION: Takes the byte stream returned from a _CRS, _PRS control method
0140  *              execution and parses the stream to create a linked list
0141  *              of device resources.
0142  *
0143  ******************************************************************************/
0144 
0145 ACPI_STATUS
0146 AcpiRsCreateResourceList (
0147     ACPI_OPERAND_OBJECT     *AmlBuffer,
0148     ACPI_BUFFER             *OutputBuffer)
0149 {
0150 
0151     ACPI_STATUS             Status;
0152     UINT8                   *AmlStart;
0153     ACPI_SIZE               ListSizeNeeded = 0;
0154     UINT32                  AmlBufferLength;
0155     void                    *Resource;
0156 
0157 
0158     ACPI_FUNCTION_TRACE (RsCreateResourceList);
0159 
0160 
0161     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "AmlBuffer = %p\n",
0162         AmlBuffer));
0163 
0164     /* Params already validated, so we don't re-validate here */
0165 
0166     AmlBufferLength = AmlBuffer->Buffer.Length;
0167     AmlStart = AmlBuffer->Buffer.Pointer;
0168 
0169     /*
0170      * Pass the AmlBuffer into a module that can calculate
0171      * the buffer size needed for the linked list
0172      */
0173     Status = AcpiRsGetListLength (AmlStart, AmlBufferLength,
0174                 &ListSizeNeeded);
0175 
0176     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Status=%X ListSizeNeeded=%X\n",
0177         Status, (UINT32) ListSizeNeeded));
0178     if (ACPI_FAILURE (Status))
0179     {
0180         return_ACPI_STATUS (Status);
0181     }
0182 
0183     /* Validate/Allocate/Clear caller buffer */
0184 
0185     Status = AcpiUtInitializeBuffer (OutputBuffer, ListSizeNeeded);
0186     if (ACPI_FAILURE (Status))
0187     {
0188         return_ACPI_STATUS (Status);
0189     }
0190 
0191     /* Do the conversion */
0192 
0193     Resource = OutputBuffer->Pointer;
0194     Status = AcpiUtWalkAmlResources (AmlStart, AmlBufferLength,
0195                 AcpiRsConvertAmlToResources, &Resource);
0196     if (ACPI_FAILURE (Status))
0197     {
0198         return_ACPI_STATUS (Status);
0199     }
0200 
0201     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
0202             OutputBuffer->Pointer, (UINT32) OutputBuffer->Length));
0203     return_ACPI_STATUS (AE_OK);
0204 }
0205 
0206 
0207 /*******************************************************************************
0208  *
0209  * FUNCTION:    AcpiRsCreatePciRoutingTable
0210  *
0211  * PARAMETERS:  PackageObject           - Pointer to an ACPI_OPERAND_OBJECT
0212  *                                        package
0213  *              OutputBuffer            - Pointer to the user's buffer
0214  *
0215  * RETURN:      Status  AE_OK if okay, else a valid ACPI_STATUS code.
0216  *              If the OutputBuffer is too small, the error will be
0217  *              AE_BUFFER_OVERFLOW and OutputBuffer->Length will point
0218  *              to the size buffer needed.
0219  *
0220  * DESCRIPTION: Takes the ACPI_OPERAND_OBJECT  package and creates a
0221  *              linked list of PCI interrupt descriptions
0222  *
0223  * NOTE: It is the caller's responsibility to ensure that the start of the
0224  * output buffer is aligned properly (if necessary).
0225  *
0226  ******************************************************************************/
0227 
0228 ACPI_STATUS
0229 AcpiRsCreatePciRoutingTable (
0230     ACPI_OPERAND_OBJECT     *PackageObject,
0231     ACPI_BUFFER             *OutputBuffer)
0232 {
0233     UINT8                   *Buffer;
0234     ACPI_OPERAND_OBJECT     **TopObjectList;
0235     ACPI_OPERAND_OBJECT     **SubObjectList;
0236     ACPI_OPERAND_OBJECT     *ObjDesc;
0237     ACPI_SIZE               BufferSizeNeeded = 0;
0238     UINT32                  NumberOfElements;
0239     UINT32                  Index;
0240     ACPI_PCI_ROUTING_TABLE  *UserPrt;
0241     ACPI_NAMESPACE_NODE     *Node;
0242     ACPI_STATUS             Status;
0243     ACPI_BUFFER             PathBuffer;
0244 
0245 
0246     ACPI_FUNCTION_TRACE (RsCreatePciRoutingTable);
0247 
0248 
0249     /* Params already validated, so we don't re-validate here */
0250 
0251     /* Get the required buffer length */
0252 
0253     Status = AcpiRsGetPciRoutingTableLength (PackageObject,
0254                 &BufferSizeNeeded);
0255     if (ACPI_FAILURE (Status))
0256     {
0257         return_ACPI_STATUS (Status);
0258     }
0259 
0260     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "BufferSizeNeeded = %X\n",
0261         (UINT32) BufferSizeNeeded));
0262 
0263     /* Validate/Allocate/Clear caller buffer */
0264 
0265     Status = AcpiUtInitializeBuffer (OutputBuffer, BufferSizeNeeded);
0266     if (ACPI_FAILURE (Status))
0267     {
0268         return_ACPI_STATUS (Status);
0269     }
0270 
0271     /*
0272      * Loop through the ACPI_INTERNAL_OBJECTS - Each object should be a
0273      * package that in turn contains an ACPI_INTEGER Address, a UINT8 Pin,
0274      * a Name, and a UINT8 SourceIndex.
0275      */
0276     TopObjectList    = PackageObject->Package.Elements;
0277     NumberOfElements = PackageObject->Package.Count;
0278     Buffer           = OutputBuffer->Pointer;
0279     UserPrt          = ACPI_CAST_PTR (ACPI_PCI_ROUTING_TABLE, Buffer);
0280 
0281     for (Index = 0; Index < NumberOfElements; Index++)
0282     {
0283         /*
0284          * Point UserPrt past this current structure
0285          *
0286          * NOTE: On the first iteration, UserPrt->Length will
0287          * be zero because we cleared the return buffer earlier
0288          */
0289         Buffer += UserPrt->Length;
0290         UserPrt = ACPI_CAST_PTR (ACPI_PCI_ROUTING_TABLE, Buffer);
0291 
0292         /*
0293          * Fill in the Length field with the information we have at this point.
0294          * The minus four is to subtract the size of the UINT8 Source[4] member
0295          * because it is added below.
0296          */
0297         UserPrt->Length = (sizeof (ACPI_PCI_ROUTING_TABLE) - 4);
0298 
0299         /* Each element of the top-level package must also be a package */
0300 
0301         if ((*TopObjectList)->Common.Type != ACPI_TYPE_PACKAGE)
0302         {
0303             ACPI_ERROR ((AE_INFO,
0304                 "(PRT[%X]) Need sub-package, found %s",
0305                 Index, AcpiUtGetObjectTypeName (*TopObjectList)));
0306             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
0307         }
0308 
0309         /* Each sub-package must be of length 4 */
0310 
0311         if ((*TopObjectList)->Package.Count != 4)
0312         {
0313             ACPI_ERROR ((AE_INFO,
0314                 "(PRT[%X]) Need package of length 4, found length %d",
0315                 Index, (*TopObjectList)->Package.Count));
0316             return_ACPI_STATUS (AE_AML_PACKAGE_LIMIT);
0317         }
0318 
0319         /*
0320          * Dereference the sub-package.
0321          * The SubObjectList will now point to an array of the four IRQ
0322          * elements: [Address, Pin, Source, SourceIndex]
0323          */
0324         SubObjectList = (*TopObjectList)->Package.Elements;
0325 
0326         /* 1) First subobject: Dereference the PRT.Address */
0327 
0328         ObjDesc = SubObjectList[0];
0329         if (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
0330         {
0331             ACPI_ERROR ((AE_INFO, "(PRT[%X].Address) Need Integer, found %s",
0332                 Index, AcpiUtGetObjectTypeName (ObjDesc)));
0333             return_ACPI_STATUS (AE_BAD_DATA);
0334         }
0335 
0336         UserPrt->Address = ObjDesc->Integer.Value;
0337 
0338         /* 2) Second subobject: Dereference the PRT.Pin */
0339 
0340         ObjDesc = SubObjectList[1];
0341         if (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
0342         {
0343             ACPI_ERROR ((AE_INFO, "(PRT[%X].Pin) Need Integer, found %s",
0344                 Index, AcpiUtGetObjectTypeName (ObjDesc)));
0345             return_ACPI_STATUS (AE_BAD_DATA);
0346         }
0347 
0348         UserPrt->Pin = (UINT32) ObjDesc->Integer.Value;
0349 
0350         /*
0351          * If the BIOS has erroneously reversed the _PRT SourceName (index 2)
0352          * and the SourceIndex (index 3), fix it. _PRT is important enough to
0353          * workaround this BIOS error. This also provides compatibility with
0354          * other ACPI implementations.
0355          */
0356         ObjDesc = SubObjectList[3];
0357         if (!ObjDesc || (ObjDesc->Common.Type != ACPI_TYPE_INTEGER))
0358         {
0359             SubObjectList[3] = SubObjectList[2];
0360             SubObjectList[2] = ObjDesc;
0361 
0362             ACPI_WARNING ((AE_INFO,
0363                 "(PRT[%X].Source) SourceName and SourceIndex are reversed, fixed",
0364                 Index));
0365         }
0366 
0367         /*
0368          * 3) Third subobject: Dereference the PRT.SourceName
0369          * The name may be unresolved (slack mode), so allow a null object
0370          */
0371         ObjDesc = SubObjectList[2];
0372         if (ObjDesc)
0373         {
0374             switch (ObjDesc->Common.Type)
0375             {
0376             case ACPI_TYPE_LOCAL_REFERENCE:
0377 
0378                 if (ObjDesc->Reference.Class != ACPI_REFCLASS_NAME)
0379                 {
0380                     ACPI_ERROR ((AE_INFO,
0381                         "(PRT[%X].Source) Need name, found Reference Class %X",
0382                         Index, ObjDesc->Reference.Class));
0383                     return_ACPI_STATUS (AE_BAD_DATA);
0384                 }
0385 
0386                 Node = ObjDesc->Reference.Node;
0387 
0388                 /* Use *remaining* length of the buffer as max for pathname */
0389 
0390                 PathBuffer.Length = OutputBuffer->Length -
0391                                     (UINT32) ((UINT8 *) UserPrt->Source -
0392                                     (UINT8 *) OutputBuffer->Pointer);
0393                 PathBuffer.Pointer = UserPrt->Source;
0394 
0395                 Status = AcpiNsHandleToPathname ((ACPI_HANDLE) Node, &PathBuffer);
0396 
0397                 /* +1 to include null terminator */
0398 
0399                 UserPrt->Length += (UINT32) ACPI_STRLEN (UserPrt->Source) + 1;
0400                 break;
0401 
0402 
0403             case ACPI_TYPE_STRING:
0404 
0405                 ACPI_STRCPY (UserPrt->Source, ObjDesc->String.Pointer);
0406 
0407                 /*
0408                  * Add to the Length field the length of the string
0409                  * (add 1 for terminator)
0410                  */
0411                 UserPrt->Length += ObjDesc->String.Length + 1;
0412                 break;
0413 
0414 
0415             case ACPI_TYPE_INTEGER:
0416                 /*
0417                  * If this is a number, then the Source Name is NULL, since the
0418                  * entire buffer was zeroed out, we can leave this alone.
0419                  *
0420                  * Add to the Length field the length of the UINT32 NULL
0421                  */
0422                 UserPrt->Length += sizeof (UINT32);
0423                 break;
0424 
0425 
0426             default:
0427 
0428                ACPI_ERROR ((AE_INFO,
0429                    "(PRT[%X].Source) Need Ref/String/Integer, found %s",
0430                    Index, AcpiUtGetObjectTypeName (ObjDesc)));
0431                return_ACPI_STATUS (AE_BAD_DATA);
0432             }
0433         }
0434 
0435         /* Now align the current length */
0436 
0437         UserPrt->Length = (UINT32) ACPI_ROUND_UP_TO_64BIT (UserPrt->Length);
0438 
0439         /* 4) Fourth subobject: Dereference the PRT.SourceIndex */
0440 
0441         ObjDesc = SubObjectList[3];
0442         if (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
0443         {
0444             ACPI_ERROR ((AE_INFO,
0445                 "(PRT[%X].SourceIndex) Need Integer, found %s",
0446                 Index, AcpiUtGetObjectTypeName (ObjDesc)));
0447             return_ACPI_STATUS (AE_BAD_DATA);
0448         }
0449 
0450         UserPrt->SourceIndex = (UINT32) ObjDesc->Integer.Value;
0451 
0452         /* Point to the next ACPI_OPERAND_OBJECT in the top level package */
0453 
0454         TopObjectList++;
0455     }
0456 
0457     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
0458             OutputBuffer->Pointer, (UINT32) OutputBuffer->Length));
0459     return_ACPI_STATUS (AE_OK);
0460 }
0461 
0462 
0463 /*******************************************************************************
0464  *
0465  * FUNCTION:    AcpiRsCreateAmlResources
0466  *
0467  * PARAMETERS:  LinkedListBuffer        - Pointer to the resource linked list
0468  *              OutputBuffer            - Pointer to the user's buffer
0469  *
0470  * RETURN:      Status  AE_OK if okay, else a valid ACPI_STATUS code.
0471  *              If the OutputBuffer is too small, the error will be
0472  *              AE_BUFFER_OVERFLOW and OutputBuffer->Length will point
0473  *              to the size buffer needed.
0474  *
0475  * DESCRIPTION: Takes the linked list of device resources and
0476  *              creates a bytestream to be used as input for the
0477  *              _SRS control method.
0478  *
0479  ******************************************************************************/
0480 
0481 ACPI_STATUS
0482 AcpiRsCreateAmlResources (
0483     ACPI_RESOURCE           *LinkedListBuffer,
0484     ACPI_BUFFER             *OutputBuffer)
0485 {
0486     ACPI_STATUS             Status;
0487     ACPI_SIZE               AmlSizeNeeded = 0;
0488 
0489 
0490     ACPI_FUNCTION_TRACE (RsCreateAmlResources);
0491 
0492 
0493     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "LinkedListBuffer = %p\n",
0494         LinkedListBuffer));
0495 
0496     /*
0497      * Params already validated, so we don't re-validate here
0498      *
0499      * Pass the LinkedListBuffer into a module that calculates
0500      * the buffer size needed for the byte stream.
0501      */
0502     Status = AcpiRsGetAmlLength (LinkedListBuffer,
0503                 &AmlSizeNeeded);
0504 
0505     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "AmlSizeNeeded=%X, %s\n",
0506         (UINT32) AmlSizeNeeded, AcpiFormatException (Status)));
0507     if (ACPI_FAILURE (Status))
0508     {
0509         return_ACPI_STATUS (Status);
0510     }
0511 
0512     /* Validate/Allocate/Clear caller buffer */
0513 
0514     Status = AcpiUtInitializeBuffer (OutputBuffer, AmlSizeNeeded);
0515     if (ACPI_FAILURE (Status))
0516     {
0517         return_ACPI_STATUS (Status);
0518     }
0519 
0520     /* Do the conversion */
0521 
0522     Status = AcpiRsConvertResourcesToAml (LinkedListBuffer, AmlSizeNeeded,
0523                     OutputBuffer->Pointer);
0524     if (ACPI_FAILURE (Status))
0525     {
0526         return_ACPI_STATUS (Status);
0527     }
0528 
0529     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
0530             OutputBuffer->Pointer, (UINT32) OutputBuffer->Length));
0531     return_ACPI_STATUS (AE_OK);
0532 }
0533