oplib.h 9.5 KB

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