Home | History | Annotate | Line # | Download | only in obio
iwm_fdvar.h revision 1.8
      1 /*	$NetBSD: iwm_fdvar.h,v 1.8 2005/01/15 16:01:00 chs Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997, 1998 Hauke Fath.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. The name of the author may not be used to endorse or promote products
     15  *    derived from this software without specific prior written permission.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 #ifndef _MAC68K_FDVAR_H
     29 #define _MAC68K_FDVAR_H
     30 
     31 /**
     32  **	Constants
     33  **/
     34 
     35 enum {
     36 	IWM_MAX_DRIVE = 2,		/* Attachable drives */
     37 	IWM_GCR_DISK_ZONES = 5,		/* Zones on GCR disk */
     38 	IWM_MAX_GCR_SECTORS = 12,	/* Max. sectors per GCR track */
     39 	IWM_MAX_FLOPPY_SECT = 50,	/* Larger than the highest sector */
     40 					/* number likely to occur */
     41 };
     42 
     43 
     44 /* Physical track format codes */
     45 enum {
     46 	IWM_GCR,		/* Apple's Group Code Recording format */
     47 	IWM_MFM_DD,		/* Standard MFM on DD disk (250 KBit/s)	*/
     48 	IWM_MFM_HD		/* Standard MFM on HD disk (500 KBit/s)	*/
     49 };
     50 
     51 /* Drive softc flags */
     52 enum {
     53 	IWM_FD_IS_OPEN	= 0x00000001,
     54 	IWM_FD_MOTOR_ON = 0x00000002
     55 };
     56 
     57 /* seek() behaviour */
     58 enum {
     59 	IWM_SEEK_VANILLA,
     60 	IWM_SEEK_RECAL,
     61 	IWM_SEEK_VERIFY
     62 };
     63 
     64 /* I/O direction */
     65 enum {
     66 	IWM_WRITE = 0,
     67 	IWM_READ
     68 };
     69 
     70 
     71 /**
     72  **	Data Types
     73  **/
     74 
     75 /*
     76  * Floppy disk format information
     77  *
     78  * XXX How to describe ZBR here? UN*X disk drive handling -- clinging
     79  *     tenaciously to the trailing edge of technology...
     80  */
     81 struct fdInfo {
     82 	short	heads;			/* # of heads the drive has */
     83 	short	tracks;			/* # of tracks per side (cyl's)	*/
     84 	short	sectorSize;		/* Bytes per sector */
     85 	short	secPerTrack;		/* fake	*/
     86 	short	secPerCyl;		/* fake	*/
     87 	short	secPerDisk;		/* # of sectors per __disk__ */
     88 	short	stepRate;		/* in ms (is a software delay) */
     89 	short	interleave;		/* Sector interleave */
     90 	short	physFormat;		/* GCR, MFM DD, MFM HD */
     91 	char	*description;
     92 };
     93 typedef struct fdInfo fdInfo_t;
     94 
     95 /*
     96  * Current physical location on Sony GCR disk
     97  */
     98 struct diskPosition {
     99 	short	track;
    100 	short	oldTrack;
    101 	short	side;
    102 	short	sector;
    103 	short	maxSect;		/* Highest sector # for this track */
    104 };
    105 typedef struct diskPosition diskPosition_t;
    106 
    107 /*
    108  * Zone recording scheme (per disk surface/head)
    109  */
    110 struct diskZone {
    111 	short	tracks;			/* # of tracks per zone	*/
    112 	short	sectPerTrack;
    113 	short	firstBlock;
    114 	short	lastBlock;
    115 };
    116 typedef struct diskZone diskZone_t;
    117 
    118 /*
    119  * Arguments passed between iwmAttach() and the fd probe routines.
    120  */
    121 struct iwmAttachArgs {
    122 	fdInfo_t *driveType;		/* Default drive parameters */
    123 	short	unit;			/* Current drive # */
    124 };
    125 typedef struct iwmAttachArgs iwmAttachArgs_t;
    126 
    127 /*
    128  * Software state per disk: the IWM can have max. 2 drives. Newer
    129  * machines don't even have a port for an external drive.
    130  *
    131  */
    132 struct fd_softc {
    133 	struct device devInfo;		/* generic device info */
    134 	struct disk diskInfo;		/* generic disk info */
    135 	struct bufq_state bufQueue;	/* queue of buf's */
    136 	int sc_active;			/* number of active requests */
    137 	struct callout motor_ch;	/* motor callout */
    138 
    139 /* private stuff here */
    140 /* errors & retries in current I/O job */
    141 	int	iwmErr;			/* Last IO error */
    142 	int	ioRetries;
    143 	int	seekRetries;
    144 	int	sectRetries;
    145 	int	verifyRetries;
    146 
    147 /* hardware info */
    148 	int	drvFlags;		/* Copy of drive flags */
    149 	short   stepDirection;		/* Current step direction */
    150 	diskPosition_t pos;		/* Physical position on disk */
    151 
    152 
    153 /* drive info */
    154 	short	unit;			/* Drive # as seen by IWM */
    155 	short	partition;		/* "Partition" info {a,b,c,...} */
    156 	fdInfo_t *defaultType;		/* default floppy format */
    157 	fdInfo_t *currentType;		/* current floppy format */
    158 	int     state;			/* XXX */
    159 
    160 /* data transfer info */
    161 	int	ioDirection;		/* Read/write */
    162 	daddr_t	startBlk;		/* Starting block # */
    163 	int	bytesLeft;		/* Bytes left to transfer */
    164 	int	bytesDone;		/* Bytes transferred */
    165 	caddr_t current_buffer; 	/* target of current data transfer */
    166 	unsigned char *cbuf;		/* ptr to cylinder cache */
    167 	int	cachedSide;		/* Which head is cached? */
    168 	cylCacheSlot_t r_slots[IWM_MAX_GCR_SECTORS];
    169 	cylCacheSlot_t w_slots[IWM_MAX_GCR_SECTORS];
    170 	int	writeLabel;		/* Write access to disklabel? */
    171 	sectorHdr_t sHdr;		/* current sector header */
    172 };
    173 typedef struct fd_softc fd_softc_t;
    174 
    175 /*
    176  * Software state of IWM controller
    177  *
    178  * SWIM/MFM mode may have some state to keep here.
    179  */
    180 struct iwm_softc {
    181 	struct device devInfo;		/* generic device info */
    182 	int	drives;			/* # of attached fd's */
    183 	fd_softc_t *fd[IWM_MAX_DRIVE];	/* ptrs to children */
    184 
    185 	int	state;			/* make that an enum? */
    186 	u_char	modeReg;		/* Copy of IWM mode register */
    187 	short	maxRetries;		/* I/O retries */
    188 	int	errors;
    189 	int	underruns;		/* data not delivered in time */
    190 };
    191 typedef struct iwm_softc iwm_softc_t;
    192 
    193 
    194 /**
    195  **     Exported functions
    196  **/
    197 
    198 /*
    199  * IWM Loadable Kernel Module : Exported functions
    200  */
    201 #ifdef _LKM
    202 int	fdModInit(void);
    203 void	fdModFree(void);
    204 #endif
    205 
    206 int 	iwmInit(void);
    207 int 	iwmCheckDrive(int32_t);
    208 int	iwmSelectDrive(int32_t);
    209 int	iwmSelectSide(int32_t);
    210 int	iwmTrack00(void);
    211 int	iwmSeek(int32_t);
    212 
    213 int     iwmReadSector(sectorHdr_t *, cylCacheSlot_t *, caddr_t);
    214 int	iwmWriteSector(sectorHdr_t *, cylCacheSlot_t *);
    215 
    216 int	iwmDiskEject(int32_t);		/* drive = [0..1] */
    217 int	iwmMotor(int32_t, int32_t);	/* on(1)/off(0)	*/
    218 
    219 /*
    220  * Debugging only
    221  */
    222 int	iwmQueryDrvFlag(int32_t, int32_t); /* reg = [0..15] */
    223 
    224 /* Make sure we run at splhigh when calling! */
    225 int	iwmReadSectHdr(sectorHdr_t *);
    226 
    227 #if 0 /* XXX not yet */
    228 int	iwmReadRawSector(int32_t, caddr_t);
    229 int	iwmWriteRawSector(int32_t, caddr_t);
    230 int	iwmReadRawTrack(int32_t, caddr_t);
    231 #endif
    232 
    233 #endif /* _MAC68K_FDVAR_H */
    234