blob: 7d0a79be34d816ac885d7c4947d2360de1eb3b91 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 *
3 * BRIEF MODULE DESCRIPTION
4 * PROM library initialisation code, assuming a version of
5 * pmon is the boot code.
6 *
7 * Copyright 2000 MontaVista Software Inc.
8 * Author: MontaVista Software, Inc.
9 * ppopov@mvista.com or source@mvista.com
10 *
11 * This file was derived from Carsten Langgaard's
12 * arch/mips/mips-boards/xx files.
13 *
14 * Carsten Langgaard, carstenl@mips.com
15 * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
16 *
17 * This program is free software; you can redistribute it and/or modify it
18 * under the terms of the GNU General Public License as published by the
19 * Free Software Foundation; either version 2 of the License, or (at your
20 * option) any later version.
21 *
22 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
25 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 * You should have received a copy of the GNU General Public License along
34 * with this program; if not, write to the Free Software Foundation, Inc.,
35 * 675 Mass Ave, Cambridge, MA 02139, USA.
36 */
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <linux/kernel.h>
39#include <linux/init.h>
40#include <linux/string.h>
41
42#include <asm/bootinfo.h>
43
44extern int prom_argc;
45extern char **prom_argv, **prom_envp;
46
47typedef struct
48{
49 char *name;
50/* char *val; */
51}t_env_var;
52
53
54char * __init prom_getcmdline(void)
55{
56 return &(arcs_cmdline[0]);
57}
58
59void __init prom_init_cmdline(void)
60{
61 char *cp;
62 int actr;
63
64 actr = 1; /* Always ignore argv[0] */
65
66 cp = &(arcs_cmdline[0]);
67 while(actr < prom_argc) {
68 strcpy(cp, prom_argv[actr]);
69 cp += strlen(prom_argv[actr]);
70 *cp++ = ' ';
71 actr++;
72 }
73 if (cp != &(arcs_cmdline[0])) /* get rid of trailing space */
74 --cp;
75 *cp = '\0';
76
77}
78
79
80char *prom_getenv(char *envname)
81{
82 /*
83 * Return a pointer to the given environment variable.
84 * Environment variables are stored in the form of "memsize=64".
85 */
86
87 t_env_var *env = (t_env_var *)prom_envp;
88 int i;
89
90 i = strlen(envname);
91
92 while(env->name) {
93 if(strncmp(envname, env->name, i) == 0) {
94 return(env->name + strlen(envname) + 1);
95 }
96 env++;
97 }
98 return(NULL);
99}
100
101static inline unsigned char str2hexnum(unsigned char c)
102{
103 if(c >= '0' && c <= '9')
104 return c - '0';
105 if(c >= 'a' && c <= 'f')
106 return c - 'a' + 10;
107 return 0; /* foo */
108}
109
110unsigned long __init prom_free_prom_memory(void)
111{
112 return 0;
113}
114
115unsigned long __init prom_get_memsize(void)
116{
117 char *memsize_str;
118 unsigned int memsize;
119
120 memsize_str = prom_getenv("memsize");
121 if (!memsize_str) {
122#ifdef CONFIG_MIPS_ITE8172
123 memsize = 32;
124#elif defined(CONFIG_MIPS_IVR)
125 memsize = 64;
126#else
127 memsize = 8;
128#endif
129 printk("memsize unknown: setting to %dMB\n", memsize);
130 } else {
131 printk("memsize: %s\n", memsize_str);
132 memsize = simple_strtol(memsize_str, NULL, 0);
133 }
134 return memsize;
135}