1 /******************************************************************************
3 * Module Name: tbxface - Public interfaces to the ACPI subsystem
4 * ACPI table oriented interfaces
7 *****************************************************************************/
10 * Copyright (C) 2000, 2001 R. Byron Moore
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #define _COMPONENT ACPI_TABLES
35 MODULE_NAME ("tbxface")
38 /*******************************************************************************
40 * FUNCTION: Acpi_load_tables
46 * DESCRIPTION: This function is called to load the ACPI tables from the
49 ******************************************************************************/
53 ACPI_PHYSICAL_ADDRESS rsdp_physical_address
)
55 ACPI_STATUS status
= AE_OK
;
56 u32 number_of_tables
= 0;
59 /* Map and validate the RSDP */
61 status
= acpi_tb_verify_rsdp (rsdp_physical_address
);
62 if (ACPI_FAILURE (status
)) {
63 REPORT_ERROR (("Acpi_load_tables: RSDP Failed validation: %s\n",
64 acpi_cm_format_exception (status
)));
68 /* Get the RSDT via the RSDP */
70 status
= acpi_tb_get_table_rsdt (&number_of_tables
);
71 if (ACPI_FAILURE (status
)) {
72 REPORT_ERROR (("Acpi_load_tables: Could not load RSDT: %s\n",
73 acpi_cm_format_exception (status
)));
77 /* Now get the rest of the tables */
79 status
= acpi_tb_get_all_tables (number_of_tables
, NULL
);
80 if (ACPI_FAILURE (status
)) {
81 REPORT_ERROR (("Acpi_load_tables: Error getting required tables (DSDT/FADT/FACS): %s\n",
82 acpi_cm_format_exception (status
)));
87 /* Load the namespace from the tables */
89 status
= acpi_ns_load_namespace ();
90 if (ACPI_FAILURE (status
)) {
91 REPORT_ERROR (("Acpi_load_tables: Could not load namespace: %s\n",
92 acpi_cm_format_exception (status
)));
100 REPORT_ERROR (("Acpi_load_tables: Could not load tables: %s\n",
101 acpi_cm_format_exception (status
)));
107 /*******************************************************************************
109 * FUNCTION: Acpi_load_table
111 * PARAMETERS: Table_ptr - pointer to a buffer containing the entire
116 * DESCRIPTION: This function is called to load a table from the caller's
117 * buffer. The buffer must contain an entire ACPI Table including
118 * a valid header. The header fields will be verified, and if it
119 * is determined that the table is invalid, the call will fail.
121 * If the call fails an appropriate status will be returned.
123 ******************************************************************************/
127 ACPI_TABLE_HEADER
*table_ptr
)
130 ACPI_TABLE_DESC table_info
;
134 return (AE_BAD_PARAMETER
);
137 /* Copy the table to a local buffer */
139 status
= acpi_tb_get_table (0, table_ptr
, &table_info
);
140 if (ACPI_FAILURE (status
)) {
144 /* Install the new table into the local data structures */
146 status
= acpi_tb_install_table (NULL
, &table_info
);
147 if (ACPI_FAILURE (status
)) {
148 /* Free table allocated by Acpi_tb_get_table */
150 acpi_tb_delete_single_table (&table_info
);
155 status
= acpi_ns_load_table (table_info
.installed_desc
, acpi_gbl_root_node
);
156 if (ACPI_FAILURE (status
)) {
157 /* Uninstall table and free the buffer */
159 acpi_tb_uninstall_table (table_info
.installed_desc
);
168 /*******************************************************************************
170 * FUNCTION: Acpi_unload_table
172 * PARAMETERS: Table_type - Type of table to be unloaded
176 * DESCRIPTION: This routine is used to force the unload of a table
178 ******************************************************************************/
182 ACPI_TABLE_TYPE table_type
)
184 ACPI_TABLE_DESC
*list_head
;
187 /* Parameter validation */
189 if (table_type
> ACPI_TABLE_MAX
) {
190 return (AE_BAD_PARAMETER
);
194 /* Find all tables of the requested type */
196 list_head
= &acpi_gbl_acpi_tables
[table_type
];
199 * Delete all namespace entries owned by this table. Note that these
200 * entries can appear anywhere in the namespace by virtue of the AML
201 * "Scope" operator. Thus, we need to track ownership by an ID, not
202 * simply a position within the hierarchy
205 acpi_ns_delete_namespace_by_owner (list_head
->table_id
);
207 /* Delete (or unmap) the actual table */
209 acpi_tb_delete_acpi_table (table_type
);
211 } while (list_head
!= &acpi_gbl_acpi_tables
[table_type
]);
217 /*******************************************************************************
219 * FUNCTION: Acpi_get_table_header
221 * PARAMETERS: Table_type - one of the defined table types
222 * Instance - the non zero instance of the table, allows
223 * support for multiple tables of the same type
224 * see Acpi_gbl_Acpi_table_flag
225 * Out_table_header - pointer to the ACPI_TABLE_HEADER if successful
227 * DESCRIPTION: This function is called to get an ACPI table header. The caller
228 * supplies an pointer to a data area sufficient to contain an ACPI
229 * ACPI_TABLE_HEADER structure.
231 * The header contains a length field that can be used to determine
232 * the size of the buffer needed to contain the entire table. This
233 * function is not valid for the RSD PTR table since it does not
234 * have a standard header and is fixed length.
236 * If the operation fails for any reason an appropriate status will
237 * be returned and the contents of Out_table_header are undefined.
239 ******************************************************************************/
242 acpi_get_table_header (
243 ACPI_TABLE_TYPE table_type
,
245 ACPI_TABLE_HEADER
*out_table_header
)
247 ACPI_TABLE_HEADER
*tbl_ptr
;
251 if ((instance
== 0) ||
252 (table_type
== ACPI_TABLE_RSDP
) ||
253 (!out_table_header
)) {
254 return (AE_BAD_PARAMETER
);
257 /* Check the table type and instance */
259 if ((table_type
> ACPI_TABLE_MAX
) ||
260 (IS_SINGLE_TABLE (acpi_gbl_acpi_table_data
[table_type
].flags
) &&
262 return (AE_BAD_PARAMETER
);
266 /* Get a pointer to the entire table */
268 status
= acpi_tb_get_table_ptr (table_type
, instance
, &tbl_ptr
);
269 if (ACPI_FAILURE (status
)) {
274 * The function will return a NULL pointer if the table is not loaded
276 if (tbl_ptr
== NULL
) {
277 return (AE_NOT_EXIST
);
281 * Copy the header to the caller's buffer
283 MEMCPY ((void *) out_table_header
, (void *) tbl_ptr
,
284 sizeof (ACPI_TABLE_HEADER
));
290 /*******************************************************************************
292 * FUNCTION: Acpi_get_table
294 * PARAMETERS: Table_type - one of the defined table types
295 * Instance - the non zero instance of the table, allows
296 * support for multiple tables of the same type
297 * see Acpi_gbl_Acpi_table_flag
298 * Ret_buffer - pointer to a structure containing a buffer to
303 * DESCRIPTION: This function is called to get an ACPI table. The caller
304 * supplies an Out_buffer large enough to contain the entire ACPI
305 * table. The caller should call the Acpi_get_table_header function
306 * first to determine the buffer size needed. Upon completion
307 * the Out_buffer->Length field will indicate the number of bytes
308 * copied into the Out_buffer->Buf_ptr buffer. This table will be
309 * a complete table including the header.
311 * If the operation fails an appropriate status will be returned
312 * and the contents of Out_buffer are undefined.
314 ******************************************************************************/
318 ACPI_TABLE_TYPE table_type
,
320 ACPI_BUFFER
*ret_buffer
)
322 ACPI_TABLE_HEADER
*tbl_ptr
;
328 * If we have a buffer, we must have a length too
330 if ((instance
== 0) ||
332 ((!ret_buffer
->pointer
) && (ret_buffer
->length
))) {
333 return (AE_BAD_PARAMETER
);
336 /* Check the table type and instance */
338 if ((table_type
> ACPI_TABLE_MAX
) ||
339 (IS_SINGLE_TABLE (acpi_gbl_acpi_table_data
[table_type
].flags
) &&
341 return (AE_BAD_PARAMETER
);
345 /* Get a pointer to the entire table */
347 status
= acpi_tb_get_table_ptr (table_type
, instance
, &tbl_ptr
);
348 if (ACPI_FAILURE (status
)) {
353 * Acpi_tb_get_table_ptr will return a NULL pointer if the
354 * table is not loaded.
356 if (tbl_ptr
== NULL
) {
357 return (AE_NOT_EXIST
);
361 * Got a table ptr, assume it's ok and copy it to the user's buffer
363 if (table_type
== ACPI_TABLE_RSDP
) {
365 * RSD PTR is the only "table" without a header
367 ret_buf_len
= sizeof (RSDP_DESCRIPTOR
);
370 ret_buf_len
= tbl_ptr
->length
;
374 * Verify we have space in the caller's buffer for the table
376 if (ret_buffer
->length
< ret_buf_len
) {
377 ret_buffer
->length
= ret_buf_len
;
378 return (AE_BUFFER_OVERFLOW
);
381 ret_buffer
->length
= ret_buf_len
;
383 MEMCPY ((void *) ret_buffer
->pointer
, (void *) tbl_ptr
, ret_buf_len
);