oplib.h 9.6 KB

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