1 /* $NetBSD: icp_ioctl.c,v 1.18 2008/04/28 20:23:50 martin Exp $ */
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
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
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
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
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
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
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>
80 #include <sys/ioctl.h>
81 #include <sys/kauth.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
;
105 icpopen(dev_t dev
, int flag
, int mode
, struct lwp
*l
)
108 if (device_lookup(&icp_cd
, minor(dev
)) == NULL
)
115 icpioctl(dev_t dev
, u_long cmd
, void *data
, int flag
,
120 mutex_enter(&icp_ioctl_mutex
);
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
);
133 icp
= device_lookup_private(&icp_cd
, ucmd
->io_node
);
139 error
= icp_ucmd(icp
, ucmd
);
143 case GDT_IOCTL_DRVERS
:
145 (ICP_DRIVER_VERSION
<< 8) | ICP_DRIVER_SUBVERSION
;
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
);
159 /* XXX magic numbers */
160 ctrt
->oem_id
= 0x8000;
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
;
169 case GDT_IOCTL_OSVERS
:
171 gdt_osv_t
*osv
= (void *) data
;
176 * __NetBSD_Version__ is encoded thusly:
182 * r = release ["",A-Z[A-Z] but numeric]
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
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
);
199 case GDT_IOCTL_CTRCNT
:
200 *(int *) data
= icp_count
;
203 case GDT_IOCTL_EVENT
:
205 struct icp_softc
*icp
;
206 gdt_event_t
*evt
= (void *) data
;
207 gdt_evt_str
*e
= &evt
->dvr
;
210 icp
= device_lookup_private(&icp_cd
, minor(dev
));
212 switch (evt
->erase
) {
214 switch (evt
->dvr
.event_source
) {
217 sizeof(e
->event_data
.eu
.test
);
222 sizeof(e
->event_data
.eu
.driver
);
227 sizeof(e
->event_data
.eu
.sync
);
232 sizeof(e
->event_data
.eu
.async
);
236 icp_store_event(icp
, e
->event_source
, e
->event_idx
,
243 icp_clear_events(icp
);
248 evt
->handle
= icp_read_event(icp
, evt
->handle
, e
);
252 icp_readapp_event(icp
, (u_int8_t
) evt
->erase
, e
);
258 case GDT_IOCTL_STATIST
:
259 memcpy(&icp_stats
, data
, sizeof(gdt_statist_t
));
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
);
274 error
= icp_freeze(icp
);
280 icp_rescan(icp
, rsc
->hdr_no
);
289 mutex_exit(&icp_ioctl_mutex
);