bsd_openprom.h 12 KB

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