/*1* Copyright (C) 2004 Florian Schirmer <[email protected]>2* Copyright (C) 2007 Aurelien Jarno <[email protected]>3*4* This program is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License as published by the6* Free Software Foundation; either version 2 of the License, or (at your7* option) any later version.8*9* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED10* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF11* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN12* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,13* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT14* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF15* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON16* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT17* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF18* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.19*20* You should have received a copy of the GNU General Public License along21* with this program; if not, write to the Free Software Foundation, Inc.,22* 675 Mass Ave, Cambridge, MA 02139, USA.23*/2425#include <linux/init.h>26#include <linux/types.h>27#include <linux/kernel.h>28#include <linux/spinlock.h>29#include <asm/bootinfo.h>30#include <asm/fw/cfe/cfe_api.h>31#include <asm/fw/cfe/cfe_error.h>3233static int cfe_cons_handle;3435const char *get_system_type(void)36{37return "Broadcom BCM47XX";38}3940void prom_putchar(char c)41{42while (cfe_write(cfe_cons_handle, &c, 1) == 0)43;44}4546static __init void prom_init_cfe(void)47{48uint32_t cfe_ept;49uint32_t cfe_handle;50uint32_t cfe_eptseal;51int argc = fw_arg0;52char **envp = (char **) fw_arg2;53int *prom_vec = (int *) fw_arg3;5455/*56* Check if a loader was used; if NOT, the 4 arguments are57* what CFE gives us (handle, 0, EPT and EPTSEAL)58*/59if (argc < 0) {60cfe_handle = (uint32_t)argc;61cfe_ept = (uint32_t)envp;62cfe_eptseal = (uint32_t)prom_vec;63} else {64if ((int)prom_vec < 0) {65/*66* Old loader; all it gives us is the handle,67* so use the "known" entrypoint and assume68* the seal.69*/70cfe_handle = (uint32_t)prom_vec;71cfe_ept = 0xBFC00500;72cfe_eptseal = CFE_EPTSEAL;73} else {74/*75* Newer loaders bundle the handle/ept/eptseal76* Note: prom_vec is in the loader's useg77* which is still alive in the TLB.78*/79cfe_handle = prom_vec[0];80cfe_ept = prom_vec[2];81cfe_eptseal = prom_vec[3];82}83}8485if (cfe_eptseal != CFE_EPTSEAL) {86/* too early for panic to do any good */87printk(KERN_ERR "CFE's entrypoint seal doesn't match.");88while (1) ;89}9091cfe_init(cfe_handle, cfe_ept);92}9394static __init void prom_init_console(void)95{96/* Initialize CFE console */97cfe_cons_handle = cfe_getstdhandle(CFE_STDHANDLE_CONSOLE);98}99100static __init void prom_init_cmdline(void)101{102static char buf[COMMAND_LINE_SIZE] __initdata;103104/* Get the kernel command line from CFE */105if (cfe_getenv("LINUX_CMDLINE", buf, COMMAND_LINE_SIZE) >= 0) {106buf[COMMAND_LINE_SIZE - 1] = 0;107strcpy(arcs_cmdline, buf);108}109110/* Force a console handover by adding a console= argument if needed,111* as CFE is not available anymore later in the boot process. */112if ((strstr(arcs_cmdline, "console=")) == NULL) {113/* Try to read the default serial port used by CFE */114if ((cfe_getenv("BOOT_CONSOLE", buf, COMMAND_LINE_SIZE) < 0)115|| (strncmp("uart", buf, 4)))116/* Default to uart0 */117strcpy(buf, "uart0");118119/* Compute the new command line */120snprintf(arcs_cmdline, COMMAND_LINE_SIZE, "%s console=ttyS%c,115200",121arcs_cmdline, buf[4]);122}123}124125static __init void prom_init_mem(void)126{127unsigned long mem;128unsigned long max;129130/* Figure out memory size by finding aliases.131*132* We should theoretically use the mapping from CFE using cfe_enummem().133* However as the BCM47XX is mostly used on low-memory systems, we134* want to reuse the memory used by CFE (around 4MB). That means cfe_*135* functions stop to work at some point during the boot, we should only136* call them at the beginning of the boot.137*138* BCM47XX uses 128MB for addressing the ram, if the system contains139* less that that amount of ram it remaps the ram more often into the140* available space.141* Accessing memory after 128MB will cause an exception.142* max contains the biggest possible address supported by the platform.143* If the method wants to try something above we assume 128MB ram.144*/145max = ((unsigned long)(prom_init) | ((128 << 20) - 1));146for (mem = (1 << 20); mem < (128 << 20); mem += (1 << 20)) {147if (((unsigned long)(prom_init) + mem) > max) {148mem = (128 << 20);149printk(KERN_DEBUG "assume 128MB RAM\n");150break;151}152if (*(unsigned long *)((unsigned long)(prom_init) + mem) ==153*(unsigned long *)(prom_init))154break;155}156157add_memory_region(0, mem, BOOT_MEM_RAM);158}159160void __init prom_init(void)161{162prom_init_cfe();163prom_init_console();164prom_init_cmdline();165prom_init_mem();166}167168void __init prom_free_prom_memory(void)169{170}171172173