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
30 #define _COMPONENT ACPI_TABLES
31 MODULE_NAME ("tbxface")
34 /*******************************************************************************
36 * FUNCTION: Acpi_load_tables
42 * DESCRIPTION: This function is called to load the ACPI tables from the
45 ******************************************************************************/
49 ACPI_PHYSICAL_ADDRESS rsdp_physical_address
)
51 ACPI_STATUS status
= AE_OK
;
52 u32 number_of_tables
= 0;
55 /* Map and validate the RSDP */
57 status
= acpi_tb_verify_rsdp (rsdp_physical_address
);
58 if (ACPI_FAILURE (status
)) {
59 REPORT_ERROR (("Acpi_load_tables: RSDP Failed validation: %s\n",
60 acpi_cm_format_exception (status
)));
64 /* Get the RSDT via the RSDP */
66 status
= acpi_tb_get_table_rsdt (&number_of_tables
);
67 if (ACPI_FAILURE (status
)) {
68 REPORT_ERROR (("Acpi_load_tables: Could not load RSDT: %s\n",
69 acpi_cm_format_exception (status
)));
73 /* Now get the rest of the tables */
75 status
= acpi_tb_get_all_tables (number_of_tables
, NULL
);
76 if (ACPI_FAILURE (status
)) {
77 REPORT_ERROR (("Acpi_load_tables: Error getting required tables (DSDT/FADT/FACS): %s\n",
78 acpi_cm_format_exception (status
)));
83 /* Load the namespace from the tables */
85 status
= acpi_ns_load_namespace ();
86 if (ACPI_FAILURE (status
)) {
87 REPORT_ERROR (("Acpi_load_tables: Could not load namespace: %s\n",
88 acpi_cm_format_exception (status
)));
96 REPORT_ERROR (("Acpi_load_tables: Could not load tables: %s\n",
97 acpi_cm_format_exception (status
)));
103 /*******************************************************************************
105 * FUNCTION: Acpi_load_table
107 * PARAMETERS: Table_ptr - pointer to a buffer containing the entire
112 * DESCRIPTION: This function is called to load a table from the caller's
113 * buffer. The buffer must contain an entire ACPI Table including
114 * a valid header. The header fields will be verified, and if it
115 * is determined that the table is invalid, the call will fail.
117 * If the call fails an appropriate status will be returned.
119 ******************************************************************************/
123 ACPI_TABLE_HEADER
*table_ptr
)
126 ACPI_TABLE_DESC table_info
;
130 return (AE_BAD_PARAMETER
);
133 /* Copy the table to a local buffer */
135 status
= acpi_tb_get_table (0, table_ptr
, &table_info
);
136 if (ACPI_FAILURE (status
)) {
140 /* Install the new table into the local data structures */
142 status
= acpi_tb_install_table (NULL
, &table_info
);
143 if (ACPI_FAILURE (status
)) {
144 /* Free table allocated by Acpi_tb_get_table */
146 acpi_tb_delete_single_table (&table_info
);
151 status
= acpi_ns_load_table (table_info
.installed_desc
, acpi_gbl_root_node
);
152 if (ACPI_FAILURE (status
)) {
153 /* Uninstall table and free the buffer */
155 acpi_tb_uninstall_table (table_info
.installed_desc
);
164 /*******************************************************************************
166 * FUNCTION: Acpi_unload_table
168 * PARAMETERS: Table_type - Type of table to be unloaded
172 * DESCRIPTION: This routine is used to force the unload of a table
174 ******************************************************************************/
178 ACPI_TABLE_TYPE table_type
)
180 ACPI_TABLE_DESC
*list_head
;
183 /* Parameter validation */
185 if (table_type
> ACPI_TABLE_MAX
) {
186 return (AE_BAD_PARAMETER
);
190 /* Find all tables of the requested type */
192 list_head
= &acpi_gbl_acpi_tables
[table_type
];
195 * Delete all namespace entries owned by this table. Note that these
196 * entries can appear anywhere in the namespace by virtue of the AML
197 * "Scope" operator. Thus, we need to track ownership by an ID, not
198 * simply a position within the hierarchy
201 acpi_ns_delete_namespace_by_owner (list_head
->table_id
);
203 /* Delete (or unmap) the actual table */
205 acpi_tb_delete_acpi_table (table_type
);
207 } while (list_head
!= &acpi_gbl_acpi_tables
[table_type
]);
213 /*******************************************************************************
215 * FUNCTION: Acpi_get_table_header
217 * PARAMETERS: Table_type - one of the defined table types
218 * Instance - the non zero instance of the table, allows
219 * support for multiple tables of the same type
220 * see Acpi_gbl_Acpi_table_flag
221 * Out_table_header - pointer to the ACPI_TABLE_HEADER if successful
223 * DESCRIPTION: This function is called to get an ACPI table header. The caller
224 * supplies an pointer to a data area sufficient to contain an ACPI
225 * ACPI_TABLE_HEADER structure.
227 * The header contains a length field that can be used to determine
228 * the size of the buffer needed to contain the entire table. This
229 * function is not valid for the RSD PTR table since it does not
230 * have a standard header and is fixed length.
232 * If the operation fails for any reason an appropriate status will
233 * be returned and the contents of Out_table_header are undefined.
235 ******************************************************************************/
238 acpi_get_table_header (
239 ACPI_TABLE_TYPE table_type
,
241 ACPI_TABLE_HEADER
*out_table_header
)
243 ACPI_TABLE_HEADER
*tbl_ptr
;
247 if ((instance
== 0) ||
248 (table_type
== ACPI_TABLE_RSDP
) ||
249 (!out_table_header
)) {
250 return (AE_BAD_PARAMETER
);
253 /* Check the table type and instance */
255 if ((table_type
> ACPI_TABLE_MAX
) ||
256 (IS_SINGLE_TABLE (acpi_gbl_acpi_table_data
[table_type
].flags
) &&
258 return (AE_BAD_PARAMETER
);
262 /* Get a pointer to the entire table */
264 status
= acpi_tb_get_table_ptr (table_type
, instance
, &tbl_ptr
);
265 if (ACPI_FAILURE (status
)) {
270 * The function will return a NULL pointer if the table is not loaded
272 if (tbl_ptr
== NULL
) {
273 return (AE_NOT_EXIST
);
277 * Copy the header to the caller's buffer
279 MEMCPY ((void *) out_table_header
, (void *) tbl_ptr
,
280 sizeof (ACPI_TABLE_HEADER
));
286 /*******************************************************************************
288 * FUNCTION: Acpi_get_table
290 * PARAMETERS: Table_type - one of the defined table types
291 * Instance - the non zero instance of the table, allows
292 * support for multiple tables of the same type
293 * see Acpi_gbl_Acpi_table_flag
294 * Ret_buffer - pointer to a structure containing a buffer to
299 * DESCRIPTION: This function is called to get an ACPI table. The caller
300 * supplies an Out_buffer large enough to contain the entire ACPI
301 * table. The caller should call the Acpi_get_table_header function
302 * first to determine the buffer size needed. Upon completion
303 * the Out_buffer->Length field will indicate the number of bytes
304 * copied into the Out_buffer->Buf_ptr buffer. This table will be
305 * a complete table including the header.
307 * If the operation fails an appropriate status will be returned
308 * and the contents of Out_buffer are undefined.
310 ******************************************************************************/
314 ACPI_TABLE_TYPE table_type
,
316 ACPI_BUFFER
*ret_buffer
)
318 ACPI_TABLE_HEADER
*tbl_ptr
;
324 * If we have a buffer, we must have a length too
326 if ((instance
== 0) ||
328 ((!ret_buffer
->pointer
) && (ret_buffer
->length
))) {
329 return (AE_BAD_PARAMETER
);
332 /* Check the table type and instance */
334 if ((table_type
> ACPI_TABLE_MAX
) ||
335 (IS_SINGLE_TABLE (acpi_gbl_acpi_table_data
[table_type
].flags
) &&
337 return (AE_BAD_PARAMETER
);
341 /* Get a pointer to the entire table */
343 status
= acpi_tb_get_table_ptr (table_type
, instance
, &tbl_ptr
);
344 if (ACPI_FAILURE (status
)) {
349 * Acpi_tb_get_table_ptr will return a NULL pointer if the
350 * table is not loaded.
352 if (tbl_ptr
== NULL
) {
353 return (AE_NOT_EXIST
);
357 * Got a table ptr, assume it's ok and copy it to the user's buffer
359 if (table_type
== ACPI_TABLE_RSDP
) {
361 * RSD PTR is the only "table" without a header
363 ret_buf_len
= sizeof (RSDP_DESCRIPTOR
);
366 ret_buf_len
= tbl_ptr
->length
;
370 * Verify we have space in the caller's buffer for the table
372 if (ret_buffer
->length
< ret_buf_len
) {
373 ret_buffer
->length
= ret_buf_len
;
374 return (AE_BUFFER_OVERFLOW
);
377 ret_buffer
->length
= ret_buf_len
;
379 MEMCPY ((void *) ret_buffer
->pointer
, (void *) tbl_ptr
, ret_buf_len
);