oplib.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /* $Id: oplib.h,v 1.14 2001/12/19 00:29:51 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. * Copyright (C) 1996 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  7. */
  8. #ifndef __SPARC64_OPLIB_H
  9. #define __SPARC64_OPLIB_H
  10. #include <linux/config.h>
  11. #include <asm/openprom.h>
  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. PROM_AP1000, /* actually no prom at all */
  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. /* PROM stdin and stdout */
  28. extern int prom_stdin, prom_stdout;
  29. /* /chosen node of the prom device tree, this stays constant after
  30. * initialization is complete.
  31. */
  32. extern int prom_chosen_node;
  33. struct linux_mlist_p1275 {
  34. struct linux_mlist_p1275 *theres_more;
  35. unsigned long start_adr;
  36. unsigned long num_bytes;
  37. };
  38. struct linux_mem_p1275 {
  39. struct linux_mlist_p1275 **p1275_totphys;
  40. struct linux_mlist_p1275 **p1275_prommap;
  41. struct linux_mlist_p1275 **p1275_available; /* What we can use */
  42. };
  43. /* The functions... */
  44. /* You must call prom_init() before using any of the library services,
  45. * preferably as early as possible. Pass it the romvec pointer.
  46. */
  47. extern void prom_init(void *cif_handler, void *cif_stack);
  48. /* Boot argument acquisition, returns the boot command line string. */
  49. extern char *prom_getbootargs(void);
  50. /* Device utilities. */
  51. /* Device operations. */
  52. /* Open the device described by the passed string. Note, that the format
  53. * of the string is different on V0 vs. V2->higher proms. The caller must
  54. * know what he/she is doing! Returns the device descriptor, an int.
  55. */
  56. extern int prom_devopen(char *device_string);
  57. /* Close a previously opened device described by the passed integer
  58. * descriptor.
  59. */
  60. extern int prom_devclose(int device_handle);
  61. /* Do a seek operation on the device described by the passed integer
  62. * descriptor.
  63. */
  64. extern void prom_seek(int device_handle, unsigned int seek_hival,
  65. unsigned int seek_lowval);
  66. /* Machine memory configuration routine. */
  67. /* This function returns a V0 format memory descriptor table, it has three
  68. * entries. One for the total amount of physical ram on the machine, one
  69. * for the amount of physical ram available, and one describing the virtual
  70. * areas which are allocated by the prom. So, in a sense the physical
  71. * available is a calculation of the total physical minus the physical mapped
  72. * by the prom with virtual mappings.
  73. *
  74. * These lists are returned pre-sorted, this should make your life easier
  75. * since the prom itself is way too lazy to do such nice things.
  76. */
  77. extern struct linux_mem_p1275 *prom_meminfo(void);
  78. /* Miscellaneous routines, don't really fit in any category per se. */
  79. /* Reboot the machine with the command line passed. */
  80. extern void prom_reboot(char *boot_command);
  81. /* Evaluate the forth string passed. */
  82. extern void prom_feval(char *forth_string);
  83. /* Enter the prom, with possibility of continuation with the 'go'
  84. * command in newer proms.
  85. */
  86. extern void prom_cmdline(void);
  87. /* Enter the prom, with no chance of continuation for the stand-alone
  88. * which calls this.
  89. */
  90. extern void prom_halt(void) __attribute__ ((noreturn));
  91. /* Halt and power-off the machine. */
  92. extern void prom_halt_power_off(void) __attribute__ ((noreturn));
  93. /* Set the PROM 'sync' callback function to the passed function pointer.
  94. * When the user gives the 'sync' command at the prom prompt while the
  95. * kernel is still active, the prom will call this routine.
  96. *
  97. */
  98. typedef int (*callback_func_t)(long *cmd);
  99. extern void prom_setcallback(callback_func_t func_ptr);
  100. /* Acquire the IDPROM of the root node in the prom device tree. This
  101. * gets passed a buffer where you would like it stuffed. The return value
  102. * is the format type of this idprom or 0xff on error.
  103. */
  104. extern unsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size);
  105. /* Get the prom major version. */
  106. extern int prom_version(void);
  107. /* Get the prom plugin revision. */
  108. extern int prom_getrev(void);
  109. /* Get the prom firmware revision. */
  110. extern int prom_getprev(void);
  111. /* Character operations to/from the console.... */
  112. /* Non-blocking get character from console. */
  113. extern int prom_nbgetchar(void);
  114. /* Non-blocking put character to console. */
  115. extern int prom_nbputchar(char character);
  116. /* Blocking get character from console. */
  117. extern char prom_getchar(void);
  118. /* Blocking put character to console. */
  119. extern void prom_putchar(char character);
  120. /* Prom's internal routines, don't use in kernel/boot code. */
  121. extern void prom_printf(char *fmt, ...);
  122. extern void prom_write(const char *buf, unsigned int len);
  123. /* Query for input device type */
  124. enum prom_input_device {
  125. PROMDEV_IKBD, /* input from keyboard */
  126. PROMDEV_ITTYA, /* input from ttya */
  127. PROMDEV_ITTYB, /* input from ttyb */
  128. PROMDEV_I_UNK,
  129. };
  130. extern enum prom_input_device prom_query_input_device(void);
  131. /* Query for output device type */
  132. enum prom_output_device {
  133. PROMDEV_OSCREEN, /* to screen */
  134. PROMDEV_OTTYA, /* to ttya */
  135. PROMDEV_OTTYB, /* to ttyb */
  136. PROMDEV_O_UNK,
  137. };
  138. extern enum prom_output_device prom_query_output_device(void);
  139. /* Multiprocessor operations... */
  140. #ifdef CONFIG_SMP
  141. /* Start the CPU with the given device tree node, context table, and context
  142. * at the passed program counter.
  143. */
  144. extern void prom_startcpu(int cpunode, unsigned long pc, unsigned long o0);
  145. /* Stop the current CPU. */
  146. extern void prom_stopself(void);
  147. /* Idle the current CPU. */
  148. extern void prom_idleself(void);
  149. /* Resume the CPU with the passed device tree node. */
  150. extern void prom_resumecpu(int cpunode);
  151. #endif
  152. /* Power management interfaces. */
  153. /* Put the current CPU to sleep. */
  154. extern void prom_sleepself(void);
  155. /* Put the entire system to sleep. */
  156. extern int prom_sleepsystem(void);
  157. /* Initiate a wakeup event. */
  158. extern int prom_wakeupsystem(void);
  159. /* MMU and memory related OBP interfaces. */
  160. /* Get unique string identifying SIMM at given physical address. */
  161. extern int prom_getunumber(int syndrome_code,
  162. unsigned long phys_addr,
  163. char *buf, int buflen);
  164. /* Retain physical memory to the caller across soft resets. */
  165. extern unsigned long prom_retain(char *name,
  166. unsigned long pa_low, unsigned long pa_high,
  167. long size, long align);
  168. /* Load explicit I/D TLB entries into the calling processor. */
  169. extern long prom_itlb_load(unsigned long index,
  170. unsigned long tte_data,
  171. unsigned long vaddr);
  172. extern long prom_dtlb_load(unsigned long index,
  173. unsigned long tte_data,
  174. unsigned long vaddr);
  175. /* Map/Unmap client program address ranges. First the format of
  176. * the mapping mode argument.
  177. */
  178. #define PROM_MAP_WRITE 0x0001 /* Writable */
  179. #define PROM_MAP_READ 0x0002 /* Readable - sw */
  180. #define PROM_MAP_EXEC 0x0004 /* Executable - sw */
  181. #define PROM_MAP_LOCKED 0x0010 /* Locked, use i/dtlb load calls for this instead */
  182. #define PROM_MAP_CACHED 0x0020 /* Cacheable in both L1 and L2 caches */
  183. #define PROM_MAP_SE 0x0040 /* Side-Effects */
  184. #define PROM_MAP_GLOB 0x0080 /* Global */
  185. #define PROM_MAP_IE 0x0100 /* Invert-Endianness */
  186. #define PROM_MAP_DEFAULT (PROM_MAP_WRITE | PROM_MAP_READ | PROM_MAP_EXEC | PROM_MAP_CACHED)
  187. extern int prom_map(int mode, unsigned long size,
  188. unsigned long vaddr, unsigned long paddr);
  189. extern void prom_unmap(unsigned long size, unsigned long vaddr);
  190. /* PROM device tree traversal functions... */
  191. #ifdef PROMLIB_INTERNAL
  192. /* Internal version of prom_getchild. */
  193. extern int __prom_getchild(int parent_node);
  194. /* Internal version of prom_getsibling. */
  195. extern int __prom_getsibling(int node);
  196. #endif
  197. /* Get the child node of the given node, or zero if no child exists. */
  198. extern int prom_getchild(int parent_node);
  199. /* Get the next sibling node of the given node, or zero if no further
  200. * siblings exist.
  201. */
  202. extern int prom_getsibling(int node);
  203. /* Get the length, at the passed node, of the given property type.
  204. * Returns -1 on error (ie. no such property at this node).
  205. */
  206. extern int prom_getproplen(int thisnode, char *property);
  207. /* Fetch the requested property using the given buffer. Returns
  208. * the number of bytes the prom put into your buffer or -1 on error.
  209. */
  210. extern int prom_getproperty(int thisnode, char *property,
  211. char *prop_buffer, int propbuf_size);
  212. /* Acquire an integer property. */
  213. extern int prom_getint(int node, char *property);
  214. /* Acquire an integer property, with a default value. */
  215. extern int prom_getintdefault(int node, char *property, int defval);
  216. /* Acquire a boolean property, 0=FALSE 1=TRUE. */
  217. extern int prom_getbool(int node, char *prop);
  218. /* Acquire a string property, null string on error. */
  219. extern void prom_getstring(int node, char *prop, char *buf, int bufsize);
  220. /* Does the passed node have the given "name"? YES=1 NO=0 */
  221. extern int prom_nodematch(int thisnode, char *name);
  222. /* Puts in buffer a prom name in the form name@x,y or name (x for which_io
  223. * and y for first regs phys address
  224. */
  225. extern int prom_getname(int node, char *buf, int buflen);
  226. /* Search all siblings starting at the passed node for "name" matching
  227. * the given string. Returns the node on success, zero on failure.
  228. */
  229. extern int prom_searchsiblings(int node_start, char *name);
  230. /* Return the first property type, as a string, for the given node.
  231. * Returns a null string on error. Buffer should be at least 32B long.
  232. */
  233. extern char *prom_firstprop(int node, char *buffer);
  234. /* Returns the next property after the passed property for the given
  235. * node. Returns null string on failure. Buffer should be at least 32B long.
  236. */
  237. extern char *prom_nextprop(int node, char *prev_property, char *buffer);
  238. /* Returns 1 if the specified node has given property. */
  239. extern int prom_node_has_property(int node, char *property);
  240. /* Returns phandle of the path specified */
  241. extern int prom_finddevice(char *name);
  242. /* Set the indicated property at the given node with the passed value.
  243. * Returns the number of bytes of your value that the prom took.
  244. */
  245. extern int prom_setprop(int node, char *prop_name, char *prop_value,
  246. int value_size);
  247. extern int prom_pathtoinode(char *path);
  248. extern int prom_inst2pkg(int);
  249. /* CPU probing helpers. */
  250. int cpu_find_by_instance(int instance, int *prom_node, int *mid);
  251. int cpu_find_by_mid(int mid, int *prom_node);
  252. /* Client interface level routines. */
  253. extern void prom_set_trap_table(unsigned long tba);
  254. extern long p1275_cmd (char *, long, ...);
  255. #if 0
  256. #define P1275_SIZE(x) ((((long)((x) / 32)) << 32) | (x))
  257. #else
  258. #define P1275_SIZE(x) x
  259. #endif
  260. /* We support at most 16 input and 1 output argument */
  261. #define P1275_ARG_NUMBER 0
  262. #define P1275_ARG_IN_STRING 1
  263. #define P1275_ARG_OUT_BUF 2
  264. #define P1275_ARG_OUT_32B 3
  265. #define P1275_ARG_IN_FUNCTION 4
  266. #define P1275_ARG_IN_BUF 5
  267. #define P1275_ARG_IN_64B 6
  268. #define P1275_IN(x) ((x) & 0xf)
  269. #define P1275_OUT(x) (((x) << 4) & 0xf0)
  270. #define P1275_INOUT(i,o) (P1275_IN(i)|P1275_OUT(o))
  271. #define P1275_ARG(n,x) ((x) << ((n)*3 + 8))
  272. #endif /* !(__SPARC64_OPLIB_H) */