acutils.h 19 KB

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