ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / acpi / acutils.h
1 /******************************************************************************
2  *
3  * Name: acutils.h -- prototypes for the common (subsystem-wide) 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 #ifndef _ACUTILS_H
45 #define _ACUTILS_H
46
47
48 typedef
49 acpi_status (*acpi_pkg_callback) (
50         u8                              object_type,
51         union acpi_operand_object       *source_object,
52         union acpi_generic_state        *state,
53         void                            *context);
54
55 acpi_status
56 acpi_ut_walk_package_tree (
57         union acpi_operand_object       *source_object,
58         void                            *target_object,
59         acpi_pkg_callback               walk_callback,
60         void                            *context);
61
62 struct acpi_pkg_info
63 {
64         u8                              *free_space;
65         acpi_size                       length;
66         u32                             object_space;
67         u32                             num_packages;
68 };
69
70 #define REF_INCREMENT       (u16) 0
71 #define REF_DECREMENT       (u16) 1
72 #define REF_FORCE_DELETE    (u16) 2
73
74 /* acpi_ut_dump_buffer */
75
76 #define DB_BYTE_DISPLAY     1
77 #define DB_WORD_DISPLAY     2
78 #define DB_DWORD_DISPLAY    4
79 #define DB_QWORD_DISPLAY    8
80
81
82 /* Global initialization interfaces */
83
84 void
85 acpi_ut_init_globals (
86         void);
87
88 void
89 acpi_ut_terminate (
90         void);
91
92
93 /*
94  * ut_init - miscellaneous initialization and shutdown
95  */
96
97 acpi_status
98 acpi_ut_hardware_initialize (
99         void);
100
101 void
102 acpi_ut_subsystem_shutdown (
103         void);
104
105 acpi_status
106 acpi_ut_validate_fadt (
107         void);
108
109 /*
110  * ut_global - Global data structures and procedures
111  */
112
113 #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
114
115 char *
116 acpi_ut_get_mutex_name (
117         u32                             mutex_id);
118
119 #endif
120
121 char *
122 acpi_ut_get_type_name (
123         acpi_object_type                type);
124
125 char *
126 acpi_ut_get_node_name (
127         void                            *object);
128
129 char *
130 acpi_ut_get_descriptor_name (
131         void                            *object);
132
133 char *
134 acpi_ut_get_object_type_name (
135         union acpi_operand_object       *obj_desc);
136
137 char *
138 acpi_ut_get_region_name (
139         u8                              space_id);
140
141 char *
142 acpi_ut_get_event_name (
143         u32                             event_id);
144
145 char
146 acpi_ut_hex_to_ascii_char (
147         acpi_integer                    integer,
148         u32                             position);
149
150 u8
151 acpi_ut_valid_object_type (
152         acpi_object_type                type);
153
154 acpi_owner_id
155 acpi_ut_allocate_owner_id (
156         u32                             id_type);
157
158
159 /*
160  * ut_clib - Local implementations of C library functions
161  */
162
163 #ifndef ACPI_USE_SYSTEM_CLIBRARY
164
165 acpi_size
166 acpi_ut_strlen (
167         const char                      *string);
168
169 char *
170 acpi_ut_strcpy (
171         char                            *dst_string,
172         const char                      *src_string);
173
174 char *
175 acpi_ut_strncpy (
176         char                            *dst_string,
177         const char                      *src_string,
178         acpi_size                       count);
179
180 int
181 acpi_ut_strncmp (
182         const char                      *string1,
183         const char                      *string2,
184         acpi_size                       count);
185
186 int
187 acpi_ut_strcmp (
188         const char                      *string1,
189         const char                      *string2);
190
191 char *
192 acpi_ut_strcat (
193         char                            *dst_string,
194         const char                      *src_string);
195
196 char *
197 acpi_ut_strncat (
198         char                            *dst_string,
199         const char                      *src_string,
200         acpi_size                       count);
201
202 u32
203 acpi_ut_strtoul (
204         const char                      *string,
205         char                            **terminator,
206         u32                             base);
207
208 char *
209 acpi_ut_strstr (
210         char                            *string1,
211         char                            *string2);
212
213 void *
214 acpi_ut_memcpy (
215         void                            *dest,
216         const void                      *src,
217         acpi_size                       count);
218
219 void *
220 acpi_ut_memset (
221         void                            *dest,
222         acpi_native_uint                value,
223         acpi_size                       count);
224
225 int
226 acpi_ut_to_upper (
227         int                             c);
228
229 int
230 acpi_ut_to_lower (
231         int                             c);
232
233 extern const u8 _acpi_ctype[];
234
235 #define _ACPI_XA     0x00    /* extra alphabetic - not supported */
236 #define _ACPI_XS     0x40    /* extra space */
237 #define _ACPI_BB     0x00    /* BEL, BS, etc. - not supported */
238 #define _ACPI_CN     0x20    /* CR, FF, HT, NL, VT */
239 #define _ACPI_DI     0x04    /* '0'-'9' */
240 #define _ACPI_LO     0x02    /* 'a'-'z' */
241 #define _ACPI_PU     0x10    /* punctuation */
242 #define _ACPI_SP     0x08    /* space */
243 #define _ACPI_UP     0x01    /* 'A'-'Z' */
244 #define _ACPI_XD     0x80    /* '0'-'9', 'A'-'F', 'a'-'f' */
245
246 #define ACPI_IS_DIGIT(c)  (_acpi_ctype[(unsigned char)(c)] & (_ACPI_DI))
247 #define ACPI_IS_SPACE(c)  (_acpi_ctype[(unsigned char)(c)] & (_ACPI_SP))
248 #define ACPI_IS_XDIGIT(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_XD))
249 #define ACPI_IS_UPPER(c)  (_acpi_ctype[(unsigned char)(c)] & (_ACPI_UP))
250 #define ACPI_IS_LOWER(c)  (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO))
251 #define ACPI_IS_PRINT(c)  (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP | _ACPI_DI | _ACPI_SP | _ACPI_PU))
252 #define ACPI_IS_ALPHA(c)  (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP))
253 #define ACPI_IS_ASCII(c)  ((c) < 0x80)
254
255 #endif /* ACPI_USE_SYSTEM_CLIBRARY */
256
257 /*
258  * ut_copy - Object construction and conversion interfaces
259  */
260
261 acpi_status
262 acpi_ut_build_simple_object(
263         union acpi_operand_object       *obj,
264         union acpi_object               *user_obj,
265         u8                              *data_space,
266         u32                             *buffer_space_used);
267
268 acpi_status
269 acpi_ut_build_package_object (
270         union acpi_operand_object       *obj,
271         u8                              *buffer,
272         u32                             *space_used);
273
274 acpi_status
275 acpi_ut_copy_ielement_to_eelement (
276         u8                              object_type,
277         union acpi_operand_object       *source_object,
278         union acpi_generic_state        *state,
279         void                            *context);
280
281 acpi_status
282 acpi_ut_copy_ielement_to_ielement (
283         u8                              object_type,
284         union acpi_operand_object       *source_object,
285         union acpi_generic_state        *state,
286         void                            *context);
287
288 acpi_status
289 acpi_ut_copy_iobject_to_eobject (
290         union acpi_operand_object       *obj,
291         struct acpi_buffer              *ret_buffer);
292
293 acpi_status
294 acpi_ut_copy_esimple_to_isimple(
295         union acpi_object               *user_obj,
296         union acpi_operand_object       **return_obj);
297
298 acpi_status
299 acpi_ut_copy_eobject_to_iobject (
300         union acpi_object               *obj,
301         union acpi_operand_object       **internal_obj);
302
303 acpi_status
304 acpi_ut_copy_isimple_to_isimple (
305         union acpi_operand_object       *source_obj,
306         union acpi_operand_object       *dest_obj);
307
308 acpi_status
309 acpi_ut_copy_ipackage_to_ipackage (
310         union acpi_operand_object       *source_obj,
311         union acpi_operand_object       *dest_obj,
312         struct acpi_walk_state          *walk_state);
313
314 acpi_status
315 acpi_ut_copy_simple_object (
316         union acpi_operand_object       *source_desc,
317         union acpi_operand_object       *dest_desc);
318
319 acpi_status
320 acpi_ut_copy_iobject_to_iobject (
321         union acpi_operand_object       *source_desc,
322         union acpi_operand_object       **dest_desc,
323         struct acpi_walk_state          *walk_state);
324
325
326 /*
327  * ut_create - Object creation
328  */
329
330 acpi_status
331 acpi_ut_update_object_reference (
332         union acpi_operand_object       *object,
333         u16                             action);
334
335
336 /*
337  * ut_debug - Debug interfaces
338  */
339
340 void
341 acpi_ut_init_stack_ptr_trace (
342         void);
343
344 void
345 acpi_ut_track_stack_ptr (
346         void);
347
348 void
349 acpi_ut_trace (
350         u32                             line_number,
351         struct acpi_debug_print_info    *dbg_info);
352
353 void
354 acpi_ut_trace_ptr (
355         u32                             line_number,
356         struct acpi_debug_print_info    *dbg_info,
357         void                            *pointer);
358
359 void
360 acpi_ut_trace_u32 (
361         u32                             line_number,
362         struct acpi_debug_print_info    *dbg_info,
363         u32                             integer);
364
365 void
366 acpi_ut_trace_str (
367         u32                             line_number,
368         struct acpi_debug_print_info    *dbg_info,
369         char                            *string);
370
371 void
372 acpi_ut_exit (
373         u32                             line_number,
374         struct acpi_debug_print_info    *dbg_info);
375
376 void
377 acpi_ut_status_exit (
378         u32                             line_number,
379         struct acpi_debug_print_info    *dbg_info,
380         acpi_status                     status);
381
382 void
383 acpi_ut_value_exit (
384         u32                             line_number,
385         struct acpi_debug_print_info    *dbg_info,
386         acpi_integer                    value);
387
388 void
389 acpi_ut_ptr_exit (
390         u32                             line_number,
391         struct acpi_debug_print_info    *dbg_info,
392         u8                              *ptr);
393
394 void
395 acpi_ut_report_info (
396         char                            *module_name,
397         u32                             line_number,
398         u32                             component_id);
399
400 void
401 acpi_ut_report_error (
402         char                            *module_name,
403         u32                             line_number,
404         u32                             component_id);
405
406 void
407 acpi_ut_report_warning (
408         char                            *module_name,
409         u32                             line_number,
410         u32                             component_id);
411
412 void
413 acpi_ut_dump_buffer (
414         u8                              *buffer,
415         u32                             count,
416         u32                             display,
417         u32                             component_id);
418
419 void ACPI_INTERNAL_VAR_XFACE
420 acpi_ut_debug_print (
421         u32                             requested_debug_level,
422         u32                             line_number,
423         struct acpi_debug_print_info    *dbg_info,
424         char                            *format,
425         ...) ACPI_PRINTF_LIKE_FUNC;
426
427 void ACPI_INTERNAL_VAR_XFACE
428 acpi_ut_debug_print_raw (
429         u32                             requested_debug_level,
430         u32                             line_number,
431         struct acpi_debug_print_info    *dbg_info,
432         char                            *format,
433         ...) ACPI_PRINTF_LIKE_FUNC;
434
435
436 /*
437  * ut_delete - Object deletion
438  */
439
440 void
441 acpi_ut_delete_internal_obj (
442         union acpi_operand_object       *object);
443
444 void
445 acpi_ut_delete_internal_package_object (
446         union acpi_operand_object       *object);
447
448 void
449 acpi_ut_delete_internal_simple_object (
450         union acpi_operand_object       *object);
451
452 void
453 acpi_ut_delete_internal_object_list (
454         union acpi_operand_object       **obj_list);
455
456
457 /*
458  * ut_eval - object evaluation
459  */
460
461 /* Method name strings */
462
463 #define METHOD_NAME__HID        "_HID"
464 #define METHOD_NAME__CID        "_CID"
465 #define METHOD_NAME__UID        "_UID"
466 #define METHOD_NAME__ADR        "_ADR"
467 #define METHOD_NAME__STA        "_STA"
468 #define METHOD_NAME__REG        "_REG"
469 #define METHOD_NAME__SEG        "_SEG"
470 #define METHOD_NAME__BBN        "_BBN"
471 #define METHOD_NAME__PRT        "_PRT"
472 #define METHOD_NAME__CRS        "_CRS"
473 #define METHOD_NAME__PRS        "_PRS"
474 #define METHOD_NAME__PRW        "_PRW"
475
476
477 acpi_status
478 acpi_ut_osi_implementation (
479         struct acpi_walk_state          *walk_state);
480
481 acpi_status
482 acpi_ut_evaluate_object (
483         struct acpi_namespace_node      *prefix_node,
484         char                            *path,
485         u32                             expected_return_btypes,
486         union acpi_operand_object       **return_desc);
487
488 acpi_status
489 acpi_ut_evaluate_numeric_object (
490         char                            *object_name,
491         struct acpi_namespace_node      *device_node,
492         acpi_integer                    *address);
493
494 acpi_status
495 acpi_ut_execute_HID (
496         struct acpi_namespace_node      *device_node,
497         struct acpi_device_id           *hid);
498
499 acpi_status
500 acpi_ut_execute_CID (
501         struct acpi_namespace_node      *device_node,
502         struct acpi_compatible_id_list **return_cid_list);
503
504 acpi_status
505 acpi_ut_execute_STA (
506         struct acpi_namespace_node      *device_node,
507         u32                             *status_flags);
508
509 acpi_status
510 acpi_ut_execute_UID (
511         struct acpi_namespace_node      *device_node,
512         struct acpi_device_id           *uid);
513
514 acpi_status
515 acpi_ut_execute_sxds (
516         struct acpi_namespace_node      *device_node,
517         u8                              *highest);
518
519 /*
520  * ut_mutex - mutual exclusion interfaces
521  */
522
523 acpi_status
524 acpi_ut_mutex_initialize (
525         void);
526
527 void
528 acpi_ut_mutex_terminate (
529         void);
530
531 acpi_status
532 acpi_ut_create_mutex (
533         acpi_mutex_handle               mutex_id);
534
535 acpi_status
536 acpi_ut_delete_mutex (
537         acpi_mutex_handle               mutex_id);
538
539 acpi_status
540 acpi_ut_acquire_mutex (
541         acpi_mutex_handle               mutex_id);
542
543 acpi_status
544 acpi_ut_release_mutex (
545         acpi_mutex_handle               mutex_id);
546
547
548 /*
549  * ut_object - internal object create/delete/cache routines
550  */
551
552 union acpi_operand_object    *
553 acpi_ut_create_internal_object_dbg (
554         char                            *module_name,
555         u32                             line_number,
556         u32                             component_id,
557         acpi_object_type                type);
558
559 void *
560 acpi_ut_allocate_object_desc_dbg (
561         char                            *module_name,
562         u32                             line_number,
563         u32                             component_id);
564
565 #define acpi_ut_create_internal_object(t) acpi_ut_create_internal_object_dbg (_THIS_MODULE,__LINE__,_COMPONENT,t)
566 #define acpi_ut_allocate_object_desc()  acpi_ut_allocate_object_desc_dbg (_THIS_MODULE,__LINE__,_COMPONENT)
567
568 void
569 acpi_ut_delete_object_desc (
570         union acpi_operand_object       *object);
571
572 u8
573 acpi_ut_valid_internal_object (
574         void                            *object);
575
576 union acpi_operand_object *
577 acpi_ut_create_buffer_object (
578         acpi_size                       buffer_size);
579
580
581 /*
582  * ut_ref_cnt - Object reference count management
583  */
584
585 void
586 acpi_ut_add_reference (
587         union acpi_operand_object       *object);
588
589 void
590 acpi_ut_remove_reference (
591         union acpi_operand_object       *object);
592
593 /*
594  * ut_size - Object size routines
595  */
596
597 acpi_status
598 acpi_ut_get_simple_object_size (
599         union acpi_operand_object       *obj,
600         acpi_size                       *obj_length);
601
602 acpi_status
603 acpi_ut_get_package_object_size (
604         union acpi_operand_object       *obj,
605         acpi_size                       *obj_length);
606
607 acpi_status
608 acpi_ut_get_object_size(
609         union acpi_operand_object       *obj,
610         acpi_size                       *obj_length);
611
612 acpi_status
613 acpi_ut_get_element_length (
614         u8                              object_type,
615         union acpi_operand_object       *source_object,
616         union acpi_generic_state        *state,
617         void                            *context);
618
619
620 /*
621  * ut_state - Generic state creation/cache routines
622  */
623
624 void
625 acpi_ut_push_generic_state (
626         union acpi_generic_state        **list_head,
627         union acpi_generic_state        *state);
628
629 union acpi_generic_state *
630 acpi_ut_pop_generic_state (
631         union acpi_generic_state        **list_head);
632
633
634 union acpi_generic_state *
635 acpi_ut_create_generic_state (
636         void);
637
638 struct acpi_thread_state *
639 acpi_ut_create_thread_state (
640         void);
641
642 union acpi_generic_state *
643 acpi_ut_create_update_state (
644         union acpi_operand_object       *object,
645         u16                             action);
646
647 union acpi_generic_state *
648 acpi_ut_create_pkg_state (
649         void                            *internal_object,
650         void                            *external_object,
651         u16                             index);
652
653 acpi_status
654 acpi_ut_create_update_state_and_push (
655         union acpi_operand_object       *object,
656         u16                             action,
657         union acpi_generic_state        **state_list);
658
659 acpi_status
660 acpi_ut_create_pkg_state_and_push (
661         void                            *internal_object,
662         void                            *external_object,
663         u16                             index,
664         union acpi_generic_state        **state_list);
665
666 union acpi_generic_state *
667 acpi_ut_create_control_state (
668         void);
669
670 void
671 acpi_ut_delete_generic_state (
672         union acpi_generic_state        *state);
673
674 void
675 acpi_ut_delete_generic_state_cache (
676         void);
677
678 void
679 acpi_ut_delete_object_cache (
680         void);
681
682 /*
683  * utmisc
684  */
685
686 void
687 acpi_ut_print_string (
688         char                            *string,
689         u8                              max_length);
690
691 acpi_status
692 acpi_ut_divide (
693         acpi_integer                    *in_dividend,
694         acpi_integer                    *in_divisor,
695         acpi_integer                    *out_quotient,
696         acpi_integer                    *out_remainder);
697
698 acpi_status
699 acpi_ut_short_divide (
700         acpi_integer                    *in_dividend,
701         u32                             divisor,
702         acpi_integer                    *out_quotient,
703         u32                             *out_remainder);
704
705 u8
706 acpi_ut_valid_acpi_name (
707         u32                             name);
708
709 u8
710 acpi_ut_valid_acpi_character (
711         char                            character);
712
713 acpi_status
714 acpi_ut_strtoul64 (
715         char                            *string,
716         u32                             base,
717         acpi_integer                    *ret_integer);
718
719 char *
720 acpi_ut_strupr (
721         char                            *src_string);
722
723 u8 *
724 acpi_ut_get_resource_end_tag (
725         union acpi_operand_object       *obj_desc);
726
727 u8
728 acpi_ut_generate_checksum (
729         u8                              *buffer,
730         u32                             length);
731
732 u32
733 acpi_ut_dword_byte_swap (
734         u32                             value);
735
736 void
737 acpi_ut_set_integer_width (
738         u8                              revision);
739
740 #ifdef ACPI_DEBUG_OUTPUT
741 void
742 acpi_ut_display_init_pathname (
743         u8                              type,
744         struct acpi_namespace_node      *obj_handle,
745         char                            *path);
746
747 #endif
748
749
750 /*
751  * Utalloc - memory allocation and object caching
752  */
753
754 void *
755 acpi_ut_acquire_from_cache (
756         u32                             list_id);
757
758 void
759 acpi_ut_release_to_cache (
760         u32                             list_id,
761         void                            *object);
762
763 void
764 acpi_ut_delete_generic_cache (
765         u32                             list_id);
766
767 acpi_status
768 acpi_ut_validate_buffer (
769         struct acpi_buffer              *buffer);
770
771 acpi_status
772 acpi_ut_initialize_buffer (
773         struct acpi_buffer              *buffer,
774         acpi_size                       required_length);
775
776
777 /* Memory allocation functions */
778
779 void *
780 acpi_ut_allocate (
781         acpi_size                       size,
782         u32                             component,
783         char                            *module,
784         u32                             line);
785
786 void *
787 acpi_ut_callocate (
788         acpi_size                       size,
789         u32                             component,
790         char                            *module,
791         u32                             line);
792
793
794 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
795
796 void *
797 acpi_ut_allocate_and_track (
798         acpi_size                       size,
799         u32                             component,
800         char                            *module,
801         u32                             line);
802
803 void *
804 acpi_ut_callocate_and_track (
805         acpi_size                       size,
806         u32                             component,
807         char                            *module,
808         u32                             line);
809
810 void
811 acpi_ut_free_and_track (
812         void                            *address,
813         u32                             component,
814         char                            *module,
815         u32                             line);
816
817 struct acpi_debug_mem_block *
818 acpi_ut_find_allocation (
819         u32                             list_id,
820         void                            *allocation);
821
822 acpi_status
823 acpi_ut_track_allocation (
824         u32                             list_id,
825         struct acpi_debug_mem_block     *address,
826         acpi_size                       size,
827         u8                              alloc_type,
828         u32                             component,
829         char                            *module,
830         u32                             line);
831
832 acpi_status
833 acpi_ut_remove_allocation (
834         u32                             list_id,
835         struct acpi_debug_mem_block     *address,
836         u32                             component,
837         char                            *module,
838         u32                             line);
839
840 void
841 acpi_ut_dump_allocation_info (
842         void);
843
844 void
845 acpi_ut_dump_allocations (
846         u32                             component,
847         char                            *module);
848 #endif
849
850
851 #endif /* _ACUTILS_H */