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