utids.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /******************************************************************************
  2. *
  3. * Module Name: utids - support for device IDs - HID, UID, CID
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2011, Intel Corp.
  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 "accommon.h"
  44. #include "acinterp.h"
  45. #define _COMPONENT ACPI_UTILITIES
  46. ACPI_MODULE_NAME("utids")
  47. /*******************************************************************************
  48. *
  49. * FUNCTION: acpi_ut_execute_HID
  50. *
  51. * PARAMETERS: device_node - Node for the device
  52. * return_id - Where the string HID is returned
  53. *
  54. * RETURN: Status
  55. *
  56. * DESCRIPTION: Executes the _HID control method that returns the hardware
  57. * ID of the device. The HID is either an 32-bit encoded EISAID
  58. * Integer or a String. A string is always returned. An EISAID
  59. * is converted to a string.
  60. *
  61. * NOTE: Internal function, no parameter validation
  62. *
  63. ******************************************************************************/
  64. acpi_status
  65. acpi_ut_execute_HID(struct acpi_namespace_node *device_node,
  66. struct acpica_device_id **return_id)
  67. {
  68. union acpi_operand_object *obj_desc;
  69. struct acpica_device_id *hid;
  70. u32 length;
  71. acpi_status status;
  72. ACPI_FUNCTION_TRACE(ut_execute_HID);
  73. status = acpi_ut_evaluate_object(device_node, METHOD_NAME__HID,
  74. ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING,
  75. &obj_desc);
  76. if (ACPI_FAILURE(status)) {
  77. return_ACPI_STATUS(status);
  78. }
  79. /* Get the size of the String to be returned, includes null terminator */
  80. if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
  81. length = ACPI_EISAID_STRING_SIZE;
  82. } else {
  83. length = obj_desc->string.length + 1;
  84. }
  85. /* Allocate a buffer for the HID */
  86. hid =
  87. ACPI_ALLOCATE_ZEROED(sizeof(struct acpica_device_id) +
  88. (acpi_size) length);
  89. if (!hid) {
  90. status = AE_NO_MEMORY;
  91. goto cleanup;
  92. }
  93. /* Area for the string starts after DEVICE_ID struct */
  94. hid->string = ACPI_ADD_PTR(char, hid, sizeof(struct acpica_device_id));
  95. /* Convert EISAID to a string or simply copy existing string */
  96. if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
  97. acpi_ex_eisa_id_to_string(hid->string, obj_desc->integer.value);
  98. } else {
  99. ACPI_STRCPY(hid->string, obj_desc->string.pointer);
  100. }
  101. hid->length = length;
  102. *return_id = hid;
  103. cleanup:
  104. /* On exit, we must delete the return object */
  105. acpi_ut_remove_reference(obj_desc);
  106. return_ACPI_STATUS(status);
  107. }
  108. /*******************************************************************************
  109. *
  110. * FUNCTION: acpi_ut_execute_UID
  111. *
  112. * PARAMETERS: device_node - Node for the device
  113. * return_id - Where the string UID is returned
  114. *
  115. * RETURN: Status
  116. *
  117. * DESCRIPTION: Executes the _UID control method that returns the unique
  118. * ID of the device. The UID is either a 64-bit Integer (NOT an
  119. * EISAID) or a string. Always returns a string. A 64-bit integer
  120. * is converted to a decimal string.
  121. *
  122. * NOTE: Internal function, no parameter validation
  123. *
  124. ******************************************************************************/
  125. acpi_status
  126. acpi_ut_execute_UID(struct acpi_namespace_node *device_node,
  127. struct acpica_device_id **return_id)
  128. {
  129. union acpi_operand_object *obj_desc;
  130. struct acpica_device_id *uid;
  131. u32 length;
  132. acpi_status status;
  133. ACPI_FUNCTION_TRACE(ut_execute_UID);
  134. status = acpi_ut_evaluate_object(device_node, METHOD_NAME__UID,
  135. ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING,
  136. &obj_desc);
  137. if (ACPI_FAILURE(status)) {
  138. return_ACPI_STATUS(status);
  139. }
  140. /* Get the size of the String to be returned, includes null terminator */
  141. if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
  142. length = ACPI_MAX64_DECIMAL_DIGITS + 1;
  143. } else {
  144. length = obj_desc->string.length + 1;
  145. }
  146. /* Allocate a buffer for the UID */
  147. uid =
  148. ACPI_ALLOCATE_ZEROED(sizeof(struct acpica_device_id) +
  149. (acpi_size) length);
  150. if (!uid) {
  151. status = AE_NO_MEMORY;
  152. goto cleanup;
  153. }
  154. /* Area for the string starts after DEVICE_ID struct */
  155. uid->string = ACPI_ADD_PTR(char, uid, sizeof(struct acpica_device_id));
  156. /* Convert an Integer to string, or just copy an existing string */
  157. if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
  158. acpi_ex_integer_to_string(uid->string, obj_desc->integer.value);
  159. } else {
  160. ACPI_STRCPY(uid->string, obj_desc->string.pointer);
  161. }
  162. uid->length = length;
  163. *return_id = uid;
  164. cleanup:
  165. /* On exit, we must delete the return object */
  166. acpi_ut_remove_reference(obj_desc);
  167. return_ACPI_STATUS(status);
  168. }
  169. /*******************************************************************************
  170. *
  171. * FUNCTION: acpi_ut_execute_CID
  172. *
  173. * PARAMETERS: device_node - Node for the device
  174. * return_cid_list - Where the CID list is returned
  175. *
  176. * RETURN: Status, list of CID strings
  177. *
  178. * DESCRIPTION: Executes the _CID control method that returns one or more
  179. * compatible hardware IDs for the device.
  180. *
  181. * NOTE: Internal function, no parameter validation
  182. *
  183. * A _CID method can return either a single compatible ID or a package of
  184. * compatible IDs. Each compatible ID can be one of the following:
  185. * 1) Integer (32 bit compressed EISA ID) or
  186. * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
  187. *
  188. * The Integer CIDs are converted to string format by this function.
  189. *
  190. ******************************************************************************/
  191. acpi_status
  192. acpi_ut_execute_CID(struct acpi_namespace_node *device_node,
  193. struct acpica_device_id_list **return_cid_list)
  194. {
  195. union acpi_operand_object **cid_objects;
  196. union acpi_operand_object *obj_desc;
  197. struct acpica_device_id_list *cid_list;
  198. char *next_id_string;
  199. u32 string_area_size;
  200. u32 length;
  201. u32 cid_list_size;
  202. acpi_status status;
  203. u32 count;
  204. u32 i;
  205. ACPI_FUNCTION_TRACE(ut_execute_CID);
  206. /* Evaluate the _CID method for this device */
  207. status = acpi_ut_evaluate_object(device_node, METHOD_NAME__CID,
  208. ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING
  209. | ACPI_BTYPE_PACKAGE, &obj_desc);
  210. if (ACPI_FAILURE(status)) {
  211. return_ACPI_STATUS(status);
  212. }
  213. /*
  214. * Get the count and size of the returned _CIDs. _CID can return either
  215. * a Package of Integers/Strings or a single Integer or String.
  216. * Note: This section also validates that all CID elements are of the
  217. * correct type (Integer or String).
  218. */
  219. if (obj_desc->common.type == ACPI_TYPE_PACKAGE) {
  220. count = obj_desc->package.count;
  221. cid_objects = obj_desc->package.elements;
  222. } else { /* Single Integer or String CID */
  223. count = 1;
  224. cid_objects = &obj_desc;
  225. }
  226. string_area_size = 0;
  227. for (i = 0; i < count; i++) {
  228. /* String lengths include null terminator */
  229. switch (cid_objects[i]->common.type) {
  230. case ACPI_TYPE_INTEGER:
  231. string_area_size += ACPI_EISAID_STRING_SIZE;
  232. break;
  233. case ACPI_TYPE_STRING:
  234. string_area_size += cid_objects[i]->string.length + 1;
  235. break;
  236. default:
  237. status = AE_TYPE;
  238. goto cleanup;
  239. }
  240. }
  241. /*
  242. * Now that we know the length of the CIDs, allocate return buffer:
  243. * 1) Size of the base structure +
  244. * 2) Size of the CID DEVICE_ID array +
  245. * 3) Size of the actual CID strings
  246. */
  247. cid_list_size = sizeof(struct acpica_device_id_list) +
  248. ((count - 1) * sizeof(struct acpica_device_id)) + string_area_size;
  249. cid_list = ACPI_ALLOCATE_ZEROED(cid_list_size);
  250. if (!cid_list) {
  251. status = AE_NO_MEMORY;
  252. goto cleanup;
  253. }
  254. /* Area for CID strings starts after the CID DEVICE_ID array */
  255. next_id_string = ACPI_CAST_PTR(char, cid_list->ids) +
  256. ((acpi_size) count * sizeof(struct acpica_device_id));
  257. /* Copy/convert the CIDs to the return buffer */
  258. for (i = 0; i < count; i++) {
  259. if (cid_objects[i]->common.type == ACPI_TYPE_INTEGER) {
  260. /* Convert the Integer (EISAID) CID to a string */
  261. acpi_ex_eisa_id_to_string(next_id_string,
  262. cid_objects[i]->integer.
  263. value);
  264. length = ACPI_EISAID_STRING_SIZE;
  265. } else { /* ACPI_TYPE_STRING */
  266. /* Copy the String CID from the returned object */
  267. ACPI_STRCPY(next_id_string,
  268. cid_objects[i]->string.pointer);
  269. length = cid_objects[i]->string.length + 1;
  270. }
  271. cid_list->ids[i].string = next_id_string;
  272. cid_list->ids[i].length = length;
  273. next_id_string += length;
  274. }
  275. /* Finish the CID list */
  276. cid_list->count = count;
  277. cid_list->list_size = cid_list_size;
  278. *return_cid_list = cid_list;
  279. cleanup:
  280. /* On exit, we must delete the _CID return object */
  281. acpi_ut_remove_reference(obj_desc);
  282. return_ACPI_STATUS(status);
  283. }