xref: /titanic_41/usr/src/uts/sun/sys/promif.h (revision c2580b931007758eab8cb5ae8726ebe1588e259b)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_PROMIF_H
28 #define	_SYS_PROMIF_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <sys/obpdefs.h>
34 
35 #if defined(_KERNEL) || defined(_KMDB)
36 #include <sys/va_list.h>
37 #endif
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 /*
44  *  These are for V0 ops only.  We sometimes have to specify
45  *  to promif which type of operation we need to perform
46  *  and since we can't get such a property from a V0 prom, we
47  *  sometimes just assume it.  V2 and later proms do the right thing.
48  */
49 #define	BLOCK	0
50 #define	NETWORK	1
51 #define	BYTE	2
52 
53 
54 #if defined(_KERNEL) || defined(_KMDB)
55 
56 #if !defined(_BOOT)
57 /*
58  * Due to FCode on sun4u machines running in a pseudo-32-bit environment
59  * we need to enable code in several of the promif routines to ensure
60  * that 64-bit pointers from the kernel are not passed through the CIF
61  * to OpenBoot.
62  *
63  * Client programs defining this token need to provide two callbacks to
64  * allow the promif routines to allocate and free memory allocated from
65  * the bottom 32-bits of the 64-bit address space:
66  *
67  * 	void *promplat_alloc(size_t);
68  * 	void promplat_free(void *, size_t);
69  *
70  * The alloc function should guarantee that it will never return an
71  * invalid pointer.
72  */
73 #define	PROM_32BIT_ADDRS
74 #endif /* _BOOT */
75 
76 typedef void promif_preprom_f(void);
77 typedef void promif_postprom_f(void);
78 
79 /*
80  * resource allocation group: OBP and IEEE 1275-1994.
81  * prom_alloc is platform dependent on SPARC.
82  */
83 extern	caddr_t		prom_alloc(caddr_t virthint, size_t size, uint_t align);
84 extern	void		prom_free(caddr_t virt, size_t size);
85 
86 /*
87  * Device tree and property group: OBP and IEEE 1275-1994.
88  */
89 extern	pnode_t		prom_childnode(pnode_t nodeid);
90 extern	pnode_t		prom_nextnode(pnode_t nodeid);
91 extern	pnode_t		prom_parentnode(pnode_t nodeid);
92 extern	pnode_t		prom_rootnode(void);
93 extern	pnode_t		prom_chosennode(void);
94 extern	pnode_t		prom_alias_node(void);
95 extern	pnode_t		prom_optionsnode(void);
96 
97 extern	int		prom_asr_list_keys_len();
98 extern	int		prom_asr_list_keys(caddr_t value);
99 extern	int		prom_asr_export_len();
100 extern	int		prom_asr_export(caddr_t value);
101 extern	int		prom_asr_disable(char *keystr, int keystr_len,
102 			    char *reason, int reason_len);
103 extern	int		prom_asr_enable(char *keystr, int keystr_len);
104 
105 extern	int		prom_getproplen(pnode_t nodeid, caddr_t name);
106 extern	int		prom_getprop(pnode_t nodeid, caddr_t name,
107 			    caddr_t value);
108 extern	caddr_t		prom_nextprop(pnode_t nodeid, caddr_t previous,
109 			    caddr_t next);
110 extern	int		prom_setprop(pnode_t nodeid, caddr_t name,
111 			    caddr_t value, int len);
112 
113 extern	int		prom_getnode_byname(pnode_t id, char *name);
114 extern	int		prom_devicetype(pnode_t id, char *type);
115 
116 extern	char		*prom_decode_composite_string(void *buf,
117 			    size_t buflen, char *prev);
118 
119 /*
120  * Device tree and property group: IEEE 1275-1994 Only.
121  */
122 extern	pnode_t		prom_finddevice(char *path);	/* Also on obp2.x */
123 
124 extern	int		prom_bounded_getprop(pnode_t nodeid,
125 			    caddr_t name, caddr_t buffer, int buflen);
126 
127 extern	phandle_t	prom_getphandle(ihandle_t i);
128 
129 /*
130  * Device pathnames and pathname conversion: OBP and IEEE 1275-1994.
131  */
132 extern	int		prom_devname_from_pathname(char *path, char *buffer);
133 extern	char		*prom_path_options(char *pathname);
134 extern	char		*prom_path_gettoken(char *from, char *to);
135 extern	void		prom_pathname(char *pathname);
136 extern	void		prom_strip_options(char *from, char *to);
137 
138 /*
139  * Device pathnames and pathname conversion: IEEE 1275-1994 only.
140  */
141 extern	int		prom_ihandle_to_path(ihandle_t, char *buf,
142 			    uint_t buflen);
143 extern	int		prom_phandle_to_path(phandle_t, char *buf,
144 			    uint_t buflen);
145 
146 /*
147  * Special device nodes: OBP and IEEE 1275-1994.
148  */
149 extern	ihandle_t	prom_stdin_ihandle(void);
150 extern	ihandle_t	prom_stdout_ihandle(void);
151 extern	pnode_t		prom_stdin_node(void);
152 extern	pnode_t		prom_stdout_node(void);
153 extern	char		*prom_stdinpath(void);
154 extern	char		*prom_stdoutpath(void);
155 extern	int		prom_stdin_devname(char *buffer);
156 extern	int		prom_stdout_devname(char *buffer);
157 extern	int		prom_stdin_is_keyboard(void);
158 extern	int		prom_stdout_is_framebuffer(void);
159 extern	int		prom_stdin_stdout_equivalence(void);
160 
161 extern void		prom_get_tem_size(size_t *, size_t *);
162 extern void		prom_get_tem_pos(uint32_t *, uint32_t *);
163 extern void		prom_get_term_font_size(int *, int *);
164 extern void		prom_hide_cursor(void);
165 
166 /*
167  * Special device nodes: IEEE 1275-1994 only.
168  */
169 extern	ihandle_t	prom_memory_ihandle(void);
170 extern	ihandle_t	prom_mmu_ihandle(void);
171 
172 /*
173  * Administrative group: OBP and IEEE 1275-1994.
174  */
175 extern	void		prom_enter_mon(void);
176 extern	void		prom_exit_to_mon(void)
177 	__NORETURN;
178 extern	void		prom_reboot(char *bootstr);
179 
180 extern	void		prom_panic(char *string)
181 	__NORETURN;
182 
183 extern	int		prom_getversion(void);
184 extern	int		prom_is_openprom(void);
185 extern	int		prom_is_p1275(void);
186 extern	int		prom_version_name(char *buf, int buflen);
187 extern	int		prom_version_check(char *buf, size_t len, pnode_t *n);
188 
189 extern	void		*prom_mon_id(void);	/* SMCC/OBP platform centric */
190 
191 extern	uint_t		prom_gettime(void);
192 
193 extern	char		*prom_bootpath(void);
194 extern	char		*prom_bootargs(void);
195 
196 extern	void		prom_interpret(char *str, uintptr_t arg1,
197 			    uintptr_t arg2, uintptr_t arg3, uintptr_t arg4,
198 			    uintptr_t arg5);
199 
200 /*
201  * Return code values from prom_version_check:
202  *
203  * This routine uses past-prediction mode to determine if the firmware
204  * on the current system is 64-bit ready.
205  *
206  * return code 2 could happen on a board-based server with a slave CPU board
207  * running down-rev firmware and the current master running adequate fw.
208  */
209 #define	PROM_VER64_OK		0	/* Prom is 64-bit ready (or n/a) */
210 #define	PROM_VER64_UPGRADE	1	/* Down-rev firmware is running */
211 #define	PROM_VER64_SUGGEST	2	/* Down-rev firmware detected .. */
212 					/* .. but not currently active */
213 
214 /*
215  * Administrative group: OBP only.
216  */
217 extern	int		prom_sethandler(void (*v0_func)(), void (*v2_func)());
218 
219 extern	struct bootparam *prom_bootparam(void);
220 
221 /*
222  * Administrative group: IEEE 1275-1994 only.
223  */
224 extern void		*prom_set_callback(void *handler);
225 extern void		prom_set_symbol_lookup(void *sym2val, void *val2sym);
226 
227 /*
228  * Administrative group: IEEE 1275 only.
229  */
230 extern	int		prom_test(char *service);
231 extern	int		prom_test_method(char *method, pnode_t node);
232 
233 /*
234  * Promif support group: Generic.
235  */
236 extern	void		prom_init(char *progname, void *prom_cookie);
237 
238 extern	void		prom_set_preprom(promif_preprom_f *);
239 extern	void		prom_set_postprom(promif_postprom_f *);
240 
241 extern  void		prom_get_tem_pos(uint32_t *, uint32_t *);
242 extern	void		prom_get_tem_size(size_t *, size_t *);
243 
244 typedef struct		__promif_redir_arg *promif_redir_arg_t;
245 typedef ssize_t		(*promif_redir_t)(promif_redir_arg_t,
246 				uchar_t *, size_t);
247 extern  void		prom_set_stdout_redirect(promif_redir_t,
248 				promif_redir_arg_t);
249 
250 extern	void		prom_suspend_prepost(void);
251 extern	void		prom_resume_prepost(void);
252 
253 extern	void		(*prom_set_nextprop_preprom(void (*)(void)))(void);
254 extern	void		(*prom_set_nextprop_postprom(void (*)(void)))(void);
255 
256 extern	void		prom_montrap(void (*funcptr)());
257 
258 typedef uint_t		prom_generation_cookie_t;
259 
260 extern	int		prom_tree_access(int (*callback)(void *arg,
261 				int has_changed), void *arg,
262 				prom_generation_cookie_t *);
263 extern	int		prom_tree_update(int (*callback)(void *arg), void *arg);
264 
265 /*
266  * I/O Group: OBP and IEEE 1275.
267  */
268 extern	uchar_t		prom_getchar(void);
269 extern	void		prom_putchar(char c);
270 extern	int		prom_mayget(void);
271 extern	int		prom_mayput(char c);
272 
273 extern  int		prom_open(char *name);
274 extern  int		prom_close(int fd);
275 extern  ssize_t		prom_read(ihandle_t fd, caddr_t buf, size_t len,
276 			    uint_t startblk, char type);
277 extern  ssize_t		prom_write(ihandle_t fd, caddr_t buf, size_t len,
278 			    uint_t startblk, char type);
279 extern	int		prom_seek(int fd, u_longlong_t offset);
280 
281 extern	void		prom_writestr(const char *buf, size_t bufsize);
282 extern	void		prom_pnode_to_pathname(pnode_t, char *);
283 
284 /*PRINTFLIKE1*/
285 extern	void		prom_printf(const char *fmt, ...)
286 	__PRINTFLIKE(1);
287 #pragma rarely_called(prom_printf)
288 
289 extern	void		prom_vprintf(const char *fmt, __va_list adx)
290 	__VPRINTFLIKE(1);
291 #pragma rarely_called(prom_vprintf)
292 
293 /*PRINTFLIKE2*/
294 extern	char		*prom_sprintf(char *s, const char *fmt, ...)
295 	__PRINTFLIKE(2);
296 extern	char		*prom_vsprintf(char *s, const char *fmt, __va_list adx)
297 	__VPRINTFLIKE(2);
298 
299 #define	PROM_WALK_CONTINUE	0	/* keep walking to next node */
300 #define	PROM_WALK_TERMINATE	1	/* abort walk now */
301 
302 extern	void		prom_walk_devs(pnode_t node,
303 			    int (*f)(pnode_t, void *, void *),
304 			    void *arg, void *result);
305 
306 extern	pnode_t		prom_findnode_byname(pnode_t id, char *name);
307 extern	pnode_t		prom_findnode_bydevtype(pnode_t id, char *devtype);
308 
309 #define	PROM_STOP	{	\
310 	prom_printf("File %s line %d\n", __FILE__, __LINE__); \
311 	prom_enter_mon();	\
312 }
313 
314 #endif	/* _KERNEL || _KMDB */
315 
316 #ifdef _KERNEL
317 
318 /*
319  * Used by wrappers which bring up console frame buffer before prom_printf()
320  * and other prom calls that may output to the console.  Struct is filled in
321  * in prom_env.c and in sunpm.c
322  */
323 
324 typedef struct promif_owrap {
325 	void (*preout)(void);
326 	void (*postout)(void);
327 } promif_owrap_t;
328 
329 /*
330  * WAN boot key storage interface
331  */
332 int prom_set_security_key(char *keyname, caddr_t buf, int buflen, int *reslen,
333     int *status);
334 int prom_get_security_key(char *keyname, caddr_t buf, int buflen, int *keylen,
335     int *status);
336 #endif	/* _KERNEL */
337 
338 #ifdef	__cplusplus
339 }
340 #endif
341 
342 #endif /* _SYS_PROMIF_H */
343