2 * Video spigot capture driver.
4 * Copyright (c) 1995, Jim Lowe. All rights reserved.
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.
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
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.
35 * The vendor will not allow me to release the spigot library code.
36 * Please don't ask me for it.
38 * To use this driver you will need the spigot library. The library is
41 * ftp.cs.uwm.edu://pub/FreeBSD-UWM/spigot/spigot.tar.gz
43 * Version 1.7, December 1995.
45 * $FreeBSD: src/sys/i386/isa/spigot.c,v 1.44 2000/01/29 16:17:36 peter Exp $
46 * $DragonFly: src/sys/dev/misc/spigot/spigot.c,v 1.9 2004/05/19 22:52:44 dillon Exp $
50 #include "use_spigot.h"
53 error "Can only have 1 spigot configured."
56 #include "opt_spigot.h"
58 #include <sys/param.h>
59 #include <sys/systm.h>
62 #include <sys/signalvar.h>
65 #include <machine/frame.h>
66 #include <machine/md_var.h>
67 #include <machine/spigot.h>
68 #include <machine/psl.h>
70 #include <bus/isa/i386/isa_device.h>
72 static struct spigot_softc {
78 } spigot_softc[NSPIGOT];
84 #define UNIT(dev) minor(dev)
86 static int spigot_probe(struct isa_device *id);
87 static int spigot_attach(struct isa_device *id);
89 struct isa_driver spigotdriver = {spigot_probe, spigot_attach, "spigot"};
91 static d_open_t spigot_open;
92 static d_close_t spigot_close;
93 static d_read_t spigot_read;
94 static d_write_t spigot_write;
95 static d_ioctl_t spigot_ioctl;
96 static d_mmap_t spigot_mmap;
99 static struct cdevsw spigot_cdevsw = {
101 /* maj */ CDEV_MAJOR,
106 /* open */ spigot_open,
107 /* close */ spigot_close,
108 /* read */ spigot_read,
109 /* write */ spigot_write,
110 /* ioctl */ spigot_ioctl,
112 /* mmap */ spigot_mmap,
113 /* strategy */ nostrategy,
118 static ointhand2_t spigintr;
121 spigot_probe(struct isa_device *devp)
123 struct spigot_softc *ss;
126 ss = (struct spigot_softc *)&spigot_softc[devp->id_unit];
131 if(devp->id_iobase != 0xad6 || inb(0xad9) == 0xff)
132 status = 0; /* not found */
134 status = 1; /* found */
142 spigot_attach(struct isa_device *devp)
145 struct spigot_softc *ss= &spigot_softc[unit = devp->id_unit];
147 devp->id_ointr = spigintr;
148 ss->maddr = kvtop(devp->id_maddr);
149 ss->irq = devp->id_irq;
150 cdevsw_add(&spigot_cdevsw, -1, unit);
151 make_dev(&spigot_cdevsw, unit, 0, 0, 0644, "spigot%d", unit);
156 spigot_open(dev_t dev, int flags, int fmt, struct thread *td)
159 struct spigot_softc *ss = (struct spigot_softc *)&spigot_softc[UNIT(dev)];
161 if((ss->flags & ALIVE) == 0)
167 #if !defined(SPIGOT_UNSECURE)
169 * Don't allow open() unless the process has sufficient privileges,
170 * since mapping the i/o page and granting i/o privilege would
171 * require sufficient privilege soon and nothing much can be done
189 spigot_close(dev_t dev, int flags, int fmt, struct thread *td)
191 struct spigot_softc *ss = (struct spigot_softc *)&spigot_softc[UNIT(dev)];
203 spigot_write(dev_t dev, struct uio *uio, int ioflag)
209 spigot_read(dev_t dev, struct uio *uio, int ioflag)
216 spigot_ioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
219 struct spigot_softc *ss = (struct spigot_softc *)&spigot_softc[UNIT(dev)];
220 struct spigot_info *info;
222 if(!data) return(EINVAL);
225 if (*(int *)data < 0 || *(int *)data > _SIG_MAXSIG)
228 ss->signal_num = *((int *)data);
230 case SPIGOT_IOPL_ON: /* allow access to the IO PAGE */
231 #if !defined(SPIGOT_UNSECURE)
238 td->td_proc->p_md.md_regs->tf_eflags |= PSL_IOPL;
240 case SPIGOT_IOPL_OFF: /* deny access to the IO PAGE */
241 td->td_proc->p_md.md_regs->tf_eflags &= ~PSL_IOPL;
243 case SPIGOT_GET_INFO:
244 info = (struct spigot_info *)data;
245 info->maddr = ss->maddr;
256 * Interrupt procedure.
257 * Just call a user level interrupt routine.
262 struct spigot_softc *ss = (struct spigot_softc *)&spigot_softc[unit];
264 if(ss->p && ss->signal_num)
265 psignal(ss->p, ss->signal_num);
269 spigot_mmap(dev_t dev, vm_offset_t offset, int nprot)
271 struct spigot_softc *ss = (struct spigot_softc *)&spigot_softc[0];
274 printf("spigot mmap failed, offset = 0x%x != 0x0\n", offset);
278 if(nprot & PROT_EXEC)
281 return i386_btop(ss->maddr);