blob: 5bd9d8f468cc3582ab02114ff272b833d8893565 [file] [log] [blame]
David VomLehna3a0f8c2009-08-30 17:15:11 -07001/*
Ralf Baechle70342282013-01-22 12:59:30 +01002 * Copyright (C) 1999, 2000, 2004, 2005 MIPS Technologies, Inc.
David VomLehna3a0f8c2009-08-30 17:15:11 -07003 * All rights reserved.
4 * Authors: Carsten Langgaard <carstenl@mips.com>
5 * Maciej W. Rozycki <macro@mips.com>
6 * Portions copyright (C) 2009 Cisco Systems, Inc.
7 *
8 * This program is free software; you can distribute it and/or modify it
9 * under the terms of the GNU General Public License (Version 2) as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
20 *
21 * PROM library initialisation code.
22 */
23#include <linux/init.h>
24#include <linux/string.h>
25#include <linux/kernel.h>
26
27#include <asm/bootinfo.h>
28#include <linux/io.h>
David VomLehna3a0f8c2009-08-30 17:15:11 -070029#include <asm/cacheflush.h>
30#include <asm/traps.h>
31
32#include <asm/mips-boards/prom.h>
33#include <asm/mips-boards/generic.h>
34#include <asm/mach-powertv/asic.h>
35
Yoichi Yuasa7e326d62009-12-18 21:38:37 +090036static int *_prom_envp;
David VomLehna3a0f8c2009-08-30 17:15:11 -070037unsigned long _prom_memsize;
38
39/*
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)])
44
45char *prom_getenv(char *envname)
46{
47 char *result = NULL;
48
49 if (_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 pointers
53 * in the PROM structures are only 32-bit, so we need some
54 * workarounds, if we are running in 64-bit mode.
55 */
56 int i, index = 0;
57
58 i = strlen(envname);
59
60 while (prom_envp(index)) {
61 if (strncmp(envname, prom_envp(index), i) == 0) {
62 result = prom_envp(index + 1);
63 break;
64 }
65 index += 2;
66 }
67 }
68
69 return result;
70}
71
David VomLehna3a0f8c2009-08-30 17:15:11 -070072void __init prom_init(void)
73{
Yoichi Yuasa7e326d62009-12-18 21:38:37 +090074 int prom_argc;
75 char *prom_argv;
76
David VomLehna3a0f8c2009-08-30 17:15:11 -070077 prom_argc = fw_arg0;
Yoichi Yuasa7e326d62009-12-18 21:38:37 +090078 prom_argv = (char *) fw_arg1;
David VomLehna3a0f8c2009-08-30 17:15:11 -070079 _prom_envp = (int *) fw_arg2;
80 _prom_memsize = (unsigned long) fw_arg3;
81
David VomLehn0d590502010-07-01 13:37:52 -070082 if (prom_argc == 1) {
83 strlcat(arcs_cmdline, " ", COMMAND_LINE_SIZE);
Yoichi Yuasa7e326d62009-12-18 21:38:37 +090084 strlcat(arcs_cmdline, prom_argv, COMMAND_LINE_SIZE);
David VomLehn0d590502010-07-01 13:37:52 -070085 }
Yoichi Yuasa7e326d62009-12-18 21:38:37 +090086
David VomLehna3a0f8c2009-08-30 17:15:11 -070087 configure_platform();
88 prom_meminit();
89
90#ifndef CONFIG_BOOTLOADER_DRIVER
91 pr_info("\nBootloader driver isn't loaded...\n");
92#endif
93}