1/******************************************************************************
2 *
3 * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
4 *
5 *****************************************************************************/
6
7/******************************************************************************
8 *
9 * 1. Copyright Notice
10 *
11 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12 * All rights reserved.
13 *
14 * 2. License
15 *
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
20 *
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
27 *
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
36 *
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
39 *
40 * 3. Conditions
41 *
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
53 *
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
65 *
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
71 *
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
74 *
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
79 *
80 * 4. Disclaimer and Export Compliance
81 *
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
90 *
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
99 *
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
114 *
115 *****************************************************************************/
116
117#define __EXCONFIG_C__
118
119#include <contrib/dev/acpica/include/acpi.h>
120#include <contrib/dev/acpica/include/accommon.h>
121#include <contrib/dev/acpica/include/acinterp.h>
122#include <contrib/dev/acpica/include/acnamesp.h>
123#include <contrib/dev/acpica/include/actables.h>
124#include <contrib/dev/acpica/include/acdispat.h>
125#include <contrib/dev/acpica/include/acevents.h>
126
127
128#define _COMPONENT ACPI_EXECUTER
129 ACPI_MODULE_NAME ("exconfig")
130
131/* Local prototypes */
132
133static ACPI_STATUS
134AcpiExAddTable (
135 UINT32 TableIndex,
136 ACPI_NAMESPACE_NODE *ParentNode,
137 ACPI_OPERAND_OBJECT **DdbHandle);
138
139static ACPI_STATUS
140AcpiExRegionRead (
141 ACPI_OPERAND_OBJECT *ObjDesc,
142 UINT32 Length,
143 UINT8 *Buffer);
144
145
146/*******************************************************************************
147 *
148 * FUNCTION: AcpiExAddTable
149 *
150 * PARAMETERS: Table - Pointer to raw table
151 * ParentNode - Where to load the table (scope)
152 * DdbHandle - Where to return the table handle.
153 *
154 * RETURN: Status
155 *
156 * DESCRIPTION: Common function to Install and Load an ACPI table with a
157 * returned table handle.
158 *
159 ******************************************************************************/
160
161static ACPI_STATUS
162AcpiExAddTable (
163 UINT32 TableIndex,
164 ACPI_NAMESPACE_NODE *ParentNode,
165 ACPI_OPERAND_OBJECT **DdbHandle)
166{
167 ACPI_STATUS Status;
168 ACPI_OPERAND_OBJECT *ObjDesc;
169
170
171 ACPI_FUNCTION_TRACE (ExAddTable);
172
173
174 /* Create an object to be the table handle */
175
176 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
177 if (!ObjDesc)
178 {
179 return_ACPI_STATUS (AE_NO_MEMORY);
180 }
181
182 /* Init the table handle */
183
184 ObjDesc->Common.Flags |= AOPOBJ_DATA_VALID;
185 ObjDesc->Reference.Class = ACPI_REFCLASS_TABLE;
186 *DdbHandle = ObjDesc;
187
188 /* Install the new table into the local data structures */
189
190 ObjDesc->Reference.Value = TableIndex;
191
192 /* Add the table to the namespace */
193
194 Status = AcpiNsLoadTable (TableIndex, ParentNode);
195 if (ACPI_FAILURE (Status))
196 {
197 AcpiUtRemoveReference (ObjDesc);
198 *DdbHandle = NULL;
199 return_ACPI_STATUS (Status);
200 }
201
202 /* Execute any module-level code that was found in the table */
203
204 AcpiExExitInterpreter ();
205 AcpiNsExecModuleCodeList ();
206 AcpiExEnterInterpreter ();
207
208 return_ACPI_STATUS (Status);
209}
210
211
212/*******************************************************************************
213 *
214 * FUNCTION: AcpiExLoadTableOp
215 *
216 * PARAMETERS: WalkState - Current state with operands
217 * ReturnDesc - Where to store the return object
218 *
219 * RETURN: Status
220 *
221 * DESCRIPTION: Load an ACPI table from the RSDT/XSDT
222 *
223 ******************************************************************************/
224
225ACPI_STATUS
226AcpiExLoadTableOp (
227 ACPI_WALK_STATE *WalkState,
228 ACPI_OPERAND_OBJECT **ReturnDesc)
229{
230 ACPI_STATUS Status;
231 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
232 ACPI_NAMESPACE_NODE *ParentNode;
233 ACPI_NAMESPACE_NODE *StartNode;
234 ACPI_NAMESPACE_NODE *ParameterNode = NULL;
235 ACPI_OPERAND_OBJECT *DdbHandle;
236 ACPI_TABLE_HEADER *Table;
237 UINT32 TableIndex;
238
239
240 ACPI_FUNCTION_TRACE (ExLoadTableOp);
241
242
243 /* Validate lengths for the SignatureString, OEMIDString, OEMTableID */
244
245 if ((Operand[0]->String.Length > ACPI_NAME_SIZE) ||
246 (Operand[1]->String.Length > ACPI_OEM_ID_SIZE) ||
247 (Operand[2]->String.Length > ACPI_OEM_TABLE_ID_SIZE))
248 {
249 return_ACPI_STATUS (AE_BAD_PARAMETER);
250 }
251
252 /* Find the ACPI table in the RSDT/XSDT */
253
254 Status = AcpiTbFindTable (Operand[0]->String.Pointer,
255 Operand[1]->String.Pointer,
256 Operand[2]->String.Pointer, &TableIndex);
257 if (ACPI_FAILURE (Status))
258 {
259 if (Status != AE_NOT_FOUND)
260 {
261 return_ACPI_STATUS (Status);
262 }
263
264 /* Table not found, return an Integer=0 and AE_OK */
265
266 DdbHandle = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
267 if (!DdbHandle)
268 {
269 return_ACPI_STATUS (AE_NO_MEMORY);
270 }
271
272 DdbHandle->Integer.Value = 0;
273 *ReturnDesc = DdbHandle;
274
275 return_ACPI_STATUS (AE_OK);
276 }
277
278 /* Default nodes */
279
280 StartNode = WalkState->ScopeInfo->Scope.Node;
281 ParentNode = AcpiGbl_RootNode;
282
283 /* RootPath (optional parameter) */
284
285 if (Operand[3]->String.Length > 0)
286 {
287 /*
288 * Find the node referenced by the RootPathString. This is the
289 * location within the namespace where the table will be loaded.
290 */
291 Status = AcpiNsGetNode (StartNode, Operand[3]->String.Pointer,
292 ACPI_NS_SEARCH_PARENT, &ParentNode);
293 if (ACPI_FAILURE (Status))
294 {
295 return_ACPI_STATUS (Status);
296 }
297 }
298
299 /* ParameterPath (optional parameter) */
300
301 if (Operand[4]->String.Length > 0)
302 {
303 if ((Operand[4]->String.Pointer[0] != '\\') &&
304 (Operand[4]->String.Pointer[0] != '^'))
305 {
306 /*
307 * Path is not absolute, so it will be relative to the node
308 * referenced by the RootPathString (or the NS root if omitted)
309 */
310 StartNode = ParentNode;
311 }
312
313 /* Find the node referenced by the ParameterPathString */
314
315 Status = AcpiNsGetNode (StartNode, Operand[4]->String.Pointer,
316 ACPI_NS_SEARCH_PARENT, &ParameterNode);
317 if (ACPI_FAILURE (Status))
318 {
319 return_ACPI_STATUS (Status);
320 }
321 }
322
323 /* Load the table into the namespace */
324
325 Status = AcpiExAddTable (TableIndex, ParentNode, &DdbHandle);
326 if (ACPI_FAILURE (Status))
327 {
328 return_ACPI_STATUS (Status);
329 }
330
331 /* Parameter Data (optional) */
332
333 if (ParameterNode)
334 {
335 /* Store the parameter data into the optional parameter object */
336
337 Status = AcpiExStore (Operand[5],
338 ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode),
339 WalkState);
340 if (ACPI_FAILURE (Status))
341 {
342 (void) AcpiExUnloadTable (DdbHandle);
343
344 AcpiUtRemoveReference (DdbHandle);
345 return_ACPI_STATUS (Status);
346 }
347 }
348
349 Status = AcpiGetTableByIndex (TableIndex, &Table);
350 if (ACPI_SUCCESS (Status))
351 {
352 ACPI_INFO ((AE_INFO,
353 "Dynamic OEM Table Load - [%.4s] OemId [%.6s] OemTableId [%.8s]",
354 Table->Signature, Table->OemId, Table->OemTableId));
355 }
356
357 /* Invoke table handler if present */
358
359 if (AcpiGbl_TableHandler)
360 {
361 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, Table,
362 AcpiGbl_TableHandlerContext);
363 }
364
365 *ReturnDesc = DdbHandle;
366 return_ACPI_STATUS (Status);
367}
368
369
370/*******************************************************************************
371 *
372 * FUNCTION: AcpiExRegionRead
373 *
374 * PARAMETERS: ObjDesc - Region descriptor
375 * Length - Number of bytes to read
376 * Buffer - Pointer to where to put the data
377 *
378 * RETURN: Status
379 *
380 * DESCRIPTION: Read data from an operation region. The read starts from the
381 * beginning of the region.
382 *
383 ******************************************************************************/
384
385static ACPI_STATUS
386AcpiExRegionRead (
387 ACPI_OPERAND_OBJECT *ObjDesc,
388 UINT32 Length,
389 UINT8 *Buffer)
390{
391 ACPI_STATUS Status;
392 ACPI_INTEGER Value;
393 UINT32 RegionOffset = 0;
394 UINT32 i;
395
396
397 /* Bytewise reads */
398
399 for (i = 0; i < Length; i++)
400 {
401 Status = AcpiEvAddressSpaceDispatch (ObjDesc, ACPI_READ,
402 RegionOffset, 8, &Value);
403 if (ACPI_FAILURE (Status))
404 {
405 return (Status);
406 }
407
408 *Buffer = (UINT8) Value;
409 Buffer++;
410 RegionOffset++;
411 }
412
413 return (AE_OK);
414}
415
416
417/*******************************************************************************
418 *
419 * FUNCTION: AcpiExLoadOp
420 *
421 * PARAMETERS: ObjDesc - Region or Buffer/Field where the table will be
422 * obtained
423 * Target - Where a handle to the table will be stored
424 * WalkState - Current state
425 *
426 * RETURN: Status
427 *
428 * DESCRIPTION: Load an ACPI table from a field or operation region
429 *
430 * NOTE: Region Fields (Field, BankField, IndexFields) are resolved to buffer
431 * objects before this code is reached.
432 *
433 * If source is an operation region, it must refer to SystemMemory, as
434 * per the ACPI specification.
435 *
436 ******************************************************************************/
437
438ACPI_STATUS
439AcpiExLoadOp (
440 ACPI_OPERAND_OBJECT *ObjDesc,
441 ACPI_OPERAND_OBJECT *Target,
442 ACPI_WALK_STATE *WalkState)
443{
444 ACPI_OPERAND_OBJECT *DdbHandle;
445 ACPI_TABLE_HEADER *Table;
446 ACPI_TABLE_DESC TableDesc;
447 UINT32 TableIndex;
448 ACPI_STATUS Status;
449 UINT32 Length;
450
451
452 ACPI_FUNCTION_TRACE (ExLoadOp);
453
454
455 ACPI_MEMSET (&TableDesc, 0, sizeof (ACPI_TABLE_DESC));
456
457 /* Source Object can be either an OpRegion or a Buffer/Field */
458
459 switch (ObjDesc->Common.Type)
460 {
461 case ACPI_TYPE_REGION:
462
463 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
464 "Load table from Region %p\n", ObjDesc));
465
466 /* Region must be SystemMemory (from ACPI spec) */
467
468 if (ObjDesc->Region.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
469 {
470 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
471 }
472
473 /*
474 * If the Region Address and Length have not been previously evaluated,
475 * evaluate them now and save the results.
476 */
477 if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
478 {
479 Status = AcpiDsGetRegionArguments (ObjDesc);
480 if (ACPI_FAILURE (Status))
481 {
482 return_ACPI_STATUS (Status);
483 }
484 }
485
486 /* Get the table header first so we can get the table length */
487
488 Table = ACPI_ALLOCATE (sizeof (ACPI_TABLE_HEADER));
489 if (!Table)
490 {
491 return_ACPI_STATUS (AE_NO_MEMORY);
492 }
493
494 Status = AcpiExRegionRead (ObjDesc, sizeof (ACPI_TABLE_HEADER),
495 ACPI_CAST_PTR (UINT8, Table));
496 Length = Table->Length;
497 ACPI_FREE (Table);
498
499 if (ACPI_FAILURE (Status))
500 {
501 return_ACPI_STATUS (Status);
502 }
503
504 /* Must have at least an ACPI table header */
505
506 if (Length < sizeof (ACPI_TABLE_HEADER))
507 {
508 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
509 }
510
511 /*
512 * The original implementation simply mapped the table, with no copy.
513 * However, the memory region is not guaranteed to remain stable and
514 * we must copy the table to a local buffer. For example, the memory
515 * region is corrupted after suspend on some machines. Dynamically
516 * loaded tables are usually small, so this overhead is minimal.
517 *
518 * The latest implementation (5/2009) does not use a mapping at all.
519 * We use the low-level operation region interface to read the table
520 * instead of the obvious optimization of using a direct mapping.
521 * This maintains a consistent use of operation regions across the
522 * entire subsystem. This is important if additional processing must
523 * be performed in the (possibly user-installed) operation region
524 * handler. For example, AcpiExec and ASLTS depend on this.
525 */
526
527 /* Allocate a buffer for the table */
528
529 TableDesc.Pointer = ACPI_ALLOCATE (Length);
530 if (!TableDesc.Pointer)
531 {
532 return_ACPI_STATUS (AE_NO_MEMORY);
533 }
534
535 /* Read the entire table */
536
537 Status = AcpiExRegionRead (ObjDesc, Length,
538 ACPI_CAST_PTR (UINT8, TableDesc.Pointer));
539 if (ACPI_FAILURE (Status))
540 {
541 ACPI_FREE (TableDesc.Pointer);
542 return_ACPI_STATUS (Status);
543 }
544
545 TableDesc.Address = ObjDesc->Region.Address;
546 break;
547
548
549 case ACPI_TYPE_BUFFER: /* Buffer or resolved RegionField */
550
551 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
552 "Load table from Buffer or Field %p\n", ObjDesc));
553
554 /* Must have at least an ACPI table header */
555
556 if (ObjDesc->Buffer.Length < sizeof (ACPI_TABLE_HEADER))
557 {
558 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
559 }
560
561 /* Get the actual table length from the table header */
562
563 Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, ObjDesc->Buffer.Pointer);
564 Length = Table->Length;
565
566 /* Table cannot extend beyond the buffer */
567
568 if (Length > ObjDesc->Buffer.Length)
569 {
570 return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
571 }
572 if (Length < sizeof (ACPI_TABLE_HEADER))
573 {
574 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
575 }
576
577 /*
578 * Copy the table from the buffer because the buffer could be modified
579 * or even deleted in the future
580 */
581 TableDesc.Pointer = ACPI_ALLOCATE (Length);
582 if (!TableDesc.Pointer)
583 {
584 return_ACPI_STATUS (AE_NO_MEMORY);
585 }
586
587 ACPI_MEMCPY (TableDesc.Pointer, Table, Length);
588 TableDesc.Address = ACPI_TO_INTEGER (TableDesc.Pointer);
589 break;
590
591
592 default:
593 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
594 }
595
596 /* Validate table checksum (will not get validated in TbAddTable) */
597
598 Status = AcpiTbVerifyChecksum (TableDesc.Pointer, Length);
599 if (ACPI_FAILURE (Status))
600 {
601 ACPI_FREE (TableDesc.Pointer);
602 return_ACPI_STATUS (Status);
603 }
604
605 /* Complete the table descriptor */
606
607 TableDesc.Length = Length;
608 TableDesc.Flags = ACPI_TABLE_ORIGIN_ALLOCATED;
609
610 /* Install the new table into the local data structures */
611
612 Status = AcpiTbAddTable (&TableDesc, &TableIndex);
613 if (ACPI_FAILURE (Status))
614 {
615 goto Cleanup;
616 }
617
618 /*
619 * Add the table to the namespace.
620 *
621 * Note: Load the table objects relative to the root of the namespace.
622 * This appears to go against the ACPI specification, but we do it for
623 * compatibility with other ACPI implementations.
624 */
625 Status = AcpiExAddTable (TableIndex, AcpiGbl_RootNode, &DdbHandle);
626 if (ACPI_FAILURE (Status))
627 {
628 /* On error, TablePtr was deallocated above */
629
630 return_ACPI_STATUS (Status);
631 }
632
633 /* Store the DdbHandle into the Target operand */
634
635 Status = AcpiExStore (DdbHandle, Target, WalkState);
636 if (ACPI_FAILURE (Status))
637 {
638 (void) AcpiExUnloadTable (DdbHandle);
639
640 /* TablePtr was deallocated above */
641
642 AcpiUtRemoveReference (DdbHandle);
643 return_ACPI_STATUS (Status);
644 }
645
646 /* Remove the reference by added by AcpiExStore above */
647
648 AcpiUtRemoveReference (DdbHandle);
649
650 /* Invoke table handler if present */
651
652 if (AcpiGbl_TableHandler)
653 {
654 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, TableDesc.Pointer,
655 AcpiGbl_TableHandlerContext);
656 }
657
658Cleanup:
659 if (ACPI_FAILURE (Status))
660 {
661 /* Delete allocated table buffer */
662
663 AcpiTbDeleteTable (&TableDesc);
664 }
665 return_ACPI_STATUS (Status);
666}
667
668
669/*******************************************************************************
670 *
671 * FUNCTION: AcpiExUnloadTable
672 *
673 * PARAMETERS: DdbHandle - Handle to a previously loaded table
674 *
675 * RETURN: Status
676 *
677 * DESCRIPTION: Unload an ACPI table
678 *
679 ******************************************************************************/
680
681ACPI_STATUS
682AcpiExUnloadTable (
683 ACPI_OPERAND_OBJECT *DdbHandle)
684{
685 ACPI_STATUS Status = AE_OK;
686 ACPI_OPERAND_OBJECT *TableDesc = DdbHandle;
687 UINT32 TableIndex;
688 ACPI_TABLE_HEADER *Table;
689
690
691 ACPI_FUNCTION_TRACE (ExUnloadTable);
692
693
694 /*
695 * Validate the handle
696 * Although the handle is partially validated in AcpiExReconfiguration()
697 * when it calls AcpiExResolveOperands(), the handle is more completely
698 * validated here.
699 *
700 * Handle must be a valid operand object of type reference. Also, the
701 * DdbHandle must still be marked valid (table has not been previously
702 * unloaded)
703 */
704 if ((!DdbHandle) ||
705 (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle) != ACPI_DESC_TYPE_OPERAND) ||
706 (DdbHandle->Common.Type != ACPI_TYPE_LOCAL_REFERENCE) ||
707 (!(DdbHandle->Common.Flags & AOPOBJ_DATA_VALID)))
708 {
709 return_ACPI_STATUS (AE_BAD_PARAMETER);
710 }
711
712 /* Get the table index from the DdbHandle */
713
714 TableIndex = TableDesc->Reference.Value;
715
716 /* Ensure the table is still loaded */
717
718 if (!AcpiTbIsTableLoaded (TableIndex))
719 {
720 return_ACPI_STATUS (AE_NOT_EXIST);
721 }
722
723 /* Invoke table handler if present */
724
725 if (AcpiGbl_TableHandler)
726 {
727 Status = AcpiGetTableByIndex (TableIndex, &Table);
728 if (ACPI_SUCCESS (Status))
729 {
730 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_UNLOAD, Table,
731 AcpiGbl_TableHandlerContext);
732 }
733 }
734
735 /* Delete the portion of the namespace owned by this table */
736
737 Status = AcpiTbDeleteNamespaceByOwner (TableIndex);
738 if (ACPI_FAILURE (Status))
739 {
740 return_ACPI_STATUS (Status);
741 }
742
743 (void) AcpiTbReleaseOwnerId (TableIndex);
744 AcpiTbSetTableLoadedFlag (TableIndex, FALSE);
745
746 /*
747 * Invalidate the handle. We do this because the handle may be stored
748 * in a named object and may not be actually deleted until much later.
749 */
750 DdbHandle->Common.Flags &= ~AOPOBJ_DATA_VALID;
751 return_ACPI_STATUS (AE_OK);
752}
753
2 *
3 * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
4 *
5 *****************************************************************************/
6
7/******************************************************************************
8 *
9 * 1. Copyright Notice
10 *
11 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12 * All rights reserved.
13 *
14 * 2. License
15 *
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
20 *
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
27 *
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
36 *
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
39 *
40 * 3. Conditions
41 *
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
53 *
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
65 *
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
71 *
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
74 *
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
79 *
80 * 4. Disclaimer and Export Compliance
81 *
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
90 *
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
99 *
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
114 *
115 *****************************************************************************/
116
117#define __EXCONFIG_C__
118
119#include <contrib/dev/acpica/include/acpi.h>
120#include <contrib/dev/acpica/include/accommon.h>
121#include <contrib/dev/acpica/include/acinterp.h>
122#include <contrib/dev/acpica/include/acnamesp.h>
123#include <contrib/dev/acpica/include/actables.h>
124#include <contrib/dev/acpica/include/acdispat.h>
125#include <contrib/dev/acpica/include/acevents.h>
126
127
128#define _COMPONENT ACPI_EXECUTER
129 ACPI_MODULE_NAME ("exconfig")
130
131/* Local prototypes */
132
133static ACPI_STATUS
134AcpiExAddTable (
135 UINT32 TableIndex,
136 ACPI_NAMESPACE_NODE *ParentNode,
137 ACPI_OPERAND_OBJECT **DdbHandle);
138
139static ACPI_STATUS
140AcpiExRegionRead (
141 ACPI_OPERAND_OBJECT *ObjDesc,
142 UINT32 Length,
143 UINT8 *Buffer);
144
145
146/*******************************************************************************
147 *
148 * FUNCTION: AcpiExAddTable
149 *
150 * PARAMETERS: Table - Pointer to raw table
151 * ParentNode - Where to load the table (scope)
152 * DdbHandle - Where to return the table handle.
153 *
154 * RETURN: Status
155 *
156 * DESCRIPTION: Common function to Install and Load an ACPI table with a
157 * returned table handle.
158 *
159 ******************************************************************************/
160
161static ACPI_STATUS
162AcpiExAddTable (
163 UINT32 TableIndex,
164 ACPI_NAMESPACE_NODE *ParentNode,
165 ACPI_OPERAND_OBJECT **DdbHandle)
166{
167 ACPI_STATUS Status;
168 ACPI_OPERAND_OBJECT *ObjDesc;
169
170
171 ACPI_FUNCTION_TRACE (ExAddTable);
172
173
174 /* Create an object to be the table handle */
175
176 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
177 if (!ObjDesc)
178 {
179 return_ACPI_STATUS (AE_NO_MEMORY);
180 }
181
182 /* Init the table handle */
183
184 ObjDesc->Common.Flags |= AOPOBJ_DATA_VALID;
185 ObjDesc->Reference.Class = ACPI_REFCLASS_TABLE;
186 *DdbHandle = ObjDesc;
187
188 /* Install the new table into the local data structures */
189
190 ObjDesc->Reference.Value = TableIndex;
191
192 /* Add the table to the namespace */
193
194 Status = AcpiNsLoadTable (TableIndex, ParentNode);
195 if (ACPI_FAILURE (Status))
196 {
197 AcpiUtRemoveReference (ObjDesc);
198 *DdbHandle = NULL;
199 return_ACPI_STATUS (Status);
200 }
201
202 /* Execute any module-level code that was found in the table */
203
204 AcpiExExitInterpreter ();
205 AcpiNsExecModuleCodeList ();
206 AcpiExEnterInterpreter ();
207
208 return_ACPI_STATUS (Status);
209}
210
211
212/*******************************************************************************
213 *
214 * FUNCTION: AcpiExLoadTableOp
215 *
216 * PARAMETERS: WalkState - Current state with operands
217 * ReturnDesc - Where to store the return object
218 *
219 * RETURN: Status
220 *
221 * DESCRIPTION: Load an ACPI table from the RSDT/XSDT
222 *
223 ******************************************************************************/
224
225ACPI_STATUS
226AcpiExLoadTableOp (
227 ACPI_WALK_STATE *WalkState,
228 ACPI_OPERAND_OBJECT **ReturnDesc)
229{
230 ACPI_STATUS Status;
231 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
232 ACPI_NAMESPACE_NODE *ParentNode;
233 ACPI_NAMESPACE_NODE *StartNode;
234 ACPI_NAMESPACE_NODE *ParameterNode = NULL;
235 ACPI_OPERAND_OBJECT *DdbHandle;
236 ACPI_TABLE_HEADER *Table;
237 UINT32 TableIndex;
238
239
240 ACPI_FUNCTION_TRACE (ExLoadTableOp);
241
242
243 /* Validate lengths for the SignatureString, OEMIDString, OEMTableID */
244
245 if ((Operand[0]->String.Length > ACPI_NAME_SIZE) ||
246 (Operand[1]->String.Length > ACPI_OEM_ID_SIZE) ||
247 (Operand[2]->String.Length > ACPI_OEM_TABLE_ID_SIZE))
248 {
249 return_ACPI_STATUS (AE_BAD_PARAMETER);
250 }
251
252 /* Find the ACPI table in the RSDT/XSDT */
253
254 Status = AcpiTbFindTable (Operand[0]->String.Pointer,
255 Operand[1]->String.Pointer,
256 Operand[2]->String.Pointer, &TableIndex);
257 if (ACPI_FAILURE (Status))
258 {
259 if (Status != AE_NOT_FOUND)
260 {
261 return_ACPI_STATUS (Status);
262 }
263
264 /* Table not found, return an Integer=0 and AE_OK */
265
266 DdbHandle = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
267 if (!DdbHandle)
268 {
269 return_ACPI_STATUS (AE_NO_MEMORY);
270 }
271
272 DdbHandle->Integer.Value = 0;
273 *ReturnDesc = DdbHandle;
274
275 return_ACPI_STATUS (AE_OK);
276 }
277
278 /* Default nodes */
279
280 StartNode = WalkState->ScopeInfo->Scope.Node;
281 ParentNode = AcpiGbl_RootNode;
282
283 /* RootPath (optional parameter) */
284
285 if (Operand[3]->String.Length > 0)
286 {
287 /*
288 * Find the node referenced by the RootPathString. This is the
289 * location within the namespace where the table will be loaded.
290 */
291 Status = AcpiNsGetNode (StartNode, Operand[3]->String.Pointer,
292 ACPI_NS_SEARCH_PARENT, &ParentNode);
293 if (ACPI_FAILURE (Status))
294 {
295 return_ACPI_STATUS (Status);
296 }
297 }
298
299 /* ParameterPath (optional parameter) */
300
301 if (Operand[4]->String.Length > 0)
302 {
303 if ((Operand[4]->String.Pointer[0] != '\\') &&
304 (Operand[4]->String.Pointer[0] != '^'))
305 {
306 /*
307 * Path is not absolute, so it will be relative to the node
308 * referenced by the RootPathString (or the NS root if omitted)
309 */
310 StartNode = ParentNode;
311 }
312
313 /* Find the node referenced by the ParameterPathString */
314
315 Status = AcpiNsGetNode (StartNode, Operand[4]->String.Pointer,
316 ACPI_NS_SEARCH_PARENT, &ParameterNode);
317 if (ACPI_FAILURE (Status))
318 {
319 return_ACPI_STATUS (Status);
320 }
321 }
322
323 /* Load the table into the namespace */
324
325 Status = AcpiExAddTable (TableIndex, ParentNode, &DdbHandle);
326 if (ACPI_FAILURE (Status))
327 {
328 return_ACPI_STATUS (Status);
329 }
330
331 /* Parameter Data (optional) */
332
333 if (ParameterNode)
334 {
335 /* Store the parameter data into the optional parameter object */
336
337 Status = AcpiExStore (Operand[5],
338 ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode),
339 WalkState);
340 if (ACPI_FAILURE (Status))
341 {
342 (void) AcpiExUnloadTable (DdbHandle);
343
344 AcpiUtRemoveReference (DdbHandle);
345 return_ACPI_STATUS (Status);
346 }
347 }
348
349 Status = AcpiGetTableByIndex (TableIndex, &Table);
350 if (ACPI_SUCCESS (Status))
351 {
352 ACPI_INFO ((AE_INFO,
353 "Dynamic OEM Table Load - [%.4s] OemId [%.6s] OemTableId [%.8s]",
354 Table->Signature, Table->OemId, Table->OemTableId));
355 }
356
357 /* Invoke table handler if present */
358
359 if (AcpiGbl_TableHandler)
360 {
361 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, Table,
362 AcpiGbl_TableHandlerContext);
363 }
364
365 *ReturnDesc = DdbHandle;
366 return_ACPI_STATUS (Status);
367}
368
369
370/*******************************************************************************
371 *
372 * FUNCTION: AcpiExRegionRead
373 *
374 * PARAMETERS: ObjDesc - Region descriptor
375 * Length - Number of bytes to read
376 * Buffer - Pointer to where to put the data
377 *
378 * RETURN: Status
379 *
380 * DESCRIPTION: Read data from an operation region. The read starts from the
381 * beginning of the region.
382 *
383 ******************************************************************************/
384
385static ACPI_STATUS
386AcpiExRegionRead (
387 ACPI_OPERAND_OBJECT *ObjDesc,
388 UINT32 Length,
389 UINT8 *Buffer)
390{
391 ACPI_STATUS Status;
392 ACPI_INTEGER Value;
393 UINT32 RegionOffset = 0;
394 UINT32 i;
395
396
397 /* Bytewise reads */
398
399 for (i = 0; i < Length; i++)
400 {
401 Status = AcpiEvAddressSpaceDispatch (ObjDesc, ACPI_READ,
402 RegionOffset, 8, &Value);
403 if (ACPI_FAILURE (Status))
404 {
405 return (Status);
406 }
407
408 *Buffer = (UINT8) Value;
409 Buffer++;
410 RegionOffset++;
411 }
412
413 return (AE_OK);
414}
415
416
417/*******************************************************************************
418 *
419 * FUNCTION: AcpiExLoadOp
420 *
421 * PARAMETERS: ObjDesc - Region or Buffer/Field where the table will be
422 * obtained
423 * Target - Where a handle to the table will be stored
424 * WalkState - Current state
425 *
426 * RETURN: Status
427 *
428 * DESCRIPTION: Load an ACPI table from a field or operation region
429 *
430 * NOTE: Region Fields (Field, BankField, IndexFields) are resolved to buffer
431 * objects before this code is reached.
432 *
433 * If source is an operation region, it must refer to SystemMemory, as
434 * per the ACPI specification.
435 *
436 ******************************************************************************/
437
438ACPI_STATUS
439AcpiExLoadOp (
440 ACPI_OPERAND_OBJECT *ObjDesc,
441 ACPI_OPERAND_OBJECT *Target,
442 ACPI_WALK_STATE *WalkState)
443{
444 ACPI_OPERAND_OBJECT *DdbHandle;
445 ACPI_TABLE_HEADER *Table;
446 ACPI_TABLE_DESC TableDesc;
447 UINT32 TableIndex;
448 ACPI_STATUS Status;
449 UINT32 Length;
450
451
452 ACPI_FUNCTION_TRACE (ExLoadOp);
453
454
455 ACPI_MEMSET (&TableDesc, 0, sizeof (ACPI_TABLE_DESC));
456
457 /* Source Object can be either an OpRegion or a Buffer/Field */
458
459 switch (ObjDesc->Common.Type)
460 {
461 case ACPI_TYPE_REGION:
462
463 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
464 "Load table from Region %p\n", ObjDesc));
465
466 /* Region must be SystemMemory (from ACPI spec) */
467
468 if (ObjDesc->Region.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
469 {
470 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
471 }
472
473 /*
474 * If the Region Address and Length have not been previously evaluated,
475 * evaluate them now and save the results.
476 */
477 if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
478 {
479 Status = AcpiDsGetRegionArguments (ObjDesc);
480 if (ACPI_FAILURE (Status))
481 {
482 return_ACPI_STATUS (Status);
483 }
484 }
485
486 /* Get the table header first so we can get the table length */
487
488 Table = ACPI_ALLOCATE (sizeof (ACPI_TABLE_HEADER));
489 if (!Table)
490 {
491 return_ACPI_STATUS (AE_NO_MEMORY);
492 }
493
494 Status = AcpiExRegionRead (ObjDesc, sizeof (ACPI_TABLE_HEADER),
495 ACPI_CAST_PTR (UINT8, Table));
496 Length = Table->Length;
497 ACPI_FREE (Table);
498
499 if (ACPI_FAILURE (Status))
500 {
501 return_ACPI_STATUS (Status);
502 }
503
504 /* Must have at least an ACPI table header */
505
506 if (Length < sizeof (ACPI_TABLE_HEADER))
507 {
508 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
509 }
510
511 /*
512 * The original implementation simply mapped the table, with no copy.
513 * However, the memory region is not guaranteed to remain stable and
514 * we must copy the table to a local buffer. For example, the memory
515 * region is corrupted after suspend on some machines. Dynamically
516 * loaded tables are usually small, so this overhead is minimal.
517 *
518 * The latest implementation (5/2009) does not use a mapping at all.
519 * We use the low-level operation region interface to read the table
520 * instead of the obvious optimization of using a direct mapping.
521 * This maintains a consistent use of operation regions across the
522 * entire subsystem. This is important if additional processing must
523 * be performed in the (possibly user-installed) operation region
524 * handler. For example, AcpiExec and ASLTS depend on this.
525 */
526
527 /* Allocate a buffer for the table */
528
529 TableDesc.Pointer = ACPI_ALLOCATE (Length);
530 if (!TableDesc.Pointer)
531 {
532 return_ACPI_STATUS (AE_NO_MEMORY);
533 }
534
535 /* Read the entire table */
536
537 Status = AcpiExRegionRead (ObjDesc, Length,
538 ACPI_CAST_PTR (UINT8, TableDesc.Pointer));
539 if (ACPI_FAILURE (Status))
540 {
541 ACPI_FREE (TableDesc.Pointer);
542 return_ACPI_STATUS (Status);
543 }
544
545 TableDesc.Address = ObjDesc->Region.Address;
546 break;
547
548
549 case ACPI_TYPE_BUFFER: /* Buffer or resolved RegionField */
550
551 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
552 "Load table from Buffer or Field %p\n", ObjDesc));
553
554 /* Must have at least an ACPI table header */
555
556 if (ObjDesc->Buffer.Length < sizeof (ACPI_TABLE_HEADER))
557 {
558 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
559 }
560
561 /* Get the actual table length from the table header */
562
563 Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, ObjDesc->Buffer.Pointer);
564 Length = Table->Length;
565
566 /* Table cannot extend beyond the buffer */
567
568 if (Length > ObjDesc->Buffer.Length)
569 {
570 return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
571 }
572 if (Length < sizeof (ACPI_TABLE_HEADER))
573 {
574 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
575 }
576
577 /*
578 * Copy the table from the buffer because the buffer could be modified
579 * or even deleted in the future
580 */
581 TableDesc.Pointer = ACPI_ALLOCATE (Length);
582 if (!TableDesc.Pointer)
583 {
584 return_ACPI_STATUS (AE_NO_MEMORY);
585 }
586
587 ACPI_MEMCPY (TableDesc.Pointer, Table, Length);
588 TableDesc.Address = ACPI_TO_INTEGER (TableDesc.Pointer);
589 break;
590
591
592 default:
593 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
594 }
595
596 /* Validate table checksum (will not get validated in TbAddTable) */
597
598 Status = AcpiTbVerifyChecksum (TableDesc.Pointer, Length);
599 if (ACPI_FAILURE (Status))
600 {
601 ACPI_FREE (TableDesc.Pointer);
602 return_ACPI_STATUS (Status);
603 }
604
605 /* Complete the table descriptor */
606
607 TableDesc.Length = Length;
608 TableDesc.Flags = ACPI_TABLE_ORIGIN_ALLOCATED;
609
610 /* Install the new table into the local data structures */
611
612 Status = AcpiTbAddTable (&TableDesc, &TableIndex);
613 if (ACPI_FAILURE (Status))
614 {
615 goto Cleanup;
616 }
617
618 /*
619 * Add the table to the namespace.
620 *
621 * Note: Load the table objects relative to the root of the namespace.
622 * This appears to go against the ACPI specification, but we do it for
623 * compatibility with other ACPI implementations.
624 */
625 Status = AcpiExAddTable (TableIndex, AcpiGbl_RootNode, &DdbHandle);
626 if (ACPI_FAILURE (Status))
627 {
628 /* On error, TablePtr was deallocated above */
629
630 return_ACPI_STATUS (Status);
631 }
632
633 /* Store the DdbHandle into the Target operand */
634
635 Status = AcpiExStore (DdbHandle, Target, WalkState);
636 if (ACPI_FAILURE (Status))
637 {
638 (void) AcpiExUnloadTable (DdbHandle);
639
640 /* TablePtr was deallocated above */
641
642 AcpiUtRemoveReference (DdbHandle);
643 return_ACPI_STATUS (Status);
644 }
645
646 /* Remove the reference by added by AcpiExStore above */
647
648 AcpiUtRemoveReference (DdbHandle);
649
650 /* Invoke table handler if present */
651
652 if (AcpiGbl_TableHandler)
653 {
654 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, TableDesc.Pointer,
655 AcpiGbl_TableHandlerContext);
656 }
657
658Cleanup:
659 if (ACPI_FAILURE (Status))
660 {
661 /* Delete allocated table buffer */
662
663 AcpiTbDeleteTable (&TableDesc);
664 }
665 return_ACPI_STATUS (Status);
666}
667
668
669/*******************************************************************************
670 *
671 * FUNCTION: AcpiExUnloadTable
672 *
673 * PARAMETERS: DdbHandle - Handle to a previously loaded table
674 *
675 * RETURN: Status
676 *
677 * DESCRIPTION: Unload an ACPI table
678 *
679 ******************************************************************************/
680
681ACPI_STATUS
682AcpiExUnloadTable (
683 ACPI_OPERAND_OBJECT *DdbHandle)
684{
685 ACPI_STATUS Status = AE_OK;
686 ACPI_OPERAND_OBJECT *TableDesc = DdbHandle;
687 UINT32 TableIndex;
688 ACPI_TABLE_HEADER *Table;
689
690
691 ACPI_FUNCTION_TRACE (ExUnloadTable);
692
693
694 /*
695 * Validate the handle
696 * Although the handle is partially validated in AcpiExReconfiguration()
697 * when it calls AcpiExResolveOperands(), the handle is more completely
698 * validated here.
699 *
700 * Handle must be a valid operand object of type reference. Also, the
701 * DdbHandle must still be marked valid (table has not been previously
702 * unloaded)
703 */
704 if ((!DdbHandle) ||
705 (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle) != ACPI_DESC_TYPE_OPERAND) ||
706 (DdbHandle->Common.Type != ACPI_TYPE_LOCAL_REFERENCE) ||
707 (!(DdbHandle->Common.Flags & AOPOBJ_DATA_VALID)))
708 {
709 return_ACPI_STATUS (AE_BAD_PARAMETER);
710 }
711
712 /* Get the table index from the DdbHandle */
713
714 TableIndex = TableDesc->Reference.Value;
715
716 /* Ensure the table is still loaded */
717
718 if (!AcpiTbIsTableLoaded (TableIndex))
719 {
720 return_ACPI_STATUS (AE_NOT_EXIST);
721 }
722
723 /* Invoke table handler if present */
724
725 if (AcpiGbl_TableHandler)
726 {
727 Status = AcpiGetTableByIndex (TableIndex, &Table);
728 if (ACPI_SUCCESS (Status))
729 {
730 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_UNLOAD, Table,
731 AcpiGbl_TableHandlerContext);
732 }
733 }
734
735 /* Delete the portion of the namespace owned by this table */
736
737 Status = AcpiTbDeleteNamespaceByOwner (TableIndex);
738 if (ACPI_FAILURE (Status))
739 {
740 return_ACPI_STATUS (Status);
741 }
742
743 (void) AcpiTbReleaseOwnerId (TableIndex);
744 AcpiTbSetTableLoadedFlag (TableIndex, FALSE);
745
746 /*
747 * Invalidate the handle. We do this because the handle may be stored
748 * in a named object and may not be actually deleted until much later.
749 */
750 DdbHandle->Common.Flags &= ~AOPOBJ_DATA_VALID;
751 return_ACPI_STATUS (AE_OK);
752}
753