]>
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 | /* | |
9 | * Copyright (C) 2000 - 2005, R. Byron Moore | |
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 | ||
45 | #include <linux/module.h> | |
46 | ||
47 | #include <acpi/acpi.h> | |
48 | #include <acpi/acnamesp.h> | |
49 | #include <acpi/actables.h> | |
50 | ||
51 | ||
52 | #define _COMPONENT ACPI_TABLES | |
53 | ACPI_MODULE_NAME ("tbxface") | |
54 | ||
55 | ||
56 | /******************************************************************************* | |
57 | * | |
58 | * FUNCTION: acpi_load_tables | |
59 | * | |
60 | * PARAMETERS: None | |
61 | * | |
62 | * RETURN: Status | |
63 | * | |
64 | * DESCRIPTION: This function is called to load the ACPI tables from the | |
65 | * provided RSDT | |
66 | * | |
67 | ******************************************************************************/ | |
68 | ||
69 | acpi_status | |
44f6c012 RM |
70 | acpi_load_tables ( |
71 | void) | |
1da177e4 LT |
72 | { |
73 | struct acpi_pointer rsdp_address; | |
74 | acpi_status status; | |
75 | ||
76 | ||
77 | ACPI_FUNCTION_TRACE ("acpi_load_tables"); | |
78 | ||
79 | ||
80 | /* Get the RSDP */ | |
81 | ||
82 | status = acpi_os_get_root_pointer (ACPI_LOGICAL_ADDRESSING, | |
83 | &rsdp_address); | |
84 | if (ACPI_FAILURE (status)) { | |
85 | ACPI_REPORT_ERROR (("acpi_load_tables: Could not get RSDP, %s\n", | |
44f6c012 | 86 | acpi_format_exception (status))); |
1da177e4 LT |
87 | goto error_exit; |
88 | } | |
89 | ||
90 | /* Map and validate the RSDP */ | |
91 | ||
92 | acpi_gbl_table_flags = rsdp_address.pointer_type; | |
93 | ||
94 | status = acpi_tb_verify_rsdp (&rsdp_address); | |
95 | if (ACPI_FAILURE (status)) { | |
96 | ACPI_REPORT_ERROR (("acpi_load_tables: RSDP Failed validation: %s\n", | |
44f6c012 | 97 | acpi_format_exception (status))); |
1da177e4 LT |
98 | goto error_exit; |
99 | } | |
100 | ||
101 | /* Get the RSDT via the RSDP */ | |
102 | ||
103 | status = acpi_tb_get_table_rsdt (); | |
104 | if (ACPI_FAILURE (status)) { | |
105 | ACPI_REPORT_ERROR (("acpi_load_tables: Could not load RSDT: %s\n", | |
44f6c012 | 106 | acpi_format_exception (status))); |
1da177e4 LT |
107 | goto error_exit; |
108 | } | |
109 | ||
110 | /* Now get the tables needed by this subsystem (FADT, DSDT, etc.) */ | |
111 | ||
112 | status = acpi_tb_get_required_tables (); | |
113 | if (ACPI_FAILURE (status)) { | |
44f6c012 RM |
114 | ACPI_REPORT_ERROR (( |
115 | "acpi_load_tables: Error getting required tables (DSDT/FADT/FACS): %s\n", | |
116 | acpi_format_exception (status))); | |
1da177e4 LT |
117 | goto error_exit; |
118 | } | |
119 | ||
120 | ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI Tables successfully acquired\n")); | |
121 | ||
1da177e4 LT |
122 | /* Load the namespace from the tables */ |
123 | ||
124 | status = acpi_ns_load_namespace (); | |
125 | if (ACPI_FAILURE (status)) { | |
126 | ACPI_REPORT_ERROR (("acpi_load_tables: Could not load namespace: %s\n", | |
44f6c012 | 127 | acpi_format_exception (status))); |
1da177e4 LT |
128 | goto error_exit; |
129 | } | |
130 | ||
131 | return_ACPI_STATUS (AE_OK); | |
132 | ||
133 | ||
134 | error_exit: | |
135 | ACPI_REPORT_ERROR (("acpi_load_tables: Could not load tables: %s\n", | |
136 | acpi_format_exception (status))); | |
137 | ||
138 | return_ACPI_STATUS (status); | |
139 | } | |
140 | ||
141 | ||
142 | #ifdef ACPI_FUTURE_USAGE | |
1da177e4 LT |
143 | /******************************************************************************* |
144 | * | |
145 | * FUNCTION: acpi_load_table | |
146 | * | |
147 | * PARAMETERS: table_ptr - pointer to a buffer containing the entire | |
148 | * table to be loaded | |
149 | * | |
150 | * RETURN: Status | |
151 | * | |
152 | * DESCRIPTION: This function is called to load a table from the caller's | |
153 | * buffer. The buffer must contain an entire ACPI Table including | |
154 | * a valid header. The header fields will be verified, and if it | |
155 | * is determined that the table is invalid, the call will fail. | |
156 | * | |
157 | ******************************************************************************/ | |
158 | ||
159 | acpi_status | |
160 | acpi_load_table ( | |
161 | struct acpi_table_header *table_ptr) | |
162 | { | |
163 | acpi_status status; | |
164 | struct acpi_table_desc table_info; | |
165 | struct acpi_pointer address; | |
166 | ||
167 | ||
168 | ACPI_FUNCTION_TRACE ("acpi_load_table"); | |
169 | ||
170 | ||
171 | if (!table_ptr) { | |
172 | return_ACPI_STATUS (AE_BAD_PARAMETER); | |
173 | } | |
174 | ||
175 | /* Copy the table to a local buffer */ | |
176 | ||
177 | address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING; | |
178 | address.pointer.logical = table_ptr; | |
179 | ||
180 | status = acpi_tb_get_table_body (&address, table_ptr, &table_info); | |
181 | if (ACPI_FAILURE (status)) { | |
182 | return_ACPI_STATUS (status); | |
183 | } | |
184 | ||
0c9938cc RM |
185 | /* Check signature for a valid table type */ |
186 | ||
187 | status = acpi_tb_recognize_table (&table_info, ACPI_TABLE_ALL); | |
188 | if (ACPI_FAILURE (status)) { | |
189 | return_ACPI_STATUS (status); | |
190 | } | |
191 | ||
1da177e4 LT |
192 | /* Install the new table into the local data structures */ |
193 | ||
194 | status = acpi_tb_install_table (&table_info); | |
195 | if (ACPI_FAILURE (status)) { | |
0c9938cc RM |
196 | if (status == AE_ALREADY_EXISTS) { |
197 | /* Table already exists, no error */ | |
198 | ||
199 | status = AE_OK; | |
200 | } | |
201 | ||
1da177e4 LT |
202 | /* Free table allocated by acpi_tb_get_table_body */ |
203 | ||
204 | acpi_tb_delete_single_table (&table_info); | |
205 | return_ACPI_STATUS (status); | |
206 | } | |
207 | ||
208 | /* Convert the table to common format if necessary */ | |
209 | ||
210 | switch (table_info.type) { | |
211 | case ACPI_TABLE_FADT: | |
212 | ||
213 | status = acpi_tb_convert_table_fadt (); | |
214 | break; | |
215 | ||
216 | case ACPI_TABLE_FACS: | |
217 | ||
218 | status = acpi_tb_build_common_facs (&table_info); | |
219 | break; | |
220 | ||
221 | default: | |
222 | /* Load table into namespace if it contains executable AML */ | |
223 | ||
224 | status = acpi_ns_load_table (table_info.installed_desc, acpi_gbl_root_node); | |
225 | break; | |
226 | } | |
227 | ||
228 | if (ACPI_FAILURE (status)) { | |
229 | /* Uninstall table and free the buffer */ | |
230 | ||
231 | (void) acpi_tb_uninstall_table (table_info.installed_desc); | |
232 | } | |
233 | ||
234 | return_ACPI_STATUS (status); | |
235 | } | |
236 | ||
237 | ||
238 | /******************************************************************************* | |
239 | * | |
240 | * FUNCTION: acpi_unload_table | |
241 | * | |
242 | * PARAMETERS: table_type - Type of table to be unloaded | |
243 | * | |
244 | * RETURN: Status | |
245 | * | |
246 | * DESCRIPTION: This routine is used to force the unload of a table | |
247 | * | |
248 | ******************************************************************************/ | |
249 | ||
250 | acpi_status | |
251 | acpi_unload_table ( | |
252 | acpi_table_type table_type) | |
253 | { | |
254 | struct acpi_table_desc *table_desc; | |
255 | ||
256 | ||
257 | ACPI_FUNCTION_TRACE ("acpi_unload_table"); | |
258 | ||
259 | ||
260 | /* Parameter validation */ | |
261 | ||
262 | if (table_type > ACPI_TABLE_MAX) { | |
263 | return_ACPI_STATUS (AE_BAD_PARAMETER); | |
264 | } | |
265 | ||
1da177e4 LT |
266 | /* Find all tables of the requested type */ |
267 | ||
268 | table_desc = acpi_gbl_table_lists[table_type].next; | |
269 | while (table_desc) { | |
270 | /* | |
271 | * Delete all namespace entries owned by this table. Note that these | |
272 | * entries can appear anywhere in the namespace by virtue of the AML | |
273 | * "Scope" operator. Thus, we need to track ownership by an ID, not | |
274 | * simply a position within the hierarchy | |
275 | */ | |
f9f4601f | 276 | acpi_ns_delete_namespace_by_owner (table_desc->owner_id); |
0c9938cc | 277 | acpi_ut_release_owner_id (&table_desc->owner_id); |
1da177e4 LT |
278 | table_desc = table_desc->next; |
279 | } | |
280 | ||
281 | /* Delete (or unmap) all tables of this type */ | |
282 | ||
283 | acpi_tb_delete_tables_by_type (table_type); | |
284 | return_ACPI_STATUS (AE_OK); | |
285 | } | |
286 | ||
287 | ||
288 | /******************************************************************************* | |
289 | * | |
290 | * FUNCTION: acpi_get_table_header | |
291 | * | |
292 | * PARAMETERS: table_type - one of the defined table types | |
293 | * Instance - the non zero instance of the table, allows | |
294 | * support for multiple tables of the same type | |
295 | * see acpi_gbl_acpi_table_flag | |
296 | * out_table_header - pointer to the struct acpi_table_header if successful | |
297 | * | |
298 | * DESCRIPTION: This function is called to get an ACPI table header. The caller | |
299 | * supplies an pointer to a data area sufficient to contain an ACPI | |
300 | * struct acpi_table_header structure. | |
301 | * | |
302 | * The header contains a length field that can be used to determine | |
303 | * the size of the buffer needed to contain the entire table. This | |
304 | * function is not valid for the RSD PTR table since it does not | |
305 | * have a standard header and is fixed length. | |
306 | * | |
307 | ******************************************************************************/ | |
308 | ||
309 | acpi_status | |
310 | acpi_get_table_header ( | |
311 | acpi_table_type table_type, | |
312 | u32 instance, | |
313 | struct acpi_table_header *out_table_header) | |
314 | { | |
315 | struct acpi_table_header *tbl_ptr; | |
316 | acpi_status status; | |
317 | ||
318 | ||
319 | ACPI_FUNCTION_TRACE ("acpi_get_table_header"); | |
320 | ||
321 | ||
322 | if ((instance == 0) || | |
323 | (table_type == ACPI_TABLE_RSDP) || | |
324 | (!out_table_header)) { | |
325 | return_ACPI_STATUS (AE_BAD_PARAMETER); | |
326 | } | |
327 | ||
328 | /* Check the table type and instance */ | |
329 | ||
330 | if ((table_type > ACPI_TABLE_MAX) || | |
331 | (ACPI_IS_SINGLE_TABLE (acpi_gbl_table_data[table_type].flags) && | |
332 | instance > 1)) { | |
333 | return_ACPI_STATUS (AE_BAD_PARAMETER); | |
334 | } | |
335 | ||
1da177e4 LT |
336 | /* Get a pointer to the entire table */ |
337 | ||
338 | status = acpi_tb_get_table_ptr (table_type, instance, &tbl_ptr); | |
339 | if (ACPI_FAILURE (status)) { | |
340 | return_ACPI_STATUS (status); | |
341 | } | |
342 | ||
44f6c012 RM |
343 | /* The function will return a NULL pointer if the table is not loaded */ |
344 | ||
1da177e4 LT |
345 | if (tbl_ptr == NULL) { |
346 | return_ACPI_STATUS (AE_NOT_EXIST); | |
347 | } | |
348 | ||
44f6c012 RM |
349 | /* Copy the header to the caller's buffer */ |
350 | ||
1da177e4 | 351 | ACPI_MEMCPY ((void *) out_table_header, (void *) tbl_ptr, |
44f6c012 | 352 | sizeof (struct acpi_table_header)); |
1da177e4 LT |
353 | |
354 | return_ACPI_STATUS (status); | |
355 | } | |
356 | ||
1da177e4 LT |
357 | #endif /* ACPI_FUTURE_USAGE */ |
358 | ||
359 | /******************************************************************************* | |
360 | * | |
361 | * FUNCTION: acpi_get_table | |
362 | * | |
363 | * PARAMETERS: table_type - one of the defined table types | |
364 | * Instance - the non zero instance of the table, allows | |
365 | * support for multiple tables of the same type | |
366 | * see acpi_gbl_acpi_table_flag | |
367 | * ret_buffer - pointer to a structure containing a buffer to | |
368 | * receive the table | |
369 | * | |
370 | * RETURN: Status | |
371 | * | |
372 | * DESCRIPTION: This function is called to get an ACPI table. The caller | |
373 | * supplies an out_buffer large enough to contain the entire ACPI | |
374 | * table. The caller should call the acpi_get_table_header function | |
375 | * first to determine the buffer size needed. Upon completion | |
376 | * the out_buffer->Length field will indicate the number of bytes | |
377 | * copied into the out_buffer->buf_ptr buffer. This table will be | |
378 | * a complete table including the header. | |
379 | * | |
380 | ******************************************************************************/ | |
381 | ||
382 | acpi_status | |
383 | acpi_get_table ( | |
384 | acpi_table_type table_type, | |
385 | u32 instance, | |
386 | struct acpi_buffer *ret_buffer) | |
387 | { | |
388 | struct acpi_table_header *tbl_ptr; | |
389 | acpi_status status; | |
390 | acpi_size table_length; | |
391 | ||
392 | ||
393 | ACPI_FUNCTION_TRACE ("acpi_get_table"); | |
394 | ||
395 | ||
396 | /* Parameter validation */ | |
397 | ||
398 | if (instance == 0) { | |
399 | return_ACPI_STATUS (AE_BAD_PARAMETER); | |
400 | } | |
401 | ||
402 | status = acpi_ut_validate_buffer (ret_buffer); | |
403 | if (ACPI_FAILURE (status)) { | |
404 | return_ACPI_STATUS (status); | |
405 | } | |
406 | ||
407 | /* Check the table type and instance */ | |
408 | ||
409 | if ((table_type > ACPI_TABLE_MAX) || | |
410 | (ACPI_IS_SINGLE_TABLE (acpi_gbl_table_data[table_type].flags) && | |
411 | instance > 1)) { | |
412 | return_ACPI_STATUS (AE_BAD_PARAMETER); | |
413 | } | |
414 | ||
1da177e4 LT |
415 | /* Get a pointer to the entire table */ |
416 | ||
417 | status = acpi_tb_get_table_ptr (table_type, instance, &tbl_ptr); | |
418 | if (ACPI_FAILURE (status)) { | |
419 | return_ACPI_STATUS (status); | |
420 | } | |
421 | ||
422 | /* | |
423 | * acpi_tb_get_table_ptr will return a NULL pointer if the | |
424 | * table is not loaded. | |
425 | */ | |
426 | if (tbl_ptr == NULL) { | |
427 | return_ACPI_STATUS (AE_NOT_EXIST); | |
428 | } | |
429 | ||
430 | /* Get the table length */ | |
431 | ||
432 | if (table_type == ACPI_TABLE_RSDP) { | |
44f6c012 RM |
433 | /* RSD PTR is the only "table" without a header */ |
434 | ||
1da177e4 LT |
435 | table_length = sizeof (struct rsdp_descriptor); |
436 | } | |
437 | else { | |
438 | table_length = (acpi_size) tbl_ptr->length; | |
439 | } | |
440 | ||
441 | /* Validate/Allocate/Clear caller buffer */ | |
442 | ||
443 | status = acpi_ut_initialize_buffer (ret_buffer, table_length); | |
444 | if (ACPI_FAILURE (status)) { | |
445 | return_ACPI_STATUS (status); | |
446 | } | |
447 | ||
448 | /* Copy the table to the buffer */ | |
449 | ||
450 | ACPI_MEMCPY ((void *) ret_buffer->pointer, (void *) tbl_ptr, table_length); | |
451 | return_ACPI_STATUS (AE_OK); | |
452 | } | |
453 | EXPORT_SYMBOL(acpi_get_table); | |
454 |