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