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