2 * Ralink SoC specific prom routines
4 * Copyright (C) 2010 Joonas Lahtinen <joonas.lahtinen@gmail.com>
5 * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/string.h>
16 #include <asm/bootinfo.h>
17 #include <asm/addrspace.h>
19 #include <asm/mach-ralink/common.h>
20 #include <asm/mach-ralink/machine.h>
22 unsigned long ramips_mem_base
;
23 unsigned long ramips_mem_size_min
;
24 unsigned long ramips_mem_size_max
;
26 static inline void *to_ram_addr(void *addr
)
30 base
= KSEG0ADDR(ramips_mem_base
);
31 if (((u32
) addr
> base
) &&
32 ((u32
) addr
< (base
+ ramips_mem_size_max
)))
35 base
= KSEG1ADDR(ramips_mem_base
);
36 if (((u32
) addr
> base
) &&
37 ((u32
) addr
< (base
+ ramips_mem_size_max
)))
40 /* some U-Boot variants uses physical addresses */
41 base
= ramips_mem_base
;
42 if (((u32
) addr
> base
) &&
43 ((u32
) addr
< (base
+ ramips_mem_size_max
)))
44 return (void *)KSEG0ADDR(addr
);
49 static char ramips_cmdline_buf
[COMMAND_LINE_SIZE
] __initdata
;
50 static void __init
prom_append_cmdline(const char *name
,
53 snprintf(ramips_cmdline_buf
, sizeof(ramips_cmdline_buf
),
54 " %s=%s", name
, value
);
55 strlcat(arcs_cmdline
, ramips_cmdline_buf
, sizeof(arcs_cmdline
));
58 #ifdef CONFIG_IMAGE_CMDLINE_HACK
59 extern char __image_cmdline
[];
61 static int __init
use_image_cmdline(void)
63 char *p
= __image_cmdline
;
75 strlcpy(arcs_cmdline
, p
, sizeof(arcs_cmdline
));
77 strlcat(arcs_cmdline
, " ", sizeof(arcs_cmdline
));
78 strlcat(arcs_cmdline
, p
, sizeof(arcs_cmdline
));
84 static int inline use_image_cmdline(void) { return 0; }
87 static __init
void prom_init_cmdline(int argc
, char **argv
)
91 if (use_image_cmdline())
95 printk(KERN_DEBUG
"argv=%p is invalid, skipping\n",
100 for (i
= 0; i
< argc
; i
++) {
101 char *p
= to_ram_addr(argv
[i
]);
105 "argv[%d]=%p is invalid, skipping\n",
110 printk(KERN_DEBUG
"argv[%d]: %s\n", i
, p
);
111 strlcat(arcs_cmdline
, " ", sizeof(arcs_cmdline
));
112 strlcat(arcs_cmdline
, p
, sizeof(arcs_cmdline
));
116 static __init
char *prom_append_env(char **env
, const char *envname
)
118 #define PROM_MAX_ENVS 256
119 int len
= strlen(envname
);
123 printk(KERN_DEBUG
"env=%p is not in RAM, skipping\n",
128 for (i
= 0; i
< PROM_MAX_ENVS
; i
++) {
129 char *p
= to_ram_addr(env
[i
]);
134 printk(KERN_DEBUG
"env[%d]: %s\n", i
, p
);
135 if (strncmp(envname
, p
, len
) == 0 && p
[len
] == '=')
136 prom_append_cmdline(envname
, p
+ len
+ 1);
143 void __init
prom_init(void)
149 ramips_soc_prom_init();
152 "prom: fw_arg0=%08x, fw_arg1=%08x, fw_arg2=%08x, fw_arg3=%08x\n",
153 (unsigned int)fw_arg0
, (unsigned int)fw_arg1
,
154 (unsigned int)fw_arg2
, (unsigned int)fw_arg3
);
157 argv
= to_ram_addr((void *)fw_arg1
);
158 prom_init_cmdline(argc
, argv
);
160 envp
= to_ram_addr((void *)fw_arg2
);
161 prom_append_env(envp
, "board");
162 prom_append_env(envp
, "ethaddr");
165 void __init
prom_free_prom_memory(void)
167 /* We do not have to prom memory to free */
This page took 0.050364 seconds and 5 git commands to generate.