]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/contrib/dev/acpica/exconfig.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / contrib / dev / acpica / exconfig.c
1 /******************************************************************************
2  *
3  * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
4  *              $Revision: 1.103 $
5  *
6  *****************************************************************************/
7
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
17  * 2.1. This is your license from Intel Corp. under its intellectual property
18  * rights.  You may have additional license terms from the party that provided
19  * you this software, covering your right to use that party's intellectual
20  * property rights.
21  *
22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23  * copy of the source code appearing in this file ("Covered Code") an
24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25  * base code distributed originally by Intel ("Original Intel Code") to copy,
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code.  No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision.  In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change.  Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee.  Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution.  In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87
88  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
89  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90  * PARTICULAR PURPOSE.
91  *
92  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
98  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99  * LIMITED REMEDY.
100  *
101  * 4.3. Licensee shall not export, either directly or indirectly, any of this
102  * software or system incorporating such software without first obtaining any
103  * required license or other approval from the U. S. Department of Commerce or
104  * any other agency or department of the United States Government.  In the
105  * event Licensee exports any such software from the United States or
106  * re-exports any such software from a foreign destination, Licensee shall
107  * ensure that the distribution and export/re-export of the software is in
108  * compliance with all laws, regulations, orders, or other restrictions of the
109  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110  * any of its subsidiaries will export/re-export any technical data, process,
111  * software, or service, directly or indirectly, to any country for which the
112  * United States government or any agency thereof requires an export license,
113  * other governmental approval, or letter of assurance, without first obtaining
114  * such license, approval or letter.
115  *
116  *****************************************************************************/
117
118 #define __EXCONFIG_C__
119
120 #include <contrib/dev/acpica/acpi.h>
121 #include <contrib/dev/acpica/acinterp.h>
122 #include <contrib/dev/acpica/amlcode.h>
123 #include <contrib/dev/acpica/acnamesp.h>
124 #include <contrib/dev/acpica/acevents.h>
125 #include <contrib/dev/acpica/actables.h>
126 #include <contrib/dev/acpica/acdispat.h>
127
128
129 #define _COMPONENT          ACPI_EXECUTER
130         ACPI_MODULE_NAME    ("exconfig")
131
132 /* Local prototypes */
133
134 static ACPI_STATUS
135 AcpiExAddTable (
136     ACPI_NATIVE_UINT        TableIndex,
137     ACPI_NAMESPACE_NODE     *ParentNode,
138     ACPI_OPERAND_OBJECT     **DdbHandle);
139
140
141 /*******************************************************************************
142  *
143  * FUNCTION:    AcpiExAddTable
144  *
145  * PARAMETERS:  Table               - Pointer to raw table
146  *              ParentNode          - Where to load the table (scope)
147  *              DdbHandle           - Where to return the table handle.
148  *
149  * RETURN:      Status
150  *
151  * DESCRIPTION: Common function to Install and Load an ACPI table with a
152  *              returned table handle.
153  *
154  ******************************************************************************/
155
156 static ACPI_STATUS
157 AcpiExAddTable (
158     ACPI_NATIVE_UINT        TableIndex,
159     ACPI_NAMESPACE_NODE     *ParentNode,
160     ACPI_OPERAND_OBJECT     **DdbHandle)
161 {
162     ACPI_STATUS             Status;
163     ACPI_OPERAND_OBJECT     *ObjDesc;
164
165
166     ACPI_FUNCTION_TRACE (ExAddTable);
167
168
169     /* Create an object to be the table handle */
170
171     ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
172     if (!ObjDesc)
173     {
174         return_ACPI_STATUS (AE_NO_MEMORY);
175     }
176
177     /* Init the table handle */
178
179     ObjDesc->Reference.Opcode = AML_LOAD_OP;
180     *DdbHandle = ObjDesc;
181
182     /* Install the new table into the local data structures */
183
184     ObjDesc->Reference.Object = ACPI_CAST_PTR (void, TableIndex);
185
186     /* Add the table to the namespace */
187
188     Status = AcpiNsLoadTable (TableIndex, ParentNode);
189     if (ACPI_FAILURE (Status))
190     {
191         AcpiUtRemoveReference (ObjDesc);
192         *DdbHandle = NULL;
193     }
194
195     return_ACPI_STATUS (Status);
196 }
197
198
199 /*******************************************************************************
200  *
201  * FUNCTION:    AcpiExLoadTableOp
202  *
203  * PARAMETERS:  WalkState           - Current state with operands
204  *              ReturnDesc          - Where to store the return object
205  *
206  * RETURN:      Status
207  *
208  * DESCRIPTION: Load an ACPI table from the RSDT/XSDT
209  *
210  ******************************************************************************/
211
212 ACPI_STATUS
213 AcpiExLoadTableOp (
214     ACPI_WALK_STATE         *WalkState,
215     ACPI_OPERAND_OBJECT     **ReturnDesc)
216 {
217     ACPI_STATUS             Status;
218     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
219     ACPI_NATIVE_UINT        TableIndex;
220     ACPI_NAMESPACE_NODE     *ParentNode;
221     ACPI_NAMESPACE_NODE     *StartNode;
222     ACPI_NAMESPACE_NODE     *ParameterNode = NULL;
223     ACPI_OPERAND_OBJECT     *DdbHandle;
224     ACPI_TABLE_HEADER       *Table;
225
226
227     ACPI_FUNCTION_TRACE (ExLoadTableOp);
228
229
230     /* Find the ACPI table in the RSDT/XSDT */
231
232     Status = AcpiTbFindTable (Operand[0]->String.Pointer,
233                               Operand[1]->String.Pointer,
234                               Operand[2]->String.Pointer, &TableIndex);
235     if (ACPI_FAILURE (Status))
236     {
237         if (Status != AE_NOT_FOUND)
238         {
239             return_ACPI_STATUS (Status);
240         }
241
242         /* Table not found, return an Integer=0 and AE_OK */
243
244         DdbHandle = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
245         if (!DdbHandle)
246         {
247             return_ACPI_STATUS (AE_NO_MEMORY);
248         }
249
250         DdbHandle->Integer.Value = 0;
251         *ReturnDesc = DdbHandle;
252
253         return_ACPI_STATUS (AE_OK);
254     }
255
256     /* Default nodes */
257
258     StartNode = WalkState->ScopeInfo->Scope.Node;
259     ParentNode = AcpiGbl_RootNode;
260
261     /* RootPath (optional parameter) */
262
263     if (Operand[3]->String.Length > 0)
264     {
265         /*
266          * Find the node referenced by the RootPathString.  This is the
267          * location within the namespace where the table will be loaded.
268          */
269         Status = AcpiNsGetNode (StartNode, Operand[3]->String.Pointer,
270                     ACPI_NS_SEARCH_PARENT, &ParentNode);
271         if (ACPI_FAILURE (Status))
272         {
273             return_ACPI_STATUS (Status);
274         }
275     }
276
277     /* ParameterPath (optional parameter) */
278
279     if (Operand[4]->String.Length > 0)
280     {
281         if ((Operand[4]->String.Pointer[0] != '\\') &&
282             (Operand[4]->String.Pointer[0] != '^'))
283         {
284             /*
285              * Path is not absolute, so it will be relative to the node
286              * referenced by the RootPathString (or the NS root if omitted)
287              */
288             StartNode = ParentNode;
289         }
290
291         /* Find the node referenced by the ParameterPathString */
292
293         Status = AcpiNsGetNode (StartNode, Operand[4]->String.Pointer,
294                     ACPI_NS_SEARCH_PARENT, &ParameterNode);
295         if (ACPI_FAILURE (Status))
296         {
297             return_ACPI_STATUS (Status);
298         }
299     }
300
301     /* Load the table into the namespace */
302
303     Status = AcpiExAddTable (TableIndex, ParentNode, &DdbHandle);
304     if (ACPI_FAILURE (Status))
305     {
306         return_ACPI_STATUS (Status);
307     }
308
309     /* Parameter Data (optional) */
310
311     if (ParameterNode)
312     {
313         /* Store the parameter data into the optional parameter object */
314
315         Status = AcpiExStore (Operand[5],
316                     ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode),
317                     WalkState);
318         if (ACPI_FAILURE (Status))
319         {
320             (void) AcpiExUnloadTable (DdbHandle);
321             return_ACPI_STATUS (Status);
322         }
323     }
324
325     Status = AcpiGetTableByIndex (TableIndex, &Table);
326     if (ACPI_SUCCESS (Status))
327     {
328         ACPI_INFO ((AE_INFO,
329             "Dynamic OEM Table Load - [%4.4s] OemId [%6.6s] OemTableId [%8.8s]",
330             Table->Signature, Table->OemId, Table->OemTableId));
331     }
332
333     *ReturnDesc = DdbHandle;
334     return_ACPI_STATUS  (Status);
335 }
336
337
338 /*******************************************************************************
339  *
340  * FUNCTION:    AcpiExLoadOp
341  *
342  * PARAMETERS:  ObjDesc         - Region or Buffer/Field where the table will be
343  *                                obtained
344  *              Target          - Where a handle to the table will be stored
345  *              WalkState       - Current state
346  *
347  * RETURN:      Status
348  *
349  * DESCRIPTION: Load an ACPI table from a field or operation region
350  *
351  * NOTE: Region Fields (Field, BankField, IndexFields) are resolved to buffer
352  *       objects before this code is reached.
353  *
354  *       If source is an operation region, it must refer to SystemMemory, as
355  *       per the ACPI specification.
356  *
357  ******************************************************************************/
358
359 ACPI_STATUS
360 AcpiExLoadOp (
361     ACPI_OPERAND_OBJECT     *ObjDesc,
362     ACPI_OPERAND_OBJECT     *Target,
363     ACPI_WALK_STATE         *WalkState)
364 {
365     ACPI_OPERAND_OBJECT     *DdbHandle;
366     ACPI_TABLE_DESC         TableDesc;
367     ACPI_NATIVE_UINT        TableIndex;
368     ACPI_STATUS             Status;
369
370
371     ACPI_FUNCTION_TRACE (ExLoadOp);
372
373
374     ACPI_MEMSET (&TableDesc, 0, sizeof (ACPI_TABLE_DESC));
375     TableDesc.Flags = ACPI_TABLE_ORIGIN_ALLOCATED;
376
377     /* Source Object can be either an OpRegion or a Buffer/Field */
378
379     switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
380     {
381     case ACPI_TYPE_REGION:
382
383         /* Region must be SystemMemory (from ACPI spec) */
384
385         if (ObjDesc->Region.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
386         {
387             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
388         }
389
390         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Load from Region %p %s\n",
391             ObjDesc, AcpiUtGetObjectTypeName (ObjDesc)));
392
393         /*
394          * If the Region Address and Length have not been previously evaluated,
395          * evaluate them now and save the results.
396          */
397         if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
398         {
399             Status = AcpiDsGetRegionArguments (ObjDesc);
400             if (ACPI_FAILURE (Status))
401             {
402                 return_ACPI_STATUS (Status);
403             }
404         }
405
406         TableDesc.Address = ObjDesc->Region.Address;
407         TableDesc.Length = ObjDesc->Region.Length;
408         TableDesc.Flags = ACPI_TABLE_ORIGIN_MAPPED;
409         break;
410
411     case ACPI_TYPE_BUFFER: /* Buffer or resolved RegionField */
412
413         /* Simply extract the buffer from the buffer object */
414
415         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Load from Buffer or Field %p %s\n",
416             ObjDesc, AcpiUtGetObjectTypeName (ObjDesc)));
417
418         TableDesc.Pointer = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
419             ObjDesc->Buffer.Pointer);
420         TableDesc.Length = TableDesc.Pointer->Length;
421         TableDesc.Flags = ACPI_TABLE_ORIGIN_ALLOCATED;
422
423         ObjDesc->Buffer.Pointer = NULL;
424         break;
425
426     default:
427         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
428     }
429
430     /*
431      * Install the new table into the local data structures
432      */
433     Status = AcpiTbAddTable (&TableDesc, &TableIndex);
434     if (ACPI_FAILURE (Status))
435     {
436         goto Cleanup;
437     }
438
439     Status = AcpiExAddTable (TableIndex, AcpiGbl_RootNode, &DdbHandle);
440     if (ACPI_FAILURE (Status))
441     {
442         /* On error, TablePtr was deallocated above */
443
444         return_ACPI_STATUS (Status);
445     }
446
447     /* Store the DdbHandle into the Target operand */
448
449     Status = AcpiExStore (DdbHandle, Target, WalkState);
450     if (ACPI_FAILURE (Status))
451     {
452         (void) AcpiExUnloadTable (DdbHandle);
453
454         /* TablePtr was deallocated above */
455
456         return_ACPI_STATUS (Status);
457     }
458
459 Cleanup:
460     if (ACPI_FAILURE (Status))
461     {
462         AcpiTbDeleteTable (&TableDesc);
463     }
464     return_ACPI_STATUS (Status);
465 }
466
467
468 /*******************************************************************************
469  *
470  * FUNCTION:    AcpiExUnloadTable
471  *
472  * PARAMETERS:  DdbHandle           - Handle to a previously loaded table
473  *
474  * RETURN:      Status
475  *
476  * DESCRIPTION: Unload an ACPI table
477  *
478  ******************************************************************************/
479
480 ACPI_STATUS
481 AcpiExUnloadTable (
482     ACPI_OPERAND_OBJECT     *DdbHandle)
483 {
484     ACPI_STATUS             Status = AE_OK;
485     ACPI_OPERAND_OBJECT     *TableDesc = DdbHandle;
486     ACPI_NATIVE_UINT        TableIndex;
487
488
489     ACPI_FUNCTION_TRACE (ExUnloadTable);
490
491
492     /*
493      * Validate the handle
494      * Although the handle is partially validated in AcpiExReconfiguration(),
495      * when it calls AcpiExResolveOperands(), the handle is more completely
496      * validated here.
497      */
498     if ((!DdbHandle) ||
499         (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle) != ACPI_DESC_TYPE_OPERAND) ||
500         (ACPI_GET_OBJECT_TYPE (DdbHandle) != ACPI_TYPE_LOCAL_REFERENCE))
501     {
502         return_ACPI_STATUS (AE_BAD_PARAMETER);
503     }
504
505     /* Get the table index from the DdbHandle */
506
507     TableIndex = (ACPI_NATIVE_UINT) TableDesc->Reference.Object;
508
509     /*
510      * Delete the entire namespace under this table Node
511      * (Offset contains the TableId)
512      */
513     AcpiTbDeleteNamespaceByOwner (TableIndex);
514     AcpiTbReleaseOwnerId (TableIndex);
515
516     AcpiTbSetTableLoadedFlag (TableIndex, FALSE);
517
518     /* Delete the table descriptor (DdbHandle) */
519
520     AcpiUtRemoveReference (TableDesc);
521     return_ACPI_STATUS (Status);
522 }
523