/*
 * |-----------------------------------------------------------|
 * | Copyright (c) 1991, 1990 MIPS Computer Systems, Inc.      |
 * | All Rights Reserved                                       |
 * |-----------------------------------------------------------|
 * |          Restricted Rights Legend                         |
 * | Use, duplication, or disclosure by the Government is      |
 * | subject to restrictions as set forth in                   |
 * | subparagraph (c)(1)(ii) of the Rights in Technical        |
 * | Data and Computer Software Clause of DFARS 252.227-7013.  |
 * |         MIPS Computer Systems, Inc.                       |
 * |         950 DeGuigne Avenue                               |
 * |         Sunnyvale, California 94088-3650, USA             |
 * |-----------------------------------------------------------|
 */
/* $Header: tcs_load.h,v 1.2.2.1 92/06/24 13:54:04 marker Exp $ */



/*****************************************************************/
/*		hps.types.h					*/
/*****************************************************************/
/*  Copyright (c) 1986 by Systech Corporation			*/
/*								*/
/*  CONFIDENTIAL.  THIS SOFTWARE IS LICENSED BY AND IS THE	*/
/*  CONFIDENTIAL AND PROPRIETARY PROPERTY OF SYSTECH COMPUTER	*/
/*  CORPORATION AND MAY NOT, WITHOUT THE PRIOR WRITTEN CONSENT	*/
/*  OF SYSTECH COMPUTER CORPORATION, BE REPRODUCED, USED OR	*/
/*  DISCLOSED EXCEPT IN ACCORDANCE WITH A SYSTECH COMPUTER	*/
/*  CORPORATION SOFTWARE LICENSE AGREEMENT.			*/
/*****************************************************************/
/* PART NUMBER: XX-XXXXXX-X					*/
/*****************************************************************/
/*****************************************************************/
/*								*/
/* This file defines some basic data types, to insure that the	*/
/* HPS on-board processor and the host processor agree on byte-	*/
/* within-word ordering, long and short word sizes, etc.	*/
/*								*/
/*****************************************************************/


typedef volatile long			bit32;
typedef volatile short			bit16;
typedef volatile unsigned char	bit8;


typedef union
{
	struct
	{
	bit16 hps_addrh;
	bit16 hps_addrl;
	} addr;
	struct
	{
		bit16 WH;
		bit16 WL;
	} ws;
	struct
	{
		bit8 HH;
		bit8 HL;
		bit8 LH;
		bit8 LL;
	} dpram_addr;
} HPS_LONG;		/* 32-bit value structured for the 68000	*/


/*	Convenient #defines to use with HPS_LONG union	*/

#define wl	ws.WL
#define wh	ws.WH
#define ll	dpram_addr.LL
#define lh	dpram_addr.LH
#define hl	dpram_addr.HL
#define hh	dpram_addr.HH


#ifdef 0
/* Shorten names, to avoid portability problems.		*/

#define	v_rtiocb	v_rtioc
#define	v_qcreate	v_qcrea
#define	v_create	v_creat
#define	v_rtnwrk	v_rtnwr
#define	v_pextend	v_pexte
#define	v_tdelete	v_tdele
#define	v_gblock	v_gbloc
#define	v_pcreate	v_pcrea
#define	v_rblock	v_rbloc
#define	v_tdelay	v_tdela

#endif

/*****************************************************************/

typedef volatile struct iocb_hdr
{
	bit16	len;			/* Total IOCB length (header + extensions)	*/
	bit16	maj_dev;		/* On-board application ID				*/
	bit16	min_dev;		/* Application-specific parameter			*/
	bit16	int_enab;		/* == 1 to interrupt on IOCB comnpletion	*/
	union
	{
		bit16	hps_addrh;	/* Completion info to give host when finished*/
		bit16	ws_WH;
		struct
		{
			bit8	HH;
			bit8	HL;
		} dpram_addrh;
	} return_msgh;
	union
	{
		bit16	hps_addrl;	/* Completion info to give host when finished*/
		bit16	ws_WL;
		struct
		{
			bit8	LH;
			bit8	LL;
		} dpram_addr;
	} return_msgl;
	bit16	data_len;		/* Length of data, in bytes */
	union
	{
		bit16	hps_addrh;	/* Completion info to give host when finished*/
		bit16	ws_WH;
		struct
		{
			bit8	HH;
			bit8	HL;
		} dpram_addrh;
	} datah;
	union
	{
		bit16	hps_addrl;	/* Completion info to give host when finished*/
		bit16	ws_WL;
		struct
		{
			bit8	LH;
			bit8	LL;
		} dpram_addr;
	} datal;
	bit16	data_dir;		/* Direction of data transfer (1 = to HPS)	*/
	bit16	mode;		/* Data in DPRAM, or bus memory (DMA)		*/
	union
	{
		bit16	hps_addrh;	/* Completion info to give host when finished*/
		bit16	ws_WH;
		struct
		{
			bit8	HH;
			bit8	HL;
		} dpram_addrh;
	} mailh;
	union
	{
		bit16	hps_addrl;	/* Completion info to give host when finished*/
		bit16	ws_WL;
		struct
		{
			bit8	LH;
			bit8	LL;
		} dpram_addr;
	} maill;
	/* These fields are reserved for the host: */
/* volatile struct iocb_hdr *next;	/* Points to next IOCB on queue */
/* int	(*finished)();		/* Pointer to completion handler */
	bit16	nexth;
	bit16	nextl;
	bit16	finishedh;
	bit16	finishedl;
} IOCBHDR;


/* Codes for int_enab:	*/
#define ENABLED	1
#define DISABLED	0

/* Codes for data_dir:	*/
#define TO_HPS		1		/* (WRITE)	*/
#define FROM_HPS	0		/* (READ)	*/

/* Codes for mode:		*/
#define DPRAM_IOCB		1
#define DPRAM_DATA		2


/* IOCB Error codes (placed in mailbox after IOCB completion):			*/

#define E_NODEV	0x01	/* No such major device					*/
#define E_NOFUNC	0x02	/* No such minor device				*/
#define E_NOCOMMAND	0x03	/* Command not recognized by device		*/
#define E_REMOTE	0x04	/* Remote station did not respond		*/
#define E_NOCONFIRM	0x05	/* Failed to receive a CONFIRM packet		*/
#define E_OVERFLOW	0x06	/* Remote sent more data than was requested	*/
#define E_NOSTATION	0x07	/* Could find no station with given address	*/
#define E_XACKTO	0x08	/* XACK Timeout during DMA			*/
#define E_BUSTO	0x09	/* Bus Grant Timeout during DMA				*/
#define E_BUSY		0x0A	/* Minor device busy				*/
#define E_NOMEM	0x0B	/* No on-board memory available				*/
#define E_CLOSED	0x0C	/* Minor device already closed			*/
#define E_OFFLINE	0x0D /* No response from network			*/
#define E_NORESP	0x0E /* No response from remote station			*/
#define E_BADRESP	0x0F /* Bad response (NAK) from remote station		*/
#define E_FULL		0x10 /* Output buffer full				*/
#define E_NETBUSY   0x11 /* Network busy					*/
#define E_CONNECT	0x12 /* No clusters connected for download		*/
#define E_CHKSUM	0x13 /* Checksum error during cluster download		*/

#define E_PANIC	0xFF	/* Panic condition on controller			*/

#define R_ERR_NO	0x100/* Error code from a remote station		*/

/*****************************************************************/

/* Download IOCB format; the HPS loader recognizes this IOCB.	*/

typedef struct
{
	IOCBHDR	header;		/* IOCB header						*/
	bit16	command;		/* OPEN, CLOSE, READ, WRITE, IOCTL		*/
	bit16	cmd_modifier;	/* For ioctls */
	union
	{
		bit16	hps_addrh;	/* Completion info to give host when finished*/
		bit16	ws_WH;
		struct
		{
			bit8	HH;
			bit8	HL;
		} dpram_addrh;
	} hpsadrh;
	union
	{
		bit16	hps_addrl;	/* Completion info to give host when finished*/
		bit16	ws_WL;
		struct
		{
			bit8	LH;
			bit8	LL;
		} dpram_addr;
	} hpsadrl;
	bit16	priority;		/* For CREATE ioctl: VRTX task priority	*/
	bit16	tid;			/* For CREATE ioctl: VRTX task ID		*/
	bit16	mode;		/* For CREATE ioctl: VRTX task mode	*/
} LOADER_IOCB;

/*
 * Download file header format
 */

typedef struct
{
	bit32	start;
	bit32	end;
	bit32	vt_start;
	bit32	vt_len;
	bit32	tt_start;
	bit32	tt_len;
	bit32	boot_start;
	bit32	v_ws;
	bit32	v_ws_size;
	bit16	v_us_size;
	bit16	t_count;
	bit16	b_pri;
	bit16	b_id;
} DNL_HDR;


/*****************************************************************/
/* IOCB command values.  Also used by on-board diagnostics.		*/ 
/* LSEEK is not recognized by the controller as a command from 	*/
/* the host-- only by the remote as a command from the 		*/
/* controller.											*/
/*****************************************************************/

#define OPEN		1
#define CLOSE		2
#define READ		3
#define WRITE		4
#define IOCTL		5
#define LSEEK		6


/* Also ioctl() requests for the raw driver.						*/

#define RAW_DEVNAME	"/dev/rhp0"	/* Pathname for raw device		*/

#define RESET_HPS	1		/* Reset HPS controller hardware		*/
#define DO_IOCB	2		/* Pass an IOCB to the HPS			*/
#define NOTIFY_ACT	3		/* Notify on station active			*/
#define SET_DEBUG	4		/* change the message printing level	*/
#define GET_RVER	9		/* get raw driver version info          */
#define GET_TVER	10		/* get tty driver version info          */
#define GET_VVER	11  		/* get vtio driver version info         */


/* IOCB command modifier values for the EPROM-resident loader		*/

#define INIT		1	/* Re-initializes VRTX					*/
#define CREATE		2	/* Starts-up a task						*/
#define LOG		3	/* Return log table						*/
#define LOGCLR		4	/* Return and clear log table				*/
#define SET_AML	5	/* Set address-modifier lines				*/
#define GET_ADDRS	6	/* Get on-board system addresses			*/

#define RAM_BASE    0x1000000
#define DPRAM_BASE  RAM_BASE
#define RAM_LEN     0x100000

#define RAM_TOP     (RAM_BASE+RAM_LEN)

#define P_BLOCK ((struct HPS6816 *) DPRAM_BASE)


struct v_table
{
	long		tracer;		/* Points to TRACER configuration table	*/
	long		workspace;	/* On-board address of VRTX workspace	*/
	long		ws_size;		/* Size of VRTX workspace (in bytes)	*/
	short	ss_size;		/* Size of system stack (in bytes)		*/
	short	is_size;		/* Int.service stack size (in bytes)	*/
	long		res_1[2];		/* H&R reserved					*/
	short	d_mask;		/* Disable mask					*/
	short	us_size;		/* User stack size (in bytes)			*/
	long		res_2;		/* H&R reserved					*/
	short	task_c;		/* Task count						*/
	short	res_3;		/* H&R reserved					*/
	int	   (*txrdy)();		/* Transmitter ready routine			*/
	int	   (*tcreate)();	/* Task create routine				*/
	int	   (*tdelete)();	/* Task delete routine				*/
	int	   (*tswitch)();	/* Task switch routine				*/
	long		cvt;			/* Component vector table			*/
	long		res_4;		/* Systech reserved		*/
	long		res_5;		/* Systech reserved		*/
};

struct t_table
{
	short	res_1;			/* H&R reserved				*/
	short	codespaceh;		/* VRTX codespace address		*/
	short	codespacel;		/* VRTX codespace address		*/
	short	workspaceh;		/* TRACER workspace address		*/
	short	workspacel;		/* TRACER workspace address		*/
	short	ws_sizeh;		/* TRACER workspace size (in bytes)	*/
	short	ws_sizel;		/* TRACER workspace size (in bytes)	*/
	short	channels;		/* VRTX/TRACER I/O channels			*/
	short	toggle;			/* VRTX-TRACER I/O toggle			*/
	short	d_mask;			/* TRACER disable mask				*/
	short	trap_instr;		/* TRAP instruction					*/
	short	traph;			/* TRAP handler routine				*/
	short	trapl;			/* TRAP handler routine				*/
	short	txrdyh;			/* Transmitter ready routine		*/
	short	txrdyl;			/* Transmitter ready routine		*/
	short	i_filterh;		/* Input filter routine				*/
	short	i_filterl;		/* Input filter routine				*/
	short	o_filterh;		/* Output filter routine			*/
	short	o_filterl;		/* Output filter routine			*/
	short	susp_outph;		/* Suspend output string			*/
	short	susp_outpl;		/* Suspend output string			*/
	short	cancelh;		/* Cancel line						*/
	short	cancell;		/* Cancel line						*/
	short	backspaceh;		/* Backspace string					*/
	short	backspacel;		/* Backspace string					*/
	short	newlineh;		/* Newline string					*/
	short	newlinel;		/* Newline string					*/
	short	reprinth;		/* Reprint line string				*/
	short	reprintl;		/* Reprint line string				*/
	short	reissueh;		/* Re-issue line string				*/
	short	reissuel;		/* Re-issue line string				*/
	short	downloadh;		/* Download routine					*/
	short	downloadl;		/* Download routine					*/
	short	res_2[7];		/* H&R reserved						*/
};


