ACPI: Video: Increase buffer size for writes to brightness proc file.
[linux-2.6-block.git] / drivers / acpi / tables / tbinstal.c
CommitLineData
1da177e4
LT
1/******************************************************************************
2 *
3 * Module Name: tbinstal - ACPI table installation and removal
4 *
5 *****************************************************************************/
6
7/*
6c9deb72 8 * Copyright (C) 2000 - 2007, R. Byron Moore
1da177e4
LT
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
1da177e4 44#include <acpi/acpi.h>
f3d2e786 45#include <acpi/acnamesp.h>
1da177e4
LT
46#include <acpi/actables.h>
47
1da177e4 48#define _COMPONENT ACPI_TABLES
4be44fcd 49ACPI_MODULE_NAME("tbinstal")
1da177e4 50
f3d2e786 51/******************************************************************************
1da177e4 52 *
f3d2e786 53 * FUNCTION: acpi_tb_verify_table
1da177e4 54 *
f3d2e786 55 * PARAMETERS: table_desc - table
1da177e4
LT
56 *
57 * RETURN: Status
58 *
f3d2e786 59 * DESCRIPTION: this function is called to verify and map table
1da177e4 60 *
f3d2e786
BM
61 *****************************************************************************/
62acpi_status acpi_tb_verify_table(struct acpi_table_desc *table_desc)
1da177e4 63{
428f2112 64 acpi_status status = AE_OK;
1da177e4 65
f3d2e786 66 ACPI_FUNCTION_TRACE(tb_verify_table);
1da177e4 67
f3d2e786 68 /* Map the table if necessary */
44f6c012 69
f3d2e786 70 if (!table_desc->pointer) {
428f2112
AS
71 if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) ==
72 ACPI_TABLE_ORIGIN_MAPPED) {
73 table_desc->pointer =
74 acpi_os_map_memory(table_desc->address,
75 table_desc->length);
76 }
f3d2e786
BM
77 if (!table_desc->pointer) {
78 return_ACPI_STATUS(AE_NO_MEMORY);
1da177e4 79 }
f3d2e786 80 }
1da177e4 81
f3d2e786 82 /* FACS is the odd table, has no standard ACPI header and no checksum */
52fc0b02 83
428f2112 84 if (!ACPI_COMPARE_NAME(&table_desc->signature, ACPI_SIG_FACS)) {
1da177e4 85
428f2112
AS
86 /* Always calculate checksum, ignore bad checksum if requested */
87
88 status =
89 acpi_tb_verify_checksum(table_desc->pointer,
90 table_desc->length);
91 }
1da177e4 92
c5fc42ac 93 return_ACPI_STATUS(status);
1da177e4
LT
94}
95
1da177e4
LT
96/*******************************************************************************
97 *
f3d2e786 98 * FUNCTION: acpi_tb_add_table
1da177e4 99 *
428f2112 100 * PARAMETERS: table_desc - Table descriptor
f3d2e786 101 * table_index - Where the table index is returned
1da177e4
LT
102 *
103 * RETURN: Status
104 *
f3d2e786 105 * DESCRIPTION: This function is called to add the ACPI table
1da177e4
LT
106 *
107 ******************************************************************************/
108
f3d2e786 109acpi_status
428f2112 110acpi_tb_add_table(struct acpi_table_desc *table_desc,
f3d2e786 111 acpi_native_uint * table_index)
1da177e4 112{
f3d2e786
BM
113 acpi_native_uint i;
114 acpi_native_uint length;
115 acpi_status status = AE_OK;
1da177e4 116
f3d2e786 117 ACPI_FUNCTION_TRACE(tb_add_table);
1da177e4 118
428f2112
AS
119 if (!table_desc->pointer) {
120 status = acpi_tb_verify_table(table_desc);
121 if (ACPI_FAILURE(status) || !table_desc->pointer) {
122 return_ACPI_STATUS(status);
123 }
124 }
125
0efabac9 126 /* The table must be either an SSDT or a PSDT or an OEMx */
428f2112
AS
127
128 if ((!ACPI_COMPARE_NAME(table_desc->pointer->signature, ACPI_SIG_PSDT))
129 &&
0efabac9
LB
130 (!ACPI_COMPARE_NAME(table_desc->pointer->signature, ACPI_SIG_SSDT))
131 && (strncmp(table_desc->pointer->signature, "OEM", 3))) {
428f2112 132 ACPI_ERROR((AE_INFO,
0efabac9 133 "Table has invalid signature [%4.4s], must be SSDT, PSDT or OEMx",
428f2112
AS
134 table_desc->pointer->signature));
135 return_ACPI_STATUS(AE_BAD_SIGNATURE);
136 }
137
f3d2e786 138 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
1da177e4 139
f3d2e786
BM
140 /* Check if table is already registered */
141
142 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
143 if (!acpi_gbl_root_table_list.tables[i].pointer) {
144 status =
145 acpi_tb_verify_table(&acpi_gbl_root_table_list.
146 tables[i]);
147 if (ACPI_FAILURE(status)
148 || !acpi_gbl_root_table_list.tables[i].pointer) {
149 continue;
150 }
151 }
152
428f2112
AS
153 length = ACPI_MIN(table_desc->length,
154 acpi_gbl_root_table_list.tables[i].length);
155 if (ACPI_MEMCMP(table_desc->pointer,
156 acpi_gbl_root_table_list.tables[i].pointer,
157 length)) {
f3d2e786
BM
158 continue;
159 }
160
161 /* Table is already registered */
162
428f2112 163 acpi_tb_delete_table(table_desc);
f3d2e786
BM
164 *table_index = i;
165 goto release;
1da177e4
LT
166 }
167
0c9938cc 168 /*
f3d2e786 169 * Add the table to the global table list
0c9938cc 170 */
428f2112
AS
171 status = acpi_tb_store_table(table_desc->address, table_desc->pointer,
172 table_desc->length, table_desc->flags,
173 table_index);
4be44fcd 174 if (ACPI_FAILURE(status)) {
f3d2e786 175 goto release;
0c9938cc
RM
176 }
177
428f2112 178 acpi_tb_print_table_header(table_desc->address, table_desc->pointer);
1da177e4 179
f3d2e786 180 release:
4be44fcd
LB
181 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
182 return_ACPI_STATUS(status);
1da177e4
LT
183}
184
1da177e4
LT
185/*******************************************************************************
186 *
f3d2e786 187 * FUNCTION: acpi_tb_resize_root_table_list
1da177e4 188 *
f3d2e786 189 * PARAMETERS: None
1da177e4
LT
190 *
191 * RETURN: Status
192 *
f3d2e786 193 * DESCRIPTION: Expand the size of global table array
1da177e4
LT
194 *
195 ******************************************************************************/
196
f3d2e786 197acpi_status acpi_tb_resize_root_table_list(void)
1da177e4 198{
f3d2e786 199 struct acpi_table_desc *tables;
1da177e4 200
f3d2e786 201 ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
1da177e4 202
f3d2e786 203 /* allow_resize flag is a parameter to acpi_initialize_tables */
1da177e4 204
c5fc42ac 205 if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
f3d2e786
BM
206 ACPI_ERROR((AE_INFO,
207 "Resize of Root Table Array is not allowed"));
208 return_ACPI_STATUS(AE_SUPPORT);
1da177e4
LT
209 }
210
f3d2e786
BM
211 /* Increase the Table Array size */
212
213 tables = ACPI_ALLOCATE_ZEROED((acpi_gbl_root_table_list.size +
214 ACPI_ROOT_TABLE_SIZE_INCREMENT)
215 * sizeof(struct acpi_table_desc));
216 if (!tables) {
217 ACPI_ERROR((AE_INFO,
218 "Could not allocate new root table array"));
219 return_ACPI_STATUS(AE_NO_MEMORY);
1da177e4
LT
220 }
221
f3d2e786
BM
222 /* Copy and free the previous table array */
223
224 if (acpi_gbl_root_table_list.tables) {
225 ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables,
226 acpi_gbl_root_table_list.size *
227 sizeof(struct acpi_table_desc));
228
c5fc42ac 229 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
f3d2e786
BM
230 ACPI_FREE(acpi_gbl_root_table_list.tables);
231 }
1da177e4
LT
232 }
233
f3d2e786
BM
234 acpi_gbl_root_table_list.tables = tables;
235 acpi_gbl_root_table_list.size += ACPI_ROOT_TABLE_SIZE_INCREMENT;
c5fc42ac 236 acpi_gbl_root_table_list.flags |= (u8) ACPI_ROOT_ORIGIN_ALLOCATED;
1da177e4 237
f3d2e786 238 return_ACPI_STATUS(AE_OK);
1da177e4
LT
239}
240
1da177e4
LT
241/*******************************************************************************
242 *
f3d2e786 243 * FUNCTION: acpi_tb_store_table
1da177e4 244 *
f3d2e786
BM
245 * PARAMETERS: Address - Table address
246 * Table - Table header
247 * Length - Table length
248 * Flags - flags
1da177e4 249 *
f3d2e786 250 * RETURN: Status and table index.
1da177e4 251 *
f3d2e786 252 * DESCRIPTION: Add an ACPI table to the global table list
1da177e4
LT
253 *
254 ******************************************************************************/
255
256acpi_status
f3d2e786
BM
257acpi_tb_store_table(acpi_physical_address address,
258 struct acpi_table_header *table,
259 u32 length, u8 flags, acpi_native_uint * table_index)
1da177e4 260{
f3d2e786 261 acpi_status status = AE_OK;
1da177e4 262
f3d2e786 263 /* Ensure that there is room for the table in the Root Table List */
f9f4601f 264
f3d2e786
BM
265 if (acpi_gbl_root_table_list.count >= acpi_gbl_root_table_list.size) {
266 status = acpi_tb_resize_root_table_list();
267 if (ACPI_FAILURE(status)) {
268 return (status);
269 }
f9f4601f
RM
270 }
271
f3d2e786
BM
272 /* Initialize added table */
273
274 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
275 address = address;
276 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
277 pointer = table;
278 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].length =
279 length;
280 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
281 owner_id = 0;
282 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].flags =
283 flags;
284
285 ACPI_MOVE_32_TO_32(&
286 (acpi_gbl_root_table_list.
287 tables[acpi_gbl_root_table_list.count].signature),
288 table->signature);
289
290 *table_index = acpi_gbl_root_table_list.count;
291 acpi_gbl_root_table_list.count++;
292 return (status);
293}
1da177e4 294
f3d2e786
BM
295/*******************************************************************************
296 *
297 * FUNCTION: acpi_tb_delete_table
298 *
299 * PARAMETERS: table_index - Table index
300 *
301 * RETURN: None
302 *
303 * DESCRIPTION: Delete one internal ACPI table
304 *
305 ******************************************************************************/
1da177e4 306
428f2112 307void acpi_tb_delete_table(struct acpi_table_desc *table_desc)
f3d2e786 308{
f3d2e786 309 /* Table must be mapped or allocated */
f3d2e786
BM
310 if (!table_desc->pointer) {
311 return;
1da177e4 312 }
428f2112
AS
313 switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
314 case ACPI_TABLE_ORIGIN_MAPPED:
315 acpi_os_unmap_memory(table_desc->pointer, table_desc->length);
316 break;
317 case ACPI_TABLE_ORIGIN_ALLOCATED:
f3d2e786 318 ACPI_FREE(table_desc->pointer);
428f2112
AS
319 break;
320 default:;
1da177e4
LT
321 }
322
f3d2e786 323 table_desc->pointer = NULL;
1da177e4
LT
324}
325
1da177e4
LT
326/*******************************************************************************
327 *
f3d2e786 328 * FUNCTION: acpi_tb_terminate
1da177e4 329 *
f3d2e786 330 * PARAMETERS: None
1da177e4 331 *
f3d2e786 332 * RETURN: None
1da177e4
LT
333 *
334 * DESCRIPTION: Delete all internal ACPI tables
335 *
336 ******************************************************************************/
337
f3d2e786 338void acpi_tb_terminate(void)
1da177e4 339{
f3d2e786
BM
340 acpi_native_uint i;
341
342 ACPI_FUNCTION_TRACE(tb_terminate);
343
344 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
345
346 /* Delete the individual tables */
347
348 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
428f2112 349 acpi_tb_delete_table(&acpi_gbl_root_table_list.tables[i]);
f3d2e786 350 }
1da177e4
LT
351
352 /*
f3d2e786
BM
353 * Delete the root table array if allocated locally. Array cannot be
354 * mapped, so we don't need to check for that flag.
1da177e4 355 */
c5fc42ac 356 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
f3d2e786 357 ACPI_FREE(acpi_gbl_root_table_list.tables);
1da177e4 358 }
f3d2e786
BM
359
360 acpi_gbl_root_table_list.tables = NULL;
361 acpi_gbl_root_table_list.flags = 0;
362 acpi_gbl_root_table_list.count = 0;
363
364 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
365 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
1da177e4
LT
366}
367
1da177e4
LT
368/*******************************************************************************
369 *
f3d2e786 370 * FUNCTION: acpi_tb_delete_namespace_by_owner
1da177e4 371 *
f3d2e786 372 * PARAMETERS: table_index - Table index
1da177e4 373 *
f3d2e786 374 * RETURN: None
1da177e4 375 *
f3d2e786 376 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
1da177e4
LT
377 *
378 ******************************************************************************/
379
f3d2e786 380void acpi_tb_delete_namespace_by_owner(acpi_native_uint table_index)
1da177e4 381{
f3d2e786 382 acpi_owner_id owner_id;
1da177e4 383
f3d2e786
BM
384 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
385 if (table_index < acpi_gbl_root_table_list.count) {
386 owner_id =
387 acpi_gbl_root_table_list.tables[table_index].owner_id;
388 } else {
389 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
1da177e4
LT
390 return;
391 }
392
f3d2e786
BM
393 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
394 acpi_ns_delete_namespace_by_owner(owner_id);
395}
1da177e4 396
f3d2e786
BM
397/*******************************************************************************
398 *
399 * FUNCTION: acpi_tb_allocate_owner_id
400 *
401 * PARAMETERS: table_index - Table index
402 *
403 * RETURN: Status
404 *
405 * DESCRIPTION: Allocates owner_id in table_desc
406 *
407 ******************************************************************************/
1da177e4 408
f3d2e786
BM
409acpi_status acpi_tb_allocate_owner_id(acpi_native_uint table_index)
410{
411 acpi_status status = AE_BAD_PARAMETER;
1da177e4 412
f3d2e786 413 ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
1da177e4 414
f3d2e786
BM
415 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
416 if (table_index < acpi_gbl_root_table_list.count) {
417 status = acpi_ut_allocate_owner_id
418 (&(acpi_gbl_root_table_list.tables[table_index].owner_id));
1da177e4
LT
419 }
420
4be44fcd 421 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
f3d2e786 422 return_ACPI_STATUS(status);
1da177e4
LT
423}
424
1da177e4
LT
425/*******************************************************************************
426 *
f3d2e786 427 * FUNCTION: acpi_tb_release_owner_id
1da177e4 428 *
f3d2e786 429 * PARAMETERS: table_index - Table index
1da177e4 430 *
f3d2e786 431 * RETURN: Status
1da177e4 432 *
f3d2e786 433 * DESCRIPTION: Releases owner_id in table_desc
1da177e4
LT
434 *
435 ******************************************************************************/
436
f3d2e786 437acpi_status acpi_tb_release_owner_id(acpi_native_uint table_index)
1da177e4 438{
f3d2e786 439 acpi_status status = AE_BAD_PARAMETER;
1da177e4 440
f3d2e786 441 ACPI_FUNCTION_TRACE(tb_release_owner_id);
1da177e4 442
f3d2e786
BM
443 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
444 if (table_index < acpi_gbl_root_table_list.count) {
445 acpi_ut_release_owner_id(&
446 (acpi_gbl_root_table_list.
447 tables[table_index].owner_id));
448 status = AE_OK;
1da177e4
LT
449 }
450
f3d2e786
BM
451 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
452 return_ACPI_STATUS(status);
1da177e4
LT
453}
454
1da177e4
LT
455/*******************************************************************************
456 *
f3d2e786 457 * FUNCTION: acpi_tb_get_owner_id
1da177e4 458 *
f3d2e786
BM
459 * PARAMETERS: table_index - Table index
460 * owner_id - Where the table owner_id is returned
1da177e4 461 *
f3d2e786 462 * RETURN: Status
1da177e4 463 *
f3d2e786 464 * DESCRIPTION: returns owner_id for the ACPI table
1da177e4
LT
465 *
466 ******************************************************************************/
467
f3d2e786
BM
468acpi_status
469acpi_tb_get_owner_id(acpi_native_uint table_index, acpi_owner_id * owner_id)
1da177e4 470{
f3d2e786 471 acpi_status status = AE_BAD_PARAMETER;
1da177e4 472
f3d2e786 473 ACPI_FUNCTION_TRACE(tb_get_owner_id);
1da177e4 474
f3d2e786
BM
475 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
476 if (table_index < acpi_gbl_root_table_list.count) {
477 *owner_id =
478 acpi_gbl_root_table_list.tables[table_index].owner_id;
479 status = AE_OK;
1da177e4
LT
480 }
481
f3d2e786
BM
482 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
483 return_ACPI_STATUS(status);
484}
1da177e4 485
f3d2e786
BM
486/*******************************************************************************
487 *
488 * FUNCTION: acpi_tb_is_table_loaded
489 *
490 * PARAMETERS: table_index - Table index
491 *
492 * RETURN: Table Loaded Flag
493 *
494 ******************************************************************************/
1da177e4 495
f3d2e786
BM
496u8 acpi_tb_is_table_loaded(acpi_native_uint table_index)
497{
498 u8 is_loaded = FALSE;
1da177e4 499
f3d2e786
BM
500 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
501 if (table_index < acpi_gbl_root_table_list.count) {
502 is_loaded = (u8)
503 (acpi_gbl_root_table_list.tables[table_index].
c5fc42ac 504 flags & ACPI_TABLE_IS_LOADED);
1da177e4
LT
505 }
506
f3d2e786
BM
507 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
508 return (is_loaded);
509}
f6dd9221 510
f3d2e786
BM
511/*******************************************************************************
512 *
513 * FUNCTION: acpi_tb_set_table_loaded_flag
514 *
515 * PARAMETERS: table_index - Table index
516 * is_loaded - TRUE if table is loaded, FALSE otherwise
517 *
518 * RETURN: None
519 *
520 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
521 *
522 ******************************************************************************/
1da177e4 523
f3d2e786
BM
524void acpi_tb_set_table_loaded_flag(acpi_native_uint table_index, u8 is_loaded)
525{
1da177e4 526
f3d2e786
BM
527 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
528 if (table_index < acpi_gbl_root_table_list.count) {
529 if (is_loaded) {
530 acpi_gbl_root_table_list.tables[table_index].flags |=
c5fc42ac 531 ACPI_TABLE_IS_LOADED;
f3d2e786
BM
532 } else {
533 acpi_gbl_root_table_list.tables[table_index].flags &=
c5fc42ac 534 ~ACPI_TABLE_IS_LOADED;
f3d2e786
BM
535 }
536 }
1da177e4 537
f3d2e786 538 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
1da177e4 539}