Home | History | Annotate | Line # | Download | only in include
bsd_openprom.h revision 1.4
      1 /*	$NetBSD: bsd_openprom.h,v 1.4 1996/02/13 22:43:33 pk Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1992, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This code is derived from software contributed to Berkeley by
      8  * Jan-Simon Pendry.
      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 University of
     21  *	California, Berkeley and its contributors.
     22  * 4. Neither the name of the University nor the names of its contributors
     23  *    may be used to endorse or promote products derived from this software
     24  *    without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36  * SUCH DAMAGE.
     37  *
     38  *	@(#)bsd_openprom.h	8.1 (Berkeley) 6/11/93
     39  */
     40 
     41 /*
     42  * This file defines the interface between the kernel and the Openboot PROM.
     43  * N.B.: this has been tested only on interface versions 0 and 2 (we have
     44  * never seen interface version 1).
     45  */
     46 
     47 /*
     48  * The v0 interface tells us what virtual memory to scan to avoid PMEG
     49  * conflicts, but the v2 interface fails to do so, and we must `magically'
     50  * know where the OPENPROM lives in virtual space.
     51  */
     52 #define	OPENPROM_STARTVADDR	0xffd00000
     53 #define	OPENPROM_ENDVADDR	0xfff00000
     54 
     55 #define	OPENPROM_MAGIC 0x10010407
     56 
     57 /*
     58  * Version 0 PROM vector device operations (collected here to emphasise that
     59  * they are deprecated).  Open and close are obvious.  Read and write are
     60  * segregated according to the device type (block, network, or character);
     61  * this is unnecessary and was eliminated from the v2 device operations, but
     62  * we are stuck with it.
     63  *
     64  * Seek is probably only useful on tape devices, since the only character
     65  * devices are the serial ports.
     66  *
     67  * Note that a v0 device name is always exactly two characters ("sd", "le",
     68  * and so forth).
     69  */
     70 struct v0devops {
     71 	int	(*v0_open)(char *dev);
     72 	int	(*v0_close)(int d);
     73 	int	(*v0_rbdev)(int d, int nblks, int blkno, void *addr);
     74 	int	(*v0_wbdev)(int d, int nblks, int blkno, void *addr);
     75 	int	(*v0_wnet)(int d, int nbytes, void *addr);
     76 	int	(*v0_rnet)(int d, int nbytes, void *addr);
     77 	int	(*v0_rcdev)(int d, int nbytes, int, void *addr);
     78 	int	(*v0_wcdev)(int d, int nbytes, int, void *addr);
     79 	int	(*v0_seek)(int d, long offset, int whence);
     80 };
     81 
     82 /*
     83  * Version 2 device operations.  Open takes a device `path' such as
     84  * /sbus/le@0,c00000,0 or /sbus/esp@.../sd@0,0, which means it can open
     85  * anything anywhere, without any magic translation.
     86  *
     87  * The memory allocator and map functions are included here even though
     88  * they relate only indirectly to devices (e.g., mmap is good for mapping
     89  * device memory, and drivers need to allocate space in which to record
     90  * the device state).
     91  */
     92 struct v2devops {
     93 	/*
     94 	 * Convert an `instance handle' (acquired through v2_open()) to
     95 	 * a `package handle', a.k.a. a `node'.
     96 	 */
     97 	int	(*v2_fd_phandle)(int d);
     98 
     99 	/* Memory allocation and release. */
    100 	void	*(*v2_malloc)(caddr_t va, u_int sz);
    101 	void	(*v2_free)(caddr_t va, u_int sz);
    102 
    103 	/* Device memory mapper. */
    104 	caddr_t	(*v2_mmap)(caddr_t va, int asi, u_int pa, u_int sz);
    105 	void	(*v2_munmap)(caddr_t va, u_int sz);
    106 
    107 	/* Device open, close, etc. */
    108 	int	(*v2_open)(char *devpath);
    109 	void	(*v2_close)(int d);
    110 	int	(*v2_read)(int d, void *buf, int nbytes);
    111 	int	(*v2_write)(int d, void *buf, int nbytes);
    112 	void	(*v2_seek)(int d, int hi, int lo);
    113 
    114 	void	(*v2_chain)();		/* ??? */
    115 	void	(*v2_release)();	/* ??? */
    116 };
    117 
    118 /*
    119  * The v0 interface describes memory regions with these linked lists.
    120  * (The !$&@#+ v2 interface reformats these as properties, so that we
    121  * have to extract them into local temporary memory and reinterpret them.)
    122  */
    123 struct v0mlist {
    124 	struct	v0mlist *next;
    125 	caddr_t	addr;
    126 	u_int	nbytes;
    127 };
    128 
    129 /*
    130  * V0 gives us three memory lists:  Total physical memory, VM reserved to
    131  * the PROM, and available physical memory (which, presumably, is just the
    132  * total minus any pages mapped in the PROM's VM region).  We can find the
    133  * reserved PMEGs by scanning the taken VM.  Unfortunately, the V2 prom
    134  * forgot to provide taken VM, and we are stuck with scanning ``magic''
    135  * addresses.
    136  */
    137 struct v0mem {
    138 	struct	v0mlist **v0_phystot;	/* physical memory */
    139 	struct	v0mlist **v0_vmprom;	/* VM used by PROM */
    140 	struct	v0mlist **v0_physavail;	/* available physical memory */
    141 };
    142 
    143 /*
    144  * The version 0 PROM breaks up the string given to the boot command and
    145  * leaves the decoded version behind.
    146  */
    147 struct v0bootargs {
    148 	char	*ba_argv[8];		/* argv format for boot string */
    149 	char	ba_args[100];		/* string space */
    150 	char	ba_bootdev[2];		/* e.g., "sd" for `b sd(...' */
    151 	int	ba_ctlr;		/* controller # */
    152 	int	ba_unit;		/* unit # */
    153 	int	ba_part;		/* partition # */
    154 	char	*ba_kernel;		/* kernel to boot, e.g., "vmunix" */
    155 	void	*ba_spare0;		/* not decoded here	XXX */
    156 };
    157 
    158 /*
    159  * The version 2 PROM interface uses the more general, if less convenient,
    160  * approach of passing the boot strings unchanged.  We also get open file
    161  * numbers for stdin and stdout (keyboard and screen, or whatever), for use
    162  * with the v2 device ops.
    163  */
    164 struct v2bootargs {
    165 	char	**v2_bootpath;		/* V2: Path to boot device */
    166 	char	**v2_bootargs;		/* V2: Boot args */
    167 	int	*v2_fd0;		/* V2: Stdin descriptor */
    168 	int	*v2_fd1;		/* V2: Stdout descriptor */
    169 };
    170 
    171 /*
    172  * The following structure defines the primary PROM vector interface.
    173  * The Boot PROM hands the kernel a pointer to this structure in %o0.
    174  * There are numerous substructures defined below.
    175  */
    176 struct promvec {
    177 	/* Version numbers. */
    178 	u_int	pv_magic;		/* Magic number */
    179 	u_int	pv_romvec_vers;		/* interface version (0, 2) */
    180 	u_int	pv_plugin_vers;		/* ??? */
    181 	u_int	pv_printrev;		/* PROM rev # (* 10, e.g 1.9 = 19) */
    182 
    183 	/* Version 0 memory descriptors (see below). */
    184 	struct	v0mem pv_v0mem;		/* V0: Memory description lists. */
    185 
    186 	/* Node operations (see below). */
    187 	struct	nodeops *pv_nodeops;	/* node functions */
    188 
    189 	char	**pv_bootstr;		/* Boot command, eg sd(0,0,0)vmunix */
    190 
    191 	struct	v0devops pv_v0devops;	/* V0: device ops */
    192 
    193 	/*
    194 	 * PROMDEV_* cookies.  I fear these may vanish in lieu of fd0/fd1
    195 	 * (see below) in future PROMs, but for now they work fine.
    196 	 */
    197 	char	*pv_stdin;		/* stdin cookie */
    198 	char	*pv_stdout;		/* stdout cookie */
    199 #define	PROMDEV_KBD	0		/* input from keyboard */
    200 #define	PROMDEV_SCREEN	0		/* output to screen */
    201 #define	PROMDEV_TTYA	1		/* in/out to ttya */
    202 #define	PROMDEV_TTYB	2		/* in/out to ttyb */
    203 
    204 	/* Blocking getchar/putchar.  NOT REENTRANT! (grr) */
    205 	int	(*pv_getchar)(void);
    206 	void	(*pv_putchar)(int ch);
    207 
    208 	/* Non-blocking variants that return -1 on error. */
    209 	int	(*pv_nbgetchar)(void);
    210 	int	(*pv_nbputchar)(int ch);
    211 
    212 	/* Put counted string (can be very slow). */
    213 	void	(*pv_putstr)(char *str, int len);
    214 
    215 	/* Miscellany. */
    216 	void	(*pv_reboot)(char *bootstr);
    217 	void	(*pv_printf)(const char *fmt, ...);
    218 	void	(*pv_abort)(void);	/* L1-A abort */
    219 	int	*pv_ticks;		/* Ticks since last reset */
    220 	__dead void (*pv_halt)(void);	/* Halt! */
    221 	void	(**pv_synchook)(void);	/* "sync" command hook */
    222 
    223 	/*
    224 	 * This eval's a FORTH string.  Unfortunately, its interface
    225 	 * changed between V0 and V2, which gave us much pain.
    226 	 */
    227 	union {
    228 		void	(*v0_eval)(int len, char *str);
    229 		void	(*v2_eval)(char *str);
    230 	} pv_fortheval;
    231 
    232 	struct	v0bootargs **pv_v0bootargs;	/* V0: Boot args */
    233 
    234 	/* Extract Ethernet address from network device. */
    235 	u_int	(*pv_enaddr)(int d, char *enaddr);
    236 
    237 	struct	v2bootargs pv_v2bootargs;	/* V2: Boot args + std in/out */
    238 	struct	v2devops pv_v2devops;	/* V2: device operations */
    239 
    240 	int	pv_spare[15];
    241 
    242 	/*
    243 	 * The following is machine-dependent.
    244 	 *
    245 	 * The sun4c needs a PROM function to set a PMEG for another
    246 	 * context, so that the kernel can map itself in all contexts.
    247 	 * It is not possible simply to set the context register, because
    248 	 * contexts 1 through N may have invalid translations for the
    249 	 * current program counter.  The hardware has a mode in which
    250 	 * all memory references go to the PROM, so the PROM can do it
    251 	 * easily.
    252 	 */
    253 	void	(*pv_setctxt)(int ctxt, caddr_t va, int pmeg);
    254 #if defined(SUN4M) && defined(notyet)
    255 	/*
    256 	 * The following are V3 ROM functions to handle MP machines in the
    257 	 * Sun4m series. They have undefined results when run on a uniprocessor!
    258 	 */
    259 	int	(*pv_v3cpustart)(u_int module, u_int ctxtbl,
    260 				 int context, caddr_t pc);
    261 	int 	(*pv_v3cpustop)(u_int module);
    262 	int	(*pv_v3cpuidle)(u_int module);
    263 	int 	(*pv_v3cpuresume)(u_int module);
    264 #endif
    265 };
    266 
    267 /*
    268  * In addition to the global stuff defined in the PROM vectors above,
    269  * the PROM has quite a collection of `nodes'.  A node is described by
    270  * an integer---these seem to be internal pointers, actually---and the
    271  * nodes are arranged into an N-ary tree.  Each node implements a fixed
    272  * set of functions, as described below.  The first two deal with the tree
    273  * structure, allowing traversals in either breadth- or depth-first fashion.
    274  * The rest deal with `properties'.
    275  *
    276  * A node property is simply a name/value pair.  The names are C strings
    277  * (NUL-terminated); the values are arbitrary byte strings (counted strings).
    278  * Many values are really just C strings.  Sometimes these are NUL-terminated,
    279  * sometimes not, depending on the the interface version; v0 seems to
    280  * terminate and v2 not.  Many others are simply integers stored as four
    281  * bytes in machine order: you just get them and go.  The third popular
    282  * format is an `address', which is made up of one or more sets of three
    283  * integers as defined below.
    284  *
    285  * N.B.: for the `next' functions, next(0) = first, and next(last) = 0.
    286  * Whoever designed this part had good taste.  On the other hand, these
    287  * operation vectors are global, rather than per-node, yet the pointers
    288  * are not in the openprom vectors but rather found by indirection from
    289  * there.  So the taste balances out.
    290  */
    291 struct openprom_addr {
    292 	int	oa_space;		/* address space (may be relative) */
    293 	u_int	oa_base;		/* address within space */
    294 	u_int	oa_size;		/* extent (number of bytes) */
    295 };
    296 
    297 struct nodeops {
    298 	/*
    299 	 * Tree traversal.
    300 	 */
    301 	int	(*no_nextnode)(int node);	/* next(node) */
    302 	int	(*no_child)(int node);	/* first child */
    303 
    304 	/*
    305 	 * Property functions.  Proper use of getprop requires calling
    306 	 * proplen first to make sure it fits.  Kind of a pain, but no
    307 	 * doubt more convenient for the PROM coder.
    308 	 */
    309 	int	(*no_proplen)(int node, caddr_t name);
    310 	int	(*no_getprop)(int node, caddr_t name, caddr_t val);
    311 	int	(*no_setprop)(int node, caddr_t name, caddr_t val, int len);
    312 	caddr_t	(*no_nextprop)(int node, caddr_t name);
    313 };
    314