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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [acpi/] [namespace/] [nsload.c] - Blame information for rev 1774

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

Line No. Rev Author Line
1 1275 phoenix
/******************************************************************************
2
 *
3
 * Module Name: nsload - namespace loading/expanding/contracting procedures
4
 *
5
 *****************************************************************************/
6
 
7
/*
8
 * Copyright (C) 2000 - 2004, R. Byron Moore
9
 * All rights reserved.
10
 *
11
 * Redistribution and use in source and binary forms, with or without
12
 * modification, are permitted provided that the following conditions
13
 * are met:
14
 * 1. Redistributions of source code must retain the above copyright
15
 *    notice, this list of conditions, and the following disclaimer,
16
 *    without modification.
17
 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18
 *    substantially similar to the "NO WARRANTY" disclaimer below
19
 *    ("Disclaimer") and any redistribution must be conditioned upon
20
 *    including a substantially similar Disclaimer requirement for further
21
 *    binary redistribution.
22
 * 3. Neither the names of the above-listed copyright holders nor the names
23
 *    of any contributors may be used to endorse or promote products derived
24
 *    from this software without specific prior written permission.
25
 *
26
 * Alternatively, this software may be distributed under the terms of the
27
 * GNU General Public License ("GPL") version 2 as published by the Free
28
 * Software Foundation.
29
 *
30
 * NO WARRANTY
31
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35
 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41
 * POSSIBILITY OF SUCH DAMAGES.
42
 */
43
 
44
 
45
#include <acpi/acpi.h>
46
#include <acpi/acnamesp.h>
47
#include <acpi/acdispat.h>
48
 
49
 
50
#define _COMPONENT          ACPI_NAMESPACE
51
         ACPI_MODULE_NAME    ("nsload")
52
 
53
 
54
#ifndef ACPI_NO_METHOD_EXECUTION
55
 
56
/*******************************************************************************
57
 *
58
 * FUNCTION:    acpi_ns_load_table
59
 *
60
 * PARAMETERS:  table_desc      - Descriptor for table to be loaded
61
 *              Node            - Owning NS node
62
 *
63
 * RETURN:      Status
64
 *
65
 * DESCRIPTION: Load one ACPI table into the namespace
66
 *
67
 ******************************************************************************/
68
 
69
acpi_status
70
acpi_ns_load_table (
71
        struct acpi_table_desc          *table_desc,
72
        struct acpi_namespace_node      *node)
73
{
74
        acpi_status                     status;
75
 
76
 
77
        ACPI_FUNCTION_TRACE ("ns_load_table");
78
 
79
 
80
        /* Check if table contains valid AML (must be DSDT, PSDT, SSDT, etc.) */
81
 
82
        if (!(acpi_gbl_table_data[table_desc->type].flags & ACPI_TABLE_EXECUTABLE)) {
83
                /* Just ignore this table */
84
 
85
                return_ACPI_STATUS (AE_OK);
86
        }
87
 
88
        /* Check validity of the AML start and length */
89
 
90
        if (!table_desc->aml_start) {
91
                ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null AML pointer\n"));
92
                return_ACPI_STATUS (AE_BAD_PARAMETER);
93
        }
94
 
95
        ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "AML block at %p\n", table_desc->aml_start));
96
 
97
        /* Ignore table if there is no AML contained within */
98
 
99
        if (!table_desc->aml_length) {
100
                ACPI_REPORT_WARNING (("Zero-length AML block in table [%4.4s]\n", table_desc->pointer->signature));
101
                return_ACPI_STATUS (AE_OK);
102
        }
103
 
104
        /*
105
         * Parse the table and load the namespace with all named
106
         * objects found within.  Control methods are NOT parsed
107
         * at this time.  In fact, the control methods cannot be
108
         * parsed until the entire namespace is loaded, because
109
         * if a control method makes a forward reference (call)
110
         * to another control method, we can't continue parsing
111
         * because we don't know how many arguments to parse next!
112
         */
113
        ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "**** Loading table into namespace ****\n"));
114
 
115
        status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
116
        if (ACPI_FAILURE (status)) {
117
                return_ACPI_STATUS (status);
118
        }
119
 
120
        status = acpi_ns_parse_table (table_desc, node->child);
121
        (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
122
 
123
        if (ACPI_FAILURE (status)) {
124
                return_ACPI_STATUS (status);
125
        }
126
 
127
        /*
128
         * Now we can parse the control methods.  We always parse
129
         * them here for a sanity check, and if configured for
130
         * just-in-time parsing, we delete the control method
131
         * parse trees.
132
         */
133
        ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
134
                "**** Begin Table Method Parsing and Object Initialization ****\n"));
135
 
136
        status = acpi_ds_initialize_objects (table_desc, node);
137
 
138
        ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
139
                "**** Completed Table Method Parsing and Object Initialization ****\n"));
140
 
141
        return_ACPI_STATUS (status);
142
}
143
 
144
 
145
/*******************************************************************************
146
 *
147
 * FUNCTION:    acpi_ns_load_table_by_type
148
 *
149
 * PARAMETERS:  table_type          - Id of the table type to load
150
 *
151
 * RETURN:      Status
152
 *
153
 * DESCRIPTION: Load an ACPI table or tables into the namespace.  All tables
154
 *              of the given type are loaded.  The mechanism allows this
155
 *              routine to be called repeatedly.
156
 *
157
 ******************************************************************************/
158
 
159
acpi_status
160
acpi_ns_load_table_by_type (
161
        acpi_table_type                 table_type)
162
{
163
        u32                             i;
164
        acpi_status                     status;
165
        struct acpi_table_desc          *table_desc;
166
 
167
 
168
        ACPI_FUNCTION_TRACE ("ns_load_table_by_type");
169
 
170
 
171
        status = acpi_ut_acquire_mutex (ACPI_MTX_TABLES);
172
        if (ACPI_FAILURE (status)) {
173
                return_ACPI_STATUS (status);
174
        }
175
 
176
        /*
177
         * Table types supported are:
178
         * DSDT (one), SSDT/PSDT (multiple)
179
         */
180
        switch (table_type) {
181
        case ACPI_TABLE_DSDT:
182
 
183
                ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Loading DSDT\n"));
184
 
185
                table_desc = acpi_gbl_table_lists[ACPI_TABLE_DSDT].next;
186
 
187
                /* If table already loaded into namespace, just return */
188
 
189
                if (table_desc->loaded_into_namespace) {
190
                        goto unlock_and_exit;
191
                }
192
 
193
                /* Now load the single DSDT */
194
 
195
                status = acpi_ns_load_table (table_desc, acpi_gbl_root_node);
196
                if (ACPI_SUCCESS (status)) {
197
                        table_desc->loaded_into_namespace = TRUE;
198
                }
199
 
200
                break;
201
 
202
 
203
        case ACPI_TABLE_SSDT:
204
 
205
                ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Loading %d SSDTs\n",
206
                        acpi_gbl_table_lists[ACPI_TABLE_SSDT].count));
207
 
208
                /*
209
                 * Traverse list of SSDT tables
210
                 */
211
                table_desc = acpi_gbl_table_lists[ACPI_TABLE_SSDT].next;
212
                for (i = 0; i < acpi_gbl_table_lists[ACPI_TABLE_SSDT].count; i++) {
213
                        /*
214
                         * Only attempt to load table if it is not
215
                         * already loaded!
216
                         */
217
                        if (!table_desc->loaded_into_namespace) {
218
                                status = acpi_ns_load_table (table_desc, acpi_gbl_root_node);
219
                                if (ACPI_FAILURE (status)) {
220
                                        break;
221
                                }
222
 
223
                                table_desc->loaded_into_namespace = TRUE;
224
                        }
225
 
226
                        table_desc = table_desc->next;
227
                }
228
                break;
229
 
230
 
231
        case ACPI_TABLE_PSDT:
232
 
233
                ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Loading %d PSDTs\n",
234
                        acpi_gbl_table_lists[ACPI_TABLE_PSDT].count));
235
 
236
                /*
237
                 * Traverse list of PSDT tables
238
                 */
239
                table_desc = acpi_gbl_table_lists[ACPI_TABLE_PSDT].next;
240
 
241
                for (i = 0; i < acpi_gbl_table_lists[ACPI_TABLE_PSDT].count; i++) {
242
                        /* Only attempt to load table if it is not already loaded! */
243
 
244
                        if (!table_desc->loaded_into_namespace) {
245
                                status = acpi_ns_load_table (table_desc, acpi_gbl_root_node);
246
                                if (ACPI_FAILURE (status)) {
247
                                        break;
248
                                }
249
 
250
                                table_desc->loaded_into_namespace = TRUE;
251
                        }
252
 
253
                        table_desc = table_desc->next;
254
                }
255
 
256
                break;
257
 
258
 
259
        default:
260
                status = AE_SUPPORT;
261
                break;
262
        }
263
 
264
 
265
unlock_and_exit:
266
        (void) acpi_ut_release_mutex (ACPI_MTX_TABLES);
267
        return_ACPI_STATUS (status);
268
}
269
 
270
 
271
/*******************************************************************************
272
 *
273
 * FUNCTION:    acpi_load_namespace
274
 *
275
 * PARAMETERS:  None
276
 *
277
 * RETURN:      Status
278
 *
279
 * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
280
 *              (DSDT points to either the BIOS or a buffer.)
281
 *
282
 ******************************************************************************/
283
 
284
acpi_status
285
acpi_ns_load_namespace (
286
        void)
287
{
288
        acpi_status                     status;
289
 
290
 
291
        ACPI_FUNCTION_TRACE ("acpi_load_name_space");
292
 
293
 
294
        /* There must be at least a DSDT installed */
295
 
296
        if (acpi_gbl_DSDT == NULL) {
297
                ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "DSDT is not in memory\n"));
298
                return_ACPI_STATUS (AE_NO_ACPI_TABLES);
299
        }
300
 
301
        /*
302
         * Load the namespace.  The DSDT is required,
303
         * but the SSDT and PSDT tables are optional.
304
         */
305
        status = acpi_ns_load_table_by_type (ACPI_TABLE_DSDT);
306
        if (ACPI_FAILURE (status)) {
307
                return_ACPI_STATUS (status);
308
        }
309
 
310
        /* Ignore exceptions from these */
311
 
312
        (void) acpi_ns_load_table_by_type (ACPI_TABLE_SSDT);
313
        (void) acpi_ns_load_table_by_type (ACPI_TABLE_PSDT);
314
 
315
        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
316
                "ACPI Namespace successfully loaded at root %p\n",
317
                acpi_gbl_root_node));
318
 
319
        return_ACPI_STATUS (status);
320
}
321
 
322
 
323
/*******************************************************************************
324
 *
325
 * FUNCTION:    acpi_ns_delete_subtree
326
 *
327
 * PARAMETERS:  start_handle        - Handle in namespace where search begins
328
 *
329
 * RETURNS      Status
330
 *
331
 * DESCRIPTION: Walks the namespace starting at the given handle and deletes
332
 *              all objects, entries, and scopes in the entire subtree.
333
 *
334
 *              Namespace/Interpreter should be locked or the subsystem should
335
 *              be in shutdown before this routine is called.
336
 *
337
 ******************************************************************************/
338
 
339
acpi_status
340
acpi_ns_delete_subtree (
341
        acpi_handle                     start_handle)
342
{
343
        acpi_status                     status;
344
        acpi_handle                     child_handle;
345
        acpi_handle                     parent_handle;
346
        acpi_handle                     next_child_handle;
347
        acpi_handle                     dummy;
348
        u32                             level;
349
 
350
 
351
        ACPI_FUNCTION_TRACE ("ns_delete_subtree");
352
 
353
 
354
        parent_handle = start_handle;
355
        child_handle = 0;
356
        level        = 1;
357
 
358
        /*
359
         * Traverse the tree of objects until we bubble back up
360
         * to where we started.
361
         */
362
        while (level > 0) {
363
                /* Attempt to get the next object in this scope */
364
 
365
                status = acpi_get_next_object (ACPI_TYPE_ANY, parent_handle,
366
                                  child_handle, &next_child_handle);
367
 
368
                child_handle = next_child_handle;
369
 
370
                /* Did we get a new object? */
371
 
372
                if (ACPI_SUCCESS (status)) {
373
                        /* Check if this object has any children */
374
 
375
                        if (ACPI_SUCCESS (acpi_get_next_object (ACPI_TYPE_ANY, child_handle,
376
                                         0, &dummy))) {
377
                                /*
378
                                 * There is at least one child of this object,
379
                                 * visit the object
380
                                 */
381
                                level++;
382
                                parent_handle = child_handle;
383
                                child_handle = 0;
384
                        }
385
                }
386
                else {
387
                        /*
388
                         * No more children in this object, go back up to
389
                         * the object's parent
390
                         */
391
                        level--;
392
 
393
                        /* Delete all children now */
394
 
395
                        acpi_ns_delete_children (child_handle);
396
 
397
                        child_handle = parent_handle;
398
                        status = acpi_get_parent (parent_handle, &parent_handle);
399
                        if (ACPI_FAILURE (status)) {
400
                                return_ACPI_STATUS (status);
401
                        }
402
                }
403
        }
404
 
405
        /* Now delete the starting object, and we are done */
406
 
407
        acpi_ns_delete_node (child_handle);
408
 
409
        return_ACPI_STATUS (AE_OK);
410
}
411
 
412
 
413
/*******************************************************************************
414
 *
415
 *  FUNCTION:       acpi_ns_unload_name_space
416
 *
417
 *  PARAMETERS:     Handle          - Root of namespace subtree to be deleted
418
 *
419
 *  RETURN:         Status
420
 *
421
 *  DESCRIPTION:    Shrinks the namespace, typically in response to an undocking
422
 *                  event.  Deletes an entire subtree starting from (and
423
 *                  including) the given handle.
424
 *
425
 ******************************************************************************/
426
 
427
acpi_status
428
acpi_ns_unload_namespace (
429
        acpi_handle                     handle)
430
{
431
        acpi_status                     status;
432
 
433
 
434
        ACPI_FUNCTION_TRACE ("ns_unload_name_space");
435
 
436
 
437
        /* Parameter validation */
438
 
439
        if (!acpi_gbl_root_node) {
440
                return_ACPI_STATUS (AE_NO_NAMESPACE);
441
        }
442
 
443
        if (!handle) {
444
                return_ACPI_STATUS (AE_BAD_PARAMETER);
445
        }
446
 
447
        /* This function does the real work */
448
 
449
        status = acpi_ns_delete_subtree (handle);
450
 
451
        return_ACPI_STATUS (status);
452
}
453
 
454
#endif
455
 

powered by: WebSVN 2.1.0

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