rsmemory.c 16 KB

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