xref: /OK3568_Linux_fs/kernel/arch/sparc/include/asm/oplib_32.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 #include <linux/spinlock.h>
14*4882a593Smuzhiyun #include <linux/compiler.h>
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun /* The master romvec pointer... */
17*4882a593Smuzhiyun extern struct linux_romvec *romvec;
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun /* Enumeration to describe the prom major version we have detected. */
20*4882a593Smuzhiyun enum prom_major_version {
21*4882a593Smuzhiyun 	PROM_V0,      /* Original sun4c V0 prom */
22*4882a593Smuzhiyun 	PROM_V2,      /* sun4c and early sun4m V2 prom */
23*4882a593Smuzhiyun 	PROM_V3,      /* sun4m and later, up to sun4d/sun4e machines V3 */
24*4882a593Smuzhiyun 	PROM_P1275,   /* IEEE compliant ISA based Sun PROM, only sun4u */
25*4882a593Smuzhiyun };
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun extern enum prom_major_version prom_vers;
28*4882a593Smuzhiyun /* Revision, and firmware revision. */
29*4882a593Smuzhiyun extern unsigned int prom_rev, prom_prev;
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun /* Root node of the prom device tree, this stays constant after
32*4882a593Smuzhiyun  * initialization is complete.
33*4882a593Smuzhiyun  */
34*4882a593Smuzhiyun extern phandle prom_root_node;
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun /* Pointer to prom structure containing the device tree traversal
37*4882a593Smuzhiyun  * and usage utility functions.  Only prom-lib should use these,
38*4882a593Smuzhiyun  * users use the interface defined by the library only!
39*4882a593Smuzhiyun  */
40*4882a593Smuzhiyun extern struct linux_nodeops *prom_nodeops;
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun /* The functions... */
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun /* You must call prom_init() before using any of the library services,
45*4882a593Smuzhiyun  * preferably as early as possible.  Pass it the romvec pointer.
46*4882a593Smuzhiyun  */
47*4882a593Smuzhiyun void prom_init(struct linux_romvec *rom_ptr);
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun /* Boot argument acquisition, returns the boot command line string. */
50*4882a593Smuzhiyun char *prom_getbootargs(void);
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun /* Miscellaneous routines, don't really fit in any category per se. */
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun /* Reboot the machine with the command line passed. */
55*4882a593Smuzhiyun void prom_reboot(char *boot_command);
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun /* Evaluate the forth string passed. */
58*4882a593Smuzhiyun void prom_feval(char *forth_string);
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun /* Enter the prom, with possibility of continuation with the 'go'
61*4882a593Smuzhiyun  * command in newer proms.
62*4882a593Smuzhiyun  */
63*4882a593Smuzhiyun void prom_cmdline(void);
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun /* Enter the prom, with no chance of continuation for the stand-alone
66*4882a593Smuzhiyun  * which calls this.
67*4882a593Smuzhiyun  */
68*4882a593Smuzhiyun void __noreturn prom_halt(void);
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun /* Set the PROM 'sync' callback function to the passed function pointer.
71*4882a593Smuzhiyun  * When the user gives the 'sync' command at the prom prompt while the
72*4882a593Smuzhiyun  * kernel is still active, the prom will call this routine.
73*4882a593Smuzhiyun  *
74*4882a593Smuzhiyun  * XXX The arguments are different on V0 vs. V2->higher proms, grrr! XXX
75*4882a593Smuzhiyun  */
76*4882a593Smuzhiyun typedef void (*sync_func_t)(void);
77*4882a593Smuzhiyun void prom_setsync(sync_func_t func_ptr);
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun /* Acquire the IDPROM of the root node in the prom device tree.  This
80*4882a593Smuzhiyun  * gets passed a buffer where you would like it stuffed.  The return value
81*4882a593Smuzhiyun  * is the format type of this idprom or 0xff on error.
82*4882a593Smuzhiyun  */
83*4882a593Smuzhiyun unsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size);
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun /* Get the prom major version. */
86*4882a593Smuzhiyun int prom_version(void);
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun /* Get the prom plugin revision. */
89*4882a593Smuzhiyun int prom_getrev(void);
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun /* Get the prom firmware revision. */
92*4882a593Smuzhiyun int prom_getprev(void);
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun /* Write a buffer of characters to the console. */
95*4882a593Smuzhiyun void prom_console_write_buf(const char *buf, int len);
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun /* Prom's internal routines, don't use in kernel/boot code. */
98*4882a593Smuzhiyun __printf(1, 2) void prom_printf(const char *fmt, ...);
99*4882a593Smuzhiyun void prom_write(const char *buf, unsigned int len);
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun /* Multiprocessor operations... */
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun /* Start the CPU with the given device tree node, context table, and context
104*4882a593Smuzhiyun  * at the passed program counter.
105*4882a593Smuzhiyun  */
106*4882a593Smuzhiyun int prom_startcpu(int cpunode, struct linux_prom_registers *context_table,
107*4882a593Smuzhiyun 		  int context, char *program_counter);
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun /* Initialize the memory lists based upon the prom version. */
110*4882a593Smuzhiyun void prom_meminit(void);
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun /* PROM device tree traversal functions... */
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun /* Get the child node of the given node, or zero if no child exists. */
115*4882a593Smuzhiyun phandle prom_getchild(phandle parent_node);
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun /* Get the next sibling node of the given node, or zero if no further
118*4882a593Smuzhiyun  * siblings exist.
119*4882a593Smuzhiyun  */
120*4882a593Smuzhiyun phandle prom_getsibling(phandle node);
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun /* Get the length, at the passed node, of the given property type.
123*4882a593Smuzhiyun  * Returns -1 on error (ie. no such property at this node).
124*4882a593Smuzhiyun  */
125*4882a593Smuzhiyun int prom_getproplen(phandle thisnode, const char *property);
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun /* Fetch the requested property using the given buffer.  Returns
128*4882a593Smuzhiyun  * the number of bytes the prom put into your buffer or -1 on error.
129*4882a593Smuzhiyun  */
130*4882a593Smuzhiyun int __must_check prom_getproperty(phandle thisnode, const char *property,
131*4882a593Smuzhiyun 				  char *prop_buffer, int propbuf_size);
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun /* Acquire an integer property. */
134*4882a593Smuzhiyun int prom_getint(phandle node, char *property);
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun /* Acquire an integer property, with a default value. */
137*4882a593Smuzhiyun int prom_getintdefault(phandle node, char *property, int defval);
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun /* Acquire a boolean property, 0=FALSE 1=TRUE. */
140*4882a593Smuzhiyun int prom_getbool(phandle node, char *prop);
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun /* Acquire a string property, null string on error. */
143*4882a593Smuzhiyun void prom_getstring(phandle node, char *prop, char *buf, int bufsize);
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun /* Search all siblings starting at the passed node for "name" matching
146*4882a593Smuzhiyun  * the given string.  Returns the node on success, zero on failure.
147*4882a593Smuzhiyun  */
148*4882a593Smuzhiyun phandle prom_searchsiblings(phandle node_start, char *name);
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun /* Returns the next property after the passed property for the given
151*4882a593Smuzhiyun  * node.  Returns null string on failure.
152*4882a593Smuzhiyun  */
153*4882a593Smuzhiyun char *prom_nextprop(phandle node, char *prev_property, char *buffer);
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun /* Returns phandle of the path specified */
156*4882a593Smuzhiyun phandle prom_finddevice(char *name);
157*4882a593Smuzhiyun 
158*4882a593Smuzhiyun /* Set the indicated property at the given node with the passed value.
159*4882a593Smuzhiyun  * Returns the number of bytes of your value that the prom took.
160*4882a593Smuzhiyun  */
161*4882a593Smuzhiyun int prom_setprop(phandle node, const char *prop_name, char *prop_value,
162*4882a593Smuzhiyun 		 int value_size);
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun phandle prom_inst2pkg(int);
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun /* Dorking with Bus ranges... */
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun /* Apply promlib probes OBIO ranges to registers. */
169*4882a593Smuzhiyun void prom_apply_obio_ranges(struct linux_prom_registers *obioregs, int nregs);
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun /* Apply ranges of any prom node (and optionally parent node as well) to registers. */
172*4882a593Smuzhiyun void prom_apply_generic_ranges(phandle node, phandle parent,
173*4882a593Smuzhiyun 			       struct linux_prom_registers *sbusregs, int nregs);
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun void prom_ranges_init(void);
176*4882a593Smuzhiyun 
177*4882a593Smuzhiyun /* CPU probing helpers.  */
178*4882a593Smuzhiyun int cpu_find_by_instance(int instance, phandle *prom_node, int *mid);
179*4882a593Smuzhiyun int cpu_find_by_mid(int mid, phandle *prom_node);
180*4882a593Smuzhiyun int cpu_get_hwmid(phandle prom_node);
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun extern spinlock_t prom_lock;
183*4882a593Smuzhiyun 
184*4882a593Smuzhiyun #endif /* !(__SPARC_OPLIB_H) */
185