oplib.h 11 KB

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