Rev 2071 | Rev 3022 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2071 | Rev 2250 | ||
---|---|---|---|
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 | phandle ofw_memory; |
42 | phandle ofw_memory; |
42 | phandle ofw_aliases; |
43 | phandle ofw_aliases; |
43 | 44 | ||
44 | void ofw_init(void) |
45 | void ofw_init(void) |
45 | { |
46 | { |
46 | ofw_chosen = ofw_find_device("/chosen"); |
47 | ofw_chosen = ofw_find_device("/chosen"); |
47 | if (ofw_chosen == -1) |
48 | if (ofw_chosen == -1) |
48 | halt(); |
49 | halt(); |
49 | 50 | ||
50 | if (ofw_get_property(ofw_chosen, "stdout", &ofw_stdout, sizeof(ofw_stdout)) <= 0) |
51 | if (ofw_get_property(ofw_chosen, "stdout", &ofw_stdout, sizeof(ofw_stdout)) <= 0) |
51 | ofw_stdout = 0; |
52 | ofw_stdout = 0; |
52 | 53 | ||
53 | ofw_root = ofw_find_device("/"); |
54 | ofw_root = ofw_find_device("/"); |
54 | if (ofw_root == -1) { |
55 | if (ofw_root == -1) { |
55 | puts("\r\nError: Unable to find / device, halted.\r\n"); |
56 | puts("\r\nError: Unable to find / device, halted.\r\n"); |
56 | halt(); |
57 | halt(); |
57 | } |
58 | } |
58 | 59 | ||
59 | if (ofw_get_property(ofw_chosen, "mmu", &ofw_mmu, sizeof(ofw_mmu)) <= 0) { |
60 | if (ofw_get_property(ofw_chosen, "mmu", &ofw_mmu, sizeof(ofw_mmu)) <= 0) { |
60 | puts("\r\nError: Unable to get mmu property, halted.\r\n"); |
61 | puts("\r\nError: Unable to get mmu property, halted.\r\n"); |
61 | halt(); |
62 | halt(); |
62 | } |
63 | } |
- | 64 | if (ofw_get_property(ofw_chosen, "memory", &ofw_memory_prop, sizeof(ofw_memory_prop)) <= 0) { |
|
- | 65 | puts("\r\nError: Unable to get memory property, halted.\r\n"); |
|
- | 66 | halt(); |
|
- | 67 | } |
|
63 | 68 | ||
64 | ofw_memory = ofw_find_device("/memory"); |
69 | ofw_memory = ofw_find_device("/memory"); |
65 | if (ofw_memory == -1) { |
70 | if (ofw_memory == -1) { |
66 | puts("\r\nError: Unable to find /memory device, halted.\r\n"); |
71 | puts("\r\nError: Unable to find /memory device, halted.\r\n"); |
67 | halt(); |
72 | halt(); |
68 | } |
73 | } |
69 | 74 | ||
70 | ofw_aliases = ofw_find_device("/aliases"); |
75 | ofw_aliases = ofw_find_device("/aliases"); |
71 | if (ofw_aliases == -1) { |
76 | if (ofw_aliases == -1) { |
72 | puts("\r\nError: Unable to find /aliases device, halted.\r\n"); |
77 | puts("\r\nError: Unable to find /aliases device, halted.\r\n"); |
73 | halt(); |
78 | halt(); |
74 | } |
79 | } |
75 | } |
80 | } |
76 | 81 | ||
77 | /** Perform a call to OpenFirmware client interface. |
82 | /** Perform a call to OpenFirmware client interface. |
78 | * |
83 | * |
79 | * @param service String identifying the service requested. |
84 | * @param service String identifying the service requested. |
80 | * @param nargs Number of input arguments. |
85 | * @param nargs Number of input arguments. |
81 | * @param nret Number of output arguments. This includes the return value. |
86 | * @param nret Number of output arguments. This includes the return value. |
82 | * @param rets Buffer for output arguments or NULL. The buffer must accommodate nret - 1 items. |
87 | * @param rets Buffer for output arguments or NULL. The buffer must accommodate nret - 1 items. |
83 | * |
88 | * |
84 | * @return Return value returned by the client interface. |
89 | * @return Return value returned by the client interface. |
85 | */ |
90 | */ |
86 | unsigned long ofw_call(const char *service, const int nargs, const int nret, ofw_arg_t *rets, ...) |
91 | unsigned long ofw_call(const char *service, const int nargs, const int nret, ofw_arg_t *rets, ...) |
87 | { |
92 | { |
88 | va_list list; |
93 | va_list list; |
89 | ofw_args_t args; |
94 | ofw_args_t args; |
90 | int i; |
95 | int i; |
91 | 96 | ||
92 | args.service = (ofw_arg_t) service; |
97 | args.service = (ofw_arg_t) service; |
93 | args.nargs = nargs; |
98 | args.nargs = nargs; |
94 | args.nret = nret; |
99 | args.nret = nret; |
95 | 100 | ||
96 | va_start(list, rets); |
101 | va_start(list, rets); |
97 | for (i = 0; i < nargs; i++) |
102 | for (i = 0; i < nargs; i++) |
98 | args.args[i] = va_arg(list, ofw_arg_t); |
103 | args.args[i] = va_arg(list, ofw_arg_t); |
99 | va_end(list); |
104 | va_end(list); |
100 | 105 | ||
101 | for (i = 0; i < nret; i++) |
106 | for (i = 0; i < nret; i++) |
102 | args.args[i + nargs] = 0; |
107 | args.args[i + nargs] = 0; |
103 | 108 | ||
104 | (void) ofw(&args); |
109 | (void) ofw(&args); |
105 | 110 | ||
106 | for (i = 1; i < nret; i++) |
111 | for (i = 1; i < nret; i++) |
107 | rets[i - 1] = args.args[i + nargs]; |
112 | rets[i - 1] = args.args[i + nargs]; |
108 | 113 | ||
109 | return args.args[nargs]; |
114 | return args.args[nargs]; |
110 | } |
115 | } |
111 | 116 | ||
112 | phandle ofw_find_device(const char *name) |
117 | phandle ofw_find_device(const char *name) |
113 | { |
118 | { |
114 | return ofw_call("finddevice", 1, 1, NULL, name); |
119 | return ofw_call("finddevice", 1, 1, NULL, name); |
115 | } |
120 | } |
116 | 121 | ||
117 | int ofw_get_property(const phandle device, const char *name, void *buf, const int buflen) |
122 | int ofw_get_property(const phandle device, const char *name, void *buf, const int buflen) |
118 | { |
123 | { |
119 | return ofw_call("getprop", 4, 1, NULL, device, name, buf, buflen); |
124 | return ofw_call("getprop", 4, 1, NULL, device, name, buf, buflen); |
120 | } |
125 | } |
121 | 126 | ||
122 | int ofw_get_proplen(const phandle device, const char *name) |
127 | int ofw_get_proplen(const phandle device, const char *name) |
123 | { |
128 | { |
124 | return ofw_call("getproplen", 2, 1, NULL, device, name); |
129 | return ofw_call("getproplen", 2, 1, NULL, device, name); |
125 | } |
130 | } |
126 | 131 | ||
127 | int ofw_next_property(const phandle device, char *previous, char *buf) |
132 | int ofw_next_property(const phandle device, char *previous, char *buf) |
128 | { |
133 | { |
129 | return ofw_call("nextprop", 3, 1, NULL, device, previous, buf); |
134 | return ofw_call("nextprop", 3, 1, NULL, device, previous, buf); |
130 | } |
135 | } |
131 | 136 | ||
132 | int ofw_package_to_path(const phandle device, char *buf, const int buflen) |
137 | int ofw_package_to_path(const phandle device, char *buf, const int buflen) |
133 | { |
138 | { |
134 | return ofw_call("package-to-path", 3, 1, NULL, device, buf, buflen); |
139 | return ofw_call("package-to-path", 3, 1, NULL, device, buf, buflen); |
135 | } |
140 | } |
136 | 141 | ||
137 | unsigned int ofw_get_address_cells(const phandle device) |
142 | unsigned int ofw_get_address_cells(const phandle device) |
138 | { |
143 | { |
139 | unsigned int ret = 1; |
144 | unsigned int ret = 1; |
140 | 145 | ||
141 | if (ofw_get_property(device, "#address-cells", &ret, sizeof(ret)) <= 0) |
146 | if (ofw_get_property(device, "#address-cells", &ret, sizeof(ret)) <= 0) |
142 | if (ofw_get_property(ofw_root, "#address-cells", &ret, sizeof(ret)) <= 0) |
147 | if (ofw_get_property(ofw_root, "#address-cells", &ret, sizeof(ret)) <= 0) |
143 | ret = OFW_ADDRESS_CELLS; |
148 | ret = OFW_ADDRESS_CELLS; |
144 | 149 | ||
145 | return ret; |
150 | return ret; |
146 | } |
151 | } |
147 | 152 | ||
148 | 153 | ||
149 | unsigned int ofw_get_size_cells(const phandle device) |
154 | unsigned int ofw_get_size_cells(const phandle device) |
150 | { |
155 | { |
151 | unsigned int ret; |
156 | unsigned int ret; |
152 | 157 | ||
153 | if (ofw_get_property(device, "#size-cells", &ret, sizeof(ret)) <= 0) |
158 | if (ofw_get_property(device, "#size-cells", &ret, sizeof(ret)) <= 0) |
154 | if (ofw_get_property(ofw_root, "#size-cells", &ret, sizeof(ret)) <= 0) |
159 | if (ofw_get_property(ofw_root, "#size-cells", &ret, sizeof(ret)) <= 0) |
155 | ret = OFW_SIZE_CELLS; |
160 | ret = OFW_SIZE_CELLS; |
156 | 161 | ||
157 | return ret; |
162 | return ret; |
158 | } |
163 | } |
159 | 164 | ||
160 | phandle ofw_get_child_node(const phandle node) |
165 | phandle ofw_get_child_node(const phandle node) |
161 | { |
166 | { |
162 | return ofw_call("child", 1, 1, NULL, node); |
167 | return ofw_call("child", 1, 1, NULL, node); |
163 | } |
168 | } |
164 | 169 | ||
165 | phandle ofw_get_peer_node(const phandle node) |
170 | phandle ofw_get_peer_node(const phandle node) |
166 | { |
171 | { |
167 | return ofw_call("peer", 1, 1, NULL, node); |
172 | return ofw_call("peer", 1, 1, NULL, node); |
168 | } |
173 | } |
169 | 174 | ||
170 | static ihandle ofw_open(const char *name) |
175 | static ihandle ofw_open(const char *name) |
171 | { |
176 | { |
172 | return ofw_call("open", 1, 1, NULL, name); |
177 | return ofw_call("open", 1, 1, NULL, name); |
173 | } |
178 | } |
174 | 179 | ||
175 | 180 | ||
176 | void ofw_write(const char *str, const int len) |
181 | void ofw_write(const char *str, const int len) |
177 | { |
182 | { |
178 | if (ofw_stdout == 0) |
183 | if (ofw_stdout == 0) |
179 | return; |
184 | return; |
180 | 185 | ||
181 | ofw_call("write", 3, 1, NULL, ofw_stdout, str, len); |
186 | ofw_call("write", 3, 1, NULL, ofw_stdout, str, len); |
182 | } |
187 | } |
183 | 188 | ||
184 | 189 | ||
185 | void *ofw_translate(const void *virt) |
190 | void *ofw_translate(const void *virt) |
186 | { |
191 | { |
187 | ofw_arg_t result[4]; |
192 | ofw_arg_t result[4]; |
188 | int shift; |
193 | int shift; |
189 | 194 | ||
190 | if (ofw_call("call-method", 3, 5, result, "translate", ofw_mmu, virt) != 0) { |
195 | if (ofw_call("call-method", 3, 5, result, "translate", ofw_mmu, virt) != 0) { |
191 | puts("Error: MMU method translate() failed, halting.\n"); |
196 | puts("Error: MMU method translate() failed, halting.\n"); |
192 | halt(); |
197 | halt(); |
193 | } |
198 | } |
194 | 199 | ||
195 | if (ofw_translate_failed(result[0])) |
200 | if (ofw_translate_failed(result[0])) |
196 | return NULL; |
201 | return NULL; |
197 | 202 | ||
198 | if (sizeof(unative_t) == 8) |
203 | if (sizeof(unative_t) == 8) |
199 | shift = 32; |
204 | shift = 32; |
200 | else |
205 | else |
201 | shift = 0; |
206 | shift = 0; |
202 | 207 | ||
203 | return (void *) ((result[2]<<shift)|result[3]); |
208 | return (void *) ((result[2] << shift) | result[3]); |
204 | } |
209 | } |
205 | 210 | ||
206 | void *ofw_claim(const void *virt, const int len) |
211 | void *ofw_claim_virt(const void *virt, const int len) |
207 | { |
212 | { |
208 | ofw_arg_t retaddr; |
213 | ofw_arg_t retaddr; |
209 | int shift; |
- | |
210 | 214 | ||
211 | if (ofw_call("call-method", 5, 2, &retaddr, "claim", ofw_mmu, 0, len, virt) != 0) { |
215 | if (ofw_call("call-method", 5, 2, &retaddr, "claim", ofw_mmu, 0, len, virt) != 0) { |
212 | puts("Error: MMU method claim() failed, halting.\n"); |
216 | puts("Error: MMU method claim() failed, halting.\n"); |
213 | halt(); |
217 | halt(); |
214 | } |
218 | } |
215 | 219 | ||
216 | return (void *) retaddr; |
220 | return (void *) retaddr; |
217 | } |
221 | } |
218 | 222 | ||
- | 223 | void *ofw_claim_phys(const void *phys, const int len) |
|
- | 224 | { |
|
- | 225 | ofw_arg_t retaddr[2]; |
|
- | 226 | int shift; |
|
- | 227 | ||
- | 228 | if (sizeof(unative_t) == 8) { |
|
- | 229 | shift = 32; |
|
- | 230 | if (ofw_call("call-method", 6, 3, retaddr, "claim", |
|
- | 231 | ofw_memory_prop, 0, len, ((uintptr_t) phys) >> shift, |
|
- | 232 | ((uintptr_t) phys) & ((uint32_t) -1)) != 0) { |
|
- | 233 | /* |
|
- | 234 | * Note that this will help us to discover |
|
- | 235 | * conflicts between OpenFirmware allocations |
|
- | 236 | * and our use of physical memory. |
|
- | 237 | * It is better to detect collisions here |
|
- | 238 | * than to cope with weird errors later. |
|
- | 239 | * |
|
- | 240 | * So this is really not to make the loader |
|
- | 241 | * more generic; it is here for debugging |
|
- | 242 | * purposes. |
|
- | 243 | */ |
|
- | 244 | puts("Error: memory method claim() failed, halting.\n"); |
|
- | 245 | halt(); |
|
- | 246 | } |
|
- | 247 | } else { |
|
- | 248 | shift = 0; |
|
- | 249 | /* |
|
- | 250 | * FIXME: the number of arguments is probably different... |
|
- | 251 | */ |
|
- | 252 | puts("Error: 32-bit ofw_claim_phys not implemented.\n"); |
|
- | 253 | halt(); |
|
- | 254 | } |
|
- | 255 | ||
- | 256 | return (void *) ((retaddr[0] << shift) | retaddr[1]); |
|
- | 257 | } |
|
- | 258 | ||
219 | int ofw_map(const void *phys, const void *virt, const int size, const int mode) |
259 | int ofw_map(const void *phys, const void *virt, const int size, const int mode) |
220 | { |
260 | { |
221 | uintptr_t phys_hi, phys_lo; |
261 | uintptr_t phys_hi, phys_lo; |
222 | 262 | ||
223 | if (sizeof(unative_t) == 8) { |
263 | if (sizeof(unative_t) == 8) { |
224 | int shift = 32; |
264 | int shift = 32; |
225 | phys_hi = (uintptr_t) phys >> shift; |
265 | phys_hi = (uintptr_t) phys >> shift; |
226 | phys_lo = (uintptr_t) phys & 0xffffffff; |
266 | phys_lo = (uintptr_t) phys & 0xffffffff; |
227 | } else { |
267 | } else { |
228 | phys_hi = 0; |
268 | phys_hi = 0; |
229 | phys_lo = (uintptr_t) phys; |
269 | phys_lo = (uintptr_t) phys; |
230 | } |
270 | } |
231 | 271 | ||
232 | return ofw_call("call-method", 7, 1, NULL, "map", ofw_mmu, mode, size, virt, |
272 | return ofw_call("call-method", 7, 1, NULL, "map", ofw_mmu, mode, size, virt, |
233 | phys_hi, phys_lo); |
273 | phys_hi, phys_lo); |
234 | } |
274 | } |
235 | 275 | ||
236 | /** Save OpenFirmware physical memory map. |
276 | /** Save OpenFirmware physical memory map. |
237 | * |
277 | * |
238 | * @param map Memory map structure where the map will be saved. |
278 | * @param map Memory map structure where the map will be saved. |
239 | * |
279 | * |
240 | * @return Zero on failure, non-zero on success. |
280 | * @return Zero on failure, non-zero on success. |
241 | */ |
281 | */ |
242 | int ofw_memmap(memmap_t *map) |
282 | int ofw_memmap(memmap_t *map) |
243 | { |
283 | { |
244 | unsigned int ac = ofw_get_address_cells(ofw_memory); |
284 | unsigned int ac = ofw_get_address_cells(ofw_memory); |
245 | unsigned int sc = ofw_get_size_cells(ofw_memory); |
285 | unsigned int sc = ofw_get_size_cells(ofw_memory); |
246 | 286 | ||
247 | uint32_t buf[((ac + sc) * MEMMAP_MAX_RECORDS)]; |
287 | uint32_t buf[((ac + sc) * MEMMAP_MAX_RECORDS)]; |
248 | int ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(buf)); |
288 | int ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(buf)); |
249 | if (ret <= 0) /* ret is the number of written bytes */ |
289 | if (ret <= 0) /* ret is the number of written bytes */ |
250 | return false; |
290 | return false; |
251 | 291 | ||
252 | int pos; |
292 | int pos; |
253 | map->total = 0; |
293 | map->total = 0; |
254 | map->count = 0; |
294 | map->count = 0; |
255 | for (pos = 0; (pos < ret / sizeof(uint32_t)) && (map->count < |
295 | for (pos = 0; (pos < ret / sizeof(uint32_t)) && |
256 | MEMMAP_MAX_RECORDS); pos += ac + sc) { |
296 | (map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) { |
257 | void * start = (void *) ((uintptr_t) buf[pos + ac - 1]); |
297 | void * start = (void *) ((uintptr_t) buf[pos + ac - 1]); |
258 | unsigned int size = buf[pos + ac + sc - 1]; |
298 | unsigned int size = buf[pos + ac + sc - 1]; |
259 | 299 | ||
260 | if (size > 0) { |
300 | if (size > 0) { |
261 | map->zones[map->count].start = start; |
301 | map->zones[map->count].start = start; |
262 | map->zones[map->count].size = size; |
302 | map->zones[map->count].size = size; |
263 | map->count++; |
303 | map->count++; |
264 | map->total += size; |
304 | map->total += size; |
265 | } |
305 | } |
266 | } |
306 | } |
267 | 307 | ||
268 | return true; |
308 | return true; |
269 | } |
309 | } |
270 | 310 | ||
271 | 311 | ||
272 | int ofw_screen(screen_t *screen) |
312 | int ofw_screen(screen_t *screen) |
273 | { |
313 | { |
274 | char device_name[BUF_SIZE]; |
314 | char device_name[BUF_SIZE]; |
275 | uint32_t virtaddr; |
315 | uint32_t virtaddr; |
276 | 316 | ||
277 | if (ofw_get_property(ofw_aliases, "screen", device_name, sizeof(device_name)) <= 0) |
317 | if (ofw_get_property(ofw_aliases, "screen", device_name, sizeof(device_name)) <= 0) |
278 | return false; |
318 | return false; |
279 | 319 | ||
280 | phandle device = ofw_find_device(device_name); |
320 | phandle device = ofw_find_device(device_name); |
281 | if (device == -1) |
321 | if (device == -1) |
282 | return false; |
322 | return false; |
283 | 323 | ||
284 | if (ofw_get_property(device, "address", &virtaddr, sizeof(virtaddr)) <= 0) |
324 | if (ofw_get_property(device, "address", &virtaddr, sizeof(virtaddr)) <= 0) |
285 | return false; |
325 | return false; |
286 | 326 | ||
287 | screen->addr = (void *) ((uintptr_t) virtaddr); |
327 | screen->addr = (void *) ((uintptr_t) virtaddr); |
288 | 328 | ||
289 | if (ofw_get_property(device, "width", &screen->width, sizeof(screen->width)) <= 0) |
329 | if (ofw_get_property(device, "width", &screen->width, sizeof(screen->width)) <= 0) |
290 | return false; |
330 | return false; |
291 | 331 | ||
292 | if (ofw_get_property(device, "height", &screen->height, sizeof(screen->height)) <= 0) |
332 | if (ofw_get_property(device, "height", &screen->height, sizeof(screen->height)) <= 0) |
293 | return false; |
333 | return false; |
294 | 334 | ||
295 | if (ofw_get_property(device, "depth", &screen->bpp, sizeof(screen->bpp)) <= 0) |
335 | if (ofw_get_property(device, "depth", &screen->bpp, sizeof(screen->bpp)) <= 0) |
296 | return false; |
336 | return false; |
297 | 337 | ||
298 | if (ofw_get_property(device, "linebytes", &screen->scanline, sizeof(screen->scanline)) <= 0) |
338 | if (ofw_get_property(device, "linebytes", &screen->scanline, sizeof(screen->scanline)) <= 0) |
299 | return false; |
339 | return false; |
300 | 340 | ||
301 | return true; |
341 | return true; |
302 | } |
342 | } |
303 | 343 | ||
304 | 344 | ||
305 | void ofw_quiesce(void) |
345 | void ofw_quiesce(void) |
306 | { |
346 | { |
307 | ofw_call("quiesce", 0, 0, NULL); |
347 | ofw_call("quiesce", 0, 0, NULL); |
308 | } |
348 | } |
309 | 349 |