Pull bugzilla-5653 into release branch
[pandora-kernel.git] / arch / arm / kernel / compat.c
1 /*
2  *  linux/arch/arm/kernel/compat.c
3  *
4  *  Copyright (C) 2001 Russell King
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * We keep the old params compatibility cruft in one place (here)
11  * so we don't end up with lots of mess around other places.
12  *
13  * NOTE:
14  *  The old struct param_struct is deprecated, but it will be kept in
15  *  the kernel for 5 years from now (2001). This will allow boot loaders
16  *  to convert to the new struct tag way.
17  */
18 #include <linux/config.h>
19 #include <linux/types.h>
20 #include <linux/kernel.h>
21 #include <linux/string.h>
22 #include <linux/init.h>
23
24 #include <asm/setup.h>
25 #include <asm/mach-types.h>
26 #include <asm/page.h>
27
28 #include <asm/mach/arch.h>
29
30 #include "compat.h"
31
32 /*
33  * Usage:
34  *  - do not go blindly adding fields, add them at the end
35  *  - when adding fields, don't rely on the address until
36  *    a patch from me has been released
37  *  - unused fields should be zero (for future expansion)
38  *  - this structure is relatively short-lived - only
39  *    guaranteed to contain useful data in setup_arch()
40  *
41  * This is the old deprecated way to pass parameters to the kernel
42  */
43 struct param_struct {
44     union {
45         struct {
46             unsigned long page_size;            /*  0 */
47             unsigned long nr_pages;             /*  4 */
48             unsigned long ramdisk_size;         /*  8 */
49             unsigned long flags;                /* 12 */
50 #define FLAG_READONLY   1
51 #define FLAG_RDLOAD     4
52 #define FLAG_RDPROMPT   8
53             unsigned long rootdev;              /* 16 */
54             unsigned long video_num_cols;       /* 20 */
55             unsigned long video_num_rows;       /* 24 */
56             unsigned long video_x;              /* 28 */
57             unsigned long video_y;              /* 32 */
58             unsigned long memc_control_reg;     /* 36 */
59             unsigned char sounddefault;         /* 40 */
60             unsigned char adfsdrives;           /* 41 */
61             unsigned char bytes_per_char_h;     /* 42 */
62             unsigned char bytes_per_char_v;     /* 43 */
63             unsigned long pages_in_bank[4];     /* 44 */
64             unsigned long pages_in_vram;        /* 60 */
65             unsigned long initrd_start;         /* 64 */
66             unsigned long initrd_size;          /* 68 */
67             unsigned long rd_start;             /* 72 */
68             unsigned long system_rev;           /* 76 */
69             unsigned long system_serial_low;    /* 80 */
70             unsigned long system_serial_high;   /* 84 */
71             unsigned long mem_fclk_21285;       /* 88 */
72         } s;
73         char unused[256];
74     } u1;
75     union {
76         char paths[8][128];
77         struct {
78             unsigned long magic;
79             char n[1024 - sizeof(unsigned long)];
80         } s;
81     } u2;
82     char commandline[COMMAND_LINE_SIZE];
83 };
84
85 static struct tag * __init memtag(struct tag *tag, unsigned long start, unsigned long size)
86 {
87         tag = tag_next(tag);
88         tag->hdr.tag = ATAG_MEM;
89         tag->hdr.size = tag_size(tag_mem32);
90         tag->u.mem.size = size;
91         tag->u.mem.start = start;
92
93         return tag;
94 }
95
96 static void __init build_tag_list(struct param_struct *params, void *taglist)
97 {
98         struct tag *tag = taglist;
99
100         if (params->u1.s.page_size != PAGE_SIZE) {
101                 printk(KERN_WARNING "Warning: bad configuration page, "
102                        "trying to continue\n");
103                 return;
104         }
105
106         printk(KERN_DEBUG "Converting old-style param struct to taglist\n");
107
108 #ifdef CONFIG_ARCH_NETWINDER
109         if (params->u1.s.nr_pages != 0x02000 &&
110             params->u1.s.nr_pages != 0x04000 &&
111             params->u1.s.nr_pages != 0x08000 &&
112             params->u1.s.nr_pages != 0x10000) {
113                 printk(KERN_WARNING "Warning: bad NeTTrom parameters "
114                        "detected, using defaults\n");
115
116                 params->u1.s.nr_pages = 0x1000; /* 16MB */
117                 params->u1.s.ramdisk_size = 0;
118                 params->u1.s.flags = FLAG_READONLY;
119                 params->u1.s.initrd_start = 0;
120                 params->u1.s.initrd_size = 0;
121                 params->u1.s.rd_start = 0;
122         }
123 #endif
124
125         tag->hdr.tag  = ATAG_CORE;
126         tag->hdr.size = tag_size(tag_core);
127         tag->u.core.flags = params->u1.s.flags & FLAG_READONLY;
128         tag->u.core.pagesize = params->u1.s.page_size;
129         tag->u.core.rootdev = params->u1.s.rootdev;
130
131         tag = tag_next(tag);
132         tag->hdr.tag = ATAG_RAMDISK;
133         tag->hdr.size = tag_size(tag_ramdisk);
134         tag->u.ramdisk.flags = (params->u1.s.flags & FLAG_RDLOAD ? 1 : 0) |
135                                (params->u1.s.flags & FLAG_RDPROMPT ? 2 : 0);
136         tag->u.ramdisk.size  = params->u1.s.ramdisk_size;
137         tag->u.ramdisk.start = params->u1.s.rd_start;
138
139         tag = tag_next(tag);
140         tag->hdr.tag = ATAG_INITRD;
141         tag->hdr.size = tag_size(tag_initrd);
142         tag->u.initrd.start = params->u1.s.initrd_start;
143         tag->u.initrd.size  = params->u1.s.initrd_size;
144
145         tag = tag_next(tag);
146         tag->hdr.tag = ATAG_SERIAL;
147         tag->hdr.size = tag_size(tag_serialnr);
148         tag->u.serialnr.low = params->u1.s.system_serial_low;
149         tag->u.serialnr.high = params->u1.s.system_serial_high;
150
151         tag = tag_next(tag);
152         tag->hdr.tag = ATAG_REVISION;
153         tag->hdr.size = tag_size(tag_revision);
154         tag->u.revision.rev = params->u1.s.system_rev;
155
156 #ifdef CONFIG_ARCH_ACORN
157         if (machine_is_riscpc()) {
158                 int i;
159                 for (i = 0; i < 4; i++)
160                         tag = memtag(tag, PHYS_OFFSET + (i << 26),
161                                  params->u1.s.pages_in_bank[i] * PAGE_SIZE);
162         } else
163 #endif
164         tag = memtag(tag, PHYS_OFFSET, params->u1.s.nr_pages * PAGE_SIZE);
165
166 #ifdef CONFIG_FOOTBRIDGE
167         if (params->u1.s.mem_fclk_21285) {
168                 tag = tag_next(tag);
169                 tag->hdr.tag = ATAG_MEMCLK;
170                 tag->hdr.size = tag_size(tag_memclk);
171                 tag->u.memclk.fmemclk = params->u1.s.mem_fclk_21285;
172         }
173 #endif
174
175 #ifdef CONFIG_ARCH_EBSA285
176         if (machine_is_ebsa285()) {
177                 tag = tag_next(tag);
178                 tag->hdr.tag = ATAG_VIDEOTEXT;
179                 tag->hdr.size = tag_size(tag_videotext);
180                 tag->u.videotext.x            = params->u1.s.video_x;
181                 tag->u.videotext.y            = params->u1.s.video_y;
182                 tag->u.videotext.video_page   = 0;
183                 tag->u.videotext.video_mode   = 0;
184                 tag->u.videotext.video_cols   = params->u1.s.video_num_cols;
185                 tag->u.videotext.video_ega_bx = 0;
186                 tag->u.videotext.video_lines  = params->u1.s.video_num_rows;
187                 tag->u.videotext.video_isvga  = 1;
188                 tag->u.videotext.video_points = 8;
189         }
190 #endif
191
192 #ifdef CONFIG_ARCH_ACORN
193         tag = tag_next(tag);
194         tag->hdr.tag = ATAG_ACORN;
195         tag->hdr.size = tag_size(tag_acorn);
196         tag->u.acorn.memc_control_reg = params->u1.s.memc_control_reg;
197         tag->u.acorn.vram_pages       = params->u1.s.pages_in_vram;
198         tag->u.acorn.sounddefault     = params->u1.s.sounddefault;
199         tag->u.acorn.adfsdrives       = params->u1.s.adfsdrives;
200 #endif
201
202         tag = tag_next(tag);
203         tag->hdr.tag = ATAG_CMDLINE;
204         tag->hdr.size = (strlen(params->commandline) + 3 +
205                          sizeof(struct tag_header)) >> 2;
206         strcpy(tag->u.cmdline.cmdline, params->commandline);
207
208         tag = tag_next(tag);
209         tag->hdr.tag = ATAG_NONE;
210         tag->hdr.size = 0;
211
212         memmove(params, taglist, ((int)tag) - ((int)taglist) +
213                                  sizeof(struct tag_header));
214 }
215
216 void __init convert_to_tag_list(struct tag *tags)
217 {
218         struct param_struct *params = (struct param_struct *)tags;
219         build_tag_list(params, &params->u2);
220 }
221
222 void __init squash_mem_tags(struct tag *tag)
223 {
224         for (; tag->hdr.size; tag = tag_next(tag))
225                 if (tag->hdr.tag == ATAG_MEM)
226                         tag->hdr.tag = ATAG_NONE;
227 }