#ifndef KERNEL
#include "/usr/sys/h/ioctl.h"
#endif

/* fifo control bit definitions */

#define FIFO_CSR13 0010000		/* Bit 13 (to user device) */
#define FIFO_CSR14 0020000		/* Bit 14 (to user device) */
#define FIFO_EMPTY 0000200		/* Fifo empty bit */
#define FIFO_INT   0000001		/* Interrupt enable bit */
#define FIFO_IEA   0000100		/* Fifo interrupt enable */
#define FIFO_REQA  0040000		/* Request A (from user device) */
#define FIFO_REQB  0100000		/* Request B (from user device) */

#define FIFOBUF_SIZE 126		/* Size of the fifo buffer */
#define FIFO_WORDS 64			/* Number of words in the fifo */

/* Structure of the fifo device */

struct fifodevice {
	unsigned short	fifocsr;		/* Fifo control register */
	unsigned short	fifobuf;		/* Fifo data register */
};

/*---------------------------------------------------------------------------*
 *									     *
 * Fifo driver IO controls:						     *
 *									     *
 *	FUNC_ON		Turns on the "functions on interrupt" 		     *
 *	FUNC_OFF	Turns off the "functions on interrupt" 		     *
 *	FUNC_START	Sends interrupt to FIFO target; initializes timeout  *
 *	READ_CSR	Returns the current contents of the csr 	     *
 *	SET_CSR		Sets the current contents of the csr 		     *
 *	SET_CTRL	Define csr values set after read or write  	     *
 *	FLUSH		Flushes the fifo				     *
 *	WRITE		Writes one 16 bit word to the FIFO         	     *
 *	READ		Reads one 16 bit word from the FIFO		     *
 *									     *
 *---------------------------------------------------------------------------*/

#define LIOCF_FUNC_ON	 _IOWR(l, 1, struct fifoblock)
#define LIOCF_FUNC_OFF	 _IOWR(l, 2, struct fifoblock)
#define LIOCF_FUNC_START _IOWR(l, 3, struct fifoblock)
#define LIOCF_READ_CSR	 _IOWR(l, 4, struct fifoblock)
#define LIOCF_SET_CSR	 _IOWR(l, 5, struct fifoblock)
#define LIOCF_SET_CTRL	 _IOWR(l, 6, struct fifoblock)
#define LIOCF_FLUSH	 _IOWR(l, 7, struct fifoblock)
#define LIOCF_WRITE	 _IOWR(l, 8, struct fifoblock)
#define LIOCF_READ	 _IOWR(l, 9, struct fifoblock)

/* IOCTL Flag options */

#define WAITIO     0000001              /* IO wait flag                    */
#define DEBUG      0000002              /* Debug flag			   */
#define I_SIGNAL   0000004		/* Signal on stray interrupt	   */
#define SET_CSR_R  0000020		/* To set the CSR after a read 	   */
#define SET_CSR_W  0000040		/* To set the CST after a write	   */
#define NO_FLOCK   0000080		/* Suppress locking of memory	   */

struct fifoblock {
  int	flags;		/* Flag options			*/
  int	(*function1)();	/* First interrupt function	*/
  int	(*function2)();	/* Second interrupt function	*/
  char  *read_buffer;	/* Buffer for input		*/
  char  *write_buffer;  /* Buffer for output		*/
  int   *terminus;      /* Terminate flag               */
  long  sigpid;		/* process to send signal to    */
  unsigned short csr;	/* Csr value (read or write)	*/
  unsigned short csr_r; /* Csr value set after read	*/
  unsigned short csr_w; /* Csr value set after write	*/
  unsigned short data;  /* Data word used by WRITE_DATA/READ_DATA	*/
  int	signal;  	/* Signal sent by unsolicited interrupt 	*/
  unsigned int timeout;	/* Timeout time in UNIX clock ticks		*/
};

/* Error definitions */

#define EBADMODE	123
#define EBDATA		124
#define EHUNG		125
#define ELOCK		126
#define EFULL		127

/* Terminate flag codes, for functions mode only */

#define FIFO_ERROR	0x00010000
#define FIFO_NOT_EMPTY	0x00010001
#define FIFO_BAD_RCOUNT 0x00010002
#define FIFO_BAD_WCOUNT 0x00010003
#define FIFO_HUNG_FULL  0x00010004
#define FIFO_CHECKSUM	0x00010005
#define FIFO_KERNERROR  0x00010007

#define FIFO_TIMEOUT	0x00010006
