xref: /netbsd-src/sys/arch/sparc/include/bsd_openprom.h (revision 970ad9314d83502b9cd29f0dabe49a97869065ed)
1*970ad931Sperry /*	$NetBSD: bsd_openprom.h,v 1.25 2007/12/24 15:46:45 perry Exp $ */
2274a9076Sderaadt 
34588caefSderaadt /*
44588caefSderaadt  * Copyright (c) 1992, 1993
54588caefSderaadt  *	The Regents of the University of California.  All rights reserved.
64588caefSderaadt  *
74588caefSderaadt  * This code is derived from software contributed to Berkeley by
84588caefSderaadt  * Jan-Simon Pendry.
94588caefSderaadt  *
104588caefSderaadt  * Redistribution and use in source and binary forms, with or without
114588caefSderaadt  * modification, are permitted provided that the following conditions
124588caefSderaadt  * are met:
134588caefSderaadt  * 1. Redistributions of source code must retain the above copyright
144588caefSderaadt  *    notice, this list of conditions and the following disclaimer.
154588caefSderaadt  * 2. Redistributions in binary form must reproduce the above copyright
164588caefSderaadt  *    notice, this list of conditions and the following disclaimer in the
174588caefSderaadt  *    documentation and/or other materials provided with the distribution.
18aad01611Sagc  * 3. Neither the name of the University nor the names of its contributors
194588caefSderaadt  *    may be used to endorse or promote products derived from this software
204588caefSderaadt  *    without specific prior written permission.
214588caefSderaadt  *
224588caefSderaadt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
234588caefSderaadt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
244588caefSderaadt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
254588caefSderaadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
264588caefSderaadt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
274588caefSderaadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
284588caefSderaadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
294588caefSderaadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
304588caefSderaadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
314588caefSderaadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
324588caefSderaadt  * SUCH DAMAGE.
334588caefSderaadt  *
344588caefSderaadt  *	@(#)bsd_openprom.h	8.1 (Berkeley) 6/11/93
354588caefSderaadt  */
364588caefSderaadt 
374588caefSderaadt /*
384bbf23d0Sabrown  * Sun4m support by Aaron Brown, Harvard University.
39bb0897eeSpk  * Changes Copyright (c) 1995 The President and Fellows of Harvard College.
40bb0897eeSpk  * All rights reserved.
41bb0897eeSpk  */
42bb0897eeSpk 
4343c1cb85Spk #ifndef _BSD_OPENPROM_H_
4443c1cb85Spk #define _BSD_OPENPROM_H_
4543c1cb85Spk 
46bb0897eeSpk /*
474588caefSderaadt  * This file defines the interface between the kernel and the Openboot PROM.
484588caefSderaadt  * N.B.: this has been tested only on interface versions 0 and 2 (we have
494588caefSderaadt  * never seen interface version 1).
504588caefSderaadt  */
514588caefSderaadt 
524588caefSderaadt /*
534588caefSderaadt  * The v0 interface tells us what virtual memory to scan to avoid PMEG
544588caefSderaadt  * conflicts, but the v2 interface fails to do so, and we must `magically'
554588caefSderaadt  * know where the OPENPROM lives in virtual space.
564588caefSderaadt  */
574588caefSderaadt #define	OPENPROM_STARTVADDR	0xffd00000
584588caefSderaadt #define	OPENPROM_ENDVADDR	0xfff00000
594588caefSderaadt 
604588caefSderaadt #define	OPENPROM_MAGIC 0x10010407
614588caefSderaadt 
624588caefSderaadt /*
634588caefSderaadt  * Version 0 PROM vector device operations (collected here to emphasise that
644588caefSderaadt  * they are deprecated).  Open and close are obvious.  Read and write are
654588caefSderaadt  * segregated according to the device type (block, network, or character);
664588caefSderaadt  * this is unnecessary and was eliminated from the v2 device operations, but
674588caefSderaadt  * we are stuck with it.
684588caefSderaadt  *
694588caefSderaadt  * Seek is probably only useful on tape devices, since the only character
704588caefSderaadt  * devices are the serial ports.
714588caefSderaadt  *
724588caefSderaadt  * Note that a v0 device name is always exactly two characters ("sd", "le",
734588caefSderaadt  * and so forth).
744588caefSderaadt  */
754588caefSderaadt struct v0devops {
76be19dad5Schristos 	int	(*v0_open)(const char *);
77be19dad5Schristos 	int	(*v0_close)(int);
78be19dad5Schristos 	int	(*v0_rbdev)(int, int, int, void *);
79be19dad5Schristos 	int	(*v0_wbdev)(int, int, int, void *);
80be19dad5Schristos 	int	(*v0_wnet)(int, int, void *);
81be19dad5Schristos 	int	(*v0_rnet)(int, int, void *);
82be19dad5Schristos 	int	(*v0_rcdev)(int, int, int, void *);
83be19dad5Schristos 	int	(*v0_wcdev)(int, int, int, void *);
84be19dad5Schristos 	int	(*v0_seek)(int, long, int);
854588caefSderaadt };
864588caefSderaadt 
874588caefSderaadt /*
884588caefSderaadt  * Version 2 device operations.  Open takes a device `path' such as
894588caefSderaadt  * /sbus/le@0,c00000,0 or /sbus/esp@.../sd@0,0, which means it can open
904588caefSderaadt  * anything anywhere, without any magic translation.
914588caefSderaadt  *
924588caefSderaadt  * The memory allocator and map functions are included here even though
934588caefSderaadt  * they relate only indirectly to devices (e.g., mmap is good for mapping
944588caefSderaadt  * device memory, and drivers need to allocate space in which to record
954588caefSderaadt  * the device state).
964588caefSderaadt  */
974588caefSderaadt struct v2devops {
98b04e1724Spk 	/*
99b04e1724Spk 	 * Convert an `instance handle' (acquired through v2_open()) to
100b04e1724Spk 	 * a `package handle', a.k.a. a `node'.
101b04e1724Spk 	 */
102be19dad5Schristos 	int	(*v2_fd_phandle)(int);
1034588caefSderaadt 
1044588caefSderaadt 	/* Memory allocation and release. */
10553524e44Schristos 	void	*(*v2_malloc)(void *, u_int);
10653524e44Schristos 	void	(*v2_free)(void *, u_int);
1074588caefSderaadt 
1084588caefSderaadt 	/* Device memory mapper. */
10953524e44Schristos 	void *	(*v2_mmap)(void *, int, u_int, u_int);
11053524e44Schristos 	void	(*v2_munmap)(void *, u_int);
1114588caefSderaadt 
1124588caefSderaadt 	/* Device open, close, etc. */
113be19dad5Schristos 	int	(*v2_open)(const char *);
114be19dad5Schristos 	void	(*v2_close)(int);
115be19dad5Schristos 	int	(*v2_read)(int, void *, int);
116be19dad5Schristos 	int	(*v2_write)(int, const void *, int);
117be19dad5Schristos 	void	(*v2_seek)(int, int, int);
1184588caefSderaadt 
119be19dad5Schristos 	void	(*v2_chain)(void);	/* ??? */
120be19dad5Schristos 	void	(*v2_release)(void);	/* ??? */
1214588caefSderaadt };
1224588caefSderaadt 
1234588caefSderaadt /*
1244588caefSderaadt  * The v0 interface describes memory regions with these linked lists.
1254588caefSderaadt  * (The !$&@#+ v2 interface reformats these as properties, so that we
1264588caefSderaadt  * have to extract them into local temporary memory and reinterpret them.)
1274588caefSderaadt  */
1284588caefSderaadt struct v0mlist {
1294588caefSderaadt 	struct	v0mlist *next;
13053524e44Schristos 	void *	addr;
1314588caefSderaadt 	u_int	nbytes;
1324588caefSderaadt };
1334588caefSderaadt 
1344588caefSderaadt /*
1354588caefSderaadt  * V0 gives us three memory lists:  Total physical memory, VM reserved to
1364588caefSderaadt  * the PROM, and available physical memory (which, presumably, is just the
1374588caefSderaadt  * total minus any pages mapped in the PROM's VM region).  We can find the
1384588caefSderaadt  * reserved PMEGs by scanning the taken VM.  Unfortunately, the V2 prom
1394588caefSderaadt  * forgot to provide taken VM, and we are stuck with scanning ``magic''
1404588caefSderaadt  * addresses.
1414588caefSderaadt  */
1424588caefSderaadt struct v0mem {
1434588caefSderaadt 	struct	v0mlist **v0_phystot;	/* physical memory */
1444588caefSderaadt 	struct	v0mlist **v0_vmprom;	/* VM used by PROM */
1454588caefSderaadt 	struct	v0mlist **v0_physavail;	/* available physical memory */
1464588caefSderaadt };
1474588caefSderaadt 
1484588caefSderaadt /*
1494588caefSderaadt  * The version 0 PROM breaks up the string given to the boot command and
1504588caefSderaadt  * leaves the decoded version behind.
1514588caefSderaadt  */
1524588caefSderaadt struct v0bootargs {
1534588caefSderaadt 	char	*ba_argv[8];		/* argv format for boot string */
1544588caefSderaadt 	char	ba_args[100];		/* string space */
1554588caefSderaadt 	char	ba_bootdev[2];		/* e.g., "sd" for `b sd(...' */
1564588caefSderaadt 	int	ba_ctlr;		/* controller # */
1574588caefSderaadt 	int	ba_unit;		/* unit # */
1584588caefSderaadt 	int	ba_part;		/* partition # */
1594588caefSderaadt 	char	*ba_kernel;		/* kernel to boot, e.g., "vmunix" */
1604588caefSderaadt 	void	*ba_spare0;		/* not decoded here	XXX */
1614588caefSderaadt };
1624588caefSderaadt 
1634588caefSderaadt /*
1644588caefSderaadt  * The version 2 PROM interface uses the more general, if less convenient,
1654588caefSderaadt  * approach of passing the boot strings unchanged.  We also get open file
1664588caefSderaadt  * numbers for stdin and stdout (keyboard and screen, or whatever), for use
1674588caefSderaadt  * with the v2 device ops.
1684588caefSderaadt  */
1694588caefSderaadt struct v2bootargs {
1704588caefSderaadt 	char	**v2_bootpath;		/* V2: Path to boot device */
1714588caefSderaadt 	char	**v2_bootargs;		/* V2: Boot args */
1724588caefSderaadt 	int	*v2_fd0;		/* V2: Stdin descriptor */
1734588caefSderaadt 	int	*v2_fd1;		/* V2: Stdout descriptor */
1744588caefSderaadt };
1754588caefSderaadt 
1764588caefSderaadt /*
177de6a644cSthorpej  * The format used by the PROM to describe a physical address.  These
178de6a644cSthorpej  * are typically found in a "reg" property.
17943c1cb85Spk  */
18043c1cb85Spk struct openprom_addr {
18143c1cb85Spk 	int	oa_space;		/* address space (may be relative) */
18243c1cb85Spk 	u_int	oa_base;		/* address within space */
18343c1cb85Spk 	u_int	oa_size;		/* extent (number of bytes) */
18443c1cb85Spk };
18543c1cb85Spk 
18643c1cb85Spk /*
187de6a644cSthorpej  * The format used by the PROM to describe an address space window.  These
188de6a644cSthorpej  * are typically found in a "range" property.
189de6a644cSthorpej  */
190de6a644cSthorpej struct openprom_range {
191de6a644cSthorpej 	int	or_child_space;		/* address space of child */
192de6a644cSthorpej 	u_int	or_child_base;		/* offset in child's view of bus */
193de6a644cSthorpej 	int	or_parent_space;	/* address space of parent */
194de6a644cSthorpej 	u_int	or_parent_base;		/* offset in parent's view of bus */
195de6a644cSthorpej 	u_int	or_size;		/* extent (number of bytes) */
196de6a644cSthorpej };
197de6a644cSthorpej 
198de6a644cSthorpej /*
199de6a644cSthorpej  * The format used by the PROM to describe an interrupt.  These are
200de6a644cSthorpej  * typically found in an "intr" property.
201de6a644cSthorpej  */
202de6a644cSthorpej struct openprom_intr {
203de6a644cSthorpej 	int	oi_pri;			/* interrupt priority */
204de6a644cSthorpej 	int	oi_vec;			/* interrupt vector */
205de6a644cSthorpej };
206de6a644cSthorpej 
207de6a644cSthorpej /*
2084588caefSderaadt  * The following structure defines the primary PROM vector interface.
2094588caefSderaadt  * The Boot PROM hands the kernel a pointer to this structure in %o0.
2104588caefSderaadt  * There are numerous substructures defined below.
2114588caefSderaadt  */
2124588caefSderaadt struct promvec {
2134588caefSderaadt 	/* Version numbers. */
2144588caefSderaadt 	u_int	pv_magic;		/* Magic number */
2151e5bf777Spk #define OBP_MAGIC	0x10010407
2164588caefSderaadt 	u_int	pv_romvec_vers;		/* interface version (0, 2) */
2174588caefSderaadt 	u_int	pv_plugin_vers;		/* ??? */
2184588caefSderaadt 	u_int	pv_printrev;		/* PROM rev # (* 10, e.g 1.9 = 19) */
2194588caefSderaadt 
2204588caefSderaadt 	/* Version 0 memory descriptors (see below). */
2214588caefSderaadt 	struct	v0mem pv_v0mem;		/* V0: Memory description lists. */
2224588caefSderaadt 
2234588caefSderaadt 	/* Node operations (see below). */
2244588caefSderaadt 	struct	nodeops *pv_nodeops;	/* node functions */
2254588caefSderaadt 
2264588caefSderaadt 	char	**pv_bootstr;		/* Boot command, eg sd(0,0,0)vmunix */
2274588caefSderaadt 
2284588caefSderaadt 	struct	v0devops pv_v0devops;	/* V0: device ops */
2294588caefSderaadt 
2304588caefSderaadt 	/*
2314588caefSderaadt 	 * PROMDEV_* cookies.  I fear these may vanish in lieu of fd0/fd1
2324588caefSderaadt 	 * (see below) in future PROMs, but for now they work fine.
2334588caefSderaadt 	 */
2344588caefSderaadt 	char	*pv_stdin;		/* stdin cookie */
2354588caefSderaadt 	char	*pv_stdout;		/* stdout cookie */
2364588caefSderaadt #define	PROMDEV_KBD	0		/* input from keyboard */
2374588caefSderaadt #define	PROMDEV_SCREEN	0		/* output to screen */
2384588caefSderaadt #define	PROMDEV_TTYA	1		/* in/out to ttya */
2394588caefSderaadt #define	PROMDEV_TTYB	2		/* in/out to ttyb */
2404588caefSderaadt 
2414588caefSderaadt 	/* Blocking getchar/putchar.  NOT REENTRANT! (grr) */
242be19dad5Schristos 	int	(*pv_getchar)(void);
243be19dad5Schristos 	void	(*pv_putchar)(int);
2444588caefSderaadt 
2454588caefSderaadt 	/* Non-blocking variants that return -1 on error. */
246be19dad5Schristos 	int	(*pv_nbgetchar)(void);
247be19dad5Schristos 	int	(*pv_nbputchar)(int);
2484588caefSderaadt 
2494588caefSderaadt 	/* Put counted string (can be very slow). */
250be19dad5Schristos 	void	(*pv_putstr)(const char *, int);
2514588caefSderaadt 
2524588caefSderaadt 	/* Miscellany. */
253be19dad5Schristos 	void	(*pv_reboot)(const char *) __attribute__((__noreturn__));
254be19dad5Schristos 	void	(*pv_printf)(const char *, ...);
255be19dad5Schristos 	void	(*pv_abort)(void);	/* L1-A abort */
2564588caefSderaadt 	int	*pv_ticks;		/* Ticks since last reset */
257*970ad931Sperry 	__dead void (*pv_halt)(void);	/* Halt! */
258be19dad5Schristos 	void	(**pv_synchook)(void);	/* "sync" command hook */
2594588caefSderaadt 
2604588caefSderaadt 	/*
2614588caefSderaadt 	 * This eval's a FORTH string.  Unfortunately, its interface
2624588caefSderaadt 	 * changed between V0 and V2, which gave us much pain.
2634588caefSderaadt 	 */
2644588caefSderaadt 	union {
265be19dad5Schristos 		void	(*v0_eval)(int, const char *);
266be19dad5Schristos 		void	(*v2_eval)(const char *);
2674588caefSderaadt 	} pv_fortheval;
2684588caefSderaadt 
2694588caefSderaadt 	struct	v0bootargs **pv_v0bootargs;	/* V0: Boot args */
2704588caefSderaadt 
2714588caefSderaadt 	/* Extract Ethernet address from network device. */
272be19dad5Schristos 	u_int	(*pv_enaddr)(int, char *);
2734588caefSderaadt 
2744588caefSderaadt 	struct	v2bootargs pv_v2bootargs;	/* V2: Boot args + std in/out */
2754588caefSderaadt 	struct	v2devops pv_v2devops;	/* V2: device operations */
2764588caefSderaadt 
2774588caefSderaadt 	int	pv_spare[15];
2784588caefSderaadt 
2794588caefSderaadt 	/*
2804588caefSderaadt 	 * The following is machine-dependent.
2814588caefSderaadt 	 *
2824588caefSderaadt 	 * The sun4c needs a PROM function to set a PMEG for another
2834588caefSderaadt 	 * context, so that the kernel can map itself in all contexts.
2844588caefSderaadt 	 * It is not possible simply to set the context register, because
2854588caefSderaadt 	 * contexts 1 through N may have invalid translations for the
2864588caefSderaadt 	 * current program counter.  The hardware has a mode in which
2874588caefSderaadt 	 * all memory references go to the PROM, so the PROM can do it
2884588caefSderaadt 	 * easily.
2894588caefSderaadt 	 */
29053524e44Schristos 	void	(*pv_setctxt)(int, void *, int);
29118fbdfc2Spk 
292773f74b6Spk 	/*
293773f74b6Spk 	 * The following are V3 ROM functions to handle MP machines in the
294773f74b6Spk 	 * Sun4m series. They have undefined results when run on a uniprocessor!
295773f74b6Spk 	 */
29653524e44Schristos 	int	(*pv_v3cpustart)(int, struct openprom_addr *, int, void *);
297be19dad5Schristos 	int 	(*pv_v3cpustop)(int);
298be19dad5Schristos 	int	(*pv_v3cpuidle)(int);
299be19dad5Schristos 	int 	(*pv_v3cpuresume)(int);
3004588caefSderaadt };
3014588caefSderaadt 
3024588caefSderaadt /*
3034588caefSderaadt  * In addition to the global stuff defined in the PROM vectors above,
3044588caefSderaadt  * the PROM has quite a collection of `nodes'.  A node is described by
3054588caefSderaadt  * an integer---these seem to be internal pointers, actually---and the
3064588caefSderaadt  * nodes are arranged into an N-ary tree.  Each node implements a fixed
3074588caefSderaadt  * set of functions, as described below.  The first two deal with the tree
3084588caefSderaadt  * structure, allowing traversals in either breadth- or depth-first fashion.
3094588caefSderaadt  * The rest deal with `properties'.
3104588caefSderaadt  *
3114588caefSderaadt  * A node property is simply a name/value pair.  The names are C strings
3124588caefSderaadt  * (NUL-terminated); the values are arbitrary byte strings (counted strings).
3134588caefSderaadt  * Many values are really just C strings.  Sometimes these are NUL-terminated,
31495054da1Ssoren  * sometimes not, depending on the interface version; v0 seems to terminate
31595054da1Ssoren  * and v2 not.  Many others are simply integers stored as four bytes in
31695054da1Ssoren  * machine order: you just get them and go.  The third popular format is
31795054da1Ssoren  * an `physical address', which is made up of one or more sets of three
31895054da1Ssoren  * integers as defined above.
3194588caefSderaadt  *
3204588caefSderaadt  * N.B.: for the `next' functions, next(0) = first, and next(last) = 0.
3214588caefSderaadt  * Whoever designed this part had good taste.  On the other hand, these
3224588caefSderaadt  * operation vectors are global, rather than per-node, yet the pointers
3234588caefSderaadt  * are not in the openprom vectors but rather found by indirection from
3244588caefSderaadt  * there.  So the taste balances out.
3254588caefSderaadt  */
3264588caefSderaadt 
3274588caefSderaadt struct nodeops {
3284588caefSderaadt 	/*
3294588caefSderaadt 	 * Tree traversal.
3304588caefSderaadt 	 */
331be19dad5Schristos 	int	(*no_nextnode)(int);	/* next(node) */
332be19dad5Schristos 	int	(*no_child)(int);	/* first child */
3334588caefSderaadt 
3344588caefSderaadt 	/*
3354588caefSderaadt 	 * Property functions.  Proper use of getprop requires calling
3364588caefSderaadt 	 * proplen first to make sure it fits.  Kind of a pain, but no
3374588caefSderaadt 	 * doubt more convenient for the PROM coder.
3384588caefSderaadt 	 */
339be19dad5Schristos 	int	(*no_proplen)(int, const char *);
340be19dad5Schristos 	int	(*no_getprop)(int, const char *, void *);
341be19dad5Schristos 	int	(*no_setprop)(int, const char *, const void *, int);
342be19dad5Schristos 	char	*(*no_nextprop)(int, const char *);
3434588caefSderaadt };
3445b2bf5a5Schristos 
34572286d42Spk /*
34672286d42Spk  *  OBP Module mailbox messages for multi processor machines.
34772286d42Spk  *
34872286d42Spk  *	00..7F	: power-on self test
34972286d42Spk  *	80..8F	: active in boot prom (at the "ok" prompt)
35072286d42Spk  *	90..EF	: idle in boot prom
35172286d42Spk  *	F0	: active in application
35272286d42Spk  *	F1..FA	: reserved for future use
35372286d42Spk  *
35472286d42Spk  *	FB	: pv_v3cpustop(node) was called for this CPU,
35572286d42Spk  *		  respond by calling pv_v3cpustop(0).
35672286d42Spk  *
35772286d42Spk  *	FC	: pv_v3cpuidle(node) was called for this CPU,
35872286d42Spk  *		  respond by calling pv_v3cpuidle(0).
35972286d42Spk  *
36072286d42Spk  *	FD	: One processor hit a BREAKPOINT, call pv_v3cpuidle(0).
36172286d42Spk  *		  [According to SunOS4 header; but what breakpoint?]
36272286d42Spk  *
36372286d42Spk  *	FE	: One processor got a WATCHDOG RESET, call pv_v3cpustop(0).
36472286d42Spk  *		  [According to SunOS4 header; never seen this, although
36572286d42Spk  *		   I've had plenty of watchdogs already]
36672286d42Spk  *
36772286d42Spk  *	FF	: This processor is not available.
36872286d42Spk  */
36972286d42Spk 
37072286d42Spk #define OPENPROM_MBX_STOP	0xfb
37172286d42Spk #define OPENPROM_MBX_ABORT	0xfc
37272286d42Spk #define OPENPROM_MBX_BPT	0xfd
37372286d42Spk #define OPENPROM_MBX_WD		0xfe
37472286d42Spk 
37543c1cb85Spk #endif /* _BSD_OPENPROM_H_ */
376