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-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
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  * $FreeBSD: releng/5.1/sys/i386/isa/spigot.c 118752 2003-08-10 23:17:49Z nectar $
   46  *
   47  */
   48 
   49 #include        "spigot.h"
   50 
   51 #if NSPIGOT > 1
   52 error "Can only have 1 spigot configured."
   53 #endif
   54 
   55 #include        "opt_spigot.h"
   56 
   57 #include        <sys/param.h>
   58 #include        <sys/systm.h>
   59 #include        <sys/bus.h>
   60 #include        <sys/conf.h>
   61 #include        <sys/kernel.h>
   62 #include        <sys/lock.h>
   63 #include        <sys/mman.h>
   64 #include        <sys/mutex.h>
   65 #include        <sys/proc.h>
   66 #include        <sys/signalvar.h>
   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 } spigot_softc[NSPIGOT];
   82 
   83 /* flags in softc */
   84 #define OPEN            0x01
   85 #define ALIVE           0x02
   86 
   87 #define UNIT(dev) minor(dev)
   88 
   89 static int      spigot_probe(struct isa_device *id);
   90 static int      spigot_attach(struct isa_device *id);
   91 
   92 struct isa_driver       spigotdriver = {
   93         INTR_TYPE_MISC,
   94         spigot_probe,
   95         spigot_attach,
   96         "spigot"
   97 };
   98 COMPAT_ISA_DRIVER(spigot, spigotdriver);
   99 
  100 static  d_open_t        spigot_open;
  101 static  d_close_t       spigot_close;
  102 static  d_read_t        spigot_read;
  103 static  d_write_t       spigot_write;
  104 static  d_ioctl_t       spigot_ioctl;
  105 static  d_mmap_t        spigot_mmap;
  106 
  107 #define CDEV_MAJOR 11
  108 static struct cdevsw spigot_cdevsw = {
  109         .d_open =       spigot_open,
  110         .d_close =      spigot_close,
  111         .d_read =       spigot_read,
  112         .d_write =      spigot_write,
  113         .d_ioctl =      spigot_ioctl,
  114         .d_mmap =       spigot_mmap,
  115         .d_name =       "spigot",
  116         .d_maj =        CDEV_MAJOR,
  117 };
  118 
  119 static ointhand2_t      spigintr;
  120 
  121 static int
  122 spigot_probe(struct isa_device *devp)
  123 {
  124 int                     status;
  125 struct  spigot_softc    *ss=(struct spigot_softc *)&spigot_softc[devp->id_unit];
  126 
  127         ss->flags = 0;
  128         ss->maddr = 0;
  129         ss->irq = 0;
  130 
  131         if(devp->id_iobase != 0xad6 || inb(0xad9) == 0xff) 
  132                 status = 0;     /* not found */
  133         else {
  134                 status = 1;     /* found */
  135                 ss->flags |= ALIVE;
  136         }
  137 
  138         return(status);
  139 }
  140 
  141 static int
  142 spigot_attach(struct isa_device *devp)
  143 {
  144         int     unit;
  145         struct  spigot_softc    *ss= &spigot_softc[unit = devp->id_unit];
  146 
  147         devp->id_ointr = spigintr;
  148         ss->maddr = kvtop(devp->id_maddr);
  149         ss->irq = devp->id_irq;
  150         make_dev(&spigot_cdevsw, unit, 0, 0, 0644, "spigot%d", unit);
  151         return 1;
  152 }
  153 
  154 static  int
  155 spigot_open(dev_t dev, int flags, int fmt, struct thread *td)
  156 {
  157 int                     error;
  158 struct  spigot_softc    *ss = (struct spigot_softc *)&spigot_softc[UNIT(dev)];
  159 
  160         if((ss->flags & ALIVE) == 0)
  161                 return ENXIO;
  162 
  163         if(ss->flags & OPEN)
  164                 return EBUSY;
  165 
  166 #if !defined(SPIGOT_UNSECURE)
  167         /*
  168          * Don't allow open() unless the process has sufficient privileges,
  169          * since mapping the i/o page and granting i/o privilege would
  170          * require sufficient privilege soon and nothing much can be done
  171          * without them.
  172          */
  173         error = suser(td);
  174         if (error != 0)
  175                 return error;
  176         error = securelevel_gt(td->td_ucred, 0);
  177         if (error != 0)
  178                 return error;
  179 #endif
  180 
  181         ss->flags |= OPEN;
  182         ss->p = 0;
  183         ss->signal_num = 0;
  184 
  185         return 0;
  186 }
  187 
  188 static  int
  189 spigot_close(dev_t dev, int flags, int fmt, struct thread *td)
  190 {
  191 struct  spigot_softc    *ss = (struct spigot_softc *)&spigot_softc[UNIT(dev)];
  192 
  193         ss->flags &= ~OPEN;
  194         ss->p = 0;
  195         ss->signal_num = 0;
  196 
  197         outb(0xad6, 0);
  198 
  199         return 0;
  200 }
  201 
  202 static  int
  203 spigot_write(dev_t dev, struct uio *uio, int ioflag)
  204 {
  205         return ENXIO;
  206 }
  207 
  208 static  int
  209 spigot_read(dev_t dev, struct uio *uio, int ioflag)
  210 {
  211         return ENXIO;
  212 }
  213 
  214 
  215 static  int
  216 spigot_ioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
  217 {
  218 int                     error;
  219 struct  spigot_softc    *ss = (struct spigot_softc *)&spigot_softc[UNIT(dev)];
  220 struct  spigot_info     *info;
  221 
  222         if(!data) return(EINVAL);
  223         switch(cmd){
  224         case    SPIGOT_SETINT:
  225                 if (*(int *)data < 0 || *(int *)data > _SIG_MAXSIG)
  226                         return EINVAL;
  227                 ss->p = td->td_proc;
  228                 ss->signal_num = *((int *)data);
  229                 break;
  230         case    SPIGOT_IOPL_ON: /* allow access to the IO PAGE */
  231 #if !defined(SPIGOT_UNSECURE)
  232                 error = suser(td);
  233                 if (error != 0)
  234                         return error;
  235                 error = securelevel_gt(td->td_ucred, 0);
  236                 if (error)
  237                         return error;
  238 #endif
  239                 td->td_frame->tf_eflags |= PSL_IOPL;
  240                 break;
  241         case    SPIGOT_IOPL_OFF: /* deny access to the IO PAGE */
  242                 td->td_frame->tf_eflags &= ~PSL_IOPL;
  243                 break;
  244         case    SPIGOT_GET_INFO:
  245                 info = (struct spigot_info *)data;
  246                 info->maddr  = ss->maddr;
  247                 info->irq = ss->irq;
  248                 break;
  249         default:
  250                 return ENOTTY;
  251         }
  252 
  253         return 0;
  254 }
  255 
  256 /*
  257  * Interrupt procedure.
  258  * Just call a user level interrupt routine.
  259  */
  260 static void
  261 spigintr(int unit)
  262 {
  263 struct  spigot_softc    *ss = (struct spigot_softc *)&spigot_softc[unit];
  264 
  265         if(ss->p && ss->signal_num) {
  266                 PROC_LOCK(ss->p);
  267                 psignal(ss->p, ss->signal_num);
  268                 PROC_UNLOCK(ss->p);
  269         }
  270 }
  271 
  272 static  int
  273 spigot_mmap(dev_t dev, vm_offset_t offset, vm_paddr_t *paddr, int nprot)
  274 {
  275 struct  spigot_softc    *ss = (struct spigot_softc *)&spigot_softc[0];
  276 
  277         if(offset != 0) {
  278                 printf("spigot mmap failed, offset = 0x%x != 0x0\n", offset);
  279                 return -1;
  280         }
  281 
  282         if(nprot & PROT_EXEC)
  283                 return -1;
  284 
  285         *paddr = ss->maddr;
  286         return 0;
  287 }

Cache object: c7ae44789022a67cd22c5f55054467b9


[ 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.