xref: /illumos-gate/usr/src/uts/sun/sys/promif.h (revision 915894ef19890baaed00080f85f6b69e225cda98)
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  * Copyright 2019 Peter Tribble.
26  */
27 
28 #ifndef	_SYS_PROMIF_H
29 #define	_SYS_PROMIF_H
30 
31 #include <sys/types.h>
32 #include <sys/obpdefs.h>
33 
34 #if defined(_KERNEL) || defined(_KMDB)
35 #include <sys/va_list.h>
36 #endif
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  *  These are for V0 ops only.  We sometimes have to specify
44  *  to promif which type of operation we need to perform
45  *  and since we can't get such a property from a V0 prom, we
46  *  sometimes just assume it.  V2 and later proms do the right thing.
47  */
48 #define	BLOCK	0
49 #define	NETWORK	1
50 #define	BYTE	2
51 
52 
53 #if defined(_KERNEL) || defined(_KMDB)
54 
55 #if !defined(_BOOT)
56 /*
57  * Due to FCode on sun4u machines running in a pseudo-32-bit environment
58  * we need to enable code in several of the promif routines to ensure
59  * that 64-bit pointers from the kernel are not passed through the CIF
60  * to OpenBoot.
61  *
62  * Client programs defining this token need to provide two callbacks to
63  * allow the promif routines to allocate and free memory allocated from
64  * the bottom 32-bits of the 64-bit address space:
65  *
66  *	void *promplat_alloc(size_t);
67  *	void promplat_free(void *, size_t);
68  *
69  * The alloc function should guarantee that it will never return an
70  * invalid pointer.
71  */
72 #define	PROM_32BIT_ADDRS
73 #endif /* _BOOT */
74 
75 typedef void promif_preprom_f(void);
76 typedef void promif_postprom_f(void);
77 
78 /*
79  * resource allocation group: OBP and IEEE 1275-1994.
80  * prom_alloc is platform dependent on SPARC.
81  */
82 extern	caddr_t		prom_alloc(caddr_t virthint, size_t size, uint_t align);
83 extern	void		prom_free(caddr_t virt, size_t size);
84 
85 /*
86  * Device tree and property group: OBP and IEEE 1275-1994.
87  */
88 extern	pnode_t		prom_childnode(pnode_t nodeid);
89 extern	pnode_t		prom_nextnode(pnode_t nodeid);
90 extern	pnode_t		prom_parentnode(pnode_t nodeid);
91 extern	pnode_t		prom_rootnode(void);
92 extern	pnode_t		prom_chosennode(void);
93 extern	pnode_t		prom_alias_node(void);
94 extern	pnode_t		prom_optionsnode(void);
95 
96 extern	int		prom_asr_list_keys_len();
97 extern	int		prom_asr_list_keys(caddr_t value);
98 extern	int		prom_asr_export_len();
99 extern	int		prom_asr_export(caddr_t value);
100 extern	int		prom_asr_disable(char *keystr, int keystr_len,
101 			    char *reason, int reason_len);
102 extern	int		prom_asr_enable(char *keystr, int keystr_len);
103 
104 extern	int		prom_getproplen(pnode_t nodeid, caddr_t name);
105 extern	int		prom_getprop(pnode_t nodeid, caddr_t name,
106 			    caddr_t value);
107 extern	caddr_t		prom_nextprop(pnode_t nodeid, caddr_t previous,
108 			    caddr_t next);
109 extern	int		prom_setprop(pnode_t nodeid, caddr_t name,
110 			    caddr_t value, int len);
111 
112 extern	int		prom_getnode_byname(pnode_t id, char *name);
113 extern	int		prom_devicetype(pnode_t id, char *type);
114 
115 extern	char		*prom_decode_composite_string(void *buf,
116 			    size_t buflen, char *prev);
117 
118 /*
119  * Device tree and property group: IEEE 1275-1994 Only.
120  */
121 extern	pnode_t		prom_finddevice(char *path);	/* Also on obp2.x */
122 
123 extern	int		prom_bounded_getprop(pnode_t nodeid,
124 			    caddr_t name, caddr_t buffer, int buflen);
125 
126 extern	phandle_t	prom_getphandle(ihandle_t i);
127 
128 /*
129  * Device pathnames and pathname conversion: OBP and IEEE 1275-1994.
130  */
131 extern	int		prom_devname_from_pathname(char *path, char *buffer);
132 extern	char		*prom_path_options(char *pathname);
133 extern	char		*prom_path_gettoken(char *from, char *to);
134 extern	void		prom_pathname(char *pathname);
135 extern	void		prom_strip_options(char *from, char *to);
136 
137 /*
138  * Device pathnames and pathname conversion: IEEE 1275-1994 only.
139  */
140 extern	int		prom_ihandle_to_path(ihandle_t, char *buf,
141 			    uint_t buflen);
142 extern	int		prom_phandle_to_path(phandle_t, char *buf,
143 			    uint_t buflen);
144 
145 /*
146  * Special device nodes: OBP and IEEE 1275-1994.
147  */
148 extern	ihandle_t	prom_stdin_ihandle(void);
149 extern	ihandle_t	prom_stdout_ihandle(void);
150 extern	pnode_t		prom_stdin_node(void);
151 extern	pnode_t		prom_stdout_node(void);
152 extern	char		*prom_stdinpath(void);
153 extern	char		*prom_stdoutpath(void);
154 extern	int		prom_stdin_devname(char *buffer);
155 extern	int		prom_stdout_devname(char *buffer);
156 extern	int		prom_stdin_is_keyboard(void);
157 extern	int		prom_stdout_is_framebuffer(void);
158 extern	int		prom_stdin_stdout_equivalence(void);
159 
160 extern void		prom_get_tem_inverses(int *, int *);
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 
188 extern	void		*prom_mon_id(void);	/* SMCC/OBP platform centric */
189 
190 extern	uint_t		prom_gettime(void);
191 
192 extern	char		*prom_bootpath(void);
193 extern	char		*prom_bootargs(void);
194 
195 extern	void		prom_interpret(char *str, uintptr_t arg1,
196 			    uintptr_t arg2, uintptr_t arg3, uintptr_t arg4,
197 			    uintptr_t arg5);
198 
199 /*
200  * Administrative group: OBP only.
201  */
202 extern	int		prom_sethandler(void (*v0_func)(), void (*v2_func)());
203 
204 extern	struct bootparam *prom_bootparam(void);
205 
206 /*
207  * Administrative group: IEEE 1275-1994 only.
208  */
209 extern void		*prom_set_callback(void *handler);
210 extern void		prom_set_symbol_lookup(void *sym2val, void *val2sym);
211 
212 /*
213  * Administrative group: IEEE 1275 only.
214  */
215 extern	int		prom_test(char *service);
216 extern	int		prom_test_method(char *method, pnode_t node);
217 
218 /*
219  * Promif support group: Generic.
220  */
221 extern	void		prom_init(char *progname, void *prom_cookie);
222 
223 extern	void		prom_set_preprom(promif_preprom_f *);
224 extern	void		prom_set_postprom(promif_postprom_f *);
225 
226 extern  void		prom_get_tem_pos(uint32_t *, uint32_t *);
227 extern	void		prom_get_tem_size(size_t *, size_t *);
228 
229 typedef struct		__promif_redir_arg *promif_redir_arg_t;
230 typedef ssize_t		(*promif_redir_t)(promif_redir_arg_t,
231 				uchar_t *, size_t);
232 extern  void		prom_set_stdout_redirect(promif_redir_t,
233 				promif_redir_arg_t);
234 
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 /*
300  * file IO
301  */
302 extern	int		prom_fopen(ihandle_t, char *);
303 extern	int		prom_volopen(ihandle_t, char *);
304 extern	int		prom_fseek(ihandle_t, int, unsigned long long);
305 extern	int		prom_fread(ihandle_t, int, caddr_t, size_t);
306 extern	int		prom_fsize(ihandle_t, int, size_t *);
307 extern	int		prom_compinfo(ihandle_t, int, int *,
308 			    size_t *, size_t *);
309 extern	void		prom_fclose(ihandle_t, int);
310 
311 
312 #endif	/* _KERNEL || _KMDB */
313 
314 #ifdef _KERNEL
315 
316 /*
317  * Used by wrappers which bring up console frame buffer before prom_printf()
318  * and other prom calls that may output to the console.  Struct is filled in
319  * in prom_env.c and in sunpm.c
320  */
321 
322 typedef struct promif_owrap {
323 	void (*preout)(void);
324 	void (*postout)(void);
325 } promif_owrap_t;
326 
327 /*
328  * WAN boot key storage interface
329  */
330 int prom_set_security_key(char *keyname, caddr_t buf, int buflen, int *reslen,
331     int *status);
332 int prom_get_security_key(char *keyname, caddr_t buf, int buflen, int *keylen,
333     int *status);
334 #endif	/* _KERNEL */
335 
336 #ifdef	__cplusplus
337 }
338 #endif
339 
340 #endif /* _SYS_PROMIF_H */
341