1a27f1a9656589a32f8a53a61537fafa49d9b595
[openwrt/svn-archive/archive.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 #include <asm/bootinfo.h>
24 #include <asm/ifxmips/ifxmips.h>
25
26 static char buf[1024]; /* for prom_printf() */
27
28 /* for voice cpu (MIPS24K) */
29 unsigned int *prom_cp1_base;
30 unsigned int prom_cp1_size;
31
32 /* for Multithreading (APRP) on MIPS34K */
33 unsigned long physical_memsize;
34
35 /* early printk on asc0 or asc1 ? */
36 #ifdef CONFIG_IFXMIPS_PROM_ASC0
37 #define IFXMIPS_ASC_DIFF 0
38 #else
39 #define IFXMIPS_ASC_DIFF IFXMIPS_ASC_BASE_DIFF
40 #endif
41
42 static inline u32 asc_r32(unsigned long r)
43 {
44 return ifxmips_r32((u32 *)(IFXMIPS_ASC_BASE_ADDR + IFXMIPS_ASC_DIFF + r));
45 }
46
47 static inline void asc_w32(u32 v, unsigned long r)
48 {
49 ifxmips_w32(v, (u32 *)(IFXMIPS_ASC_BASE_ADDR + IFXMIPS_ASC_DIFF + r));
50 }
51
52 void prom_free_prom_memory(void)
53 {
54 }
55
56 void prom_putchar(char c)
57 {
58 unsigned long flags;
59
60 local_irq_save(flags);
61 while ((asc_r32(IFXMIPS_ASC_FSTAT) & ASCFSTAT_TXFFLMASK) >> ASCFSTAT_TXFFLOFF)
62 ;
63
64 if (c == '\n')
65 asc_w32('\r', IFXMIPS_ASC_TBUF);
66 asc_w32(c, IFXMIPS_ASC_TBUF);
67 local_irq_restore(flags);
68 }
69
70 void prom_printf(const char *fmt, ...)
71 {
72 va_list args;
73 int l;
74 char *p, *buf_end;
75
76 va_start(args, fmt);
77 l = vsprintf(buf, fmt, args);
78 va_end(args);
79 buf_end = buf + l;
80
81 for (p = buf; p < buf_end; p++)
82 prom_putchar(*p);
83 }
84
85 unsigned int *prom_get_cp1_base(void)
86 {
87 return prom_cp1_base;
88 }
89 EXPORT_SYMBOL(prom_get_cp1_base);
90
91 unsigned int prom_get_cp1_size(void)
92 {
93 /* return size im MB */
94 return prom_cp1_size>>20;
95 }
96 EXPORT_SYMBOL(prom_get_cp1_size);
97
98 void __init prom_init(void)
99 {
100 int argc = fw_arg0;
101 char **argv = (char **) fw_arg1;
102 char **envp = (char **) fw_arg2;
103
104 int memsize = 16; /* assume 16M as default */
105 int i;
106
107 mips_machtype = MACH_INFINEON_IFXMIPS;
108
109 if (argc) {
110 argv = (char **)KSEG1ADDR((unsigned long)argv);
111 arcs_cmdline[0] = '\0';
112 for (i = 1; i < argc; i++) {
113 char *a = (char *)KSEG1ADDR(argv[i]);
114 if (!argv[i])
115 continue;
116 /* for voice cpu on Twinpass/Danube */
117 if (cpu_data[0].cputype == CPU_24K)
118 if (!strncmp(a, "cp1_size=", 9)) {
119 prom_cp1_size = memparse(a + 9, &a);
120 continue;
121 }
122 if (strlen(arcs_cmdline) + strlen(a + 1) >= sizeof(arcs_cmdline)) {
123 prom_printf("cmdline overflow, skipping: %s\n", a);
124 break;
125 }
126 strcat(arcs_cmdline, a);
127 strcat(arcs_cmdline, " ");
128 }
129 if (!*arcs_cmdline)
130 strcpy(&(arcs_cmdline[0]),
131 "console=ttyS0,115200 rootfstype=squashfs,jffs2");
132 }
133 envp = (char **)KSEG1ADDR((unsigned long)envp);
134 while (*envp) {
135 char *e = (char *)KSEG1ADDR(*envp);
136
137 if (!strncmp(e, "memsize=", 8)) {
138 e += 8;
139 memsize = simple_strtoul(e, NULL, 10);
140 }
141 envp++;
142 }
143 memsize *= 1024 * 1024;
144
145 /* only on Twinpass/Danube a second CPU is used for Voice */
146 if ((cpu_data[0].cputype == CPU_24K) && (prom_cp1_size)) {
147 memsize -= prom_cp1_size;
148 prom_cp1_base = (unsigned int *)KSEG1ADDR(memsize);
149
150 prom_printf("Using %dMB Ram and reserving %dMB for cp1\n",
151 memsize>>20, prom_cp1_size>>20);
152 }
153
154 add_memory_region(0x00000000, memsize, BOOT_MEM_RAM);
155 }