rsaddr.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  1. /*******************************************************************************
  2. *
  3. * Module Name: rsaddr - Address resource descriptors (16/32/64)
  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 ("rsaddr")
  46. /*******************************************************************************
  47. *
  48. * FUNCTION: acpi_rs_address16_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_address16_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. u8 *temp_ptr;
  76. acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address16);
  77. u32 index;
  78. u16 temp16;
  79. u8 temp8;
  80. ACPI_FUNCTION_TRACE ("rs_address16_resource");
  81. /*
  82. * Point past the Descriptor to get the number of bytes consumed
  83. */
  84. buffer += 1;
  85. ACPI_MOVE_16_TO_16 (&temp16, buffer);
  86. /* Validate minimum descriptor length */
  87. if (temp16 < 13) {
  88. return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
  89. }
  90. *bytes_consumed = temp16 + 3;
  91. output_struct->id = ACPI_RSTYPE_ADDRESS16;
  92. /*
  93. * Get the Resource Type (Byte3)
  94. */
  95. buffer += 2;
  96. temp8 = *buffer;
  97. /* Values 0-2 and 0xC0-0xFF are valid */
  98. if ((temp8 > 2) && (temp8 < 0xC0)) {
  99. return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
  100. }
  101. output_struct->data.address16.resource_type = temp8;
  102. /*
  103. * Get the General Flags (Byte4)
  104. */
  105. buffer += 1;
  106. temp8 = *buffer;
  107. /* Producer / Consumer */
  108. output_struct->data.address16.producer_consumer = temp8 & 0x01;
  109. /* Decode */
  110. output_struct->data.address16.decode = (temp8 >> 1) & 0x01;
  111. /* Min Address Fixed */
  112. output_struct->data.address16.min_address_fixed = (temp8 >> 2) & 0x01;
  113. /* Max Address Fixed */
  114. output_struct->data.address16.max_address_fixed = (temp8 >> 3) & 0x01;
  115. /*
  116. * Get the Type Specific Flags (Byte5)
  117. */
  118. buffer += 1;
  119. temp8 = *buffer;
  120. if (ACPI_MEMORY_RANGE == output_struct->data.address16.resource_type) {
  121. output_struct->data.address16.attribute.memory.read_write_attribute =
  122. (u16) (temp8 & 0x01);
  123. output_struct->data.address16.attribute.memory.cache_attribute =
  124. (u16) ((temp8 >> 1) & 0x03);
  125. }
  126. else {
  127. if (ACPI_IO_RANGE == output_struct->data.address16.resource_type) {
  128. output_struct->data.address16.attribute.io.range_attribute =
  129. (u16) (temp8 & 0x03);
  130. output_struct->data.address16.attribute.io.translation_attribute =
  131. (u16) ((temp8 >> 4) & 0x03);
  132. }
  133. else {
  134. /* BUS_NUMBER_RANGE == Address16.Data->resource_type */
  135. /* Nothing needs to be filled in */
  136. }
  137. }
  138. /*
  139. * Get Granularity (Bytes 6-7)
  140. */
  141. buffer += 1;
  142. ACPI_MOVE_16_TO_32 (&output_struct->data.address16.granularity, buffer);
  143. /*
  144. * Get min_address_range (Bytes 8-9)
  145. */
  146. buffer += 2;
  147. ACPI_MOVE_16_TO_32 (&output_struct->data.address16.min_address_range, buffer);
  148. /*
  149. * Get max_address_range (Bytes 10-11)
  150. */
  151. buffer += 2;
  152. ACPI_MOVE_16_TO_32 (&output_struct->data.address16.max_address_range, buffer);
  153. /*
  154. * Get address_translation_offset (Bytes 12-13)
  155. */
  156. buffer += 2;
  157. ACPI_MOVE_16_TO_32 (&output_struct->data.address16.address_translation_offset, buffer);
  158. /*
  159. * Get address_length (Bytes 14-15)
  160. */
  161. buffer += 2;
  162. ACPI_MOVE_16_TO_32 (&output_struct->data.address16.address_length, buffer);
  163. /*
  164. * Resource Source Index (if present)
  165. */
  166. buffer += 2;
  167. /*
  168. * This will leave us pointing to the Resource Source Index
  169. * If it is present, then save it off and calculate the
  170. * pointer to where the null terminated string goes:
  171. * Each Interrupt takes 32-bits + the 5 bytes of the
  172. * stream that are default.
  173. *
  174. * Note: Some resource descriptors will have an additional null, so
  175. * we add 1 to the length.
  176. */
  177. if (*bytes_consumed > (16 + 1)) {
  178. /* Dereference the Index */
  179. temp8 = *buffer;
  180. output_struct->data.address16.resource_source.index = (u32) temp8;
  181. /* Point to the String */
  182. buffer += 1;
  183. /* Point the String pointer to the end of this structure */
  184. output_struct->data.address16.resource_source.string_ptr =
  185. (char *)((u8 * )output_struct + struct_size);
  186. temp_ptr = (u8 *) output_struct->data.address16.resource_source.string_ptr;
  187. /* Copy the string into the buffer */
  188. index = 0;
  189. while (0x00 != *buffer) {
  190. *temp_ptr = *buffer;
  191. temp_ptr += 1;
  192. buffer += 1;
  193. index += 1;
  194. }
  195. /*
  196. * Add the terminating null
  197. */
  198. *temp_ptr = 0x00;
  199. output_struct->data.address16.resource_source.string_length = index + 1;
  200. /*
  201. * In order for the struct_size to fall on a 32-bit boundary,
  202. * calculate the length of the string and expand the
  203. * struct_size to the next 32-bit boundary.
  204. */
  205. temp8 = (u8) (index + 1);
  206. struct_size += ACPI_ROUND_UP_to_32_bITS (temp8);
  207. }
  208. else {
  209. output_struct->data.address16.resource_source.index = 0x00;
  210. output_struct->data.address16.resource_source.string_length = 0;
  211. output_struct->data.address16.resource_source.string_ptr = NULL;
  212. }
  213. /*
  214. * Set the Length parameter
  215. */
  216. output_struct->length = (u32) struct_size;
  217. /*
  218. * Return the final size of the structure
  219. */
  220. *structure_size = struct_size;
  221. return_ACPI_STATUS (AE_OK);
  222. }
  223. /*******************************************************************************
  224. *
  225. * FUNCTION: acpi_rs_address16_stream
  226. *
  227. * PARAMETERS: linked_list - Pointer to the resource linked list
  228. * output_buffer - Pointer to the user's return buffer
  229. * bytes_consumed - Pointer to where the number of bytes
  230. * used in the output_buffer is returned
  231. *
  232. * RETURN: Status
  233. *
  234. * DESCRIPTION: Take the linked list resource structure and fills in the
  235. * the appropriate bytes in a byte stream
  236. *
  237. ******************************************************************************/
  238. acpi_status
  239. acpi_rs_address16_stream (
  240. struct acpi_resource *linked_list,
  241. u8 **output_buffer,
  242. acpi_size *bytes_consumed)
  243. {
  244. u8 *buffer = *output_buffer;
  245. u8 *length_field;
  246. u8 temp8;
  247. char *temp_pointer = NULL;
  248. acpi_size actual_bytes;
  249. ACPI_FUNCTION_TRACE ("rs_address16_stream");
  250. /*
  251. * The descriptor field is static
  252. */
  253. *buffer = 0x88;
  254. buffer += 1;
  255. /*
  256. * Save a pointer to the Length field - to be filled in later
  257. */
  258. length_field = buffer;
  259. buffer += 2;
  260. /*
  261. * Set the Resource Type (Memory, Io, bus_number)
  262. */
  263. temp8 = (u8) (linked_list->data.address16.resource_type & 0x03);
  264. *buffer = temp8;
  265. buffer += 1;
  266. /*
  267. * Set the general flags
  268. */
  269. temp8 = (u8) (linked_list->data.address16.producer_consumer & 0x01);
  270. temp8 |= (linked_list->data.address16.decode & 0x01) << 1;
  271. temp8 |= (linked_list->data.address16.min_address_fixed & 0x01) << 2;
  272. temp8 |= (linked_list->data.address16.max_address_fixed & 0x01) << 3;
  273. *buffer = temp8;
  274. buffer += 1;
  275. /*
  276. * Set the type specific flags
  277. */
  278. temp8 = 0;
  279. if (ACPI_MEMORY_RANGE == linked_list->data.address16.resource_type) {
  280. temp8 = (u8)
  281. (linked_list->data.address16.attribute.memory.read_write_attribute &
  282. 0x01);
  283. temp8 |=
  284. (linked_list->data.address16.attribute.memory.cache_attribute &
  285. 0x03) << 1;
  286. }
  287. else if (ACPI_IO_RANGE == linked_list->data.address16.resource_type) {
  288. temp8 = (u8)
  289. (linked_list->data.address16.attribute.io.range_attribute &
  290. 0x03);
  291. temp8 |=
  292. (linked_list->data.address16.attribute.io.translation_attribute &
  293. 0x03) << 4;
  294. }
  295. *buffer = temp8;
  296. buffer += 1;
  297. /*
  298. * Set the address space granularity
  299. */
  300. ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.granularity);
  301. buffer += 2;
  302. /*
  303. * Set the address range minimum
  304. */
  305. ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.min_address_range);
  306. buffer += 2;
  307. /*
  308. * Set the address range maximum
  309. */
  310. ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.max_address_range);
  311. buffer += 2;
  312. /*
  313. * Set the address translation offset
  314. */
  315. ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.address_translation_offset);
  316. buffer += 2;
  317. /*
  318. * Set the address length
  319. */
  320. ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.address_length);
  321. buffer += 2;
  322. /*
  323. * Resource Source Index and Resource Source are optional
  324. */
  325. if (0 != linked_list->data.address16.resource_source.string_length) {
  326. temp8 = (u8) linked_list->data.address16.resource_source.index;
  327. *buffer = temp8;
  328. buffer += 1;
  329. temp_pointer = (char *) buffer;
  330. /*
  331. * Copy the string
  332. */
  333. ACPI_STRCPY (temp_pointer,
  334. linked_list->data.address16.resource_source.string_ptr);
  335. /*
  336. * Buffer needs to be set to the length of the sting + one for the
  337. * terminating null
  338. */
  339. buffer += (acpi_size)(ACPI_STRLEN (linked_list->data.address16.resource_source.string_ptr) + 1);
  340. }
  341. /*
  342. * Return the number of bytes consumed in this operation
  343. */
  344. actual_bytes = ACPI_PTR_DIFF (buffer, *output_buffer);
  345. *bytes_consumed = actual_bytes;
  346. /*
  347. * Set the length field to the number of bytes consumed
  348. * minus the header size (3 bytes)
  349. */
  350. actual_bytes -= 3;
  351. ACPI_MOVE_SIZE_TO_16 (length_field, &actual_bytes);
  352. return_ACPI_STATUS (AE_OK);
  353. }
  354. /*******************************************************************************
  355. *
  356. * FUNCTION: acpi_rs_address32_resource
  357. *
  358. * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
  359. * stream
  360. * bytes_consumed - Pointer to where the number of bytes
  361. * consumed the byte_stream_buffer is
  362. * returned
  363. * output_buffer - Pointer to the return data buffer
  364. * structure_size - Pointer to where the number of bytes
  365. * in the return data struct is returned
  366. *
  367. * RETURN: Status
  368. *
  369. * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  370. * structure pointed to by the output_buffer. Return the
  371. * number of bytes consumed from the byte stream.
  372. *
  373. ******************************************************************************/
  374. acpi_status
  375. acpi_rs_address32_resource (
  376. u8 *byte_stream_buffer,
  377. acpi_size *bytes_consumed,
  378. u8 **output_buffer,
  379. acpi_size *structure_size)
  380. {
  381. u8 *buffer;
  382. struct acpi_resource *output_struct= (void *) *output_buffer;
  383. u16 temp16;
  384. u8 temp8;
  385. u8 *temp_ptr;
  386. acpi_size struct_size;
  387. u32 index;
  388. ACPI_FUNCTION_TRACE ("rs_address32_resource");
  389. buffer = byte_stream_buffer;
  390. struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address32);
  391. /*
  392. * Point past the Descriptor to get the number of bytes consumed
  393. */
  394. buffer += 1;
  395. ACPI_MOVE_16_TO_16 (&temp16, buffer);
  396. /* Validate minimum descriptor length */
  397. if (temp16 < 23) {
  398. return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
  399. }
  400. *bytes_consumed = temp16 + 3;
  401. output_struct->id = ACPI_RSTYPE_ADDRESS32;
  402. /*
  403. * Get the Resource Type (Byte3)
  404. */
  405. buffer += 2;
  406. temp8 = *buffer;
  407. /* Values 0-2 and 0xC0-0xFF are valid */
  408. if ((temp8 > 2) && (temp8 < 0xC0)) {
  409. return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
  410. }
  411. output_struct->data.address32.resource_type = temp8;
  412. /*
  413. * Get the General Flags (Byte4)
  414. */
  415. buffer += 1;
  416. temp8 = *buffer;
  417. /*
  418. * Producer / Consumer
  419. */
  420. output_struct->data.address32.producer_consumer = temp8 & 0x01;
  421. /*
  422. * Decode
  423. */
  424. output_struct->data.address32.decode = (temp8 >> 1) & 0x01;
  425. /*
  426. * Min Address Fixed
  427. */
  428. output_struct->data.address32.min_address_fixed = (temp8 >> 2) & 0x01;
  429. /*
  430. * Max Address Fixed
  431. */
  432. output_struct->data.address32.max_address_fixed = (temp8 >> 3) & 0x01;
  433. /*
  434. * Get the Type Specific Flags (Byte5)
  435. */
  436. buffer += 1;
  437. temp8 = *buffer;
  438. if (ACPI_MEMORY_RANGE == output_struct->data.address32.resource_type) {
  439. output_struct->data.address32.attribute.memory.read_write_attribute =
  440. (u16) (temp8 & 0x01);
  441. output_struct->data.address32.attribute.memory.cache_attribute =
  442. (u16) ((temp8 >> 1) & 0x03);
  443. }
  444. else {
  445. if (ACPI_IO_RANGE == output_struct->data.address32.resource_type) {
  446. output_struct->data.address32.attribute.io.range_attribute =
  447. (u16) (temp8 & 0x03);
  448. output_struct->data.address32.attribute.io.translation_attribute =
  449. (u16) ((temp8 >> 4) & 0x03);
  450. }
  451. else {
  452. /* BUS_NUMBER_RANGE == output_struct->Data.Address32.resource_type */
  453. /* Nothing needs to be filled in */
  454. }
  455. }
  456. /*
  457. * Get Granularity (Bytes 6-9)
  458. */
  459. buffer += 1;
  460. ACPI_MOVE_32_TO_32 (&output_struct->data.address32.granularity, buffer);
  461. /*
  462. * Get min_address_range (Bytes 10-13)
  463. */
  464. buffer += 4;
  465. ACPI_MOVE_32_TO_32 (&output_struct->data.address32.min_address_range, buffer);
  466. /*
  467. * Get max_address_range (Bytes 14-17)
  468. */
  469. buffer += 4;
  470. ACPI_MOVE_32_TO_32 (&output_struct->data.address32.max_address_range, buffer);
  471. /*
  472. * Get address_translation_offset (Bytes 18-21)
  473. */
  474. buffer += 4;
  475. ACPI_MOVE_32_TO_32 (&output_struct->data.address32.address_translation_offset, buffer);
  476. /*
  477. * Get address_length (Bytes 22-25)
  478. */
  479. buffer += 4;
  480. ACPI_MOVE_32_TO_32 (&output_struct->data.address32.address_length, buffer);
  481. /*
  482. * Resource Source Index (if present)
  483. */
  484. buffer += 4;
  485. /*
  486. * This will leave us pointing to the Resource Source Index
  487. * If it is present, then save it off and calculate the
  488. * pointer to where the null terminated string goes:
  489. *
  490. * Note: Some resource descriptors will have an additional null, so
  491. * we add 1 to the length.
  492. */
  493. if (*bytes_consumed > (26 + 1)) {
  494. /* Dereference the Index */
  495. temp8 = *buffer;
  496. output_struct->data.address32.resource_source.index =
  497. (u32) temp8;
  498. /* Point to the String */
  499. buffer += 1;
  500. /* Point the String pointer to the end of this structure */
  501. output_struct->data.address32.resource_source.string_ptr =
  502. (char *)((u8 *)output_struct + struct_size);
  503. temp_ptr = (u8 *) output_struct->data.address32.resource_source.string_ptr;
  504. /* Copy the string into the buffer */
  505. index = 0;
  506. while (0x00 != *buffer) {
  507. *temp_ptr = *buffer;
  508. temp_ptr += 1;
  509. buffer += 1;
  510. index += 1;
  511. }
  512. /*
  513. * Add the terminating null
  514. */
  515. *temp_ptr = 0x00;
  516. output_struct->data.address32.resource_source.string_length = index + 1;
  517. /*
  518. * In order for the struct_size to fall on a 32-bit boundary,
  519. * calculate the length of the string and expand the
  520. * struct_size to the next 32-bit boundary.
  521. */
  522. temp8 = (u8) (index + 1);
  523. struct_size += ACPI_ROUND_UP_to_32_bITS (temp8);
  524. }
  525. else {
  526. output_struct->data.address32.resource_source.index = 0x00;
  527. output_struct->data.address32.resource_source.string_length = 0;
  528. output_struct->data.address32.resource_source.string_ptr = NULL;
  529. }
  530. /*
  531. * Set the Length parameter
  532. */
  533. output_struct->length = (u32) struct_size;
  534. /*
  535. * Return the final size of the structure
  536. */
  537. *structure_size = struct_size;
  538. return_ACPI_STATUS (AE_OK);
  539. }
  540. /*******************************************************************************
  541. *
  542. * FUNCTION: acpi_rs_address32_stream
  543. *
  544. * PARAMETERS: linked_list - Pointer to the resource linked list
  545. * output_buffer - Pointer to the user's return buffer
  546. * bytes_consumed - Pointer to where the number of bytes
  547. * used in the output_buffer is returned
  548. *
  549. * RETURN: Status
  550. *
  551. * DESCRIPTION: Take the linked list resource structure and fills in the
  552. * the appropriate bytes in a byte stream
  553. *
  554. ******************************************************************************/
  555. acpi_status
  556. acpi_rs_address32_stream (
  557. struct acpi_resource *linked_list,
  558. u8 **output_buffer,
  559. acpi_size *bytes_consumed)
  560. {
  561. u8 *buffer;
  562. u16 *length_field;
  563. u8 temp8;
  564. char *temp_pointer;
  565. ACPI_FUNCTION_TRACE ("rs_address32_stream");
  566. buffer = *output_buffer;
  567. /*
  568. * The descriptor field is static
  569. */
  570. *buffer = 0x87;
  571. buffer += 1;
  572. /*
  573. * Set a pointer to the Length field - to be filled in later
  574. */
  575. length_field = ACPI_CAST_PTR (u16, buffer);
  576. buffer += 2;
  577. /*
  578. * Set the Resource Type (Memory, Io, bus_number)
  579. */
  580. temp8 = (u8) (linked_list->data.address32.resource_type & 0x03);
  581. *buffer = temp8;
  582. buffer += 1;
  583. /*
  584. * Set the general flags
  585. */
  586. temp8 = (u8) (linked_list->data.address32.producer_consumer & 0x01);
  587. temp8 |= (linked_list->data.address32.decode & 0x01) << 1;
  588. temp8 |= (linked_list->data.address32.min_address_fixed & 0x01) << 2;
  589. temp8 |= (linked_list->data.address32.max_address_fixed & 0x01) << 3;
  590. *buffer = temp8;
  591. buffer += 1;
  592. /*
  593. * Set the type specific flags
  594. */
  595. temp8 = 0;
  596. if (ACPI_MEMORY_RANGE == linked_list->data.address32.resource_type) {
  597. temp8 = (u8)
  598. (linked_list->data.address32.attribute.memory.read_write_attribute &
  599. 0x01);
  600. temp8 |=
  601. (linked_list->data.address32.attribute.memory.cache_attribute &
  602. 0x03) << 1;
  603. }
  604. else if (ACPI_IO_RANGE == linked_list->data.address32.resource_type) {
  605. temp8 = (u8)
  606. (linked_list->data.address32.attribute.io.range_attribute &
  607. 0x03);
  608. temp8 |=
  609. (linked_list->data.address32.attribute.io.translation_attribute &
  610. 0x03) << 4;
  611. }
  612. *buffer = temp8;
  613. buffer += 1;
  614. /*
  615. * Set the address space granularity
  616. */
  617. ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.granularity);
  618. buffer += 4;
  619. /*
  620. * Set the address range minimum
  621. */
  622. ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.min_address_range);
  623. buffer += 4;
  624. /*
  625. * Set the address range maximum
  626. */
  627. ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.max_address_range);
  628. buffer += 4;
  629. /*
  630. * Set the address translation offset
  631. */
  632. ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.address_translation_offset);
  633. buffer += 4;
  634. /*
  635. * Set the address length
  636. */
  637. ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.address_length);
  638. buffer += 4;
  639. /*
  640. * Resource Source Index and Resource Source are optional
  641. */
  642. if (0 != linked_list->data.address32.resource_source.string_length) {
  643. temp8 = (u8) linked_list->data.address32.resource_source.index;
  644. *buffer = temp8;
  645. buffer += 1;
  646. temp_pointer = (char *) buffer;
  647. /*
  648. * Copy the string
  649. */
  650. ACPI_STRCPY (temp_pointer,
  651. linked_list->data.address32.resource_source.string_ptr);
  652. /*
  653. * Buffer needs to be set to the length of the sting + one for the
  654. * terminating null
  655. */
  656. buffer += (acpi_size)(ACPI_STRLEN (linked_list->data.address32.resource_source.string_ptr) + 1);
  657. }
  658. /*
  659. * Return the number of bytes consumed in this operation
  660. */
  661. *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
  662. /*
  663. * Set the length field to the number of bytes consumed
  664. * minus the header size (3 bytes)
  665. */
  666. *length_field = (u16) (*bytes_consumed - 3);
  667. return_ACPI_STATUS (AE_OK);
  668. }
  669. /*******************************************************************************
  670. *
  671. * FUNCTION: acpi_rs_address64_resource
  672. *
  673. * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
  674. * stream
  675. * bytes_consumed - Pointer to where the number of bytes
  676. * consumed the byte_stream_buffer is
  677. * returned
  678. * output_buffer - Pointer to the return data buffer
  679. * structure_size - Pointer to where the number of bytes
  680. * in the return data struct is returned
  681. *
  682. * RETURN: Status
  683. *
  684. * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  685. * structure pointed to by the output_buffer. Return the
  686. * number of bytes consumed from the byte stream.
  687. *
  688. ******************************************************************************/
  689. acpi_status
  690. acpi_rs_address64_resource (
  691. u8 *byte_stream_buffer,
  692. acpi_size *bytes_consumed,
  693. u8 **output_buffer,
  694. acpi_size *structure_size)
  695. {
  696. u8 *buffer;
  697. struct acpi_resource *output_struct = (void *) *output_buffer;
  698. u16 temp16;
  699. u8 temp8;
  700. u8 resource_type;
  701. u8 *temp_ptr;
  702. acpi_size struct_size;
  703. u32 index;
  704. ACPI_FUNCTION_TRACE ("rs_address64_resource");
  705. buffer = byte_stream_buffer;
  706. struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address64);
  707. resource_type = *buffer;
  708. /*
  709. * Point past the Descriptor to get the number of bytes consumed
  710. */
  711. buffer += 1;
  712. ACPI_MOVE_16_TO_16 (&temp16, buffer);
  713. /* Validate minimum descriptor length */
  714. if (temp16 < 43) {
  715. return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
  716. }
  717. *bytes_consumed = temp16 + 3;
  718. output_struct->id = ACPI_RSTYPE_ADDRESS64;
  719. /*
  720. * Get the Resource Type (Byte3)
  721. */
  722. buffer += 2;
  723. temp8 = *buffer;
  724. /* Values 0-2 and 0xC0-0xFF are valid */
  725. if ((temp8 > 2) && (temp8 < 0xC0)) {
  726. return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
  727. }
  728. output_struct->data.address64.resource_type = temp8;
  729. /*
  730. * Get the General Flags (Byte4)
  731. */
  732. buffer += 1;
  733. temp8 = *buffer;
  734. /*
  735. * Producer / Consumer
  736. */
  737. output_struct->data.address64.producer_consumer = temp8 & 0x01;
  738. /*
  739. * Decode
  740. */
  741. output_struct->data.address64.decode = (temp8 >> 1) & 0x01;
  742. /*
  743. * Min Address Fixed
  744. */
  745. output_struct->data.address64.min_address_fixed = (temp8 >> 2) & 0x01;
  746. /*
  747. * Max Address Fixed
  748. */
  749. output_struct->data.address64.max_address_fixed = (temp8 >> 3) & 0x01;
  750. /*
  751. * Get the Type Specific Flags (Byte5)
  752. */
  753. buffer += 1;
  754. temp8 = *buffer;
  755. if (ACPI_MEMORY_RANGE == output_struct->data.address64.resource_type) {
  756. output_struct->data.address64.attribute.memory.read_write_attribute =
  757. (u16) (temp8 & 0x01);
  758. output_struct->data.address64.attribute.memory.cache_attribute =
  759. (u16) ((temp8 >> 1) & 0x03);
  760. }
  761. else {
  762. if (ACPI_IO_RANGE == output_struct->data.address64.resource_type) {
  763. output_struct->data.address64.attribute.io.range_attribute =
  764. (u16) (temp8 & 0x03);
  765. output_struct->data.address64.attribute.io.translation_attribute =
  766. (u16) ((temp8 >> 4) & 0x03);
  767. }
  768. else {
  769. /* BUS_NUMBER_RANGE == output_struct->Data.Address64.resource_type */
  770. /* Nothing needs to be filled in */
  771. }
  772. }
  773. if (resource_type == ACPI_RDESC_TYPE_EXTENDED_ADDRESS_SPACE) {
  774. /* Move past revision_id and Reserved byte */
  775. buffer += 2;
  776. }
  777. /*
  778. * Get Granularity (Bytes 6-13) or (Bytes 8-15)
  779. */
  780. buffer += 1;
  781. ACPI_MOVE_64_TO_64 (&output_struct->data.address64.granularity, buffer);
  782. /*
  783. * Get min_address_range (Bytes 14-21) or (Bytes 16-23)
  784. */
  785. buffer += 8;
  786. ACPI_MOVE_64_TO_64 (&output_struct->data.address64.min_address_range, buffer);
  787. /*
  788. * Get max_address_range (Bytes 22-29) or (Bytes 24-31)
  789. */
  790. buffer += 8;
  791. ACPI_MOVE_64_TO_64 (&output_struct->data.address64.max_address_range, buffer);
  792. /*
  793. * Get address_translation_offset (Bytes 30-37) or (Bytes 32-39)
  794. */
  795. buffer += 8;
  796. ACPI_MOVE_64_TO_64 (&output_struct->data.address64.address_translation_offset, buffer);
  797. /*
  798. * Get address_length (Bytes 38-45) or (Bytes 40-47)
  799. */
  800. buffer += 8;
  801. ACPI_MOVE_64_TO_64 (&output_struct->data.address64.address_length, buffer);
  802. output_struct->data.address64.resource_source.index = 0x00;
  803. output_struct->data.address64.resource_source.string_length = 0;
  804. output_struct->data.address64.resource_source.string_ptr = NULL;
  805. if (resource_type == ACPI_RDESC_TYPE_EXTENDED_ADDRESS_SPACE) {
  806. /* Get type_specific_attribute (Bytes 48-55) */
  807. buffer += 8;
  808. ACPI_MOVE_64_TO_64 (&output_struct->data.address64.type_specific_attributes, buffer);
  809. }
  810. else {
  811. output_struct->data.address64.type_specific_attributes = 0;
  812. /*
  813. * Resource Source Index (if present)
  814. */
  815. buffer += 8;
  816. /*
  817. * This will leave us pointing to the Resource Source Index
  818. * If it is present, then save it off and calculate the
  819. * pointer to where the null terminated string goes:
  820. * Each Interrupt takes 32-bits + the 5 bytes of the
  821. * stream that are default.
  822. *
  823. * Note: Some resource descriptors will have an additional null, so
  824. * we add 1 to the length.
  825. */
  826. if (*bytes_consumed > (46 + 1)) {
  827. /* Dereference the Index */
  828. temp8 = *buffer;
  829. output_struct->data.address64.resource_source.index =
  830. (u32) temp8;
  831. /* Point to the String */
  832. buffer += 1;
  833. /* Point the String pointer to the end of this structure */
  834. output_struct->data.address64.resource_source.string_ptr =
  835. (char *)((u8 *)output_struct + struct_size);
  836. temp_ptr = (u8 *) output_struct->data.address64.resource_source.string_ptr;
  837. /* Copy the string into the buffer */
  838. index = 0;
  839. while (0x00 != *buffer) {
  840. *temp_ptr = *buffer;
  841. temp_ptr += 1;
  842. buffer += 1;
  843. index += 1;
  844. }
  845. /*
  846. * Add the terminating null
  847. */
  848. *temp_ptr = 0x00;
  849. output_struct->data.address64.resource_source.string_length = index + 1;
  850. /*
  851. * In order for the struct_size to fall on a 32-bit boundary,
  852. * calculate the length of the string and expand the
  853. * struct_size to the next 32-bit boundary.
  854. */
  855. temp8 = (u8) (index + 1);
  856. struct_size += ACPI_ROUND_UP_to_32_bITS (temp8);
  857. }
  858. }
  859. /*
  860. * Set the Length parameter
  861. */
  862. output_struct->length = (u32) struct_size;
  863. /*
  864. * Return the final size of the structure
  865. */
  866. *structure_size = struct_size;
  867. return_ACPI_STATUS (AE_OK);
  868. }
  869. /*******************************************************************************
  870. *
  871. * FUNCTION: acpi_rs_address64_stream
  872. *
  873. * PARAMETERS: linked_list - Pointer to the resource linked list
  874. * output_buffer - Pointer to the user's return buffer
  875. * bytes_consumed - Pointer to where the number of bytes
  876. * used in the output_buffer is returned
  877. *
  878. * RETURN: Status
  879. *
  880. * DESCRIPTION: Take the linked list resource structure and fills in the
  881. * the appropriate bytes in a byte stream
  882. *
  883. ******************************************************************************/
  884. acpi_status
  885. acpi_rs_address64_stream (
  886. struct acpi_resource *linked_list,
  887. u8 **output_buffer,
  888. acpi_size *bytes_consumed)
  889. {
  890. u8 *buffer;
  891. u16 *length_field;
  892. u8 temp8;
  893. char *temp_pointer;
  894. ACPI_FUNCTION_TRACE ("rs_address64_stream");
  895. buffer = *output_buffer;
  896. /*
  897. * The descriptor field is static
  898. */
  899. *buffer = 0x8A;
  900. buffer += 1;
  901. /*
  902. * Set a pointer to the Length field - to be filled in later
  903. */
  904. length_field = ACPI_CAST_PTR (u16, buffer);
  905. buffer += 2;
  906. /*
  907. * Set the Resource Type (Memory, Io, bus_number)
  908. */
  909. temp8 = (u8) (linked_list->data.address64.resource_type & 0x03);
  910. *buffer = temp8;
  911. buffer += 1;
  912. /*
  913. * Set the general flags
  914. */
  915. temp8 = (u8) (linked_list->data.address64.producer_consumer & 0x01);
  916. temp8 |= (linked_list->data.address64.decode & 0x01) << 1;
  917. temp8 |= (linked_list->data.address64.min_address_fixed & 0x01) << 2;
  918. temp8 |= (linked_list->data.address64.max_address_fixed & 0x01) << 3;
  919. *buffer = temp8;
  920. buffer += 1;
  921. /*
  922. * Set the type specific flags
  923. */
  924. temp8 = 0;
  925. if (ACPI_MEMORY_RANGE == linked_list->data.address64.resource_type) {
  926. temp8 = (u8)
  927. (linked_list->data.address64.attribute.memory.read_write_attribute &
  928. 0x01);
  929. temp8 |=
  930. (linked_list->data.address64.attribute.memory.cache_attribute &
  931. 0x03) << 1;
  932. }
  933. else if (ACPI_IO_RANGE == linked_list->data.address64.resource_type) {
  934. temp8 = (u8)
  935. (linked_list->data.address64.attribute.io.range_attribute &
  936. 0x03);
  937. temp8 |=
  938. (linked_list->data.address64.attribute.io.range_attribute &
  939. 0x03) << 4;
  940. }
  941. *buffer = temp8;
  942. buffer += 1;
  943. /*
  944. * Set the address space granularity
  945. */
  946. ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.granularity);
  947. buffer += 8;
  948. /*
  949. * Set the address range minimum
  950. */
  951. ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.min_address_range);
  952. buffer += 8;
  953. /*
  954. * Set the address range maximum
  955. */
  956. ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.max_address_range);
  957. buffer += 8;
  958. /*
  959. * Set the address translation offset
  960. */
  961. ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.address_translation_offset);
  962. buffer += 8;
  963. /*
  964. * Set the address length
  965. */
  966. ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.address_length);
  967. buffer += 8;
  968. /*
  969. * Resource Source Index and Resource Source are optional
  970. */
  971. if (0 != linked_list->data.address64.resource_source.string_length) {
  972. temp8 = (u8) linked_list->data.address64.resource_source.index;
  973. *buffer = temp8;
  974. buffer += 1;
  975. temp_pointer = (char *) buffer;
  976. /*
  977. * Copy the string
  978. */
  979. ACPI_STRCPY (temp_pointer, linked_list->data.address64.resource_source.string_ptr);
  980. /*
  981. * Buffer needs to be set to the length of the sting + one for the
  982. * terminating null
  983. */
  984. buffer += (acpi_size)(ACPI_STRLEN (linked_list->data.address64.resource_source.string_ptr) + 1);
  985. }
  986. /*
  987. * Return the number of bytes consumed in this operation
  988. */
  989. *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
  990. /*
  991. * Set the length field to the number of bytes consumed
  992. * minus the header size (3 bytes)
  993. */
  994. *length_field = (u16) (*bytes_consumed - 3);
  995. return_ACPI_STATUS (AE_OK);
  996. }