oplib.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /* $Id: oplib.h,v 1.23 2001/12/21 00:54:31 davem Exp $
  2. * oplib.h: Describes the interface and available routines in the
  3. * Linux Prom library.
  4. *
  5. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  6. */
  7. #ifndef __SPARC_OPLIB_H
  8. #define __SPARC_OPLIB_H
  9. #include <asm/openprom.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/compiler.h>
  12. /* The master romvec pointer... */
  13. extern struct linux_romvec *romvec;
  14. /* Enumeration to describe the prom major version we have detected. */
  15. enum prom_major_version {
  16. PROM_V0, /* Original sun4c V0 prom */
  17. PROM_V2, /* sun4c and early sun4m V2 prom */
  18. PROM_V3, /* sun4m and later, up to sun4d/sun4e machines V3 */
  19. PROM_P1275, /* IEEE compliant ISA based Sun PROM, only sun4u */
  20. PROM_AP1000, /* actually no prom at all */
  21. PROM_SUN4, /* Old sun4 proms are totally different, but we'll shoehorn it to make it fit */
  22. };
  23. extern enum prom_major_version prom_vers;
  24. /* Revision, and firmware revision. */
  25. extern unsigned int prom_rev, prom_prev;
  26. /* Root node of the prom device tree, this stays constant after
  27. * initialization is complete.
  28. */
  29. extern int prom_root_node;
  30. /* PROM stdin and stdout */
  31. extern int prom_stdin, prom_stdout;
  32. /* Pointer to prom structure containing the device tree traversal
  33. * and usage utility functions. Only prom-lib should use these,
  34. * users use the interface defined by the library only!
  35. */
  36. extern struct linux_nodeops *prom_nodeops;
  37. /* The functions... */
  38. /* You must call prom_init() before using any of the library services,
  39. * preferably as early as possible. Pass it the romvec pointer.
  40. */
  41. extern void prom_init(struct linux_romvec *rom_ptr);
  42. /* Boot argument acquisition, returns the boot command line string. */
  43. extern char *prom_getbootargs(void);
  44. /* Device utilities. */
  45. /* Map and unmap devices in IO space at virtual addresses. Note that the
  46. * virtual address you pass is a request and the prom may put your mappings
  47. * somewhere else, so check your return value as that is where your new
  48. * mappings really are!
  49. *
  50. * Another note, these are only available on V2 or higher proms!
  51. */
  52. extern char *prom_mapio(char *virt_hint, int io_space, unsigned int phys_addr, unsigned int num_bytes);
  53. extern void prom_unmapio(char *virt_addr, unsigned int num_bytes);
  54. /* Device operations. */
  55. /* Open the device described by the passed string. Note, that the format
  56. * of the string is different on V0 vs. V2->higher proms. The caller must
  57. * know what he/she is doing! Returns the device descriptor, an int.
  58. */
  59. extern int prom_devopen(char *device_string);
  60. /* Close a previously opened device described by the passed integer
  61. * descriptor.
  62. */
  63. extern int prom_devclose(int device_handle);
  64. /* Do a seek operation on the device described by the passed integer
  65. * descriptor.
  66. */
  67. extern void prom_seek(int device_handle, unsigned int seek_hival,
  68. unsigned int seek_lowval);
  69. /* Machine memory configuration routine. */
  70. /* This function returns a V0 format memory descriptor table, it has three
  71. * entries. One for the total amount of physical ram on the machine, one
  72. * for the amount of physical ram available, and one describing the virtual
  73. * areas which are allocated by the prom. So, in a sense the physical
  74. * available is a calculation of the total physical minus the physical mapped
  75. * by the prom with virtual mappings.
  76. *
  77. * These lists are returned pre-sorted, this should make your life easier
  78. * since the prom itself is way too lazy to do such nice things.
  79. */
  80. extern struct linux_mem_v0 *prom_meminfo(void);
  81. /* Miscellaneous routines, don't really fit in any category per se. */
  82. /* Reboot the machine with the command line passed. */
  83. extern void prom_reboot(char *boot_command);
  84. /* Evaluate the forth string passed. */
  85. extern void prom_feval(char *forth_string);
  86. /* Enter the prom, with possibility of continuation with the 'go'
  87. * command in newer proms.
  88. */
  89. extern void prom_cmdline(void);
  90. /* Enter the prom, with no chance of continuation for the stand-alone
  91. * which calls this.
  92. */
  93. extern void prom_halt(void) __attribute__ ((noreturn));
  94. /* Set the PROM 'sync' callback function to the passed function pointer.
  95. * When the user gives the 'sync' command at the prom prompt while the
  96. * kernel is still active, the prom will call this routine.
  97. *
  98. * XXX The arguments are different on V0 vs. V2->higher proms, grrr! XXX
  99. */
  100. typedef void (*sync_func_t)(void);
  101. extern void prom_setsync(sync_func_t func_ptr);
  102. /* Acquire the IDPROM of the root node in the prom device tree. This
  103. * gets passed a buffer where you would like it stuffed. The return value
  104. * is the format type of this idprom or 0xff on error.
  105. */
  106. extern unsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size);
  107. /* Get the prom major version. */
  108. extern int prom_version(void);
  109. /* Get the prom plugin revision. */
  110. extern int prom_getrev(void);
  111. /* Get the prom firmware revision. */
  112. extern int prom_getprev(void);
  113. /* Character operations to/from the console.... */
  114. /* Non-blocking get character from console. */
  115. extern int prom_nbgetchar(void);
  116. /* Non-blocking put character to console. */
  117. extern int prom_nbputchar(char character);
  118. /* Blocking get character from console. */
  119. extern char prom_getchar(void);
  120. /* Blocking put character to console. */
  121. extern void prom_putchar(char character);
  122. /* Prom's internal routines, don't use in kernel/boot code. */
  123. extern void prom_printf(char *fmt, ...);
  124. extern void prom_write(const char *buf, unsigned int len);
  125. /* Query for input device type */
  126. enum prom_input_device {
  127. PROMDEV_IKBD, /* input from keyboard */
  128. PROMDEV_ITTYA, /* input from ttya */
  129. PROMDEV_ITTYB, /* input from ttyb */
  130. PROMDEV_IRSC, /* input from rsc */
  131. PROMDEV_IVCONS, /* input from virtual-console */
  132. PROMDEV_I_UNK,
  133. };
  134. extern enum prom_input_device prom_query_input_device(void);
  135. /* Query for output device type */
  136. enum prom_output_device {
  137. PROMDEV_OSCREEN, /* to screen */
  138. PROMDEV_OTTYA, /* to ttya */
  139. PROMDEV_OTTYB, /* to ttyb */
  140. PROMDEV_ORSC, /* to rsc */
  141. PROMDEV_OVCONS, /* to virtual-console */
  142. PROMDEV_O_UNK,
  143. };
  144. extern enum prom_output_device prom_query_output_device(void);
  145. /* Multiprocessor operations... */
  146. /* Start the CPU with the given device tree node, context table, and context
  147. * at the passed program counter.
  148. */
  149. extern int prom_startcpu(int cpunode, struct linux_prom_registers *context_table,
  150. int context, char *program_counter);
  151. /* Stop the CPU with the passed device tree node. */
  152. extern int prom_stopcpu(int cpunode);
  153. /* Idle the CPU with the passed device tree node. */
  154. extern int prom_idlecpu(int cpunode);
  155. /* Re-Start the CPU with the passed device tree node. */
  156. extern int prom_restartcpu(int cpunode);
  157. /* PROM memory allocation facilities... */
  158. /* Allocated at possibly the given virtual address a chunk of the
  159. * indicated size.
  160. */
  161. extern char *prom_alloc(char *virt_hint, unsigned int size);
  162. /* Free a previously allocated chunk. */
  163. extern void prom_free(char *virt_addr, unsigned int size);
  164. /* Sun4/sun4c specific memory-management startup hook. */
  165. /* Map the passed segment in the given context at the passed
  166. * virtual address.
  167. */
  168. extern void prom_putsegment(int context, unsigned long virt_addr,
  169. int physical_segment);
  170. /* PROM device tree traversal functions... */
  171. #ifdef PROMLIB_INTERNAL
  172. /* Internal version of prom_getchild. */
  173. extern int __prom_getchild(int parent_node);
  174. /* Internal version of prom_getsibling. */
  175. extern int __prom_getsibling(int node);
  176. #endif
  177. /* Get the child node of the given node, or zero if no child exists. */
  178. extern int prom_getchild(int parent_node);
  179. /* Get the next sibling node of the given node, or zero if no further
  180. * siblings exist.
  181. */
  182. extern int prom_getsibling(int node);
  183. /* Get the length, at the passed node, of the given property type.
  184. * Returns -1 on error (ie. no such property at this node).
  185. */
  186. extern int prom_getproplen(int thisnode, char *property);
  187. /* Fetch the requested property using the given buffer. Returns
  188. * the number of bytes the prom put into your buffer or -1 on error.
  189. */
  190. extern int __must_check prom_getproperty(int thisnode, char *property,
  191. char *prop_buffer, int propbuf_size);
  192. /* Acquire an integer property. */
  193. extern int prom_getint(int node, char *property);
  194. /* Acquire an integer property, with a default value. */
  195. extern int prom_getintdefault(int node, char *property, int defval);
  196. /* Acquire a boolean property, 0=FALSE 1=TRUE. */
  197. extern int prom_getbool(int node, char *prop);
  198. /* Acquire a string property, null string on error. */
  199. extern void prom_getstring(int node, char *prop, char *buf, int bufsize);
  200. /* Does the passed node have the given "name"? YES=1 NO=0 */
  201. extern int prom_nodematch(int thisnode, char *name);
  202. /* Search all siblings starting at the passed node for "name" matching
  203. * the given string. Returns the node on success, zero on failure.
  204. */
  205. extern int prom_searchsiblings(int node_start, char *name);
  206. /* Return the first property type, as a string, for the given node.
  207. * Returns a null string on error.
  208. */
  209. extern char *prom_firstprop(int node, char *buffer);
  210. /* Returns the next property after the passed property for the given
  211. * node. Returns null string on failure.
  212. */
  213. extern char *prom_nextprop(int node, char *prev_property, char *buffer);
  214. /* Returns phandle of the path specified */
  215. extern int prom_finddevice(char *name);
  216. /* Returns 1 if the specified node has given property. */
  217. extern int prom_node_has_property(int node, char *property);
  218. /* Set the indicated property at the given node with the passed value.
  219. * Returns the number of bytes of your value that the prom took.
  220. */
  221. extern int prom_setprop(int node, char *prop_name, char *prop_value,
  222. int value_size);
  223. extern int prom_pathtoinode(char *path);
  224. extern int prom_inst2pkg(int);
  225. /* Dorking with Bus ranges... */
  226. /* Apply promlib probes OBIO ranges to registers. */
  227. extern void prom_apply_obio_ranges(struct linux_prom_registers *obioregs, int nregs);
  228. /* Apply ranges of any prom node (and optionally parent node as well) to registers. */
  229. extern void prom_apply_generic_ranges(int node, int parent,
  230. struct linux_prom_registers *sbusregs, int nregs);
  231. /* CPU probing helpers. */
  232. int cpu_find_by_instance(int instance, int *prom_node, int *mid);
  233. int cpu_find_by_mid(int mid, int *prom_node);
  234. int cpu_get_hwmid(int prom_node);
  235. extern spinlock_t prom_lock;
  236. #endif /* !(__SPARC_OPLIB_H) */