blob: 22258a4c652bdb2182d0d14e46614fa847ebf128 [file] [log] [blame]
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +02001/*
2 * Copyright (C) 2004 Florian Schirmer <jolt@tuxbox.org>
Aurelien Jarno25e5fb92007-09-25 15:41:24 +02003 * Copyright (C) 2007 Aurelien Jarno <aurelien@aurel32.net>
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +02004 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
11 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
13 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
14 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
15 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
16 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
17 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
18 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
19 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#include <linux/init.h>
Aurelien Jarno25e5fb92007-09-25 15:41:24 +020027#include <linux/types.h>
28#include <linux/kernel.h>
29#include <linux/spinlock.h>
Hauke Mehrtensd3dce3d2012-10-03 11:34:16 +000030#include <linux/smp.h>
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +020031#include <asm/bootinfo.h>
Aurelien Jarno25e5fb92007-09-25 15:41:24 +020032#include <asm/fw/cfe/cfe_api.h>
33#include <asm/fw/cfe/cfe_error.h>
34
35static int cfe_cons_handle;
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +020036
37const char *get_system_type(void)
38{
39 return "Broadcom BCM47XX";
40}
41
Aurelien Jarno25e5fb92007-09-25 15:41:24 +020042void prom_putchar(char c)
43{
44 while (cfe_write(cfe_cons_handle, &c, 1) == 0)
45 ;
46}
47
48static __init void prom_init_cfe(void)
49{
50 uint32_t cfe_ept;
51 uint32_t cfe_handle;
52 uint32_t cfe_eptseal;
53 int argc = fw_arg0;
54 char **envp = (char **) fw_arg2;
55 int *prom_vec = (int *) fw_arg3;
56
57 /*
58 * Check if a loader was used; if NOT, the 4 arguments are
59 * what CFE gives us (handle, 0, EPT and EPTSEAL)
60 */
61 if (argc < 0) {
62 cfe_handle = (uint32_t)argc;
63 cfe_ept = (uint32_t)envp;
64 cfe_eptseal = (uint32_t)prom_vec;
65 } else {
66 if ((int)prom_vec < 0) {
67 /*
68 * Old loader; all it gives us is the handle,
69 * so use the "known" entrypoint and assume
70 * the seal.
71 */
72 cfe_handle = (uint32_t)prom_vec;
73 cfe_ept = 0xBFC00500;
74 cfe_eptseal = CFE_EPTSEAL;
75 } else {
76 /*
77 * Newer loaders bundle the handle/ept/eptseal
78 * Note: prom_vec is in the loader's useg
79 * which is still alive in the TLB.
80 */
81 cfe_handle = prom_vec[0];
82 cfe_ept = prom_vec[2];
83 cfe_eptseal = prom_vec[3];
84 }
85 }
86
87 if (cfe_eptseal != CFE_EPTSEAL) {
88 /* too early for panic to do any good */
89 printk(KERN_ERR "CFE's entrypoint seal doesn't match.");
90 while (1) ;
91 }
92
93 cfe_init(cfe_handle, cfe_ept);
94}
95
96static __init void prom_init_console(void)
97{
98 /* Initialize CFE console */
99 cfe_cons_handle = cfe_getstdhandle(CFE_STDHANDLE_CONSOLE);
100}
101
102static __init void prom_init_cmdline(void)
103{
Dmitri Vorobiev7580c9c2009-10-13 23:43:24 +0300104 static char buf[COMMAND_LINE_SIZE] __initdata;
Aurelien Jarno25e5fb92007-09-25 15:41:24 +0200105
106 /* Get the kernel command line from CFE */
Dmitri Vorobiev7580c9c2009-10-13 23:43:24 +0300107 if (cfe_getenv("LINUX_CMDLINE", buf, COMMAND_LINE_SIZE) >= 0) {
108 buf[COMMAND_LINE_SIZE - 1] = 0;
Aurelien Jarno25e5fb92007-09-25 15:41:24 +0200109 strcpy(arcs_cmdline, buf);
110 }
111
112 /* Force a console handover by adding a console= argument if needed,
113 * as CFE is not available anymore later in the boot process. */
114 if ((strstr(arcs_cmdline, "console=")) == NULL) {
115 /* Try to read the default serial port used by CFE */
Dmitri Vorobiev7580c9c2009-10-13 23:43:24 +0300116 if ((cfe_getenv("BOOT_CONSOLE", buf, COMMAND_LINE_SIZE) < 0)
Aurelien Jarno25e5fb92007-09-25 15:41:24 +0200117 || (strncmp("uart", buf, 4)))
118 /* Default to uart0 */
119 strcpy(buf, "uart0");
120
121 /* Compute the new command line */
Dmitri Vorobiev7580c9c2009-10-13 23:43:24 +0300122 snprintf(arcs_cmdline, COMMAND_LINE_SIZE, "%s console=ttyS%c,115200",
Aurelien Jarno25e5fb92007-09-25 15:41:24 +0200123 arcs_cmdline, buf[4]);
124 }
125}
126
127static __init void prom_init_mem(void)
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +0200128{
129 unsigned long mem;
Hauke Mehrtensaec92222010-07-27 22:12:43 +0200130 unsigned long max;
Hauke Mehrtensd3dce3d2012-10-03 11:34:16 +0000131 struct cpuinfo_mips *c = &current_cpu_data;
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +0200132
Aurelien Jarno25e5fb92007-09-25 15:41:24 +0200133 /* Figure out memory size by finding aliases.
134 *
135 * We should theoretically use the mapping from CFE using cfe_enummem().
136 * However as the BCM47XX is mostly used on low-memory systems, we
137 * want to reuse the memory used by CFE (around 4MB). That means cfe_*
138 * functions stop to work at some point during the boot, we should only
139 * call them at the beginning of the boot.
Hauke Mehrtensaec92222010-07-27 22:12:43 +0200140 *
141 * BCM47XX uses 128MB for addressing the ram, if the system contains
142 * less that that amount of ram it remaps the ram more often into the
143 * available space.
144 * Accessing memory after 128MB will cause an exception.
145 * max contains the biggest possible address supported by the platform.
146 * If the method wants to try something above we assume 128MB ram.
Aurelien Jarno25e5fb92007-09-25 15:41:24 +0200147 */
Hauke Mehrtensaec92222010-07-27 22:12:43 +0200148 max = ((unsigned long)(prom_init) | ((128 << 20) - 1));
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +0200149 for (mem = (1 << 20); mem < (128 << 20); mem += (1 << 20)) {
Hauke Mehrtensaec92222010-07-27 22:12:43 +0200150 if (((unsigned long)(prom_init) + mem) > max) {
151 mem = (128 << 20);
152 printk(KERN_DEBUG "assume 128MB RAM\n");
153 break;
154 }
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +0200155 if (*(unsigned long *)((unsigned long)(prom_init) + mem) ==
156 *(unsigned long *)(prom_init))
157 break;
158 }
159
Hauke Mehrtensd3dce3d2012-10-03 11:34:16 +0000160 /* Ignoring the last page when ddr size is 128M. Cached
161 * accesses to last page is causing the processor to prefetch
162 * using address above 128M stepping out of the ddr address
163 * space.
164 */
165 if (c->cputype == CPU_74K && (mem == (128 << 20)))
166 mem -= 0x1000;
167
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +0200168 add_memory_region(0, mem, BOOT_MEM_RAM);
169}
170
Aurelien Jarno25e5fb92007-09-25 15:41:24 +0200171void __init prom_init(void)
172{
173 prom_init_cfe();
174 prom_init_console();
175 prom_init_cmdline();
176 prom_init_mem();
177}
178
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +0200179void __init prom_free_prom_memory(void)
180{
181}