1 #ifndef __SPARC_OPENPROM_H 2 #define __SPARC_OPENPROM_H 3 4 /* openprom.h: Prom structures and defines for access to the OPENBOOT 5 * prom routines and data areas. 6 * 7 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 8 */ 9 10 /* In the v0 interface of the openboot prom we could traverse a nice 11 * little list structure to figure out where in vm-space the prom had 12 * mapped itself and how much space it was taking up. In the v2 prom 13 * interface we have to rely on 'magic' values. :-( Most of the machines 14 * I have checked on have the prom mapped here all the time though. 15 */ 16 17 #define KADB_DEBUGGER_BEGVM 0xffc00000 /* Where kern debugger is in virt-mem */ 18 19 #define LINUX_OPPROM_BEGVM 0xffd00000 20 #define LINUX_OPPROM_ENDVM 0xfff00000 21 22 #define LINUX_OPPROM_MAGIC 0x10010407 23 24 #ifndef __ASSEMBLY__ 25 /* The device functions structure for the v0 prom. Nice and neat, open, 26 * close, read & write divvied up between net + block + char devices. We 27 * also have a seek routine only usable for block devices. The divide 28 * and conquer strategy of this struct becomes unnecessary for v2. 29 * 30 * V0 device names are limited to two characters, 'sd' for scsi-disk, 31 * 'le' for local-ethernet, etc. Note that it is technically possible 32 * to boot a kernel off of a tape drive and use the tape as the root 33 * partition! In order to do this you have to have 'magic' formatted 34 * tapes from Sun supposedly :-) 35 */ 36 37 struct linux_dev_v0_funcs { 38 int (*v0_devopen)(char *device_str); 39 int (*v0_devclose)(int dev_desc); 40 int (*v0_rdblkdev)(int dev_desc, int num_blks, int blk_st, char* buf); 41 int (*v0_wrblkdev)(int dev_desc, int num_blks, int blk_st, char* buf); 42 int (*v0_wrnetdev)(int dev_desc, int num_bytes, char* buf); 43 int (*v0_rdnetdev)(int dev_desc, int num_bytes, char* buf); 44 int (*v0_rdchardev)(int dev_desc, int num_bytes, int dummy, char* buf); 45 int (*v0_wrchardev)(int dev_desc, int num_bytes, int dummy, char* buf); 46 int (*v0_seekdev)(int dev_desc, long logical_offst, int from); 47 }; 48 49 /* The OpenBoot Prom device operations for version-2 interfaces are both 50 * good and bad. They now allow you to address ANY device whatsoever 51 * that is in the machine via these funny "device paths". They look like 52 * this: 53 * 54 * "/sbus/esp@0,0xf004002c/sd@3,1" 55 * 56 * You can basically reference any device on the machine this way, and 57 * you pass this string to the v2 dev_ops. Producing these strings all 58 * the time can be a pain in the rear after a while. Why v2 has memory 59 * allocations in here are beyond me. Perhaps they figure that if you 60 * are going to use only the prom's device drivers then your memory 61 * management is either non-existent or pretty sad. :-) 62 */ 63 64 struct linux_dev_v2_funcs { 65 int (*v2_inst2pkg)(int d); /* Convert ihandle to phandle */ 66 67 /* "dumb" prom memory management routines, probably 68 * only safe to use for mapping device address spaces... 69 */ 70 71 char* (*v2_dumb_mem_alloc)(char* va, unsigned sz); 72 void (*v2_dumb_mem_free)(char* va, unsigned sz); 73 74 /* "dumb" mmap() munmap(), copy on write? what's that? */ 75 char* (*v2_dumb_mmap)(char* virta, int which_io, unsigned paddr, unsigned sz); 76 void (*v2_dumb_munmap)(char* virta, unsigned size); 77 78 /* Basic Operations, self-explanatory */ 79 int (*v2_dev_open)(char *devpath); 80 void (*v2_dev_close)(int d); 81 int (*v2_dev_read)(int d, char* buf, int nbytes); 82 int (*v2_dev_write)(int d, char* buf, int nbytes); 83 void (*v2_dev_seek)(int d, int hi, int lo); 84 85 /* Never issued (multistage load support) */ 86 void (*v2_wheee2)(void); 87 void (*v2_wheee3)(void); 88 }; 89 90 /* Just like the device ops, they slightly screwed up the mem-list 91 * from v0 to v2. Probably easier on the prom-writer dude, sucks for 92 * us though. See above comment about prom-vm mapped address space 93 * magic numbers. :-( 94 */ 95 96 struct linux_mlist_v0 { 97 struct linux_mlist_v0 *theres_more; 98 char* start_adr; 99 unsigned num_bytes; 100 }; 101 102 /* The linux_mlist_v0's are pointed to by this structure. One list 103 * per description. This means one list for total physical memory, 104 * one for prom's address mapping, and one for physical mem left after 105 * the kernel is loaded. 106 */ 107 108 struct linux_mem_v0 { 109 struct linux_mlist_v0 **v0_totphys; /* all of physical */ 110 struct linux_mlist_v0 **v0_prommap; /* addresses map'd by prom */ 111 struct linux_mlist_v0 **v0_available; /* what phys. is left over */ 112 }; 113 114 /* Arguments sent to the kernel from the boot prompt. */ 115 116 struct linux_arguments_v0 { 117 char *argv[8]; /* argv format for boot string */ 118 char args[100]; /* string space */ 119 char boot_dev[2]; /* e.g., "sd" for `b sd(...' */ 120 int boot_dev_ctrl; /* controller # */ 121 int boot_dev_unit; /* unit # */ 122 int dev_partition; /* partition # */ 123 char *kernel_file_name; /* kernel to boot, e.g., "vmunix" */ 124 void *aieee1; /* give me some time :> */ 125 }; 126 127 /* Prom version-2 gives us the raw strings for boot arguments and 128 * boot device path. We also get the stdin and stdout file pseudo 129 * descriptors for use with the mungy v2 device functions. 130 */ 131 struct linux_bootargs_v2 { 132 char **bootpath; /* V2: Path to boot device */ 133 char **bootargs; /* V2: Boot args */ 134 int *fd_stdin; /* V2: Stdin descriptor */ 135 int *fd_stdout; /* V2: Stdout descriptor */ 136 }; 137 138 /* This is the actual Prom Vector from which everything else is accessed 139 * via struct and function pointers, etc. The prom when it loads us into 140 * memory plops a pointer to this master structure in register %o0 before 141 * it jumps to the kernel start address. I will update this soon to cover 142 * the v3 semantics (cpu_start, cpu_stop and other SMP fun things). :-) 143 */ 144 145 struct linux_romvec { 146 /* Version numbers. */ 147 unsigned int pv_magic_cookie; /* Magic Mushroom... */ 148 unsigned int pv_romvers; /* iface vers (0, 2, or 3) */ 149 unsigned int pv_plugin_revision; /* revision relative to above vers */ 150 unsigned int pv_printrev; /* print revision */ 151 152 /* Version 0 memory descriptors (see below). */ 153 struct linux_mem_v0 pv_v0mem; /* V0: Memory description lists. */ 154 155 /* Node operations (see below). */ 156 struct linux_nodeops *pv_nodeops; /* node functions, gets device data */ 157 158 char **pv_bootstr; /* Boot command, eg sd(0,0,0)vmunix */ 159 160 struct linux_dev_v0_funcs pv_v0devops; /* V0: device ops */ 161 162 /* 163 * PROMDEV_* cookies. I fear these may vanish in lieu of fd0/fd1 164 * (see below) in future PROMs, but for now they work fine. 165 */ 166 char *pv_stdin; /* stdin cookie */ 167 char *pv_stdout; /* stdout cookie */ 168 #define PROMDEV_KBD 0 /* input from keyboard */ 169 #define PROMDEV_SCREEN 0 /* output to screen */ 170 #define PROMDEV_TTYA 1 /* in/out to ttya */ 171 #define PROMDEV_TTYB 2 /* in/out to ttyb */ 172 173 /* Blocking getchar/putchar. NOT REENTRANT! (grr) */ 174 int (*pv_getchar)(void); 175 void (*pv_putchar)(int ch); 176 177 /* Non-blocking variants that return -1 on error. */ 178 int (*pv_nbgetchar)(void); 179 int (*pv_nbputchar)(int ch); 180 181 /* Put counted string (can be very slow). */ 182 void (*pv_putstr)(char *str, int len); 183 184 /* Miscellany. */ 185 void (*pv_reboot)(char *bootstr); 186 void (*pv_printf)(const char *fmt, ...); 187 void (*pv_abort)(void); /* BREAK key abort */ 188 int *pv_ticks; /* milliseconds since last reset */ 189 void (*pv_halt)(void); /* End the show */ 190 void (**pv_synchook)(void); /* "sync" ptr to function */ 191 192 /* 193 * This eval's a FORTH string. Unfortunately, its interface 194 * changed between V0 and V2, which gave us much pain. 195 */ 196 union { 197 void (*v0_eval)(int len, char *str); 198 void (*v2_eval)(char *str); 199 } pv_fortheval; 200 201 struct linux_arguments_v0 **pv_v0bootargs; /* V0: Boot args */ 202 203 /* Extract Ethernet address from network device. */ 204 unsigned int (*pv_enaddr)(int d, char *enaddr); 205 206 struct linux_bootargs_v2 pv_v2bootargs; /* V2: Boot args+std-in/out */ 207 struct linux_dev_v2_funcs pv_v2devops; /* V2: device operations */ 208 209 int filler[15]; 210 211 /* 212 * The following is machine-dependent. 213 * 214 * The sun4c needs a PROM function to set a PMEG for another 215 * context, so that the kernel can map itself in all contexts. 216 * It is not possible simply to set the context register, because 217 * contexts 1 through N may have invalid translations for the 218 * current program counter. The hardware has a mode in which 219 * all memory references go to the PROM, so the PROM can do it 220 * easily. 221 */ 222 void (*pv_setctxt)(int ctxt, char* va, int pmeg); 223 224 /* Prom version 3 Multiprocessor routines. This stuff is crazy. 225 * No joke. Calling these when there is only one cpu probably 226 * crashes the machine, have to test this. :-) 227 */ 228 229 /* v3_cpustart() will start the cpu 'whichcpu' in mmu-context 230 * 'thiscontext' executing at address 'prog_counter' 231 */ 232 233 int (*v3_cpustart)(unsigned int whichcpu, int ctxtbl_ptr, 234 int thiscontext, char* prog_counter); 235 236 /* v3_cpustop() will cause cpu 'whichcpu' to stop executing 237 * until a resume cpu call is made. 238 */ 239 240 int (*v3_cpustop)(unsigned int whichcpu); 241 242 /* v3_cpuidle() will idle cpu 'whichcpu' until a stop or 243 * resume cpu call is made. 244 */ 245 246 int (*v3_cpuidle)(unsigned int whichcpu); 247 248 /* v3_cpuresume() will resume processor 'whichcpu' executing 249 * starting with whatever 'pc' and 'npc' were left at the 250 * last 'idle' or 'stop' call. 251 */ 252 253 int (*v3_cpuresume)(unsigned int whichcpu); 254 255 }; 256 257 /* 258 * In addition to the global stuff defined in the PROM vectors above, 259 * the PROM has quite a collection of `nodes'. A node is described by 260 * an integer---these seem to be internal pointers, actually---and the 261 * nodes are arranged into an N-ary tree. Each node implements a fixed 262 * set of functions, as described below. The first two deal with the tree 263 * structure, allowing traversals in either breadth- or depth-first fashion. 264 * The rest deal with `properties'. 265 * 266 * A node property is simply a name/value pair. The names are C strings 267 * (NUL-terminated); the values are arbitrary byte strings (counted strings). 268 * Many values are really just C strings. Sometimes these are NUL-terminated, 269 * sometimes not, depending on the the interface version; v0 seems to 270 * terminate and v2 not. Many others are simply integers stored as four 271 * bytes in machine order: you just get them and go. The third popular 272 * format is an `address', which is made up of one or more sets of three 273 * integers as defined below. 274 * 275 * One uses these functions to traverse the device tree to see what devices 276 * this machine has attached to it. 277 * 278 * N.B.: for the `next' functions, next(0) = first, and next(last) = 0. 279 * Whoever designed this part had good taste. On the other hand, these 280 * operation vectors are global, rather than per-node, yet the pointers 281 * are not in the openprom vectors but rather found by indirection from 282 * there. So the taste balances out. 283 */ 284 285 struct linux_nodeops { 286 /* 287 * Tree traversal. 288 */ 289 int (*no_nextnode)(int node); /* next(node) */ 290 int (*no_child)(int node); /* first child */ 291 292 /* 293 * Property functions. Proper use of getprop requires calling 294 * proplen first to make sure it fits. Kind of a pain, but no 295 * doubt more convenient for the PROM coder. 296 */ 297 int (*no_proplen)(int node, char* name); 298 int (*no_getprop)(int node, char* name, char* val); 299 int (*no_setprop)(int node, char* name, char* val, int len); 300 char* (*no_nextprop)(int node, char* name); 301 }; 302 303 /* More fun PROM structures for device probing. */ 304 #define PROMREG_MAX 16 305 #define PROMVADDR_MAX 16 306 #define PROMINTR_MAX 15 307 308 struct linux_prom_registers { 309 int which_io; /* is this in OBIO space? */ 310 char *phys_addr; /* The physical address of this register */ 311 int reg_size; /* How many bytes does this register take up? */ 312 }; 313 314 struct linux_prom_irqs { 315 int pri; /* IRQ priority */ 316 int vector; /* This is foobar, what does it do? */ 317 }; 318 319 /* Element of the "ranges" vector */ 320 struct linux_prom_ranges { 321 unsigned int ot_child_space; 322 unsigned int ot_child_base; /* Bus feels this */ 323 unsigned int ot_parent_space; 324 unsigned int ot_parent_base; /* CPU looks from here */ 325 unsigned int or_size; 326 }; 327 328 #endif /* !(__ASSEMBLY__) */ 329 330 #endif /* !(__SPARC_OPENPROM_H) */