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