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