acutils.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. /******************************************************************************
  2. *
  3. * Name: acutils.h -- prototypes for the common (subsystem-wide) procedures
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #ifndef _ACUTILS_H
  43. #define _ACUTILS_H
  44. extern const u8 acpi_gbl_resource_aml_sizes[];
  45. /* Types for Resource descriptor entries */
  46. #define ACPI_INVALID_RESOURCE 0
  47. #define ACPI_FIXED_LENGTH 1
  48. #define ACPI_VARIABLE_LENGTH 2
  49. #define ACPI_SMALL_VARIABLE_LENGTH 3
  50. typedef
  51. acpi_status(*acpi_pkg_callback) (u8 object_type,
  52. union acpi_operand_object * source_object,
  53. union acpi_generic_state * state,
  54. void *context);
  55. struct acpi_pkg_info {
  56. u8 *free_space;
  57. acpi_size length;
  58. u32 object_space;
  59. u32 num_packages;
  60. };
  61. #define REF_INCREMENT (u16) 0
  62. #define REF_DECREMENT (u16) 1
  63. #define REF_FORCE_DELETE (u16) 2
  64. /* acpi_ut_dump_buffer */
  65. #define DB_BYTE_DISPLAY 1
  66. #define DB_WORD_DISPLAY 2
  67. #define DB_DWORD_DISPLAY 4
  68. #define DB_QWORD_DISPLAY 8
  69. /*
  70. * utglobal - Global data structures and procedures
  71. */
  72. void acpi_ut_init_globals(void);
  73. #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
  74. char *acpi_ut_get_mutex_name(u32 mutex_id);
  75. #endif
  76. char *acpi_ut_get_type_name(acpi_object_type type);
  77. char *acpi_ut_get_node_name(void *object);
  78. char *acpi_ut_get_descriptor_name(void *object);
  79. char *acpi_ut_get_object_type_name(union acpi_operand_object *obj_desc);
  80. char *acpi_ut_get_region_name(u8 space_id);
  81. char *acpi_ut_get_event_name(u32 event_id);
  82. char acpi_ut_hex_to_ascii_char(acpi_integer integer, u32 position);
  83. u8 acpi_ut_valid_object_type(acpi_object_type type);
  84. /*
  85. * utinit - miscellaneous initialization and shutdown
  86. */
  87. acpi_status acpi_ut_hardware_initialize(void);
  88. void acpi_ut_subsystem_shutdown(void);
  89. acpi_status acpi_ut_validate_fadt(void);
  90. /*
  91. * utclib - Local implementations of C library functions
  92. */
  93. #ifndef ACPI_USE_SYSTEM_CLIBRARY
  94. acpi_size acpi_ut_strlen(const char *string);
  95. char *acpi_ut_strcpy(char *dst_string, const char *src_string);
  96. char *acpi_ut_strncpy(char *dst_string,
  97. const char *src_string, acpi_size count);
  98. int acpi_ut_memcmp(const char *buffer1, const char *buffer2, acpi_size count);
  99. int acpi_ut_strncmp(const char *string1, const char *string2, acpi_size count);
  100. int acpi_ut_strcmp(const char *string1, const char *string2);
  101. char *acpi_ut_strcat(char *dst_string, const char *src_string);
  102. char *acpi_ut_strncat(char *dst_string,
  103. const char *src_string, acpi_size count);
  104. u32 acpi_ut_strtoul(const char *string, char **terminator, u32 base);
  105. char *acpi_ut_strstr(char *string1, char *string2);
  106. void *acpi_ut_memcpy(void *dest, const void *src, acpi_size count);
  107. void *acpi_ut_memset(void *dest, acpi_native_uint value, acpi_size count);
  108. int acpi_ut_to_upper(int c);
  109. int acpi_ut_to_lower(int c);
  110. extern const u8 _acpi_ctype[];
  111. #define _ACPI_XA 0x00 /* extra alphabetic - not supported */
  112. #define _ACPI_XS 0x40 /* extra space */
  113. #define _ACPI_BB 0x00 /* BEL, BS, etc. - not supported */
  114. #define _ACPI_CN 0x20 /* CR, FF, HT, NL, VT */
  115. #define _ACPI_DI 0x04 /* '0'-'9' */
  116. #define _ACPI_LO 0x02 /* 'a'-'z' */
  117. #define _ACPI_PU 0x10 /* punctuation */
  118. #define _ACPI_SP 0x08 /* space */
  119. #define _ACPI_UP 0x01 /* 'A'-'Z' */
  120. #define _ACPI_XD 0x80 /* '0'-'9', 'A'-'F', 'a'-'f' */
  121. #define ACPI_IS_DIGIT(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_DI))
  122. #define ACPI_IS_SPACE(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_SP))
  123. #define ACPI_IS_XDIGIT(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_XD))
  124. #define ACPI_IS_UPPER(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_UP))
  125. #define ACPI_IS_LOWER(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO))
  126. #define ACPI_IS_PRINT(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP | _ACPI_DI | _ACPI_SP | _ACPI_PU))
  127. #define ACPI_IS_ALPHA(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP))
  128. #endif /* ACPI_USE_SYSTEM_CLIBRARY */
  129. /*
  130. * utcopy - Object construction and conversion interfaces
  131. */
  132. acpi_status
  133. acpi_ut_build_simple_object(union acpi_operand_object *obj,
  134. union acpi_object *user_obj,
  135. u8 * data_space, u32 * buffer_space_used);
  136. acpi_status
  137. acpi_ut_build_package_object(union acpi_operand_object *obj,
  138. u8 * buffer, u32 * space_used);
  139. acpi_status
  140. acpi_ut_copy_iobject_to_eobject(union acpi_operand_object *obj,
  141. struct acpi_buffer *ret_buffer);
  142. acpi_status
  143. acpi_ut_copy_eobject_to_iobject(union acpi_object *obj,
  144. union acpi_operand_object **internal_obj);
  145. acpi_status
  146. acpi_ut_copy_isimple_to_isimple(union acpi_operand_object *source_obj,
  147. union acpi_operand_object *dest_obj);
  148. acpi_status
  149. acpi_ut_copy_iobject_to_iobject(union acpi_operand_object *source_desc,
  150. union acpi_operand_object **dest_desc,
  151. struct acpi_walk_state *walk_state);
  152. /*
  153. * utcreate - Object creation
  154. */
  155. acpi_status
  156. acpi_ut_update_object_reference(union acpi_operand_object *object, u16 action);
  157. /*
  158. * utdebug - Debug interfaces
  159. */
  160. void acpi_ut_init_stack_ptr_trace(void);
  161. void acpi_ut_track_stack_ptr(void);
  162. void
  163. acpi_ut_trace(u32 line_number,
  164. const char *function_name, char *module_name, u32 component_id);
  165. void
  166. acpi_ut_trace_ptr(u32 line_number,
  167. const char *function_name,
  168. char *module_name, u32 component_id, void *pointer);
  169. void
  170. acpi_ut_trace_u32(u32 line_number,
  171. const char *function_name,
  172. char *module_name, u32 component_id, u32 integer);
  173. void
  174. acpi_ut_trace_str(u32 line_number,
  175. const char *function_name,
  176. char *module_name, u32 component_id, char *string);
  177. void
  178. acpi_ut_exit(u32 line_number,
  179. const char *function_name, char *module_name, u32 component_id);
  180. void
  181. acpi_ut_status_exit(u32 line_number,
  182. const char *function_name,
  183. char *module_name, u32 component_id, acpi_status status);
  184. void
  185. acpi_ut_value_exit(u32 line_number,
  186. const char *function_name,
  187. char *module_name, u32 component_id, acpi_integer value);
  188. void
  189. acpi_ut_ptr_exit(u32 line_number,
  190. const char *function_name,
  191. char *module_name, u32 component_id, u8 * ptr);
  192. void acpi_ut_report_info(char *module_name, u32 line_number, u32 component_id);
  193. void acpi_ut_report_error(char *module_name, u32 line_number, u32 component_id);
  194. void
  195. acpi_ut_report_warning(char *module_name, u32 line_number, u32 component_id);
  196. void acpi_ut_dump_buffer(u8 * buffer, u32 count, u32 display, u32 component_id);
  197. void ACPI_INTERNAL_VAR_XFACE
  198. acpi_ut_debug_print(u32 requested_debug_level,
  199. u32 line_number,
  200. const char *function_name,
  201. char *module_name,
  202. u32 component_id, char *format, ...) ACPI_PRINTF_LIKE_FUNC;
  203. void ACPI_INTERNAL_VAR_XFACE
  204. acpi_ut_debug_print_raw(u32 requested_debug_level,
  205. u32 line_number,
  206. const char *function_name,
  207. char *module_name,
  208. u32 component_id,
  209. char *format, ...) ACPI_PRINTF_LIKE_FUNC;
  210. /*
  211. * utdelete - Object deletion and reference counts
  212. */
  213. void acpi_ut_add_reference(union acpi_operand_object *object);
  214. void acpi_ut_remove_reference(union acpi_operand_object *object);
  215. void acpi_ut_delete_internal_package_object(union acpi_operand_object *object);
  216. void acpi_ut_delete_internal_simple_object(union acpi_operand_object *object);
  217. void acpi_ut_delete_internal_object_list(union acpi_operand_object **obj_list);
  218. /*
  219. * uteval - object evaluation
  220. */
  221. acpi_status acpi_ut_osi_implementation(struct acpi_walk_state *walk_state);
  222. acpi_status
  223. acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node,
  224. char *path,
  225. u32 expected_return_btypes,
  226. union acpi_operand_object **return_desc);
  227. acpi_status
  228. acpi_ut_evaluate_numeric_object(char *object_name,
  229. struct acpi_namespace_node *device_node,
  230. acpi_integer * address);
  231. acpi_status
  232. acpi_ut_execute_HID(struct acpi_namespace_node *device_node,
  233. struct acpi_device_id *hid);
  234. acpi_status
  235. acpi_ut_execute_CID(struct acpi_namespace_node *device_node,
  236. struct acpi_compatible_id_list **return_cid_list);
  237. acpi_status
  238. acpi_ut_execute_STA(struct acpi_namespace_node *device_node,
  239. u32 * status_flags);
  240. acpi_status
  241. acpi_ut_execute_UID(struct acpi_namespace_node *device_node,
  242. struct acpi_device_id *uid);
  243. acpi_status
  244. acpi_ut_execute_sxds(struct acpi_namespace_node *device_node, u8 * highest);
  245. /*
  246. * utobject - internal object create/delete/cache routines
  247. */
  248. union acpi_operand_object *acpi_ut_create_internal_object_dbg(char *module_name,
  249. u32 line_number,
  250. u32 component_id,
  251. acpi_object_type
  252. type);
  253. void *acpi_ut_allocate_object_desc_dbg(char *module_name,
  254. u32 line_number, u32 component_id);
  255. #define acpi_ut_create_internal_object(t) acpi_ut_create_internal_object_dbg (_acpi_module_name,__LINE__,_COMPONENT,t)
  256. #define acpi_ut_allocate_object_desc() acpi_ut_allocate_object_desc_dbg (_acpi_module_name,__LINE__,_COMPONENT)
  257. void acpi_ut_delete_object_desc(union acpi_operand_object *object);
  258. u8 acpi_ut_valid_internal_object(void *object);
  259. union acpi_operand_object *acpi_ut_create_buffer_object(acpi_size buffer_size);
  260. union acpi_operand_object *acpi_ut_create_string_object(acpi_size string_size);
  261. acpi_status
  262. acpi_ut_get_object_size(union acpi_operand_object *obj, acpi_size * obj_length);
  263. /*
  264. * utstate - Generic state creation/cache routines
  265. */
  266. void
  267. acpi_ut_push_generic_state(union acpi_generic_state **list_head,
  268. union acpi_generic_state *state);
  269. union acpi_generic_state *acpi_ut_pop_generic_state(union acpi_generic_state
  270. **list_head);
  271. union acpi_generic_state *acpi_ut_create_generic_state(void);
  272. struct acpi_thread_state *acpi_ut_create_thread_state(void);
  273. union acpi_generic_state *acpi_ut_create_update_state(union acpi_operand_object
  274. *object, u16 action);
  275. union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object,
  276. void *external_object,
  277. u16 index);
  278. acpi_status
  279. acpi_ut_create_update_state_and_push(union acpi_operand_object *object,
  280. u16 action,
  281. union acpi_generic_state **state_list);
  282. #ifdef ACPI_FUTURE_USAGE
  283. acpi_status
  284. acpi_ut_create_pkg_state_and_push(void *internal_object,
  285. void *external_object,
  286. u16 index,
  287. union acpi_generic_state **state_list);
  288. #endif /* ACPI_FUTURE_USAGE */
  289. union acpi_generic_state *acpi_ut_create_control_state(void);
  290. void acpi_ut_delete_generic_state(union acpi_generic_state *state);
  291. /*
  292. * utmath
  293. */
  294. acpi_status
  295. acpi_ut_divide(acpi_integer in_dividend,
  296. acpi_integer in_divisor,
  297. acpi_integer * out_quotient, acpi_integer * out_remainder);
  298. acpi_status
  299. acpi_ut_short_divide(acpi_integer in_dividend,
  300. u32 divisor,
  301. acpi_integer * out_quotient, u32 * out_remainder);
  302. /*
  303. * utmisc
  304. */
  305. acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id);
  306. void acpi_ut_release_owner_id(acpi_owner_id * owner_id);
  307. acpi_status
  308. acpi_ut_walk_package_tree(union acpi_operand_object *source_object,
  309. void *target_object,
  310. acpi_pkg_callback walk_callback, void *context);
  311. void acpi_ut_strupr(char *src_string);
  312. void acpi_ut_print_string(char *string, u8 max_length);
  313. u8 acpi_ut_valid_acpi_name(u32 name);
  314. u8 acpi_ut_valid_acpi_character(char character);
  315. acpi_status
  316. acpi_ut_strtoul64(char *string, u32 base, acpi_integer * ret_integer);
  317. /* Values for Base above (16=Hex, 10=Decimal) */
  318. #define ACPI_ANY_BASE 0
  319. acpi_status acpi_ut_validate_resource(void *aml, u8 * return_index);
  320. u32 acpi_ut_get_descriptor_length(void *aml);
  321. u16 acpi_ut_get_resource_length(void *aml);
  322. u8 acpi_ut_get_resource_header_length(void *aml);
  323. u8 acpi_ut_get_resource_type(void *aml);
  324. acpi_status
  325. acpi_ut_get_resource_end_tag(union acpi_operand_object *obj_desc,
  326. u8 ** end_tag);
  327. u8 acpi_ut_generate_checksum(u8 * buffer, u32 length);
  328. u32 acpi_ut_dword_byte_swap(u32 value);
  329. void acpi_ut_set_integer_width(u8 revision);
  330. #ifdef ACPI_DEBUG_OUTPUT
  331. void
  332. acpi_ut_display_init_pathname(u8 type,
  333. struct acpi_namespace_node *obj_handle,
  334. char *path);
  335. #endif
  336. /*
  337. * utmutex - mutex support
  338. */
  339. acpi_status acpi_ut_mutex_initialize(void);
  340. void acpi_ut_mutex_terminate(void);
  341. acpi_status acpi_ut_acquire_mutex(acpi_mutex_handle mutex_id);
  342. acpi_status acpi_ut_release_mutex(acpi_mutex_handle mutex_id);
  343. /*
  344. * utalloc - memory allocation and object caching
  345. */
  346. acpi_status acpi_ut_create_caches(void);
  347. acpi_status acpi_ut_delete_caches(void);
  348. acpi_status acpi_ut_validate_buffer(struct acpi_buffer *buffer);
  349. acpi_status
  350. acpi_ut_initialize_buffer(struct acpi_buffer *buffer,
  351. acpi_size required_length);
  352. void *acpi_ut_allocate(acpi_size size, u32 component, char *module, u32 line);
  353. void *acpi_ut_callocate(acpi_size size, u32 component, char *module, u32 line);
  354. #ifdef ACPI_DBG_TRACK_ALLOCATIONS
  355. void *acpi_ut_allocate_and_track(acpi_size size,
  356. u32 component, char *module, u32 line);
  357. void *acpi_ut_callocate_and_track(acpi_size size,
  358. u32 component, char *module, u32 line);
  359. void
  360. acpi_ut_free_and_track(void *address, u32 component, char *module, u32 line);
  361. #ifdef ACPI_FUTURE_USAGE
  362. void acpi_ut_dump_allocation_info(void);
  363. #endif /* ACPI_FUTURE_USAGE */
  364. void acpi_ut_dump_allocations(u32 component, char *module);
  365. #endif
  366. #endif /* _ACUTILS_H */