18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * oplib.h:  Describes the interface and available routines in the
48c2ecf20Sopenharmony_ci *           Linux Prom library.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifndef __SPARC_OPLIB_H
108c2ecf20Sopenharmony_ci#define __SPARC_OPLIB_H
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <asm/openprom.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/* The master romvec pointer... */
158c2ecf20Sopenharmony_ciextern struct linux_romvec *romvec;
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/* Enumeration to describe the prom major version we have detected. */
188c2ecf20Sopenharmony_cienum prom_major_version {
198c2ecf20Sopenharmony_ci	PROM_V0,      /* Original sun4c V0 prom */
208c2ecf20Sopenharmony_ci	PROM_V2,      /* sun4c and early sun4m V2 prom */
218c2ecf20Sopenharmony_ci	PROM_V3,      /* sun4m and later, up to sun4d/sun4e machines V3 */
228c2ecf20Sopenharmony_ci	PROM_P1275,   /* IEEE compliant ISA based Sun PROM, only sun4u */
238c2ecf20Sopenharmony_ci};
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ciextern enum prom_major_version prom_vers;
268c2ecf20Sopenharmony_ci/* Revision, and firmware revision. */
278c2ecf20Sopenharmony_ciextern unsigned int prom_rev, prom_prev;
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci/* Root node of the prom device tree, this stays constant after
308c2ecf20Sopenharmony_ci * initialization is complete.
318c2ecf20Sopenharmony_ci */
328c2ecf20Sopenharmony_ciextern int prom_root_node;
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/* Pointer to prom structure containing the device tree traversal
358c2ecf20Sopenharmony_ci * and usage utility functions.  Only prom-lib should use these,
368c2ecf20Sopenharmony_ci * users use the interface defined by the library only!
378c2ecf20Sopenharmony_ci */
388c2ecf20Sopenharmony_ciextern struct linux_nodeops *prom_nodeops;
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci/* The functions... */
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci/* You must call prom_init() before using any of the library services,
438c2ecf20Sopenharmony_ci * preferably as early as possible.  Pass it the romvec pointer.
448c2ecf20Sopenharmony_ci */
458c2ecf20Sopenharmony_ciextern void prom_init(struct linux_romvec *rom_ptr);
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci/* Boot argument acquisition, returns the boot command line string. */
488c2ecf20Sopenharmony_ciextern char *prom_getbootargs(void);
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci/* Device utilities. */
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci/* Map and unmap devices in IO space at virtual addresses. Note that the
538c2ecf20Sopenharmony_ci * virtual address you pass is a request and the prom may put your mappings
548c2ecf20Sopenharmony_ci * somewhere else, so check your return value as that is where your new
558c2ecf20Sopenharmony_ci * mappings really are!
568c2ecf20Sopenharmony_ci *
578c2ecf20Sopenharmony_ci * Another note, these are only available on V2 or higher proms!
588c2ecf20Sopenharmony_ci */
598c2ecf20Sopenharmony_ciextern char *prom_mapio(char *virt_hint, int io_space, unsigned int phys_addr, unsigned int num_bytes);
608c2ecf20Sopenharmony_ciextern void prom_unmapio(char *virt_addr, unsigned int num_bytes);
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci/* Device operations. */
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/* Open the device described by the passed string.  Note, that the format
658c2ecf20Sopenharmony_ci * of the string is different on V0 vs. V2->higher proms.  The caller must
668c2ecf20Sopenharmony_ci * know what he/she is doing!  Returns the device descriptor, an int.
678c2ecf20Sopenharmony_ci */
688c2ecf20Sopenharmony_ciextern int prom_devopen(char *device_string);
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci/* Close a previously opened device described by the passed integer
718c2ecf20Sopenharmony_ci * descriptor.
728c2ecf20Sopenharmony_ci */
738c2ecf20Sopenharmony_ciextern int prom_devclose(int device_handle);
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci/* Do a seek operation on the device described by the passed integer
768c2ecf20Sopenharmony_ci * descriptor.
778c2ecf20Sopenharmony_ci */
788c2ecf20Sopenharmony_ciextern void prom_seek(int device_handle, unsigned int seek_hival,
798c2ecf20Sopenharmony_ci		      unsigned int seek_lowval);
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci/* Machine memory configuration routine. */
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci/* This function returns a V0 format memory descriptor table, it has three
848c2ecf20Sopenharmony_ci * entries.  One for the total amount of physical ram on the machine, one
858c2ecf20Sopenharmony_ci * for the amount of physical ram available, and one describing the virtual
868c2ecf20Sopenharmony_ci * areas which are allocated by the prom.  So, in a sense the physical
878c2ecf20Sopenharmony_ci * available is a calculation of the total physical minus the physical mapped
888c2ecf20Sopenharmony_ci * by the prom with virtual mappings.
898c2ecf20Sopenharmony_ci *
908c2ecf20Sopenharmony_ci * These lists are returned pre-sorted, this should make your life easier
918c2ecf20Sopenharmony_ci * since the prom itself is way too lazy to do such nice things.
928c2ecf20Sopenharmony_ci */
938c2ecf20Sopenharmony_ciextern struct linux_mem_v0 *prom_meminfo(void);
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci/* Miscellaneous routines, don't really fit in any category per se. */
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci/* Reboot the machine with the command line passed. */
988c2ecf20Sopenharmony_ciextern void prom_reboot(char *boot_command);
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci/* Evaluate the forth string passed. */
1018c2ecf20Sopenharmony_ciextern void prom_feval(char *forth_string);
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci/* Enter the prom, with possibility of continuation with the 'go'
1048c2ecf20Sopenharmony_ci * command in newer proms.
1058c2ecf20Sopenharmony_ci */
1068c2ecf20Sopenharmony_ciextern void prom_cmdline(void);
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci/* Enter the prom, with no chance of continuation for the stand-alone
1098c2ecf20Sopenharmony_ci * which calls this.
1108c2ecf20Sopenharmony_ci */
1118c2ecf20Sopenharmony_ciextern void prom_halt(void);
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci/* Set the PROM 'sync' callback function to the passed function pointer.
1148c2ecf20Sopenharmony_ci * When the user gives the 'sync' command at the prom prompt while the
1158c2ecf20Sopenharmony_ci * kernel is still active, the prom will call this routine.
1168c2ecf20Sopenharmony_ci *
1178c2ecf20Sopenharmony_ci * XXX The arguments are different on V0 vs. V2->higher proms, grrr! XXX
1188c2ecf20Sopenharmony_ci */
1198c2ecf20Sopenharmony_citypedef void (*sync_func_t)(void);
1208c2ecf20Sopenharmony_ciextern void prom_setsync(sync_func_t func_ptr);
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci/* Acquire the IDPROM of the root node in the prom device tree.  This
1238c2ecf20Sopenharmony_ci * gets passed a buffer where you would like it stuffed.  The return value
1248c2ecf20Sopenharmony_ci * is the format type of this idprom or 0xff on error.
1258c2ecf20Sopenharmony_ci */
1268c2ecf20Sopenharmony_ciextern unsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size);
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci/* Get the prom major version. */
1298c2ecf20Sopenharmony_ciextern int prom_version(void);
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci/* Get the prom plugin revision. */
1328c2ecf20Sopenharmony_ciextern int prom_getrev(void);
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci/* Get the prom firmware revision. */
1358c2ecf20Sopenharmony_ciextern int prom_getprev(void);
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci/* Character operations to/from the console.... */
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci/* Non-blocking get character from console. */
1408c2ecf20Sopenharmony_ciextern int prom_nbgetchar(void);
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci/* Non-blocking put character to console. */
1438c2ecf20Sopenharmony_ciextern int prom_nbputchar(char character);
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci/* Blocking get character from console. */
1468c2ecf20Sopenharmony_ciextern char prom_getchar(void);
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci/* Blocking put character to console. */
1498c2ecf20Sopenharmony_ciextern void prom_putchar(char character);
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci/* Prom's internal printf routine, don't use in kernel/boot code. */
1528c2ecf20Sopenharmony_civoid prom_printf(char *fmt, ...);
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci/* Query for input device type */
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_cienum prom_input_device {
1578c2ecf20Sopenharmony_ci	PROMDEV_IKBD,			/* input from keyboard */
1588c2ecf20Sopenharmony_ci	PROMDEV_ITTYA,			/* input from ttya */
1598c2ecf20Sopenharmony_ci	PROMDEV_ITTYB,			/* input from ttyb */
1608c2ecf20Sopenharmony_ci	PROMDEV_I_UNK,
1618c2ecf20Sopenharmony_ci};
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ciextern enum prom_input_device prom_query_input_device(void);
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci/* Query for output device type */
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_cienum prom_output_device {
1688c2ecf20Sopenharmony_ci	PROMDEV_OSCREEN,		/* to screen */
1698c2ecf20Sopenharmony_ci	PROMDEV_OTTYA,			/* to ttya */
1708c2ecf20Sopenharmony_ci	PROMDEV_OTTYB,			/* to ttyb */
1718c2ecf20Sopenharmony_ci	PROMDEV_O_UNK,
1728c2ecf20Sopenharmony_ci};
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ciextern enum prom_output_device prom_query_output_device(void);
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci/* Multiprocessor operations... */
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci/* Start the CPU with the given device tree node, context table, and context
1798c2ecf20Sopenharmony_ci * at the passed program counter.
1808c2ecf20Sopenharmony_ci */
1818c2ecf20Sopenharmony_ciextern int prom_startcpu(int cpunode, struct linux_prom_registers *context_table,
1828c2ecf20Sopenharmony_ci			 int context, char *program_counter);
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci/* Stop the CPU with the passed device tree node. */
1858c2ecf20Sopenharmony_ciextern int prom_stopcpu(int cpunode);
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci/* Idle the CPU with the passed device tree node. */
1888c2ecf20Sopenharmony_ciextern int prom_idlecpu(int cpunode);
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci/* Re-Start the CPU with the passed device tree node. */
1918c2ecf20Sopenharmony_ciextern int prom_restartcpu(int cpunode);
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci/* PROM memory allocation facilities... */
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci/* Allocated at possibly the given virtual address a chunk of the
1968c2ecf20Sopenharmony_ci * indicated size.
1978c2ecf20Sopenharmony_ci */
1988c2ecf20Sopenharmony_ciextern char *prom_alloc(char *virt_hint, unsigned int size);
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci/* Free a previously allocated chunk. */
2018c2ecf20Sopenharmony_ciextern void prom_free(char *virt_addr, unsigned int size);
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci/* Sun4/sun4c specific memory-management startup hook. */
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci/* Map the passed segment in the given context at the passed
2068c2ecf20Sopenharmony_ci * virtual address.
2078c2ecf20Sopenharmony_ci */
2088c2ecf20Sopenharmony_ciextern void prom_putsegment(int context, unsigned long virt_addr,
2098c2ecf20Sopenharmony_ci			    int physical_segment);
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci/* PROM device tree traversal functions... */
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci/* Get the child node of the given node, or zero if no child exists. */
2148c2ecf20Sopenharmony_ciextern int prom_getchild(int parent_node);
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci/* Get the next sibling node of the given node, or zero if no further
2178c2ecf20Sopenharmony_ci * siblings exist.
2188c2ecf20Sopenharmony_ci */
2198c2ecf20Sopenharmony_ciextern int prom_getsibling(int node);
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci/* Get the length, at the passed node, of the given property type.
2228c2ecf20Sopenharmony_ci * Returns -1 on error (ie. no such property at this node).
2238c2ecf20Sopenharmony_ci */
2248c2ecf20Sopenharmony_ciextern int prom_getproplen(int thisnode, char *property);
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci/* Fetch the requested property using the given buffer.  Returns
2278c2ecf20Sopenharmony_ci * the number of bytes the prom put into your buffer or -1 on error.
2288c2ecf20Sopenharmony_ci */
2298c2ecf20Sopenharmony_ciextern int prom_getproperty(int thisnode, char *property,
2308c2ecf20Sopenharmony_ci			    char *prop_buffer, int propbuf_size);
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci/* Acquire an integer property. */
2338c2ecf20Sopenharmony_ciextern int prom_getint(int node, char *property);
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci/* Acquire an integer property, with a default value. */
2368c2ecf20Sopenharmony_ciextern int prom_getintdefault(int node, char *property, int defval);
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci/* Acquire a boolean property, 0=FALSE 1=TRUE. */
2398c2ecf20Sopenharmony_ciextern int prom_getbool(int node, char *prop);
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_ci/* Acquire a string property, null string on error. */
2428c2ecf20Sopenharmony_ciextern void prom_getstring(int node, char *prop, char *buf, int bufsize);
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci/* Does the passed node have the given "name"? YES=1 NO=0 */
2458c2ecf20Sopenharmony_ciextern int prom_nodematch(int thisnode, char *name);
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci/* Search all siblings starting at the passed node for "name" matching
2488c2ecf20Sopenharmony_ci * the given string.  Returns the node on success, zero on failure.
2498c2ecf20Sopenharmony_ci */
2508c2ecf20Sopenharmony_ciextern int prom_searchsiblings(int node_start, char *name);
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci/* Return the first property type, as a string, for the given node.
2538c2ecf20Sopenharmony_ci * Returns a null string on error.
2548c2ecf20Sopenharmony_ci */
2558c2ecf20Sopenharmony_ciextern char *prom_firstprop(int node);
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci/* Returns the next property after the passed property for the given
2588c2ecf20Sopenharmony_ci * node.  Returns null string on failure.
2598c2ecf20Sopenharmony_ci */
2608c2ecf20Sopenharmony_ciextern char *prom_nextprop(int node, char *prev_property);
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci/* Returns 1 if the specified node has given property. */
2638c2ecf20Sopenharmony_ciextern int prom_node_has_property(int node, char *property);
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci/* Set the indicated property at the given node with the passed value.
2668c2ecf20Sopenharmony_ci * Returns the number of bytes of your value that the prom took.
2678c2ecf20Sopenharmony_ci */
2688c2ecf20Sopenharmony_ciextern int prom_setprop(int node, char *prop_name, char *prop_value,
2698c2ecf20Sopenharmony_ci			int value_size);
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ciextern int prom_pathtoinode(char *path);
2728c2ecf20Sopenharmony_ciextern int prom_inst2pkg(int);
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci/* Dorking with Bus ranges... */
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci/* Adjust reg values with the passed ranges. */
2778c2ecf20Sopenharmony_ciextern void prom_adjust_regs(struct linux_prom_registers *regp, int nregs,
2788c2ecf20Sopenharmony_ci			     struct linux_prom_ranges *rangep, int nranges);
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_ci/* Adjust child ranges with the passed parent ranges. */
2818c2ecf20Sopenharmony_ciextern void prom_adjust_ranges(struct linux_prom_ranges *cranges, int ncranges,
2828c2ecf20Sopenharmony_ci			       struct linux_prom_ranges *pranges, int npranges);
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_ci/* Apply promlib probed OBIO ranges to registers. */
2858c2ecf20Sopenharmony_ciextern void prom_apply_obio_ranges(struct linux_prom_registers *obioregs, int nregs);
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci/* Apply ranges of any prom node (and optionally parent node as well) to registers. */
2888c2ecf20Sopenharmony_ciextern void prom_apply_generic_ranges(int node, int parent,
2898c2ecf20Sopenharmony_ci				      struct linux_prom_registers *sbusregs, int nregs);
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci#endif /* !(__SPARC_OPLIB_H) */
293