psutils.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /******************************************************************************
  2. *
  3. * Module Name: psutils - Parser miscellaneous utilities (Parser only)
  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. #include <acpi/acpi.h>
  43. #include <acpi/acparser.h>
  44. #include <acpi/amlcode.h>
  45. #include <acpi/acnamesp.h>
  46. #define _COMPONENT ACPI_PARSER
  47. ACPI_MODULE_NAME ("psutils")
  48. /*******************************************************************************
  49. *
  50. * FUNCTION: acpi_ps_create_scope_op
  51. *
  52. * PARAMETERS: None
  53. *
  54. * RETURN: scope_op
  55. *
  56. * DESCRIPTION: Create a Scope and associated namepath op with the root name
  57. *
  58. ******************************************************************************/
  59. union acpi_parse_object *
  60. acpi_ps_create_scope_op (
  61. void)
  62. {
  63. union acpi_parse_object *scope_op;
  64. scope_op = acpi_ps_alloc_op (AML_SCOPE_OP);
  65. if (!scope_op) {
  66. return (NULL);
  67. }
  68. scope_op->named.name = ACPI_ROOT_NAME;
  69. return (scope_op);
  70. }
  71. /*******************************************************************************
  72. *
  73. * FUNCTION: acpi_ps_init_op
  74. *
  75. * PARAMETERS: Op - A newly allocated Op object
  76. * Opcode - Opcode to store in the Op
  77. *
  78. * RETURN: Status
  79. *
  80. * DESCRIPTION: Allocate an acpi_op, choose op type (and thus size) based on
  81. * opcode
  82. *
  83. ******************************************************************************/
  84. void
  85. acpi_ps_init_op (
  86. union acpi_parse_object *op,
  87. u16 opcode)
  88. {
  89. ACPI_FUNCTION_ENTRY ();
  90. op->common.data_type = ACPI_DESC_TYPE_PARSER;
  91. op->common.aml_opcode = opcode;
  92. ACPI_DISASM_ONLY_MEMBERS (ACPI_STRNCPY (op->common.aml_op_name,
  93. (acpi_ps_get_opcode_info (opcode))->name, sizeof (op->common.aml_op_name)));
  94. }
  95. /*******************************************************************************
  96. *
  97. * FUNCTION: acpi_ps_alloc_op
  98. *
  99. * PARAMETERS: Opcode - Opcode that will be stored in the new Op
  100. *
  101. * RETURN: Pointer to the new Op.
  102. *
  103. * DESCRIPTION: Allocate an acpi_op, choose op type (and thus size) based on
  104. * opcode. A cache of opcodes is available for the pure
  105. * GENERIC_OP, since this is by far the most commonly used.
  106. *
  107. ******************************************************************************/
  108. union acpi_parse_object*
  109. acpi_ps_alloc_op (
  110. u16 opcode)
  111. {
  112. union acpi_parse_object *op;
  113. const struct acpi_opcode_info *op_info;
  114. u8 flags = ACPI_PARSEOP_GENERIC;
  115. ACPI_FUNCTION_ENTRY ();
  116. op_info = acpi_ps_get_opcode_info (opcode);
  117. /* Determine type of parse_op required */
  118. if (op_info->flags & AML_DEFER) {
  119. flags = ACPI_PARSEOP_DEFERRED;
  120. }
  121. else if (op_info->flags & AML_NAMED) {
  122. flags = ACPI_PARSEOP_NAMED;
  123. }
  124. else if (opcode == AML_INT_BYTELIST_OP) {
  125. flags = ACPI_PARSEOP_BYTELIST;
  126. }
  127. /* Allocate the minimum required size object */
  128. if (flags == ACPI_PARSEOP_GENERIC) {
  129. /* The generic op (default) is by far the most common (16 to 1) */
  130. op = acpi_ut_acquire_from_cache (ACPI_MEM_LIST_PSNODE);
  131. }
  132. else {
  133. /* Extended parseop */
  134. op = acpi_ut_acquire_from_cache (ACPI_MEM_LIST_PSNODE_EXT);
  135. }
  136. /* Initialize the Op */
  137. if (op) {
  138. acpi_ps_init_op (op, opcode);
  139. op->common.flags = flags;
  140. }
  141. return (op);
  142. }
  143. /*******************************************************************************
  144. *
  145. * FUNCTION: acpi_ps_free_op
  146. *
  147. * PARAMETERS: Op - Op to be freed
  148. *
  149. * RETURN: None.
  150. *
  151. * DESCRIPTION: Free an Op object. Either put it on the GENERIC_OP cache list
  152. * or actually free it.
  153. *
  154. ******************************************************************************/
  155. void
  156. acpi_ps_free_op (
  157. union acpi_parse_object *op)
  158. {
  159. ACPI_FUNCTION_NAME ("ps_free_op");
  160. if (op->common.aml_opcode == AML_INT_RETURN_VALUE_OP) {
  161. ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Free retval op: %p\n", op));
  162. }
  163. if (op->common.flags & ACPI_PARSEOP_GENERIC) {
  164. acpi_ut_release_to_cache (ACPI_MEM_LIST_PSNODE, op);
  165. }
  166. else {
  167. acpi_ut_release_to_cache (ACPI_MEM_LIST_PSNODE_EXT, op);
  168. }
  169. }
  170. #ifdef ACPI_ENABLE_OBJECT_CACHE
  171. /*******************************************************************************
  172. *
  173. * FUNCTION: acpi_ps_delete_parse_cache
  174. *
  175. * PARAMETERS: None
  176. *
  177. * RETURN: None
  178. *
  179. * DESCRIPTION: Free all objects that are on the parse cache list.
  180. *
  181. ******************************************************************************/
  182. void
  183. acpi_ps_delete_parse_cache (
  184. void)
  185. {
  186. ACPI_FUNCTION_TRACE ("ps_delete_parse_cache");
  187. acpi_ut_delete_generic_cache (ACPI_MEM_LIST_PSNODE);
  188. acpi_ut_delete_generic_cache (ACPI_MEM_LIST_PSNODE_EXT);
  189. return_VOID;
  190. }
  191. #endif
  192. /*******************************************************************************
  193. *
  194. * FUNCTION: Utility functions
  195. *
  196. * DESCRIPTION: Low level character and object functions
  197. *
  198. ******************************************************************************/
  199. /*
  200. * Is "c" a namestring lead character?
  201. */
  202. u8
  203. acpi_ps_is_leading_char (
  204. u32 c)
  205. {
  206. return ((u8) (c == '_' || (c >= 'A' && c <= 'Z')));
  207. }
  208. /*
  209. * Is "c" a namestring prefix character?
  210. */
  211. u8
  212. acpi_ps_is_prefix_char (
  213. u32 c)
  214. {
  215. return ((u8) (c == '\\' || c == '^'));
  216. }
  217. /*
  218. * Get op's name (4-byte name segment) or 0 if unnamed
  219. */
  220. #ifdef ACPI_FUTURE_USAGE
  221. u32
  222. acpi_ps_get_name (
  223. union acpi_parse_object *op)
  224. {
  225. /* The "generic" object has no name associated with it */
  226. if (op->common.flags & ACPI_PARSEOP_GENERIC) {
  227. return (0);
  228. }
  229. /* Only the "Extended" parse objects have a name */
  230. return (op->named.name);
  231. }
  232. #endif /* ACPI_FUTURE_USAGE */
  233. /*
  234. * Set op's name
  235. */
  236. void
  237. acpi_ps_set_name (
  238. union acpi_parse_object *op,
  239. u32 name)
  240. {
  241. /* The "generic" object has no name associated with it */
  242. if (op->common.flags & ACPI_PARSEOP_GENERIC) {
  243. return;
  244. }
  245. op->named.name = name;
  246. }