[package] block-extroot: r20784 reverted r20735, add it back (#7104)
[15.05/openwrt.git] / target / linux / ifxmips / files / arch / mips / ifxmips / prom.c
1 /*
2  *   This program is free software; you can redistribute it and/or modify
3  *   it under the terms of the GNU General Public License as published by
4  *   the Free Software Foundation; either version 2 of the License, or
5  *   (at your option) any later version.
6  *
7  *   This program is distributed in the hope that it will be useful,
8  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *   GNU General Public License for more details.
11  *
12  *   You should have received a copy of the GNU General Public License
13  *   along with this program; if not, write to the Free Software
14  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
15  *
16  *   Copyright (C) 2005 Wu Qi Ming infineon
17  *   Copyright (C) 2007 John Crispin <blogic@openwrt.org>
18  */
19
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/bootmem.h>
23
24 #include <asm/bootinfo.h>
25
26 #include <ifxmips.h>
27
28 static char buf[1024]; /* for prom_printf() */
29
30 /* for voice cpu (MIPS24K) */
31 unsigned int *prom_cp1_base;
32 unsigned int prom_cp1_size;
33
34 /* for Multithreading (APRP) on MIPS34K */
35 unsigned long physical_memsize;
36
37 /* early printk on asc0 or asc1 ? */
38 #ifdef CONFIG_IFXMIPS_PROM_ASC0
39 #define IFXMIPS_ASC_DIFF        0
40 #else
41 #define IFXMIPS_ASC_DIFF        IFXMIPS_ASC_BASE_DIFF
42 #endif
43
44 static inline u32 asc_r32(unsigned long r)
45 {
46         return ifxmips_r32((u32 *)(IFXMIPS_ASC_BASE_ADDR + IFXMIPS_ASC_DIFF + r));
47 }
48
49 static inline void asc_w32(u32 v, unsigned long r)
50 {
51         ifxmips_w32(v, (u32 *)(IFXMIPS_ASC_BASE_ADDR + IFXMIPS_ASC_DIFF + r));
52 }
53
54 void prom_free_prom_memory(void)
55 {
56 }
57
58 void prom_putchar(char c)
59 {
60         unsigned long flags;
61
62         local_irq_save(flags);
63         while ((asc_r32(IFXMIPS_ASC_FSTAT) & ASCFSTAT_TXFFLMASK) >> ASCFSTAT_TXFFLOFF)
64                 ;
65
66         if (c == '\n')
67                 asc_w32('\r', IFXMIPS_ASC_TBUF);
68         asc_w32(c, IFXMIPS_ASC_TBUF);
69         local_irq_restore(flags);
70 }
71
72 void prom_printf(const char *fmt, ...)
73 {
74         va_list args;
75         int l;
76         char *p, *buf_end;
77
78         va_start(args, fmt);
79         l = vsprintf(buf, fmt, args);
80         va_end(args);
81         buf_end = buf + l;
82
83         for (p = buf; p < buf_end; p++)
84                 prom_putchar(*p);
85 }
86
87 unsigned int *prom_get_cp1_base(void)
88 {
89         return prom_cp1_base;
90 }
91 EXPORT_SYMBOL(prom_get_cp1_base);
92
93 unsigned int prom_get_cp1_size(void)
94 {
95         /* return size im MB */
96         return prom_cp1_size>>20;
97 }
98 EXPORT_SYMBOL(prom_get_cp1_size);
99
100 void __init prom_init(void)
101 {
102         int argc = fw_arg0;
103         char **argv = (char **) fw_arg1;
104         char **envp = (char **) fw_arg2;
105
106         int memsize = 16; /* assume 16M as default */
107         int i;
108
109         mips_machtype = MACH_INFINEON_IFXMIPS;
110
111         if (argc) {
112                 argv = (char **)KSEG1ADDR((unsigned long)argv);
113                 arcs_cmdline[0] = '\0';
114                 for (i = 1; i < argc; i++) {
115                         char *a = (char *)KSEG1ADDR(argv[i]);
116                         if (!argv[i])
117                                 continue;
118                         /* for voice cpu on Twinpass/Danube */
119                         if (cpu_data[0].cputype == CPU_24K)
120                                 if (!strncmp(a, "cp1_size=", 9)) {
121                                         prom_cp1_size = memparse(a + 9, &a);
122                                         continue;
123                                 }
124                         if (strlen(arcs_cmdline) + strlen(a + 1) >= sizeof(arcs_cmdline)) {
125                                 prom_printf("cmdline overflow, skipping: %s\n", a);
126                                 break;
127                         }
128                         strcat(arcs_cmdline, a);
129                         strcat(arcs_cmdline, " ");
130                 }
131                 if (!*arcs_cmdline)
132                         strcpy(&(arcs_cmdline[0]),
133                                 "console=ttyS0,115200 rootfstype=squashfs,jffs2");
134         }
135         envp = (char **)KSEG1ADDR((unsigned long)envp);
136         while (*envp) {
137                 char *e = (char *)KSEG1ADDR(*envp);
138
139                 if (!strncmp(e, "memsize=", 8)) {
140                         e += 8;
141                         memsize = simple_strtoul(e, NULL, 10);
142                 }
143                 envp++;
144         }
145         memsize *= 1024 * 1024;
146
147         /* only on Twinpass/Danube a second CPU is used for Voice */
148         if ((cpu_data[0].cputype == CPU_24K) && (prom_cp1_size)) {
149                 memsize -= prom_cp1_size;
150                 prom_cp1_base = (unsigned int *)KSEG1ADDR(memsize);
151
152                 prom_printf("Using %dMB Ram and reserving %dMB for cp1\n",
153                         memsize>>20, prom_cp1_size>>20);
154         }
155
156         add_memory_region(0x00000000, memsize, BOOT_MEM_RAM);
157 }