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