blob: 56a09b9d7b1b51d3c7457abe1e33d97865981b86 [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 */
Sam Ravnborgf05a6862014-05-16 23:25:50 +020046void prom_init(struct linux_romvec *rom_ptr);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070047
48/* Boot argument acquisition, returns the boot command line string. */
Sam Ravnborgf05a6862014-05-16 23:25:50 +020049char *prom_getbootargs(void);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070050
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070051/* Miscellaneous routines, don't really fit in any category per se. */
52
53/* Reboot the machine with the command line passed. */
Sam Ravnborgf05a6862014-05-16 23:25:50 +020054void prom_reboot(char *boot_command);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070055
56/* Evaluate the forth string passed. */
Sam Ravnborgf05a6862014-05-16 23:25:50 +020057void prom_feval(char *forth_string);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070058
59/* Enter the prom, with possibility of continuation with the 'go'
60 * command in newer proms.
61 */
Sam Ravnborgf05a6862014-05-16 23:25:50 +020062void prom_cmdline(void);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070063
64/* Enter the prom, with no chance of continuation for the stand-alone
65 * which calls this.
66 */
Sam Ravnborgf05a6862014-05-16 23:25:50 +020067void __noreturn prom_halt(void);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070068
69/* Set the PROM 'sync' callback function to the passed function pointer.
70 * When the user gives the 'sync' command at the prom prompt while the
71 * kernel is still active, the prom will call this routine.
72 *
73 * XXX The arguments are different on V0 vs. V2->higher proms, grrr! XXX
74 */
75typedef void (*sync_func_t)(void);
Sam Ravnborgf05a6862014-05-16 23:25:50 +020076void prom_setsync(sync_func_t func_ptr);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070077
78/* Acquire the IDPROM of the root node in the prom device tree. This
79 * gets passed a buffer where you would like it stuffed. The return value
80 * is the format type of this idprom or 0xff on error.
81 */
Sam Ravnborgf05a6862014-05-16 23:25:50 +020082unsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070083
84/* Get the prom major version. */
Sam Ravnborgf05a6862014-05-16 23:25:50 +020085int prom_version(void);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070086
87/* Get the prom plugin revision. */
Sam Ravnborgf05a6862014-05-16 23:25:50 +020088int prom_getrev(void);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070089
90/* Get the prom firmware revision. */
Sam Ravnborgf05a6862014-05-16 23:25:50 +020091int prom_getprev(void);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070092
David S. Miller595a2512010-11-30 20:15:58 -080093/* Write a buffer of characters to the console. */
Sam Ravnborgf05a6862014-05-16 23:25:50 +020094void prom_console_write_buf(const char *buf, int len);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070095
96/* Prom's internal routines, don't use in kernel/boot code. */
Sam Ravnborgf05a6862014-05-16 23:25:50 +020097__printf(1, 2) void prom_printf(const char *fmt, ...);
98void prom_write(const char *buf, unsigned int len);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070099
100/* Multiprocessor operations... */
101
102/* Start the CPU with the given device tree node, context table, and context
103 * at the passed program counter.
104 */
Sam Ravnborgf05a6862014-05-16 23:25:50 +0200105int prom_startcpu(int cpunode, struct linux_prom_registers *context_table,
106 int context, char *program_counter);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700107
Sam Ravnborg5f66dd32011-01-03 08:27:55 +0000108/* Initialize the memory lists based upon the prom version. */
109void prom_meminit(void);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700110
111/* PROM device tree traversal functions... */
112
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700113/* Get the child node of the given node, or zero if no child exists. */
Sam Ravnborgf05a6862014-05-16 23:25:50 +0200114phandle prom_getchild(phandle parent_node);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700115
116/* Get the next sibling node of the given node, or zero if no further
117 * siblings exist.
118 */
Sam Ravnborgf05a6862014-05-16 23:25:50 +0200119phandle prom_getsibling(phandle node);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700120
121/* Get the length, at the passed node, of the given property type.
122 * Returns -1 on error (ie. no such property at this node).
123 */
Sam Ravnborgf05a6862014-05-16 23:25:50 +0200124int prom_getproplen(phandle thisnode, const char *property);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700125
126/* Fetch the requested property using the given buffer. Returns
127 * the number of bytes the prom put into your buffer or -1 on error.
128 */
Sam Ravnborgf05a6862014-05-16 23:25:50 +0200129int __must_check prom_getproperty(phandle thisnode, const char *property,
130 char *prop_buffer, int propbuf_size);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700131
132/* Acquire an integer property. */
Sam Ravnborgf05a6862014-05-16 23:25:50 +0200133int prom_getint(phandle node, char *property);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700134
135/* Acquire an integer property, with a default value. */
Sam Ravnborgf05a6862014-05-16 23:25:50 +0200136int prom_getintdefault(phandle node, char *property, int defval);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700137
138/* Acquire a boolean property, 0=FALSE 1=TRUE. */
Sam Ravnborgf05a6862014-05-16 23:25:50 +0200139int prom_getbool(phandle node, char *prop);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700140
141/* Acquire a string property, null string on error. */
Sam Ravnborgf05a6862014-05-16 23:25:50 +0200142void prom_getstring(phandle node, char *prop, char *buf, int bufsize);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700143
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700144/* Search all siblings starting at the passed node for "name" matching
145 * the given string. Returns the node on success, zero on failure.
146 */
Sam Ravnborgf05a6862014-05-16 23:25:50 +0200147phandle prom_searchsiblings(phandle node_start, char *name);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700148
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700149/* Returns the next property after the passed property for the given
150 * node. Returns null string on failure.
151 */
Sam Ravnborgf05a6862014-05-16 23:25:50 +0200152char *prom_nextprop(phandle node, char *prev_property, char *buffer);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700153
154/* Returns phandle of the path specified */
Sam Ravnborgf05a6862014-05-16 23:25:50 +0200155phandle prom_finddevice(char *name);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700156
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700157/* Set the indicated property at the given node with the passed value.
158 * Returns the number of bytes of your value that the prom took.
159 */
Sam Ravnborgf05a6862014-05-16 23:25:50 +0200160int prom_setprop(phandle node, const char *prop_name, char *prop_value,
161 int value_size);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700162
Sam Ravnborgf05a6862014-05-16 23:25:50 +0200163phandle prom_inst2pkg(int);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700164
165/* Dorking with Bus ranges... */
166
167/* Apply promlib probes OBIO ranges to registers. */
Sam Ravnborgf05a6862014-05-16 23:25:50 +0200168void prom_apply_obio_ranges(struct linux_prom_registers *obioregs, int nregs);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700169
170/* Apply ranges of any prom node (and optionally parent node as well) to registers. */
Sam Ravnborgf05a6862014-05-16 23:25:50 +0200171void prom_apply_generic_ranges(phandle node, phandle parent,
172 struct linux_prom_registers *sbusregs, int nregs);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700173
Sam Ravnborg5f66dd32011-01-03 08:27:55 +0000174void prom_ranges_init(void);
175
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700176/* CPU probing helpers. */
Andres Salomon8d125562010-10-08 14:18:11 -0700177int cpu_find_by_instance(int instance, phandle *prom_node, int *mid);
178int cpu_find_by_mid(int mid, phandle *prom_node);
179int cpu_get_hwmid(phandle prom_node);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700180
181extern spinlock_t prom_lock;
182
183#endif /* !(__SPARC_OPLIB_H) */