blob: 4c2539243e46034e7c57838d448eaf9ccb4c0cd6 [file] [log] [blame]
Sam Ravnborgf5e706a2008-07-17 21:55:51 -07001/*
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 */
7
8#ifndef __SPARC_OPLIB_H
9#define __SPARC_OPLIB_H
10
11#include <asm/openprom.h>
12#include <linux/spinlock.h>
13#include <linux/compiler.h>
14
15/* The master romvec pointer... */
16extern struct linux_romvec *romvec;
17
18/* Enumeration to describe the prom major version we have detected. */
19enum prom_major_version {
20 PROM_V0, /* Original sun4c V0 prom */
21 PROM_V2, /* sun4c and early sun4m V2 prom */
22 PROM_V3, /* sun4m and later, up to sun4d/sun4e machines V3 */
23 PROM_P1275, /* IEEE compliant ISA based Sun PROM, only sun4u */
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070024};
25
26extern enum prom_major_version prom_vers;
27/* Revision, and firmware revision. */
28extern unsigned int prom_rev, prom_prev;
29
30/* Root node of the prom device tree, this stays constant after
31 * initialization is complete.
32 */
Andres Salomon8d125562010-10-08 14:18:11 -070033extern phandle prom_root_node;
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070034
35/* Pointer to prom structure containing the device tree traversal
36 * and usage utility functions. Only prom-lib should use these,
37 * users use the interface defined by the library only!
38 */
39extern struct linux_nodeops *prom_nodeops;
40
41/* The functions... */
42
43/* You must call prom_init() before using any of the library services,
44 * preferably as early as possible. Pass it the romvec pointer.
45 */
46extern void prom_init(struct linux_romvec *rom_ptr);
47
48/* Boot argument acquisition, returns the boot command line string. */
49extern char *prom_getbootargs(void);
50
51/* Device utilities. */
52
53/* Map and unmap devices in IO space at virtual addresses. Note that the
54 * virtual address you pass is a request and the prom may put your mappings
55 * somewhere else, so check your return value as that is where your new
56 * mappings really are!
57 *
58 * Another note, these are only available on V2 or higher proms!
59 */
60extern char *prom_mapio(char *virt_hint, int io_space, unsigned int phys_addr, unsigned int num_bytes);
61extern void prom_unmapio(char *virt_addr, unsigned int num_bytes);
62
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070063/* Miscellaneous routines, don't really fit in any category per se. */
64
65/* Reboot the machine with the command line passed. */
66extern void prom_reboot(char *boot_command);
67
68/* Evaluate the forth string passed. */
69extern void prom_feval(char *forth_string);
70
71/* Enter the prom, with possibility of continuation with the 'go'
72 * command in newer proms.
73 */
74extern void prom_cmdline(void);
75
76/* Enter the prom, with no chance of continuation for the stand-alone
77 * which calls this.
78 */
79extern void prom_halt(void) __attribute__ ((noreturn));
80
81/* Set the PROM 'sync' callback function to the passed function pointer.
82 * When the user gives the 'sync' command at the prom prompt while the
83 * kernel is still active, the prom will call this routine.
84 *
85 * XXX The arguments are different on V0 vs. V2->higher proms, grrr! XXX
86 */
87typedef void (*sync_func_t)(void);
88extern void prom_setsync(sync_func_t func_ptr);
89
90/* Acquire the IDPROM of the root node in the prom device tree. This
91 * gets passed a buffer where you would like it stuffed. The return value
92 * is the format type of this idprom or 0xff on error.
93 */
94extern unsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size);
95
96/* Get the prom major version. */
97extern int prom_version(void);
98
99/* Get the prom plugin revision. */
100extern int prom_getrev(void);
101
102/* Get the prom firmware revision. */
103extern int prom_getprev(void);
104
105/* Character operations to/from the console.... */
106
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700107/* Blocking get character from console. */
David S. Millere62cac12010-11-30 14:33:29 -0800108extern void prom_getchar(char *buf);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700109
110/* Blocking put character to console. */
David S. Millere62cac12010-11-30 14:33:29 -0800111extern void prom_putchar(const char *buf);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700112
113/* Prom's internal routines, don't use in kernel/boot code. */
Robert Reifefe6c3d2008-12-08 00:59:17 -0800114extern void prom_printf(const char *fmt, ...);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700115extern void prom_write(const char *buf, unsigned int len);
116
117/* Multiprocessor operations... */
118
119/* Start the CPU with the given device tree node, context table, and context
120 * at the passed program counter.
121 */
122extern int prom_startcpu(int cpunode, struct linux_prom_registers *context_table,
123 int context, char *program_counter);
124
125/* Stop the CPU with the passed device tree node. */
126extern int prom_stopcpu(int cpunode);
127
128/* Idle the CPU with the passed device tree node. */
129extern int prom_idlecpu(int cpunode);
130
131/* Re-Start the CPU with the passed device tree node. */
132extern int prom_restartcpu(int cpunode);
133
134/* PROM memory allocation facilities... */
135
136/* Allocated at possibly the given virtual address a chunk of the
137 * indicated size.
138 */
139extern char *prom_alloc(char *virt_hint, unsigned int size);
140
141/* Free a previously allocated chunk. */
142extern void prom_free(char *virt_addr, unsigned int size);
143
144/* Sun4/sun4c specific memory-management startup hook. */
145
146/* Map the passed segment in the given context at the passed
147 * virtual address.
148 */
149extern void prom_putsegment(int context, unsigned long virt_addr,
150 int physical_segment);
151
152
153/* PROM device tree traversal functions... */
154
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700155/* Get the child node of the given node, or zero if no child exists. */
Andres Salomon8d125562010-10-08 14:18:11 -0700156extern phandle prom_getchild(phandle parent_node);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700157
158/* Get the next sibling node of the given node, or zero if no further
159 * siblings exist.
160 */
Andres Salomon8d125562010-10-08 14:18:11 -0700161extern phandle prom_getsibling(phandle node);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700162
163/* Get the length, at the passed node, of the given property type.
164 * Returns -1 on error (ie. no such property at this node).
165 */
Andres Salomon8d125562010-10-08 14:18:11 -0700166extern int prom_getproplen(phandle thisnode, const char *property);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700167
168/* Fetch the requested property using the given buffer. Returns
169 * the number of bytes the prom put into your buffer or -1 on error.
170 */
Andres Salomon8d125562010-10-08 14:18:11 -0700171extern int __must_check prom_getproperty(phandle thisnode, const char *property,
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700172 char *prop_buffer, int propbuf_size);
173
174/* Acquire an integer property. */
Andres Salomon8d125562010-10-08 14:18:11 -0700175extern int prom_getint(phandle node, char *property);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700176
177/* Acquire an integer property, with a default value. */
Andres Salomon8d125562010-10-08 14:18:11 -0700178extern int prom_getintdefault(phandle node, char *property, int defval);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700179
180/* Acquire a boolean property, 0=FALSE 1=TRUE. */
Andres Salomon8d125562010-10-08 14:18:11 -0700181extern int prom_getbool(phandle node, char *prop);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700182
183/* Acquire a string property, null string on error. */
Andres Salomon8d125562010-10-08 14:18:11 -0700184extern void prom_getstring(phandle node, char *prop, char *buf, int bufsize);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700185
186/* Does the passed node have the given "name"? YES=1 NO=0 */
Andres Salomon8d125562010-10-08 14:18:11 -0700187extern int prom_nodematch(phandle thisnode, char *name);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700188
189/* Search all siblings starting at the passed node for "name" matching
190 * the given string. Returns the node on success, zero on failure.
191 */
Andres Salomon8d125562010-10-08 14:18:11 -0700192extern phandle prom_searchsiblings(phandle node_start, char *name);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700193
194/* Return the first property type, as a string, for the given node.
195 * Returns a null string on error.
196 */
Andres Salomon8d125562010-10-08 14:18:11 -0700197extern char *prom_firstprop(phandle node, char *buffer);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700198
199/* Returns the next property after the passed property for the given
200 * node. Returns null string on failure.
201 */
Andres Salomon8d125562010-10-08 14:18:11 -0700202extern char *prom_nextprop(phandle node, char *prev_property, char *buffer);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700203
204/* Returns phandle of the path specified */
Andres Salomon8d125562010-10-08 14:18:11 -0700205extern phandle prom_finddevice(char *name);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700206
207/* Returns 1 if the specified node has given property. */
Andres Salomon8d125562010-10-08 14:18:11 -0700208extern int prom_node_has_property(phandle node, char *property);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700209
210/* Set the indicated property at the given node with the passed value.
211 * Returns the number of bytes of your value that the prom took.
212 */
Andres Salomon8d125562010-10-08 14:18:11 -0700213extern int prom_setprop(phandle node, const char *prop_name, char *prop_value,
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700214 int value_size);
215
Andres Salomon8d125562010-10-08 14:18:11 -0700216extern phandle prom_inst2pkg(int);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700217
218/* Dorking with Bus ranges... */
219
220/* Apply promlib probes OBIO ranges to registers. */
221extern void prom_apply_obio_ranges(struct linux_prom_registers *obioregs, int nregs);
222
223/* Apply ranges of any prom node (and optionally parent node as well) to registers. */
Andres Salomon8d125562010-10-08 14:18:11 -0700224extern void prom_apply_generic_ranges(phandle node, phandle parent,
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700225 struct linux_prom_registers *sbusregs, int nregs);
226
227/* CPU probing helpers. */
Andres Salomon8d125562010-10-08 14:18:11 -0700228int cpu_find_by_instance(int instance, phandle *prom_node, int *mid);
229int cpu_find_by_mid(int mid, phandle *prom_node);
230int cpu_get_hwmid(phandle prom_node);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700231
232extern spinlock_t prom_lock;
233
234#endif /* !(__SPARC_OPLIB_H) */