rsmemory.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. /*******************************************************************************
  2. *
  3. * Module Name: rsmem24 - Memory resource descriptors
  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/acresrc.h>
  44. #define _COMPONENT ACPI_RESOURCES
  45. ACPI_MODULE_NAME("rsmemory")
  46. /*******************************************************************************
  47. *
  48. * FUNCTION: acpi_rs_memory24_resource
  49. *
  50. * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
  51. * stream
  52. * bytes_consumed - Pointer to where the number of bytes
  53. * consumed the byte_stream_buffer is
  54. * returned
  55. * output_buffer - Pointer to the return data buffer
  56. * structure_size - Pointer to where the number of bytes
  57. * in the return data struct is returned
  58. *
  59. * RETURN: Status
  60. *
  61. * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  62. * structure pointed to by the output_buffer. Return the
  63. * number of bytes consumed from the byte stream.
  64. *
  65. ******************************************************************************/
  66. acpi_status
  67. acpi_rs_memory24_resource(u8 * byte_stream_buffer,
  68. acpi_size * bytes_consumed,
  69. u8 ** output_buffer, acpi_size * structure_size)
  70. {
  71. u8 *buffer = byte_stream_buffer;
  72. struct acpi_resource *output_struct = (void *)*output_buffer;
  73. u16 temp16 = 0;
  74. u8 temp8 = 0;
  75. acpi_size struct_size =
  76. ACPI_SIZEOF_RESOURCE(struct acpi_resource_mem24);
  77. ACPI_FUNCTION_TRACE("rs_memory24_resource");
  78. /* Point past the Descriptor to get the number of bytes consumed */
  79. buffer += 1;
  80. ACPI_MOVE_16_TO_16(&temp16, buffer);
  81. buffer += 2;
  82. *bytes_consumed = (acpi_size) temp16 + 3;
  83. output_struct->id = ACPI_RSTYPE_MEM24;
  84. /* Check Byte 3 the Read/Write bit */
  85. temp8 = *buffer;
  86. buffer += 1;
  87. output_struct->data.memory24.read_write_attribute = temp8 & 0x01;
  88. /* Get min_base_address (Bytes 4-5) */
  89. ACPI_MOVE_16_TO_16(&temp16, buffer);
  90. buffer += 2;
  91. output_struct->data.memory24.min_base_address = temp16;
  92. /* Get max_base_address (Bytes 6-7) */
  93. ACPI_MOVE_16_TO_16(&temp16, buffer);
  94. buffer += 2;
  95. output_struct->data.memory24.max_base_address = temp16;
  96. /* Get Alignment (Bytes 8-9) */
  97. ACPI_MOVE_16_TO_16(&temp16, buffer);
  98. buffer += 2;
  99. output_struct->data.memory24.alignment = temp16;
  100. /* Get range_length (Bytes 10-11) */
  101. ACPI_MOVE_16_TO_16(&temp16, buffer);
  102. output_struct->data.memory24.range_length = temp16;
  103. /* Set the Length parameter */
  104. output_struct->length = (u32) struct_size;
  105. /* Return the final size of the structure */
  106. *structure_size = struct_size;
  107. return_ACPI_STATUS(AE_OK);
  108. }
  109. /*******************************************************************************
  110. *
  111. * FUNCTION: acpi_rs_memory24_stream
  112. *
  113. * PARAMETERS: linked_list - Pointer to the resource linked list
  114. * output_buffer - Pointer to the user's return buffer
  115. * bytes_consumed - Pointer to where the number of bytes
  116. * used in the output_buffer is returned
  117. *
  118. * RETURN: Status
  119. *
  120. * DESCRIPTION: Take the linked list resource structure and fills in the
  121. * the appropriate bytes in a byte stream
  122. *
  123. ******************************************************************************/
  124. acpi_status
  125. acpi_rs_memory24_stream(struct acpi_resource *linked_list,
  126. u8 ** output_buffer, acpi_size * bytes_consumed)
  127. {
  128. u8 *buffer = *output_buffer;
  129. u16 temp16 = 0;
  130. u8 temp8 = 0;
  131. ACPI_FUNCTION_TRACE("rs_memory24_stream");
  132. /* The descriptor field is static */
  133. *buffer = 0x81;
  134. buffer += 1;
  135. /* The length field is static */
  136. temp16 = 0x09;
  137. ACPI_MOVE_16_TO_16(buffer, &temp16);
  138. buffer += 2;
  139. /* Set the Information Byte */
  140. temp8 = (u8) (linked_list->data.memory24.read_write_attribute & 0x01);
  141. *buffer = temp8;
  142. buffer += 1;
  143. /* Set the Range minimum base address */
  144. ACPI_MOVE_32_TO_16(buffer,
  145. &linked_list->data.memory24.min_base_address);
  146. buffer += 2;
  147. /* Set the Range maximum base address */
  148. ACPI_MOVE_32_TO_16(buffer,
  149. &linked_list->data.memory24.max_base_address);
  150. buffer += 2;
  151. /* Set the base alignment */
  152. ACPI_MOVE_32_TO_16(buffer, &linked_list->data.memory24.alignment);
  153. buffer += 2;
  154. /* Set the range length */
  155. ACPI_MOVE_32_TO_16(buffer, &linked_list->data.memory24.range_length);
  156. buffer += 2;
  157. /* Return the number of bytes consumed in this operation */
  158. *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
  159. return_ACPI_STATUS(AE_OK);
  160. }
  161. /*******************************************************************************
  162. *
  163. * FUNCTION: acpi_rs_memory32_range_resource
  164. *
  165. * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
  166. * stream
  167. * bytes_consumed - Pointer to where the number of bytes
  168. * consumed the byte_stream_buffer is
  169. * returned
  170. * output_buffer - Pointer to the return data buffer
  171. * structure_size - Pointer to where the number of bytes
  172. * in the return data struct is returned
  173. *
  174. * RETURN: Status
  175. *
  176. * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  177. * structure pointed to by the output_buffer. Return the
  178. * number of bytes consumed from the byte stream.
  179. *
  180. ******************************************************************************/
  181. acpi_status
  182. acpi_rs_memory32_range_resource(u8 * byte_stream_buffer,
  183. acpi_size * bytes_consumed,
  184. u8 ** output_buffer, acpi_size * structure_size)
  185. {
  186. u8 *buffer = byte_stream_buffer;
  187. struct acpi_resource *output_struct = (void *)*output_buffer;
  188. u16 temp16 = 0;
  189. u8 temp8 = 0;
  190. acpi_size struct_size =
  191. ACPI_SIZEOF_RESOURCE(struct acpi_resource_mem32);
  192. ACPI_FUNCTION_TRACE("rs_memory32_range_resource");
  193. /* Point past the Descriptor to get the number of bytes consumed */
  194. buffer += 1;
  195. ACPI_MOVE_16_TO_16(&temp16, buffer);
  196. buffer += 2;
  197. *bytes_consumed = (acpi_size) temp16 + 3;
  198. output_struct->id = ACPI_RSTYPE_MEM32;
  199. /*
  200. * Point to the place in the output buffer where the data portion will
  201. * begin.
  202. * 1. Set the RESOURCE_DATA * Data to point to its own address, then
  203. * 2. Set the pointer to the next address.
  204. *
  205. * NOTE: output_struct->Data is cast to u8, otherwise, this addition adds
  206. * 4 * sizeof(RESOURCE_DATA) instead of 4 * sizeof(u8)
  207. */
  208. /* Check Byte 3 the Read/Write bit */
  209. temp8 = *buffer;
  210. buffer += 1;
  211. output_struct->data.memory32.read_write_attribute = temp8 & 0x01;
  212. /* Get min_base_address (Bytes 4-7) */
  213. ACPI_MOVE_32_TO_32(&output_struct->data.memory32.min_base_address,
  214. buffer);
  215. buffer += 4;
  216. /* Get max_base_address (Bytes 8-11) */
  217. ACPI_MOVE_32_TO_32(&output_struct->data.memory32.max_base_address,
  218. buffer);
  219. buffer += 4;
  220. /* Get Alignment (Bytes 12-15) */
  221. ACPI_MOVE_32_TO_32(&output_struct->data.memory32.alignment, buffer);
  222. buffer += 4;
  223. /* Get range_length (Bytes 16-19) */
  224. ACPI_MOVE_32_TO_32(&output_struct->data.memory32.range_length, buffer);
  225. /* Set the Length parameter */
  226. output_struct->length = (u32) struct_size;
  227. /* Return the final size of the structure */
  228. *structure_size = struct_size;
  229. return_ACPI_STATUS(AE_OK);
  230. }
  231. /*******************************************************************************
  232. *
  233. * FUNCTION: acpi_rs_fixed_memory32_resource
  234. *
  235. * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
  236. * stream
  237. * bytes_consumed - Pointer to where the number of bytes
  238. * consumed the byte_stream_buffer is
  239. * returned
  240. * output_buffer - Pointer to the return data buffer
  241. * structure_size - Pointer to where the number of bytes
  242. * in the return data struct is returned
  243. *
  244. * RETURN: Status
  245. *
  246. * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  247. * structure pointed to by the output_buffer. Return the
  248. * number of bytes consumed from the byte stream.
  249. *
  250. ******************************************************************************/
  251. acpi_status
  252. acpi_rs_fixed_memory32_resource(u8 * byte_stream_buffer,
  253. acpi_size * bytes_consumed,
  254. u8 ** output_buffer, acpi_size * structure_size)
  255. {
  256. u8 *buffer = byte_stream_buffer;
  257. struct acpi_resource *output_struct = (void *)*output_buffer;
  258. u16 temp16 = 0;
  259. u8 temp8 = 0;
  260. acpi_size struct_size =
  261. ACPI_SIZEOF_RESOURCE(struct acpi_resource_fixed_mem32);
  262. ACPI_FUNCTION_TRACE("rs_fixed_memory32_resource");
  263. /* Point past the Descriptor to get the number of bytes consumed */
  264. buffer += 1;
  265. ACPI_MOVE_16_TO_16(&temp16, buffer);
  266. buffer += 2;
  267. *bytes_consumed = (acpi_size) temp16 + 3;
  268. output_struct->id = ACPI_RSTYPE_FIXED_MEM32;
  269. /* Check Byte 3 the Read/Write bit */
  270. temp8 = *buffer;
  271. buffer += 1;
  272. output_struct->data.fixed_memory32.read_write_attribute = temp8 & 0x01;
  273. /* Get range_base_address (Bytes 4-7) */
  274. ACPI_MOVE_32_TO_32(&output_struct->data.fixed_memory32.
  275. range_base_address, buffer);
  276. buffer += 4;
  277. /* Get range_length (Bytes 8-11) */
  278. ACPI_MOVE_32_TO_32(&output_struct->data.fixed_memory32.range_length,
  279. buffer);
  280. /* Set the Length parameter */
  281. output_struct->length = (u32) struct_size;
  282. /* Return the final size of the structure */
  283. *structure_size = struct_size;
  284. return_ACPI_STATUS(AE_OK);
  285. }
  286. /*******************************************************************************
  287. *
  288. * FUNCTION: acpi_rs_memory32_range_stream
  289. *
  290. * PARAMETERS: linked_list - Pointer to the resource linked list
  291. * output_buffer - Pointer to the user's return buffer
  292. * bytes_consumed - Pointer to where the number of bytes
  293. * used in the output_buffer is returned
  294. *
  295. * RETURN: Status
  296. *
  297. * DESCRIPTION: Take the linked list resource structure and fills in the
  298. * the appropriate bytes in a byte stream
  299. *
  300. ******************************************************************************/
  301. acpi_status
  302. acpi_rs_memory32_range_stream(struct acpi_resource *linked_list,
  303. u8 ** output_buffer, acpi_size * bytes_consumed)
  304. {
  305. u8 *buffer = *output_buffer;
  306. u16 temp16 = 0;
  307. u8 temp8 = 0;
  308. ACPI_FUNCTION_TRACE("rs_memory32_range_stream");
  309. /* The descriptor field is static */
  310. *buffer = 0x85;
  311. buffer += 1;
  312. /* The length field is static */
  313. temp16 = 0x11;
  314. ACPI_MOVE_16_TO_16(buffer, &temp16);
  315. buffer += 2;
  316. /* Set the Information Byte */
  317. temp8 = (u8) (linked_list->data.memory32.read_write_attribute & 0x01);
  318. *buffer = temp8;
  319. buffer += 1;
  320. /* Set the Range minimum base address */
  321. ACPI_MOVE_32_TO_32(buffer,
  322. &linked_list->data.memory32.min_base_address);
  323. buffer += 4;
  324. /* Set the Range maximum base address */
  325. ACPI_MOVE_32_TO_32(buffer,
  326. &linked_list->data.memory32.max_base_address);
  327. buffer += 4;
  328. /* Set the base alignment */
  329. ACPI_MOVE_32_TO_32(buffer, &linked_list->data.memory32.alignment);
  330. buffer += 4;
  331. /* Set the range length */
  332. ACPI_MOVE_32_TO_32(buffer, &linked_list->data.memory32.range_length);
  333. buffer += 4;
  334. /* Return the number of bytes consumed in this operation */
  335. *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
  336. return_ACPI_STATUS(AE_OK);
  337. }
  338. /*******************************************************************************
  339. *
  340. * FUNCTION: acpi_rs_fixed_memory32_stream
  341. *
  342. * PARAMETERS: linked_list - Pointer to the resource linked list
  343. * output_buffer - Pointer to the user's return buffer
  344. * bytes_consumed - Pointer to where the number of bytes
  345. * used in the output_buffer is returned
  346. *
  347. * RETURN: Status
  348. *
  349. * DESCRIPTION: Take the linked list resource structure and fills in the
  350. * the appropriate bytes in a byte stream
  351. *
  352. ******************************************************************************/
  353. acpi_status
  354. acpi_rs_fixed_memory32_stream(struct acpi_resource *linked_list,
  355. u8 ** output_buffer, acpi_size * bytes_consumed)
  356. {
  357. u8 *buffer = *output_buffer;
  358. u16 temp16 = 0;
  359. u8 temp8 = 0;
  360. ACPI_FUNCTION_TRACE("rs_fixed_memory32_stream");
  361. /* The descriptor field is static */
  362. *buffer = 0x86;
  363. buffer += 1;
  364. /* The length field is static */
  365. temp16 = 0x09;
  366. ACPI_MOVE_16_TO_16(buffer, &temp16);
  367. buffer += 2;
  368. /* Set the Information Byte */
  369. temp8 =
  370. (u8) (linked_list->data.fixed_memory32.read_write_attribute & 0x01);
  371. *buffer = temp8;
  372. buffer += 1;
  373. /* Set the Range base address */
  374. ACPI_MOVE_32_TO_32(buffer,
  375. &linked_list->data.fixed_memory32.
  376. range_base_address);
  377. buffer += 4;
  378. /* Set the range length */
  379. ACPI_MOVE_32_TO_32(buffer,
  380. &linked_list->data.fixed_memory32.range_length);
  381. buffer += 4;
  382. /* Return the number of bytes consumed in this operation */
  383. *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
  384. return_ACPI_STATUS(AE_OK);
  385. }