diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/acpi/tables/tbxface.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/acpi/tables/tbxface.c')
-rw-r--r-- | drivers/acpi/tables/tbxface.c | 448 |
1 files changed, 448 insertions, 0 deletions
diff --git a/drivers/acpi/tables/tbxface.c b/drivers/acpi/tables/tbxface.c new file mode 100644 index 000000000000..7715043461c4 --- /dev/null +++ b/drivers/acpi/tables/tbxface.c | |||
@@ -0,0 +1,448 @@ | |||
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 | ||
70 | acpi_load_tables (void) | ||
71 | { | ||
72 | struct acpi_pointer rsdp_address; | ||
73 | acpi_status status; | ||
74 | |||
75 | |||
76 | ACPI_FUNCTION_TRACE ("acpi_load_tables"); | ||
77 | |||
78 | |||
79 | /* Get the RSDP */ | ||
80 | |||
81 | status = acpi_os_get_root_pointer (ACPI_LOGICAL_ADDRESSING, | ||
82 | &rsdp_address); | ||
83 | if (ACPI_FAILURE (status)) { | ||
84 | ACPI_REPORT_ERROR (("acpi_load_tables: Could not get RSDP, %s\n", | ||
85 | acpi_format_exception (status))); | ||
86 | goto error_exit; | ||
87 | } | ||
88 | |||
89 | /* Map and validate the RSDP */ | ||
90 | |||
91 | acpi_gbl_table_flags = rsdp_address.pointer_type; | ||
92 | |||
93 | status = acpi_tb_verify_rsdp (&rsdp_address); | ||
94 | if (ACPI_FAILURE (status)) { | ||
95 | ACPI_REPORT_ERROR (("acpi_load_tables: RSDP Failed validation: %s\n", | ||
96 | acpi_format_exception (status))); | ||
97 | goto error_exit; | ||
98 | } | ||
99 | |||
100 | /* Get the RSDT via the RSDP */ | ||
101 | |||
102 | status = acpi_tb_get_table_rsdt (); | ||
103 | if (ACPI_FAILURE (status)) { | ||
104 | ACPI_REPORT_ERROR (("acpi_load_tables: Could not load RSDT: %s\n", | ||
105 | acpi_format_exception (status))); | ||
106 | goto error_exit; | ||
107 | } | ||
108 | |||
109 | /* Now get the tables needed by this subsystem (FADT, DSDT, etc.) */ | ||
110 | |||
111 | status = acpi_tb_get_required_tables (); | ||
112 | if (ACPI_FAILURE (status)) { | ||
113 | ACPI_REPORT_ERROR (("acpi_load_tables: Error getting required tables (DSDT/FADT/FACS): %s\n", | ||
114 | acpi_format_exception (status))); | ||
115 | goto error_exit; | ||
116 | } | ||
117 | |||
118 | ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI Tables successfully acquired\n")); | ||
119 | |||
120 | |||
121 | /* Load the namespace from the tables */ | ||
122 | |||
123 | status = acpi_ns_load_namespace (); | ||
124 | if (ACPI_FAILURE (status)) { | ||
125 | ACPI_REPORT_ERROR (("acpi_load_tables: Could not load namespace: %s\n", | ||
126 | acpi_format_exception (status))); | ||
127 | goto error_exit; | ||
128 | } | ||
129 | |||
130 | return_ACPI_STATUS (AE_OK); | ||
131 | |||
132 | |||
133 | error_exit: | ||
134 | ACPI_REPORT_ERROR (("acpi_load_tables: Could not load tables: %s\n", | ||
135 | acpi_format_exception (status))); | ||
136 | |||
137 | return_ACPI_STATUS (status); | ||
138 | } | ||
139 | |||
140 | |||
141 | #ifdef ACPI_FUTURE_USAGE | ||
142 | |||
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 | |||
185 | /* Install the new table into the local data structures */ | ||
186 | |||
187 | status = acpi_tb_install_table (&table_info); | ||
188 | if (ACPI_FAILURE (status)) { | ||
189 | /* Free table allocated by acpi_tb_get_table_body */ | ||
190 | |||
191 | acpi_tb_delete_single_table (&table_info); | ||
192 | return_ACPI_STATUS (status); | ||
193 | } | ||
194 | |||
195 | /* Convert the table to common format if necessary */ | ||
196 | |||
197 | switch (table_info.type) { | ||
198 | case ACPI_TABLE_FADT: | ||
199 | |||
200 | status = acpi_tb_convert_table_fadt (); | ||
201 | break; | ||
202 | |||
203 | case ACPI_TABLE_FACS: | ||
204 | |||
205 | status = acpi_tb_build_common_facs (&table_info); | ||
206 | break; | ||
207 | |||
208 | default: | ||
209 | /* Load table into namespace if it contains executable AML */ | ||
210 | |||
211 | status = acpi_ns_load_table (table_info.installed_desc, acpi_gbl_root_node); | ||
212 | break; | ||
213 | } | ||
214 | |||
215 | if (ACPI_FAILURE (status)) { | ||
216 | /* Uninstall table and free the buffer */ | ||
217 | |||
218 | (void) acpi_tb_uninstall_table (table_info.installed_desc); | ||
219 | } | ||
220 | |||
221 | return_ACPI_STATUS (status); | ||
222 | } | ||
223 | |||
224 | |||
225 | /******************************************************************************* | ||
226 | * | ||
227 | * FUNCTION: acpi_unload_table | ||
228 | * | ||
229 | * PARAMETERS: table_type - Type of table to be unloaded | ||
230 | * | ||
231 | * RETURN: Status | ||
232 | * | ||
233 | * DESCRIPTION: This routine is used to force the unload of a table | ||
234 | * | ||
235 | ******************************************************************************/ | ||
236 | |||
237 | acpi_status | ||
238 | acpi_unload_table ( | ||
239 | acpi_table_type table_type) | ||
240 | { | ||
241 | struct acpi_table_desc *table_desc; | ||
242 | |||
243 | |||
244 | ACPI_FUNCTION_TRACE ("acpi_unload_table"); | ||
245 | |||
246 | |||
247 | /* Parameter validation */ | ||
248 | |||
249 | if (table_type > ACPI_TABLE_MAX) { | ||
250 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
251 | } | ||
252 | |||
253 | |||
254 | /* Find all tables of the requested type */ | ||
255 | |||
256 | table_desc = acpi_gbl_table_lists[table_type].next; | ||
257 | while (table_desc) { | ||
258 | /* | ||
259 | * Delete all namespace entries owned by this table. Note that these | ||
260 | * entries can appear anywhere in the namespace by virtue of the AML | ||
261 | * "Scope" operator. Thus, we need to track ownership by an ID, not | ||
262 | * simply a position within the hierarchy | ||
263 | */ | ||
264 | acpi_ns_delete_namespace_by_owner (table_desc->table_id); | ||
265 | |||
266 | table_desc = table_desc->next; | ||
267 | } | ||
268 | |||
269 | /* Delete (or unmap) all tables of this type */ | ||
270 | |||
271 | acpi_tb_delete_tables_by_type (table_type); | ||
272 | return_ACPI_STATUS (AE_OK); | ||
273 | } | ||
274 | |||
275 | |||
276 | /******************************************************************************* | ||
277 | * | ||
278 | * FUNCTION: acpi_get_table_header | ||
279 | * | ||
280 | * PARAMETERS: table_type - one of the defined table types | ||
281 | * Instance - the non zero instance of the table, allows | ||
282 | * support for multiple tables of the same type | ||
283 | * see acpi_gbl_acpi_table_flag | ||
284 | * out_table_header - pointer to the struct acpi_table_header if successful | ||
285 | * | ||
286 | * DESCRIPTION: This function is called to get an ACPI table header. The caller | ||
287 | * supplies an pointer to a data area sufficient to contain an ACPI | ||
288 | * struct acpi_table_header structure. | ||
289 | * | ||
290 | * The header contains a length field that can be used to determine | ||
291 | * the size of the buffer needed to contain the entire table. This | ||
292 | * function is not valid for the RSD PTR table since it does not | ||
293 | * have a standard header and is fixed length. | ||
294 | * | ||
295 | ******************************************************************************/ | ||
296 | |||
297 | acpi_status | ||
298 | acpi_get_table_header ( | ||
299 | acpi_table_type table_type, | ||
300 | u32 instance, | ||
301 | struct acpi_table_header *out_table_header) | ||
302 | { | ||
303 | struct acpi_table_header *tbl_ptr; | ||
304 | acpi_status status; | ||
305 | |||
306 | |||
307 | ACPI_FUNCTION_TRACE ("acpi_get_table_header"); | ||
308 | |||
309 | |||
310 | if ((instance == 0) || | ||
311 | (table_type == ACPI_TABLE_RSDP) || | ||
312 | (!out_table_header)) { | ||
313 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
314 | } | ||
315 | |||
316 | /* Check the table type and instance */ | ||
317 | |||
318 | if ((table_type > ACPI_TABLE_MAX) || | ||
319 | (ACPI_IS_SINGLE_TABLE (acpi_gbl_table_data[table_type].flags) && | ||
320 | instance > 1)) { | ||
321 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
322 | } | ||
323 | |||
324 | |||
325 | /* Get a pointer to the entire table */ | ||
326 | |||
327 | status = acpi_tb_get_table_ptr (table_type, instance, &tbl_ptr); | ||
328 | if (ACPI_FAILURE (status)) { | ||
329 | return_ACPI_STATUS (status); | ||
330 | } | ||
331 | |||
332 | /* | ||
333 | * The function will return a NULL pointer if the table is not loaded | ||
334 | */ | ||
335 | if (tbl_ptr == NULL) { | ||
336 | return_ACPI_STATUS (AE_NOT_EXIST); | ||
337 | } | ||
338 | |||
339 | /* | ||
340 | * Copy the header to the caller's buffer | ||
341 | */ | ||
342 | ACPI_MEMCPY ((void *) out_table_header, (void *) tbl_ptr, | ||
343 | sizeof (struct acpi_table_header)); | ||
344 | |||
345 | return_ACPI_STATUS (status); | ||
346 | } | ||
347 | |||
348 | |||
349 | #endif /* ACPI_FUTURE_USAGE */ | ||
350 | |||
351 | /******************************************************************************* | ||
352 | * | ||
353 | * FUNCTION: acpi_get_table | ||
354 | * | ||
355 | * PARAMETERS: table_type - one of the defined table types | ||
356 | * Instance - the non zero instance of the table, allows | ||
357 | * support for multiple tables of the same type | ||
358 | * see acpi_gbl_acpi_table_flag | ||
359 | * ret_buffer - pointer to a structure containing a buffer to | ||
360 | * receive the table | ||
361 | * | ||
362 | * RETURN: Status | ||
363 | * | ||
364 | * DESCRIPTION: This function is called to get an ACPI table. The caller | ||
365 | * supplies an out_buffer large enough to contain the entire ACPI | ||
366 | * table. The caller should call the acpi_get_table_header function | ||
367 | * first to determine the buffer size needed. Upon completion | ||
368 | * the out_buffer->Length field will indicate the number of bytes | ||
369 | * copied into the out_buffer->buf_ptr buffer. This table will be | ||
370 | * a complete table including the header. | ||
371 | * | ||
372 | ******************************************************************************/ | ||
373 | |||
374 | acpi_status | ||
375 | acpi_get_table ( | ||
376 | acpi_table_type table_type, | ||
377 | u32 instance, | ||
378 | struct acpi_buffer *ret_buffer) | ||
379 | { | ||
380 | struct acpi_table_header *tbl_ptr; | ||
381 | acpi_status status; | ||
382 | acpi_size table_length; | ||
383 | |||
384 | |||
385 | ACPI_FUNCTION_TRACE ("acpi_get_table"); | ||
386 | |||
387 | |||
388 | /* Parameter validation */ | ||
389 | |||
390 | if (instance == 0) { | ||
391 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
392 | } | ||
393 | |||
394 | status = acpi_ut_validate_buffer (ret_buffer); | ||
395 | if (ACPI_FAILURE (status)) { | ||
396 | return_ACPI_STATUS (status); | ||
397 | } | ||
398 | |||
399 | /* Check the table type and instance */ | ||
400 | |||
401 | if ((table_type > ACPI_TABLE_MAX) || | ||
402 | (ACPI_IS_SINGLE_TABLE (acpi_gbl_table_data[table_type].flags) && | ||
403 | instance > 1)) { | ||
404 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
405 | } | ||
406 | |||
407 | |||
408 | /* Get a pointer to the entire table */ | ||
409 | |||
410 | status = acpi_tb_get_table_ptr (table_type, instance, &tbl_ptr); | ||
411 | if (ACPI_FAILURE (status)) { | ||
412 | return_ACPI_STATUS (status); | ||
413 | } | ||
414 | |||
415 | /* | ||
416 | * acpi_tb_get_table_ptr will return a NULL pointer if the | ||
417 | * table is not loaded. | ||
418 | */ | ||
419 | if (tbl_ptr == NULL) { | ||
420 | return_ACPI_STATUS (AE_NOT_EXIST); | ||
421 | } | ||
422 | |||
423 | /* Get the table length */ | ||
424 | |||
425 | if (table_type == ACPI_TABLE_RSDP) { | ||
426 | /* | ||
427 | * RSD PTR is the only "table" without a header | ||
428 | */ | ||
429 | table_length = sizeof (struct rsdp_descriptor); | ||
430 | } | ||
431 | else { | ||
432 | table_length = (acpi_size) tbl_ptr->length; | ||
433 | } | ||
434 | |||
435 | /* Validate/Allocate/Clear caller buffer */ | ||
436 | |||
437 | status = acpi_ut_initialize_buffer (ret_buffer, table_length); | ||
438 | if (ACPI_FAILURE (status)) { | ||
439 | return_ACPI_STATUS (status); | ||
440 | } | ||
441 | |||
442 | /* Copy the table to the buffer */ | ||
443 | |||
444 | ACPI_MEMCPY ((void *) ret_buffer->pointer, (void *) tbl_ptr, table_length); | ||
445 | return_ACPI_STATUS (AE_OK); | ||
446 | } | ||
447 | EXPORT_SYMBOL(acpi_get_table); | ||
448 | |||