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