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