diff options
Diffstat (limited to 'arch/powerpc/boot/ps3.c')
-rw-r--r-- | arch/powerpc/boot/ps3.c | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/arch/powerpc/boot/ps3.c b/arch/powerpc/boot/ps3.c new file mode 100644 index 000000000000..893d59339c26 --- /dev/null +++ b/arch/powerpc/boot/ps3.c | |||
@@ -0,0 +1,161 @@ | |||
1 | /* | ||
2 | * PS3 bootwrapper support. | ||
3 | * | ||
4 | * Copyright (C) 2007 Sony Computer Entertainment Inc. | ||
5 | * Copyright 2007 Sony Corp. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; version 2 of the License. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | */ | ||
20 | |||
21 | #include <stdarg.h> | ||
22 | #include <stddef.h> | ||
23 | #include "types.h" | ||
24 | #include "elf.h" | ||
25 | #include "string.h" | ||
26 | #include "stdio.h" | ||
27 | #include "page.h" | ||
28 | #include "ops.h" | ||
29 | |||
30 | extern s64 lv1_panic(u64 in_1); | ||
31 | extern s64 lv1_get_logical_partition_id(u64 *out_1); | ||
32 | extern s64 lv1_get_logical_ppe_id(u64 *out_1); | ||
33 | extern s64 lv1_get_repository_node_value(u64 in_1, u64 in_2, u64 in_3, | ||
34 | u64 in_4, u64 in_5, u64 *out_1, u64 *out_2); | ||
35 | |||
36 | #ifdef DEBUG | ||
37 | #define DBG(fmt...) printf(fmt) | ||
38 | #else | ||
39 | static inline int __attribute__ ((format (printf, 1, 2))) DBG( | ||
40 | const char *fmt, ...) {return 0;} | ||
41 | #endif | ||
42 | |||
43 | BSS_STACK(4096); | ||
44 | |||
45 | /* A buffer that may be edited by tools operating on a zImage binary so as to | ||
46 | * edit the command line passed to vmlinux (by setting /chosen/bootargs). | ||
47 | * The buffer is put in it's own section so that tools may locate it easier. | ||
48 | */ | ||
49 | static char cmdline[COMMAND_LINE_SIZE] | ||
50 | __attribute__((__section__("__builtin_cmdline"))); | ||
51 | |||
52 | static void prep_cmdline(void *chosen) | ||
53 | { | ||
54 | if (cmdline[0] == '\0') | ||
55 | getprop(chosen, "bootargs", cmdline, COMMAND_LINE_SIZE-1); | ||
56 | else | ||
57 | setprop_str(chosen, "bootargs", cmdline); | ||
58 | |||
59 | printf("cmdline: '%s'\n", cmdline); | ||
60 | } | ||
61 | |||
62 | static void ps3_console_write(const char *buf, int len) | ||
63 | { | ||
64 | } | ||
65 | |||
66 | static void ps3_exit(void) | ||
67 | { | ||
68 | printf("ps3_exit\n"); | ||
69 | |||
70 | /* lv1_panic will shutdown the lpar. */ | ||
71 | |||
72 | lv1_panic(0); /* zero = do not reboot */ | ||
73 | while (1); | ||
74 | } | ||
75 | |||
76 | static int ps3_repository_read_rm_size(u64 *rm_size) | ||
77 | { | ||
78 | s64 result; | ||
79 | u64 lpar_id; | ||
80 | u64 ppe_id; | ||
81 | u64 v2; | ||
82 | |||
83 | result = lv1_get_logical_partition_id(&lpar_id); | ||
84 | |||
85 | if (result) | ||
86 | return -1; | ||
87 | |||
88 | result = lv1_get_logical_ppe_id(&ppe_id); | ||
89 | |||
90 | if (result) | ||
91 | return -1; | ||
92 | |||
93 | /* | ||
94 | * n1: 0000000062690000 : ....bi.. | ||
95 | * n2: 7075000000000000 : pu...... | ||
96 | * n3: 0000000000000001 : ........ | ||
97 | * n4: 726d5f73697a6500 : rm_size. | ||
98 | */ | ||
99 | |||
100 | result = lv1_get_repository_node_value(lpar_id, 0x0000000062690000ULL, | ||
101 | 0x7075000000000000ULL, ppe_id, 0x726d5f73697a6500ULL, rm_size, | ||
102 | &v2); | ||
103 | |||
104 | printf("%s:%d: ppe_id %lu \n", __func__, __LINE__, | ||
105 | (unsigned long)ppe_id); | ||
106 | printf("%s:%d: lpar_id %lu \n", __func__, __LINE__, | ||
107 | (unsigned long)lpar_id); | ||
108 | printf("%s:%d: rm_size %llxh \n", __func__, __LINE__, *rm_size); | ||
109 | |||
110 | return result ? -1 : 0; | ||
111 | } | ||
112 | |||
113 | void ps3_copy_vectors(void) | ||
114 | { | ||
115 | extern char __system_reset_kernel[]; | ||
116 | |||
117 | memcpy((void *)0x100, __system_reset_kernel, 0x100); | ||
118 | flush_cache((void *)0x100, 0x100); | ||
119 | } | ||
120 | |||
121 | void platform_init(void) | ||
122 | { | ||
123 | extern char _end[]; | ||
124 | extern char _dtb_start[]; | ||
125 | extern char _initrd_start[]; | ||
126 | extern char _initrd_end[]; | ||
127 | const u32 heapsize = 0x1000000 - (u32)_end; /* 16MiB */ | ||
128 | void *chosen; | ||
129 | unsigned long ft_addr; | ||
130 | u64 rm_size; | ||
131 | |||
132 | console_ops.write = ps3_console_write; | ||
133 | platform_ops.exit = ps3_exit; | ||
134 | |||
135 | printf("\n-- PS3 bootwrapper --\n"); | ||
136 | |||
137 | simple_alloc_init(_end, heapsize, 32, 64); | ||
138 | ft_init(_dtb_start, 0, 4); | ||
139 | |||
140 | chosen = finddevice("/chosen"); | ||
141 | |||
142 | ps3_repository_read_rm_size(&rm_size); | ||
143 | dt_fixup_memory(0, rm_size); | ||
144 | |||
145 | if (_initrd_end > _initrd_start) { | ||
146 | setprop_val(chosen, "linux,initrd-start", (u32)(_initrd_start)); | ||
147 | setprop_val(chosen, "linux,initrd-end", (u32)(_initrd_end)); | ||
148 | } | ||
149 | |||
150 | prep_cmdline(chosen); | ||
151 | |||
152 | ft_addr = dt_ops.finalize(); | ||
153 | |||
154 | ps3_copy_vectors(); | ||
155 | |||
156 | printf(" flat tree at 0x%lx\n\r", ft_addr); | ||
157 | |||
158 | ((kernel_entry_t)0)(ft_addr, 0, NULL); | ||
159 | |||
160 | ps3_exit(); | ||
161 | } | ||