Home | History | Annotate | Line # | Download | only in include
promlib.h revision 1.8
      1 /*	$NetBSD: promlib.h,v 1.8 2003/02/26 17:39:06 pk Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Paul Kranenburg.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * OPENPROM functions.  These are here mainly to hide the OPENPROM interface
     41  * from the rest of the kernel.
     42  */
     43 
     44 #ifndef _SPARC_PROMLIB_H_
     45 #define _SPARC_PROMLIB_H_
     46 
     47 #include <machine/idprom.h>
     48 #include <machine/bsd_openprom.h>
     49 #include <machine/openfirm.h>
     50 
     51 /*
     52  * A set of methods to access the firmware.
     53  * We use this to support various versions of Open Boot Prom
     54  * or Open Firmware implementations.
     55  */
     56 struct promops {
     57 	int	po_version;		/* PROM version number */
     58 #define PROM_OLDMON	0
     59 #define PROM_OBP_V0	1
     60 #define PROM_OBP_V2	2
     61 #define PROM_OBP_V3	3
     62 #define PROM_OPENFIRM	4
     63 	int	po_revision;		/* revision level */
     64 	int	po_stdin;		/* stdio handles */
     65 	int	po_stdout;		/* */
     66 	void	*po_bootcookie;
     67 
     68 	/* Access to boot arguments */
     69 	char	*(*po_bootpath) __P((void));
     70 	char	*(*po_bootfile) __P((void));
     71 	char	*(*po_bootargs) __P((void));
     72 
     73 	/* I/O functions */
     74 	int	(*po_getchar) __P((void));
     75 	int	(*po_peekchar) __P((void));
     76 	void	(*po_putchar) __P((int));
     77 	void	(*po_putstr) __P((char *, int));
     78 	int	(*po_open) __P((char *));
     79 	void	(*po_close) __P((int));
     80 	int	(*po_read) __P((int, void *, int));
     81 	int	(*po_write) __P((int, void *, int));
     82 	int	(*po_seek) __P((int, u_quad_t));
     83 
     84 	int	(*po_instance_to_package) __P((int));
     85 
     86 	/* Misc functions (common in OBP 0,2,3) */
     87 	void	(*po_halt) __P((void))		__attribute__((__noreturn__));
     88 	void	(*po_reboot) __P((char *))	__attribute__((__noreturn__));
     89 	void	(*po_abort) __P((void));
     90 	void	(*po_interpret) __P((char *));
     91 	void	(*po_setcallback) __P((void (*)__P((void))));
     92 	int	(*po_ticks) __P((void));
     93 	void	*po_tickdata;
     94 
     95 	/* sun4/sun4c only */
     96 	void	(*po_setcontext) __P((int ctxt, caddr_t va, int pmeg));
     97 
     98 	/* MP functions (OBP v3 only) */
     99 	int	(*po_cpustart) __P((int, struct openprom_addr *, int, caddr_t));
    100 	int	(*po_cpustop) __P((int));
    101 	int	(*po_cpuidle) __P((int));
    102 	int	(*po_cpuresume) __P((int));
    103 
    104 	/* Device node traversal (OBP v0, v2, v3; but not sun4) */
    105 	int	(*po_firstchild) __P((int));
    106 	int	(*po_nextsibling) __P((int));
    107 
    108 	/* Device node properties */
    109 	int	(*po_getproplen) __P((int node, char *name));
    110 	int	(*po_getprop) __P((int node, char *name, void *, int));
    111 	int	(*po_setprop) __P((int node, char *name, const void *, int));
    112 	char	*(*po_nextprop) __P((int node, char *name));
    113 
    114 	int	(*po_finddevice) __P((char *name));
    115 
    116 };
    117 
    118 extern struct promops	promops;
    119 
    120 /*
    121  * Memory description array.
    122  * Same as version 2 rom meminfo property.
    123  */
    124 struct memarr {
    125 	int	zero;
    126 	u_int	addr;
    127 	u_int	len;
    128 };
    129 int	prom_makememarr(struct memarr *, int max, int which);
    130 #define	MEMARR_AVAILPHYS	0
    131 #define	MEMARR_TOTALPHYS	1
    132 
    133 struct idprom	*prom_getidprom(void);
    134 void		prom_getether(u_char *);
    135 
    136 void	prom_init	__P((void));	/* To setup promops */
    137 
    138 /* Utility routines */
    139 int	prom_prop	__P((int, char *, int, int *, void **));
    140 int	PROM_getprop		__P((int, char *, int, int *, void **));
    141 int	PROM_getpropint	__P((int node, char *name, int deflt));
    142 char	*PROM_getpropstring	__P((int node, char *name));
    143 char	*PROM_getpropstringA	__P((int node, char *name, char *, size_t));
    144 void	prom_printf	__P((const char *, ...));
    145 
    146 int	prom_findroot	__P((void));
    147 int	prom_findnode	__P((int, const char *));
    148 int	prom_search	__P((int, const char *));
    149 int	prom_opennode	__P((char *));
    150 int	prom_node_has_property __P((int, const char *));
    151 
    152 #define	findroot()		prom_findroot()
    153 #define	findnode(node,name)	prom_findnode(node,name)
    154 #define	search_prom(node,name)	prom_search(node,name)
    155 #define	opennode(name)		prom_opennode(name)
    156 #define	node_has_property(node,prop)	prom_node_has_property(node,prop)
    157 
    158 void	prom_halt __P((void))	__attribute__((__noreturn__));
    159 void	prom_boot __P((char *))	__attribute__((__noreturn__));
    160 
    161 #if defined(MULTIPROCESSOR)
    162 #define callrom() do {		\
    163 	mp_pause_cpus();	\
    164 	prom_abort();		\
    165 	mp_resume_cpus();	\
    166 } while (0)
    167 #else
    168 #define callrom()		prom_abort()
    169 #endif
    170 
    171 #define prom_version()		(promops.po_version)
    172 #define prom_revision()		(promops.po_revision)
    173 #define prom_stdin()		(promops.po_stdin)
    174 #define prom_stdout()		(promops.po_stdout)
    175 #define _prom_halt()		((*promops.po_halt)(/*void*/))
    176 #define _prom_boot(a)		((*promops.po_reboot)(a))
    177 #define prom_abort()		((*promops.po_abort)(/*void*/))
    178 #define prom_interpret(a)	((*promops.po_interpret)(a))
    179 #define prom_setcallback(f)	((*promops.po_setcallback)(f))
    180 #define prom_setcontext(c,a,p)	((*promops.po_setcontext)(c,a,p))
    181 #define prom_getbootpath()	((*promops.po_bootpath)(/*void*/))
    182 #define prom_getbootfile()	((*promops.po_bootfile)(/*void*/))
    183 #define prom_getbootargs()	((*promops.po_bootargs)(/*void*/))
    184 #define prom_ticks()		((*promops.po_ticks)(/*void*/))
    185 
    186 
    187 #define prom_open(name)		((*promops.po_open)(name))
    188 #define prom_close(fd)		((*promops.po_close)(fd))
    189 #define prom_instance_to_package(fd) \
    190 				((*promops.po_instance_to_package)(fd))
    191 #define prom_read(fd,b,n)	((*promops.po_read)(fd,b,n))
    192 #define prom_write(fd,b,n)	((*promops.po_write)(fd,b,n))
    193 #define prom_seek(fd,o)		((*promops.po_seek)(fd,o))
    194 #define prom_getchar()		((*promops.po_getchar)(/*void*/))
    195 #define prom_peekchar()		((*promops.po_peekchar)(/*void*/))
    196 #define prom_putchar(c)		((*promops.po_putchar)(c))
    197 #define prom_putstr(b,n)	((*promops.po_putstr)(b,n))
    198 
    199 /* Node traversal */
    200 #define prom_firstchild(node)	((*promops.po_firstchild)(node))
    201 #define prom_nextsibling(node)	((*promops.po_nextsibling)(node))
    202 #define prom_proplen(node,name)	((*promops.po_getproplen)(node, name))
    203 #define _prom_getprop(node, name, buf, len) \
    204 				((*promops.po_getprop)(node, name, buf, len))
    205 #define prom_setprop(node, name, value, len) \
    206 				((*promops.po_setprop)(node, name, value, len))
    207 #define prom_nextprop(node,name)	((*promops.po_nextprop)(node, name))
    208 #define prom_finddevice(name)	((*promops.po_finddevice)(name))
    209 
    210 #define firstchild(node)	prom_firstchild(node)
    211 #define nextsibling(node)	prom_nextsibling(node)
    212 #define PROM_getproplen(node,name)	prom_proplen(node, name)
    213 
    214 
    215 /* MP stuff - not currently used */
    216 #define prom_cpustart(m,a,c,pc)	((*promops.po_cpustart)(m,a,c,pc))
    217 #define prom_cpustop(m)		((*promops.po_cpustop)(m))
    218 #define prom_cpuidle(m)		((*promops.po_cpuidle)(m))
    219 #define prom_cpuresume(m)	((*promops.po_cpuresume)(m))
    220 
    221 extern void	*romp;		/* PROM-supplied argument (see locore) */
    222 
    223 #endif /* _SPARC_PROMLIB_H_ */
    224