rsmemory.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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->type = 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: Resource - 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 *resource,
  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 Type field is static */
  133. *buffer = ACPI_RDESC_TYPE_MEMORY_24;
  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) (resource->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, &resource->data.memory24.min_base_address);
  145. buffer += 2;
  146. /* Set the Range maximum base address */
  147. ACPI_MOVE_32_TO_16(buffer, &resource->data.memory24.max_base_address);
  148. buffer += 2;
  149. /* Set the base alignment */
  150. ACPI_MOVE_32_TO_16(buffer, &resource->data.memory24.alignment);
  151. buffer += 2;
  152. /* Set the range length */
  153. ACPI_MOVE_32_TO_16(buffer, &resource->data.memory24.range_length);
  154. buffer += 2;
  155. /* Return the number of bytes consumed in this operation */
  156. *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
  157. return_ACPI_STATUS(AE_OK);
  158. }
  159. /*******************************************************************************
  160. *
  161. * FUNCTION: acpi_rs_memory32_range_resource
  162. *
  163. * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
  164. * stream
  165. * bytes_consumed - Pointer to where the number of bytes
  166. * consumed the byte_stream_buffer is
  167. * returned
  168. * output_buffer - Pointer to the return data buffer
  169. * structure_size - Pointer to where the number of bytes
  170. * in the return data struct is returned
  171. *
  172. * RETURN: Status
  173. *
  174. * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  175. * structure pointed to by the output_buffer. Return the
  176. * number of bytes consumed from the byte stream.
  177. *
  178. ******************************************************************************/
  179. acpi_status
  180. acpi_rs_memory32_range_resource(u8 * byte_stream_buffer,
  181. acpi_size * bytes_consumed,
  182. u8 ** output_buffer, acpi_size * structure_size)
  183. {
  184. u8 *buffer = byte_stream_buffer;
  185. struct acpi_resource *output_struct = (void *)*output_buffer;
  186. u16 temp16 = 0;
  187. u8 temp8 = 0;
  188. acpi_size struct_size =
  189. ACPI_SIZEOF_RESOURCE(struct acpi_resource_mem32);
  190. ACPI_FUNCTION_TRACE("rs_memory32_range_resource");
  191. /* Point past the Descriptor to get the number of bytes consumed */
  192. buffer += 1;
  193. ACPI_MOVE_16_TO_16(&temp16, buffer);
  194. buffer += 2;
  195. *bytes_consumed = (acpi_size) temp16 + 3;
  196. output_struct->type = ACPI_RSTYPE_MEM32;
  197. /*
  198. * Point to the place in the output buffer where the data portion will
  199. * begin.
  200. * 1. Set the RESOURCE_DATA * Data to point to its own address, then
  201. * 2. Set the pointer to the next address.
  202. *
  203. * NOTE: output_struct->Data is cast to u8, otherwise, this addition adds
  204. * 4 * sizeof(RESOURCE_DATA) instead of 4 * sizeof(u8)
  205. */
  206. /* Check Byte 3 the Read/Write bit */
  207. temp8 = *buffer;
  208. buffer += 1;
  209. output_struct->data.memory32.read_write_attribute = temp8 & 0x01;
  210. /* Get min_base_address (Bytes 4-7) */
  211. ACPI_MOVE_32_TO_32(&output_struct->data.memory32.min_base_address,
  212. buffer);
  213. buffer += 4;
  214. /* Get max_base_address (Bytes 8-11) */
  215. ACPI_MOVE_32_TO_32(&output_struct->data.memory32.max_base_address,
  216. buffer);
  217. buffer += 4;
  218. /* Get Alignment (Bytes 12-15) */
  219. ACPI_MOVE_32_TO_32(&output_struct->data.memory32.alignment, buffer);
  220. buffer += 4;
  221. /* Get range_length (Bytes 16-19) */
  222. ACPI_MOVE_32_TO_32(&output_struct->data.memory32.range_length, buffer);
  223. /* Set the Length parameter */
  224. output_struct->length = (u32) struct_size;
  225. /* Return the final size of the structure */
  226. *structure_size = struct_size;
  227. return_ACPI_STATUS(AE_OK);
  228. }
  229. /*******************************************************************************
  230. *
  231. * FUNCTION: acpi_rs_fixed_memory32_resource
  232. *
  233. * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
  234. * stream
  235. * bytes_consumed - Pointer to where the number of bytes
  236. * consumed the byte_stream_buffer is
  237. * returned
  238. * output_buffer - Pointer to the return data buffer
  239. * structure_size - Pointer to where the number of bytes
  240. * in the return data struct is returned
  241. *
  242. * RETURN: Status
  243. *
  244. * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  245. * structure pointed to by the output_buffer. Return the
  246. * number of bytes consumed from the byte stream.
  247. *
  248. ******************************************************************************/
  249. acpi_status
  250. acpi_rs_fixed_memory32_resource(u8 * byte_stream_buffer,
  251. acpi_size * bytes_consumed,
  252. u8 ** output_buffer, acpi_size * structure_size)
  253. {
  254. u8 *buffer = byte_stream_buffer;
  255. struct acpi_resource *output_struct = (void *)*output_buffer;
  256. u16 temp16 = 0;
  257. u8 temp8 = 0;
  258. acpi_size struct_size =
  259. ACPI_SIZEOF_RESOURCE(struct acpi_resource_fixed_mem32);
  260. ACPI_FUNCTION_TRACE("rs_fixed_memory32_resource");
  261. /* Point past the Descriptor to get the number of bytes consumed */
  262. buffer += 1;
  263. ACPI_MOVE_16_TO_16(&temp16, buffer);
  264. buffer += 2;
  265. *bytes_consumed = (acpi_size) temp16 + 3;
  266. output_struct->type = ACPI_RSTYPE_FIXED_MEM32;
  267. /* Check Byte 3 the Read/Write bit */
  268. temp8 = *buffer;
  269. buffer += 1;
  270. output_struct->data.fixed_memory32.read_write_attribute = temp8 & 0x01;
  271. /* Get range_base_address (Bytes 4-7) */
  272. ACPI_MOVE_32_TO_32(&output_struct->data.fixed_memory32.
  273. range_base_address, buffer);
  274. buffer += 4;
  275. /* Get range_length (Bytes 8-11) */
  276. ACPI_MOVE_32_TO_32(&output_struct->data.fixed_memory32.range_length,
  277. buffer);
  278. /* Set the Length parameter */
  279. output_struct->length = (u32) struct_size;
  280. /* Return the final size of the structure */
  281. *structure_size = struct_size;
  282. return_ACPI_STATUS(AE_OK);
  283. }
  284. /*******************************************************************************
  285. *
  286. * FUNCTION: acpi_rs_memory32_range_stream
  287. *
  288. * PARAMETERS: Resource - Pointer to the resource linked list
  289. * output_buffer - Pointer to the user's return buffer
  290. * bytes_consumed - Pointer to where the number of bytes
  291. * used in the output_buffer is returned
  292. *
  293. * RETURN: Status
  294. *
  295. * DESCRIPTION: Take the linked list resource structure and fills in the
  296. * the appropriate bytes in a byte stream
  297. *
  298. ******************************************************************************/
  299. acpi_status
  300. acpi_rs_memory32_range_stream(struct acpi_resource *resource,
  301. u8 ** output_buffer, acpi_size * bytes_consumed)
  302. {
  303. u8 *buffer = *output_buffer;
  304. u16 temp16 = 0;
  305. u8 temp8 = 0;
  306. ACPI_FUNCTION_TRACE("rs_memory32_range_stream");
  307. /* The Descriptor Type field is static */
  308. *buffer = ACPI_RDESC_TYPE_MEMORY_32;
  309. buffer += 1;
  310. /* The length field is static */
  311. temp16 = 0x11;
  312. ACPI_MOVE_16_TO_16(buffer, &temp16);
  313. buffer += 2;
  314. /* Set the Information Byte */
  315. temp8 = (u8) (resource->data.memory32.read_write_attribute & 0x01);
  316. *buffer = temp8;
  317. buffer += 1;
  318. /* Set the Range minimum base address */
  319. ACPI_MOVE_32_TO_32(buffer, &resource->data.memory32.min_base_address);
  320. buffer += 4;
  321. /* Set the Range maximum base address */
  322. ACPI_MOVE_32_TO_32(buffer, &resource->data.memory32.max_base_address);
  323. buffer += 4;
  324. /* Set the base alignment */
  325. ACPI_MOVE_32_TO_32(buffer, &resource->data.memory32.alignment);
  326. buffer += 4;
  327. /* Set the range length */
  328. ACPI_MOVE_32_TO_32(buffer, &resource->data.memory32.range_length);
  329. buffer += 4;
  330. /* Return the number of bytes consumed in this operation */
  331. *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
  332. return_ACPI_STATUS(AE_OK);
  333. }
  334. /*******************************************************************************
  335. *
  336. * FUNCTION: acpi_rs_fixed_memory32_stream
  337. *
  338. * PARAMETERS: Resource - Pointer to the resource linked list
  339. * output_buffer - Pointer to the user's return buffer
  340. * bytes_consumed - Pointer to where the number of bytes
  341. * used in the output_buffer is returned
  342. *
  343. * RETURN: Status
  344. *
  345. * DESCRIPTION: Take the linked list resource structure and fills in the
  346. * the appropriate bytes in a byte stream
  347. *
  348. ******************************************************************************/
  349. acpi_status
  350. acpi_rs_fixed_memory32_stream(struct acpi_resource *resource,
  351. u8 ** output_buffer, acpi_size * bytes_consumed)
  352. {
  353. u8 *buffer = *output_buffer;
  354. u16 temp16 = 0;
  355. u8 temp8 = 0;
  356. ACPI_FUNCTION_TRACE("rs_fixed_memory32_stream");
  357. /* The Descriptor Type field is static */
  358. *buffer = ACPI_RDESC_TYPE_FIXED_MEMORY_32;
  359. buffer += 1;
  360. /* The length field is static */
  361. temp16 = 0x09;
  362. ACPI_MOVE_16_TO_16(buffer, &temp16);
  363. buffer += 2;
  364. /* Set the Information Byte */
  365. temp8 =
  366. (u8) (resource->data.fixed_memory32.read_write_attribute & 0x01);
  367. *buffer = temp8;
  368. buffer += 1;
  369. /* Set the Range base address */
  370. ACPI_MOVE_32_TO_32(buffer,
  371. &resource->data.fixed_memory32.range_base_address);
  372. buffer += 4;
  373. /* Set the range length */
  374. ACPI_MOVE_32_TO_32(buffer, &resource->data.fixed_memory32.range_length);
  375. buffer += 4;
  376. /* Return the number of bytes consumed in this operation */
  377. *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
  378. return_ACPI_STATUS(AE_OK);
  379. }