ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

rscreate.c
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *
00003  * Module Name: rscreate - Create resource lists/tables
00004  *
00005  ******************************************************************************/
00006 
00007 /******************************************************************************
00008  *
00009  * 1. Copyright Notice
00010  *
00011  * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
00012  * All rights reserved.
00013  *
00014  * 2. License
00015  *
00016  * 2.1. This is your license from Intel Corp. under its intellectual property
00017  * rights.  You may have additional license terms from the party that provided
00018  * you this software, covering your right to use that party's intellectual
00019  * property rights.
00020  *
00021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
00022  * copy of the source code appearing in this file ("Covered Code") an
00023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
00024  * base code distributed originally by Intel ("Original Intel Code") to copy,
00025  * make derivatives, distribute, use and display any portion of the Covered
00026  * Code in any form, with the right to sublicense such rights; and
00027  *
00028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
00029  * license (with the right to sublicense), under only those claims of Intel
00030  * patents that are infringed by the Original Intel Code, to make, use, sell,
00031  * offer to sell, and import the Covered Code and derivative works thereof
00032  * solely to the minimum extent necessary to exercise the above copyright
00033  * license, and in no event shall the patent license extend to any additions
00034  * to or modifications of the Original Intel Code.  No other license or right
00035  * is granted directly or by implication, estoppel or otherwise;
00036  *
00037  * The above copyright and patent license is granted only if the following
00038  * conditions are met:
00039  *
00040  * 3. Conditions
00041  *
00042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
00043  * Redistribution of source code of any substantial portion of the Covered
00044  * Code or modification with rights to further distribute source must include
00045  * the above Copyright Notice, the above License, this list of Conditions,
00046  * and the following Disclaimer and Export Compliance provision.  In addition,
00047  * Licensee must cause all Covered Code to which Licensee contributes to
00048  * contain a file documenting the changes Licensee made to create that Covered
00049  * Code and the date of any change.  Licensee must include in that file the
00050  * documentation of any changes made by any predecessor Licensee.  Licensee
00051  * must include a prominent statement that the modification is derived,
00052  * directly or indirectly, from Original Intel Code.
00053  *
00054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
00055  * Redistribution of source code of any substantial portion of the Covered
00056  * Code or modification without rights to further distribute source must
00057  * include the following Disclaimer and Export Compliance provision in the
00058  * documentation and/or other materials provided with distribution.  In
00059  * addition, Licensee may not authorize further sublicense of source of any
00060  * portion of the Covered Code, and must include terms to the effect that the
00061  * license from Licensee to its licensee is limited to the intellectual
00062  * property embodied in the software Licensee provides to its licensee, and
00063  * not to intellectual property embodied in modifications its licensee may
00064  * make.
00065  *
00066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
00067  * substantial portion of the Covered Code or modification must reproduce the
00068  * above Copyright Notice, and the following Disclaimer and Export Compliance
00069  * provision in the documentation and/or other materials provided with the
00070  * distribution.
00071  *
00072  * 3.4. Intel retains all right, title, and interest in and to the Original
00073  * Intel Code.
00074  *
00075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
00076  * Intel shall be used in advertising or otherwise to promote the sale, use or
00077  * other dealings in products derived from or relating to the Covered Code
00078  * without prior written authorization from Intel.
00079  *
00080  * 4. Disclaimer and Export Compliance
00081  *
00082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
00083  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
00084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
00085  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
00086  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
00087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
00088  * PARTICULAR PURPOSE.
00089  *
00090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
00091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
00092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
00093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
00094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
00095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
00096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
00097  * LIMITED REMEDY.
00098  *
00099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
00100  * software or system incorporating such software without first obtaining any
00101  * required license or other approval from the U. S. Department of Commerce or
00102  * any other agency or department of the United States Government.  In the
00103  * event Licensee exports any such software from the United States or
00104  * re-exports any such software from a foreign destination, Licensee shall
00105  * ensure that the distribution and export/re-export of the software is in
00106  * compliance with all laws, regulations, orders, or other restrictions of the
00107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
00108  * any of its subsidiaries will export/re-export any technical data, process,
00109  * software, or service, directly or indirectly, to any country for which the
00110  * United States government or any agency thereof requires an export license,
00111  * other governmental approval, or letter of assurance, without first obtaining
00112  * such license, approval or letter.
00113  *
00114  *****************************************************************************/
00115 
00116 #define __RSCREATE_C__
00117 
00118 #include "acpi.h"
00119 #include "accommon.h"
00120 #include "acresrc.h"
00121 #include "acnamesp.h"
00122 
00123 #define _COMPONENT          ACPI_RESOURCES
00124         ACPI_MODULE_NAME    ("rscreate")
00125 
00126 
00127 /*******************************************************************************
00128  *
00129  * FUNCTION:    AcpiRsCreateResourceList
00130  *
00131  * PARAMETERS:  AmlBuffer           - Pointer to the resource byte stream
00132  *              OutputBuffer        - Pointer to the user's buffer
00133  *
00134  * RETURN:      Status: AE_OK if okay, else a valid ACPI_STATUS code
00135  *              If OutputBuffer is not large enough, OutputBufferLength
00136  *              indicates how large OutputBuffer should be, else it
00137  *              indicates how may UINT8 elements of OutputBuffer are valid.
00138  *
00139  * DESCRIPTION: Takes the byte stream returned from a _CRS, _PRS control method
00140  *              execution and parses the stream to create a linked list
00141  *              of device resources.
00142  *
00143  ******************************************************************************/
00144 
00145 ACPI_STATUS
00146 AcpiRsCreateResourceList (
00147     ACPI_OPERAND_OBJECT     *AmlBuffer,
00148     ACPI_BUFFER             *OutputBuffer)
00149 {
00150 
00151     ACPI_STATUS             Status;
00152     UINT8                   *AmlStart;
00153     ACPI_SIZE               ListSizeNeeded = 0;
00154     UINT32                  AmlBufferLength;
00155     void                    *Resource;
00156 
00157 
00158     ACPI_FUNCTION_TRACE (RsCreateResourceList);
00159 
00160 
00161     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "AmlBuffer = %p\n",
00162         AmlBuffer));
00163 
00164     /* Params already validated, so we don't re-validate here */
00165 
00166     AmlBufferLength = AmlBuffer->Buffer.Length;
00167     AmlStart = AmlBuffer->Buffer.Pointer;
00168 
00169     /*
00170      * Pass the AmlBuffer into a module that can calculate
00171      * the buffer size needed for the linked list
00172      */
00173     Status = AcpiRsGetListLength (AmlStart, AmlBufferLength,
00174                 &ListSizeNeeded);
00175 
00176     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Status=%X ListSizeNeeded=%X\n",
00177         Status, (UINT32) ListSizeNeeded));
00178     if (ACPI_FAILURE (Status))
00179     {
00180         return_ACPI_STATUS (Status);
00181     }
00182 
00183     /* Validate/Allocate/Clear caller buffer */
00184 
00185     Status = AcpiUtInitializeBuffer (OutputBuffer, ListSizeNeeded);
00186     if (ACPI_FAILURE (Status))
00187     {
00188         return_ACPI_STATUS (Status);
00189     }
00190 
00191     /* Do the conversion */
00192 
00193     Resource = OutputBuffer->Pointer;
00194     Status = AcpiUtWalkAmlResources (AmlStart, AmlBufferLength,
00195                 AcpiRsConvertAmlToResources, &Resource);
00196     if (ACPI_FAILURE (Status))
00197     {
00198         return_ACPI_STATUS (Status);
00199     }
00200 
00201     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
00202             OutputBuffer->Pointer, (UINT32) OutputBuffer->Length));
00203     return_ACPI_STATUS (AE_OK);
00204 }
00205 
00206 
00207 /*******************************************************************************
00208  *
00209  * FUNCTION:    AcpiRsCreatePciRoutingTable
00210  *
00211  * PARAMETERS:  PackageObject           - Pointer to an ACPI_OPERAND_OBJECT
00212  *                                        package
00213  *              OutputBuffer            - Pointer to the user's buffer
00214  *
00215  * RETURN:      Status  AE_OK if okay, else a valid ACPI_STATUS code.
00216  *              If the OutputBuffer is too small, the error will be
00217  *              AE_BUFFER_OVERFLOW and OutputBuffer->Length will point
00218  *              to the size buffer needed.
00219  *
00220  * DESCRIPTION: Takes the ACPI_OPERAND_OBJECT  package and creates a
00221  *              linked list of PCI interrupt descriptions
00222  *
00223  * NOTE: It is the caller's responsibility to ensure that the start of the
00224  * output buffer is aligned properly (if necessary).
00225  *
00226  ******************************************************************************/
00227 
00228 ACPI_STATUS
00229 AcpiRsCreatePciRoutingTable (
00230     ACPI_OPERAND_OBJECT     *PackageObject,
00231     ACPI_BUFFER             *OutputBuffer)
00232 {
00233     UINT8                   *Buffer;
00234     ACPI_OPERAND_OBJECT     **TopObjectList;
00235     ACPI_OPERAND_OBJECT     **SubObjectList;
00236     ACPI_OPERAND_OBJECT     *ObjDesc;
00237     ACPI_SIZE               BufferSizeNeeded = 0;
00238     UINT32                  NumberOfElements;
00239     UINT32                  Index;
00240     ACPI_PCI_ROUTING_TABLE  *UserPrt;
00241     ACPI_NAMESPACE_NODE     *Node;
00242     ACPI_STATUS             Status;
00243     ACPI_BUFFER             PathBuffer;
00244 
00245 
00246     ACPI_FUNCTION_TRACE (RsCreatePciRoutingTable);
00247 
00248 
00249     /* Params already validated, so we don't re-validate here */
00250 
00251     /* Get the required buffer length */
00252 
00253     Status = AcpiRsGetPciRoutingTableLength (PackageObject,
00254                 &BufferSizeNeeded);
00255     if (ACPI_FAILURE (Status))
00256     {
00257         return_ACPI_STATUS (Status);
00258     }
00259 
00260     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "BufferSizeNeeded = %X\n",
00261         (UINT32) BufferSizeNeeded));
00262 
00263     /* Validate/Allocate/Clear caller buffer */
00264 
00265     Status = AcpiUtInitializeBuffer (OutputBuffer, BufferSizeNeeded);
00266     if (ACPI_FAILURE (Status))
00267     {
00268         return_ACPI_STATUS (Status);
00269     }
00270 
00271     /*
00272      * Loop through the ACPI_INTERNAL_OBJECTS - Each object should be a
00273      * package that in turn contains an UINT64 Address, a UINT8 Pin,
00274      * a Name, and a UINT8 SourceIndex.
00275      */
00276     TopObjectList    = PackageObject->Package.Elements;
00277     NumberOfElements = PackageObject->Package.Count;
00278     Buffer           = OutputBuffer->Pointer;
00279     UserPrt          = ACPI_CAST_PTR (ACPI_PCI_ROUTING_TABLE, Buffer);
00280 
00281     for (Index = 0; Index < NumberOfElements; Index++)
00282     {
00283         /*
00284          * Point UserPrt past this current structure
00285          *
00286          * NOTE: On the first iteration, UserPrt->Length will
00287          * be zero because we cleared the return buffer earlier
00288          */
00289         Buffer += UserPrt->Length;
00290         UserPrt = ACPI_CAST_PTR (ACPI_PCI_ROUTING_TABLE, Buffer);
00291 
00292         /*
00293          * Fill in the Length field with the information we have at this point.
00294          * The minus four is to subtract the size of the UINT8 Source[4] member
00295          * because it is added below.
00296          */
00297         UserPrt->Length = (sizeof (ACPI_PCI_ROUTING_TABLE) - 4);
00298 
00299         /* Each element of the top-level package must also be a package */
00300 
00301         if ((*TopObjectList)->Common.Type != ACPI_TYPE_PACKAGE)
00302         {
00303             ACPI_ERROR ((AE_INFO,
00304                 "(PRT[%u]) Need sub-package, found %s",
00305                 Index, AcpiUtGetObjectTypeName (*TopObjectList)));
00306             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
00307         }
00308 
00309         /* Each sub-package must be of length 4 */
00310 
00311         if ((*TopObjectList)->Package.Count != 4)
00312         {
00313             ACPI_ERROR ((AE_INFO,
00314                 "(PRT[%u]) Need package of length 4, found length %u",
00315                 Index, (*TopObjectList)->Package.Count));
00316             return_ACPI_STATUS (AE_AML_PACKAGE_LIMIT);
00317         }
00318 
00319         /*
00320          * Dereference the sub-package.
00321          * The SubObjectList will now point to an array of the four IRQ
00322          * elements: [Address, Pin, Source, SourceIndex]
00323          */
00324         SubObjectList = (*TopObjectList)->Package.Elements;
00325 
00326         /* 1) First subobject: Dereference the PRT.Address */
00327 
00328         ObjDesc = SubObjectList[0];
00329         if (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
00330         {
00331             ACPI_ERROR ((AE_INFO, "(PRT[%u].Address) Need Integer, found %s",
00332                 Index, AcpiUtGetObjectTypeName (ObjDesc)));
00333             return_ACPI_STATUS (AE_BAD_DATA);
00334         }
00335 
00336         UserPrt->Address = ObjDesc->Integer.Value;
00337 
00338         /* 2) Second subobject: Dereference the PRT.Pin */
00339 
00340         ObjDesc = SubObjectList[1];
00341         if (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
00342         {
00343             ACPI_ERROR ((AE_INFO, "(PRT[%u].Pin) Need Integer, found %s",
00344                 Index, AcpiUtGetObjectTypeName (ObjDesc)));
00345             return_ACPI_STATUS (AE_BAD_DATA);
00346         }
00347 
00348         UserPrt->Pin = (UINT32) ObjDesc->Integer.Value;
00349 
00350         /*
00351          * If the BIOS has erroneously reversed the _PRT SourceName (index 2)
00352          * and the SourceIndex (index 3), fix it. _PRT is important enough to
00353          * workaround this BIOS error. This also provides compatibility with
00354          * other ACPI implementations.
00355          */
00356         ObjDesc = SubObjectList[3];
00357         if (!ObjDesc || (ObjDesc->Common.Type != ACPI_TYPE_INTEGER))
00358         {
00359             SubObjectList[3] = SubObjectList[2];
00360             SubObjectList[2] = ObjDesc;
00361 
00362             ACPI_WARNING ((AE_INFO,
00363                 "(PRT[%X].Source) SourceName and SourceIndex are reversed, fixed",
00364                 Index));
00365         }
00366 
00367         /*
00368          * 3) Third subobject: Dereference the PRT.SourceName
00369          * The name may be unresolved (slack mode), so allow a null object
00370          */
00371         ObjDesc = SubObjectList[2];
00372         if (ObjDesc)
00373         {
00374             switch (ObjDesc->Common.Type)
00375             {
00376             case ACPI_TYPE_LOCAL_REFERENCE:
00377 
00378                 if (ObjDesc->Reference.Class != ACPI_REFCLASS_NAME)
00379                 {
00380                     ACPI_ERROR ((AE_INFO,
00381                         "(PRT[%u].Source) Need name, found Reference Class 0x%X",
00382                         Index, ObjDesc->Reference.Class));
00383                     return_ACPI_STATUS (AE_BAD_DATA);
00384                 }
00385 
00386                 Node = ObjDesc->Reference.Node;
00387 
00388                 /* Use *remaining* length of the buffer as max for pathname */
00389 
00390                 PathBuffer.Length = OutputBuffer->Length -
00391                                     (UINT32) ((UINT8 *) UserPrt->Source -
00392                                     (UINT8 *) OutputBuffer->Pointer);
00393                 PathBuffer.Pointer = UserPrt->Source;
00394 
00395                 Status = AcpiNsHandleToPathname ((ACPI_HANDLE) Node, &PathBuffer);
00396 
00397                 /* +1 to include null terminator */
00398 
00399                 UserPrt->Length += (UINT32) ACPI_STRLEN (UserPrt->Source) + 1;
00400                 break;
00401 
00402 
00403             case ACPI_TYPE_STRING:
00404 
00405                 ACPI_STRCPY (UserPrt->Source, ObjDesc->String.Pointer);
00406 
00407                 /*
00408                  * Add to the Length field the length of the string
00409                  * (add 1 for terminator)
00410                  */
00411                 UserPrt->Length += ObjDesc->String.Length + 1;
00412                 break;
00413 
00414 
00415             case ACPI_TYPE_INTEGER:
00416                 /*
00417                  * If this is a number, then the Source Name is NULL, since the
00418                  * entire buffer was zeroed out, we can leave this alone.
00419                  *
00420                  * Add to the Length field the length of the UINT32 NULL
00421                  */
00422                 UserPrt->Length += sizeof (UINT32);
00423                 break;
00424 
00425 
00426             default:
00427 
00428                ACPI_ERROR ((AE_INFO,
00429                    "(PRT[%u].Source) Need Ref/String/Integer, found %s",
00430                    Index, AcpiUtGetObjectTypeName (ObjDesc)));
00431                return_ACPI_STATUS (AE_BAD_DATA);
00432             }
00433         }
00434 
00435         /* Now align the current length */
00436 
00437         UserPrt->Length = (UINT32) ACPI_ROUND_UP_TO_64BIT (UserPrt->Length);
00438 
00439         /* 4) Fourth subobject: Dereference the PRT.SourceIndex */
00440 
00441         ObjDesc = SubObjectList[3];
00442         if (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
00443         {
00444             ACPI_ERROR ((AE_INFO,
00445                 "(PRT[%u].SourceIndex) Need Integer, found %s",
00446                 Index, AcpiUtGetObjectTypeName (ObjDesc)));
00447             return_ACPI_STATUS (AE_BAD_DATA);
00448         }
00449 
00450         UserPrt->SourceIndex = (UINT32) ObjDesc->Integer.Value;
00451 
00452         /* Point to the next ACPI_OPERAND_OBJECT in the top level package */
00453 
00454         TopObjectList++;
00455     }
00456 
00457     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
00458             OutputBuffer->Pointer, (UINT32) OutputBuffer->Length));
00459     return_ACPI_STATUS (AE_OK);
00460 }
00461 
00462 
00463 /*******************************************************************************
00464  *
00465  * FUNCTION:    AcpiRsCreateAmlResources
00466  *
00467  * PARAMETERS:  LinkedListBuffer        - Pointer to the resource linked list
00468  *              OutputBuffer            - Pointer to the user's buffer
00469  *
00470  * RETURN:      Status  AE_OK if okay, else a valid ACPI_STATUS code.
00471  *              If the OutputBuffer is too small, the error will be
00472  *              AE_BUFFER_OVERFLOW and OutputBuffer->Length will point
00473  *              to the size buffer needed.
00474  *
00475  * DESCRIPTION: Takes the linked list of device resources and
00476  *              creates a bytestream to be used as input for the
00477  *              _SRS control method.
00478  *
00479  ******************************************************************************/
00480 
00481 ACPI_STATUS
00482 AcpiRsCreateAmlResources (
00483     ACPI_RESOURCE           *LinkedListBuffer,
00484     ACPI_BUFFER             *OutputBuffer)
00485 {
00486     ACPI_STATUS             Status;
00487     ACPI_SIZE               AmlSizeNeeded = 0;
00488 
00489 
00490     ACPI_FUNCTION_TRACE (RsCreateAmlResources);
00491 
00492 
00493     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "LinkedListBuffer = %p\n",
00494         LinkedListBuffer));
00495 
00496     /*
00497      * Params already validated, so we don't re-validate here
00498      *
00499      * Pass the LinkedListBuffer into a module that calculates
00500      * the buffer size needed for the byte stream.
00501      */
00502     Status = AcpiRsGetAmlLength (LinkedListBuffer,
00503                 &AmlSizeNeeded);
00504 
00505     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "AmlSizeNeeded=%X, %s\n",
00506         (UINT32) AmlSizeNeeded, AcpiFormatException (Status)));
00507     if (ACPI_FAILURE (Status))
00508     {
00509         return_ACPI_STATUS (Status);
00510     }
00511 
00512     /* Validate/Allocate/Clear caller buffer */
00513 
00514     Status = AcpiUtInitializeBuffer (OutputBuffer, AmlSizeNeeded);
00515     if (ACPI_FAILURE (Status))
00516     {
00517         return_ACPI_STATUS (Status);
00518     }
00519 
00520     /* Do the conversion */
00521 
00522     Status = AcpiRsConvertResourcesToAml (LinkedListBuffer, AmlSizeNeeded,
00523                     OutputBuffer->Pointer);
00524     if (ACPI_FAILURE (Status))
00525     {
00526         return_ACPI_STATUS (Status);
00527     }
00528 
00529     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
00530             OutputBuffer->Pointer, (UINT32) OutputBuffer->Length));
00531     return_ACPI_STATUS (AE_OK);
00532 }
00533 

Generated on Sat May 26 2012 04:25:55 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.