2 * oplib.h: Describes the interface and available routines in the
5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
8 #ifndef __SPARC_OPLIB_H
9 #define __SPARC_OPLIB_H
11 #include <asm/openprom.h>
12 #include <linux/spinlock.h>
13 #include <linux/compiler.h>
15 /* The master romvec pointer... */
16 extern struct linux_romvec *romvec;
18 /* Enumeration to describe the prom major version we have detected. */
19 enum prom_major_version {
20 PROM_V0, /* Original sun4c V0 prom */
21 PROM_V2, /* sun4c and early sun4m V2 prom */
22 PROM_V3, /* sun4m and later, up to sun4d/sun4e machines V3 */
23 PROM_P1275, /* IEEE compliant ISA based Sun PROM, only sun4u */
24 PROM_AP1000, /* actually no prom at all */
25 PROM_SUN4, /* Old sun4 proms are totally different, but we'll shoehorn it to make it fit */
28 extern enum prom_major_version prom_vers;
29 /* Revision, and firmware revision. */
30 extern unsigned int prom_rev, prom_prev;
32 /* Root node of the prom device tree, this stays constant after
33 * initialization is complete.
35 extern int prom_root_node;
37 /* Pointer to prom structure containing the device tree traversal
38 * and usage utility functions. Only prom-lib should use these,
39 * users use the interface defined by the library only!
41 extern struct linux_nodeops *prom_nodeops;
43 /* The functions... */
45 /* You must call prom_init() before using any of the library services,
46 * preferably as early as possible. Pass it the romvec pointer.
48 extern void prom_init(struct linux_romvec *rom_ptr);
50 /* Boot argument acquisition, returns the boot command line string. */
51 extern char *prom_getbootargs(void);
53 /* Device utilities. */
55 /* Map and unmap devices in IO space at virtual addresses. Note that the
56 * virtual address you pass is a request and the prom may put your mappings
57 * somewhere else, so check your return value as that is where your new
58 * mappings really are!
60 * Another note, these are only available on V2 or higher proms!
62 extern char *prom_mapio(char *virt_hint, int io_space, unsigned int phys_addr, unsigned int num_bytes);
63 extern void prom_unmapio(char *virt_addr, unsigned int num_bytes);
65 /* Device operations. */
67 /* Open the device described by the passed string. Note, that the format
68 * of the string is different on V0 vs. V2->higher proms. The caller must
69 * know what he/she is doing! Returns the device descriptor, an int.
71 extern int prom_devopen(char *device_string);
73 /* Close a previously opened device described by the passed integer
76 extern int prom_devclose(int device_handle);
78 /* Do a seek operation on the device described by the passed integer
81 extern void prom_seek(int device_handle, unsigned int seek_hival,
82 unsigned int seek_lowval);
84 /* Miscellaneous routines, don't really fit in any category per se. */
86 /* Reboot the machine with the command line passed. */
87 extern void prom_reboot(char *boot_command);
89 /* Evaluate the forth string passed. */
90 extern void prom_feval(char *forth_string);
92 /* Enter the prom, with possibility of continuation with the 'go'
93 * command in newer proms.
95 extern void prom_cmdline(void);
97 /* Enter the prom, with no chance of continuation for the stand-alone
100 extern void prom_halt(void) __attribute__ ((noreturn));
102 /* Set the PROM 'sync' callback function to the passed function pointer.
103 * When the user gives the 'sync' command at the prom prompt while the
104 * kernel is still active, the prom will call this routine.
106 * XXX The arguments are different on V0 vs. V2->higher proms, grrr! XXX
108 typedef void (*sync_func_t)(void);
109 extern void prom_setsync(sync_func_t func_ptr);
111 /* Acquire the IDPROM of the root node in the prom device tree. This
112 * gets passed a buffer where you would like it stuffed. The return value
113 * is the format type of this idprom or 0xff on error.
115 extern unsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size);
117 /* Get the prom major version. */
118 extern int prom_version(void);
120 /* Get the prom plugin revision. */
121 extern int prom_getrev(void);
123 /* Get the prom firmware revision. */
124 extern int prom_getprev(void);
126 /* Character operations to/from the console.... */
128 /* Non-blocking get character from console. */
129 extern int prom_nbgetchar(void);
131 /* Non-blocking put character to console. */
132 extern int prom_nbputchar(char character);
134 /* Blocking get character from console. */
135 extern char prom_getchar(void);
137 /* Blocking put character to console. */
138 extern void prom_putchar(char character);
140 /* Prom's internal routines, don't use in kernel/boot code. */
141 extern void prom_printf(char *fmt, ...);
142 extern void prom_write(const char *buf, unsigned int len);
144 /* Multiprocessor operations... */
146 /* Start the CPU with the given device tree node, context table, and context
147 * at the passed program counter.
149 extern int prom_startcpu(int cpunode, struct linux_prom_registers *context_table,
150 int context, char *program_counter);
152 /* Stop the CPU with the passed device tree node. */
153 extern int prom_stopcpu(int cpunode);
155 /* Idle the CPU with the passed device tree node. */
156 extern int prom_idlecpu(int cpunode);
158 /* Re-Start the CPU with the passed device tree node. */
159 extern int prom_restartcpu(int cpunode);
161 /* PROM memory allocation facilities... */
163 /* Allocated at possibly the given virtual address a chunk of the
166 extern char *prom_alloc(char *virt_hint, unsigned int size);
168 /* Free a previously allocated chunk. */
169 extern void prom_free(char *virt_addr, unsigned int size);
171 /* Sun4/sun4c specific memory-management startup hook. */
173 /* Map the passed segment in the given context at the passed
176 extern void prom_putsegment(int context, unsigned long virt_addr,
177 int physical_segment);
180 /* PROM device tree traversal functions... */
182 #ifdef PROMLIB_INTERNAL
184 /* Internal version of prom_getchild. */
185 extern int __prom_getchild(int parent_node);
187 /* Internal version of prom_getsibling. */
188 extern int __prom_getsibling(int node);
193 /* Get the child node of the given node, or zero if no child exists. */
194 extern int prom_getchild(int parent_node);
196 /* Get the next sibling node of the given node, or zero if no further
199 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).
204 extern int prom_getproplen(int thisnode, 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.
209 extern int __must_check prom_getproperty(int thisnode, char *property,
210 char *prop_buffer, int propbuf_size);
212 /* Acquire an integer property. */
213 extern int prom_getint(int node, char *property);
215 /* Acquire an integer property, with a default value. */
216 extern int prom_getintdefault(int node, char *property, int defval);
218 /* Acquire a boolean property, 0=FALSE 1=TRUE. */
219 extern int prom_getbool(int node, char *prop);
221 /* Acquire a string property, null string on error. */
222 extern void prom_getstring(int node, char *prop, char *buf, int bufsize);
224 /* Does the passed node have the given "name"? YES=1 NO=0 */
225 extern int prom_nodematch(int thisnode, char *name);
227 /* Search all siblings starting at the passed node for "name" matching
228 * the given string. Returns the node on success, zero on failure.
230 extern int prom_searchsiblings(int node_start, char *name);
232 /* Return the first property type, as a string, for the given node.
233 * Returns a null string on error.
235 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.
240 extern char *prom_nextprop(int node, char *prev_property, char *buffer);
242 /* Returns phandle of the path specified */
243 extern int prom_finddevice(char *name);
245 /* Returns 1 if the specified node has given property. */
246 extern int prom_node_has_property(int node, char *property);
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.
251 extern int prom_setprop(int node, char *prop_name, char *prop_value,
254 extern int prom_pathtoinode(char *path);
255 extern int prom_inst2pkg(int);
257 /* Dorking with Bus ranges... */
259 /* Apply promlib probes OBIO ranges to registers. */
260 extern void prom_apply_obio_ranges(struct linux_prom_registers *obioregs, int nregs);
262 /* Apply ranges of any prom node (and optionally parent node as well) to registers. */
263 extern void prom_apply_generic_ranges(int node, int parent,
264 struct linux_prom_registers *sbusregs, int nregs);
266 /* CPU probing helpers. */
267 int cpu_find_by_instance(int instance, int *prom_node, int *mid);
268 int cpu_find_by_mid(int mid, int *prom_node);
269 int cpu_get_hwmid(int prom_node);
271 extern spinlock_t prom_lock;
273 #endif /* !(__SPARC_OPLIB_H) */