Module Name: src Committed By: mbalmer Date: Wed Feb 8 12:22:00 UTC 2012
Modified Files: src/sys/dev/scsipi: uk.c Log Message: Convert uk(4) to device_t. While here, clean up the code a bit. releng ok (ack 3, nak 0, wait no more) To generate a diff of this commit: cvs rdiff -u -r1.59 -r1.60 src/sys/dev/scsipi/uk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/scsipi/uk.c diff -u src/sys/dev/scsipi/uk.c:1.59 src/sys/dev/scsipi/uk.c:1.60 --- src/sys/dev/scsipi/uk.c:1.59 Sun Dec 6 22:48:17 2009 +++ src/sys/dev/scsipi/uk.c Wed Feb 8 12:22:00 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: uk.c,v 1.59 2009/12/06 22:48:17 dyoung Exp $ */ +/* $NetBSD: uk.c,v 1.60 2012/02/08 12:22:00 mbalmer Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uk.c,v 1.59 2009/12/06 22:48:17 dyoung Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uk.c,v 1.60 2012/02/08 12:22:00 mbalmer Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -50,10 +50,8 @@ __KERNEL_RCSID(0, "$NetBSD: uk.c,v 1.59 #include <dev/scsipi/scsipi_all.h> #include <dev/scsipi/scsiconf.h> -#define UKUNIT(z) (minor(z)) - struct uk_softc { - struct device sc_dev; + device_t sc_dev; struct scsipi_periph *sc_periph; /* all the inter level info */ }; @@ -62,8 +60,14 @@ static int ukmatch(device_t, cfdata_t, v static void ukattach(device_t, device_t, void *); static int ukdetach(device_t, int); - -CFATTACH_DECL(uk, sizeof(struct uk_softc), ukmatch, ukattach, ukdetach, NULL); +CFATTACH_DECL_NEW( + uk, + sizeof(struct uk_softc), + ukmatch, + ukattach, + ukdetach, + NULL +); extern struct cfdriver uk_cd; @@ -77,11 +81,9 @@ const struct cdevsw uk_cdevsw = { }; static int -ukmatch(device_t parent, cfdata_t match, - void *aux) +ukmatch(device_t parent, cfdata_t match, void *aux) { - - return (1); + return 1; } /* @@ -96,12 +98,11 @@ ukattach(device_t parent, device_t self, struct scsipi_periph *periph = sa->sa_periph; SC_DEBUG(periph, SCSIPI_DB2, ("ukattach: ")); + uk->sc_dev = self; - /* - * Store information needed to contact our base driver - */ + /* Store information needed to contact our base driver */ uk->sc_periph = periph; - periph->periph_dev = &uk->sc_dev; + periph->periph_dev = uk->sc_dev; printf("\n"); } @@ -109,7 +110,6 @@ ukattach(device_t parent, device_t self, static int ukdetach(device_t self, int flags) { - /*struct uk_softc *uk = device_private(self);*/ int cmaj, mn; /* locate the major number */ @@ -119,12 +119,9 @@ ukdetach(device_t self, int flags) mn = device_unit(self); vdevgone(cmaj, mn, mn, VCHR); - return (0); + return 0; } -/* - * open the device. - */ static int ukopen(dev_t dev, int flag, int fmt, struct lwp *l) { @@ -133,10 +130,10 @@ ukopen(dev_t dev, int flag, int fmt, str struct scsipi_periph *periph; struct scsipi_adapter *adapt; - unit = UKUNIT(dev); + unit = minor(dev); uk = device_lookup_private(&uk_cd, unit); if (uk == NULL) - return (ENXIO); + return ENXIO; periph = uk->sc_periph; adapt = periph->periph_channel->chan_adapter; @@ -145,30 +142,24 @@ ukopen(dev_t dev, int flag, int fmt, str ("ukopen: dev=0x%"PRIx64" (unit %d (of %d))\n", dev, unit, uk_cd.cd_ndevs)); - /* - * Only allow one at a time - */ + /* Only allow one at a time */ if (periph->periph_flags & PERIPH_OPEN) { - aprint_error_dev(&uk->sc_dev, "already open\n"); - return (EBUSY); + aprint_error_dev(uk->sc_dev, "already open\n"); + return EBUSY; } if ((error = scsipi_adapter_addref(adapt)) != 0) - return (error); + return error; periph->periph_flags |= PERIPH_OPEN; SC_DEBUG(periph, SCSIPI_DB3, ("open complete\n")); - return (0); + return 0; } -/* - * close the device.. only called if we are the LAST - * occurence of an open device - */ static int ukclose(dev_t dev, int flag, int fmt, struct lwp *l) { - struct uk_softc *uk = device_lookup_private(&uk_cd, UKUNIT(dev)); + struct uk_softc *uk = device_lookup_private(&uk_cd, minor(dev)); struct scsipi_periph *periph = uk->sc_periph; struct scsipi_adapter *adapt = periph->periph_channel->chan_adapter; @@ -179,17 +170,17 @@ ukclose(dev_t dev, int flag, int fmt, st scsipi_adapter_delref(adapt); periph->periph_flags &= ~PERIPH_OPEN; - return (0); + return 0; } /* - * Perform special action on behalf of the user + * Perform special action on behalf of the user. * Only does generic scsi ioctls. */ static int ukioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l) { - struct uk_softc *uk = device_lookup_private(&uk_cd, UKUNIT(dev)); + struct uk_softc *uk = device_lookup_private(&uk_cd, minor(dev)); - return (scsipi_do_ioctl(uk->sc_periph, dev, cmd, addr, flag, l)); + return scsipi_do_ioctl(uk->sc_periph, dev, cmd, addr, flag, l); }