exconfig.c revision 1.9 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.8 christos * Copyright (C) 2000 - 2016, 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_NAMESPACE_NODE *ParentNode,
63 1.1 jruoho ACPI_OPERAND_OBJECT **DdbHandle);
64 1.1 jruoho
65 1.1 jruoho static ACPI_STATUS
66 1.1 jruoho AcpiExRegionRead (
67 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc,
68 1.1 jruoho UINT32 Length,
69 1.1 jruoho UINT8 *Buffer);
70 1.1 jruoho
71 1.1 jruoho
72 1.1 jruoho /*******************************************************************************
73 1.1 jruoho *
74 1.1 jruoho * FUNCTION: AcpiExAddTable
75 1.1 jruoho *
76 1.1 jruoho * PARAMETERS: Table - Pointer to raw table
77 1.1 jruoho * ParentNode - Where to load the table (scope)
78 1.1 jruoho * DdbHandle - Where to return the table handle.
79 1.1 jruoho *
80 1.1 jruoho * RETURN: Status
81 1.1 jruoho *
82 1.1 jruoho * DESCRIPTION: Common function to Install and Load an ACPI table with a
83 1.1 jruoho * returned table handle.
84 1.1 jruoho *
85 1.1 jruoho ******************************************************************************/
86 1.1 jruoho
87 1.1 jruoho static ACPI_STATUS
88 1.1 jruoho AcpiExAddTable (
89 1.1 jruoho UINT32 TableIndex,
90 1.1 jruoho ACPI_NAMESPACE_NODE *ParentNode,
91 1.1 jruoho ACPI_OPERAND_OBJECT **DdbHandle)
92 1.1 jruoho {
93 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc;
94 1.1 jruoho ACPI_STATUS Status;
95 1.1 jruoho ACPI_OWNER_ID OwnerId;
96 1.1 jruoho
97 1.1 jruoho
98 1.1 jruoho ACPI_FUNCTION_TRACE (ExAddTable);
99 1.1 jruoho
100 1.1 jruoho
101 1.1 jruoho /* Create an object to be the table handle */
102 1.1 jruoho
103 1.1 jruoho ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
104 1.1 jruoho if (!ObjDesc)
105 1.1 jruoho {
106 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
107 1.1 jruoho }
108 1.1 jruoho
109 1.1 jruoho /* Init the table handle */
110 1.1 jruoho
111 1.1 jruoho ObjDesc->Common.Flags |= AOPOBJ_DATA_VALID;
112 1.1 jruoho ObjDesc->Reference.Class = ACPI_REFCLASS_TABLE;
113 1.1 jruoho *DdbHandle = ObjDesc;
114 1.1 jruoho
115 1.1 jruoho /* Install the new table into the local data structures */
116 1.1 jruoho
117 1.1 jruoho ObjDesc->Reference.Value = TableIndex;
118 1.1 jruoho
119 1.1 jruoho /* Add the table to the namespace */
120 1.1 jruoho
121 1.1 jruoho Status = AcpiNsLoadTable (TableIndex, ParentNode);
122 1.1 jruoho if (ACPI_FAILURE (Status))
123 1.1 jruoho {
124 1.1 jruoho AcpiUtRemoveReference (ObjDesc);
125 1.1 jruoho *DdbHandle = NULL;
126 1.1 jruoho return_ACPI_STATUS (Status);
127 1.1 jruoho }
128 1.1 jruoho
129 1.1 jruoho /* Execute any module-level code that was found in the table */
130 1.1 jruoho
131 1.1 jruoho AcpiExExitInterpreter ();
132 1.9 christos if (AcpiGbl_GroupModuleLevelCode)
133 1.9 christos {
134 1.9 christos AcpiNsExecModuleCodeList ();
135 1.9 christos }
136 1.1 jruoho AcpiExEnterInterpreter ();
137 1.1 jruoho
138 1.3 jruoho /*
139 1.3 jruoho * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is
140 1.3 jruoho * responsible for discovering any new wake GPEs by running _PRW methods
141 1.3 jruoho * that may have been loaded by this table.
142 1.3 jruoho */
143 1.1 jruoho Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
144 1.1 jruoho if (ACPI_SUCCESS (Status))
145 1.1 jruoho {
146 1.1 jruoho AcpiEvUpdateGpes (OwnerId);
147 1.1 jruoho }
148 1.1 jruoho
149 1.1 jruoho return_ACPI_STATUS (AE_OK);
150 1.1 jruoho }
151 1.1 jruoho
152 1.1 jruoho
153 1.1 jruoho /*******************************************************************************
154 1.1 jruoho *
155 1.1 jruoho * FUNCTION: AcpiExLoadTableOp
156 1.1 jruoho *
157 1.1 jruoho * PARAMETERS: WalkState - Current state with operands
158 1.1 jruoho * ReturnDesc - Where to store the return object
159 1.1 jruoho *
160 1.1 jruoho * RETURN: Status
161 1.1 jruoho *
162 1.1 jruoho * DESCRIPTION: Load an ACPI table from the RSDT/XSDT
163 1.1 jruoho *
164 1.1 jruoho ******************************************************************************/
165 1.1 jruoho
166 1.1 jruoho ACPI_STATUS
167 1.1 jruoho AcpiExLoadTableOp (
168 1.1 jruoho ACPI_WALK_STATE *WalkState,
169 1.1 jruoho ACPI_OPERAND_OBJECT **ReturnDesc)
170 1.1 jruoho {
171 1.1 jruoho ACPI_STATUS Status;
172 1.1 jruoho ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
173 1.1 jruoho ACPI_NAMESPACE_NODE *ParentNode;
174 1.1 jruoho ACPI_NAMESPACE_NODE *StartNode;
175 1.1 jruoho ACPI_NAMESPACE_NODE *ParameterNode = NULL;
176 1.1 jruoho ACPI_OPERAND_OBJECT *DdbHandle;
177 1.1 jruoho ACPI_TABLE_HEADER *Table;
178 1.1 jruoho UINT32 TableIndex;
179 1.1 jruoho
180 1.1 jruoho
181 1.1 jruoho ACPI_FUNCTION_TRACE (ExLoadTableOp);
182 1.1 jruoho
183 1.1 jruoho
184 1.1 jruoho /* Find the ACPI table in the RSDT/XSDT */
185 1.1 jruoho
186 1.4 christos Status = AcpiTbFindTable (
187 1.8 christos Operand[0]->String.Pointer,
188 1.8 christos Operand[1]->String.Pointer,
189 1.8 christos Operand[2]->String.Pointer, &TableIndex);
190 1.1 jruoho if (ACPI_FAILURE (Status))
191 1.1 jruoho {
192 1.1 jruoho if (Status != AE_NOT_FOUND)
193 1.1 jruoho {
194 1.1 jruoho return_ACPI_STATUS (Status);
195 1.1 jruoho }
196 1.1 jruoho
197 1.1 jruoho /* Table not found, return an Integer=0 and AE_OK */
198 1.1 jruoho
199 1.1 jruoho DdbHandle = AcpiUtCreateIntegerObject ((UINT64) 0);
200 1.1 jruoho if (!DdbHandle)
201 1.1 jruoho {
202 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
203 1.1 jruoho }
204 1.1 jruoho
205 1.1 jruoho *ReturnDesc = DdbHandle;
206 1.1 jruoho return_ACPI_STATUS (AE_OK);
207 1.1 jruoho }
208 1.1 jruoho
209 1.1 jruoho /* Default nodes */
210 1.1 jruoho
211 1.1 jruoho StartNode = WalkState->ScopeInfo->Scope.Node;
212 1.1 jruoho ParentNode = AcpiGbl_RootNode;
213 1.1 jruoho
214 1.1 jruoho /* RootPath (optional parameter) */
215 1.1 jruoho
216 1.1 jruoho if (Operand[3]->String.Length > 0)
217 1.1 jruoho {
218 1.1 jruoho /*
219 1.4 christos * Find the node referenced by the RootPathString. This is the
220 1.1 jruoho * location within the namespace where the table will be loaded.
221 1.1 jruoho */
222 1.1 jruoho Status = AcpiNsGetNode (StartNode, Operand[3]->String.Pointer,
223 1.8 christos ACPI_NS_SEARCH_PARENT, &ParentNode);
224 1.1 jruoho if (ACPI_FAILURE (Status))
225 1.1 jruoho {
226 1.1 jruoho return_ACPI_STATUS (Status);
227 1.1 jruoho }
228 1.1 jruoho }
229 1.1 jruoho
230 1.1 jruoho /* ParameterPath (optional parameter) */
231 1.1 jruoho
232 1.1 jruoho if (Operand[4]->String.Length > 0)
233 1.1 jruoho {
234 1.4 christos if ((Operand[4]->String.Pointer[0] != AML_ROOT_PREFIX) &&
235 1.4 christos (Operand[4]->String.Pointer[0] != AML_PARENT_PREFIX))
236 1.1 jruoho {
237 1.1 jruoho /*
238 1.1 jruoho * Path is not absolute, so it will be relative to the node
239 1.1 jruoho * referenced by the RootPathString (or the NS root if omitted)
240 1.1 jruoho */
241 1.1 jruoho StartNode = ParentNode;
242 1.1 jruoho }
243 1.1 jruoho
244 1.1 jruoho /* Find the node referenced by the ParameterPathString */
245 1.1 jruoho
246 1.1 jruoho Status = AcpiNsGetNode (StartNode, Operand[4]->String.Pointer,
247 1.8 christos ACPI_NS_SEARCH_PARENT, &ParameterNode);
248 1.1 jruoho if (ACPI_FAILURE (Status))
249 1.1 jruoho {
250 1.1 jruoho return_ACPI_STATUS (Status);
251 1.1 jruoho }
252 1.1 jruoho }
253 1.1 jruoho
254 1.1 jruoho /* Load the table into the namespace */
255 1.1 jruoho
256 1.1 jruoho Status = AcpiExAddTable (TableIndex, ParentNode, &DdbHandle);
257 1.1 jruoho if (ACPI_FAILURE (Status))
258 1.1 jruoho {
259 1.1 jruoho return_ACPI_STATUS (Status);
260 1.1 jruoho }
261 1.1 jruoho
262 1.1 jruoho /* Parameter Data (optional) */
263 1.1 jruoho
264 1.1 jruoho if (ParameterNode)
265 1.1 jruoho {
266 1.1 jruoho /* Store the parameter data into the optional parameter object */
267 1.1 jruoho
268 1.1 jruoho Status = AcpiExStore (Operand[5],
269 1.8 christos ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode), WalkState);
270 1.1 jruoho if (ACPI_FAILURE (Status))
271 1.1 jruoho {
272 1.1 jruoho (void) AcpiExUnloadTable (DdbHandle);
273 1.1 jruoho
274 1.1 jruoho AcpiUtRemoveReference (DdbHandle);
275 1.1 jruoho return_ACPI_STATUS (Status);
276 1.1 jruoho }
277 1.1 jruoho }
278 1.1 jruoho
279 1.1 jruoho Status = AcpiGetTableByIndex (TableIndex, &Table);
280 1.1 jruoho if (ACPI_SUCCESS (Status))
281 1.1 jruoho {
282 1.9 christos ACPI_INFO (("Dynamic OEM Table Load:"));
283 1.1 jruoho AcpiTbPrintTableHeader (0, Table);
284 1.1 jruoho }
285 1.1 jruoho
286 1.1 jruoho /* Invoke table handler if present */
287 1.1 jruoho
288 1.1 jruoho if (AcpiGbl_TableHandler)
289 1.1 jruoho {
290 1.1 jruoho (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, Table,
291 1.8 christos AcpiGbl_TableHandlerContext);
292 1.1 jruoho }
293 1.1 jruoho
294 1.1 jruoho *ReturnDesc = DdbHandle;
295 1.4 christos return_ACPI_STATUS (Status);
296 1.1 jruoho }
297 1.1 jruoho
298 1.1 jruoho
299 1.1 jruoho /*******************************************************************************
300 1.1 jruoho *
301 1.1 jruoho * FUNCTION: AcpiExRegionRead
302 1.1 jruoho *
303 1.1 jruoho * PARAMETERS: ObjDesc - Region descriptor
304 1.1 jruoho * Length - Number of bytes to read
305 1.1 jruoho * Buffer - Pointer to where to put the data
306 1.1 jruoho *
307 1.1 jruoho * RETURN: Status
308 1.1 jruoho *
309 1.1 jruoho * DESCRIPTION: Read data from an operation region. The read starts from the
310 1.1 jruoho * beginning of the region.
311 1.1 jruoho *
312 1.1 jruoho ******************************************************************************/
313 1.1 jruoho
314 1.1 jruoho static ACPI_STATUS
315 1.1 jruoho AcpiExRegionRead (
316 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc,
317 1.1 jruoho UINT32 Length,
318 1.1 jruoho UINT8 *Buffer)
319 1.1 jruoho {
320 1.1 jruoho ACPI_STATUS Status;
321 1.1 jruoho UINT64 Value;
322 1.1 jruoho UINT32 RegionOffset = 0;
323 1.1 jruoho UINT32 i;
324 1.1 jruoho
325 1.1 jruoho
326 1.1 jruoho /* Bytewise reads */
327 1.1 jruoho
328 1.1 jruoho for (i = 0; i < Length; i++)
329 1.1 jruoho {
330 1.4 christos Status = AcpiEvAddressSpaceDispatch (ObjDesc, NULL, ACPI_READ,
331 1.8 christos RegionOffset, 8, &Value);
332 1.1 jruoho if (ACPI_FAILURE (Status))
333 1.1 jruoho {
334 1.1 jruoho return (Status);
335 1.1 jruoho }
336 1.1 jruoho
337 1.1 jruoho *Buffer = (UINT8) Value;
338 1.1 jruoho Buffer++;
339 1.1 jruoho RegionOffset++;
340 1.1 jruoho }
341 1.1 jruoho
342 1.1 jruoho return (AE_OK);
343 1.1 jruoho }
344 1.1 jruoho
345 1.1 jruoho
346 1.1 jruoho /*******************************************************************************
347 1.1 jruoho *
348 1.1 jruoho * FUNCTION: AcpiExLoadOp
349 1.1 jruoho *
350 1.1 jruoho * PARAMETERS: ObjDesc - Region or Buffer/Field where the table will be
351 1.1 jruoho * obtained
352 1.1 jruoho * Target - Where a handle to the table will be stored
353 1.1 jruoho * WalkState - Current state
354 1.1 jruoho *
355 1.1 jruoho * RETURN: Status
356 1.1 jruoho *
357 1.1 jruoho * DESCRIPTION: Load an ACPI table from a field or operation region
358 1.1 jruoho *
359 1.1 jruoho * NOTE: Region Fields (Field, BankField, IndexFields) are resolved to buffer
360 1.1 jruoho * objects before this code is reached.
361 1.1 jruoho *
362 1.1 jruoho * If source is an operation region, it must refer to SystemMemory, as
363 1.1 jruoho * per the ACPI specification.
364 1.1 jruoho *
365 1.1 jruoho ******************************************************************************/
366 1.1 jruoho
367 1.1 jruoho ACPI_STATUS
368 1.1 jruoho AcpiExLoadOp (
369 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc,
370 1.1 jruoho ACPI_OPERAND_OBJECT *Target,
371 1.1 jruoho ACPI_WALK_STATE *WalkState)
372 1.1 jruoho {
373 1.1 jruoho ACPI_OPERAND_OBJECT *DdbHandle;
374 1.5 christos ACPI_TABLE_HEADER *TableHeader;
375 1.1 jruoho ACPI_TABLE_HEADER *Table;
376 1.1 jruoho UINT32 TableIndex;
377 1.1 jruoho ACPI_STATUS Status;
378 1.1 jruoho UINT32 Length;
379 1.1 jruoho
380 1.1 jruoho
381 1.1 jruoho ACPI_FUNCTION_TRACE (ExLoadOp);
382 1.1 jruoho
383 1.1 jruoho
384 1.1 jruoho /* Source Object can be either an OpRegion or a Buffer/Field */
385 1.1 jruoho
386 1.1 jruoho switch (ObjDesc->Common.Type)
387 1.1 jruoho {
388 1.1 jruoho case ACPI_TYPE_REGION:
389 1.1 jruoho
390 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
391 1.1 jruoho "Load table from Region %p\n", ObjDesc));
392 1.1 jruoho
393 1.1 jruoho /* Region must be SystemMemory (from ACPI spec) */
394 1.1 jruoho
395 1.1 jruoho if (ObjDesc->Region.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
396 1.1 jruoho {
397 1.1 jruoho return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
398 1.1 jruoho }
399 1.1 jruoho
400 1.1 jruoho /*
401 1.8 christos * If the Region Address and Length have not been previously
402 1.8 christos * evaluated, evaluate them now and save the results.
403 1.1 jruoho */
404 1.1 jruoho if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
405 1.1 jruoho {
406 1.1 jruoho Status = AcpiDsGetRegionArguments (ObjDesc);
407 1.1 jruoho if (ACPI_FAILURE (Status))
408 1.1 jruoho {
409 1.1 jruoho return_ACPI_STATUS (Status);
410 1.1 jruoho }
411 1.1 jruoho }
412 1.1 jruoho
413 1.1 jruoho /* Get the table header first so we can get the table length */
414 1.1 jruoho
415 1.5 christos TableHeader = ACPI_ALLOCATE (sizeof (ACPI_TABLE_HEADER));
416 1.5 christos if (!TableHeader)
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 Status = AcpiExRegionRead (ObjDesc, sizeof (ACPI_TABLE_HEADER),
422 1.8 christos ACPI_CAST_PTR (UINT8, TableHeader));
423 1.5 christos Length = TableHeader->Length;
424 1.5 christos ACPI_FREE (TableHeader);
425 1.1 jruoho
426 1.1 jruoho if (ACPI_FAILURE (Status))
427 1.1 jruoho {
428 1.1 jruoho return_ACPI_STATUS (Status);
429 1.1 jruoho }
430 1.1 jruoho
431 1.1 jruoho /* Must have at least an ACPI table header */
432 1.1 jruoho
433 1.1 jruoho if (Length < sizeof (ACPI_TABLE_HEADER))
434 1.1 jruoho {
435 1.1 jruoho return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
436 1.1 jruoho }
437 1.1 jruoho
438 1.1 jruoho /*
439 1.1 jruoho * The original implementation simply mapped the table, with no copy.
440 1.1 jruoho * However, the memory region is not guaranteed to remain stable and
441 1.1 jruoho * we must copy the table to a local buffer. For example, the memory
442 1.1 jruoho * region is corrupted after suspend on some machines. Dynamically
443 1.1 jruoho * loaded tables are usually small, so this overhead is minimal.
444 1.1 jruoho *
445 1.1 jruoho * The latest implementation (5/2009) does not use a mapping at all.
446 1.1 jruoho * We use the low-level operation region interface to read the table
447 1.1 jruoho * instead of the obvious optimization of using a direct mapping.
448 1.1 jruoho * This maintains a consistent use of operation regions across the
449 1.1 jruoho * entire subsystem. This is important if additional processing must
450 1.1 jruoho * be performed in the (possibly user-installed) operation region
451 1.1 jruoho * handler. For example, AcpiExec and ASLTS depend on this.
452 1.1 jruoho */
453 1.1 jruoho
454 1.1 jruoho /* Allocate a buffer for the table */
455 1.1 jruoho
456 1.5 christos Table = ACPI_ALLOCATE (Length);
457 1.5 christos if (!Table)
458 1.1 jruoho {
459 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
460 1.1 jruoho }
461 1.1 jruoho
462 1.1 jruoho /* Read the entire table */
463 1.1 jruoho
464 1.1 jruoho Status = AcpiExRegionRead (ObjDesc, Length,
465 1.8 christos ACPI_CAST_PTR (UINT8, Table));
466 1.1 jruoho if (ACPI_FAILURE (Status))
467 1.1 jruoho {
468 1.5 christos ACPI_FREE (Table);
469 1.1 jruoho return_ACPI_STATUS (Status);
470 1.1 jruoho }
471 1.1 jruoho break;
472 1.1 jruoho
473 1.1 jruoho case ACPI_TYPE_BUFFER: /* Buffer or resolved RegionField */
474 1.1 jruoho
475 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
476 1.1 jruoho "Load table from Buffer or Field %p\n", ObjDesc));
477 1.1 jruoho
478 1.1 jruoho /* Must have at least an ACPI table header */
479 1.1 jruoho
480 1.1 jruoho if (ObjDesc->Buffer.Length < sizeof (ACPI_TABLE_HEADER))
481 1.1 jruoho {
482 1.1 jruoho return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
483 1.1 jruoho }
484 1.1 jruoho
485 1.1 jruoho /* Get the actual table length from the table header */
486 1.1 jruoho
487 1.8 christos TableHeader = ACPI_CAST_PTR (
488 1.8 christos ACPI_TABLE_HEADER, ObjDesc->Buffer.Pointer);
489 1.5 christos Length = TableHeader->Length;
490 1.1 jruoho
491 1.1 jruoho /* Table cannot extend beyond the buffer */
492 1.1 jruoho
493 1.1 jruoho if (Length > ObjDesc->Buffer.Length)
494 1.1 jruoho {
495 1.1 jruoho return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
496 1.1 jruoho }
497 1.1 jruoho if (Length < sizeof (ACPI_TABLE_HEADER))
498 1.1 jruoho {
499 1.1 jruoho return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
500 1.1 jruoho }
501 1.1 jruoho
502 1.1 jruoho /*
503 1.8 christos * Copy the table from the buffer because the buffer could be
504 1.8 christos * modified or even deleted in the future
505 1.1 jruoho */
506 1.5 christos Table = ACPI_ALLOCATE (Length);
507 1.5 christos if (!Table)
508 1.1 jruoho {
509 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
510 1.1 jruoho }
511 1.1 jruoho
512 1.7 christos memcpy (Table, TableHeader, Length);
513 1.1 jruoho break;
514 1.1 jruoho
515 1.4 christos default:
516 1.1 jruoho
517 1.1 jruoho return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
518 1.1 jruoho }
519 1.1 jruoho
520 1.5 christos /* Install the new table into the local data structures */
521 1.5 christos
522 1.9 christos ACPI_INFO (("Dynamic OEM Table Load:"));
523 1.5 christos (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
524 1.5 christos
525 1.5 christos Status = AcpiTbInstallStandardTable (ACPI_PTR_TO_PHYSADDR (Table),
526 1.8 christos ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, TRUE, TRUE,
527 1.8 christos &TableIndex);
528 1.1 jruoho
529 1.5 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
530 1.1 jruoho if (ACPI_FAILURE (Status))
531 1.1 jruoho {
532 1.5 christos /* Delete allocated table buffer */
533 1.5 christos
534 1.5 christos ACPI_FREE (Table);
535 1.1 jruoho return_ACPI_STATUS (Status);
536 1.1 jruoho }
537 1.1 jruoho
538 1.5 christos /*
539 1.5 christos * Note: Now table is "INSTALLED", it must be validated before
540 1.5 christos * loading.
541 1.5 christos */
542 1.8 christos Status = AcpiTbValidateTable (
543 1.8 christos &AcpiGbl_RootTableList.Tables[TableIndex]);
544 1.1 jruoho if (ACPI_FAILURE (Status))
545 1.1 jruoho {
546 1.1 jruoho return_ACPI_STATUS (Status);
547 1.1 jruoho }
548 1.1 jruoho
549 1.1 jruoho /*
550 1.1 jruoho * Add the table to the namespace.
551 1.1 jruoho *
552 1.1 jruoho * Note: Load the table objects relative to the root of the namespace.
553 1.1 jruoho * This appears to go against the ACPI specification, but we do it for
554 1.1 jruoho * compatibility with other ACPI implementations.
555 1.1 jruoho */
556 1.1 jruoho Status = AcpiExAddTable (TableIndex, AcpiGbl_RootNode, &DdbHandle);
557 1.1 jruoho if (ACPI_FAILURE (Status))
558 1.1 jruoho {
559 1.1 jruoho /* On error, TablePtr was deallocated above */
560 1.1 jruoho
561 1.1 jruoho return_ACPI_STATUS (Status);
562 1.1 jruoho }
563 1.1 jruoho
564 1.1 jruoho /* Store the DdbHandle into the Target operand */
565 1.1 jruoho
566 1.1 jruoho Status = AcpiExStore (DdbHandle, Target, WalkState);
567 1.1 jruoho if (ACPI_FAILURE (Status))
568 1.1 jruoho {
569 1.1 jruoho (void) AcpiExUnloadTable (DdbHandle);
570 1.1 jruoho
571 1.1 jruoho /* TablePtr was deallocated above */
572 1.1 jruoho
573 1.1 jruoho AcpiUtRemoveReference (DdbHandle);
574 1.1 jruoho return_ACPI_STATUS (Status);
575 1.1 jruoho }
576 1.1 jruoho
577 1.1 jruoho /* Remove the reference by added by AcpiExStore above */
578 1.1 jruoho
579 1.1 jruoho AcpiUtRemoveReference (DdbHandle);
580 1.1 jruoho
581 1.1 jruoho /* Invoke table handler if present */
582 1.1 jruoho
583 1.1 jruoho if (AcpiGbl_TableHandler)
584 1.1 jruoho {
585 1.5 christos (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, Table,
586 1.8 christos AcpiGbl_TableHandlerContext);
587 1.1 jruoho }
588 1.1 jruoho
589 1.1 jruoho return_ACPI_STATUS (Status);
590 1.1 jruoho }
591 1.1 jruoho
592 1.1 jruoho
593 1.1 jruoho /*******************************************************************************
594 1.1 jruoho *
595 1.1 jruoho * FUNCTION: AcpiExUnloadTable
596 1.1 jruoho *
597 1.1 jruoho * PARAMETERS: DdbHandle - Handle to a previously loaded table
598 1.1 jruoho *
599 1.1 jruoho * RETURN: Status
600 1.1 jruoho *
601 1.1 jruoho * DESCRIPTION: Unload an ACPI table
602 1.1 jruoho *
603 1.1 jruoho ******************************************************************************/
604 1.1 jruoho
605 1.1 jruoho ACPI_STATUS
606 1.1 jruoho AcpiExUnloadTable (
607 1.1 jruoho ACPI_OPERAND_OBJECT *DdbHandle)
608 1.1 jruoho {
609 1.1 jruoho ACPI_STATUS Status = AE_OK;
610 1.1 jruoho ACPI_OPERAND_OBJECT *TableDesc = DdbHandle;
611 1.1 jruoho UINT32 TableIndex;
612 1.1 jruoho ACPI_TABLE_HEADER *Table;
613 1.1 jruoho
614 1.1 jruoho
615 1.1 jruoho ACPI_FUNCTION_TRACE (ExUnloadTable);
616 1.1 jruoho
617 1.1 jruoho
618 1.1 jruoho /*
619 1.5 christos * Temporarily emit a warning so that the ASL for the machine can be
620 1.5 christos * hopefully obtained. This is to say that the Unload() operator is
621 1.5 christos * extremely rare if not completely unused.
622 1.5 christos */
623 1.5 christos ACPI_WARNING ((AE_INFO,
624 1.5 christos "Received request to unload an ACPI table"));
625 1.5 christos
626 1.5 christos /*
627 1.1 jruoho * Validate the handle
628 1.1 jruoho * Although the handle is partially validated in AcpiExReconfiguration()
629 1.1 jruoho * when it calls AcpiExResolveOperands(), the handle is more completely
630 1.1 jruoho * validated here.
631 1.1 jruoho *
632 1.1 jruoho * Handle must be a valid operand object of type reference. Also, the
633 1.1 jruoho * DdbHandle must still be marked valid (table has not been previously
634 1.1 jruoho * unloaded)
635 1.1 jruoho */
636 1.1 jruoho if ((!DdbHandle) ||
637 1.1 jruoho (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle) != ACPI_DESC_TYPE_OPERAND) ||
638 1.1 jruoho (DdbHandle->Common.Type != ACPI_TYPE_LOCAL_REFERENCE) ||
639 1.1 jruoho (!(DdbHandle->Common.Flags & AOPOBJ_DATA_VALID)))
640 1.1 jruoho {
641 1.4 christos return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
642 1.1 jruoho }
643 1.1 jruoho
644 1.1 jruoho /* Get the table index from the DdbHandle */
645 1.1 jruoho
646 1.1 jruoho TableIndex = TableDesc->Reference.Value;
647 1.1 jruoho
648 1.1 jruoho /* Ensure the table is still loaded */
649 1.1 jruoho
650 1.1 jruoho if (!AcpiTbIsTableLoaded (TableIndex))
651 1.1 jruoho {
652 1.1 jruoho return_ACPI_STATUS (AE_NOT_EXIST);
653 1.1 jruoho }
654 1.1 jruoho
655 1.1 jruoho /* Invoke table handler if present */
656 1.1 jruoho
657 1.1 jruoho if (AcpiGbl_TableHandler)
658 1.1 jruoho {
659 1.1 jruoho Status = AcpiGetTableByIndex (TableIndex, &Table);
660 1.1 jruoho if (ACPI_SUCCESS (Status))
661 1.1 jruoho {
662 1.1 jruoho (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_UNLOAD, Table,
663 1.8 christos AcpiGbl_TableHandlerContext);
664 1.1 jruoho }
665 1.1 jruoho }
666 1.1 jruoho
667 1.1 jruoho /* Delete the portion of the namespace owned by this table */
668 1.1 jruoho
669 1.1 jruoho Status = AcpiTbDeleteNamespaceByOwner (TableIndex);
670 1.1 jruoho if (ACPI_FAILURE (Status))
671 1.1 jruoho {
672 1.1 jruoho return_ACPI_STATUS (Status);
673 1.1 jruoho }
674 1.1 jruoho
675 1.1 jruoho (void) AcpiTbReleaseOwnerId (TableIndex);
676 1.1 jruoho AcpiTbSetTableLoadedFlag (TableIndex, FALSE);
677 1.1 jruoho
678 1.1 jruoho /*
679 1.1 jruoho * Invalidate the handle. We do this because the handle may be stored
680 1.1 jruoho * in a named object and may not be actually deleted until much later.
681 1.1 jruoho */
682 1.1 jruoho DdbHandle->Common.Flags &= ~AOPOBJ_DATA_VALID;
683 1.1 jruoho return_ACPI_STATUS (AE_OK);
684 1.1 jruoho }
685