Home | History | Annotate | Line # | Download | only in acpiexec
aeinitfile.c revision 1.1
      1 /******************************************************************************
      2  *
      3  * Module Name: aeinitfile - Support for optional initialization file
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2015, Intel Corp.
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions, and the following disclaimer,
     16  *    without modification.
     17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  *    including a substantially similar Disclaimer requirement for further
     21  *    binary redistribution.
     22  * 3. Neither the names of the above-listed copyright holders nor the names
     23  *    of any contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * Alternatively, this software may be distributed under the terms of the
     27  * GNU General Public License ("GPL") version 2 as published by the Free
     28  * Software Foundation.
     29  *
     30  * NO WARRANTY
     31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  * POSSIBILITY OF SUCH DAMAGES.
     42  */
     43 
     44 #include "aecommon.h"
     45 #include "acdispat.h"
     46 
     47 #define _COMPONENT          ACPI_TOOLS
     48         ACPI_MODULE_NAME    ("aeinitfile")
     49 
     50 
     51 /* Local prototypes */
     52 
     53 static void
     54 AeDoOneOverride (
     55     char                    *Pathname,
     56     char                    *ValueString,
     57     ACPI_OPERAND_OBJECT     *ObjDesc,
     58     ACPI_WALK_STATE         *WalkState);
     59 
     60 
     61 #define AE_FILE_BUFFER_SIZE  512
     62 
     63 static char                 NameBuffer[AE_FILE_BUFFER_SIZE];
     64 static char                 ValueBuffer[AE_FILE_BUFFER_SIZE];
     65 static FILE                 *InitFile;
     66 
     67 
     68 /******************************************************************************
     69  *
     70  * FUNCTION:    AeOpenInitializationFile
     71  *
     72  * PARAMETERS:  Filename            - Path to the init file
     73  *
     74  * RETURN:      Status
     75  *
     76  * DESCRIPTION: Open the initialization file for the -fi option
     77  *
     78  *****************************************************************************/
     79 
     80 int
     81 AeOpenInitializationFile (
     82     char                    *Filename)
     83 {
     84 
     85     InitFile = fopen (Filename, "r");
     86     if (!InitFile)
     87     {
     88         perror ("Could not open initialization file");
     89         return (-1);
     90     }
     91 
     92     AcpiOsPrintf ("Opened initialization file [%s]\n", Filename);
     93     return (0);
     94 }
     95 
     96 
     97 /******************************************************************************
     98  *
     99  * FUNCTION:    AeDoObjectOverrides
    100  *
    101  * PARAMETERS:  None
    102  *
    103  * RETURN:      None
    104  *
    105  * DESCRIPTION: Read the initialization file and perform all overrides
    106  *
    107  * NOTE:        The format of the file is multiple lines, each of format:
    108  *                  <ACPI-pathname> <Integer Value>
    109  *
    110  *****************************************************************************/
    111 
    112 void
    113 AeDoObjectOverrides (
    114     void)
    115 {
    116     ACPI_OPERAND_OBJECT     *ObjDesc;
    117     ACPI_WALK_STATE         *WalkState;
    118     int                     i;
    119 
    120 
    121     if (!InitFile)
    122     {
    123         return;
    124     }
    125 
    126     /* Create needed objects to be reused for each init entry */
    127 
    128     ObjDesc = AcpiUtCreateIntegerObject (0);
    129     WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
    130 
    131     NameBuffer[0] = '\\';
    132 
    133      /* Read the entire file line-by-line */
    134 
    135     while (fscanf (InitFile, "%s %s\n",
    136         ACPI_CAST_PTR (char, &NameBuffer[1]),
    137         ACPI_CAST_PTR (char, &ValueBuffer)) == 2)
    138     {
    139         /* Add a root prefix if not present in the string */
    140 
    141         i = 0;
    142         if (NameBuffer[1] == '\\')
    143         {
    144             i = 1;
    145         }
    146 
    147         AeDoOneOverride (&NameBuffer[i], ValueBuffer, ObjDesc, WalkState);
    148     }
    149 
    150     /* Cleanup */
    151 
    152     fclose (InitFile);
    153     AcpiDsDeleteWalkState (WalkState);
    154     AcpiUtRemoveReference (ObjDesc);
    155 }
    156 
    157 
    158 /******************************************************************************
    159  *
    160  * FUNCTION:    AeDoOneOverride
    161  *
    162  * PARAMETERS:  Pathname            - AML namepath
    163  *              ValueString         - New integer value to be stored
    164  *              ObjDesc             - Descriptor with integer override value
    165  *              WalkState           - Used for the Store operation
    166  *
    167  * RETURN:      None
    168  *
    169  * DESCRIPTION: Perform an overrided for a single namespace object
    170  *
    171  *****************************************************************************/
    172 
    173 static void
    174 AeDoOneOverride (
    175     char                    *Pathname,
    176     char                    *ValueString,
    177     ACPI_OPERAND_OBJECT     *ObjDesc,
    178     ACPI_WALK_STATE         *WalkState)
    179 {
    180     ACPI_HANDLE             Handle;
    181     ACPI_STATUS             Status;
    182     UINT64                  Value;
    183 
    184 
    185     AcpiOsPrintf ("Value Override: %s, ", Pathname);
    186 
    187     /*
    188      * Get the namespace node associated with the override
    189      * pathname from the init file.
    190      */
    191     Status = AcpiGetHandle (NULL, Pathname, &Handle);
    192     if (ACPI_FAILURE (Status))
    193     {
    194         AcpiOsPrintf ("%s\n", AcpiFormatException (Status));
    195         return;
    196     }
    197 
    198     /* Extract the 64-bit integer */
    199 
    200     Status = AcpiUtStrtoul64 (ValueString, 0, &Value);
    201     if (ACPI_FAILURE (Status))
    202     {
    203         AcpiOsPrintf ("%s\n", AcpiFormatException (Status));
    204         return;
    205     }
    206 
    207     ObjDesc->Integer.Value = Value;
    208 
    209     /*
    210      * At the point this function is called, the namespace is fully
    211      * built and initialized. We can simply store the new object to
    212      * the target node.
    213      */
    214     AcpiExEnterInterpreter ();
    215     Status = AcpiExStore (ObjDesc, Handle, WalkState);
    216     AcpiExExitInterpreter ();
    217 
    218     if (ACPI_FAILURE (Status))
    219     {
    220         AcpiOsPrintf ("%s\n", AcpiFormatException (Status));
    221         return;
    222     }
    223 
    224     AcpiOsPrintf ("New value: 0x%8.8X%8.8X\n",
    225         ACPI_FORMAT_UINT64 (Value));
    226 }
    227