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... */ 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 */ 24}; 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 */ 33extern 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 */ 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 63/* 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 81typedef void (*sync_func_t)(void); 82extern void prom_setsync(sync_func_t func_ptr); 83 84/* Acquire the IDPROM of the root node in the prom device tree. This 85 * gets passed a buffer where you would like it stuffed. The return value 86 * is the format type of this idprom or 0xff on error. 87 */ 88extern unsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size); 89 90/* Get the prom major version. */ 91extern int prom_version(void); 92 93/* Get the prom plugin revision. */ 94extern int prom_getrev(void); 95 96/* Get the prom firmware revision. */ 97extern int prom_getprev(void); 98 99/* Write a buffer of characters to the console. */ 100extern void prom_console_write_buf(const char *buf, int len); 101 102/* Prom's internal routines, don't use in kernel/boot code. */ 103extern void prom_printf(const char *fmt, ...); 104extern void prom_write(const char *buf, unsigned int len); 105 106/* Multiprocessor operations... */ 107 108/* Start the CPU with the given device tree node, context table, and context 109 * at the passed program counter. 110 */ 111extern int prom_startcpu(int cpunode, struct linux_prom_registers *context_table, 112 int context, char *program_counter); 113 114/* Stop the CPU with the passed device tree node. */ 115extern int prom_stopcpu(int cpunode); 116 117/* Idle the CPU with the passed device tree node. */ 118extern int prom_idlecpu(int cpunode); 119 120/* Re-Start the CPU with the passed device tree node. */ 121extern int prom_restartcpu(int cpunode); 122 123/* PROM memory allocation facilities... */ 124 125/* Allocated at possibly the given virtual address a chunk of the 126 * indicated size. 127 */ 128extern char *prom_alloc(char *virt_hint, unsigned int size); 129 130/* Free a previously allocated chunk. */ 131extern void prom_free(char *virt_addr, unsigned int size); 132 133/* Sun4/sun4c specific memory-management startup hook. */ 134 135/* Map the passed segment in the given context at the passed 136 * virtual address. 137 */ 138extern void prom_putsegment(int context, unsigned long virt_addr, 139 int physical_segment); 140 141 142/* PROM device tree traversal functions... */ 143 144/* Get the child node of the given node, or zero if no child exists. */ 145extern int prom_getchild(int parent_node); 146 147/* Get the next sibling node of the given node, or zero if no further 148 * siblings exist. 149 */ 150extern int prom_getsibling(int node); 151 152/* Get the length, at the passed node, of the given property type. 153 * Returns -1 on error (ie. no such property at this node). 154 */ 155extern int prom_getproplen(int thisnode, const char *property); 156 157/* Fetch the requested property using the given buffer. Returns 158 * the number of bytes the prom put into your buffer or -1 on error. 159 */ 160extern int __must_check prom_getproperty(int thisnode, const char *property, 161 char *prop_buffer, int propbuf_size); 162 163/* Acquire an integer property. */ 164extern int prom_getint(int node, char *property); 165 166/* Acquire an integer property, with a default value. */ 167extern int prom_getintdefault(int node, char *property, int defval); 168 169/* Acquire a boolean property, 0=FALSE 1=TRUE. */ 170extern int prom_getbool(int node, char *prop); 171 172/* Acquire a string property, null string on error. */ 173extern void prom_getstring(int node, char *prop, char *buf, int bufsize); 174 175/* Does the passed node have the given "name"? YES=1 NO=0 */ 176extern int prom_nodematch(int thisnode, char *name); 177 178/* Search all siblings starting at the passed node for "name" matching 179 * the given string. Returns the node on success, zero on failure. 180 */ 181extern int prom_searchsiblings(int node_start, char *name); 182 183/* Return the first property type, as a string, for the given node. 184 * Returns a null string on error. 185 */ 186extern char *prom_firstprop(int node, char *buffer); 187 188/* Returns the next property after the passed property for the given 189 * node. Returns null string on failure. 190 */ 191extern char *prom_nextprop(int node, char *prev_property, char *buffer); 192 193/* Returns phandle of the path specified */ 194extern int prom_finddevice(char *name); 195 196/* Returns 1 if the specified node has given property. */ 197extern int prom_node_has_property(int node, char *property); 198 199/* Set the indicated property at the given node with the passed value. 200 * Returns the number of bytes of your value that the prom took. 201 */ 202extern int prom_setprop(int node, const char *prop_name, char *prop_value, 203 int value_size); 204 205extern int prom_inst2pkg(int); 206 207/* Dorking with Bus ranges... */ 208 209/* Apply promlib probes OBIO ranges to registers. */ 210extern void prom_apply_obio_ranges(struct linux_prom_registers *obioregs, int nregs); 211 212/* Apply ranges of any prom node (and optionally parent node as well) to registers. */ 213extern void prom_apply_generic_ranges(int node, int parent, 214 struct linux_prom_registers *sbusregs, int nregs); 215 216/* CPU probing helpers. */ 217int cpu_find_by_instance(int instance, int *prom_node, int *mid); 218int cpu_find_by_mid(int mid, int *prom_node); 219int cpu_get_hwmid(int prom_node); 220 221extern spinlock_t prom_lock; 222 223#endif /* !(__SPARC_OPLIB_H) */ 224