/*
 * ioctl.i86  -  DOS IOCTL interface
 *
 * Copyright (C) 2003-2007 Gero Kuhlmann   <gero@gkminix.han.de>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Id: ioctl.i86,v 1.5 2007/01/06 18:30:53 gkminix Exp $
 */

#ifndef DOS_IOCTL_I86
#define DOS_IOCTL_I86


/*
 * Include the main C header file
 */
#define GAS_INCLUDE
#include <dos/ioctl.h86>



/*
 **************************************************************************
 *
 * Device driver opcodes:
 *
 */
#define	DEV_INIT	0x0000		/* initialize device */
#define	DEV_MEDIA_CHECK	0x0001		/* media check for block device */
#define	DEV_BUILD_BPB	0x0002		/* build block device parameter block */
#define	DEV_IOCTL_INP	0x0003		/* read from IOCTL control channel */
#define	DEV_INPUT	0x0004		/* read from device */
#define	DEV_NOWAIT	0x0005		/* read from device without waiting */
#define	DEV_INP_STATUS	0x0006		/* input status */
#define	DEV_INP_FLUSH	0x0007		/* flush input buffers */
#define	DEV_OUTPUT	0x0008		/* write to device */
#define	DEV_OUT_VERIFY	0x0009		/* write to device with verify */
#define	DEV_OUT_STATUS	0x000A		/* output status */
#define	DEV_OUT_FLUSH	0x000B		/* flush output buffers */
#define	DEV_IOCTL_OUT	0x000C		/* write to IOCTL control channel */
#define	DEV_OPEN	0x000D		/* open device */
#define	DEV_CLOSE	0x000E		/* close device */
#define	DEV_REMOVE	0x000F		/* check for removable media */
#define	DEV_OUT_BUSY	0x0010		/* output until busy */
#define DEV_GENERIC	0x0013		/* generic IOCTL */
#define DEV_GET_LOG	0x0017		/* get logical device */
#define DEV_SET_LOG	0x0018		/* set logical device */
#define DEV_CHECK_GEN	0x0019		/* check generic IOCTL support */



/*
 **************************************************************************
 *
 * Device driver error codes:
 *
 */
#define DEVERR_BUSY	0x0100		/* busy flag */
#define DEVERR_REMOVE	0x0200		/* not-removable flag */
#define DEVERR_ERRFLAG	0x8000		/* error flag */

#define	DEVERR_SUCCESS	0x0000		/* success */
#define	DEVERR_PROTECT	0x8000		/* write protect violation */
#define	DEVERR_UNKNOWN	0x8001		/* unknown unit */
#define	DEVERR_NOTREADY	0x8002		/* device not ready */
#define	DEVERR_COMMAND	0x8003		/* unknown command */
#define	DEVERR_CRC	0x8004		/* CRC error */
#define	DEVERR_LENGTH	0x8005		/* bad driver request struct length */
#define	DEVERR_SEEK	0x8006		/* seek error */
#define	DEVERR_MEDIA	0x8007		/* unknown media type */
#define	DEVERR_SECTOR	0x8008		/* sector not found */
#define	DEVERR_PAPER	0x8009		/* printer out of paper */
#define	DEVERR_WRITE	0x800A		/* write error */
#define	DEVERR_READ	0x800B		/* read error */
#define	DEVERR_GENERAL	0x800C		/* general error */
#define DEVERR_CHANGE	0x800F		/* invalid disk change */



/*
 **************************************************************************
 *
 * Layout of device header
 *
 */
#define	DEV_NAME_SIZE	8		/* size of device name */


			.struct	0
devhdr_next:		.struct	.+4	/* far pointer to next device header */
devhdr_attr:		.struct	.+2	/* device attributes */
devhdr_strategy:	.struct	.+2	/* offset to strategy routine */
devhdr_interrupt:	.struct	.+2	/* offset to interrupt handler */
devhdr_name:		.struct	.+DEV_NAME_SIZE		/* device name */

#define DEVHDR_LENGTH	(10 + DEV_NAME_SIZE)



/*
 **************************************************************************
 *
 * Request header for devices (to be used by the interrupt handler):
 *
 */
			.struct	0
devreq_length:		.struct	.+1	/* length of device header */
devreq_subunit:		.struct	.+1	/* number of device subunit */
devreq_command:		.struct	.+1	/* command opcode */
devreq_status:		.struct	.+2	/* return result code */

#define DEVREQ_LENGTH	5		/* length of standard request header */
#define DEVREQ_FUNC_OFS	0x000D		/* offset to function-specific part */


/*
 * Request header for device function 00 (initialize device):
 */
			.struct	DEVREQ_FUNC_OFS
dev0_units:		.struct	.+1	/* OUT: number of subunits */
dev0_memavail:				/* IN:  end of available memory */
dev0_free:		.struct	.+4	/* OUT: first free byte */
dev0_cmdline:				/* IN:  pointer to command line */
dev0_bpb:		.struct	.+4	/* OUT: pointer to BPB */
dev0_firstdrv:		.struct	.+1	/* IN:  drive number for first unit */
dev0_errflag:		.struct	.+2	/* OUT: error message flag */

#define DEV0_LENGTH	(DEVREQ_FUNC_OFS + 12)


/*
 * Request header for device function 01 (media check):
 */
			.struct	DEVREQ_FUNC_OFS
dev1_media:		.struct	.+1	/* IN:  media descriptor */
dev1_status:		.struct	.+1	/* OUT: media status */
dev1_volume:		.struct	.+4	/* OUT: far ptr to volume ID */

#define DEV1_LENGTH	(DEVREQ_FUNC_OFS + 6)


/*
 * Request header for device function 02 (build BPB):
 */
			.struct	DEVREQ_FUNC_OFS
dev2_media:		.struct	.+1	/* IN:  media descriptor */
dev2_txaddr:		.struct	.+4	/* IN:  far ptr to transfer area */
dev2_bpb:		.struct	.+4	/* OUT: far ptr to BPB */

#define DEV2_LENGTH	(DEVREQ_FUNC_OFS + 9)


/*
 * Request header for device functions 03 and 0C (read/write IOCTL channel):
 */
			.struct	DEVREQ_FUNC_OFS
dev3_media:		.struct	.+1	/* IN:  media descriptor */
dev3_txaddr:		.struct	.+4	/* IN:  far ptr to transfer area */
dev3_buflen:		.struct	.+2	/* IN/OUT: number of bytes transfered */

#define DEV3_LENGTH	(DEVREQ_FUNC_OFS + 7)


/*
 * Request header for device functions 04, 08 and 09 (read/write device):
 */
			.struct	DEVREQ_FUNC_OFS
dev4_media:		.struct	.+1	/* IN:  media descriptor */
dev4_txaddr:		.struct	.+4	/* IN:  far ptr to transfer area */
dev4_count:		.struct	.+2	/* IN/OUT:  byte/sector count */
dev4_sector:		.struct	.+2	/* IN:  starting sector number */
dev4_volume:		.struct	.+4	/* OUT: far ptr to volume ID */
dev4_sect32:		.struct	.+4	/* IN:  32-bit starting sector num */

#define DEV4_LENGTH	(DEVREQ_FUNC_OFS + 17)
#define DEV4_COMPAQ_LEN	(DEVREQ_FUNC_OFS + 11)


/*
 * Request header for device function 05 (read character device without wait):
 */
			.struct	DEVREQ_FUNC_OFS
dev5_char:		.struct	.+1	/* character read */

#define DEV5_LENGTH	(DEVREQ_FUNC_OFS + 1)


/*
 * Request header for device function 10 (write until busy):
 */
			.struct	DEVREQ_FUNC_OFS
			.struct	.+1	/* reserved */
dev10_txaddr:		.struct	.+4	/* IN:  far ptr to transfer area */
dev10_buflen:		.struct	.+2	/* IN/OUT: number of bytes */

#define DEV10_LENGTH	(DEVREQ_FUNC_OFS + 7)


/*
 * Request header for device functions 13 and 19 (generic functions):
 */
			.struct	DEVREQ_FUNC_OFS
dev13_category:		.struct	.+1	/* IN:  category code */
dev13_function:		.struct	.+1	/* IN:  function code */
dev13_ds:		.struct	.+2	/* IN:  copy of DS */
dev13_header:		.struct	.+2	/* IN:  offset of device drv header */
dev13_params:		.struct	.+4	/* IN:  far ptr to parameter block */

#define DEV13_LENGTH	(DEVREQ_FUNC_OFS + 10)


#endif

