155118Storek /*
2*63320Sbostic  * Copyright (c) 1992, 1993
3*63320Sbostic  *	The Regents of the University of California.  All rights reserved.
455118Storek  *
555118Storek  * This code is derived from software contributed to Berkeley by
655118Storek  * Jan-Simon Pendry.
755118Storek  *
855118Storek  * %sccs.include.redist.c%
955118Storek  *
10*63320Sbostic  *	@(#)bsd_openprom.h	8.1 (Berkeley) 06/11/93
1155118Storek  *
1259198Storek  * from: $Header: bsd_openprom.h,v 1.3 92/09/09 00:41:33 leres Exp $
1355118Storek  */
1455118Storek 
1555118Storek /*
1655118Storek  * This file defines the interface between the kernel and the Openboot PROM.
1755118Storek  * N.B.: this has been tested only on interface versions 0 and 2 (we have
1855118Storek  * never seen interface version 1).
1955118Storek  */
2055118Storek 
2155118Storek /*
2255118Storek  * The v0 interface tells us what virtual memory to scan to avoid PMEG
2355118Storek  * conflicts, but the v2 interface fails to do so, and we must `magically'
2455118Storek  * know where the OPENPROM lives in virtual space.
2555118Storek  */
2655118Storek #define	OPENPROM_STARTVADDR	0xffd00000
2755118Storek #define	OPENPROM_ENDVADDR	0xfff00000
2855118Storek 
2955118Storek #define	OPENPROM_MAGIC 0x10010407
3055118Storek 
3155118Storek /*
3255118Storek  * Version 0 PROM vector device operations (collected here to emphasise that
3355118Storek  * they are deprecated).  Open and close are obvious.  Read and write are
3455118Storek  * segregated according to the device type (block, network, or character);
3555118Storek  * this is unnecessary and was eliminated from the v2 device operations, but
3655118Storek  * we are stuck with it.
3755118Storek  *
3855118Storek  * Seek is probably only useful on tape devices, since the only character
3955118Storek  * devices are the serial ports.
4055118Storek  *
4155118Storek  * Note that a v0 device name is always exactly two characters ("sd", "le",
4255118Storek  * and so forth).
4355118Storek  */
4455118Storek struct v0devops {
4555118Storek 	int	(*v0_open)(char *dev);
4655118Storek 	int	(*v0_close)(int d);
4755118Storek 	int	(*v0_rbdev)(int d, int nblks, int blkno, caddr_t addr);
4855118Storek 	int	(*v0_wbdev)(int d, int nblks, int blkno, caddr_t addr);
4955118Storek 	int	(*v0_wnet)(int d, int nbytes, caddr_t addr);
5055118Storek 	int	(*v0_rnet)(int d, int nbytes, caddr_t addr);
5155118Storek 	int	(*v0_rcdev)(int d, int nbytes, int, caddr_t addr);
5255118Storek 	int	(*v0_wcdev)(int d, int nbytes, int, caddr_t addr);
5355118Storek 	int	(*v0_seek)(int d, long offset, int whence);
5455118Storek };
5555118Storek 
5655118Storek /*
5755118Storek  * Version 2 device operations.  Open takes a device `path' such as
5855118Storek  * /sbus/le@0,c00000,0 or /sbus/esp@.../sd@0,0, which means it can open
5955118Storek  * anything anywhere, without any magic translation.
6055118Storek  *
6155118Storek  * The memory allocator and map functions are included here even though
6255118Storek  * they relate only indirectly to devices (e.g., mmap is good for mapping
6355118Storek  * device memory, and drivers need to allocate space in which to record
6455118Storek  * the device state).
6555118Storek  */
6655118Storek struct v2devops {
6755118Storek 	int	(*v2_xxx1)(int d);	/* ??? convert fd to something */
6855118Storek 
6955118Storek 	/* Memory allocation and release. */
7055118Storek 	caddr_t	(*v2_malloc)(caddr_t va, u_int sz);
7155118Storek 	void	(*v2_free)(caddr_t va, u_int sz);
7255118Storek 
7355118Storek 	/* Device memory mapper. */
7455118Storek 	caddr_t	(*v2_mmap)(caddr_t va, int asi, u_int pa, u_int sz);
7555118Storek 	void	(*v2_munmap)(caddr_t va, u_int sz);
7655118Storek 
7755118Storek 	/* Device open, close, etc. */
7855118Storek 	int	(*v2_open)(char *devpath);
7955118Storek 	void	(*v2_close)(int d);
8055118Storek 	int	(*v2_read)(int d, caddr_t buf, int nbytes);
8155118Storek 	int	(*v2_write)(int d, caddr_t buf, int nbytes);
8255118Storek 	void	(*v2_seek)(int d, int hi, int lo);
8355118Storek 
8455118Storek 	void	(*v2_xxx2)();		/* ??? */
8555118Storek 	void	(*v2_xxx3)();		/* ??? */
8655118Storek };
8755118Storek 
8855118Storek /*
8955118Storek  * The v0 interface describes memory regions with these linked lists.
9055118Storek  * (The !$&@#+ v2 interface reformats these as properties, so that we
9155118Storek  * have to extract them into local temporary memory and reinterpret them.)
9255118Storek  */
9355118Storek struct v0mlist {
9455118Storek 	struct	v0mlist *next;
9555118Storek 	caddr_t	addr;
9655118Storek 	u_int	nbytes;
9755118Storek };
9855118Storek 
9955118Storek /*
10055118Storek  * V0 gives us three memory lists:  Total physical memory, VM reserved to
10155118Storek  * the PROM, and available physical memory (which, presumably, is just the
10255118Storek  * total minus any pages mapped in the PROM's VM region).  We can find the
10355118Storek  * reserved PMEGs by scanning the taken VM.  Unfortunately, the V2 prom
10455118Storek  * forgot to provide taken VM, and we are stuck with scanning ``magic''
10555118Storek  * addresses.
10655118Storek  */
10755118Storek struct v0mem {
10855118Storek 	struct	v0mlist **v0_phystot;	/* physical memory */
10955118Storek 	struct	v0mlist **v0_vmprom;	/* VM used by PROM */
11055118Storek 	struct	v0mlist **v0_physavail;	/* available physical memory */
11155118Storek };
11255118Storek 
11355118Storek /*
11455118Storek  * The version 0 PROM breaks up the string given to the boot command and
11555118Storek  * leaves the decoded version behind.
11655118Storek  */
11755118Storek struct v0bootargs {
11855118Storek 	char	*ba_argv[8];		/* argv format for boot string */
11955118Storek 	char	ba_args[100];		/* string space */
12055118Storek 	char	ba_bootdev[2];		/* e.g., "sd" for `b sd(...' */
12155118Storek 	int	ba_ctlr;		/* controller # */
12255118Storek 	int	ba_unit;		/* unit # */
12355118Storek 	int	ba_part;		/* partition # */
12455118Storek 	char	*ba_kernel;		/* kernel to boot, e.g., "vmunix" */
12555118Storek 	void	*ba_spare0;		/* not decoded here	XXX */
12655118Storek };
12755118Storek 
12855118Storek /*
12955118Storek  * The version 2 PROM interface uses the more general, if less convenient,
13055118Storek  * approach of passing the boot strings unchanged.  We also get open file
13155118Storek  * numbers for stdin and stdout (keyboard and screen, or whatever), for use
13255118Storek  * with the v2 device ops.
13355118Storek  */
13455118Storek struct v2bootargs {
13555118Storek 	char	**v2_bootpath;		/* V2: Path to boot device */
13655118Storek 	char	**v2_bootargs;		/* V2: Boot args */
13755118Storek 	int	*v2_fd0;		/* V2: Stdin descriptor */
13855118Storek 	int	*v2_fd1;		/* V2: Stdout descriptor */
13955118Storek };
14055118Storek 
14155118Storek /*
14255118Storek  * The following structure defines the primary PROM vector interface.
14355118Storek  * The Boot PROM hands the kernel a pointer to this structure in %o0.
14455118Storek  * There are numerous substructures defined below.
14555118Storek  */
14655118Storek struct promvec {
14755118Storek 	/* Version numbers. */
14855118Storek 	u_int	pv_magic;		/* Magic number */
14955118Storek 	u_int	pv_romvec_vers;		/* interface version (0, 2) */
15055118Storek 	u_int	pv_plugin_vers;		/* ??? */
15155118Storek 	u_int	pv_printrev;		/* PROM rev # (* 10, e.g 1.9 = 19) */
15255118Storek 
15355118Storek 	/* Version 0 memory descriptors (see below). */
15455118Storek 	struct	v0mem pv_v0mem;		/* V0: Memory description lists. */
15555118Storek 
15655118Storek 	/* Node operations (see below). */
15755118Storek 	struct	nodeops *pv_nodeops;	/* node functions */
15855118Storek 
15955118Storek 	char	**pv_bootstr;		/* Boot command, eg sd(0,0,0)vmunix */
16055118Storek 
16155118Storek 	struct	v0devops pv_v0devops;	/* V0: device ops */
16255118Storek 
16355118Storek 	/*
16455118Storek 	 * PROMDEV_* cookies.  I fear these may vanish in lieu of fd0/fd1
16555118Storek 	 * (see below) in future PROMs, but for now they work fine.
16655118Storek 	 */
16755118Storek 	char	*pv_stdin;		/* stdin cookie */
16855118Storek 	char	*pv_stdout;		/* stdout cookie */
16955118Storek #define	PROMDEV_KBD	0		/* input from keyboard */
17055118Storek #define	PROMDEV_SCREEN	0		/* output to screen */
17155118Storek #define	PROMDEV_TTYA	1		/* in/out to ttya */
17255118Storek #define	PROMDEV_TTYB	2		/* in/out to ttyb */
17355118Storek 
17455118Storek 	/* Blocking getchar/putchar.  NOT REENTRANT! (grr) */
17555118Storek 	int	(*pv_getchar)(void);
17655118Storek 	void	(*pv_putchar)(int ch);
17755118Storek 
17855118Storek 	/* Non-blocking variants that return -1 on error. */
17955118Storek 	int	(*pv_nbgetchar)(void);
18055118Storek 	int	(*pv_nbputchar)(int ch);
18155118Storek 
18255118Storek 	/* Put counted string (can be very slow). */
18355118Storek 	void	(*pv_putstr)(char *str, int len);
18455118Storek 
18555118Storek 	/* Miscellany. */
18655118Storek 	void	(*pv_reboot)(char *bootstr);
18759198Storek 	void	(*pv_printf)(const char *fmt, ...);
18855118Storek 	void	(*pv_abort)(void);	/* L1-A abort */
18955118Storek 	int	*pv_ticks;		/* Ticks since last reset */
19059198Storek 	__dead void (*pv_halt)(void);	/* Halt! */
19155118Storek 	void	(**pv_synchook)(void);	/* "sync" command hook */
19255118Storek 
19355118Storek 	/*
19455118Storek 	 * This eval's a FORTH string.  Unfortunately, its interface
19555118Storek 	 * changed between V0 and V2, which gave us much pain.
19655118Storek 	 */
19755118Storek 	union {
19855118Storek 		void	(*v0_eval)(int len, char *str);
19955118Storek 		void	(*v2_eval)(char *str);
20055118Storek 	} pv_fortheval;
20155118Storek 
20255118Storek 	struct	v0bootargs **pv_v0bootargs;	/* V0: Boot args */
20355118Storek 
20455118Storek 	/* Extract Ethernet address from network device. */
20555118Storek 	u_int	(*pv_enaddr)(int d, char *enaddr);
20655118Storek 
20755118Storek 	struct	v2bootargs pv_v2bootargs;	/* V2: Boot args + std in/out */
20855118Storek 	struct	v2devops pv_v2devops;	/* V2: device operations */
20955118Storek 
21055118Storek 	int	pv_spare[15];
21155118Storek 
21255118Storek 	/*
21355118Storek 	 * The following is machine-dependent.
21455118Storek 	 *
21555118Storek 	 * The sun4c needs a PROM function to set a PMEG for another
21655118Storek 	 * context, so that the kernel can map itself in all contexts.
21755118Storek 	 * It is not possible simply to set the context register, because
21855118Storek 	 * contexts 1 through N may have invalid translations for the
21955118Storek 	 * current program counter.  The hardware has a mode in which
22055118Storek 	 * all memory references go to the PROM, so the PROM can do it
22155118Storek 	 * easily.
22255118Storek 	 */
22355118Storek 	void	(*pv_setctxt)(int ctxt, caddr_t va, int pmeg);
22455118Storek };
22555118Storek 
22655118Storek /*
22755118Storek  * In addition to the global stuff defined in the PROM vectors above,
22855118Storek  * the PROM has quite a collection of `nodes'.  A node is described by
22955118Storek  * an integer---these seem to be internal pointers, actually---and the
23055118Storek  * nodes are arranged into an N-ary tree.  Each node implements a fixed
23155118Storek  * set of functions, as described below.  The first two deal with the tree
23255118Storek  * structure, allowing traversals in either breadth- or depth-first fashion.
23355118Storek  * The rest deal with `properties'.
23455118Storek  *
23555118Storek  * A node property is simply a name/value pair.  The names are C strings
23655118Storek  * (NUL-terminated); the values are arbitrary byte strings (counted strings).
23755118Storek  * Many values are really just C strings.  Sometimes these are NUL-terminated,
23855118Storek  * sometimes not, depending on the the interface version; v0 seems to
23955118Storek  * terminate and v2 not.  Many others are simply integers stored as four
24055118Storek  * bytes in machine order: you just get them and go.  The third popular
24155118Storek  * format is an `address', which is made up of one or more sets of three
24255118Storek  * integers as defined below.
24355118Storek  *
24455118Storek  * N.B.: for the `next' functions, next(0) = first, and next(last) = 0.
24555118Storek  * Whoever designed this part had good taste.  On the other hand, these
24655118Storek  * operation vectors are global, rather than per-node, yet the pointers
24755118Storek  * are not in the openprom vectors but rather found by indirection from
24855118Storek  * there.  So the taste balances out.
24955118Storek  */
25055118Storek struct openprom_addr {
25155118Storek 	int	oa_space;		/* address space (may be relative) */
25255118Storek 	u_int	oa_base;		/* address within space */
25355118Storek 	u_int	oa_size;		/* extent (number of bytes) */
25455118Storek };
25555118Storek 
25655118Storek struct nodeops {
25755118Storek 	/*
25855118Storek 	 * Tree traversal.
25955118Storek 	 */
26055118Storek 	int	(*no_nextnode)(int node);	/* next(node) */
26155118Storek 	int	(*no_child)(int node);	/* first child */
26255118Storek 
26355118Storek 	/*
26455118Storek 	 * Property functions.  Proper use of getprop requires calling
26555118Storek 	 * proplen first to make sure it fits.  Kind of a pain, but no
26655118Storek 	 * doubt more convenient for the PROM coder.
26755118Storek 	 */
26855118Storek 	int	(*no_proplen)(int node, caddr_t name);
26955118Storek 	int	(*no_getprop)(int node, caddr_t name, caddr_t val);
27055118Storek 	int	(*no_setprop)(int node, caddr_t name, caddr_t val, int len);
27155118Storek 	caddr_t	(*no_nextprop)(int node, caddr_t name);
27255118Storek };
273