Updated PCI IDs to latest snapshot.
[tangerine.git] / arch / common / boot / grub2 / kern / ieee1275 / ieee1275.c
blobaa48e20c4e35fd4a16030f29b133d948f97b7b3d
1 /* of.c - Access the Open Firmware client interface. */
2 /*
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)
29 int
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;
38 args;
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)
44 return -1;
45 *phandlep = args.phandle;
46 if (args.phandle == IEEE1275_PHANDLE_INVALID)
47 return -1;
48 return 0;
51 int
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;
65 args;
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)
74 return -1;
75 if (actual)
76 *actual = (grub_ssize_t) args.size;
77 if (args.size == IEEE1275_CELL_INVALID)
78 return -1;
79 return 0;
82 int
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)
87 int ret;
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. */
91 if (ret == 0)
93 unsigned int i;
94 size /= sizeof (grub_uint32_t);
95 for (i = 0; i < size; i++)
96 buf[i] = grub_be_to_cpu32 (buf[i]);
98 #endif
99 return ret;
103 grub_ieee1275_next_property (grub_ieee1275_phandle_t phandle, char *prev_prop,
104 char *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;
114 args;
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)
123 return -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;
138 args;
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)
146 return -1;
147 *length = args.length;
148 if (args.length == IEEE1275_CELL_INVALID)
149 return -1;
150 return 0;
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;
163 args;
165 INIT_IEEE1275_COMMON (&args.common, "instance-to-package", 1, 1);
166 args.ihandle = ihandle;
168 if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
169 return -1;
170 *phandlep = args.phandle;
171 if (args.phandle == IEEE1275_PHANDLE_INVALID)
172 return -1;
173 return 0;
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;
189 args;
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)
197 return -1;
198 if (actual)
199 *actual = args.actual;
200 if (args.actual == IEEE1275_CELL_INVALID)
201 return -1;
202 return 0;
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;
218 args;
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)
226 return -1;
227 if (actual)
228 *actual = args.actual;
229 if (args.actual == IEEE1275_CELL_INVALID)
230 return -1;
231 return 0;
235 grub_ieee1275_write (grub_ieee1275_ihandle_t ihandle, void *buffer,
236 grub_size_t len, grub_ssize_t *actualp)
238 struct write_args
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;
246 args;
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)
254 return -1;
255 if (actualp)
256 *actualp = args.actual;
257 return 0;
261 grub_ieee1275_read (grub_ieee1275_ihandle_t ihandle, void *buffer,
262 grub_size_t len, grub_ssize_t *actualp)
264 struct write_args
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;
272 args;
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)
280 return -1;
281 if (actualp)
282 *actualp = args.actual;
283 return 0;
287 grub_ieee1275_seek (grub_ieee1275_ihandle_t ihandle, int pos_hi,
288 int pos_lo, grub_ssize_t *result)
290 struct write_args
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;
298 args;
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)
306 return -1;
308 if (result)
309 *result = args.result;
310 return 0;
314 grub_ieee1275_peer (grub_ieee1275_phandle_t node,
315 grub_ieee1275_phandle_t *result)
317 struct peer_args
319 struct grub_ieee1275_common_hdr common;
320 grub_ieee1275_phandle_t node;
321 grub_ieee1275_phandle_t result;
323 args;
325 INIT_IEEE1275_COMMON (&args.common, "peer", 1, 1);
326 args.node = node;
328 if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
329 return -1;
330 *result = args.result;
331 if (args.result == 0)
332 return -1;
333 return 0;
337 grub_ieee1275_child (grub_ieee1275_phandle_t node,
338 grub_ieee1275_phandle_t *result)
340 struct child_args
342 struct grub_ieee1275_common_hdr common;
343 grub_ieee1275_phandle_t node;
344 grub_ieee1275_phandle_t result;
346 args;
348 INIT_IEEE1275_COMMON (&args.common, "child", 1, 1);
349 args.node = node;
350 args.result = IEEE1275_PHANDLE_INVALID;
352 if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
353 return -1;
354 *result = args.result;
355 if (args.result == 0)
356 return -1;
357 return 0;
361 grub_ieee1275_parent (grub_ieee1275_phandle_t node,
362 grub_ieee1275_phandle_t *result)
364 struct parent_args
366 struct grub_ieee1275_common_hdr common;
367 grub_ieee1275_phandle_t node;
368 grub_ieee1275_phandle_t result;
370 args;
372 INIT_IEEE1275_COMMON (&args.common, "parent", 1, 1);
373 args.node = node;
374 args.result = IEEE1275_PHANDLE_INVALID;
376 if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
377 return -1;
378 *result = args.result;
379 return 0;
383 grub_ieee1275_interpret (const char *command, grub_ieee1275_cell_t *catch)
385 struct enter_args
387 struct grub_ieee1275_common_hdr common;
388 grub_ieee1275_cell_t command;
389 grub_ieee1275_cell_t catch;
391 args;
393 if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_CANNOT_INTERPRET))
394 return -1;
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)
400 return -1;
401 if (catch)
402 *catch = args.catch;
403 return 0;
407 grub_ieee1275_enter (void)
409 struct enter_args
411 struct grub_ieee1275_common_hdr common;
413 args;
415 INIT_IEEE1275_COMMON (&args.common, "enter", 0, 0);
417 if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
418 return -1;
419 return 0;
422 void
423 grub_ieee1275_exit (void)
425 struct exit_args
427 struct grub_ieee1275_common_hdr common;
429 args;
431 INIT_IEEE1275_COMMON (&args.common, "exit", 0, 0);
433 IEEE1275_CALL_ENTRY_FN (&args);
434 for (;;) ;
438 grub_ieee1275_open (const char *path, grub_ieee1275_ihandle_t *result)
440 struct open_args
442 struct grub_ieee1275_common_hdr common;
443 grub_ieee1275_cell_t path;
444 grub_ieee1275_ihandle_t result;
446 args;
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)
452 return -1;
453 *result = args.result;
454 if (args.result == IEEE1275_IHANDLE_INVALID)
455 return -1;
456 return 0;
460 grub_ieee1275_close (grub_ieee1275_ihandle_t ihandle)
462 struct close_args
464 struct grub_ieee1275_common_hdr common;
465 grub_ieee1275_ihandle_t ihandle;
467 args;
469 INIT_IEEE1275_COMMON (&args.common, "close", 1, 0);
470 args.ihandle = ihandle;
472 if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
473 return -1;
475 return 0;
479 grub_ieee1275_claim (grub_addr_t addr, grub_size_t size, unsigned int align,
480 grub_addr_t *result)
482 struct claim_args
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;
490 args;
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)
498 return -1;
499 if (result)
500 *result = args.base;
501 if (args.base == IEEE1275_CELL_INVALID)
502 return -1;
503 return 0;
507 grub_ieee1275_release (grub_addr_t addr, grub_size_t size)
509 struct release_args
511 struct grub_ieee1275_common_hdr common;
512 grub_ieee1275_cell_t addr;
513 grub_ieee1275_cell_t size;
515 args;
517 INIT_IEEE1275_COMMON (&args.common, "release", 2, 0);
518 args.addr = addr;
519 args.size = size;
521 if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
522 return -1;
523 return 0;
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;
540 args;
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)
549 return -1;
550 *actual = args.actual;
551 if ((args.actual == IEEE1275_CELL_INVALID) || (args.actual != args.size))
552 return -1;
553 return 0;
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;
563 char *method;
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;
571 args;
573 INIT_IEEE1275_COMMON (&args.common, "call-method", 6, 1);
574 args.method = "color!";
575 args.ihandle = ihandle;
576 args.index = index;
577 args.r = r;
578 args.g = g;
579 args.b = b;
581 if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
582 return -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;
594 args;
596 INIT_IEEE1275_COMMON (&args.common, "milliseconds", 0, 1);
598 if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
599 return -1;
600 *msecs = args.msecs;
601 return 0;