1/******************************************************************************
2 *
3 * Name: acutils.h -- prototypes for the common (subsystem-wide) procedures
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2012, Intel Corp.
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
47extern const u8 acpi_gbl_resource_aml_sizes[];
48extern const u8 acpi_gbl_resource_aml_serial_bus_sizes[];
49
50/* Strings used by the disassembler and debugger resource dump routines */
51
52#if defined(ACPI_DISASSEMBLER) || defined (ACPI_DEBUGGER)
53
54extern const char *acpi_gbl_bm_decode[];
55extern const char *acpi_gbl_config_decode[];
56extern const char *acpi_gbl_consume_decode[];
57extern const char *acpi_gbl_dec_decode[];
58extern const char *acpi_gbl_he_decode[];
59extern const char *acpi_gbl_io_decode[];
60extern const char *acpi_gbl_ll_decode[];
61extern const char *acpi_gbl_max_decode[];
62extern const char *acpi_gbl_mem_decode[];
63extern const char *acpi_gbl_min_decode[];
64extern const char *acpi_gbl_mtp_decode[];
65extern const char *acpi_gbl_rng_decode[];
66extern const char *acpi_gbl_rw_decode[];
67extern const char *acpi_gbl_shr_decode[];
68extern const char *acpi_gbl_siz_decode[];
69extern const char *acpi_gbl_trs_decode[];
70extern const char *acpi_gbl_ttp_decode[];
71extern const char *acpi_gbl_typ_decode[];
72#endif
73
74/* Types for Resource descriptor entries */
75
76#define ACPI_INVALID_RESOURCE           0
77#define ACPI_FIXED_LENGTH               1
78#define ACPI_VARIABLE_LENGTH            2
79#define ACPI_SMALL_VARIABLE_LENGTH      3
80
81typedef
82acpi_status(*acpi_walk_aml_callback) (u8 * aml,
83				      u32 length,
84				      u32 offset,
85				      u8 resource_index, void **context);
86
87typedef
88acpi_status(*acpi_pkg_callback) (u8 object_type,
89				 union acpi_operand_object * source_object,
90				 union acpi_generic_state * state,
91				 void *context);
92
93struct acpi_pkg_info {
94	u8 *free_space;
95	acpi_size length;
96	u32 object_space;
97	u32 num_packages;
98};
99
100#define REF_INCREMENT       (u16) 0
101#define REF_DECREMENT       (u16) 1
102#define REF_FORCE_DELETE    (u16) 2
103
104/* acpi_ut_dump_buffer */
105
106#define DB_BYTE_DISPLAY     1
107#define DB_WORD_DISPLAY     2
108#define DB_DWORD_DISPLAY    4
109#define DB_QWORD_DISPLAY    8
110
111/*
112 * utglobal - Global data structures and procedures
113 */
114acpi_status acpi_ut_init_globals(void);
115
116#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
117
118char *acpi_ut_get_mutex_name(u32 mutex_id);
119
120const char *acpi_ut_get_notify_name(u32 notify_value);
121
122#endif
123
124char *acpi_ut_get_type_name(acpi_object_type type);
125
126char *acpi_ut_get_node_name(void *object);
127
128char *acpi_ut_get_descriptor_name(void *object);
129
130const char *acpi_ut_get_reference_name(union acpi_operand_object *object);
131
132char *acpi_ut_get_object_type_name(union acpi_operand_object *obj_desc);
133
134char *acpi_ut_get_region_name(u8 space_id);
135
136char *acpi_ut_get_event_name(u32 event_id);
137
138char acpi_ut_hex_to_ascii_char(u64 integer, u32 position);
139
140u8 acpi_ut_valid_object_type(acpi_object_type type);
141
142/*
143 * utinit - miscellaneous initialization and shutdown
144 */
145acpi_status acpi_ut_hardware_initialize(void);
146
147void acpi_ut_subsystem_shutdown(void);
148
149/*
150 * utclib - Local implementations of C library functions
151 */
152#ifndef ACPI_USE_SYSTEM_CLIBRARY
153
154acpi_size acpi_ut_strlen(const char *string);
155
156char *acpi_ut_strcpy(char *dst_string, const char *src_string);
157
158char *acpi_ut_strncpy(char *dst_string,
159		      const char *src_string, acpi_size count);
160
161int acpi_ut_memcmp(const char *buffer1, const char *buffer2, acpi_size count);
162
163int acpi_ut_strncmp(const char *string1, const char *string2, acpi_size count);
164
165int acpi_ut_strcmp(const char *string1, const char *string2);
166
167char *acpi_ut_strcat(char *dst_string, const char *src_string);
168
169char *acpi_ut_strncat(char *dst_string,
170		      const char *src_string, acpi_size count);
171
172u32 acpi_ut_strtoul(const char *string, char **terminator, u32 base);
173
174char *acpi_ut_strstr(char *string1, char *string2);
175
176void *acpi_ut_memcpy(void *dest, const void *src, acpi_size count);
177
178void *acpi_ut_memset(void *dest, u8 value, acpi_size count);
179
180int acpi_ut_to_upper(int c);
181
182int acpi_ut_to_lower(int c);
183
184extern const u8 _acpi_ctype[];
185
186#define _ACPI_XA     0x00	/* extra alphabetic - not supported */
187#define _ACPI_XS     0x40	/* extra space */
188#define _ACPI_BB     0x00	/* BEL, BS, etc. - not supported */
189#define _ACPI_CN     0x20	/* CR, FF, HT, NL, VT */
190#define _ACPI_DI     0x04	/* '0'-'9' */
191#define _ACPI_LO     0x02	/* 'a'-'z' */
192#define _ACPI_PU     0x10	/* punctuation */
193#define _ACPI_SP     0x08	/* space */
194#define _ACPI_UP     0x01	/* 'A'-'Z' */
195#define _ACPI_XD     0x80	/* '0'-'9', 'A'-'F', 'a'-'f' */
196
197#define ACPI_IS_DIGIT(c)  (_acpi_ctype[(unsigned char)(c)] & (_ACPI_DI))
198#define ACPI_IS_SPACE(c)  (_acpi_ctype[(unsigned char)(c)] & (_ACPI_SP))
199#define ACPI_IS_XDIGIT(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_XD))
200#define ACPI_IS_UPPER(c)  (_acpi_ctype[(unsigned char)(c)] & (_ACPI_UP))
201#define ACPI_IS_LOWER(c)  (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO))
202#define ACPI_IS_PRINT(c)  (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP | _ACPI_DI | _ACPI_SP | _ACPI_PU))
203#define ACPI_IS_ALPHA(c)  (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP))
204
205#endif				/* ACPI_USE_SYSTEM_CLIBRARY */
206
207/*
208 * utcopy - Object construction and conversion interfaces
209 */
210acpi_status
211acpi_ut_build_simple_object(union acpi_operand_object *obj,
212			    union acpi_object *user_obj,
213			    u8 * data_space, u32 * buffer_space_used);
214
215acpi_status
216acpi_ut_build_package_object(union acpi_operand_object *obj,
217			     u8 * buffer, u32 * space_used);
218
219acpi_status
220acpi_ut_copy_iobject_to_eobject(union acpi_operand_object *obj,
221				struct acpi_buffer *ret_buffer);
222
223acpi_status
224acpi_ut_copy_eobject_to_iobject(union acpi_object *obj,
225				union acpi_operand_object **internal_obj);
226
227acpi_status
228acpi_ut_copy_isimple_to_isimple(union acpi_operand_object *source_obj,
229				union acpi_operand_object *dest_obj);
230
231acpi_status
232acpi_ut_copy_iobject_to_iobject(union acpi_operand_object *source_desc,
233				union acpi_operand_object **dest_desc,
234				struct acpi_walk_state *walk_state);
235
236/*
237 * utcreate - Object creation
238 */
239acpi_status
240acpi_ut_update_object_reference(union acpi_operand_object *object, u16 action);
241
242/*
243 * utdebug - Debug interfaces
244 */
245void acpi_ut_init_stack_ptr_trace(void);
246
247void acpi_ut_track_stack_ptr(void);
248
249void
250acpi_ut_trace(u32 line_number,
251	      const char *function_name,
252	      const char *module_name, u32 component_id);
253
254void
255acpi_ut_trace_ptr(u32 line_number,
256		  const char *function_name,
257		  const char *module_name, u32 component_id, void *pointer);
258
259void
260acpi_ut_trace_u32(u32 line_number,
261		  const char *function_name,
262		  const char *module_name, u32 component_id, u32 integer);
263
264void
265acpi_ut_trace_str(u32 line_number,
266		  const char *function_name,
267		  const char *module_name, u32 component_id, char *string);
268
269void
270acpi_ut_exit(u32 line_number,
271	     const char *function_name,
272	     const char *module_name, u32 component_id);
273
274void
275acpi_ut_status_exit(u32 line_number,
276		    const char *function_name,
277		    const char *module_name,
278		    u32 component_id, acpi_status status);
279
280void
281acpi_ut_value_exit(u32 line_number,
282		   const char *function_name,
283		   const char *module_name, u32 component_id, u64 value);
284
285void
286acpi_ut_ptr_exit(u32 line_number,
287		 const char *function_name,
288		 const char *module_name, u32 component_id, u8 *ptr);
289
290void acpi_ut_dump_buffer(u8 * buffer, u32 count, u32 display, u32 component_id);
291
292void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display);
293
294void acpi_ut_report_error(char *module_name, u32 line_number);
295
296void acpi_ut_report_info(char *module_name, u32 line_number);
297
298void acpi_ut_report_warning(char *module_name, u32 line_number);
299
300/*
301 * utdelete - Object deletion and reference counts
302 */
303void acpi_ut_add_reference(union acpi_operand_object *object);
304
305void acpi_ut_remove_reference(union acpi_operand_object *object);
306
307void acpi_ut_delete_internal_package_object(union acpi_operand_object *object);
308
309void acpi_ut_delete_internal_simple_object(union acpi_operand_object *object);
310
311void acpi_ut_delete_internal_object_list(union acpi_operand_object **obj_list);
312
313/*
314 * uteval - object evaluation
315 */
316acpi_status
317acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node,
318			char *path,
319			u32 expected_return_btypes,
320			union acpi_operand_object **return_desc);
321
322acpi_status
323acpi_ut_evaluate_numeric_object(char *object_name,
324				struct acpi_namespace_node *device_node,
325				u64 *value);
326
327acpi_status
328acpi_ut_execute_STA(struct acpi_namespace_node *device_node, u32 *status_flags);
329
330acpi_status
331acpi_ut_execute_power_methods(struct acpi_namespace_node *device_node,
332			      const char **method_names,
333			      u8 method_count, u8 *out_values);
334
335/*
336 * utids - device ID support
337 */
338acpi_status
339acpi_ut_execute_HID(struct acpi_namespace_node *device_node,
340		    struct acpica_device_id **return_id);
341
342acpi_status
343acpi_ut_execute_UID(struct acpi_namespace_node *device_node,
344		    struct acpica_device_id **return_id);
345
346acpi_status
347acpi_ut_execute_CID(struct acpi_namespace_node *device_node,
348		    struct acpica_device_id_list **return_cid_list);
349
350/*
351 * utlock - reader/writer locks
352 */
353acpi_status acpi_ut_create_rw_lock(struct acpi_rw_lock *lock);
354
355void acpi_ut_delete_rw_lock(struct acpi_rw_lock *lock);
356
357acpi_status acpi_ut_acquire_read_lock(struct acpi_rw_lock *lock);
358
359acpi_status acpi_ut_release_read_lock(struct acpi_rw_lock *lock);
360
361acpi_status acpi_ut_acquire_write_lock(struct acpi_rw_lock *lock);
362
363void acpi_ut_release_write_lock(struct acpi_rw_lock *lock);
364
365/*
366 * utobject - internal object create/delete/cache routines
367 */
368union acpi_operand_object *acpi_ut_create_internal_object_dbg(const char
369							      *module_name,
370							      u32 line_number,
371							      u32 component_id,
372							      acpi_object_type
373							      type);
374
375void *acpi_ut_allocate_object_desc_dbg(const char *module_name,
376				       u32 line_number, u32 component_id);
377
378#define acpi_ut_create_internal_object(t) acpi_ut_create_internal_object_dbg (_acpi_module_name,__LINE__,_COMPONENT,t)
379#define acpi_ut_allocate_object_desc()  acpi_ut_allocate_object_desc_dbg (_acpi_module_name,__LINE__,_COMPONENT)
380
381void acpi_ut_delete_object_desc(union acpi_operand_object *object);
382
383u8 acpi_ut_valid_internal_object(void *object);
384
385union acpi_operand_object *acpi_ut_create_package_object(u32 count);
386
387union acpi_operand_object *acpi_ut_create_integer_object(u64 value);
388
389union acpi_operand_object *acpi_ut_create_buffer_object(acpi_size buffer_size);
390
391union acpi_operand_object *acpi_ut_create_string_object(acpi_size string_size);
392
393acpi_status
394acpi_ut_get_object_size(union acpi_operand_object *obj, acpi_size * obj_length);
395
396/*
397 * utosi - Support for the _OSI predefined control method
398 */
399acpi_status acpi_ut_initialize_interfaces(void);
400
401void acpi_ut_interface_terminate(void);
402
403acpi_status acpi_ut_install_interface(acpi_string interface_name);
404
405acpi_status acpi_ut_remove_interface(acpi_string interface_name);
406
407struct acpi_interface_info *acpi_ut_get_interface(acpi_string interface_name);
408
409acpi_status acpi_ut_osi_implementation(struct acpi_walk_state *walk_state);
410
411/*
412 * utstate - Generic state creation/cache routines
413 */
414void
415acpi_ut_push_generic_state(union acpi_generic_state **list_head,
416			   union acpi_generic_state *state);
417
418union acpi_generic_state *acpi_ut_pop_generic_state(union acpi_generic_state
419						    **list_head);
420
421union acpi_generic_state *acpi_ut_create_generic_state(void);
422
423struct acpi_thread_state *acpi_ut_create_thread_state(void);
424
425union acpi_generic_state *acpi_ut_create_update_state(union acpi_operand_object
426						      *object, u16 action);
427
428union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object,
429						   void *external_object,
430						   u16 index);
431
432acpi_status
433acpi_ut_create_update_state_and_push(union acpi_operand_object *object,
434				     u16 action,
435				     union acpi_generic_state **state_list);
436
437#ifdef	ACPI_FUTURE_USAGE
438acpi_status
439acpi_ut_create_pkg_state_and_push(void *internal_object,
440				  void *external_object,
441				  u16 index,
442				  union acpi_generic_state **state_list);
443#endif				/* ACPI_FUTURE_USAGE */
444
445union acpi_generic_state *acpi_ut_create_control_state(void);
446
447void acpi_ut_delete_generic_state(union acpi_generic_state *state);
448
449/*
450 * utmath
451 */
452acpi_status
453acpi_ut_divide(u64 in_dividend,
454	       u64 in_divisor, u64 *out_quotient, u64 *out_remainder);
455
456acpi_status
457acpi_ut_short_divide(u64 in_dividend,
458		     u32 divisor, u64 *out_quotient, u32 *out_remainder);
459
460/*
461 * utmisc
462 */
463const char *acpi_ut_validate_exception(acpi_status status);
464
465u8 acpi_ut_is_pci_root_bridge(char *id);
466
467u8 acpi_ut_is_aml_table(struct acpi_table_header *table);
468
469acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id);
470
471void acpi_ut_release_owner_id(acpi_owner_id * owner_id);
472
473acpi_status
474acpi_ut_walk_package_tree(union acpi_operand_object *source_object,
475			  void *target_object,
476			  acpi_pkg_callback walk_callback, void *context);
477
478void acpi_ut_strupr(char *src_string);
479
480void acpi_ut_print_string(char *string, u8 max_length);
481
482u8 acpi_ut_valid_acpi_name(u32 name);
483
484acpi_name acpi_ut_repair_name(char *name);
485
486u8 acpi_ut_valid_acpi_char(char character, u32 position);
487
488acpi_status acpi_ut_strtoul64(char *string, u32 base, u64 * ret_integer);
489
490/* Values for Base above (16=Hex, 10=Decimal) */
491
492#define ACPI_ANY_BASE        0
493
494u32 acpi_ut_dword_byte_swap(u32 value);
495
496void acpi_ut_set_integer_width(u8 revision);
497
498#ifdef ACPI_DEBUG_OUTPUT
499void
500acpi_ut_display_init_pathname(u8 type,
501			      struct acpi_namespace_node *obj_handle,
502			      char *path);
503#endif
504
505/*
506 * utresrc
507 */
508acpi_status
509acpi_ut_walk_aml_resources(u8 * aml,
510			   acpi_size aml_length,
511			   acpi_walk_aml_callback user_function,
512			   void **context);
513
514acpi_status acpi_ut_validate_resource(void *aml, u8 * return_index);
515
516u32 acpi_ut_get_descriptor_length(void *aml);
517
518u16 acpi_ut_get_resource_length(void *aml);
519
520u8 acpi_ut_get_resource_header_length(void *aml);
521
522u8 acpi_ut_get_resource_type(void *aml);
523
524acpi_status
525acpi_ut_get_resource_end_tag(union acpi_operand_object *obj_desc,
526			     u8 ** end_tag);
527
528/*
529 * utmutex - mutex support
530 */
531acpi_status acpi_ut_mutex_initialize(void);
532
533void acpi_ut_mutex_terminate(void);
534
535acpi_status acpi_ut_acquire_mutex(acpi_mutex_handle mutex_id);
536
537acpi_status acpi_ut_release_mutex(acpi_mutex_handle mutex_id);
538
539/*
540 * utalloc - memory allocation and object caching
541 */
542acpi_status acpi_ut_create_caches(void);
543
544acpi_status acpi_ut_delete_caches(void);
545
546acpi_status acpi_ut_validate_buffer(struct acpi_buffer *buffer);
547
548acpi_status
549acpi_ut_initialize_buffer(struct acpi_buffer *buffer,
550			  acpi_size required_length);
551
552void *acpi_ut_allocate(acpi_size size,
553		       u32 component, const char *module, u32 line);
554
555void *acpi_ut_allocate_zeroed(acpi_size size,
556			      u32 component, const char *module, u32 line);
557
558#ifdef ACPI_DBG_TRACK_ALLOCATIONS
559void *acpi_ut_allocate_and_track(acpi_size size,
560				 u32 component, const char *module, u32 line);
561
562void *acpi_ut_allocate_zeroed_and_track(acpi_size size,
563					u32 component,
564					const char *module, u32 line);
565
566void
567acpi_ut_free_and_track(void *address,
568		       u32 component, const char *module, u32 line);
569
570#ifdef	ACPI_FUTURE_USAGE
571void acpi_ut_dump_allocation_info(void);
572#endif				/* ACPI_FUTURE_USAGE */
573
574void acpi_ut_dump_allocations(u32 component, const char *module);
575
576acpi_status
577acpi_ut_create_list(char *list_name,
578		    u16 object_size, struct acpi_memory_list **return_cache);
579
580#endif				/* ACPI_DBG_TRACK_ALLOCATIONS */
581
582/*
583 * utaddress - address range check
584 */
585acpi_status
586acpi_ut_add_address_range(acpi_adr_space_type space_id,
587			  acpi_physical_address address,
588			  u32 length, struct acpi_namespace_node *region_node);
589
590void
591acpi_ut_remove_address_range(acpi_adr_space_type space_id,
592			     struct acpi_namespace_node *region_node);
593
594u32
595acpi_ut_check_address_range(acpi_adr_space_type space_id,
596			    acpi_physical_address address, u32 length, u8 warn);
597
598void acpi_ut_delete_address_lists(void);
599
600/*
601 * utxferror - various error/warning output functions
602 */
603void ACPI_INTERNAL_VAR_XFACE
604acpi_ut_predefined_warning(const char *module_name,
605			   u32 line_number,
606			   char *pathname,
607			   u8 node_flags, const char *format, ...);
608
609void ACPI_INTERNAL_VAR_XFACE
610acpi_ut_predefined_info(const char *module_name,
611			u32 line_number,
612			char *pathname, u8 node_flags, const char *format, ...);
613
614void
615acpi_ut_namespace_error(const char *module_name,
616			u32 line_number,
617			const char *internal_name, acpi_status lookup_status);
618
619void
620acpi_ut_method_error(const char *module_name,
621		     u32 line_number,
622		     const char *message,
623		     struct acpi_namespace_node *node,
624		     const char *path, acpi_status lookup_status);
625
626#endif				/* _ACUTILS_H */
627