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