exconfig.c revision 1.19 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.3 jruoho /*
8 1.19 christos * Copyright (C) 2000 - 2022, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.3 jruoho * Redistribution and use in source and binary forms, with or without
12 1.3 jruoho * modification, are permitted provided that the following conditions
13 1.3 jruoho * are met:
14 1.3 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.3 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.3 jruoho * without modification.
17 1.3 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.3 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.3 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.3 jruoho * including a substantially similar Disclaimer requirement for further
21 1.3 jruoho * binary redistribution.
22 1.3 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.3 jruoho * of any contributors may be used to endorse or promote products derived
24 1.3 jruoho * from this software without specific prior written permission.
25 1.3 jruoho *
26 1.3 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.3 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.3 jruoho * Software Foundation.
29 1.3 jruoho *
30 1.3 jruoho * NO WARRANTY
31 1.3 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.3 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.17 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 1.3 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.3 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.3 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.3 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.3 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.3 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.3 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.3 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.3 jruoho */
43 1.1 jruoho
44 1.1 jruoho #include "acpi.h"
45 1.1 jruoho #include "accommon.h"
46 1.1 jruoho #include "acinterp.h"
47 1.1 jruoho #include "acnamesp.h"
48 1.1 jruoho #include "actables.h"
49 1.1 jruoho #include "acdispat.h"
50 1.1 jruoho #include "acevents.h"
51 1.4 christos #include "amlcode.h"
52 1.1 jruoho
53 1.1 jruoho
54 1.1 jruoho #define _COMPONENT ACPI_EXECUTER
55 1.1 jruoho ACPI_MODULE_NAME ("exconfig")
56 1.1 jruoho
57 1.1 jruoho /* Local prototypes */
58 1.1 jruoho
59 1.1 jruoho static ACPI_STATUS
60 1.1 jruoho AcpiExAddTable (
61 1.1 jruoho UINT32 TableIndex,
62 1.1 jruoho ACPI_OPERAND_OBJECT **DdbHandle);
63 1.1 jruoho
64 1.1 jruoho static ACPI_STATUS
65 1.1 jruoho AcpiExRegionRead (
66 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc,
67 1.1 jruoho UINT32 Length,
68 1.1 jruoho UINT8 *Buffer);
69 1.1 jruoho
70 1.1 jruoho
71 1.1 jruoho /*******************************************************************************
72 1.1 jruoho *
73 1.1 jruoho * FUNCTION: AcpiExAddTable
74 1.1 jruoho *
75 1.1 jruoho * PARAMETERS: Table - Pointer to raw table
76 1.1 jruoho * ParentNode - Where to load the table (scope)
77 1.1 jruoho * DdbHandle - Where to return the table handle.
78 1.1 jruoho *
79 1.1 jruoho * RETURN: Status
80 1.1 jruoho *
81 1.1 jruoho * DESCRIPTION: Common function to Install and Load an ACPI table with a
82 1.1 jruoho * returned table handle.
83 1.1 jruoho *
84 1.1 jruoho ******************************************************************************/
85 1.1 jruoho
86 1.1 jruoho static ACPI_STATUS
87 1.1 jruoho AcpiExAddTable (
88 1.1 jruoho UINT32 TableIndex,
89 1.1 jruoho ACPI_OPERAND_OBJECT **DdbHandle)
90 1.1 jruoho {
91 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc;
92 1.1 jruoho
93 1.1 jruoho
94 1.1 jruoho ACPI_FUNCTION_TRACE (ExAddTable);
95 1.1 jruoho
96 1.1 jruoho
97 1.1 jruoho /* Create an object to be the table handle */
98 1.1 jruoho
99 1.1 jruoho ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
100 1.1 jruoho if (!ObjDesc)
101 1.1 jruoho {
102 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
103 1.1 jruoho }
104 1.1 jruoho
105 1.1 jruoho /* Init the table handle */
106 1.1 jruoho
107 1.1 jruoho ObjDesc->Common.Flags |= AOPOBJ_DATA_VALID;
108 1.1 jruoho ObjDesc->Reference.Class = ACPI_REFCLASS_TABLE;
109 1.10 christos ObjDesc->Reference.Value = TableIndex;
110 1.1 jruoho *DdbHandle = ObjDesc;
111 1.1 jruoho return_ACPI_STATUS (AE_OK);
112 1.1 jruoho }
113 1.1 jruoho
114 1.1 jruoho
115 1.1 jruoho /*******************************************************************************
116 1.1 jruoho *
117 1.1 jruoho * FUNCTION: AcpiExLoadTableOp
118 1.1 jruoho *
119 1.1 jruoho * PARAMETERS: WalkState - Current state with operands
120 1.1 jruoho * ReturnDesc - Where to store the return object
121 1.1 jruoho *
122 1.1 jruoho * RETURN: Status
123 1.1 jruoho *
124 1.1 jruoho * DESCRIPTION: Load an ACPI table from the RSDT/XSDT
125 1.1 jruoho *
126 1.1 jruoho ******************************************************************************/
127 1.1 jruoho
128 1.1 jruoho ACPI_STATUS
129 1.1 jruoho AcpiExLoadTableOp (
130 1.1 jruoho ACPI_WALK_STATE *WalkState,
131 1.1 jruoho ACPI_OPERAND_OBJECT **ReturnDesc)
132 1.1 jruoho {
133 1.1 jruoho ACPI_STATUS Status;
134 1.1 jruoho ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
135 1.1 jruoho ACPI_NAMESPACE_NODE *ParentNode;
136 1.1 jruoho ACPI_NAMESPACE_NODE *StartNode;
137 1.1 jruoho ACPI_NAMESPACE_NODE *ParameterNode = NULL;
138 1.19 christos ACPI_OPERAND_OBJECT *ReturnObj;
139 1.1 jruoho ACPI_OPERAND_OBJECT *DdbHandle;
140 1.1 jruoho UINT32 TableIndex;
141 1.1 jruoho
142 1.1 jruoho
143 1.1 jruoho ACPI_FUNCTION_TRACE (ExLoadTableOp);
144 1.1 jruoho
145 1.1 jruoho
146 1.19 christos /* Create the return object */
147 1.19 christos
148 1.19 christos ReturnObj = AcpiUtCreateIntegerObject ((UINT64) 0);
149 1.19 christos if (!ReturnObj)
150 1.19 christos {
151 1.19 christos return_ACPI_STATUS (AE_NO_MEMORY);
152 1.19 christos }
153 1.19 christos
154 1.19 christos *ReturnDesc = ReturnObj;
155 1.19 christos
156 1.1 jruoho /* Find the ACPI table in the RSDT/XSDT */
157 1.1 jruoho
158 1.10 christos AcpiExExitInterpreter ();
159 1.4 christos Status = AcpiTbFindTable (
160 1.8 christos Operand[0]->String.Pointer,
161 1.8 christos Operand[1]->String.Pointer,
162 1.8 christos Operand[2]->String.Pointer, &TableIndex);
163 1.10 christos AcpiExEnterInterpreter ();
164 1.1 jruoho if (ACPI_FAILURE (Status))
165 1.1 jruoho {
166 1.1 jruoho if (Status != AE_NOT_FOUND)
167 1.1 jruoho {
168 1.1 jruoho return_ACPI_STATUS (Status);
169 1.1 jruoho }
170 1.1 jruoho
171 1.1 jruoho /* Table not found, return an Integer=0 and AE_OK */
172 1.1 jruoho
173 1.1 jruoho return_ACPI_STATUS (AE_OK);
174 1.1 jruoho }
175 1.1 jruoho
176 1.1 jruoho /* Default nodes */
177 1.1 jruoho
178 1.1 jruoho StartNode = WalkState->ScopeInfo->Scope.Node;
179 1.1 jruoho ParentNode = AcpiGbl_RootNode;
180 1.1 jruoho
181 1.1 jruoho /* RootPath (optional parameter) */
182 1.1 jruoho
183 1.1 jruoho if (Operand[3]->String.Length > 0)
184 1.1 jruoho {
185 1.1 jruoho /*
186 1.4 christos * Find the node referenced by the RootPathString. This is the
187 1.1 jruoho * location within the namespace where the table will be loaded.
188 1.1 jruoho */
189 1.10 christos Status = AcpiNsGetNodeUnlocked (StartNode,
190 1.10 christos Operand[3]->String.Pointer, ACPI_NS_SEARCH_PARENT,
191 1.10 christos &ParentNode);
192 1.1 jruoho if (ACPI_FAILURE (Status))
193 1.1 jruoho {
194 1.1 jruoho return_ACPI_STATUS (Status);
195 1.1 jruoho }
196 1.1 jruoho }
197 1.1 jruoho
198 1.1 jruoho /* ParameterPath (optional parameter) */
199 1.1 jruoho
200 1.1 jruoho if (Operand[4]->String.Length > 0)
201 1.1 jruoho {
202 1.4 christos if ((Operand[4]->String.Pointer[0] != AML_ROOT_PREFIX) &&
203 1.4 christos (Operand[4]->String.Pointer[0] != AML_PARENT_PREFIX))
204 1.1 jruoho {
205 1.1 jruoho /*
206 1.1 jruoho * Path is not absolute, so it will be relative to the node
207 1.1 jruoho * referenced by the RootPathString (or the NS root if omitted)
208 1.1 jruoho */
209 1.1 jruoho StartNode = ParentNode;
210 1.1 jruoho }
211 1.1 jruoho
212 1.1 jruoho /* Find the node referenced by the ParameterPathString */
213 1.1 jruoho
214 1.10 christos Status = AcpiNsGetNodeUnlocked (StartNode,
215 1.10 christos Operand[4]->String.Pointer, ACPI_NS_SEARCH_PARENT,
216 1.10 christos &ParameterNode);
217 1.1 jruoho if (ACPI_FAILURE (Status))
218 1.1 jruoho {
219 1.1 jruoho return_ACPI_STATUS (Status);
220 1.1 jruoho }
221 1.1 jruoho }
222 1.1 jruoho
223 1.1 jruoho /* Load the table into the namespace */
224 1.1 jruoho
225 1.10 christos ACPI_INFO (("Dynamic OEM Table Load:"));
226 1.10 christos AcpiExExitInterpreter ();
227 1.10 christos Status = AcpiTbLoadTable (TableIndex, ParentNode);
228 1.10 christos AcpiExEnterInterpreter ();
229 1.10 christos if (ACPI_FAILURE (Status))
230 1.10 christos {
231 1.11 christos return_ACPI_STATUS (Status);
232 1.10 christos }
233 1.10 christos
234 1.10 christos Status = AcpiExAddTable (TableIndex, &DdbHandle);
235 1.1 jruoho if (ACPI_FAILURE (Status))
236 1.1 jruoho {
237 1.1 jruoho return_ACPI_STATUS (Status);
238 1.1 jruoho }
239 1.1 jruoho
240 1.15 christos /* Complete the initialization/resolution of new objects */
241 1.13 christos
242 1.15 christos AcpiExExitInterpreter();
243 1.15 christos AcpiNsInitializeObjects();
244 1.15 christos AcpiExEnterInterpreter();
245 1.13 christos
246 1.1 jruoho /* Parameter Data (optional) */
247 1.1 jruoho
248 1.1 jruoho if (ParameterNode)
249 1.1 jruoho {
250 1.1 jruoho /* Store the parameter data into the optional parameter object */
251 1.1 jruoho
252 1.1 jruoho Status = AcpiExStore (Operand[5],
253 1.8 christos ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode), WalkState);
254 1.1 jruoho if (ACPI_FAILURE (Status))
255 1.1 jruoho {
256 1.1 jruoho (void) AcpiExUnloadTable (DdbHandle);
257 1.1 jruoho
258 1.1 jruoho AcpiUtRemoveReference (DdbHandle);
259 1.1 jruoho return_ACPI_STATUS (Status);
260 1.1 jruoho }
261 1.1 jruoho }
262 1.1 jruoho
263 1.19 christos /* Remove the reference to DdbHandle created by AcpiExAddTable above */
264 1.19 christos
265 1.19 christos AcpiUtRemoveReference (DdbHandle);
266 1.19 christos
267 1.19 christos /* Return -1 (non-zero) indicates success */
268 1.19 christos
269 1.19 christos ReturnObj->Integer.Value = 0xFFFFFFFFFFFFFFFF;
270 1.4 christos return_ACPI_STATUS (Status);
271 1.1 jruoho }
272 1.1 jruoho
273 1.1 jruoho
274 1.1 jruoho /*******************************************************************************
275 1.1 jruoho *
276 1.1 jruoho * FUNCTION: AcpiExRegionRead
277 1.1 jruoho *
278 1.1 jruoho * PARAMETERS: ObjDesc - Region descriptor
279 1.1 jruoho * Length - Number of bytes to read
280 1.1 jruoho * Buffer - Pointer to where to put the data
281 1.1 jruoho *
282 1.1 jruoho * RETURN: Status
283 1.1 jruoho *
284 1.1 jruoho * DESCRIPTION: Read data from an operation region. The read starts from the
285 1.1 jruoho * beginning of the region.
286 1.1 jruoho *
287 1.1 jruoho ******************************************************************************/
288 1.1 jruoho
289 1.1 jruoho static ACPI_STATUS
290 1.1 jruoho AcpiExRegionRead (
291 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc,
292 1.1 jruoho UINT32 Length,
293 1.1 jruoho UINT8 *Buffer)
294 1.1 jruoho {
295 1.1 jruoho ACPI_STATUS Status;
296 1.1 jruoho UINT64 Value;
297 1.1 jruoho UINT32 RegionOffset = 0;
298 1.1 jruoho UINT32 i;
299 1.1 jruoho
300 1.1 jruoho
301 1.1 jruoho /* Bytewise reads */
302 1.1 jruoho
303 1.1 jruoho for (i = 0; i < Length; i++)
304 1.1 jruoho {
305 1.4 christos Status = AcpiEvAddressSpaceDispatch (ObjDesc, NULL, ACPI_READ,
306 1.8 christos RegionOffset, 8, &Value);
307 1.1 jruoho if (ACPI_FAILURE (Status))
308 1.1 jruoho {
309 1.1 jruoho return (Status);
310 1.1 jruoho }
311 1.1 jruoho
312 1.1 jruoho *Buffer = (UINT8) Value;
313 1.1 jruoho Buffer++;
314 1.1 jruoho RegionOffset++;
315 1.1 jruoho }
316 1.1 jruoho
317 1.1 jruoho return (AE_OK);
318 1.1 jruoho }
319 1.1 jruoho
320 1.1 jruoho
321 1.1 jruoho /*******************************************************************************
322 1.1 jruoho *
323 1.1 jruoho * FUNCTION: AcpiExLoadOp
324 1.1 jruoho *
325 1.1 jruoho * PARAMETERS: ObjDesc - Region or Buffer/Field where the table will be
326 1.1 jruoho * obtained
327 1.19 christos * Target - Where the status of the load will be stored
328 1.1 jruoho * WalkState - Current state
329 1.1 jruoho *
330 1.1 jruoho * RETURN: Status
331 1.1 jruoho *
332 1.1 jruoho * DESCRIPTION: Load an ACPI table from a field or operation region
333 1.1 jruoho *
334 1.1 jruoho * NOTE: Region Fields (Field, BankField, IndexFields) are resolved to buffer
335 1.1 jruoho * objects before this code is reached.
336 1.1 jruoho *
337 1.1 jruoho * If source is an operation region, it must refer to SystemMemory, as
338 1.1 jruoho * per the ACPI specification.
339 1.1 jruoho *
340 1.1 jruoho ******************************************************************************/
341 1.1 jruoho
342 1.1 jruoho ACPI_STATUS
343 1.1 jruoho AcpiExLoadOp (
344 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc,
345 1.1 jruoho ACPI_OPERAND_OBJECT *Target,
346 1.1 jruoho ACPI_WALK_STATE *WalkState)
347 1.1 jruoho {
348 1.1 jruoho ACPI_OPERAND_OBJECT *DdbHandle;
349 1.5 christos ACPI_TABLE_HEADER *TableHeader;
350 1.1 jruoho ACPI_TABLE_HEADER *Table;
351 1.1 jruoho UINT32 TableIndex;
352 1.1 jruoho ACPI_STATUS Status;
353 1.1 jruoho UINT32 Length;
354 1.1 jruoho
355 1.1 jruoho
356 1.1 jruoho ACPI_FUNCTION_TRACE (ExLoadOp);
357 1.1 jruoho
358 1.1 jruoho
359 1.19 christos if (Target->Common.DescriptorType == ACPI_DESC_TYPE_NAMED)
360 1.19 christos {
361 1.19 christos Target = AcpiNsGetAttachedObject (ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Target));
362 1.19 christos }
363 1.19 christos if (Target->Common.Type != ACPI_TYPE_INTEGER)
364 1.19 christos {
365 1.19 christos ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
366 1.19 christos "Type not integer: %X\n", Target->Common.Type));
367 1.19 christos return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
368 1.19 christos }
369 1.19 christos
370 1.19 christos Target->Integer.Value = 0;
371 1.19 christos
372 1.1 jruoho /* Source Object can be either an OpRegion or a Buffer/Field */
373 1.1 jruoho
374 1.1 jruoho switch (ObjDesc->Common.Type)
375 1.1 jruoho {
376 1.1 jruoho case ACPI_TYPE_REGION:
377 1.1 jruoho
378 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
379 1.1 jruoho "Load table from Region %p\n", ObjDesc));
380 1.1 jruoho
381 1.1 jruoho /* Region must be SystemMemory (from ACPI spec) */
382 1.1 jruoho
383 1.1 jruoho if (ObjDesc->Region.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
384 1.1 jruoho {
385 1.1 jruoho return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
386 1.1 jruoho }
387 1.1 jruoho
388 1.1 jruoho /*
389 1.8 christos * If the Region Address and Length have not been previously
390 1.8 christos * evaluated, evaluate them now and save the results.
391 1.1 jruoho */
392 1.1 jruoho if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
393 1.1 jruoho {
394 1.1 jruoho Status = AcpiDsGetRegionArguments (ObjDesc);
395 1.1 jruoho if (ACPI_FAILURE (Status))
396 1.1 jruoho {
397 1.1 jruoho return_ACPI_STATUS (Status);
398 1.1 jruoho }
399 1.1 jruoho }
400 1.1 jruoho
401 1.1 jruoho /* Get the table header first so we can get the table length */
402 1.1 jruoho
403 1.5 christos TableHeader = ACPI_ALLOCATE (sizeof (ACPI_TABLE_HEADER));
404 1.5 christos if (!TableHeader)
405 1.1 jruoho {
406 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
407 1.1 jruoho }
408 1.1 jruoho
409 1.1 jruoho Status = AcpiExRegionRead (ObjDesc, sizeof (ACPI_TABLE_HEADER),
410 1.8 christos ACPI_CAST_PTR (UINT8, TableHeader));
411 1.5 christos Length = TableHeader->Length;
412 1.5 christos ACPI_FREE (TableHeader);
413 1.1 jruoho
414 1.1 jruoho if (ACPI_FAILURE (Status))
415 1.1 jruoho {
416 1.1 jruoho return_ACPI_STATUS (Status);
417 1.1 jruoho }
418 1.1 jruoho
419 1.1 jruoho /* Must have at least an ACPI table header */
420 1.1 jruoho
421 1.1 jruoho if (Length < sizeof (ACPI_TABLE_HEADER))
422 1.1 jruoho {
423 1.1 jruoho return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
424 1.1 jruoho }
425 1.1 jruoho
426 1.1 jruoho /*
427 1.1 jruoho * The original implementation simply mapped the table, with no copy.
428 1.1 jruoho * However, the memory region is not guaranteed to remain stable and
429 1.1 jruoho * we must copy the table to a local buffer. For example, the memory
430 1.1 jruoho * region is corrupted after suspend on some machines. Dynamically
431 1.1 jruoho * loaded tables are usually small, so this overhead is minimal.
432 1.1 jruoho *
433 1.1 jruoho * The latest implementation (5/2009) does not use a mapping at all.
434 1.1 jruoho * We use the low-level operation region interface to read the table
435 1.1 jruoho * instead of the obvious optimization of using a direct mapping.
436 1.1 jruoho * This maintains a consistent use of operation regions across the
437 1.1 jruoho * entire subsystem. This is important if additional processing must
438 1.1 jruoho * be performed in the (possibly user-installed) operation region
439 1.1 jruoho * handler. For example, AcpiExec and ASLTS depend on this.
440 1.1 jruoho */
441 1.1 jruoho
442 1.1 jruoho /* Allocate a buffer for the table */
443 1.1 jruoho
444 1.5 christos Table = ACPI_ALLOCATE (Length);
445 1.5 christos if (!Table)
446 1.1 jruoho {
447 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
448 1.1 jruoho }
449 1.1 jruoho
450 1.1 jruoho /* Read the entire table */
451 1.1 jruoho
452 1.1 jruoho Status = AcpiExRegionRead (ObjDesc, Length,
453 1.8 christos ACPI_CAST_PTR (UINT8, Table));
454 1.1 jruoho if (ACPI_FAILURE (Status))
455 1.1 jruoho {
456 1.5 christos ACPI_FREE (Table);
457 1.1 jruoho return_ACPI_STATUS (Status);
458 1.1 jruoho }
459 1.1 jruoho break;
460 1.1 jruoho
461 1.1 jruoho case ACPI_TYPE_BUFFER: /* Buffer or resolved RegionField */
462 1.1 jruoho
463 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
464 1.1 jruoho "Load table from Buffer or Field %p\n", ObjDesc));
465 1.1 jruoho
466 1.1 jruoho /* Must have at least an ACPI table header */
467 1.1 jruoho
468 1.1 jruoho if (ObjDesc->Buffer.Length < sizeof (ACPI_TABLE_HEADER))
469 1.1 jruoho {
470 1.1 jruoho return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
471 1.1 jruoho }
472 1.1 jruoho
473 1.1 jruoho /* Get the actual table length from the table header */
474 1.1 jruoho
475 1.8 christos TableHeader = ACPI_CAST_PTR (
476 1.8 christos ACPI_TABLE_HEADER, ObjDesc->Buffer.Pointer);
477 1.5 christos Length = TableHeader->Length;
478 1.1 jruoho
479 1.1 jruoho /* Table cannot extend beyond the buffer */
480 1.1 jruoho
481 1.1 jruoho if (Length > ObjDesc->Buffer.Length)
482 1.1 jruoho {
483 1.1 jruoho return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
484 1.1 jruoho }
485 1.1 jruoho if (Length < sizeof (ACPI_TABLE_HEADER))
486 1.1 jruoho {
487 1.1 jruoho return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
488 1.1 jruoho }
489 1.1 jruoho
490 1.1 jruoho /*
491 1.8 christos * Copy the table from the buffer because the buffer could be
492 1.8 christos * modified or even deleted in the future
493 1.1 jruoho */
494 1.5 christos Table = ACPI_ALLOCATE (Length);
495 1.5 christos if (!Table)
496 1.1 jruoho {
497 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
498 1.1 jruoho }
499 1.1 jruoho
500 1.7 christos memcpy (Table, TableHeader, Length);
501 1.1 jruoho break;
502 1.1 jruoho
503 1.4 christos default:
504 1.1 jruoho
505 1.1 jruoho return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
506 1.1 jruoho }
507 1.1 jruoho
508 1.5 christos /* Install the new table into the local data structures */
509 1.5 christos
510 1.9 christos ACPI_INFO (("Dynamic OEM Table Load:"));
511 1.10 christos AcpiExExitInterpreter ();
512 1.11 christos Status = AcpiTbInstallAndLoadTable (ACPI_PTR_TO_PHYSADDR (Table),
513 1.18 christos ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, Table, TRUE, &TableIndex);
514 1.10 christos AcpiExEnterInterpreter ();
515 1.1 jruoho if (ACPI_FAILURE (Status))
516 1.1 jruoho {
517 1.5 christos /* Delete allocated table buffer */
518 1.5 christos
519 1.5 christos ACPI_FREE (Table);
520 1.1 jruoho return_ACPI_STATUS (Status);
521 1.1 jruoho }
522 1.1 jruoho
523 1.5 christos /*
524 1.1 jruoho * Add the table to the namespace.
525 1.1 jruoho *
526 1.1 jruoho * Note: Load the table objects relative to the root of the namespace.
527 1.1 jruoho * This appears to go against the ACPI specification, but we do it for
528 1.1 jruoho * compatibility with other ACPI implementations.
529 1.1 jruoho */
530 1.10 christos Status = AcpiExAddTable (TableIndex, &DdbHandle);
531 1.1 jruoho if (ACPI_FAILURE (Status))
532 1.1 jruoho {
533 1.1 jruoho return_ACPI_STATUS (Status);
534 1.1 jruoho }
535 1.1 jruoho
536 1.15 christos /* Complete the initialization/resolution of new objects */
537 1.13 christos
538 1.15 christos AcpiExExitInterpreter ();
539 1.15 christos AcpiNsInitializeObjects ();
540 1.15 christos AcpiExEnterInterpreter ();
541 1.13 christos
542 1.19 christos /* Remove the reference to DdbHandle created by AcpiExAddTable above */
543 1.1 jruoho
544 1.19 christos AcpiUtRemoveReference (DdbHandle);
545 1.1 jruoho
546 1.19 christos /* Return -1 (non-zero) indicates success */
547 1.1 jruoho
548 1.19 christos Target->Integer.Value = 0xFFFFFFFFFFFFFFFF;
549 1.1 jruoho return_ACPI_STATUS (Status);
550 1.1 jruoho }
551 1.1 jruoho
552 1.1 jruoho
553 1.1 jruoho /*******************************************************************************
554 1.1 jruoho *
555 1.1 jruoho * FUNCTION: AcpiExUnloadTable
556 1.1 jruoho *
557 1.1 jruoho * PARAMETERS: DdbHandle - Handle to a previously loaded table
558 1.1 jruoho *
559 1.1 jruoho * RETURN: Status
560 1.1 jruoho *
561 1.1 jruoho * DESCRIPTION: Unload an ACPI table
562 1.1 jruoho *
563 1.1 jruoho ******************************************************************************/
564 1.1 jruoho
565 1.1 jruoho ACPI_STATUS
566 1.1 jruoho AcpiExUnloadTable (
567 1.1 jruoho ACPI_OPERAND_OBJECT *DdbHandle)
568 1.1 jruoho {
569 1.1 jruoho ACPI_STATUS Status = AE_OK;
570 1.1 jruoho ACPI_OPERAND_OBJECT *TableDesc = DdbHandle;
571 1.1 jruoho UINT32 TableIndex;
572 1.1 jruoho
573 1.1 jruoho
574 1.1 jruoho ACPI_FUNCTION_TRACE (ExUnloadTable);
575 1.1 jruoho
576 1.1 jruoho
577 1.1 jruoho /*
578 1.5 christos * Temporarily emit a warning so that the ASL for the machine can be
579 1.5 christos * hopefully obtained. This is to say that the Unload() operator is
580 1.5 christos * extremely rare if not completely unused.
581 1.5 christos */
582 1.5 christos ACPI_WARNING ((AE_INFO,
583 1.5 christos "Received request to unload an ACPI table"));
584 1.5 christos
585 1.5 christos /*
586 1.13 christos * May 2018: Unload is no longer supported for the following reasons:
587 1.13 christos * 1) A correct implementation on some hosts may not be possible.
588 1.13 christos * 2) Other ACPI implementations do not correctly/fully support it.
589 1.13 christos * 3) It requires host device driver support which does not exist.
590 1.13 christos * (To properly support namespace unload out from underneath.)
591 1.13 christos * 4) This AML operator has never been seen in the field.
592 1.13 christos */
593 1.13 christos ACPI_EXCEPTION ((AE_INFO, AE_NOT_IMPLEMENTED,
594 1.13 christos "AML Unload operator is not supported"));
595 1.13 christos
596 1.13 christos /*
597 1.1 jruoho * Validate the handle
598 1.1 jruoho * Although the handle is partially validated in AcpiExReconfiguration()
599 1.1 jruoho * when it calls AcpiExResolveOperands(), the handle is more completely
600 1.1 jruoho * validated here.
601 1.1 jruoho *
602 1.1 jruoho * Handle must be a valid operand object of type reference. Also, the
603 1.1 jruoho * DdbHandle must still be marked valid (table has not been previously
604 1.1 jruoho * unloaded)
605 1.1 jruoho */
606 1.1 jruoho if ((!DdbHandle) ||
607 1.1 jruoho (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle) != ACPI_DESC_TYPE_OPERAND) ||
608 1.1 jruoho (DdbHandle->Common.Type != ACPI_TYPE_LOCAL_REFERENCE) ||
609 1.1 jruoho (!(DdbHandle->Common.Flags & AOPOBJ_DATA_VALID)))
610 1.1 jruoho {
611 1.4 christos return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
612 1.1 jruoho }
613 1.1 jruoho
614 1.1 jruoho /* Get the table index from the DdbHandle */
615 1.1 jruoho
616 1.1 jruoho TableIndex = TableDesc->Reference.Value;
617 1.1 jruoho
618 1.10 christos /*
619 1.10 christos * Release the interpreter lock so that the table lock won't have
620 1.10 christos * strict order requirement against it.
621 1.10 christos */
622 1.10 christos AcpiExExitInterpreter ();
623 1.11 christos Status = AcpiTbUnloadTable (TableIndex);
624 1.10 christos AcpiExEnterInterpreter ();
625 1.10 christos
626 1.1 jruoho /*
627 1.1 jruoho * Invalidate the handle. We do this because the handle may be stored
628 1.1 jruoho * in a named object and may not be actually deleted until much later.
629 1.1 jruoho */
630 1.10 christos if (ACPI_SUCCESS (Status))
631 1.10 christos {
632 1.10 christos DdbHandle->Common.Flags &= ~AOPOBJ_DATA_VALID;
633 1.10 christos }
634 1.10 christos return_ACPI_STATUS (Status);
635 1.1 jruoho }
636