/*-=-=-=-=-=-=-=-=-=-=-=- RCCL/RCI Notice of Copyright -=-=-=-=-=-=-=-=-=-=-*
 *									    *
 *	Copyright (C) 1987, 1991 by John E. Lloyd.			    *
 *									    *
 *	Information on copyright permissions, as well as a complete	    *
 *	disclaimer of warranty, is given in the file COPYRIGHT.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

#ifndef _IODEVICE_H_
#define _IODEVICE_H_


#define DEVICE_NAME_SIZE	15	/* max name length of a device */

#define IOC_SIGINTER_ENABLE	1
#define IOC_SIGINTER_DISABLE	2
#define IOC_TIMEOUT		3
#define IOC_SET_BLOCKTIME	4
#define IOC_GET_BLOCKTIME	5

/* access codes for allocating devices */

#define DEV_NONE	0x00	/* no program is allowed acces */
#define DEV_EXTERNAL	0x01	/* external programs allowed access */
#define DEV_INTERNAL	0x02	/* current program is allowed access */
#define DEV_ALL		DEV_EXTERNAL | DEV_INTERNAL /* both allowed */

#include "../h/cdefs.h"

#define MAX_DEVARGS	4

struct devAddr {
	char *name;			/* name of the driver */
	int address;			/* bus address of the driver */
	char *addrStr;			/* string address information */
	int args[MAX_DEVARGS];		/* extra information arguments */
};

typedef struct {
	char *name;			/* symbolic name of the driver	    */

	int (*read)();			/* reads from device		    */
	int (*testRead)();		/* says if device is for read	    */
	int (*write)();			/* writes to device		    */
	int (*testWrite)();		/* says that a write can proceed    */

	int (*probe)();			/* sees if interface is present     */
	int (*attach)();		/* starts up control session 	    */
	int (*detach)();		/* winds up control session 	    */
	int (*signal)();		/* signals the device		    */

	int (*ioctl)();			/* sets options and interrupts	    */
	
	/* Interrupt attach and handler functions for non-UNIX systems */

	int (*intrAttach)();		/* enable or disable interrupts */
	int (*intrHandler)();		/* handle an interrupt */

} IO_DRIVER_SPEC;

typedef struct {
	char defined;			/* IO device is alive and present   */
	char name[DEVICE_NAME_SIZE+1];	/* place to store device name */

	/* Fields for use by the driver functions */

	int unit;			/* unit number of the driver 	    */
	int address;			/* bus address of interface 	    */
	char *addrStr;			/* address information string	    */
	int args[MAX_DEVARGS];		/* argument values passed to driver */

	unsigned char *location;	/* memory address of interface	    */
	int size;			/* size of the interface (in bytes) */
	unsigned long timeout;		/* a spin-loop timeout parameter    */
	int blocktime;			/* time read or write can block	    */
	int error;			/* error register 		    */
	int byteCount;			/* byte count for I/O operations    */

	int (*read)();			/* interface routines; copies of    */
	int (*testRead)();		/* those in IO_DRIVER_SPEC ...      */
	int (*write)();			/*  ...  */
	int (*testWrite)();		/*  ...  */

	int (*probe)();			/*  ...  */
	int (*attach)();		/*  ...  */
	int (*detach)();		/*  ...  */
	int (*signal)();		/*  ...  */

	int (*ioctl)();			/*  ...  */

} IO_DEVICE;

typedef struct {
	char name[DEVICE_NAME_SIZE+1];	/* place to store device name */

	int address;			/* bus address of interface 	    */
	int args[MAX_DEVARGS];		/* argument values passed to driver */

	unsigned char *location;	/* memory address of interface	    */
	int ipl;			/* interrupt priority level */
	int vector;			/* interrupt vector number */

	int (*intrAttach)();		/* enable or disable interrupts */
	int (*intrHandler)();		/* handle the interrupt */
} IO_INTERRUPT;

#endif
