promif.h revision 5648:161f8007cab9
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 2007 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
40extern "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
76typedef void promif_preprom_f(void);
77typedef 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 */
83extern	caddr_t		prom_alloc(caddr_t virthint, size_t size, uint_t align);
84extern	void		prom_free(caddr_t virt, size_t size);
85
86/*
87 * Device tree and property group: OBP and IEEE 1275-1994.
88 */
89extern	pnode_t		prom_childnode(pnode_t nodeid);
90extern	pnode_t		prom_nextnode(pnode_t nodeid);
91extern	pnode_t		prom_parentnode(pnode_t nodeid);
92extern	pnode_t		prom_rootnode(void);
93extern	pnode_t		prom_chosennode(void);
94extern	pnode_t		prom_alias_node(void);
95extern	pnode_t		prom_optionsnode(void);
96
97extern	int		prom_asr_list_keys_len();
98extern	int		prom_asr_list_keys(caddr_t value);
99extern	int		prom_asr_export_len();
100extern	int		prom_asr_export(caddr_t value);
101extern	int		prom_asr_disable(char *keystr, int keystr_len,
102			    char *reason, int reason_len);
103extern	int		prom_asr_enable(char *keystr, int keystr_len);
104
105extern	int		prom_getproplen(pnode_t nodeid, caddr_t name);
106extern	int		prom_getprop(pnode_t nodeid, caddr_t name,
107			    caddr_t value);
108extern	caddr_t		prom_nextprop(pnode_t nodeid, caddr_t previous,
109			    caddr_t next);
110extern	int		prom_setprop(pnode_t nodeid, caddr_t name,
111			    caddr_t value, int len);
112
113extern	int		prom_getnode_byname(pnode_t id, char *name);
114extern	int		prom_devicetype(pnode_t id, char *type);
115
116extern	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 */
122extern	pnode_t		prom_finddevice(char *path);	/* Also on obp2.x */
123
124extern	int		prom_bounded_getprop(pnode_t nodeid,
125			    caddr_t name, caddr_t buffer, int buflen);
126
127extern	phandle_t	prom_getphandle(ihandle_t i);
128
129/*
130 * Device pathnames and pathname conversion: OBP and IEEE 1275-1994.
131 */
132extern	int		prom_devname_from_pathname(char *path, char *buffer);
133extern	char		*prom_path_options(char *pathname);
134extern	char		*prom_path_gettoken(char *from, char *to);
135extern	void		prom_pathname(char *pathname);
136extern	void		prom_strip_options(char *from, char *to);
137
138/*
139 * Device pathnames and pathname conversion: IEEE 1275-1994 only.
140 */
141extern	int		prom_ihandle_to_path(ihandle_t, char *buf,
142			    uint_t buflen);
143extern	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 */
149extern	ihandle_t	prom_stdin_ihandle(void);
150extern	ihandle_t	prom_stdout_ihandle(void);
151extern	pnode_t		prom_stdin_node(void);
152extern	pnode_t		prom_stdout_node(void);
153extern	char		*prom_stdinpath(void);
154extern	char		*prom_stdoutpath(void);
155extern	int		prom_stdin_devname(char *buffer);
156extern	int		prom_stdout_devname(char *buffer);
157extern	int		prom_stdin_is_keyboard(void);
158extern	int		prom_stdout_is_framebuffer(void);
159extern	int		prom_stdin_stdout_equivalence(void);
160
161extern void		prom_get_tem_inverses(int *, int *);
162extern void		prom_get_tem_size(size_t *, size_t *);
163extern void		prom_get_tem_pos(uint32_t *, uint32_t *);
164extern void		prom_get_term_font_size(int *, int *);
165extern void		prom_hide_cursor(void);
166
167/*
168 * Special device nodes: IEEE 1275-1994 only.
169 */
170extern	ihandle_t	prom_memory_ihandle(void);
171extern	ihandle_t	prom_mmu_ihandle(void);
172
173/*
174 * Administrative group: OBP and IEEE 1275-1994.
175 */
176extern	void		prom_enter_mon(void);
177extern	void		prom_exit_to_mon(void)
178	__NORETURN;
179extern	void		prom_reboot(char *bootstr);
180
181extern	void		prom_panic(char *string)
182	__NORETURN;
183
184extern	int		prom_getversion(void);
185extern	int		prom_is_openprom(void);
186extern	int		prom_is_p1275(void);
187extern	int		prom_version_name(char *buf, int buflen);
188extern	int		prom_version_check(char *buf, size_t len, pnode_t *n);
189
190extern	void		*prom_mon_id(void);	/* SMCC/OBP platform centric */
191
192extern	uint_t		prom_gettime(void);
193
194extern	char		*prom_bootpath(void);
195extern	char		*prom_bootargs(void);
196
197extern	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 */
218extern	int		prom_sethandler(void (*v0_func)(), void (*v2_func)());
219
220extern	struct bootparam *prom_bootparam(void);
221
222/*
223 * Administrative group: IEEE 1275-1994 only.
224 */
225extern void		*prom_set_callback(void *handler);
226extern void		prom_set_symbol_lookup(void *sym2val, void *val2sym);
227
228/*
229 * Administrative group: IEEE 1275 only.
230 */
231extern	int		prom_test(char *service);
232extern	int		prom_test_method(char *method, pnode_t node);
233
234/*
235 * Promif support group: Generic.
236 */
237extern	void		prom_init(char *progname, void *prom_cookie);
238
239extern	void		prom_set_preprom(promif_preprom_f *);
240extern	void		prom_set_postprom(promif_postprom_f *);
241
242extern  void		prom_get_tem_pos(uint32_t *, uint32_t *);
243extern	void		prom_get_tem_size(size_t *, size_t *);
244
245typedef struct		__promif_redir_arg *promif_redir_arg_t;
246typedef ssize_t		(*promif_redir_t)(promif_redir_arg_t,
247				uchar_t *, size_t);
248extern  void		prom_set_stdout_redirect(promif_redir_t,
249				promif_redir_arg_t);
250
251extern	void		prom_suspend_prepost(void);
252extern	void		prom_resume_prepost(void);
253
254extern	void		(*prom_set_nextprop_preprom(void (*)(void)))(void);
255extern	void		(*prom_set_nextprop_postprom(void (*)(void)))(void);
256
257extern	void		prom_montrap(void (*funcptr)());
258
259typedef uint_t		prom_generation_cookie_t;
260
261extern	int		prom_tree_access(int (*callback)(void *arg,
262				int has_changed), void *arg,
263				prom_generation_cookie_t *);
264extern	int		prom_tree_update(int (*callback)(void *arg), void *arg);
265
266/*
267 * I/O Group: OBP and IEEE 1275.
268 */
269extern	uchar_t		prom_getchar(void);
270extern	void		prom_putchar(char c);
271extern	int		prom_mayget(void);
272extern	int		prom_mayput(char c);
273
274extern  int		prom_open(char *name);
275extern  int		prom_close(int fd);
276extern  ssize_t		prom_read(ihandle_t fd, caddr_t buf, size_t len,
277			    uint_t startblk, char type);
278extern  ssize_t		prom_write(ihandle_t fd, caddr_t buf, size_t len,
279			    uint_t startblk, char type);
280extern	int		prom_seek(int fd, u_longlong_t offset);
281
282extern	void		prom_writestr(const char *buf, size_t bufsize);
283extern	void		prom_pnode_to_pathname(pnode_t, char *);
284
285/*PRINTFLIKE1*/
286extern	void		prom_printf(const char *fmt, ...)
287	__PRINTFLIKE(1);
288#pragma rarely_called(prom_printf)
289
290extern	void		prom_vprintf(const char *fmt, __va_list adx)
291	__VPRINTFLIKE(1);
292#pragma rarely_called(prom_vprintf)
293
294/*PRINTFLIKE2*/
295extern	char		*prom_sprintf(char *s, const char *fmt, ...)
296	__PRINTFLIKE(2);
297extern	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
303extern	void		prom_walk_devs(pnode_t node,
304			    int (*f)(pnode_t, void *, void *),
305			    void *arg, void *result);
306
307extern	pnode_t		prom_findnode_byname(pnode_t id, char *name);
308extern	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 */
318extern	int		prom_fopen(ihandle_t, char *);
319extern	int		prom_fseek(ihandle_t, int, unsigned long long);
320extern	int		prom_fread(ihandle_t, int, caddr_t, size_t);
321extern	int		prom_fsize(ihandle_t, int, size_t *);
322extern	int		prom_compinfo(ihandle_t, int, int *,
323			    size_t *, size_t *);
324extern	void		prom_fclose(ihandle_t, int);
325
326
327#endif	/* _KERNEL || _KMDB */
328
329#ifdef _KERNEL
330
331/*
332 * Used by wrappers which bring up console frame buffer before prom_printf()
333 * and other prom calls that may output to the console.  Struct is filled in
334 * in prom_env.c and in sunpm.c
335 */
336
337typedef struct promif_owrap {
338	void (*preout)(void);
339	void (*postout)(void);
340} promif_owrap_t;
341
342/*
343 * WAN boot key storage interface
344 */
345int prom_set_security_key(char *keyname, caddr_t buf, int buflen, int *reslen,
346    int *status);
347int prom_get_security_key(char *keyname, caddr_t buf, int buflen, int *keylen,
348    int *status);
349#endif	/* _KERNEL */
350
351#ifdef	__cplusplus
352}
353#endif
354
355#endif /* _SYS_PROMIF_H */
356