162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * oplib.h:  Describes the interface and available routines in the
462306a36Sopenharmony_ci *           Linux Prom library.
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#ifndef __SPARC_OPLIB_H
1062306a36Sopenharmony_ci#define __SPARC_OPLIB_H
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#include <asm/openprom.h>
1362306a36Sopenharmony_ci#include <linux/spinlock.h>
1462306a36Sopenharmony_ci#include <linux/compiler.h>
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci/* The master romvec pointer... */
1762306a36Sopenharmony_ciextern struct linux_romvec *romvec;
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci/* Enumeration to describe the prom major version we have detected. */
2062306a36Sopenharmony_cienum prom_major_version {
2162306a36Sopenharmony_ci	PROM_V0,      /* Original sun4c V0 prom */
2262306a36Sopenharmony_ci	PROM_V2,      /* sun4c and early sun4m V2 prom */
2362306a36Sopenharmony_ci	PROM_V3,      /* sun4m and later, up to sun4d/sun4e machines V3 */
2462306a36Sopenharmony_ci	PROM_P1275,   /* IEEE compliant ISA based Sun PROM, only sun4u */
2562306a36Sopenharmony_ci};
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ciextern enum prom_major_version prom_vers;
2862306a36Sopenharmony_ci/* Revision, and firmware revision. */
2962306a36Sopenharmony_ciextern unsigned int prom_rev, prom_prev;
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci/* Root node of the prom device tree, this stays constant after
3262306a36Sopenharmony_ci * initialization is complete.
3362306a36Sopenharmony_ci */
3462306a36Sopenharmony_ciextern phandle prom_root_node;
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci/* Pointer to prom structure containing the device tree traversal
3762306a36Sopenharmony_ci * and usage utility functions.  Only prom-lib should use these,
3862306a36Sopenharmony_ci * users use the interface defined by the library only!
3962306a36Sopenharmony_ci */
4062306a36Sopenharmony_ciextern struct linux_nodeops *prom_nodeops;
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci/* The functions... */
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci/* You must call prom_init() before using any of the library services,
4562306a36Sopenharmony_ci * preferably as early as possible.  Pass it the romvec pointer.
4662306a36Sopenharmony_ci */
4762306a36Sopenharmony_civoid prom_init(struct linux_romvec *rom_ptr);
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci/* Boot argument acquisition, returns the boot command line string. */
5062306a36Sopenharmony_cichar *prom_getbootargs(void);
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci/* Miscellaneous routines, don't really fit in any category per se. */
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci/* Reboot the machine with the command line passed. */
5562306a36Sopenharmony_civoid prom_reboot(char *boot_command);
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci/* Evaluate the forth string passed. */
5862306a36Sopenharmony_civoid prom_feval(char *forth_string);
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci/* Enter the prom, with possibility of continuation with the 'go'
6162306a36Sopenharmony_ci * command in newer proms.
6262306a36Sopenharmony_ci */
6362306a36Sopenharmony_civoid prom_cmdline(void);
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci/* Enter the prom, with no chance of continuation for the stand-alone
6662306a36Sopenharmony_ci * which calls this.
6762306a36Sopenharmony_ci */
6862306a36Sopenharmony_civoid __noreturn prom_halt(void);
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci/* Set the PROM 'sync' callback function to the passed function pointer.
7162306a36Sopenharmony_ci * When the user gives the 'sync' command at the prom prompt while the
7262306a36Sopenharmony_ci * kernel is still active, the prom will call this routine.
7362306a36Sopenharmony_ci *
7462306a36Sopenharmony_ci * XXX The arguments are different on V0 vs. V2->higher proms, grrr! XXX
7562306a36Sopenharmony_ci */
7662306a36Sopenharmony_citypedef void (*sync_func_t)(void);
7762306a36Sopenharmony_civoid prom_setsync(sync_func_t func_ptr);
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci/* Acquire the IDPROM of the root node in the prom device tree.  This
8062306a36Sopenharmony_ci * gets passed a buffer where you would like it stuffed.  The return value
8162306a36Sopenharmony_ci * is the format type of this idprom or 0xff on error.
8262306a36Sopenharmony_ci */
8362306a36Sopenharmony_ciunsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size);
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci/* Get the prom major version. */
8662306a36Sopenharmony_ciint prom_version(void);
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci/* Get the prom plugin revision. */
8962306a36Sopenharmony_ciint prom_getrev(void);
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci/* Get the prom firmware revision. */
9262306a36Sopenharmony_ciint prom_getprev(void);
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci/* Write a buffer of characters to the console. */
9562306a36Sopenharmony_civoid prom_console_write_buf(const char *buf, int len);
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci/* Prom's internal routines, don't use in kernel/boot code. */
9862306a36Sopenharmony_ci__printf(1, 2) void prom_printf(const char *fmt, ...);
9962306a36Sopenharmony_civoid prom_write(const char *buf, unsigned int len);
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci/* Multiprocessor operations... */
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci/* Start the CPU with the given device tree node, context table, and context
10462306a36Sopenharmony_ci * at the passed program counter.
10562306a36Sopenharmony_ci */
10662306a36Sopenharmony_ciint prom_startcpu(int cpunode, struct linux_prom_registers *context_table,
10762306a36Sopenharmony_ci		  int context, char *program_counter);
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci/* Initialize the memory lists based upon the prom version. */
11062306a36Sopenharmony_civoid prom_meminit(void);
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci/* PROM device tree traversal functions... */
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci/* Get the child node of the given node, or zero if no child exists. */
11562306a36Sopenharmony_ciphandle prom_getchild(phandle parent_node);
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci/* Get the next sibling node of the given node, or zero if no further
11862306a36Sopenharmony_ci * siblings exist.
11962306a36Sopenharmony_ci */
12062306a36Sopenharmony_ciphandle prom_getsibling(phandle node);
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci/* Get the length, at the passed node, of the given property type.
12362306a36Sopenharmony_ci * Returns -1 on error (ie. no such property at this node).
12462306a36Sopenharmony_ci */
12562306a36Sopenharmony_ciint prom_getproplen(phandle thisnode, const char *property);
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ci/* Fetch the requested property using the given buffer.  Returns
12862306a36Sopenharmony_ci * the number of bytes the prom put into your buffer or -1 on error.
12962306a36Sopenharmony_ci */
13062306a36Sopenharmony_ciint __must_check prom_getproperty(phandle thisnode, const char *property,
13162306a36Sopenharmony_ci				  char *prop_buffer, int propbuf_size);
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ci/* Acquire an integer property. */
13462306a36Sopenharmony_ciint prom_getint(phandle node, char *property);
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci/* Acquire an integer property, with a default value. */
13762306a36Sopenharmony_ciint prom_getintdefault(phandle node, char *property, int defval);
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci/* Acquire a boolean property, 0=FALSE 1=TRUE. */
14062306a36Sopenharmony_ciint prom_getbool(phandle node, char *prop);
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci/* Acquire a string property, null string on error. */
14362306a36Sopenharmony_civoid prom_getstring(phandle node, char *prop, char *buf, int bufsize);
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci/* Search all siblings starting at the passed node for "name" matching
14662306a36Sopenharmony_ci * the given string.  Returns the node on success, zero on failure.
14762306a36Sopenharmony_ci */
14862306a36Sopenharmony_ciphandle prom_searchsiblings(phandle node_start, char *name);
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_ci/* Returns the next property after the passed property for the given
15162306a36Sopenharmony_ci * node.  Returns null string on failure.
15262306a36Sopenharmony_ci */
15362306a36Sopenharmony_cichar *prom_nextprop(phandle node, char *prev_property, char *buffer);
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci/* Returns phandle of the path specified */
15662306a36Sopenharmony_ciphandle prom_finddevice(char *name);
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ci/* Set the indicated property at the given node with the passed value.
15962306a36Sopenharmony_ci * Returns the number of bytes of your value that the prom took.
16062306a36Sopenharmony_ci */
16162306a36Sopenharmony_ciint prom_setprop(phandle node, const char *prop_name, char *prop_value,
16262306a36Sopenharmony_ci		 int value_size);
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ciphandle prom_inst2pkg(int);
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_ci/* Dorking with Bus ranges... */
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_ci/* Apply promlib probes OBIO ranges to registers. */
16962306a36Sopenharmony_civoid prom_apply_obio_ranges(struct linux_prom_registers *obioregs, int nregs);
17062306a36Sopenharmony_ci
17162306a36Sopenharmony_ci/* Apply ranges of any prom node (and optionally parent node as well) to registers. */
17262306a36Sopenharmony_civoid prom_apply_generic_ranges(phandle node, phandle parent,
17362306a36Sopenharmony_ci			       struct linux_prom_registers *sbusregs, int nregs);
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_civoid prom_ranges_init(void);
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ci/* CPU probing helpers.  */
17862306a36Sopenharmony_ciint cpu_find_by_instance(int instance, phandle *prom_node, int *mid);
17962306a36Sopenharmony_ciint cpu_find_by_mid(int mid, phandle *prom_node);
18062306a36Sopenharmony_ciint cpu_get_hwmid(phandle prom_node);
18162306a36Sopenharmony_ci
18262306a36Sopenharmony_ciextern spinlock_t prom_lock;
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci#endif /* !(__SPARC_OPLIB_H) */
185