rsmemory.c 16 KB

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