]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/acpi/acpica/tbxfload.c
arm: imx6: defconfig: update tx6 defconfigs
[karo-tx-linux.git] / drivers / acpi / acpica / tbxfload.c
1 /******************************************************************************
2  *
3  * Module Name: tbxfload - Table load/unload external interfaces
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2013, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions, and the following disclaimer,
16  *    without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  *    substantially similar to the "NO WARRANTY" disclaimer below
19  *    ("Disclaimer") and any redistribution must be conditioned upon
20  *    including a substantially similar Disclaimer requirement for further
21  *    binary redistribution.
22  * 3. Neither the names of the above-listed copyright holders nor the names
23  *    of any contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * NO WARRANTY
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41  * POSSIBILITY OF SUCH DAMAGES.
42  */
43
44 #include <linux/export.h>
45 #include <acpi/acpi.h>
46 #include "accommon.h"
47 #include "acnamesp.h"
48 #include "actables.h"
49
50 #define _COMPONENT          ACPI_TABLES
51 ACPI_MODULE_NAME("tbxfload")
52
53 /* Local prototypes */
54 static acpi_status acpi_tb_load_namespace(void);
55
56 /*******************************************************************************
57  *
58  * FUNCTION:    acpi_load_tables
59  *
60  * PARAMETERS:  None
61  *
62  * RETURN:      Status
63  *
64  * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
65  *
66  ******************************************************************************/
67
68 acpi_status acpi_load_tables(void)
69 {
70         acpi_status status;
71
72         ACPI_FUNCTION_TRACE(acpi_load_tables);
73
74         /* Load the namespace from the tables */
75
76         status = acpi_tb_load_namespace();
77         if (ACPI_FAILURE(status)) {
78                 ACPI_EXCEPTION((AE_INFO, status,
79                                 "While loading namespace from ACPI tables"));
80         }
81
82         return_ACPI_STATUS(status);
83 }
84
85 ACPI_EXPORT_SYMBOL(acpi_load_tables)
86
87 /*******************************************************************************
88  *
89  * FUNCTION:    acpi_tb_load_namespace
90  *
91  * PARAMETERS:  None
92  *
93  * RETURN:      Status
94  *
95  * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
96  *              the RSDT/XSDT.
97  *
98  ******************************************************************************/
99 static acpi_status acpi_tb_load_namespace(void)
100 {
101         acpi_status status;
102         u32 i;
103         struct acpi_table_header *new_dsdt;
104
105         ACPI_FUNCTION_TRACE(tb_load_namespace);
106
107         (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
108
109         /*
110          * Load the namespace. The DSDT is required, but any SSDT and
111          * PSDT tables are optional. Verify the DSDT.
112          */
113         if (!acpi_gbl_root_table_list.current_table_count ||
114             !ACPI_COMPARE_NAME(&
115                                (acpi_gbl_root_table_list.
116                                 tables[ACPI_TABLE_INDEX_DSDT].signature),
117                                ACPI_SIG_DSDT)
118             ||
119             ACPI_FAILURE(acpi_tb_verify_table
120                          (&acpi_gbl_root_table_list.
121                           tables[ACPI_TABLE_INDEX_DSDT]))) {
122                 status = AE_NO_ACPI_TABLES;
123                 goto unlock_and_exit;
124         }
125
126         /*
127          * Save the DSDT pointer for simple access. This is the mapped memory
128          * address. We must take care here because the address of the .Tables
129          * array can change dynamically as tables are loaded at run-time. Note:
130          * .Pointer field is not validated until after call to acpi_tb_verify_table.
131          */
132         acpi_gbl_DSDT =
133             acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].pointer;
134
135         /*
136          * Optionally copy the entire DSDT to local memory (instead of simply
137          * mapping it.) There are some BIOSs that corrupt or replace the original
138          * DSDT, creating the need for this option. Default is FALSE, do not copy
139          * the DSDT.
140          */
141         if (acpi_gbl_copy_dsdt_locally) {
142                 new_dsdt = acpi_tb_copy_dsdt(ACPI_TABLE_INDEX_DSDT);
143                 if (new_dsdt) {
144                         acpi_gbl_DSDT = new_dsdt;
145                 }
146         }
147
148         /*
149          * Save the original DSDT header for detection of table corruption
150          * and/or replacement of the DSDT from outside the OS.
151          */
152         ACPI_MEMCPY(&acpi_gbl_original_dsdt_header, acpi_gbl_DSDT,
153                     sizeof(struct acpi_table_header));
154
155         (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
156
157         /* Load and parse tables */
158
159         status = acpi_ns_load_table(ACPI_TABLE_INDEX_DSDT, acpi_gbl_root_node);
160         if (ACPI_FAILURE(status)) {
161                 return_ACPI_STATUS(status);
162         }
163
164         /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
165
166         (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
167         for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
168                 if ((!ACPI_COMPARE_NAME
169                      (&(acpi_gbl_root_table_list.tables[i].signature),
170                       ACPI_SIG_SSDT)
171                      &&
172                      !ACPI_COMPARE_NAME(&
173                                         (acpi_gbl_root_table_list.tables[i].
174                                          signature), ACPI_SIG_PSDT))
175                     ||
176                     ACPI_FAILURE(acpi_tb_verify_table
177                                  (&acpi_gbl_root_table_list.tables[i]))) {
178                         continue;
179                 }
180
181                 /*
182                  * Optionally do not load any SSDTs from the RSDT/XSDT. This can
183                  * be useful for debugging ACPI problems on some machines.
184                  */
185                 if (acpi_gbl_disable_ssdt_table_load) {
186                         ACPI_INFO((AE_INFO, "Ignoring %4.4s at %p",
187                                    acpi_gbl_root_table_list.tables[i].signature.
188                                    ascii, ACPI_CAST_PTR(void,
189                                                         acpi_gbl_root_table_list.
190                                                         tables[i].address)));
191                         continue;
192                 }
193
194                 /* Ignore errors while loading tables, get as many as possible */
195
196                 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
197                 (void)acpi_ns_load_table(i, acpi_gbl_root_node);
198                 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
199         }
200
201         ACPI_INFO((AE_INFO, "All ACPI Tables successfully acquired"));
202
203       unlock_and_exit:
204         (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
205         return_ACPI_STATUS(status);
206 }
207
208 /*******************************************************************************
209  *
210  * FUNCTION:    acpi_load_table
211  *
212  * PARAMETERS:  table               - Pointer to a buffer containing the ACPI
213  *                                    table to be loaded.
214  *
215  * RETURN:      Status
216  *
217  * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
218  *              be a valid ACPI table with a valid ACPI table header.
219  *              Note1: Mainly intended to support hotplug addition of SSDTs.
220  *              Note2: Does not copy the incoming table. User is responsible
221  *              to ensure that the table is not deleted or unmapped.
222  *
223  ******************************************************************************/
224
225 acpi_status acpi_load_table(struct acpi_table_header *table)
226 {
227         acpi_status status;
228         struct acpi_table_desc table_desc;
229         u32 table_index;
230
231         ACPI_FUNCTION_TRACE(acpi_load_table);
232
233         /* Parameter validation */
234
235         if (!table) {
236                 return_ACPI_STATUS(AE_BAD_PARAMETER);
237         }
238
239         /* Init local table descriptor */
240
241         ACPI_MEMSET(&table_desc, 0, sizeof(struct acpi_table_desc));
242         table_desc.address = ACPI_PTR_TO_PHYSADDR(table);
243         table_desc.pointer = table;
244         table_desc.length = table->length;
245         table_desc.flags = ACPI_TABLE_ORIGIN_UNKNOWN;
246
247         /* Must acquire the interpreter lock during this operation */
248
249         status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
250         if (ACPI_FAILURE(status)) {
251                 return_ACPI_STATUS(status);
252         }
253
254         /* Install the table and load it into the namespace */
255
256         ACPI_INFO((AE_INFO, "Host-directed Dynamic ACPI Table Load:"));
257         status = acpi_tb_add_table(&table_desc, &table_index);
258         if (ACPI_FAILURE(status)) {
259                 goto unlock_and_exit;
260         }
261
262         status = acpi_ns_load_table(table_index, acpi_gbl_root_node);
263
264         /* Invoke table handler if present */
265
266         if (acpi_gbl_table_handler) {
267                 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD, table,
268                                              acpi_gbl_table_handler_context);
269         }
270
271       unlock_and_exit:
272         (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
273         return_ACPI_STATUS(status);
274 }
275
276 ACPI_EXPORT_SYMBOL(acpi_load_table)
277
278 /*******************************************************************************
279  *
280  * FUNCTION:    acpi_unload_parent_table
281  *
282  * PARAMETERS:  object              - Handle to any namespace object owned by
283  *                                    the table to be unloaded
284  *
285  * RETURN:      Status
286  *
287  * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads
288  *              the table and deletes all namespace objects associated with
289  *              that table. Unloading of the DSDT is not allowed.
290  *              Note: Mainly intended to support hotplug removal of SSDTs.
291  *
292  ******************************************************************************/
293 acpi_status acpi_unload_parent_table(acpi_handle object)
294 {
295         struct acpi_namespace_node *node =
296             ACPI_CAST_PTR(struct acpi_namespace_node, object);
297         acpi_status status = AE_NOT_EXIST;
298         acpi_owner_id owner_id;
299         u32 i;
300
301         ACPI_FUNCTION_TRACE(acpi_unload_parent_table);
302
303         /* Parameter validation */
304
305         if (!object) {
306                 return_ACPI_STATUS(AE_BAD_PARAMETER);
307         }
308
309         /*
310          * The node owner_id is currently the same as the parent table ID.
311          * However, this could change in the future.
312          */
313         owner_id = node->owner_id;
314         if (!owner_id) {
315
316                 /* owner_id==0 means DSDT is the owner. DSDT cannot be unloaded */
317
318                 return_ACPI_STATUS(AE_TYPE);
319         }
320
321         /* Must acquire the interpreter lock during this operation */
322
323         status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
324         if (ACPI_FAILURE(status)) {
325                 return_ACPI_STATUS(status);
326         }
327
328         /* Find the table in the global table list */
329
330         for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
331                 if (owner_id != acpi_gbl_root_table_list.tables[i].owner_id) {
332                         continue;
333                 }
334
335                 /*
336                  * Allow unload of SSDT and OEMx tables only. Do not allow unload
337                  * of the DSDT. No other types of tables should get here, since
338                  * only these types can contain AML and thus are the only types
339                  * that can create namespace objects.
340                  */
341                 if (ACPI_COMPARE_NAME
342                     (acpi_gbl_root_table_list.tables[i].signature.ascii,
343                      ACPI_SIG_DSDT)) {
344                         status = AE_TYPE;
345                         break;
346                 }
347
348                 /* Ensure the table is actually loaded */
349
350                 if (!acpi_tb_is_table_loaded(i)) {
351                         status = AE_NOT_EXIST;
352                         break;
353                 }
354
355                 /* Invoke table handler if present */
356
357                 if (acpi_gbl_table_handler) {
358                         (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_UNLOAD,
359                                                      acpi_gbl_root_table_list.
360                                                      tables[i].pointer,
361                                                      acpi_gbl_table_handler_context);
362                 }
363
364                 /*
365                  * Delete all namespace objects owned by this table. Note that
366                  * these objects can appear anywhere in the namespace by virtue
367                  * of the AML "Scope" operator. Thus, we need to track ownership
368                  * by an ID, not simply a position within the hierarchy.
369                  */
370                 status = acpi_tb_delete_namespace_by_owner(i);
371                 if (ACPI_FAILURE(status)) {
372                         break;
373                 }
374
375                 status = acpi_tb_release_owner_id(i);
376                 acpi_tb_set_table_loaded_flag(i, FALSE);
377                 break;
378         }
379
380         (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
381         return_ACPI_STATUS(status);
382 }
383
384 ACPI_EXPORT_SYMBOL(acpi_unload_parent_table)