blob: 6a0da3b1695c0c913f484bf88d90bf7378c9594a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: oplib.h,v 1.14 2001/12/19 00:29:51 davem Exp $
2 * oplib.h: Describes the interface and available routines in the
3 * Linux Prom library.
4 *
5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
6 * Copyright (C) 1996 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
7 */
8
9#ifndef __SPARC64_OPLIB_H
10#define __SPARC64_OPLIB_H
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <asm/openprom.h>
13
David S. Miller90a66462006-03-08 17:18:19 -080014/* OBP version string. */
15extern char prom_version[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17/* Root node of the prom device tree, this stays constant after
18 * initialization is complete.
19 */
20extern int prom_root_node;
21
22/* PROM stdin and stdout */
23extern int prom_stdin, prom_stdout;
24
25/* /chosen node of the prom device tree, this stays constant after
26 * initialization is complete.
27 */
28extern int prom_chosen_node;
29
David S. Millerbff06d52005-09-22 20:11:33 -070030/* Helper values and strings in arch/sparc64/kernel/head.S */
David S. Millerd82ace72006-02-09 02:52:44 -080031extern const char prom_peer_name[];
32extern const char prom_compatible_name[];
33extern const char prom_root_compatible[];
David S. Millerbff06d52005-09-22 20:11:33 -070034extern const char prom_finddev_name[];
35extern const char prom_chosen_path[];
36extern const char prom_getprop_name[];
37extern const char prom_mmu_name[];
38extern const char prom_callmethod_name[];
39extern const char prom_translate_name[];
40extern const char prom_map_name[];
41extern const char prom_unmap_name[];
42extern int prom_mmu_ihandle_cache;
43extern unsigned int prom_boot_mapped_pc;
44extern unsigned int prom_boot_mapping_mode;
45extern unsigned long prom_boot_mapping_phys_high, prom_boot_mapping_phys_low;
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047struct linux_mlist_p1275 {
48 struct linux_mlist_p1275 *theres_more;
49 unsigned long start_adr;
50 unsigned long num_bytes;
51};
52
53struct linux_mem_p1275 {
54 struct linux_mlist_p1275 **p1275_totphys;
55 struct linux_mlist_p1275 **p1275_prommap;
56 struct linux_mlist_p1275 **p1275_available; /* What we can use */
57};
58
59/* The functions... */
60
61/* You must call prom_init() before using any of the library services,
62 * preferably as early as possible. Pass it the romvec pointer.
63 */
64extern void prom_init(void *cif_handler, void *cif_stack);
65
66/* Boot argument acquisition, returns the boot command line string. */
67extern char *prom_getbootargs(void);
68
69/* Device utilities. */
70
71/* Device operations. */
72
73/* Open the device described by the passed string. Note, that the format
74 * of the string is different on V0 vs. V2->higher proms. The caller must
75 * know what he/she is doing! Returns the device descriptor, an int.
76 */
David S. Millerbff06d52005-09-22 20:11:33 -070077extern int prom_devopen(const char *device_string);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79/* Close a previously opened device described by the passed integer
80 * descriptor.
81 */
82extern int prom_devclose(int device_handle);
83
84/* Do a seek operation on the device described by the passed integer
85 * descriptor.
86 */
87extern void prom_seek(int device_handle, unsigned int seek_hival,
88 unsigned int seek_lowval);
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090/* Miscellaneous routines, don't really fit in any category per se. */
91
92/* Reboot the machine with the command line passed. */
David S. Millerbff06d52005-09-22 20:11:33 -070093extern void prom_reboot(const char *boot_command);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95/* Evaluate the forth string passed. */
David S. Millerbff06d52005-09-22 20:11:33 -070096extern void prom_feval(const char *forth_string);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98/* Enter the prom, with possibility of continuation with the 'go'
99 * command in newer proms.
100 */
101extern void prom_cmdline(void);
102
103/* Enter the prom, with no chance of continuation for the stand-alone
104 * which calls this.
105 */
106extern void prom_halt(void) __attribute__ ((noreturn));
107
108/* Halt and power-off the machine. */
109extern void prom_halt_power_off(void) __attribute__ ((noreturn));
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 */
116typedef int (*callback_func_t)(long *cmd);
117extern void prom_setcallback(callback_func_t func_ptr);
118
119/* Acquire the IDPROM of the root node in the prom device tree. This
120 * gets passed a buffer where you would like it stuffed. The return value
121 * is the format type of this idprom or 0xff on error.
122 */
123extern unsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size);
124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125/* Character operations to/from the console.... */
126
127/* Non-blocking get character from console. */
128extern int prom_nbgetchar(void);
129
130/* Non-blocking put character to console. */
131extern int prom_nbputchar(char character);
132
133/* Blocking get character from console. */
134extern char prom_getchar(void);
135
136/* Blocking put character to console. */
137extern void prom_putchar(char character);
138
139/* Prom's internal routines, don't use in kernel/boot code. */
David S. Millerbff06d52005-09-22 20:11:33 -0700140extern void prom_printf(const char *fmt, ...);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141extern void prom_write(const char *buf, unsigned int len);
142
143/* Query for input device type */
144
145enum prom_input_device {
146 PROMDEV_IKBD, /* input from keyboard */
147 PROMDEV_ITTYA, /* input from ttya */
148 PROMDEV_ITTYB, /* input from ttyb */
Eddie C. Dostc126cf82006-01-18 14:54:31 -0800149 PROMDEV_IRSC, /* input from rsc */
David S. Miller1a7a2422006-02-11 23:24:30 -0800150 PROMDEV_IVCONS, /* input from virtual-console */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 PROMDEV_I_UNK,
152};
153
154extern enum prom_input_device prom_query_input_device(void);
155
156/* Query for output device type */
157
158enum prom_output_device {
159 PROMDEV_OSCREEN, /* to screen */
160 PROMDEV_OTTYA, /* to ttya */
161 PROMDEV_OTTYB, /* to ttyb */
Eddie C. Dostc126cf82006-01-18 14:54:31 -0800162 PROMDEV_ORSC, /* to rsc */
David S. Miller1a7a2422006-02-11 23:24:30 -0800163 PROMDEV_OVCONS, /* to virtual-console */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 PROMDEV_O_UNK,
165};
166
167extern enum prom_output_device prom_query_output_device(void);
168
169/* Multiprocessor operations... */
170#ifdef CONFIG_SMP
David S. Miller7890f792006-02-15 02:26:54 -0800171/* Start the CPU with the given device tree node at the passed program
172 * counter with the given arg passed in via register %o0.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 */
David S. Miller7890f792006-02-15 02:26:54 -0800174extern void prom_startcpu(int cpunode, unsigned long pc, unsigned long arg);
175
176/* Start the CPU with the given cpu ID at the passed program
177 * counter with the given arg passed in via register %o0.
178 */
179extern void prom_startcpu_cpuid(int cpuid, unsigned long pc, unsigned long arg);
180
181/* Stop the CPU with the given cpu ID. */
182extern void prom_stopcpu_cpuid(int cpuid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184/* Stop the current CPU. */
185extern void prom_stopself(void);
186
187/* Idle the current CPU. */
188extern void prom_idleself(void);
189
190/* Resume the CPU with the passed device tree node. */
191extern void prom_resumecpu(int cpunode);
192#endif
193
194/* Power management interfaces. */
195
196/* Put the current CPU to sleep. */
197extern void prom_sleepself(void);
198
199/* Put the entire system to sleep. */
200extern int prom_sleepsystem(void);
201
202/* Initiate a wakeup event. */
203extern int prom_wakeupsystem(void);
204
205/* MMU and memory related OBP interfaces. */
206
207/* Get unique string identifying SIMM at given physical address. */
208extern int prom_getunumber(int syndrome_code,
209 unsigned long phys_addr,
210 char *buf, int buflen);
211
212/* Retain physical memory to the caller across soft resets. */
David S. Millerbff06d52005-09-22 20:11:33 -0700213extern unsigned long prom_retain(const char *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 unsigned long pa_low, unsigned long pa_high,
215 long size, long align);
216
217/* Load explicit I/D TLB entries into the calling processor. */
218extern long prom_itlb_load(unsigned long index,
219 unsigned long tte_data,
220 unsigned long vaddr);
221
222extern long prom_dtlb_load(unsigned long index,
223 unsigned long tte_data,
224 unsigned long vaddr);
225
226/* Map/Unmap client program address ranges. First the format of
227 * the mapping mode argument.
228 */
229#define PROM_MAP_WRITE 0x0001 /* Writable */
230#define PROM_MAP_READ 0x0002 /* Readable - sw */
231#define PROM_MAP_EXEC 0x0004 /* Executable - sw */
232#define PROM_MAP_LOCKED 0x0010 /* Locked, use i/dtlb load calls for this instead */
233#define PROM_MAP_CACHED 0x0020 /* Cacheable in both L1 and L2 caches */
234#define PROM_MAP_SE 0x0040 /* Side-Effects */
235#define PROM_MAP_GLOB 0x0080 /* Global */
236#define PROM_MAP_IE 0x0100 /* Invert-Endianness */
237#define PROM_MAP_DEFAULT (PROM_MAP_WRITE | PROM_MAP_READ | PROM_MAP_EXEC | PROM_MAP_CACHED)
238
239extern int prom_map(int mode, unsigned long size,
240 unsigned long vaddr, unsigned long paddr);
241extern void prom_unmap(unsigned long size, unsigned long vaddr);
242
243
244/* PROM device tree traversal functions... */
245
246#ifdef PROMLIB_INTERNAL
247
248/* Internal version of prom_getchild. */
249extern int __prom_getchild(int parent_node);
250
251/* Internal version of prom_getsibling. */
252extern int __prom_getsibling(int node);
253
254#endif
255
256/* Get the child node of the given node, or zero if no child exists. */
257extern int prom_getchild(int parent_node);
258
259/* Get the next sibling node of the given node, or zero if no further
260 * siblings exist.
261 */
262extern int prom_getsibling(int node);
263
264/* Get the length, at the passed node, of the given property type.
265 * Returns -1 on error (ie. no such property at this node).
266 */
David S. Millerbff06d52005-09-22 20:11:33 -0700267extern int prom_getproplen(int thisnode, const char *property);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
269/* Fetch the requested property using the given buffer. Returns
270 * the number of bytes the prom put into your buffer or -1 on error.
271 */
David S. Millerbff06d52005-09-22 20:11:33 -0700272extern int prom_getproperty(int thisnode, const char *property,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 char *prop_buffer, int propbuf_size);
274
275/* Acquire an integer property. */
David S. Millerbff06d52005-09-22 20:11:33 -0700276extern int prom_getint(int node, const char *property);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
278/* Acquire an integer property, with a default value. */
David S. Millerbff06d52005-09-22 20:11:33 -0700279extern int prom_getintdefault(int node, const char *property, int defval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
281/* Acquire a boolean property, 0=FALSE 1=TRUE. */
David S. Millerbff06d52005-09-22 20:11:33 -0700282extern int prom_getbool(int node, const char *prop);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284/* Acquire a string property, null string on error. */
David S. Millerbff06d52005-09-22 20:11:33 -0700285extern void prom_getstring(int node, const char *prop, char *buf, int bufsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287/* Does the passed node have the given "name"? YES=1 NO=0 */
David S. Millerbff06d52005-09-22 20:11:33 -0700288extern int prom_nodematch(int thisnode, const char *name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290/* Search all siblings starting at the passed node for "name" matching
291 * the given string. Returns the node on success, zero on failure.
292 */
David S. Millerbff06d52005-09-22 20:11:33 -0700293extern int prom_searchsiblings(int node_start, const char *name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
295/* Return the first property type, as a string, for the given node.
296 * Returns a null string on error. Buffer should be at least 32B long.
297 */
298extern char *prom_firstprop(int node, char *buffer);
299
300/* Returns the next property after the passed property for the given
301 * node. Returns null string on failure. Buffer should be at least 32B long.
302 */
David S. Millerbff06d52005-09-22 20:11:33 -0700303extern char *prom_nextprop(int node, const char *prev_property, char *buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
305/* Returns 1 if the specified node has given property. */
David S. Millerbff06d52005-09-22 20:11:33 -0700306extern int prom_node_has_property(int node, const char *property);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308/* Returns phandle of the path specified */
David S. Millerbff06d52005-09-22 20:11:33 -0700309extern int prom_finddevice(const char *name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
311/* Set the indicated property at the given node with the passed value.
312 * Returns the number of bytes of your value that the prom took.
313 */
David S. Millerbff06d52005-09-22 20:11:33 -0700314extern int prom_setprop(int node, const char *prop_name, char *prop_value,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 int value_size);
316
David S. Millerbff06d52005-09-22 20:11:33 -0700317extern int prom_pathtoinode(const char *path);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318extern int prom_inst2pkg(int);
319
320/* CPU probing helpers. */
David S. Miller07f8e5f2006-06-21 23:34:02 -0700321struct device_node;
322int cpu_find_by_instance(int instance, struct device_node **dev_node, int *mid);
323int cpu_find_by_mid(int mid, struct device_node **prom_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
325/* Client interface level routines. */
326extern void prom_set_trap_table(unsigned long tba);
David S. Miller12eaa322006-02-10 15:39:51 -0800327extern void prom_set_trap_table_sun4v(unsigned long tba, unsigned long mmfsa);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
David S. Millerbff06d52005-09-22 20:11:33 -0700329extern long p1275_cmd(const char *, long, ...);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
331
332#if 0
333#define P1275_SIZE(x) ((((long)((x) / 32)) << 32) | (x))
334#else
335#define P1275_SIZE(x) x
336#endif
337
338/* We support at most 16 input and 1 output argument */
339#define P1275_ARG_NUMBER 0
340#define P1275_ARG_IN_STRING 1
341#define P1275_ARG_OUT_BUF 2
342#define P1275_ARG_OUT_32B 3
343#define P1275_ARG_IN_FUNCTION 4
344#define P1275_ARG_IN_BUF 5
345#define P1275_ARG_IN_64B 6
346
347#define P1275_IN(x) ((x) & 0xf)
348#define P1275_OUT(x) (((x) << 4) & 0xf0)
349#define P1275_INOUT(i,o) (P1275_IN(i)|P1275_OUT(o))
350#define P1275_ARG(n,x) ((x) << ((n)*3 + 8))
351
352#endif /* !(__SPARC64_OPLIB_H) */