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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [acpi/] [namespace/] [nsutils.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: nsutils - Utilities for accessing ACPI namespace, accessing
4
 *                        parents and siblings and Scope manipulation
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/amlcode.h>
49
#include <acpi/actables.h>
50
 
51
#define _COMPONENT          ACPI_NAMESPACE
52
         ACPI_MODULE_NAME    ("nsutils")
53
 
54
 
55
/*******************************************************************************
56
 *
57
 * FUNCTION:    acpi_ns_report_error
58
 *
59
 * PARAMETERS:  module_name         - Caller's module name (for error output)
60
 *              line_number         - Caller's line number (for error output)
61
 *              component_id        - Caller's component ID (for error output)
62
 *              Message             - Error message to use on failure
63
 *
64
 * RETURN:      None
65
 *
66
 * DESCRIPTION: Print warning message with full pathname
67
 *
68
 ******************************************************************************/
69
 
70
void
71
acpi_ns_report_error (
72
        char                            *module_name,
73
        u32                             line_number,
74
        u32                             component_id,
75
        char                            *internal_name,
76
        acpi_status                     lookup_status)
77
{
78
        acpi_status                     status;
79
        char                            *name = NULL;
80
 
81
 
82
        acpi_os_printf ("%8s-%04d: *** Error: Looking up ",
83
                module_name, line_number);
84
 
85
        if (lookup_status == AE_BAD_CHARACTER) {
86
                /* There is a non-ascii character in the name */
87
 
88
                acpi_os_printf ("[0x%4.4X] (NON-ASCII)\n", *(ACPI_CAST_PTR (u32, internal_name)));
89
        }
90
        else {
91
                /* Convert path to external format */
92
 
93
                status = acpi_ns_externalize_name (ACPI_UINT32_MAX, internal_name, NULL, &name);
94
 
95
                /* Print target name */
96
 
97
                if (ACPI_SUCCESS (status)) {
98
                        acpi_os_printf ("[%s]", name);
99
                }
100
                else {
101
                        acpi_os_printf ("[COULD NOT EXTERNALIZE NAME]");
102
                }
103
 
104
                if (name) {
105
                        ACPI_MEM_FREE (name);
106
                }
107
        }
108
 
109
        acpi_os_printf (" in namespace, %s\n",
110
                acpi_format_exception (lookup_status));
111
}
112
 
113
 
114
/*******************************************************************************
115
 *
116
 * FUNCTION:    acpi_ns_report_method_error
117
 *
118
 * PARAMETERS:  module_name         - Caller's module name (for error output)
119
 *              line_number         - Caller's line number (for error output)
120
 *              component_id        - Caller's component ID (for error output)
121
 *              Message             - Error message to use on failure
122
 *
123
 * RETURN:      None
124
 *
125
 * DESCRIPTION: Print warning message with full pathname
126
 *
127
 ******************************************************************************/
128
 
129
void
130
acpi_ns_report_method_error (
131
        char                            *module_name,
132
        u32                             line_number,
133
        u32                             component_id,
134
        char                            *message,
135
        struct acpi_namespace_node      *prefix_node,
136
        char                            *path,
137
        acpi_status                     method_status)
138
{
139
        acpi_status                     status;
140
        struct acpi_namespace_node      *node = prefix_node;
141
 
142
 
143
        if (path) {
144
                status = acpi_ns_get_node_by_path (path, prefix_node, ACPI_NS_NO_UPSEARCH, &node);
145
                if (ACPI_FAILURE (status)) {
146
                        acpi_os_printf ("report_method_error: Could not get node\n");
147
                        return;
148
                }
149
        }
150
 
151
        acpi_os_printf ("%8s-%04d: *** Error: ", module_name, line_number);
152
        acpi_ns_print_node_pathname (node, message);
153
        acpi_os_printf (", %s\n", acpi_format_exception (method_status));
154
}
155
 
156
 
157
/*******************************************************************************
158
 *
159
 * FUNCTION:    acpi_ns_print_node_pathname
160
 *
161
 * PARAMETERS:  Node                - Object
162
 *              Msg                 - Prefix message
163
 *
164
 * DESCRIPTION: Print an object's full namespace pathname
165
 *              Manages allocation/freeing of a pathname buffer
166
 *
167
 ******************************************************************************/
168
 
169
void
170
acpi_ns_print_node_pathname (
171
        struct acpi_namespace_node      *node,
172
        char                            *msg)
173
{
174
        struct acpi_buffer              buffer;
175
        acpi_status                     status;
176
 
177
 
178
        if (!node) {
179
                acpi_os_printf ("[NULL NAME]");
180
                return;
181
        }
182
 
183
        /* Convert handle to a full pathname and print it (with supplied message) */
184
 
185
        buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
186
 
187
        status = acpi_ns_handle_to_pathname (node, &buffer);
188
        if (ACPI_SUCCESS (status)) {
189
                if (msg) {
190
                        acpi_os_printf ("%s ", msg);
191
                }
192
 
193
                acpi_os_printf ("[%s] (Node %p)", (char *) buffer.pointer, node);
194
                ACPI_MEM_FREE (buffer.pointer);
195
        }
196
}
197
 
198
 
199
/*******************************************************************************
200
 *
201
 * FUNCTION:    acpi_ns_valid_root_prefix
202
 *
203
 * PARAMETERS:  Prefix          - Character to be checked
204
 *
205
 * RETURN:      TRUE if a valid prefix
206
 *
207
 * DESCRIPTION: Check if a character is a valid ACPI Root prefix
208
 *
209
 ******************************************************************************/
210
 
211
u8
212
acpi_ns_valid_root_prefix (
213
        char                            prefix)
214
{
215
 
216
        return ((u8) (prefix == '\\'));
217
}
218
 
219
 
220
/*******************************************************************************
221
 *
222
 * FUNCTION:    acpi_ns_valid_path_separator
223
 *
224
 * PARAMETERS:  Sep              - Character to be checked
225
 *
226
 * RETURN:      TRUE if a valid path separator
227
 *
228
 * DESCRIPTION: Check if a character is a valid ACPI path separator
229
 *
230
 ******************************************************************************/
231
 
232
u8
233
acpi_ns_valid_path_separator (
234
        char                            sep)
235
{
236
 
237
        return ((u8) (sep == '.'));
238
}
239
 
240
 
241
/*******************************************************************************
242
 *
243
 * FUNCTION:    acpi_ns_get_type
244
 *
245
 * PARAMETERS:  Handle              - Parent Node to be examined
246
 *
247
 * RETURN:      Type field from Node whose handle is passed
248
 *
249
 ******************************************************************************/
250
 
251
acpi_object_type
252
acpi_ns_get_type (
253
        struct acpi_namespace_node      *node)
254
{
255
        ACPI_FUNCTION_TRACE ("ns_get_type");
256
 
257
 
258
        if (!node) {
259
                ACPI_REPORT_WARNING (("ns_get_type: Null Node input pointer\n"));
260
                return_VALUE (ACPI_TYPE_ANY);
261
        }
262
 
263
        return_VALUE ((acpi_object_type) node->type);
264
}
265
 
266
 
267
/*******************************************************************************
268
 *
269
 * FUNCTION:    acpi_ns_local
270
 *
271
 * PARAMETERS:  Type            - A namespace object type
272
 *
273
 * RETURN:      LOCAL if names must be found locally in objects of the
274
 *              passed type, 0 if enclosing scopes should be searched
275
 *
276
 ******************************************************************************/
277
 
278
u32
279
acpi_ns_local (
280
        acpi_object_type                type)
281
{
282
        ACPI_FUNCTION_TRACE ("ns_local");
283
 
284
 
285
        if (!acpi_ut_valid_object_type (type)) {
286
                /* Type code out of range  */
287
 
288
                ACPI_REPORT_WARNING (("ns_local: Invalid Object Type\n"));
289
                return_VALUE (ACPI_NS_NORMAL);
290
        }
291
 
292
        return_VALUE ((u32) acpi_gbl_ns_properties[type] & ACPI_NS_LOCAL);
293
}
294
 
295
 
296
/*******************************************************************************
297
 *
298
 * FUNCTION:    acpi_ns_get_internal_name_length
299
 *
300
 * PARAMETERS:  Info            - Info struct initialized with the
301
 *                                external name pointer.
302
 *
303
 * RETURN:      Status
304
 *
305
 * DESCRIPTION: Calculate the length of the internal (AML) namestring
306
 *              corresponding to the external (ASL) namestring.
307
 *
308
 ******************************************************************************/
309
 
310
void
311
acpi_ns_get_internal_name_length (
312
        struct acpi_namestring_info     *info)
313
{
314
        char                            *next_external_char;
315
        u32                             i;
316
 
317
 
318
        ACPI_FUNCTION_ENTRY ();
319
 
320
 
321
        next_external_char = info->external_name;
322
        info->num_carats = 0;
323
        info->num_segments = 0;
324
        info->fully_qualified = FALSE;
325
 
326
        /*
327
         * For the internal name, the required length is 4 bytes
328
         * per segment, plus 1 each for root_prefix, multi_name_prefix_op,
329
         * segment count, trailing null (which is not really needed,
330
         * but no there's harm in putting it there)
331
         *
332
         * strlen() + 1 covers the first name_seg, which has no
333
         * path separator
334
         */
335
        if (acpi_ns_valid_root_prefix (next_external_char[0])) {
336
                info->fully_qualified = TRUE;
337
                next_external_char++;
338
        }
339
        else {
340
                /*
341
                 * Handle Carat prefixes
342
                 */
343
                while (*next_external_char == '^') {
344
                        info->num_carats++;
345
                        next_external_char++;
346
                }
347
        }
348
 
349
        /*
350
         * Determine the number of ACPI name "segments" by counting
351
         * the number of path separators within the string.  Start
352
         * with one segment since the segment count is (# separators)
353
         * + 1, and zero separators is ok.
354
         */
355
        if (*next_external_char) {
356
                info->num_segments = 1;
357
                for (i = 0; next_external_char[i]; i++) {
358
                        if (acpi_ns_valid_path_separator (next_external_char[i])) {
359
                                info->num_segments++;
360
                        }
361
                }
362
        }
363
 
364
        info->length = (ACPI_NAME_SIZE * info->num_segments) +
365
                          4 + info->num_carats;
366
 
367
        info->next_external_char = next_external_char;
368
}
369
 
370
 
371
/*******************************************************************************
372
 *
373
 * FUNCTION:    acpi_ns_build_internal_name
374
 *
375
 * PARAMETERS:  Info            - Info struct fully initialized
376
 *
377
 * RETURN:      Status
378
 *
379
 * DESCRIPTION: Construct the internal (AML) namestring
380
 *              corresponding to the external (ASL) namestring.
381
 *
382
 ******************************************************************************/
383
 
384
acpi_status
385
acpi_ns_build_internal_name (
386
        struct acpi_namestring_info     *info)
387
{
388
        u32                             num_segments = info->num_segments;
389
        char                            *internal_name = info->internal_name;
390
        char                            *external_name = info->next_external_char;
391
        char                            *result = NULL;
392
        acpi_native_uint                i;
393
 
394
 
395
        ACPI_FUNCTION_TRACE ("ns_build_internal_name");
396
 
397
 
398
        /* Setup the correct prefixes, counts, and pointers */
399
 
400
        if (info->fully_qualified) {
401
                internal_name[0] = '\\';
402
 
403
                if (num_segments <= 1) {
404
                        result = &internal_name[1];
405
                }
406
                else if (num_segments == 2) {
407
                        internal_name[1] = AML_DUAL_NAME_PREFIX;
408
                        result = &internal_name[2];
409
                }
410
                else {
411
                        internal_name[1] = AML_MULTI_NAME_PREFIX_OP;
412
                        internal_name[2] = (char) num_segments;
413
                        result = &internal_name[3];
414
                }
415
        }
416
        else {
417
                /*
418
                 * Not fully qualified.
419
                 * Handle Carats first, then append the name segments
420
                 */
421
                i = 0;
422
                if (info->num_carats) {
423
                        for (i = 0; i < info->num_carats; i++) {
424
                                internal_name[i] = '^';
425
                        }
426
                }
427
 
428
                if (num_segments <= 1) {
429
                        result = &internal_name[i];
430
                }
431
                else if (num_segments == 2) {
432
                        internal_name[i] = AML_DUAL_NAME_PREFIX;
433
                        result = &internal_name[(acpi_native_uint) (i+1)];
434
                }
435
                else {
436
                        internal_name[i] = AML_MULTI_NAME_PREFIX_OP;
437
                        internal_name[(acpi_native_uint) (i+1)] = (char) num_segments;
438
                        result = &internal_name[(acpi_native_uint) (i+2)];
439
                }
440
        }
441
 
442
        /* Build the name (minus path separators) */
443
 
444
        for (; num_segments; num_segments--) {
445
                for (i = 0; i < ACPI_NAME_SIZE; i++) {
446
                        if (acpi_ns_valid_path_separator (*external_name) ||
447
                           (*external_name == 0)) {
448
                                /* Pad the segment with underscore(s) if segment is short */
449
 
450
                                result[i] = '_';
451
                        }
452
                        else {
453
                                /* Convert the character to uppercase and save it */
454
 
455
                                result[i] = (char) ACPI_TOUPPER ((int) *external_name);
456
                                external_name++;
457
                        }
458
                }
459
 
460
                /* Now we must have a path separator, or the pathname is bad */
461
 
462
                if (!acpi_ns_valid_path_separator (*external_name) &&
463
                        (*external_name != 0)) {
464
                        return_ACPI_STATUS (AE_BAD_PARAMETER);
465
                }
466
 
467
                /* Move on the next segment */
468
 
469
                external_name++;
470
                result += ACPI_NAME_SIZE;
471
        }
472
 
473
        /* Terminate the string */
474
 
475
        *result = 0;
476
 
477
        if (info->fully_qualified) {
478
                ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Returning [%p] (abs) \"\\%s\"\n",
479
                        internal_name, internal_name));
480
        }
481
        else {
482
                ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Returning [%p] (rel) \"%s\"\n",
483
                        internal_name, internal_name));
484
        }
485
 
486
        return_ACPI_STATUS (AE_OK);
487
}
488
 
489
 
490
/*******************************************************************************
491
 *
492
 * FUNCTION:    acpi_ns_internalize_name
493
 *
494
 * PARAMETERS:  *external_name          - External representation of name
495
 *              **Converted Name        - Where to return the resulting
496
 *                                        internal represention of the name
497
 *
498
 * RETURN:      Status
499
 *
500
 * DESCRIPTION: Convert an external representation (e.g. "\_PR_.CPU0")
501
 *              to internal form (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
502
 *
503
 *******************************************************************************/
504
 
505
acpi_status
506
acpi_ns_internalize_name (
507
        char                            *external_name,
508
        char                            **converted_name)
509
{
510
        char                            *internal_name;
511
        struct acpi_namestring_info     info;
512
        acpi_status                     status;
513
 
514
 
515
        ACPI_FUNCTION_TRACE ("ns_internalize_name");
516
 
517
 
518
        if ((!external_name)     ||
519
                (*external_name == 0) ||
520
                (!converted_name)) {
521
                return_ACPI_STATUS (AE_BAD_PARAMETER);
522
        }
523
 
524
        /* Get the length of the new internal name */
525
 
526
        info.external_name = external_name;
527
        acpi_ns_get_internal_name_length (&info);
528
 
529
        /* We need a segment to store the internal  name */
530
 
531
        internal_name = ACPI_MEM_CALLOCATE (info.length);
532
        if (!internal_name) {
533
                return_ACPI_STATUS (AE_NO_MEMORY);
534
        }
535
 
536
        /* Build the name */
537
 
538
        info.internal_name = internal_name;
539
        status = acpi_ns_build_internal_name (&info);
540
        if (ACPI_FAILURE (status)) {
541
                ACPI_MEM_FREE (internal_name);
542
                return_ACPI_STATUS (status);
543
        }
544
 
545
        *converted_name = internal_name;
546
        return_ACPI_STATUS (AE_OK);
547
}
548
 
549
 
550
/*******************************************************************************
551
 *
552
 * FUNCTION:    acpi_ns_externalize_name
553
 *
554
 * PARAMETERS:  *internal_name         - Internal representation of name
555
 *              **converted_name       - Where to return the resulting
556
 *                                       external representation of name
557
 *
558
 * RETURN:      Status
559
 *
560
 * DESCRIPTION: Convert internal name (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
561
 *              to its external form (e.g. "\_PR_.CPU0")
562
 *
563
 ******************************************************************************/
564
 
565
acpi_status
566
acpi_ns_externalize_name (
567
        u32                             internal_name_length,
568
        char                            *internal_name,
569
        u32                             *converted_name_length,
570
        char                            **converted_name)
571
{
572
        acpi_native_uint                names_index = 0;
573
        acpi_native_uint                num_segments = 0;
574
        acpi_native_uint                required_length;
575
        acpi_native_uint                prefix_length = 0;
576
        acpi_native_uint                i = 0;
577
        acpi_native_uint                j = 0;
578
 
579
 
580
        ACPI_FUNCTION_TRACE ("ns_externalize_name");
581
 
582
 
583
        if (!internal_name_length   ||
584
                !internal_name          ||
585
                !converted_name) {
586
                return_ACPI_STATUS (AE_BAD_PARAMETER);
587
        }
588
 
589
        /*
590
         * Check for a prefix (one '\' | one or more '^').
591
         */
592
        switch (internal_name[0]) {
593
        case '\\':
594
                prefix_length = 1;
595
                break;
596
 
597
        case '^':
598
                for (i = 0; i < internal_name_length; i++) {
599
                        if (internal_name[i] == '^') {
600
                                prefix_length = i + 1;
601
                        }
602
                        else {
603
                                break;
604
                        }
605
                }
606
 
607
                if (i == internal_name_length) {
608
                        prefix_length = i;
609
                }
610
 
611
                break;
612
 
613
        default:
614
                break;
615
        }
616
 
617
        /*
618
         * Check for object names.  Note that there could be 0-255 of these
619
         * 4-byte elements.
620
         */
621
        if (prefix_length < internal_name_length) {
622
                switch (internal_name[prefix_length]) {
623
                case AML_MULTI_NAME_PREFIX_OP:
624
 
625
                        /* <count> 4-byte names */
626
 
627
                        names_index = prefix_length + 2;
628
                        num_segments = (acpi_native_uint) (u8) internal_name[(acpi_native_uint) (prefix_length + 1)];
629
                        break;
630
 
631
                case AML_DUAL_NAME_PREFIX:
632
 
633
                        /* Two 4-byte names */
634
 
635
                        names_index = prefix_length + 1;
636
                        num_segments = 2;
637
                        break;
638
 
639
                case 0:
640
 
641
                        /* null_name */
642
 
643
                        names_index = 0;
644
                        num_segments = 0;
645
                        break;
646
 
647
                default:
648
 
649
                        /* one 4-byte name */
650
 
651
                        names_index = prefix_length;
652
                        num_segments = 1;
653
                        break;
654
                }
655
        }
656
 
657
        /*
658
         * Calculate the length of converted_name, which equals the length
659
         * of the prefix, length of all object names, length of any required
660
         * punctuation ('.') between object names, plus the NULL terminator.
661
         */
662
        required_length = prefix_length + (4 * num_segments) +
663
                           ((num_segments > 0) ? (num_segments - 1) : 0) + 1;
664
 
665
        /*
666
         * Check to see if we're still in bounds.  If not, there's a problem
667
         * with internal_name (invalid format).
668
         */
669
        if (required_length > internal_name_length) {
670
                ACPI_REPORT_ERROR (("ns_externalize_name: Invalid internal name\n"));
671
                return_ACPI_STATUS (AE_BAD_PATHNAME);
672
        }
673
 
674
        /*
675
         * Build converted_name...
676
         */
677
        *converted_name = ACPI_MEM_CALLOCATE (required_length);
678
        if (!(*converted_name)) {
679
                return_ACPI_STATUS (AE_NO_MEMORY);
680
        }
681
 
682
        j = 0;
683
 
684
        for (i = 0; i < prefix_length; i++) {
685
                (*converted_name)[j++] = internal_name[i];
686
        }
687
 
688
        if (num_segments > 0) {
689
                for (i = 0; i < num_segments; i++) {
690
                        if (i > 0) {
691
                                (*converted_name)[j++] = '.';
692
                        }
693
 
694
                        (*converted_name)[j++] = internal_name[names_index++];
695
                        (*converted_name)[j++] = internal_name[names_index++];
696
                        (*converted_name)[j++] = internal_name[names_index++];
697
                        (*converted_name)[j++] = internal_name[names_index++];
698
                }
699
        }
700
 
701
        if (converted_name_length) {
702
                *converted_name_length = (u32) required_length;
703
        }
704
 
705
        return_ACPI_STATUS (AE_OK);
706
}
707
 
708
 
709
/*******************************************************************************
710
 *
711
 * FUNCTION:    acpi_ns_map_handle_to_node
712
 *
713
 * PARAMETERS:  Handle          - Handle to be converted to an Node
714
 *
715
 * RETURN:      A Name table entry pointer
716
 *
717
 * DESCRIPTION: Convert a namespace handle to a real Node
718
 *
719
 * Note: Real integer handles allow for more verification
720
 *       and keep all pointers within this subsystem.
721
 *
722
 ******************************************************************************/
723
 
724
struct acpi_namespace_node *
725
acpi_ns_map_handle_to_node (
726
        acpi_handle                     handle)
727
{
728
 
729
        ACPI_FUNCTION_ENTRY ();
730
 
731
 
732
        /*
733
         * Simple implementation.
734
         */
735
        if (!handle) {
736
                return (NULL);
737
        }
738
 
739
        if (handle == ACPI_ROOT_OBJECT) {
740
                return (acpi_gbl_root_node);
741
        }
742
 
743
        /* We can at least attempt to verify the handle */
744
 
745
        if (ACPI_GET_DESCRIPTOR_TYPE (handle) != ACPI_DESC_TYPE_NAMED) {
746
                return (NULL);
747
        }
748
 
749
        return ((struct acpi_namespace_node *) handle);
750
}
751
 
752
 
753
/*******************************************************************************
754
 *
755
 * FUNCTION:    acpi_ns_convert_entry_to_handle
756
 *
757
 * PARAMETERS:  Node          - Node to be converted to a Handle
758
 *
759
 * RETURN:      An USER acpi_handle
760
 *
761
 * DESCRIPTION: Convert a real Node to a namespace handle
762
 *
763
 ******************************************************************************/
764
 
765
acpi_handle
766
acpi_ns_convert_entry_to_handle (
767
        struct acpi_namespace_node          *node)
768
{
769
 
770
 
771
        /*
772
         * Simple implementation for now;
773
         */
774
        return ((acpi_handle) node);
775
 
776
 
777
/* ---------------------------------------------------
778
 
779
        if (!Node)
780
        {
781
                return (NULL);
782
        }
783
 
784
        if (Node == acpi_gbl_root_node)
785
        {
786
                return (ACPI_ROOT_OBJECT);
787
        }
788
 
789
 
790
        return ((acpi_handle) Node);
791
------------------------------------------------------*/
792
}
793
 
794
 
795
/*******************************************************************************
796
 *
797
 * FUNCTION:    acpi_ns_terminate
798
 *
799
 * PARAMETERS:  none
800
 *
801
 * RETURN:      none
802
 *
803
 * DESCRIPTION: free memory allocated for table storage.
804
 *
805
 ******************************************************************************/
806
 
807
void
808
acpi_ns_terminate (void)
809
{
810
        union acpi_operand_object       *obj_desc;
811
 
812
 
813
        ACPI_FUNCTION_TRACE ("ns_terminate");
814
 
815
 
816
        /*
817
         * 1) Free the entire namespace -- all nodes and objects
818
         *
819
         * Delete all object descriptors attached to namepsace nodes
820
         */
821
        acpi_ns_delete_namespace_subtree (acpi_gbl_root_node);
822
 
823
        /* Detach any objects attached to the root */
824
 
825
        obj_desc = acpi_ns_get_attached_object (acpi_gbl_root_node);
826
        if (obj_desc) {
827
                acpi_ns_detach_object (acpi_gbl_root_node);
828
        }
829
 
830
        ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Namespace freed\n"));
831
 
832
        /*
833
         * 2) Now we can delete the ACPI tables
834
         */
835
        acpi_tb_delete_all_tables ();
836
        ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n"));
837
 
838
        return_VOID;
839
}
840
 
841
 
842
/*******************************************************************************
843
 *
844
 * FUNCTION:    acpi_ns_opens_scope
845
 *
846
 * PARAMETERS:  Type        - A valid namespace type
847
 *
848
 * RETURN:      NEWSCOPE if the passed type "opens a name scope" according
849
 *              to the ACPI specification, else 0
850
 *
851
 ******************************************************************************/
852
 
853
u32
854
acpi_ns_opens_scope (
855
        acpi_object_type                type)
856
{
857
        ACPI_FUNCTION_TRACE_STR ("ns_opens_scope", acpi_ut_get_type_name (type));
858
 
859
 
860
        if (!acpi_ut_valid_object_type (type)) {
861
                /* type code out of range  */
862
 
863
                ACPI_REPORT_WARNING (("ns_opens_scope: Invalid Object Type %X\n", type));
864
                return_VALUE (ACPI_NS_NORMAL);
865
        }
866
 
867
        return_VALUE (((u32) acpi_gbl_ns_properties[type]) & ACPI_NS_NEWSCOPE);
868
}
869
 
870
 
871
/*******************************************************************************
872
 *
873
 * FUNCTION:    acpi_ns_get_node_by_path
874
 *
875
 * PARAMETERS:  *Pathname   - Name to be found, in external (ASL) format. The
876
 *                            \ (backslash) and ^ (carat) prefixes, and the
877
 *                            . (period) to separate segments are supported.
878
 *              start_node  - Root of subtree to be searched, or NS_ALL for the
879
 *                            root of the name space.  If Name is fully
880
 *                            qualified (first s8 is '\'), the passed value
881
 *                            of Scope will not be accessed.
882
 *              Flags       - Used to indicate whether to perform upsearch or
883
 *                            not.
884
 *              return_node - Where the Node is returned
885
 *
886
 * DESCRIPTION: Look up a name relative to a given scope and return the
887
 *              corresponding Node.  NOTE: Scope can be null.
888
 *
889
 * MUTEX:       Locks namespace
890
 *
891
 ******************************************************************************/
892
 
893
acpi_status
894
acpi_ns_get_node_by_path (
895
        char                            *pathname,
896
        struct acpi_namespace_node      *start_node,
897
        u32                             flags,
898
        struct acpi_namespace_node      **return_node)
899
{
900
        union acpi_generic_state        scope_info;
901
        acpi_status                     status;
902
        char                            *internal_path = NULL;
903
 
904
 
905
        ACPI_FUNCTION_TRACE_PTR ("ns_get_node_by_path", pathname);
906
 
907
 
908
        if (pathname) {
909
                /* Convert path to internal representation */
910
 
911
                status = acpi_ns_internalize_name (pathname, &internal_path);
912
                if (ACPI_FAILURE (status)) {
913
                        return_ACPI_STATUS (status);
914
                }
915
        }
916
 
917
        /* Must lock namespace during lookup */
918
 
919
        status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
920
        if (ACPI_FAILURE (status)) {
921
                goto cleanup;
922
        }
923
 
924
        /* Setup lookup scope (search starting point) */
925
 
926
        scope_info.scope.node = start_node;
927
 
928
        /* Lookup the name in the namespace */
929
 
930
        status = acpi_ns_lookup (&scope_info, internal_path,
931
                         ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
932
                         (flags | ACPI_NS_DONT_OPEN_SCOPE),
933
                         NULL, return_node);
934
        if (ACPI_FAILURE (status)) {
935
                ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "%s, %s\n",
936
                                internal_path, acpi_format_exception (status)));
937
        }
938
 
939
        (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
940
 
941
cleanup:
942
        /* Cleanup */
943
        if (internal_path) {
944
                ACPI_MEM_FREE (internal_path);
945
        }
946
        return_ACPI_STATUS (status);
947
}
948
 
949
 
950
/*******************************************************************************
951
 *
952
 * FUNCTION:    acpi_ns_find_parent_name
953
 *
954
 * PARAMETERS:  *child_node            - Named Obj whose name is to be found
955
 *
956
 * RETURN:      The ACPI name
957
 *
958
 * DESCRIPTION: Search for the given obj in its parent scope and return the
959
 *              name segment, or "????" if the parent name can't be found
960
 *              (which "should not happen").
961
 *
962
 ******************************************************************************/
963
 
964
acpi_name
965
acpi_ns_find_parent_name (
966
        struct acpi_namespace_node      *child_node)
967
{
968
        struct acpi_namespace_node      *parent_node;
969
 
970
 
971
        ACPI_FUNCTION_TRACE ("ns_find_parent_name");
972
 
973
 
974
        if (child_node) {
975
                /* Valid entry.  Get the parent Node */
976
 
977
                parent_node = acpi_ns_get_parent_node (child_node);
978
                if (parent_node) {
979
                        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Parent of %p [%4.4s] is %p [%4.4s]\n",
980
                                child_node, acpi_ut_get_node_name (child_node),
981
                                parent_node, acpi_ut_get_node_name (parent_node)));
982
 
983
                        if (parent_node->name.integer) {
984
                                return_VALUE ((acpi_name) parent_node->name.integer);
985
                        }
986
                }
987
 
988
                ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "unable to find parent of %p (%4.4s)\n",
989
                        child_node, acpi_ut_get_node_name (child_node)));
990
        }
991
 
992
        return_VALUE (ACPI_UNKNOWN_NAME);
993
}
994
 
995
 
996
/*******************************************************************************
997
 *
998
 * FUNCTION:    acpi_ns_get_parent_node
999
 *
1000
 * PARAMETERS:  Node       - Current table entry
1001
 *
1002
 * RETURN:      Parent entry of the given entry
1003
 *
1004
 * DESCRIPTION: Obtain the parent entry for a given entry in the namespace.
1005
 *
1006
 ******************************************************************************/
1007
 
1008
 
1009
struct acpi_namespace_node *
1010
acpi_ns_get_parent_node (
1011
        struct acpi_namespace_node      *node)
1012
{
1013
        ACPI_FUNCTION_ENTRY ();
1014
 
1015
 
1016
        if (!node) {
1017
                return (NULL);
1018
        }
1019
 
1020
        /*
1021
         * Walk to the end of this peer list.
1022
         * The last entry is marked with a flag and the peer
1023
         * pointer is really a pointer back to the parent.
1024
         * This saves putting a parent back pointer in each and
1025
         * every named object!
1026
         */
1027
        while (!(node->flags & ANOBJ_END_OF_PEER_LIST)) {
1028
                node = node->peer;
1029
        }
1030
 
1031
 
1032
        return (node->peer);
1033
}
1034
 
1035
 
1036
/*******************************************************************************
1037
 *
1038
 * FUNCTION:    acpi_ns_get_next_valid_node
1039
 *
1040
 * PARAMETERS:  Node       - Current table entry
1041
 *
1042
 * RETURN:      Next valid Node in the linked node list.  NULL if no more valid
1043
 *              nodess
1044
 *
1045
 * DESCRIPTION: Find the next valid node within a name table.
1046
 *              Useful for implementing NULL-end-of-list loops.
1047
 *
1048
 ******************************************************************************/
1049
 
1050
 
1051
struct acpi_namespace_node *
1052
acpi_ns_get_next_valid_node (
1053
        struct acpi_namespace_node      *node)
1054
{
1055
 
1056
        /* If we are at the end of this peer list, return NULL */
1057
 
1058
        if (node->flags & ANOBJ_END_OF_PEER_LIST) {
1059
                return NULL;
1060
        }
1061
 
1062
        /* Otherwise just return the next peer */
1063
 
1064
        return (node->peer);
1065
}
1066
 
1067
 

powered by: WebSVN 2.1.0

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