Merge remote-tracking branch 'mmc-uh/next'
[deliverable/linux.git] / drivers / acpi / acpica / tbdata.c
CommitLineData
c418ce19
BM
1/******************************************************************************
2 *
3 * Module Name: tbdata - Table manager data structure functions
4 *
5 *****************************************************************************/
6
7/*
c8100dc4 8 * Copyright (C) 2000 - 2016, Intel Corp.
c418ce19
BM
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 <acpi/acpi.h>
45#include "accommon.h"
46#include "acnamesp.h"
47#include "actables.h"
ac0f06eb 48#include "acevents.h"
c418ce19
BM
49
50#define _COMPONENT ACPI_TABLES
51ACPI_MODULE_NAME("tbdata")
52
53/*******************************************************************************
54 *
55 * FUNCTION: acpi_tb_init_table_descriptor
56 *
57 * PARAMETERS: table_desc - Table descriptor
58 * address - Physical address of the table
59 * flags - Allocation flags of the table
60 * table - Pointer to the table
61 *
62 * RETURN: None
63 *
64 * DESCRIPTION: Initialize a new table descriptor
65 *
66 ******************************************************************************/
67void
68acpi_tb_init_table_descriptor(struct acpi_table_desc *table_desc,
69 acpi_physical_address address,
70 u8 flags, struct acpi_table_header *table)
71{
72
73 /*
74 * Initialize the table descriptor. Set the pointer to NULL, since the
75 * table is not fully mapped at this time.
76 */
4fa4616e 77 memset(table_desc, 0, sizeof(struct acpi_table_desc));
c418ce19
BM
78 table_desc->address = address;
79 table_desc->length = table->length;
80 table_desc->flags = flags;
81 ACPI_MOVE_32_TO_32(table_desc->signature.ascii, table->signature);
82}
83
84/*******************************************************************************
85 *
86 * FUNCTION: acpi_tb_acquire_table
87 *
88 * PARAMETERS: table_desc - Table descriptor
89 * table_ptr - Where table is returned
90 * table_length - Where table length is returned
91 * table_flags - Where table allocation flags are returned
92 *
93 * RETURN: Status
94 *
95 * DESCRIPTION: Acquire an ACPI table. It can be used for tables not
96 * maintained in the acpi_gbl_root_table_list.
97 *
98 ******************************************************************************/
99
100acpi_status
101acpi_tb_acquire_table(struct acpi_table_desc *table_desc,
102 struct acpi_table_header **table_ptr,
103 u32 *table_length, u8 *table_flags)
104{
105 struct acpi_table_header *table = NULL;
106
107 switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
108 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
109
110 table =
111 acpi_os_map_memory(table_desc->address, table_desc->length);
112 break;
113
114 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
115 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
116
6d3fd3cc
LZ
117 table = ACPI_CAST_PTR(struct acpi_table_header,
118 ACPI_PHYSADDR_TO_PTR(table_desc->
119 address));
c418ce19
BM
120 break;
121
122 default:
123
124 break;
125 }
126
127 /* Table is not valid yet */
128
129 if (!table) {
130 return (AE_NO_MEMORY);
131 }
132
133 /* Fill the return values */
134
135 *table_ptr = table;
136 *table_length = table_desc->length;
137 *table_flags = table_desc->flags;
138 return (AE_OK);
139}
140
141/*******************************************************************************
142 *
143 * FUNCTION: acpi_tb_release_table
144 *
145 * PARAMETERS: table - Pointer for the table
146 * table_length - Length for the table
147 * table_flags - Allocation flags for the table
148 *
149 * RETURN: None
150 *
151 * DESCRIPTION: Release a table. The inverse of acpi_tb_acquire_table().
152 *
153 ******************************************************************************/
154
155void
156acpi_tb_release_table(struct acpi_table_header *table,
157 u32 table_length, u8 table_flags)
158{
159
160 switch (table_flags & ACPI_TABLE_ORIGIN_MASK) {
161 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
162
163 acpi_os_unmap_memory(table, table_length);
164 break;
165
166 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
167 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
168 default:
169
170 break;
171 }
172}
173
174/*******************************************************************************
175 *
176 * FUNCTION: acpi_tb_acquire_temp_table
177 *
178 * PARAMETERS: table_desc - Table descriptor to be acquired
179 * address - Address of the table
180 * flags - Allocation flags of the table
181 *
182 * RETURN: Status
183 *
184 * DESCRIPTION: This function validates the table header to obtain the length
185 * of a table and fills the table descriptor to make its state as
186 * "INSTALLED". Such a table descriptor is only used for verified
187 * installation.
188 *
189 ******************************************************************************/
190
191acpi_status
192acpi_tb_acquire_temp_table(struct acpi_table_desc *table_desc,
193 acpi_physical_address address, u8 flags)
194{
195 struct acpi_table_header *table_header;
196
197 switch (flags & ACPI_TABLE_ORIGIN_MASK) {
198 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
199
200 /* Get the length of the full table from the header */
201
202 table_header =
203 acpi_os_map_memory(address,
204 sizeof(struct acpi_table_header));
205 if (!table_header) {
206 return (AE_NO_MEMORY);
207 }
208
209 acpi_tb_init_table_descriptor(table_desc, address, flags,
210 table_header);
211 acpi_os_unmap_memory(table_header,
212 sizeof(struct acpi_table_header));
213 return (AE_OK);
214
215 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
216 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
217
6d3fd3cc
LZ
218 table_header = ACPI_CAST_PTR(struct acpi_table_header,
219 ACPI_PHYSADDR_TO_PTR(address));
c418ce19
BM
220 if (!table_header) {
221 return (AE_NO_MEMORY);
222 }
223
224 acpi_tb_init_table_descriptor(table_desc, address, flags,
225 table_header);
226 return (AE_OK);
227
228 default:
229
230 break;
231 }
232
233 /* Table is not valid yet */
234
235 return (AE_NO_MEMORY);
236}
237
238/*******************************************************************************
239 *
240 * FUNCTION: acpi_tb_release_temp_table
241 *
242 * PARAMETERS: table_desc - Table descriptor to be released
243 *
244 * RETURN: Status
245 *
246 * DESCRIPTION: The inverse of acpi_tb_acquire_temp_table().
247 *
248 *****************************************************************************/
249
250void acpi_tb_release_temp_table(struct acpi_table_desc *table_desc)
251{
252
253 /*
254 * Note that the .Address is maintained by the callers of
255 * acpi_tb_acquire_temp_table(), thus do not invoke acpi_tb_uninstall_table()
256 * where .Address will be freed.
257 */
258 acpi_tb_invalidate_table(table_desc);
259}
260
261/******************************************************************************
262 *
263 * FUNCTION: acpi_tb_validate_table
264 *
265 * PARAMETERS: table_desc - Table descriptor
266 *
267 * RETURN: Status
268 *
269 * DESCRIPTION: This function is called to validate the table, the returned
270 * table descriptor is in "VALIDATED" state.
271 *
272 *****************************************************************************/
273
274acpi_status acpi_tb_validate_table(struct acpi_table_desc *table_desc)
275{
276 acpi_status status = AE_OK;
277
278 ACPI_FUNCTION_TRACE(tb_validate_table);
279
280 /* Validate the table if necessary */
281
282 if (!table_desc->pointer) {
283 status = acpi_tb_acquire_table(table_desc, &table_desc->pointer,
284 &table_desc->length,
285 &table_desc->flags);
286 if (!table_desc->pointer) {
287 status = AE_NO_MEMORY;
288 }
289 }
290
291 return_ACPI_STATUS(status);
292}
293
294/*******************************************************************************
295 *
296 * FUNCTION: acpi_tb_invalidate_table
297 *
298 * PARAMETERS: table_desc - Table descriptor
299 *
300 * RETURN: None
301 *
302 * DESCRIPTION: Invalidate one internal ACPI table, this is the inverse of
303 * acpi_tb_validate_table().
304 *
305 ******************************************************************************/
306
307void acpi_tb_invalidate_table(struct acpi_table_desc *table_desc)
308{
309
310 ACPI_FUNCTION_TRACE(tb_invalidate_table);
311
312 /* Table must be validated */
313
314 if (!table_desc->pointer) {
315 return_VOID;
316 }
317
318 acpi_tb_release_table(table_desc->pointer, table_desc->length,
319 table_desc->flags);
320 table_desc->pointer = NULL;
321
322 return_VOID;
323}
324
325/******************************************************************************
326 *
47d68c7f
LZ
327 * FUNCTION: acpi_tb_validate_temp_table
328 *
329 * PARAMETERS: table_desc - Table descriptor
330 *
331 * RETURN: Status
332 *
333 * DESCRIPTION: This function is called to validate the table, the returned
334 * table descriptor is in "VALIDATED" state.
335 *
336 *****************************************************************************/
337
338acpi_status acpi_tb_validate_temp_table(struct acpi_table_desc *table_desc)
339{
340
341 if (!table_desc->pointer && !acpi_gbl_verify_table_checksum) {
342 /*
343 * Only validates the header of the table.
344 * Note that Length contains the size of the mapping after invoking
345 * this work around, this value is required by
346 * acpi_tb_release_temp_table().
347 * We can do this because in acpi_init_table_descriptor(), the Length
348 * field of the installed descriptor is filled with the actual
349 * table length obtaining from the table header.
350 */
351 table_desc->length = sizeof(struct acpi_table_header);
352 }
353
354 return (acpi_tb_validate_table(table_desc));
355}
356
357/******************************************************************************
358 *
359 * FUNCTION: acpi_tb_verify_temp_table
c418ce19
BM
360 *
361 * PARAMETERS: table_desc - Table descriptor
362 * signature - Table signature to verify
363 *
364 * RETURN: Status
365 *
366 * DESCRIPTION: This function is called to validate and verify the table, the
367 * returned table descriptor is in "VALIDATED" state.
368 *
369 *****************************************************************************/
370
371acpi_status
f5c1e1c5 372acpi_tb_verify_temp_table(struct acpi_table_desc *table_desc, char *signature)
c418ce19
BM
373{
374 acpi_status status = AE_OK;
375
47d68c7f 376 ACPI_FUNCTION_TRACE(tb_verify_temp_table);
c418ce19
BM
377
378 /* Validate the table */
379
47d68c7f 380 status = acpi_tb_validate_temp_table(table_desc);
c418ce19
BM
381 if (ACPI_FAILURE(status)) {
382 return_ACPI_STATUS(AE_NO_MEMORY);
383 }
384
385 /* If a particular signature is expected (DSDT/FACS), it must match */
386
387 if (signature && !ACPI_COMPARE_NAME(&table_desc->signature, signature)) {
388 ACPI_BIOS_ERROR((AE_INFO,
389 "Invalid signature 0x%X for ACPI table, expected [%s]",
390 table_desc->signature.integer, signature));
391 status = AE_BAD_SIGNATURE;
392 goto invalidate_and_exit;
393 }
394
395 /* Verify the checksum */
396
47d68c7f
LZ
397 if (acpi_gbl_verify_table_checksum) {
398 status =
399 acpi_tb_verify_checksum(table_desc->pointer,
400 table_desc->length);
401 if (ACPI_FAILURE(status)) {
402 ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY,
1d0a0b2f 403 "%4.4s 0x%8.8X%8.8X"
47d68c7f 404 " Attempted table install failed",
6a0df32c
BM
405 acpi_ut_valid_nameseg(table_desc->
406 signature.
407 ascii) ?
47d68c7f 408 table_desc->signature.ascii : "????",
1d0a0b2f
LZ
409 ACPI_FORMAT_UINT64(table_desc->
410 address)));
1fad8738 411
47d68c7f
LZ
412 goto invalidate_and_exit;
413 }
c418ce19
BM
414 }
415
416 return_ACPI_STATUS(AE_OK);
417
418invalidate_and_exit:
419 acpi_tb_invalidate_table(table_desc);
420 return_ACPI_STATUS(status);
421}
422
423/*******************************************************************************
424 *
425 * FUNCTION: acpi_tb_resize_root_table_list
426 *
427 * PARAMETERS: None
428 *
429 * RETURN: Status
430 *
431 * DESCRIPTION: Expand the size of global table array
432 *
433 ******************************************************************************/
434
435acpi_status acpi_tb_resize_root_table_list(void)
436{
437 struct acpi_table_desc *tables;
438 u32 table_count;
439
440 ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
441
442 /* allow_resize flag is a parameter to acpi_initialize_tables */
443
444 if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
445 ACPI_ERROR((AE_INFO,
446 "Resize of Root Table Array is not allowed"));
447 return_ACPI_STATUS(AE_SUPPORT);
448 }
449
450 /* Increase the Table Array size */
451
452 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
453 table_count = acpi_gbl_root_table_list.max_table_count;
454 } else {
455 table_count = acpi_gbl_root_table_list.current_table_count;
456 }
457
f5c1e1c5 458 tables = ACPI_ALLOCATE_ZEROED(((acpi_size)table_count +
c418ce19
BM
459 ACPI_ROOT_TABLE_SIZE_INCREMENT) *
460 sizeof(struct acpi_table_desc));
461 if (!tables) {
462 ACPI_ERROR((AE_INFO,
463 "Could not allocate new root table array"));
464 return_ACPI_STATUS(AE_NO_MEMORY);
465 }
466
467 /* Copy and free the previous table array */
468
469 if (acpi_gbl_root_table_list.tables) {
4fa4616e 470 memcpy(tables, acpi_gbl_root_table_list.tables,
f5c1e1c5 471 (acpi_size)table_count * sizeof(struct acpi_table_desc));
c418ce19
BM
472
473 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
474 ACPI_FREE(acpi_gbl_root_table_list.tables);
475 }
476 }
477
478 acpi_gbl_root_table_list.tables = tables;
479 acpi_gbl_root_table_list.max_table_count =
480 table_count + ACPI_ROOT_TABLE_SIZE_INCREMENT;
481 acpi_gbl_root_table_list.flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
482
483 return_ACPI_STATUS(AE_OK);
484}
485
486/*******************************************************************************
487 *
76cffa79 488 * FUNCTION: acpi_tb_get_next_table_descriptor
c418ce19
BM
489 *
490 * PARAMETERS: table_index - Where table index is returned
76cffa79 491 * table_desc - Where table descriptor is returned
c418ce19 492 *
76cffa79 493 * RETURN: Status and table index/descriptor.
c418ce19
BM
494 *
495 * DESCRIPTION: Allocate a new ACPI table entry to the global table list
496 *
497 ******************************************************************************/
498
76cffa79
LZ
499acpi_status
500acpi_tb_get_next_table_descriptor(u32 *table_index,
501 struct acpi_table_desc **table_desc)
c418ce19
BM
502{
503 acpi_status status;
76cffa79 504 u32 i;
c418ce19
BM
505
506 /* Ensure that there is room for the table in the Root Table List */
507
508 if (acpi_gbl_root_table_list.current_table_count >=
509 acpi_gbl_root_table_list.max_table_count) {
510 status = acpi_tb_resize_root_table_list();
511 if (ACPI_FAILURE(status)) {
512 return (status);
513 }
514 }
515
76cffa79 516 i = acpi_gbl_root_table_list.current_table_count;
c418ce19 517 acpi_gbl_root_table_list.current_table_count++;
76cffa79
LZ
518
519 if (table_index) {
520 *table_index = i;
521 }
522 if (table_desc) {
523 *table_desc = &acpi_gbl_root_table_list.tables[i];
524 }
525
c418ce19
BM
526 return (AE_OK);
527}
528
529/*******************************************************************************
530 *
531 * FUNCTION: acpi_tb_terminate
532 *
533 * PARAMETERS: None
534 *
535 * RETURN: None
536 *
537 * DESCRIPTION: Delete all internal ACPI tables
538 *
539 ******************************************************************************/
540
541void acpi_tb_terminate(void)
542{
543 u32 i;
544
545 ACPI_FUNCTION_TRACE(tb_terminate);
546
547 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
548
549 /* Delete the individual tables */
550
551 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
552 acpi_tb_uninstall_table(&acpi_gbl_root_table_list.tables[i]);
553 }
554
555 /*
556 * Delete the root table array if allocated locally. Array cannot be
557 * mapped, so we don't need to check for that flag.
558 */
559 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
560 ACPI_FREE(acpi_gbl_root_table_list.tables);
561 }
562
563 acpi_gbl_root_table_list.tables = NULL;
564 acpi_gbl_root_table_list.flags = 0;
565 acpi_gbl_root_table_list.current_table_count = 0;
566
567 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
568
569 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
570 return_VOID;
571}
572
573/*******************************************************************************
574 *
575 * FUNCTION: acpi_tb_delete_namespace_by_owner
576 *
577 * PARAMETERS: table_index - Table index
578 *
579 * RETURN: Status
580 *
581 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
582 *
583 ******************************************************************************/
584
585acpi_status acpi_tb_delete_namespace_by_owner(u32 table_index)
586{
587 acpi_owner_id owner_id;
588 acpi_status status;
589
590 ACPI_FUNCTION_TRACE(tb_delete_namespace_by_owner);
591
592 status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
593 if (ACPI_FAILURE(status)) {
594 return_ACPI_STATUS(status);
595 }
596
597 if (table_index >= acpi_gbl_root_table_list.current_table_count) {
598
599 /* The table index does not exist */
600
601 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
602 return_ACPI_STATUS(AE_NOT_EXIST);
603 }
604
605 /* Get the owner ID for this table, used to delete namespace nodes */
606
607 owner_id = acpi_gbl_root_table_list.tables[table_index].owner_id;
608 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
609
610 /*
611 * Need to acquire the namespace writer lock to prevent interference
612 * with any concurrent namespace walks. The interpreter must be
613 * released during the deletion since the acquisition of the deletion
614 * lock may block, and also since the execution of a namespace walk
615 * must be allowed to use the interpreter.
616 */
617 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
618 status = acpi_ut_acquire_write_lock(&acpi_gbl_namespace_rw_lock);
619
620 acpi_ns_delete_namespace_by_owner(owner_id);
621 if (ACPI_FAILURE(status)) {
622 return_ACPI_STATUS(status);
623 }
624
625 acpi_ut_release_write_lock(&acpi_gbl_namespace_rw_lock);
626
627 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
628 return_ACPI_STATUS(status);
629}
630
631/*******************************************************************************
632 *
633 * FUNCTION: acpi_tb_allocate_owner_id
634 *
635 * PARAMETERS: table_index - Table index
636 *
637 * RETURN: Status
638 *
639 * DESCRIPTION: Allocates owner_id in table_desc
640 *
641 ******************************************************************************/
642
643acpi_status acpi_tb_allocate_owner_id(u32 table_index)
644{
645 acpi_status status = AE_BAD_PARAMETER;
646
647 ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
648
649 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
650 if (table_index < acpi_gbl_root_table_list.current_table_count) {
651 status =
652 acpi_ut_allocate_owner_id(&
653 (acpi_gbl_root_table_list.
654 tables[table_index].owner_id));
655 }
656
657 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
658 return_ACPI_STATUS(status);
659}
660
661/*******************************************************************************
662 *
663 * FUNCTION: acpi_tb_release_owner_id
664 *
665 * PARAMETERS: table_index - Table index
666 *
667 * RETURN: Status
668 *
669 * DESCRIPTION: Releases owner_id in table_desc
670 *
671 ******************************************************************************/
672
673acpi_status acpi_tb_release_owner_id(u32 table_index)
674{
675 acpi_status status = AE_BAD_PARAMETER;
676
677 ACPI_FUNCTION_TRACE(tb_release_owner_id);
678
679 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
680 if (table_index < acpi_gbl_root_table_list.current_table_count) {
681 acpi_ut_release_owner_id(&
682 (acpi_gbl_root_table_list.
683 tables[table_index].owner_id));
684 status = AE_OK;
685 }
686
687 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
688 return_ACPI_STATUS(status);
689}
690
691/*******************************************************************************
692 *
693 * FUNCTION: acpi_tb_get_owner_id
694 *
695 * PARAMETERS: table_index - Table index
696 * owner_id - Where the table owner_id is returned
697 *
698 * RETURN: Status
699 *
700 * DESCRIPTION: returns owner_id for the ACPI table
701 *
702 ******************************************************************************/
703
f5c1e1c5 704acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id *owner_id)
c418ce19
BM
705{
706 acpi_status status = AE_BAD_PARAMETER;
707
708 ACPI_FUNCTION_TRACE(tb_get_owner_id);
709
710 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
711 if (table_index < acpi_gbl_root_table_list.current_table_count) {
712 *owner_id =
713 acpi_gbl_root_table_list.tables[table_index].owner_id;
714 status = AE_OK;
715 }
716
717 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
718 return_ACPI_STATUS(status);
719}
720
721/*******************************************************************************
722 *
723 * FUNCTION: acpi_tb_is_table_loaded
724 *
725 * PARAMETERS: table_index - Index into the root table
726 *
727 * RETURN: Table Loaded Flag
728 *
729 ******************************************************************************/
730
731u8 acpi_tb_is_table_loaded(u32 table_index)
732{
733 u8 is_loaded = FALSE;
734
735 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
736 if (table_index < acpi_gbl_root_table_list.current_table_count) {
737 is_loaded = (u8)
738 (acpi_gbl_root_table_list.tables[table_index].flags &
739 ACPI_TABLE_IS_LOADED);
740 }
741
742 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
743 return (is_loaded);
744}
745
746/*******************************************************************************
747 *
748 * FUNCTION: acpi_tb_set_table_loaded_flag
749 *
750 * PARAMETERS: table_index - Table index
751 * is_loaded - TRUE if table is loaded, FALSE otherwise
752 *
753 * RETURN: None
754 *
755 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
756 *
757 ******************************************************************************/
758
759void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded)
760{
761
762 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
763 if (table_index < acpi_gbl_root_table_list.current_table_count) {
764 if (is_loaded) {
765 acpi_gbl_root_table_list.tables[table_index].flags |=
766 ACPI_TABLE_IS_LOADED;
767 } else {
768 acpi_gbl_root_table_list.tables[table_index].flags &=
769 ~ACPI_TABLE_IS_LOADED;
770 }
771 }
772
773 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
774}
ac0f06eb
LZ
775
776/*******************************************************************************
777 *
778 * FUNCTION: acpi_tb_load_table
779 *
780 * PARAMETERS: table_index - Table index
781 * parent_node - Where table index is returned
782 *
783 * RETURN: Status
784 *
785 * DESCRIPTION: Load an ACPI table
786 *
787 ******************************************************************************/
788
789acpi_status
790acpi_tb_load_table(u32 table_index, struct acpi_namespace_node *parent_node)
791{
792 struct acpi_table_header *table;
793 acpi_status status;
794 acpi_owner_id owner_id;
795
796 ACPI_FUNCTION_TRACE(tb_load_table);
797
798 /*
799 * Note: Now table is "INSTALLED", it must be validated before
800 * using.
801 */
802 status = acpi_get_table_by_index(table_index, &table);
803 if (ACPI_FAILURE(status)) {
804 return_ACPI_STATUS(status);
805 }
806
807 status = acpi_ns_load_table(table_index, parent_node);
808
809 /* Execute any module-level code that was found in the table */
810
811 if (!acpi_gbl_parse_table_as_term_list
812 && acpi_gbl_group_module_level_code) {
813 acpi_ns_exec_module_code_list();
814 }
815
816 /*
817 * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is
818 * responsible for discovering any new wake GPEs by running _PRW methods
819 * that may have been loaded by this table.
820 */
821 status = acpi_tb_get_owner_id(table_index, &owner_id);
822 if (ACPI_SUCCESS(status)) {
823 acpi_ev_update_gpes(owner_id);
824 }
825
826 /* Invoke table handler if present */
827
828 if (acpi_gbl_table_handler) {
829 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD, table,
830 acpi_gbl_table_handler_context);
831 }
832
833 return_ACPI_STATUS(status);
834}
835
836/*******************************************************************************
837 *
838 * FUNCTION: acpi_tb_install_and_load_table
839 *
840 * PARAMETERS: table - Pointer to the table
841 * address - Physical address of the table
842 * flags - Allocation flags of the table
843 * table_index - Where table index is returned
844 *
845 * RETURN: Status
846 *
847 * DESCRIPTION: Install and load an ACPI table
848 *
849 ******************************************************************************/
850
851acpi_status
852acpi_tb_install_and_load_table(struct acpi_table_header *table,
853 acpi_physical_address address,
854 u8 flags, u8 override, u32 *table_index)
855{
856 acpi_status status;
857 u32 i;
858 acpi_owner_id owner_id;
859
860 ACPI_FUNCTION_TRACE(acpi_load_table);
861
862 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
863
864 /* Install the table and load it into the namespace */
865
866 status = acpi_tb_install_standard_table(address, flags, TRUE,
867 override, &i);
868 if (ACPI_FAILURE(status)) {
869 goto unlock_and_exit;
870 }
871
872 /*
873 * Note: Now table is "INSTALLED", it must be validated before
874 * using.
875 */
876 status = acpi_tb_validate_table(&acpi_gbl_root_table_list.tables[i]);
877 if (ACPI_FAILURE(status)) {
878 goto unlock_and_exit;
879 }
880
881 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
882 status = acpi_ns_load_table(i, acpi_gbl_root_node);
883
884 /* Execute any module-level code that was found in the table */
885
886 if (!acpi_gbl_parse_table_as_term_list
887 && acpi_gbl_group_module_level_code) {
888 acpi_ns_exec_module_code_list();
889 }
890
891 /*
892 * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is
893 * responsible for discovering any new wake GPEs by running _PRW methods
894 * that may have been loaded by this table.
895 */
896 status = acpi_tb_get_owner_id(i, &owner_id);
897 if (ACPI_SUCCESS(status)) {
898 acpi_ev_update_gpes(owner_id);
899 }
900
901 /* Invoke table handler if present */
902
903 if (acpi_gbl_table_handler) {
904 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD, table,
905 acpi_gbl_table_handler_context);
906 }
907 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
908
909unlock_and_exit:
910 *table_index = i;
911 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
912 return_ACPI_STATUS(status);
913}
This page took 0.147303 seconds and 5 git commands to generate.