2 * BRIEF MODULE DESCRIPTION
3 * PROM library initialisation code, assuming a version of
4 * pmon is the boot code.
6 * Copyright 2000,2001 MontaVista Software Inc.
7 * Author: MontaVista Software, Inc.
8 * ppopov@mvista.com or source@mvista.com
10 * This file was derived from Carsten Langgaard's
11 * arch/mips/mips-boards/xx files.
13 * Carsten Langgaard, carstenl@mips.com
14 * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
16 * This program is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License as published by the
18 * Free Software Foundation; either version 2 of the License, or (at your
19 * option) any later version.
21 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
24 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * You should have received a copy of the GNU General Public License along
33 * with this program; if not, write to the Free Software Foundation, Inc.,
34 * 675 Mass Ave, Cambridge, MA 02139, USA.
37 #include <linux/module.h>
38 #include <linux/kernel.h>
39 #include <linux/init.h>
40 #include <linux/string.h>
41 #include <linux/interrupt.h>
43 #include <linux/slab.h>
45 #include <asm/addrspace.h>
46 #include <asm/bootinfo.h>
47 #include <asm-generic/sections.h>
53 /* global PROM environment variables and pointers */
55 char **prom_argv
, **prom_envp
;
62 struct prom_pmemblock mdesc
[PROM_MAX_PMEMBLOCKS
];
64 /* default feature sets */
65 static char msp_default_features
[] =
66 #if defined(CONFIG_PMC_MSP4200_EVAL) \
67 || defined(CONFIG_PMC_MSP4200_GW)
69 #elif defined(CONFIG_PMC_MSP7120_EVAL) \
70 || defined(CONFIG_PMC_MSP7120_GW)
72 #elif defined(CONFIG_PMC_MSP7120_FPGA)
76 /* conversion functions */
77 static inline unsigned char str2hexnum(unsigned char c
)
79 if (c
>= '0' && c
<= '9')
81 if (c
>= 'a' && c
<= 'f')
86 int str2eaddr(unsigned char *ea
, unsigned char *str
)
89 unsigned char num
= 0;
91 while (*str
!= '\0') {
92 if ((*str
== '.') || (*str
== ':')) {
98 num
|= str2hexnum(*str
++);
108 EXPORT_SYMBOL(str2eaddr
);
110 static inline unsigned long str2hex(unsigned char *str
)
116 value
|= str2hexnum(*str
++);
122 /* function to query the system information */
123 const char *get_system_type(void)
125 #if defined(CONFIG_PMC_MSP4200_EVAL)
126 return "PMC-Sierra MSP4200 Eval Board";
127 #elif defined(CONFIG_PMC_MSP4200_GW)
128 return "PMC-Sierra MSP4200 VoIP Gateway";
129 #elif defined(CONFIG_PMC_MSP7120_EVAL)
130 return "PMC-Sierra MSP7120 Eval Board";
131 #elif defined(CONFIG_PMC_MSP7120_GW)
132 return "PMC-Sierra MSP7120 Residential Gateway";
133 #elif defined(CONFIG_PMC_MSP7120_FPGA)
134 return "PMC-Sierra MSP7120 FPGA";
136 #error "What is the type of *your* MSP?"
140 int get_ethernet_addr(char *ethaddr_name
, char *ethernet_addr
)
144 ethaddr_str
= prom_getenv(ethaddr_name
);
146 printk(KERN_WARNING
"%s not set in boot prom\n", ethaddr_name
);
150 if (str2eaddr(ethernet_addr
, ethaddr_str
) == -1) {
151 printk(KERN_WARNING
"%s badly formatted-<%s>\n",
152 ethaddr_name
, ethaddr_str
);
156 if (init_debug
> 1) {
158 printk(KERN_DEBUG
"get_ethernet_addr: for %s ", ethaddr_name
);
159 for (i
= 0; i
< 5; i
++)
160 printk(KERN_DEBUG
"%02x:",
161 (unsigned char)*(ethernet_addr
+i
));
162 printk(KERN_DEBUG
"%02x\n", *(ethernet_addr
+i
));
167 EXPORT_SYMBOL(get_ethernet_addr
);
169 static char *get_features(void)
171 char *feature
= prom_getenv(FEATURES
);
173 if (feature
== NULL
) {
174 /* default features based on MACHINE_TYPE */
175 feature
= msp_default_features
;
181 static char test_feature(char c
)
183 char *feature
= get_features();
191 return FEATURE_NOEXIST
;
194 unsigned long get_deviceid(void)
196 char *deviceid
= prom_getenv(DEVICEID
);
198 if (deviceid
== NULL
)
201 return str2hex(deviceid
);
204 char identify_pci(void)
206 return test_feature(PCI_KEY
);
208 EXPORT_SYMBOL(identify_pci
);
210 char identify_pcimux(void)
212 return test_feature(PCIMUX_KEY
);
215 char identify_sec(void)
217 return test_feature(SEC_KEY
);
219 EXPORT_SYMBOL(identify_sec
);
221 char identify_spad(void)
223 return test_feature(SPAD_KEY
);
225 EXPORT_SYMBOL(identify_spad
);
227 char identify_tdm(void)
229 return test_feature(TDM_KEY
);
231 EXPORT_SYMBOL(identify_tdm
);
233 char identify_zsp(void)
235 return test_feature(ZSP_KEY
);
237 EXPORT_SYMBOL(identify_zsp
);
239 static char identify_enetfeature(char key
, unsigned long interface_num
)
241 char *feature
= get_features();
244 if (*feature
++ == key
&& interface_num
-- == 0)
249 return FEATURE_NOEXIST
;
252 char identify_enet(unsigned long interface_num
)
254 return identify_enetfeature(ENET_KEY
, interface_num
);
256 EXPORT_SYMBOL(identify_enet
);
258 char identify_enetTxD(unsigned long interface_num
)
260 return identify_enetfeature(ENETTXD_KEY
, interface_num
);
262 EXPORT_SYMBOL(identify_enetTxD
);
264 unsigned long identify_family(void)
266 unsigned long deviceid
;
268 deviceid
= get_deviceid();
270 return deviceid
& CPU_DEVID_FAMILY
;
272 EXPORT_SYMBOL(identify_family
);
274 unsigned long identify_revision(void)
276 unsigned long deviceid
;
278 deviceid
= get_deviceid();
280 return deviceid
& CPU_DEVID_REVISION
;
282 EXPORT_SYMBOL(identify_revision
);
284 /* PROM environment functions */
285 char *prom_getenv(char *env_name
)
288 * Return a pointer to the given environment variable. prom_envp
289 * points to a null terminated array of pointers to variables.
290 * Environment variables are stored in the form of "memsize=64"
293 char **var
= prom_envp
;
294 int i
= strlen(env_name
);
297 if (strncmp(env_name
, *var
, i
) == 0) {
298 return *var
+ strlen(env_name
) + 1;
306 /* PROM commandline functions */
307 void __init
prom_init_cmdline(void)
312 actr
= 1; /* Always ignore argv[0] */
314 cp
= &(arcs_cmdline
[0]);
315 while (actr
< prom_argc
) {
316 strcpy(cp
, prom_argv
[actr
]);
317 cp
+= strlen(prom_argv
[actr
]);
321 if (cp
!= &(arcs_cmdline
[0])) /* get rid of trailing space */
326 /* memory allocation functions */
327 static int __init
prom_memtype_classify(unsigned int type
)
333 return BOOT_MEM_ROM_DATA
;
335 return BOOT_MEM_RESERVED
;
339 void __init
prom_meminit(void)
341 struct prom_pmemblock
*p
;
347 unsigned long base
, size
;
349 type
= prom_memtype_classify(p
->type
);
353 add_memory_region(base
, size
, type
);
358 void __init
prom_free_prom_memory(void)
369 * preserve environment variables and command line from pmon/bbload
370 * first preserve the command line
372 for (argc
= 0; argc
< prom_argc
; argc
++) {
373 len
+= sizeof(char *); /* length of pointer */
374 len
+= strlen(prom_argv
[argc
]) + 1; /* length of string */
376 len
+= sizeof(char *); /* plus length of null pointer */
378 argv
= kmalloc(len
, GFP_KERNEL
);
379 ptr
= (char *) &argv
[prom_argc
+ 1]; /* strings follow array */
381 for (argc
= 0; argc
< prom_argc
; argc
++) {
383 strcpy(ptr
, prom_argv
[argc
]);
384 ptr
+= strlen(prom_argv
[argc
]) + 1;
386 argv
[prom_argc
] = NULL
; /* end array with null pointer */
389 /* next preserve the environment variables */
392 for (envp
= prom_envp
; *envp
!= NULL
; envp
++) {
393 i
++; /* count number of environment variables */
394 len
+= sizeof(char *); /* length of pointer */
395 len
+= strlen(*envp
) + 1; /* length of string */
397 len
+= sizeof(char *); /* plus length of null pointer */
399 envp
= kmalloc(len
, GFP_KERNEL
);
400 ptr
= (char *) &envp
[i
+1];
402 for (argc
= 0; argc
< i
; argc
++) {
404 strcpy(ptr
, prom_envp
[argc
]);
405 ptr
+= strlen(prom_envp
[argc
]) + 1;
407 envp
[i
] = NULL
; /* end array with null pointer */
410 for (i
= 0; i
< boot_mem_map
.nr_map
; i
++) {
411 if (boot_mem_map
.map
[i
].type
!= BOOT_MEM_ROM_DATA
)
414 addr
= boot_mem_map
.map
[i
].addr
;
415 free_init_pages("prom memory",
416 addr
, addr
+ boot_mem_map
.map
[i
].size
);
420 struct prom_pmemblock
*__init
prom_getmdesc(void)
422 static char memsz_env
[] __initdata
= "memsize";
423 static char heaptop_env
[] __initdata
= "heaptop";
425 unsigned int memsize
;
426 unsigned int heaptop
;
429 str
= prom_getenv(memsz_env
);
431 ppfinit("memsize not set in boot prom, "
432 "set to default (32Mb)\n");
433 memsize
= 0x02000000;
435 memsize
= simple_strtol(str
, NULL
, 0);
438 /* if memsize is a bad size, use reasonable default */
439 memsize
= 0x02000000;
442 /* convert to physical address (removing caching bits, etc) */
443 memsize
= CPHYSADDR(memsize
);
446 str
= prom_getenv(heaptop_env
);
448 heaptop
= CPHYSADDR((u32
)&_text
);
449 ppfinit("heaptop not set in boot prom, "
450 "set to default 0x%08x\n", heaptop
);
452 heaptop
= simple_strtol(str
, NULL
, 16);
454 /* heaptop conversion bad, might have 0xValue */
455 heaptop
= simple_strtol(str
, NULL
, 0);
458 /* heaptop still bad, use reasonable default */
459 heaptop
= CPHYSADDR((u32
)&_text
);
463 /* convert to physical address (removing caching bits, etc) */
464 heaptop
= CPHYSADDR((u32
)heaptop
);
467 /* the base region */
469 mdesc
[i
].type
= BOOT_MEM_RESERVED
;
470 mdesc
[i
].base
= 0x00000000;
471 mdesc
[i
].size
= PAGE_ALIGN(0x300 + 0x80);
472 /* jtag interrupt vector + sizeof vector */
475 if (heaptop
> mdesc
[i
].base
+ mdesc
[i
].size
) {
477 mdesc
[i
].type
= BOOT_MEM_ROM_DATA
;
478 mdesc
[i
].base
= mdesc
[i
-1].base
+ mdesc
[i
-1].size
;
479 mdesc
[i
].size
= heaptop
- mdesc
[i
].base
;
482 /* end of PMON data to start of kernel -- probably zero .. */
483 if (heaptop
!= CPHYSADDR((u32
)_text
)) {
485 mdesc
[i
].type
= BOOT_MEM_RAM
;
486 mdesc
[i
].base
= heaptop
;
487 mdesc
[i
].size
= CPHYSADDR((u32
)_text
) - mdesc
[i
].base
;
492 mdesc
[i
].type
= BOOT_MEM_RESERVED
;
493 mdesc
[i
].base
= CPHYSADDR((u32
)_text
);
494 mdesc
[i
].size
= CPHYSADDR(PAGE_ALIGN((u32
)_end
)) - mdesc
[i
].base
;
496 /* Remainder of RAM -- under memsize */
498 mdesc
[i
].type
= yamon_free
;
499 mdesc
[i
].base
= mdesc
[i
-1].base
+ mdesc
[i
-1].size
;
500 mdesc
[i
].size
= memsize
- mdesc
[i
].base
;