Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: tbxface - Public interfaces to the ACPI subsystem | |
4 | * ACPI table oriented interfaces | |
5 | * | |
6 | *****************************************************************************/ | |
7 | ||
8 | /* | |
4a90c7e8 | 9 | * Copyright (C) 2000 - 2006, R. Byron Moore |
1da177e4 LT |
10 | * All rights reserved. |
11 | * | |
12 | * Redistribution and use in source and binary forms, with or without | |
13 | * modification, are permitted provided that the following conditions | |
14 | * are met: | |
15 | * 1. Redistributions of source code must retain the above copyright | |
16 | * notice, this list of conditions, and the following disclaimer, | |
17 | * without modification. | |
18 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | |
19 | * substantially similar to the "NO WARRANTY" disclaimer below | |
20 | * ("Disclaimer") and any redistribution must be conditioned upon | |
21 | * including a substantially similar Disclaimer requirement for further | |
22 | * binary redistribution. | |
23 | * 3. Neither the names of the above-listed copyright holders nor the names | |
24 | * of any contributors may be used to endorse or promote products derived | |
25 | * from this software without specific prior written permission. | |
26 | * | |
27 | * Alternatively, this software may be distributed under the terms of the | |
28 | * GNU General Public License ("GPL") version 2 as published by the Free | |
29 | * Software Foundation. | |
30 | * | |
31 | * NO WARRANTY | |
32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
33 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
34 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | |
35 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
36 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
37 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
38 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
39 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
40 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
41 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
42 | * POSSIBILITY OF SUCH DAMAGES. | |
43 | */ | |
44 | ||
1da177e4 LT |
45 | #include <acpi/acpi.h> |
46 | #include <acpi/acnamesp.h> | |
47 | #include <acpi/actables.h> | |
48 | ||
1da177e4 | 49 | #define _COMPONENT ACPI_TABLES |
4be44fcd | 50 | ACPI_MODULE_NAME("tbxface") |
1da177e4 LT |
51 | |
52 | /******************************************************************************* | |
53 | * | |
54 | * FUNCTION: acpi_load_tables | |
55 | * | |
56 | * PARAMETERS: None | |
57 | * | |
58 | * RETURN: Status | |
59 | * | |
60 | * DESCRIPTION: This function is called to load the ACPI tables from the | |
61 | * provided RSDT | |
62 | * | |
63 | ******************************************************************************/ | |
4be44fcd | 64 | acpi_status acpi_load_tables(void) |
1da177e4 | 65 | { |
4be44fcd LB |
66 | struct acpi_pointer rsdp_address; |
67 | acpi_status status; | |
1da177e4 | 68 | |
b229cf92 | 69 | ACPI_FUNCTION_TRACE(acpi_load_tables); |
1da177e4 LT |
70 | |
71 | /* Get the RSDP */ | |
72 | ||
4be44fcd LB |
73 | status = acpi_os_get_root_pointer(ACPI_LOGICAL_ADDRESSING, |
74 | &rsdp_address); | |
75 | if (ACPI_FAILURE(status)) { | |
b8e4d893 | 76 | ACPI_EXCEPTION((AE_INFO, status, "Could not get the RSDP")); |
1da177e4 LT |
77 | goto error_exit; |
78 | } | |
79 | ||
80 | /* Map and validate the RSDP */ | |
81 | ||
82 | acpi_gbl_table_flags = rsdp_address.pointer_type; | |
83 | ||
4be44fcd LB |
84 | status = acpi_tb_verify_rsdp(&rsdp_address); |
85 | if (ACPI_FAILURE(status)) { | |
b8e4d893 | 86 | ACPI_EXCEPTION((AE_INFO, status, "During RSDP validation")); |
1da177e4 LT |
87 | goto error_exit; |
88 | } | |
89 | ||
90 | /* Get the RSDT via the RSDP */ | |
91 | ||
4be44fcd LB |
92 | status = acpi_tb_get_table_rsdt(); |
93 | if (ACPI_FAILURE(status)) { | |
b8e4d893 | 94 | ACPI_EXCEPTION((AE_INFO, status, "Could not load RSDT")); |
1da177e4 LT |
95 | goto error_exit; |
96 | } | |
97 | ||
98 | /* Now get the tables needed by this subsystem (FADT, DSDT, etc.) */ | |
99 | ||
4be44fcd LB |
100 | status = acpi_tb_get_required_tables(); |
101 | if (ACPI_FAILURE(status)) { | |
b8e4d893 BM |
102 | ACPI_EXCEPTION((AE_INFO, status, |
103 | "Could not get all required tables (DSDT/FADT/FACS)")); | |
1da177e4 LT |
104 | goto error_exit; |
105 | } | |
106 | ||
4be44fcd | 107 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI Tables successfully acquired\n")); |
1da177e4 | 108 | |
1da177e4 LT |
109 | /* Load the namespace from the tables */ |
110 | ||
4be44fcd LB |
111 | status = acpi_ns_load_namespace(); |
112 | if (ACPI_FAILURE(status)) { | |
b8e4d893 | 113 | ACPI_EXCEPTION((AE_INFO, status, "Could not load namespace")); |
1da177e4 LT |
114 | goto error_exit; |
115 | } | |
116 | ||
4be44fcd | 117 | return_ACPI_STATUS(AE_OK); |
1da177e4 | 118 | |
4be44fcd | 119 | error_exit: |
b8e4d893 | 120 | ACPI_EXCEPTION((AE_INFO, status, "Could not load tables")); |
4be44fcd | 121 | return_ACPI_STATUS(status); |
1da177e4 LT |
122 | } |
123 | ||
8313524a BM |
124 | ACPI_EXPORT_SYMBOL(acpi_load_tables) |
125 | ||
1da177e4 | 126 | #ifdef ACPI_FUTURE_USAGE |
1da177e4 LT |
127 | /******************************************************************************* |
128 | * | |
129 | * FUNCTION: acpi_load_table | |
130 | * | |
131 | * PARAMETERS: table_ptr - pointer to a buffer containing the entire | |
132 | * table to be loaded | |
133 | * | |
134 | * RETURN: Status | |
135 | * | |
136 | * DESCRIPTION: This function is called to load a table from the caller's | |
137 | * buffer. The buffer must contain an entire ACPI Table including | |
138 | * a valid header. The header fields will be verified, and if it | |
139 | * is determined that the table is invalid, the call will fail. | |
140 | * | |
141 | ******************************************************************************/ | |
4be44fcd | 142 | acpi_status acpi_load_table(struct acpi_table_header *table_ptr) |
1da177e4 | 143 | { |
4be44fcd LB |
144 | acpi_status status; |
145 | struct acpi_table_desc table_info; | |
146 | struct acpi_pointer address; | |
1da177e4 | 147 | |
b229cf92 | 148 | ACPI_FUNCTION_TRACE(acpi_load_table); |
1da177e4 LT |
149 | |
150 | if (!table_ptr) { | |
4be44fcd | 151 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
152 | } |
153 | ||
154 | /* Copy the table to a local buffer */ | |
155 | ||
4be44fcd | 156 | address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING; |
1da177e4 LT |
157 | address.pointer.logical = table_ptr; |
158 | ||
4be44fcd LB |
159 | status = acpi_tb_get_table_body(&address, table_ptr, &table_info); |
160 | if (ACPI_FAILURE(status)) { | |
161 | return_ACPI_STATUS(status); | |
1da177e4 LT |
162 | } |
163 | ||
0c9938cc RM |
164 | /* Check signature for a valid table type */ |
165 | ||
4be44fcd LB |
166 | status = acpi_tb_recognize_table(&table_info, ACPI_TABLE_ALL); |
167 | if (ACPI_FAILURE(status)) { | |
168 | return_ACPI_STATUS(status); | |
0c9938cc RM |
169 | } |
170 | ||
1da177e4 LT |
171 | /* Install the new table into the local data structures */ |
172 | ||
4be44fcd LB |
173 | status = acpi_tb_install_table(&table_info); |
174 | if (ACPI_FAILURE(status)) { | |
0c9938cc | 175 | if (status == AE_ALREADY_EXISTS) { |
52fc0b02 | 176 | |
0c9938cc RM |
177 | /* Table already exists, no error */ |
178 | ||
179 | status = AE_OK; | |
180 | } | |
181 | ||
1da177e4 LT |
182 | /* Free table allocated by acpi_tb_get_table_body */ |
183 | ||
4be44fcd LB |
184 | acpi_tb_delete_single_table(&table_info); |
185 | return_ACPI_STATUS(status); | |
1da177e4 LT |
186 | } |
187 | ||
188 | /* Convert the table to common format if necessary */ | |
189 | ||
190 | switch (table_info.type) { | |
b229cf92 | 191 | case ACPI_TABLE_ID_FADT: |
1da177e4 | 192 | |
4be44fcd | 193 | status = acpi_tb_convert_table_fadt(); |
1da177e4 LT |
194 | break; |
195 | ||
b229cf92 | 196 | case ACPI_TABLE_ID_FACS: |
1da177e4 | 197 | |
4be44fcd | 198 | status = acpi_tb_build_common_facs(&table_info); |
1da177e4 LT |
199 | break; |
200 | ||
201 | default: | |
202 | /* Load table into namespace if it contains executable AML */ | |
203 | ||
4be44fcd LB |
204 | status = |
205 | acpi_ns_load_table(table_info.installed_desc, | |
206 | acpi_gbl_root_node); | |
1da177e4 LT |
207 | break; |
208 | } | |
209 | ||
4be44fcd | 210 | if (ACPI_FAILURE(status)) { |
52fc0b02 | 211 | |
1da177e4 LT |
212 | /* Uninstall table and free the buffer */ |
213 | ||
4be44fcd | 214 | (void)acpi_tb_uninstall_table(table_info.installed_desc); |
1da177e4 LT |
215 | } |
216 | ||
4be44fcd | 217 | return_ACPI_STATUS(status); |
1da177e4 LT |
218 | } |
219 | ||
8313524a BM |
220 | ACPI_EXPORT_SYMBOL(acpi_load_table) |
221 | ||
1da177e4 LT |
222 | /******************************************************************************* |
223 | * | |
224 | * FUNCTION: acpi_unload_table | |
225 | * | |
226 | * PARAMETERS: table_type - Type of table to be unloaded | |
227 | * | |
228 | * RETURN: Status | |
229 | * | |
230 | * DESCRIPTION: This routine is used to force the unload of a table | |
231 | * | |
232 | ******************************************************************************/ | |
4be44fcd | 233 | acpi_status acpi_unload_table(acpi_table_type table_type) |
1da177e4 | 234 | { |
4be44fcd | 235 | struct acpi_table_desc *table_desc; |
1da177e4 | 236 | |
b229cf92 | 237 | ACPI_FUNCTION_TRACE(acpi_unload_table); |
1da177e4 LT |
238 | |
239 | /* Parameter validation */ | |
240 | ||
b229cf92 | 241 | if (table_type > ACPI_TABLE_ID_MAX) { |
4be44fcd | 242 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
243 | } |
244 | ||
1da177e4 LT |
245 | /* Find all tables of the requested type */ |
246 | ||
247 | table_desc = acpi_gbl_table_lists[table_type].next; | |
248 | while (table_desc) { | |
249 | /* | |
250 | * Delete all namespace entries owned by this table. Note that these | |
251 | * entries can appear anywhere in the namespace by virtue of the AML | |
252 | * "Scope" operator. Thus, we need to track ownership by an ID, not | |
253 | * simply a position within the hierarchy | |
254 | */ | |
4be44fcd LB |
255 | acpi_ns_delete_namespace_by_owner(table_desc->owner_id); |
256 | acpi_ut_release_owner_id(&table_desc->owner_id); | |
1da177e4 LT |
257 | table_desc = table_desc->next; |
258 | } | |
259 | ||
260 | /* Delete (or unmap) all tables of this type */ | |
261 | ||
4be44fcd LB |
262 | acpi_tb_delete_tables_by_type(table_type); |
263 | return_ACPI_STATUS(AE_OK); | |
1da177e4 LT |
264 | } |
265 | ||
8313524a BM |
266 | ACPI_EXPORT_SYMBOL(acpi_unload_table) |
267 | ||
1da177e4 LT |
268 | /******************************************************************************* |
269 | * | |
270 | * FUNCTION: acpi_get_table_header | |
271 | * | |
272 | * PARAMETERS: table_type - one of the defined table types | |
273 | * Instance - the non zero instance of the table, allows | |
274 | * support for multiple tables of the same type | |
275 | * see acpi_gbl_acpi_table_flag | |
276 | * out_table_header - pointer to the struct acpi_table_header if successful | |
277 | * | |
278 | * DESCRIPTION: This function is called to get an ACPI table header. The caller | |
279 | * supplies an pointer to a data area sufficient to contain an ACPI | |
280 | * struct acpi_table_header structure. | |
281 | * | |
282 | * The header contains a length field that can be used to determine | |
283 | * the size of the buffer needed to contain the entire table. This | |
284 | * function is not valid for the RSD PTR table since it does not | |
285 | * have a standard header and is fixed length. | |
286 | * | |
287 | ******************************************************************************/ | |
1da177e4 | 288 | acpi_status |
4be44fcd LB |
289 | acpi_get_table_header(acpi_table_type table_type, |
290 | u32 instance, struct acpi_table_header *out_table_header) | |
1da177e4 | 291 | { |
4be44fcd LB |
292 | struct acpi_table_header *tbl_ptr; |
293 | acpi_status status; | |
1da177e4 | 294 | |
b229cf92 | 295 | ACPI_FUNCTION_TRACE(acpi_get_table_header); |
1da177e4 | 296 | |
4be44fcd | 297 | if ((instance == 0) || |
b229cf92 | 298 | (table_type == ACPI_TABLE_ID_RSDP) || (!out_table_header)) { |
4be44fcd | 299 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
300 | } |
301 | ||
302 | /* Check the table type and instance */ | |
303 | ||
b229cf92 | 304 | if ((table_type > ACPI_TABLE_ID_MAX) || |
4be44fcd LB |
305 | (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags) && |
306 | instance > 1)) { | |
307 | return_ACPI_STATUS(AE_BAD_PARAMETER); | |
1da177e4 LT |
308 | } |
309 | ||
1da177e4 LT |
310 | /* Get a pointer to the entire table */ |
311 | ||
4be44fcd LB |
312 | status = acpi_tb_get_table_ptr(table_type, instance, &tbl_ptr); |
313 | if (ACPI_FAILURE(status)) { | |
314 | return_ACPI_STATUS(status); | |
1da177e4 LT |
315 | } |
316 | ||
44f6c012 RM |
317 | /* The function will return a NULL pointer if the table is not loaded */ |
318 | ||
1da177e4 | 319 | if (tbl_ptr == NULL) { |
4be44fcd | 320 | return_ACPI_STATUS(AE_NOT_EXIST); |
1da177e4 LT |
321 | } |
322 | ||
44f6c012 RM |
323 | /* Copy the header to the caller's buffer */ |
324 | ||
4be44fcd LB |
325 | ACPI_MEMCPY((void *)out_table_header, (void *)tbl_ptr, |
326 | sizeof(struct acpi_table_header)); | |
1da177e4 | 327 | |
4be44fcd | 328 | return_ACPI_STATUS(status); |
1da177e4 LT |
329 | } |
330 | ||
8313524a | 331 | ACPI_EXPORT_SYMBOL(acpi_get_table_header) |
4be44fcd | 332 | #endif /* ACPI_FUTURE_USAGE */ |
1da177e4 LT |
333 | |
334 | /******************************************************************************* | |
335 | * | |
336 | * FUNCTION: acpi_get_table | |
337 | * | |
338 | * PARAMETERS: table_type - one of the defined table types | |
339 | * Instance - the non zero instance of the table, allows | |
340 | * support for multiple tables of the same type | |
341 | * see acpi_gbl_acpi_table_flag | |
342 | * ret_buffer - pointer to a structure containing a buffer to | |
343 | * receive the table | |
344 | * | |
345 | * RETURN: Status | |
346 | * | |
347 | * DESCRIPTION: This function is called to get an ACPI table. The caller | |
348 | * supplies an out_buffer large enough to contain the entire ACPI | |
349 | * table. The caller should call the acpi_get_table_header function | |
350 | * first to determine the buffer size needed. Upon completion | |
351 | * the out_buffer->Length field will indicate the number of bytes | |
352 | * copied into the out_buffer->buf_ptr buffer. This table will be | |
353 | * a complete table including the header. | |
354 | * | |
355 | ******************************************************************************/ | |
1da177e4 | 356 | acpi_status |
4be44fcd LB |
357 | acpi_get_table(acpi_table_type table_type, |
358 | u32 instance, struct acpi_buffer *ret_buffer) | |
1da177e4 | 359 | { |
4be44fcd LB |
360 | struct acpi_table_header *tbl_ptr; |
361 | acpi_status status; | |
362 | acpi_size table_length; | |
1da177e4 | 363 | |
b229cf92 | 364 | ACPI_FUNCTION_TRACE(acpi_get_table); |
1da177e4 LT |
365 | |
366 | /* Parameter validation */ | |
367 | ||
368 | if (instance == 0) { | |
4be44fcd | 369 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
370 | } |
371 | ||
4be44fcd LB |
372 | status = acpi_ut_validate_buffer(ret_buffer); |
373 | if (ACPI_FAILURE(status)) { | |
374 | return_ACPI_STATUS(status); | |
1da177e4 LT |
375 | } |
376 | ||
377 | /* Check the table type and instance */ | |
378 | ||
b229cf92 | 379 | if ((table_type > ACPI_TABLE_ID_MAX) || |
4be44fcd LB |
380 | (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags) && |
381 | instance > 1)) { | |
382 | return_ACPI_STATUS(AE_BAD_PARAMETER); | |
1da177e4 LT |
383 | } |
384 | ||
1da177e4 LT |
385 | /* Get a pointer to the entire table */ |
386 | ||
4be44fcd LB |
387 | status = acpi_tb_get_table_ptr(table_type, instance, &tbl_ptr); |
388 | if (ACPI_FAILURE(status)) { | |
389 | return_ACPI_STATUS(status); | |
1da177e4 LT |
390 | } |
391 | ||
392 | /* | |
393 | * acpi_tb_get_table_ptr will return a NULL pointer if the | |
394 | * table is not loaded. | |
395 | */ | |
396 | if (tbl_ptr == NULL) { | |
4be44fcd | 397 | return_ACPI_STATUS(AE_NOT_EXIST); |
1da177e4 LT |
398 | } |
399 | ||
400 | /* Get the table length */ | |
401 | ||
b229cf92 | 402 | if (table_type == ACPI_TABLE_ID_RSDP) { |
52fc0b02 | 403 | |
44f6c012 RM |
404 | /* RSD PTR is the only "table" without a header */ |
405 | ||
4be44fcd LB |
406 | table_length = sizeof(struct rsdp_descriptor); |
407 | } else { | |
1da177e4 LT |
408 | table_length = (acpi_size) tbl_ptr->length; |
409 | } | |
410 | ||
411 | /* Validate/Allocate/Clear caller buffer */ | |
412 | ||
4be44fcd LB |
413 | status = acpi_ut_initialize_buffer(ret_buffer, table_length); |
414 | if (ACPI_FAILURE(status)) { | |
415 | return_ACPI_STATUS(status); | |
1da177e4 LT |
416 | } |
417 | ||
418 | /* Copy the table to the buffer */ | |
419 | ||
4be44fcd LB |
420 | ACPI_MEMCPY((void *)ret_buffer->pointer, (void *)tbl_ptr, table_length); |
421 | return_ACPI_STATUS(AE_OK); | |
1da177e4 | 422 | } |
1da177e4 | 423 | |
8313524a | 424 | ACPI_EXPORT_SYMBOL(acpi_get_table) |