aeinitfile.c revision 1.1.1.3 1 /******************************************************************************
2 *
3 * Module Name: aeinitfile - Support for optional initialization file
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2016, 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 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;
67
68
69 /******************************************************************************
70 *
71 * FUNCTION: AeOpenInitializationFile
72 *
73 * PARAMETERS: Filename - Path to the init file
74 *
75 * RETURN: Status
76 *
77 * DESCRIPTION: Open the initialization file for the -fi option
78 *
79 *****************************************************************************/
80
81 int
82 AeOpenInitializationFile (
83 char *Filename)
84 {
85
86 InitFile = fopen (Filename, "r");
87 if (!InitFile)
88 {
89 perror ("Could not open initialization file");
90 return (-1);
91 }
92
93 AcpiOsPrintf ("Opened initialization file [%s]\n", Filename);
94 return (0);
95 }
96
97
98 /******************************************************************************
99 *
100 * FUNCTION: AeDoObjectOverrides
101 *
102 * PARAMETERS: None
103 *
104 * RETURN: None
105 *
106 * DESCRIPTION: Read the initialization file and perform all overrides
107 *
108 * NOTE: The format of the file is multiple lines, each of format:
109 * <ACPI-pathname> <Integer Value>
110 *
111 *****************************************************************************/
112
113 void
114 AeDoObjectOverrides (
115 void)
116 {
117 ACPI_OPERAND_OBJECT *ObjDesc;
118 ACPI_WALK_STATE *WalkState;
119 int i;
120
121
122 if (!InitFile)
123 {
124 return;
125 }
126
127 /* Create needed objects to be reused for each init entry */
128
129 ObjDesc = AcpiUtCreateIntegerObject (0);
130 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
131 NameBuffer[0] = '\\';
132
133 /* Read the entire file line-by-line */
134
135 while (fgets (LineBuffer, AE_FILE_BUFFER_SIZE, InitFile) != NULL)
136 {
137 if (sscanf (LineBuffer, "%s %s\n",
138 &NameBuffer[1], ValueBuffer) != 2)
139 {
140 goto CleanupAndExit;
141 }
142
143 /* Add a root prefix if not present in the string */
144
145 i = 0;
146 if (NameBuffer[1] == '\\')
147 {
148 i = 1;
149 }
150
151 AeDoOneOverride (&NameBuffer[i], ValueBuffer, ObjDesc, WalkState);
152 }
153
154 /* Cleanup */
155
156 CleanupAndExit:
157 fclose (InitFile);
158 AcpiDsDeleteWalkState (WalkState);
159 AcpiUtRemoveReference (ObjDesc);
160 }
161
162
163 /******************************************************************************
164 *
165 * FUNCTION: AeDoOneOverride
166 *
167 * PARAMETERS: Pathname - AML namepath
168 * ValueString - New integer value to be stored
169 * ObjDesc - Descriptor with integer override value
170 * WalkState - Used for the Store operation
171 *
172 * RETURN: None
173 *
174 * DESCRIPTION: Perform an overrided for a single namespace object
175 *
176 *****************************************************************************/
177
178 static void
179 AeDoOneOverride (
180 char *Pathname,
181 char *ValueString,
182 ACPI_OPERAND_OBJECT *ObjDesc,
183 ACPI_WALK_STATE *WalkState)
184 {
185 ACPI_HANDLE Handle;
186 ACPI_STATUS Status;
187 UINT64 Value;
188
189
190 AcpiOsPrintf ("Value Override: %s, ", Pathname);
191
192 /*
193 * Get the namespace node associated with the override
194 * pathname from the init file.
195 */
196 Status = AcpiGetHandle (NULL, Pathname, &Handle);
197 if (ACPI_FAILURE (Status))
198 {
199 AcpiOsPrintf ("%s\n", AcpiFormatException (Status));
200 return;
201 }
202
203 /* Extract the 64-bit integer */
204
205 Status = AcpiUtStrtoul64 (ValueString, 0, &Value);
206 if (ACPI_FAILURE (Status))
207 {
208 AcpiOsPrintf ("%s %s\n", ValueString,
209 AcpiFormatException (Status));
210 return;
211 }
212
213 ObjDesc->Integer.Value = Value;
214
215 /*
216 * At the point this function is called, the namespace is fully
217 * built and initialized. We can simply store the new object to
218 * the target node.
219 */
220 AcpiExEnterInterpreter ();
221 Status = AcpiExStore (ObjDesc, Handle, WalkState);
222 AcpiExExitInterpreter ();
223
224 if (ACPI_FAILURE (Status))
225 {
226 AcpiOsPrintf ("%s\n", AcpiFormatException (Status));
227 return;
228 }
229
230 AcpiOsPrintf ("New value: 0x%8.8X%8.8X\n",
231 ACPI_FORMAT_UINT64 (Value));
232 }
233