aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/mips/fw/lib/Makefile2
-rw-r--r--arch/mips/fw/lib/cmdline.c101
-rw-r--r--arch/mips/include/asm/fw/fw.h47
3 files changed, 150 insertions, 0 deletions
diff --git a/arch/mips/fw/lib/Makefile b/arch/mips/fw/lib/Makefile
index 84befc968fc4..529150516777 100644
--- a/arch/mips/fw/lib/Makefile
+++ b/arch/mips/fw/lib/Makefile
@@ -2,4 +2,6 @@
2# Makefile for generic prom monitor library routines under Linux. 2# Makefile for generic prom monitor library routines under Linux.
3# 3#
4 4
5lib-y += cmdline.o
6
5lib-$(CONFIG_64BIT) += call_o32.o 7lib-$(CONFIG_64BIT) += call_o32.o
diff --git a/arch/mips/fw/lib/cmdline.c b/arch/mips/fw/lib/cmdline.c
new file mode 100644
index 000000000000..ffd0345780ae
--- /dev/null
+++ b/arch/mips/fw/lib/cmdline.c
@@ -0,0 +1,101 @@
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.
7 */
8#include <linux/init.h>
9#include <linux/kernel.h>
10#include <linux/string.h>
11
12#include <asm/addrspace.h>
13#include <asm/fw/fw.h>
14
15int fw_argc;
16int *_fw_argv;
17int *_fw_envp;
18
19void __init fw_init_cmdline(void)
20{
21 int i;
22
23 /* Validate command line parameters. */
24 if ((fw_arg0 >= CKSEG0) || (fw_arg1 < CKSEG0)) {
25 fw_argc = 0;
26 _fw_argv = NULL;
27 } else {
28 fw_argc = (fw_arg0 & 0x0000ffff);
29 _fw_argv = (int *)fw_arg1;
30 }
31
32 /* Validate environment pointer. */
33 if (fw_arg2 < CKSEG0)
34 _fw_envp = NULL;
35 else
36 _fw_envp = (int *)fw_arg2;
37
38 for (i = 1; i < fw_argc; i++) {
39 strlcat(arcs_cmdline, fw_argv(i), COMMAND_LINE_SIZE);
40 if (i < (fw_argc - 1))
41 strlcat(arcs_cmdline, " ", COMMAND_LINE_SIZE);
42 }
43}
44
45char * __init fw_getcmdline(void)
46{
47 return &(arcs_cmdline[0]);
48}
49
50char *fw_getenv(char *envname)
51{
52 char *result = NULL;
53
54 if (_fw_envp != NULL) {
55 /*
56 * Return a pointer to the given environment variable.
57 * YAMON uses "name", "value" pairs, while U-Boot uses
58 * "name=value".
59 */
60 int i, yamon, index = 0;
61
62 yamon = (strchr(fw_envp(index), '=') == NULL);
63 i = strlen(envname);
64
65 while (fw_envp(index)) {
66 if (strncmp(envname, fw_envp(index), i) == 0) {
67 if (yamon) {
68 result = fw_envp(index + 1);
69 break;
70 } else if (fw_envp(index)[i] == '=') {
71 result = (fw_envp(index + 1) + i);
72 break;
73 }
74 }
75
76 /* Increment array index. */
77 if (yamon)
78 index += 2;
79 else
80 index += 1;
81 }
82 }
83
84 return result;
85}
86
87unsigned long fw_getenvl(char *envname)
88{
89 unsigned long envl = 0UL;
90 char *str;
91 long val;
92 int tmp;
93
94 str = fw_getenv(envname);
95 if (str) {
96 tmp = kstrtol(str, 0, &val);
97 envl = (unsigned long)val;
98 }
99
100 return envl;
101}
diff --git a/arch/mips/include/asm/fw/fw.h b/arch/mips/include/asm/fw/fw.h
new file mode 100644
index 000000000000..d6c50a7e9ede
--- /dev/null
+++ b/arch/mips/include/asm/fw/fw.h
@@ -0,0 +1,47 @@
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2012 MIPS Technologies, Inc.
7 */
8#ifndef __ASM_FW_H_
9#define __ASM_FW_H_
10
11#include <asm/bootinfo.h> /* For cleaner code... */
12
13enum fw_memtypes {
14 fw_dontuse,
15 fw_code,
16 fw_free,
17};
18
19typedef struct {
20 unsigned long base; /* Within KSEG0 */
21 unsigned int size; /* bytes */
22 enum fw_memtypes type; /* fw_memtypes */
23} fw_memblock_t;
24
25/* Maximum number of memory block descriptors. */
26#define FW_MAX_MEMBLOCKS 32
27
28extern int fw_argc;
29extern int *_fw_argv;
30extern int *_fw_envp;
31
32/*
33 * Most firmware like YAMON, PMON, etc. pass arguments and environment
34 * variables as 32-bit pointers. These take care of sign extension.
35 */
36#define fw_argv(index) ((char *)(long)_fw_argv[(index)])
37#define fw_envp(index) ((char *)(long)_fw_envp[(index)])
38
39extern void fw_init_cmdline(void);
40extern char *fw_getcmdline(void);
41extern fw_memblock_t *fw_getmdesc(void);
42extern void fw_meminit(void);
43extern char *fw_getenv(char *name);
44extern unsigned long fw_getenvl(char *name);
45extern void fw_init_early_console(char port);
46
47#endif /* __ASM_FW_H_ */