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
1462306a36Sopenharmony_ci/* The master romvec pointer... */
1562306a36Sopenharmony_ciextern struct linux_romvec *romvec;
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci/* Enumeration to describe the prom major version we have detected. */
1862306a36Sopenharmony_cienum prom_major_version {
1962306a36Sopenharmony_ci	PROM_V0,      /* Original sun4c V0 prom */
2062306a36Sopenharmony_ci	PROM_V2,      /* sun4c and early sun4m V2 prom */
2162306a36Sopenharmony_ci	PROM_V3,      /* sun4m and later, up to sun4d/sun4e machines V3 */
2262306a36Sopenharmony_ci	PROM_P1275,   /* IEEE compliant ISA based Sun PROM, only sun4u */
2362306a36Sopenharmony_ci};
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ciextern enum prom_major_version prom_vers;
2662306a36Sopenharmony_ci/* Revision, and firmware revision. */
2762306a36Sopenharmony_ciextern unsigned int prom_rev, prom_prev;
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci/* Root node of the prom device tree, this stays constant after
3062306a36Sopenharmony_ci * initialization is complete.
3162306a36Sopenharmony_ci */
3262306a36Sopenharmony_ciextern int prom_root_node;
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci/* Pointer to prom structure containing the device tree traversal
3562306a36Sopenharmony_ci * and usage utility functions.  Only prom-lib should use these,
3662306a36Sopenharmony_ci * users use the interface defined by the library only!
3762306a36Sopenharmony_ci */
3862306a36Sopenharmony_ciextern struct linux_nodeops *prom_nodeops;
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci/* The functions... */
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci/* You must call prom_init() before using any of the library services,
4362306a36Sopenharmony_ci * preferably as early as possible.  Pass it the romvec pointer.
4462306a36Sopenharmony_ci */
4562306a36Sopenharmony_ciextern void prom_init(struct linux_romvec *rom_ptr);
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci/* Boot argument acquisition, returns the boot command line string. */
4862306a36Sopenharmony_ciextern char *prom_getbootargs(void);
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci/* Device utilities. */
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci/* Map and unmap devices in IO space at virtual addresses. Note that the
5362306a36Sopenharmony_ci * virtual address you pass is a request and the prom may put your mappings
5462306a36Sopenharmony_ci * somewhere else, so check your return value as that is where your new
5562306a36Sopenharmony_ci * mappings really are!
5662306a36Sopenharmony_ci *
5762306a36Sopenharmony_ci * Another note, these are only available on V2 or higher proms!
5862306a36Sopenharmony_ci */
5962306a36Sopenharmony_ciextern char *prom_mapio(char *virt_hint, int io_space, unsigned int phys_addr, unsigned int num_bytes);
6062306a36Sopenharmony_ciextern void prom_unmapio(char *virt_addr, unsigned int num_bytes);
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci/* Device operations. */
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci/* Open the device described by the passed string.  Note, that the format
6562306a36Sopenharmony_ci * of the string is different on V0 vs. V2->higher proms.  The caller must
6662306a36Sopenharmony_ci * know what he/she is doing!  Returns the device descriptor, an int.
6762306a36Sopenharmony_ci */
6862306a36Sopenharmony_ciextern int prom_devopen(char *device_string);
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci/* Close a previously opened device described by the passed integer
7162306a36Sopenharmony_ci * descriptor.
7262306a36Sopenharmony_ci */
7362306a36Sopenharmony_ciextern int prom_devclose(int device_handle);
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci/* Do a seek operation on the device described by the passed integer
7662306a36Sopenharmony_ci * descriptor.
7762306a36Sopenharmony_ci */
7862306a36Sopenharmony_ciextern void prom_seek(int device_handle, unsigned int seek_hival,
7962306a36Sopenharmony_ci		      unsigned int seek_lowval);
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci/* Machine memory configuration routine. */
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci/* This function returns a V0 format memory descriptor table, it has three
8462306a36Sopenharmony_ci * entries.  One for the total amount of physical ram on the machine, one
8562306a36Sopenharmony_ci * for the amount of physical ram available, and one describing the virtual
8662306a36Sopenharmony_ci * areas which are allocated by the prom.  So, in a sense the physical
8762306a36Sopenharmony_ci * available is a calculation of the total physical minus the physical mapped
8862306a36Sopenharmony_ci * by the prom with virtual mappings.
8962306a36Sopenharmony_ci *
9062306a36Sopenharmony_ci * These lists are returned pre-sorted, this should make your life easier
9162306a36Sopenharmony_ci * since the prom itself is way too lazy to do such nice things.
9262306a36Sopenharmony_ci */
9362306a36Sopenharmony_ciextern struct linux_mem_v0 *prom_meminfo(void);
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci/* Miscellaneous routines, don't really fit in any category per se. */
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci/* Reboot the machine with the command line passed. */
9862306a36Sopenharmony_ciextern void prom_reboot(char *boot_command);
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci/* Evaluate the forth string passed. */
10162306a36Sopenharmony_ciextern void prom_feval(char *forth_string);
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci/* Enter the prom, with possibility of continuation with the 'go'
10462306a36Sopenharmony_ci * command in newer proms.
10562306a36Sopenharmony_ci */
10662306a36Sopenharmony_ciextern void prom_cmdline(void);
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci/* Enter the prom, with no chance of continuation for the stand-alone
10962306a36Sopenharmony_ci * which calls this.
11062306a36Sopenharmony_ci */
11162306a36Sopenharmony_ciextern void prom_halt(void);
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci/* Set the PROM 'sync' callback function to the passed function pointer.
11462306a36Sopenharmony_ci * When the user gives the 'sync' command at the prom prompt while the
11562306a36Sopenharmony_ci * kernel is still active, the prom will call this routine.
11662306a36Sopenharmony_ci *
11762306a36Sopenharmony_ci * XXX The arguments are different on V0 vs. V2->higher proms, grrr! XXX
11862306a36Sopenharmony_ci */
11962306a36Sopenharmony_citypedef void (*sync_func_t)(void);
12062306a36Sopenharmony_ciextern void prom_setsync(sync_func_t func_ptr);
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci/* Acquire the IDPROM of the root node in the prom device tree.  This
12362306a36Sopenharmony_ci * gets passed a buffer where you would like it stuffed.  The return value
12462306a36Sopenharmony_ci * is the format type of this idprom or 0xff on error.
12562306a36Sopenharmony_ci */
12662306a36Sopenharmony_ciextern unsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size);
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ci/* Get the prom major version. */
12962306a36Sopenharmony_ciextern int prom_version(void);
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci/* Get the prom plugin revision. */
13262306a36Sopenharmony_ciextern int prom_getrev(void);
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci/* Get the prom firmware revision. */
13562306a36Sopenharmony_ciextern int prom_getprev(void);
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci/* Character operations to/from the console.... */
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci/* Non-blocking get character from console. */
14062306a36Sopenharmony_ciextern int prom_nbgetchar(void);
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci/* Non-blocking put character to console. */
14362306a36Sopenharmony_ciextern int prom_nbputchar(char character);
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci/* Blocking get character from console. */
14662306a36Sopenharmony_ciextern char prom_getchar(void);
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci/* Blocking put character to console. */
14962306a36Sopenharmony_ciextern void prom_putchar(char character);
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci/* Prom's internal printf routine, don't use in kernel/boot code. */
15262306a36Sopenharmony_civoid prom_printf(char *fmt, ...);
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ci/* Query for input device type */
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_cienum prom_input_device {
15762306a36Sopenharmony_ci	PROMDEV_IKBD,			/* input from keyboard */
15862306a36Sopenharmony_ci	PROMDEV_ITTYA,			/* input from ttya */
15962306a36Sopenharmony_ci	PROMDEV_ITTYB,			/* input from ttyb */
16062306a36Sopenharmony_ci	PROMDEV_I_UNK,
16162306a36Sopenharmony_ci};
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_ciextern enum prom_input_device prom_query_input_device(void);
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ci/* Query for output device type */
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_cienum prom_output_device {
16862306a36Sopenharmony_ci	PROMDEV_OSCREEN,		/* to screen */
16962306a36Sopenharmony_ci	PROMDEV_OTTYA,			/* to ttya */
17062306a36Sopenharmony_ci	PROMDEV_OTTYB,			/* to ttyb */
17162306a36Sopenharmony_ci	PROMDEV_O_UNK,
17262306a36Sopenharmony_ci};
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_ciextern enum prom_output_device prom_query_output_device(void);
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_ci/* Multiprocessor operations... */
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ci/* Start the CPU with the given device tree node, context table, and context
17962306a36Sopenharmony_ci * at the passed program counter.
18062306a36Sopenharmony_ci */
18162306a36Sopenharmony_ciextern int prom_startcpu(int cpunode, struct linux_prom_registers *context_table,
18262306a36Sopenharmony_ci			 int context, char *program_counter);
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci/* Stop the CPU with the passed device tree node. */
18562306a36Sopenharmony_ciextern int prom_stopcpu(int cpunode);
18662306a36Sopenharmony_ci
18762306a36Sopenharmony_ci/* Idle the CPU with the passed device tree node. */
18862306a36Sopenharmony_ciextern int prom_idlecpu(int cpunode);
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci/* Re-Start the CPU with the passed device tree node. */
19162306a36Sopenharmony_ciextern int prom_restartcpu(int cpunode);
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci/* PROM memory allocation facilities... */
19462306a36Sopenharmony_ci
19562306a36Sopenharmony_ci/* Allocated at possibly the given virtual address a chunk of the
19662306a36Sopenharmony_ci * indicated size.
19762306a36Sopenharmony_ci */
19862306a36Sopenharmony_ciextern char *prom_alloc(char *virt_hint, unsigned int size);
19962306a36Sopenharmony_ci
20062306a36Sopenharmony_ci/* Free a previously allocated chunk. */
20162306a36Sopenharmony_ciextern void prom_free(char *virt_addr, unsigned int size);
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_ci/* Sun4/sun4c specific memory-management startup hook. */
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_ci/* Map the passed segment in the given context at the passed
20662306a36Sopenharmony_ci * virtual address.
20762306a36Sopenharmony_ci */
20862306a36Sopenharmony_ciextern void prom_putsegment(int context, unsigned long virt_addr,
20962306a36Sopenharmony_ci			    int physical_segment);
21062306a36Sopenharmony_ci
21162306a36Sopenharmony_ci/* PROM device tree traversal functions... */
21262306a36Sopenharmony_ci
21362306a36Sopenharmony_ci/* Get the child node of the given node, or zero if no child exists. */
21462306a36Sopenharmony_ciextern int prom_getchild(int parent_node);
21562306a36Sopenharmony_ci
21662306a36Sopenharmony_ci/* Get the next sibling node of the given node, or zero if no further
21762306a36Sopenharmony_ci * siblings exist.
21862306a36Sopenharmony_ci */
21962306a36Sopenharmony_ciextern int prom_getsibling(int node);
22062306a36Sopenharmony_ci
22162306a36Sopenharmony_ci/* Get the length, at the passed node, of the given property type.
22262306a36Sopenharmony_ci * Returns -1 on error (ie. no such property at this node).
22362306a36Sopenharmony_ci */
22462306a36Sopenharmony_ciextern int prom_getproplen(int thisnode, char *property);
22562306a36Sopenharmony_ci
22662306a36Sopenharmony_ci/* Fetch the requested property using the given buffer.  Returns
22762306a36Sopenharmony_ci * the number of bytes the prom put into your buffer or -1 on error.
22862306a36Sopenharmony_ci */
22962306a36Sopenharmony_ciextern int prom_getproperty(int thisnode, char *property,
23062306a36Sopenharmony_ci			    char *prop_buffer, int propbuf_size);
23162306a36Sopenharmony_ci
23262306a36Sopenharmony_ci/* Acquire an integer property. */
23362306a36Sopenharmony_ciextern int prom_getint(int node, char *property);
23462306a36Sopenharmony_ci
23562306a36Sopenharmony_ci/* Acquire an integer property, with a default value. */
23662306a36Sopenharmony_ciextern int prom_getintdefault(int node, char *property, int defval);
23762306a36Sopenharmony_ci
23862306a36Sopenharmony_ci/* Acquire a boolean property, 0=FALSE 1=TRUE. */
23962306a36Sopenharmony_ciextern int prom_getbool(int node, char *prop);
24062306a36Sopenharmony_ci
24162306a36Sopenharmony_ci/* Acquire a string property, null string on error. */
24262306a36Sopenharmony_ciextern void prom_getstring(int node, char *prop, char *buf, int bufsize);
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_ci/* Does the passed node have the given "name"? YES=1 NO=0 */
24562306a36Sopenharmony_ciextern int prom_nodematch(int thisnode, char *name);
24662306a36Sopenharmony_ci
24762306a36Sopenharmony_ci/* Search all siblings starting at the passed node for "name" matching
24862306a36Sopenharmony_ci * the given string.  Returns the node on success, zero on failure.
24962306a36Sopenharmony_ci */
25062306a36Sopenharmony_ciextern int prom_searchsiblings(int node_start, char *name);
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_ci/* Return the first property type, as a string, for the given node.
25362306a36Sopenharmony_ci * Returns a null string on error.
25462306a36Sopenharmony_ci */
25562306a36Sopenharmony_ciextern char *prom_firstprop(int node);
25662306a36Sopenharmony_ci
25762306a36Sopenharmony_ci/* Returns the next property after the passed property for the given
25862306a36Sopenharmony_ci * node.  Returns null string on failure.
25962306a36Sopenharmony_ci */
26062306a36Sopenharmony_ciextern char *prom_nextprop(int node, char *prev_property);
26162306a36Sopenharmony_ci
26262306a36Sopenharmony_ci/* Returns 1 if the specified node has given property. */
26362306a36Sopenharmony_ciextern int prom_node_has_property(int node, char *property);
26462306a36Sopenharmony_ci
26562306a36Sopenharmony_ci/* Set the indicated property at the given node with the passed value.
26662306a36Sopenharmony_ci * Returns the number of bytes of your value that the prom took.
26762306a36Sopenharmony_ci */
26862306a36Sopenharmony_ciextern int prom_setprop(int node, char *prop_name, char *prop_value,
26962306a36Sopenharmony_ci			int value_size);
27062306a36Sopenharmony_ci
27162306a36Sopenharmony_ciextern int prom_pathtoinode(char *path);
27262306a36Sopenharmony_ciextern int prom_inst2pkg(int);
27362306a36Sopenharmony_ci
27462306a36Sopenharmony_ci/* Dorking with Bus ranges... */
27562306a36Sopenharmony_ci
27662306a36Sopenharmony_ci/* Adjust reg values with the passed ranges. */
27762306a36Sopenharmony_ciextern void prom_adjust_regs(struct linux_prom_registers *regp, int nregs,
27862306a36Sopenharmony_ci			     struct linux_prom_ranges *rangep, int nranges);
27962306a36Sopenharmony_ci
28062306a36Sopenharmony_ci/* Adjust child ranges with the passed parent ranges. */
28162306a36Sopenharmony_ciextern void prom_adjust_ranges(struct linux_prom_ranges *cranges, int ncranges,
28262306a36Sopenharmony_ci			       struct linux_prom_ranges *pranges, int npranges);
28362306a36Sopenharmony_ci
28462306a36Sopenharmony_ci/* Apply promlib probed OBIO ranges to registers. */
28562306a36Sopenharmony_ciextern void prom_apply_obio_ranges(struct linux_prom_registers *obioregs, int nregs);
28662306a36Sopenharmony_ci
28762306a36Sopenharmony_ci/* Apply ranges of any prom node (and optionally parent node as well) to registers. */
28862306a36Sopenharmony_ciextern void prom_apply_generic_ranges(int node, int parent,
28962306a36Sopenharmony_ci				      struct linux_prom_registers *sbusregs, int nregs);
29062306a36Sopenharmony_ci
29162306a36Sopenharmony_ci
29262306a36Sopenharmony_ci#endif /* !(__SPARC_OPLIB_H) */
293