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