oplib.h 9.5 KB

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