fixes several compile errors, reserves memory for second core, adds u-boot env parsin...
[openwrt/svn-archive/archive.git] / target / linux / ifxmips / files / arch / mips / ifxmips / prom.c
1 /*
2 * arch/mips/ifxmips/prom.c
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
17 *
18 * Copyright (C) 2005 Wu Qi Ming infineon
19 *
20 * Rewrite of Infineon IFXMips code, thanks to infineon for the support,
21 * software and hardware
22 *
23 * Copyright (C) 2007 John Crispin <blogic@openwrt.org>
24 *
25 */
26
27 #include <linux/init.h>
28 #include <linux/bootmem.h>
29 #include <asm/bootinfo.h>
30 #include <asm/ifxmips/ifxmips.h>
31
32
33 static char buf[1024];
34 u32 *prom_cp1_base = NULL;
35 u32 prom_cp1_size = 0;
36
37 void
38 prom_free_prom_memory(void)
39 {
40 }
41
42 void
43 prom_putchar(char c)
44 {
45 while((ifxmips_r32(IFXMIPS_ASC1_FSTAT) & ASCFSTAT_TXFFLMASK) >> ASCFSTAT_TXFFLOFF);
46
47 if(c == '\n')
48 ifxmips_w32('\r', IFXMIPS_ASC1_TBUF);
49 ifxmips_w32(c, IFXMIPS_ASC1_TBUF);
50 }
51
52 void
53 prom_printf(const char * fmt, ...)
54 {
55 va_list args;
56 int l;
57 char *p, *buf_end;
58
59 va_start(args, fmt);
60 l = vsprintf(buf, fmt, args);
61 va_end(args);
62 buf_end = buf + l;
63
64 for(p = buf; p < buf_end; p++)
65 {
66 prom_putchar(*p);
67 }
68 }
69
70 u32 *prom_get_cp1_base(void)
71 {
72 return prom_cp1_base;
73 }
74
75 u32 prom_get_cp1_size(void)
76 {
77 return prom_cp1_size;
78 }
79
80 void __init
81 prom_init(void)
82 {
83 int argc = fw_arg0;
84 char **argv = (char **) fw_arg1;
85 char **envp = (char **) fw_arg2;
86
87 int memsize = 16;
88 int i;
89
90 mips_machtype = MACH_INFINEON_IFXMIPS;
91
92 argv = (char**)KSEG1ADDR((unsigned long)argv);
93 arcs_cmdline[0] = '\0';
94 for(i = 1; i < argc; i++)
95 {
96 char *a = (char*)KSEG1ADDR(argv[i]);
97 if(!a)
98 continue;
99 if(strlen(arcs_cmdline) + strlen(a + 1) >= sizeof(arcs_cmdline))
100 break;
101 strcat(arcs_cmdline, a);
102 strcat(arcs_cmdline, " ");
103 }
104
105 envp = (char**)KSEG1ADDR((unsigned long)envp);
106 while(*envp)
107 {
108 char *e = (char*)KSEG1ADDR(*envp);
109
110 if(!strncmp(e, "memsize=", 8))
111 {
112 e += 8;
113 memsize = simple_strtoul(e, NULL, 10);
114 }
115 envp++;
116 }
117
118 prom_cp1_size = 2;
119 memsize -= prom_cp1_size;
120 prom_cp1_base = (u32*)(0xA0000000 + (memsize * 1024 * 1024));
121
122 prom_printf(KERN_INFO "Using %dMB Ram and reserving %dMB for cp1\n", memsize, prom_cp1_size);
123 memsize *= 1024 * 1024;
124
125 if(!*arcs_cmdline)
126 strcpy(&(arcs_cmdline[0]), "console=ttyS0,115200 rootfstype=squashfs,jffs2 init=/etc/preinit");
127
128 add_memory_region(0x00000000, memsize, BOOT_MEM_RAM);
129 }