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