utids.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. /******************************************************************************
  2. *
  3. * Module Name: utids - support for device Ids - HID, UID, CID
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2013, 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 acpi_pnp_device_id **return_id)
  67. {
  68. union acpi_operand_object *obj_desc;
  69. struct acpi_pnp_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 acpi_pnp_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 PNP_DEVICE_ID struct */
  94. hid->string =
  95. ACPI_ADD_PTR(char, hid, sizeof(struct acpi_pnp_device_id));
  96. /* Convert EISAID to a string or simply copy existing string */
  97. if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
  98. acpi_ex_eisa_id_to_string(hid->string, obj_desc->integer.value);
  99. } else {
  100. ACPI_STRCPY(hid->string, obj_desc->string.pointer);
  101. }
  102. hid->length = length;
  103. *return_id = hid;
  104. cleanup:
  105. /* On exit, we must delete the return object */
  106. acpi_ut_remove_reference(obj_desc);
  107. return_ACPI_STATUS(status);
  108. }
  109. /*******************************************************************************
  110. *
  111. * FUNCTION: acpi_ut_execute_SUB
  112. *
  113. * PARAMETERS: device_node - Node for the device
  114. * return_id - Where the _SUB is returned
  115. *
  116. * RETURN: Status
  117. *
  118. * DESCRIPTION: Executes the _SUB control method that returns the subsystem
  119. * ID of the device. The _SUB value is always a string containing
  120. * either a valid PNP or ACPI ID.
  121. *
  122. * NOTE: Internal function, no parameter validation
  123. *
  124. ******************************************************************************/
  125. acpi_status
  126. acpi_ut_execute_SUB(struct acpi_namespace_node *device_node,
  127. struct acpi_pnp_device_id **return_id)
  128. {
  129. union acpi_operand_object *obj_desc;
  130. struct acpi_pnp_device_id *sub;
  131. u32 length;
  132. acpi_status status;
  133. ACPI_FUNCTION_TRACE(ut_execute_SUB);
  134. status = acpi_ut_evaluate_object(device_node, METHOD_NAME__SUB,
  135. ACPI_BTYPE_STRING, &obj_desc);
  136. if (ACPI_FAILURE(status)) {
  137. return_ACPI_STATUS(status);
  138. }
  139. /* Get the size of the String to be returned, includes null terminator */
  140. length = obj_desc->string.length + 1;
  141. /* Allocate a buffer for the SUB */
  142. sub =
  143. ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_pnp_device_id) +
  144. (acpi_size) length);
  145. if (!sub) {
  146. status = AE_NO_MEMORY;
  147. goto cleanup;
  148. }
  149. /* Area for the string starts after PNP_DEVICE_ID struct */
  150. sub->string =
  151. ACPI_ADD_PTR(char, sub, sizeof(struct acpi_pnp_device_id));
  152. /* Simply copy existing string */
  153. ACPI_STRCPY(sub->string, obj_desc->string.pointer);
  154. sub->length = length;
  155. *return_id = sub;
  156. cleanup:
  157. /* On exit, we must delete the return object */
  158. acpi_ut_remove_reference(obj_desc);
  159. return_ACPI_STATUS(status);
  160. }
  161. /*******************************************************************************
  162. *
  163. * FUNCTION: acpi_ut_execute_UID
  164. *
  165. * PARAMETERS: device_node - Node for the device
  166. * return_id - Where the string UID is returned
  167. *
  168. * RETURN: Status
  169. *
  170. * DESCRIPTION: Executes the _UID control method that returns the unique
  171. * ID of the device. The UID is either a 64-bit Integer (NOT an
  172. * EISAID) or a string. Always returns a string. A 64-bit integer
  173. * is converted to a decimal string.
  174. *
  175. * NOTE: Internal function, no parameter validation
  176. *
  177. ******************************************************************************/
  178. acpi_status
  179. acpi_ut_execute_UID(struct acpi_namespace_node *device_node,
  180. struct acpi_pnp_device_id **return_id)
  181. {
  182. union acpi_operand_object *obj_desc;
  183. struct acpi_pnp_device_id *uid;
  184. u32 length;
  185. acpi_status status;
  186. ACPI_FUNCTION_TRACE(ut_execute_UID);
  187. status = acpi_ut_evaluate_object(device_node, METHOD_NAME__UID,
  188. ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING,
  189. &obj_desc);
  190. if (ACPI_FAILURE(status)) {
  191. return_ACPI_STATUS(status);
  192. }
  193. /* Get the size of the String to be returned, includes null terminator */
  194. if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
  195. length = ACPI_MAX64_DECIMAL_DIGITS + 1;
  196. } else {
  197. length = obj_desc->string.length + 1;
  198. }
  199. /* Allocate a buffer for the UID */
  200. uid =
  201. ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_pnp_device_id) +
  202. (acpi_size) length);
  203. if (!uid) {
  204. status = AE_NO_MEMORY;
  205. goto cleanup;
  206. }
  207. /* Area for the string starts after PNP_DEVICE_ID struct */
  208. uid->string =
  209. ACPI_ADD_PTR(char, uid, sizeof(struct acpi_pnp_device_id));
  210. /* Convert an Integer to string, or just copy an existing string */
  211. if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
  212. acpi_ex_integer_to_string(uid->string, obj_desc->integer.value);
  213. } else {
  214. ACPI_STRCPY(uid->string, obj_desc->string.pointer);
  215. }
  216. uid->length = length;
  217. *return_id = uid;
  218. cleanup:
  219. /* On exit, we must delete the return object */
  220. acpi_ut_remove_reference(obj_desc);
  221. return_ACPI_STATUS(status);
  222. }
  223. /*******************************************************************************
  224. *
  225. * FUNCTION: acpi_ut_execute_CID
  226. *
  227. * PARAMETERS: device_node - Node for the device
  228. * return_cid_list - Where the CID list is returned
  229. *
  230. * RETURN: Status, list of CID strings
  231. *
  232. * DESCRIPTION: Executes the _CID control method that returns one or more
  233. * compatible hardware IDs for the device.
  234. *
  235. * NOTE: Internal function, no parameter validation
  236. *
  237. * A _CID method can return either a single compatible ID or a package of
  238. * compatible IDs. Each compatible ID can be one of the following:
  239. * 1) Integer (32 bit compressed EISA ID) or
  240. * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
  241. *
  242. * The Integer CIDs are converted to string format by this function.
  243. *
  244. ******************************************************************************/
  245. acpi_status
  246. acpi_ut_execute_CID(struct acpi_namespace_node *device_node,
  247. struct acpi_pnp_device_id_list **return_cid_list)
  248. {
  249. union acpi_operand_object **cid_objects;
  250. union acpi_operand_object *obj_desc;
  251. struct acpi_pnp_device_id_list *cid_list;
  252. char *next_id_string;
  253. u32 string_area_size;
  254. u32 length;
  255. u32 cid_list_size;
  256. acpi_status status;
  257. u32 count;
  258. u32 i;
  259. ACPI_FUNCTION_TRACE(ut_execute_CID);
  260. /* Evaluate the _CID method for this device */
  261. status = acpi_ut_evaluate_object(device_node, METHOD_NAME__CID,
  262. ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING
  263. | ACPI_BTYPE_PACKAGE, &obj_desc);
  264. if (ACPI_FAILURE(status)) {
  265. return_ACPI_STATUS(status);
  266. }
  267. /*
  268. * Get the count and size of the returned _CIDs. _CID can return either
  269. * a Package of Integers/Strings or a single Integer or String.
  270. * Note: This section also validates that all CID elements are of the
  271. * correct type (Integer or String).
  272. */
  273. if (obj_desc->common.type == ACPI_TYPE_PACKAGE) {
  274. count = obj_desc->package.count;
  275. cid_objects = obj_desc->package.elements;
  276. } else { /* Single Integer or String CID */
  277. count = 1;
  278. cid_objects = &obj_desc;
  279. }
  280. string_area_size = 0;
  281. for (i = 0; i < count; i++) {
  282. /* String lengths include null terminator */
  283. switch (cid_objects[i]->common.type) {
  284. case ACPI_TYPE_INTEGER:
  285. string_area_size += ACPI_EISAID_STRING_SIZE;
  286. break;
  287. case ACPI_TYPE_STRING:
  288. string_area_size += cid_objects[i]->string.length + 1;
  289. break;
  290. default:
  291. status = AE_TYPE;
  292. goto cleanup;
  293. }
  294. }
  295. /*
  296. * Now that we know the length of the CIDs, allocate return buffer:
  297. * 1) Size of the base structure +
  298. * 2) Size of the CID PNP_DEVICE_ID array +
  299. * 3) Size of the actual CID strings
  300. */
  301. cid_list_size = sizeof(struct acpi_pnp_device_id_list) +
  302. ((count - 1) * sizeof(struct acpi_pnp_device_id)) +
  303. string_area_size;
  304. cid_list = ACPI_ALLOCATE_ZEROED(cid_list_size);
  305. if (!cid_list) {
  306. status = AE_NO_MEMORY;
  307. goto cleanup;
  308. }
  309. /* Area for CID strings starts after the CID PNP_DEVICE_ID array */
  310. next_id_string = ACPI_CAST_PTR(char, cid_list->ids) +
  311. ((acpi_size) count * sizeof(struct acpi_pnp_device_id));
  312. /* Copy/convert the CIDs to the return buffer */
  313. for (i = 0; i < count; i++) {
  314. if (cid_objects[i]->common.type == ACPI_TYPE_INTEGER) {
  315. /* Convert the Integer (EISAID) CID to a string */
  316. acpi_ex_eisa_id_to_string(next_id_string,
  317. cid_objects[i]->integer.
  318. value);
  319. length = ACPI_EISAID_STRING_SIZE;
  320. } else { /* ACPI_TYPE_STRING */
  321. /* Copy the String CID from the returned object */
  322. ACPI_STRCPY(next_id_string,
  323. cid_objects[i]->string.pointer);
  324. length = cid_objects[i]->string.length + 1;
  325. }
  326. cid_list->ids[i].string = next_id_string;
  327. cid_list->ids[i].length = length;
  328. next_id_string += length;
  329. }
  330. /* Finish the CID list */
  331. cid_list->count = count;
  332. cid_list->list_size = cid_list_size;
  333. *return_cid_list = cid_list;
  334. cleanup:
  335. /* On exit, we must delete the _CID return object */
  336. acpi_ut_remove_reference(obj_desc);
  337. return_ACPI_STATUS(status);
  338. }