ramips: rt305x: remove per-board physmap_flash_data instances
[openwrt.git] / target / linux / ramips / files / arch / mips / ralink / common / prom.c
1 /*
2 * Ralink SoC specific prom routines
3 *
4 * Copyright (C) 2010 Joonas Lahtinen <joonas.lahtinen@gmail.com>
5 * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
6 *
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.
10 */
11
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/string.h>
15
16 #include <asm/bootinfo.h>
17 #include <asm/addrspace.h>
18
19 #include <asm/mach-ralink/common.h>
20 #include <asm/mach-ralink/machine.h>
21 #include <ralink_soc.h>
22
23 static inline void *to_ram_addr(void *addr)
24 {
25 u32 base;
26
27 base = KSEG0ADDR(RALINK_SOC_SDRAM_BASE);
28 if (((u32) addr > base) &&
29 ((u32) addr < (base + RALINK_SOC_MEM_SIZE_MAX)))
30 return addr;
31
32 base = KSEG1ADDR(RALINK_SOC_SDRAM_BASE);
33 if (((u32) addr > base) &&
34 ((u32) addr < (base + RALINK_SOC_MEM_SIZE_MAX)))
35 return addr;
36
37 /* some U-Boot variants uses physical addresses */
38 base = RALINK_SOC_SDRAM_BASE;
39 if (((u32) addr > base) &&
40 ((u32) addr < (base + RALINK_SOC_MEM_SIZE_MAX)))
41 return (void *)KSEG0ADDR(addr);
42
43 return NULL;
44 }
45
46 static char ramips_cmdline_buf[COMMAND_LINE_SIZE] __initdata;
47 static void __init prom_append_cmdline(const char *name,
48 const char *value)
49 {
50 snprintf(ramips_cmdline_buf, sizeof(ramips_cmdline_buf),
51 " %s=%s", name, value);
52 strlcat(arcs_cmdline, ramips_cmdline_buf, sizeof(arcs_cmdline));
53 }
54
55 #ifdef CONFIG_IMAGE_CMDLINE_HACK
56 extern char __image_cmdline[];
57
58 static int __init use_image_cmdline(void)
59 {
60 char *p = __image_cmdline;
61 int replace = 0;
62
63 if (*p == '-') {
64 replace = 1;
65 p++;
66 }
67
68 if (*p == '\0')
69 return 0;
70
71 if (replace) {
72 strlcpy(arcs_cmdline, p, sizeof(arcs_cmdline));
73 } else {
74 strlcat(arcs_cmdline, " ", sizeof(arcs_cmdline));
75 strlcat(arcs_cmdline, p, sizeof(arcs_cmdline));
76 }
77
78 return 1;
79 }
80 #else
81 static int inline use_image_cmdline(void) { return 0; }
82 #endif
83
84 static __init void prom_init_cmdline(int argc, char **argv)
85 {
86 int i;
87
88 if (use_image_cmdline())
89 return;
90
91 if (!argv) {
92 printk(KERN_DEBUG "argv=%p is invalid, skipping\n",
93 argv);
94 return;
95 }
96
97 for (i = 0; i < argc; i++) {
98 char *p = to_ram_addr(argv[i]);
99
100 if (!p) {
101 printk(KERN_DEBUG
102 "argv[%d]=%p is invalid, skipping\n",
103 i, argv[i]);
104 continue;
105 }
106
107 printk(KERN_DEBUG "argv[%d]: %s\n", i, p);
108 strlcat(arcs_cmdline, " ", sizeof(arcs_cmdline));
109 strlcat(arcs_cmdline, p, sizeof(arcs_cmdline));
110 }
111 }
112
113 static __init char *prom_append_env(char **env, const char *envname)
114 {
115 #define PROM_MAX_ENVS 256
116 int len = strlen(envname);
117 int i;
118
119 if (!env) {
120 printk(KERN_DEBUG "env=%p is not in RAM, skipping\n",
121 env);
122 return NULL;
123 }
124
125 for (i = 0; i < PROM_MAX_ENVS; i++) {
126 char *p = to_ram_addr(env[i]);
127
128 if (!p)
129 break;
130
131 printk(KERN_DEBUG "env[%d]: %s\n", i, p);
132 if (strncmp(envname, p, len) == 0 && p[len] == '=')
133 prom_append_cmdline(envname, p + len + 1);
134 }
135
136 return NULL;
137 #undef PROM_MAX_ENVS
138 }
139
140 void __init prom_init(void)
141 {
142 int argc;
143 char **envp;
144 char **argv;
145
146 printk(KERN_DEBUG
147 "prom: fw_arg0=%08x, fw_arg1=%08x, fw_arg2=%08x, fw_arg3=%08x\n",
148 (unsigned int)fw_arg0, (unsigned int)fw_arg1,
149 (unsigned int)fw_arg2, (unsigned int)fw_arg3);
150
151 argc = fw_arg0;
152 argv = to_ram_addr((void *)fw_arg1);
153 prom_init_cmdline(argc, argv);
154
155 envp = to_ram_addr((void *)fw_arg2);
156 prom_append_env(envp, "board");
157 prom_append_env(envp, "ethaddr");
158 }
159
160 void __init prom_free_prom_memory(void)
161 {
162 /* We do not have to prom memory to free */
163 }
This page took 0.107179 seconds and 5 git commands to generate.