1 /* oplib.h: Describes the interface and available routines in the
2 * Linux Prom library.
3 *
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5 */
6
7 #ifndef __SPARC_OPLIB_H
8 #define __SPARC_OPLIB_H
9
10 #include <asm/openprom.h>
11
12 /* The master romvec pointer... */
13 extern struct linux_romvec *romvec;
14
15 /* Enumeration to describe the prom major version we have detected. */
16 enum prom_major_version {
17 PROM_V0, /* Origional sun4c V0 prom */
18 PROM_V2, /* sun4c and early sun4m V2 prom */
19 PROM_V3, /* sun4m and later, up to sun4d/sun4e machines V3 */
20 PROM_P1275, /* IEEE compliant ISA based Sun PROM, only sun4u */
21 };
22
23 extern enum prom_major_version prom_vers;
24 /* Revision, and firmware revision. */
25 extern unsigned int prom_rev, prom_prev;
26
27 /* Root node of the prom device tree, this stays constant after
28 * initialization is complete.
29 */
30 extern int prom_root_node;
31
32 /* Pointer to prom structure containing the device tree traversal
33 * and usage utility functions. Only prom-lib should use these,
34 * users use the interface defined by the library only!
35 */
36 extern struct linux_nodeops *prom_nodeops;
37
38 /* The functions... */
39
40 /* You must call prom_init() before using any of the library services,
41 * preferably as early as possible. Pass it the romvec pointer.
42 */
43 extern int prom_init(struct linux_romvec *rom_ptr);
44
45 /* Boot argument acquisition, returns the boot command line string. */
46 extern char *prom_getbootargs(void);
47
48 /* Device utilities. */
49
50 /* Map and unmap devices in IO space at virtual addresses. Note that the
51 * virtual address you pass is a request and the prom may put your mappings
52 * somewhere else, so check your return value as that is where your new
53 * mappings really are!
54 *
55 * Another note, these are only available on V2 or higher proms!
56 */
57 extern char *prom_mapio(char *virt_hint, int io_space, unsigned int phys_addr, unsigned int num_bytes);
58 extern void prom_unmapio(char *virt_addr, unsigned int num_bytes);
59
60 /* Device operations. */
61
62 /* Open the device described by the passed string. Note, that the format
63 * of the string is different on V0 vs. V2->higher proms. The caller must
64 * know what he/she is doing! Returns the device descriptor, an int.
65 */
66 extern int prom_devopen(char *device_string);
67
68 /* Close a previously opened device described by the passed integer
69 * descriptor.
70 */
71 extern int prom_devclose(int device_handle);
72
73 /* Do a seek operation on the device described by the passed integer
74 * descriptor.
75 */
76 extern void prom_seek(int device_handle, unsigned int seek_hival,
77 unsigned int seek_lowval);
78
79 /* Machine memory configuration routine. */
80
81 /* This function returns a V0 format memory descriptor table, it has three
82 * entries. One for the total amount of physical ram on the machine, one
83 * for the amount of physical ram available, and one describing the virtual
84 * areas which are allocated by the prom. So, in a sense the physical
85 * available is a calculation of the total physical minus the physcial mapped
86 * by the prom with virtual mappings.
87 *
88 * These lists are returned pre-sorted, this should make your life easier
89 * since the prom itself is way too lazy to do such nice things.
90 */
91 extern struct linux_mem_v0 *prom_meminfo(void);
92
93 /* Miscellaneous routines, don't really fit in any category per se. */
94
95 /* Reboot the machine with the command line passed. */
96 extern void prom_reboot(char *boot_command);
97
98 /* Evaluate the forth string passed. */
99 extern void prom_feval(char *forth_string);
100
101 /* Enter the prom, with possibility of continuation with the 'go'
102 * command in newer proms.
103 */
104 extern void prom_halt(void);
105
106 /* Enter the prom, with no chance of continuation for the stand-alone
107 * which calls this.
108 */
109 extern void prom_die(void);
110
111 /* Set the PROM 'sync' callback function to the passed function pointer.
112 * When the user gives the 'sync' command at the prom prompt while the
113 * kernel is still active, the prom will call this routine.
114 *
115 * XXX The arguments are different on V0 vs. V2->higher proms, grrr! XXX
116 */
117 typedef void (*sync_func_t)(void);
118 extern void prom_setsync(sync_func_t func_ptr);
119
120 /* Acquire the IDPROM of the root node in the prom device tree. This
121 * gets passed a buffer where you would like it stuffed. The return value
122 * is the format type of this idprom or 0xff on error.
123 */
124 extern unsigned char prom_getidp(char *idp_buffer, int idpbuf_size);
125
126 /* Get the prom major version. */
127 extern int prom_version(void);
128
129 /* Get the prom plugin revision. */
130 extern int prom_getrev(void);
131
132 /* Get the prom firmware revision. */
133 extern int prom_getprev(void);
134
135 /* Character operations to/from the console.... */
136
137 /* Non-blocking get character from console. */
138 extern int prom_nbgetchar(void);
139
140 /* Non-blocking put character to console. */
141 extern int prom_nbputchar(char character);
142
143 /* Blocking get character from console. */
144 extern char prom_getchar(void);
145
146 /* Blocking put character to console. */
147 extern void prom_putchar(char character);
148
149 /* Prom's internal printf routine, don't use in kernel/boot code. */
150 void prom_printf(char *fmt, ...);
151
152 /* Multiprocessor operations... */
153
154 /* Start the CPU with the given device tree node, context table, and context
155 * at the passed program counter.
156 */
157 extern int prom_startcpu(int cpunode, struct linux_prom_registers *context_table,
158 int context, char *program_counter);
159
160 /* Stop the CPU with the passed device tree node. */
161 extern int prom_stopcpu(int cpunode);
162
163 /* Idle the CPU with the passed device tree node. */
164 extern int prom_idlecpu(int cpunode);
165
166 /* Re-Start the CPU with the passed device tree node. */
167 extern int prom_restartcpu(int cpunode);
168
169 /* PROM memory allocation facilities... */
170
171 /* Allocated at possibly the given virtual address a chunk of the
172 * indicated size.
173 */
174 extern char *prom_alloc(char *virt_hint, unsigned int size);
175
176 /* Free a previously allocated chunk. */
177 extern void prom_free(char *virt_addr, unsigned int size);
178
179 /* Sun4/sun4c specific memory-management startup hook. */
180
181 /* Map the passed segment in the given context at the passed
182 * virtual address.
183 */
184 extern void prom_putsegment(int context, unsigned long virt_addr,
185 int physical_segment);
186
187 /* PROM device tree traversal functions... */
188
189 /* Get the child node of the given node, or zero if no child exists. */
190 extern int prom_getchild(int parent_node);
191
192 /* Get the next sibling node of the given node, or zero if no further
193 * siblings exist.
194 */
195 extern int prom_getsibling(int node);
196
197 /* Get the length, at the passed node, of the given property type.
198 * Returns -1 on error (ie. no such property at this node).
199 */
200 extern int prom_getproplen(int thisnode, char *property);
201
202 /* Fetch the requested property using the given buffer. Returns
203 * the number of bytes the prom put into your buffer or -1 on error.
204 */
205 extern int prom_getproperty(int thisnode, char *property,
206 char *prop_buffer, int propbuf_size);
207
208 /* Acquire an integer property. */
209 extern int prom_getint(int node, char *property);
210
211 /* Acquire an integer property, with a default value. */
212 extern int prom_getintdefault(int node, char *property, int defval);
213
214 /* Acquire a boolean property, 0=FALSE 1=TRUE. */
215 extern int prom_getbool(int node, char *prop);
216
217 /* Acquire a string property, null string on error. */
218 extern void prom_getstring(int node, char *prop, char *buf, int bufsize);
219
220 /* Does the passed node have the given "name"? YES=1 NO=0 */
221 extern int prom_nodematch(int thisnode, char *name);
222
223 /* Search all siblings starting at the passed node for "name" matching
224 * the given string. Returns the node on success, zero on failure.
225 */
226 extern int prom_searchsiblings(int node_start, char *name);
227
228 /* Return the first property type, as a string, for the given node.
229 * Returns a null string on error.
230 */
231 extern char *prom_firstprop(int node);
232
233 /* Returns the next property after the passed property for the given
234 * node. Returns null string on failure.
235 */
236 extern char *prom_nextprop(int node, char *prev_property);
237
238 /* Set the indicated property at the given node with the passed value.
239 * Returns the number of bytes of your value that the prom took.
240 */
241 extern int prom_setprop(int node, char *prop_name, char *prop_value,
242 int value_size);
243
244 /* Dorking with Bus ranges... */
245
246 /* Adjust reg values with the passed ranges. */
247 extern void prom_adjust_regs(struct linux_prom_registers *regp, int nregs,
248 struct linux_prom_ranges *rangep, int nranges);
249
250 /* Adjust child ranges with the passed parent ranges. */
251 extern void prom_adjust_ranges(struct linux_prom_ranges *cranges, int ncranges,
252 struct linux_prom_ranges *pranges, int npranges);
253
254 /* Apply promlib probed OBIO ranges to registers. */
255 extern void prom_apply_obio_ranges(struct linux_prom_registers *obioregs, int nregs);
256
257 /* Apply promlib probed SBUS ranges to registers. */
258 extern void prom_apply_sbus_ranges(struct linux_prom_registers *sbusregs, int nregs);
259
260 #endif /* !(__SPARC_OPLIB_H) */