18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/* oplib.h:  Describes the interface and available routines in the
38c2ecf20Sopenharmony_ci *           Linux Prom library.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 1995, 2007 David S. Miller (davem@davemloft.net)
68c2ecf20Sopenharmony_ci * Copyright (C) 1996 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifndef __SPARC64_OPLIB_H
108c2ecf20Sopenharmony_ci#define __SPARC64_OPLIB_H
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <asm/openprom.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/* OBP version string. */
158c2ecf20Sopenharmony_ciextern char prom_version[];
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/* Root node of the prom device tree, this stays constant after
188c2ecf20Sopenharmony_ci * initialization is complete.
198c2ecf20Sopenharmony_ci */
208c2ecf20Sopenharmony_ciextern phandle prom_root_node;
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci/* PROM stdout */
238c2ecf20Sopenharmony_ciextern int prom_stdout;
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/* /chosen node of the prom device tree, this stays constant after
268c2ecf20Sopenharmony_ci * initialization is complete.
278c2ecf20Sopenharmony_ci */
288c2ecf20Sopenharmony_ciextern phandle prom_chosen_node;
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/* Helper values and strings in arch/sparc64/kernel/head.S */
318c2ecf20Sopenharmony_ciextern const char prom_peer_name[];
328c2ecf20Sopenharmony_ciextern const char prom_compatible_name[];
338c2ecf20Sopenharmony_ciextern const char prom_root_compatible[];
348c2ecf20Sopenharmony_ciextern const char prom_cpu_compatible[];
358c2ecf20Sopenharmony_ciextern const char prom_finddev_name[];
368c2ecf20Sopenharmony_ciextern const char prom_chosen_path[];
378c2ecf20Sopenharmony_ciextern const char prom_cpu_path[];
388c2ecf20Sopenharmony_ciextern const char prom_getprop_name[];
398c2ecf20Sopenharmony_ciextern const char prom_mmu_name[];
408c2ecf20Sopenharmony_ciextern const char prom_callmethod_name[];
418c2ecf20Sopenharmony_ciextern const char prom_translate_name[];
428c2ecf20Sopenharmony_ciextern const char prom_map_name[];
438c2ecf20Sopenharmony_ciextern const char prom_unmap_name[];
448c2ecf20Sopenharmony_ciextern int prom_mmu_ihandle_cache;
458c2ecf20Sopenharmony_ciextern unsigned int prom_boot_mapped_pc;
468c2ecf20Sopenharmony_ciextern unsigned int prom_boot_mapping_mode;
478c2ecf20Sopenharmony_ciextern unsigned long prom_boot_mapping_phys_high, prom_boot_mapping_phys_low;
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_cistruct linux_mlist_p1275 {
508c2ecf20Sopenharmony_ci	struct linux_mlist_p1275 *theres_more;
518c2ecf20Sopenharmony_ci	unsigned long start_adr;
528c2ecf20Sopenharmony_ci	unsigned long num_bytes;
538c2ecf20Sopenharmony_ci};
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_cistruct linux_mem_p1275 {
568c2ecf20Sopenharmony_ci	struct linux_mlist_p1275 **p1275_totphys;
578c2ecf20Sopenharmony_ci	struct linux_mlist_p1275 **p1275_prommap;
588c2ecf20Sopenharmony_ci	struct linux_mlist_p1275 **p1275_available; /* What we can use */
598c2ecf20Sopenharmony_ci};
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci/* The functions... */
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci/* You must call prom_init() before using any of the library services,
648c2ecf20Sopenharmony_ci * preferably as early as possible.  Pass it the romvec pointer.
658c2ecf20Sopenharmony_ci */
668c2ecf20Sopenharmony_civoid prom_init(void *cif_handler);
678c2ecf20Sopenharmony_civoid prom_init_report(void);
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/* Boot argument acquisition, returns the boot command line string. */
708c2ecf20Sopenharmony_cichar *prom_getbootargs(void);
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci/* Miscellaneous routines, don't really fit in any category per se. */
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci/* Reboot the machine with the command line passed. */
758c2ecf20Sopenharmony_civoid prom_reboot(const char *boot_command);
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci/* Evaluate the forth string passed. */
788c2ecf20Sopenharmony_civoid prom_feval(const char *forth_string);
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci/* Enter the prom, with possibility of continuation with the 'go'
818c2ecf20Sopenharmony_ci * command in newer proms.
828c2ecf20Sopenharmony_ci */
838c2ecf20Sopenharmony_civoid prom_cmdline(void);
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci/* Enter the prom, with no chance of continuation for the stand-alone
868c2ecf20Sopenharmony_ci * which calls this.
878c2ecf20Sopenharmony_ci */
888c2ecf20Sopenharmony_civoid prom_halt(void) __attribute__ ((noreturn));
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci/* Halt and power-off the machine. */
918c2ecf20Sopenharmony_civoid prom_halt_power_off(void) __attribute__ ((noreturn));
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/* Acquire the IDPROM of the root node in the prom device tree.  This
948c2ecf20Sopenharmony_ci * gets passed a buffer where you would like it stuffed.  The return value
958c2ecf20Sopenharmony_ci * is the format type of this idprom or 0xff on error.
968c2ecf20Sopenharmony_ci */
978c2ecf20Sopenharmony_ciunsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size);
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci/* Write a buffer of characters to the console. */
1008c2ecf20Sopenharmony_civoid prom_console_write_buf(const char *buf, int len);
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci/* Prom's internal routines, don't use in kernel/boot code. */
1038c2ecf20Sopenharmony_ci__printf(1, 2) void prom_printf(const char *fmt, ...);
1048c2ecf20Sopenharmony_civoid prom_write(const char *buf, unsigned int len);
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci/* Multiprocessor operations... */
1078c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP
1088c2ecf20Sopenharmony_ci/* Start the CPU with the given device tree node at the passed program
1098c2ecf20Sopenharmony_ci * counter with the given arg passed in via register %o0.
1108c2ecf20Sopenharmony_ci */
1118c2ecf20Sopenharmony_civoid prom_startcpu(int cpunode, unsigned long pc, unsigned long arg);
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci/* Start the CPU with the given cpu ID at the passed program
1148c2ecf20Sopenharmony_ci * counter with the given arg passed in via register %o0.
1158c2ecf20Sopenharmony_ci */
1168c2ecf20Sopenharmony_civoid prom_startcpu_cpuid(int cpuid, unsigned long pc, unsigned long arg);
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci/* Stop the CPU with the given cpu ID.  */
1198c2ecf20Sopenharmony_civoid prom_stopcpu_cpuid(int cpuid);
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci/* Stop the current CPU. */
1228c2ecf20Sopenharmony_civoid prom_stopself(void);
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci/* Idle the current CPU. */
1258c2ecf20Sopenharmony_civoid prom_idleself(void);
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci/* Resume the CPU with the passed device tree node. */
1288c2ecf20Sopenharmony_civoid prom_resumecpu(int cpunode);
1298c2ecf20Sopenharmony_ci#endif
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci/* Power management interfaces. */
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci/* Put the current CPU to sleep. */
1348c2ecf20Sopenharmony_civoid prom_sleepself(void);
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci/* Put the entire system to sleep. */
1378c2ecf20Sopenharmony_ciint prom_sleepsystem(void);
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci/* Initiate a wakeup event. */
1408c2ecf20Sopenharmony_ciint prom_wakeupsystem(void);
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci/* MMU and memory related OBP interfaces. */
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci/* Get unique string identifying SIMM at given physical address. */
1458c2ecf20Sopenharmony_ciint prom_getunumber(int syndrome_code,
1468c2ecf20Sopenharmony_ci		    unsigned long phys_addr,
1478c2ecf20Sopenharmony_ci		    char *buf, int buflen);
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci/* Retain physical memory to the caller across soft resets. */
1508c2ecf20Sopenharmony_ciint prom_retain(const char *name, unsigned long size,
1518c2ecf20Sopenharmony_ci		unsigned long align, unsigned long *paddr);
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci/* Load explicit I/D TLB entries into the calling processor. */
1548c2ecf20Sopenharmony_cilong prom_itlb_load(unsigned long index,
1558c2ecf20Sopenharmony_ci		    unsigned long tte_data,
1568c2ecf20Sopenharmony_ci		    unsigned long vaddr);
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_cilong prom_dtlb_load(unsigned long index,
1598c2ecf20Sopenharmony_ci		    unsigned long tte_data,
1608c2ecf20Sopenharmony_ci		    unsigned long vaddr);
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci/* Map/Unmap client program address ranges.  First the format of
1638c2ecf20Sopenharmony_ci * the mapping mode argument.
1648c2ecf20Sopenharmony_ci */
1658c2ecf20Sopenharmony_ci#define PROM_MAP_WRITE	0x0001 /* Writable */
1668c2ecf20Sopenharmony_ci#define PROM_MAP_READ	0x0002 /* Readable - sw */
1678c2ecf20Sopenharmony_ci#define PROM_MAP_EXEC	0x0004 /* Executable - sw */
1688c2ecf20Sopenharmony_ci#define PROM_MAP_LOCKED	0x0010 /* Locked, use i/dtlb load calls for this instead */
1698c2ecf20Sopenharmony_ci#define PROM_MAP_CACHED	0x0020 /* Cacheable in both L1 and L2 caches */
1708c2ecf20Sopenharmony_ci#define PROM_MAP_SE	0x0040 /* Side-Effects */
1718c2ecf20Sopenharmony_ci#define PROM_MAP_GLOB	0x0080 /* Global */
1728c2ecf20Sopenharmony_ci#define PROM_MAP_IE	0x0100 /* Invert-Endianness */
1738c2ecf20Sopenharmony_ci#define PROM_MAP_DEFAULT (PROM_MAP_WRITE | PROM_MAP_READ | PROM_MAP_EXEC | PROM_MAP_CACHED)
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ciint prom_map(int mode, unsigned long size,
1768c2ecf20Sopenharmony_ci	     unsigned long vaddr, unsigned long paddr);
1778c2ecf20Sopenharmony_civoid prom_unmap(unsigned long size, unsigned long vaddr);
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci/* PROM device tree traversal functions... */
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci/* Get the child node of the given node, or zero if no child exists. */
1838c2ecf20Sopenharmony_ciphandle prom_getchild(phandle parent_node);
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci/* Get the next sibling node of the given node, or zero if no further
1868c2ecf20Sopenharmony_ci * siblings exist.
1878c2ecf20Sopenharmony_ci */
1888c2ecf20Sopenharmony_ciphandle prom_getsibling(phandle node);
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci/* Get the length, at the passed node, of the given property type.
1918c2ecf20Sopenharmony_ci * Returns -1 on error (ie. no such property at this node).
1928c2ecf20Sopenharmony_ci */
1938c2ecf20Sopenharmony_ciint prom_getproplen(phandle thisnode, const char *property);
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci/* Fetch the requested property using the given buffer.  Returns
1968c2ecf20Sopenharmony_ci * the number of bytes the prom put into your buffer or -1 on error.
1978c2ecf20Sopenharmony_ci */
1988c2ecf20Sopenharmony_ciint prom_getproperty(phandle thisnode, const char *property,
1998c2ecf20Sopenharmony_ci		     char *prop_buffer, int propbuf_size);
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci/* Acquire an integer property. */
2028c2ecf20Sopenharmony_ciint prom_getint(phandle node, const char *property);
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci/* Acquire an integer property, with a default value. */
2058c2ecf20Sopenharmony_ciint prom_getintdefault(phandle node, const char *property, int defval);
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci/* Acquire a boolean property, 0=FALSE 1=TRUE. */
2088c2ecf20Sopenharmony_ciint prom_getbool(phandle node, const char *prop);
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ci/* Acquire a string property, null string on error. */
2118c2ecf20Sopenharmony_civoid prom_getstring(phandle node, const char *prop, char *buf,
2128c2ecf20Sopenharmony_ci		    int bufsize);
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci/* Does the passed node have the given "name"? YES=1 NO=0 */
2158c2ecf20Sopenharmony_ciint prom_nodematch(phandle thisnode, const char *name);
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci/* Search all siblings starting at the passed node for "name" matching
2188c2ecf20Sopenharmony_ci * the given string.  Returns the node on success, zero on failure.
2198c2ecf20Sopenharmony_ci */
2208c2ecf20Sopenharmony_ciphandle prom_searchsiblings(phandle node_start, const char *name);
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci/* Return the first property type, as a string, for the given node.
2238c2ecf20Sopenharmony_ci * Returns a null string on error. Buffer should be at least 32B long.
2248c2ecf20Sopenharmony_ci */
2258c2ecf20Sopenharmony_cichar *prom_firstprop(phandle node, char *buffer);
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci/* Returns the next property after the passed property for the given
2288c2ecf20Sopenharmony_ci * node.  Returns null string on failure. Buffer should be at least 32B long.
2298c2ecf20Sopenharmony_ci */
2308c2ecf20Sopenharmony_cichar *prom_nextprop(phandle node, const char *prev_property, char *buf);
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci/* Returns 1 if the specified node has given property. */
2338c2ecf20Sopenharmony_ciint prom_node_has_property(phandle node, const char *property);
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci/* Returns phandle of the path specified */
2368c2ecf20Sopenharmony_ciphandle prom_finddevice(const char *name);
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci/* Set the indicated property at the given node with the passed value.
2398c2ecf20Sopenharmony_ci * Returns the number of bytes of your value that the prom took.
2408c2ecf20Sopenharmony_ci */
2418c2ecf20Sopenharmony_ciint prom_setprop(phandle node, const char *prop_name, char *prop_value,
2428c2ecf20Sopenharmony_ci		 int value_size);
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ciphandle prom_inst2pkg(int);
2458c2ecf20Sopenharmony_civoid prom_sun4v_guest_soft_state(void);
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ciint prom_ihandle2path(int handle, char *buffer, int bufsize);
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci/* Client interface level routines. */
2508c2ecf20Sopenharmony_civoid p1275_cmd_direct(unsigned long *);
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci#endif /* !(__SPARC64_OPLIB_H) */
253