880febc62bc49a8edb0efe3a64f97d2f6f69b7c3
[10.03/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 #include <asm/bootinfo.h>
24 #include <asm/ifxmips/ifxmips.h>
25
26 static char buf[1024];
27 unsigned int *prom_cp1_base = NULL;
28 unsigned int prom_cp1_size = 0;
29
30 #ifdef IFXMIPS_PROM_ASC0
31 #define IFXMIPS_ASC_DIFF        0
32 #else
33 #define IFXMIPS_ASC_DIFF        IFXMIPS_ASC_BASE_DIFF
34 #endif
35
36 static inline u32
37 asc_r32(unsigned long r)
38 {
39         return ifxmips_r32((u32*)(IFXMIPS_ASC_BASE_ADDR + IFXMIPS_ASC_DIFF + r));
40 }
41
42 static inline void
43 asc_w32(u32 v, unsigned long r)
44 {
45         ifxmips_w32(v, (u32*)(IFXMIPS_ASC_BASE_ADDR + IFXMIPS_ASC_DIFF + r));
46 }
47
48 void
49 prom_free_prom_memory(void)
50 {
51 }
52
53 void
54 prom_putchar(char c)
55 {
56         unsigned long flags;
57
58         local_irq_save(flags);
59         while((asc_r32(IFXMIPS_ASC_FSTAT) & ASCFSTAT_TXFFLMASK) >> ASCFSTAT_TXFFLOFF);
60
61         if(c == '\n')
62                 asc_w32('\r', IFXMIPS_ASC_TBUF);
63         asc_w32(c, IFXMIPS_ASC_TBUF);
64         local_irq_restore(flags);
65 }
66
67 void
68 prom_printf(const char * fmt, ...)
69 {
70         va_list args;
71         int l;
72         char *p, *buf_end;
73
74         va_start(args, fmt);
75         l = vsprintf(buf, fmt, args);
76         va_end(args);
77         buf_end = buf + l;
78
79         for(p = buf; p < buf_end; p++)
80                 prom_putchar(*p);
81 }
82
83 unsigned int *prom_get_cp1_base(void)
84 {
85         return prom_cp1_base;
86 }
87 EXPORT_SYMBOL(prom_get_cp1_base);
88
89 unsigned int prom_get_cp1_size(void)
90 {
91         return prom_cp1_size;
92 }
93 EXPORT_SYMBOL(prom_get_cp1_size);
94
95 void __init
96 prom_init(void)
97 {
98         int argc = fw_arg0;
99         char **argv = (char **) fw_arg1;
100         char **envp = (char **) fw_arg2;
101
102         int memsize = 16;
103         int i;
104
105         mips_machtype = MACH_INFINEON_IFXMIPS;
106
107         argv = (char**)KSEG1ADDR((unsigned long)argv);
108         arcs_cmdline[0] = '\0';
109         for(i = 1; i < argc; i++)
110         {
111                 char *a = (char*)KSEG1ADDR(argv[i]);
112                 if(!a)
113                         continue;
114                 if(strlen(arcs_cmdline) + strlen(a + 1) >= sizeof(arcs_cmdline))
115                         break;
116                 strcat(arcs_cmdline, a);
117                 strcat(arcs_cmdline, " ");
118         }
119
120         envp = (char**)KSEG1ADDR((unsigned long)envp);
121         while(*envp)
122         {
123                 char *e = (char*)KSEG1ADDR(*envp);
124
125                 if(!strncmp(e, "memsize=", 8))
126                 {
127                         e += 8;
128                         memsize = simple_strtoul(e, NULL, 10);
129                 }
130                 envp++;
131         }
132
133         prom_cp1_size = 2;
134         memsize -= prom_cp1_size;
135         prom_cp1_base = (unsigned int*)(0xA0000000 + (memsize * 1024 * 1024));
136
137         prom_printf("Using %dMB Ram and reserving %dMB for cp1\n", memsize, prom_cp1_size);
138         memsize *= 1024 * 1024;
139
140         if(!*arcs_cmdline)
141                 strcpy(&(arcs_cmdline[0]),
142                         "console=ttyS0,115200 rootfstype=squashfs,jffs2 init=/etc/preinit");
143
144         add_memory_region(0x00000000, memsize, BOOT_MEM_RAM);
145 }