Sam Ravnborg | f5e706a | 2008-07-17 21:55:51 -0700 | [diff] [blame] | 1 | /* |
| 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... */ |
| 16 | extern struct linux_romvec *romvec; |
| 17 | |
| 18 | /* Enumeration to describe the prom major version we have detected. */ |
| 19 | enum 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 Ravnborg | f5e706a | 2008-07-17 21:55:51 -0700 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | extern enum prom_major_version prom_vers; |
| 27 | /* Revision, and firmware revision. */ |
| 28 | extern unsigned int prom_rev, prom_prev; |
| 29 | |
| 30 | /* Root node of the prom device tree, this stays constant after |
| 31 | * initialization is complete. |
| 32 | */ |
| 33 | extern int prom_root_node; |
| 34 | |
| 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 | */ |
| 39 | extern 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 | */ |
| 46 | extern void prom_init(struct linux_romvec *rom_ptr); |
| 47 | |
| 48 | /* Boot argument acquisition, returns the boot command line string. */ |
| 49 | extern 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 | */ |
| 60 | extern char *prom_mapio(char *virt_hint, int io_space, unsigned int phys_addr, unsigned int num_bytes); |
| 61 | extern void prom_unmapio(char *virt_addr, unsigned int num_bytes); |
| 62 | |
| 63 | /* Device operations. */ |
| 64 | |
| 65 | /* Open the device described by the passed string. Note, that the format |
| 66 | * of the string is different on V0 vs. V2->higher proms. The caller must |
| 67 | * know what he/she is doing! Returns the device descriptor, an int. |
| 68 | */ |
| 69 | extern int prom_devopen(char *device_string); |
| 70 | |
| 71 | /* Close a previously opened device described by the passed integer |
| 72 | * descriptor. |
| 73 | */ |
| 74 | extern int prom_devclose(int device_handle); |
| 75 | |
| 76 | /* Do a seek operation on the device described by the passed integer |
| 77 | * descriptor. |
| 78 | */ |
| 79 | extern void prom_seek(int device_handle, unsigned int seek_hival, |
| 80 | unsigned int seek_lowval); |
| 81 | |
| 82 | /* Miscellaneous routines, don't really fit in any category per se. */ |
| 83 | |
| 84 | /* Reboot the machine with the command line passed. */ |
| 85 | extern void prom_reboot(char *boot_command); |
| 86 | |
| 87 | /* Evaluate the forth string passed. */ |
| 88 | extern void prom_feval(char *forth_string); |
| 89 | |
| 90 | /* Enter the prom, with possibility of continuation with the 'go' |
| 91 | * command in newer proms. |
| 92 | */ |
| 93 | extern void prom_cmdline(void); |
| 94 | |
| 95 | /* Enter the prom, with no chance of continuation for the stand-alone |
| 96 | * which calls this. |
| 97 | */ |
| 98 | extern void prom_halt(void) __attribute__ ((noreturn)); |
| 99 | |
| 100 | /* Set the PROM 'sync' callback function to the passed function pointer. |
| 101 | * When the user gives the 'sync' command at the prom prompt while the |
| 102 | * kernel is still active, the prom will call this routine. |
| 103 | * |
| 104 | * XXX The arguments are different on V0 vs. V2->higher proms, grrr! XXX |
| 105 | */ |
| 106 | typedef void (*sync_func_t)(void); |
| 107 | extern void prom_setsync(sync_func_t func_ptr); |
| 108 | |
| 109 | /* Acquire the IDPROM of the root node in the prom device tree. This |
| 110 | * gets passed a buffer where you would like it stuffed. The return value |
| 111 | * is the format type of this idprom or 0xff on error. |
| 112 | */ |
| 113 | extern unsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size); |
| 114 | |
| 115 | /* Get the prom major version. */ |
| 116 | extern int prom_version(void); |
| 117 | |
| 118 | /* Get the prom plugin revision. */ |
| 119 | extern int prom_getrev(void); |
| 120 | |
| 121 | /* Get the prom firmware revision. */ |
| 122 | extern int prom_getprev(void); |
| 123 | |
| 124 | /* Character operations to/from the console.... */ |
| 125 | |
| 126 | /* Non-blocking get character from console. */ |
| 127 | extern int prom_nbgetchar(void); |
| 128 | |
| 129 | /* Non-blocking put character to console. */ |
| 130 | extern int prom_nbputchar(char character); |
| 131 | |
| 132 | /* Blocking get character from console. */ |
| 133 | extern char prom_getchar(void); |
| 134 | |
| 135 | /* Blocking put character to console. */ |
| 136 | extern void prom_putchar(char character); |
| 137 | |
| 138 | /* Prom's internal routines, don't use in kernel/boot code. */ |
Robert Reif | efe6c3d | 2008-12-08 00:59:17 -0800 | [diff] [blame] | 139 | extern void prom_printf(const char *fmt, ...); |
Sam Ravnborg | f5e706a | 2008-07-17 21:55:51 -0700 | [diff] [blame] | 140 | extern void prom_write(const char *buf, unsigned int len); |
| 141 | |
| 142 | /* Multiprocessor operations... */ |
| 143 | |
| 144 | /* Start the CPU with the given device tree node, context table, and context |
| 145 | * at the passed program counter. |
| 146 | */ |
| 147 | extern int prom_startcpu(int cpunode, struct linux_prom_registers *context_table, |
| 148 | int context, char *program_counter); |
| 149 | |
| 150 | /* Stop the CPU with the passed device tree node. */ |
| 151 | extern int prom_stopcpu(int cpunode); |
| 152 | |
| 153 | /* Idle the CPU with the passed device tree node. */ |
| 154 | extern int prom_idlecpu(int cpunode); |
| 155 | |
| 156 | /* Re-Start the CPU with the passed device tree node. */ |
| 157 | extern int prom_restartcpu(int cpunode); |
| 158 | |
| 159 | /* PROM memory allocation facilities... */ |
| 160 | |
| 161 | /* Allocated at possibly the given virtual address a chunk of the |
| 162 | * indicated size. |
| 163 | */ |
| 164 | extern char *prom_alloc(char *virt_hint, unsigned int size); |
| 165 | |
| 166 | /* Free a previously allocated chunk. */ |
| 167 | extern void prom_free(char *virt_addr, unsigned int size); |
| 168 | |
| 169 | /* Sun4/sun4c specific memory-management startup hook. */ |
| 170 | |
| 171 | /* Map the passed segment in the given context at the passed |
| 172 | * virtual address. |
| 173 | */ |
| 174 | extern void prom_putsegment(int context, unsigned long virt_addr, |
| 175 | int physical_segment); |
| 176 | |
| 177 | |
| 178 | /* PROM device tree traversal functions... */ |
| 179 | |
Sam Ravnborg | f5e706a | 2008-07-17 21:55:51 -0700 | [diff] [blame] | 180 | /* Get the child node of the given node, or zero if no child exists. */ |
| 181 | extern int prom_getchild(int parent_node); |
| 182 | |
| 183 | /* Get the next sibling node of the given node, or zero if no further |
| 184 | * siblings exist. |
| 185 | */ |
| 186 | extern int prom_getsibling(int node); |
| 187 | |
| 188 | /* Get the length, at the passed node, of the given property type. |
| 189 | * Returns -1 on error (ie. no such property at this node). |
| 190 | */ |
David S. Miller | ab04323 | 2008-12-05 16:54:44 -0800 | [diff] [blame] | 191 | extern int prom_getproplen(int thisnode, const char *property); |
Sam Ravnborg | f5e706a | 2008-07-17 21:55:51 -0700 | [diff] [blame] | 192 | |
| 193 | /* Fetch the requested property using the given buffer. Returns |
| 194 | * the number of bytes the prom put into your buffer or -1 on error. |
| 195 | */ |
David S. Miller | ab04323 | 2008-12-05 16:54:44 -0800 | [diff] [blame] | 196 | extern int __must_check prom_getproperty(int thisnode, const char *property, |
Sam Ravnborg | f5e706a | 2008-07-17 21:55:51 -0700 | [diff] [blame] | 197 | char *prop_buffer, int propbuf_size); |
| 198 | |
| 199 | /* Acquire an integer property. */ |
| 200 | extern int prom_getint(int node, char *property); |
| 201 | |
| 202 | /* Acquire an integer property, with a default value. */ |
| 203 | extern int prom_getintdefault(int node, char *property, int defval); |
| 204 | |
| 205 | /* Acquire a boolean property, 0=FALSE 1=TRUE. */ |
| 206 | extern int prom_getbool(int node, char *prop); |
| 207 | |
| 208 | /* Acquire a string property, null string on error. */ |
| 209 | extern void prom_getstring(int node, char *prop, char *buf, int bufsize); |
| 210 | |
| 211 | /* Does the passed node have the given "name"? YES=1 NO=0 */ |
| 212 | extern int prom_nodematch(int thisnode, char *name); |
| 213 | |
| 214 | /* Search all siblings starting at the passed node for "name" matching |
| 215 | * the given string. Returns the node on success, zero on failure. |
| 216 | */ |
| 217 | extern int prom_searchsiblings(int node_start, char *name); |
| 218 | |
| 219 | /* Return the first property type, as a string, for the given node. |
| 220 | * Returns a null string on error. |
| 221 | */ |
| 222 | extern char *prom_firstprop(int node, char *buffer); |
| 223 | |
| 224 | /* Returns the next property after the passed property for the given |
| 225 | * node. Returns null string on failure. |
| 226 | */ |
| 227 | extern char *prom_nextprop(int node, char *prev_property, char *buffer); |
| 228 | |
| 229 | /* Returns phandle of the path specified */ |
| 230 | extern int prom_finddevice(char *name); |
| 231 | |
| 232 | /* Returns 1 if the specified node has given property. */ |
| 233 | extern int prom_node_has_property(int node, char *property); |
| 234 | |
| 235 | /* Set the indicated property at the given node with the passed value. |
| 236 | * Returns the number of bytes of your value that the prom took. |
| 237 | */ |
David S. Miller | ab04323 | 2008-12-05 16:54:44 -0800 | [diff] [blame] | 238 | extern int prom_setprop(int node, const char *prop_name, char *prop_value, |
Sam Ravnborg | f5e706a | 2008-07-17 21:55:51 -0700 | [diff] [blame] | 239 | int value_size); |
| 240 | |
| 241 | extern int prom_pathtoinode(char *path); |
| 242 | extern int prom_inst2pkg(int); |
| 243 | |
| 244 | /* Dorking with Bus ranges... */ |
| 245 | |
| 246 | /* Apply promlib probes OBIO ranges to registers. */ |
| 247 | extern void prom_apply_obio_ranges(struct linux_prom_registers *obioregs, int nregs); |
| 248 | |
| 249 | /* Apply ranges of any prom node (and optionally parent node as well) to registers. */ |
| 250 | extern void prom_apply_generic_ranges(int node, int parent, |
| 251 | struct linux_prom_registers *sbusregs, int nregs); |
| 252 | |
| 253 | /* CPU probing helpers. */ |
| 254 | int cpu_find_by_instance(int instance, int *prom_node, int *mid); |
| 255 | int cpu_find_by_mid(int mid, int *prom_node); |
| 256 | int cpu_get_hwmid(int prom_node); |
| 257 | |
| 258 | extern spinlock_t prom_lock; |
| 259 | |
| 260 | #endif /* !(__SPARC_OPLIB_H) */ |