OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [acpi/] [tables/] [tbxface.c] - Blame information for rev 1275

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.