Home | History | Annotate | Line # | Download | only in vsa
hdc9224.c revision 1.4.6.1
      1  1.4.6.1        is /*	$NetBSD: hdc9224.c,v 1.4.6.1 1997/03/12 21:21:04 is Exp $ */
      2      1.1     ragge /*
      3      1.1     ragge  * Copyright (c) 1996 Ludd, University of Lule}, Sweden.
      4      1.1     ragge  * All rights reserved.
      5      1.1     ragge  *
      6      1.1     ragge  * This code is derived from software contributed to Ludd by Bertram Barth.
      7      1.1     ragge  *
      8      1.1     ragge  * Redistribution and use in source and binary forms, with or without
      9      1.1     ragge  * modification, are permitted provided that the following conditions
     10      1.1     ragge  * are met:
     11      1.1     ragge  * 1. Redistributions of source code must retain the above copyright
     12      1.1     ragge  *    notice, this list of conditions and the following disclaimer.
     13      1.1     ragge  * 2. Redistributions in binary form must reproduce the above copyright
     14      1.1     ragge  *    notice, this list of conditions and the following disclaimer in the
     15      1.1     ragge  *    documentation and/or other materials provided with the distribution.
     16      1.1     ragge  * 3. All advertising materials mentioning features or use of this software
     17      1.1     ragge  *    must display the following acknowledgement:
     18      1.1     ragge  *	This product includes software developed at Ludd, University of
     19      1.1     ragge  *	Lule}, Sweden and its contributors.
     20      1.1     ragge  * 4. The name of the author may not be used to endorse or promote products
     21      1.1     ragge  *    derived from this software without specific prior written permission
     22      1.1     ragge  *
     23      1.1     ragge  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24      1.1     ragge  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25      1.1     ragge  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26      1.1     ragge  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27      1.1     ragge  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28      1.1     ragge  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29      1.1     ragge  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30      1.1     ragge  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31      1.1     ragge  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32      1.1     ragge  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33      1.1     ragge  */
     34      1.1     ragge 
     35      1.1     ragge /*
     36      1.1     ragge  * with much help from (in alphabetical order):
     37      1.1     ragge  *	Jeremy
     38      1.1     ragge  *	Roger Ivie
     39      1.1     ragge  *	Rick Macklem
     40      1.1     ragge  *	Mike Young
     41      1.1     ragge  */
     42      1.1     ragge 
     43      1.1     ragge /* #define DEBUG	/* */
     44      1.1     ragge /* #define TRACE	/* */
     45      1.1     ragge static int haveLock = 0;
     46      1.1     ragge static int keepLock = 0;
     47      1.1     ragge 
     48      1.1     ragge #define F_READ	11
     49      1.1     ragge #define F_WRITE 12
     50      1.1     ragge 
     51      1.1     ragge #define trace(x)
     52      1.1     ragge #define debug(x)
     53      1.1     ragge 
     54      1.1     ragge #include "hdc.h"
     55      1.1     ragge #if NHDC > 0
     56      1.1     ragge 
     57      1.1     ragge #include <sys/param.h>
     58      1.1     ragge #include <sys/systm.h>
     59      1.1     ragge #include <sys/kernel.h>
     60      1.1     ragge #include <sys/conf.h>
     61      1.1     ragge #include <sys/file.h>
     62      1.1     ragge #include <sys/stat.h>
     63      1.1     ragge #include <sys/ioctl.h>
     64      1.1     ragge #include <sys/buf.h>
     65      1.1     ragge #include <sys/proc.h>
     66      1.1     ragge #include <sys/user.h>
     67      1.1     ragge #include <sys/map.h>
     68      1.1     ragge #include <sys/device.h>
     69      1.1     ragge #include <sys/dkstat.h>
     70      1.1     ragge #include <sys/disklabel.h>
     71      1.1     ragge #include <sys/disk.h>
     72      1.1     ragge #include <sys/syslog.h>
     73      1.1     ragge 
     74      1.1     ragge #include <machine/pte.h>
     75      1.1     ragge #include <machine/sid.h>
     76      1.1     ragge #include <machine/cpu.h>
     77      1.1     ragge #include <machine/uvax.h>
     78      1.1     ragge #include <machine/ka410.h>
     79      1.1     ragge #include <machine/vsbus.h>
     80      1.1     ragge 
     81      1.1     ragge #include <vax/vsa/hdc9224.h>
     82      1.1     ragge 
     83      1.1     ragge 
     84      1.1     ragge /*
     85      1.1     ragge  * some definitions
     86      1.1     ragge  */
     87      1.1     ragge #define CTLRNAME  "hdc"
     88      1.1     ragge #define UNITNAME  "rd"
     89      1.1     ragge #define HDC_PRI	  LOG_INFO
     90      1.1     ragge 
     91      1.1     ragge /* Bits in minor device */
     92      1.1     ragge #define HDCUNIT(dev)	DISKUNIT(dev)
     93      1.1     ragge #define HDCPART(dev)	DISKPART(dev)
     94      1.1     ragge #define HDCCTLR(dev)	0
     95      1.1     ragge #define HDCLABELDEV(dev)	(MAKEDISKDEV(major(dev),HDCUNIT(dev),RAW_PART))
     96      1.1     ragge 
     97      1.1     ragge #define MAX_WAIT	(1000*1000)	/* # of loop-instructions in seconds */
     98      1.1     ragge 
     99      1.1     ragge 
    100      1.1     ragge /*
    101      1.1     ragge  * on-disk geometry block
    102      1.1     ragge  */
    103      1.1     ragge #define _aP	__attribute__ ((packed))	/* force byte-alignment */
    104      1.1     ragge struct rdgeom {
    105      1.1     ragge   char mbz[10];		/* 10 bytes of zero */
    106      1.1     ragge   long xbn_count _aP;	/* number of XBNs */
    107      1.1     ragge   long dbn_count _aP;	/* number of DBNs */
    108      1.1     ragge   long lbn_count _aP;	/* number of LBNs (Logical-Block-Numbers) */
    109      1.1     ragge   long rbn_count _aP;	/* number of RBNs (Replacement-Block-Numbers) */
    110      1.1     ragge   short nspt;		/* number of sectors per track */
    111      1.1     ragge   short ntracks;	/* number of tracks */
    112      1.1     ragge   short ncylinders;	/* number of cylinders */
    113      1.1     ragge   short precomp;	/* first cylinder for write precompensation */
    114      1.1     ragge   short reduced;	/* first cylinder for reduced write current */
    115      1.1     ragge   short seek_rate;	/* seek rate or zero for buffered seeks */
    116      1.1     ragge   short crc_eec;	/* 0 if CRC is being used or 1 if ECC is being used */
    117      1.1     ragge   short rct;		/* "replacement control table" (RCT) */
    118      1.1     ragge   short rct_ncopies;	/* number of copies of the RCT */
    119      1.1     ragge   long	media_id _aP;	/* media identifier */
    120      1.1     ragge   short interleave;	/* sector-to-sector interleave */
    121      1.1     ragge   short headskew;	/* head-to-head skew */
    122      1.1     ragge   short cylskew;	/* cylinder-to-cylinder skew */
    123      1.1     ragge   short gap0_size;	/* size of GAP 0 in the MFM format */
    124      1.1     ragge   short gap1_size;	/* size of GAP 1 in the MFM format */
    125      1.1     ragge   short gap2_size;	/* size of GAP 2 in the MFM format */
    126      1.1     ragge   short gap3_size;	/* size of GAP 3 in the MFM format */
    127      1.1     ragge   short sync_value;	/* sync value used to start a track when formatting */
    128      1.1     ragge   char	reserved[32];	/* reserved for use by the RQDX1/2/3 formatter */
    129      1.1     ragge   short serial_number;	/* serial number */
    130      1.1     ragge #if 0	/* we don't need these 412 useless bytes ... */
    131      1.1     ragge   char	fill[412-2];	/* Filler bytes to the end of the block */
    132      1.1     ragge   short checksum;	/* checksum over the XBN */
    133      1.1     ragge #endif
    134      1.1     ragge };
    135      1.1     ragge 
    136      1.1     ragge /*
    137      1.1     ragge  * Software status
    138      1.1     ragge  */
    139      1.1     ragge struct	rdsoftc {
    140      1.1     ragge 	struct device	sc_dev;		/* must be here! (pseudo-OOP:) */
    141      1.1     ragge 	struct disk	sc_dk;		/* disklabel etc. */
    142      1.1     ragge 	struct rdgeom	sc_xbn;		/* on-disk geometry information */
    143      1.1     ragge 	struct rdparams {
    144      1.1     ragge 		u_short cylinders;	/* number of cylinders */
    145      1.1     ragge 		u_char	heads;		/* number of heads (tracks) */
    146      1.1     ragge 		u_char	sectors;	/* number of sectors/track */
    147      1.1     ragge 		u_long	diskblks;	/* number of sectors/disk */
    148      1.1     ragge 		u_long	disklbns;	/* number of available sectors */
    149      1.1     ragge 		u_long	blksize;	/* number of bytes/sector */
    150      1.1     ragge 		u_long	diskbytes;	/* number of bytes/disk */
    151      1.1     ragge 		char	diskname[8];
    152      1.1     ragge 	} sc_param;
    153      1.1     ragge 	int	sc_drive;		/* physical unit number */
    154      1.1     ragge 	int	sc_flags;
    155      1.1     ragge 	int	sc_state;
    156      1.1     ragge 	int	sc_mode;
    157      1.1     ragge };
    158      1.1     ragge 
    159      1.1     ragge struct	hdcsoftc {
    160      1.1     ragge 	struct device sc_dev;		/* must be here (pseudo-OOP:) */
    161      1.1     ragge 	struct hdc9224_DKCreg *sc_dkc;	/* I/O address of the controller */
    162      1.1     ragge 	struct hdc9224_UDCreg sc_creg;	/* (command) registers to be written */
    163      1.1     ragge 	struct hdc9224_UDCreg sc_sreg;	/* (status) registers being read */
    164      1.1     ragge 	struct confargs *sc_cfargs;	/* remember args being probed with */
    165      1.1     ragge 	char	*sc_dmabase;		/* */
    166      1.1     ragge 	long	sc_dmasize;		/* */
    167      1.1     ragge 	long	sc_ioaddr;		/* unmapped I/O address */
    168      1.1     ragge 	long	sc_ivec;		/* interrupt vector address */
    169      1.1     ragge 	short	sc_ibit;		/* bit-value in interrupt register */
    170      1.1     ragge 	short	sc_status;		/* copy of status register */
    171      1.1     ragge 	short	sc_state;
    172      1.1     ragge 	short	sc_flags;
    173      1.1     ragge 	short	sc_errors;
    174      1.1     ragge };
    175      1.1     ragge 
    176      1.1     ragge /*
    177      1.1     ragge  * Device definition for (new) autoconfiguration.
    178      1.1     ragge  */
    179      1.1     ragge int	hdcmatch  __P((struct device *parent, void *cfdata, void *aux));
    180      1.1     ragge void	hdcattach __P((struct device *parent, struct device *self, void *aux));
    181      1.2       cgd int	hdcprint  __P((void *aux, const char *name));
    182      1.1     ragge 
    183      1.1     ragge struct	cfdriver hdc_cd = {
    184      1.1     ragge 	NULL, "hdc", DV_DULL
    185      1.1     ragge };
    186      1.1     ragge struct	cfattach hdc_ca = {
    187      1.1     ragge 	sizeof(struct hdcsoftc), hdcmatch, hdcattach
    188      1.1     ragge };
    189      1.1     ragge 
    190      1.1     ragge int	rdmatch __P((struct device *parent, void *cfdata, void *aux));
    191      1.1     ragge void	rdattach __P((struct device *parent, struct device *self, void *aux));
    192      1.2       cgd int	rdprint __P((void *aux, const char *name));
    193      1.1     ragge void	rdstrategy __P((struct buf *bp));
    194      1.1     ragge 
    195      1.1     ragge struct	cfdriver rd_cd = {
    196      1.1     ragge 	NULL, "rd", DV_DISK
    197      1.1     ragge };
    198      1.1     ragge struct	cfattach rd_ca = {
    199      1.1     ragge 	sizeof(struct rdsoftc), rdmatch, rdattach
    200      1.1     ragge };
    201      1.1     ragge 
    202      1.1     ragge struct dkdriver rddkdriver = { rdstrategy };
    203      1.1     ragge 
    204      1.1     ragge /*
    205      1.1     ragge  * prototypes for (almost) all the internal routines
    206      1.1     ragge  */
    207      1.1     ragge int hdc_reset	__P((struct hdcsoftc *sc));
    208      1.1     ragge int hdc_select	__P((struct hdcsoftc *sc, int drive));
    209      1.1     ragge int hdc_command __P((struct hdcsoftc *sc, int cmd));
    210      1.1     ragge 
    211      1.1     ragge int hdc_getdata	 __P((struct hdcsoftc *hdc, struct rdsoftc *rd, int drive));
    212      1.1     ragge int hdc_getlabel __P((struct hdcsoftc *hdc, struct rdsoftc *rd, int drive));
    213      1.1     ragge 
    214      1.1     ragge void rdgetlabel __P((struct rdsoftc *sc));
    215      1.1     ragge 
    216      1.1     ragge /*
    217      1.1     ragge  * new-config's hdcmatch() is similiar to old-config's hdcprobe(),
    218      1.1     ragge  * thus we probe for the existence of the controller and reset it.
    219      1.1     ragge  * NB: we can't initialize the controller yet, since space for hdcsoftc
    220      1.1     ragge  *     is not yet allocated. Thus we do this in hdcattach()...
    221      1.1     ragge  */
    222      1.1     ragge int
    223      1.1     ragge hdcmatch(parent, match, aux)
    224      1.1     ragge 	struct device *parent;
    225      1.1     ragge 	void *match, *aux;
    226      1.1     ragge {
    227      1.1     ragge 	struct cfdata *cf = match;
    228      1.1     ragge 	struct confargs *ca = aux;
    229      1.1     ragge 
    230      1.1     ragge 	trace(("hdcmatch(0x%x, %d, %s)\n", parent, cf->cf_unit, ca->ca_name));
    231      1.1     ragge 
    232      1.1     ragge 	if (strcmp(ca->ca_name, "hdc") &&
    233      1.1     ragge 	    strcmp(ca->ca_name, "hdc9224") &&
    234      1.1     ragge 	    strcmp(ca->ca_name, "HDC9224"))
    235      1.1     ragge 		return (0);
    236      1.1     ragge 
    237      1.1     ragge 	/*
    238      1.1     ragge 	 * only(?) VS2000/KA410 has exactly one HDC9224 controller
    239      1.1     ragge 	 */
    240      1.1     ragge 	if (vax_boardtype != VAX_BTYP_410) {
    241      1.4  christos 		printf ("unexpected boardtype 0x%x in hdcmatch()\n",
    242      1.1     ragge 			vax_boardtype);
    243      1.1     ragge 		return (0);
    244      1.1     ragge 	}
    245      1.1     ragge 	if (cf->cf_unit != 0)
    246      1.1     ragge 		return (0);
    247      1.1     ragge 
    248      1.1     ragge 	return (1);
    249      1.1     ragge }
    250      1.1     ragge 
    251      1.1     ragge struct hdc_attach_args {
    252      1.1     ragge 	int ha_drive;
    253      1.1     ragge };
    254      1.1     ragge 
    255      1.1     ragge int
    256      1.1     ragge rdprint(aux, name)
    257      1.1     ragge 	void *aux;
    258      1.2       cgd 	const char *name;
    259      1.1     ragge {
    260      1.1     ragge 	struct hdc_attach_args *ha = aux;
    261      1.1     ragge 
    262      1.1     ragge 	trace(("rdprint(%d, %s)\n", ha->ha_drive, name));
    263      1.1     ragge 
    264      1.1     ragge 	if (!name)
    265      1.4  christos 		printf (" drive %d", ha->ha_drive);
    266      1.1     ragge 	return (QUIET);
    267      1.1     ragge }
    268      1.1     ragge 
    269      1.1     ragge /*
    270      1.1     ragge  * hdc_attach() probes for all possible devices
    271      1.1     ragge  */
    272      1.1     ragge void
    273      1.1     ragge hdcattach(parent, self, aux)
    274      1.1     ragge 	struct device *parent, *self;
    275      1.1     ragge 	void *aux;
    276      1.1     ragge {
    277      1.1     ragge 	struct hdcsoftc *sc = (void*)self;
    278      1.1     ragge 	struct confargs *ca = aux;
    279      1.1     ragge 	struct hdc_attach_args ha;
    280      1.1     ragge 
    281      1.1     ragge 	trace(("hdcattach(0x%x, 0x%x, %s)\n", parent, self, ca->ca_name));
    282      1.1     ragge 
    283      1.4  christos 	printf ("\n");
    284      1.1     ragge 	/*
    285      1.1     ragge 	 * first reset/initialize the controller
    286      1.1     ragge 	 */
    287      1.1     ragge 	sc->sc_cfargs = ca;
    288      1.1     ragge 
    289      1.1     ragge 	sc->sc_ioaddr = ca->ca_ioaddr;
    290      1.1     ragge 	sc->sc_dkc = (void*)uvax_phys2virt(sc->sc_ioaddr);
    291      1.1     ragge 	sc->sc_ibit = ca->ca_intbit;
    292      1.1     ragge 	sc->sc_ivec = ca->ca_intvec;
    293      1.1     ragge 	sc->sc_status = 0;
    294      1.1     ragge 	sc->sc_state = 0;
    295      1.1     ragge 	sc->sc_flags = 0;
    296      1.1     ragge 	sc->sc_errors = 0;
    297      1.1     ragge 
    298      1.1     ragge 	sc->sc_dkc     = (void*)uvax_phys2virt(KA410_DKC_BASE);
    299      1.1     ragge 	sc->sc_dmabase = (void*)uvax_phys2virt(KA410_DMA_BASE);
    300      1.1     ragge 	sc->sc_dmasize = KA410_DMA_SIZE;
    301      1.1     ragge 
    302      1.1     ragge 	if (hdc_reset(sc) != 0) {
    303      1.1     ragge 		delay(500*1000);	/* wait .5 seconds */
    304      1.1     ragge 		if (hdc_reset(sc) != 0)
    305      1.4  christos 			printf ("problems with hdc_reset()...\n");
    306      1.1     ragge 	}
    307      1.1     ragge 
    308      1.1     ragge 	/*
    309      1.1     ragge 	 * now probe for all possible disks
    310      1.1     ragge 	 */
    311      1.1     ragge 	for (ha.ha_drive=0; ha.ha_drive<3; ha.ha_drive++)
    312      1.1     ragge 		(void)config_found(self, (void*)&ha, rdprint);
    313      1.1     ragge 
    314      1.1     ragge #ifdef notyet
    315      1.1     ragge 	/*
    316      1.1     ragge 	 * now that probing is done, we can register and enable interrupts
    317      1.1     ragge 	 */
    318      1.1     ragge 	vsbus_intr_register(XXX);
    319      1.1     ragge 	vsbus_intr_enable(XXX);
    320      1.1     ragge #endif
    321      1.1     ragge }
    322      1.1     ragge 
    323      1.1     ragge /*
    324      1.1     ragge  * rdmatch() probes for the existence of a RD-type disk/floppy
    325      1.1     ragge  */
    326      1.1     ragge int
    327      1.1     ragge rdmatch(parent, match, aux)
    328      1.1     ragge 	struct device *parent;
    329      1.1     ragge 	void *match, *aux;
    330      1.1     ragge {
    331      1.1     ragge 	struct hdcsoftc *hdc = (void*)parent;
    332      1.1     ragge 	struct cfdata *cf = match;
    333      1.1     ragge 	struct hdc_attach_args *ha = aux;
    334      1.1     ragge 	int drive = ha->ha_drive;
    335      1.1     ragge 	int res;
    336      1.1     ragge 
    337      1.1     ragge 	trace(("rdmatch(%d, %d)\n", cf->cf_unit, drive));
    338      1.1     ragge 
    339      1.1     ragge 	if (cf->cf_unit != ha->ha_drive)
    340      1.1     ragge 		return (0);
    341      1.1     ragge 
    342      1.1     ragge 	switch (drive) {
    343      1.1     ragge 	case 0:
    344      1.1     ragge 	case 1:
    345      1.1     ragge 	case 2:
    346      1.1     ragge 		res = hdc_select(hdc, drive);
    347      1.1     ragge 		break;
    348      1.1     ragge 	default:
    349      1.4  christos 		printf ("rdmatch: invalid unit-number %d\n", drive);
    350      1.1     ragge 		return (0);
    351      1.1     ragge 	}
    352      1.1     ragge 
    353      1.1     ragge 	debug (("cstat: %x dstat: %x\n", hdc->sc_sreg.udc_cstat,
    354      1.1     ragge 		hdc->sc_sreg.udc_dstat));
    355      1.1     ragge 	if (drive == 1)
    356      1.1     ragge 	  return (0);	/* XXX */
    357      1.1     ragge 
    358      1.1     ragge 	return (1);
    359      1.1     ragge }
    360      1.1     ragge 
    361      1.1     ragge void
    362      1.1     ragge rdattach(parent, self, aux)
    363      1.1     ragge 	struct device *parent, *self;
    364      1.1     ragge 	void *aux;
    365      1.1     ragge {
    366      1.1     ragge 	struct hdcsoftc *hdc = (void*)parent;
    367      1.1     ragge 	struct rdsoftc *rd = (void*)self;
    368      1.1     ragge 	struct hdc_attach_args *ha = aux;
    369      1.1     ragge 	struct rdparams *rp = &rd->sc_param;
    370      1.1     ragge 
    371      1.1     ragge 	trace(("rdattach(%d)\n", ha->ha_drive));
    372      1.1     ragge 
    373      1.1     ragge 	rd->sc_drive = ha->ha_drive;
    374      1.1     ragge 	/*
    375      1.1     ragge 	 * Initialize and attach the disk structure.
    376      1.1     ragge 	 */
    377      1.1     ragge 	rd->sc_dk.dk_driver = &rddkdriver;
    378      1.1     ragge 	rd->sc_dk.dk_name = rd->sc_dev.dv_xname;
    379      1.1     ragge 	disk_attach(&rd->sc_dk);
    380      1.1     ragge 	/*
    381      1.1     ragge 	 * if it's not a floppy then evaluate the on-disk geometry.
    382      1.1     ragge 	 * if neccessary correct the label...
    383      1.1     ragge 	 */
    384      1.4  christos 	printf("\n%s: ", rd->sc_dev.dv_xname);
    385      1.1     ragge 	if (rd->sc_drive == 2) {
    386      1.4  christos 		printf("floppy (RX33)\n");
    387      1.1     ragge 	}
    388      1.1     ragge 	else {
    389      1.1     ragge 		hdc_getdata(hdc, rd, rd->sc_drive);
    390      1.4  christos 		printf("%s, %d MB, %d LBN, %d cyl, %d head, %d sect/track\n",
    391      1.1     ragge 		       rp->diskname, rp->diskblks/2048, rp->disklbns,
    392      1.1     ragge 		       rp->cylinders, rp->heads, rp->sectors);
    393      1.1     ragge 	}
    394      1.1     ragge }
    395      1.1     ragge 
    396      1.1     ragge /*
    397      1.1     ragge  * Read/write routine for a buffer.  For now we poll the controller,
    398      1.1     ragge  * thus this routine waits for the transfer to complete.
    399      1.1     ragge  */
    400      1.1     ragge void
    401      1.1     ragge rdstrategy(bp)
    402      1.1     ragge 	struct buf *bp;
    403      1.1     ragge {
    404      1.1     ragge 	struct rdsoftc *rd = rd_cd.cd_devs[HDCUNIT(bp->b_dev)];
    405      1.1     ragge 	struct hdcsoftc *hdc = (void *)rd->sc_dev.dv_parent;
    406      1.1     ragge 	struct partition *p;
    407      1.1     ragge 	int blkno, i, s;
    408      1.1     ragge 
    409      1.1     ragge 	trace (("rdstrategy(#%d/%d)\n", bp->b_blkno, bp->b_bcount));
    410      1.1     ragge 
    411      1.1     ragge 	/* XXX		should make some checks... */
    412      1.1     ragge 
    413      1.1     ragge 	/*
    414      1.1     ragge 	 * If it's a null transfer, return immediatly
    415      1.1     ragge 	 */
    416      1.1     ragge 	if (bp->b_bcount == 0)
    417      1.1     ragge 		goto done;
    418      1.1     ragge 
    419      1.1     ragge 	/*
    420      1.1     ragge 	 * what follows now should not be here but in rdstart...
    421      1.1     ragge 	 */
    422      1.1     ragge 	/*------------------------------*/
    423      1.1     ragge 	blkno = bp->b_blkno / (rd->sc_dk.dk_label->d_secsize / DEV_BSIZE);
    424  1.4.6.1        is 	p = &rd->sc_dk.dk_label->d_partitions[HDCPART(bp->b_dev)];
    425  1.4.6.1        is 	blkno += p->p_offset;
    426  1.4.6.1        is 
    427      1.1     ragge 	/* nblks = howmany(bp->b_bcount, sd->sc_dk.dk_label->d_secsize); */
    428      1.1     ragge 
    429      1.1     ragge 	if (hdc_strategy(hdc, rd, HDCUNIT(bp->b_dev),
    430      1.1     ragge 			 ((bp->b_flags & B_READ) ? F_READ : F_WRITE),
    431      1.1     ragge 			 blkno, bp->b_bcount, bp->b_data) == 0)
    432      1.1     ragge 		goto done;
    433      1.1     ragge 	/*------------------------------*/
    434      1.1     ragge bad:
    435      1.1     ragge 	bp->b_flags |= B_ERROR;
    436      1.1     ragge done:
    437      1.1     ragge 	/*
    438      1.1     ragge 	 * Correctly set the buf to indicate a completed xfer
    439      1.1     ragge 	 */
    440      1.1     ragge 	bp->b_resid = 0;	/* ??? bertram */
    441      1.1     ragge 	biodone(bp);
    442      1.1     ragge }
    443      1.1     ragge 
    444      1.1     ragge int
    445      1.1     ragge hdc_strategy(hdc, rd, unit, func, dblk, size, buf)
    446      1.1     ragge 	struct hdcsoftc *hdc;
    447      1.1     ragge 	struct rdsoftc *rd;
    448      1.1     ragge 	int unit;
    449      1.1     ragge 	int func;
    450      1.1     ragge 	int dblk;
    451      1.1     ragge 	int size;
    452      1.1     ragge 	char *buf;
    453      1.1     ragge {
    454      1.1     ragge 	struct hdc9224_UDCreg *p = &hdc->sc_creg;
    455      1.1     ragge 	struct disklabel *lp = rd->sc_dk.dk_label;
    456      1.1     ragge 	int sect, head, cyl;
    457      1.1     ragge 	int scount;
    458      1.1     ragge 	int cmd, res = 0;
    459      1.1     ragge 
    460      1.1     ragge 	trace (("hdc_strategy(%d, %d, %d, %d, 0x%x)\n",
    461      1.1     ragge 		unit, func, dblk, size, buf));
    462      1.1     ragge 
    463      1.1     ragge 	hdc_select(hdc, unit);		/* select drive right now */
    464      1.1     ragge 
    465      1.1     ragge 	if (unit != 2 && dblk == -1) {	/* read the on-disk geometry */
    466      1.1     ragge 
    467      1.1     ragge 	  p->udc_dma7  = 0;
    468      1.1     ragge 	  p->udc_dma15 = 0;
    469      1.1     ragge 	  p->udc_dma23 = 0;
    470      1.1     ragge 
    471      1.1     ragge 	  p->udc_dsect = 0;
    472      1.1     ragge 	  p->udc_dhead = 0;
    473      1.1     ragge 	  p->udc_dcyl  = 0;
    474      1.1     ragge 
    475      1.1     ragge 	  p->udc_scnt  = size/512;
    476      1.1     ragge 	  p->udc_rtcnt = 0xF0;
    477      1.1     ragge 	  p->udc_mode  = 0xC0;
    478      1.1     ragge 	  p->udc_term  = 0xB4;
    479      1.1     ragge 
    480      1.1     ragge 	  vsbus_lockDMA(hdc->sc_cfargs);		/* bertram XXX */
    481      1.1     ragge 	  haveLock = 1;
    482      1.1     ragge 	  keepLock = 1;
    483      1.1     ragge 
    484      1.1     ragge #ifdef PARANOID
    485      1.1     ragge 	  bzero (hdc->sc_dmabase, size);	/* clear disk buffer */
    486      1.1     ragge #endif
    487      1.1     ragge 	  cmd = 0x5C | 0x03;			/* bypass bad sectors */
    488      1.1     ragge 	  cmd = 0x5C | 0x01;			/* terminate if bad sector */
    489      1.1     ragge 
    490      1.1     ragge 	  res = hdc_command (hdc, cmd);
    491      1.1     ragge 	  /* hold the locking ! */
    492      1.1     ragge 	  bcopy (hdc->sc_dmabase, buf, size);	/* copy to buf */
    493      1.1     ragge 	  /* now release the locking */
    494      1.1     ragge 
    495      1.1     ragge 	  vsbus_unlockDMA(hdc->sc_cfargs);
    496      1.1     ragge 	  haveLock = 0;
    497      1.1     ragge 	  keepLock = 0;
    498      1.1     ragge 
    499      1.1     ragge 	  return (res);
    500      1.1     ragge 	}
    501      1.1     ragge 
    502      1.1     ragge 	scount = size / 512;
    503      1.1     ragge 	while (scount) {
    504      1.1     ragge 	  /*
    505      1.1     ragge 	   * prepare drive/operation parameter
    506      1.1     ragge 	   */
    507      1.1     ragge 	  cyl  = dblk / lp->d_secpercyl;
    508      1.1     ragge 	  sect = dblk % lp->d_secpercyl;
    509      1.1     ragge 	  head = sect / lp->d_nsectors;
    510      1.1     ragge 	  sect = sect % lp->d_nsectors;
    511      1.1     ragge 	  if (unit == 2)
    512      1.1     ragge 		sect++;
    513      1.1     ragge 	  else
    514      1.1     ragge 		cyl++;		/* first cylinder is reserved */
    515      1.1     ragge 
    516      1.1     ragge 	  size = 512 * min(scount, lp->d_nsectors - sect);
    517      1.1     ragge 
    518      1.1     ragge 	  debug (("hdc_strategy: block #%d ==> s/t/c=%d/%d/%d (%d/%d)\n",
    519      1.1     ragge 		  dblk, sect, head, cyl, scount, size));
    520      1.1     ragge 
    521      1.1     ragge 	  /*
    522      1.1     ragge 	   * now initialize the register values ...
    523      1.1     ragge 	   */
    524      1.1     ragge 	  p->udc_dma7  = 0;
    525      1.1     ragge 	  p->udc_dma15 = 0;
    526      1.1     ragge 	  p->udc_dma23 = 0;
    527      1.1     ragge 
    528      1.1     ragge 	  p->udc_dsect = sect;
    529      1.1     ragge 	  head |= (cyl >> 4) & 0x70;
    530      1.1     ragge 	  p->udc_dhead = head;
    531      1.1     ragge 	  p->udc_dcyl  = cyl;
    532      1.1     ragge 
    533      1.1     ragge 	  p->udc_scnt  = size/512;
    534      1.1     ragge 
    535      1.1     ragge 	  if (unit == 2) {	/* floppy */
    536      1.1     ragge 	    p->udc_rtcnt = 0xF2;
    537      1.1     ragge 	    p->udc_mode	 = 0x81;	/* RX33 with RX50 media */
    538      1.1     ragge 	    p->udc_mode	 = 0x82;	/* RX33 with RX33 media */
    539      1.1     ragge 	    p->udc_term	 = 0xB4;
    540      1.1     ragge 	  } else {		 /* disk */
    541      1.1     ragge 	    p->udc_rtcnt = 0xF0;
    542      1.1     ragge 	    p->udc_mode	 = 0xC0;
    543      1.1     ragge 	    p->udc_term	 = 0xB4;
    544      1.1     ragge 	  }
    545      1.1     ragge 
    546      1.1     ragge 	  vsbus_lockDMA(hdc->sc_cfargs);
    547      1.1     ragge 	  haveLock = 1;
    548      1.1     ragge 	  keepLock = 1;
    549      1.1     ragge 
    550      1.1     ragge 	  if (func == F_WRITE) {
    551      1.1     ragge 	    bcopy (buf, hdc->sc_dmabase, size); /* copy from buf */
    552      1.1     ragge 	    cmd = 0xA0 | (unit==2 ? 1 : 0);
    553      1.1     ragge 	    res = hdc_command (hdc, cmd);
    554      1.1     ragge 	  }
    555      1.1     ragge 	  else {
    556      1.1     ragge #ifdef PARANOID
    557      1.1     ragge 	    bzero (hdc->sc_dmabase, size);		/* clear disk buffer */
    558      1.1     ragge #endif
    559      1.1     ragge 	    cmd = 0x5C | 0x03;	/* bypass bad sectors */
    560      1.1     ragge 	    cmd = 0x5C | 0x01;	/* terminate if bad sector */
    561      1.1     ragge 	    res = hdc_command (hdc, cmd);
    562      1.1     ragge 	    bcopy (hdc->sc_dmabase, buf, size); /* copy to buf */
    563      1.1     ragge 	  }
    564      1.1     ragge 
    565      1.1     ragge 	  vsbus_unlockDMA(hdc->sc_cfargs);
    566      1.1     ragge 	  haveLock = 0;
    567      1.1     ragge 	  keepLock = 0;
    568      1.1     ragge 
    569      1.1     ragge 	  scount -= size/512;
    570      1.1     ragge 	  dblk += size/512;
    571      1.1     ragge 	  buf += size;
    572      1.1     ragge 	}
    573      1.1     ragge 
    574      1.1     ragge 	if (unit != 2)		/* deselect drive, if not floppy */
    575      1.1     ragge 	  hdc_command (hdc, DKC_CMD_DRDESELECT);
    576      1.1     ragge 
    577      1.1     ragge 	return 0;
    578      1.1     ragge }
    579      1.1     ragge 
    580      1.1     ragge char hdc_iobuf[17*512];		/* we won't need more */
    581      1.1     ragge 
    582      1.1     ragge #ifdef DEBUG
    583      1.1     ragge /*
    584      1.1     ragge  * display the contents of the on-disk geometry structure
    585      1.1     ragge  */
    586      1.1     ragge int
    587      1.1     ragge hdc_printgeom(p)
    588      1.1     ragge 	struct rdgeom *p;
    589      1.1     ragge {
    590      1.1     ragge 	char dname[8];
    591      1.1     ragge 	hdc_mid2str(p->media_id, dname);
    592      1.1     ragge 
    593      1.4  christos 	printf ("**DiskData**	 XBNs: %d, DBNs: %d, LBNs: %d, RBNs: %d\n",
    594      1.1     ragge 		p->xbn_count, p->dbn_count, p->lbn_count, p->rbn_count);
    595      1.4  christos 	printf ("sec/track: %d, tracks: %d, cyl: %d, precomp/reduced: %d/%d\n",
    596      1.1     ragge 		p->nspt, p->ntracks, p->ncylinders, p->precomp, p->reduced);
    597      1.4  christos 	printf ("seek-rate: %d, crc/eec: %s, RCT: %d, RCT-copies: %d\n",
    598      1.1     ragge 		p->seek_rate, p->crc_eec?"EEC":"CRC", p->rct, p->rct_ncopies);
    599      1.4  christos 	printf ("media-ID: %s, interleave: %d, headskew: %d, cylskew: %d\n",
    600      1.1     ragge 		dname, p->interleave, p->headskew, p->cylskew);
    601      1.4  christos 	printf ("gap0: %d, gap1: %d, gap2: %d, gap3: %d, sync-value: %d\n",
    602      1.1     ragge 		p->gap0_size, p->gap1_size, p->gap2_size, p->gap3_size,
    603      1.1     ragge 		p->sync_value);
    604      1.1     ragge }
    605      1.1     ragge #endif
    606      1.1     ragge 
    607      1.1     ragge /*
    608      1.1     ragge  * Convert media_id to string/name (encoding is documented in mscp.h)
    609      1.1     ragge  */
    610      1.1     ragge int
    611      1.1     ragge hdc_mid2str(media_id, name)
    612      1.1     ragge 	long media_id;
    613      1.1     ragge 	char *name;
    614      1.1     ragge {
    615      1.1     ragge 	struct {			/* For RD32 this struct holds: */
    616      1.1     ragge 		u_long mt:7;		/* number in name: 0x20 == 32 */
    617      1.1     ragge 		u_long a2:5;		/* ' ' encoded as 0x0 */
    618      1.1     ragge 		u_long a1:5;		/* 'D' encoded with base '@' */
    619      1.1     ragge 		u_long a0:5;		/* 'R' encoded with base '@' */
    620      1.1     ragge 		u_long d1:5;		/* 'U' encoded with base '@' */
    621      1.1     ragge 		u_long d0:5;		/* 'D' encoded with base '@' */
    622      1.1     ragge 	} *p = (void*)&media_id;
    623      1.1     ragge 
    624      1.1     ragge #define MIDCHR(x)	(x ? x + '@' : ' ')
    625      1.1     ragge 
    626      1.4  christos 	sprintf (name, "%c%c%d", MIDCHR(p->a0), MIDCHR(p->a1), p->mt);
    627      1.1     ragge }
    628      1.1     ragge 
    629      1.1     ragge int
    630      1.1     ragge hdc_getdata(hdc, rd, unit)
    631      1.1     ragge 	struct hdcsoftc *hdc;
    632      1.1     ragge 	struct rdsoftc *rd;
    633      1.1     ragge 	int unit;
    634      1.1     ragge {
    635      1.1     ragge 	struct disklabel *lp = rd->sc_dk.dk_label;
    636      1.1     ragge 	struct rdparams *rp = &rd->sc_param;
    637      1.1     ragge 	int res;
    638      1.1     ragge 
    639      1.1     ragge 	trace (("hdc_getdata(%d)\n", unit));
    640      1.1     ragge 
    641      1.1     ragge 	bzero(rd->sc_dk.dk_label, sizeof(struct disklabel));
    642      1.1     ragge 	bzero(rd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel));
    643      1.1     ragge 
    644      1.1     ragge 	if (unit == 2) {
    645      1.1     ragge 		lp->d_secsize = DEV_BSIZE;
    646      1.1     ragge 		lp->d_ntracks = 2;
    647      1.1     ragge 		lp->d_nsectors = 15;
    648      1.1     ragge 		lp->d_ncylinders = 80;
    649      1.1     ragge 		lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
    650      1.1     ragge 
    651      1.1     ragge 		return (0);
    652      1.1     ragge 	}
    653      1.1     ragge 
    654      1.1     ragge 	res = hdc_strategy(hdc, rd, unit, F_READ, -1, 4096, hdc_iobuf);
    655      1.1     ragge 	bcopy (hdc_iobuf, &rd->sc_xbn, sizeof(struct rdgeom));
    656      1.1     ragge #ifdef DEBUG
    657      1.1     ragge 	hdc_printgeom(&rd->sc_xbn);
    658      1.1     ragge #endif
    659      1.1     ragge 	lp->d_secsize = DEV_BSIZE;
    660      1.1     ragge 	lp->d_ntracks = rd->sc_xbn.ntracks;
    661      1.1     ragge 	lp->d_nsectors = rd->sc_xbn.nspt;
    662      1.1     ragge 	lp->d_ncylinders = rd->sc_xbn.ncylinders;
    663      1.1     ragge 	lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
    664      1.1     ragge 
    665      1.1     ragge 	rp->cylinders = rd->sc_xbn.ncylinders;
    666      1.1     ragge 	rp->heads = rd->sc_xbn.ntracks;
    667      1.1     ragge 	rp->sectors = rd->sc_xbn.nspt;
    668      1.1     ragge 	rp->diskblks = rp->cylinders * rp->heads * rp->sectors;
    669      1.1     ragge 	rp->disklbns = rd->sc_xbn.lbn_count;
    670      1.1     ragge 	rp->blksize = DEV_BSIZE;
    671      1.1     ragge 	rp->diskbytes = rp->disklbns * rp->blksize;
    672      1.1     ragge 	hdc_mid2str(rd->sc_xbn.media_id, rp->diskname);
    673      1.1     ragge 
    674      1.1     ragge 	return (0);
    675      1.1     ragge }
    676      1.1     ragge 
    677      1.1     ragge int
    678      1.1     ragge hdc_getlabel(hdc, rd, unit)
    679      1.1     ragge 	struct hdcsoftc *hdc;
    680      1.1     ragge 	struct rdsoftc *rd;
    681      1.1     ragge 	int unit;
    682      1.1     ragge {
    683      1.1     ragge 	struct disklabel *lp = rd->sc_dk.dk_label;
    684      1.1     ragge 	struct disklabel *xp = (void*)(hdc_iobuf + 64);
    685      1.1     ragge 	int res;
    686      1.1     ragge 
    687      1.1     ragge 	trace (("hdc_getlabel(%d)\n", unit));
    688      1.1     ragge 
    689      1.1     ragge #define LBL_CHECK(x)	if (xp->x != lp->x) {			\
    690      1.4  christos 			  printf ("%d-->%d\n", xp->x, lp->x);	\
    691      1.1     ragge 			  xp->x = lp->x;			\
    692      1.1     ragge 			}
    693      1.1     ragge 	res = hdc_strategy(hdc, rd, unit, F_READ, 0, DEV_BSIZE, hdc_iobuf);
    694      1.1     ragge 	LBL_CHECK(d_secsize);
    695      1.1     ragge 	LBL_CHECK(d_ntracks);
    696      1.1     ragge 	LBL_CHECK(d_nsectors);
    697      1.1     ragge 	LBL_CHECK(d_ncylinders);
    698      1.1     ragge 	LBL_CHECK(d_secpercyl);
    699      1.1     ragge 	bcopy(xp, lp, sizeof(struct disklabel));
    700      1.1     ragge 
    701      1.1     ragge 	return (0);
    702      1.1     ragge }
    703      1.1     ragge 
    704      1.1     ragge /*
    705      1.1     ragge  * Return the size of a partition, if known, or -1 if not.
    706      1.1     ragge  */
    707      1.1     ragge hdcsize(dev)
    708      1.1     ragge 	dev_t dev;
    709      1.1     ragge {
    710      1.1     ragge 	int unit = HDCUNIT(dev);
    711      1.1     ragge 	int part = HDCPART(dev);
    712      1.1     ragge 	struct rdsoftc *rd = rd_cd.cd_devs[unit];
    713      1.1     ragge 	int size;
    714      1.1     ragge 
    715      1.1     ragge 	trace (("hdcsize(%x == %d/%d)\n", dev, unit, part));
    716      1.1     ragge 
    717      1.1     ragge 	if (hdcopen(dev, 0, S_IFBLK) != 0)
    718      1.1     ragge 		return (-1);
    719      1.1     ragge #if 0
    720      1.1     ragge 	if (rd->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP)
    721      1.1     ragge 		size = -1;
    722      1.1     ragge 	else
    723      1.1     ragge #endif
    724      1.1     ragge 		size = rd->sc_dk.dk_label->d_partitions[part].p_size;
    725      1.1     ragge 	if (hdcclose(dev, 0, S_IFBLK) != 0)
    726      1.1     ragge 		return (-1);
    727      1.1     ragge 	debug (("hdcsize: size=%d\n", size));
    728      1.1     ragge 	return (size);
    729      1.1     ragge }
    730      1.1     ragge 
    731      1.1     ragge /*
    732      1.1     ragge  *
    733      1.1     ragge  */
    734      1.1     ragge int
    735      1.1     ragge hdcopen (dev, flag, fmt)
    736      1.1     ragge 	dev_t dev;
    737      1.1     ragge 	int flag;
    738      1.1     ragge 	int fmt;
    739      1.1     ragge {
    740      1.1     ragge 	int unit = HDCUNIT(dev);
    741      1.1     ragge 	int part = HDCPART(dev);
    742      1.1     ragge 	struct hdcsoftc *hdc;
    743      1.1     ragge 	struct rdsoftc *rd;
    744      1.1     ragge 	int res, error;
    745      1.1     ragge 
    746      1.1     ragge 	trace (("hdcopen(0x%x = %d/%d)\n", dev, unit, part));
    747      1.1     ragge 
    748      1.1     ragge 	if (unit >= rd_cd.cd_ndevs) {
    749      1.4  christos 		printf ("hdcopen: invalid unit %d\n", unit);
    750      1.1     ragge 		return ENXIO;
    751      1.1     ragge 	}
    752      1.1     ragge 	rd = rd_cd.cd_devs[unit];
    753      1.1     ragge 	if (!rd) {
    754      1.4  christos 		printf("hdcopen: null-pointer in rdsoftc.\n");
    755      1.1     ragge 		return (ENXIO);
    756      1.1     ragge 	}
    757      1.1     ragge 	hdc = (void *)rd->sc_dev.dv_parent;
    758      1.1     ragge 
    759      1.1     ragge 	/* XXX here's much more to do! XXX */
    760      1.1     ragge 
    761      1.1     ragge 	hdc_getdata (hdc, rd, unit);
    762      1.1     ragge 	hdc_getlabel (hdc, rd, unit);
    763      1.1     ragge 
    764      1.1     ragge 	return (0);
    765      1.1     ragge }
    766      1.1     ragge 
    767      1.1     ragge /*
    768      1.1     ragge  *
    769      1.1     ragge  */
    770      1.1     ragge int
    771      1.1     ragge hdcclose (dev, flag)
    772      1.1     ragge 	dev_t dev;
    773      1.1     ragge 	int flag;
    774      1.1     ragge {
    775      1.1     ragge 	trace (("hdcclose()\n"));
    776      1.1     ragge 	return (0);
    777      1.1     ragge }
    778      1.1     ragge 
    779      1.1     ragge /*
    780      1.1     ragge  *
    781      1.1     ragge  */
    782      1.1     ragge void
    783      1.1     ragge hdcstrategy(bp)
    784      1.1     ragge 	register struct buf *bp;
    785      1.1     ragge {
    786      1.1     ragge 	trace (("hdcstrategy()\n"));
    787      1.1     ragge 	rdstrategy(bp);
    788      1.1     ragge 	debug (("hdcstrategy done.\n"));
    789      1.1     ragge }
    790      1.1     ragge 
    791      1.1     ragge /*
    792      1.1     ragge  *
    793      1.1     ragge  */
    794      1.1     ragge int
    795      1.1     ragge hdcioctl(dev, cmd, data, flag, p)
    796      1.1     ragge 	dev_t dev;
    797      1.1     ragge 	int cmd;
    798      1.1     ragge 	caddr_t data;	/* aka: addr */
    799      1.1     ragge 	int flag;
    800      1.1     ragge 	struct proc *p;
    801      1.1     ragge {
    802      1.1     ragge 	struct rdsoftc *rd = rd_cd.cd_devs[HDCUNIT(dev)];
    803      1.1     ragge 	struct hdcsoftc *hdc = (void *)rd->sc_dev.dv_parent;
    804      1.1     ragge 	int error;
    805      1.1     ragge 
    806      1.1     ragge 	trace (("hdcioctl(%x, %x)\n", dev, cmd));
    807      1.1     ragge 
    808      1.1     ragge 	/*
    809      1.1     ragge 	 * If the device is not valid.. abandon ship
    810      1.1     ragge 	 */
    811      1.1     ragge 	/* XXX */
    812      1.1     ragge 
    813      1.1     ragge 	switch (cmd) {
    814      1.1     ragge 	case DIOCGDINFO:
    815      1.1     ragge 		*(struct disklabel *)data = *(rd->sc_dk.dk_label);
    816      1.1     ragge 		return (0);
    817      1.1     ragge 
    818      1.1     ragge 	case DIOCGPART:
    819      1.1     ragge 		((struct partinfo *)data)->disklab = rd->sc_dk.dk_label;
    820      1.1     ragge 		((struct partinfo *)data)->part =
    821      1.1     ragge 		  &rd->sc_dk.dk_label->d_partitions[HDCPART(dev)];
    822      1.1     ragge 		return (0);
    823      1.1     ragge 
    824      1.1     ragge 	case DIOCWDINFO:
    825      1.1     ragge 	case DIOCSDINFO:
    826      1.1     ragge /* XXX
    827      1.1     ragge 		if ((flag & FWRITE) == 0)
    828      1.1     ragge 			return EBADF;
    829      1.1     ragge 
    830      1.1     ragge 		if ((error = sdlock(sd)) != 0)
    831      1.1     ragge 			return error;
    832      1.1     ragge 		sd->flags |= SDF_LABELLING;
    833      1.1     ragge */
    834      1.1     ragge 		error = setdisklabel(rd->sc_dk.dk_label,
    835      1.1     ragge 		     (struct disklabel *)data, 0, rd->sc_dk.dk_cpulabel);
    836      1.1     ragge 		if (error == 0) {
    837      1.1     ragge 			if (cmd == DIOCWDINFO)
    838      1.1     ragge 				error = writedisklabel(HDCLABELDEV(dev),
    839      1.1     ragge 					rdstrategy, rd->sc_dk.dk_label,
    840      1.1     ragge 					rd->sc_dk.dk_cpulabel);
    841      1.1     ragge 		}
    842      1.1     ragge /* XXX
    843      1.1     ragge 		sd->flags &= ~SDF_LABELLING;
    844      1.1     ragge 		sdunlock(sd);
    845      1.1     ragge */
    846      1.1     ragge 		return (error);
    847      1.1     ragge 
    848      1.1     ragge 	case DIOCWLABEL:
    849      1.1     ragge 		if ((flag & FWRITE) == 0)
    850      1.1     ragge 			return (EBADF);
    851      1.1     ragge /* XXX
    852      1.1     ragge 		if (*(int *)data)
    853      1.1     ragge 			sd->flags |= SDF_WLABEL;
    854      1.1     ragge 		else
    855      1.1     ragge 			sd->flags &= ~SDF_WLABEL;
    856      1.1     ragge */
    857      1.1     ragge 		return (0);
    858      1.1     ragge 
    859      1.1     ragge 	default:
    860      1.1     ragge 		if (HDCPART(dev) != RAW_PART)
    861      1.1     ragge 			return ENOTTY;
    862      1.4  christos 		printf ("IOCTL %x not implemented.\n", cmd);
    863      1.1     ragge 		return (-1);
    864      1.1     ragge 	}
    865      1.1     ragge }
    866      1.1     ragge 
    867      1.1     ragge /*
    868      1.1     ragge  *
    869      1.1     ragge  */
    870      1.1     ragge int
    871      1.1     ragge hdcintr()
    872      1.1     ragge {
    873      1.1     ragge 	trace (("hdcintr()\n"));
    874      1.1     ragge }
    875      1.1     ragge 
    876      1.1     ragge /*
    877      1.1     ragge  *
    878      1.1     ragge  */
    879      1.1     ragge int
    880      1.1     ragge hdcread (dev, uio)
    881      1.1     ragge 	dev_t dev;
    882      1.1     ragge 	struct uio *uio;
    883      1.1     ragge {
    884      1.1     ragge 	trace (("hdcread()\n"));
    885      1.1     ragge 	return (physio (hdcstrategy, NULL, dev, B_READ, minphys, uio));
    886      1.1     ragge }
    887      1.1     ragge 
    888      1.1     ragge /*
    889      1.1     ragge  *
    890      1.1     ragge  */
    891      1.1     ragge int
    892      1.1     ragge hdcwrite (dev, uio)
    893      1.1     ragge 	dev_t dev;
    894      1.1     ragge 	struct uio *uio;
    895      1.1     ragge {
    896      1.1     ragge 	trace (("hdcwrite()\n"));
    897      1.1     ragge 	return (physio (hdcstrategy, NULL, dev, B_WRITE, minphys, uio));
    898      1.1     ragge }
    899      1.1     ragge 
    900      1.1     ragge /*
    901      1.1     ragge  *
    902      1.1     ragge  */
    903      1.1     ragge int
    904      1.1     ragge hdcdump(dev)
    905      1.1     ragge 	dev_t dev;
    906      1.1     ragge {
    907      1.1     ragge 	trace (("hdcdump (%x)\n", dev));
    908      1.1     ragge }
    909      1.1     ragge 
    910      1.1     ragge /*
    911      1.1     ragge  * we have to wait 0.7 usec between two accesses to any of the
    912      1.1     ragge  * dkc-registers, on a VS2000 with 1 MIPS, this is roughly one
    913      1.1     ragge  * instruction. Thus the loop-overhead will be enough...
    914      1.1     ragge  */
    915      1.1     ragge void
    916      1.1     ragge hdc_readregs(sc)
    917      1.1     ragge 	struct hdcsoftc *sc;
    918      1.1     ragge {
    919      1.1     ragge 	int i;
    920      1.1     ragge 	char *p;
    921      1.1     ragge 
    922      1.1     ragge 	trace(("hdc_readregs()\n"));
    923      1.1     ragge 
    924      1.1     ragge 	sc->sc_dkc->dkc_cmd = 0x40;	/* set internal counter to zero */
    925      1.1     ragge 	p = (void*)&sc->sc_sreg;
    926      1.1     ragge 	for (i=0; i<10; i++)
    927      1.1     ragge 		*p++ = sc->sc_dkc->dkc_reg;	/* dkc_reg auto-increments */
    928      1.1     ragge }
    929      1.1     ragge 
    930      1.1     ragge void
    931      1.1     ragge hdc_writeregs(sc)
    932      1.1     ragge 	struct hdcsoftc *sc;
    933      1.1     ragge {
    934      1.1     ragge 	int i;
    935      1.1     ragge 	char *p;
    936      1.1     ragge 
    937      1.1     ragge 	trace(("hdc_writeregs()\n"));
    938      1.1     ragge 
    939      1.1     ragge 	sc->sc_dkc->dkc_cmd = 0x40;	/* set internal counter to zero */
    940      1.1     ragge 	p = (void*)&sc->sc_creg;
    941      1.1     ragge 	for (i=0; i<10; i++)
    942      1.1     ragge 		sc->sc_dkc->dkc_reg = *p++;	/* dkc_reg auto-increments */
    943      1.1     ragge }
    944      1.1     ragge 
    945      1.1     ragge /*
    946      1.1     ragge  * hdc_command() issues a command and polls the intreq-register
    947      1.1     ragge  * to find when command has completed
    948      1.1     ragge  */
    949      1.1     ragge int
    950      1.1     ragge hdc_command(sc, cmd)
    951      1.1     ragge 	struct hdcsoftc *sc;
    952      1.1     ragge 	int cmd;
    953      1.1     ragge {
    954      1.1     ragge 	volatile u_char *intreq = (void*)uvax_phys2virt(KA410_INTREQ);
    955      1.1     ragge 	volatile u_char *intclr = (void*)uvax_phys2virt(KA410_INTCLR);
    956      1.1     ragge 	volatile u_char *intmsk = (void*)uvax_phys2virt(KA410_INTMSK);
    957      1.1     ragge 	int i, c;
    958      1.1     ragge 
    959      1.1     ragge 	trace (("hdc_command(%x)\n", cmd));
    960      1.1     ragge 	debug (("intr-state: %x %x %x\n", *intreq, *intclr, *intmsk));
    961      1.1     ragge 
    962      1.1     ragge 	if (!haveLock) {
    963      1.1     ragge 	  vsbus_lockDMA(sc->sc_cfargs);
    964      1.1     ragge 	  haveLock = 1;
    965      1.1     ragge 	}
    966      1.1     ragge 
    967      1.1     ragge 	hdc_writeregs(sc);		/* write the prepared registers */
    968      1.1     ragge 	*intclr = INTR_DC;		/* clear any old interrupt */
    969      1.1     ragge 	sc->sc_dkc->dkc_cmd = cmd;	/* issue the command */
    970      1.1     ragge 	for (i=0; i<MAX_WAIT; i++) {
    971      1.1     ragge 		if ((c = *intreq) & INTR_DC)
    972      1.1     ragge 			break;
    973      1.1     ragge 	}
    974      1.1     ragge 	if ((c & INTR_DC) == 0) {
    975      1.4  christos 		printf ("hdc_command: timeout in command 0x%x\n", cmd);
    976      1.1     ragge 	}
    977      1.1     ragge 	hdc_readregs(sc);		/* read the status registers */
    978      1.1     ragge 	sc->sc_status = sc->sc_dkc->dkc_stat;
    979      1.1     ragge 
    980      1.1     ragge 	if (!keepLock) {
    981      1.1     ragge 	  vsbus_unlockDMA(sc->sc_cfargs);
    982      1.1     ragge 	  haveLock = 0;
    983      1.1     ragge 	}
    984      1.1     ragge 
    985      1.1     ragge 	if (sc->sc_status != DKC_ST_DONE|DKC_TC_SUCCESS) {
    986      1.4  christos 		printf ("command 0x%x completed with status 0x%x\n",
    987      1.1     ragge 			cmd, sc->sc_status);
    988      1.1     ragge 		return (-1);
    989      1.1     ragge 	}
    990      1.1     ragge 	return (0);
    991      1.1     ragge }
    992      1.1     ragge 
    993      1.1     ragge /*
    994      1.1     ragge  * writing zero into the command-register will reset the controller.
    995      1.1     ragge  * This will not interrupt data-transfer commands!
    996      1.1     ragge  * Also no interrupt is generated, thus we don't use hdc_command()
    997      1.1     ragge  */
    998      1.1     ragge int
    999      1.1     ragge hdc_reset(sc)
   1000      1.1     ragge 	struct hdcsoftc *sc;
   1001      1.1     ragge {
   1002      1.1     ragge 	trace (("hdc_reset()\n"));
   1003      1.1     ragge 
   1004      1.1     ragge 	sc->sc_dkc->dkc_cmd = DKC_CMD_RESET;	/* issue RESET command */
   1005      1.1     ragge 	hdc_readregs(sc);			/* read the status registers */
   1006      1.1     ragge 	sc->sc_status = sc->sc_dkc->dkc_stat;
   1007      1.1     ragge 	if (sc->sc_status != DKC_ST_DONE|DKC_TC_SUCCESS) {
   1008      1.4  christos 		printf ("RESET command completed with status 0x%x\n",
   1009      1.1     ragge 			sc->sc_status);
   1010      1.1     ragge 		return (-1);
   1011      1.1     ragge 	}
   1012      1.1     ragge 	return (0);
   1013      1.1     ragge }
   1014      1.1     ragge 
   1015      1.1     ragge int
   1016      1.1     ragge hdc_rxselect(sc, unit)
   1017      1.1     ragge 	struct hdcsoftc *sc;
   1018      1.1     ragge 	int unit;
   1019      1.1     ragge {
   1020      1.1     ragge 	register struct hdc9224_UDCreg *p = &sc->sc_creg;
   1021      1.1     ragge 	register struct hdc9224_UDCreg *q = &sc->sc_sreg;
   1022      1.1     ragge 	int error;
   1023      1.1     ragge 
   1024      1.1     ragge 	/*
   1025      1.1     ragge 	 * bring command-regs in some known-to-work state and
   1026      1.1     ragge 	 * select the drive with the DRIVE SELECT command.
   1027      1.1     ragge 	 */
   1028      1.1     ragge 	p->udc_dma7  = 0;
   1029      1.1     ragge 	p->udc_dma15 = 0;
   1030      1.1     ragge 	p->udc_dma23 = 0;
   1031      1.1     ragge 	p->udc_dsect = 1;	/* sectors are numbered 1..15 !!! */
   1032      1.1     ragge 	p->udc_dhead = 0;
   1033      1.1     ragge 	p->udc_dcyl  = 0;
   1034      1.1     ragge 	p->udc_scnt  = 0;
   1035      1.1     ragge 
   1036      1.1     ragge 	p->udc_rtcnt = UDC_RC_RX33READ;
   1037      1.1     ragge 	p->udc_mode  = UDC_MD_RX33;
   1038      1.1     ragge 	p->udc_term  = UDC_TC_FDD;
   1039      1.1     ragge 
   1040      1.1     ragge 	/*
   1041      1.1     ragge 	 * this is ...
   1042      1.1     ragge 	 */
   1043      1.1     ragge 	error = hdc_command (sc, DKC_CMD_DRSEL_RX33 | unit);
   1044      1.1     ragge 
   1045      1.1     ragge 	if ((error != 0) || (q->udc_dstat & UDC_DS_READY == 0)) {
   1046      1.4  christos 	  printf("\nfloppy-drive not ready (new floppy inserted?)\n\n");
   1047      1.1     ragge 	  p->udc_rtcnt &= ~UDC_RC_INVRDY;	/* clear INVRDY-flag */
   1048      1.1     ragge 	  error = hdc_command(sc, DKC_CMD_DRSEL_RX33 | unit);
   1049      1.1     ragge 	  if ((error != 0) || (q->udc_dstat & UDC_DS_READY == 0)) {
   1050      1.4  christos 	    printf("diskette not ready(1): %x/%x\n", error, q->udc_dstat);
   1051      1.4  christos 	    printf("floppy-drive offline?\n");
   1052      1.1     ragge 	    return (-1);
   1053      1.1     ragge 	  }
   1054      1.1     ragge 
   1055      1.1     ragge 	  if (q->udc_dstat & UDC_DS_TRK00)		    /* if track-0 */
   1056      1.1     ragge 	    error = hdc_command(sc, DKC_CMD_STEPIN_FDD);   /* step inwards */
   1057      1.1     ragge 	  else						    /* else */
   1058      1.1     ragge 	    error = hdc_command(sc, DKC_CMD_STEPOUT_FDD);  /* step outwards */
   1059      1.1     ragge 
   1060      1.1     ragge 	  if ((error != 0) || (q->udc_dstat & UDC_DS_READY == 1)) {
   1061      1.4  christos 	    printf("diskette not ready(2): %x/%x\n", error, q->udc_dstat);
   1062      1.4  christos 	    printf("No floppy inserted or drive offline\n");
   1063      1.1     ragge 	    /* return (-1); */
   1064      1.1     ragge 	  }
   1065      1.1     ragge 
   1066      1.1     ragge 	  p->udc_rtcnt |= UDC_RC_INVRDY;
   1067      1.1     ragge 	  error = hdc_command(sc, DKC_CMD_DRSEL_RX33 | unit);
   1068      1.1     ragge 	  if ((error != 0) || (q->udc_dstat & UDC_DS_READY == 0)) {
   1069      1.4  christos 	    printf("diskette not ready(3): %x/%x\n", error, q->udc_dstat);
   1070      1.4  christos 	    printf("no floppy inserted or floppy-door open\n");
   1071      1.1     ragge 	    return(-1);
   1072      1.1     ragge 	  }
   1073      1.4  christos 	  printf("floppy-drive reselected.\n");
   1074      1.1     ragge 	}
   1075      1.1     ragge 	if (error)
   1076      1.1     ragge 		error = hdc_command (sc, DKC_CMD_DRSEL_RX33 | unit);
   1077      1.1     ragge 
   1078      1.1     ragge 	return (error);
   1079      1.1     ragge }
   1080      1.1     ragge 
   1081      1.1     ragge int
   1082      1.1     ragge hdc_rdselect(sc, unit)
   1083      1.1     ragge 	struct hdcsoftc *sc;
   1084      1.1     ragge 	int unit;
   1085      1.1     ragge {
   1086      1.1     ragge 	register struct hdc9224_UDCreg *p = &sc->sc_creg;
   1087      1.1     ragge 	register struct hdc9224_UDCreg *q = &sc->sc_sreg;
   1088      1.1     ragge 	int error;
   1089      1.1     ragge 
   1090      1.1     ragge 	/*
   1091      1.1     ragge 	 * bring "creg" in some known-to-work state and
   1092      1.1     ragge 	 * select the drive with the DRIVE SELECT command.
   1093      1.1     ragge 	 */
   1094      1.1     ragge 	p->udc_dma7  = 0;
   1095      1.1     ragge 	p->udc_dma15 = 0;
   1096      1.1     ragge 	p->udc_dma23 = 0;
   1097      1.1     ragge 	p->udc_dsect = 0;		/* sectors are numbered 0..16 */
   1098      1.1     ragge 	p->udc_dhead = 0;
   1099      1.1     ragge 	p->udc_dcyl  = 0;
   1100      1.1     ragge 	p->udc_scnt  = 0;
   1101      1.1     ragge 
   1102      1.1     ragge 	p->udc_rtcnt = UDC_RC_HDD_READ;
   1103      1.1     ragge 	p->udc_mode  = UDC_MD_HDD;
   1104      1.1     ragge 	p->udc_term  = UDC_TC_HDD;
   1105      1.1     ragge 
   1106      1.1     ragge 	error = hdc_command (sc, DKC_CMD_DRSEL_HDD | unit);
   1107      1.1     ragge 	if (error)
   1108      1.1     ragge 		error = hdc_command (sc, DKC_CMD_DRSEL_HDD | unit);
   1109      1.1     ragge 
   1110      1.1     ragge 	return (error);
   1111      1.1     ragge }
   1112      1.1     ragge 
   1113      1.1     ragge /*
   1114      1.1     ragge  * bring command-regs into some known-to-work state and select
   1115      1.1     ragge  * the drive with the DRIVE SELECT command.
   1116      1.1     ragge  */
   1117      1.1     ragge int
   1118      1.1     ragge hdc_select(sc, unit)
   1119      1.1     ragge 	struct hdcsoftc *sc;
   1120      1.1     ragge 	int unit;
   1121      1.1     ragge {
   1122      1.1     ragge 	int error;
   1123      1.1     ragge 
   1124      1.1     ragge 	trace (("hdc_select(%x,%d)\n", sc, unit));
   1125      1.1     ragge 
   1126      1.1     ragge 	switch (unit) {
   1127      1.1     ragge 	case 0:
   1128      1.1     ragge 	case 1:
   1129      1.1     ragge 		error = hdc_rdselect(sc, unit);
   1130      1.1     ragge 		break;
   1131      1.1     ragge 	case 2:
   1132      1.1     ragge 		error = hdc_rxselect(sc, unit);
   1133      1.1     ragge 		/* bertram: delay ??? XXX */
   1134      1.1     ragge 		break;
   1135      1.1     ragge 	default:
   1136      1.4  christos 		printf("invalid unit %d in hdc_select()\n", unit);
   1137      1.1     ragge 		error = -1;
   1138      1.1     ragge 	}
   1139      1.1     ragge 
   1140      1.1     ragge 	return (error);
   1141      1.1     ragge }
   1142      1.1     ragge 
   1143      1.1     ragge #endif	/* NHDC > 0 */
   1144