Deleted Added
sdiff udiff text old ( 111815 ) new ( 114001 )
full compact
1/* $FreeBSD: head/sys/dev/iir/iir_ctrl.c 114001 2003-04-25 05:37:04Z scottl $ */
2/*
3 * Copyright (c) 2000-01 Intel Corporation
4 * All Rights Reserved
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
17 *
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
28 * SUCH DAMAGE.
29 */
30
31/*
32 * iir_ctrl.c: Control functions and /dev entry points for /dev/iir*
33 *
34 * Written by: Achim Leubner <achim.leubner@intel.com>
35 * Fixes/Additions: Boji Tony Kannanthanam <boji.t.kannanthanam@intel.com>
36 *
37 * TODO:
38 */
39
40#ident "$Id: iir_ctrl.c 1.2 2001/07/18 11:17:22 achim Exp $"
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/endian.h>
45#include <sys/malloc.h>
46#include <sys/kernel.h>
47#include <sys/uio.h>
48#include <sys/conf.h>
49#include <sys/disk.h>
50#include <sys/stat.h>
51#include <sys/disklabel.h>
52#include <machine/bus.h>
53#include <vm/vm.h>
54#include <vm/vm_kern.h>
55#include <vm/vm_extern.h>
56#include <vm/pmap.h>
57
58#include <dev/iir/iir.h>
59
60/* Entry points and other prototypes */
61static struct gdt_softc *gdt_minor2softc(int minor_no);
62
63static d_open_t iir_open;
64static d_close_t iir_close;
65static d_write_t iir_write;
66static d_read_t iir_read;
67static d_ioctl_t iir_ioctl;
68
69#define CDEV_MAJOR IIR_CDEV_MAJOR
70
71/* Normally, this is a static structure. But we need it in pci/iir_pci.c */
72static struct cdevsw iir_cdevsw = {
73 .d_open = iir_open,
74 .d_close = iir_close,
75 .d_read = iir_read,
76 .d_write = iir_write,
77 .d_ioctl = iir_ioctl,
78 .d_name = "iir",
79 .d_maj = CDEV_MAJOR,
80};
81
82/*
83static int iir_devsw_installed = 0;
84*/
85#ifndef SDEV_PER_HBA
86static int sdev_made = 0;
87#endif
88extern int gdt_cnt;
89extern char ostype[];
90extern char osrelease[];
91extern gdt_statist_t gdt_stat;
92
93/*
94 * Given a controller number,
95 * make a special device and return the dev_t
96 */
97dev_t
98gdt_make_dev(int unit)
99{
100 dev_t dev;
101
102#ifdef SDEV_PER_HBA
103 dev = make_dev(&iir_cdevsw, hba2minor(unit), UID_ROOT, GID_OPERATOR,
104 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, "iir%d", unit);
105#else
106 if (sdev_made)
107 return (0);
108 dev = make_dev(&iir_cdevsw, 0, UID_ROOT, GID_OPERATOR,
109 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, "iir");
110 sdev_made = 1;
111#endif
112 return (dev);
113}
114
115void
116gdt_destroy_dev(dev_t dev)
117{
118 if (dev != NULL)
119 destroy_dev(dev);
120}
121
122/*
123 * Given a minor device number,
124 * return the pointer to its softc structure
125 */
126static struct gdt_softc *
127gdt_minor2softc(int minor_no)
128{
129 struct gdt_softc *gdt;
130 int hanum;
131
132#ifdef SDEV_PER_HBA
133 hanum = minor2hba(minor_no);
134#else
135 hanum = minor_no;
136#endif
137
138 for (gdt = TAILQ_FIRST(&gdt_softcs);
139 gdt != NULL && gdt->sc_hanum != hanum;
140 gdt = TAILQ_NEXT(gdt, links));
141
142 return (gdt);
143}
144
145static int
146iir_open(dev_t dev, int flags, int fmt, d_thread_t * p)
147{
148 GDT_DPRINTF(GDT_D_DEBUG, ("iir_open()\n"));
149
150#ifdef SDEV_PER_HBA
151 int minor_no;
152 struct gdt_softc *gdt;
153
154 minor_no = minor(dev);
155 gdt = gdt_minor2softc(minor_no);
156 if (gdt == NULL)
157 return (ENXIO);
158#endif
159
160 return (0);
161}
162
163static int
164iir_close(dev_t dev, int flags, int fmt, d_thread_t * p)
165{
166 GDT_DPRINTF(GDT_D_DEBUG, ("iir_close()\n"));
167
168#ifdef SDEV_PER_HBA
169 int minor_no;
170 struct gdt_softc *gdt;
171
172 minor_no = minor(dev);
173 gdt = gdt_minor2softc(minor_no);
174 if (gdt == NULL)
175 return (ENXIO);
176#endif
177
178 return (0);
179}
180
181static int
182iir_write(dev_t dev, struct uio * uio, int ioflag)
183{
184 GDT_DPRINTF(GDT_D_DEBUG, ("iir_write()\n"));
185
186#ifdef SDEV_PER_HBA
187 int minor_no;
188 struct gdt_softc *gdt;
189
190 minor_no = minor(dev);
191 gdt = gdt_minor2softc(minor_no);
192 if (gdt == NULL)
193 return (ENXIO);
194#endif
195
196 return (0);
197}
198
199static int
200iir_read(dev_t dev, struct uio * uio, int ioflag)
201{
202 GDT_DPRINTF(GDT_D_DEBUG, ("iir_read()\n"));
203
204#ifdef SDEV_PER_HBA
205 int minor_no;
206 struct gdt_softc *gdt;
207
208 minor_no = minor(dev);
209 gdt = gdt_minor2softc(minor_no);
210 if (gdt == NULL)
211 return (ENXIO);
212#endif
213
214 return (0);
215}
216
217/**
218 * This is the control syscall interface.
219 * It should be binary compatible with UnixWare,
220 * if not totally syntatically so.
221 */
222
223static int
224iir_ioctl(dev_t dev, u_long cmd, caddr_t cmdarg, int flags, d_thread_t * p)
225{
226 GDT_DPRINTF(GDT_D_DEBUG, ("iir_ioctl() cmd 0x%lx\n",cmd));
227
228#ifdef SDEV_PER_HBA
229 int minor_no;
230 struct gdt_softc *gdt;
231
232 minor_no = minor(dev);
233 gdt = gdt_minor2softc(minor_no);
234 if (gdt == NULL)
235 return (ENXIO);
236#endif
237 ++gdt_stat.io_count_act;
238 if (gdt_stat.io_count_act > gdt_stat.io_count_max)
239 gdt_stat.io_count_max = gdt_stat.io_count_act;
240
241 switch (cmd) {
242 case GDT_IOCTL_GENERAL:
243 {
244 gdt_ucmd_t *ucmd;
245 struct gdt_softc *gdt;
246 int lock;
247
248 ucmd = (gdt_ucmd_t *)cmdarg;
249 gdt = gdt_minor2softc(ucmd->io_node);
250 if (gdt == NULL)
251 return (ENXIO);
252 lock = splcam();
253 TAILQ_INSERT_TAIL(&gdt->sc_ucmd_queue, ucmd, links);
254 ucmd->complete_flag = FALSE;
255 splx(lock);
256 gdt_next(gdt);
257 if (!ucmd->complete_flag)
258 (void) tsleep((void *)ucmd, PCATCH | PRIBIO, "iirucw", 0);
259 break;
260 }
261
262 case GDT_IOCTL_DRVERS:
263 *(int *)cmdarg =
264 (IIR_DRIVER_VERSION << 8) | IIR_DRIVER_SUBVERSION;
265 break;
266
267 case GDT_IOCTL_CTRTYPE:
268 {
269 gdt_ctrt_t *p;
270 struct gdt_softc *gdt;
271
272 p = (gdt_ctrt_t *)cmdarg;
273 gdt = gdt_minor2softc(p->io_node);
274 if (gdt == NULL)
275 return (ENXIO);
276 p->oem_id = 0x8000;
277 p->type = 0xfd;
278 p->info = (gdt->sc_bus << 8) | (gdt->sc_slot << 3);
279 p->ext_type = 0x6000 | gdt->sc_subdevice;
280 p->device_id = gdt->sc_device;
281 p->sub_device_id = gdt->sc_subdevice;
282 break;
283 }
284
285 case GDT_IOCTL_OSVERS:
286 {
287 gdt_osv_t *p;
288
289 p = (gdt_osv_t *)cmdarg;
290 p->oscode = 10;
291 p->version = osrelease[0] - '0';
292 if (osrelease[1] == '.')
293 p->subversion = osrelease[2] - '0';
294 else
295 p->subversion = 0;
296 if (osrelease[3] == '.')
297 p->revision = osrelease[4] - '0';
298 else
299 p->revision = 0;
300 strcpy(p->name, ostype);
301 break;
302 }
303
304 case GDT_IOCTL_CTRCNT:
305 *(int *)cmdarg = gdt_cnt;
306 break;
307
308 case GDT_IOCTL_EVENT:
309 {
310 gdt_event_t *p;
311 int lock;
312
313 p = (gdt_event_t *)cmdarg;
314 if (p->erase == 0xff) {
315 if (p->dvr.event_source == GDT_ES_TEST)
316 p->dvr.event_data.size = sizeof(p->dvr.event_data.eu.test);
317 else if (p->dvr.event_source == GDT_ES_DRIVER)
318 p->dvr.event_data.size= sizeof(p->dvr.event_data.eu.driver);
319 else if (p->dvr.event_source == GDT_ES_SYNC)
320 p->dvr.event_data.size = sizeof(p->dvr.event_data.eu.sync);
321 else
322 p->dvr.event_data.size = sizeof(p->dvr.event_data.eu.async);
323 lock = splcam();
324 gdt_store_event(p->dvr.event_source, p->dvr.event_idx,
325 &p->dvr.event_data);
326 splx(lock);
327 } else if (p->erase == 0xfe) {
328 lock = splcam();
329 gdt_clear_events();
330 splx(lock);
331 } else if (p->erase == 0) {
332 p->handle = gdt_read_event(p->handle, &p->dvr);
333 } else {
334 gdt_readapp_event((u_int8_t)p->erase, &p->dvr);
335 }
336 break;
337 }
338
339 case GDT_IOCTL_STATIST:
340 {
341 gdt_statist_t *p;
342
343 p = (gdt_statist_t *)cmdarg;
344 bcopy(&gdt_stat, p, sizeof(gdt_statist_t));
345 break;
346 }
347
348 default:
349 break;
350 }
351
352 --gdt_stat.io_count_act;
353 return (0);
354}
355
356/*
357static void
358iir_drvinit(void *unused)
359{
360 GDT_DPRINTF(GDT_D_DEBUG, ("iir_drvinit()\n"));
361
362 if (!iir_devsw_installed) {
363 cdevsw_add(&iir_cdevsw);
364 iir_devsw_installed = 1;
365 }
366}
367
368SYSINIT(iir_dev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE + CDEV_MAJOR, iir_drvinit, NULL)
369*/