aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2007-06-13 00:52:54 -0400
committerPaul Mackerras <paulus@samba.org>2007-06-14 08:30:15 -0400
commit2e6016133755eb3cc44e8efab92573d23ed75888 (patch)
tree94442dc3acd51c31222282bb15d6946692448279
parenta0ae9c7c05b969cbaffb0371f8698c54465b4c96 (diff)
[POWERPC] Split low-level OF-related bootloader code into separate files
Currently, all OF-related code in the bootloader is contained in of.c. of.c also provides the platform specific things necessary to boot on an OF platform. However, there are platforms (such as PReP) which can include an OF implementation, but are not bootable as pure OF systems. For use by such platforms, this patch splits out the low-level parts of the OF code (call_prom() and various wrappers thereof) into a new oflib.c file. In addition, the code related to bootwrapper console output via OF are moved to a new ofconsole.c file. Both these files are included in the wrapper.a library where they can be used by both full-OF and partial OF platforms. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Paul Mackerras <paulus@samba.org>
-rw-r--r--arch/powerpc/boot/Makefile2
-rw-r--r--arch/powerpc/boot/of.c188
-rw-r--r--arch/powerpc/boot/of.h15
-rw-r--r--arch/powerpc/boot/ofconsole.c45
-rw-r--r--arch/powerpc/boot/oflib.c172
5 files changed, 240 insertions, 182 deletions
diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
index ff2701949ee1..fa195fbd0519 100644
--- a/arch/powerpc/boot/Makefile
+++ b/arch/powerpc/boot/Makefile
@@ -43,7 +43,7 @@ $(addprefix $(obj)/,$(zlib) gunzip_util.o main.o): \
43 43
44src-wlib := string.S crt0.S stdio.c main.c flatdevtree.c flatdevtree_misc.c \ 44src-wlib := string.S crt0.S stdio.c main.c flatdevtree.c flatdevtree_misc.c \
45 ns16550.c serial.c simple_alloc.c div64.S util.S \ 45 ns16550.c serial.c simple_alloc.c div64.S util.S \
46 gunzip_util.c elf_util.c $(zlib) devtree.c \ 46 gunzip_util.c elf_util.c $(zlib) devtree.c oflib.c ofconsole.c \
47 44x.c ebony.c mv64x60.c mpsc.c mv64x60_i2c.c 47 44x.c ebony.c mv64x60.c mpsc.c mv64x60_i2c.c
48src-plat := of.c cuboot-83xx.c cuboot-85xx.c holly.c \ 48src-plat := of.c cuboot-83xx.c cuboot-85xx.c holly.c \
49 cuboot-ebony.c treeboot-ebony.c prpmc2800.c 49 cuboot-ebony.c treeboot-ebony.c prpmc2800.c
diff --git a/arch/powerpc/boot/of.c b/arch/powerpc/boot/of.c
index d16ee3e3f868..6108aef28f03 100644
--- a/arch/powerpc/boot/of.c
+++ b/arch/powerpc/boot/of.c
@@ -15,8 +15,7 @@
15#include "page.h" 15#include "page.h"
16#include "ops.h" 16#include "ops.h"
17 17
18typedef void *ihandle; 18#include "of.h"
19typedef void *phandle;
20 19
21extern char _end[]; 20extern char _end[];
22 21
@@ -25,154 +24,10 @@ extern char _end[];
25#define RAM_END (512<<20) /* Fixme: use OF */ 24#define RAM_END (512<<20) /* Fixme: use OF */
26#define ONE_MB 0x100000 25#define ONE_MB 0x100000
27 26
28int (*prom) (void *);
29 27
30 28
31static unsigned long claim_base; 29static unsigned long claim_base;
32 30
33static int call_prom(const char *service, int nargs, int nret, ...)
34{
35 int i;
36 struct prom_args {
37 const char *service;
38 int nargs;
39 int nret;
40 unsigned int args[12];
41 } args;
42 va_list list;
43
44 args.service = service;
45 args.nargs = nargs;
46 args.nret = nret;
47
48 va_start(list, nret);
49 for (i = 0; i < nargs; i++)
50 args.args[i] = va_arg(list, unsigned int);
51 va_end(list);
52
53 for (i = 0; i < nret; i++)
54 args.args[nargs+i] = 0;
55
56 if (prom(&args) < 0)
57 return -1;
58
59 return (nret > 0)? args.args[nargs]: 0;
60}
61
62static int call_prom_ret(const char *service, int nargs, int nret,
63 unsigned int *rets, ...)
64{
65 int i;
66 struct prom_args {
67 const char *service;
68 int nargs;
69 int nret;
70 unsigned int args[12];
71 } args;
72 va_list list;
73
74 args.service = service;
75 args.nargs = nargs;
76 args.nret = nret;
77
78 va_start(list, rets);
79 for (i = 0; i < nargs; i++)
80 args.args[i] = va_arg(list, unsigned int);
81 va_end(list);
82
83 for (i = 0; i < nret; i++)
84 args.args[nargs+i] = 0;
85
86 if (prom(&args) < 0)
87 return -1;
88
89 if (rets != (void *) 0)
90 for (i = 1; i < nret; ++i)
91 rets[i-1] = args.args[nargs+i];
92
93 return (nret > 0)? args.args[nargs]: 0;
94}
95
96/*
97 * Older OF's require that when claiming a specific range of addresses,
98 * we claim the physical space in the /memory node and the virtual
99 * space in the chosen mmu node, and then do a map operation to
100 * map virtual to physical.
101 */
102static int need_map = -1;
103static ihandle chosen_mmu;
104static phandle memory;
105
106/* returns true if s2 is a prefix of s1 */
107static int string_match(const char *s1, const char *s2)
108{
109 for (; *s2; ++s2)
110 if (*s1++ != *s2)
111 return 0;
112 return 1;
113}
114
115static int check_of_version(void)
116{
117 phandle oprom, chosen;
118 char version[64];
119
120 oprom = finddevice("/openprom");
121 if (oprom == (phandle) -1)
122 return 0;
123 if (getprop(oprom, "model", version, sizeof(version)) <= 0)
124 return 0;
125 version[sizeof(version)-1] = 0;
126 printf("OF version = '%s'\r\n", version);
127 if (!string_match(version, "Open Firmware, 1.")
128 && !string_match(version, "FirmWorks,3."))
129 return 0;
130 chosen = finddevice("/chosen");
131 if (chosen == (phandle) -1) {
132 chosen = finddevice("/chosen@0");
133 if (chosen == (phandle) -1) {
134 printf("no chosen\n");
135 return 0;
136 }
137 }
138 if (getprop(chosen, "mmu", &chosen_mmu, sizeof(chosen_mmu)) <= 0) {
139 printf("no mmu\n");
140 return 0;
141 }
142 memory = (ihandle) call_prom("open", 1, 1, "/memory");
143 if (memory == (ihandle) -1) {
144 memory = (ihandle) call_prom("open", 1, 1, "/memory@0");
145 if (memory == (ihandle) -1) {
146 printf("no memory node\n");
147 return 0;
148 }
149 }
150 printf("old OF detected\r\n");
151 return 1;
152}
153
154static void *claim(unsigned long virt, unsigned long size, unsigned long align)
155{
156 int ret;
157 unsigned int result;
158
159 if (need_map < 0)
160 need_map = check_of_version();
161 if (align || !need_map)
162 return (void *) call_prom("claim", 3, 1, virt, size, align);
163
164 ret = call_prom_ret("call-method", 5, 2, &result, "claim", memory,
165 align, size, virt);
166 if (ret != 0 || result == -1)
167 return (void *) -1;
168 ret = call_prom_ret("call-method", 5, 2, &result, "claim", chosen_mmu,
169 align, size, virt);
170 /* 0x12 == coherent + read/write */
171 ret = call_prom("call-method", 6, 1, "map", chosen_mmu,
172 0x12, size, virt, virt);
173 return (void *) virt;
174}
175
176static void *of_try_claim(unsigned long size) 31static void *of_try_claim(unsigned long size)
177{ 32{
178 unsigned long addr = 0; 33 unsigned long addr = 0;
@@ -184,7 +39,7 @@ static void *of_try_claim(unsigned long size)
184#ifdef DEBUG 39#ifdef DEBUG
185 printf(" trying: 0x%08lx\n\r", claim_base); 40 printf(" trying: 0x%08lx\n\r", claim_base);
186#endif 41#endif
187 addr = (unsigned long)claim(claim_base, size, 0); 42 addr = (unsigned long)of_claim(claim_base, size, 0);
188 if ((void *)addr != (void *)-1) 43 if ((void *)addr != (void *)-1)
189 break; 44 break;
190 } 45 }
@@ -218,52 +73,24 @@ static void *of_vmlinux_alloc(unsigned long size)
218 return p; 73 return p;
219} 74}
220 75
221static void of_exit(void)
222{
223 call_prom("exit", 0, 0);
224}
225
226/* 76/*
227 * OF device tree routines 77 * OF device tree routines
228 */ 78 */
229static void *of_finddevice(const char *name) 79static void *of_finddevice(const char *name)
230{ 80{
231 return (phandle) call_prom("finddevice", 1, 1, name); 81 return (phandle) of_call_prom("finddevice", 1, 1, name);
232} 82}
233 83
234static int of_getprop(const void *phandle, const char *name, void *buf, 84static int of_getprop(const void *phandle, const char *name, void *buf,
235 const int buflen) 85 const int buflen)
236{ 86{
237 return call_prom("getprop", 4, 1, phandle, name, buf, buflen); 87 return of_call_prom("getprop", 4, 1, phandle, name, buf, buflen);
238} 88}
239 89
240static int of_setprop(const void *phandle, const char *name, const void *buf, 90static int of_setprop(const void *phandle, const char *name, const void *buf,
241 const int buflen) 91 const int buflen)
242{ 92{
243 return call_prom("setprop", 4, 1, phandle, name, buf, buflen); 93 return of_call_prom("setprop", 4, 1, phandle, name, buf, buflen);
244}
245
246/*
247 * OF console routines
248 */
249static void *of_stdout_handle;
250
251static int of_console_open(void)
252{
253 void *devp;
254
255 if (((devp = finddevice("/chosen")) != NULL)
256 && (getprop(devp, "stdout", &of_stdout_handle,
257 sizeof(of_stdout_handle))
258 == sizeof(of_stdout_handle)))
259 return 0;
260
261 return -1;
262}
263
264static void of_console_write(char *buf, int len)
265{
266 call_prom("write", 3, 1, of_stdout_handle, buf, len);
267} 94}
268 95
269void platform_init(unsigned long a1, unsigned long a2, void *promptr) 96void platform_init(unsigned long a1, unsigned long a2, void *promptr)
@@ -277,10 +104,9 @@ void platform_init(unsigned long a1, unsigned long a2, void *promptr)
277 dt_ops.getprop = of_getprop; 104 dt_ops.getprop = of_getprop;
278 dt_ops.setprop = of_setprop; 105 dt_ops.setprop = of_setprop;
279 106
280 console_ops.open = of_console_open; 107 of_console_init();
281 console_ops.write = of_console_write;
282 108
283 prom = (int (*)(void *))promptr; 109 of_init(promptr);
284 loader_info.promptr = promptr; 110 loader_info.promptr = promptr;
285 if (a1 && a2 && a2 != 0xdeadbeef) { 111 if (a1 && a2 && a2 != 0xdeadbeef) {
286 loader_info.initrd_addr = a1; 112 loader_info.initrd_addr = a1;
diff --git a/arch/powerpc/boot/of.h b/arch/powerpc/boot/of.h
new file mode 100644
index 000000000000..169d31106991
--- /dev/null
+++ b/arch/powerpc/boot/of.h
@@ -0,0 +1,15 @@
1#ifndef _PPC_BOOT_OF_H_
2#define _PPC_BOOT_OF_H_
3
4typedef void *phandle;
5typedef void *ihandle;
6
7void of_init(void *promptr);
8int of_call_prom(const char *service, int nargs, int nret, ...);
9void *of_claim(unsigned long virt, unsigned long size, unsigned long align);
10void of_exit(void);
11
12/* Console functions */
13void of_console_init(void);
14
15#endif /* _PPC_BOOT_OF_H_ */
diff --git a/arch/powerpc/boot/ofconsole.c b/arch/powerpc/boot/ofconsole.c
new file mode 100644
index 000000000000..00c9dc92dd2f
--- /dev/null
+++ b/arch/powerpc/boot/ofconsole.c
@@ -0,0 +1,45 @@
1/*
2 * OF console routines
3 *
4 * Copyright (C) Paul Mackerras 1997.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11#include <stddef.h>
12#include "types.h"
13#include "elf.h"
14#include "string.h"
15#include "stdio.h"
16#include "page.h"
17#include "ops.h"
18
19#include "of.h"
20
21static void *of_stdout_handle;
22
23static int of_console_open(void)
24{
25 void *devp;
26
27 if (((devp = finddevice("/chosen")) != NULL)
28 && (getprop(devp, "stdout", &of_stdout_handle,
29 sizeof(of_stdout_handle))
30 == sizeof(of_stdout_handle)))
31 return 0;
32
33 return -1;
34}
35
36static void of_console_write(char *buf, int len)
37{
38 of_call_prom("write", 3, 1, of_stdout_handle, buf, len);
39}
40
41void of_console_init(void)
42{
43 console_ops.open = of_console_open;
44 console_ops.write = of_console_write;
45}
diff --git a/arch/powerpc/boot/oflib.c b/arch/powerpc/boot/oflib.c
new file mode 100644
index 000000000000..e9b95d8ae7ff
--- /dev/null
+++ b/arch/powerpc/boot/oflib.c
@@ -0,0 +1,172 @@
1/*
2 * Copyright (C) Paul Mackerras 1997.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 */
9#include <stddef.h>
10#include "types.h"
11#include "elf.h"
12#include "string.h"
13#include "stdio.h"
14#include "page.h"
15#include "ops.h"
16
17#include "of.h"
18
19static int (*prom) (void *);
20
21void of_init(void *promptr)
22{
23 prom = (int (*)(void *))promptr;
24}
25
26int of_call_prom(const char *service, int nargs, int nret, ...)
27{
28 int i;
29 struct prom_args {
30 const char *service;
31 int nargs;
32 int nret;
33 unsigned int args[12];
34 } args;
35 va_list list;
36
37 args.service = service;
38 args.nargs = nargs;
39 args.nret = nret;
40
41 va_start(list, nret);
42 for (i = 0; i < nargs; i++)
43 args.args[i] = va_arg(list, unsigned int);
44 va_end(list);
45
46 for (i = 0; i < nret; i++)
47 args.args[nargs+i] = 0;
48
49 if (prom(&args) < 0)
50 return -1;
51
52 return (nret > 0)? args.args[nargs]: 0;
53}
54
55static int of_call_prom_ret(const char *service, int nargs, int nret,
56 unsigned int *rets, ...)
57{
58 int i;
59 struct prom_args {
60 const char *service;
61 int nargs;
62 int nret;
63 unsigned int args[12];
64 } args;
65 va_list list;
66
67 args.service = service;
68 args.nargs = nargs;
69 args.nret = nret;
70
71 va_start(list, rets);
72 for (i = 0; i < nargs; i++)
73 args.args[i] = va_arg(list, unsigned int);
74 va_end(list);
75
76 for (i = 0; i < nret; i++)
77 args.args[nargs+i] = 0;
78
79 if (prom(&args) < 0)
80 return -1;
81
82 if (rets != (void *) 0)
83 for (i = 1; i < nret; ++i)
84 rets[i-1] = args.args[nargs+i];
85
86 return (nret > 0)? args.args[nargs]: 0;
87}
88
89/* returns true if s2 is a prefix of s1 */
90static int string_match(const char *s1, const char *s2)
91{
92 for (; *s2; ++s2)
93 if (*s1++ != *s2)
94 return 0;
95 return 1;
96}
97
98/*
99 * Older OF's require that when claiming a specific range of addresses,
100 * we claim the physical space in the /memory node and the virtual
101 * space in the chosen mmu node, and then do a map operation to
102 * map virtual to physical.
103 */
104static int need_map = -1;
105static ihandle chosen_mmu;
106static phandle memory;
107
108static int check_of_version(void)
109{
110 phandle oprom, chosen;
111 char version[64];
112
113 oprom = finddevice("/openprom");
114 if (oprom == (phandle) -1)
115 return 0;
116 if (getprop(oprom, "model", version, sizeof(version)) <= 0)
117 return 0;
118 version[sizeof(version)-1] = 0;
119 printf("OF version = '%s'\r\n", version);
120 if (!string_match(version, "Open Firmware, 1.")
121 && !string_match(version, "FirmWorks,3."))
122 return 0;
123 chosen = finddevice("/chosen");
124 if (chosen == (phandle) -1) {
125 chosen = finddevice("/chosen@0");
126 if (chosen == (phandle) -1) {
127 printf("no chosen\n");
128 return 0;
129 }
130 }
131 if (getprop(chosen, "mmu", &chosen_mmu, sizeof(chosen_mmu)) <= 0) {
132 printf("no mmu\n");
133 return 0;
134 }
135 memory = (ihandle) of_call_prom("open", 1, 1, "/memory");
136 if (memory == (ihandle) -1) {
137 memory = (ihandle) of_call_prom("open", 1, 1, "/memory@0");
138 if (memory == (ihandle) -1) {
139 printf("no memory node\n");
140 return 0;
141 }
142 }
143 printf("old OF detected\r\n");
144 return 1;
145}
146
147void *of_claim(unsigned long virt, unsigned long size, unsigned long align)
148{
149 int ret;
150 unsigned int result;
151
152 if (need_map < 0)
153 need_map = check_of_version();
154 if (align || !need_map)
155 return (void *) of_call_prom("claim", 3, 1, virt, size, align);
156
157 ret = of_call_prom_ret("call-method", 5, 2, &result, "claim", memory,
158 align, size, virt);
159 if (ret != 0 || result == -1)
160 return (void *) -1;
161 ret = of_call_prom_ret("call-method", 5, 2, &result, "claim", chosen_mmu,
162 align, size, virt);
163 /* 0x12 == coherent + read/write */
164 ret = of_call_prom("call-method", 6, 1, "map", chosen_mmu,
165 0x12, size, virt, virt);
166 return (void *) virt;
167}
168
169void of_exit(void)
170{
171 of_call_prom("exit", 0, 0);
172}