]> bbs.cooldavid.org Git - net-next-2.6.git/blame - arch/mips/ar7/prom.c
MIPS: Alchemy: Use strlcat() for the command line arguments
[net-next-2.6.git] / arch / mips / ar7 / prom.c
CommitLineData
7ca5dc14
FF
1/*
2 * Carsten Langgaard, carstenl@mips.com
3 * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
4 *
5 * This program is free software; you can distribute it and/or modify it
6 * under the terms of the GNU General Public License (Version 2) as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
17 *
18 * Putting things on the screen/serial line using YAMONs facilities.
19 */
20#include <linux/init.h>
21#include <linux/kernel.h>
22#include <linux/serial_reg.h>
23#include <linux/spinlock.h>
24#include <linux/module.h>
25#include <linux/string.h>
26#include <linux/io.h>
27#include <asm/bootinfo.h>
28
29#include <asm/mach-ar7/ar7.h>
30#include <asm/mach-ar7/prom.h>
31
32#define MAX_ENTRY 80
33
34struct env_var {
35 char *name;
36 char *value;
37};
38
39static struct env_var adam2_env[MAX_ENTRY];
40
41char *prom_getenv(const char *name)
42{
43 int i;
44 for (i = 0; (i < MAX_ENTRY) && adam2_env[i].name; i++)
45 if (!strcmp(name, adam2_env[i].name))
46 return adam2_env[i].value;
47
48 return NULL;
49}
50EXPORT_SYMBOL(prom_getenv);
51
7ca5dc14
FF
52static void __init ar7_init_cmdline(int argc, char *argv[])
53{
9feb8367 54 int i;
7ca5dc14 55
9feb8367
YY
56 for (i = 1; i < argc; i++) {
57 strlcat(arcs_cmdline, argv[i], COMMAND_LINE_SIZE);
58 if (i < (argc - 1))
59 strlcat(arcs_cmdline, " ", COMMAND_LINE_SIZE);
7ca5dc14
FF
60 }
61}
62
63struct psbl_rec {
64 u32 psbl_size;
65 u32 env_base;
66 u32 env_size;
67 u32 ffs_base;
68 u32 ffs_size;
69};
70
71static __initdata char psp_env_version[] = "TIENV0.8";
72
73struct psp_env_chunk {
74 u8 num;
75 u8 ctrl;
76 u16 csum;
77 u8 len;
78 char data[11];
79} __attribute__ ((packed));
80
81struct psp_var_map_entry {
82 u8 num;
83 char *value;
84};
85
86static struct psp_var_map_entry psp_var_map[] = {
87 { 1, "cpufrequency" },
88 { 2, "memsize" },
89 { 3, "flashsize" },
90 { 4, "modetty0" },
91 { 5, "modetty1" },
92 { 8, "maca" },
93 { 9, "macb" },
94 { 28, "sysfrequency" },
95 { 38, "mipsfrequency" },
96};
97
98/*
99
100Well-known variable (num is looked up in table above for matching variable name)
101Example: cpufrequency=211968000
102+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
103| 01 |CTRL|CHECKSUM | 01 | _2 | _1 | _1 | _9 | _6 | _8 | _0 | _0 | _0 | \0 | FF
104+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
105
106Name=Value pair in a single chunk
107Example: NAME=VALUE
108+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
109| 00 |CTRL|CHECKSUM | 01 | _N | _A | _M | _E | _0 | _V | _A | _L | _U | _E | \0
110+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
111
112Name=Value pair in 2 chunks (len is the number of chunks)
113Example: bootloaderVersion=1.3.7.15
114+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
115| 00 |CTRL|CHECKSUM | 02 | _b | _o | _o | _t | _l | _o | _a | _d | _e | _r | _V
116+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
117| _e | _r | _s | _i | _o | _n | \0 | _1 | _. | _3 | _. | _7 | _. | _1 | _5 | \0
118+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
119
120Data is padded with 0xFF
121
122*/
123
124#define PSP_ENV_SIZE 4096
125
126static char psp_env_data[PSP_ENV_SIZE] = { 0, };
127
128static char * __init lookup_psp_var_map(u8 num)
129{
130 int i;
131
ea85a0e4 132 for (i = 0; i < ARRAY_SIZE(psp_var_map); i++)
7ca5dc14
FF
133 if (psp_var_map[i].num == num)
134 return psp_var_map[i].value;
135
136 return NULL;
137}
138
139static void __init add_adam2_var(char *name, char *value)
140{
141 int i;
142 for (i = 0; i < MAX_ENTRY; i++) {
143 if (!adam2_env[i].name) {
144 adam2_env[i].name = name;
145 adam2_env[i].value = value;
146 return;
147 } else if (!strcmp(adam2_env[i].name, name)) {
148 adam2_env[i].value = value;
149 return;
150 }
151 }
152}
153
154static int __init parse_psp_env(void *psp_env_base)
155{
156 int i, n;
157 char *name, *value;
158 struct psp_env_chunk *chunks = (struct psp_env_chunk *)psp_env_data;
159
160 memcpy_fromio(chunks, psp_env_base, PSP_ENV_SIZE);
161
162 i = 1;
163 n = PSP_ENV_SIZE / sizeof(struct psp_env_chunk);
164 while (i < n) {
165 if ((chunks[i].num == 0xff) || ((i + chunks[i].len) > n))
166 break;
167 value = chunks[i].data;
168 if (chunks[i].num) {
169 name = lookup_psp_var_map(chunks[i].num);
170 } else {
171 name = value;
172 value += strlen(name) + 1;
173 }
174 if (name)
175 add_adam2_var(name, value);
176 i += chunks[i].len;
177 }
178 return 0;
179}
180
181static void __init ar7_init_env(struct env_var *env)
182{
183 int i;
184 struct psbl_rec *psbl = (struct psbl_rec *)(KSEG1ADDR(0x14000300));
185 void *psp_env = (void *)KSEG1ADDR(psbl->env_base);
186
187 if (strcmp(psp_env, psp_env_version) == 0) {
188 parse_psp_env(psp_env);
189 } else {
190 for (i = 0; i < MAX_ENTRY; i++, env++)
191 if (env->name)
192 add_adam2_var(env->name, env->value);
193 }
194}
195
196static void __init console_config(void)
197{
198#ifdef CONFIG_SERIAL_8250_CONSOLE
199 char console_string[40];
200 int baud = 0;
201 char parity = '\0', bits = '\0', flow = '\0';
202 char *s, *p;
203
9fd4c4f4 204 if (strstr(arcs_cmdline, "console="))
7ca5dc14
FF
205 return;
206
7ca5dc14
FF
207 s = prom_getenv("modetty0");
208 if (s) {
209 baud = simple_strtoul(s, &p, 10);
210 s = p;
211 if (*s == ',')
212 s++;
213 if (*s)
214 parity = *s++;
215 if (*s == ',')
216 s++;
217 if (*s)
218 bits = *s++;
219 if (*s == ',')
220 s++;
221 if (*s == 'h')
222 flow = 'r';
223 }
224
225 if (baud == 0)
226 baud = 38400;
227 if (parity != 'n' && parity != 'o' && parity != 'e')
228 parity = 'n';
229 if (bits != '7' && bits != '8')
230 bits = '8';
231
232 if (flow == 'r')
233 sprintf(console_string, " console=ttyS0,%d%c%c%c", baud,
234 parity, bits, flow);
235 else
236 sprintf(console_string, " console=ttyS0,%d%c%c", baud, parity,
237 bits);
9feb8367 238 strlcat(arcs_cmdline, console_string, COMMAND_LINE_SIZE);
7ca5dc14
FF
239#endif
240}
241
242void __init prom_init(void)
243{
244 ar7_init_cmdline(fw_arg0, (char **)fw_arg1);
245 ar7_init_env((struct env_var *)fw_arg2);
246 console_config();
247}
248
249#define PORT(offset) (KSEG1ADDR(AR7_REGS_UART0 + (offset * 4)))
250static inline unsigned int serial_in(int offset)
251{
252 return readl((void *)PORT(offset));
253}
254
255static inline void serial_out(int offset, int value)
256{
257 writel(value, (void *)PORT(offset));
258}
259
7ca5dc14
FF
260int prom_putchar(char c)
261{
262 while ((serial_in(UART_LSR) & UART_LSR_TEMT) == 0)
263 ;
264 serial_out(UART_TX, c);
265 return 1;
266}