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 */
26 extern enum prom_major_version prom_vers;
27 /* Revision, and firmware revision. */
28 extern unsigned int prom_rev, prom_prev;
30 /* Root node of the prom device tree, this stays constant after
31 * initialization is complete.
33 extern phandle prom_root_node;
35 /* Pointer to prom structure containing the device tree traversal
36 * and usage utility functions. Only prom-lib should use these,
37 * users use the interface defined by the library only!
39 extern struct linux_nodeops *prom_nodeops;
41 /* The functions... */
43 /* You must call prom_init() before using any of the library services,
44 * preferably as early as possible. Pass it the romvec pointer.
46 extern void prom_init(struct linux_romvec *rom_ptr);
48 /* Boot argument acquisition, returns the boot command line string. */
49 extern char *prom_getbootargs(void);
51 /* Miscellaneous routines, don't really fit in any category per se. */
53 /* Reboot the machine with the command line passed. */
54 extern void prom_reboot(char *boot_command);
56 /* Evaluate the forth string passed. */
57 extern void prom_feval(char *forth_string);
59 /* Enter the prom, with possibility of continuation with the 'go'
60 * command in newer proms.
62 extern void prom_cmdline(void);
64 /* Enter the prom, with no chance of continuation for the stand-alone
67 extern void prom_halt(void) __attribute__ ((noreturn));
69 /* Set the PROM 'sync' callback function to the passed function pointer.
70 * When the user gives the 'sync' command at the prom prompt while the
71 * kernel is still active, the prom will call this routine.
73 * XXX The arguments are different on V0 vs. V2->higher proms, grrr! XXX
75 typedef void (*sync_func_t)(void);
76 extern void prom_setsync(sync_func_t func_ptr);
78 /* Acquire the IDPROM of the root node in the prom device tree. This
79 * gets passed a buffer where you would like it stuffed. The return value
80 * is the format type of this idprom or 0xff on error.
82 extern unsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size);
84 /* Get the prom major version. */
85 extern int prom_version(void);
87 /* Get the prom plugin revision. */
88 extern int prom_getrev(void);
90 /* Get the prom firmware revision. */
91 extern int prom_getprev(void);
93 /* Write a buffer of characters to the console. */
94 extern void prom_console_write_buf(const char *buf, int len);
96 /* Prom's internal routines, don't use in kernel/boot code. */
97 extern void prom_printf(const char *fmt, ...);
98 extern void prom_write(const char *buf, unsigned int len);
100 /* Multiprocessor operations... */
102 /* Start the CPU with the given device tree node, context table, and context
103 * at the passed program counter.
105 extern int prom_startcpu(int cpunode, struct linux_prom_registers *context_table,
106 int context, char *program_counter);
108 /* Stop the CPU with the passed device tree node. */
109 extern int prom_stopcpu(int cpunode);
111 /* Idle the CPU with the passed device tree node. */
112 extern int prom_idlecpu(int cpunode);
114 /* Re-Start the CPU with the passed device tree node. */
115 extern int prom_restartcpu(int cpunode);
117 /* PROM memory allocation facilities... */
119 /* Allocated at possibly the given virtual address a chunk of the
122 extern char *prom_alloc(char *virt_hint, unsigned int size);
124 /* Free a previously allocated chunk. */
125 extern void prom_free(char *virt_addr, unsigned int size);
127 /* Sun4/sun4c specific memory-management startup hook. */
129 /* Map the passed segment in the given context at the passed
132 extern void prom_putsegment(int context, unsigned long virt_addr,
133 int physical_segment);
136 /* PROM device tree traversal functions... */
138 /* Get the child node of the given node, or zero if no child exists. */
139 extern phandle prom_getchild(phandle parent_node);
141 /* Get the next sibling node of the given node, or zero if no further
144 extern phandle prom_getsibling(phandle node);
146 /* Get the length, at the passed node, of the given property type.
147 * Returns -1 on error (ie. no such property at this node).
149 extern int prom_getproplen(phandle thisnode, const char *property);
151 /* Fetch the requested property using the given buffer. Returns
152 * the number of bytes the prom put into your buffer or -1 on error.
154 extern int __must_check prom_getproperty(phandle thisnode, const char *property,
155 char *prop_buffer, int propbuf_size);
157 /* Acquire an integer property. */
158 extern int prom_getint(phandle node, char *property);
160 /* Acquire an integer property, with a default value. */
161 extern int prom_getintdefault(phandle node, char *property, int defval);
163 /* Acquire a boolean property, 0=FALSE 1=TRUE. */
164 extern int prom_getbool(phandle node, char *prop);
166 /* Acquire a string property, null string on error. */
167 extern void prom_getstring(phandle node, char *prop, char *buf, int bufsize);
169 /* Does the passed node have the given "name"? YES=1 NO=0 */
170 extern int prom_nodematch(phandle thisnode, char *name);
172 /* Search all siblings starting at the passed node for "name" matching
173 * the given string. Returns the node on success, zero on failure.
175 extern phandle prom_searchsiblings(phandle node_start, char *name);
177 /* Return the first property type, as a string, for the given node.
178 * Returns a null string on error.
180 extern char *prom_firstprop(phandle node, char *buffer);
182 /* Returns the next property after the passed property for the given
183 * node. Returns null string on failure.
185 extern char *prom_nextprop(phandle node, char *prev_property, char *buffer);
187 /* Returns phandle of the path specified */
188 extern phandle prom_finddevice(char *name);
190 /* Returns 1 if the specified node has given property. */
191 extern int prom_node_has_property(phandle node, char *property);
193 /* Set the indicated property at the given node with the passed value.
194 * Returns the number of bytes of your value that the prom took.
196 extern int prom_setprop(phandle node, const char *prop_name, char *prop_value,
199 extern phandle prom_inst2pkg(int);
201 /* Dorking with Bus ranges... */
203 /* Apply promlib probes OBIO ranges to registers. */
204 extern void prom_apply_obio_ranges(struct linux_prom_registers *obioregs, int nregs);
206 /* Apply ranges of any prom node (and optionally parent node as well) to registers. */
207 extern void prom_apply_generic_ranges(phandle node, phandle parent,
208 struct linux_prom_registers *sbusregs, int nregs);
210 /* CPU probing helpers. */
211 int cpu_find_by_instance(int instance, phandle *prom_node, int *mid);
212 int cpu_find_by_mid(int mid, phandle *prom_node);
213 int cpu_get_hwmid(phandle prom_node);
215 extern spinlock_t prom_lock;
217 #endif /* !(__SPARC_OPLIB_H) */