1 /******************************************************************************
3 * Module Name: tbxface - Public interfaces to the ACPI subsystem
4 * ACPI table oriented interfaces
7 *****************************************************************************/
10 * Copyright (C) 2000 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 TABLE_MANAGER
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
];
200 * Delete all namespace entries owned by this table. Note that these
201 * entries can appear anywhere in the namespace by virtue of the AML
202 * "Scope" operator. Thus, we need to track ownership by an ID, not
203 * simply a position within the hierarchy
206 acpi_ns_delete_namespace_by_owner (list_head
->table_id
);
208 /* Delete (or unmap) the actual table */
210 acpi_tb_delete_acpi_table (table_type
);
212 } while (list_head
!= &acpi_gbl_acpi_tables
[table_type
]);
218 /*******************************************************************************
220 * FUNCTION: Acpi_get_table_header
222 * PARAMETERS: Table_type - one of the defined table types
223 * Instance - the non zero instance of the table, allows
224 * support for multiple tables of the same type
225 * see Acpi_gbl_Acpi_table_flag
226 * Out_table_header - pointer to the ACPI_TABLE_HEADER if successful
228 * DESCRIPTION: This function is called to get an ACPI table header. The caller
229 * supplies an pointer to a data area sufficient to contain an ACPI
230 * ACPI_TABLE_HEADER structure.
232 * The header contains a length field that can be used to determine
233 * the size of the buffer needed to contain the entire table. This
234 * function is not valid for the RSD PTR table since it does not
235 * have a standard header and is fixed length.
237 * If the operation fails for any reason an appropriate status will
238 * be returned and the contents of Out_table_header are undefined.
240 ******************************************************************************/
243 acpi_get_table_header (
244 ACPI_TABLE_TYPE table_type
,
246 ACPI_TABLE_HEADER
*out_table_header
)
248 ACPI_TABLE_HEADER
*tbl_ptr
;
252 if ((instance
== 0) ||
253 (table_type
== ACPI_TABLE_RSDP
) ||
256 return (AE_BAD_PARAMETER
);
259 /* Check the table type and instance */
261 if ((table_type
> ACPI_TABLE_MAX
) ||
262 (IS_SINGLE_TABLE (acpi_gbl_acpi_table_data
[table_type
].flags
) &&
265 return (AE_BAD_PARAMETER
);
269 /* Get a pointer to the entire table */
271 status
= acpi_tb_get_table_ptr (table_type
, instance
, &tbl_ptr
);
272 if (ACPI_FAILURE (status
)) {
277 * The function will return a NULL pointer if the table is not loaded
279 if (tbl_ptr
== NULL
) {
280 return (AE_NOT_EXIST
);
284 * Copy the header to the caller's buffer
286 MEMCPY ((void *) out_table_header
, (void *) tbl_ptr
,
287 sizeof (ACPI_TABLE_HEADER
));
293 /*******************************************************************************
295 * FUNCTION: Acpi_get_table
297 * PARAMETERS: Table_type - one of the defined table types
298 * Instance - the non zero instance of the table, allows
299 * support for multiple tables of the same type
300 * see Acpi_gbl_Acpi_table_flag
301 * Ret_buffer - pointer to a structure containing a buffer to
306 * DESCRIPTION: This function is called to get an ACPI table. The caller
307 * supplies an Out_buffer large enough to contain the entire ACPI
308 * table. The caller should call the Acpi_get_table_header function
309 * first to determine the buffer size needed. Upon completion
310 * the Out_buffer->Length field will indicate the number of bytes
311 * copied into the Out_buffer->Buf_ptr buffer. This table will be
312 * a complete table including the header.
314 * If the operation fails an appropriate status will be returned
315 * and the contents of Out_buffer are undefined.
317 ******************************************************************************/
321 ACPI_TABLE_TYPE table_type
,
323 ACPI_BUFFER
*ret_buffer
)
325 ACPI_TABLE_HEADER
*tbl_ptr
;
331 * If we have a buffer, we must have a length too
333 if ((instance
== 0) ||
335 ((!ret_buffer
->pointer
) && (ret_buffer
->length
)))
337 return (AE_BAD_PARAMETER
);
340 /* Check the table type and instance */
342 if ((table_type
> ACPI_TABLE_MAX
) ||
343 (IS_SINGLE_TABLE (acpi_gbl_acpi_table_data
[table_type
].flags
) &&
346 return (AE_BAD_PARAMETER
);
350 /* Get a pointer to the entire table */
352 status
= acpi_tb_get_table_ptr (table_type
, instance
, &tbl_ptr
);
353 if (ACPI_FAILURE (status
)) {
358 * Acpi_tb_get_table_ptr will return a NULL pointer if the
359 * table is not loaded.
361 if (tbl_ptr
== NULL
) {
362 return (AE_NOT_EXIST
);
366 * Got a table ptr, assume it's ok and copy it to the user's buffer
368 if (table_type
== ACPI_TABLE_RSDP
) {
370 * RSD PTR is the only "table" without a header
372 ret_buf_len
= sizeof (RSDP_DESCRIPTOR
);
375 ret_buf_len
= tbl_ptr
->length
;
379 * Verify we have space in the caller's buffer for the table
381 if (ret_buffer
->length
< ret_buf_len
) {
382 ret_buffer
->length
= ret_buf_len
;
383 return (AE_BUFFER_OVERFLOW
);
386 ret_buffer
->length
= ret_buf_len
;
388 MEMCPY ((void *) ret_buffer
->pointer
, (void *) tbl_ptr
, ret_buf_len
);