oplib.h 11 KB

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