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#include <linux/spinlock.h>
148c2ecf20Sopenharmony_ci#include <linux/compiler.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci/* The master romvec pointer... */
178c2ecf20Sopenharmony_ciextern struct linux_romvec *romvec;
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci/* Enumeration to describe the prom major version we have detected. */
208c2ecf20Sopenharmony_cienum prom_major_version {
218c2ecf20Sopenharmony_ci	PROM_V0,      /* Original sun4c V0 prom */
228c2ecf20Sopenharmony_ci	PROM_V2,      /* sun4c and early sun4m V2 prom */
238c2ecf20Sopenharmony_ci	PROM_V3,      /* sun4m and later, up to sun4d/sun4e machines V3 */
248c2ecf20Sopenharmony_ci	PROM_P1275,   /* IEEE compliant ISA based Sun PROM, only sun4u */
258c2ecf20Sopenharmony_ci};
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ciextern enum prom_major_version prom_vers;
288c2ecf20Sopenharmony_ci/* Revision, and firmware revision. */
298c2ecf20Sopenharmony_ciextern unsigned int prom_rev, prom_prev;
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci/* Root node of the prom device tree, this stays constant after
328c2ecf20Sopenharmony_ci * initialization is complete.
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_ciextern phandle prom_root_node;
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci/* Pointer to prom structure containing the device tree traversal
378c2ecf20Sopenharmony_ci * and usage utility functions.  Only prom-lib should use these,
388c2ecf20Sopenharmony_ci * users use the interface defined by the library only!
398c2ecf20Sopenharmony_ci */
408c2ecf20Sopenharmony_ciextern struct linux_nodeops *prom_nodeops;
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci/* The functions... */
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci/* You must call prom_init() before using any of the library services,
458c2ecf20Sopenharmony_ci * preferably as early as possible.  Pass it the romvec pointer.
468c2ecf20Sopenharmony_ci */
478c2ecf20Sopenharmony_civoid prom_init(struct linux_romvec *rom_ptr);
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci/* Boot argument acquisition, returns the boot command line string. */
508c2ecf20Sopenharmony_cichar *prom_getbootargs(void);
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci/* Miscellaneous routines, don't really fit in any category per se. */
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci/* Reboot the machine with the command line passed. */
558c2ecf20Sopenharmony_civoid prom_reboot(char *boot_command);
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/* Evaluate the forth string passed. */
588c2ecf20Sopenharmony_civoid prom_feval(char *forth_string);
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci/* Enter the prom, with possibility of continuation with the 'go'
618c2ecf20Sopenharmony_ci * command in newer proms.
628c2ecf20Sopenharmony_ci */
638c2ecf20Sopenharmony_civoid prom_cmdline(void);
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci/* Enter the prom, with no chance of continuation for the stand-alone
668c2ecf20Sopenharmony_ci * which calls this.
678c2ecf20Sopenharmony_ci */
688c2ecf20Sopenharmony_civoid __noreturn prom_halt(void);
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci/* Set the PROM 'sync' callback function to the passed function pointer.
718c2ecf20Sopenharmony_ci * When the user gives the 'sync' command at the prom prompt while the
728c2ecf20Sopenharmony_ci * kernel is still active, the prom will call this routine.
738c2ecf20Sopenharmony_ci *
748c2ecf20Sopenharmony_ci * XXX The arguments are different on V0 vs. V2->higher proms, grrr! XXX
758c2ecf20Sopenharmony_ci */
768c2ecf20Sopenharmony_citypedef void (*sync_func_t)(void);
778c2ecf20Sopenharmony_civoid prom_setsync(sync_func_t func_ptr);
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci/* Acquire the IDPROM of the root node in the prom device tree.  This
808c2ecf20Sopenharmony_ci * gets passed a buffer where you would like it stuffed.  The return value
818c2ecf20Sopenharmony_ci * is the format type of this idprom or 0xff on error.
828c2ecf20Sopenharmony_ci */
838c2ecf20Sopenharmony_ciunsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size);
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci/* Get the prom major version. */
868c2ecf20Sopenharmony_ciint prom_version(void);
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci/* Get the prom plugin revision. */
898c2ecf20Sopenharmony_ciint prom_getrev(void);
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci/* Get the prom firmware revision. */
928c2ecf20Sopenharmony_ciint prom_getprev(void);
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci/* Write a buffer of characters to the console. */
958c2ecf20Sopenharmony_civoid prom_console_write_buf(const char *buf, int len);
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci/* Prom's internal routines, don't use in kernel/boot code. */
988c2ecf20Sopenharmony_ci__printf(1, 2) void prom_printf(const char *fmt, ...);
998c2ecf20Sopenharmony_civoid prom_write(const char *buf, unsigned int len);
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci/* Multiprocessor operations... */
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci/* Start the CPU with the given device tree node, context table, and context
1048c2ecf20Sopenharmony_ci * at the passed program counter.
1058c2ecf20Sopenharmony_ci */
1068c2ecf20Sopenharmony_ciint prom_startcpu(int cpunode, struct linux_prom_registers *context_table,
1078c2ecf20Sopenharmony_ci		  int context, char *program_counter);
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci/* Initialize the memory lists based upon the prom version. */
1108c2ecf20Sopenharmony_civoid prom_meminit(void);
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci/* PROM device tree traversal functions... */
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci/* Get the child node of the given node, or zero if no child exists. */
1158c2ecf20Sopenharmony_ciphandle prom_getchild(phandle parent_node);
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci/* Get the next sibling node of the given node, or zero if no further
1188c2ecf20Sopenharmony_ci * siblings exist.
1198c2ecf20Sopenharmony_ci */
1208c2ecf20Sopenharmony_ciphandle prom_getsibling(phandle node);
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci/* Get the length, at the passed node, of the given property type.
1238c2ecf20Sopenharmony_ci * Returns -1 on error (ie. no such property at this node).
1248c2ecf20Sopenharmony_ci */
1258c2ecf20Sopenharmony_ciint prom_getproplen(phandle thisnode, const char *property);
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci/* Fetch the requested property using the given buffer.  Returns
1288c2ecf20Sopenharmony_ci * the number of bytes the prom put into your buffer or -1 on error.
1298c2ecf20Sopenharmony_ci */
1308c2ecf20Sopenharmony_ciint __must_check prom_getproperty(phandle thisnode, const char *property,
1318c2ecf20Sopenharmony_ci				  char *prop_buffer, int propbuf_size);
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci/* Acquire an integer property. */
1348c2ecf20Sopenharmony_ciint prom_getint(phandle node, char *property);
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci/* Acquire an integer property, with a default value. */
1378c2ecf20Sopenharmony_ciint prom_getintdefault(phandle node, char *property, int defval);
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci/* Acquire a boolean property, 0=FALSE 1=TRUE. */
1408c2ecf20Sopenharmony_ciint prom_getbool(phandle node, char *prop);
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci/* Acquire a string property, null string on error. */
1438c2ecf20Sopenharmony_civoid prom_getstring(phandle node, char *prop, char *buf, int bufsize);
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci/* Search all siblings starting at the passed node for "name" matching
1468c2ecf20Sopenharmony_ci * the given string.  Returns the node on success, zero on failure.
1478c2ecf20Sopenharmony_ci */
1488c2ecf20Sopenharmony_ciphandle prom_searchsiblings(phandle node_start, char *name);
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci/* Returns the next property after the passed property for the given
1518c2ecf20Sopenharmony_ci * node.  Returns null string on failure.
1528c2ecf20Sopenharmony_ci */
1538c2ecf20Sopenharmony_cichar *prom_nextprop(phandle node, char *prev_property, char *buffer);
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci/* Returns phandle of the path specified */
1568c2ecf20Sopenharmony_ciphandle prom_finddevice(char *name);
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci/* Set the indicated property at the given node with the passed value.
1598c2ecf20Sopenharmony_ci * Returns the number of bytes of your value that the prom took.
1608c2ecf20Sopenharmony_ci */
1618c2ecf20Sopenharmony_ciint prom_setprop(phandle node, const char *prop_name, char *prop_value,
1628c2ecf20Sopenharmony_ci		 int value_size);
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ciphandle prom_inst2pkg(int);
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci/* Dorking with Bus ranges... */
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci/* Apply promlib probes OBIO ranges to registers. */
1698c2ecf20Sopenharmony_civoid prom_apply_obio_ranges(struct linux_prom_registers *obioregs, int nregs);
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci/* Apply ranges of any prom node (and optionally parent node as well) to registers. */
1728c2ecf20Sopenharmony_civoid prom_apply_generic_ranges(phandle node, phandle parent,
1738c2ecf20Sopenharmony_ci			       struct linux_prom_registers *sbusregs, int nregs);
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_civoid prom_ranges_init(void);
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci/* CPU probing helpers.  */
1788c2ecf20Sopenharmony_ciint cpu_find_by_instance(int instance, phandle *prom_node, int *mid);
1798c2ecf20Sopenharmony_ciint cpu_find_by_mid(int mid, phandle *prom_node);
1808c2ecf20Sopenharmony_ciint cpu_get_hwmid(phandle prom_node);
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ciextern spinlock_t prom_lock;
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci#endif /* !(__SPARC_OPLIB_H) */
185