1999-12-05 00:13:19 +03:00
|
|
|
/* $NetBSD: fd.c,v 1.41 1999/12/04 21:20:04 ragge Exp $ */
|
1994-10-26 05:01:24 +03:00
|
|
|
|
1994-04-07 21:43:29 +04:00
|
|
|
/*
|
1994-05-29 05:44:26 +04:00
|
|
|
* Copyright (c) 1994 Christian E. Hopps
|
1996-05-04 08:54:00 +04:00
|
|
|
* Copyright (c) 1996 Ezra Story
|
1994-04-07 21:43:29 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
1994-05-29 05:44:26 +04:00
|
|
|
* This product includes software developed by Christian E. Hopps.
|
1996-05-04 08:54:00 +04:00
|
|
|
* This product includes software developed by Ezra Story.
|
1994-04-07 21:43:29 +04:00
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1994-04-06 03:04:05 +04:00
|
|
|
*/
|
1994-05-29 05:44:26 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/disk.h>
|
|
|
|
#include <sys/dkbad.h>
|
1996-04-22 01:10:48 +04:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <machine/cpu.h>
|
1994-05-29 05:44:26 +04:00
|
|
|
#include <amiga/amiga/device.h>
|
|
|
|
#include <amiga/amiga/custom.h>
|
|
|
|
#include <amiga/amiga/cia.h>
|
|
|
|
#include <amiga/amiga/cc.h>
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1996-04-22 01:10:48 +04:00
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <machine/conf.h>
|
|
|
|
|
1997-07-17 05:28:54 +04:00
|
|
|
#include "locators.h"
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
enum fdc_bits { FDB_CHANGED = 2, FDB_PROTECT, FDB_CYLZERO, FDB_READY };
|
1994-04-06 03:04:05 +04:00
|
|
|
/*
|
1994-05-29 05:44:26 +04:00
|
|
|
* partitions in fd represent different format floppies
|
|
|
|
* partition a is 0 etc..
|
1994-04-06 03:04:05 +04:00
|
|
|
*/
|
1995-08-13 00:30:45 +04:00
|
|
|
enum fd_parttypes {
|
|
|
|
FDAMIGAPART = 0,
|
1994-05-29 05:44:26 +04:00
|
|
|
FDMSDOSPART,
|
|
|
|
FDMAXPARTS
|
|
|
|
};
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
#define FDBBSIZE (8192)
|
|
|
|
#define FDSBSIZE (8192)
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
#define b_cylin b_resid
|
1994-07-04 23:37:51 +04:00
|
|
|
#define FDUNIT(dev) DISKUNIT(dev)
|
|
|
|
#define FDPART(dev) DISKPART(dev)
|
|
|
|
#define FDMAKEDEV(m, u, p) MAKEDISKDEV((m), (u), (p))
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1996-05-04 08:54:00 +04:00
|
|
|
/* that's nice, but we don't want to always use this as an amiga drive
|
|
|
|
bunghole :-) */
|
1994-05-29 05:44:26 +04:00
|
|
|
#define FDNHEADS (2) /* amiga drives always have 2 heads */
|
|
|
|
#define FDSECSIZE (512) /* amiga drives always have 512 byte sectors */
|
|
|
|
#define FDSECLWORDS (128)
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
#define FDSETTLEDELAY (18000) /* usec delay after seeking after switch dir */
|
|
|
|
#define FDSTEPDELAY (3500) /* usec delay after steping */
|
|
|
|
#define FDPRESIDEDELAY (1000) /* usec delay before writing can occur */
|
|
|
|
#define FDWRITEDELAY (1300) /* usec delay after write */
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
#define FDSTEPOUT (1) /* decrease track step */
|
|
|
|
#define FDSTEPIN (0) /* increase track step */
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
#define FDCUNITMASK (0x78) /* mask for all units (bits 6-3) */
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
#define FDRETRIES (2) /* default number of retries */
|
|
|
|
#define FDMAXUNITS (4) /* maximum number of supported units */
|
|
|
|
|
|
|
|
#define DISKLEN_READ (0) /* fake mask for reading */
|
|
|
|
#define DISKLEN_WRITE (1 << 14) /* bit for writing */
|
|
|
|
#define DISKLEN_DMAEN (1 << 15) /* dma go */
|
|
|
|
#define DMABUFSZ ((DISKLEN_WRITE - 1) * 2) /* largest dma possible */
|
|
|
|
|
|
|
|
#define FDMFMSYNC (0x4489)
|
1996-05-04 08:54:00 +04:00
|
|
|
#define FDMFMID (0x5554)
|
|
|
|
#define FDMFMDATA (0x5545)
|
|
|
|
#define FDMFMGAP1 (0x9254)
|
|
|
|
#define FDMFMGAP2 (0xAAAA)
|
|
|
|
#define FDMFMGAP3 (0x9254)
|
|
|
|
#define CRC16POLY (0x1021) /* (x^16) + x^12 + x^5 + x^0 */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Msdos-type MFM encode/decode
|
|
|
|
*/
|
|
|
|
static u_char msdecode[128];
|
|
|
|
static u_char msencode[16] =
|
|
|
|
{
|
|
|
|
0x2a, 0x29, 0x24, 0x25, 0x12, 0x11, 0x14, 0x15,
|
|
|
|
0x4a, 0x49, 0x44, 0x45, 0x52, 0x51, 0x54, 0x55
|
|
|
|
};
|
|
|
|
static u_short mscrctab[256];
|
|
|
|
|
|
|
|
/*
|
|
|
|
5554 aaaa aaaa aaa5 2aa4 4452 aa51
|
|
|
|
00 00 03 02 ac 0d
|
|
|
|
*/
|
1994-04-06 03:04:05 +04:00
|
|
|
|
|
|
|
/*
|
1994-05-29 05:44:26 +04:00
|
|
|
* floppy device type
|
1994-04-06 03:04:05 +04:00
|
|
|
*/
|
1994-05-29 05:44:26 +04:00
|
|
|
struct fdtype {
|
|
|
|
u_int driveid; /* drive identification (from drive) */
|
|
|
|
u_int ncylinders; /* number of cylinders on drive */
|
|
|
|
u_int amiga_nsectors; /* number of sectors per amiga track */
|
|
|
|
u_int msdos_nsectors; /* number of sectors per msdos track */
|
|
|
|
u_int nreadw; /* number of words (short) read per track */
|
|
|
|
u_int nwritew; /* number of words (short) written per track */
|
|
|
|
u_int gap; /* track gap size in long words */
|
|
|
|
u_int precomp[2]; /* 1st and 2nd precomp values */
|
|
|
|
char *desc; /* description of drive type (useq) */
|
1994-04-06 03:04:05 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
1994-05-29 05:44:26 +04:00
|
|
|
* floppy disk device data
|
1994-04-06 03:04:05 +04:00
|
|
|
*/
|
1994-05-29 05:44:26 +04:00
|
|
|
struct fd_softc {
|
1996-01-08 01:01:38 +03:00
|
|
|
struct device sc_dv; /* generic device info; must come first */
|
|
|
|
struct disk dkdev; /* generic disk info */
|
1994-05-29 05:44:26 +04:00
|
|
|
struct buf bufq; /* queue of buf's */
|
|
|
|
struct fdtype *type;
|
|
|
|
void *cachep; /* cached track data (write through) */
|
|
|
|
int cachetrk; /* cahced track -1 for none */
|
|
|
|
int hwunit; /* unit for amiga controlling hw */
|
|
|
|
int unitmask; /* mask for cia select deslect */
|
|
|
|
int pstepdir; /* previous step direction */
|
1994-06-05 11:45:08 +04:00
|
|
|
int curcyl; /* current curcyl head positioned on */
|
1994-05-29 05:44:26 +04:00
|
|
|
int flags; /* misc flags */
|
|
|
|
int wlabel;
|
|
|
|
int stepdelay; /* useq to delay after seek user setable */
|
|
|
|
int nsectors; /* number of sectors per track */
|
|
|
|
int openpart; /* which partition [ab] == [12] is open */
|
|
|
|
short retries; /* number of times to retry failed io */
|
|
|
|
short retried; /* number of times current io retried */
|
1996-05-04 08:54:00 +04:00
|
|
|
int bytespersec; /* number of bytes per sector */
|
1994-04-06 03:04:05 +04:00
|
|
|
};
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/* fd_softc->flags */
|
|
|
|
#define FDF_MOTORON (0x01) /* motor is running */
|
|
|
|
#define FDF_MOTOROFF (0x02) /* motor is waiting to be turned off */
|
|
|
|
#define FDF_WMOTOROFF (0x04) /* unit wants a wakeup after off */
|
|
|
|
#define FDF_DIRTY (0x08) /* track cache needs write */
|
|
|
|
#define FDF_WRITEWAIT (0x10) /* need to head select delay on next setpos */
|
|
|
|
#define FDF_HAVELABEL (0x20) /* label is valid */
|
|
|
|
#define FDF_JUSTFLUSH (0x40) /* don't bother caching track. */
|
1994-07-18 05:37:48 +04:00
|
|
|
#define FDF_NOTRACK0 (0x80) /* was not able to recalibrate drive */
|
1994-05-29 05:44:26 +04:00
|
|
|
|
|
|
|
int fdc_wantwakeup;
|
1994-06-05 11:45:08 +04:00
|
|
|
int fdc_side;
|
1994-05-29 05:44:26 +04:00
|
|
|
void *fdc_dmap;
|
|
|
|
struct fd_softc *fdc_indma;
|
1996-04-29 10:23:47 +04:00
|
|
|
int fdc_dmalen;
|
|
|
|
int fdc_dmawrite;
|
1994-05-29 05:44:26 +04:00
|
|
|
|
|
|
|
struct fdcargs {
|
|
|
|
struct fdtype *type;
|
|
|
|
int unit;
|
|
|
|
};
|
|
|
|
|
1996-12-23 12:09:49 +03:00
|
|
|
int fdcmatch __P((struct device *, struct cfdata *, void *));
|
1996-04-22 01:10:48 +04:00
|
|
|
void fdcattach __P((struct device *, struct device *, void *));
|
1996-08-28 01:53:46 +04:00
|
|
|
int fdcprint __P((void *, const char *));
|
1996-12-23 12:09:49 +03:00
|
|
|
int fdmatch __P((struct device *, struct cfdata *, void *));
|
1996-04-22 01:10:48 +04:00
|
|
|
void fdattach __P((struct device *, struct device *, void *));
|
|
|
|
|
|
|
|
void fdintr __P((int));
|
1996-04-29 10:23:47 +04:00
|
|
|
void fdidxintr __P((void));
|
1996-04-22 01:10:48 +04:00
|
|
|
void fdstrategy __P((struct buf *));
|
|
|
|
int fdloaddisk __P((struct fd_softc *));
|
1997-10-09 03:37:50 +04:00
|
|
|
void fdgetdefaultlabel __P((struct fd_softc *, struct disklabel *, int));
|
1996-04-22 01:10:48 +04:00
|
|
|
int fdgetdisklabel __P((struct fd_softc *, dev_t));
|
|
|
|
int fdsetdisklabel __P((struct fd_softc *, struct disklabel *));
|
|
|
|
int fdputdisklabel __P((struct fd_softc *, dev_t));
|
|
|
|
struct fdtype * fdcgetfdtype __P((int));
|
|
|
|
void fdmotoroff __P((void *));
|
|
|
|
void fdsetpos __P((struct fd_softc *, int, int));
|
|
|
|
void fdselunit __P((struct fd_softc *));
|
|
|
|
void fdstart __P((struct fd_softc *));
|
|
|
|
void fdcont __P((struct fd_softc *));
|
|
|
|
void fddmastart __P((struct fd_softc *, int));
|
|
|
|
void fdcalibrate __P((void *));
|
|
|
|
void fddmadone __P((struct fd_softc *, int));
|
|
|
|
void fddone __P((struct fd_softc *));
|
|
|
|
void fdfindwork __P((int));
|
|
|
|
void fdminphys __P((struct buf *));
|
|
|
|
void fdcachetoraw __P((struct fd_softc *));
|
1996-05-04 08:54:00 +04:00
|
|
|
void amcachetoraw __P((struct fd_softc *));
|
|
|
|
int amrawtocache __P((struct fd_softc *));
|
1996-04-22 01:10:48 +04:00
|
|
|
u_long *fdfindsync __P((u_long *, u_long *));
|
|
|
|
int fdrawtocache __P((struct fd_softc *));
|
1996-05-04 08:54:00 +04:00
|
|
|
void mscachetoraw __P((struct fd_softc *));
|
|
|
|
int msrawtocache __P((struct fd_softc *));
|
1996-04-22 01:10:48 +04:00
|
|
|
u_long *mfmblkencode __P((u_long *, u_long *, u_long *, int));
|
|
|
|
u_long *mfmblkdecode __P((u_long *, u_long *, u_long *, int));
|
1996-05-04 08:54:00 +04:00
|
|
|
u_short *msblkdecode __P((u_short *, u_char *, int));
|
|
|
|
u_short *msblkencode __P((u_short *, u_char *, int, u_short *));
|
1994-05-29 05:44:26 +04:00
|
|
|
|
|
|
|
struct dkdriver fddkdriver = { fdstrategy };
|
1994-04-06 03:04:05 +04:00
|
|
|
|
|
|
|
/*
|
1995-08-13 00:30:45 +04:00
|
|
|
* read size is (nsectors + 1) * mfm secsize + gap bytes + 2 shorts
|
1994-05-29 05:44:26 +04:00
|
|
|
* write size is nsectors * mfm secsize + gap bytes + 3 shorts
|
|
|
|
* the extra shorts are to deal with a dma hw bug in the controller
|
|
|
|
* they are probably too much (I belive the bug is 1 short on write and
|
|
|
|
* 3 bits on read) but there is no need to be cheap here.
|
1994-04-06 03:04:05 +04:00
|
|
|
*/
|
1994-05-29 05:44:26 +04:00
|
|
|
#define MAXTRKSZ (22 * FDSECSIZE)
|
|
|
|
struct fdtype fdtype[] = {
|
|
|
|
{ 0x00000000, 80, 11, 9, 7358, 6815, 414, { 80, 161 }, "3.5dd" },
|
|
|
|
{ 0x55555555, 40, 11, 9, 7358, 6815, 414, { 80, 161 }, "5.25dd" },
|
|
|
|
{ 0xAAAAAAAA, 80, 22, 18, 14716, 13630, 828, { 80, 161 }, "3.5hd" }
|
1994-04-06 03:04:05 +04:00
|
|
|
};
|
1994-05-29 05:44:26 +04:00
|
|
|
int nfdtype = sizeof(fdtype) / sizeof(*fdtype);
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1996-03-17 04:16:48 +03:00
|
|
|
struct cfattach fd_ca = {
|
|
|
|
sizeof(struct fd_softc), fdmatch, fdattach
|
1996-03-17 08:53:57 +03:00
|
|
|
};
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1998-01-12 13:39:01 +03:00
|
|
|
extern struct cfdriver fd_cd;
|
1996-03-17 04:16:48 +03:00
|
|
|
|
|
|
|
struct cfattach fdc_ca = {
|
|
|
|
sizeof(struct device), fdcmatch, fdcattach
|
|
|
|
};
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
1995-08-13 00:30:45 +04:00
|
|
|
* all hw access through macros, this helps to hide the active low
|
1994-05-29 05:44:26 +04:00
|
|
|
* properties
|
|
|
|
*/
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
#define FDUNITMASK(unit) (1 << (3 + (unit)))
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* select units using mask
|
|
|
|
*/
|
|
|
|
#define FDSELECT(um) do { ciab.prb &= ~(um); } while (0)
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* deselect units using mask
|
|
|
|
*/
|
|
|
|
#define FDDESELECT(um) do { ciab.prb |= (um); delay(1); } while (0)
|
1994-04-06 03:04:05 +04:00
|
|
|
|
|
|
|
/*
|
1994-05-29 05:44:26 +04:00
|
|
|
* test hw condition bits
|
1994-04-06 03:04:05 +04:00
|
|
|
*/
|
1994-05-29 05:44:26 +04:00
|
|
|
#define FDTESTC(bit) ((ciaa.pra & (1 << (bit))) == 0)
|
1994-04-06 03:04:05 +04:00
|
|
|
|
|
|
|
/*
|
1994-05-29 05:44:26 +04:00
|
|
|
* set motor for select units, true motor on else off
|
1994-04-06 03:04:05 +04:00
|
|
|
*/
|
1994-05-29 05:44:26 +04:00
|
|
|
#define FDSETMOTOR(on) do { \
|
|
|
|
if (on) ciab.prb &= ~CIAB_PRB_MTR; else ciab.prb |= CIAB_PRB_MTR; \
|
|
|
|
} while (0)
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* set head for select units
|
|
|
|
*/
|
|
|
|
#define FDSETHEAD(head) do { \
|
|
|
|
if (head) ciab.prb &= ~CIAB_PRB_SIDE; else ciab.prb |= CIAB_PRB_SIDE; \
|
|
|
|
delay(1); } while (0)
|
1994-04-06 03:04:05 +04:00
|
|
|
|
|
|
|
/*
|
1994-05-29 05:44:26 +04:00
|
|
|
* select direction, true towards spindle else outwards
|
1994-04-06 03:04:05 +04:00
|
|
|
*/
|
1994-05-29 05:44:26 +04:00
|
|
|
#define FDSETDIR(in) do { \
|
|
|
|
if (in) ciab.prb &= ~CIAB_PRB_DIR; else ciab.prb |= CIAB_PRB_DIR; \
|
|
|
|
delay(1); } while (0)
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* step the selected units
|
|
|
|
*/
|
|
|
|
#define FDSTEP do { \
|
|
|
|
ciab.prb &= ~CIAB_PRB_STEP; ciab.prb |= CIAB_PRB_STEP; \
|
|
|
|
} while (0)
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
#define FDDMASTART(len, towrite) do { \
|
|
|
|
int dmasz = (len) | ((towrite) ? DISKLEN_WRITE : 0) | DISKLEN_DMAEN; \
|
|
|
|
custom.dsklen = dmasz; custom.dsklen = dmasz; } while (0)
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
#define FDDMASTOP do { custom.dsklen = 0; } while (0)
|
1994-04-06 03:04:05 +04:00
|
|
|
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
int
|
1996-12-23 12:09:49 +03:00
|
|
|
fdcmatch(pdp, cfp, auxp)
|
1994-05-29 05:44:26 +04:00
|
|
|
struct device *pdp;
|
1996-12-23 12:09:49 +03:00
|
|
|
struct cfdata *cfp;
|
|
|
|
void *auxp;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1996-03-17 04:16:48 +03:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
if (matchname("fdc", auxp) == 0 || cfp->cf_unit != 0)
|
|
|
|
return(0);
|
|
|
|
if ((fdc_dmap = alloc_chipmem(DMABUFSZ)) == NULL) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("fdc: unable to allocate dma buffer\n");
|
1994-05-29 05:44:26 +04:00
|
|
|
return(0);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
1994-05-29 05:44:26 +04:00
|
|
|
return(1);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1994-05-29 05:44:26 +04:00
|
|
|
fdcattach(pdp, dp, auxp)
|
1996-04-22 01:10:48 +04:00
|
|
|
struct device *pdp, *dp;
|
1994-05-29 05:44:26 +04:00
|
|
|
void *auxp;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
struct fdcargs args;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(": dmabuf pa 0x%x", kvtop(fdc_dmap));
|
|
|
|
printf(": dmabuf ka %p\n", fdc_dmap);
|
1994-05-29 05:44:26 +04:00
|
|
|
args.unit = 0;
|
|
|
|
args.type = fdcgetfdtype(args.unit);
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-06-05 11:45:08 +04:00
|
|
|
fdc_side = -1;
|
1994-05-29 05:44:26 +04:00
|
|
|
config_found(dp, &args, fdcprint);
|
|
|
|
for (args.unit++; args.unit < FDMAXUNITS; args.unit++) {
|
|
|
|
if ((args.type = fdcgetfdtype(args.unit)) == NULL)
|
|
|
|
continue;
|
|
|
|
config_found(dp, &args, fdcprint);
|
|
|
|
}
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
int
|
|
|
|
fdcprint(auxp, pnp)
|
|
|
|
void *auxp;
|
1996-08-28 01:53:46 +04:00
|
|
|
const char *pnp;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1995-04-06 23:45:00 +04:00
|
|
|
struct fdcargs *fcp;
|
|
|
|
|
|
|
|
fcp = auxp;
|
|
|
|
if (pnp)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("fd%d at %s unit %d:", fcp->unit, pnp,
|
1996-04-22 01:10:48 +04:00
|
|
|
fcp->type->driveid);
|
1994-05-29 05:44:26 +04:00
|
|
|
return(UNCONF);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*ARGSUSED*/
|
|
|
|
int
|
1996-12-23 12:09:49 +03:00
|
|
|
fdmatch(pdp, cfp, auxp)
|
1994-05-29 05:44:26 +04:00
|
|
|
struct device *pdp;
|
1996-12-23 12:09:49 +03:00
|
|
|
struct cfdata *cfp;
|
|
|
|
void *auxp;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1996-03-17 04:16:48 +03:00
|
|
|
|
1997-07-17 05:28:54 +04:00
|
|
|
#define cf_unit cf_loc[FDCCF_UNIT]
|
1994-05-29 05:44:26 +04:00
|
|
|
struct fdcargs *fdap;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
fdap = auxp;
|
1997-07-17 05:28:54 +04:00
|
|
|
if (cfp->cf_unit == fdap->unit || cfp->cf_unit == FDCCF_UNIT_DEFAULT)
|
1994-05-29 05:44:26 +04:00
|
|
|
return(1);
|
|
|
|
return(0);
|
|
|
|
#undef cf_unit
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1994-05-29 05:44:26 +04:00
|
|
|
fdattach(pdp, dp, auxp)
|
|
|
|
struct device *pdp, *dp;
|
|
|
|
void *auxp;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
struct fdcargs *ap;
|
|
|
|
struct fd_softc *sc;
|
1996-05-04 08:54:00 +04:00
|
|
|
int i;
|
1994-05-29 05:44:26 +04:00
|
|
|
|
|
|
|
ap = auxp;
|
|
|
|
sc = (struct fd_softc *)dp;
|
|
|
|
|
1994-06-05 11:45:08 +04:00
|
|
|
sc->curcyl = sc->cachetrk = -1;
|
1994-05-29 05:44:26 +04:00
|
|
|
sc->openpart = -1;
|
|
|
|
sc->type = ap->type;
|
|
|
|
sc->hwunit = ap->unit;
|
|
|
|
sc->unitmask = 1 << (3 + ap->unit);
|
|
|
|
sc->retries = FDRETRIES;
|
|
|
|
sc->stepdelay = FDSTEPDELAY;
|
1996-05-04 08:54:00 +04:00
|
|
|
sc->bytespersec = 512;
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" unit %d: %s %d cyl, %d head, %d sec [%d sec], 512 bytes/sec\n",
|
1996-04-22 01:10:48 +04:00
|
|
|
sc->hwunit, sc->type->desc, sc->type->ncylinders, FDNHEADS,
|
1994-05-29 05:44:26 +04:00
|
|
|
sc->type->amiga_nsectors, sc->type->msdos_nsectors);
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1996-01-08 01:01:38 +03:00
|
|
|
/*
|
|
|
|
* Initialize and attach the disk structure.
|
|
|
|
*/
|
|
|
|
sc->dkdev.dk_name = sc->sc_dv.dv_xname;
|
|
|
|
sc->dkdev.dk_driver = &fddkdriver;
|
|
|
|
disk_attach(&sc->dkdev);
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* calibrate the drive
|
|
|
|
*/
|
|
|
|
fdsetpos(sc, 0, 0);
|
|
|
|
fdsetpos(sc, sc->type->ncylinders, 0);
|
|
|
|
fdsetpos(sc, 0, 0);
|
|
|
|
fdmotoroff(sc);
|
1994-04-22 06:20:48 +04:00
|
|
|
|
1996-05-04 08:54:00 +04:00
|
|
|
/*
|
|
|
|
* precalc msdos MFM and CRC
|
|
|
|
*/
|
|
|
|
for (i = 0; i < 128; i++)
|
|
|
|
msdecode[i] = 0xff;
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
msdecode[msencode[i]] = i;
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
mscrctab[i] = (0x1021 * (i & 0xf0)) ^ (0x1021 * (i & 0x0f)) ^
|
|
|
|
(0x1021 * (i >> 4));
|
|
|
|
}
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* enable disk related interrupts
|
|
|
|
*/
|
1996-01-28 22:48:39 +03:00
|
|
|
custom.dmacon = DMAF_SETCLR | DMAF_MASTER | DMAF_DISK;
|
1996-04-29 10:23:47 +04:00
|
|
|
custom.intena = INTF_SETCLR | INTF_DSKBLK;
|
|
|
|
ciab.icr = CIA_ICR_FLG;
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*ARGSUSED*/
|
|
|
|
int
|
1996-04-22 01:10:48 +04:00
|
|
|
fdopen(dev, flags, devtype, p)
|
1994-05-29 05:44:26 +04:00
|
|
|
dev_t dev;
|
|
|
|
int flags, devtype;
|
|
|
|
struct proc *p;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
struct fd_softc *sc;
|
|
|
|
int wasopen, fwork, error, s;
|
|
|
|
|
|
|
|
error = 0;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
if (FDPART(dev) >= FDMAXPARTS)
|
|
|
|
return(ENXIO);
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1996-03-17 04:16:48 +03:00
|
|
|
if ((sc = getsoftc(fd_cd, FDUNIT(dev))) == NULL)
|
1994-05-29 05:44:26 +04:00
|
|
|
return(ENXIO);
|
1994-07-18 05:37:48 +04:00
|
|
|
if (sc->flags & FDF_NOTRACK0)
|
|
|
|
return(ENXIO);
|
1994-05-29 05:44:26 +04:00
|
|
|
if (sc->cachep == NULL)
|
|
|
|
sc->cachep = malloc(MAXTRKSZ, M_DEVBUF, M_WAITOK);
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
s = splbio();
|
|
|
|
/*
|
1995-04-10 13:14:00 +04:00
|
|
|
* if we are sleeping in fdclose(); waiting for a chance to
|
1994-05-29 05:44:26 +04:00
|
|
|
* shut the motor off, do a sleep here also.
|
|
|
|
*/
|
|
|
|
while (sc->flags & FDF_WMOTOROFF)
|
1996-04-22 01:10:48 +04:00
|
|
|
tsleep(fdmotoroff, PRIBIO, "fdopen", 0);
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
fwork = 0;
|
|
|
|
/*
|
1995-08-13 00:30:45 +04:00
|
|
|
* if not open let user open request type, otherwise
|
1994-05-29 05:44:26 +04:00
|
|
|
* ensure they are trying to open same type.
|
|
|
|
*/
|
|
|
|
if (sc->openpart == FDPART(dev))
|
|
|
|
wasopen = 1;
|
|
|
|
else if (sc->openpart == -1) {
|
|
|
|
sc->openpart = FDPART(dev);
|
|
|
|
wasopen = 0;
|
1994-04-06 03:04:05 +04:00
|
|
|
} else {
|
1994-05-29 05:44:26 +04:00
|
|
|
wasopen = 1;
|
|
|
|
error = EPERM;
|
|
|
|
goto done;
|
1995-08-13 00:30:45 +04:00
|
|
|
}
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* wait for current io to complete if any
|
|
|
|
*/
|
|
|
|
if (fdc_indma) {
|
|
|
|
fwork = 1;
|
1995-08-13 00:30:45 +04:00
|
|
|
fdc_wantwakeup++;
|
1996-04-22 01:10:48 +04:00
|
|
|
tsleep(fdopen, PRIBIO, "fdopen", 0);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
1996-04-22 01:10:48 +04:00
|
|
|
if ((error = fdloaddisk(sc)) != 0)
|
1994-05-29 05:44:26 +04:00
|
|
|
goto done;
|
1996-04-22 01:10:48 +04:00
|
|
|
if ((error = fdgetdisklabel(sc, dev)) != 0)
|
1994-05-29 05:44:26 +04:00
|
|
|
goto done;
|
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" open successful\n");
|
1994-05-29 05:44:26 +04:00
|
|
|
#endif
|
|
|
|
done:
|
|
|
|
/*
|
1995-08-13 00:30:45 +04:00
|
|
|
* if we requested that fddone()->fdfindwork() wake us, allow it to
|
1994-05-29 05:44:26 +04:00
|
|
|
* complete its job now
|
|
|
|
*/
|
|
|
|
if (fwork)
|
|
|
|
fdfindwork(FDUNIT(dev));
|
|
|
|
splx(s);
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1995-08-13 00:30:45 +04:00
|
|
|
/*
|
1994-05-29 05:44:26 +04:00
|
|
|
* if we were not open and we marked us so reverse that.
|
|
|
|
*/
|
|
|
|
if (error && wasopen == 0)
|
1996-05-04 08:54:00 +04:00
|
|
|
sc->openpart = -1;
|
1994-05-29 05:44:26 +04:00
|
|
|
return(error);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*ARGSUSED*/
|
|
|
|
int
|
1995-04-10 13:14:00 +04:00
|
|
|
fdclose(dev, flags, devtype, p)
|
1994-05-29 05:44:26 +04:00
|
|
|
dev_t dev;
|
|
|
|
int flags, devtype;
|
|
|
|
struct proc *p;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
struct fd_softc *sc;
|
|
|
|
int s;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("fdclose()\n");
|
1994-05-29 05:44:26 +04:00
|
|
|
#endif
|
1996-03-17 04:16:48 +03:00
|
|
|
sc = getsoftc(fd_cd, FDUNIT(dev));
|
1994-05-29 05:44:26 +04:00
|
|
|
s = splbio();
|
|
|
|
if (sc->flags & FDF_MOTORON) {
|
|
|
|
sc->flags |= FDF_WMOTOROFF;
|
1995-04-10 13:14:00 +04:00
|
|
|
tsleep(fdmotoroff, PRIBIO, "fdclose", 0);
|
1994-05-29 05:44:26 +04:00
|
|
|
sc->flags &= ~FDF_WMOTOROFF;
|
|
|
|
wakeup(fdmotoroff);
|
|
|
|
}
|
|
|
|
sc->openpart = -1;
|
|
|
|
splx(s);
|
|
|
|
return(0);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
int
|
|
|
|
fdioctl(dev, cmd, addr, flag, p)
|
|
|
|
dev_t dev;
|
1994-12-01 20:24:23 +03:00
|
|
|
u_long cmd;
|
1994-05-29 05:44:26 +04:00
|
|
|
caddr_t addr;
|
1994-12-01 20:24:23 +03:00
|
|
|
int flag;
|
1994-05-29 05:44:26 +04:00
|
|
|
struct proc *p;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
struct fd_softc *sc;
|
|
|
|
int error, wlab;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1996-03-17 04:16:48 +03:00
|
|
|
sc = getsoftc(fd_cd, FDUNIT(dev));
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
if ((sc->flags & FDF_HAVELABEL) == 0)
|
|
|
|
return(EBADF);
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case DIOCSBAD:
|
|
|
|
return(EINVAL);
|
|
|
|
case DIOCSRETRIES:
|
|
|
|
if (*(int *)addr < 0)
|
|
|
|
return(EINVAL);
|
|
|
|
sc->retries = *(int *)addr;
|
|
|
|
return(0);
|
|
|
|
case DIOCSSTEP:
|
|
|
|
if (*(int *)addr < FDSTEPDELAY)
|
|
|
|
return(EINVAL);
|
1996-01-08 01:01:38 +03:00
|
|
|
sc->dkdev.dk_label->d_trkseek = sc->stepdelay = *(int *)addr;
|
1994-05-29 05:44:26 +04:00
|
|
|
return(0);
|
|
|
|
case DIOCGDINFO:
|
1996-01-08 01:01:38 +03:00
|
|
|
*(struct disklabel *)addr = *(sc->dkdev.dk_label);
|
1994-05-29 05:44:26 +04:00
|
|
|
return(0);
|
|
|
|
case DIOCGPART:
|
1996-01-08 01:01:38 +03:00
|
|
|
((struct partinfo *)addr)->disklab = sc->dkdev.dk_label;
|
1995-08-13 00:30:45 +04:00
|
|
|
((struct partinfo *)addr)->part =
|
1996-01-08 01:01:38 +03:00
|
|
|
&sc->dkdev.dk_label->d_partitions[FDPART(dev)];
|
1994-05-29 05:44:26 +04:00
|
|
|
return(0);
|
|
|
|
case DIOCSDINFO:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return(EBADF);
|
|
|
|
return(fdsetdisklabel(sc, (struct disklabel *)addr));
|
|
|
|
case DIOCWDINFO:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return(EBADF);
|
1996-04-22 01:10:48 +04:00
|
|
|
if ((error = fdsetdisklabel(sc, (struct disklabel *)addr)) != 0)
|
1994-05-29 05:44:26 +04:00
|
|
|
return(error);
|
|
|
|
wlab = sc->wlabel;
|
|
|
|
sc->wlabel = 1;
|
|
|
|
error = fdputdisklabel(sc, dev);
|
|
|
|
sc->wlabel = wlab;
|
|
|
|
return(error);
|
|
|
|
case DIOCWLABEL:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return(EBADF);
|
|
|
|
sc->wlabel = *(int *)addr;
|
|
|
|
return(0);
|
1997-10-09 03:37:50 +04:00
|
|
|
case DIOCGDEFLABEL:
|
|
|
|
fdgetdefaultlabel(sc, (struct disklabel *)addr, FDPART(dev));
|
|
|
|
return(0);
|
1994-05-29 05:44:26 +04:00
|
|
|
default:
|
|
|
|
return(ENOTTY);
|
|
|
|
}
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
1995-08-13 00:30:45 +04:00
|
|
|
/*
|
1994-05-29 05:44:26 +04:00
|
|
|
* no dumps to floppy disks thank you.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
fdsize(dev)
|
|
|
|
dev_t dev;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
return(-1);
|
|
|
|
}
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
int
|
1996-04-22 01:10:48 +04:00
|
|
|
fdread(dev, uio, flags)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int flags;
|
1994-05-29 05:44:26 +04:00
|
|
|
{
|
1995-07-05 06:12:38 +04:00
|
|
|
return (physio(fdstrategy, NULL, dev, B_READ, fdminphys, uio));
|
1994-05-29 05:44:26 +04:00
|
|
|
}
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
int
|
1996-04-22 01:10:48 +04:00
|
|
|
fdwrite(dev, uio, flags)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int flags;
|
1994-05-29 05:44:26 +04:00
|
|
|
{
|
1995-07-05 06:12:38 +04:00
|
|
|
return (physio(fdstrategy, NULL, dev, B_WRITE, fdminphys, uio));
|
1994-05-29 05:44:26 +04:00
|
|
|
}
|
1994-04-06 03:04:05 +04:00
|
|
|
|
|
|
|
|
1996-04-22 01:10:48 +04:00
|
|
|
void
|
|
|
|
fdintr(flag)
|
|
|
|
int flag;
|
1994-05-29 05:44:26 +04:00
|
|
|
{
|
|
|
|
int s;
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
s = splbio();
|
|
|
|
if (fdc_indma)
|
|
|
|
fddmadone(fdc_indma, 0);
|
|
|
|
splx(s);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
1996-04-29 10:23:47 +04:00
|
|
|
void
|
|
|
|
fdidxintr()
|
|
|
|
{
|
|
|
|
if (fdc_indma && fdc_dmalen) {
|
|
|
|
/*
|
|
|
|
* turn off intr and start actual dma
|
|
|
|
*/
|
|
|
|
ciab.icr = CIA_ICR_FLG;
|
|
|
|
FDDMASTART(fdc_dmalen, fdc_dmawrite);
|
|
|
|
fdc_dmalen = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-04-06 03:04:05 +04:00
|
|
|
void
|
1994-05-29 05:44:26 +04:00
|
|
|
fdstrategy(bp)
|
|
|
|
struct buf *bp;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
struct disklabel *lp;
|
|
|
|
struct fd_softc *sc;
|
|
|
|
struct buf *dp;
|
|
|
|
int unit, part, s;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
unit = FDUNIT(bp->b_dev);
|
|
|
|
part = FDPART(bp->b_dev);
|
1996-03-17 04:16:48 +03:00
|
|
|
sc = getsoftc(fd_cd, unit);
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("fdstrategy: 0x%x\n", bp);
|
1994-05-29 05:44:26 +04:00
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* check for valid partition and bounds
|
|
|
|
*/
|
1996-01-08 01:01:38 +03:00
|
|
|
lp = sc->dkdev.dk_label;
|
1994-05-29 05:44:26 +04:00
|
|
|
if ((sc->flags & FDF_HAVELABEL) == 0) {
|
|
|
|
bp->b_error = EIO;
|
|
|
|
goto bad;
|
1995-08-13 00:30:45 +04:00
|
|
|
}
|
1994-05-29 05:44:26 +04:00
|
|
|
if (bounds_check_with_label(bp, lp, sc->wlabel) <= 0)
|
|
|
|
goto done;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* trans count of zero or bounds check indicates io is done
|
|
|
|
* we are done.
|
|
|
|
*/
|
|
|
|
if (bp->b_bcount == 0)
|
|
|
|
goto done;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* queue the buf and kick the low level code
|
|
|
|
*/
|
|
|
|
s = splbio();
|
|
|
|
dp = &sc->bufq;
|
|
|
|
disksort(dp, bp);
|
|
|
|
fdstart(sc);
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
bad:
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
done:
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
biodone(bp);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-05-29 05:44:26 +04:00
|
|
|
* make sure disk is loaded and label is up-to-date.
|
1994-04-06 03:04:05 +04:00
|
|
|
*/
|
1994-05-29 05:44:26 +04:00
|
|
|
int
|
|
|
|
fdloaddisk(sc)
|
|
|
|
struct fd_softc *sc;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* if diskchange is low step drive to 0 then up one then to zero.
|
|
|
|
*/
|
1996-04-29 10:23:47 +04:00
|
|
|
fdselunit(sc); /* make sure the unit is selected */
|
1994-05-29 05:44:26 +04:00
|
|
|
if (FDTESTC(FDB_CHANGED)) {
|
1996-04-29 10:23:47 +04:00
|
|
|
fdsetpos(sc, 0, 0);
|
1994-05-29 05:44:26 +04:00
|
|
|
sc->cachetrk = -1; /* invalidate the cache */
|
|
|
|
sc->flags &= ~FDF_HAVELABEL;
|
|
|
|
fdsetpos(sc, FDNHEADS, 0);
|
|
|
|
fdsetpos(sc, 0, 0);
|
|
|
|
if (FDTESTC(FDB_CHANGED)) {
|
|
|
|
fdmotoroff(sc);
|
1996-05-04 08:54:00 +04:00
|
|
|
FDDESELECT(sc->unitmask);
|
1994-05-29 05:44:26 +04:00
|
|
|
return(ENXIO);
|
|
|
|
}
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
1996-05-04 08:54:00 +04:00
|
|
|
FDDESELECT(sc->unitmask);
|
1994-05-29 05:44:26 +04:00
|
|
|
fdmotoroff(sc);
|
|
|
|
sc->type = fdcgetfdtype(sc->hwunit);
|
|
|
|
if (sc->type == NULL)
|
|
|
|
return(ENXIO);
|
|
|
|
if (sc->openpart == FDMSDOSPART)
|
|
|
|
sc->nsectors = sc->type->msdos_nsectors;
|
|
|
|
else
|
|
|
|
sc->nsectors = sc->type->amiga_nsectors;
|
|
|
|
return(0);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
1997-10-09 03:37:50 +04:00
|
|
|
void
|
|
|
|
fdgetdefaultlabel(sc, lp, part)
|
|
|
|
struct fd_softc *sc;
|
1997-10-11 20:13:19 +04:00
|
|
|
struct disklabel *lp;
|
1997-10-09 03:37:50 +04:00
|
|
|
int part; /* XXX ick */
|
|
|
|
{
|
|
|
|
|
|
|
|
bzero(lp, sizeof(struct disklabel));
|
|
|
|
lp->d_secsize = FDSECSIZE;
|
|
|
|
lp->d_ntracks = FDNHEADS;
|
|
|
|
lp->d_ncylinders = sc->type->ncylinders;
|
|
|
|
lp->d_nsectors = sc->nsectors;
|
|
|
|
lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
|
|
|
|
lp->d_type = DTYPE_FLOPPY;
|
|
|
|
lp->d_secperunit = lp->d_secpercyl * lp->d_ncylinders;
|
|
|
|
lp->d_rpm = 300; /* good guess I suppose. */
|
|
|
|
lp->d_interleave = 1; /* should change when adding msdos */
|
|
|
|
sc->stepdelay = lp->d_trkseek = FDSTEPDELAY;
|
|
|
|
lp->d_bbsize = 0;
|
|
|
|
lp->d_sbsize = 0;
|
|
|
|
lp->d_partitions[part].p_size = lp->d_secperunit;
|
|
|
|
lp->d_partitions[part].p_fstype = FS_UNUSED;
|
|
|
|
lp->d_partitions[part].p_fsize = 1024;
|
|
|
|
lp->d_partitions[part].p_frag = 8;
|
|
|
|
lp->d_partitions[part].p_cpg = 2; /* adosfs: reserved blocks */
|
|
|
|
lp->d_npartitions = part + 1;
|
|
|
|
lp->d_magic = lp->d_magic2 = DISKMAGIC;
|
|
|
|
lp->d_checksum = dkcksum(lp);
|
|
|
|
}
|
|
|
|
|
1994-04-06 03:04:05 +04:00
|
|
|
/*
|
1994-05-29 05:44:26 +04:00
|
|
|
* read disk label, if present otherwise create one
|
|
|
|
* return a new label if raw part and none found, otherwise err.
|
1994-04-06 03:04:05 +04:00
|
|
|
*/
|
1994-05-29 05:44:26 +04:00
|
|
|
int
|
|
|
|
fdgetdisklabel(sc, dev)
|
|
|
|
struct fd_softc *sc;
|
|
|
|
dev_t dev;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
struct disklabel *lp, *dlp;
|
|
|
|
struct cpu_disklabel *clp;
|
|
|
|
struct buf *bp;
|
|
|
|
int error, part;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1996-05-04 08:54:00 +04:00
|
|
|
if (sc->flags & FDF_HAVELABEL &&
|
|
|
|
sc->dkdev.dk_label->d_npartitions == (FDPART(dev) + 1))
|
1994-04-06 03:04:05 +04:00
|
|
|
return(0);
|
1994-05-29 05:44:26 +04:00
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("fdgetdisklabel()\n");
|
1994-05-29 05:44:26 +04:00
|
|
|
#endif
|
|
|
|
part = FDPART(dev);
|
1996-01-08 01:01:38 +03:00
|
|
|
lp = sc->dkdev.dk_label;
|
|
|
|
clp = sc->dkdev.dk_cpulabel;
|
1994-05-29 05:44:26 +04:00
|
|
|
bzero(lp, sizeof(struct disklabel));
|
|
|
|
bzero(clp, sizeof(struct cpu_disklabel));
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
lp->d_secsize = FDSECSIZE;
|
|
|
|
lp->d_ntracks = FDNHEADS;
|
|
|
|
lp->d_ncylinders = sc->type->ncylinders;
|
|
|
|
lp->d_nsectors = sc->nsectors;
|
|
|
|
lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
|
|
|
|
lp->d_secperunit = lp->d_secpercyl * lp->d_ncylinders;
|
|
|
|
lp->d_npartitions = part + 1;
|
|
|
|
lp->d_partitions[part].p_size = lp->d_secperunit;
|
|
|
|
lp->d_partitions[part].p_fstype = FS_UNUSED;
|
1994-06-16 19:06:49 +04:00
|
|
|
lp->d_partitions[part].p_fsize = 1024;
|
1994-05-29 05:44:26 +04:00
|
|
|
lp->d_partitions[part].p_frag = 8;
|
1996-04-05 09:08:07 +04:00
|
|
|
lp->d_partitions[part].p_cpg = 2; /* for adosfs: reserved blks */
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
sc->flags |= FDF_HAVELABEL;
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
bp = (void *)geteblk((int)lp->d_secsize);
|
1995-08-13 00:30:45 +04:00
|
|
|
bp->b_dev = dev;
|
1994-05-29 05:44:26 +04:00
|
|
|
bp->b_blkno = 0;
|
|
|
|
bp->b_cylin = 0;
|
|
|
|
bp->b_bcount = FDSECSIZE;
|
|
|
|
bp->b_flags = B_BUSY | B_READ;
|
|
|
|
fdstrategy(bp);
|
1996-04-22 01:10:48 +04:00
|
|
|
if ((error = biowait(bp)) != 0)
|
1994-05-29 05:44:26 +04:00
|
|
|
goto nolabel;
|
|
|
|
dlp = (struct disklabel *)(bp->b_data + LABELOFFSET);
|
|
|
|
if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC ||
|
|
|
|
dkcksum(dlp)) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto nolabel;
|
|
|
|
}
|
|
|
|
bcopy(dlp, lp, sizeof(struct disklabel));
|
|
|
|
if (lp->d_trkseek > FDSTEPDELAY)
|
|
|
|
sc->stepdelay = lp->d_trkseek;
|
|
|
|
brelse(bp);
|
|
|
|
return(0);
|
|
|
|
nolabel:
|
1997-10-09 03:37:50 +04:00
|
|
|
fdgetdefaultlabel(sc, lp, part);
|
1994-05-29 05:44:26 +04:00
|
|
|
brelse(bp);
|
|
|
|
return(0);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-05-29 05:44:26 +04:00
|
|
|
* set the incore copy of this units disklabel
|
1994-04-06 03:04:05 +04:00
|
|
|
*/
|
|
|
|
int
|
1994-05-29 05:44:26 +04:00
|
|
|
fdsetdisklabel(sc, lp)
|
|
|
|
struct fd_softc *sc;
|
|
|
|
struct disklabel *lp;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
struct disklabel *clp;
|
|
|
|
struct partition *pp;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
1995-08-13 00:30:45 +04:00
|
|
|
* must have at least opened raw unit to fetch the
|
1994-05-29 05:44:26 +04:00
|
|
|
* raw_part stuff.
|
|
|
|
*/
|
|
|
|
if ((sc->flags & FDF_HAVELABEL) == 0)
|
|
|
|
return(EINVAL);
|
1996-01-08 01:01:38 +03:00
|
|
|
clp = sc->dkdev.dk_label;
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* make sure things check out and we only have one valid
|
|
|
|
* partition
|
|
|
|
*/
|
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("fdsetdisklabel\n");
|
1994-05-29 05:44:26 +04:00
|
|
|
#endif
|
|
|
|
if (lp->d_secsize != FDSECSIZE ||
|
|
|
|
lp->d_nsectors != clp->d_nsectors ||
|
|
|
|
lp->d_ntracks != FDNHEADS ||
|
|
|
|
lp->d_ncylinders != clp->d_ncylinders ||
|
|
|
|
lp->d_secpercyl != clp->d_secpercyl ||
|
|
|
|
lp->d_secperunit != clp->d_secperunit ||
|
|
|
|
lp->d_magic != DISKMAGIC ||
|
|
|
|
lp->d_magic2 != DISKMAGIC ||
|
1994-06-05 11:45:08 +04:00
|
|
|
lp->d_npartitions == 0 ||
|
|
|
|
lp->d_npartitions > FDMAXPARTS ||
|
1994-05-29 05:44:26 +04:00
|
|
|
(lp->d_partitions[0].p_offset && lp->d_partitions[1].p_offset) ||
|
|
|
|
dkcksum(lp))
|
|
|
|
return(EINVAL);
|
1995-08-13 00:30:45 +04:00
|
|
|
/*
|
|
|
|
* if any partitions are present make sure they
|
1994-05-29 05:44:26 +04:00
|
|
|
* represent the currently open type
|
|
|
|
*/
|
|
|
|
if ((pp = &lp->d_partitions[0])->p_size) {
|
|
|
|
if ((pp = &lp->d_partitions[1])->p_size == 0)
|
|
|
|
goto done;
|
|
|
|
else if (sc->openpart != 1)
|
|
|
|
return(EINVAL);
|
|
|
|
} else if (sc->openpart != 0)
|
|
|
|
return(EINVAL);
|
1995-08-13 00:30:45 +04:00
|
|
|
/*
|
1994-05-29 05:44:26 +04:00
|
|
|
* make sure selected partition is within bounds
|
1995-08-13 00:30:45 +04:00
|
|
|
* XXX on the second check, its to handle a bug in
|
1994-06-16 19:06:49 +04:00
|
|
|
* XXX the cluster routines as they require mutliples
|
1999-12-05 00:13:19 +03:00
|
|
|
* XXX of NBPG currently
|
1994-05-29 05:44:26 +04:00
|
|
|
*/
|
1994-06-16 19:06:49 +04:00
|
|
|
if ((pp->p_offset + pp->p_size >= lp->d_secperunit) ||
|
1999-12-05 00:13:19 +03:00
|
|
|
(pp->p_frag * pp->p_fsize % NBPG))
|
1994-05-29 05:44:26 +04:00
|
|
|
return(EINVAL);
|
|
|
|
done:
|
|
|
|
bcopy(lp, clp, sizeof(struct disklabel));
|
1994-04-06 03:04:05 +04:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-05-29 05:44:26 +04:00
|
|
|
* write out the incore copy of this units disklabel
|
1994-04-06 03:04:05 +04:00
|
|
|
*/
|
1994-05-29 05:44:26 +04:00
|
|
|
int
|
|
|
|
fdputdisklabel(sc, dev)
|
|
|
|
struct fd_softc *sc;
|
|
|
|
dev_t dev;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
struct disklabel *lp, *dlp;
|
|
|
|
struct buf *bp;
|
|
|
|
int error;
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
if ((sc->flags & FDF_HAVELABEL) == 0)
|
|
|
|
return(EBADF);
|
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("fdputdisklabel\n");
|
1994-05-29 05:44:26 +04:00
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* get buf and read in sector 0
|
|
|
|
*/
|
1996-01-08 01:01:38 +03:00
|
|
|
lp = sc->dkdev.dk_label;
|
1994-05-29 05:44:26 +04:00
|
|
|
bp = (void *)geteblk((int)lp->d_secsize);
|
|
|
|
bp->b_dev = FDMAKEDEV(major(dev), FDUNIT(dev), RAW_PART);
|
|
|
|
bp->b_blkno = 0;
|
|
|
|
bp->b_cylin = 0;
|
|
|
|
bp->b_bcount = FDSECSIZE;
|
|
|
|
bp->b_flags = B_BUSY | B_READ;
|
|
|
|
fdstrategy(bp);
|
1996-04-22 01:10:48 +04:00
|
|
|
if ((error = biowait(bp)) != 0)
|
1994-05-29 05:44:26 +04:00
|
|
|
goto done;
|
|
|
|
/*
|
|
|
|
* copy disklabel to buf and write it out syncronous
|
|
|
|
*/
|
|
|
|
dlp = (struct disklabel *)(bp->b_data + LABELOFFSET);
|
|
|
|
bcopy(lp, dlp, sizeof(struct disklabel));
|
|
|
|
bp->b_blkno = 0;
|
|
|
|
bp->b_cylin = 0;
|
|
|
|
bp->b_flags = B_WRITE;
|
|
|
|
fdstrategy(bp);
|
|
|
|
error = biowait(bp);
|
|
|
|
done:
|
|
|
|
brelse(bp);
|
|
|
|
return(error);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* figure out drive type or NULL if none.
|
|
|
|
*/
|
|
|
|
struct fdtype *
|
|
|
|
fdcgetfdtype(unit)
|
1994-04-06 03:04:05 +04:00
|
|
|
int unit;
|
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
struct fdtype *ftp;
|
|
|
|
u_long id, idb;
|
|
|
|
int cnt, umask;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
|
|
|
id = 0;
|
1994-05-29 05:44:26 +04:00
|
|
|
umask = 1 << (3 + unit);
|
|
|
|
|
|
|
|
FDDESELECT(FDCUNITMASK);
|
|
|
|
|
|
|
|
FDSETMOTOR(1);
|
|
|
|
delay(1);
|
|
|
|
FDSELECT(umask);
|
|
|
|
delay(1);
|
|
|
|
FDDESELECT(umask);
|
|
|
|
|
|
|
|
FDSETMOTOR(0);
|
|
|
|
delay(1);
|
|
|
|
FDSELECT(umask);
|
|
|
|
delay(1);
|
|
|
|
FDDESELECT(umask);
|
|
|
|
|
|
|
|
for (idb = 0x80000000; idb; idb >>= 1) {
|
|
|
|
FDSELECT(umask);
|
|
|
|
delay(1);
|
|
|
|
if (FDTESTC(FDB_READY) == 0)
|
|
|
|
id |= idb;
|
|
|
|
FDDESELECT(umask);
|
|
|
|
delay(1);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
1994-05-29 05:44:26 +04:00
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("fdcgettype unit %d id 0x%lx\n", unit, id);
|
1994-04-06 03:04:05 +04:00
|
|
|
#endif
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
for (cnt = 0, ftp = fdtype; cnt < nfdtype; ftp++, cnt++)
|
|
|
|
if (ftp->driveid == id)
|
|
|
|
return(ftp);
|
|
|
|
/*
|
|
|
|
* 3.5dd's at unit 0 do not always return id.
|
|
|
|
*/
|
|
|
|
if (unit == 0)
|
|
|
|
return(fdtype);
|
|
|
|
return(NULL);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* turn motor off if possible otherwise mark as needed and will be done
|
|
|
|
* later.
|
|
|
|
*/
|
1994-04-06 03:04:05 +04:00
|
|
|
void
|
1994-05-29 05:44:26 +04:00
|
|
|
fdmotoroff(arg)
|
|
|
|
void *arg;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
struct fd_softc *sc;
|
1996-04-22 01:10:48 +04:00
|
|
|
int s;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
sc = arg;
|
|
|
|
s = splbio();
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("fdmotoroff: unit %d\n", sc->hwunit);
|
1994-05-29 05:44:26 +04:00
|
|
|
#endif
|
1995-08-13 00:30:45 +04:00
|
|
|
if ((sc->flags & FDF_MOTORON) == 0)
|
1994-05-29 05:44:26 +04:00
|
|
|
goto done;
|
|
|
|
/*
|
|
|
|
* if we have a timeout on a dma operation let fddmadone()
|
|
|
|
* deal with it.
|
|
|
|
*/
|
|
|
|
if (fdc_indma == sc) {
|
|
|
|
fddmadone(sc, 1);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" motor was on, turning off\n");
|
1994-05-29 05:44:26 +04:00
|
|
|
#endif
|
1994-04-22 06:20:48 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* flush cache if needed
|
|
|
|
*/
|
|
|
|
if (sc->flags & FDF_DIRTY) {
|
|
|
|
sc->flags |= FDF_JUSTFLUSH | FDF_MOTOROFF;
|
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" flushing dirty buffer first\n");
|
1994-05-29 05:44:26 +04:00
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* if dma'ing done for now, fddone() will call us again
|
|
|
|
*/
|
|
|
|
if (fdc_indma)
|
|
|
|
goto done;
|
|
|
|
fddmastart(sc, sc->cachetrk);
|
|
|
|
goto done;
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* if controller is busy just schedule us to be called back
|
|
|
|
*/
|
|
|
|
if (fdc_indma) {
|
|
|
|
/*
|
|
|
|
* someone else has the controller now
|
|
|
|
* just set flag and let fddone() call us again.
|
|
|
|
*/
|
|
|
|
sc->flags |= FDF_MOTOROFF;
|
|
|
|
goto done;
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
1994-05-29 05:44:26 +04:00
|
|
|
|
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" hw turning unit off\n");
|
1994-05-29 05:44:26 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
sc->flags &= ~(FDF_MOTORON | FDF_MOTOROFF);
|
|
|
|
FDDESELECT(FDCUNITMASK);
|
|
|
|
FDSETMOTOR(0);
|
|
|
|
delay(1);
|
|
|
|
FDSELECT(sc->unitmask);
|
|
|
|
delay(4);
|
|
|
|
FDDESELECT(sc->unitmask);
|
|
|
|
delay(1);
|
|
|
|
if (sc->flags & FDF_WMOTOROFF)
|
|
|
|
wakeup(fdmotoroff);
|
|
|
|
done:
|
|
|
|
splx(s);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* select drive seek to track exit with motor on.
|
|
|
|
* fdsetpos(x, 0, 0) does calibrates the drive.
|
|
|
|
*/
|
1994-04-06 03:04:05 +04:00
|
|
|
void
|
1994-05-29 05:44:26 +04:00
|
|
|
fdsetpos(sc, trk, towrite)
|
|
|
|
struct fd_softc *sc;
|
|
|
|
int trk, towrite;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-06-05 11:45:08 +04:00
|
|
|
int nstep, sdir, ondly, ncyl, nside;
|
1994-05-29 05:44:26 +04:00
|
|
|
|
|
|
|
FDDESELECT(FDCUNITMASK);
|
|
|
|
FDSETMOTOR(1);
|
|
|
|
delay(1);
|
|
|
|
FDSELECT(sc->unitmask);
|
|
|
|
delay(1);
|
1994-06-05 11:45:08 +04:00
|
|
|
if ((sc->flags & FDF_MOTORON) == 0) {
|
|
|
|
ondly = 0;
|
|
|
|
while (FDTESTC(FDB_READY) == 0) {
|
|
|
|
delay(1000);
|
|
|
|
if (++ondly >= 1000)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1994-05-29 05:44:26 +04:00
|
|
|
sc->flags |= FDF_MOTORON;
|
|
|
|
|
1994-06-05 11:45:08 +04:00
|
|
|
ncyl = trk / FDNHEADS;
|
|
|
|
nside = trk % FDNHEADS;
|
|
|
|
|
|
|
|
if (sc->curcyl == ncyl && fdc_side == nside)
|
1994-05-29 05:44:26 +04:00
|
|
|
return;
|
1994-06-05 11:45:08 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
if (towrite)
|
|
|
|
sc->flags |= FDF_WRITEWAIT;
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("fdsetpos: cyl %d head %d towrite %d\n", trk / FDNHEADS,
|
1994-05-29 05:44:26 +04:00
|
|
|
trk % FDNHEADS, towrite);
|
|
|
|
#endif
|
1994-06-05 11:45:08 +04:00
|
|
|
nstep = ncyl - sc->curcyl;
|
1994-05-29 05:44:26 +04:00
|
|
|
if (nstep) {
|
|
|
|
/*
|
|
|
|
* figure direction
|
|
|
|
*/
|
1994-06-07 09:41:51 +04:00
|
|
|
if (nstep > 0 && ncyl != 0) {
|
1994-05-29 05:44:26 +04:00
|
|
|
sdir = FDSTEPIN;
|
|
|
|
FDSETDIR(1);
|
|
|
|
} else {
|
|
|
|
nstep = -nstep;
|
|
|
|
sdir = FDSTEPOUT;
|
|
|
|
FDSETDIR(0);
|
|
|
|
}
|
1994-06-05 11:45:08 +04:00
|
|
|
if (ncyl == 0) {
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
1995-08-13 00:30:45 +04:00
|
|
|
* either just want cylinder 0 or doing
|
1994-05-29 05:44:26 +04:00
|
|
|
* a calibrate.
|
|
|
|
*/
|
1994-07-18 05:37:48 +04:00
|
|
|
nstep = 256;
|
|
|
|
while (FDTESTC(FDB_CYLZERO) == 0 && nstep--) {
|
1994-05-29 05:44:26 +04:00
|
|
|
FDSTEP;
|
|
|
|
delay(sc->stepdelay);
|
|
|
|
}
|
1994-07-18 05:37:48 +04:00
|
|
|
if (nstep < 0)
|
|
|
|
sc->flags |= FDF_NOTRACK0;
|
1994-05-29 05:44:26 +04:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* step the needed amount amount.
|
|
|
|
*/
|
|
|
|
while (nstep--) {
|
|
|
|
FDSTEP;
|
|
|
|
delay(sc->stepdelay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
1995-08-13 00:30:45 +04:00
|
|
|
* if switched directions
|
1994-05-29 05:44:26 +04:00
|
|
|
* allow drive to settle.
|
|
|
|
*/
|
|
|
|
if (sc->pstepdir != sdir)
|
|
|
|
delay(FDSETTLEDELAY);
|
|
|
|
sc->pstepdir = sdir;
|
1994-06-05 11:45:08 +04:00
|
|
|
sc->curcyl = ncyl;
|
1994-05-29 05:44:26 +04:00
|
|
|
}
|
1994-06-05 11:45:08 +04:00
|
|
|
if (nside == fdc_side)
|
1994-05-29 05:44:26 +04:00
|
|
|
return;
|
|
|
|
/*
|
|
|
|
* select side
|
|
|
|
*/
|
1994-06-05 11:45:08 +04:00
|
|
|
fdc_side = nside;
|
|
|
|
FDSETHEAD(nside);
|
1994-05-29 05:44:26 +04:00
|
|
|
delay(FDPRESIDEDELAY);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1994-05-29 05:44:26 +04:00
|
|
|
fdselunit(sc)
|
|
|
|
struct fd_softc *sc;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
FDDESELECT(FDCUNITMASK); /* deselect all */
|
|
|
|
FDSETMOTOR(sc->flags & FDF_MOTORON); /* set motor to unit's state */
|
|
|
|
delay(1);
|
|
|
|
FDSELECT(sc->unitmask); /* select unit */
|
|
|
|
delay(1);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-05-29 05:44:26 +04:00
|
|
|
* process next buf on device queue.
|
|
|
|
* normall sequence of events:
|
1995-08-13 00:30:45 +04:00
|
|
|
* fdstart() -> fddmastart();
|
1996-05-04 08:54:00 +04:00
|
|
|
* fdidxintr();
|
1994-05-29 05:44:26 +04:00
|
|
|
* fdintr() -> fddmadone() -> fddone();
|
|
|
|
* if the track is in the cache then fdstart() will short-circuit
|
|
|
|
* to fddone() else if the track cache is dirty it will flush. If
|
|
|
|
* the buf is not an entire track it will cache the requested track.
|
1994-04-06 03:04:05 +04:00
|
|
|
*/
|
1994-05-29 05:44:26 +04:00
|
|
|
void
|
|
|
|
fdstart(sc)
|
|
|
|
struct fd_softc *sc;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
int trk, error, write;
|
|
|
|
struct buf *bp, *dp;
|
1996-05-04 08:54:00 +04:00
|
|
|
int changed;
|
1994-05-29 05:44:26 +04:00
|
|
|
|
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("fdstart: unit %d\n", sc->hwunit);
|
1994-05-29 05:44:26 +04:00
|
|
|
#endif
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* if dma'ing just return. we must have been called from fdstartegy.
|
|
|
|
*/
|
|
|
|
if (fdc_indma)
|
|
|
|
return;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* get next buf if there.
|
|
|
|
*/
|
|
|
|
dp = &sc->bufq;
|
|
|
|
if ((bp = dp->b_actf) == NULL) {
|
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" nothing to do\n");
|
1994-05-29 05:44:26 +04:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1996-01-16 00:53:50 +03:00
|
|
|
/*
|
|
|
|
* Mark us as busy now, in case fddone() gets called in one
|
|
|
|
* of the cases below.
|
|
|
|
*/
|
|
|
|
disk_busy(&sc->dkdev);
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* make sure same disk is loaded
|
|
|
|
*/
|
|
|
|
fdselunit(sc);
|
1996-05-04 08:54:00 +04:00
|
|
|
changed = FDTESTC(FDB_CHANGED);
|
|
|
|
FDDESELECT(sc->unitmask);
|
|
|
|
if (changed) {
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
1995-08-13 00:30:45 +04:00
|
|
|
* disk missing, invalidate all future io on
|
|
|
|
* this unit until re-open()'ed also invalidate
|
1994-05-29 05:44:26 +04:00
|
|
|
* all current io
|
|
|
|
*/
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("fdstart: disk changed\n");
|
1994-05-29 05:44:26 +04:00
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" disk was removed invalidating all io\n");
|
1994-05-29 05:44:26 +04:00
|
|
|
#endif
|
|
|
|
sc->flags &= ~FDF_HAVELABEL;
|
|
|
|
for (;;) {
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_error = EIO;
|
|
|
|
if (bp->b_actf == NULL)
|
|
|
|
break;
|
|
|
|
biodone(bp);
|
|
|
|
bp = bp->b_actf;
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* do fddone() on last buf to allow other units to start.
|
|
|
|
*/
|
|
|
|
dp->b_actf = bp;
|
|
|
|
fddone(sc);
|
|
|
|
return;
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
1995-08-13 00:30:45 +04:00
|
|
|
/*
|
1994-05-29 05:44:26 +04:00
|
|
|
* we have a valid buf, setup our local version
|
|
|
|
* we use this count to allow reading over multiple tracks.
|
|
|
|
* into a single buffer
|
|
|
|
*/
|
|
|
|
dp->b_bcount = bp->b_bcount;
|
|
|
|
dp->b_blkno = bp->b_blkno;
|
|
|
|
dp->b_data = bp->b_data;
|
|
|
|
dp->b_flags = bp->b_flags;
|
|
|
|
dp->b_resid = 0;
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
if (bp->b_flags & B_READ)
|
|
|
|
write = 0;
|
|
|
|
else if (FDTESTC(FDB_PROTECT) == 0)
|
|
|
|
write = 1;
|
|
|
|
else {
|
|
|
|
error = EPERM;
|
|
|
|
goto bad;
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* figure trk given blkno
|
|
|
|
*/
|
|
|
|
trk = bp->b_blkno / sc->nsectors;
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* check to see if same as currently cached track
|
|
|
|
* if so we need to do no dma read.
|
|
|
|
*/
|
|
|
|
if (trk == sc->cachetrk) {
|
|
|
|
fddone(sc);
|
|
|
|
return;
|
|
|
|
}
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
1995-08-13 00:30:45 +04:00
|
|
|
* if we will be overwriting the entire cache, don't bother to
|
1994-05-29 05:44:26 +04:00
|
|
|
* fetch it.
|
|
|
|
*/
|
1994-06-20 10:36:47 +04:00
|
|
|
if (bp->b_bcount == (sc->nsectors * FDSECSIZE) && write &&
|
|
|
|
bp->b_blkno % sc->nsectors == 0) {
|
1994-05-29 05:44:26 +04:00
|
|
|
if (sc->flags & FDF_DIRTY)
|
|
|
|
sc->flags |= FDF_JUSTFLUSH;
|
|
|
|
else {
|
|
|
|
sc->cachetrk = trk;
|
|
|
|
fddone(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* start dma read of `trk'
|
|
|
|
*/
|
|
|
|
fddmastart(sc, trk);
|
|
|
|
return;
|
|
|
|
bad:
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_error = error;
|
|
|
|
fddone(sc);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
1995-08-13 00:30:45 +04:00
|
|
|
* continue a started operation on next track. always begin at
|
1994-06-20 10:36:47 +04:00
|
|
|
* sector 0 on the next track.
|
1994-05-29 05:44:26 +04:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
fdcont(sc)
|
|
|
|
struct fd_softc *sc;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
struct buf *dp, *bp;
|
|
|
|
int trk, write;
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
dp = &sc->bufq;
|
|
|
|
bp = dp->b_actf;
|
|
|
|
dp->b_data += (dp->b_bcount - bp->b_resid);
|
|
|
|
dp->b_blkno += (dp->b_bcount - bp->b_resid) / FDSECSIZE;
|
|
|
|
dp->b_bcount = bp->b_resid;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-04-22 06:20:48 +04:00
|
|
|
/*
|
1994-05-29 05:44:26 +04:00
|
|
|
* figure trk given blkno
|
1994-04-22 06:20:48 +04:00
|
|
|
*/
|
1994-05-29 05:44:26 +04:00
|
|
|
trk = dp->b_blkno / sc->nsectors;
|
|
|
|
#ifdef DEBUG
|
1994-06-20 10:36:47 +04:00
|
|
|
if (trk != sc->cachetrk + 1 || dp->b_blkno % sc->nsectors != 0)
|
1994-05-29 05:44:26 +04:00
|
|
|
panic("fdcont: confused");
|
1994-04-22 06:20:48 +04:00
|
|
|
#endif
|
1994-05-29 05:44:26 +04:00
|
|
|
if (dp->b_flags & B_READ)
|
|
|
|
write = 0;
|
|
|
|
else
|
|
|
|
write = 1;
|
|
|
|
/*
|
1995-08-13 00:30:45 +04:00
|
|
|
* if we will be overwriting the entire cache, don't bother to
|
1994-05-29 05:44:26 +04:00
|
|
|
* fetch it.
|
|
|
|
*/
|
|
|
|
if (dp->b_bcount == (sc->nsectors * FDSECSIZE) && write) {
|
|
|
|
if (sc->flags & FDF_DIRTY)
|
|
|
|
sc->flags |= FDF_JUSTFLUSH;
|
|
|
|
else {
|
|
|
|
sc->cachetrk = trk;
|
|
|
|
fddone(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* start dma read of `trk'
|
|
|
|
*/
|
|
|
|
fddmastart(sc, trk);
|
|
|
|
return;
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
void
|
|
|
|
fddmastart(sc, trk)
|
|
|
|
struct fd_softc *sc;
|
|
|
|
int trk;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
int adkmask, ndmaw, write, dmatrk;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("fddmastart: unit %d cyl %d head %d", sc->hwunit,
|
1994-05-29 05:44:26 +04:00
|
|
|
trk / FDNHEADS, trk % FDNHEADS);
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* flush the cached track if dirty else read requested track.
|
|
|
|
*/
|
|
|
|
if (sc->flags & FDF_DIRTY) {
|
|
|
|
fdcachetoraw(sc);
|
|
|
|
ndmaw = sc->type->nwritew;
|
|
|
|
dmatrk = sc->cachetrk;
|
|
|
|
write = 1;
|
|
|
|
} else {
|
|
|
|
ndmaw = sc->type->nreadw;
|
|
|
|
dmatrk = trk;
|
|
|
|
write = 0;
|
|
|
|
}
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" %s", write ? " flushing cache\n" : " loading cache\n");
|
1994-05-29 05:44:26 +04:00
|
|
|
#endif
|
|
|
|
sc->cachetrk = trk;
|
|
|
|
fdc_indma = sc;
|
|
|
|
fdsetpos(sc, dmatrk, write);
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* setup dma stuff
|
|
|
|
*/
|
|
|
|
if (write == 0) {
|
|
|
|
custom.adkcon = ADKF_MSBSYNC;
|
|
|
|
custom.adkcon = ADKF_SETCLR | ADKF_WORDSYNC | ADKF_FAST;
|
|
|
|
custom.dsksync = FDMFMSYNC;
|
|
|
|
} else {
|
|
|
|
custom.adkcon = ADKF_PRECOMP1 | ADKF_PRECOMP0 | ADKF_WORDSYNC |
|
|
|
|
ADKF_MSBSYNC;
|
|
|
|
adkmask = ADKF_SETCLR | ADKF_FAST | ADKF_MFMPREC;
|
|
|
|
if (dmatrk >= sc->type->precomp[0])
|
|
|
|
adkmask |= ADKF_PRECOMP0;
|
|
|
|
if (dmatrk >= sc->type->precomp[1])
|
|
|
|
adkmask |= ADKF_PRECOMP1;
|
|
|
|
custom.adkcon = adkmask;
|
|
|
|
}
|
|
|
|
custom.dskpt = (u_char *)kvtop(fdc_dmap);
|
1996-05-04 08:54:00 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If writing an MSDOS track, activate disk index pulse
|
|
|
|
* interrupt, dma will be started in the intr routine fdidxintr()
|
|
|
|
* Otherwise, start the DMA here.
|
|
|
|
*/
|
|
|
|
if (write && sc->openpart == FDMSDOSPART) {
|
|
|
|
fdc_dmalen = ndmaw;
|
|
|
|
fdc_dmawrite = write;
|
|
|
|
ciab.icr = CIA_ICR_IR_SC | CIA_ICR_FLG;
|
|
|
|
} else {
|
|
|
|
FDDMASTART(ndmaw, write);
|
|
|
|
fdc_dmalen = 0;
|
|
|
|
}
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" dma started\n");
|
1994-05-29 05:44:26 +04:00
|
|
|
#endif
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* recalibrate the drive
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
fdcalibrate(arg)
|
|
|
|
void *arg;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
struct fd_softc *sc;
|
|
|
|
static int loopcnt;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
sc = arg;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
if (loopcnt == 0) {
|
|
|
|
/*
|
|
|
|
* seek cyl 0
|
|
|
|
*/
|
|
|
|
fdc_indma = sc;
|
|
|
|
sc->stepdelay += 900;
|
|
|
|
if (sc->cachetrk > 1)
|
|
|
|
fdsetpos(sc, sc->cachetrk % FDNHEADS, 0);
|
|
|
|
sc->stepdelay -= 900;
|
|
|
|
}
|
|
|
|
if (loopcnt++ & 1)
|
|
|
|
fdsetpos(sc, sc->cachetrk, 0);
|
|
|
|
else
|
|
|
|
fdsetpos(sc, sc->cachetrk + FDNHEADS, 0);
|
|
|
|
/*
|
|
|
|
* trk++, trk, trk++, trk, trk++, trk, trk++, trk and dma
|
|
|
|
*/
|
|
|
|
if (loopcnt < 8)
|
|
|
|
timeout(fdcalibrate, sc, hz / 8);
|
|
|
|
else {
|
|
|
|
loopcnt = 0;
|
|
|
|
fdc_indma = NULL;
|
|
|
|
timeout(fdmotoroff, sc, 3 * hz / 2);
|
|
|
|
fddmastart(sc, sc->cachetrk);
|
|
|
|
}
|
|
|
|
}
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
void
|
|
|
|
fddmadone(sc, timeo)
|
|
|
|
struct fd_softc *sc;
|
|
|
|
int timeo;
|
|
|
|
{
|
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("fddmadone: unit %d, timeo %d\n", sc->hwunit, timeo);
|
1994-05-29 05:44:26 +04:00
|
|
|
#endif
|
|
|
|
fdc_indma = NULL;
|
|
|
|
untimeout(fdmotoroff, sc);
|
|
|
|
FDDMASTOP;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* guarantee the drive has been at current head and cyl
|
|
|
|
* for at least FDWRITEDELAY after a write.
|
|
|
|
*/
|
|
|
|
if (sc->flags & FDF_WRITEWAIT) {
|
|
|
|
delay(FDWRITEDELAY);
|
|
|
|
sc->flags &= ~FDF_WRITEWAIT;
|
|
|
|
}
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
if ((sc->flags & FDF_MOTOROFF) == 0) {
|
|
|
|
/*
|
|
|
|
* motor runs for 1.5 seconds after last dma
|
|
|
|
*/
|
|
|
|
timeout(fdmotoroff, sc, 3 * hz / 2);
|
|
|
|
}
|
|
|
|
if (sc->flags & FDF_DIRTY) {
|
|
|
|
/*
|
|
|
|
* if buffer dirty, the last dma cleaned it
|
|
|
|
*/
|
|
|
|
sc->flags &= ~FDF_DIRTY;
|
|
|
|
if (timeo)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("%s: write of track cache timed out.\n",
|
1996-01-14 03:23:56 +03:00
|
|
|
sc->sc_dv.dv_xname);
|
1994-05-29 05:44:26 +04:00
|
|
|
if (sc->flags & FDF_JUSTFLUSH) {
|
1994-06-20 10:36:47 +04:00
|
|
|
sc->flags &= ~FDF_JUSTFLUSH;
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* we are done dma'ing
|
|
|
|
*/
|
|
|
|
fddone(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* load the cache
|
|
|
|
*/
|
|
|
|
fddmastart(sc, sc->cachetrk);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#ifdef FDDEBUG
|
|
|
|
else if (sc->flags & FDF_MOTOROFF)
|
|
|
|
panic("fddmadone: FDF_MOTOROFF with no FDF_DIRTY");
|
|
|
|
#endif
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* cache loaded decode it into cache buffer
|
|
|
|
*/
|
|
|
|
if (timeo == 0 && fdrawtocache(sc) == 0)
|
|
|
|
sc->retried = 0;
|
|
|
|
else {
|
|
|
|
#ifdef FDDEBUG
|
|
|
|
if (timeo)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("%s: fddmadone: cache load timed out.\n",
|
1996-01-08 01:01:38 +03:00
|
|
|
sc->sc_dv.dv_xname);
|
1994-05-29 05:44:26 +04:00
|
|
|
#endif
|
|
|
|
if (sc->retried >= sc->retries) {
|
|
|
|
sc->retried = 0;
|
|
|
|
sc->cachetrk = -1;
|
|
|
|
} else {
|
|
|
|
sc->retried++;
|
|
|
|
/*
|
|
|
|
* this will be restarted at end of calibrate loop.
|
|
|
|
*/
|
|
|
|
untimeout(fdmotoroff, sc);
|
|
|
|
fdcalibrate(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fddone(sc);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1994-05-29 05:44:26 +04:00
|
|
|
fddone(sc)
|
|
|
|
struct fd_softc *sc;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
struct buf *dp, *bp;
|
|
|
|
char *data;
|
1996-04-22 01:10:48 +04:00
|
|
|
int sz;
|
1994-05-29 05:44:26 +04:00
|
|
|
|
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("fddone: unit %d\n", sc->hwunit);
|
1994-05-29 05:44:26 +04:00
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* check to see if unit is just flushing the cache,
|
1994-06-20 10:36:47 +04:00
|
|
|
* that is we have no io queued.
|
1994-05-29 05:44:26 +04:00
|
|
|
*/
|
|
|
|
if (sc->flags & FDF_MOTOROFF)
|
1994-06-20 10:36:47 +04:00
|
|
|
goto nobuf;
|
1994-05-29 05:44:26 +04:00
|
|
|
|
|
|
|
dp = &sc->bufq;
|
|
|
|
if ((bp = dp->b_actf) == NULL)
|
|
|
|
panic ("fddone");
|
1994-04-06 03:04:05 +04:00
|
|
|
/*
|
1994-05-29 05:44:26 +04:00
|
|
|
* check for an error that may have occured
|
|
|
|
* while getting the track.
|
1994-04-06 03:04:05 +04:00
|
|
|
*/
|
1994-05-29 05:44:26 +04:00
|
|
|
if (sc->cachetrk == -1) {
|
|
|
|
sc->retried = 0;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_error = EIO;
|
|
|
|
} else if ((bp->b_flags & B_ERROR) == 0) {
|
|
|
|
data = sc->cachep;
|
|
|
|
/*
|
|
|
|
* get offset of data in track cache and limit
|
|
|
|
* the copy size to not exceed the cache's end.
|
|
|
|
*/
|
|
|
|
data += (dp->b_blkno % sc->nsectors) * FDSECSIZE;
|
|
|
|
sz = sc->nsectors - dp->b_blkno % sc->nsectors;
|
|
|
|
sz *= FDSECSIZE;
|
|
|
|
sz = min(dp->b_bcount, sz);
|
|
|
|
if (bp->b_flags & B_READ)
|
|
|
|
bcopy(data, dp->b_data, sz);
|
|
|
|
else {
|
|
|
|
bcopy(dp->b_data, data, sz);
|
|
|
|
sc->flags |= FDF_DIRTY;
|
1994-04-22 06:20:48 +04:00
|
|
|
}
|
1994-05-29 05:44:26 +04:00
|
|
|
bp->b_resid = dp->b_bcount - sz;
|
|
|
|
if (bp->b_resid == 0) {
|
|
|
|
bp->b_error = 0;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* not done yet need to read next track
|
|
|
|
*/
|
|
|
|
fdcont(sc);
|
1994-04-22 06:20:48 +04:00
|
|
|
return;
|
|
|
|
}
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* remove from queue.
|
|
|
|
*/
|
|
|
|
dp->b_actf = bp->b_actf;
|
1996-01-08 01:01:38 +03:00
|
|
|
|
|
|
|
disk_unbusy(&sc->dkdev, (bp->b_bcount - bp->b_resid));
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
biodone(bp);
|
|
|
|
nobuf:
|
1996-01-08 01:01:38 +03:00
|
|
|
fdfindwork(sc->sc_dv.dv_unit);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1994-05-29 05:44:26 +04:00
|
|
|
fdfindwork(unit)
|
|
|
|
int unit;
|
1995-08-13 00:30:45 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
struct fd_softc *ssc, *sc;
|
|
|
|
int i, last;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
1996-04-22 01:10:48 +04:00
|
|
|
* first see if we have any fdopen()'s waiting
|
1994-05-29 05:44:26 +04:00
|
|
|
*/
|
|
|
|
if (fdc_wantwakeup) {
|
1996-04-22 01:10:48 +04:00
|
|
|
wakeup(fdopen);
|
1994-05-29 05:44:26 +04:00
|
|
|
fdc_wantwakeup--;
|
|
|
|
return;
|
|
|
|
}
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* start next available unit, linear search from the next unit
|
|
|
|
* wrapping and finally this unit.
|
|
|
|
*/
|
|
|
|
last = 0;
|
|
|
|
ssc = NULL;
|
|
|
|
for (i = unit + 1; last == 0; i++) {
|
|
|
|
if (i == unit)
|
|
|
|
last = 1;
|
1996-03-17 04:16:48 +03:00
|
|
|
if (i >= fd_cd.cd_ndevs) {
|
1994-05-29 05:44:26 +04:00
|
|
|
i = -1;
|
|
|
|
continue;
|
|
|
|
}
|
1996-03-17 04:16:48 +03:00
|
|
|
if ((sc = fd_cd.cd_devs[i]) == NULL)
|
1994-05-29 05:44:26 +04:00
|
|
|
continue;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
1995-08-13 00:30:45 +04:00
|
|
|
* if unit has requested to be turned off
|
1994-05-29 05:44:26 +04:00
|
|
|
* and it has no buf's queued do it now
|
|
|
|
*/
|
|
|
|
if (sc->flags & FDF_MOTOROFF) {
|
|
|
|
if (sc->bufq.b_actf == NULL)
|
|
|
|
fdmotoroff(sc);
|
|
|
|
else {
|
|
|
|
/*
|
1995-08-13 00:30:45 +04:00
|
|
|
* we gained a buf request while
|
1994-05-29 05:44:26 +04:00
|
|
|
* we waited, forget the motoroff
|
|
|
|
*/
|
|
|
|
sc->flags &= ~FDF_MOTOROFF;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* if we now have dma unit must have needed
|
|
|
|
* flushing, quit
|
|
|
|
*/
|
|
|
|
if (fdc_indma)
|
|
|
|
return;
|
1995-08-13 00:30:45 +04:00
|
|
|
}
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* if we have no start unit and the current unit has
|
|
|
|
* io waiting choose this unit to start.
|
|
|
|
*/
|
|
|
|
if (ssc == NULL && sc->bufq.b_actf)
|
|
|
|
ssc = sc;
|
|
|
|
}
|
|
|
|
if (ssc)
|
|
|
|
fdstart(ssc);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* min byte count to whats left of the track in question
|
|
|
|
*/
|
1995-08-13 00:30:45 +04:00
|
|
|
void
|
1994-05-29 05:44:26 +04:00
|
|
|
fdminphys(bp)
|
|
|
|
struct buf *bp;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
struct fd_softc *sc;
|
|
|
|
int trk, sec, toff, tsz;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1996-03-17 04:16:48 +03:00
|
|
|
if ((sc = getsoftc(fd_cd, FDUNIT(bp->b_dev))) == NULL)
|
1995-07-24 11:25:46 +04:00
|
|
|
panic("fdminphys: couldn't get softc");
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
trk = bp->b_blkno / sc->nsectors;
|
|
|
|
sec = bp->b_blkno % sc->nsectors;
|
1994-04-22 06:20:48 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
toff = sec * FDSECSIZE;
|
|
|
|
tsz = sc->nsectors * FDSECSIZE;
|
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("fdminphys: before %d", bp->b_bcount);
|
1994-04-22 06:20:48 +04:00
|
|
|
#endif
|
1994-05-29 05:44:26 +04:00
|
|
|
bp->b_bcount = min(bp->b_bcount, tsz - toff);
|
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" after %d\n", bp->b_bcount);
|
1994-05-29 05:44:26 +04:00
|
|
|
#endif
|
1995-08-13 00:30:45 +04:00
|
|
|
minphys(bp);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-05-29 05:44:26 +04:00
|
|
|
* encode the track cache into raw MFM ready for dma
|
|
|
|
* when we go to multiple disk formats, this will call type dependent
|
|
|
|
* functions
|
1994-04-06 03:04:05 +04:00
|
|
|
*/
|
1996-05-04 08:54:00 +04:00
|
|
|
void fdcachetoraw(sc)
|
|
|
|
struct fd_softc *sc;
|
|
|
|
{
|
|
|
|
if (sc->openpart == FDMSDOSPART)
|
|
|
|
mscachetoraw(sc);
|
|
|
|
else
|
|
|
|
amcachetoraw(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* decode raw MFM from dma into units track cache.
|
|
|
|
* when we go to multiple disk formats, this will call type dependent
|
|
|
|
* functions
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
fdrawtocache(sc)
|
|
|
|
struct fd_softc *sc;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (sc->openpart == FDMSDOSPART)
|
|
|
|
return(msrawtocache(sc));
|
|
|
|
else
|
|
|
|
return(amrawtocache(sc));
|
|
|
|
}
|
|
|
|
|
1994-04-06 03:04:05 +04:00
|
|
|
void
|
1996-05-04 08:54:00 +04:00
|
|
|
amcachetoraw(sc)
|
1994-05-29 05:44:26 +04:00
|
|
|
struct fd_softc *sc;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
static u_long mfmnull[4];
|
|
|
|
u_long *rp, *crp, *dp, hcksum, dcksum, info, zero;
|
|
|
|
int sec, i;
|
|
|
|
|
|
|
|
rp = fdc_dmap;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* not yet one sector (- 1 long) gap.
|
|
|
|
* for now use previous drivers values
|
|
|
|
*/
|
|
|
|
for (i = 0; i < sc->type->gap; i++)
|
|
|
|
*rp++ = 0xaaaaaaaa;
|
|
|
|
/*
|
|
|
|
* process sectors
|
|
|
|
*/
|
|
|
|
dp = sc->cachep;
|
|
|
|
zero = 0;
|
|
|
|
info = 0xff000000 | (sc->cachetrk << 16) | sc->nsectors;
|
|
|
|
for (sec = 0; sec < sc->nsectors; sec++, info += (1 << 8) - 1) {
|
|
|
|
hcksum = dcksum = 0;
|
|
|
|
/*
|
|
|
|
* sector format
|
|
|
|
* offset description
|
|
|
|
*-----------------------------------
|
1995-08-13 00:30:45 +04:00
|
|
|
* 0 null
|
|
|
|
* 1 sync
|
1994-05-29 05:44:26 +04:00
|
|
|
* oddbits evenbits
|
|
|
|
*----------------------
|
|
|
|
* 2 3 [0xff]b [trk]b [sec]b [togap]b
|
|
|
|
* 4-7 8-11 null
|
|
|
|
* 12 13 header cksum [2-11]
|
|
|
|
* 14 15 data cksum [16-271]
|
|
|
|
* 16-143 144-271 data
|
|
|
|
*/
|
|
|
|
*rp = 0xaaaaaaaa;
|
|
|
|
if (*(rp - 1) & 0x1)
|
|
|
|
*rp &= 0x7fffffff; /* clock bit correction */
|
|
|
|
rp++;
|
|
|
|
*rp++ = (FDMFMSYNC << 16) | FDMFMSYNC;
|
|
|
|
rp = mfmblkencode(&info, rp, &hcksum, 1);
|
|
|
|
rp = mfmblkencode(mfmnull, rp, &hcksum, 4);
|
|
|
|
rp = mfmblkencode(&hcksum, rp, NULL, 1);
|
|
|
|
|
|
|
|
crp = rp;
|
|
|
|
rp = mfmblkencode(dp, rp + 2, &dcksum, FDSECLWORDS);
|
|
|
|
dp += FDSECLWORDS;
|
|
|
|
crp = mfmblkencode(&dcksum, crp, NULL, 1);
|
|
|
|
if (*(crp - 1) & 0x1)
|
|
|
|
*crp &= 0x7fffffff; /* clock bit correction */
|
|
|
|
else if ((*crp & 0x40000000) == 0)
|
|
|
|
*crp |= 0x80000000;
|
1996-05-04 08:54:00 +04:00
|
|
|
}
|
1994-05-29 05:44:26 +04:00
|
|
|
*rp = 0xaaa80000;
|
|
|
|
if (*(rp - 1) & 0x1)
|
|
|
|
*rp &= 0x7fffffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
u_long *
|
|
|
|
fdfindsync(rp, ep)
|
|
|
|
u_long *rp, *ep;
|
|
|
|
{
|
|
|
|
u_short *sp;
|
|
|
|
|
|
|
|
sp = (u_short *)rp;
|
|
|
|
while ((u_long *)sp < ep && *sp != FDMFMSYNC)
|
|
|
|
sp++;
|
|
|
|
while ((u_long *)sp < ep && *sp == FDMFMSYNC)
|
|
|
|
sp++;
|
|
|
|
if ((u_long *)sp < ep)
|
|
|
|
return((u_long *)sp);
|
|
|
|
return(NULL);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1996-05-04 08:54:00 +04:00
|
|
|
amrawtocache(sc)
|
1994-05-29 05:44:26 +04:00
|
|
|
struct fd_softc *sc;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
u_long mfmnull[4];
|
|
|
|
u_long *dp, *rp, *erp, *crp, *srp, hcksum, dcksum, info, cktmp;
|
|
|
|
int cnt, doagain;
|
|
|
|
|
|
|
|
doagain = 1;
|
|
|
|
srp = rp = fdc_dmap;
|
|
|
|
erp = (u_long *)((u_short *)rp + sc->type->nreadw);
|
|
|
|
cnt = 0;
|
|
|
|
again:
|
|
|
|
if (doagain == 0 || (rp = srp = fdfindsync(srp, erp)) == NULL) {
|
|
|
|
#ifdef DIAGNOSTIC
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("%s: corrupted track (%d) data.\n",
|
1996-01-08 01:01:38 +03:00
|
|
|
sc->sc_dv.dv_xname, sc->cachetrk);
|
1994-05-29 05:44:26 +04:00
|
|
|
#endif
|
|
|
|
return(-1);
|
|
|
|
}
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* process sectors
|
|
|
|
*/
|
|
|
|
for (; cnt < sc->nsectors; cnt++) {
|
|
|
|
hcksum = dcksum = 0;
|
|
|
|
rp = mfmblkdecode(rp, &info, &hcksum, 1);
|
|
|
|
rp = mfmblkdecode(rp, mfmnull, &hcksum, 4);
|
|
|
|
rp = mfmblkdecode(rp, &cktmp, NULL, 1);
|
|
|
|
if (cktmp != hcksum) {
|
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" info 0x%x hchksum 0x%x trkhcksum 0x%x\n",
|
1994-05-29 05:44:26 +04:00
|
|
|
info, hcksum, cktmp);
|
|
|
|
#endif
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
if (((info >> 16) & 0xff) != sc->cachetrk) {
|
|
|
|
#ifdef DEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("%s: incorrect track found: 0x%lx %d\n",
|
1996-01-08 01:01:38 +03:00
|
|
|
sc->sc_dv.dv_xname, info, sc->cachetrk);
|
1994-05-29 05:44:26 +04:00
|
|
|
#endif
|
|
|
|
goto again;
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
1994-05-29 05:44:26 +04:00
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" info 0x%x\n", info);
|
1994-05-29 05:44:26 +04:00
|
|
|
#endif
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
rp = mfmblkdecode(rp, &cktmp, NULL, 1);
|
|
|
|
dp = sc->cachep;
|
|
|
|
dp += FDSECLWORDS * ((info >> 8) & 0xff);
|
|
|
|
crp = mfmblkdecode(rp, dp, &dcksum, FDSECLWORDS);
|
|
|
|
if (cktmp != dcksum) {
|
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" info 0x%x dchksum 0x%x trkdcksum 0x%x\n",
|
1994-05-29 05:44:26 +04:00
|
|
|
info, dcksum, cktmp);
|
|
|
|
#endif
|
|
|
|
goto again;
|
|
|
|
}
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* if we are at gap then we can no longer be sure
|
|
|
|
* of correct sync marks
|
|
|
|
*/
|
|
|
|
if ((info && 0xff) == 1)
|
|
|
|
doagain = 1;
|
|
|
|
else
|
|
|
|
doagain = 0;
|
|
|
|
srp = rp = fdfindsync(crp, erp);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
1994-05-29 05:44:26 +04:00
|
|
|
return(0);
|
|
|
|
}
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1996-05-04 08:54:00 +04:00
|
|
|
void
|
|
|
|
mscachetoraw(sc)
|
|
|
|
struct fd_softc *sc;
|
|
|
|
{
|
|
|
|
u_short *rp, *erp, crc;
|
|
|
|
u_char *cp, tb[5];
|
|
|
|
int sec, i;
|
|
|
|
|
|
|
|
rp = (u_short *)fdc_dmap;
|
|
|
|
erp = rp + sc->type->nwritew;
|
|
|
|
cp = sc->cachep;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* initial track filler (828 * GAP1)
|
|
|
|
*/
|
|
|
|
for (i = 0; i < sc->type->gap; i++) {
|
|
|
|
*rp++ = FDMFMGAP1;
|
|
|
|
*rp++ = FDMFMGAP1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (sec = 0; sec < sc->nsectors; sec++) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* leading sector gap
|
|
|
|
* (12 * GAP2) + (3 * SYNC)
|
|
|
|
*/
|
|
|
|
for (i = 0; i < 12; i++)
|
|
|
|
*rp++ = FDMFMGAP2;
|
|
|
|
*rp++ = FDMFMSYNC;
|
|
|
|
*rp++ = FDMFMSYNC;
|
|
|
|
*rp++ = FDMFMSYNC;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sector information
|
|
|
|
* (ID) + track + side + sector + sector size + CRC16
|
|
|
|
*/
|
|
|
|
*rp++ = FDMFMID;
|
|
|
|
tb[0] = sc->cachetrk / FDNHEADS;
|
|
|
|
tb[1] = sc->cachetrk % FDNHEADS;
|
|
|
|
tb[2] = sec + 1;
|
|
|
|
i = sc->bytespersec;
|
|
|
|
tb[3] = i < 256 ? 0 : (i < 512 ? 1 : (i < 1024 ? 2 : 3));
|
|
|
|
rp = msblkencode(rp, tb, 4, &crc);
|
|
|
|
tb[0] = crc >> 8;
|
|
|
|
tb[1] = crc & 0xff;
|
|
|
|
tb[2] = 0x4e; /* GAP1 decoded */
|
|
|
|
rp = msblkencode(rp, tb, 3, 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sector info/data gap
|
|
|
|
* (22 * GAP1) + (12 * GAP2) + (3 * SYNC)
|
|
|
|
*/
|
|
|
|
for (i = 0; i < 21; i++)
|
|
|
|
*rp++ = FDMFMGAP1;
|
|
|
|
for (i = 0; i < 12; i++)
|
|
|
|
*rp++ = FDMFMGAP2;
|
|
|
|
*rp++ = FDMFMSYNC;
|
|
|
|
*rp++ = FDMFMSYNC;
|
|
|
|
*rp++ = FDMFMSYNC;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sector data
|
|
|
|
* (DATA) + ...data... + CRC16
|
|
|
|
*/
|
|
|
|
*rp++ = FDMFMDATA;
|
|
|
|
rp = msblkencode(rp, cp, sc->bytespersec, &crc);
|
|
|
|
cp += sc->bytespersec;
|
|
|
|
tb[0] = crc >> 8;
|
|
|
|
tb[1] = crc & 0xff;
|
|
|
|
tb[2] = 0x4e; /* GAP3 decoded */
|
|
|
|
rp = msblkencode(rp, tb, 3, 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* trailing sector gap
|
|
|
|
* (80 * GAP3)
|
|
|
|
*/
|
|
|
|
for (i = 0; i < 79; i++)
|
|
|
|
*rp++ = FDMFMGAP3;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fill rest of track with GAP3
|
|
|
|
*/
|
|
|
|
while (rp != erp)
|
|
|
|
*rp++ = FDMFMGAP3;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
msrawtocache(sc)
|
|
|
|
struct fd_softc *sc;
|
|
|
|
{
|
|
|
|
u_short *rp, *srp, *erp;
|
|
|
|
u_char tb[5], *cp;
|
|
|
|
int ct, sec, retry;
|
|
|
|
|
|
|
|
srp = rp = (u_short *)fdc_dmap;
|
|
|
|
erp = rp + sc->type->nreadw;
|
|
|
|
cp = sc->cachep;
|
|
|
|
|
|
|
|
for (ct = 0; ct < sc->nsectors; ct++) {
|
|
|
|
retry = 1;
|
|
|
|
do {
|
|
|
|
/*
|
|
|
|
* skip leading gap to sync
|
|
|
|
*/
|
|
|
|
if ((rp = (u_short *)fdfindsync((u_long *)rp, (u_long *)erp)) == NULL) {
|
|
|
|
#ifdef DIAGNOSTIC
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("%s: corrupted track (%d) data.\n",
|
1996-05-04 08:54:00 +04:00
|
|
|
sc->sc_dv.dv_xname, sc->cachetrk);
|
|
|
|
#endif
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Grab sector info
|
|
|
|
*/
|
|
|
|
if (*rp++ != FDMFMID)
|
|
|
|
continue;
|
|
|
|
rp = msblkdecode(rp, tb, 4);
|
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("sector id: sector %d, track %d, side %d,"
|
1996-05-04 08:54:00 +04:00
|
|
|
"bps %d\n", tb[2], tb[0], tb[1], 128 << tb[3]);
|
|
|
|
#endif
|
|
|
|
if ((tb[0] * FDNHEADS + tb[1]) != sc->cachetrk ||
|
|
|
|
tb[2] > sc->nsectors)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sec = tb[2];
|
|
|
|
sc->bytespersec = 128 << tb[3];
|
|
|
|
rp += 2; /* skip CRC-16 */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* skip gap and read in data
|
|
|
|
*/
|
|
|
|
if ((rp = (u_short *)fdfindsync((u_long *)rp, (u_long *)erp)) == NULL)
|
|
|
|
return(-1);
|
|
|
|
if (*rp++ != FDMFMDATA)
|
|
|
|
continue;
|
|
|
|
rp = msblkdecode(rp, cp + ((sec-1) * sc->bytespersec),
|
|
|
|
sc->bytespersec);
|
|
|
|
rp += 2; /* skip CRC-16 */
|
|
|
|
|
|
|
|
retry = 0;
|
|
|
|
} while (retry);
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* encode len longwords of `dp' data in amiga mfm block format (`rp')
|
|
|
|
* this format specified that the odd bits are at current pos and even
|
|
|
|
* bits at len + current pos
|
|
|
|
*/
|
|
|
|
u_long *
|
|
|
|
mfmblkencode(dp, rp, cp, len)
|
|
|
|
u_long *dp, *rp, *cp;
|
|
|
|
int len;
|
|
|
|
{
|
|
|
|
u_long *sdp, *edp, d, dtmp, correct;
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
sdp = dp;
|
|
|
|
edp = dp + len;
|
1994-04-06 03:04:05 +04:00
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
if (*(rp - 1) & 0x1)
|
|
|
|
correct = 1;
|
|
|
|
else
|
|
|
|
correct = 0;
|
|
|
|
/*
|
|
|
|
* do odd bits
|
|
|
|
*/
|
|
|
|
while (dp < edp) {
|
|
|
|
d = (*dp >> 1) & 0x55555555; /* remove clock bits */
|
|
|
|
dtmp = d ^ 0x55555555;
|
|
|
|
d |= ((dtmp >> 1) | 0x80000000) & (dtmp << 1);
|
1994-04-06 03:04:05 +04:00
|
|
|
/*
|
1994-05-29 05:44:26 +04:00
|
|
|
* correct upper clock bit if needed
|
1994-04-06 03:04:05 +04:00
|
|
|
*/
|
1994-05-29 05:44:26 +04:00
|
|
|
if (correct)
|
|
|
|
d &= 0x7fffffff;
|
|
|
|
if (d & 0x1)
|
|
|
|
correct = 1;
|
|
|
|
else
|
|
|
|
correct = 0;
|
1994-04-06 03:04:05 +04:00
|
|
|
/*
|
1994-05-29 05:44:26 +04:00
|
|
|
* do checksums and store in raw buffer
|
1994-04-06 03:04:05 +04:00
|
|
|
*/
|
1994-05-29 05:44:26 +04:00
|
|
|
if (cp)
|
|
|
|
*cp ^= d;
|
|
|
|
*rp++ = d;
|
|
|
|
dp++;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* do even bits
|
|
|
|
*/
|
|
|
|
dp = sdp;
|
|
|
|
while (dp < edp) {
|
|
|
|
d = *dp & 0x55555555; /* remove clock bits */
|
|
|
|
dtmp = d ^ 0x55555555;
|
|
|
|
d |= ((dtmp >> 1) | 0x80000000) & (dtmp << 1);
|
1994-04-22 06:20:48 +04:00
|
|
|
/*
|
1994-05-29 05:44:26 +04:00
|
|
|
* correct upper clock bit if needed
|
1994-04-22 06:20:48 +04:00
|
|
|
*/
|
1994-05-29 05:44:26 +04:00
|
|
|
if (correct)
|
|
|
|
d &= 0x7fffffff;
|
|
|
|
if (d & 0x1)
|
|
|
|
correct = 1;
|
|
|
|
else
|
|
|
|
correct = 0;
|
|
|
|
/*
|
|
|
|
* do checksums and store in raw buffer
|
|
|
|
*/
|
|
|
|
if (cp)
|
|
|
|
*cp ^= d;
|
|
|
|
*rp++ = d;
|
|
|
|
dp++;
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
1994-05-29 05:44:26 +04:00
|
|
|
if (cp)
|
|
|
|
*cp &= 0x55555555;
|
|
|
|
return(rp);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
|
|
|
|
1994-05-29 05:44:26 +04:00
|
|
|
/*
|
|
|
|
* decode len longwords of `dp' data in amiga mfm block format (`rp')
|
|
|
|
* this format specified that the odd bits are at current pos and even
|
|
|
|
* bits at len + current pos
|
|
|
|
*/
|
|
|
|
u_long *
|
|
|
|
mfmblkdecode(rp, dp, cp, len)
|
|
|
|
u_long *rp, *dp, *cp;
|
|
|
|
int len;
|
1994-04-06 03:04:05 +04:00
|
|
|
{
|
1994-05-29 05:44:26 +04:00
|
|
|
u_long o, e;
|
|
|
|
int cnt;
|
|
|
|
|
|
|
|
cnt = len;
|
|
|
|
while (cnt--) {
|
|
|
|
o = *rp;
|
|
|
|
e = *(rp + len);
|
|
|
|
if (cp) {
|
|
|
|
*cp ^= o;
|
|
|
|
*cp ^= e;
|
|
|
|
}
|
|
|
|
o &= 0x55555555;
|
|
|
|
e &= 0x55555555;
|
|
|
|
*dp++ = (o << 1) | e;
|
|
|
|
rp++;
|
1994-04-22 06:20:48 +04:00
|
|
|
}
|
1994-05-29 05:44:26 +04:00
|
|
|
if (cp)
|
|
|
|
*cp &= 0x55555555;
|
|
|
|
return(rp + len);
|
1994-04-06 03:04:05 +04:00
|
|
|
}
|
1995-04-13 15:59:21 +04:00
|
|
|
|
1996-05-04 08:54:00 +04:00
|
|
|
/*
|
|
|
|
* decode len words in standard MFM format to len bytes
|
|
|
|
* of data.
|
|
|
|
*/
|
|
|
|
u_short *
|
|
|
|
msblkdecode(rp, cp, len)
|
|
|
|
u_short *rp;
|
|
|
|
u_char *cp;
|
|
|
|
int len;
|
|
|
|
{
|
|
|
|
while (len--) {
|
|
|
|
*cp++ = msdecode[*rp & 0x7f] |
|
|
|
|
(msdecode[(*rp >> 8) & 0x7f] << 4);
|
|
|
|
rp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(rp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* encode len bytes of data into len words in standard MFM format.
|
|
|
|
* If a pointer is supplied for crc, calculate the CRC-16 of the data
|
|
|
|
* as well.
|
|
|
|
*/
|
|
|
|
u_short *
|
|
|
|
msblkencode(rp, cp, len, crc)
|
|
|
|
u_short *rp;
|
|
|
|
u_char *cp;
|
|
|
|
int len;
|
|
|
|
u_short *crc;
|
|
|
|
{
|
|
|
|
u_short td;
|
|
|
|
u_short mycrc;
|
|
|
|
|
|
|
|
/* preload crc for header (4 bytes)
|
|
|
|
* or data (anything else)
|
|
|
|
*/
|
|
|
|
mycrc = (len == 4) ? 0xb230 : 0xe295;
|
|
|
|
|
|
|
|
while (len--) {
|
|
|
|
td = (msencode[*cp >> 4] << 8) | msencode[*cp & 0x0f];
|
|
|
|
|
|
|
|
/* Check for zeros in top bit of encode and bottom
|
|
|
|
* bit of previous encode. if so, slap a one in betweem
|
|
|
|
* them.
|
|
|
|
*/
|
|
|
|
if ((td & 0x140) == 0)
|
|
|
|
td |= 0x80;
|
|
|
|
if ((td & 0x4000) == 0 && (rp[-1] & 1) == 0)
|
|
|
|
td |= 0x8000;
|
|
|
|
|
|
|
|
*rp++ = td;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* calc crc if requested
|
|
|
|
*/
|
|
|
|
if (crc)
|
|
|
|
mycrc = (mycrc << 8) ^ mscrctab[*cp ^ (mycrc >> 8)];
|
|
|
|
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (crc)
|
|
|
|
*crc = mycrc;
|
|
|
|
|
|
|
|
return(rp);
|
|
|
|
}
|
|
|
|
|
1995-04-13 15:59:21 +04:00
|
|
|
int
|
1996-04-22 01:10:48 +04:00
|
|
|
fddump(dev, blkno, va, size)
|
|
|
|
dev_t dev;
|
|
|
|
daddr_t blkno;
|
|
|
|
caddr_t va;
|
|
|
|
size_t size;
|
1995-04-13 15:59:21 +04:00
|
|
|
{
|
|
|
|
return (EINVAL);
|
|
|
|
}
|