xref: /OK3568_Linux_fs/kernel/arch/sparc/include/asm/oplib_64.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /* oplib.h:  Describes the interface and available routines in the
3*4882a593Smuzhiyun  *           Linux Prom library.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 1995, 2007 David S. Miller (davem@davemloft.net)
6*4882a593Smuzhiyun  * Copyright (C) 1996 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #ifndef __SPARC64_OPLIB_H
10*4882a593Smuzhiyun #define __SPARC64_OPLIB_H
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <asm/openprom.h>
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun /* OBP version string. */
15*4882a593Smuzhiyun extern char prom_version[];
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun /* Root node of the prom device tree, this stays constant after
18*4882a593Smuzhiyun  * initialization is complete.
19*4882a593Smuzhiyun  */
20*4882a593Smuzhiyun extern phandle prom_root_node;
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun /* PROM stdout */
23*4882a593Smuzhiyun extern int prom_stdout;
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun /* /chosen node of the prom device tree, this stays constant after
26*4882a593Smuzhiyun  * initialization is complete.
27*4882a593Smuzhiyun  */
28*4882a593Smuzhiyun extern phandle prom_chosen_node;
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun /* Helper values and strings in arch/sparc64/kernel/head.S */
31*4882a593Smuzhiyun extern const char prom_peer_name[];
32*4882a593Smuzhiyun extern const char prom_compatible_name[];
33*4882a593Smuzhiyun extern const char prom_root_compatible[];
34*4882a593Smuzhiyun extern const char prom_cpu_compatible[];
35*4882a593Smuzhiyun extern const char prom_finddev_name[];
36*4882a593Smuzhiyun extern const char prom_chosen_path[];
37*4882a593Smuzhiyun extern const char prom_cpu_path[];
38*4882a593Smuzhiyun extern const char prom_getprop_name[];
39*4882a593Smuzhiyun extern const char prom_mmu_name[];
40*4882a593Smuzhiyun extern const char prom_callmethod_name[];
41*4882a593Smuzhiyun extern const char prom_translate_name[];
42*4882a593Smuzhiyun extern const char prom_map_name[];
43*4882a593Smuzhiyun extern const char prom_unmap_name[];
44*4882a593Smuzhiyun extern int prom_mmu_ihandle_cache;
45*4882a593Smuzhiyun extern unsigned int prom_boot_mapped_pc;
46*4882a593Smuzhiyun extern unsigned int prom_boot_mapping_mode;
47*4882a593Smuzhiyun extern unsigned long prom_boot_mapping_phys_high, prom_boot_mapping_phys_low;
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun struct linux_mlist_p1275 {
50*4882a593Smuzhiyun 	struct linux_mlist_p1275 *theres_more;
51*4882a593Smuzhiyun 	unsigned long start_adr;
52*4882a593Smuzhiyun 	unsigned long num_bytes;
53*4882a593Smuzhiyun };
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun struct linux_mem_p1275 {
56*4882a593Smuzhiyun 	struct linux_mlist_p1275 **p1275_totphys;
57*4882a593Smuzhiyun 	struct linux_mlist_p1275 **p1275_prommap;
58*4882a593Smuzhiyun 	struct linux_mlist_p1275 **p1275_available; /* What we can use */
59*4882a593Smuzhiyun };
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun /* The functions... */
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun /* You must call prom_init() before using any of the library services,
64*4882a593Smuzhiyun  * preferably as early as possible.  Pass it the romvec pointer.
65*4882a593Smuzhiyun  */
66*4882a593Smuzhiyun void prom_init(void *cif_handler);
67*4882a593Smuzhiyun void prom_init_report(void);
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun /* Boot argument acquisition, returns the boot command line string. */
70*4882a593Smuzhiyun char *prom_getbootargs(void);
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun /* Miscellaneous routines, don't really fit in any category per se. */
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun /* Reboot the machine with the command line passed. */
75*4882a593Smuzhiyun void prom_reboot(const char *boot_command);
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun /* Evaluate the forth string passed. */
78*4882a593Smuzhiyun void prom_feval(const char *forth_string);
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun /* Enter the prom, with possibility of continuation with the 'go'
81*4882a593Smuzhiyun  * command in newer proms.
82*4882a593Smuzhiyun  */
83*4882a593Smuzhiyun void prom_cmdline(void);
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun /* Enter the prom, with no chance of continuation for the stand-alone
86*4882a593Smuzhiyun  * which calls this.
87*4882a593Smuzhiyun  */
88*4882a593Smuzhiyun void prom_halt(void) __attribute__ ((noreturn));
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun /* Halt and power-off the machine. */
91*4882a593Smuzhiyun void prom_halt_power_off(void) __attribute__ ((noreturn));
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun /* Acquire the IDPROM of the root node in the prom device tree.  This
94*4882a593Smuzhiyun  * gets passed a buffer where you would like it stuffed.  The return value
95*4882a593Smuzhiyun  * is the format type of this idprom or 0xff on error.
96*4882a593Smuzhiyun  */
97*4882a593Smuzhiyun unsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size);
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun /* Write a buffer of characters to the console. */
100*4882a593Smuzhiyun void prom_console_write_buf(const char *buf, int len);
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun /* Prom's internal routines, don't use in kernel/boot code. */
103*4882a593Smuzhiyun __printf(1, 2) void prom_printf(const char *fmt, ...);
104*4882a593Smuzhiyun void prom_write(const char *buf, unsigned int len);
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun /* Multiprocessor operations... */
107*4882a593Smuzhiyun #ifdef CONFIG_SMP
108*4882a593Smuzhiyun /* Start the CPU with the given device tree node at the passed program
109*4882a593Smuzhiyun  * counter with the given arg passed in via register %o0.
110*4882a593Smuzhiyun  */
111*4882a593Smuzhiyun void prom_startcpu(int cpunode, unsigned long pc, unsigned long arg);
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun /* Start the CPU with the given cpu ID at the passed program
114*4882a593Smuzhiyun  * counter with the given arg passed in via register %o0.
115*4882a593Smuzhiyun  */
116*4882a593Smuzhiyun void prom_startcpu_cpuid(int cpuid, unsigned long pc, unsigned long arg);
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun /* Stop the CPU with the given cpu ID.  */
119*4882a593Smuzhiyun void prom_stopcpu_cpuid(int cpuid);
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun /* Stop the current CPU. */
122*4882a593Smuzhiyun void prom_stopself(void);
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun /* Idle the current CPU. */
125*4882a593Smuzhiyun void prom_idleself(void);
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun /* Resume the CPU with the passed device tree node. */
128*4882a593Smuzhiyun void prom_resumecpu(int cpunode);
129*4882a593Smuzhiyun #endif
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun /* Power management interfaces. */
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun /* Put the current CPU to sleep. */
134*4882a593Smuzhiyun void prom_sleepself(void);
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun /* Put the entire system to sleep. */
137*4882a593Smuzhiyun int prom_sleepsystem(void);
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun /* Initiate a wakeup event. */
140*4882a593Smuzhiyun int prom_wakeupsystem(void);
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun /* MMU and memory related OBP interfaces. */
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun /* Get unique string identifying SIMM at given physical address. */
145*4882a593Smuzhiyun int prom_getunumber(int syndrome_code,
146*4882a593Smuzhiyun 		    unsigned long phys_addr,
147*4882a593Smuzhiyun 		    char *buf, int buflen);
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun /* Retain physical memory to the caller across soft resets. */
150*4882a593Smuzhiyun int prom_retain(const char *name, unsigned long size,
151*4882a593Smuzhiyun 		unsigned long align, unsigned long *paddr);
152*4882a593Smuzhiyun 
153*4882a593Smuzhiyun /* Load explicit I/D TLB entries into the calling processor. */
154*4882a593Smuzhiyun long prom_itlb_load(unsigned long index,
155*4882a593Smuzhiyun 		    unsigned long tte_data,
156*4882a593Smuzhiyun 		    unsigned long vaddr);
157*4882a593Smuzhiyun 
158*4882a593Smuzhiyun long prom_dtlb_load(unsigned long index,
159*4882a593Smuzhiyun 		    unsigned long tte_data,
160*4882a593Smuzhiyun 		    unsigned long vaddr);
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun /* Map/Unmap client program address ranges.  First the format of
163*4882a593Smuzhiyun  * the mapping mode argument.
164*4882a593Smuzhiyun  */
165*4882a593Smuzhiyun #define PROM_MAP_WRITE	0x0001 /* Writable */
166*4882a593Smuzhiyun #define PROM_MAP_READ	0x0002 /* Readable - sw */
167*4882a593Smuzhiyun #define PROM_MAP_EXEC	0x0004 /* Executable - sw */
168*4882a593Smuzhiyun #define PROM_MAP_LOCKED	0x0010 /* Locked, use i/dtlb load calls for this instead */
169*4882a593Smuzhiyun #define PROM_MAP_CACHED	0x0020 /* Cacheable in both L1 and L2 caches */
170*4882a593Smuzhiyun #define PROM_MAP_SE	0x0040 /* Side-Effects */
171*4882a593Smuzhiyun #define PROM_MAP_GLOB	0x0080 /* Global */
172*4882a593Smuzhiyun #define PROM_MAP_IE	0x0100 /* Invert-Endianness */
173*4882a593Smuzhiyun #define PROM_MAP_DEFAULT (PROM_MAP_WRITE | PROM_MAP_READ | PROM_MAP_EXEC | PROM_MAP_CACHED)
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun int prom_map(int mode, unsigned long size,
176*4882a593Smuzhiyun 	     unsigned long vaddr, unsigned long paddr);
177*4882a593Smuzhiyun void prom_unmap(unsigned long size, unsigned long vaddr);
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun 
180*4882a593Smuzhiyun /* PROM device tree traversal functions... */
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun /* Get the child node of the given node, or zero if no child exists. */
183*4882a593Smuzhiyun phandle prom_getchild(phandle parent_node);
184*4882a593Smuzhiyun 
185*4882a593Smuzhiyun /* Get the next sibling node of the given node, or zero if no further
186*4882a593Smuzhiyun  * siblings exist.
187*4882a593Smuzhiyun  */
188*4882a593Smuzhiyun phandle prom_getsibling(phandle node);
189*4882a593Smuzhiyun 
190*4882a593Smuzhiyun /* Get the length, at the passed node, of the given property type.
191*4882a593Smuzhiyun  * Returns -1 on error (ie. no such property at this node).
192*4882a593Smuzhiyun  */
193*4882a593Smuzhiyun int prom_getproplen(phandle thisnode, const char *property);
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun /* Fetch the requested property using the given buffer.  Returns
196*4882a593Smuzhiyun  * the number of bytes the prom put into your buffer or -1 on error.
197*4882a593Smuzhiyun  */
198*4882a593Smuzhiyun int prom_getproperty(phandle thisnode, const char *property,
199*4882a593Smuzhiyun 		     char *prop_buffer, int propbuf_size);
200*4882a593Smuzhiyun 
201*4882a593Smuzhiyun /* Acquire an integer property. */
202*4882a593Smuzhiyun int prom_getint(phandle node, const char *property);
203*4882a593Smuzhiyun 
204*4882a593Smuzhiyun /* Acquire an integer property, with a default value. */
205*4882a593Smuzhiyun int prom_getintdefault(phandle node, const char *property, int defval);
206*4882a593Smuzhiyun 
207*4882a593Smuzhiyun /* Acquire a boolean property, 0=FALSE 1=TRUE. */
208*4882a593Smuzhiyun int prom_getbool(phandle node, const char *prop);
209*4882a593Smuzhiyun 
210*4882a593Smuzhiyun /* Acquire a string property, null string on error. */
211*4882a593Smuzhiyun void prom_getstring(phandle node, const char *prop, char *buf,
212*4882a593Smuzhiyun 		    int bufsize);
213*4882a593Smuzhiyun 
214*4882a593Smuzhiyun /* Does the passed node have the given "name"? YES=1 NO=0 */
215*4882a593Smuzhiyun int prom_nodematch(phandle thisnode, const char *name);
216*4882a593Smuzhiyun 
217*4882a593Smuzhiyun /* Search all siblings starting at the passed node for "name" matching
218*4882a593Smuzhiyun  * the given string.  Returns the node on success, zero on failure.
219*4882a593Smuzhiyun  */
220*4882a593Smuzhiyun phandle prom_searchsiblings(phandle node_start, const char *name);
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun /* Return the first property type, as a string, for the given node.
223*4882a593Smuzhiyun  * Returns a null string on error. Buffer should be at least 32B long.
224*4882a593Smuzhiyun  */
225*4882a593Smuzhiyun char *prom_firstprop(phandle node, char *buffer);
226*4882a593Smuzhiyun 
227*4882a593Smuzhiyun /* Returns the next property after the passed property for the given
228*4882a593Smuzhiyun  * node.  Returns null string on failure. Buffer should be at least 32B long.
229*4882a593Smuzhiyun  */
230*4882a593Smuzhiyun char *prom_nextprop(phandle node, const char *prev_property, char *buf);
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun /* Returns 1 if the specified node has given property. */
233*4882a593Smuzhiyun int prom_node_has_property(phandle node, const char *property);
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun /* Returns phandle of the path specified */
236*4882a593Smuzhiyun phandle prom_finddevice(const char *name);
237*4882a593Smuzhiyun 
238*4882a593Smuzhiyun /* Set the indicated property at the given node with the passed value.
239*4882a593Smuzhiyun  * Returns the number of bytes of your value that the prom took.
240*4882a593Smuzhiyun  */
241*4882a593Smuzhiyun int prom_setprop(phandle node, const char *prop_name, char *prop_value,
242*4882a593Smuzhiyun 		 int value_size);
243*4882a593Smuzhiyun 
244*4882a593Smuzhiyun phandle prom_inst2pkg(int);
245*4882a593Smuzhiyun void prom_sun4v_guest_soft_state(void);
246*4882a593Smuzhiyun 
247*4882a593Smuzhiyun int prom_ihandle2path(int handle, char *buffer, int bufsize);
248*4882a593Smuzhiyun 
249*4882a593Smuzhiyun /* Client interface level routines. */
250*4882a593Smuzhiyun void p1275_cmd_direct(unsigned long *);
251*4882a593Smuzhiyun 
252*4882a593Smuzhiyun #endif /* !(__SPARC64_OPLIB_H) */
253