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