oplib.h 11 KB

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