1 /* $NetBSD: promlib.h,v 1.22 2007/03/04 06:00:45 christos Exp $ */
4 * Copyright (c) 1999 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 #ifndef _SPARC_PROMLIB_H_
38 #define _SPARC_PROMLIB_H_
41 #include "opt_multiprocessor.h"
44 #include <machine/idprom.h>
45 #include <machine/bsd_openprom.h>
46 #include <machine/openfirm.h>
49 * A set of methods to access the firmware.
50 * We use this to support various versions of Open Boot Prom
51 * or Open Firmware implementations.
54 int po_version
; /* PROM version number */
59 #define PROM_OPENFIRM 4
60 int po_revision
; /* revision level */
61 int po_stdin
; /* stdio handles */
65 /* Access to boot arguments */
66 const char *(*po_bootpath
)(void);
67 const char *(*po_bootfile
)(void);
68 const char *(*po_bootargs
)(void);
71 int (*po_getchar
)(void);
72 int (*po_peekchar
)(void);
73 void (*po_putchar
)(int);
74 void (*po_putstr
)(const char *, int);
75 int (*po_open
)(const char *);
76 void (*po_close
)(int);
77 int (*po_read
)(int, void *, int);
78 int (*po_write
)(int, const void *, int);
79 int (*po_seek
)(int, u_quad_t
);
81 int (*po_instance_to_package
)(int);
83 /* Misc functions (common in OBP 0,2,3) */
84 void (*po_halt
)(void) __attribute__((__noreturn__
));
85 void (*po_reboot
)(const char *) __attribute__((__noreturn__
));
86 void (*po_abort
)(void);
87 void (*po_interpret
)(const char *);
88 void (*po_setcallback
)(void (*)(void));
89 int (*po_ticks
)(void);
93 void (*po_setcontext
)(int ctxt
, void *va
, int pmeg
);
95 /* MP functions (OBP v3 only) */
96 int (*po_cpustart
)(int, struct openprom_addr
*, int, void *);
97 int (*po_cpustop
)(int);
98 int (*po_cpuidle
)(int);
99 int (*po_cpuresume
)(int);
101 /* Device node traversal (OBP v0, v2, v3; but not sun4) */
102 int (*po_firstchild
)(int);
103 int (*po_nextsibling
)(int);
105 /* Device node properties */
106 int (*po_getproplen
)(int, const char *);
107 int (*po_getprop
)(int, const char *, void *, int);
108 int (*po_setprop
)(int, const char *, const void *, int);
109 char *(*po_nextprop
)(int, const char *);
111 int (*po_finddevice
)(const char *);
115 extern struct promops promops
;
118 * Memory description array.
119 * Same as version 2 rom meminfo property.
126 int prom_makememarr(struct memarr
*, int, int);
127 #define MEMARR_AVAILPHYS 0
128 #define MEMARR_TOTALPHYS 1
130 struct idprom
*prom_getidprom(void);
131 void prom_getether(int, u_char
*);
132 const char *prom_pa_location(u_int
, u_int
);
134 void prom_init(void); /* To setup promops */
136 /* Utility routines */
137 int prom_getprop(int, const char *, size_t, int *, void *);
138 int prom_getpropint(int, const char *, int);
139 char *prom_getpropstring(int, const char *);
140 char *prom_getpropstringA(int, const char *, char *, size_t);
141 void prom_printf(const char *, ...);
143 int prom_findroot(void);
144 int prom_findnode(int, const char *);
145 int prom_search(int, const char *);
146 int prom_opennode(const char *);
147 int prom_node_has_property(int, const char *);
148 int prom_getoptionsnode(void);
149 int prom_getoption(const char *, char *, int);
151 #define findroot() prom_findroot()
152 #define findnode(node,name) prom_findnode(node,name)
153 #define opennode(name) prom_opennode(name)
154 #define node_has_property(node,prop) prom_node_has_property(node,prop)
156 void prom_halt(void) __attribute__((__noreturn__
));
157 void prom_boot(char *) __attribute__((__noreturn__
));
159 #if defined(MULTIPROCESSOR)
160 #define callrom() do { \
166 #define callrom() prom_abort()
169 #define prom_version() (promops.po_version)
170 #define prom_revision() (promops.po_revision)
171 #define prom_stdin() (promops.po_stdin)
172 #define prom_stdout() (promops.po_stdout)
173 #define _prom_halt() ((*promops.po_halt)(/*void*/))
174 #define _prom_boot(a) ((*promops.po_reboot)(a))
175 #define prom_abort() ((*promops.po_abort)(/*void*/))
176 #define prom_interpret(a) ((*promops.po_interpret)(a))
177 #define prom_setcallback(f) ((*promops.po_setcallback)(f))
178 #define prom_setcontext(c,a,p) ((*promops.po_setcontext)(c,a,p))
179 #define prom_getbootpath() ((*promops.po_bootpath)(/*void*/))
180 #define prom_getbootfile() ((*promops.po_bootfile)(/*void*/))
181 #define prom_getbootargs() ((*promops.po_bootargs)(/*void*/))
182 #define prom_ticks() ((*promops.po_ticks)(/*void*/))
185 #define prom_open(name) ((*promops.po_open)(name))
186 #define prom_close(fd) ((*promops.po_close)(fd))
187 #define prom_instance_to_package(fd) \
188 ((*promops.po_instance_to_package)(fd))
189 #define prom_read(fd,b,n) ((*promops.po_read)(fd,b,n))
190 #define prom_write(fd,b,n) ((*promops.po_write)(fd,b,n))
191 #define prom_seek(fd,o) ((*promops.po_seek)(fd,o))
192 #define prom_getchar() ((*promops.po_getchar)(/*void*/))
193 #define prom_peekchar() ((*promops.po_peekchar)(/*void*/))
194 #define prom_putchar(c) ((*promops.po_putchar)(c))
195 #define prom_putstr(b,n) ((*promops.po_putstr)(b,n))
198 #define prom_firstchild(node) ((*promops.po_firstchild)(node))
199 #define prom_nextsibling(node) ((*promops.po_nextsibling)(node))
200 #define prom_proplen(node,name) ((*promops.po_getproplen)(node, name))
201 #define _prom_getprop(node, name, buf, len) \
202 ((*promops.po_getprop)(node, name, buf, len))
203 #define prom_setprop(node, name, value, len) \
204 ((*promops.po_setprop)(node, name, value, len))
205 #define prom_nextprop(node,name) ((*promops.po_nextprop)(node, name))
206 #define prom_finddevice(name) ((*promops.po_finddevice)(name))
208 #define firstchild(node) prom_firstchild(node)
209 #define nextsibling(node) prom_nextsibling(node)
210 #define prom_getproplen(node,name) prom_proplen(node, name)
213 /* MP stuff - not currently used */
214 #define prom_cpustart(m,a,c,pc) ((*promops.po_cpustart)(m,a,c,pc))
215 #define prom_cpustop(m) ((*promops.po_cpustop)(m))
216 #define prom_cpuidle(m) ((*promops.po_cpuidle)(m))
217 #define prom_cpuresume(m) ((*promops.po_cpuresume)(m))
219 extern void *romp
; /* PROM-supplied argument (see locore) */
221 #endif /* _SPARC_PROMLIB_H_ */