1 /* $NetBSD: bsd_openprom.h,v 1.24 2007/03/04 06:00:44 christos Exp $ */
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)bsd_openprom.h 8.1 (Berkeley) 6/11/93
38 * Sun4m support by Aaron Brown, Harvard University.
39 * Changes Copyright (c) 1995 The President and Fellows of Harvard College.
40 * All rights reserved.
43 #ifndef _BSD_OPENPROM_H_
44 #define _BSD_OPENPROM_H_
47 * This file defines the interface between the kernel and the Openboot PROM.
48 * N.B.: this has been tested only on interface versions 0 and 2 (we have
49 * never seen interface version 1).
53 * The v0 interface tells us what virtual memory to scan to avoid PMEG
54 * conflicts, but the v2 interface fails to do so, and we must `magically'
55 * know where the OPENPROM lives in virtual space.
57 #define OPENPROM_STARTVADDR 0xffd00000
58 #define OPENPROM_ENDVADDR 0xfff00000
60 #define OPENPROM_MAGIC 0x10010407
63 * Version 0 PROM vector device operations (collected here to emphasise that
64 * they are deprecated). Open and close are obvious. Read and write are
65 * segregated according to the device type (block, network, or character);
66 * this is unnecessary and was eliminated from the v2 device operations, but
67 * we are stuck with it.
69 * Seek is probably only useful on tape devices, since the only character
70 * devices are the serial ports.
72 * Note that a v0 device name is always exactly two characters ("sd", "le",
76 int (*v0_open
)(const char *);
78 int (*v0_rbdev
)(int, int, int, void *);
79 int (*v0_wbdev
)(int, int, int, void *);
80 int (*v0_wnet
)(int, int, void *);
81 int (*v0_rnet
)(int, int, void *);
82 int (*v0_rcdev
)(int, int, int, void *);
83 int (*v0_wcdev
)(int, int, int, void *);
84 int (*v0_seek
)(int, long, int);
88 * Version 2 device operations. Open takes a device `path' such as
89 * /sbus/le@0,c00000,0 or /sbus/esp@.../sd@0,0, which means it can open
90 * anything anywhere, without any magic translation.
92 * The memory allocator and map functions are included here even though
93 * they relate only indirectly to devices (e.g., mmap is good for mapping
94 * device memory, and drivers need to allocate space in which to record
99 * Convert an `instance handle' (acquired through v2_open()) to
100 * a `package handle', a.k.a. a `node'.
102 int (*v2_fd_phandle
)(int);
104 /* Memory allocation and release. */
105 void *(*v2_malloc
)(void *, u_int
);
106 void (*v2_free
)(void *, u_int
);
108 /* Device memory mapper. */
109 void * (*v2_mmap
)(void *, int, u_int
, u_int
);
110 void (*v2_munmap
)(void *, u_int
);
112 /* Device open, close, etc. */
113 int (*v2_open
)(const char *);
114 void (*v2_close
)(int);
115 int (*v2_read
)(int, void *, int);
116 int (*v2_write
)(int, const void *, int);
117 void (*v2_seek
)(int, int, int);
119 void (*v2_chain
)(void); /* ??? */
120 void (*v2_release
)(void); /* ??? */
124 * The v0 interface describes memory regions with these linked lists.
125 * (The !$&@#+ v2 interface reformats these as properties, so that we
126 * have to extract them into local temporary memory and reinterpret them.)
129 struct v0mlist
*next
;
135 * V0 gives us three memory lists: Total physical memory, VM reserved to
136 * the PROM, and available physical memory (which, presumably, is just the
137 * total minus any pages mapped in the PROM's VM region). We can find the
138 * reserved PMEGs by scanning the taken VM. Unfortunately, the V2 prom
139 * forgot to provide taken VM, and we are stuck with scanning ``magic''
143 struct v0mlist
**v0_phystot
; /* physical memory */
144 struct v0mlist
**v0_vmprom
; /* VM used by PROM */
145 struct v0mlist
**v0_physavail
; /* available physical memory */
149 * The version 0 PROM breaks up the string given to the boot command and
150 * leaves the decoded version behind.
153 char *ba_argv
[8]; /* argv format for boot string */
154 char ba_args
[100]; /* string space */
155 char ba_bootdev
[2]; /* e.g., "sd" for `b sd(...' */
156 int ba_ctlr
; /* controller # */
157 int ba_unit
; /* unit # */
158 int ba_part
; /* partition # */
159 char *ba_kernel
; /* kernel to boot, e.g., "vmunix" */
160 void *ba_spare0
; /* not decoded here XXX */
164 * The version 2 PROM interface uses the more general, if less convenient,
165 * approach of passing the boot strings unchanged. We also get open file
166 * numbers for stdin and stdout (keyboard and screen, or whatever), for use
167 * with the v2 device ops.
170 char **v2_bootpath
; /* V2: Path to boot device */
171 char **v2_bootargs
; /* V2: Boot args */
172 int *v2_fd0
; /* V2: Stdin descriptor */
173 int *v2_fd1
; /* V2: Stdout descriptor */
177 * The format used by the PROM to describe a physical address. These
178 * are typically found in a "reg" property.
180 struct openprom_addr
{
181 int oa_space
; /* address space (may be relative) */
182 u_int oa_base
; /* address within space */
183 u_int oa_size
; /* extent (number of bytes) */
187 * The format used by the PROM to describe an address space window. These
188 * are typically found in a "range" property.
190 struct openprom_range
{
191 int or_child_space
; /* address space of child */
192 u_int or_child_base
; /* offset in child's view of bus */
193 int or_parent_space
; /* address space of parent */
194 u_int or_parent_base
; /* offset in parent's view of bus */
195 u_int or_size
; /* extent (number of bytes) */
199 * The format used by the PROM to describe an interrupt. These are
200 * typically found in an "intr" property.
202 struct openprom_intr
{
203 int oi_pri
; /* interrupt priority */
204 int oi_vec
; /* interrupt vector */
208 * The following structure defines the primary PROM vector interface.
209 * The Boot PROM hands the kernel a pointer to this structure in %o0.
210 * There are numerous substructures defined below.
213 /* Version numbers. */
214 u_int pv_magic
; /* Magic number */
215 #define OBP_MAGIC 0x10010407
216 u_int pv_romvec_vers
; /* interface version (0, 2) */
217 u_int pv_plugin_vers
; /* ??? */
218 u_int pv_printrev
; /* PROM rev # (* 10, e.g 1.9 = 19) */
220 /* Version 0 memory descriptors (see below). */
221 struct v0mem pv_v0mem
; /* V0: Memory description lists. */
223 /* Node operations (see below). */
224 struct nodeops
*pv_nodeops
; /* node functions */
226 char **pv_bootstr
; /* Boot command, eg sd(0,0,0)vmunix */
228 struct v0devops pv_v0devops
; /* V0: device ops */
231 * PROMDEV_* cookies. I fear these may vanish in lieu of fd0/fd1
232 * (see below) in future PROMs, but for now they work fine.
234 char *pv_stdin
; /* stdin cookie */
235 char *pv_stdout
; /* stdout cookie */
236 #define PROMDEV_KBD 0 /* input from keyboard */
237 #define PROMDEV_SCREEN 0 /* output to screen */
238 #define PROMDEV_TTYA 1 /* in/out to ttya */
239 #define PROMDEV_TTYB 2 /* in/out to ttyb */
241 /* Blocking getchar/putchar. NOT REENTRANT! (grr) */
242 int (*pv_getchar
)(void);
243 void (*pv_putchar
)(int);
245 /* Non-blocking variants that return -1 on error. */
246 int (*pv_nbgetchar
)(void);
247 int (*pv_nbputchar
)(int);
249 /* Put counted string (can be very slow). */
250 void (*pv_putstr
)(const char *, int);
253 void (*pv_reboot
)(const char *) __attribute__((__noreturn__
));
254 void (*pv_printf
)(const char *, ...);
255 void (*pv_abort
)(void); /* L1-A abort */
256 int *pv_ticks
; /* Ticks since last reset */
257 __dead
void (*pv_halt
)(void); /* Halt! */
258 void (**pv_synchook
)(void); /* "sync" command hook */
261 * This eval's a FORTH string. Unfortunately, its interface
262 * changed between V0 and V2, which gave us much pain.
265 void (*v0_eval
)(int, const char *);
266 void (*v2_eval
)(const char *);
269 struct v0bootargs
**pv_v0bootargs
; /* V0: Boot args */
271 /* Extract Ethernet address from network device. */
272 u_int (*pv_enaddr
)(int, char *);
274 struct v2bootargs pv_v2bootargs
; /* V2: Boot args + std in/out */
275 struct v2devops pv_v2devops
; /* V2: device operations */
280 * The following is machine-dependent.
282 * The sun4c needs a PROM function to set a PMEG for another
283 * context, so that the kernel can map itself in all contexts.
284 * It is not possible simply to set the context register, because
285 * contexts 1 through N may have invalid translations for the
286 * current program counter. The hardware has a mode in which
287 * all memory references go to the PROM, so the PROM can do it
290 void (*pv_setctxt
)(int, void *, int);
293 * The following are V3 ROM functions to handle MP machines in the
294 * Sun4m series. They have undefined results when run on a uniprocessor!
296 int (*pv_v3cpustart
)(int, struct openprom_addr
*, int, void *);
297 int (*pv_v3cpustop
)(int);
298 int (*pv_v3cpuidle
)(int);
299 int (*pv_v3cpuresume
)(int);
303 * In addition to the global stuff defined in the PROM vectors above,
304 * the PROM has quite a collection of `nodes'. A node is described by
305 * an integer---these seem to be internal pointers, actually---and the
306 * nodes are arranged into an N-ary tree. Each node implements a fixed
307 * set of functions, as described below. The first two deal with the tree
308 * structure, allowing traversals in either breadth- or depth-first fashion.
309 * The rest deal with `properties'.
311 * A node property is simply a name/value pair. The names are C strings
312 * (NUL-terminated); the values are arbitrary byte strings (counted strings).
313 * Many values are really just C strings. Sometimes these are NUL-terminated,
314 * sometimes not, depending on the interface version; v0 seems to terminate
315 * and v2 not. Many others are simply integers stored as four bytes in
316 * machine order: you just get them and go. The third popular format is
317 * an `physical address', which is made up of one or more sets of three
318 * integers as defined above.
320 * N.B.: for the `next' functions, next(0) = first, and next(last) = 0.
321 * Whoever designed this part had good taste. On the other hand, these
322 * operation vectors are global, rather than per-node, yet the pointers
323 * are not in the openprom vectors but rather found by indirection from
324 * there. So the taste balances out.
331 int (*no_nextnode
)(int); /* next(node) */
332 int (*no_child
)(int); /* first child */
335 * Property functions. Proper use of getprop requires calling
336 * proplen first to make sure it fits. Kind of a pain, but no
337 * doubt more convenient for the PROM coder.
339 int (*no_proplen
)(int, const char *);
340 int (*no_getprop
)(int, const char *, void *);
341 int (*no_setprop
)(int, const char *, const void *, int);
342 char *(*no_nextprop
)(int, const char *);
346 * OBP Module mailbox messages for multi processor machines.
348 * 00..7F : power-on self test
349 * 80..8F : active in boot prom (at the "ok" prompt)
350 * 90..EF : idle in boot prom
351 * F0 : active in application
352 * F1..FA : reserved for future use
354 * FB : pv_v3cpustop(node) was called for this CPU,
355 * respond by calling pv_v3cpustop(0).
357 * FC : pv_v3cpuidle(node) was called for this CPU,
358 * respond by calling pv_v3cpuidle(0).
360 * FD : One processor hit a BREAKPOINT, call pv_v3cpuidle(0).
361 * [According to SunOS4 header; but what breakpoint?]
363 * FE : One processor got a WATCHDOG RESET, call pv_v3cpustop(0).
364 * [According to SunOS4 header; never seen this, although
365 * I've had plenty of watchdogs already]
367 * FF : This processor is not available.
370 #define OPENPROM_MBX_STOP 0xfb
371 #define OPENPROM_MBX_ABORT 0xfc
372 #define OPENPROM_MBX_BPT 0xfd
373 #define OPENPROM_MBX_WD 0xfe
375 #endif /* _BSD_OPENPROM_H_ */