]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/acpi/resources/rsmemory.c
Linux-2.6.12-rc2
[mirror_ubuntu-artful-kernel.git] / drivers / acpi / resources / rsmemory.c
1 /*******************************************************************************
2 *
3 * Module Name: rsmem24 - Memory resource descriptors
4 *
5 ******************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44
45 #include <acpi/acpi.h>
46 #include <acpi/acresrc.h>
47
48 #define _COMPONENT ACPI_RESOURCES
49 ACPI_MODULE_NAME ("rsmemory")
50
51
52 /*******************************************************************************
53 *
54 * FUNCTION: acpi_rs_memory24_resource
55 *
56 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
57 * stream
58 * bytes_consumed - Pointer to where the number of bytes
59 * consumed the byte_stream_buffer is
60 * returned
61 * output_buffer - Pointer to the return data buffer
62 * structure_size - Pointer to where the number of bytes
63 * in the return data struct is returned
64 *
65 * RETURN: Status
66 *
67 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
68 * structure pointed to by the output_buffer. Return the
69 * number of bytes consumed from the byte stream.
70 *
71 ******************************************************************************/
72
73 acpi_status
74 acpi_rs_memory24_resource (
75 u8 *byte_stream_buffer,
76 acpi_size *bytes_consumed,
77 u8 **output_buffer,
78 acpi_size *structure_size)
79 {
80 u8 *buffer = byte_stream_buffer;
81 struct acpi_resource *output_struct = (void *) *output_buffer;
82 u16 temp16 = 0;
83 u8 temp8 = 0;
84 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_mem24);
85
86
87 ACPI_FUNCTION_TRACE ("rs_memory24_resource");
88
89
90 /*
91 * Point past the Descriptor to get the number of bytes consumed
92 */
93 buffer += 1;
94
95 ACPI_MOVE_16_TO_16 (&temp16, buffer);
96 buffer += 2;
97 *bytes_consumed = (acpi_size) temp16 + 3;
98 output_struct->id = ACPI_RSTYPE_MEM24;
99
100 /*
101 * Check Byte 3 the Read/Write bit
102 */
103 temp8 = *buffer;
104 buffer += 1;
105 output_struct->data.memory24.read_write_attribute = temp8 & 0x01;
106
107 /*
108 * Get min_base_address (Bytes 4-5)
109 */
110 ACPI_MOVE_16_TO_16 (&temp16, buffer);
111 buffer += 2;
112 output_struct->data.memory24.min_base_address = temp16;
113
114 /*
115 * Get max_base_address (Bytes 6-7)
116 */
117 ACPI_MOVE_16_TO_16 (&temp16, buffer);
118 buffer += 2;
119 output_struct->data.memory24.max_base_address = temp16;
120
121 /*
122 * Get Alignment (Bytes 8-9)
123 */
124 ACPI_MOVE_16_TO_16 (&temp16, buffer);
125 buffer += 2;
126 output_struct->data.memory24.alignment = temp16;
127
128 /*
129 * Get range_length (Bytes 10-11)
130 */
131 ACPI_MOVE_16_TO_16 (&temp16, buffer);
132 output_struct->data.memory24.range_length = temp16;
133
134 /*
135 * Set the Length parameter
136 */
137 output_struct->length = (u32) struct_size;
138
139 /*
140 * Return the final size of the structure
141 */
142 *structure_size = struct_size;
143 return_ACPI_STATUS (AE_OK);
144 }
145
146
147 /*******************************************************************************
148 *
149 * FUNCTION: acpi_rs_memory24_stream
150 *
151 * PARAMETERS: linked_list - Pointer to the resource linked list
152 * output_buffer - Pointer to the user's return buffer
153 * bytes_consumed - Pointer to where the number of bytes
154 * used in the output_buffer is returned
155 *
156 * RETURN: Status
157 *
158 * DESCRIPTION: Take the linked list resource structure and fills in the
159 * the appropriate bytes in a byte stream
160 *
161 ******************************************************************************/
162
163 acpi_status
164 acpi_rs_memory24_stream (
165 struct acpi_resource *linked_list,
166 u8 **output_buffer,
167 acpi_size *bytes_consumed)
168 {
169 u8 *buffer = *output_buffer;
170 u16 temp16 = 0;
171 u8 temp8 = 0;
172
173
174 ACPI_FUNCTION_TRACE ("rs_memory24_stream");
175
176
177 /*
178 * The descriptor field is static
179 */
180 *buffer = 0x81;
181 buffer += 1;
182
183 /*
184 * The length field is static
185 */
186 temp16 = 0x09;
187 ACPI_MOVE_16_TO_16 (buffer, &temp16);
188 buffer += 2;
189
190 /*
191 * Set the Information Byte
192 */
193 temp8 = (u8) (linked_list->data.memory24.read_write_attribute & 0x01);
194 *buffer = temp8;
195 buffer += 1;
196
197 /*
198 * Set the Range minimum base address
199 */
200 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.memory24.min_base_address);
201 buffer += 2;
202
203 /*
204 * Set the Range maximum base address
205 */
206 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.memory24.max_base_address);
207 buffer += 2;
208
209 /*
210 * Set the base alignment
211 */
212 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.memory24.alignment);
213 buffer += 2;
214
215 /*
216 * Set the range length
217 */
218 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.memory24.range_length);
219 buffer += 2;
220
221 /*
222 * Return the number of bytes consumed in this operation
223 */
224 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
225 return_ACPI_STATUS (AE_OK);
226 }
227
228
229 /*******************************************************************************
230 *
231 * FUNCTION: acpi_rs_memory32_range_resource
232 *
233 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
234 * stream
235 * bytes_consumed - Pointer to where the number of bytes
236 * consumed the byte_stream_buffer is
237 * returned
238 * output_buffer - Pointer to the return data buffer
239 * structure_size - Pointer to where the number of bytes
240 * in the return data struct is returned
241 *
242 * RETURN: Status
243 *
244 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
245 * structure pointed to by the output_buffer. Return the
246 * number of bytes consumed from the byte stream.
247 *
248 ******************************************************************************/
249
250 acpi_status
251 acpi_rs_memory32_range_resource (
252 u8 *byte_stream_buffer,
253 acpi_size *bytes_consumed,
254 u8 **output_buffer,
255 acpi_size *structure_size)
256 {
257 u8 *buffer = byte_stream_buffer;
258 struct acpi_resource *output_struct = (void *) *output_buffer;
259 u16 temp16 = 0;
260 u8 temp8 = 0;
261 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_mem32);
262
263
264 ACPI_FUNCTION_TRACE ("rs_memory32_range_resource");
265
266
267 /*
268 * Point past the Descriptor to get the number of bytes consumed
269 */
270 buffer += 1;
271
272 ACPI_MOVE_16_TO_16 (&temp16, buffer);
273 buffer += 2;
274 *bytes_consumed = (acpi_size) temp16 + 3;
275
276 output_struct->id = ACPI_RSTYPE_MEM32;
277
278 /*
279 * Point to the place in the output buffer where the data portion will
280 * begin.
281 * 1. Set the RESOURCE_DATA * Data to point to its own address, then
282 * 2. Set the pointer to the next address.
283 *
284 * NOTE: output_struct->Data is cast to u8, otherwise, this addition adds
285 * 4 * sizeof(RESOURCE_DATA) instead of 4 * sizeof(u8)
286 */
287
288 /*
289 * Check Byte 3 the Read/Write bit
290 */
291 temp8 = *buffer;
292 buffer += 1;
293
294 output_struct->data.memory32.read_write_attribute = temp8 & 0x01;
295
296 /*
297 * Get min_base_address (Bytes 4-7)
298 */
299 ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.min_base_address, buffer);
300 buffer += 4;
301
302 /*
303 * Get max_base_address (Bytes 8-11)
304 */
305 ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.max_base_address, buffer);
306 buffer += 4;
307
308 /*
309 * Get Alignment (Bytes 12-15)
310 */
311 ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.alignment, buffer);
312 buffer += 4;
313
314 /*
315 * Get range_length (Bytes 16-19)
316 */
317 ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.range_length, buffer);
318
319 /*
320 * Set the Length parameter
321 */
322 output_struct->length = (u32) struct_size;
323
324 /*
325 * Return the final size of the structure
326 */
327 *structure_size = struct_size;
328 return_ACPI_STATUS (AE_OK);
329 }
330
331
332 /*******************************************************************************
333 *
334 * FUNCTION: acpi_rs_fixed_memory32_resource
335 *
336 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
337 * stream
338 * bytes_consumed - Pointer to where the number of bytes
339 * consumed the byte_stream_buffer is
340 * returned
341 * output_buffer - Pointer to the return data buffer
342 * structure_size - Pointer to where the number of bytes
343 * in the return data struct is returned
344 *
345 * RETURN: Status
346 *
347 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
348 * structure pointed to by the output_buffer. Return the
349 * number of bytes consumed from the byte stream.
350 *
351 ******************************************************************************/
352
353 acpi_status
354 acpi_rs_fixed_memory32_resource (
355 u8 *byte_stream_buffer,
356 acpi_size *bytes_consumed,
357 u8 **output_buffer,
358 acpi_size *structure_size)
359 {
360 u8 *buffer = byte_stream_buffer;
361 struct acpi_resource *output_struct = (void *) *output_buffer;
362 u16 temp16 = 0;
363 u8 temp8 = 0;
364 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_fixed_mem32);
365
366
367 ACPI_FUNCTION_TRACE ("rs_fixed_memory32_resource");
368
369
370 /*
371 * Point past the Descriptor to get the number of bytes consumed
372 */
373 buffer += 1;
374 ACPI_MOVE_16_TO_16 (&temp16, buffer);
375
376 buffer += 2;
377 *bytes_consumed = (acpi_size) temp16 + 3;
378
379 output_struct->id = ACPI_RSTYPE_FIXED_MEM32;
380
381 /*
382 * Check Byte 3 the Read/Write bit
383 */
384 temp8 = *buffer;
385 buffer += 1;
386 output_struct->data.fixed_memory32.read_write_attribute = temp8 & 0x01;
387
388 /*
389 * Get range_base_address (Bytes 4-7)
390 */
391 ACPI_MOVE_32_TO_32 (&output_struct->data.fixed_memory32.range_base_address, buffer);
392 buffer += 4;
393
394 /*
395 * Get range_length (Bytes 8-11)
396 */
397 ACPI_MOVE_32_TO_32 (&output_struct->data.fixed_memory32.range_length, buffer);
398
399 /*
400 * Set the Length parameter
401 */
402 output_struct->length = (u32) struct_size;
403
404 /*
405 * Return the final size of the structure
406 */
407 *structure_size = struct_size;
408 return_ACPI_STATUS (AE_OK);
409 }
410
411
412 /*******************************************************************************
413 *
414 * FUNCTION: acpi_rs_memory32_range_stream
415 *
416 * PARAMETERS: linked_list - Pointer to the resource linked list
417 * output_buffer - Pointer to the user's return buffer
418 * bytes_consumed - Pointer to where the number of bytes
419 * used in the output_buffer is returned
420 *
421 * RETURN: Status
422 *
423 * DESCRIPTION: Take the linked list resource structure and fills in the
424 * the appropriate bytes in a byte stream
425 *
426 ******************************************************************************/
427
428 acpi_status
429 acpi_rs_memory32_range_stream (
430 struct acpi_resource *linked_list,
431 u8 **output_buffer,
432 acpi_size *bytes_consumed)
433 {
434 u8 *buffer = *output_buffer;
435 u16 temp16 = 0;
436 u8 temp8 = 0;
437
438
439 ACPI_FUNCTION_TRACE ("rs_memory32_range_stream");
440
441
442 /*
443 * The descriptor field is static
444 */
445 *buffer = 0x85;
446 buffer += 1;
447
448 /*
449 * The length field is static
450 */
451 temp16 = 0x11;
452
453 ACPI_MOVE_16_TO_16 (buffer, &temp16);
454 buffer += 2;
455
456 /*
457 * Set the Information Byte
458 */
459 temp8 = (u8) (linked_list->data.memory32.read_write_attribute & 0x01);
460 *buffer = temp8;
461 buffer += 1;
462
463 /*
464 * Set the Range minimum base address
465 */
466 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.min_base_address);
467 buffer += 4;
468
469 /*
470 * Set the Range maximum base address
471 */
472 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.max_base_address);
473 buffer += 4;
474
475 /*
476 * Set the base alignment
477 */
478 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.alignment);
479 buffer += 4;
480
481 /*
482 * Set the range length
483 */
484 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.range_length);
485 buffer += 4;
486
487 /*
488 * Return the number of bytes consumed in this operation
489 */
490 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
491 return_ACPI_STATUS (AE_OK);
492 }
493
494
495 /*******************************************************************************
496 *
497 * FUNCTION: acpi_rs_fixed_memory32_stream
498 *
499 * PARAMETERS: linked_list - Pointer to the resource linked list
500 * output_buffer - Pointer to the user's return buffer
501 * bytes_consumed - Pointer to where the number of bytes
502 * used in the output_buffer is returned
503 *
504 * RETURN: Status
505 *
506 * DESCRIPTION: Take the linked list resource structure and fills in the
507 * the appropriate bytes in a byte stream
508 *
509 ******************************************************************************/
510
511 acpi_status
512 acpi_rs_fixed_memory32_stream (
513 struct acpi_resource *linked_list,
514 u8 **output_buffer,
515 acpi_size *bytes_consumed)
516 {
517 u8 *buffer = *output_buffer;
518 u16 temp16 = 0;
519 u8 temp8 = 0;
520
521
522 ACPI_FUNCTION_TRACE ("rs_fixed_memory32_stream");
523
524
525 /*
526 * The descriptor field is static
527 */
528 *buffer = 0x86;
529 buffer += 1;
530
531 /*
532 * The length field is static
533 */
534 temp16 = 0x09;
535
536 ACPI_MOVE_16_TO_16 (buffer, &temp16);
537 buffer += 2;
538
539 /*
540 * Set the Information Byte
541 */
542 temp8 = (u8) (linked_list->data.fixed_memory32.read_write_attribute & 0x01);
543 *buffer = temp8;
544 buffer += 1;
545
546 /*
547 * Set the Range base address
548 */
549 ACPI_MOVE_32_TO_32 (buffer,
550 &linked_list->data.fixed_memory32.range_base_address);
551 buffer += 4;
552
553 /*
554 * Set the range length
555 */
556 ACPI_MOVE_32_TO_32 (buffer,
557 &linked_list->data.fixed_memory32.range_length);
558 buffer += 4;
559
560 /*
561 * Return the number of bytes consumed in this operation
562 */
563 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
564 return_ACPI_STATUS (AE_OK);
565 }
566