Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / scsipi / uk.c
blob6fcf470e9736cf6d3cd0ddde8a2b2bceab741b42
1 /* $NetBSD: uk.c,v 1.58 2009/05/12 14:44:31 cegger Exp $ */
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Dummy driver for a device we can't identify.
34 * Originally by Julian Elischer (julian@tfs.com)
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: uk.c,v 1.58 2009/05/12 14:44:31 cegger Exp $");
40 #include <sys/param.h>
41 #include <sys/systm.h>
43 #include <sys/errno.h>
44 #include <sys/ioctl.h>
45 #include <sys/device.h>
46 #include <sys/conf.h>
47 #include <sys/vnode.h>
49 #include <dev/scsipi/scsi_all.h>
50 #include <dev/scsipi/scsipi_all.h>
51 #include <dev/scsipi/scsiconf.h>
53 #define UKUNIT(z) (minor(z))
55 struct uk_softc {
56 struct device sc_dev;
58 struct scsipi_periph *sc_periph; /* all the inter level info */
61 static int ukmatch(device_t, cfdata_t, void *);
62 static void ukattach(device_t, device_t, void *);
63 static int ukdetach(device_t, int);
66 CFATTACH_DECL(uk, sizeof(struct uk_softc), ukmatch, ukattach, ukdetach, NULL);
68 extern struct cfdriver uk_cd;
70 static dev_type_open(ukopen);
71 static dev_type_close(ukclose);
72 static dev_type_ioctl(ukioctl);
74 const struct cdevsw uk_cdevsw = {
75 ukopen, ukclose, noread, nowrite, ukioctl,
76 nostop, notty, nopoll, nommap, nokqfilter, D_OTHER,
79 static int
80 ukmatch(device_t parent, cfdata_t match,
81 void *aux)
84 return (1);
88 * The routine called by the low level scsi routine when it discovers
89 * a device suitable for this driver.
91 static void
92 ukattach(device_t parent, device_t self, void *aux)
94 struct uk_softc *uk = device_private(self);
95 struct scsipibus_attach_args *sa = aux;
96 struct scsipi_periph *periph = sa->sa_periph;
98 SC_DEBUG(periph, SCSIPI_DB2, ("ukattach: "));
101 * Store information needed to contact our base driver
103 uk->sc_periph = periph;
104 periph->periph_dev = &uk->sc_dev;
106 printf("\n");
109 static int
110 ukdetach(device_t self, int flags)
112 /*struct uk_softc *uk = device_private(self);*/
113 int cmaj, mn;
115 /* locate the major number */
116 cmaj = cdevsw_lookup_major(&uk_cdevsw);
118 /* Nuke the vnodes for any open instances */
119 mn = device_unit(self);
120 vdevgone(cmaj, mn, mn, VCHR);
122 return (0);
126 * open the device.
128 static int
129 ukopen(dev_t dev, int flag, int fmt, struct lwp *l)
131 int unit, error;
132 struct uk_softc *uk;
133 struct scsipi_periph *periph;
134 struct scsipi_adapter *adapt;
136 unit = UKUNIT(dev);
137 uk = device_lookup_private(&uk_cd, unit);
138 if (uk == NULL)
139 return (ENXIO);
141 periph = uk->sc_periph;
142 adapt = periph->periph_channel->chan_adapter;
144 SC_DEBUG(periph, SCSIPI_DB1,
145 ("ukopen: dev=0x%"PRIx64" (unit %d (of %d))\n", dev, unit,
146 uk_cd.cd_ndevs));
149 * Only allow one at a time
151 if (periph->periph_flags & PERIPH_OPEN) {
152 aprint_error_dev(&uk->sc_dev, "already open\n");
153 return (EBUSY);
156 if ((error = scsipi_adapter_addref(adapt)) != 0)
157 return (error);
158 periph->periph_flags |= PERIPH_OPEN;
160 SC_DEBUG(periph, SCSIPI_DB3, ("open complete\n"));
161 return (0);
165 * close the device.. only called if we are the LAST
166 * occurence of an open device
168 static int
169 ukclose(dev_t dev, int flag, int fmt, struct lwp *l)
171 struct uk_softc *uk = device_lookup_private(&uk_cd, UKUNIT(dev));
172 struct scsipi_periph *periph = uk->sc_periph;
173 struct scsipi_adapter *adapt = periph->periph_channel->chan_adapter;
175 SC_DEBUG(uk->sc_periph, SCSIPI_DB1, ("closing\n"));
177 scsipi_wait_drain(periph);
179 scsipi_adapter_delref(adapt);
180 periph->periph_flags &= ~PERIPH_OPEN;
182 return (0);
186 * Perform special action on behalf of the user
187 * Only does generic scsi ioctls.
189 static int
190 ukioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
192 struct uk_softc *uk = device_lookup_private(&uk_cd, UKUNIT(dev));
194 return (scsipi_do_ioctl(uk->sc_periph, dev, cmd, addr, flag, l));