tbxface.c 14.2 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8
/******************************************************************************
 *
 * Module Name: tbxface - Public interfaces to the ACPI subsystem
 *                         ACPI table oriented interfaces
 *
 *****************************************************************************/

/*
B
Bob Moore 已提交
9
 * Copyright (C) 2000 - 2006, R. Byron Moore
L
Linus Torvalds 已提交
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 46 47 48 49
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions, and the following disclaimer,
 *    without modification.
 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
 *    substantially similar to the "NO WARRANTY" disclaimer below
 *    ("Disclaimer") and any redistribution must be conditioned upon
 *    including a substantially similar Disclaimer requirement for further
 *    binary redistribution.
 * 3. Neither the names of the above-listed copyright holders nor the names
 *    of any contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 *
 * NO WARRANTY
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 */

#include <acpi/acpi.h>
#include <acpi/acnamesp.h>
#include <acpi/actables.h>

#define _COMPONENT          ACPI_TABLES
L
Len Brown 已提交
50
ACPI_MODULE_NAME("tbxface")
L
Linus Torvalds 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63

/*******************************************************************************
 *
 * FUNCTION:    acpi_load_tables
 *
 * PARAMETERS:  None
 *
 * RETURN:      Status
 *
 * DESCRIPTION: This function is called to load the ACPI tables from the
 *              provided RSDT
 *
 ******************************************************************************/
L
Len Brown 已提交
64
acpi_status acpi_load_tables(void)
L
Linus Torvalds 已提交
65
{
L
Len Brown 已提交
66 67
	struct acpi_pointer rsdp_address;
	acpi_status status;
L
Linus Torvalds 已提交
68

B
Bob Moore 已提交
69
	ACPI_FUNCTION_TRACE(acpi_load_tables);
L
Linus Torvalds 已提交
70 71 72

	/* Get the RSDP */

L
Len Brown 已提交
73 74 75
	status = acpi_os_get_root_pointer(ACPI_LOGICAL_ADDRESSING,
					  &rsdp_address);
	if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
76
		ACPI_EXCEPTION((AE_INFO, status, "Could not get the RSDP"));
L
Linus Torvalds 已提交
77 78 79 80 81 82 83
		goto error_exit;
	}

	/* Map and validate the RSDP */

	acpi_gbl_table_flags = rsdp_address.pointer_type;

L
Len Brown 已提交
84 85
	status = acpi_tb_verify_rsdp(&rsdp_address);
	if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
86
		ACPI_EXCEPTION((AE_INFO, status, "During RSDP validation"));
L
Linus Torvalds 已提交
87 88 89 90 91
		goto error_exit;
	}

	/* Get the RSDT via the RSDP */

L
Len Brown 已提交
92 93
	status = acpi_tb_get_table_rsdt();
	if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
94
		ACPI_EXCEPTION((AE_INFO, status, "Could not load RSDT"));
L
Linus Torvalds 已提交
95 96 97 98 99
		goto error_exit;
	}

	/* Now get the tables needed by this subsystem (FADT, DSDT, etc.) */

L
Len Brown 已提交
100 101
	status = acpi_tb_get_required_tables();
	if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
102 103
		ACPI_EXCEPTION((AE_INFO, status,
				"Could not get all required tables (DSDT/FADT/FACS)"));
L
Linus Torvalds 已提交
104 105 106
		goto error_exit;
	}

L
Len Brown 已提交
107
	ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI Tables successfully acquired\n"));
L
Linus Torvalds 已提交
108 109 110

	/* Load the namespace from the tables */

L
Len Brown 已提交
111 112
	status = acpi_ns_load_namespace();
	if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
113
		ACPI_EXCEPTION((AE_INFO, status, "Could not load namespace"));
L
Linus Torvalds 已提交
114 115 116
		goto error_exit;
	}

L
Len Brown 已提交
117
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
118

L
Len Brown 已提交
119
      error_exit:
B
Bob Moore 已提交
120
	ACPI_EXCEPTION((AE_INFO, status, "Could not load tables"));
L
Len Brown 已提交
121
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
122 123
}

B
Bob Moore 已提交
124 125
ACPI_EXPORT_SYMBOL(acpi_load_tables)

L
Linus Torvalds 已提交
126 127 128 129 130 131 132 133 134 135
/*******************************************************************************
 *
 * FUNCTION:    acpi_load_table
 *
 * PARAMETERS:  table_ptr       - pointer to a buffer containing the entire
 *                                table to be loaded
 *
 * RETURN:      Status
 *
 * DESCRIPTION: This function is called to load a table from the caller's
B
Bob Moore 已提交
136 137
 *              buffer. The buffer must contain an entire ACPI Table including
 *              a valid header. The header fields will be verified, and if it
L
Linus Torvalds 已提交
138 139 140
 *              is determined that the table is invalid, the call will fail.
 *
 ******************************************************************************/
L
Len Brown 已提交
141
acpi_status acpi_load_table(struct acpi_table_header *table_ptr)
L
Linus Torvalds 已提交
142
{
L
Len Brown 已提交
143 144 145
	acpi_status status;
	struct acpi_table_desc table_info;
	struct acpi_pointer address;
L
Linus Torvalds 已提交
146

B
Bob Moore 已提交
147
	ACPI_FUNCTION_TRACE(acpi_load_table);
L
Linus Torvalds 已提交
148 149

	if (!table_ptr) {
L
Len Brown 已提交
150
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
151 152 153 154
	}

	/* Copy the table to a local buffer */

L
Len Brown 已提交
155
	address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING;
L
Linus Torvalds 已提交
156 157
	address.pointer.logical = table_ptr;

L
Len Brown 已提交
158 159 160
	status = acpi_tb_get_table_body(&address, table_ptr, &table_info);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
161 162
	}

163 164
	/* Check signature for a valid table type */

L
Len Brown 已提交
165 166 167
	status = acpi_tb_recognize_table(&table_info, ACPI_TABLE_ALL);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
168 169
	}

L
Linus Torvalds 已提交
170 171
	/* Install the new table into the local data structures */

L
Len Brown 已提交
172 173
	status = acpi_tb_install_table(&table_info);
	if (ACPI_FAILURE(status)) {
174
		if (status == AE_ALREADY_EXISTS) {
B
Bob Moore 已提交
175

176 177 178 179 180
			/* Table already exists, no error */

			status = AE_OK;
		}

L
Linus Torvalds 已提交
181 182
		/* Free table allocated by acpi_tb_get_table_body */

L
Len Brown 已提交
183 184
		acpi_tb_delete_single_table(&table_info);
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
185 186 187 188 189
	}

	/* Convert the table to common format if necessary */

	switch (table_info.type) {
B
Bob Moore 已提交
190
	case ACPI_TABLE_ID_FADT:
L
Linus Torvalds 已提交
191

L
Len Brown 已提交
192
		status = acpi_tb_convert_table_fadt();
L
Linus Torvalds 已提交
193 194
		break;

B
Bob Moore 已提交
195
	case ACPI_TABLE_ID_FACS:
L
Linus Torvalds 已提交
196

L
Len Brown 已提交
197
		status = acpi_tb_build_common_facs(&table_info);
L
Linus Torvalds 已提交
198 199 200 201 202
		break;

	default:
		/* Load table into namespace if it contains executable AML */

L
Len Brown 已提交
203 204 205
		status =
		    acpi_ns_load_table(table_info.installed_desc,
				       acpi_gbl_root_node);
L
Linus Torvalds 已提交
206 207 208
		break;
	}

L
Len Brown 已提交
209
	if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
210

L
Linus Torvalds 已提交
211 212
		/* Uninstall table and free the buffer */

L
Len Brown 已提交
213
		(void)acpi_tb_uninstall_table(table_info.installed_desc);
L
Linus Torvalds 已提交
214 215
	}

L
Len Brown 已提交
216
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
217 218
}

B
Bob Moore 已提交
219 220
ACPI_EXPORT_SYMBOL(acpi_load_table)

221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
/*******************************************************************************
 *
 * FUNCTION:    acpi_unload_table_id
 *
 * PARAMETERS:  table_type    - Type of table to be unloaded
 *              id            - Owner ID of the table to be removed.
 *
 * RETURN:      Status
 *
 * DESCRIPTION: This routine is used to force the unload of a table (by id)
 *
 ******************************************************************************/
acpi_status acpi_unload_table_id(acpi_table_type table_type, acpi_owner_id id)
{
	struct acpi_table_desc *table_desc;
	acpi_status status;

	ACPI_FUNCTION_TRACE(acpi_unload_table);

	/* Parameter validation */
	if (table_type > ACPI_TABLE_ID_MAX)
		return_ACPI_STATUS(AE_BAD_PARAMETER);

	/* Find table from the requested type list */
	table_desc = acpi_gbl_table_lists[table_type].next;
	while (table_desc && table_desc->owner_id != id)
		table_desc = table_desc->next;

	if (!table_desc)
		return_ACPI_STATUS(AE_NOT_EXIST);

	/*
	 * Delete all namespace objects owned by this table. Note that these
	 * objects can appear anywhere in the namespace by virtue of the AML
	 * "Scope" operator. Thus, we need to track ownership by an ID, not
	 * simply a position within the hierarchy
	 */
	acpi_ns_delete_namespace_by_owner(table_desc->owner_id);

	status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
	if (ACPI_FAILURE(status))
		return_ACPI_STATUS(status);

	(void)acpi_tb_uninstall_table(table_desc);

	(void)acpi_ut_release_mutex(ACPI_MTX_TABLES);

	return_ACPI_STATUS(AE_OK);
}

ACPI_EXPORT_SYMBOL(acpi_unload_table_id)

#ifdef ACPI_FUTURE_USAGE
L
Linus Torvalds 已提交
274 275 276 277 278 279 280 281 282 283 284
/*******************************************************************************
 *
 * FUNCTION:    acpi_unload_table
 *
 * PARAMETERS:  table_type    - Type of table to be unloaded
 *
 * RETURN:      Status
 *
 * DESCRIPTION: This routine is used to force the unload of a table
 *
 ******************************************************************************/
L
Len Brown 已提交
285
acpi_status acpi_unload_table(acpi_table_type table_type)
L
Linus Torvalds 已提交
286
{
L
Len Brown 已提交
287
	struct acpi_table_desc *table_desc;
L
Linus Torvalds 已提交
288

B
Bob Moore 已提交
289
	ACPI_FUNCTION_TRACE(acpi_unload_table);
L
Linus Torvalds 已提交
290 291 292

	/* Parameter validation */

B
Bob Moore 已提交
293
	if (table_type > ACPI_TABLE_ID_MAX) {
L
Len Brown 已提交
294
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
295 296 297 298 299
	}

	/* Find all tables of the requested type */

	table_desc = acpi_gbl_table_lists[table_type].next;
B
Bob Moore 已提交
300 301 302 303
	if (!table_desc) {
		return_ACPI_STATUS(AE_NOT_EXIST);
	}

L
Linus Torvalds 已提交
304 305
	while (table_desc) {
		/*
B
Bob Moore 已提交
306 307 308
		 * Delete all namespace objects owned by this table. Note that these
		 * objects can appear anywhere in the namespace by virtue of the AML
		 * "Scope" operator. Thus, we need to track ownership by an ID, not
L
Linus Torvalds 已提交
309 310
		 * simply a position within the hierarchy
		 */
L
Len Brown 已提交
311
		acpi_ns_delete_namespace_by_owner(table_desc->owner_id);
L
Linus Torvalds 已提交
312 313 314 315 316
		table_desc = table_desc->next;
	}

	/* Delete (or unmap) all tables of this type */

L
Len Brown 已提交
317 318
	acpi_tb_delete_tables_by_type(table_type);
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
319 320
}

B
Bob Moore 已提交
321 322
ACPI_EXPORT_SYMBOL(acpi_unload_table)

L
Linus Torvalds 已提交
323 324 325 326 327 328 329 330 331 332
/*******************************************************************************
 *
 * FUNCTION:    acpi_get_table_header
 *
 * PARAMETERS:  table_type      - one of the defined table types
 *              Instance        - the non zero instance of the table, allows
 *                                support for multiple tables of the same type
 *                                see acpi_gbl_acpi_table_flag
 *              out_table_header - pointer to the struct acpi_table_header if successful
 *
B
Bob Moore 已提交
333
 * DESCRIPTION: This function is called to get an ACPI table header. The caller
L
Linus Torvalds 已提交
334 335 336 337
 *              supplies an pointer to a data area sufficient to contain an ACPI
 *              struct acpi_table_header structure.
 *
 *              The header contains a length field that can be used to determine
B
Bob Moore 已提交
338
 *              the size of the buffer needed to contain the entire table. This
L
Linus Torvalds 已提交
339 340 341 342 343
 *              function is not valid for the RSD PTR table since it does not
 *              have a standard header and is fixed length.
 *
 ******************************************************************************/
acpi_status
L
Len Brown 已提交
344 345
acpi_get_table_header(acpi_table_type table_type,
		      u32 instance, struct acpi_table_header *out_table_header)
L
Linus Torvalds 已提交
346
{
L
Len Brown 已提交
347 348
	struct acpi_table_header *tbl_ptr;
	acpi_status status;
L
Linus Torvalds 已提交
349

B
Bob Moore 已提交
350
	ACPI_FUNCTION_TRACE(acpi_get_table_header);
L
Linus Torvalds 已提交
351

L
Len Brown 已提交
352
	if ((instance == 0) ||
B
Bob Moore 已提交
353
	    (table_type == ACPI_TABLE_ID_RSDP) || (!out_table_header)) {
L
Len Brown 已提交
354
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
355 356 357 358
	}

	/* Check the table type and instance */

B
Bob Moore 已提交
359
	if ((table_type > ACPI_TABLE_ID_MAX) ||
L
Len Brown 已提交
360 361 362
	    (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags) &&
	     instance > 1)) {
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
363 364 365 366
	}

	/* Get a pointer to the entire table */

L
Len Brown 已提交
367 368 369
	status = acpi_tb_get_table_ptr(table_type, instance, &tbl_ptr);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
370 371
	}

R
Robert Moore 已提交
372 373
	/* The function will return a NULL pointer if the table is not loaded */

L
Linus Torvalds 已提交
374
	if (tbl_ptr == NULL) {
L
Len Brown 已提交
375
		return_ACPI_STATUS(AE_NOT_EXIST);
L
Linus Torvalds 已提交
376 377
	}

R
Robert Moore 已提交
378 379
	/* Copy the header to the caller's buffer */

B
Bob Moore 已提交
380 381
	ACPI_MEMCPY(ACPI_CAST_PTR(void, out_table_header),
		    ACPI_CAST_PTR(void, tbl_ptr),
L
Len Brown 已提交
382
		    sizeof(struct acpi_table_header));
L
Linus Torvalds 已提交
383

L
Len Brown 已提交
384
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
385 386
}

B
Bob Moore 已提交
387
ACPI_EXPORT_SYMBOL(acpi_get_table_header)
L
Len Brown 已提交
388
#endif				/*  ACPI_FUTURE_USAGE  */
L
Linus Torvalds 已提交
389 390 391 392 393 394 395 396 397 398 399 400 401 402

/*******************************************************************************
 *
 * FUNCTION:    acpi_get_table
 *
 * PARAMETERS:  table_type      - one of the defined table types
 *              Instance        - the non zero instance of the table, allows
 *                                support for multiple tables of the same type
 *                                see acpi_gbl_acpi_table_flag
 *              ret_buffer      - pointer to a structure containing a buffer to
 *                                receive the table
 *
 * RETURN:      Status
 *
B
Bob Moore 已提交
403
 * DESCRIPTION: This function is called to get an ACPI table. The caller
L
Linus Torvalds 已提交
404
 *              supplies an out_buffer large enough to contain the entire ACPI
B
Bob Moore 已提交
405 406
 *              table. The caller should call the acpi_get_table_header function
 *              first to determine the buffer size needed. Upon completion
L
Linus Torvalds 已提交
407 408 409 410 411 412
 *              the out_buffer->Length field will indicate the number of bytes
 *              copied into the out_buffer->buf_ptr buffer. This table will be
 *              a complete table including the header.
 *
 ******************************************************************************/
acpi_status
L
Len Brown 已提交
413 414
acpi_get_table(acpi_table_type table_type,
	       u32 instance, struct acpi_buffer *ret_buffer)
L
Linus Torvalds 已提交
415
{
L
Len Brown 已提交
416 417 418
	struct acpi_table_header *tbl_ptr;
	acpi_status status;
	acpi_size table_length;
L
Linus Torvalds 已提交
419

B
Bob Moore 已提交
420
	ACPI_FUNCTION_TRACE(acpi_get_table);
L
Linus Torvalds 已提交
421 422 423 424

	/* Parameter validation */

	if (instance == 0) {
L
Len Brown 已提交
425
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
426 427
	}

L
Len Brown 已提交
428 429 430
	status = acpi_ut_validate_buffer(ret_buffer);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
431 432 433 434
	}

	/* Check the table type and instance */

B
Bob Moore 已提交
435
	if ((table_type > ACPI_TABLE_ID_MAX) ||
L
Len Brown 已提交
436 437 438
	    (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags) &&
	     instance > 1)) {
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
439 440 441 442
	}

	/* Get a pointer to the entire table */

L
Len Brown 已提交
443 444 445
	status = acpi_tb_get_table_ptr(table_type, instance, &tbl_ptr);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
446 447 448 449 450 451 452
	}

	/*
	 * acpi_tb_get_table_ptr will return a NULL pointer if the
	 * table is not loaded.
	 */
	if (tbl_ptr == NULL) {
L
Len Brown 已提交
453
		return_ACPI_STATUS(AE_NOT_EXIST);
L
Linus Torvalds 已提交
454 455 456 457
	}

	/* Get the table length */

B
Bob Moore 已提交
458
	if (table_type == ACPI_TABLE_ID_RSDP) {
B
Bob Moore 已提交
459

R
Robert Moore 已提交
460 461
		/* RSD PTR is the only "table" without a header */

L
Len Brown 已提交
462 463
		table_length = sizeof(struct rsdp_descriptor);
	} else {
L
Linus Torvalds 已提交
464 465 466 467 468
		table_length = (acpi_size) tbl_ptr->length;
	}

	/* Validate/Allocate/Clear caller buffer */

L
Len Brown 已提交
469 470 471
	status = acpi_ut_initialize_buffer(ret_buffer, table_length);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
472 473 474 475
	}

	/* Copy the table to the buffer */

B
Bob Moore 已提交
476 477 478
	ACPI_MEMCPY(ACPI_CAST_PTR(void, ret_buffer->pointer),
		    ACPI_CAST_PTR(void, tbl_ptr), table_length);

L
Len Brown 已提交
479
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
480 481
}

B
Bob Moore 已提交
482
ACPI_EXPORT_SYMBOL(acpi_get_table)