Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / sparc / stand / ofwboot / promlib.c
bloba378a5d2ed8ddf0c57b4849e3ff460ac5b0338e5
1 /* $NetBSD: promlib.c,v 1.1 2006/01/27 18:31:12 cdi Exp $ */
3 /*-
4 * Copyright (c) 2005 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Paul Kranenburg.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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>
40 #include "openfirm.h"
43 void *romp;
44 struct promops promops;
47 static void
48 openfirmware_fatal(void)
50 printf("Invalid Openfirmware environment\n");
51 exit(0);
54 static int
55 openfirmware_chosen(void)
57 static int phandle = -1;
59 if (phandle == -1) {
60 if ( (phandle = OF_finddevice("/chosen")) == -1) {
61 exit(0);
65 return (phandle);
68 static const char*
69 openfirmware_bootpath(void)
71 static char bootpath[PROM_MAX_PATH];
73 if (_prom_getprop(openfirmware_chosen(), "bootpath", bootpath,
74 sizeof(bootpath)) < 0) {
75 openfirmware_fatal();
78 return bootpath;
81 static const char*
82 openfirmware_bootfile(void)
84 /* Default image name */
85 return "netbsd";
88 static const char*
89 openfirmware_bootargs(void)
91 static char bootargs[PROM_MAX_PATH * 2];
93 if (_prom_getprop(openfirmware_chosen(), "bootargs", bootargs,
94 sizeof(bootargs)) < 0) {
95 openfirmware_fatal();
98 return bootargs;
101 static int
102 openfirmware_getchar(void)
104 unsigned char ch = '\0';
105 int l;
107 while ((l = OF_read(prom_stdin(), &ch, 1)) != 1)
108 if (l != -2 && l != 0)
109 return -1;
110 return ch;
113 static void
114 openfirmware_putchar(int c)
116 char ch = c;
118 if (c == '\n')
119 putchar('\r');
120 OF_write(prom_stdout(), &ch, 1);
123 void
124 prom_halt(void)
126 _prom_halt();
130 prom_findroot(void)
132 return OF_peer(0);
135 void
136 prom_init(void)
138 int phandle, size;
140 OF_initialize();
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;
149 /* I/O functions */
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;
175 /* Console I/O */
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))) {
182 prom_halt();