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 "actables.h"
15
16#define _COMPONENT ACPI_TABLES
17ACPI_MODULE_NAME("tbxface")
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32acpi_status acpi_allocate_root_table(u32 initial_table_count)
33{
34
35 acpi_gbl_root_table_list.max_table_count = initial_table_count;
36 acpi_gbl_root_table_list.flags = ACPI_ROOT_ALLOW_RESIZE;
37
38 return (acpi_tb_resize_root_table_list());
39}
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67acpi_status ACPI_INIT_FUNCTION
68acpi_initialize_tables(struct acpi_table_desc *initial_table_array,
69 u32 initial_table_count, u8 allow_resize)
70{
71 acpi_physical_address rsdp_address;
72 acpi_status status;
73
74 ACPI_FUNCTION_TRACE(acpi_initialize_tables);
75
76
77
78
79
80 if (!initial_table_array) {
81 status = acpi_allocate_root_table(initial_table_count);
82 if (ACPI_FAILURE(status)) {
83 return_ACPI_STATUS(status);
84 }
85 } else {
86
87
88 memset(initial_table_array, 0,
89 (acpi_size)initial_table_count *
90 sizeof(struct acpi_table_desc));
91
92 acpi_gbl_root_table_list.tables = initial_table_array;
93 acpi_gbl_root_table_list.max_table_count = initial_table_count;
94 acpi_gbl_root_table_list.flags = ACPI_ROOT_ORIGIN_UNKNOWN;
95 if (allow_resize) {
96 acpi_gbl_root_table_list.flags |=
97 ACPI_ROOT_ALLOW_RESIZE;
98 }
99 }
100
101
102
103 rsdp_address = acpi_os_get_root_pointer();
104 if (!rsdp_address) {
105 return_ACPI_STATUS(AE_NOT_FOUND);
106 }
107
108
109
110
111
112
113 status = acpi_tb_parse_root_table(rsdp_address);
114 return_ACPI_STATUS(status);
115}
116
117ACPI_EXPORT_SYMBOL_INIT(acpi_initialize_tables)
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133acpi_status ACPI_INIT_FUNCTION acpi_reallocate_root_table(void)
134{
135 acpi_status status;
136 struct acpi_table_desc *table_desc;
137 u32 i, j;
138
139 ACPI_FUNCTION_TRACE(acpi_reallocate_root_table);
140
141
142
143
144
145
146
147 if ((acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) &&
148 acpi_gbl_enable_table_validation) {
149 return_ACPI_STATUS(AE_SUPPORT);
150 }
151
152 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
153
154
155
156
157
158
159
160 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
161 table_desc = &acpi_gbl_root_table_list.tables[i];
162 if (table_desc->pointer) {
163 ACPI_ERROR((AE_INFO,
164 "Table [%4.4s] is not invalidated during early boot stage",
165 table_desc->signature.ascii));
166 }
167 }
168
169 if (!acpi_gbl_enable_table_validation) {
170
171
172
173
174 acpi_gbl_enable_table_validation = TRUE;
175 for (i = 0; i < acpi_gbl_root_table_list.current_table_count;
176 ++i) {
177 table_desc = &acpi_gbl_root_table_list.tables[i];
178 if (!(table_desc->flags & ACPI_TABLE_IS_VERIFIED)) {
179 status =
180 acpi_tb_verify_temp_table(table_desc, NULL,
181 &j);
182 if (ACPI_FAILURE(status)) {
183 acpi_tb_uninstall_table(table_desc);
184 }
185 }
186 }
187 }
188
189 acpi_gbl_root_table_list.flags |= ACPI_ROOT_ALLOW_RESIZE;
190 status = acpi_tb_resize_root_table_list();
191 acpi_gbl_root_table_list.flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
192
193 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
194 return_ACPI_STATUS(status);
195}
196
197ACPI_EXPORT_SYMBOL_INIT(acpi_reallocate_root_table)
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215acpi_status
216acpi_get_table_header(char *signature,
217 u32 instance, struct acpi_table_header *out_table_header)
218{
219 u32 i;
220 u32 j;
221 struct acpi_table_header *header;
222
223
224
225 if (!signature || !out_table_header) {
226 return (AE_BAD_PARAMETER);
227 }
228
229
230
231 for (i = 0, j = 0; i < acpi_gbl_root_table_list.current_table_count;
232 i++) {
233 if (!ACPI_COMPARE_NAMESEG
234 (&(acpi_gbl_root_table_list.tables[i].signature),
235 signature)) {
236 continue;
237 }
238
239 if (++j < instance) {
240 continue;
241 }
242
243 if (!acpi_gbl_root_table_list.tables[i].pointer) {
244 if ((acpi_gbl_root_table_list.tables[i].flags &
245 ACPI_TABLE_ORIGIN_MASK) ==
246 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL) {
247 header =
248 acpi_os_map_memory(acpi_gbl_root_table_list.
249 tables[i].address,
250 sizeof(struct
251 acpi_table_header));
252 if (!header) {
253 return (AE_NO_MEMORY);
254 }
255
256 memcpy(out_table_header, header,
257 sizeof(struct acpi_table_header));
258 acpi_os_unmap_memory(header,
259 sizeof(struct
260 acpi_table_header));
261 } else {
262 return (AE_NOT_FOUND);
263 }
264 } else {
265 memcpy(out_table_header,
266 acpi_gbl_root_table_list.tables[i].pointer,
267 sizeof(struct acpi_table_header));
268 }
269 return (AE_OK);
270 }
271
272 return (AE_NOT_FOUND);
273}
274
275ACPI_EXPORT_SYMBOL(acpi_get_table_header)
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296acpi_status
297acpi_get_table(char *signature,
298 u32 instance, struct acpi_table_header ** out_table)
299{
300 u32 i;
301 u32 j;
302 acpi_status status = AE_NOT_FOUND;
303 struct acpi_table_desc *table_desc;
304
305
306
307 if (!signature || !out_table) {
308 return (AE_BAD_PARAMETER);
309 }
310
311
312
313
314
315
316 *out_table = NULL;
317
318 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
319
320
321
322 for (i = 0, j = 0; i < acpi_gbl_root_table_list.current_table_count;
323 i++) {
324 table_desc = &acpi_gbl_root_table_list.tables[i];
325
326 if (!ACPI_COMPARE_NAMESEG(&table_desc->signature, signature)) {
327 continue;
328 }
329
330 if (++j < instance) {
331 continue;
332 }
333
334 status = acpi_tb_get_table(table_desc, out_table);
335 break;
336 }
337
338 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
339 return (status);
340}
341
342ACPI_EXPORT_SYMBOL(acpi_get_table)
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359void acpi_put_table(struct acpi_table_header *table)
360{
361 u32 i;
362 struct acpi_table_desc *table_desc;
363
364 ACPI_FUNCTION_TRACE(acpi_put_table);
365
366 if (!table) {
367 return_VOID;
368 }
369
370 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
371
372
373
374 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
375 table_desc = &acpi_gbl_root_table_list.tables[i];
376
377 if (table_desc->pointer != table) {
378 continue;
379 }
380
381 acpi_tb_put_table(table_desc);
382 break;
383 }
384
385 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
386 return_VOID;
387}
388
389ACPI_EXPORT_SYMBOL(acpi_put_table)
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404acpi_status
405acpi_get_table_by_index(u32 table_index, struct acpi_table_header **out_table)
406{
407 acpi_status status;
408
409 ACPI_FUNCTION_TRACE(acpi_get_table_by_index);
410
411
412
413 if (!out_table) {
414 return_ACPI_STATUS(AE_BAD_PARAMETER);
415 }
416
417
418
419
420
421
422 *out_table = NULL;
423
424 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
425
426
427
428 if (table_index >= acpi_gbl_root_table_list.current_table_count) {
429 status = AE_BAD_PARAMETER;
430 goto unlock_and_exit;
431 }
432
433 status =
434 acpi_tb_get_table(&acpi_gbl_root_table_list.tables[table_index],
435 out_table);
436
437unlock_and_exit:
438 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
439 return_ACPI_STATUS(status);
440}
441
442ACPI_EXPORT_SYMBOL(acpi_get_table_by_index)
443
444
445
446
447
448
449
450
451
452
453
454
455
456acpi_status
457acpi_install_table_handler(acpi_table_handler handler, void *context)
458{
459 acpi_status status;
460
461 ACPI_FUNCTION_TRACE(acpi_install_table_handler);
462
463 if (!handler) {
464 return_ACPI_STATUS(AE_BAD_PARAMETER);
465 }
466
467 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
468 if (ACPI_FAILURE(status)) {
469 return_ACPI_STATUS(status);
470 }
471
472
473
474 if (acpi_gbl_table_handler) {
475 status = AE_ALREADY_EXISTS;
476 goto cleanup;
477 }
478
479
480
481 acpi_gbl_table_handler = handler;
482 acpi_gbl_table_handler_context = context;
483
484cleanup:
485 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
486 return_ACPI_STATUS(status);
487}
488
489ACPI_EXPORT_SYMBOL(acpi_install_table_handler)
490
491
492
493
494
495
496
497
498
499
500
501
502
503acpi_status acpi_remove_table_handler(acpi_table_handler handler)
504{
505 acpi_status status;
506
507 ACPI_FUNCTION_TRACE(acpi_remove_table_handler);
508
509 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
510 if (ACPI_FAILURE(status)) {
511 return_ACPI_STATUS(status);
512 }
513
514
515
516 if (!handler || handler != acpi_gbl_table_handler) {
517 status = AE_BAD_PARAMETER;
518 goto cleanup;
519 }
520
521
522
523 acpi_gbl_table_handler = NULL;
524
525cleanup:
526 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
527 return_ACPI_STATUS(status);
528}
529
530ACPI_EXPORT_SYMBOL(acpi_remove_table_handler)
531