xref: /titanic_51/usr/src/uts/sun/sys/promif.h (revision 45818ee124adeaaf947698996b4f4c722afc6d1f)
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 2008 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_inverses(int *, int *);
162 extern void		prom_get_tem_size(size_t *, size_t *);
163 extern void		prom_get_tem_pos(uint32_t *, uint32_t *);
164 extern void		prom_get_term_font_size(int *, int *);
165 extern void		prom_hide_cursor(void);
166 
167 /*
168  * Special device nodes: IEEE 1275-1994 only.
169  */
170 extern	ihandle_t	prom_memory_ihandle(void);
171 extern	ihandle_t	prom_mmu_ihandle(void);
172 
173 /*
174  * Administrative group: OBP and IEEE 1275-1994.
175  */
176 extern	void		prom_enter_mon(void);
177 extern	void		prom_exit_to_mon(void)
178 	__NORETURN;
179 extern	void		prom_reboot(char *bootstr);
180 
181 extern	void		prom_panic(char *string)
182 	__NORETURN;
183 
184 extern	int		prom_getversion(void);
185 extern	int		prom_is_openprom(void);
186 extern	int		prom_is_p1275(void);
187 extern	int		prom_version_name(char *buf, int buflen);
188 extern	int		prom_version_check(char *buf, size_t len, pnode_t *n);
189 
190 extern	void		*prom_mon_id(void);	/* SMCC/OBP platform centric */
191 
192 extern	uint_t		prom_gettime(void);
193 
194 extern	char		*prom_bootpath(void);
195 extern	char		*prom_bootargs(void);
196 
197 extern	void		prom_interpret(char *str, uintptr_t arg1,
198 			    uintptr_t arg2, uintptr_t arg3, uintptr_t arg4,
199 			    uintptr_t arg5);
200 
201 /*
202  * Return code values from prom_version_check:
203  *
204  * This routine uses past-prediction mode to determine if the firmware
205  * on the current system is 64-bit ready.
206  *
207  * return code 2 could happen on a board-based server with a slave CPU board
208  * running down-rev firmware and the current master running adequate fw.
209  */
210 #define	PROM_VER64_OK		0	/* Prom is 64-bit ready (or n/a) */
211 #define	PROM_VER64_UPGRADE	1	/* Down-rev firmware is running */
212 #define	PROM_VER64_SUGGEST	2	/* Down-rev firmware detected .. */
213 					/* .. but not currently active */
214 
215 /*
216  * Administrative group: OBP only.
217  */
218 extern	int		prom_sethandler(void (*v0_func)(), void (*v2_func)());
219 
220 extern	struct bootparam *prom_bootparam(void);
221 
222 /*
223  * Administrative group: IEEE 1275-1994 only.
224  */
225 extern void		*prom_set_callback(void *handler);
226 extern void		prom_set_symbol_lookup(void *sym2val, void *val2sym);
227 
228 /*
229  * Administrative group: IEEE 1275 only.
230  */
231 extern	int		prom_test(char *service);
232 extern	int		prom_test_method(char *method, pnode_t node);
233 
234 /*
235  * Promif support group: Generic.
236  */
237 extern	void		prom_init(char *progname, void *prom_cookie);
238 
239 extern	void		prom_set_preprom(promif_preprom_f *);
240 extern	void		prom_set_postprom(promif_postprom_f *);
241 
242 extern  void		prom_get_tem_pos(uint32_t *, uint32_t *);
243 extern	void		prom_get_tem_size(size_t *, size_t *);
244 
245 typedef struct		__promif_redir_arg *promif_redir_arg_t;
246 typedef ssize_t		(*promif_redir_t)(promif_redir_arg_t,
247 				uchar_t *, size_t);
248 extern  void		prom_set_stdout_redirect(promif_redir_t,
249 				promif_redir_arg_t);
250 
251 extern	void		prom_suspend_prepost(void);
252 extern	void		prom_resume_prepost(void);
253 
254 extern	void		(*prom_set_nextprop_preprom(void (*)(void)))(void);
255 extern	void		(*prom_set_nextprop_postprom(void (*)(void)))(void);
256 
257 extern	void		prom_montrap(void (*funcptr)());
258 
259 typedef uint_t		prom_generation_cookie_t;
260 
261 extern	int		prom_tree_access(int (*callback)(void *arg,
262 				int has_changed), void *arg,
263 				prom_generation_cookie_t *);
264 extern	int		prom_tree_update(int (*callback)(void *arg), void *arg);
265 
266 /*
267  * I/O Group: OBP and IEEE 1275.
268  */
269 extern	uchar_t		prom_getchar(void);
270 extern	void		prom_putchar(char c);
271 extern	int		prom_mayget(void);
272 extern	int		prom_mayput(char c);
273 
274 extern  int		prom_open(char *name);
275 extern  int		prom_close(int fd);
276 extern  ssize_t		prom_read(ihandle_t fd, caddr_t buf, size_t len,
277 			    uint_t startblk, char type);
278 extern  ssize_t		prom_write(ihandle_t fd, caddr_t buf, size_t len,
279 			    uint_t startblk, char type);
280 extern	int		prom_seek(int fd, u_longlong_t offset);
281 
282 extern	void		prom_writestr(const char *buf, size_t bufsize);
283 extern	void		prom_pnode_to_pathname(pnode_t, char *);
284 
285 /*PRINTFLIKE1*/
286 extern	void		prom_printf(const char *fmt, ...)
287 	__PRINTFLIKE(1);
288 #pragma rarely_called(prom_printf)
289 
290 extern	void		prom_vprintf(const char *fmt, __va_list adx)
291 	__VPRINTFLIKE(1);
292 #pragma rarely_called(prom_vprintf)
293 
294 /*PRINTFLIKE2*/
295 extern	char		*prom_sprintf(char *s, const char *fmt, ...)
296 	__PRINTFLIKE(2);
297 extern	char		*prom_vsprintf(char *s, const char *fmt, __va_list adx)
298 	__VPRINTFLIKE(2);
299 
300 #define	PROM_WALK_CONTINUE	0	/* keep walking to next node */
301 #define	PROM_WALK_TERMINATE	1	/* abort walk now */
302 
303 extern	void		prom_walk_devs(pnode_t node,
304 			    int (*f)(pnode_t, void *, void *),
305 			    void *arg, void *result);
306 
307 extern	pnode_t		prom_findnode_byname(pnode_t id, char *name);
308 extern	pnode_t		prom_findnode_bydevtype(pnode_t id, char *devtype);
309 
310 #define	PROM_STOP	{	\
311 	prom_printf("File %s line %d\n", __FILE__, __LINE__); \
312 	prom_enter_mon();	\
313 }
314 
315 /*
316  * file IO
317  */
318 extern	int		prom_fopen(ihandle_t, char *);
319 extern	int		prom_volopen(ihandle_t, char *);
320 extern	int		prom_fseek(ihandle_t, int, unsigned long long);
321 extern	int		prom_fread(ihandle_t, int, caddr_t, size_t);
322 extern	int		prom_fsize(ihandle_t, int, size_t *);
323 extern	int		prom_compinfo(ihandle_t, int, int *,
324 			    size_t *, size_t *);
325 extern	void		prom_fclose(ihandle_t, int);
326 
327 
328 #endif	/* _KERNEL || _KMDB */
329 
330 #ifdef _KERNEL
331 
332 /*
333  * Used by wrappers which bring up console frame buffer before prom_printf()
334  * and other prom calls that may output to the console.  Struct is filled in
335  * in prom_env.c and in sunpm.c
336  */
337 
338 typedef struct promif_owrap {
339 	void (*preout)(void);
340 	void (*postout)(void);
341 } promif_owrap_t;
342 
343 /*
344  * WAN boot key storage interface
345  */
346 int prom_set_security_key(char *keyname, caddr_t buf, int buflen, int *reslen,
347     int *status);
348 int prom_get_security_key(char *keyname, caddr_t buf, int buflen, int *keylen,
349     int *status);
350 #endif	/* _KERNEL */
351 
352 #ifdef	__cplusplus
353 }
354 #endif
355 
356 #endif /* _SYS_PROMIF_H */
357