exconfig.c revision 1.11 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.11 christos * Copyright (C) 2000 - 2017, 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.1 jruoho /* Parameter Data (optional) */
237 1.1 jruoho
238 1.1 jruoho if (ParameterNode)
239 1.1 jruoho {
240 1.1 jruoho /* Store the parameter data into the optional parameter object */
241 1.1 jruoho
242 1.1 jruoho Status = AcpiExStore (Operand[5],
243 1.8 christos ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode), WalkState);
244 1.1 jruoho if (ACPI_FAILURE (Status))
245 1.1 jruoho {
246 1.1 jruoho (void) AcpiExUnloadTable (DdbHandle);
247 1.1 jruoho
248 1.1 jruoho AcpiUtRemoveReference (DdbHandle);
249 1.1 jruoho return_ACPI_STATUS (Status);
250 1.1 jruoho }
251 1.1 jruoho }
252 1.1 jruoho
253 1.1 jruoho *ReturnDesc = DdbHandle;
254 1.4 christos return_ACPI_STATUS (Status);
255 1.1 jruoho }
256 1.1 jruoho
257 1.1 jruoho
258 1.1 jruoho /*******************************************************************************
259 1.1 jruoho *
260 1.1 jruoho * FUNCTION: AcpiExRegionRead
261 1.1 jruoho *
262 1.1 jruoho * PARAMETERS: ObjDesc - Region descriptor
263 1.1 jruoho * Length - Number of bytes to read
264 1.1 jruoho * Buffer - Pointer to where to put the data
265 1.1 jruoho *
266 1.1 jruoho * RETURN: Status
267 1.1 jruoho *
268 1.1 jruoho * DESCRIPTION: Read data from an operation region. The read starts from the
269 1.1 jruoho * beginning of the region.
270 1.1 jruoho *
271 1.1 jruoho ******************************************************************************/
272 1.1 jruoho
273 1.1 jruoho static ACPI_STATUS
274 1.1 jruoho AcpiExRegionRead (
275 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc,
276 1.1 jruoho UINT32 Length,
277 1.1 jruoho UINT8 *Buffer)
278 1.1 jruoho {
279 1.1 jruoho ACPI_STATUS Status;
280 1.1 jruoho UINT64 Value;
281 1.1 jruoho UINT32 RegionOffset = 0;
282 1.1 jruoho UINT32 i;
283 1.1 jruoho
284 1.1 jruoho
285 1.1 jruoho /* Bytewise reads */
286 1.1 jruoho
287 1.1 jruoho for (i = 0; i < Length; i++)
288 1.1 jruoho {
289 1.4 christos Status = AcpiEvAddressSpaceDispatch (ObjDesc, NULL, ACPI_READ,
290 1.8 christos RegionOffset, 8, &Value);
291 1.1 jruoho if (ACPI_FAILURE (Status))
292 1.1 jruoho {
293 1.1 jruoho return (Status);
294 1.1 jruoho }
295 1.1 jruoho
296 1.1 jruoho *Buffer = (UINT8) Value;
297 1.1 jruoho Buffer++;
298 1.1 jruoho RegionOffset++;
299 1.1 jruoho }
300 1.1 jruoho
301 1.1 jruoho return (AE_OK);
302 1.1 jruoho }
303 1.1 jruoho
304 1.1 jruoho
305 1.1 jruoho /*******************************************************************************
306 1.1 jruoho *
307 1.1 jruoho * FUNCTION: AcpiExLoadOp
308 1.1 jruoho *
309 1.1 jruoho * PARAMETERS: ObjDesc - Region or Buffer/Field where the table will be
310 1.1 jruoho * obtained
311 1.1 jruoho * Target - Where a handle to the table will be stored
312 1.1 jruoho * WalkState - Current state
313 1.1 jruoho *
314 1.1 jruoho * RETURN: Status
315 1.1 jruoho *
316 1.1 jruoho * DESCRIPTION: Load an ACPI table from a field or operation region
317 1.1 jruoho *
318 1.1 jruoho * NOTE: Region Fields (Field, BankField, IndexFields) are resolved to buffer
319 1.1 jruoho * objects before this code is reached.
320 1.1 jruoho *
321 1.1 jruoho * If source is an operation region, it must refer to SystemMemory, as
322 1.1 jruoho * per the ACPI specification.
323 1.1 jruoho *
324 1.1 jruoho ******************************************************************************/
325 1.1 jruoho
326 1.1 jruoho ACPI_STATUS
327 1.1 jruoho AcpiExLoadOp (
328 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc,
329 1.1 jruoho ACPI_OPERAND_OBJECT *Target,
330 1.1 jruoho ACPI_WALK_STATE *WalkState)
331 1.1 jruoho {
332 1.1 jruoho ACPI_OPERAND_OBJECT *DdbHandle;
333 1.5 christos ACPI_TABLE_HEADER *TableHeader;
334 1.1 jruoho ACPI_TABLE_HEADER *Table;
335 1.1 jruoho UINT32 TableIndex;
336 1.1 jruoho ACPI_STATUS Status;
337 1.1 jruoho UINT32 Length;
338 1.1 jruoho
339 1.1 jruoho
340 1.1 jruoho ACPI_FUNCTION_TRACE (ExLoadOp);
341 1.1 jruoho
342 1.1 jruoho
343 1.1 jruoho /* Source Object can be either an OpRegion or a Buffer/Field */
344 1.1 jruoho
345 1.1 jruoho switch (ObjDesc->Common.Type)
346 1.1 jruoho {
347 1.1 jruoho case ACPI_TYPE_REGION:
348 1.1 jruoho
349 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
350 1.1 jruoho "Load table from Region %p\n", ObjDesc));
351 1.1 jruoho
352 1.1 jruoho /* Region must be SystemMemory (from ACPI spec) */
353 1.1 jruoho
354 1.1 jruoho if (ObjDesc->Region.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
355 1.1 jruoho {
356 1.1 jruoho return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
357 1.1 jruoho }
358 1.1 jruoho
359 1.1 jruoho /*
360 1.8 christos * If the Region Address and Length have not been previously
361 1.8 christos * evaluated, evaluate them now and save the results.
362 1.1 jruoho */
363 1.1 jruoho if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
364 1.1 jruoho {
365 1.1 jruoho Status = AcpiDsGetRegionArguments (ObjDesc);
366 1.1 jruoho if (ACPI_FAILURE (Status))
367 1.1 jruoho {
368 1.1 jruoho return_ACPI_STATUS (Status);
369 1.1 jruoho }
370 1.1 jruoho }
371 1.1 jruoho
372 1.1 jruoho /* Get the table header first so we can get the table length */
373 1.1 jruoho
374 1.5 christos TableHeader = ACPI_ALLOCATE (sizeof (ACPI_TABLE_HEADER));
375 1.5 christos if (!TableHeader)
376 1.1 jruoho {
377 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
378 1.1 jruoho }
379 1.1 jruoho
380 1.1 jruoho Status = AcpiExRegionRead (ObjDesc, sizeof (ACPI_TABLE_HEADER),
381 1.8 christos ACPI_CAST_PTR (UINT8, TableHeader));
382 1.5 christos Length = TableHeader->Length;
383 1.5 christos ACPI_FREE (TableHeader);
384 1.1 jruoho
385 1.1 jruoho if (ACPI_FAILURE (Status))
386 1.1 jruoho {
387 1.1 jruoho return_ACPI_STATUS (Status);
388 1.1 jruoho }
389 1.1 jruoho
390 1.1 jruoho /* Must have at least an ACPI table header */
391 1.1 jruoho
392 1.1 jruoho if (Length < sizeof (ACPI_TABLE_HEADER))
393 1.1 jruoho {
394 1.1 jruoho return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
395 1.1 jruoho }
396 1.1 jruoho
397 1.1 jruoho /*
398 1.1 jruoho * The original implementation simply mapped the table, with no copy.
399 1.1 jruoho * However, the memory region is not guaranteed to remain stable and
400 1.1 jruoho * we must copy the table to a local buffer. For example, the memory
401 1.1 jruoho * region is corrupted after suspend on some machines. Dynamically
402 1.1 jruoho * loaded tables are usually small, so this overhead is minimal.
403 1.1 jruoho *
404 1.1 jruoho * The latest implementation (5/2009) does not use a mapping at all.
405 1.1 jruoho * We use the low-level operation region interface to read the table
406 1.1 jruoho * instead of the obvious optimization of using a direct mapping.
407 1.1 jruoho * This maintains a consistent use of operation regions across the
408 1.1 jruoho * entire subsystem. This is important if additional processing must
409 1.1 jruoho * be performed in the (possibly user-installed) operation region
410 1.1 jruoho * handler. For example, AcpiExec and ASLTS depend on this.
411 1.1 jruoho */
412 1.1 jruoho
413 1.1 jruoho /* Allocate a buffer for the table */
414 1.1 jruoho
415 1.5 christos Table = ACPI_ALLOCATE (Length);
416 1.5 christos if (!Table)
417 1.1 jruoho {
418 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
419 1.1 jruoho }
420 1.1 jruoho
421 1.1 jruoho /* Read the entire table */
422 1.1 jruoho
423 1.1 jruoho Status = AcpiExRegionRead (ObjDesc, Length,
424 1.8 christos ACPI_CAST_PTR (UINT8, Table));
425 1.1 jruoho if (ACPI_FAILURE (Status))
426 1.1 jruoho {
427 1.5 christos ACPI_FREE (Table);
428 1.1 jruoho return_ACPI_STATUS (Status);
429 1.1 jruoho }
430 1.1 jruoho break;
431 1.1 jruoho
432 1.1 jruoho case ACPI_TYPE_BUFFER: /* Buffer or resolved RegionField */
433 1.1 jruoho
434 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
435 1.1 jruoho "Load table from Buffer or Field %p\n", ObjDesc));
436 1.1 jruoho
437 1.1 jruoho /* Must have at least an ACPI table header */
438 1.1 jruoho
439 1.1 jruoho if (ObjDesc->Buffer.Length < sizeof (ACPI_TABLE_HEADER))
440 1.1 jruoho {
441 1.1 jruoho return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
442 1.1 jruoho }
443 1.1 jruoho
444 1.1 jruoho /* Get the actual table length from the table header */
445 1.1 jruoho
446 1.8 christos TableHeader = ACPI_CAST_PTR (
447 1.8 christos ACPI_TABLE_HEADER, ObjDesc->Buffer.Pointer);
448 1.5 christos Length = TableHeader->Length;
449 1.1 jruoho
450 1.1 jruoho /* Table cannot extend beyond the buffer */
451 1.1 jruoho
452 1.1 jruoho if (Length > ObjDesc->Buffer.Length)
453 1.1 jruoho {
454 1.1 jruoho return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
455 1.1 jruoho }
456 1.1 jruoho if (Length < sizeof (ACPI_TABLE_HEADER))
457 1.1 jruoho {
458 1.1 jruoho return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
459 1.1 jruoho }
460 1.1 jruoho
461 1.1 jruoho /*
462 1.8 christos * Copy the table from the buffer because the buffer could be
463 1.8 christos * modified or even deleted in the future
464 1.1 jruoho */
465 1.5 christos Table = ACPI_ALLOCATE (Length);
466 1.5 christos if (!Table)
467 1.1 jruoho {
468 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
469 1.1 jruoho }
470 1.1 jruoho
471 1.7 christos memcpy (Table, TableHeader, Length);
472 1.1 jruoho break;
473 1.1 jruoho
474 1.4 christos default:
475 1.1 jruoho
476 1.1 jruoho return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
477 1.1 jruoho }
478 1.1 jruoho
479 1.5 christos /* Install the new table into the local data structures */
480 1.5 christos
481 1.9 christos ACPI_INFO (("Dynamic OEM Table Load:"));
482 1.10 christos AcpiExExitInterpreter ();
483 1.11 christos Status = AcpiTbInstallAndLoadTable (ACPI_PTR_TO_PHYSADDR (Table),
484 1.10 christos ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, TRUE, &TableIndex);
485 1.10 christos AcpiExEnterInterpreter ();
486 1.1 jruoho if (ACPI_FAILURE (Status))
487 1.1 jruoho {
488 1.5 christos /* Delete allocated table buffer */
489 1.5 christos
490 1.5 christos ACPI_FREE (Table);
491 1.1 jruoho return_ACPI_STATUS (Status);
492 1.1 jruoho }
493 1.1 jruoho
494 1.5 christos /*
495 1.1 jruoho * Add the table to the namespace.
496 1.1 jruoho *
497 1.1 jruoho * Note: Load the table objects relative to the root of the namespace.
498 1.1 jruoho * This appears to go against the ACPI specification, but we do it for
499 1.1 jruoho * compatibility with other ACPI implementations.
500 1.1 jruoho */
501 1.10 christos Status = AcpiExAddTable (TableIndex, &DdbHandle);
502 1.1 jruoho if (ACPI_FAILURE (Status))
503 1.1 jruoho {
504 1.1 jruoho /* On error, TablePtr was deallocated above */
505 1.1 jruoho
506 1.1 jruoho return_ACPI_STATUS (Status);
507 1.1 jruoho }
508 1.1 jruoho
509 1.1 jruoho /* Store the DdbHandle into the Target operand */
510 1.1 jruoho
511 1.1 jruoho Status = AcpiExStore (DdbHandle, Target, WalkState);
512 1.1 jruoho if (ACPI_FAILURE (Status))
513 1.1 jruoho {
514 1.1 jruoho (void) AcpiExUnloadTable (DdbHandle);
515 1.1 jruoho
516 1.1 jruoho /* TablePtr was deallocated above */
517 1.1 jruoho
518 1.1 jruoho AcpiUtRemoveReference (DdbHandle);
519 1.1 jruoho return_ACPI_STATUS (Status);
520 1.1 jruoho }
521 1.1 jruoho
522 1.1 jruoho /* Remove the reference by added by AcpiExStore above */
523 1.1 jruoho
524 1.1 jruoho AcpiUtRemoveReference (DdbHandle);
525 1.1 jruoho return_ACPI_STATUS (Status);
526 1.1 jruoho }
527 1.1 jruoho
528 1.1 jruoho
529 1.1 jruoho /*******************************************************************************
530 1.1 jruoho *
531 1.1 jruoho * FUNCTION: AcpiExUnloadTable
532 1.1 jruoho *
533 1.1 jruoho * PARAMETERS: DdbHandle - Handle to a previously loaded table
534 1.1 jruoho *
535 1.1 jruoho * RETURN: Status
536 1.1 jruoho *
537 1.1 jruoho * DESCRIPTION: Unload an ACPI table
538 1.1 jruoho *
539 1.1 jruoho ******************************************************************************/
540 1.1 jruoho
541 1.1 jruoho ACPI_STATUS
542 1.1 jruoho AcpiExUnloadTable (
543 1.1 jruoho ACPI_OPERAND_OBJECT *DdbHandle)
544 1.1 jruoho {
545 1.1 jruoho ACPI_STATUS Status = AE_OK;
546 1.1 jruoho ACPI_OPERAND_OBJECT *TableDesc = DdbHandle;
547 1.1 jruoho UINT32 TableIndex;
548 1.1 jruoho
549 1.1 jruoho
550 1.1 jruoho ACPI_FUNCTION_TRACE (ExUnloadTable);
551 1.1 jruoho
552 1.1 jruoho
553 1.1 jruoho /*
554 1.5 christos * Temporarily emit a warning so that the ASL for the machine can be
555 1.5 christos * hopefully obtained. This is to say that the Unload() operator is
556 1.5 christos * extremely rare if not completely unused.
557 1.5 christos */
558 1.5 christos ACPI_WARNING ((AE_INFO,
559 1.5 christos "Received request to unload an ACPI table"));
560 1.5 christos
561 1.5 christos /*
562 1.1 jruoho * Validate the handle
563 1.1 jruoho * Although the handle is partially validated in AcpiExReconfiguration()
564 1.1 jruoho * when it calls AcpiExResolveOperands(), the handle is more completely
565 1.1 jruoho * validated here.
566 1.1 jruoho *
567 1.1 jruoho * Handle must be a valid operand object of type reference. Also, the
568 1.1 jruoho * DdbHandle must still be marked valid (table has not been previously
569 1.1 jruoho * unloaded)
570 1.1 jruoho */
571 1.1 jruoho if ((!DdbHandle) ||
572 1.1 jruoho (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle) != ACPI_DESC_TYPE_OPERAND) ||
573 1.1 jruoho (DdbHandle->Common.Type != ACPI_TYPE_LOCAL_REFERENCE) ||
574 1.1 jruoho (!(DdbHandle->Common.Flags & AOPOBJ_DATA_VALID)))
575 1.1 jruoho {
576 1.4 christos return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
577 1.1 jruoho }
578 1.1 jruoho
579 1.1 jruoho /* Get the table index from the DdbHandle */
580 1.1 jruoho
581 1.1 jruoho TableIndex = TableDesc->Reference.Value;
582 1.1 jruoho
583 1.10 christos /*
584 1.10 christos * Release the interpreter lock so that the table lock won't have
585 1.10 christos * strict order requirement against it.
586 1.10 christos */
587 1.10 christos AcpiExExitInterpreter ();
588 1.11 christos Status = AcpiTbUnloadTable (TableIndex);
589 1.10 christos AcpiExEnterInterpreter ();
590 1.10 christos
591 1.1 jruoho /*
592 1.1 jruoho * Invalidate the handle. We do this because the handle may be stored
593 1.1 jruoho * in a named object and may not be actually deleted until much later.
594 1.1 jruoho */
595 1.10 christos if (ACPI_SUCCESS (Status))
596 1.10 christos {
597 1.10 christos DdbHandle->Common.Flags &= ~AOPOBJ_DATA_VALID;
598 1.10 christos }
599 1.10 christos return_ACPI_STATUS (Status);
600 1.1 jruoho }
601