1
2
3
4
5
6
7
8
9
10#define EXPORT_ACPI_INTERFACES
11
12#include <acpi/acpi.h>
13#include "accommon.h"
14#include "acnamesp.h"
15#include "actables.h"
16#include "acevents.h"
17
18#define _COMPONENT ACPI_TABLES
19ACPI_MODULE_NAME("tbxfload")
20
21
22
23
24
25
26
27
28
29
30
31
32acpi_status ACPI_INIT_FUNCTION acpi_load_tables(void)
33{
34 acpi_status status;
35
36 ACPI_FUNCTION_TRACE(acpi_load_tables);
37
38
39
40
41
42
43
44
45
46
47
48
49
50 status = acpi_ev_install_region_handlers();
51 if (ACPI_FAILURE(status)) {
52 ACPI_EXCEPTION((AE_INFO, status,
53 "During Region initialization"));
54 return_ACPI_STATUS(status);
55 }
56
57
58
59 status = acpi_tb_load_namespace();
60
61
62
63 if (status == AE_CTRL_TERMINATE) {
64 status = AE_OK;
65 }
66
67 if (ACPI_FAILURE(status)) {
68 ACPI_EXCEPTION((AE_INFO, status,
69 "While loading namespace from ACPI tables"));
70 }
71
72
73
74
75
76
77
78
79 status = acpi_ns_initialize_objects();
80 if (ACPI_SUCCESS(status)) {
81 acpi_gbl_namespace_initialized = TRUE;
82 }
83
84 return_ACPI_STATUS(status);
85}
86
87ACPI_EXPORT_SYMBOL_INIT(acpi_load_tables)
88
89
90
91
92
93
94
95
96
97
98
99
100
101acpi_status acpi_tb_load_namespace(void)
102{
103 acpi_status status;
104 u32 i;
105 struct acpi_table_header *new_dsdt;
106 struct acpi_table_desc *table;
107 u32 tables_loaded = 0;
108 u32 tables_failed = 0;
109
110 ACPI_FUNCTION_TRACE(tb_load_namespace);
111
112 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
113
114
115
116
117
118 table = &acpi_gbl_root_table_list.tables[acpi_gbl_dsdt_index];
119
120 if (!acpi_gbl_root_table_list.current_table_count ||
121 !ACPI_COMPARE_NAMESEG(table->signature.ascii, ACPI_SIG_DSDT) ||
122 ACPI_FAILURE(acpi_tb_validate_table(table))) {
123 status = AE_NO_ACPI_TABLES;
124 goto unlock_and_exit;
125 }
126
127
128
129
130
131
132
133 acpi_gbl_DSDT = table->pointer;
134
135
136
137
138
139
140
141 if (acpi_gbl_copy_dsdt_locally) {
142 new_dsdt = acpi_tb_copy_dsdt(acpi_gbl_dsdt_index);
143 if (new_dsdt) {
144 acpi_gbl_DSDT = new_dsdt;
145 }
146 }
147
148
149
150
151
152 memcpy(&acpi_gbl_original_dsdt_header, acpi_gbl_DSDT,
153 sizeof(struct acpi_table_header));
154
155
156
157 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
158 status = acpi_ns_load_table(acpi_gbl_dsdt_index, acpi_gbl_root_node);
159 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
160 if (ACPI_FAILURE(status)) {
161 ACPI_EXCEPTION((AE_INFO, status, "[DSDT] table load failed"));
162 tables_failed++;
163 } else {
164 tables_loaded++;
165 }
166
167
168
169 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
170 table = &acpi_gbl_root_table_list.tables[i];
171
172 if (!table->address ||
173 (!ACPI_COMPARE_NAMESEG
174 (table->signature.ascii, ACPI_SIG_SSDT)
175 && !ACPI_COMPARE_NAMESEG(table->signature.ascii,
176 ACPI_SIG_PSDT)
177 && !ACPI_COMPARE_NAMESEG(table->signature.ascii,
178 ACPI_SIG_OSDT))
179 || ACPI_FAILURE(acpi_tb_validate_table(table))) {
180 continue;
181 }
182
183
184
185 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
186 status = acpi_ns_load_table(i, acpi_gbl_root_node);
187 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
188 if (ACPI_FAILURE(status)) {
189 ACPI_EXCEPTION((AE_INFO, status,
190 "(%4.4s:%8.8s) while loading table",
191 table->signature.ascii,
192 table->pointer->oem_table_id));
193
194 tables_failed++;
195
196 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
197 "Table [%4.4s:%8.8s] (id FF) - Table namespace load failed\n\n",
198 table->signature.ascii,
199 table->pointer->oem_table_id));
200 } else {
201 tables_loaded++;
202 }
203 }
204
205 if (!tables_failed) {
206 ACPI_INFO(("%u ACPI AML tables successfully acquired and loaded", tables_loaded));
207 } else {
208 ACPI_ERROR((AE_INFO,
209 "%u table load failures, %u successful",
210 tables_failed, tables_loaded));
211
212
213
214 status = AE_CTRL_TERMINATE;
215 }
216
217#ifdef ACPI_APPLICATION
218 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "\n"));
219#endif
220
221unlock_and_exit:
222 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
223 return_ACPI_STATUS(status);
224}
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242acpi_status ACPI_INIT_FUNCTION
243acpi_install_table(acpi_physical_address address, u8 physical)
244{
245 acpi_status status;
246 u8 flags;
247 u32 table_index;
248
249 ACPI_FUNCTION_TRACE(acpi_install_table);
250
251 if (physical) {
252 flags = ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL;
253 } else {
254 flags = ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL;
255 }
256
257 status = acpi_tb_install_standard_table(address, flags,
258 FALSE, FALSE, &table_index);
259
260 return_ACPI_STATUS(status);
261}
262
263ACPI_EXPORT_SYMBOL_INIT(acpi_install_table)
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283acpi_status acpi_load_table(struct acpi_table_header *table, u32 *table_idx)
284{
285 acpi_status status;
286 u32 table_index;
287
288 ACPI_FUNCTION_TRACE(acpi_load_table);
289
290
291
292 if (!table) {
293 return_ACPI_STATUS(AE_BAD_PARAMETER);
294 }
295
296
297
298 ACPI_INFO(("Host-directed Dynamic ACPI Table Load:"));
299 status = acpi_tb_install_and_load_table(ACPI_PTR_TO_PHYSADDR(table),
300 ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL,
301 FALSE, &table_index);
302 if (table_idx) {
303 *table_idx = table_index;
304 }
305
306 if (ACPI_SUCCESS(status)) {
307
308
309
310 acpi_ns_initialize_objects();
311 }
312
313 return_ACPI_STATUS(status);
314}
315
316ACPI_EXPORT_SYMBOL(acpi_load_table)
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333acpi_status acpi_unload_parent_table(acpi_handle object)
334{
335 struct acpi_namespace_node *node =
336 ACPI_CAST_PTR(struct acpi_namespace_node, object);
337 acpi_status status = AE_NOT_EXIST;
338 acpi_owner_id owner_id;
339 u32 i;
340
341 ACPI_FUNCTION_TRACE(acpi_unload_parent_table);
342
343
344
345 if (!object) {
346 return_ACPI_STATUS(AE_BAD_PARAMETER);
347 }
348
349
350
351
352
353 owner_id = node->owner_id;
354 if (!owner_id) {
355
356
357
358 return_ACPI_STATUS(AE_TYPE);
359 }
360
361
362
363 status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
364 if (ACPI_FAILURE(status)) {
365 return_ACPI_STATUS(status);
366 }
367
368
369
370 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
371 if (owner_id != acpi_gbl_root_table_list.tables[i].owner_id) {
372 continue;
373 }
374
375
376
377
378
379
380
381 if (ACPI_COMPARE_NAMESEG
382 (acpi_gbl_root_table_list.tables[i].signature.ascii,
383 ACPI_SIG_DSDT)) {
384 status = AE_TYPE;
385 break;
386 }
387
388 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
389 status = acpi_tb_unload_table(i);
390 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
391 break;
392 }
393
394 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
395 return_ACPI_STATUS(status);
396}
397
398ACPI_EXPORT_SYMBOL(acpi_unload_parent_table)
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413acpi_status acpi_unload_table(u32 table_index)
414{
415 acpi_status status;
416
417 ACPI_FUNCTION_TRACE(acpi_unload_table);
418
419 if (table_index == 1) {
420
421
422
423 return_ACPI_STATUS(AE_TYPE);
424 }
425
426 status = acpi_tb_unload_table(table_index);
427 return_ACPI_STATUS(status);
428}
429
430ACPI_EXPORT_SYMBOL(acpi_unload_table)
431