Create a branch for header work.
[reactos.git] / drivers / bus / acpi / resource / rsmemory.c
1 /*******************************************************************************
2 *
3 * Module Name: rsmem24 - Acpi_rs_memory24_resource
4 * Acpi_rs_memory24_stream
5 * Acpi_rs_memory32_range_resource
6 * Acpi_rs_fixed_memory32_resource
7 * Acpi_rs_memory32_range_stream
8 * Acpi_rs_fixed_memory32_stream
9 * $Revision: 1.1 $
10 *
11 ******************************************************************************/
12
13 /*
14 * Copyright (C) 2000, 2001 R. Byron Moore
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 */
30
31
32 #include <acpi.h>
33
34 #define _COMPONENT ACPI_RESOURCES
35 MODULE_NAME ("rsmemory")
36
37
38 /*******************************************************************************
39 *
40 * FUNCTION: Acpi_rs_memory24_resource
41 *
42 * PARAMETERS: Byte_stream_buffer - Pointer to the resource input byte
43 * stream
44 * Bytes_consumed - u32 pointer that is filled with
45 * the number of bytes consumed from
46 * the Byte_stream_buffer
47 * Output_buffer - Pointer to the user's return buffer
48 * Structure_size - u32 pointer that is filled with
49 * the number of bytes in the filled
50 * in structure
51 *
52 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
53 *
54 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
55 * structure pointed to by the Output_buffer. Return the
56 * number of bytes consumed from the byte stream.
57 *
58 ******************************************************************************/
59
60 ACPI_STATUS
61 acpi_rs_memory24_resource (
62 u8 *byte_stream_buffer,
63 u32 *bytes_consumed,
64 u8 **output_buffer,
65 u32 *structure_size)
66 {
67 u8 *buffer = byte_stream_buffer;
68 RESOURCE *output_struct = (RESOURCE *) * output_buffer;
69 u16 temp16 = 0;
70 u8 temp8 = 0;
71 u32 struct_size = sizeof (MEMORY24_RESOURCE) +
72 RESOURCE_LENGTH_NO_DATA;
73
74
75 /*
76 * Point past the Descriptor to get the number of bytes consumed
77 */
78 buffer += 1;
79
80 MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
81 buffer += 2;
82 *bytes_consumed = temp16 + 3;
83 output_struct->id = memory24;
84
85 /*
86 * Check Byte 3 the Read/Write bit
87 */
88 temp8 = *buffer;
89 buffer += 1;
90 output_struct->data.memory24.read_write_attribute = temp8 & 0x01;
91
92 /*
93 * Get Min_base_address (Bytes 4-5)
94 */
95 MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
96 buffer += 2;
97 output_struct->data.memory24.min_base_address = temp16;
98
99 /*
100 * Get Max_base_address (Bytes 6-7)
101 */
102 MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
103 buffer += 2;
104 output_struct->data.memory24.max_base_address = temp16;
105
106 /*
107 * Get Alignment (Bytes 8-9)
108 */
109 MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
110 buffer += 2;
111 output_struct->data.memory24.alignment = temp16;
112
113 /*
114 * Get Range_length (Bytes 10-11)
115 */
116 MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
117 output_struct->data.memory24.range_length = temp16;
118
119 /*
120 * Set the Length parameter
121 */
122 output_struct->length = struct_size;
123
124 /*
125 * Return the final size of the structure
126 */
127 *structure_size = struct_size;
128
129 return (AE_OK);
130 }
131
132
133 /*******************************************************************************
134 *
135 * FUNCTION: Acpi_rs_memory24_stream
136 *
137 * PARAMETERS: Linked_list - Pointer to the resource linked list
138 * Output_buffer - Pointer to the user's return buffer
139 * Bytes_consumed - u32 pointer that is filled with
140 * the number of bytes of the
141 * Output_buffer used
142 *
143 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
144 *
145 * DESCRIPTION: Take the linked list resource structure and fills in the
146 * the appropriate bytes in a byte stream
147 *
148 ******************************************************************************/
149
150 ACPI_STATUS
151 acpi_rs_memory24_stream (
152 RESOURCE *linked_list,
153 u8 **output_buffer,
154 u32 *bytes_consumed)
155 {
156 u8 *buffer = *output_buffer;
157 u16 temp16 = 0;
158 u8 temp8 = 0;
159
160
161 /*
162 * The descriptor field is static
163 */
164 *buffer = 0x81;
165 buffer += 1;
166
167 /*
168 * The length field is static
169 */
170 temp16 = 0x09;
171 MOVE_UNALIGNED16_TO_16 (buffer, &temp16);
172 buffer += 2;
173
174 /*
175 * Set the Information Byte
176 */
177 temp8 = (u8) (linked_list->data.memory24.read_write_attribute & 0x01);
178 *buffer = temp8;
179 buffer += 1;
180
181 /*
182 * Set the Range minimum base address
183 */
184 MOVE_UNALIGNED16_TO_16 (buffer, &linked_list->data.memory24.min_base_address);
185 buffer += 2;
186
187 /*
188 * Set the Range maximum base address
189 */
190 MOVE_UNALIGNED16_TO_16 (buffer, &linked_list->data.memory24.max_base_address);
191 buffer += 2;
192
193 /*
194 * Set the base alignment
195 */
196 MOVE_UNALIGNED16_TO_16 (buffer, &linked_list->data.memory24.alignment);
197 buffer += 2;
198
199 /*
200 * Set the range length
201 */
202 MOVE_UNALIGNED16_TO_16 (buffer, &linked_list->data.memory24.range_length);
203 buffer += 2;
204
205 /*
206 * Return the number of bytes consumed in this operation
207 */
208 *bytes_consumed = (u32) ((NATIVE_UINT) buffer -
209 (NATIVE_UINT) *output_buffer);
210
211 return (AE_OK);
212 }
213
214
215 /*******************************************************************************
216 *
217 * FUNCTION: Acpi_rs_memory32_range_resource
218 *
219 * PARAMETERS: Byte_stream_buffer - Pointer to the resource input byte
220 * stream
221 * Bytes_consumed - u32 pointer that is filled with
222 * the number of bytes consumed from
223 * the Byte_stream_buffer
224 * Output_buffer - Pointer to the user's return buffer
225 * Structure_size - u32 pointer that is filled with
226 * the number of bytes in the filled
227 * in structure
228 *
229 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
230 *
231 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
232 * structure pointed to by the Output_buffer. Return the
233 * number of bytes consumed from the byte stream.
234 *
235 ******************************************************************************/
236
237 ACPI_STATUS
238 acpi_rs_memory32_range_resource (
239 u8 *byte_stream_buffer,
240 u32 *bytes_consumed,
241 u8 **output_buffer,
242 u32 *structure_size)
243 {
244 u8 *buffer = byte_stream_buffer;
245 RESOURCE *output_struct = (RESOURCE *) * output_buffer;
246 u16 temp16 = 0;
247 u8 temp8 = 0;
248 u32 struct_size = sizeof (MEMORY32_RESOURCE) +
249 RESOURCE_LENGTH_NO_DATA;
250
251
252 /*
253 * Point past the Descriptor to get the number of bytes consumed
254 */
255 buffer += 1;
256
257 MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
258 buffer += 2;
259 *bytes_consumed = temp16 + 3;
260
261 output_struct->id = memory32;
262
263 /*
264 * Point to the place in the output buffer where the data portion will
265 * begin.
266 * 1. Set the RESOURCE_DATA * Data to point to it's own address, then
267 * 2. Set the pointer to the next address.
268 *
269 * NOTE: Output_struct->Data is cast to u8, otherwise, this addition adds
270 * 4 * sizeof(RESOURCE_DATA) instead of 4 * sizeof(u8)
271 */
272
273 /*
274 * Check Byte 3 the Read/Write bit
275 */
276 temp8 = *buffer;
277 buffer += 1;
278
279 output_struct->data.memory32.read_write_attribute = temp8 & 0x01;
280
281 /*
282 * Get Min_base_address (Bytes 4-7)
283 */
284 MOVE_UNALIGNED32_TO_32 (&output_struct->data.memory32.min_base_address,
285 buffer);
286 buffer += 4;
287
288 /*
289 * Get Max_base_address (Bytes 8-11)
290 */
291 MOVE_UNALIGNED32_TO_32 (&output_struct->data.memory32.max_base_address,
292 buffer);
293 buffer += 4;
294
295 /*
296 * Get Alignment (Bytes 12-15)
297 */
298 MOVE_UNALIGNED32_TO_32 (&output_struct->data.memory32.alignment, buffer);
299 buffer += 4;
300
301 /*
302 * Get Range_length (Bytes 16-19)
303 */
304 MOVE_UNALIGNED32_TO_32 (&output_struct->data.memory32.range_length, buffer);
305
306 /*
307 * Set the Length parameter
308 */
309 output_struct->length = struct_size;
310
311 /*
312 * Return the final size of the structure
313 */
314 *structure_size = struct_size;
315
316 return (AE_OK);
317 }
318
319
320 /*******************************************************************************
321 *
322 * FUNCTION: Acpi_rs_fixed_memory32_resource
323 *
324 * PARAMETERS: Byte_stream_buffer - Pointer to the resource input byte
325 * stream
326 * Bytes_consumed - u32 pointer that is filled with
327 * the number of bytes consumed from
328 * the Byte_stream_buffer
329 * Output_buffer - Pointer to the user's return buffer
330 * Structure_size - u32 pointer that is filled with
331 * the number of bytes in the filled
332 * in structure
333 *
334 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
335 *
336 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
337 * structure pointed to by the Output_buffer. Return the
338 * number of bytes consumed from the byte stream.
339 *
340 ******************************************************************************/
341
342 ACPI_STATUS
343 acpi_rs_fixed_memory32_resource (
344 u8 *byte_stream_buffer,
345 u32 *bytes_consumed,
346 u8 **output_buffer,
347 u32 *structure_size)
348 {
349 u8 *buffer = byte_stream_buffer;
350 RESOURCE *output_struct = (RESOURCE *) * output_buffer;
351 u16 temp16 = 0;
352 u8 temp8 = 0;
353 u32 struct_size = sizeof (FIXED_MEMORY32_RESOURCE) +
354 RESOURCE_LENGTH_NO_DATA;
355
356
357 /*
358 * Point past the Descriptor to get the number of bytes consumed
359 */
360 buffer += 1;
361 MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
362
363 buffer += 2;
364 *bytes_consumed = temp16 + 3;
365
366 output_struct->id = fixed_memory32;
367
368 /*
369 * Check Byte 3 the Read/Write bit
370 */
371 temp8 = *buffer;
372 buffer += 1;
373 output_struct->data.fixed_memory32.read_write_attribute = temp8 & 0x01;
374
375 /*
376 * Get Range_base_address (Bytes 4-7)
377 */
378 MOVE_UNALIGNED32_TO_32 (&output_struct->data.fixed_memory32.range_base_address,
379 buffer);
380 buffer += 4;
381
382 /*
383 * Get Range_length (Bytes 8-11)
384 */
385 MOVE_UNALIGNED32_TO_32 (&output_struct->data.fixed_memory32.range_length,
386 buffer);
387
388 /*
389 * Set the Length parameter
390 */
391 output_struct->length = struct_size;
392
393 /*
394 * Return the final size of the structure
395 */
396 *structure_size = struct_size;
397
398 return (AE_OK);
399 }
400
401
402 /*******************************************************************************
403 *
404 * FUNCTION: Acpi_rs_memory32_range_stream
405 *
406 * PARAMETERS: Linked_list - Pointer to the resource linked list
407 * Output_buffer - Pointer to the user's return buffer
408 * Bytes_consumed - u32 pointer that is filled with
409 * the number of bytes of the
410 * Output_buffer used
411 *
412 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
413 *
414 * DESCRIPTION: Take the linked list resource structure and fills in the
415 * the appropriate bytes in a byte stream
416 *
417 ******************************************************************************/
418
419 ACPI_STATUS
420 acpi_rs_memory32_range_stream (
421 RESOURCE *linked_list,
422 u8 **output_buffer,
423 u32 *bytes_consumed)
424 {
425 u8 *buffer = *output_buffer;
426 u16 temp16 = 0;
427 u8 temp8 = 0;
428
429
430 /*
431 * The descriptor field is static
432 */
433 *buffer = 0x85;
434 buffer += 1;
435
436 /*
437 * The length field is static
438 */
439 temp16 = 0x11;
440
441 MOVE_UNALIGNED16_TO_16 (buffer, &temp16);
442 buffer += 2;
443
444 /*
445 * Set the Information Byte
446 */
447 temp8 = (u8) (linked_list->data.memory32.read_write_attribute & 0x01);
448 *buffer = temp8;
449 buffer += 1;
450
451 /*
452 * Set the Range minimum base address
453 */
454 MOVE_UNALIGNED32_TO_32 (buffer, &linked_list->data.memory32.min_base_address);
455 buffer += 4;
456
457 /*
458 * Set the Range maximum base address
459 */
460 MOVE_UNALIGNED32_TO_32 (buffer, &linked_list->data.memory32.max_base_address);
461 buffer += 4;
462
463 /*
464 * Set the base alignment
465 */
466 MOVE_UNALIGNED32_TO_32 (buffer, &linked_list->data.memory32.alignment);
467 buffer += 4;
468
469 /*
470 * Set the range length
471 */
472 MOVE_UNALIGNED32_TO_32 (buffer, &linked_list->data.memory32.range_length);
473 buffer += 4;
474
475 /*
476 * Return the number of bytes consumed in this operation
477 */
478 *bytes_consumed = (u32) ((NATIVE_UINT) buffer -
479 (NATIVE_UINT) *output_buffer);
480
481 return (AE_OK);
482 }
483
484
485 /*******************************************************************************
486 *
487 * FUNCTION: Acpi_rs_fixed_memory32_stream
488 *
489 * PARAMETERS: Linked_list - Pointer to the resource linked list
490 * Output_buffer - Pointer to the user's return buffer
491 * Bytes_consumed - u32 pointer that is filled with
492 * the number of bytes of the
493 * Output_buffer used
494 *
495 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
496 *
497 * DESCRIPTION: Take the linked list resource structure and fills in the
498 * the appropriate bytes in a byte stream
499 *
500 ******************************************************************************/
501
502 ACPI_STATUS
503 acpi_rs_fixed_memory32_stream (
504 RESOURCE *linked_list,
505 u8 **output_buffer,
506 u32 *bytes_consumed)
507 {
508 u8 *buffer = *output_buffer;
509 u16 temp16 = 0;
510 u8 temp8 = 0;
511
512
513 /*
514 * The descriptor field is static
515 */
516 *buffer = 0x86;
517 buffer += 1;
518
519 /*
520 * The length field is static
521 */
522 temp16 = 0x09;
523
524 MOVE_UNALIGNED16_TO_16 (buffer, &temp16);
525 buffer += 2;
526
527 /*
528 * Set the Information Byte
529 */
530 temp8 = (u8) (linked_list->data.fixed_memory32.read_write_attribute & 0x01);
531 *buffer = temp8;
532 buffer += 1;
533
534 /*
535 * Set the Range base address
536 */
537 MOVE_UNALIGNED32_TO_32 (buffer,
538 &linked_list->data.fixed_memory32.range_base_address);
539 buffer += 4;
540
541 /*
542 * Set the range length
543 */
544 MOVE_UNALIGNED32_TO_32 (buffer,
545 &linked_list->data.fixed_memory32.range_length);
546 buffer += 4;
547
548 /*
549 * Return the number of bytes consumed in this operation
550 */
551 *bytes_consumed = (u32) ((NATIVE_UINT) buffer -
552 (NATIVE_UINT) *output_buffer);
553
554 return (AE_OK);
555 }
556