xref: /titanic_41/usr/src/uts/sun/sys/promif.h (revision 70025d765b044c6d8594bb965a2247a61e991a99)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 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 /*
162  * Special device nodes: IEEE 1275-1994 only.
163  */
164 extern	ihandle_t	prom_memory_ihandle(void);
165 extern	ihandle_t	prom_mmu_ihandle(void);
166 
167 /*
168  * Administrative group: OBP and IEEE 1275-1994.
169  */
170 extern	void		prom_enter_mon(void);
171 extern	void		prom_exit_to_mon(void)
172 	__NORETURN;
173 extern	void		prom_reboot(char *bootstr);
174 
175 extern	void		prom_panic(char *string)
176 	__NORETURN;
177 
178 extern	int		prom_getversion(void);
179 extern	int		prom_is_openprom(void);
180 extern	int		prom_is_p1275(void);
181 extern	int		prom_version_name(char *buf, int buflen);
182 extern	int		prom_version_check(char *buf, size_t len, pnode_t *n);
183 
184 extern	void		*prom_mon_id(void);	/* SMCC/OBP platform centric */
185 
186 extern	uint_t		prom_gettime(void);
187 
188 extern	char		*prom_bootpath(void);
189 extern	char		*prom_bootargs(void);
190 
191 extern	void		prom_interpret(char *str, uintptr_t arg1,
192 			    uintptr_t arg2, uintptr_t arg3, uintptr_t arg4,
193 			    uintptr_t arg5);
194 
195 /*
196  * Return code values from prom_version_check:
197  *
198  * This routine uses past-prediction mode to determine if the firmware
199  * on the current system is 64-bit ready.
200  *
201  * return code 2 could happen on a board-based server with a slave CPU board
202  * running down-rev firmware and the current master running adequate fw.
203  */
204 #define	PROM_VER64_OK		0	/* Prom is 64-bit ready (or n/a) */
205 #define	PROM_VER64_UPGRADE	1	/* Down-rev firmware is running */
206 #define	PROM_VER64_SUGGEST	2	/* Down-rev firmware detected .. */
207 					/* .. but not currently active */
208 
209 /*
210  * Administrative group: OBP only.
211  */
212 extern	int		prom_sethandler(void (*v0_func)(), void (*v2_func)());
213 
214 extern	struct bootparam *prom_bootparam(void);
215 
216 /*
217  * Administrative group: IEEE 1275-1994 only.
218  */
219 extern void		*prom_set_callback(void *handler);
220 extern void		prom_set_symbol_lookup(void *sym2val, void *val2sym);
221 
222 /*
223  * Administrative group: IEEE 1275 only.
224  */
225 extern	int		prom_test(char *service);
226 extern	int		prom_test_method(char *method, pnode_t node);
227 
228 /*
229  * Promif support group: Generic.
230  */
231 extern	void		prom_init(char *progname, void *prom_cookie);
232 
233 extern	void		prom_set_preprom(promif_preprom_f *);
234 extern	void		prom_set_postprom(promif_postprom_f *);
235 extern	void		prom_suspend_prepost(void);
236 extern	void		prom_resume_prepost(void);
237 
238 extern	void		(*prom_set_nextprop_preprom(void (*)(void)))(void);
239 extern	void		(*prom_set_nextprop_postprom(void (*)(void)))(void);
240 
241 extern	void		prom_montrap(void (*funcptr)());
242 
243 typedef uint_t		prom_generation_cookie_t;
244 
245 extern	int		prom_tree_access(int (*callback)(void *arg,
246 				int has_changed), void *arg,
247 				prom_generation_cookie_t *);
248 extern	int		prom_tree_update(int (*callback)(void *arg), void *arg);
249 
250 /*
251  * I/O Group: OBP and IEEE 1275.
252  */
253 extern	uchar_t		prom_getchar(void);
254 extern	void		prom_putchar(char c);
255 extern	int		prom_mayget(void);
256 extern	int		prom_mayput(char c);
257 
258 extern  int		prom_open(char *name);
259 extern  int		prom_close(int fd);
260 extern  ssize_t		prom_read(ihandle_t fd, caddr_t buf, size_t len,
261 			    uint_t startblk, char type);
262 extern  ssize_t		prom_write(ihandle_t fd, caddr_t buf, size_t len,
263 			    uint_t startblk, char type);
264 extern	int		prom_seek(int fd, u_longlong_t offset);
265 
266 extern	void		prom_writestr(const char *buf, size_t bufsize);
267 extern	void		prom_pnode_to_pathname(pnode_t, char *);
268 
269 /*PRINTFLIKE1*/
270 extern	void		prom_printf(const char *fmt, ...)
271 	__PRINTFLIKE(1);
272 #pragma rarely_called(prom_printf)
273 
274 extern	void		prom_vprintf(const char *fmt, __va_list adx)
275 	__VPRINTFLIKE(1);
276 #pragma rarely_called(prom_vprintf)
277 
278 /*PRINTFLIKE2*/
279 extern	char		*prom_sprintf(char *s, const char *fmt, ...)
280 	__PRINTFLIKE(2);
281 extern	char		*prom_vsprintf(char *s, const char *fmt, __va_list adx)
282 	__VPRINTFLIKE(2);
283 
284 #define	PROM_WALK_CONTINUE	0	/* keep walking to next node */
285 #define	PROM_WALK_TERMINATE	1	/* abort walk now */
286 
287 extern	void		prom_walk_devs(pnode_t node,
288 			    int (*f)(pnode_t, void *, void *),
289 			    void *arg, void *result);
290 
291 extern	pnode_t		prom_findnode_byname(pnode_t id, char *name);
292 extern	pnode_t		prom_findnode_bydevtype(pnode_t id, char *devtype);
293 
294 #define	PROM_STOP	{	\
295 	prom_printf("File %s line %d\n", __FILE__, __LINE__); \
296 	prom_enter_mon();	\
297 }
298 
299 #endif	/* _KERNEL || _KMDB */
300 
301 #ifdef _KERNEL
302 
303 /*
304  * Used by wrappers which bring up console frame buffer before prom_printf()
305  * and other prom calls that may output to the console.  Struct is filled in
306  * in prom_env.c and in sunpm.c
307  */
308 
309 typedef struct promif_owrap {
310 	void (*preout)(void);
311 	void (*postout)(void);
312 } promif_owrap_t;
313 
314 /*
315  * WAN boot key storage interface
316  */
317 int prom_set_security_key(char *keyname, caddr_t buf, int buflen, int *reslen,
318     int *status);
319 int prom_get_security_key(char *keyname, caddr_t buf, int buflen, int *keylen,
320     int *status);
321 #endif	/* _KERNEL */
322 
323 #ifdef	__cplusplus
324 }
325 #endif
326 
327 #endif /* _SYS_PROMIF_H */
328