Sync ACPICA with Intel's version 20160831.
[dragonfly.git] / sys / contrib / dev / acpica / source / tools / acpiexec / aeinitfile.c
blob8151435e3448af3ecc8b5b84e9a05e5119da439f
1 /******************************************************************************
3 * Module Name: aeinitfile - Support for optional initialization file
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, Intel Corp.
9 * All rights reserved.
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.
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.
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.
44 #include "aecommon.h"
45 #include "acdispat.h"
47 #define _COMPONENT ACPI_TOOLS
48 ACPI_MODULE_NAME ("aeinitfile")
51 /* Local prototypes */
53 static void
54 AeDoOneOverride (
55 char *Pathname,
56 char *ValueString,
57 ACPI_OPERAND_OBJECT *ObjDesc,
58 ACPI_WALK_STATE *WalkState);
61 #define AE_FILE_BUFFER_SIZE 512
63 static char LineBuffer[AE_FILE_BUFFER_SIZE];
64 static char NameBuffer[AE_FILE_BUFFER_SIZE];
65 static char ValueBuffer[AE_FILE_BUFFER_SIZE];
66 static FILE *InitFile;
69 /******************************************************************************
71 * FUNCTION: AeOpenInitializationFile
73 * PARAMETERS: Filename - Path to the init file
75 * RETURN: Status
77 * DESCRIPTION: Open the initialization file for the -fi option
79 *****************************************************************************/
81 int
82 AeOpenInitializationFile (
83 char *Filename)
86 InitFile = fopen (Filename, "r");
87 if (!InitFile)
89 fprintf (stderr,
90 "Could not open initialization file: %s\n", Filename);
91 return (-1);
94 AcpiOsPrintf ("Opened initialization file [%s]\n", Filename);
95 return (0);
99 /******************************************************************************
101 * FUNCTION: AeDoObjectOverrides
103 * PARAMETERS: None
105 * RETURN: None
107 * DESCRIPTION: Read the initialization file and perform all overrides
109 * NOTE: The format of the file is multiple lines, each of format:
110 * <ACPI-pathname> <Integer Value>
112 *****************************************************************************/
114 void
115 AeDoObjectOverrides (
116 void)
118 ACPI_OPERAND_OBJECT *ObjDesc;
119 ACPI_WALK_STATE *WalkState;
120 int i;
123 if (!InitFile)
125 return;
128 /* Create needed objects to be reused for each init entry */
130 ObjDesc = AcpiUtCreateIntegerObject (0);
131 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
132 NameBuffer[0] = '\\';
134 /* Read the entire file line-by-line */
136 while (fgets (LineBuffer, AE_FILE_BUFFER_SIZE, InitFile) != NULL)
138 if (sscanf (LineBuffer, "%s %s\n",
139 &NameBuffer[1], ValueBuffer) != 2)
141 goto CleanupAndExit;
144 /* Add a root prefix if not present in the string */
146 i = 0;
147 if (NameBuffer[1] == '\\')
149 i = 1;
152 AeDoOneOverride (&NameBuffer[i], ValueBuffer, ObjDesc, WalkState);
155 /* Cleanup */
157 CleanupAndExit:
158 fclose (InitFile);
159 AcpiDsDeleteWalkState (WalkState);
160 AcpiUtRemoveReference (ObjDesc);
164 /******************************************************************************
166 * FUNCTION: AeDoOneOverride
168 * PARAMETERS: Pathname - AML namepath
169 * ValueString - New integer value to be stored
170 * ObjDesc - Descriptor with integer override value
171 * WalkState - Used for the Store operation
173 * RETURN: None
175 * DESCRIPTION: Perform an override for a single namespace object
177 *****************************************************************************/
179 static void
180 AeDoOneOverride (
181 char *Pathname,
182 char *ValueString,
183 ACPI_OPERAND_OBJECT *ObjDesc,
184 ACPI_WALK_STATE *WalkState)
186 ACPI_HANDLE Handle;
187 ACPI_STATUS Status;
188 UINT64 Value;
191 AcpiOsPrintf ("Value Override: %s, ", Pathname);
194 * Get the namespace node associated with the override
195 * pathname from the init file.
197 Status = AcpiGetHandle (NULL, Pathname, &Handle);
198 if (ACPI_FAILURE (Status))
200 AcpiOsPrintf ("%s\n", AcpiFormatException (Status));
201 return;
204 /* Extract the 64-bit integer */
206 Status = AcpiUtStrtoul64 (ValueString,
207 (ACPI_STRTOUL_BASE16 | ACPI_STRTOUL_64BIT), &Value);
208 if (ACPI_FAILURE (Status))
210 AcpiOsPrintf ("%s %s\n", ValueString,
211 AcpiFormatException (Status));
212 return;
215 ObjDesc->Integer.Value = Value;
218 * At the point this function is called, the namespace is fully
219 * built and initialized. We can simply store the new object to
220 * the target node.
222 AcpiExEnterInterpreter ();
223 Status = AcpiExStore (ObjDesc, Handle, WalkState);
224 AcpiExExitInterpreter ();
226 if (ACPI_FAILURE (Status))
228 AcpiOsPrintf ("%s\n", AcpiFormatException (Status));
229 return;
232 AcpiOsPrintf ("New value: 0x%8.8X%8.8X\n",
233 ACPI_FORMAT_UINT64 (Value));