Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/mscp Copied from ../../arch/vax/mscp/mscp_disk.c, v
details: https://anonhg.NetBSD.org/src/rev/95a6b71db962
branches: trunk
changeset: 473334:95a6b71db962
user: ragge <ragge%NetBSD.org@localhost>
date: Sat May 29 19:11:41 1999 +0000
description:
Copied from ../../arch/vax/mscp/mscp_disk.c,v
diffstat:
sys/dev/mscp/mscp_disk.c | 1008 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 1008 insertions(+), 0 deletions(-)
diffs (truncated from 1012 to 300 lines):
diff -r b037a44c5dd4 -r 95a6b71db962 sys/dev/mscp/mscp_disk.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/mscp/mscp_disk.c Sat May 29 19:11:41 1999 +0000
@@ -0,0 +1,1008 @@
+/* $NetBSD: mscp_disk.c,v 1.20 1999/05/29 19:11:41 ragge Exp $ */
+/*
+ * Copyright (c) 1996 Ludd, University of Lule}, Sweden.
+ * Copyright (c) 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * 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:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
+ *
+ * @(#)uda.c 7.32 (Berkeley) 2/13/91
+ */
+
+/*
+ * RA disk device driver
+ * RX MSCP floppy disk device driver
+ */
+
+/*
+ * TODO
+ * write bad block forwarding code
+ */
+
+#include <sys/param.h>
+#include <sys/buf.h>
+#include <sys/device.h>
+#include <sys/disk.h>
+#include <sys/disklabel.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/fcntl.h>
+#include <sys/reboot.h>
+#include <sys/proc.h>
+#include <sys/systm.h>
+
+#include <ufs/ufs/dinode.h>
+#include <ufs/ffs/fs.h>
+
+#include <machine/cpu.h>
+#include <machine/rpb.h>
+
+#include <vax/mscp/mscp.h>
+#include <vax/mscp/mscpvar.h>
+
+#include "locators.h"
+#include "ioconf.h"
+#include "ra.h"
+
+#define RAMAJOR 9 /* RA major device number XXX */
+
+/*
+ * Drive status, per drive
+ */
+struct ra_softc {
+ struct device ra_dev; /* Autoconf struct */
+ struct disk ra_disk;
+ int ra_state; /* open/closed state */
+ u_long ra_mediaid; /* media id */
+ int ra_hwunit; /* Hardware unit number */
+ int ra_havelabel; /* true if we have a label */
+ int ra_wlabel; /* label sector is currently writable */
+};
+
+#define rx_softc ra_softc
+
+void rxattach __P((struct device *, struct device *, void *));
+int rx_putonline __P((struct rx_softc *));
+void rrmakelabel __P((struct disklabel *, long));
+
+#if NRA
+
+int ramatch __P((struct device *, struct cfdata *, void *));
+void raattach __P((struct device *, struct device *, void *));
+int raopen __P((dev_t, int, int, struct proc *));
+int raclose __P((dev_t, int, int, struct proc *));
+void rastrategy __P((struct buf *));
+int raread __P((dev_t, struct uio *));
+int rawrite __P((dev_t, struct uio *));
+int raioctl __P((dev_t, int, caddr_t, int, struct proc *));
+int radump __P((dev_t, daddr_t, caddr_t, size_t));
+int rasize __P((dev_t));
+int ra_putonline __P((struct ra_softc *));
+
+struct cfattach ra_ca = {
+ sizeof(struct ra_softc), ramatch, raattach
+};
+
+/*
+ * More driver definitions, for generic MSCP code.
+ */
+
+int
+ramatch(parent, cf, aux)
+ struct device *parent;
+ struct cfdata *cf;
+ void *aux;
+{
+ struct drive_attach_args *da = aux;
+ struct mscp *mp = da->da_mp;
+
+ if ((da->da_typ & MSCPBUS_DISK) == 0)
+ return 0;
+ if (cf->cf_loc[MSCPBUSCF_DRIVE] != MSCPBUSCF_DRIVE_DEFAULT &&
+ cf->cf_loc[MSCPBUSCF_DRIVE] != mp->mscp_unit)
+ return 0;
+ /*
+ * Check if this disk is a floppy; then don't configure it.
+ * Seems to be a safe way to test it per Chris Torek.
+ */
+ if (MSCP_MID_ECH(1, mp->mscp_guse.guse_mediaid) == 'X' - '@')
+ return 0;
+ return 1;
+}
+
+/*
+ * The attach routine only checks and prints drive type.
+ * Bringing the disk online is done when the disk is accessed
+ * the first time.
+ */
+void
+raattach(parent, self, aux)
+ struct device *parent, *self;
+ void *aux;
+{
+ struct ra_softc *ra = (void *)self;
+ struct mscp_softc *mi = (void *)parent;
+
+ rxattach(parent, self, aux);
+ /*
+ * Find out if we booted from this disk.
+ */
+ if ((B_TYPE(bootdev) == BDEV_UDA) && (ra->ra_hwunit == B_UNIT(bootdev))
+ && (mi->mi_ctlrnr == B_CONTROLLER(bootdev))
+ && (mi->mi_adapnr == B_ADAPTOR(bootdev)))
+ booted_from = self;
+}
+
+/*
+ * (Try to) put the drive online. This is done the first time the
+ * drive is opened, or if it har fallen offline.
+ */
+int
+ra_putonline(ra)
+ struct ra_softc *ra;
+{
+ struct disklabel *dl;
+ char *msg;
+
+ if (rx_putonline(ra) != MSCP_DONE)
+ return MSCP_FAILED;
+
+ dl = ra->ra_disk.dk_label;
+
+ ra->ra_state = DK_RDLABEL;
+ printf("%s", ra->ra_dev.dv_xname);
+ if ((msg = readdisklabel(MAKEDISKDEV(RAMAJOR, ra->ra_dev.dv_unit,
+ RAW_PART), rastrategy, dl, NULL)) != NULL)
+ printf(": %s", msg);
+ else {
+ ra->ra_havelabel = 1;
+ ra->ra_state = DK_OPEN;
+ }
+
+ printf(": size %d sectors\n", dl->d_secperunit);
+
+ return MSCP_DONE;
+}
+
+/*
+ * Open a drive.
+ */
+/*ARGSUSED*/
+int
+raopen(dev, flag, fmt, p)
+ dev_t dev;
+ int flag, fmt;
+ struct proc *p;
+{
+ register struct ra_softc *ra;
+ int part, unit, mask;
+ /*
+ * Make sure this is a reasonable open request.
+ */
+ unit = DISKUNIT(dev);
+ if (unit >= ra_cd.cd_ndevs)
+ return ENXIO;
+ ra = ra_cd.cd_devs[unit];
+ if (ra == 0)
+ return ENXIO;
+
+ /*
+ * If this is the first open; we must first try to put
+ * the disk online (and read the label).
+ */
+ if (ra->ra_state == DK_CLOSED)
+ if (ra_putonline(ra) == MSCP_FAILED)
+ return ENXIO;
+
+ /* If the disk has no label; allow writing everywhere */
+ if (ra->ra_havelabel == 0)
+ ra->ra_wlabel = 1;
+
+ part = DISKPART(dev);
+ if (part >= ra->ra_disk.dk_label->d_npartitions)
+ return ENXIO;
+
+ /*
+ * Wait for the state to settle
+ */
+#if notyet
+ while (ra->ra_state != DK_OPEN)
+ if ((error = tsleep((caddr_t)ra, (PZERO + 1) | PCATCH,
+ devopn, 0))) {
+ splx(s);
+ return (error);
+ }
+#endif
+
+ mask = 1 << part;
+
+ switch (fmt) {
+ case S_IFCHR:
+ ra->ra_disk.dk_copenmask |= mask;
+ break;
+ case S_IFBLK:
+ ra->ra_disk.dk_bopenmask |= mask;
+ break;
+ }
+ ra->ra_disk.dk_openmask |= mask;
+ return 0;
+}
+
+/* ARGSUSED */
+int
+raclose(dev, flags, fmt, p)
+ dev_t dev;
+ int flags, fmt;
+ struct proc *p;
+{
+ register int unit = DISKUNIT(dev);
+ register struct ra_softc *ra = ra_cd.cd_devs[unit];
+ int mask = (1 << DISKPART(dev));
+
+ switch (fmt) {
+ case S_IFCHR:
+ ra->ra_disk.dk_copenmask &= ~mask;
+ break;
+ case S_IFBLK:
+ ra->ra_disk.dk_bopenmask &= ~mask;
+ break;
+ }
+ ra->ra_disk.dk_openmask =
+ ra->ra_disk.dk_copenmask | ra->ra_disk.dk_bopenmask;
+
+ /*
+ * Should wait for I/O to complete on this partition even if
+ * others are open, but wait for work on blkflush().
+ */
+#if notyet
+ if (ra->ra_openpart == 0) {
+ s = splbio();
+ while (udautab[unit].b_actf)
+ sleep((caddr_t)&udautab[unit], PZERO - 1);
+ splx(s);
+ ra->ra_state = CLOSED;
+ ra->ra_wlabel = 0;
+ }
+#endif
+ return (0);
Home |
Main Index |
Thread Index |
Old Index