Home | History | Annotate | Line # | Download | only in ic
icp_ioctl.c revision 1.10.4.1
      1  1.10.4.1      yamt /*	$NetBSD: icp_ioctl.c,v 1.10.4.1 2006/10/22 06:05:44 yamt Exp $	*/
      2       1.1   thorpej 
      3       1.1   thorpej /*-
      4       1.1   thorpej  * Copyright (c) 2003 The NetBSD Foundation, Inc.
      5       1.1   thorpej  * All rights reserved.
      6       1.1   thorpej  *
      7       1.1   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1   thorpej  * by Jason R. Thorpe of Wasabi Systems, Inc.
      9       1.1   thorpej  *
     10       1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     11       1.1   thorpej  * modification, are permitted provided that the following conditions
     12       1.1   thorpej  * are met:
     13       1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     14       1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     15       1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     17       1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     18       1.1   thorpej  * 3. All advertising materials mentioning features or use of this software
     19       1.1   thorpej  *    must display the following acknowledgement:
     20       1.1   thorpej  *        This product includes software developed by the NetBSD
     21       1.1   thorpej  *        Foundation, Inc. and its contributors.
     22       1.1   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.1   thorpej  *    contributors may be used to endorse or promote products derived
     24       1.1   thorpej  *    from this software without specific prior written permission.
     25       1.1   thorpej  *
     26       1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.1   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.1   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.1   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.1   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.1   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.1   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.1   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.1   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.1   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.1   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1   thorpej  */
     38       1.1   thorpej 
     39       1.1   thorpej /*
     40       1.1   thorpej  *       Copyright (c) 2000-01 Intel Corporation
     41       1.1   thorpej  *       All Rights Reserved
     42       1.1   thorpej  *
     43       1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     44       1.1   thorpej  * modification, are permitted provided that the following conditions
     45       1.1   thorpej  * are met:
     46       1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     47       1.1   thorpej  *    notice, this list of conditions, and the following disclaimer,
     48       1.1   thorpej  *    without modification, immediately at the beginning of the file.
     49       1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     50       1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     51       1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     52       1.1   thorpej  * 3. The name of the author may not be used to endorse or promote products
     53       1.1   thorpej  *    derived from this software without specific prior written permission.
     54       1.1   thorpej  *
     55       1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     56       1.1   thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     57       1.1   thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     58       1.1   thorpej  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     59       1.1   thorpej  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     60       1.1   thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     61       1.1   thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     62       1.1   thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     63       1.1   thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     64       1.1   thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     65       1.1   thorpej  * SUCH DAMAGE.
     66       1.1   thorpej  */
     67       1.1   thorpej 
     68       1.1   thorpej /*
     69       1.1   thorpej  * icp_ioctl.c: Ioctl interface for the ICP-Vortex management tools.
     70       1.1   thorpej  *
     71       1.1   thorpej  * Based on ICP's FreeBSD "iir" driver ioctl interface, written by
     72       1.1   thorpej  * Achim Leubner <achim.leubner (at) intel.com>.
     73       1.1   thorpej  *
     74       1.1   thorpej  * This is intended to be ABI-compatile with the ioctl interface for
     75       1.1   thorpej  * other OSs.
     76       1.1   thorpej  */
     77       1.1   thorpej 
     78       1.1   thorpej #include <sys/cdefs.h>
     79  1.10.4.1      yamt __KERNEL_RCSID(0, "$NetBSD: icp_ioctl.c,v 1.10.4.1 2006/10/22 06:05:44 yamt Exp $");
     80       1.1   thorpej 
     81       1.1   thorpej #include <sys/param.h>
     82       1.6     perry #include <sys/systm.h>
     83       1.1   thorpej #include <sys/kernel.h>
     84       1.1   thorpej #include <sys/device.h>
     85       1.1   thorpej #include <sys/proc.h>
     86       1.1   thorpej #include <sys/conf.h>
     87       1.1   thorpej #include <sys/ioctl.h>
     88       1.1   thorpej 
     89       1.1   thorpej #include <machine/bus.h>
     90       1.1   thorpej 
     91       1.1   thorpej #include <dev/ic/icpreg.h>
     92       1.1   thorpej #include <dev/ic/icpvar.h>
     93       1.1   thorpej 
     94       1.1   thorpej /* These are simply the same as ICP's "iir" driver for FreeBSD. */
     95       1.1   thorpej #define	ICP_DRIVER_VERSION		1
     96       1.1   thorpej #define	ICP_DRIVER_SUBVERSION		3
     97       1.1   thorpej 
     98       1.1   thorpej static dev_type_open(icpopen);
     99       1.1   thorpej static dev_type_ioctl(icpioctl);
    100       1.1   thorpej 
    101       1.1   thorpej const struct cdevsw icp_cdevsw = {
    102       1.1   thorpej 	icpopen, nullclose, noread, nowrite, icpioctl,
    103      1.10  christos 	nostop, notty, nopoll, nommap, nokqfilter, D_OTHER,
    104       1.1   thorpej };
    105       1.1   thorpej 
    106       1.1   thorpej extern struct cfdriver icp_cd;
    107       1.1   thorpej 
    108       1.3   thorpej static struct lock icp_ioctl_mutex =
    109       1.3   thorpej     LOCK_INITIALIZER(PRIBIO|PCATCH, "icplk", 0, 0);
    110       1.3   thorpej 
    111       1.1   thorpej static int
    112  1.10.4.1      yamt icpopen(dev_t dev, int flag __unused, int mode __unused, struct lwp *l __unused)
    113       1.1   thorpej {
    114       1.1   thorpej 
    115       1.1   thorpej 	if (device_lookup(&icp_cd, minor(dev)) == NULL)
    116       1.1   thorpej 		return (ENXIO);
    117       1.1   thorpej 
    118       1.1   thorpej 	return (0);
    119       1.1   thorpej }
    120       1.1   thorpej 
    121       1.1   thorpej static int
    122  1.10.4.1      yamt icpioctl(dev_t dev, u_long cmd, caddr_t data, int flag __unused,
    123  1.10.4.1      yamt     struct lwp *l __unused)
    124       1.1   thorpej {
    125       1.3   thorpej 	int error;
    126       1.3   thorpej 
    127       1.3   thorpej 	if ((error = lockmgr(&icp_ioctl_mutex, LK_EXCLUSIVE, NULL)) != 0)
    128       1.3   thorpej 		return (error);
    129       1.1   thorpej 
    130       1.1   thorpej 	switch (cmd) {
    131       1.1   thorpej 	case GDT_IOCTL_GENERAL:
    132       1.1   thorpej 	    {
    133       1.1   thorpej 		struct icp_softc *icp;
    134       1.1   thorpej 		gdt_ucmd_t *ucmd = (void *) data;
    135       1.1   thorpej 
    136       1.9  christos 		if (securelevel > 1)
    137       1.9  christos 			return (EPERM);
    138       1.9  christos 
    139       1.1   thorpej 		icp = device_lookup(&icp_cd, ucmd->io_node);
    140       1.3   thorpej 		if (icp == NULL) {
    141       1.3   thorpej 			error = ENXIO;
    142       1.3   thorpej 			break;
    143       1.3   thorpej 		}
    144       1.1   thorpej 
    145       1.1   thorpej 		error = icp_ucmd(icp, ucmd);
    146       1.1   thorpej 		break;
    147       1.1   thorpej 	    }
    148       1.1   thorpej 
    149       1.1   thorpej 	case GDT_IOCTL_DRVERS:
    150       1.1   thorpej 		*(int *) data =
    151       1.1   thorpej 		    (ICP_DRIVER_VERSION << 8) | ICP_DRIVER_SUBVERSION;
    152       1.1   thorpej 		break;
    153       1.1   thorpej 
    154       1.1   thorpej 	case GDT_IOCTL_CTRTYPE:
    155       1.1   thorpej 	    {
    156       1.1   thorpej 		struct icp_softc *icp;
    157       1.7  christos 		gdt_ctrt_t *ctrt = (void *) data;
    158       1.1   thorpej 
    159       1.7  christos 		icp = device_lookup(&icp_cd, ctrt->io_node);
    160       1.3   thorpej 		if (icp == NULL) {
    161       1.3   thorpej 			error = ENXIO;
    162       1.3   thorpej 			break;
    163       1.3   thorpej 		}
    164       1.1   thorpej 
    165       1.1   thorpej 		/* XXX magic numbers */
    166       1.7  christos 		ctrt->oem_id = 0x8000;
    167       1.7  christos 		ctrt->type = 0xfd;
    168       1.7  christos 		ctrt->info = (icp->icp_pci_bus << 8) | (icp->icp_pci_device << 3);
    169       1.7  christos 		ctrt->ext_type = 0x6000 | icp->icp_pci_subdevice_id;
    170       1.7  christos 		ctrt->device_id = icp->icp_pci_device_id;
    171       1.7  christos 		ctrt->sub_device_id = icp->icp_pci_subdevice_id;
    172       1.1   thorpej 		break;
    173       1.1   thorpej 	    }
    174       1.1   thorpej 
    175       1.1   thorpej 	case GDT_IOCTL_OSVERS:
    176       1.1   thorpej 	    {
    177       1.7  christos 		gdt_osv_t *osv = (void *) data;
    178       1.1   thorpej 
    179       1.7  christos 		osv->oscode = 12;
    180       1.1   thorpej 
    181       1.1   thorpej 		/*
    182       1.1   thorpej 		 * __NetBSD_Version__ is encoded thusly:
    183       1.1   thorpej 		 *
    184       1.1   thorpej 		 *	MMmmrrpp00
    185       1.1   thorpej 		 *
    186       1.1   thorpej 		 * M = major version
    187       1.1   thorpej 		 * m = minor version
    188       1.1   thorpej 		 * r = release ["",A-Z[A-Z] but numeric]
    189       1.1   thorpej 		 * p = patchlevel
    190       1.1   thorpej 		 *
    191       1.1   thorpej 		 * Since the ABI is not supposed to change between
    192       1.1   thorpej 		 * patchlevels of the same major/minor version, we
    193       1.1   thorpej 		 * will encode major/minor/release into the returned
    194       1.1   thorpej 		 * data.
    195       1.1   thorpej 		 */
    196       1.1   thorpej 
    197       1.7  christos 		osv->version = __NetBSD_Version__ / 100000000;
    198       1.7  christos 		osv->subversion = (__NetBSD_Version__ / 1000000) % 100;
    199       1.7  christos 		osv->revision = (__NetBSD_Version__ / 10000) % 100;
    200       1.1   thorpej 
    201       1.7  christos 		strcpy(osv->name, ostype);
    202       1.1   thorpej 		break;
    203       1.1   thorpej 	    }
    204       1.1   thorpej 
    205       1.1   thorpej 	case GDT_IOCTL_CTRCNT:
    206       1.1   thorpej 		*(int *) data = icp_count;
    207       1.1   thorpej 		break;
    208       1.1   thorpej 
    209       1.1   thorpej 	case GDT_IOCTL_EVENT:
    210       1.1   thorpej 	    {
    211       1.1   thorpej 		struct icp_softc *icp;
    212       1.7  christos 		gdt_event_t *evt = (void *) data;
    213       1.7  christos 		gdt_evt_str *e = &evt->dvr;
    214       1.1   thorpej 		int s;
    215       1.1   thorpej 
    216       1.1   thorpej 		icp = device_lookup(&icp_cd, minor(dev));
    217       1.1   thorpej 
    218       1.7  christos 		switch (evt->erase) {
    219       1.1   thorpej 		case 0xff:
    220       1.7  christos 			switch (evt->dvr.event_source) {
    221       1.1   thorpej 			case GDT_ES_TEST:
    222       1.1   thorpej 				e->event_data.size =
    223       1.1   thorpej 				    sizeof(e->event_data.eu.test);
    224       1.1   thorpej 				break;
    225       1.1   thorpej 
    226       1.1   thorpej 			case GDT_ES_DRIVER:
    227       1.1   thorpej 				e->event_data.size =
    228       1.1   thorpej 				    sizeof(e->event_data.eu.driver);
    229       1.1   thorpej 				break;
    230       1.1   thorpej 
    231       1.1   thorpej 			case GDT_ES_SYNC:
    232       1.1   thorpej 				e->event_data.size =
    233       1.1   thorpej 				    sizeof(e->event_data.eu.sync);
    234       1.1   thorpej 				break;
    235       1.1   thorpej 
    236       1.1   thorpej 			default:
    237       1.1   thorpej 				e->event_data.size =
    238       1.1   thorpej 				    sizeof(e->event_data.eu.async);
    239       1.1   thorpej 				break;
    240       1.1   thorpej 			}
    241       1.1   thorpej 			s = splbio();
    242       1.1   thorpej 			icp_store_event(icp, e->event_source, e->event_idx,
    243       1.1   thorpej 			    &e->event_data);
    244       1.1   thorpej 			splx(s);
    245       1.1   thorpej 			break;
    246       1.1   thorpej 
    247       1.1   thorpej 		case 0xfe:
    248       1.1   thorpej 			s = splbio();
    249       1.1   thorpej 			icp_clear_events(icp);
    250       1.1   thorpej 			splx(s);
    251       1.1   thorpej 			break;
    252       1.1   thorpej 
    253       1.1   thorpej 		case 0:
    254       1.7  christos 			evt->handle = icp_read_event(icp, evt->handle, e);
    255       1.1   thorpej 			break;
    256       1.1   thorpej 
    257       1.1   thorpej 		default:
    258       1.7  christos 			icp_readapp_event(icp, (u_int8_t) evt->erase, e);
    259       1.1   thorpej 			break;
    260       1.1   thorpej 		}
    261       1.1   thorpej 		break;
    262       1.1   thorpej 	    }
    263       1.1   thorpej 
    264       1.1   thorpej 	case GDT_IOCTL_STATIST:
    265       1.1   thorpej 		memcpy(&icp_stats, data, sizeof(gdt_statist_t));
    266       1.1   thorpej 		break;
    267       1.1   thorpej 
    268       1.3   thorpej 
    269       1.3   thorpej 	case GDT_IOCTL_RESCAN:
    270       1.3   thorpej 	    {
    271       1.3   thorpej 		struct icp_softc *icp;
    272       1.3   thorpej 		gdt_rescan_t *rsc = (void *) data;
    273       1.3   thorpej 
    274       1.3   thorpej 		icp = device_lookup(&icp_cd, rsc->io_node);
    275       1.3   thorpej 		if (icp == NULL) {
    276       1.3   thorpej 			error = ENXIO;
    277       1.3   thorpej 			break;
    278       1.3   thorpej 		}
    279       1.3   thorpej 
    280       1.3   thorpej 		error = icp_freeze(icp);
    281       1.3   thorpej 		if (error)
    282       1.3   thorpej 			break;
    283       1.3   thorpej 		if (rsc->flag == 0)
    284       1.3   thorpej 			icp_rescan_all(icp);
    285       1.3   thorpej 		else
    286       1.3   thorpej 			icp_rescan(icp, rsc->hdr_no);
    287       1.3   thorpej 		icp_unfreeze(icp);
    288       1.3   thorpej 		break;
    289       1.3   thorpej 	    }
    290       1.3   thorpej 
    291       1.1   thorpej 	default:
    292       1.3   thorpej 		error = ENOTTY;
    293       1.1   thorpej 	}
    294       1.3   thorpej 
    295       1.3   thorpej 	(void) lockmgr(&icp_ioctl_mutex, LK_RELEASE, NULL);
    296       1.1   thorpej 
    297       1.1   thorpej 	return (error);
    298       1.1   thorpej }
    299