Rev 3022 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3022 | Rev 4055 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2005 Martin Decky |
2 | * Copyright (c) 2005 Martin Decky |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | #include <ofw.h> |
29 | #include <ofw.h> |
30 | #include <ofwarch.h> |
30 | #include <ofwarch.h> |
31 | #include <printf.h> |
31 | #include <printf.h> |
32 | #include <asm.h> |
32 | #include <asm.h> |
33 | #include <types.h> |
33 | #include <types.h> |
34 | 34 | ||
35 | uintptr_t ofw_cif; |
35 | uintptr_t ofw_cif; |
36 | 36 | ||
37 | phandle ofw_chosen; |
37 | phandle ofw_chosen; |
38 | ihandle ofw_stdout; |
38 | ihandle ofw_stdout; |
39 | phandle ofw_root; |
39 | phandle ofw_root; |
40 | ihandle ofw_mmu; |
40 | ihandle ofw_mmu; |
41 | ihandle ofw_memory_prop; |
41 | ihandle ofw_memory_prop; |
42 | phandle ofw_memory; |
42 | phandle ofw_memory; |
43 | phandle ofw_aliases; |
43 | phandle ofw_aliases; |
44 | 44 | ||
45 | void ofw_init(void) |
45 | void ofw_init(void) |
46 | { |
46 | { |
47 | ofw_chosen = ofw_find_device("/chosen"); |
47 | ofw_chosen = ofw_find_device("/chosen"); |
48 | if (ofw_chosen == -1) |
48 | if (ofw_chosen == -1) |
49 | halt(); |
49 | halt(); |
50 | 50 | ||
51 | if (ofw_get_property(ofw_chosen, "stdout", &ofw_stdout, sizeof(ofw_stdout)) <= 0) |
51 | if (ofw_get_property(ofw_chosen, "stdout", &ofw_stdout, |
- | 52 | sizeof(ofw_stdout)) <= 0) |
|
52 | ofw_stdout = 0; |
53 | ofw_stdout = 0; |
53 | 54 | ||
54 | ofw_root = ofw_find_device("/"); |
55 | ofw_root = ofw_find_device("/"); |
55 | if (ofw_root == -1) { |
56 | if (ofw_root == -1) { |
56 | puts("\r\nError: Unable to find / device, halted.\r\n"); |
57 | puts("\r\nError: Unable to find / device, halted.\r\n"); |
57 | halt(); |
58 | halt(); |
58 | } |
59 | } |
59 | 60 | ||
60 | if (ofw_get_property(ofw_chosen, "mmu", &ofw_mmu, sizeof(ofw_mmu)) <= 0) { |
61 | if (ofw_get_property(ofw_chosen, "mmu", &ofw_mmu, |
- | 62 | sizeof(ofw_mmu)) <= 0) { |
|
61 | puts("\r\nError: Unable to get mmu property, halted.\r\n"); |
63 | puts("\r\nError: Unable to get mmu property, halted.\r\n"); |
62 | halt(); |
64 | halt(); |
63 | } |
65 | } |
64 | if (ofw_get_property(ofw_chosen, "memory", &ofw_memory_prop, sizeof(ofw_memory_prop)) <= 0) { |
66 | if (ofw_get_property(ofw_chosen, "memory", &ofw_memory_prop, |
- | 67 | sizeof(ofw_memory_prop)) <= 0) { |
|
65 | puts("\r\nError: Unable to get memory property, halted.\r\n"); |
68 | puts("\r\nError: Unable to get memory property, halted.\r\n"); |
66 | halt(); |
69 | halt(); |
67 | } |
70 | } |
68 | 71 | ||
69 | ofw_memory = ofw_find_device("/memory"); |
72 | ofw_memory = ofw_find_device("/memory"); |
70 | if (ofw_memory == -1) { |
73 | if (ofw_memory == -1) { |
71 | puts("\r\nError: Unable to find /memory device, halted.\r\n"); |
74 | puts("\r\nError: Unable to find /memory device, halted.\r\n"); |
72 | halt(); |
75 | halt(); |
73 | } |
76 | } |
74 | 77 | ||
75 | ofw_aliases = ofw_find_device("/aliases"); |
78 | ofw_aliases = ofw_find_device("/aliases"); |
76 | if (ofw_aliases == -1) { |
79 | if (ofw_aliases == -1) { |
77 | puts("\r\nError: Unable to find /aliases device, halted.\r\n"); |
80 | puts("\r\nError: Unable to find /aliases device, halted.\r\n"); |
78 | halt(); |
81 | halt(); |
79 | } |
82 | } |
80 | } |
83 | } |
81 | 84 | ||
82 | /** Perform a call to OpenFirmware client interface. |
85 | /** Perform a call to OpenFirmware client interface. |
83 | * |
86 | * |
84 | * @param service String identifying the service requested. |
87 | * @param service String identifying the service requested. |
85 | * @param nargs Number of input arguments. |
88 | * @param nargs Number of input arguments. |
86 | * @param nret Number of output arguments. This includes the return value. |
89 | * @param nret Number of output arguments. This includes the return |
- | 90 | * value. |
|
87 | * @param rets Buffer for output arguments or NULL. The buffer must accommodate nret - 1 items. |
91 | * @param rets Buffer for output arguments or NULL. The buffer must |
- | 92 | * accommodate nret - 1 items. |
|
88 | * |
93 | * |
89 | * @return Return value returned by the client interface. |
94 | * @return Return value returned by the client interface. |
90 | */ |
95 | */ |
- | 96 | unsigned long |
|
91 | unsigned long ofw_call(const char *service, const int nargs, const int nret, ofw_arg_t *rets, ...) |
97 | ofw_call(const char *service, const int nargs, const int nret, ofw_arg_t *rets, |
- | 98 | ...) |
|
92 | { |
99 | { |
93 | va_list list; |
100 | va_list list; |
94 | ofw_args_t args; |
101 | ofw_args_t args; |
95 | int i; |
102 | int i; |
96 | 103 | ||
97 | args.service = (ofw_arg_t) service; |
104 | args.service = (ofw_arg_t) service; |
98 | args.nargs = nargs; |
105 | args.nargs = nargs; |
99 | args.nret = nret; |
106 | args.nret = nret; |
100 | 107 | ||
101 | va_start(list, rets); |
108 | va_start(list, rets); |
102 | for (i = 0; i < nargs; i++) |
109 | for (i = 0; i < nargs; i++) |
103 | args.args[i] = va_arg(list, ofw_arg_t); |
110 | args.args[i] = va_arg(list, ofw_arg_t); |
104 | va_end(list); |
111 | va_end(list); |
105 | 112 | ||
106 | for (i = 0; i < nret; i++) |
113 | for (i = 0; i < nret; i++) |
107 | args.args[i + nargs] = 0; |
114 | args.args[i + nargs] = 0; |
108 | 115 | ||
109 | (void) ofw(&args); |
116 | (void) ofw(&args); |
110 | 117 | ||
111 | for (i = 1; i < nret; i++) |
118 | for (i = 1; i < nret; i++) |
112 | rets[i - 1] = args.args[i + nargs]; |
119 | rets[i - 1] = args.args[i + nargs]; |
113 | 120 | ||
114 | return args.args[nargs]; |
121 | return args.args[nargs]; |
115 | } |
122 | } |
116 | 123 | ||
117 | phandle ofw_find_device(const char *name) |
124 | phandle ofw_find_device(const char *name) |
118 | { |
125 | { |
119 | return ofw_call("finddevice", 1, 1, NULL, name); |
126 | return ofw_call("finddevice", 1, 1, NULL, name); |
120 | } |
127 | } |
121 | 128 | ||
- | 129 | int |
|
122 | int ofw_get_property(const phandle device, const char *name, void *buf, const int buflen) |
130 | ofw_get_property(const phandle device, const char *name, void *buf, |
- | 131 | const int buflen) |
|
123 | { |
132 | { |
124 | return ofw_call("getprop", 4, 1, NULL, device, name, buf, buflen); |
133 | return ofw_call("getprop", 4, 1, NULL, device, name, buf, buflen); |
125 | } |
134 | } |
126 | 135 | ||
127 | int ofw_get_proplen(const phandle device, const char *name) |
136 | int ofw_get_proplen(const phandle device, const char *name) |
128 | { |
137 | { |
129 | return ofw_call("getproplen", 2, 1, NULL, device, name); |
138 | return ofw_call("getproplen", 2, 1, NULL, device, name); |
130 | } |
139 | } |
131 | 140 | ||
132 | int ofw_next_property(const phandle device, char *previous, char *buf) |
141 | int ofw_next_property(const phandle device, char *previous, char *buf) |
133 | { |
142 | { |
134 | return ofw_call("nextprop", 3, 1, NULL, device, previous, buf); |
143 | return ofw_call("nextprop", 3, 1, NULL, device, previous, buf); |
135 | } |
144 | } |
136 | 145 | ||
137 | int ofw_package_to_path(const phandle device, char *buf, const int buflen) |
146 | int ofw_package_to_path(const phandle device, char *buf, const int buflen) |
138 | { |
147 | { |
139 | return ofw_call("package-to-path", 3, 1, NULL, device, buf, buflen); |
148 | return ofw_call("package-to-path", 3, 1, NULL, device, buf, buflen); |
140 | } |
149 | } |
141 | 150 | ||
142 | unsigned int ofw_get_address_cells(const phandle device) |
151 | unsigned int ofw_get_address_cells(const phandle device) |
143 | { |
152 | { |
144 | unsigned int ret = 1; |
153 | unsigned int ret = 1; |
145 | 154 | ||
146 | if (ofw_get_property(device, "#address-cells", &ret, sizeof(ret)) <= 0) |
155 | if (ofw_get_property(device, "#address-cells", &ret, sizeof(ret)) <= 0) |
147 | if (ofw_get_property(ofw_root, "#address-cells", &ret, sizeof(ret)) <= 0) |
156 | if (ofw_get_property(ofw_root, "#address-cells", &ret, |
- | 157 | sizeof(ret)) <= 0) |
|
148 | ret = OFW_ADDRESS_CELLS; |
158 | ret = OFW_ADDRESS_CELLS; |
149 | 159 | ||
150 | return ret; |
160 | return ret; |
151 | } |
161 | } |
152 | 162 | ||
153 | 163 | ||
154 | unsigned int ofw_get_size_cells(const phandle device) |
164 | unsigned int ofw_get_size_cells(const phandle device) |
155 | { |
165 | { |
156 | unsigned int ret; |
166 | unsigned int ret; |
157 | 167 | ||
158 | if (ofw_get_property(device, "#size-cells", &ret, sizeof(ret)) <= 0) |
168 | if (ofw_get_property(device, "#size-cells", &ret, sizeof(ret)) <= 0) |
159 | if (ofw_get_property(ofw_root, "#size-cells", &ret, sizeof(ret)) <= 0) |
169 | if (ofw_get_property(ofw_root, "#size-cells", &ret, |
- | 170 | sizeof(ret)) <= 0) |
|
160 | ret = OFW_SIZE_CELLS; |
171 | ret = OFW_SIZE_CELLS; |
161 | 172 | ||
162 | return ret; |
173 | return ret; |
163 | } |
174 | } |
164 | 175 | ||
165 | phandle ofw_get_child_node(const phandle node) |
176 | phandle ofw_get_child_node(const phandle node) |
166 | { |
177 | { |
167 | return ofw_call("child", 1, 1, NULL, node); |
178 | return ofw_call("child", 1, 1, NULL, node); |
168 | } |
179 | } |
169 | 180 | ||
170 | phandle ofw_get_peer_node(const phandle node) |
181 | phandle ofw_get_peer_node(const phandle node) |
171 | { |
182 | { |
172 | return ofw_call("peer", 1, 1, NULL, node); |
183 | return ofw_call("peer", 1, 1, NULL, node); |
173 | } |
184 | } |
174 | 185 | ||
175 | static ihandle ofw_open(const char *name) |
186 | static ihandle ofw_open(const char *name) |
176 | { |
187 | { |
177 | return ofw_call("open", 1, 1, NULL, name); |
188 | return ofw_call("open", 1, 1, NULL, name); |
178 | } |
189 | } |
179 | 190 | ||
180 | 191 | ||
181 | void ofw_write(const char *str, const int len) |
192 | void ofw_write(const char *str, const int len) |
182 | { |
193 | { |
183 | if (ofw_stdout == 0) |
194 | if (ofw_stdout == 0) |
184 | return; |
195 | return; |
185 | 196 | ||
186 | ofw_call("write", 3, 1, NULL, ofw_stdout, str, len); |
197 | ofw_call("write", 3, 1, NULL, ofw_stdout, str, len); |
187 | } |
198 | } |
188 | 199 | ||
189 | 200 | ||
190 | void *ofw_translate(const void *virt) |
201 | void *ofw_translate(const void *virt) |
191 | { |
202 | { |
192 | ofw_arg_t result[4]; |
203 | ofw_arg_t result[4]; |
193 | int shift; |
204 | int shift; |
194 | 205 | ||
195 | if (ofw_call("call-method", 3, 5, result, "translate", ofw_mmu, virt) != 0) { |
206 | if (ofw_call("call-method", 4, 5, result, "translate", ofw_mmu, |
- | 207 | virt, 0) != 0) { |
|
196 | puts("Error: MMU method translate() failed, halting.\n"); |
208 | puts("Error: MMU method translate() failed, halting.\n"); |
197 | halt(); |
209 | halt(); |
198 | } |
210 | } |
199 | 211 | ||
200 | if (ofw_translate_failed(result[0])) |
212 | if (ofw_translate_failed(result[0])) |
201 | return NULL; |
213 | return NULL; |
202 | 214 | ||
203 | if (sizeof(unative_t) == 8) |
215 | if (sizeof(unative_t) == 8) |
204 | shift = 32; |
216 | shift = 32; |
205 | else |
217 | else |
206 | shift = 0; |
218 | shift = 0; |
207 | 219 | ||
208 | return (void *) ((result[2] << shift) | result[3]); |
220 | return (void *) ((result[2] << shift) | result[3]); |
209 | } |
221 | } |
210 | 222 | ||
211 | void *ofw_claim_virt(const void *virt, const int len) |
223 | void *ofw_claim_virt(const void *virt, const int len) |
212 | { |
224 | { |
213 | ofw_arg_t retaddr; |
225 | ofw_arg_t retaddr; |
214 | 226 | ||
215 | if (ofw_call("call-method", 5, 2, &retaddr, "claim", ofw_mmu, 0, len, virt) != 0) { |
227 | if (ofw_call("call-method", 5, 2, &retaddr, "claim", ofw_mmu, 0, len, |
- | 228 | virt) != 0) { |
|
216 | puts("Error: MMU method claim() failed, halting.\n"); |
229 | puts("Error: MMU method claim() failed, halting.\n"); |
217 | halt(); |
230 | halt(); |
218 | } |
231 | } |
219 | 232 | ||
220 | return (void *) retaddr; |
233 | return (void *) retaddr; |
221 | } |
234 | } |
222 | 235 | ||
223 | void *ofw_claim_phys(const void *phys, const int len) |
236 | void *ofw_claim_phys(const void *phys, const int len) |
224 | { |
237 | { |
225 | ofw_arg_t retaddr[2]; |
238 | ofw_arg_t retaddr[2]; |
226 | int shift; |
239 | int shift; |
227 | 240 | ||
228 | if (sizeof(unative_t) == 8) { |
241 | if (sizeof(unative_t) == 8) { |
229 | shift = 32; |
242 | shift = 32; |
230 | if (ofw_call("call-method", 6, 3, retaddr, "claim", |
243 | if (ofw_call("call-method", 6, 3, retaddr, "claim", |
231 | ofw_memory_prop, 0, len, ((uintptr_t) phys) >> shift, |
244 | ofw_memory_prop, 0, len, ((uintptr_t) phys) >> shift, |
232 | ((uintptr_t) phys) & ((uint32_t) -1)) != 0) { |
245 | ((uintptr_t) phys) & ((uint32_t) -1)) != 0) { |
233 | /* |
246 | /* |
234 | * Note that this will help us to discover |
247 | * Note that this will help us to discover |
235 | * conflicts between OpenFirmware allocations |
248 | * conflicts between OpenFirmware allocations |
236 | * and our use of physical memory. |
249 | * and our use of physical memory. |
237 | * It is better to detect collisions here |
250 | * It is better to detect collisions here |
238 | * than to cope with weird errors later. |
251 | * than to cope with weird errors later. |
239 | * |
252 | * |
240 | * So this is really not to make the loader |
253 | * So this is really not to make the loader |
241 | * more generic; it is here for debugging |
254 | * more generic; it is here for debugging |
242 | * purposes. |
255 | * purposes. |
243 | */ |
256 | */ |
244 | puts("Error: memory method claim() failed, halting.\n"); |
257 | puts("Error: memory method claim() failed, halting.\n"); |
245 | halt(); |
258 | halt(); |
246 | } |
259 | } |
247 | } else { |
260 | } else { |
248 | shift = 0; |
261 | shift = 0; |
249 | /* |
262 | /* |
250 | * FIXME: the number of arguments is probably different... |
263 | * FIXME: the number of arguments is probably different... |
251 | */ |
264 | */ |
252 | puts("Error: 32-bit ofw_claim_phys not implemented.\n"); |
265 | puts("Error: 32-bit ofw_claim_phys not implemented.\n"); |
253 | halt(); |
266 | halt(); |
254 | } |
267 | } |
255 | 268 | ||
256 | return (void *) ((retaddr[0] << shift) | retaddr[1]); |
269 | return (void *) ((retaddr[0] << shift) | retaddr[1]); |
257 | } |
270 | } |
258 | 271 | ||
259 | int ofw_map(const void *phys, const void *virt, const int size, const int mode) |
272 | int ofw_map(const void *phys, const void *virt, const int size, const int mode) |
260 | { |
273 | { |
261 | uintptr_t phys_hi, phys_lo; |
274 | uintptr_t phys_hi, phys_lo; |
262 | 275 | ||
263 | if (sizeof(unative_t) == 8) { |
276 | if (sizeof(unative_t) == 8) { |
264 | int shift = 32; |
277 | int shift = 32; |
265 | phys_hi = (uintptr_t) phys >> shift; |
278 | phys_hi = (uintptr_t) phys >> shift; |
266 | phys_lo = (uintptr_t) phys & 0xffffffff; |
279 | phys_lo = (uintptr_t) phys & 0xffffffff; |
267 | } else { |
280 | } else { |
268 | phys_hi = 0; |
281 | phys_hi = 0; |
269 | phys_lo = (uintptr_t) phys; |
282 | phys_lo = (uintptr_t) phys; |
270 | } |
283 | } |
271 | 284 | ||
272 | return ofw_call("call-method", 7, 1, NULL, "map", ofw_mmu, mode, size, virt, |
285 | return ofw_call("call-method", 7, 1, NULL, "map", ofw_mmu, mode, size, |
273 | phys_hi, phys_lo); |
286 | virt, phys_hi, phys_lo); |
274 | } |
287 | } |
275 | 288 | ||
276 | /** Save OpenFirmware physical memory map. |
289 | /** Save OpenFirmware physical memory map. |
277 | * |
290 | * |
278 | * @param map Memory map structure where the map will be saved. |
291 | * @param map Memory map structure where the map will be saved. |
279 | * |
292 | * |
280 | * @return Zero on failure, non-zero on success. |
293 | * @return Zero on failure, non-zero on success. |
281 | */ |
294 | */ |
282 | int ofw_memmap(memmap_t *map) |
295 | int ofw_memmap(memmap_t *map) |
283 | { |
296 | { |
284 | unsigned int ac = ofw_get_address_cells(ofw_memory); |
297 | unsigned int ac = ofw_get_address_cells(ofw_memory) / |
- | 298 | (sizeof(uintptr_t) / sizeof(uint32_t)); |
|
285 | unsigned int sc = ofw_get_size_cells(ofw_memory); |
299 | unsigned int sc = ofw_get_size_cells(ofw_memory) / |
- | 300 | (sizeof(uintptr_t) / sizeof(uint32_t)); |
|
286 | 301 | ||
287 | uint32_t buf[((ac + sc) * MEMMAP_MAX_RECORDS)]; |
302 | uintptr_t buf[((ac + sc) * MEMMAP_MAX_RECORDS)]; |
288 | int ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(buf)); |
303 | int ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(buf)); |
289 | if (ret <= 0) /* ret is the number of written bytes */ |
304 | if (ret <= 0) /* ret is the number of written bytes */ |
290 | return false; |
305 | return false; |
291 | 306 | ||
292 | int pos; |
307 | int pos; |
293 | map->total = 0; |
308 | map->total = 0; |
294 | map->count = 0; |
309 | map->count = 0; |
295 | for (pos = 0; (pos < ret / sizeof(uint32_t)) && |
310 | for (pos = 0; (pos < ret / sizeof(uintptr_t)) && |
296 | (map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) { |
311 | (map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) { |
297 | void * start = (void *) ((uintptr_t) buf[pos + ac - 1]); |
312 | void *start = (void *) (buf[pos + ac - 1]); |
298 | unsigned int size = buf[pos + ac + sc - 1]; |
313 | unsigned int size = buf[pos + ac + sc - 1]; |
- | 314 | ||
299 | 315 | /* |
|
- | 316 | * This is a hot fix of the issue which occurs on machines |
|
- | 317 | * where there are holes in the physical memory (such as |
|
- | 318 | * SunBlade 1500). Should we detect a hole in the physical |
|
- | 319 | * memory, we will ignore any memory detected behind |
|
- | 320 | * the hole and pretend the hole does not exist. |
|
- | 321 | */ |
|
- | 322 | if ((map->count > 0) && (map->zones[map->count - 1].start + |
|
- | 323 | map->zones[map->count - 1].size < start)) |
|
- | 324 | break; |
|
- | 325 | ||
300 | if (size > 0) { |
326 | if (size > 0) { |
301 | map->zones[map->count].start = start; |
327 | map->zones[map->count].start = start; |
302 | map->zones[map->count].size = size; |
328 | map->zones[map->count].size = size; |
303 | map->count++; |
329 | map->count++; |
304 | map->total += size; |
330 | map->total += size; |
305 | } |
331 | } |
306 | } |
332 | } |
307 | 333 | ||
308 | return true; |
334 | return true; |
309 | } |
335 | } |
310 | 336 | ||
311 | - | ||
312 | int ofw_screen(screen_t *screen) |
337 | int ofw_screen(screen_t *screen) |
313 | { |
338 | { |
314 | char device_name[BUF_SIZE]; |
339 | char device_name[BUF_SIZE]; |
315 | uint32_t virtaddr; |
340 | uint32_t virtaddr; |
316 | 341 | ||
317 | if (ofw_get_property(ofw_aliases, "screen", device_name, sizeof(device_name)) <= 0) |
342 | if (ofw_get_property(ofw_aliases, "screen", device_name, |
- | 343 | sizeof(device_name)) <= 0) |
|
318 | return false; |
344 | return false; |
319 | 345 | ||
320 | phandle device = ofw_find_device(device_name); |
346 | phandle device = ofw_find_device(device_name); |
321 | if (device == -1) |
347 | if (device == -1) |
322 | return false; |
348 | return false; |
323 | 349 | ||
324 | if (ofw_get_property(device, "address", &virtaddr, sizeof(virtaddr)) <= 0) |
350 | if (ofw_get_property(device, "address", &virtaddr, |
- | 351 | sizeof(virtaddr)) <= 0) |
|
325 | return false; |
352 | return false; |
326 | 353 | ||
327 | screen->addr = (void *) ((uintptr_t) virtaddr); |
354 | screen->addr = (void *) ((uintptr_t) virtaddr); |
328 | 355 | ||
329 | if (ofw_get_property(device, "width", &screen->width, sizeof(screen->width)) <= 0) |
356 | if (ofw_get_property(device, "width", &screen->width, |
- | 357 | sizeof(screen->width)) <= 0) |
|
330 | return false; |
358 | return false; |
331 | 359 | ||
332 | if (ofw_get_property(device, "height", &screen->height, sizeof(screen->height)) <= 0) |
360 | if (ofw_get_property(device, "height", &screen->height, |
- | 361 | sizeof(screen->height)) <= 0) |
|
333 | return false; |
362 | return false; |
334 | 363 | ||
335 | if (ofw_get_property(device, "depth", &screen->bpp, sizeof(screen->bpp)) <= 0) |
364 | if (ofw_get_property(device, "depth", &screen->bpp, |
- | 365 | sizeof(screen->bpp)) <= 0) |
|
336 | return false; |
366 | return false; |
337 | 367 | ||
338 | if (ofw_get_property(device, "linebytes", &screen->scanline, sizeof(screen->scanline)) <= 0) |
368 | if (ofw_get_property(device, "linebytes", &screen->scanline, |
- | 369 | sizeof(screen->scanline)) <= 0) |
|
339 | return false; |
370 | return false; |
340 | 371 | ||
341 | return true; |
372 | return true; |
342 | } |
373 | } |
343 | 374 | ||
- | 375 | #define RED(i) (((i) >> 5) & ((1 << 3) - 1)) |
|
- | 376 | #define GREEN(i) (((i) >> 3) & ((1 << 2) - 1)) |
|
- | 377 | #define BLUE(i) ((i) & ((1 << 3) - 1)) |
|
- | 378 | #define CLIP(i) ((i) <= 255 ? (i) : 255) |
|
- | 379 | ||
- | 380 | ||
- | 381 | /** |
|
- | 382 | * Sets up the palette for the 8-bit color depth configuration so that the |
|
- | 383 | * 3:2:3 color scheme can be used. Checks that setting the palette makes sense |
|
- | 384 | * (appropriate nodes exist in the OBP tree and the color depth is not greater |
|
- | 385 | * than 8). |
|
- | 386 | * |
|
- | 387 | * @return true if the palette has been set, false otherwise |
|
- | 388 | * |
|
- | 389 | */ |
|
- | 390 | int ofw_setup_palette(void) |
|
- | 391 | { |
|
- | 392 | char device_name[BUF_SIZE]; |
|
- | 393 | ||
- | 394 | /* resolve alias */ |
|
- | 395 | if (ofw_get_property(ofw_aliases, "screen", device_name, |
|
- | 396 | sizeof(device_name)) <= 0) |
|
- | 397 | return false; |
|
- | 398 | ||
- | 399 | /* for depth greater than 8 it makes no sense to set up the palette */ |
|
- | 400 | uint32_t depth; |
|
- | 401 | phandle device = ofw_find_device(device_name); |
|
- | 402 | if (device == -1) |
|
- | 403 | return false; |
|
- | 404 | if (ofw_get_property(device, "depth", &depth, sizeof(uint32_t)) <= 0) |
|
- | 405 | return false; |
|
- | 406 | if (depth != 8) |
|
- | 407 | return false; |
|
- | 408 | ||
- | 409 | /* required in order to be able to make a method call */ |
|
- | 410 | ihandle screen = ofw_open(device_name); |
|
- | 411 | if (screen == -1) |
|
- | 412 | return false; |
|
- | 413 | ||
- | 414 | /* setup the palette so that the (inverted) 3:2:3 scheme is usable */ |
|
- | 415 | unsigned int i; |
|
- | 416 | for (i = 0; i < 256; i++) |
|
- | 417 | ofw_call("call-method", 6, 1, NULL, "color!", screen, |
|
- | 418 | 255 - i, CLIP(BLUE(i) * 37), GREEN(i) * 85, CLIP(RED(i) * 37)); |
|
- | 419 | return true; |
|
- | 420 | } |
|
344 | 421 | ||
345 | void ofw_quiesce(void) |
422 | void ofw_quiesce(void) |
346 | { |
423 | { |
347 | ofw_call("quiesce", 0, 0, NULL); |
424 | ofw_call("quiesce", 0, 0, NULL); |
348 | } |
425 | } |
349 | 426 |