1 /* $FreeBSD: src/sys/dev/iir/iir_ctrl.c,v 1.2.2.4 2002/05/05 08:18:12 asmodai Exp $ */
3 * Copyright (c) 2000-01 Intel Corporation
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer,
11 * without modification, immediately at the beginning of the file.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * iir_ctrl.c: Control functions and /dev entry points for /dev/iir*
34 * Written by: Achim Leubner <achim.leubner@intel.com>
35 * Fixes/Additions: Boji Tony Kannanthanam <boji.t.kannanthanam@intel.com>
40 #ident "$Id: iir_ctrl.c 1.2 2001/07/18 11:17:22 achim Exp $"
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/malloc.h>
45 #include <sys/kernel.h>
49 #include <sys/disklabel.h>
50 #include <machine/bus.h>
52 #include <vm/vm_kern.h>
53 #include <vm/vm_extern.h>
56 #include <dev/iir/iir.h>
58 /* Entry points and other prototypes */
59 static struct gdt_softc *gdt_minor2softc(int minor_no);
61 static d_open_t iir_open;
62 static d_close_t iir_close;
63 static d_write_t iir_write;
64 static d_read_t iir_read;
65 static d_ioctl_t iir_ioctl;
67 #define CDEV_MAJOR IIR_CDEV_MAJOR
69 /* Normally, this is a static structure. But we need it in pci/iir_pci.c */
70 static struct cdevsw iir_cdevsw = {
72 /* close */ iir_close,
74 /* write */ iir_write,
75 /* ioctl */ iir_ioctl,
78 /* strategy */ nostrategy,
87 static int iir_devsw_installed = 0;
89 static int sdev_made = 0;
93 extern char osrelease[];
94 extern gdt_statist_t gdt_stat;
97 * Given a controller number,
98 * make a special device and return the dev_t
101 gdt_make_dev(int unit)
106 dev = make_dev(&iir_cdevsw, hba2minor(unit), UID_ROOT, GID_OPERATOR,
107 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, "iir%d", unit);
111 dev = make_dev(&iir_cdevsw, 0, UID_ROOT, GID_OPERATOR,
112 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, "iir");
119 gdt_destroy_dev(dev_t dev)
126 * Given a minor device number,
127 * return the pointer to its softc structure
129 static struct gdt_softc *
130 gdt_minor2softc(int minor_no)
132 struct gdt_softc *gdt;
136 hanum = minor2hba(minor_no);
141 for (gdt = TAILQ_FIRST(&gdt_softcs);
142 gdt != NULL && gdt->sc_hanum != hanum;
143 gdt = TAILQ_NEXT(gdt, links));
149 iir_open(dev_t dev, int flags, int fmt, d_thread_t * p)
151 GDT_DPRINTF(GDT_D_DEBUG, ("iir_open()\n"));
155 struct gdt_softc *gdt;
157 minor_no = minor(dev);
158 gdt = gdt_minor2softc(minor_no);
167 iir_close(dev_t dev, int flags, int fmt, d_thread_t * p)
169 GDT_DPRINTF(GDT_D_DEBUG, ("iir_close()\n"));
173 struct gdt_softc *gdt;
175 minor_no = minor(dev);
176 gdt = gdt_minor2softc(minor_no);
185 iir_write(dev_t dev, struct uio * uio, int ioflag)
187 GDT_DPRINTF(GDT_D_DEBUG, ("iir_write()\n"));
191 struct gdt_softc *gdt;
193 minor_no = minor(dev);
194 gdt = gdt_minor2softc(minor_no);
203 iir_read(dev_t dev, struct uio * uio, int ioflag)
205 GDT_DPRINTF(GDT_D_DEBUG, ("iir_read()\n"));
209 struct gdt_softc *gdt;
211 minor_no = minor(dev);
212 gdt = gdt_minor2softc(minor_no);
221 * This is the control syscall interface.
222 * It should be binary compatible with UnixWare,
223 * if not totally syntatically so.
227 iir_ioctl(dev_t dev, u_long cmd, caddr_t cmdarg, int flags, d_thread_t * p)
229 GDT_DPRINTF(GDT_D_DEBUG, ("iir_ioctl() cmd 0x%lx\n",cmd));
233 struct gdt_softc *gdt;
235 minor_no = minor(dev);
236 gdt = gdt_minor2softc(minor_no);
240 ++gdt_stat.io_count_act;
241 if (gdt_stat.io_count_act > gdt_stat.io_count_max)
242 gdt_stat.io_count_max = gdt_stat.io_count_act;
245 case GDT_IOCTL_GENERAL:
248 struct gdt_softc *gdt;
251 ucmd = (gdt_ucmd_t *)cmdarg;
252 gdt = gdt_minor2softc(ucmd->io_node);
256 TAILQ_INSERT_TAIL(&gdt->sc_ucmd_queue, ucmd, links);
257 ucmd->complete_flag = FALSE;
260 if (!ucmd->complete_flag)
261 (void) tsleep((void *)ucmd, PCATCH | PRIBIO, "iirucw", 0);
265 case GDT_IOCTL_DRVERS:
267 (IIR_DRIVER_VERSION << 8) | IIR_DRIVER_SUBVERSION;
270 case GDT_IOCTL_CTRTYPE:
273 struct gdt_softc *gdt;
275 p = (gdt_ctrt_t *)cmdarg;
276 gdt = gdt_minor2softc(p->io_node);
281 p->info = (gdt->sc_bus << 8) | (gdt->sc_slot << 3);
282 p->ext_type = 0x6000 | gdt->sc_subdevice;
283 p->device_id = gdt->sc_device;
284 p->sub_device_id = gdt->sc_subdevice;
288 case GDT_IOCTL_OSVERS:
292 p = (gdt_osv_t *)cmdarg;
294 p->version = osrelease[0] - '0';
295 if (osrelease[1] == '.')
296 p->subversion = osrelease[2] - '0';
299 if (osrelease[3] == '.')
300 p->revision = osrelease[4] - '0';
303 strcpy(p->name, ostype);
307 case GDT_IOCTL_CTRCNT:
308 *(int *)cmdarg = gdt_cnt;
311 case GDT_IOCTL_EVENT:
316 p = (gdt_event_t *)cmdarg;
317 if (p->erase == 0xff) {
318 if (p->dvr.event_source == GDT_ES_TEST)
319 p->dvr.event_data.size = sizeof(p->dvr.event_data.eu.test);
320 else if (p->dvr.event_source == GDT_ES_DRIVER)
321 p->dvr.event_data.size= sizeof(p->dvr.event_data.eu.driver);
322 else if (p->dvr.event_source == GDT_ES_SYNC)
323 p->dvr.event_data.size = sizeof(p->dvr.event_data.eu.sync);
325 p->dvr.event_data.size = sizeof(p->dvr.event_data.eu.async);
327 gdt_store_event(p->dvr.event_source, p->dvr.event_idx,
330 } else if (p->erase == 0xfe) {
334 } else if (p->erase == 0) {
335 p->handle = gdt_read_event(p->handle, &p->dvr);
337 gdt_readapp_event((u_int8_t)p->erase, &p->dvr);
342 case GDT_IOCTL_STATIST:
346 p = (gdt_statist_t *)cmdarg;
347 bcopy(&gdt_stat, p, sizeof(gdt_statist_t));
355 --gdt_stat.io_count_act;
360 iir_drvinit(void *unused)
362 GDT_DPRINTF(GDT_D_DEBUG, ("iir_drvinit()\n"));
364 if (!iir_devsw_installed) {
365 /* Add the I/O (data) channel */
366 cdevsw_add(&iir_cdevsw);
367 iir_devsw_installed = 1;
371 SYSINIT(iir_dev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE + CDEV_MAJOR, iir_drvinit, NULL)