1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44#include <acpi/acpi.h>
45#include <acpi/actables.h>
46
47#define _COMPONENT ACPI_TABLES
48ACPI_MODULE_NAME("tbinstal")
49
50
51static acpi_status
52acpi_tb_match_signature(char *signature,
53 struct acpi_table_desc *table_info, u8 search_type);
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70static acpi_status
71acpi_tb_match_signature(char *signature,
72 struct acpi_table_desc *table_info, u8 search_type)
73{
74 acpi_native_uint i;
75
76 ACPI_FUNCTION_TRACE(tb_match_signature);
77
78
79
80 for (i = 0; i < (ACPI_TABLE_ID_MAX + 1); i++) {
81 if (!(acpi_gbl_table_data[i].flags & search_type)) {
82 continue;
83 }
84
85 if (!ACPI_STRNCMP(signature, acpi_gbl_table_data[i].signature,
86 acpi_gbl_table_data[i].sig_length)) {
87
88
89
90 if (table_info) {
91 table_info->type = (u8) i;
92 }
93
94 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
95 "Table [%4.4s] is an ACPI table consumed by the core subsystem\n",
96 (char *)acpi_gbl_table_data[i].
97 signature));
98
99 return_ACPI_STATUS(AE_OK);
100 }
101 }
102
103 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
104 "Table [%4.4s] is not an ACPI table consumed by the core subsystem - ignored\n",
105 (char *)signature));
106
107 return_ACPI_STATUS(AE_TABLE_NOT_SUPPORTED);
108}
109
110
111
112
113
114
115
116
117
118
119
120
121
122acpi_status acpi_tb_install_table(struct acpi_table_desc *table_info)
123{
124 acpi_status status;
125
126 ACPI_FUNCTION_TRACE(tb_install_table);
127
128
129
130 status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
131 if (ACPI_FAILURE(status)) {
132 ACPI_EXCEPTION((AE_INFO, status,
133 "Could not acquire table mutex"));
134 return_ACPI_STATUS(status);
135 }
136
137
138
139
140
141 status = acpi_tb_is_table_installed(table_info);
142 if (ACPI_FAILURE(status)) {
143 goto unlock_and_exit;
144 }
145
146
147
148 status = acpi_tb_init_table_descriptor(table_info->type, table_info);
149 if (ACPI_FAILURE(status)) {
150 ACPI_EXCEPTION((AE_INFO, status,
151 "Could not install table [%4.4s]",
152 table_info->pointer->signature));
153 }
154
155 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s located at %p\n",
156 acpi_gbl_table_data[table_info->type].name,
157 table_info->pointer));
158
159 unlock_and_exit:
160 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
161 return_ACPI_STATUS(status);
162}
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185acpi_status
186acpi_tb_recognize_table(struct acpi_table_desc *table_info, u8 search_type)
187{
188 struct acpi_table_header *table_header;
189 acpi_status status;
190
191 ACPI_FUNCTION_TRACE(tb_recognize_table);
192
193
194
195 table_header = (struct acpi_table_header *)table_info->pointer;
196 if (!table_header) {
197 return_ACPI_STATUS(AE_BAD_PARAMETER);
198 }
199
200
201
202
203
204
205
206
207
208 status = acpi_tb_match_signature(table_header->signature,
209 table_info, search_type);
210 if (ACPI_FAILURE(status)) {
211 return_ACPI_STATUS(status);
212 }
213
214 status = acpi_tb_validate_table_header(table_header);
215 if (ACPI_FAILURE(status)) {
216 return_ACPI_STATUS(status);
217 }
218
219
220
221 table_info->length = (acpi_size) table_header->length;
222 return_ACPI_STATUS(status);
223}
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238acpi_status
239acpi_tb_init_table_descriptor(acpi_table_type table_type,
240 struct acpi_table_desc *table_info)
241{
242 struct acpi_table_list *list_head;
243 struct acpi_table_desc *table_desc;
244 acpi_status status;
245
246 ACPI_FUNCTION_TRACE_U32(tb_init_table_descriptor, table_type);
247
248
249
250 table_desc = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_table_desc));
251 if (!table_desc) {
252 return_ACPI_STATUS(AE_NO_MEMORY);
253 }
254
255
256
257 status = acpi_ut_allocate_owner_id(&table_desc->owner_id);
258 if (ACPI_FAILURE(status)) {
259 goto error_exit1;
260 }
261
262
263
264 list_head = &acpi_gbl_table_lists[table_type];
265
266
267
268
269
270
271 if (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags)) {
272
273
274
275
276 if (list_head->next) {
277 status = AE_ALREADY_EXISTS;
278 goto error_exit2;
279 }
280
281 table_desc->next = list_head->next;
282 list_head->next = table_desc;
283
284 if (table_desc->next) {
285 table_desc->next->prev = table_desc;
286 }
287
288 list_head->count++;
289 } else {
290
291
292
293
294
295
296 list_head->count++;
297
298 if (!list_head->next) {
299 list_head->next = table_desc;
300 } else {
301 table_desc->next = list_head->next;
302
303 while (table_desc->next->next) {
304 table_desc->next = table_desc->next->next;
305 }
306
307 table_desc->next->next = table_desc;
308 table_desc->prev = table_desc->next;
309 table_desc->next = NULL;
310 }
311 }
312
313
314
315 table_desc->loaded_into_namespace = FALSE;
316 table_desc->type = (u8) table_type;
317 table_desc->pointer = table_info->pointer;
318 table_desc->length = table_info->length;
319 table_desc->allocation = table_info->allocation;
320 table_desc->aml_start = (u8 *) (table_desc->pointer + 1),
321 table_desc->aml_length = (u32)
322 (table_desc->length - (u32) sizeof(struct acpi_table_header));
323
324
325
326
327
328 if (acpi_gbl_table_data[table_type].global_ptr) {
329 *(acpi_gbl_table_data[table_type].global_ptr) =
330 table_info->pointer;
331 }
332
333
334
335 table_info->owner_id = table_desc->owner_id;
336 table_info->installed_desc = table_desc;
337 return_ACPI_STATUS(AE_OK);
338
339
340
341 error_exit2:
342
343 acpi_ut_release_owner_id(&table_desc->owner_id);
344
345 error_exit1:
346
347 ACPI_FREE(table_desc);
348 return_ACPI_STATUS(status);
349}
350
351
352
353
354
355
356
357
358
359
360
361
362
363void acpi_tb_delete_all_tables(void)
364{
365 acpi_table_type type;
366
367
368
369
370
371 for (type = 0; type < (ACPI_TABLE_ID_MAX + 1); type++) {
372 acpi_tb_delete_tables_by_type(type);
373 }
374}
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389void acpi_tb_delete_tables_by_type(acpi_table_type type)
390{
391 struct acpi_table_desc *table_desc;
392 u32 count;
393 u32 i;
394
395 ACPI_FUNCTION_TRACE_U32(tb_delete_tables_by_type, type);
396
397 if (type > ACPI_TABLE_ID_MAX) {
398 return_VOID;
399 }
400
401 if (ACPI_FAILURE(acpi_ut_acquire_mutex(ACPI_MTX_TABLES))) {
402 return;
403 }
404
405
406
407 switch (type) {
408 case ACPI_TABLE_ID_RSDP:
409 acpi_gbl_RSDP = NULL;
410 break;
411
412 case ACPI_TABLE_ID_DSDT:
413 acpi_gbl_DSDT = NULL;
414 break;
415
416 case ACPI_TABLE_ID_FADT:
417 acpi_gbl_FADT = NULL;
418 break;
419
420 case ACPI_TABLE_ID_FACS:
421 acpi_gbl_FACS = NULL;
422 break;
423
424 case ACPI_TABLE_ID_XSDT:
425 acpi_gbl_XSDT = NULL;
426 break;
427
428 case ACPI_TABLE_ID_SSDT:
429 case ACPI_TABLE_ID_PSDT:
430 default:
431 break;
432 }
433
434
435
436
437
438 table_desc = acpi_gbl_table_lists[type].next;
439 count = acpi_gbl_table_lists[type].count;
440
441
442
443
444
445 for (i = 0; i < count; i++) {
446 table_desc = acpi_tb_uninstall_table(table_desc);
447 }
448
449 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
450 return_VOID;
451}
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466void acpi_tb_delete_single_table(struct acpi_table_desc *table_desc)
467{
468
469
470
471 if ((!table_desc) || (!table_desc->pointer)) {
472 return;
473 }
474
475
476
477 switch (table_desc->allocation) {
478 case ACPI_MEM_NOT_ALLOCATED:
479 break;
480
481 case ACPI_MEM_ALLOCATED:
482
483 ACPI_FREE(table_desc->pointer);
484 break;
485
486 case ACPI_MEM_MAPPED:
487
488 acpi_os_unmap_memory(table_desc->pointer, table_desc->length);
489 break;
490
491 default:
492 break;
493 }
494}
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510struct acpi_table_desc *acpi_tb_uninstall_table(struct acpi_table_desc
511 *table_desc)
512{
513 struct acpi_table_desc *next_desc;
514
515 ACPI_FUNCTION_TRACE_PTR(tb_uninstall_table, table_desc);
516
517 if (!table_desc) {
518 return_PTR(NULL);
519 }
520
521
522
523 if (table_desc->prev) {
524 table_desc->prev->next = table_desc->next;
525 } else {
526
527
528 acpi_gbl_table_lists[table_desc->type].next = table_desc->next;
529 }
530
531 if (table_desc->next) {
532 table_desc->next->prev = table_desc->prev;
533 }
534
535
536
537 acpi_tb_delete_single_table(table_desc);
538
539
540
541 acpi_ut_release_owner_id(&table_desc->owner_id);
542
543
544
545 next_desc = table_desc->next;
546 ACPI_FREE(table_desc);
547
548
549
550 return_PTR(next_desc);
551}
552