18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __SPARC_OPENPROM_H
38c2ecf20Sopenharmony_ci#define __SPARC_OPENPROM_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci/* openprom.h:  Prom structures and defines for access to the OPENBOOT
68c2ecf20Sopenharmony_ci *              prom routines and data areas.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Copyright (C) 1995,1996 David S. Miller (davem@caip.rutgers.edu)
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci/* Empirical constants... */
128c2ecf20Sopenharmony_ci#define LINUX_OPPROM_MAGIC      0x10010407
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
158c2ecf20Sopenharmony_ci#include <linux/of.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/* V0 prom device operations. */
188c2ecf20Sopenharmony_cistruct linux_dev_v0_funcs {
198c2ecf20Sopenharmony_ci	int (*v0_devopen)(char *device_str);
208c2ecf20Sopenharmony_ci	int (*v0_devclose)(int dev_desc);
218c2ecf20Sopenharmony_ci	int (*v0_rdblkdev)(int dev_desc, int num_blks, int blk_st, char *buf);
228c2ecf20Sopenharmony_ci	int (*v0_wrblkdev)(int dev_desc, int num_blks, int blk_st, char *buf);
238c2ecf20Sopenharmony_ci	int (*v0_wrnetdev)(int dev_desc, int num_bytes, char *buf);
248c2ecf20Sopenharmony_ci	int (*v0_rdnetdev)(int dev_desc, int num_bytes, char *buf);
258c2ecf20Sopenharmony_ci	int (*v0_rdchardev)(int dev_desc, int num_bytes, int dummy, char *buf);
268c2ecf20Sopenharmony_ci	int (*v0_wrchardev)(int dev_desc, int num_bytes, int dummy, char *buf);
278c2ecf20Sopenharmony_ci	int (*v0_seekdev)(int dev_desc, long logical_offst, int from);
288c2ecf20Sopenharmony_ci};
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/* V2 and later prom device operations. */
318c2ecf20Sopenharmony_cistruct linux_dev_v2_funcs {
328c2ecf20Sopenharmony_ci	phandle (*v2_inst2pkg)(int d);	/* Convert ihandle to phandle */
338c2ecf20Sopenharmony_ci	char * (*v2_dumb_mem_alloc)(char *va, unsigned int sz);
348c2ecf20Sopenharmony_ci	void (*v2_dumb_mem_free)(char *va, unsigned int sz);
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci	/* To map devices into virtual I/O space. */
378c2ecf20Sopenharmony_ci	char * (*v2_dumb_mmap)(char *virta, int which_io, unsigned int paddr, unsigned int sz);
388c2ecf20Sopenharmony_ci	void (*v2_dumb_munmap)(char *virta, unsigned int size);
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci	int (*v2_dev_open)(char *devpath);
418c2ecf20Sopenharmony_ci	void (*v2_dev_close)(int d);
428c2ecf20Sopenharmony_ci	int (*v2_dev_read)(int d, char *buf, int nbytes);
438c2ecf20Sopenharmony_ci	int (*v2_dev_write)(int d, const char *buf, int nbytes);
448c2ecf20Sopenharmony_ci	int (*v2_dev_seek)(int d, int hi, int lo);
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci	/* Never issued (multistage load support) */
478c2ecf20Sopenharmony_ci	void (*v2_wheee2)(void);
488c2ecf20Sopenharmony_ci	void (*v2_wheee3)(void);
498c2ecf20Sopenharmony_ci};
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cistruct linux_mlist_v0 {
528c2ecf20Sopenharmony_ci	struct linux_mlist_v0 *theres_more;
538c2ecf20Sopenharmony_ci	unsigned int start_adr;
548c2ecf20Sopenharmony_ci	unsigned int num_bytes;
558c2ecf20Sopenharmony_ci};
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_cistruct linux_mem_v0 {
588c2ecf20Sopenharmony_ci	struct linux_mlist_v0 **v0_totphys;
598c2ecf20Sopenharmony_ci	struct linux_mlist_v0 **v0_prommap;
608c2ecf20Sopenharmony_ci	struct linux_mlist_v0 **v0_available; /* What we can use */
618c2ecf20Sopenharmony_ci};
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci/* Arguments sent to the kernel from the boot prompt. */
648c2ecf20Sopenharmony_cistruct linux_arguments_v0 {
658c2ecf20Sopenharmony_ci	char *argv[8];
668c2ecf20Sopenharmony_ci	char args[100];
678c2ecf20Sopenharmony_ci	char boot_dev[2];
688c2ecf20Sopenharmony_ci	int boot_dev_ctrl;
698c2ecf20Sopenharmony_ci	int boot_dev_unit;
708c2ecf20Sopenharmony_ci	int dev_partition;
718c2ecf20Sopenharmony_ci	char *kernel_file_name;
728c2ecf20Sopenharmony_ci	void *aieee1;           /* XXX */
738c2ecf20Sopenharmony_ci};
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci/* V2 and up boot things. */
768c2ecf20Sopenharmony_cistruct linux_bootargs_v2 {
778c2ecf20Sopenharmony_ci	char **bootpath;
788c2ecf20Sopenharmony_ci	char **bootargs;
798c2ecf20Sopenharmony_ci	int *fd_stdin;
808c2ecf20Sopenharmony_ci	int *fd_stdout;
818c2ecf20Sopenharmony_ci};
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci/* The top level PROM vector. */
848c2ecf20Sopenharmony_cistruct linux_romvec {
858c2ecf20Sopenharmony_ci	/* Version numbers. */
868c2ecf20Sopenharmony_ci	unsigned int pv_magic_cookie;
878c2ecf20Sopenharmony_ci	unsigned int pv_romvers;
888c2ecf20Sopenharmony_ci	unsigned int pv_plugin_revision;
898c2ecf20Sopenharmony_ci	unsigned int pv_printrev;
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci	/* Version 0 memory descriptors. */
928c2ecf20Sopenharmony_ci	struct linux_mem_v0 pv_v0mem;
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci	/* Node operations. */
958c2ecf20Sopenharmony_ci	struct linux_nodeops *pv_nodeops;
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	char **pv_bootstr;
988c2ecf20Sopenharmony_ci	struct linux_dev_v0_funcs pv_v0devops;
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	char *pv_stdin;
1018c2ecf20Sopenharmony_ci	char *pv_stdout;
1028c2ecf20Sopenharmony_ci#define	PROMDEV_KBD	0		/* input from keyboard */
1038c2ecf20Sopenharmony_ci#define	PROMDEV_SCREEN	0		/* output to screen */
1048c2ecf20Sopenharmony_ci#define	PROMDEV_TTYA	1		/* in/out to ttya */
1058c2ecf20Sopenharmony_ci#define	PROMDEV_TTYB	2		/* in/out to ttyb */
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	/* Blocking getchar/putchar.  NOT REENTRANT! (grr) */
1088c2ecf20Sopenharmony_ci	int (*pv_getchar)(void);
1098c2ecf20Sopenharmony_ci	void (*pv_putchar)(int ch);
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci	/* Non-blocking variants. */
1128c2ecf20Sopenharmony_ci	int (*pv_nbgetchar)(void);
1138c2ecf20Sopenharmony_ci	int (*pv_nbputchar)(int ch);
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci	void (*pv_putstr)(char *str, int len);
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci	/* Miscellany. */
1188c2ecf20Sopenharmony_ci	void (*pv_reboot)(char *bootstr);
1198c2ecf20Sopenharmony_ci	void (*pv_printf)(__const__ char *fmt, ...);
1208c2ecf20Sopenharmony_ci	void (*pv_abort)(void);
1218c2ecf20Sopenharmony_ci	__volatile__ int *pv_ticks;
1228c2ecf20Sopenharmony_ci	void (*pv_halt)(void);
1238c2ecf20Sopenharmony_ci	void (**pv_synchook)(void);
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci	/* Evaluate a forth string, not different proto for V0 and V2->up. */
1268c2ecf20Sopenharmony_ci	union {
1278c2ecf20Sopenharmony_ci		void (*v0_eval)(int len, char *str);
1288c2ecf20Sopenharmony_ci		void (*v2_eval)(char *str);
1298c2ecf20Sopenharmony_ci	} pv_fortheval;
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	struct linux_arguments_v0 **pv_v0bootargs;
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci	/* Get ether address. */
1348c2ecf20Sopenharmony_ci	unsigned int (*pv_enaddr)(int d, char *enaddr);
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci	struct linux_bootargs_v2 pv_v2bootargs;
1378c2ecf20Sopenharmony_ci	struct linux_dev_v2_funcs pv_v2devops;
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci	int filler[15];
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci	/* This one is sun4c/sun4 only. */
1428c2ecf20Sopenharmony_ci	void (*pv_setctxt)(int ctxt, char *va, int pmeg);
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci	/* Prom version 3 Multiprocessor routines. This stuff is crazy.
1458c2ecf20Sopenharmony_ci	 * No joke. Calling these when there is only one cpu probably
1468c2ecf20Sopenharmony_ci	 * crashes the machine, have to test this. :-)
1478c2ecf20Sopenharmony_ci	 */
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci	/* v3_cpustart() will start the cpu 'whichcpu' in mmu-context
1508c2ecf20Sopenharmony_ci	 * 'thiscontext' executing at address 'prog_counter'
1518c2ecf20Sopenharmony_ci	 */
1528c2ecf20Sopenharmony_ci	int (*v3_cpustart)(unsigned int whichcpu, int ctxtbl_ptr,
1538c2ecf20Sopenharmony_ci			   int thiscontext, char *prog_counter);
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci	/* v3_cpustop() will cause cpu 'whichcpu' to stop executing
1568c2ecf20Sopenharmony_ci	 * until a resume cpu call is made.
1578c2ecf20Sopenharmony_ci	 */
1588c2ecf20Sopenharmony_ci	int (*v3_cpustop)(unsigned int whichcpu);
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci	/* v3_cpuidle() will idle cpu 'whichcpu' until a stop or
1618c2ecf20Sopenharmony_ci	 * resume cpu call is made.
1628c2ecf20Sopenharmony_ci	 */
1638c2ecf20Sopenharmony_ci	int (*v3_cpuidle)(unsigned int whichcpu);
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci	/* v3_cpuresume() will resume processor 'whichcpu' executing
1668c2ecf20Sopenharmony_ci	 * starting with whatever 'pc' and 'npc' were left at the
1678c2ecf20Sopenharmony_ci	 * last 'idle' or 'stop' call.
1688c2ecf20Sopenharmony_ci	 */
1698c2ecf20Sopenharmony_ci	int (*v3_cpuresume)(unsigned int whichcpu);
1708c2ecf20Sopenharmony_ci};
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci/* Routines for traversing the prom device tree. */
1738c2ecf20Sopenharmony_cistruct linux_nodeops {
1748c2ecf20Sopenharmony_ci	phandle (*no_nextnode)(phandle node);
1758c2ecf20Sopenharmony_ci	phandle (*no_child)(phandle node);
1768c2ecf20Sopenharmony_ci	int (*no_proplen)(phandle node, const char *name);
1778c2ecf20Sopenharmony_ci	int (*no_getprop)(phandle node, const char *name, char *val);
1788c2ecf20Sopenharmony_ci	int (*no_setprop)(phandle node, const char *name, char *val, int len);
1798c2ecf20Sopenharmony_ci	char * (*no_nextprop)(phandle node, char *name);
1808c2ecf20Sopenharmony_ci};
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci/* More fun PROM structures for device probing. */
1838c2ecf20Sopenharmony_ci#if defined(__sparc__) && defined(__arch64__)
1848c2ecf20Sopenharmony_ci#define PROMREG_MAX     24
1858c2ecf20Sopenharmony_ci#define PROMVADDR_MAX   16
1868c2ecf20Sopenharmony_ci#define PROMINTR_MAX    32
1878c2ecf20Sopenharmony_ci#else
1888c2ecf20Sopenharmony_ci#define PROMREG_MAX     16
1898c2ecf20Sopenharmony_ci#define PROMVADDR_MAX   16
1908c2ecf20Sopenharmony_ci#define PROMINTR_MAX    15
1918c2ecf20Sopenharmony_ci#endif
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_cistruct linux_prom_registers {
1948c2ecf20Sopenharmony_ci	unsigned int which_io;	/* hi part of physical address */
1958c2ecf20Sopenharmony_ci	unsigned int phys_addr;	/* The physical address of this register */
1968c2ecf20Sopenharmony_ci	unsigned int reg_size;	/* How many bytes does this register take up? */
1978c2ecf20Sopenharmony_ci};
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_cistruct linux_prom64_registers {
2008c2ecf20Sopenharmony_ci	unsigned long phys_addr;
2018c2ecf20Sopenharmony_ci	unsigned long reg_size;
2028c2ecf20Sopenharmony_ci};
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_cistruct linux_prom_irqs {
2058c2ecf20Sopenharmony_ci	int pri;    /* IRQ priority */
2068c2ecf20Sopenharmony_ci	int vector; /* This is foobar, what does it do? */
2078c2ecf20Sopenharmony_ci};
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci/* Element of the "ranges" vector */
2108c2ecf20Sopenharmony_cistruct linux_prom_ranges {
2118c2ecf20Sopenharmony_ci	unsigned int ot_child_space;
2128c2ecf20Sopenharmony_ci	unsigned int ot_child_base;		/* Bus feels this */
2138c2ecf20Sopenharmony_ci	unsigned int ot_parent_space;
2148c2ecf20Sopenharmony_ci	unsigned int ot_parent_base;		/* CPU looks from here */
2158c2ecf20Sopenharmony_ci	unsigned int or_size;
2168c2ecf20Sopenharmony_ci};
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci/*
2198c2ecf20Sopenharmony_ci * Ranges and reg properties are a bit different for PCI.
2208c2ecf20Sopenharmony_ci */
2218c2ecf20Sopenharmony_ci#if defined(__sparc__) && defined(__arch64__)
2228c2ecf20Sopenharmony_cistruct linux_prom_pci_registers {
2238c2ecf20Sopenharmony_ci	unsigned int phys_hi;
2248c2ecf20Sopenharmony_ci	unsigned int phys_mid;
2258c2ecf20Sopenharmony_ci	unsigned int phys_lo;
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci	unsigned int size_hi;
2288c2ecf20Sopenharmony_ci	unsigned int size_lo;
2298c2ecf20Sopenharmony_ci};
2308c2ecf20Sopenharmony_ci#else
2318c2ecf20Sopenharmony_cistruct linux_prom_pci_registers {
2328c2ecf20Sopenharmony_ci	/*
2338c2ecf20Sopenharmony_ci	 * We don't know what information this field contain.
2348c2ecf20Sopenharmony_ci	 * We guess, PCI device function is in bits 15:8
2358c2ecf20Sopenharmony_ci	 * So, ...
2368c2ecf20Sopenharmony_ci	 */
2378c2ecf20Sopenharmony_ci	unsigned int which_io;  /* Let it be which_io */
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ci	unsigned int phys_hi;
2408c2ecf20Sopenharmony_ci	unsigned int phys_lo;
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ci	unsigned int size_hi;
2438c2ecf20Sopenharmony_ci	unsigned int size_lo;
2448c2ecf20Sopenharmony_ci};
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_ci#endif
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_cistruct linux_prom_pci_ranges {
2498c2ecf20Sopenharmony_ci	unsigned int child_phys_hi;	/* Only certain bits are encoded here. */
2508c2ecf20Sopenharmony_ci	unsigned int child_phys_mid;
2518c2ecf20Sopenharmony_ci	unsigned int child_phys_lo;
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci	unsigned int parent_phys_hi;
2548c2ecf20Sopenharmony_ci	unsigned int parent_phys_lo;
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ci	unsigned int size_hi;
2578c2ecf20Sopenharmony_ci	unsigned int size_lo;
2588c2ecf20Sopenharmony_ci};
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_cistruct linux_prom_pci_intmap {
2618c2ecf20Sopenharmony_ci	unsigned int phys_hi;
2628c2ecf20Sopenharmony_ci	unsigned int phys_mid;
2638c2ecf20Sopenharmony_ci	unsigned int phys_lo;
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci	unsigned int interrupt;
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci	int          cnode;
2688c2ecf20Sopenharmony_ci	unsigned int cinterrupt;
2698c2ecf20Sopenharmony_ci};
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_cistruct linux_prom_pci_intmask {
2728c2ecf20Sopenharmony_ci	unsigned int phys_hi;
2738c2ecf20Sopenharmony_ci	unsigned int phys_mid;
2748c2ecf20Sopenharmony_ci	unsigned int phys_lo;
2758c2ecf20Sopenharmony_ci	unsigned int interrupt;
2768c2ecf20Sopenharmony_ci};
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci#endif /* !(__ASSEMBLY__) */
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_ci#endif /* !(__SPARC_OPENPROM_H) */
281