lots of code cleanup for ifxmips
[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/bootmem.h>
22 #include <asm/bootinfo.h>
23 #include <asm/ifxmips/ifxmips.h>
24
25 static char buf[1024];
26 unsigned int *prom_cp1_base = NULL;
27 unsigned int prom_cp1_size = 0;
28
29 void
30 prom_free_prom_memory(void)
31 {
32 }
33
34 void
35 prom_putchar(char c)
36 {
37 while((ifxmips_r32(IFXMIPS_ASC1_FSTAT) & ASCFSTAT_TXFFLMASK) >> ASCFSTAT_TXFFLOFF);
38
39 if(c == '\n')
40 ifxmips_w32('\r', IFXMIPS_ASC1_TBUF);
41 ifxmips_w32(c, IFXMIPS_ASC1_TBUF);
42 }
43
44 void
45 prom_printf(const char * fmt, ...)
46 {
47 va_list args;
48 int l;
49 char *p, *buf_end;
50
51 va_start(args, fmt);
52 l = vsprintf(buf, fmt, args);
53 va_end(args);
54 buf_end = buf + l;
55
56 for(p = buf; p < buf_end; p++)
57 prom_putchar(*p);
58 }
59
60 unsigned int *prom_get_cp1_base(void)
61 {
62 return prom_cp1_base;
63 }
64
65 unsigned int prom_get_cp1_size(void)
66 {
67 return prom_cp1_size;
68 }
69
70 void __init
71 prom_init(void)
72 {
73 int argc = fw_arg0;
74 char **argv = (char **) fw_arg1;
75 char **envp = (char **) fw_arg2;
76
77 int memsize = 16;
78 int i;
79
80 mips_machtype = MACH_INFINEON_IFXMIPS;
81
82 argv = (char**)KSEG1ADDR((unsigned long)argv);
83 arcs_cmdline[0] = '\0';
84 for(i = 1; i < argc; i++)
85 {
86 char *a = (char*)KSEG1ADDR(argv[i]);
87 if(!a)
88 continue;
89 if(strlen(arcs_cmdline) + strlen(a + 1) >= sizeof(arcs_cmdline))
90 break;
91 strcat(arcs_cmdline, a);
92 strcat(arcs_cmdline, " ");
93 }
94
95 envp = (char**)KSEG1ADDR((unsigned long)envp);
96 while(*envp)
97 {
98 char *e = (char*)KSEG1ADDR(*envp);
99
100 if(!strncmp(e, "memsize=", 8))
101 {
102 e += 8;
103 memsize = simple_strtoul(e, NULL, 10);
104 }
105 envp++;
106 }
107
108 prom_cp1_size = 2;
109 memsize -= prom_cp1_size;
110 prom_cp1_base = (unsigned int*)(0xA0000000 + (memsize * 1024 * 1024));
111
112 prom_printf(KERN_INFO "Using %dMB Ram and reserving %dMB for cp1\n",
113 memsize, prom_cp1_size);
114 memsize *= 1024 * 1024;
115
116 if(!*arcs_cmdline)
117 strcpy(&(arcs_cmdline[0]),
118 "console=ttyS0,115200 rootfstype=squashfs,jffs2 init=/etc/preinit");
119
120 add_memory_region(0x00000000, memsize, BOOT_MEM_RAM);
121 }