/*1* Copyright (C) 1999, 2000, 2004, 2005 MIPS Technologies, Inc.2* All rights reserved.3* Authors: Carsten Langgaard <[email protected]>4* Maciej W. Rozycki <[email protected]>5* Portions copyright (C) 2009 Cisco Systems, Inc.6*7* This program is free software; you can distribute it and/or modify it8* under the terms of the GNU General Public License (Version 2) as9* published by the Free Software Foundation.10*11* This program is distributed in the hope it will be useful, but WITHOUT12* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or13* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License14* for more details.15*16* You should have received a copy of the GNU General Public License along17* with this program; if not, write to the Free Software Foundation, Inc.,18* 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.19*20* PROM library initialisation code.21*/22#include <linux/init.h>23#include <linux/string.h>24#include <linux/kernel.h>2526#include <asm/bootinfo.h>27#include <linux/io.h>28#include <asm/system.h>29#include <asm/cacheflush.h>30#include <asm/traps.h>3132#include <asm/mips-boards/prom.h>33#include <asm/mips-boards/generic.h>34#include <asm/mach-powertv/asic.h>3536static int *_prom_envp;37unsigned long _prom_memsize;3839/*40* YAMON (32-bit PROM) pass arguments and environment as 32-bit pointer.41* This macro take care of sign extension, if running in 64-bit mode.42*/43#define prom_envp(index) ((char *)(long)_prom_envp[(index)])4445char *prom_getenv(char *envname)46{47char *result = NULL;4849if (_prom_envp != NULL) {50/*51* Return a pointer to the given environment variable.52* In 64-bit mode: we're using 64-bit pointers, but all pointers53* in the PROM structures are only 32-bit, so we need some54* workarounds, if we are running in 64-bit mode.55*/56int i, index = 0;5758i = strlen(envname);5960while (prom_envp(index)) {61if (strncmp(envname, prom_envp(index), i) == 0) {62result = prom_envp(index + 1);63break;64}65index += 2;66}67}6869return result;70}7172/* TODO: Verify on linux-mips mailing list that the following two */73/* functions are correct */74/* TODO: Copy NMI and EJTAG exception vectors to memory from the */75/* BootROM exception vectors. Flush their cache entries. test it. */7677static void __init mips_nmi_setup(void)78{79void *base;80#if defined(CONFIG_CPU_MIPS32_R1)81base = cpu_has_veic ?82(void *)(CAC_BASE + 0xa80) :83(void *)(CAC_BASE + 0x380);84#elif defined(CONFIG_CPU_MIPS32_R2)85base = (void *)0xbfc00000;86#else87#error NMI exception handler address not defined88#endif89}9091static void __init mips_ejtag_setup(void)92{93void *base;9495#if defined(CONFIG_CPU_MIPS32_R1)96base = cpu_has_veic ?97(void *)(CAC_BASE + 0xa00) :98(void *)(CAC_BASE + 0x300);99#elif defined(CONFIG_CPU_MIPS32_R2)100base = (void *)0xbfc00480;101#else102#error EJTAG exception handler address not defined103#endif104}105106void __init prom_init(void)107{108int prom_argc;109char *prom_argv;110111prom_argc = fw_arg0;112prom_argv = (char *) fw_arg1;113_prom_envp = (int *) fw_arg2;114_prom_memsize = (unsigned long) fw_arg3;115116board_nmi_handler_setup = mips_nmi_setup;117board_ejtag_handler_setup = mips_ejtag_setup;118119if (prom_argc == 1) {120strlcat(arcs_cmdline, " ", COMMAND_LINE_SIZE);121strlcat(arcs_cmdline, prom_argv, COMMAND_LINE_SIZE);122}123124configure_platform();125prom_meminit();126127#ifndef CONFIG_BOOTLOADER_DRIVER128pr_info("\nBootloader driver isn't loaded...\n");129#endif130}131132133