rsaddr.c 31 KB

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