1 /* of.c - Access the Open Firmware client interface. */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2003,2004,2005,2007,2008 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB 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.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #include <grub/ieee1275/ieee1275.h>
21 #include <grub/types.h>
23 #define IEEE1275_PHANDLE_INVALID ((grub_ieee1275_phandle_t) -1)
24 #define IEEE1275_IHANDLE_INVALID ((grub_ieee1275_ihandle_t) 0)
25 #define IEEE1275_CELL_INVALID ((grub_ieee1275_cell_t) -1)
30 grub_ieee1275_finddevice (char *name
, grub_ieee1275_phandle_t
*phandlep
)
32 struct find_device_args
34 struct grub_ieee1275_common_hdr common
;
35 grub_ieee1275_cell_t device
;
36 grub_ieee1275_phandle_t phandle
;
40 INIT_IEEE1275_COMMON (&args
.common
, "finddevice", 1, 1);
41 args
.device
= (grub_ieee1275_cell_t
) name
;
43 if (IEEE1275_CALL_ENTRY_FN (&args
) == -1)
45 *phandlep
= args
.phandle
;
46 if (args
.phandle
== IEEE1275_PHANDLE_INVALID
)
52 grub_ieee1275_get_property (grub_ieee1275_phandle_t phandle
,
53 const char *property
, void *buf
,
54 grub_size_t size
, grub_ssize_t
*actual
)
56 struct get_property_args
58 struct grub_ieee1275_common_hdr common
;
59 grub_ieee1275_phandle_t phandle
;
60 grub_ieee1275_cell_t prop
;
61 grub_ieee1275_cell_t buf
;
62 grub_ieee1275_cell_t buflen
;
63 grub_ieee1275_cell_t size
;
67 INIT_IEEE1275_COMMON (&args
.common
, "getprop", 4, 1);
68 args
.phandle
= phandle
;
69 args
.prop
= (grub_ieee1275_cell_t
) property
;
70 args
.buf
= (grub_ieee1275_cell_t
) buf
;
71 args
.buflen
= (grub_ieee1275_cell_t
) size
;
73 if (IEEE1275_CALL_ENTRY_FN (&args
) == -1)
76 *actual
= (grub_ssize_t
) args
.size
;
77 if (args
.size
== IEEE1275_CELL_INVALID
)
83 grub_ieee1275_get_integer_property (grub_ieee1275_phandle_t phandle
,
84 const char *property
, grub_uint32_t
*buf
,
85 grub_size_t size
, grub_ssize_t
*actual
)
88 ret
= grub_ieee1275_get_property (phandle
, property
, (void *) buf
, size
, actual
);
89 #ifndef GRUB_CPU_WORDS_BIGENDIAN
90 /* Integer properties are always in big endian. */
94 size
/= sizeof (grub_uint32_t
);
95 for (i
= 0; i
< size
; i
++)
96 buf
[i
] = grub_be_to_cpu32 (buf
[i
]);
103 grub_ieee1275_next_property (grub_ieee1275_phandle_t phandle
, char *prev_prop
,
106 struct get_property_args
108 struct grub_ieee1275_common_hdr common
;
109 grub_ieee1275_phandle_t phandle
;
110 grub_ieee1275_cell_t prev_prop
;
111 grub_ieee1275_cell_t next_prop
;
112 grub_ieee1275_cell_t flags
;
116 INIT_IEEE1275_COMMON (&args
.common
, "nextprop", 3, 1);
117 args
.phandle
= phandle
;
118 args
.prev_prop
= (grub_ieee1275_cell_t
) prev_prop
;
119 args
.next_prop
= (grub_ieee1275_cell_t
) prop
;
120 args
.flags
= (grub_ieee1275_cell_t
) -1;
122 if (IEEE1275_CALL_ENTRY_FN (&args
) == -1)
124 return (int) args
.flags
;
128 grub_ieee1275_get_property_length (grub_ieee1275_phandle_t phandle
,
129 const char *prop
, grub_ssize_t
*length
)
131 struct get_property_args
133 struct grub_ieee1275_common_hdr common
;
134 grub_ieee1275_phandle_t phandle
;
135 grub_ieee1275_cell_t prop
;
136 grub_ieee1275_cell_t length
;
140 INIT_IEEE1275_COMMON (&args
.common
, "getproplen", 2, 1);
141 args
.phandle
= phandle
;
142 args
.prop
= (grub_ieee1275_cell_t
) prop
;
143 args
.length
= (grub_ieee1275_cell_t
) -1;
145 if (IEEE1275_CALL_ENTRY_FN (&args
) == -1)
147 *length
= args
.length
;
148 if (args
.length
== IEEE1275_CELL_INVALID
)
154 grub_ieee1275_instance_to_package (grub_ieee1275_ihandle_t ihandle
,
155 grub_ieee1275_phandle_t
*phandlep
)
157 struct instance_to_package_args
159 struct grub_ieee1275_common_hdr common
;
160 grub_ieee1275_ihandle_t ihandle
;
161 grub_ieee1275_phandle_t phandle
;
165 INIT_IEEE1275_COMMON (&args
.common
, "instance-to-package", 1, 1);
166 args
.ihandle
= ihandle
;
168 if (IEEE1275_CALL_ENTRY_FN (&args
) == -1)
170 *phandlep
= args
.phandle
;
171 if (args
.phandle
== IEEE1275_PHANDLE_INVALID
)
177 grub_ieee1275_package_to_path (grub_ieee1275_phandle_t phandle
,
178 char *path
, grub_size_t len
,
179 grub_ssize_t
*actual
)
181 struct instance_to_package_args
183 struct grub_ieee1275_common_hdr common
;
184 grub_ieee1275_phandle_t phandle
;
185 grub_ieee1275_cell_t buf
;
186 grub_ieee1275_cell_t buflen
;
187 grub_ieee1275_cell_t actual
;
191 INIT_IEEE1275_COMMON (&args
.common
, "package-to-path", 3, 1);
192 args
.phandle
= phandle
;
193 args
.buf
= (grub_ieee1275_cell_t
) path
;
194 args
.buflen
= (grub_ieee1275_cell_t
) len
;
196 if (IEEE1275_CALL_ENTRY_FN (&args
) == -1)
199 *actual
= args
.actual
;
200 if (args
.actual
== IEEE1275_CELL_INVALID
)
206 grub_ieee1275_instance_to_path (grub_ieee1275_ihandle_t ihandle
,
207 char *path
, grub_size_t len
,
208 grub_ssize_t
*actual
)
210 struct instance_to_path_args
212 struct grub_ieee1275_common_hdr common
;
213 grub_ieee1275_ihandle_t ihandle
;
214 grub_ieee1275_cell_t buf
;
215 grub_ieee1275_cell_t buflen
;
216 grub_ieee1275_cell_t actual
;
220 INIT_IEEE1275_COMMON (&args
.common
, "instance-to-path", 3, 1);
221 args
.ihandle
= ihandle
;
222 args
.buf
= (grub_ieee1275_cell_t
) path
;
223 args
.buflen
= (grub_ieee1275_cell_t
) len
;
225 if (IEEE1275_CALL_ENTRY_FN (&args
) == -1)
228 *actual
= args
.actual
;
229 if (args
.actual
== IEEE1275_CELL_INVALID
)
235 grub_ieee1275_write (grub_ieee1275_ihandle_t ihandle
, void *buffer
,
236 grub_size_t len
, grub_ssize_t
*actualp
)
240 struct grub_ieee1275_common_hdr common
;
241 grub_ieee1275_ihandle_t ihandle
;
242 grub_ieee1275_cell_t buf
;
243 grub_ieee1275_cell_t len
;
244 grub_ieee1275_cell_t actual
;
248 INIT_IEEE1275_COMMON (&args
.common
, "write", 3, 1);
249 args
.ihandle
= ihandle
;
250 args
.buf
= (grub_ieee1275_cell_t
) buffer
;
251 args
.len
= (grub_ieee1275_cell_t
) len
;
253 if (IEEE1275_CALL_ENTRY_FN (&args
) == -1)
256 *actualp
= args
.actual
;
261 grub_ieee1275_read (grub_ieee1275_ihandle_t ihandle
, void *buffer
,
262 grub_size_t len
, grub_ssize_t
*actualp
)
266 struct grub_ieee1275_common_hdr common
;
267 grub_ieee1275_ihandle_t ihandle
;
268 grub_ieee1275_cell_t buf
;
269 grub_ieee1275_cell_t len
;
270 grub_ieee1275_cell_t actual
;
274 INIT_IEEE1275_COMMON (&args
.common
, "read", 3, 1);
275 args
.ihandle
= ihandle
;
276 args
.buf
= (grub_ieee1275_cell_t
) buffer
;
277 args
.len
= (grub_ieee1275_cell_t
) len
;
279 if (IEEE1275_CALL_ENTRY_FN (&args
) == -1)
282 *actualp
= args
.actual
;
287 grub_ieee1275_seek (grub_ieee1275_ihandle_t ihandle
, int pos_hi
,
288 int pos_lo
, grub_ssize_t
*result
)
292 struct grub_ieee1275_common_hdr common
;
293 grub_ieee1275_ihandle_t ihandle
;
294 grub_ieee1275_cell_t pos_hi
;
295 grub_ieee1275_cell_t pos_lo
;
296 grub_ieee1275_cell_t result
;
300 INIT_IEEE1275_COMMON (&args
.common
, "seek", 3, 1);
301 args
.ihandle
= ihandle
;
302 args
.pos_hi
= (grub_ieee1275_cell_t
) pos_hi
;
303 args
.pos_lo
= (grub_ieee1275_cell_t
) pos_lo
;
305 if (IEEE1275_CALL_ENTRY_FN (&args
) == -1)
309 *result
= args
.result
;
314 grub_ieee1275_peer (grub_ieee1275_phandle_t node
,
315 grub_ieee1275_phandle_t
*result
)
319 struct grub_ieee1275_common_hdr common
;
320 grub_ieee1275_phandle_t node
;
321 grub_ieee1275_phandle_t result
;
325 INIT_IEEE1275_COMMON (&args
.common
, "peer", 1, 1);
328 if (IEEE1275_CALL_ENTRY_FN (&args
) == -1)
330 *result
= args
.result
;
331 if (args
.result
== 0)
337 grub_ieee1275_child (grub_ieee1275_phandle_t node
,
338 grub_ieee1275_phandle_t
*result
)
342 struct grub_ieee1275_common_hdr common
;
343 grub_ieee1275_phandle_t node
;
344 grub_ieee1275_phandle_t result
;
348 INIT_IEEE1275_COMMON (&args
.common
, "child", 1, 1);
350 args
.result
= IEEE1275_PHANDLE_INVALID
;
352 if (IEEE1275_CALL_ENTRY_FN (&args
) == -1)
354 *result
= args
.result
;
355 if (args
.result
== 0)
361 grub_ieee1275_parent (grub_ieee1275_phandle_t node
,
362 grub_ieee1275_phandle_t
*result
)
366 struct grub_ieee1275_common_hdr common
;
367 grub_ieee1275_phandle_t node
;
368 grub_ieee1275_phandle_t result
;
372 INIT_IEEE1275_COMMON (&args
.common
, "parent", 1, 1);
374 args
.result
= IEEE1275_PHANDLE_INVALID
;
376 if (IEEE1275_CALL_ENTRY_FN (&args
) == -1)
378 *result
= args
.result
;
383 grub_ieee1275_interpret (const char *command
, grub_ieee1275_cell_t
*catch)
387 struct grub_ieee1275_common_hdr common
;
388 grub_ieee1275_cell_t command
;
389 grub_ieee1275_cell_t
catch;
393 if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_CANNOT_INTERPRET
))
396 INIT_IEEE1275_COMMON (&args
.common
, "interpret", 1, 1);
397 args
.command
= (grub_ieee1275_cell_t
) command
;
399 if (IEEE1275_CALL_ENTRY_FN (&args
) == -1)
407 grub_ieee1275_enter (void)
411 struct grub_ieee1275_common_hdr common
;
415 INIT_IEEE1275_COMMON (&args
.common
, "enter", 0, 0);
417 if (IEEE1275_CALL_ENTRY_FN (&args
) == -1)
423 grub_ieee1275_exit (void)
427 struct grub_ieee1275_common_hdr common
;
431 INIT_IEEE1275_COMMON (&args
.common
, "exit", 0, 0);
433 IEEE1275_CALL_ENTRY_FN (&args
);
438 grub_ieee1275_open (const char *path
, grub_ieee1275_ihandle_t
*result
)
442 struct grub_ieee1275_common_hdr common
;
443 grub_ieee1275_cell_t path
;
444 grub_ieee1275_ihandle_t result
;
448 INIT_IEEE1275_COMMON (&args
.common
, "open", 1, 1);
449 args
.path
= (grub_ieee1275_cell_t
) path
;
451 if (IEEE1275_CALL_ENTRY_FN (&args
) == -1)
453 *result
= args
.result
;
454 if (args
.result
== IEEE1275_IHANDLE_INVALID
)
460 grub_ieee1275_close (grub_ieee1275_ihandle_t ihandle
)
464 struct grub_ieee1275_common_hdr common
;
465 grub_ieee1275_ihandle_t ihandle
;
469 INIT_IEEE1275_COMMON (&args
.common
, "close", 1, 0);
470 args
.ihandle
= ihandle
;
472 if (IEEE1275_CALL_ENTRY_FN (&args
) == -1)
479 grub_ieee1275_claim (grub_addr_t addr
, grub_size_t size
, unsigned int align
,
484 struct grub_ieee1275_common_hdr common
;
485 grub_ieee1275_cell_t addr
;
486 grub_ieee1275_cell_t size
;
487 grub_ieee1275_cell_t align
;
488 grub_ieee1275_cell_t base
;
492 INIT_IEEE1275_COMMON (&args
.common
, "claim", 3, 1);
493 args
.addr
= (grub_ieee1275_cell_t
) addr
;
494 args
.size
= (grub_ieee1275_cell_t
) size
;
495 args
.align
= (grub_ieee1275_cell_t
) align
;
497 if (IEEE1275_CALL_ENTRY_FN (&args
) == -1)
501 if (args
.base
== IEEE1275_CELL_INVALID
)
507 grub_ieee1275_release (grub_addr_t addr
, grub_size_t size
)
511 struct grub_ieee1275_common_hdr common
;
512 grub_ieee1275_cell_t addr
;
513 grub_ieee1275_cell_t size
;
517 INIT_IEEE1275_COMMON (&args
.common
, "release", 2, 0);
521 if (IEEE1275_CALL_ENTRY_FN (&args
) == -1)
527 grub_ieee1275_set_property (grub_ieee1275_phandle_t phandle
,
528 const char *propname
, void *buf
,
529 grub_size_t size
, grub_ssize_t
*actual
)
531 struct set_property_args
533 struct grub_ieee1275_common_hdr common
;
534 grub_ieee1275_phandle_t phandle
;
535 grub_ieee1275_cell_t propname
;
536 grub_ieee1275_cell_t buf
;
537 grub_ieee1275_cell_t size
;
538 grub_ieee1275_cell_t actual
;
542 INIT_IEEE1275_COMMON (&args
.common
, "setprop", 4, 1);
543 args
.size
= (grub_ieee1275_cell_t
) size
;
544 args
.buf
= (grub_ieee1275_cell_t
) buf
;
545 args
.propname
= (grub_ieee1275_cell_t
) propname
;
546 args
.phandle
= (grub_ieee1275_cell_t
) phandle
;
548 if (IEEE1275_CALL_ENTRY_FN (&args
) == -1)
550 *actual
= args
.actual
;
551 if ((args
.actual
== IEEE1275_CELL_INVALID
) || (args
.actual
!= args
.size
))
557 grub_ieee1275_set_color (grub_ieee1275_ihandle_t ihandle
,
558 int index
, int r
, int g
, int b
)
560 struct set_color_args
562 struct grub_ieee1275_common_hdr common
;
564 grub_ieee1275_ihandle_t ihandle
;
565 grub_ieee1275_cell_t index
;
566 grub_ieee1275_cell_t b
;
567 grub_ieee1275_cell_t g
;
568 grub_ieee1275_cell_t r
;
569 grub_ieee1275_cell_t catch_result
;
573 INIT_IEEE1275_COMMON (&args
.common
, "call-method", 6, 1);
574 args
.method
= "color!";
575 args
.ihandle
= ihandle
;
581 if (IEEE1275_CALL_ENTRY_FN (&args
) == -1)
583 return args
.catch_result
;
587 grub_ieee1275_milliseconds (grub_uint32_t
*msecs
)
589 struct milliseconds_args
591 struct grub_ieee1275_common_hdr common
;
592 grub_ieee1275_cell_t msecs
;
596 INIT_IEEE1275_COMMON (&args
.common
, "milliseconds", 0, 1);
598 if (IEEE1275_CALL_ENTRY_FN (&args
) == -1)