rsaddr.c 32 KB

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