promlib.h revision 1.18 1 /* $NetBSD: promlib.h,v 1.18 2004/03/21 13:52:00 pk Exp $ */
2
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Paul Kranenburg.
9 *
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.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * OPENPROM functions. These are here mainly to hide the OPENPROM interface
41 * from the rest of the kernel.
42 */
43
44 #ifndef _SPARC_PROMLIB_H_
45 #define _SPARC_PROMLIB_H_
46
47 #ifdef _KERNEL_OPT
48 #include "opt_multiprocessor.h"
49 #endif
50
51 #include <machine/idprom.h>
52 #include <machine/bsd_openprom.h>
53 #include <machine/openfirm.h>
54
55 /*
56 * A set of methods to access the firmware.
57 * We use this to support various versions of Open Boot Prom
58 * or Open Firmware implementations.
59 */
60 struct promops {
61 int po_version; /* PROM version number */
62 #define PROM_OLDMON 0
63 #define PROM_OBP_V0 1
64 #define PROM_OBP_V2 2
65 #define PROM_OBP_V3 3
66 #define PROM_OPENFIRM 4
67 int po_revision; /* revision level */
68 int po_stdin; /* stdio handles */
69 int po_stdout; /* */
70 void *po_bootcookie;
71
72 /* Access to boot arguments */
73 char *(*po_bootpath)(void);
74 char *(*po_bootfile)(void);
75 char *(*po_bootargs)(void);
76
77 /* I/O functions */
78 int (*po_getchar)(void);
79 int (*po_peekchar)(void);
80 void (*po_putchar)(int);
81 void (*po_putstr)(char *, int);
82 int (*po_open)(char *);
83 void (*po_close)(int);
84 int (*po_read)(int, void *, int);
85 int (*po_write)(int, void *, int);
86 int (*po_seek)(int, u_quad_t);
87
88 int (*po_instance_to_package)(int);
89
90 /* Misc functions (common in OBP 0,2,3) */
91 void (*po_halt)(void) __attribute__((__noreturn__));
92 void (*po_reboot)(char *) __attribute__((__noreturn__));
93 void (*po_abort)(void);
94 void (*po_interpret)(char *);
95 void (*po_setcallback)(void (*)(void));
96 int (*po_ticks)(void);
97 void *po_tickdata;
98
99 /* sun4/sun4c only */
100 void (*po_setcontext)(int ctxt, caddr_t va, int pmeg);
101
102 /* MP functions (OBP v3 only) */
103 int (*po_cpustart)(int, struct openprom_addr *, int, caddr_t);
104 int (*po_cpustop)(int);
105 int (*po_cpuidle)(int);
106 int (*po_cpuresume)(int);
107
108 /* Device node traversal (OBP v0, v2, v3; but not sun4) */
109 int (*po_firstchild)(int);
110 int (*po_nextsibling)(int);
111
112 /* Device node properties */
113 int (*po_getproplen)(int node, char *name);
114 int (*po_getprop)(int node, char *name, void *, int);
115 int (*po_setprop)(int node, char *name, const void *, int);
116 char *(*po_nextprop)(int node, char *name);
117
118 int (*po_finddevice)(char *name);
119
120 };
121
122 extern struct promops promops;
123
124 /*
125 * Memory description array.
126 * Same as version 2 rom meminfo property.
127 */
128 struct memarr {
129 long zero;
130 u_long addr;
131 u_long len;
132 };
133 int prom_makememarr(struct memarr *, int max, int which);
134 #define MEMARR_AVAILPHYS 0
135 #define MEMARR_TOTALPHYS 1
136
137 struct idprom *prom_getidprom(void);
138 void prom_getether(int, u_char *);
139
140 void prom_init(void); /* To setup promops */
141
142 /* Utility routines */
143 int prom_getprop(int, char *, size_t, int *, void *);
144 int prom_getpropint(int node, char *name, int deflt);
145 char *prom_getpropstring(int node, char *name);
146 char *prom_getpropstringA(int node, char *name, char *, size_t);
147 void prom_printf(const char *, ...);
148
149 int prom_findroot(void);
150 int prom_findnode(int, const char *);
151 int prom_search(int, const char *);
152 int prom_opennode(char *);
153 int prom_node_has_property(int, const char *);
154 int prom_getoptionsnode(void);
155 int prom_getoption(const char *name, char *buf, int buflen);
156
157 #define findroot() prom_findroot()
158 #define findnode(node,name) prom_findnode(node,name)
159 #define opennode(name) prom_opennode(name)
160 #define node_has_property(node,prop) prom_node_has_property(node,prop)
161
162 void prom_halt(void) __attribute__((__noreturn__));
163 void prom_boot(char *) __attribute__((__noreturn__));
164
165 #if defined(MULTIPROCESSOR)
166 #define callrom() do { \
167 mp_pause_cpus(); \
168 prom_abort(); \
169 mp_resume_cpus(); \
170 } while (0)
171 #else
172 #define callrom() prom_abort()
173 #endif
174
175 #define prom_version() (promops.po_version)
176 #define prom_revision() (promops.po_revision)
177 #define prom_stdin() (promops.po_stdin)
178 #define prom_stdout() (promops.po_stdout)
179 #define _prom_halt() ((*promops.po_halt)(/*void*/))
180 #define _prom_boot(a) ((*promops.po_reboot)(a))
181 #define prom_abort() ((*promops.po_abort)(/*void*/))
182 #define prom_interpret(a) ((*promops.po_interpret)(a))
183 #define prom_setcallback(f) ((*promops.po_setcallback)(f))
184 #define prom_setcontext(c,a,p) ((*promops.po_setcontext)(c,a,p))
185 #define prom_getbootpath() ((*promops.po_bootpath)(/*void*/))
186 #define prom_getbootfile() ((*promops.po_bootfile)(/*void*/))
187 #define prom_getbootargs() ((*promops.po_bootargs)(/*void*/))
188 #define prom_ticks() ((*promops.po_ticks)(/*void*/))
189
190
191 #define prom_open(name) ((*promops.po_open)(name))
192 #define prom_close(fd) ((*promops.po_close)(fd))
193 #define prom_instance_to_package(fd) \
194 ((*promops.po_instance_to_package)(fd))
195 #define prom_read(fd,b,n) ((*promops.po_read)(fd,b,n))
196 #define prom_write(fd,b,n) ((*promops.po_write)(fd,b,n))
197 #define prom_seek(fd,o) ((*promops.po_seek)(fd,o))
198 #define prom_getchar() ((*promops.po_getchar)(/*void*/))
199 #define prom_peekchar() ((*promops.po_peekchar)(/*void*/))
200 #define prom_putchar(c) ((*promops.po_putchar)(c))
201 #define prom_putstr(b,n) ((*promops.po_putstr)(b,n))
202
203 /* Node traversal */
204 #define prom_firstchild(node) ((*promops.po_firstchild)(node))
205 #define prom_nextsibling(node) ((*promops.po_nextsibling)(node))
206 #define prom_proplen(node,name) ((*promops.po_getproplen)(node, name))
207 #define _prom_getprop(node, name, buf, len) \
208 ((*promops.po_getprop)(node, name, buf, len))
209 #define prom_setprop(node, name, value, len) \
210 ((*promops.po_setprop)(node, name, value, len))
211 #define prom_nextprop(node,name) ((*promops.po_nextprop)(node, name))
212 #define prom_finddevice(name) ((*promops.po_finddevice)(name))
213
214 #define firstchild(node) prom_firstchild(node)
215 #define nextsibling(node) prom_nextsibling(node)
216 #define prom_getproplen(node,name) prom_proplen(node, name)
217
218
219 /* MP stuff - not currently used */
220 #define prom_cpustart(m,a,c,pc) ((*promops.po_cpustart)(m,a,c,pc))
221 #define prom_cpustop(m) ((*promops.po_cpustop)(m))
222 #define prom_cpuidle(m) ((*promops.po_cpuidle)(m))
223 #define prom_cpuresume(m) ((*promops.po_cpuresume)(m))
224
225 extern void *romp; /* PROM-supplied argument (see locore) */
226
227 #endif /* _SPARC_PROMLIB_H_ */
228