exconfig.c revision 1.13 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.12 christos * Copyright (C) 2000 - 2018, 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.3 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY 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.1 jruoho ACPI_OPERAND_OBJECT *DdbHandle;
139 1.1 jruoho UINT32 TableIndex;
140 1.1 jruoho
141 1.1 jruoho
142 1.1 jruoho ACPI_FUNCTION_TRACE (ExLoadTableOp);
143 1.1 jruoho
144 1.1 jruoho
145 1.1 jruoho /* Find the ACPI table in the RSDT/XSDT */
146 1.1 jruoho
147 1.10 christos AcpiExExitInterpreter ();
148 1.4 christos Status = AcpiTbFindTable (
149 1.8 christos Operand[0]->String.Pointer,
150 1.8 christos Operand[1]->String.Pointer,
151 1.8 christos Operand[2]->String.Pointer, &TableIndex);
152 1.10 christos AcpiExEnterInterpreter ();
153 1.1 jruoho if (ACPI_FAILURE (Status))
154 1.1 jruoho {
155 1.1 jruoho if (Status != AE_NOT_FOUND)
156 1.1 jruoho {
157 1.1 jruoho return_ACPI_STATUS (Status);
158 1.1 jruoho }
159 1.1 jruoho
160 1.1 jruoho /* Table not found, return an Integer=0 and AE_OK */
161 1.1 jruoho
162 1.1 jruoho DdbHandle = AcpiUtCreateIntegerObject ((UINT64) 0);
163 1.1 jruoho if (!DdbHandle)
164 1.1 jruoho {
165 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
166 1.1 jruoho }
167 1.1 jruoho
168 1.1 jruoho *ReturnDesc = DdbHandle;
169 1.1 jruoho return_ACPI_STATUS (AE_OK);
170 1.1 jruoho }
171 1.1 jruoho
172 1.1 jruoho /* Default nodes */
173 1.1 jruoho
174 1.1 jruoho StartNode = WalkState->ScopeInfo->Scope.Node;
175 1.1 jruoho ParentNode = AcpiGbl_RootNode;
176 1.1 jruoho
177 1.1 jruoho /* RootPath (optional parameter) */
178 1.1 jruoho
179 1.1 jruoho if (Operand[3]->String.Length > 0)
180 1.1 jruoho {
181 1.1 jruoho /*
182 1.4 christos * Find the node referenced by the RootPathString. This is the
183 1.1 jruoho * location within the namespace where the table will be loaded.
184 1.1 jruoho */
185 1.10 christos Status = AcpiNsGetNodeUnlocked (StartNode,
186 1.10 christos Operand[3]->String.Pointer, ACPI_NS_SEARCH_PARENT,
187 1.10 christos &ParentNode);
188 1.1 jruoho if (ACPI_FAILURE (Status))
189 1.1 jruoho {
190 1.1 jruoho return_ACPI_STATUS (Status);
191 1.1 jruoho }
192 1.1 jruoho }
193 1.1 jruoho
194 1.1 jruoho /* ParameterPath (optional parameter) */
195 1.1 jruoho
196 1.1 jruoho if (Operand[4]->String.Length > 0)
197 1.1 jruoho {
198 1.4 christos if ((Operand[4]->String.Pointer[0] != AML_ROOT_PREFIX) &&
199 1.4 christos (Operand[4]->String.Pointer[0] != AML_PARENT_PREFIX))
200 1.1 jruoho {
201 1.1 jruoho /*
202 1.1 jruoho * Path is not absolute, so it will be relative to the node
203 1.1 jruoho * referenced by the RootPathString (or the NS root if omitted)
204 1.1 jruoho */
205 1.1 jruoho StartNode = ParentNode;
206 1.1 jruoho }
207 1.1 jruoho
208 1.1 jruoho /* Find the node referenced by the ParameterPathString */
209 1.1 jruoho
210 1.10 christos Status = AcpiNsGetNodeUnlocked (StartNode,
211 1.10 christos Operand[4]->String.Pointer, ACPI_NS_SEARCH_PARENT,
212 1.10 christos &ParameterNode);
213 1.1 jruoho if (ACPI_FAILURE (Status))
214 1.1 jruoho {
215 1.1 jruoho return_ACPI_STATUS (Status);
216 1.1 jruoho }
217 1.1 jruoho }
218 1.1 jruoho
219 1.1 jruoho /* Load the table into the namespace */
220 1.1 jruoho
221 1.10 christos ACPI_INFO (("Dynamic OEM Table Load:"));
222 1.10 christos AcpiExExitInterpreter ();
223 1.10 christos Status = AcpiTbLoadTable (TableIndex, ParentNode);
224 1.10 christos AcpiExEnterInterpreter ();
225 1.10 christos if (ACPI_FAILURE (Status))
226 1.10 christos {
227 1.11 christos return_ACPI_STATUS (Status);
228 1.10 christos }
229 1.10 christos
230 1.10 christos Status = AcpiExAddTable (TableIndex, &DdbHandle);
231 1.1 jruoho if (ACPI_FAILURE (Status))
232 1.1 jruoho {
233 1.1 jruoho return_ACPI_STATUS (Status);
234 1.1 jruoho }
235 1.1 jruoho
236 1.13 christos /* Complete the initialization/resolution of package objects */
237 1.13 christos
238 1.13 christos Status = AcpiNsWalkNamespace (ACPI_TYPE_PACKAGE, ACPI_ROOT_OBJECT,
239 1.13 christos ACPI_UINT32_MAX, 0, AcpiNsInitOnePackage, NULL, NULL, NULL);
240 1.13 christos
241 1.1 jruoho /* Parameter Data (optional) */
242 1.1 jruoho
243 1.1 jruoho if (ParameterNode)
244 1.1 jruoho {
245 1.1 jruoho /* Store the parameter data into the optional parameter object */
246 1.1 jruoho
247 1.1 jruoho Status = AcpiExStore (Operand[5],
248 1.8 christos ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode), WalkState);
249 1.1 jruoho if (ACPI_FAILURE (Status))
250 1.1 jruoho {
251 1.1 jruoho (void) AcpiExUnloadTable (DdbHandle);
252 1.1 jruoho
253 1.1 jruoho AcpiUtRemoveReference (DdbHandle);
254 1.1 jruoho return_ACPI_STATUS (Status);
255 1.1 jruoho }
256 1.1 jruoho }
257 1.1 jruoho
258 1.1 jruoho *ReturnDesc = DdbHandle;
259 1.4 christos return_ACPI_STATUS (Status);
260 1.1 jruoho }
261 1.1 jruoho
262 1.1 jruoho
263 1.1 jruoho /*******************************************************************************
264 1.1 jruoho *
265 1.1 jruoho * FUNCTION: AcpiExRegionRead
266 1.1 jruoho *
267 1.1 jruoho * PARAMETERS: ObjDesc - Region descriptor
268 1.1 jruoho * Length - Number of bytes to read
269 1.1 jruoho * Buffer - Pointer to where to put the data
270 1.1 jruoho *
271 1.1 jruoho * RETURN: Status
272 1.1 jruoho *
273 1.1 jruoho * DESCRIPTION: Read data from an operation region. The read starts from the
274 1.1 jruoho * beginning of the region.
275 1.1 jruoho *
276 1.1 jruoho ******************************************************************************/
277 1.1 jruoho
278 1.1 jruoho static ACPI_STATUS
279 1.1 jruoho AcpiExRegionRead (
280 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc,
281 1.1 jruoho UINT32 Length,
282 1.1 jruoho UINT8 *Buffer)
283 1.1 jruoho {
284 1.1 jruoho ACPI_STATUS Status;
285 1.1 jruoho UINT64 Value;
286 1.1 jruoho UINT32 RegionOffset = 0;
287 1.1 jruoho UINT32 i;
288 1.1 jruoho
289 1.1 jruoho
290 1.1 jruoho /* Bytewise reads */
291 1.1 jruoho
292 1.1 jruoho for (i = 0; i < Length; i++)
293 1.1 jruoho {
294 1.4 christos Status = AcpiEvAddressSpaceDispatch (ObjDesc, NULL, ACPI_READ,
295 1.8 christos RegionOffset, 8, &Value);
296 1.1 jruoho if (ACPI_FAILURE (Status))
297 1.1 jruoho {
298 1.1 jruoho return (Status);
299 1.1 jruoho }
300 1.1 jruoho
301 1.1 jruoho *Buffer = (UINT8) Value;
302 1.1 jruoho Buffer++;
303 1.1 jruoho RegionOffset++;
304 1.1 jruoho }
305 1.1 jruoho
306 1.1 jruoho return (AE_OK);
307 1.1 jruoho }
308 1.1 jruoho
309 1.1 jruoho
310 1.1 jruoho /*******************************************************************************
311 1.1 jruoho *
312 1.1 jruoho * FUNCTION: AcpiExLoadOp
313 1.1 jruoho *
314 1.1 jruoho * PARAMETERS: ObjDesc - Region or Buffer/Field where the table will be
315 1.1 jruoho * obtained
316 1.1 jruoho * Target - Where a handle to the table will be stored
317 1.1 jruoho * WalkState - Current state
318 1.1 jruoho *
319 1.1 jruoho * RETURN: Status
320 1.1 jruoho *
321 1.1 jruoho * DESCRIPTION: Load an ACPI table from a field or operation region
322 1.1 jruoho *
323 1.1 jruoho * NOTE: Region Fields (Field, BankField, IndexFields) are resolved to buffer
324 1.1 jruoho * objects before this code is reached.
325 1.1 jruoho *
326 1.1 jruoho * If source is an operation region, it must refer to SystemMemory, as
327 1.1 jruoho * per the ACPI specification.
328 1.1 jruoho *
329 1.1 jruoho ******************************************************************************/
330 1.1 jruoho
331 1.1 jruoho ACPI_STATUS
332 1.1 jruoho AcpiExLoadOp (
333 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc,
334 1.1 jruoho ACPI_OPERAND_OBJECT *Target,
335 1.1 jruoho ACPI_WALK_STATE *WalkState)
336 1.1 jruoho {
337 1.1 jruoho ACPI_OPERAND_OBJECT *DdbHandle;
338 1.5 christos ACPI_TABLE_HEADER *TableHeader;
339 1.1 jruoho ACPI_TABLE_HEADER *Table;
340 1.1 jruoho UINT32 TableIndex;
341 1.1 jruoho ACPI_STATUS Status;
342 1.1 jruoho UINT32 Length;
343 1.1 jruoho
344 1.1 jruoho
345 1.1 jruoho ACPI_FUNCTION_TRACE (ExLoadOp);
346 1.1 jruoho
347 1.1 jruoho
348 1.1 jruoho /* Source Object can be either an OpRegion or a Buffer/Field */
349 1.1 jruoho
350 1.1 jruoho switch (ObjDesc->Common.Type)
351 1.1 jruoho {
352 1.1 jruoho case ACPI_TYPE_REGION:
353 1.1 jruoho
354 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
355 1.1 jruoho "Load table from Region %p\n", ObjDesc));
356 1.1 jruoho
357 1.1 jruoho /* Region must be SystemMemory (from ACPI spec) */
358 1.1 jruoho
359 1.1 jruoho if (ObjDesc->Region.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
360 1.1 jruoho {
361 1.1 jruoho return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
362 1.1 jruoho }
363 1.1 jruoho
364 1.1 jruoho /*
365 1.8 christos * If the Region Address and Length have not been previously
366 1.8 christos * evaluated, evaluate them now and save the results.
367 1.1 jruoho */
368 1.1 jruoho if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
369 1.1 jruoho {
370 1.1 jruoho Status = AcpiDsGetRegionArguments (ObjDesc);
371 1.1 jruoho if (ACPI_FAILURE (Status))
372 1.1 jruoho {
373 1.1 jruoho return_ACPI_STATUS (Status);
374 1.1 jruoho }
375 1.1 jruoho }
376 1.1 jruoho
377 1.1 jruoho /* Get the table header first so we can get the table length */
378 1.1 jruoho
379 1.5 christos TableHeader = ACPI_ALLOCATE (sizeof (ACPI_TABLE_HEADER));
380 1.5 christos if (!TableHeader)
381 1.1 jruoho {
382 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
383 1.1 jruoho }
384 1.1 jruoho
385 1.1 jruoho Status = AcpiExRegionRead (ObjDesc, sizeof (ACPI_TABLE_HEADER),
386 1.8 christos ACPI_CAST_PTR (UINT8, TableHeader));
387 1.5 christos Length = TableHeader->Length;
388 1.5 christos ACPI_FREE (TableHeader);
389 1.1 jruoho
390 1.1 jruoho if (ACPI_FAILURE (Status))
391 1.1 jruoho {
392 1.1 jruoho return_ACPI_STATUS (Status);
393 1.1 jruoho }
394 1.1 jruoho
395 1.1 jruoho /* Must have at least an ACPI table header */
396 1.1 jruoho
397 1.1 jruoho if (Length < sizeof (ACPI_TABLE_HEADER))
398 1.1 jruoho {
399 1.1 jruoho return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
400 1.1 jruoho }
401 1.1 jruoho
402 1.1 jruoho /*
403 1.1 jruoho * The original implementation simply mapped the table, with no copy.
404 1.1 jruoho * However, the memory region is not guaranteed to remain stable and
405 1.1 jruoho * we must copy the table to a local buffer. For example, the memory
406 1.1 jruoho * region is corrupted after suspend on some machines. Dynamically
407 1.1 jruoho * loaded tables are usually small, so this overhead is minimal.
408 1.1 jruoho *
409 1.1 jruoho * The latest implementation (5/2009) does not use a mapping at all.
410 1.1 jruoho * We use the low-level operation region interface to read the table
411 1.1 jruoho * instead of the obvious optimization of using a direct mapping.
412 1.1 jruoho * This maintains a consistent use of operation regions across the
413 1.1 jruoho * entire subsystem. This is important if additional processing must
414 1.1 jruoho * be performed in the (possibly user-installed) operation region
415 1.1 jruoho * handler. For example, AcpiExec and ASLTS depend on this.
416 1.1 jruoho */
417 1.1 jruoho
418 1.1 jruoho /* Allocate a buffer for the table */
419 1.1 jruoho
420 1.5 christos Table = ACPI_ALLOCATE (Length);
421 1.5 christos if (!Table)
422 1.1 jruoho {
423 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
424 1.1 jruoho }
425 1.1 jruoho
426 1.1 jruoho /* Read the entire table */
427 1.1 jruoho
428 1.1 jruoho Status = AcpiExRegionRead (ObjDesc, Length,
429 1.8 christos ACPI_CAST_PTR (UINT8, Table));
430 1.1 jruoho if (ACPI_FAILURE (Status))
431 1.1 jruoho {
432 1.5 christos ACPI_FREE (Table);
433 1.1 jruoho return_ACPI_STATUS (Status);
434 1.1 jruoho }
435 1.1 jruoho break;
436 1.1 jruoho
437 1.1 jruoho case ACPI_TYPE_BUFFER: /* Buffer or resolved RegionField */
438 1.1 jruoho
439 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
440 1.1 jruoho "Load table from Buffer or Field %p\n", ObjDesc));
441 1.1 jruoho
442 1.1 jruoho /* Must have at least an ACPI table header */
443 1.1 jruoho
444 1.1 jruoho if (ObjDesc->Buffer.Length < sizeof (ACPI_TABLE_HEADER))
445 1.1 jruoho {
446 1.1 jruoho return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
447 1.1 jruoho }
448 1.1 jruoho
449 1.1 jruoho /* Get the actual table length from the table header */
450 1.1 jruoho
451 1.8 christos TableHeader = ACPI_CAST_PTR (
452 1.8 christos ACPI_TABLE_HEADER, ObjDesc->Buffer.Pointer);
453 1.5 christos Length = TableHeader->Length;
454 1.1 jruoho
455 1.1 jruoho /* Table cannot extend beyond the buffer */
456 1.1 jruoho
457 1.1 jruoho if (Length > ObjDesc->Buffer.Length)
458 1.1 jruoho {
459 1.1 jruoho return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
460 1.1 jruoho }
461 1.1 jruoho if (Length < sizeof (ACPI_TABLE_HEADER))
462 1.1 jruoho {
463 1.1 jruoho return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
464 1.1 jruoho }
465 1.1 jruoho
466 1.1 jruoho /*
467 1.8 christos * Copy the table from the buffer because the buffer could be
468 1.8 christos * modified or even deleted in the future
469 1.1 jruoho */
470 1.5 christos Table = ACPI_ALLOCATE (Length);
471 1.5 christos if (!Table)
472 1.1 jruoho {
473 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
474 1.1 jruoho }
475 1.1 jruoho
476 1.7 christos memcpy (Table, TableHeader, Length);
477 1.1 jruoho break;
478 1.1 jruoho
479 1.4 christos default:
480 1.1 jruoho
481 1.1 jruoho return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
482 1.1 jruoho }
483 1.1 jruoho
484 1.5 christos /* Install the new table into the local data structures */
485 1.5 christos
486 1.9 christos ACPI_INFO (("Dynamic OEM Table Load:"));
487 1.10 christos AcpiExExitInterpreter ();
488 1.11 christos Status = AcpiTbInstallAndLoadTable (ACPI_PTR_TO_PHYSADDR (Table),
489 1.10 christos ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, TRUE, &TableIndex);
490 1.10 christos AcpiExEnterInterpreter ();
491 1.1 jruoho if (ACPI_FAILURE (Status))
492 1.1 jruoho {
493 1.5 christos /* Delete allocated table buffer */
494 1.5 christos
495 1.5 christos ACPI_FREE (Table);
496 1.1 jruoho return_ACPI_STATUS (Status);
497 1.1 jruoho }
498 1.1 jruoho
499 1.5 christos /*
500 1.1 jruoho * Add the table to the namespace.
501 1.1 jruoho *
502 1.1 jruoho * Note: Load the table objects relative to the root of the namespace.
503 1.1 jruoho * This appears to go against the ACPI specification, but we do it for
504 1.1 jruoho * compatibility with other ACPI implementations.
505 1.1 jruoho */
506 1.10 christos Status = AcpiExAddTable (TableIndex, &DdbHandle);
507 1.1 jruoho if (ACPI_FAILURE (Status))
508 1.1 jruoho {
509 1.1 jruoho /* On error, TablePtr was deallocated above */
510 1.1 jruoho
511 1.1 jruoho return_ACPI_STATUS (Status);
512 1.1 jruoho }
513 1.1 jruoho
514 1.13 christos /* Complete the initialization/resolution of package objects */
515 1.13 christos
516 1.13 christos Status = AcpiNsWalkNamespace (ACPI_TYPE_PACKAGE, ACPI_ROOT_OBJECT,
517 1.13 christos ACPI_UINT32_MAX, 0, AcpiNsInitOnePackage, NULL, NULL, NULL);
518 1.13 christos
519 1.1 jruoho /* Store the DdbHandle into the Target operand */
520 1.1 jruoho
521 1.1 jruoho Status = AcpiExStore (DdbHandle, Target, WalkState);
522 1.1 jruoho if (ACPI_FAILURE (Status))
523 1.1 jruoho {
524 1.1 jruoho (void) AcpiExUnloadTable (DdbHandle);
525 1.1 jruoho
526 1.1 jruoho /* TablePtr was deallocated above */
527 1.1 jruoho
528 1.1 jruoho AcpiUtRemoveReference (DdbHandle);
529 1.1 jruoho return_ACPI_STATUS (Status);
530 1.1 jruoho }
531 1.1 jruoho
532 1.1 jruoho /* Remove the reference by added by AcpiExStore above */
533 1.1 jruoho
534 1.1 jruoho AcpiUtRemoveReference (DdbHandle);
535 1.1 jruoho return_ACPI_STATUS (Status);
536 1.1 jruoho }
537 1.1 jruoho
538 1.1 jruoho
539 1.1 jruoho /*******************************************************************************
540 1.1 jruoho *
541 1.1 jruoho * FUNCTION: AcpiExUnloadTable
542 1.1 jruoho *
543 1.1 jruoho * PARAMETERS: DdbHandle - Handle to a previously loaded table
544 1.1 jruoho *
545 1.1 jruoho * RETURN: Status
546 1.1 jruoho *
547 1.1 jruoho * DESCRIPTION: Unload an ACPI table
548 1.1 jruoho *
549 1.1 jruoho ******************************************************************************/
550 1.1 jruoho
551 1.1 jruoho ACPI_STATUS
552 1.1 jruoho AcpiExUnloadTable (
553 1.1 jruoho ACPI_OPERAND_OBJECT *DdbHandle)
554 1.1 jruoho {
555 1.1 jruoho ACPI_STATUS Status = AE_OK;
556 1.1 jruoho ACPI_OPERAND_OBJECT *TableDesc = DdbHandle;
557 1.1 jruoho UINT32 TableIndex;
558 1.1 jruoho
559 1.1 jruoho
560 1.1 jruoho ACPI_FUNCTION_TRACE (ExUnloadTable);
561 1.1 jruoho
562 1.1 jruoho
563 1.1 jruoho /*
564 1.5 christos * Temporarily emit a warning so that the ASL for the machine can be
565 1.5 christos * hopefully obtained. This is to say that the Unload() operator is
566 1.5 christos * extremely rare if not completely unused.
567 1.5 christos */
568 1.5 christos ACPI_WARNING ((AE_INFO,
569 1.5 christos "Received request to unload an ACPI table"));
570 1.5 christos
571 1.5 christos /*
572 1.13 christos * May 2018: Unload is no longer supported for the following reasons:
573 1.13 christos * 1) A correct implementation on some hosts may not be possible.
574 1.13 christos * 2) Other ACPI implementations do not correctly/fully support it.
575 1.13 christos * 3) It requires host device driver support which does not exist.
576 1.13 christos * (To properly support namespace unload out from underneath.)
577 1.13 christos * 4) This AML operator has never been seen in the field.
578 1.13 christos */
579 1.13 christos ACPI_EXCEPTION ((AE_INFO, AE_NOT_IMPLEMENTED,
580 1.13 christos "AML Unload operator is not supported"));
581 1.13 christos
582 1.13 christos /*
583 1.1 jruoho * Validate the handle
584 1.1 jruoho * Although the handle is partially validated in AcpiExReconfiguration()
585 1.1 jruoho * when it calls AcpiExResolveOperands(), the handle is more completely
586 1.1 jruoho * validated here.
587 1.1 jruoho *
588 1.1 jruoho * Handle must be a valid operand object of type reference. Also, the
589 1.1 jruoho * DdbHandle must still be marked valid (table has not been previously
590 1.1 jruoho * unloaded)
591 1.1 jruoho */
592 1.1 jruoho if ((!DdbHandle) ||
593 1.1 jruoho (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle) != ACPI_DESC_TYPE_OPERAND) ||
594 1.1 jruoho (DdbHandle->Common.Type != ACPI_TYPE_LOCAL_REFERENCE) ||
595 1.1 jruoho (!(DdbHandle->Common.Flags & AOPOBJ_DATA_VALID)))
596 1.1 jruoho {
597 1.4 christos return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
598 1.1 jruoho }
599 1.1 jruoho
600 1.1 jruoho /* Get the table index from the DdbHandle */
601 1.1 jruoho
602 1.1 jruoho TableIndex = TableDesc->Reference.Value;
603 1.1 jruoho
604 1.10 christos /*
605 1.10 christos * Release the interpreter lock so that the table lock won't have
606 1.10 christos * strict order requirement against it.
607 1.10 christos */
608 1.10 christos AcpiExExitInterpreter ();
609 1.11 christos Status = AcpiTbUnloadTable (TableIndex);
610 1.10 christos AcpiExEnterInterpreter ();
611 1.10 christos
612 1.1 jruoho /*
613 1.1 jruoho * Invalidate the handle. We do this because the handle may be stored
614 1.1 jruoho * in a named object and may not be actually deleted until much later.
615 1.1 jruoho */
616 1.10 christos if (ACPI_SUCCESS (Status))
617 1.10 christos {
618 1.10 christos DdbHandle->Common.Flags &= ~AOPOBJ_DATA_VALID;
619 1.10 christos }
620 1.10 christos return_ACPI_STATUS (Status);
621 1.1 jruoho }
622