The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/i386/isa/spigot.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Video spigot capture driver.
    3  *
    4  * Copyright (c) 1995, Jim Lowe.  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 are
    8  * met: 1. Redistributions of source code must retain the above copyright
    9  * notice, this list of conditions and the following disclaimer. 2.
   10  * Redistributions in binary form must reproduce the above copyright notice,
   11  * this list of conditions and the following disclaimer in the documentation
   12  * and/or other materials provided with the distribution.
   13  *
   14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
   15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   16  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   17  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
   18  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   20  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   21  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   24  * SUCH DAMAGE.
   25  *
   26  * This is the minimum driver code required to make a spigot work.
   27  * Unfortunatly, I can't include a real driver since the information
   28  * on the spigot is under non-disclosure.  You can pick up a library
   29  * that will work with this driver from
   30  * ftp://ftp.cs.uwm.edu/pub/FreeBSD-UWM.  The library contains the
   31  * source that I can release as well as several object modules and
   32  * functions that allows one to read spigot data.  See the code for
   33  * spigot_grab.c that is included with the library data.
   34  *
   35  * The vendor will not allow me to release the spigot library code.
   36  * Please don't ask me for it.
   37  *
   38  * To use this driver you will need the spigot library.  The library is
   39  * available from:
   40  *
   41  *      ftp.cs.uwm.edu://pub/FreeBSD-UWM/spigot/spigot.tar.gz
   42  *
   43  * Version 1.7, December 1995.
   44  *
   45  */
   46 
   47 #include        "spigot.h"
   48 #if NSPIGOT > 0
   49 
   50 #if NSPIGOT > 1
   51 error "Can only have 1 spigot configured."
   52 #endif
   53 
   54 #include        "opt_devfs.h"
   55 #include        "opt_spigot.h"
   56 
   57 #include        <sys/param.h>
   58 #include        <sys/systm.h>
   59 #include        <sys/kernel.h>
   60 #include        <sys/conf.h>
   61 #include        <sys/proc.h>
   62 #include        <sys/signalvar.h>
   63 #include        <sys/mman.h>
   64 #ifdef DEVFS
   65 #include        <sys/devfsext.h>
   66 #endif /* DEVFS */
   67 
   68 #include        <machine/frame.h>
   69 #include        <machine/md_var.h>
   70 #include        <machine/spigot.h>
   71 #include        <machine/psl.h>
   72 
   73 #include        <i386/isa/isa_device.h>
   74 
   75 static struct spigot_softc {
   76         u_long          flags;
   77         u_long          maddr;
   78         struct proc     *p;
   79         u_long          signal_num;
   80         u_short         irq;
   81 #ifdef  DEVFS
   82         void    *devfs_token;
   83 #endif
   84 } spigot_softc[NSPIGOT];
   85 
   86 /* flags in softc */
   87 #define OPEN            0x01
   88 #define ALIVE           0x02
   89 
   90 #define UNIT(dev) minor(dev)
   91 
   92 static int      spigot_probe(struct isa_device *id);
   93 static int      spigot_attach(struct isa_device *id);
   94 
   95 struct isa_driver       spigotdriver = {spigot_probe, spigot_attach, "spigot"};
   96 
   97 static  d_open_t        spigot_open;
   98 static  d_close_t       spigot_close;
   99 static  d_read_t        spigot_read;
  100 static  d_write_t       spigot_write;
  101 static  d_ioctl_t       spigot_ioctl;
  102 static  d_mmap_t        spigot_mmap;
  103 
  104 #define CDEV_MAJOR 11
  105 static struct cdevsw spigot_cdevsw = 
  106         { spigot_open,  spigot_close,   spigot_read,    spigot_write,   /*11*/
  107           spigot_ioctl, nostop,         nullreset,      nodevtotty,/* Spigot */
  108           seltrue,      spigot_mmap,    NULL,   "spigot",       NULL,   -1  };
  109 
  110 static ointhand2_t      spigintr;
  111 
  112 static int
  113 spigot_probe(struct isa_device *devp)
  114 {
  115 int                     status;
  116 struct  spigot_softc    *ss=(struct spigot_softc *)&spigot_softc[devp->id_unit];
  117 
  118         ss->flags = 0;
  119         ss->maddr = 0;
  120         ss->irq = 0;
  121 
  122         if(devp->id_iobase != 0xad6 || inb(0xad9) == 0xff) 
  123                 status = 0;     /* not found */
  124         else {
  125                 status = 1;     /* found */
  126                 ss->flags |= ALIVE;
  127         }
  128 
  129         return(status);
  130 }
  131 
  132 static int
  133 spigot_attach(struct isa_device *devp)
  134 {
  135         int     unit;
  136         struct  spigot_softc    *ss= &spigot_softc[unit = devp->id_unit];
  137 
  138         devp->id_ointr = spigintr;
  139         ss->maddr = kvtop(devp->id_maddr);
  140         ss->irq = devp->id_irq;
  141 #ifdef DEVFS
  142         ss->devfs_token = 
  143                 devfs_add_devswf(&spigot_cdevsw, unit, DV_CHR, 0, 0, 0644,
  144                                  "spigot%d", unit);
  145 #endif
  146 
  147         return 1;
  148 }
  149 
  150 static  int
  151 spigot_open(dev_t dev, int flags, int fmt, struct proc *p)
  152 {
  153 int                     error;
  154 struct  spigot_softc    *ss = (struct spigot_softc *)&spigot_softc[UNIT(dev)];
  155 
  156         if((ss->flags & ALIVE) == 0)
  157                 return ENXIO;
  158 
  159         if(ss->flags & OPEN)
  160                 return EBUSY;
  161 
  162 #if !defined(SPIGOT_UNSECURE)
  163         /*
  164          * Don't allow open() unless the process has sufficient privileges,
  165          * since mapping the i/o page and granting i/o privilege would
  166          * require sufficient privilege soon and nothing much can be done
  167          * without them.
  168          */
  169         error = suser(p->p_ucred, &p->p_acflag);
  170         if (error != 0)
  171                 return error;
  172         if (securelevel > 0)
  173                 return EPERM;
  174 #endif
  175 
  176         ss->flags |= OPEN;
  177         ss->p = 0;
  178         ss->signal_num = 0;
  179 
  180         return 0;
  181 }
  182 
  183 static  int
  184 spigot_close(dev_t dev, int flags, int fmt, struct proc *p)
  185 {
  186 struct  spigot_softc    *ss = (struct spigot_softc *)&spigot_softc[UNIT(dev)];
  187 
  188         ss->flags &= ~OPEN;
  189         ss->p = 0;
  190         ss->signal_num = 0;
  191 
  192         outb(0xad6, 0);
  193 
  194         return 0;
  195 }
  196 
  197 static  int
  198 spigot_write(dev_t dev, struct uio *uio, int ioflag)
  199 {
  200         return ENXIO;
  201 }
  202 
  203 static  int
  204 spigot_read(dev_t dev, struct uio *uio, int ioflag)
  205 {
  206         return ENXIO;
  207 }
  208 
  209 
  210 static  int
  211 spigot_ioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
  212 {
  213 int                     error;
  214 struct  spigot_softc    *ss = (struct spigot_softc *)&spigot_softc[UNIT(dev)];
  215 struct  spigot_info     *info;
  216 
  217         if(!data) return(EINVAL);
  218         switch(cmd){
  219         case    SPIGOT_SETINT:
  220                 ss->p = p;
  221                 ss->signal_num = *((int *)data);
  222                 break;
  223         case    SPIGOT_IOPL_ON: /* allow access to the IO PAGE */
  224 #if !defined(SPIGOT_UNSECURE)
  225                 error = suser(p->p_ucred, &p->p_acflag);
  226                 if (error != 0)
  227                         return error;
  228                 if (securelevel > 0)
  229                         return EPERM;
  230 #endif
  231                 p->p_md.md_regs->tf_eflags |= PSL_IOPL;
  232                 break;
  233         case    SPIGOT_IOPL_OFF: /* deny access to the IO PAGE */
  234                 p->p_md.md_regs->tf_eflags &= ~PSL_IOPL;
  235                 break;
  236         case    SPIGOT_GET_INFO:
  237                 info = (struct spigot_info *)data;
  238                 info->maddr  = ss->maddr;
  239                 info->irq = ss->irq;
  240                 break;
  241         default:
  242                 return ENOTTY;
  243         }
  244 
  245         return 0;
  246 }
  247 
  248 /*
  249  * Interrupt procedure.
  250  * Just call a user level interrupt routine.
  251  */
  252 static void
  253 spigintr(int unit)
  254 {
  255 struct  spigot_softc    *ss = (struct spigot_softc *)&spigot_softc[unit];
  256 
  257         if(ss->p && ss->signal_num)
  258                 psignal(ss->p, ss->signal_num);
  259 }
  260 
  261 static  int
  262 spigot_mmap(dev_t dev, vm_offset_t offset, int nprot)
  263 {
  264 struct  spigot_softc    *ss = (struct spigot_softc *)&spigot_softc[0];
  265 
  266         if(offset != 0) {
  267                 printf("spigot mmap failed, offset = 0x%x != 0x0\n", offset);
  268                 return -1;
  269         }
  270 
  271         if(nprot & PROT_EXEC)
  272                 return -1;
  273 
  274         return i386_btop(ss->maddr);
  275 }
  276 
  277 
  278 static spigot_devsw_installed = 0;
  279 
  280 static void     spigot_drvinit(void *unused)
  281 {
  282         dev_t dev;
  283 
  284         if( ! spigot_devsw_installed ) {
  285                 dev = makedev(CDEV_MAJOR, 0);
  286                 cdevsw_add(&dev,&spigot_cdevsw, NULL);
  287                 spigot_devsw_installed = 1;
  288         }
  289 }
  290 
  291 SYSINIT(spigotdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,spigot_drvinit,NULL)
  292 
  293 
  294 #endif /* NSPIGOT */

Cache object: de52b8908c70f56cb6ba79b30a8c8c81


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.