rsaddr.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  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->id = 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: linked_list - 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 *linked_list,
  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) (linked_list->data.address16.resource_type & 0x03);
  334. buffer += 1;
  335. /* Set the general flags */
  336. *buffer = acpi_rs_encode_general_flags(&linked_list->data);
  337. buffer += 1;
  338. /* Set the type specific flags */
  339. *buffer = acpi_rs_encode_specific_flags(&linked_list->data);
  340. buffer += 1;
  341. /* Set the address space granularity */
  342. ACPI_MOVE_32_TO_16(buffer, &linked_list->data.address16.granularity);
  343. buffer += 2;
  344. /* Set the address range minimum */
  345. ACPI_MOVE_32_TO_16(buffer,
  346. &linked_list->data.address16.min_address_range);
  347. buffer += 2;
  348. /* Set the address range maximum */
  349. ACPI_MOVE_32_TO_16(buffer,
  350. &linked_list->data.address16.max_address_range);
  351. buffer += 2;
  352. /* Set the address translation offset */
  353. ACPI_MOVE_32_TO_16(buffer,
  354. &linked_list->data.address16.
  355. address_translation_offset);
  356. buffer += 2;
  357. /* Set the address length */
  358. ACPI_MOVE_32_TO_16(buffer, &linked_list->data.address16.address_length);
  359. buffer += 2;
  360. /* Resource Source Index and Resource Source are optional */
  361. if (linked_list->data.address16.resource_source.string_length) {
  362. *buffer =
  363. (u8) linked_list->data.address16.resource_source.index;
  364. buffer += 1;
  365. /* Copy the resource_source string */
  366. ACPI_STRCPY((char *)buffer,
  367. linked_list->data.address16.resource_source.
  368. string_ptr);
  369. /*
  370. * Buffer needs to be set to the length of the string + one for the
  371. * terminating null
  372. */
  373. buffer +=
  374. (acpi_size) (ACPI_STRLEN
  375. (linked_list->data.address16.resource_source.
  376. string_ptr) + 1);
  377. }
  378. /* Return the number of bytes consumed in this operation */
  379. actual_bytes = ACPI_PTR_DIFF(buffer, *output_buffer);
  380. *bytes_consumed = actual_bytes;
  381. /*
  382. * Set the length field to the number of bytes consumed
  383. * minus the header size (3 bytes)
  384. */
  385. actual_bytes -= 3;
  386. ACPI_MOVE_SIZE_TO_16(length_field, &actual_bytes);
  387. return_ACPI_STATUS(AE_OK);
  388. }
  389. /*******************************************************************************
  390. *
  391. * FUNCTION: acpi_rs_address32_resource
  392. *
  393. * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
  394. * stream
  395. * bytes_consumed - Pointer to where the number of bytes
  396. * consumed the byte_stream_buffer is
  397. * returned
  398. * output_buffer - Pointer to the return data buffer
  399. * structure_size - Pointer to where the number of bytes
  400. * in the return data struct is returned
  401. *
  402. * RETURN: Status
  403. *
  404. * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  405. * structure pointed to by the output_buffer. Return the
  406. * number of bytes consumed from the byte stream.
  407. *
  408. ******************************************************************************/
  409. acpi_status
  410. acpi_rs_address32_resource(u8 * byte_stream_buffer,
  411. acpi_size * bytes_consumed,
  412. u8 ** output_buffer, acpi_size * structure_size)
  413. {
  414. u16 temp16;
  415. u8 temp8;
  416. u8 *temp_ptr;
  417. u32 index;
  418. u8 *buffer = byte_stream_buffer;
  419. struct acpi_resource *output_struct = (void *)*output_buffer;
  420. acpi_size struct_size =
  421. ACPI_SIZEOF_RESOURCE(struct acpi_resource_address32);
  422. ACPI_FUNCTION_TRACE("rs_address32_resource");
  423. /* Get the Descriptor Length field */
  424. buffer += 1;
  425. ACPI_MOVE_16_TO_16(&temp16, buffer);
  426. /* Validate minimum descriptor length */
  427. if (temp16 < 23) {
  428. return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH);
  429. }
  430. *bytes_consumed = temp16 + 3;
  431. output_struct->id = ACPI_RSTYPE_ADDRESS32;
  432. /* Get the Resource Type (Byte3) */
  433. buffer += 2;
  434. temp8 = *buffer;
  435. /* Values 0-2 and 0xC0-0xFF are valid */
  436. if ((temp8 > 2) && (temp8 < 0xC0)) {
  437. return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
  438. }
  439. output_struct->data.address32.resource_type = temp8;
  440. /* Get the General Flags (Byte4) */
  441. buffer += 1;
  442. acpi_rs_decode_general_flags(&output_struct->data, *buffer);
  443. /* Get the Type Specific Flags (Byte5) */
  444. buffer += 1;
  445. acpi_rs_decode_specific_flags(&output_struct->data, *buffer);
  446. /* Get Granularity (Bytes 6-9) */
  447. buffer += 1;
  448. ACPI_MOVE_32_TO_32(&output_struct->data.address32.granularity, buffer);
  449. /* Get min_address_range (Bytes 10-13) */
  450. buffer += 4;
  451. ACPI_MOVE_32_TO_32(&output_struct->data.address32.min_address_range,
  452. buffer);
  453. /* Get max_address_range (Bytes 14-17) */
  454. buffer += 4;
  455. ACPI_MOVE_32_TO_32(&output_struct->data.address32.max_address_range,
  456. buffer);
  457. /* Get address_translation_offset (Bytes 18-21) */
  458. buffer += 4;
  459. ACPI_MOVE_32_TO_32(&output_struct->data.address32.
  460. address_translation_offset, buffer);
  461. /* Get address_length (Bytes 22-25) */
  462. buffer += 4;
  463. ACPI_MOVE_32_TO_32(&output_struct->data.address32.address_length,
  464. buffer);
  465. /* Resource Source Index (if present) */
  466. buffer += 4;
  467. /*
  468. * This will leave us pointing to the Resource Source Index
  469. * If it is present, then save it off and calculate the
  470. * pointer to where the null terminated string goes:
  471. *
  472. * Note: Some resource descriptors will have an additional null, so
  473. * we add 1 to the length.
  474. */
  475. if (*bytes_consumed > (26 + 1)) {
  476. /* Dereference the Index */
  477. output_struct->data.address32.resource_source.index =
  478. (u32) * buffer;
  479. /* Point to the String */
  480. buffer += 1;
  481. /* Point the String pointer to the end of this structure */
  482. output_struct->data.address32.resource_source.string_ptr =
  483. (char *)((u8 *) output_struct + struct_size);
  484. temp_ptr = (u8 *)
  485. output_struct->data.address32.resource_source.string_ptr;
  486. /* Copy the resource_source string into the buffer */
  487. index = 0;
  488. while (*buffer) {
  489. *temp_ptr = *buffer;
  490. temp_ptr++;
  491. buffer++;
  492. index++;
  493. }
  494. /* Add the terminating null and set the string length */
  495. *temp_ptr = 0;
  496. output_struct->data.address32.resource_source.string_length =
  497. index + 1;
  498. /*
  499. * In order for the struct_size to fall on a 32-bit boundary,
  500. * calculate the length of the string and expand the
  501. * struct_size to the next 32-bit boundary.
  502. */
  503. temp8 = (u8) (index + 1);
  504. struct_size += ACPI_ROUND_UP_to_32_bITS(temp8);
  505. } else {
  506. output_struct->data.address32.resource_source.index = 0;
  507. output_struct->data.address32.resource_source.string_length = 0;
  508. output_struct->data.address32.resource_source.string_ptr = NULL;
  509. }
  510. /* Set the Length parameter */
  511. output_struct->length = (u32) struct_size;
  512. /* Return the final size of the structure */
  513. *structure_size = struct_size;
  514. return_ACPI_STATUS(AE_OK);
  515. }
  516. /*******************************************************************************
  517. *
  518. * FUNCTION: acpi_rs_address32_stream
  519. *
  520. * PARAMETERS: linked_list - Pointer to the resource linked list
  521. * output_buffer - Pointer to the user's return buffer
  522. * bytes_consumed - Pointer to where the number of bytes
  523. * used in the output_buffer is returned
  524. *
  525. * RETURN: Status
  526. *
  527. * DESCRIPTION: Take the linked list resource structure and fills in the
  528. * the appropriate bytes in a byte stream
  529. *
  530. ******************************************************************************/
  531. acpi_status
  532. acpi_rs_address32_stream(struct acpi_resource *linked_list,
  533. u8 ** output_buffer, acpi_size * bytes_consumed)
  534. {
  535. u8 *buffer;
  536. u16 *length_field;
  537. ACPI_FUNCTION_TRACE("rs_address32_stream");
  538. buffer = *output_buffer;
  539. /* Set the Descriptor Type field */
  540. *buffer = ACPI_RDESC_TYPE_DWORD_ADDRESS_SPACE;
  541. buffer += 1;
  542. /* Save a pointer to the Length field - to be filled in later */
  543. length_field = ACPI_CAST_PTR(u16, buffer);
  544. buffer += 2;
  545. /* Set the Resource Type (Memory, Io, bus_number) */
  546. *buffer = (u8) (linked_list->data.address32.resource_type & 0x03);
  547. buffer += 1;
  548. /* Set the general flags */
  549. *buffer = acpi_rs_encode_general_flags(&linked_list->data);
  550. buffer += 1;
  551. /* Set the type specific flags */
  552. *buffer = acpi_rs_encode_specific_flags(&linked_list->data);
  553. buffer += 1;
  554. /* Set the address space granularity */
  555. ACPI_MOVE_32_TO_32(buffer, &linked_list->data.address32.granularity);
  556. buffer += 4;
  557. /* Set the address range minimum */
  558. ACPI_MOVE_32_TO_32(buffer,
  559. &linked_list->data.address32.min_address_range);
  560. buffer += 4;
  561. /* Set the address range maximum */
  562. ACPI_MOVE_32_TO_32(buffer,
  563. &linked_list->data.address32.max_address_range);
  564. buffer += 4;
  565. /* Set the address translation offset */
  566. ACPI_MOVE_32_TO_32(buffer,
  567. &linked_list->data.address32.
  568. address_translation_offset);
  569. buffer += 4;
  570. /* Set the address length */
  571. ACPI_MOVE_32_TO_32(buffer, &linked_list->data.address32.address_length);
  572. buffer += 4;
  573. /* Resource Source Index and Resource Source are optional */
  574. if (linked_list->data.address32.resource_source.string_length) {
  575. *buffer =
  576. (u8) linked_list->data.address32.resource_source.index;
  577. buffer += 1;
  578. /* Copy the resource_source string */
  579. ACPI_STRCPY((char *)buffer,
  580. linked_list->data.address32.resource_source.
  581. string_ptr);
  582. /*
  583. * Buffer needs to be set to the length of the string + one for the
  584. * terminating null
  585. */
  586. buffer +=
  587. (acpi_size) (ACPI_STRLEN
  588. (linked_list->data.address32.resource_source.
  589. string_ptr) + 1);
  590. }
  591. /* Return the number of bytes consumed in this operation */
  592. *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
  593. /*
  594. * Set the length field to the number of bytes consumed
  595. * minus the header size (3 bytes)
  596. */
  597. *length_field = (u16) (*bytes_consumed - 3);
  598. return_ACPI_STATUS(AE_OK);
  599. }
  600. /*******************************************************************************
  601. *
  602. * FUNCTION: acpi_rs_address64_resource
  603. *
  604. * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
  605. * stream
  606. * bytes_consumed - Pointer to where the number of bytes
  607. * consumed the byte_stream_buffer is
  608. * returned
  609. * output_buffer - Pointer to the return data buffer
  610. * structure_size - Pointer to where the number of bytes
  611. * in the return data struct is returned
  612. *
  613. * RETURN: Status
  614. *
  615. * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  616. * structure pointed to by the output_buffer. Return the
  617. * number of bytes consumed from the byte stream.
  618. *
  619. ******************************************************************************/
  620. acpi_status
  621. acpi_rs_address64_resource(u8 * byte_stream_buffer,
  622. acpi_size * bytes_consumed,
  623. u8 ** output_buffer, acpi_size * structure_size)
  624. {
  625. u16 temp16;
  626. u8 temp8;
  627. u8 resource_type;
  628. u8 *temp_ptr;
  629. u32 index;
  630. u8 *buffer = byte_stream_buffer;
  631. struct acpi_resource *output_struct = (void *)*output_buffer;
  632. acpi_size struct_size =
  633. ACPI_SIZEOF_RESOURCE(struct acpi_resource_address64);
  634. ACPI_FUNCTION_TRACE("rs_address64_resource");
  635. /* Get the Descriptor Type */
  636. resource_type = *buffer;
  637. /* Get the Descriptor Length field */
  638. buffer += 1;
  639. ACPI_MOVE_16_TO_16(&temp16, buffer);
  640. /* Validate minimum descriptor length */
  641. if (temp16 < 43) {
  642. return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH);
  643. }
  644. *bytes_consumed = temp16 + 3;
  645. output_struct->id = ACPI_RSTYPE_ADDRESS64;
  646. /* Get the Resource Type (Byte3) */
  647. buffer += 2;
  648. temp8 = *buffer;
  649. /* Values 0-2 and 0xC0-0xFF are valid */
  650. if ((temp8 > 2) && (temp8 < 0xC0)) {
  651. return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
  652. }
  653. output_struct->data.address64.resource_type = temp8;
  654. /* Get the General Flags (Byte4) */
  655. buffer += 1;
  656. acpi_rs_decode_general_flags(&output_struct->data, *buffer);
  657. /* Get the Type Specific Flags (Byte5) */
  658. buffer += 1;
  659. acpi_rs_decode_specific_flags(&output_struct->data, *buffer);
  660. if (resource_type == ACPI_RDESC_TYPE_EXTENDED_ADDRESS_SPACE) {
  661. /* Move past revision_id and Reserved byte */
  662. buffer += 2;
  663. }
  664. /* Get Granularity (Bytes 6-13) or (Bytes 8-15) */
  665. buffer += 1;
  666. ACPI_MOVE_64_TO_64(&output_struct->data.address64.granularity, buffer);
  667. /* Get min_address_range (Bytes 14-21) or (Bytes 16-23) */
  668. buffer += 8;
  669. ACPI_MOVE_64_TO_64(&output_struct->data.address64.min_address_range,
  670. buffer);
  671. /* Get max_address_range (Bytes 22-29) or (Bytes 24-31) */
  672. buffer += 8;
  673. ACPI_MOVE_64_TO_64(&output_struct->data.address64.max_address_range,
  674. buffer);
  675. /* Get address_translation_offset (Bytes 30-37) or (Bytes 32-39) */
  676. buffer += 8;
  677. ACPI_MOVE_64_TO_64(&output_struct->data.address64.
  678. address_translation_offset, buffer);
  679. /* Get address_length (Bytes 38-45) or (Bytes 40-47) */
  680. buffer += 8;
  681. ACPI_MOVE_64_TO_64(&output_struct->data.address64.address_length,
  682. buffer);
  683. output_struct->data.address64.resource_source.index = 0;
  684. output_struct->data.address64.resource_source.string_length = 0;
  685. output_struct->data.address64.resource_source.string_ptr = NULL;
  686. if (resource_type == ACPI_RDESC_TYPE_EXTENDED_ADDRESS_SPACE) {
  687. /* Get type_specific_attribute (Bytes 48-55) */
  688. buffer += 8;
  689. ACPI_MOVE_64_TO_64(&output_struct->data.address64.
  690. type_specific_attributes, buffer);
  691. } else {
  692. output_struct->data.address64.type_specific_attributes = 0;
  693. /* Resource Source Index (if present) */
  694. buffer += 8;
  695. /*
  696. * This will leave us pointing to the Resource Source Index
  697. * If it is present, then save it off and calculate the
  698. * pointer to where the null terminated string goes:
  699. * Each Interrupt takes 32-bits + the 5 bytes of the
  700. * stream that are default.
  701. *
  702. * Note: Some resource descriptors will have an additional null, so
  703. * we add 1 to the length.
  704. */
  705. if (*bytes_consumed > (46 + 1)) {
  706. /* Dereference the Index */
  707. output_struct->data.address64.resource_source.index =
  708. (u32) * buffer;
  709. /* Point to the String */
  710. buffer += 1;
  711. /* Point the String pointer to the end of this structure */
  712. output_struct->data.address64.resource_source.
  713. string_ptr =
  714. (char *)((u8 *) output_struct + struct_size);
  715. temp_ptr = (u8 *)
  716. output_struct->data.address64.resource_source.
  717. string_ptr;
  718. /* Copy the resource_source string into the buffer */
  719. index = 0;
  720. while (*buffer) {
  721. *temp_ptr = *buffer;
  722. temp_ptr++;
  723. buffer++;
  724. index++;
  725. }
  726. /*
  727. * Add the terminating null and set the string length
  728. */
  729. *temp_ptr = 0;
  730. output_struct->data.address64.resource_source.
  731. string_length = index + 1;
  732. /*
  733. * In order for the struct_size to fall on a 32-bit boundary,
  734. * calculate the length of the string and expand the
  735. * struct_size to the next 32-bit boundary.
  736. */
  737. temp8 = (u8) (index + 1);
  738. struct_size += ACPI_ROUND_UP_to_32_bITS(temp8);
  739. }
  740. }
  741. /* Set the Length parameter */
  742. output_struct->length = (u32) struct_size;
  743. /* Return the final size of the structure */
  744. *structure_size = struct_size;
  745. return_ACPI_STATUS(AE_OK);
  746. }
  747. /*******************************************************************************
  748. *
  749. * FUNCTION: acpi_rs_address64_stream
  750. *
  751. * PARAMETERS: linked_list - Pointer to the resource linked list
  752. * output_buffer - Pointer to the user's return buffer
  753. * bytes_consumed - Pointer to where the number of bytes
  754. * used in the output_buffer is returned
  755. *
  756. * RETURN: Status
  757. *
  758. * DESCRIPTION: Take the linked list resource structure and fills in the
  759. * the appropriate bytes in a byte stream
  760. *
  761. ******************************************************************************/
  762. acpi_status
  763. acpi_rs_address64_stream(struct acpi_resource *linked_list,
  764. u8 ** output_buffer, acpi_size * bytes_consumed)
  765. {
  766. u8 *buffer;
  767. u16 *length_field;
  768. ACPI_FUNCTION_TRACE("rs_address64_stream");
  769. buffer = *output_buffer;
  770. /* Set the Descriptor Type field */
  771. *buffer = ACPI_RDESC_TYPE_QWORD_ADDRESS_SPACE;
  772. buffer += 1;
  773. /* Save a pointer to the Length field - to be filled in later */
  774. length_field = ACPI_CAST_PTR(u16, buffer);
  775. buffer += 2;
  776. /* Set the Resource Type (Memory, Io, bus_number) */
  777. *buffer = (u8) (linked_list->data.address64.resource_type & 0x03);
  778. buffer += 1;
  779. /* Set the general flags */
  780. *buffer = acpi_rs_encode_general_flags(&linked_list->data);
  781. buffer += 1;
  782. /* Set the type specific flags */
  783. *buffer = acpi_rs_encode_specific_flags(&linked_list->data);
  784. buffer += 1;
  785. /* Set the address space granularity */
  786. ACPI_MOVE_64_TO_64(buffer, &linked_list->data.address64.granularity);
  787. buffer += 8;
  788. /* Set the address range minimum */
  789. ACPI_MOVE_64_TO_64(buffer,
  790. &linked_list->data.address64.min_address_range);
  791. buffer += 8;
  792. /* Set the address range maximum */
  793. ACPI_MOVE_64_TO_64(buffer,
  794. &linked_list->data.address64.max_address_range);
  795. buffer += 8;
  796. /* Set the address translation offset */
  797. ACPI_MOVE_64_TO_64(buffer,
  798. &linked_list->data.address64.
  799. address_translation_offset);
  800. buffer += 8;
  801. /* Set the address length */
  802. ACPI_MOVE_64_TO_64(buffer, &linked_list->data.address64.address_length);
  803. buffer += 8;
  804. /* Resource Source Index and Resource Source are optional */
  805. if (linked_list->data.address64.resource_source.string_length) {
  806. *buffer =
  807. (u8) linked_list->data.address64.resource_source.index;
  808. buffer += 1;
  809. /* Copy the resource_source string */
  810. ACPI_STRCPY((char *)buffer,
  811. linked_list->data.address64.resource_source.
  812. string_ptr);
  813. /*
  814. * Buffer needs to be set to the length of the string + one for the
  815. * terminating null
  816. */
  817. buffer +=
  818. (acpi_size) (ACPI_STRLEN
  819. (linked_list->data.address64.resource_source.
  820. string_ptr) + 1);
  821. }
  822. /* Return the number of bytes consumed in this operation */
  823. *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
  824. /*
  825. * Set the length field to the number of bytes consumed
  826. * minus the header size (3 bytes)
  827. */
  828. *length_field = (u16) (*bytes_consumed - 3);
  829. return_ACPI_STATUS(AE_OK);
  830. }