exconfig.c revision 85756
1/******************************************************************************
2 *
3 * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
4 *              $Revision: 44 $
5 *
6 *****************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, 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 "acpi.h"
121#include "acparser.h"
122#include "acinterp.h"
123#include "amlcode.h"
124#include "acnamesp.h"
125#include "acevents.h"
126#include "actables.h"
127#include "acdispat.h"
128
129
130#define _COMPONENT          ACPI_EXECUTER
131        MODULE_NAME         ("exconfig")
132
133
134/*****************************************************************************
135 *
136 * FUNCTION:    AcpiExLoadTableOp
137 *
138 * PARAMETERS:  RgnDesc         - Op region where the table will be obtained
139 *              DdbHandle       - Where a handle to the table will be returned
140 *
141 * RETURN:      Status
142 *
143 * DESCRIPTION: Load an ACPI table
144 *
145 ****************************************************************************/
146
147ACPI_STATUS
148AcpiExLoadOp (
149    ACPI_OPERAND_OBJECT     *RgnDesc,
150    ACPI_OPERAND_OBJECT     *DdbHandle)
151{
152    ACPI_STATUS             Status;
153    ACPI_OPERAND_OBJECT     *TableDesc = NULL;
154    UINT8                   *TablePtr;
155    UINT8                   *TableDataPtr;
156    ACPI_TABLE_HEADER       TableHeader;
157    ACPI_TABLE_DESC         TableInfo;
158    UINT32                  i;
159
160
161    FUNCTION_TRACE ("ExLoadOp");
162
163    /* TBD: [Unhandled] Object can be either a field or an opregion */
164
165
166    /* Get the table header */
167
168    TableHeader.Length = 0;
169    for (i = 0; i < sizeof (ACPI_TABLE_HEADER); i++)
170    {
171        Status = AcpiEvAddressSpaceDispatch (RgnDesc, ACPI_READ_ADR_SPACE,
172                            (ACPI_PHYSICAL_ADDRESS) i, 8,
173                            (UINT32 *) ((UINT8 *) &TableHeader + i));
174        if (ACPI_FAILURE (Status))
175        {
176            return_ACPI_STATUS (Status);
177        }
178    }
179
180    /* Allocate a buffer for the entire table */
181
182    TablePtr = ACPI_MEM_ALLOCATE (TableHeader.Length);
183    if (!TablePtr)
184    {
185        return_ACPI_STATUS (AE_NO_MEMORY);
186    }
187
188    /* Copy the header to the buffer */
189
190    MEMCPY (TablePtr, &TableHeader, sizeof (ACPI_TABLE_HEADER));
191    TableDataPtr = TablePtr + sizeof (ACPI_TABLE_HEADER);
192
193
194    /* Get the table from the op region */
195
196    for (i = 0; i < TableHeader.Length; i++)
197    {
198        Status = AcpiEvAddressSpaceDispatch (RgnDesc, ACPI_READ_ADR_SPACE,
199                            (ACPI_PHYSICAL_ADDRESS) i, 8,
200                            (UINT32 *) (TableDataPtr + i));
201        if (ACPI_FAILURE (Status))
202        {
203            goto Cleanup;
204        }
205    }
206
207
208    /* Table must be either an SSDT or a PSDT */
209
210    if ((!STRNCMP (TableHeader.Signature,
211                    AcpiGbl_AcpiTableData[ACPI_TABLE_PSDT].Signature,
212                    AcpiGbl_AcpiTableData[ACPI_TABLE_PSDT].SigLength)) &&
213        (!STRNCMP (TableHeader.Signature,
214                    AcpiGbl_AcpiTableData[ACPI_TABLE_SSDT].Signature,
215                    AcpiGbl_AcpiTableData[ACPI_TABLE_SSDT].SigLength)))
216    {
217        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
218            "Table has invalid signature [%4.4s], must be SSDT or PSDT\n",
219            (char*)TableHeader.Signature));
220        Status = AE_BAD_SIGNATURE;
221        goto Cleanup;
222    }
223
224    /* Create an object to be the table handle */
225
226    TableDesc = AcpiUtCreateInternalObject (INTERNAL_TYPE_REFERENCE);
227    if (!TableDesc)
228    {
229        Status = AE_NO_MEMORY;
230        goto Cleanup;
231    }
232
233
234    /* Install the new table into the local data structures */
235
236    TableInfo.Pointer      = (ACPI_TABLE_HEADER *) TablePtr;
237    TableInfo.Length       = TableHeader.Length;
238    TableInfo.Allocation   = ACPI_MEM_ALLOCATED;
239    TableInfo.BasePointer  = TablePtr;
240
241    Status = AcpiTbInstallTable (NULL, &TableInfo);
242    if (ACPI_FAILURE (Status))
243    {
244        goto Cleanup;
245    }
246
247    /* Add the table to the namespace */
248
249    /* TBD: [Restructure] - change to whatever new interface is appropriate */
250/*
251    Status = AcpiLoadNamespace ();
252    if (ACPI_FAILURE (Status))
253    {
254*/
255        /* TBD: [Errors] Unload the table on failure ? */
256/*
257        goto Cleanup;
258    }
259*/
260
261
262    /* TBD: [Investigate] we need a pointer to the table desc */
263
264    /* Init the table handle */
265
266    TableDesc->Reference.Opcode = AML_LOAD_OP;
267    TableDesc->Reference.Object = TableInfo.InstalledDesc;
268
269    /* TBD: store the tabledesc into the DdbHandle target */
270    /* DdbHandle = TableDesc; */
271
272    return_ACPI_STATUS (Status);
273
274
275Cleanup:
276
277    ACPI_MEM_FREE (TableDesc);
278    ACPI_MEM_FREE (TablePtr);
279    return_ACPI_STATUS (Status);
280}
281
282
283/*****************************************************************************
284 *
285 * FUNCTION:    AcpiExUnloadTable
286 *
287 * PARAMETERS:  DdbHandle           - Handle to a previously loaded table
288 *
289 * RETURN:      Status
290 *
291 * DESCRIPTION: Unload an ACPI table
292 *
293 ****************************************************************************/
294
295ACPI_STATUS
296AcpiExUnloadTable (
297    ACPI_OPERAND_OBJECT     *DdbHandle)
298{
299    ACPI_STATUS             Status = AE_NOT_IMPLEMENTED;
300    ACPI_OPERAND_OBJECT     *TableDesc = DdbHandle;
301    ACPI_TABLE_DESC         *TableInfo;
302
303
304    FUNCTION_TRACE ("ExUnloadTable");
305
306
307    /*
308     * Validate the handle
309     * Although the handle is partially validated in AcpiExReconfiguration(),
310     * when it calls AcpiExResolveOperands(), the handle is more completely
311     * validated here.
312     */
313    if ((!DdbHandle) ||
314        (!VALID_DESCRIPTOR_TYPE (DdbHandle, ACPI_DESC_TYPE_INTERNAL)) ||
315        (((ACPI_OPERAND_OBJECT  *)DdbHandle)->Common.Type !=
316                INTERNAL_TYPE_REFERENCE))
317    {
318        return_ACPI_STATUS (AE_BAD_PARAMETER);
319    }
320
321    /* Get the actual table descriptor from the DdbHandle */
322
323    TableInfo = (ACPI_TABLE_DESC *) TableDesc->Reference.Object;
324
325    /*
326     * Delete the entire namespace under this table Node
327     * (Offset contains the TableId)
328     */
329    Status = AcpiNsDeleteNamespaceByOwner (TableInfo->TableId);
330    if (ACPI_FAILURE (Status))
331    {
332        return_ACPI_STATUS (Status);
333    }
334
335    /* Delete the table itself */
336
337    AcpiTbUninstallTable (TableInfo->InstalledDesc);
338
339    /* Delete the table descriptor (DdbHandle) */
340
341    AcpiUtRemoveReference (TableDesc);
342
343    return_ACPI_STATUS (Status);
344}
345
346