1 /* $NetBSD: promlib.c,v 1.1 2006/01/27 18:31:12 cdi Exp $ */
4 * Copyright (c) 2005 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * OPENPROM functions. These are here mainly to hide the OPENPROM interface
34 * from the rest of the kernel.
37 #include <sys/types.h>
38 #include <machine/promlib.h>
44 struct promops promops
;
48 openfirmware_fatal(void)
50 printf("Invalid Openfirmware environment\n");
55 openfirmware_chosen(void)
57 static int phandle
= -1;
60 if ( (phandle
= OF_finddevice("/chosen")) == -1) {
69 openfirmware_bootpath(void)
71 static char bootpath
[PROM_MAX_PATH
];
73 if (_prom_getprop(openfirmware_chosen(), "bootpath", bootpath
,
74 sizeof(bootpath
)) < 0) {
82 openfirmware_bootfile(void)
84 /* Default image name */
89 openfirmware_bootargs(void)
91 static char bootargs
[PROM_MAX_PATH
* 2];
93 if (_prom_getprop(openfirmware_chosen(), "bootargs", bootargs
,
94 sizeof(bootargs
)) < 0) {
102 openfirmware_getchar(void)
104 unsigned char ch
= '\0';
107 while ((l
= OF_read(prom_stdin(), &ch
, 1)) != 1)
108 if (l
!= -2 && l
!= 0)
114 openfirmware_putchar(int c
)
120 OF_write(prom_stdout(), &ch
, 1);
142 memset(promops
, 0, sizeof(promops
));
144 /* Access to boot arguments */
145 promops
.po_bootpath
= openfirmware_bootpath
;
146 promops
.po_bootfile
= openfirmware_bootfile
;
147 promops
.po_bootargs
= openfirmware_bootargs
;
150 promops
.po_getchar
= openfirmware_getchar
;
151 promops
.po_putchar
= openfirmware_putchar
;
152 promops
.po_open
= OF_open
;
153 promops
.po_close
= OF_close
;
154 promops
.po_read
= OF_read
;
155 promops
.po_write
= OF_write
;
156 promops
.po_seek
= OF_seek
;
158 promops
.po_instance_to_package
= OF_instance_to_package
;
160 /* Program termination control */
161 promops
.po_halt
= OF_exit
;
162 promops
.po_abort
= OF_enter
;
163 promops
.po_ticks
= OF_milliseconds
;
165 /* Device node traversal */
166 promops
.po_firstchild
= OF_child
;
167 promops
.po_nextsibling
= OF_peer
;
169 /* Device node properties */
170 promops
.po_getprop
= OF_getprop
;
172 /* Device discovery */
173 promops
.po_finddevice
= OF_finddevice
;
176 phandle
= openfirmware_chosen();
177 size
= _prom_getprop(phandle
, "stdin", &promops
.po_stdin
,
178 sizeof(promops
.po_stdin
));
179 size
+= _prom_getprop(phandle
, "stdout", &promops
.po_stdout
,
180 sizeof(promops
.po_stdout
));
181 if (size
!= (sizeof(promops
.po_stdin
) + sizeof(promops
.po_stdout
))) {