make oldconfig will rebuild these...
[linux-2.4.21-pre4.git] / drivers / acpi / resources / rsmemory.c
1 /*******************************************************************************
2  *
3  * Module Name: rsmem24 - Memory resource descriptors
4  *              $Revision: 1.1.1.1 $
5  *
6  ******************************************************************************/
7
8 /*
9  *  Copyright (C) 2000, 2001 R. Byron Moore
10  *
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  */
25
26
27 #include "acpi.h"
28 #include "acresrc.h"
29
30 #define _COMPONENT          ACPI_RESOURCES
31          MODULE_NAME         ("rsmemory")
32
33
34 /*******************************************************************************
35  *
36  * FUNCTION:    Acpi_rs_memory24_resource
37  *
38  * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
39  *                                        stream
40  *              Bytes_consumed          - u32 pointer that is filled with
41  *                                        the number of bytes consumed from
42  *                                        the Byte_stream_buffer
43  *              Output_buffer           - Pointer to the user's return buffer
44  *              Structure_size          - u32 pointer that is filled with
45  *                                        the number of bytes in the filled
46  *                                        in structure
47  *
48  * RETURN:      Status
49  *
50  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
51  *              structure pointed to by the Output_buffer. Return the
52  *              number of bytes consumed from the byte stream.
53  *
54  ******************************************************************************/
55
56 acpi_status
57 acpi_rs_memory24_resource (
58         u8                      *byte_stream_buffer,
59         u32                     *bytes_consumed,
60         u8                      **output_buffer,
61         u32                     *structure_size)
62 {
63         u8                      *buffer = byte_stream_buffer;
64         acpi_resource           *output_struct = (acpi_resource *) *output_buffer;
65         u16                     temp16 = 0;
66         u8                      temp8 = 0;
67         u32                     struct_size = SIZEOF_RESOURCE (acpi_resource_mem24);
68
69
70         FUNCTION_TRACE ("Rs_memory24_resource");
71
72
73         /*
74          * Point past the Descriptor to get the number of bytes consumed
75          */
76         buffer += 1;
77
78         MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
79         buffer += 2;
80         *bytes_consumed = temp16 + 3;
81         output_struct->id = ACPI_RSTYPE_MEM24;
82
83         /*
84          * Check Byte 3 the Read/Write bit
85          */
86         temp8 = *buffer;
87         buffer += 1;
88         output_struct->data.memory24.read_write_attribute = temp8 & 0x01;
89
90         /*
91          * Get Min_base_address (Bytes 4-5)
92          */
93         MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
94         buffer += 2;
95         output_struct->data.memory24.min_base_address = temp16;
96
97         /*
98          * Get Max_base_address (Bytes 6-7)
99          */
100         MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
101         buffer += 2;
102         output_struct->data.memory24.max_base_address = temp16;
103
104         /*
105          * Get Alignment (Bytes 8-9)
106          */
107         MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
108         buffer += 2;
109         output_struct->data.memory24.alignment = temp16;
110
111         /*
112          * Get Range_length (Bytes 10-11)
113          */
114         MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
115         output_struct->data.memory24.range_length = temp16;
116
117         /*
118          * Set the Length parameter
119          */
120         output_struct->length = struct_size;
121
122         /*
123          * Return the final size of the structure
124          */
125         *structure_size = struct_size;
126         return_ACPI_STATUS (AE_OK);
127 }
128
129
130 /*******************************************************************************
131  *
132  * FUNCTION:    Acpi_rs_memory24_stream
133  *
134  * PARAMETERS:  Linked_list             - Pointer to the resource linked list
135  *              Output_buffer           - Pointer to the user's return buffer
136  *              Bytes_consumed          - u32 pointer that is filled with
137  *                                        the number of bytes of the
138  *                                        Output_buffer used
139  *
140  * RETURN:      Status
141  *
142  * DESCRIPTION: Take the linked list resource structure and fills in the
143  *              the appropriate bytes in a byte stream
144  *
145  ******************************************************************************/
146
147 acpi_status
148 acpi_rs_memory24_stream (
149         acpi_resource           *linked_list,
150         u8                      **output_buffer,
151         u32                     *bytes_consumed)
152 {
153         u8                      *buffer = *output_buffer;
154         u16                     temp16 = 0;
155         u8                      temp8 = 0;
156
157
158         FUNCTION_TRACE ("Rs_memory24_stream");
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 = POINTER_DIFF (buffer, *output_buffer);
209         return_ACPI_STATUS (AE_OK);
210 }
211
212
213 /*******************************************************************************
214  *
215  * FUNCTION:    Acpi_rs_memory32_range_resource
216  *
217  * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
218  *                                        stream
219  *              Bytes_consumed          - u32 pointer that is filled with
220  *                                        the number of bytes consumed from
221  *                                        the Byte_stream_buffer
222  *              Output_buffer           - Pointer to the user's return buffer
223  *              Structure_size          - u32 pointer that is filled with
224  *                                        the number of bytes in the filled
225  *                                        in structure
226  *
227  * RETURN:      Status
228  *
229  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
230  *              structure pointed to by the Output_buffer. Return the
231  *              number of bytes consumed from the byte stream.
232  *
233  ******************************************************************************/
234
235 acpi_status
236 acpi_rs_memory32_range_resource (
237         u8                      *byte_stream_buffer,
238         u32                     *bytes_consumed,
239         u8                      **output_buffer,
240         u32                     *structure_size)
241 {
242         u8                      *buffer = byte_stream_buffer;
243         acpi_resource           *output_struct = (acpi_resource *) *output_buffer;
244         u16                     temp16 = 0;
245         u8                      temp8 = 0;
246         u32                     struct_size = SIZEOF_RESOURCE (acpi_resource_mem32);
247
248
249         FUNCTION_TRACE ("Rs_memory32_range_resource");
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 = ACPI_RSTYPE_MEM32;
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         return_ACPI_STATUS (AE_OK);
316 }
317
318
319 /*******************************************************************************
320  *
321  * FUNCTION:    Acpi_rs_fixed_memory32_resource
322  *
323  * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
324  *                                        stream
325  *              Bytes_consumed          - u32 pointer that is filled with
326  *                                        the number of bytes consumed from
327  *                                        the Byte_stream_buffer
328  *              Output_buffer           - Pointer to the user's return buffer
329  *              Structure_size          - u32 pointer that is filled with
330  *                                        the number of bytes in the filled
331  *                                        in structure
332  *
333  * RETURN:      Status
334  *
335  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
336  *              structure pointed to by the Output_buffer. Return the
337  *              number of bytes consumed from the byte stream.
338  *
339  ******************************************************************************/
340
341 acpi_status
342 acpi_rs_fixed_memory32_resource (
343         u8                      *byte_stream_buffer,
344         u32                     *bytes_consumed,
345         u8                      **output_buffer,
346         u32                     *structure_size)
347 {
348         u8                      *buffer = byte_stream_buffer;
349         acpi_resource           *output_struct = (acpi_resource *) *output_buffer;
350         u16                     temp16 = 0;
351         u8                      temp8 = 0;
352         u32                     struct_size = SIZEOF_RESOURCE (acpi_resource_fixed_mem32);
353
354
355         FUNCTION_TRACE ("Rs_fixed_memory32_resource");
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 = ACPI_RSTYPE_FIXED_MEM32;
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         return_ACPI_STATUS (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
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         acpi_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         FUNCTION_TRACE ("Rs_memory32_range_stream");
431
432
433         /*
434          * The descriptor field is static
435          */
436         *buffer = 0x85;
437         buffer += 1;
438
439         /*
440          * The length field is static
441          */
442         temp16 = 0x11;
443
444         MOVE_UNALIGNED16_TO_16 (buffer, &temp16);
445         buffer += 2;
446
447         /*
448          * Set the Information Byte
449          */
450         temp8 = (u8) (linked_list->data.memory32.read_write_attribute & 0x01);
451         *buffer = temp8;
452         buffer += 1;
453
454         /*
455          * Set the Range minimum base address
456          */
457         MOVE_UNALIGNED32_TO_32 (buffer, &linked_list->data.memory32.min_base_address);
458         buffer += 4;
459
460         /*
461          * Set the Range maximum base address
462          */
463         MOVE_UNALIGNED32_TO_32 (buffer, &linked_list->data.memory32.max_base_address);
464         buffer += 4;
465
466         /*
467          * Set the base alignment
468          */
469         MOVE_UNALIGNED32_TO_32 (buffer, &linked_list->data.memory32.alignment);
470         buffer += 4;
471
472         /*
473          * Set the range length
474          */
475         MOVE_UNALIGNED32_TO_32 (buffer, &linked_list->data.memory32.range_length);
476         buffer += 4;
477
478         /*
479          * Return the number of bytes consumed in this operation
480          */
481         *bytes_consumed = POINTER_DIFF (buffer, *output_buffer);
482         return_ACPI_STATUS (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
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         acpi_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         FUNCTION_TRACE ("Rs_fixed_memory32_stream");
515
516
517         /*
518          * The descriptor field is static
519          */
520         *buffer = 0x86;
521         buffer += 1;
522
523         /*
524          * The length field is static
525          */
526         temp16 = 0x09;
527
528         MOVE_UNALIGNED16_TO_16 (buffer, &temp16);
529         buffer += 2;
530
531         /*
532          * Set the Information Byte
533          */
534         temp8 = (u8) (linked_list->data.fixed_memory32.read_write_attribute & 0x01);
535         *buffer = temp8;
536         buffer += 1;
537
538         /*
539          * Set the Range base address
540          */
541         MOVE_UNALIGNED32_TO_32 (buffer,
542                          &linked_list->data.fixed_memory32.range_base_address);
543         buffer += 4;
544
545         /*
546          * Set the range length
547          */
548         MOVE_UNALIGNED32_TO_32 (buffer,
549                          &linked_list->data.fixed_memory32.range_length);
550         buffer += 4;
551
552         /*
553          * Return the number of bytes consumed in this operation
554          */
555         *bytes_consumed = POINTER_DIFF (buffer, *output_buffer);
556         return_ACPI_STATUS (AE_OK);
557 }
558