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