No empty .Rs/.Re
[netbsd-mini2440.git] / sys / dev / ic / icp_ioctl.c
blobd9c575f96dc852381b909248a90d58b82f775be4
1 /* $NetBSD: icp_ioctl.c,v 1.18 2008/04/28 20:23:50 martin Exp $ */
3 /*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of Wasabi Systems, Inc.
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 * Copyright (c) 2000-01 Intel Corporation
34 * All Rights Reserved
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions, and the following disclaimer,
41 * without modification, immediately at the beginning of the file.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. The name of the author may not be used to endorse or promote products
46 * derived from this software without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
52 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
62 * icp_ioctl.c: Ioctl interface for the ICP-Vortex management tools.
64 * Based on ICP's FreeBSD "iir" driver ioctl interface, written by
65 * Achim Leubner <achim.leubner@intel.com>.
67 * This is intended to be ABI-compatile with the ioctl interface for
68 * other OSs.
71 #include <sys/cdefs.h>
72 __KERNEL_RCSID(0, "$NetBSD: icp_ioctl.c,v 1.18 2008/04/28 20:23:50 martin Exp $");
74 #include <sys/param.h>
75 #include <sys/systm.h>
76 #include <sys/kernel.h>
77 #include <sys/device.h>
78 #include <sys/proc.h>
79 #include <sys/conf.h>
80 #include <sys/ioctl.h>
81 #include <sys/kauth.h>
83 #include <sys/bus.h>
85 #include <dev/ic/icpreg.h>
86 #include <dev/ic/icpvar.h>
88 /* These are simply the same as ICP's "iir" driver for FreeBSD. */
89 #define ICP_DRIVER_VERSION 1
90 #define ICP_DRIVER_SUBVERSION 3
92 static dev_type_open(icpopen);
93 static dev_type_ioctl(icpioctl);
95 const struct cdevsw icp_cdevsw = {
96 icpopen, nullclose, noread, nowrite, icpioctl,
97 nostop, notty, nopoll, nommap, nokqfilter, D_OTHER,
100 extern struct cfdriver icp_cd;
102 kmutex_t icp_ioctl_mutex;
104 static int
105 icpopen(dev_t dev, int flag, int mode, struct lwp *l)
108 if (device_lookup(&icp_cd, minor(dev)) == NULL)
109 return (ENXIO);
111 return (0);
114 static int
115 icpioctl(dev_t dev, u_long cmd, void *data, int flag,
116 struct lwp *l)
118 int error = 0;
120 mutex_enter(&icp_ioctl_mutex);
122 switch (cmd) {
123 case GDT_IOCTL_GENERAL:
125 struct icp_softc *icp;
126 gdt_ucmd_t *ucmd = (void *) data;
128 error = kauth_authorize_device_passthru(l->l_cred, dev,
129 KAUTH_REQ_DEVICE_RAWIO_PASSTHRU_ALL, data);
130 if (error)
131 break;
133 icp = device_lookup_private(&icp_cd, ucmd->io_node);
134 if (icp == NULL) {
135 error = ENXIO;
136 break;
139 error = icp_ucmd(icp, ucmd);
140 break;
143 case GDT_IOCTL_DRVERS:
144 *(int *) data =
145 (ICP_DRIVER_VERSION << 8) | ICP_DRIVER_SUBVERSION;
146 break;
148 case GDT_IOCTL_CTRTYPE:
150 struct icp_softc *icp;
151 gdt_ctrt_t *ctrt = (void *) data;
153 icp = device_lookup_private(&icp_cd, ctrt->io_node);
154 if (icp == NULL) {
155 error = ENXIO;
156 break;
159 /* XXX magic numbers */
160 ctrt->oem_id = 0x8000;
161 ctrt->type = 0xfd;
162 ctrt->info = (icp->icp_pci_bus << 8) | (icp->icp_pci_device << 3);
163 ctrt->ext_type = 0x6000 | icp->icp_pci_subdevice_id;
164 ctrt->device_id = icp->icp_pci_device_id;
165 ctrt->sub_device_id = icp->icp_pci_subdevice_id;
166 break;
169 case GDT_IOCTL_OSVERS:
171 gdt_osv_t *osv = (void *) data;
173 osv->oscode = 12;
176 * __NetBSD_Version__ is encoded thusly:
178 * MMmmrrpp00
180 * M = major version
181 * m = minor version
182 * r = release ["",A-Z[A-Z] but numeric]
183 * p = patchlevel
185 * Since the ABI is not supposed to change between
186 * patchlevels of the same major/minor version, we
187 * will encode major/minor/release into the returned
188 * data.
191 osv->version = __NetBSD_Version__ / 100000000;
192 osv->subversion = (__NetBSD_Version__ / 1000000) % 100;
193 osv->revision = (__NetBSD_Version__ / 10000) % 100;
195 strcpy(osv->name, ostype);
196 break;
199 case GDT_IOCTL_CTRCNT:
200 *(int *) data = icp_count;
201 break;
203 case GDT_IOCTL_EVENT:
205 struct icp_softc *icp;
206 gdt_event_t *evt = (void *) data;
207 gdt_evt_str *e = &evt->dvr;
208 int s;
210 icp = device_lookup_private(&icp_cd, minor(dev));
212 switch (evt->erase) {
213 case 0xff:
214 switch (evt->dvr.event_source) {
215 case GDT_ES_TEST:
216 e->event_data.size =
217 sizeof(e->event_data.eu.test);
218 break;
220 case GDT_ES_DRIVER:
221 e->event_data.size =
222 sizeof(e->event_data.eu.driver);
223 break;
225 case GDT_ES_SYNC:
226 e->event_data.size =
227 sizeof(e->event_data.eu.sync);
228 break;
230 default:
231 e->event_data.size =
232 sizeof(e->event_data.eu.async);
233 break;
235 s = splbio();
236 icp_store_event(icp, e->event_source, e->event_idx,
237 &e->event_data);
238 splx(s);
239 break;
241 case 0xfe:
242 s = splbio();
243 icp_clear_events(icp);
244 splx(s);
245 break;
247 case 0:
248 evt->handle = icp_read_event(icp, evt->handle, e);
249 break;
251 default:
252 icp_readapp_event(icp, (u_int8_t) evt->erase, e);
253 break;
255 break;
258 case GDT_IOCTL_STATIST:
259 memcpy(&icp_stats, data, sizeof(gdt_statist_t));
260 break;
263 case GDT_IOCTL_RESCAN:
265 struct icp_softc *icp;
266 gdt_rescan_t *rsc = (void *) data;
268 icp = device_lookup_private(&icp_cd, rsc->io_node);
269 if (icp == NULL) {
270 error = ENXIO;
271 break;
274 error = icp_freeze(icp);
275 if (error)
276 break;
277 if (rsc->flag == 0)
278 icp_rescan_all(icp);
279 else
280 icp_rescan(icp, rsc->hdr_no);
281 icp_unfreeze(icp);
282 break;
285 default:
286 error = ENOTTY;
289 mutex_exit(&icp_ioctl_mutex);
291 return (error);