oplib.h 12 KB

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