exconfig.c revision 1.23 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.22 christos /******************************************************************************
8 1.22 christos *
9 1.22 christos * 1. Copyright Notice
10 1.22 christos *
11 1.23 christos * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.
12 1.1 jruoho * All rights reserved.
13 1.1 jruoho *
14 1.22 christos * 2. License
15 1.22 christos *
16 1.22 christos * 2.1. This is your license from Intel Corp. under its intellectual property
17 1.22 christos * rights. You may have additional license terms from the party that provided
18 1.22 christos * you this software, covering your right to use that party's intellectual
19 1.22 christos * property rights.
20 1.22 christos *
21 1.22 christos * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 1.22 christos * copy of the source code appearing in this file ("Covered Code") an
23 1.22 christos * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 1.22 christos * base code distributed originally by Intel ("Original Intel Code") to copy,
25 1.22 christos * make derivatives, distribute, use and display any portion of the Covered
26 1.22 christos * Code in any form, with the right to sublicense such rights; and
27 1.22 christos *
28 1.22 christos * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 1.22 christos * license (with the right to sublicense), under only those claims of Intel
30 1.22 christos * patents that are infringed by the Original Intel Code, to make, use, sell,
31 1.22 christos * offer to sell, and import the Covered Code and derivative works thereof
32 1.22 christos * solely to the minimum extent necessary to exercise the above copyright
33 1.22 christos * license, and in no event shall the patent license extend to any additions
34 1.22 christos * to or modifications of the Original Intel Code. No other license or right
35 1.22 christos * is granted directly or by implication, estoppel or otherwise;
36 1.22 christos *
37 1.22 christos * The above copyright and patent license is granted only if the following
38 1.22 christos * conditions are met:
39 1.22 christos *
40 1.22 christos * 3. Conditions
41 1.22 christos *
42 1.22 christos * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 1.22 christos * Redistribution of source code of any substantial portion of the Covered
44 1.22 christos * Code or modification with rights to further distribute source must include
45 1.22 christos * the above Copyright Notice, the above License, this list of Conditions,
46 1.22 christos * and the following Disclaimer and Export Compliance provision. In addition,
47 1.22 christos * Licensee must cause all Covered Code to which Licensee contributes to
48 1.22 christos * contain a file documenting the changes Licensee made to create that Covered
49 1.22 christos * Code and the date of any change. Licensee must include in that file the
50 1.22 christos * documentation of any changes made by any predecessor Licensee. Licensee
51 1.22 christos * must include a prominent statement that the modification is derived,
52 1.22 christos * directly or indirectly, from Original Intel Code.
53 1.22 christos *
54 1.22 christos * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 1.22 christos * Redistribution of source code of any substantial portion of the Covered
56 1.22 christos * Code or modification without rights to further distribute source must
57 1.22 christos * include the following Disclaimer and Export Compliance provision in the
58 1.22 christos * documentation and/or other materials provided with distribution. In
59 1.22 christos * addition, Licensee may not authorize further sublicense of source of any
60 1.22 christos * portion of the Covered Code, and must include terms to the effect that the
61 1.22 christos * license from Licensee to its licensee is limited to the intellectual
62 1.22 christos * property embodied in the software Licensee provides to its licensee, and
63 1.22 christos * not to intellectual property embodied in modifications its licensee may
64 1.22 christos * make.
65 1.22 christos *
66 1.22 christos * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 1.22 christos * substantial portion of the Covered Code or modification must reproduce the
68 1.22 christos * above Copyright Notice, and the following Disclaimer and Export Compliance
69 1.22 christos * provision in the documentation and/or other materials provided with the
70 1.22 christos * distribution.
71 1.22 christos *
72 1.22 christos * 3.4. Intel retains all right, title, and interest in and to the Original
73 1.22 christos * Intel Code.
74 1.22 christos *
75 1.22 christos * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 1.22 christos * Intel shall be used in advertising or otherwise to promote the sale, use or
77 1.22 christos * other dealings in products derived from or relating to the Covered Code
78 1.22 christos * without prior written authorization from Intel.
79 1.22 christos *
80 1.22 christos * 4. Disclaimer and Export Compliance
81 1.22 christos *
82 1.22 christos * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 1.22 christos * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 1.22 christos * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 1.22 christos * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 1.22 christos
87 1.22 christos * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 1.22 christos * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 1.22 christos * PARTICULAR PURPOSE.
90 1.22 christos *
91 1.22 christos * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 1.22 christos * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 1.22 christos * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 1.22 christos * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 1.22 christos * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 1.22 christos * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 1.22 christos * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 1.22 christos * LIMITED REMEDY.
99 1.22 christos *
100 1.22 christos * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 1.22 christos * software or system incorporating such software without first obtaining any
102 1.22 christos * required license or other approval from the U. S. Department of Commerce or
103 1.22 christos * any other agency or department of the United States Government. In the
104 1.22 christos * event Licensee exports any such software from the United States or
105 1.22 christos * re-exports any such software from a foreign destination, Licensee shall
106 1.22 christos * ensure that the distribution and export/re-export of the software is in
107 1.22 christos * compliance with all laws, regulations, orders, or other restrictions of the
108 1.22 christos * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 1.22 christos * any of its subsidiaries will export/re-export any technical data, process,
110 1.22 christos * software, or service, directly or indirectly, to any country for which the
111 1.22 christos * United States government or any agency thereof requires an export license,
112 1.22 christos * other governmental approval, or letter of assurance, without first obtaining
113 1.22 christos * such license, approval or letter.
114 1.22 christos *
115 1.22 christos *****************************************************************************
116 1.22 christos *
117 1.22 christos * Alternatively, you may choose to be licensed under the terms of the
118 1.22 christos * following license:
119 1.22 christos *
120 1.3 jruoho * Redistribution and use in source and binary forms, with or without
121 1.3 jruoho * modification, are permitted provided that the following conditions
122 1.3 jruoho * are met:
123 1.3 jruoho * 1. Redistributions of source code must retain the above copyright
124 1.3 jruoho * notice, this list of conditions, and the following disclaimer,
125 1.3 jruoho * without modification.
126 1.3 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
127 1.3 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
128 1.3 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
129 1.3 jruoho * including a substantially similar Disclaimer requirement for further
130 1.3 jruoho * binary redistribution.
131 1.3 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
132 1.3 jruoho * of any contributors may be used to endorse or promote products derived
133 1.3 jruoho * from this software without specific prior written permission.
134 1.3 jruoho *
135 1.3 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
136 1.3 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
137 1.17 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
138 1.3 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
139 1.22 christos * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
140 1.22 christos * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
141 1.22 christos * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
142 1.22 christos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
143 1.22 christos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
144 1.22 christos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
145 1.22 christos * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 1.22 christos *
147 1.22 christos * Alternatively, you may choose to be licensed under the terms of the
148 1.22 christos * GNU General Public License ("GPL") version 2 as published by the Free
149 1.22 christos * Software Foundation.
150 1.22 christos *
151 1.22 christos *****************************************************************************/
152 1.1 jruoho
153 1.1 jruoho #include "acpi.h"
154 1.1 jruoho #include "accommon.h"
155 1.1 jruoho #include "acinterp.h"
156 1.1 jruoho #include "acnamesp.h"
157 1.1 jruoho #include "actables.h"
158 1.1 jruoho #include "acdispat.h"
159 1.1 jruoho #include "acevents.h"
160 1.4 christos #include "amlcode.h"
161 1.1 jruoho
162 1.1 jruoho
163 1.1 jruoho #define _COMPONENT ACPI_EXECUTER
164 1.1 jruoho ACPI_MODULE_NAME ("exconfig")
165 1.1 jruoho
166 1.1 jruoho /* Local prototypes */
167 1.1 jruoho
168 1.1 jruoho static ACPI_STATUS
169 1.1 jruoho AcpiExAddTable (
170 1.1 jruoho UINT32 TableIndex,
171 1.1 jruoho ACPI_OPERAND_OBJECT **DdbHandle);
172 1.1 jruoho
173 1.1 jruoho static ACPI_STATUS
174 1.1 jruoho AcpiExRegionRead (
175 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc,
176 1.1 jruoho UINT32 Length,
177 1.1 jruoho UINT8 *Buffer);
178 1.1 jruoho
179 1.1 jruoho
180 1.1 jruoho /*******************************************************************************
181 1.1 jruoho *
182 1.1 jruoho * FUNCTION: AcpiExAddTable
183 1.1 jruoho *
184 1.1 jruoho * PARAMETERS: Table - Pointer to raw table
185 1.1 jruoho * ParentNode - Where to load the table (scope)
186 1.1 jruoho * DdbHandle - Where to return the table handle.
187 1.1 jruoho *
188 1.1 jruoho * RETURN: Status
189 1.1 jruoho *
190 1.1 jruoho * DESCRIPTION: Common function to Install and Load an ACPI table with a
191 1.1 jruoho * returned table handle.
192 1.1 jruoho *
193 1.1 jruoho ******************************************************************************/
194 1.1 jruoho
195 1.1 jruoho static ACPI_STATUS
196 1.1 jruoho AcpiExAddTable (
197 1.1 jruoho UINT32 TableIndex,
198 1.1 jruoho ACPI_OPERAND_OBJECT **DdbHandle)
199 1.1 jruoho {
200 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc;
201 1.1 jruoho
202 1.1 jruoho
203 1.1 jruoho ACPI_FUNCTION_TRACE (ExAddTable);
204 1.1 jruoho
205 1.1 jruoho
206 1.1 jruoho /* Create an object to be the table handle */
207 1.1 jruoho
208 1.1 jruoho ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
209 1.1 jruoho if (!ObjDesc)
210 1.1 jruoho {
211 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
212 1.1 jruoho }
213 1.1 jruoho
214 1.1 jruoho /* Init the table handle */
215 1.1 jruoho
216 1.1 jruoho ObjDesc->Common.Flags |= AOPOBJ_DATA_VALID;
217 1.1 jruoho ObjDesc->Reference.Class = ACPI_REFCLASS_TABLE;
218 1.10 christos ObjDesc->Reference.Value = TableIndex;
219 1.1 jruoho *DdbHandle = ObjDesc;
220 1.1 jruoho return_ACPI_STATUS (AE_OK);
221 1.1 jruoho }
222 1.1 jruoho
223 1.1 jruoho
224 1.1 jruoho /*******************************************************************************
225 1.1 jruoho *
226 1.1 jruoho * FUNCTION: AcpiExLoadTableOp
227 1.1 jruoho *
228 1.1 jruoho * PARAMETERS: WalkState - Current state with operands
229 1.1 jruoho * ReturnDesc - Where to store the return object
230 1.1 jruoho *
231 1.1 jruoho * RETURN: Status
232 1.1 jruoho *
233 1.1 jruoho * DESCRIPTION: Load an ACPI table from the RSDT/XSDT
234 1.1 jruoho *
235 1.1 jruoho ******************************************************************************/
236 1.1 jruoho
237 1.1 jruoho ACPI_STATUS
238 1.1 jruoho AcpiExLoadTableOp (
239 1.1 jruoho ACPI_WALK_STATE *WalkState,
240 1.1 jruoho ACPI_OPERAND_OBJECT **ReturnDesc)
241 1.1 jruoho {
242 1.1 jruoho ACPI_STATUS Status;
243 1.1 jruoho ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
244 1.1 jruoho ACPI_NAMESPACE_NODE *ParentNode;
245 1.1 jruoho ACPI_NAMESPACE_NODE *StartNode;
246 1.1 jruoho ACPI_NAMESPACE_NODE *ParameterNode = NULL;
247 1.19 christos ACPI_OPERAND_OBJECT *ReturnObj;
248 1.1 jruoho ACPI_OPERAND_OBJECT *DdbHandle;
249 1.1 jruoho UINT32 TableIndex;
250 1.1 jruoho
251 1.1 jruoho
252 1.1 jruoho ACPI_FUNCTION_TRACE (ExLoadTableOp);
253 1.1 jruoho
254 1.1 jruoho
255 1.19 christos /* Create the return object */
256 1.19 christos
257 1.19 christos ReturnObj = AcpiUtCreateIntegerObject ((UINT64) 0);
258 1.19 christos if (!ReturnObj)
259 1.19 christos {
260 1.19 christos return_ACPI_STATUS (AE_NO_MEMORY);
261 1.19 christos }
262 1.19 christos
263 1.19 christos *ReturnDesc = ReturnObj;
264 1.19 christos
265 1.1 jruoho /* Find the ACPI table in the RSDT/XSDT */
266 1.1 jruoho
267 1.10 christos AcpiExExitInterpreter ();
268 1.4 christos Status = AcpiTbFindTable (
269 1.8 christos Operand[0]->String.Pointer,
270 1.8 christos Operand[1]->String.Pointer,
271 1.8 christos Operand[2]->String.Pointer, &TableIndex);
272 1.10 christos AcpiExEnterInterpreter ();
273 1.1 jruoho if (ACPI_FAILURE (Status))
274 1.1 jruoho {
275 1.1 jruoho if (Status != AE_NOT_FOUND)
276 1.1 jruoho {
277 1.1 jruoho return_ACPI_STATUS (Status);
278 1.1 jruoho }
279 1.1 jruoho
280 1.1 jruoho /* Table not found, return an Integer=0 and AE_OK */
281 1.1 jruoho
282 1.1 jruoho return_ACPI_STATUS (AE_OK);
283 1.1 jruoho }
284 1.1 jruoho
285 1.1 jruoho /* Default nodes */
286 1.1 jruoho
287 1.1 jruoho StartNode = WalkState->ScopeInfo->Scope.Node;
288 1.1 jruoho ParentNode = AcpiGbl_RootNode;
289 1.1 jruoho
290 1.1 jruoho /* RootPath (optional parameter) */
291 1.1 jruoho
292 1.1 jruoho if (Operand[3]->String.Length > 0)
293 1.1 jruoho {
294 1.1 jruoho /*
295 1.4 christos * Find the node referenced by the RootPathString. This is the
296 1.1 jruoho * location within the namespace where the table will be loaded.
297 1.1 jruoho */
298 1.10 christos Status = AcpiNsGetNodeUnlocked (StartNode,
299 1.10 christos Operand[3]->String.Pointer, ACPI_NS_SEARCH_PARENT,
300 1.10 christos &ParentNode);
301 1.1 jruoho if (ACPI_FAILURE (Status))
302 1.1 jruoho {
303 1.1 jruoho return_ACPI_STATUS (Status);
304 1.1 jruoho }
305 1.1 jruoho }
306 1.1 jruoho
307 1.1 jruoho /* ParameterPath (optional parameter) */
308 1.1 jruoho
309 1.1 jruoho if (Operand[4]->String.Length > 0)
310 1.1 jruoho {
311 1.4 christos if ((Operand[4]->String.Pointer[0] != AML_ROOT_PREFIX) &&
312 1.4 christos (Operand[4]->String.Pointer[0] != AML_PARENT_PREFIX))
313 1.1 jruoho {
314 1.1 jruoho /*
315 1.1 jruoho * Path is not absolute, so it will be relative to the node
316 1.1 jruoho * referenced by the RootPathString (or the NS root if omitted)
317 1.1 jruoho */
318 1.1 jruoho StartNode = ParentNode;
319 1.1 jruoho }
320 1.1 jruoho
321 1.1 jruoho /* Find the node referenced by the ParameterPathString */
322 1.1 jruoho
323 1.10 christos Status = AcpiNsGetNodeUnlocked (StartNode,
324 1.10 christos Operand[4]->String.Pointer, ACPI_NS_SEARCH_PARENT,
325 1.10 christos &ParameterNode);
326 1.1 jruoho if (ACPI_FAILURE (Status))
327 1.1 jruoho {
328 1.1 jruoho return_ACPI_STATUS (Status);
329 1.1 jruoho }
330 1.1 jruoho }
331 1.1 jruoho
332 1.1 jruoho /* Load the table into the namespace */
333 1.1 jruoho
334 1.10 christos ACPI_INFO (("Dynamic OEM Table Load:"));
335 1.10 christos AcpiExExitInterpreter ();
336 1.10 christos Status = AcpiTbLoadTable (TableIndex, ParentNode);
337 1.10 christos AcpiExEnterInterpreter ();
338 1.10 christos if (ACPI_FAILURE (Status))
339 1.10 christos {
340 1.11 christos return_ACPI_STATUS (Status);
341 1.10 christos }
342 1.10 christos
343 1.10 christos Status = AcpiExAddTable (TableIndex, &DdbHandle);
344 1.1 jruoho if (ACPI_FAILURE (Status))
345 1.1 jruoho {
346 1.1 jruoho return_ACPI_STATUS (Status);
347 1.1 jruoho }
348 1.1 jruoho
349 1.15 christos /* Complete the initialization/resolution of new objects */
350 1.13 christos
351 1.15 christos AcpiExExitInterpreter();
352 1.15 christos AcpiNsInitializeObjects();
353 1.15 christos AcpiExEnterInterpreter();
354 1.13 christos
355 1.1 jruoho /* Parameter Data (optional) */
356 1.1 jruoho
357 1.1 jruoho if (ParameterNode)
358 1.1 jruoho {
359 1.1 jruoho /* Store the parameter data into the optional parameter object */
360 1.1 jruoho
361 1.1 jruoho Status = AcpiExStore (Operand[5],
362 1.8 christos ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode), WalkState);
363 1.1 jruoho if (ACPI_FAILURE (Status))
364 1.1 jruoho {
365 1.1 jruoho (void) AcpiExUnloadTable (DdbHandle);
366 1.1 jruoho
367 1.1 jruoho AcpiUtRemoveReference (DdbHandle);
368 1.1 jruoho return_ACPI_STATUS (Status);
369 1.1 jruoho }
370 1.1 jruoho }
371 1.1 jruoho
372 1.19 christos /* Remove the reference to DdbHandle created by AcpiExAddTable above */
373 1.19 christos
374 1.19 christos AcpiUtRemoveReference (DdbHandle);
375 1.19 christos
376 1.19 christos /* Return -1 (non-zero) indicates success */
377 1.19 christos
378 1.19 christos ReturnObj->Integer.Value = 0xFFFFFFFFFFFFFFFF;
379 1.4 christos return_ACPI_STATUS (Status);
380 1.1 jruoho }
381 1.1 jruoho
382 1.1 jruoho
383 1.1 jruoho /*******************************************************************************
384 1.1 jruoho *
385 1.1 jruoho * FUNCTION: AcpiExRegionRead
386 1.1 jruoho *
387 1.1 jruoho * PARAMETERS: ObjDesc - Region descriptor
388 1.1 jruoho * Length - Number of bytes to read
389 1.1 jruoho * Buffer - Pointer to where to put the data
390 1.1 jruoho *
391 1.1 jruoho * RETURN: Status
392 1.1 jruoho *
393 1.1 jruoho * DESCRIPTION: Read data from an operation region. The read starts from the
394 1.1 jruoho * beginning of the region.
395 1.1 jruoho *
396 1.1 jruoho ******************************************************************************/
397 1.1 jruoho
398 1.1 jruoho static ACPI_STATUS
399 1.1 jruoho AcpiExRegionRead (
400 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc,
401 1.1 jruoho UINT32 Length,
402 1.1 jruoho UINT8 *Buffer)
403 1.1 jruoho {
404 1.1 jruoho ACPI_STATUS Status;
405 1.1 jruoho UINT64 Value;
406 1.1 jruoho UINT32 RegionOffset = 0;
407 1.1 jruoho UINT32 i;
408 1.1 jruoho
409 1.1 jruoho
410 1.1 jruoho /* Bytewise reads */
411 1.1 jruoho
412 1.1 jruoho for (i = 0; i < Length; i++)
413 1.1 jruoho {
414 1.4 christos Status = AcpiEvAddressSpaceDispatch (ObjDesc, NULL, ACPI_READ,
415 1.8 christos RegionOffset, 8, &Value);
416 1.1 jruoho if (ACPI_FAILURE (Status))
417 1.1 jruoho {
418 1.1 jruoho return (Status);
419 1.1 jruoho }
420 1.1 jruoho
421 1.1 jruoho *Buffer = (UINT8) Value;
422 1.1 jruoho Buffer++;
423 1.1 jruoho RegionOffset++;
424 1.1 jruoho }
425 1.1 jruoho
426 1.1 jruoho return (AE_OK);
427 1.1 jruoho }
428 1.1 jruoho
429 1.1 jruoho
430 1.1 jruoho /*******************************************************************************
431 1.1 jruoho *
432 1.1 jruoho * FUNCTION: AcpiExLoadOp
433 1.1 jruoho *
434 1.1 jruoho * PARAMETERS: ObjDesc - Region or Buffer/Field where the table will be
435 1.1 jruoho * obtained
436 1.19 christos * Target - Where the status of the load will be stored
437 1.1 jruoho * WalkState - Current state
438 1.1 jruoho *
439 1.1 jruoho * RETURN: Status
440 1.1 jruoho *
441 1.1 jruoho * DESCRIPTION: Load an ACPI table from a field or operation region
442 1.1 jruoho *
443 1.1 jruoho * NOTE: Region Fields (Field, BankField, IndexFields) are resolved to buffer
444 1.1 jruoho * objects before this code is reached.
445 1.1 jruoho *
446 1.1 jruoho * If source is an operation region, it must refer to SystemMemory, as
447 1.1 jruoho * per the ACPI specification.
448 1.1 jruoho *
449 1.1 jruoho ******************************************************************************/
450 1.1 jruoho
451 1.1 jruoho ACPI_STATUS
452 1.1 jruoho AcpiExLoadOp (
453 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc,
454 1.1 jruoho ACPI_OPERAND_OBJECT *Target,
455 1.1 jruoho ACPI_WALK_STATE *WalkState)
456 1.1 jruoho {
457 1.1 jruoho ACPI_OPERAND_OBJECT *DdbHandle;
458 1.5 christos ACPI_TABLE_HEADER *TableHeader;
459 1.1 jruoho ACPI_TABLE_HEADER *Table;
460 1.1 jruoho UINT32 TableIndex;
461 1.1 jruoho ACPI_STATUS Status;
462 1.1 jruoho UINT32 Length;
463 1.1 jruoho
464 1.1 jruoho
465 1.1 jruoho ACPI_FUNCTION_TRACE (ExLoadOp);
466 1.1 jruoho
467 1.1 jruoho
468 1.19 christos if (Target->Common.DescriptorType == ACPI_DESC_TYPE_NAMED)
469 1.19 christos {
470 1.19 christos Target = AcpiNsGetAttachedObject (ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Target));
471 1.19 christos }
472 1.19 christos if (Target->Common.Type != ACPI_TYPE_INTEGER)
473 1.19 christos {
474 1.20 christos ACPI_ERROR ((AE_INFO, "Type not integer: %X", Target->Common.Type));
475 1.19 christos return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
476 1.19 christos }
477 1.19 christos
478 1.19 christos Target->Integer.Value = 0;
479 1.19 christos
480 1.1 jruoho /* Source Object can be either an OpRegion or a Buffer/Field */
481 1.1 jruoho
482 1.1 jruoho switch (ObjDesc->Common.Type)
483 1.1 jruoho {
484 1.1 jruoho case ACPI_TYPE_REGION:
485 1.1 jruoho
486 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
487 1.1 jruoho "Load table from Region %p\n", ObjDesc));
488 1.1 jruoho
489 1.1 jruoho /* Region must be SystemMemory (from ACPI spec) */
490 1.1 jruoho
491 1.1 jruoho if (ObjDesc->Region.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
492 1.1 jruoho {
493 1.1 jruoho return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
494 1.1 jruoho }
495 1.1 jruoho
496 1.1 jruoho /*
497 1.8 christos * If the Region Address and Length have not been previously
498 1.8 christos * evaluated, evaluate them now and save the results.
499 1.1 jruoho */
500 1.1 jruoho if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
501 1.1 jruoho {
502 1.1 jruoho Status = AcpiDsGetRegionArguments (ObjDesc);
503 1.1 jruoho if (ACPI_FAILURE (Status))
504 1.1 jruoho {
505 1.1 jruoho return_ACPI_STATUS (Status);
506 1.1 jruoho }
507 1.1 jruoho }
508 1.1 jruoho
509 1.1 jruoho /* Get the table header first so we can get the table length */
510 1.1 jruoho
511 1.5 christos TableHeader = ACPI_ALLOCATE (sizeof (ACPI_TABLE_HEADER));
512 1.5 christos if (!TableHeader)
513 1.1 jruoho {
514 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
515 1.1 jruoho }
516 1.1 jruoho
517 1.1 jruoho Status = AcpiExRegionRead (ObjDesc, sizeof (ACPI_TABLE_HEADER),
518 1.8 christos ACPI_CAST_PTR (UINT8, TableHeader));
519 1.5 christos Length = TableHeader->Length;
520 1.5 christos ACPI_FREE (TableHeader);
521 1.1 jruoho
522 1.1 jruoho if (ACPI_FAILURE (Status))
523 1.1 jruoho {
524 1.1 jruoho return_ACPI_STATUS (Status);
525 1.1 jruoho }
526 1.1 jruoho
527 1.1 jruoho /* Must have at least an ACPI table header */
528 1.1 jruoho
529 1.1 jruoho if (Length < sizeof (ACPI_TABLE_HEADER))
530 1.1 jruoho {
531 1.1 jruoho return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
532 1.1 jruoho }
533 1.1 jruoho
534 1.1 jruoho /*
535 1.1 jruoho * The original implementation simply mapped the table, with no copy.
536 1.1 jruoho * However, the memory region is not guaranteed to remain stable and
537 1.1 jruoho * we must copy the table to a local buffer. For example, the memory
538 1.1 jruoho * region is corrupted after suspend on some machines. Dynamically
539 1.1 jruoho * loaded tables are usually small, so this overhead is minimal.
540 1.1 jruoho *
541 1.1 jruoho * The latest implementation (5/2009) does not use a mapping at all.
542 1.1 jruoho * We use the low-level operation region interface to read the table
543 1.1 jruoho * instead of the obvious optimization of using a direct mapping.
544 1.1 jruoho * This maintains a consistent use of operation regions across the
545 1.1 jruoho * entire subsystem. This is important if additional processing must
546 1.1 jruoho * be performed in the (possibly user-installed) operation region
547 1.1 jruoho * handler. For example, AcpiExec and ASLTS depend on this.
548 1.1 jruoho */
549 1.1 jruoho
550 1.1 jruoho /* Allocate a buffer for the table */
551 1.1 jruoho
552 1.5 christos Table = ACPI_ALLOCATE (Length);
553 1.5 christos if (!Table)
554 1.1 jruoho {
555 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
556 1.1 jruoho }
557 1.1 jruoho
558 1.1 jruoho /* Read the entire table */
559 1.1 jruoho
560 1.1 jruoho Status = AcpiExRegionRead (ObjDesc, Length,
561 1.8 christos ACPI_CAST_PTR (UINT8, Table));
562 1.1 jruoho if (ACPI_FAILURE (Status))
563 1.1 jruoho {
564 1.5 christos ACPI_FREE (Table);
565 1.1 jruoho return_ACPI_STATUS (Status);
566 1.1 jruoho }
567 1.1 jruoho break;
568 1.1 jruoho
569 1.1 jruoho case ACPI_TYPE_BUFFER: /* Buffer or resolved RegionField */
570 1.1 jruoho
571 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
572 1.1 jruoho "Load table from Buffer or Field %p\n", ObjDesc));
573 1.1 jruoho
574 1.1 jruoho /* Must have at least an ACPI table header */
575 1.1 jruoho
576 1.1 jruoho if (ObjDesc->Buffer.Length < sizeof (ACPI_TABLE_HEADER))
577 1.1 jruoho {
578 1.1 jruoho return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
579 1.1 jruoho }
580 1.1 jruoho
581 1.1 jruoho /* Get the actual table length from the table header */
582 1.1 jruoho
583 1.8 christos TableHeader = ACPI_CAST_PTR (
584 1.8 christos ACPI_TABLE_HEADER, ObjDesc->Buffer.Pointer);
585 1.5 christos Length = TableHeader->Length;
586 1.1 jruoho
587 1.1 jruoho /* Table cannot extend beyond the buffer */
588 1.1 jruoho
589 1.1 jruoho if (Length > ObjDesc->Buffer.Length)
590 1.1 jruoho {
591 1.1 jruoho return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
592 1.1 jruoho }
593 1.1 jruoho if (Length < sizeof (ACPI_TABLE_HEADER))
594 1.1 jruoho {
595 1.1 jruoho return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
596 1.1 jruoho }
597 1.1 jruoho
598 1.1 jruoho /*
599 1.8 christos * Copy the table from the buffer because the buffer could be
600 1.8 christos * modified or even deleted in the future
601 1.1 jruoho */
602 1.5 christos Table = ACPI_ALLOCATE (Length);
603 1.5 christos if (!Table)
604 1.1 jruoho {
605 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
606 1.1 jruoho }
607 1.1 jruoho
608 1.7 christos memcpy (Table, TableHeader, Length);
609 1.1 jruoho break;
610 1.1 jruoho
611 1.4 christos default:
612 1.1 jruoho
613 1.1 jruoho return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
614 1.1 jruoho }
615 1.1 jruoho
616 1.5 christos /* Install the new table into the local data structures */
617 1.5 christos
618 1.9 christos ACPI_INFO (("Dynamic OEM Table Load:"));
619 1.10 christos AcpiExExitInterpreter ();
620 1.11 christos Status = AcpiTbInstallAndLoadTable (ACPI_PTR_TO_PHYSADDR (Table),
621 1.18 christos ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, Table, TRUE, &TableIndex);
622 1.10 christos AcpiExEnterInterpreter ();
623 1.1 jruoho if (ACPI_FAILURE (Status))
624 1.1 jruoho {
625 1.5 christos /* Delete allocated table buffer */
626 1.5 christos
627 1.5 christos ACPI_FREE (Table);
628 1.1 jruoho return_ACPI_STATUS (Status);
629 1.1 jruoho }
630 1.1 jruoho
631 1.5 christos /*
632 1.1 jruoho * Add the table to the namespace.
633 1.1 jruoho *
634 1.1 jruoho * Note: Load the table objects relative to the root of the namespace.
635 1.1 jruoho * This appears to go against the ACPI specification, but we do it for
636 1.1 jruoho * compatibility with other ACPI implementations.
637 1.1 jruoho */
638 1.10 christos Status = AcpiExAddTable (TableIndex, &DdbHandle);
639 1.1 jruoho if (ACPI_FAILURE (Status))
640 1.1 jruoho {
641 1.1 jruoho return_ACPI_STATUS (Status);
642 1.1 jruoho }
643 1.1 jruoho
644 1.15 christos /* Complete the initialization/resolution of new objects */
645 1.13 christos
646 1.15 christos AcpiExExitInterpreter ();
647 1.15 christos AcpiNsInitializeObjects ();
648 1.15 christos AcpiExEnterInterpreter ();
649 1.13 christos
650 1.19 christos /* Remove the reference to DdbHandle created by AcpiExAddTable above */
651 1.1 jruoho
652 1.19 christos AcpiUtRemoveReference (DdbHandle);
653 1.1 jruoho
654 1.19 christos /* Return -1 (non-zero) indicates success */
655 1.1 jruoho
656 1.19 christos Target->Integer.Value = 0xFFFFFFFFFFFFFFFF;
657 1.1 jruoho return_ACPI_STATUS (Status);
658 1.1 jruoho }
659 1.1 jruoho
660 1.1 jruoho
661 1.1 jruoho /*******************************************************************************
662 1.1 jruoho *
663 1.1 jruoho * FUNCTION: AcpiExUnloadTable
664 1.1 jruoho *
665 1.1 jruoho * PARAMETERS: DdbHandle - Handle to a previously loaded table
666 1.1 jruoho *
667 1.1 jruoho * RETURN: Status
668 1.1 jruoho *
669 1.1 jruoho * DESCRIPTION: Unload an ACPI table
670 1.1 jruoho *
671 1.1 jruoho ******************************************************************************/
672 1.1 jruoho
673 1.1 jruoho ACPI_STATUS
674 1.1 jruoho AcpiExUnloadTable (
675 1.1 jruoho ACPI_OPERAND_OBJECT *DdbHandle)
676 1.1 jruoho {
677 1.1 jruoho ACPI_STATUS Status = AE_OK;
678 1.1 jruoho ACPI_OPERAND_OBJECT *TableDesc = DdbHandle;
679 1.1 jruoho UINT32 TableIndex;
680 1.1 jruoho
681 1.1 jruoho
682 1.1 jruoho ACPI_FUNCTION_TRACE (ExUnloadTable);
683 1.1 jruoho
684 1.1 jruoho
685 1.1 jruoho /*
686 1.5 christos * Temporarily emit a warning so that the ASL for the machine can be
687 1.5 christos * hopefully obtained. This is to say that the Unload() operator is
688 1.5 christos * extremely rare if not completely unused.
689 1.5 christos */
690 1.5 christos ACPI_WARNING ((AE_INFO,
691 1.5 christos "Received request to unload an ACPI table"));
692 1.5 christos
693 1.5 christos /*
694 1.13 christos * May 2018: Unload is no longer supported for the following reasons:
695 1.13 christos * 1) A correct implementation on some hosts may not be possible.
696 1.13 christos * 2) Other ACPI implementations do not correctly/fully support it.
697 1.13 christos * 3) It requires host device driver support which does not exist.
698 1.13 christos * (To properly support namespace unload out from underneath.)
699 1.13 christos * 4) This AML operator has never been seen in the field.
700 1.13 christos */
701 1.13 christos ACPI_EXCEPTION ((AE_INFO, AE_NOT_IMPLEMENTED,
702 1.13 christos "AML Unload operator is not supported"));
703 1.13 christos
704 1.13 christos /*
705 1.1 jruoho * Validate the handle
706 1.1 jruoho * Although the handle is partially validated in AcpiExReconfiguration()
707 1.1 jruoho * when it calls AcpiExResolveOperands(), the handle is more completely
708 1.1 jruoho * validated here.
709 1.1 jruoho *
710 1.1 jruoho * Handle must be a valid operand object of type reference. Also, the
711 1.1 jruoho * DdbHandle must still be marked valid (table has not been previously
712 1.1 jruoho * unloaded)
713 1.1 jruoho */
714 1.1 jruoho if ((!DdbHandle) ||
715 1.1 jruoho (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle) != ACPI_DESC_TYPE_OPERAND) ||
716 1.1 jruoho (DdbHandle->Common.Type != ACPI_TYPE_LOCAL_REFERENCE) ||
717 1.1 jruoho (!(DdbHandle->Common.Flags & AOPOBJ_DATA_VALID)))
718 1.1 jruoho {
719 1.4 christos return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
720 1.1 jruoho }
721 1.1 jruoho
722 1.1 jruoho /* Get the table index from the DdbHandle */
723 1.1 jruoho
724 1.1 jruoho TableIndex = TableDesc->Reference.Value;
725 1.1 jruoho
726 1.10 christos /*
727 1.10 christos * Release the interpreter lock so that the table lock won't have
728 1.10 christos * strict order requirement against it.
729 1.10 christos */
730 1.10 christos AcpiExExitInterpreter ();
731 1.11 christos Status = AcpiTbUnloadTable (TableIndex);
732 1.10 christos AcpiExEnterInterpreter ();
733 1.10 christos
734 1.1 jruoho /*
735 1.1 jruoho * Invalidate the handle. We do this because the handle may be stored
736 1.1 jruoho * in a named object and may not be actually deleted until much later.
737 1.1 jruoho */
738 1.10 christos if (ACPI_SUCCESS (Status))
739 1.10 christos {
740 1.10 christos DdbHandle->Common.Flags &= ~AOPOBJ_DATA_VALID;
741 1.10 christos }
742 1.10 christos return_ACPI_STATUS (Status);
743 1.1 jruoho }
744