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