1995-02-06 23:20:17 +00:00
|
|
|
/*
|
|
|
|
* Video spigot capture driver.
|
|
|
|
*
|
|
|
|
* Copyright (c) 1995, Jim Lowe. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer. 2.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1995-05-30 08:16:23 +00:00
|
|
|
* This is the minimum driver code required to make a spigot work.
|
1995-02-06 23:20:17 +00:00
|
|
|
* Unfortunatly, I can't include a real driver since the information
|
|
|
|
* on the spigot is under non-disclosure. You can pick up a library
|
1998-01-24 02:54:56 +00:00
|
|
|
* that will work with this driver from
|
|
|
|
* ftp://ftp.cs.uwm.edu/pub/FreeBSD-UWM. The library contains the
|
|
|
|
* source that I can release as well as several object modules and
|
|
|
|
* functions that allows one to read spigot data. See the code for
|
|
|
|
* spigot_grab.c that is included with the library data.
|
1995-02-06 23:20:17 +00:00
|
|
|
*
|
1995-09-01 00:25:18 +00:00
|
|
|
* The vendor will not allow me to release the spigot library code.
|
|
|
|
* Please don't ask me for it.
|
1995-02-06 23:20:17 +00:00
|
|
|
*
|
1995-09-01 00:25:18 +00:00
|
|
|
* To use this driver you will need the spigot library. The library is
|
|
|
|
* available from:
|
|
|
|
*
|
1998-01-24 02:54:56 +00:00
|
|
|
* ftp.cs.uwm.edu://pub/FreeBSD-UWM/spigot/spigot.tar.gz
|
1995-09-01 00:25:18 +00:00
|
|
|
*
|
1996-02-01 07:36:34 +00:00
|
|
|
* Version 1.7, December 1995.
|
1995-02-06 23:20:17 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-02 16:32:55 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1995-02-06 23:20:17 +00:00
|
|
|
#include "spigot.h"
|
|
|
|
|
|
|
|
#if NSPIGOT > 1
|
|
|
|
error "Can only have 1 spigot configured."
|
|
|
|
#endif
|
|
|
|
|
1998-08-08 19:26:08 +00:00
|
|
|
#include "opt_spigot.h"
|
1998-01-24 02:54:56 +00:00
|
|
|
|
1995-02-06 23:20:17 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/bus.h>
|
1995-12-06 23:52:35 +00:00
|
|
|
#include <sys/conf.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/mutex.h>
|
1995-02-06 23:20:17 +00:00
|
|
|
#include <sys/proc.h>
|
1995-12-06 23:52:35 +00:00
|
|
|
#include <sys/signalvar.h>
|
1995-02-06 23:20:17 +00:00
|
|
|
|
1995-12-06 23:52:35 +00:00
|
|
|
#include <machine/frame.h>
|
1996-06-25 20:31:01 +00:00
|
|
|
#include <machine/md_var.h>
|
1995-02-26 05:14:53 +00:00
|
|
|
#include <machine/spigot.h>
|
|
|
|
#include <machine/psl.h>
|
|
|
|
|
1995-02-06 23:20:17 +00:00
|
|
|
#include <i386/isa/isa_device.h>
|
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
static struct spigot_softc {
|
1995-09-01 00:25:18 +00:00
|
|
|
u_long flags;
|
|
|
|
u_long maddr;
|
1995-02-06 23:20:17 +00:00
|
|
|
struct proc *p;
|
1995-09-01 00:25:18 +00:00
|
|
|
u_long signal_num;
|
|
|
|
u_short irq;
|
1995-02-06 23:20:17 +00:00
|
|
|
} spigot_softc[NSPIGOT];
|
|
|
|
|
|
|
|
/* flags in softc */
|
1995-05-30 08:16:23 +00:00
|
|
|
#define OPEN 0x01
|
1995-08-01 07:07:42 +00:00
|
|
|
#define ALIVE 0x02
|
1995-02-06 23:20:17 +00:00
|
|
|
|
|
|
|
#define UNIT(dev) minor(dev)
|
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
static int spigot_probe(struct isa_device *id);
|
|
|
|
static int spigot_attach(struct isa_device *id);
|
1995-02-06 23:20:17 +00:00
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
struct isa_driver spigotdriver = {
|
|
|
|
INTR_TYPE_MISC,
|
|
|
|
spigot_probe,
|
|
|
|
spigot_attach,
|
|
|
|
"spigot"
|
|
|
|
};
|
|
|
|
COMPAT_ISA_DRIVER(spigot, spigotdriver);
|
1995-02-06 23:20:17 +00:00
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static d_open_t spigot_open;
|
|
|
|
static d_close_t spigot_close;
|
|
|
|
static d_read_t spigot_read;
|
|
|
|
static d_write_t spigot_write;
|
|
|
|
static d_ioctl_t spigot_ioctl;
|
|
|
|
static d_mmap_t spigot_mmap;
|
|
|
|
|
|
|
|
#define CDEV_MAJOR 11
|
1999-05-30 16:53:49 +00:00
|
|
|
static struct cdevsw spigot_cdevsw = {
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_open = spigot_open,
|
|
|
|
.d_close = spigot_close,
|
|
|
|
.d_read = spigot_read,
|
|
|
|
.d_write = spigot_write,
|
|
|
|
.d_ioctl = spigot_ioctl,
|
|
|
|
.d_mmap = spigot_mmap,
|
|
|
|
.d_name = "spigot",
|
|
|
|
.d_maj = CDEV_MAJOR,
|
1999-05-30 16:53:49 +00:00
|
|
|
};
|
1995-12-08 11:19:42 +00:00
|
|
|
|
1998-10-22 05:58:45 +00:00
|
|
|
static ointhand2_t spigintr;
|
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
static int
|
1995-05-30 08:16:23 +00:00
|
|
|
spigot_probe(struct isa_device *devp)
|
1995-02-06 23:20:17 +00:00
|
|
|
{
|
|
|
|
int status;
|
1995-08-01 07:07:42 +00:00
|
|
|
struct spigot_softc *ss=(struct spigot_softc *)&spigot_softc[devp->id_unit];
|
1995-02-06 23:20:17 +00:00
|
|
|
|
1995-08-01 07:07:42 +00:00
|
|
|
ss->flags = 0;
|
1995-09-01 00:25:18 +00:00
|
|
|
ss->maddr = 0;
|
|
|
|
ss->irq = 0;
|
1995-08-01 07:07:42 +00:00
|
|
|
|
|
|
|
if(devp->id_iobase != 0xad6 || inb(0xad9) == 0xff)
|
|
|
|
status = 0; /* not found */
|
|
|
|
else {
|
|
|
|
status = 1; /* found */
|
|
|
|
ss->flags |= ALIVE;
|
|
|
|
}
|
1995-02-06 23:20:17 +00:00
|
|
|
|
|
|
|
return(status);
|
|
|
|
}
|
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
static int
|
1995-02-06 23:20:17 +00:00
|
|
|
spigot_attach(struct isa_device *devp)
|
|
|
|
{
|
1995-12-08 11:19:42 +00:00
|
|
|
int unit;
|
|
|
|
struct spigot_softc *ss= &spigot_softc[unit = devp->id_unit];
|
1995-08-01 07:07:42 +00:00
|
|
|
|
1998-10-22 05:58:45 +00:00
|
|
|
devp->id_ointr = spigintr;
|
1995-09-01 00:25:18 +00:00
|
|
|
ss->maddr = kvtop(devp->id_maddr);
|
|
|
|
ss->irq = devp->id_irq;
|
1999-08-23 20:59:21 +00:00
|
|
|
make_dev(&spigot_cdevsw, unit, 0, 0, 0644, "spigot%d", unit);
|
1995-02-06 23:20:17 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
spigot_open(dev_t dev, int flags, int fmt, struct thread *td)
|
1995-02-06 23:20:17 +00:00
|
|
|
{
|
1997-04-14 15:54:39 +00:00
|
|
|
int error;
|
1995-02-06 23:20:17 +00:00
|
|
|
struct spigot_softc *ss = (struct spigot_softc *)&spigot_softc[UNIT(dev)];
|
|
|
|
|
1995-08-01 07:07:42 +00:00
|
|
|
if((ss->flags & ALIVE) == 0)
|
|
|
|
return ENXIO;
|
1995-02-06 23:20:17 +00:00
|
|
|
|
|
|
|
if(ss->flags & OPEN)
|
|
|
|
return EBUSY;
|
1995-08-01 07:07:42 +00:00
|
|
|
|
1996-02-01 07:36:34 +00:00
|
|
|
#if !defined(SPIGOT_UNSECURE)
|
1997-04-14 15:54:39 +00:00
|
|
|
/*
|
|
|
|
* Don't allow open() unless the process has sufficient privileges,
|
|
|
|
* since mapping the i/o page and granting i/o privilege would
|
|
|
|
* require sufficient privilege soon and nothing much can be done
|
|
|
|
* without them.
|
|
|
|
*/
|
2002-04-01 21:31:13 +00:00
|
|
|
error = suser(td);
|
1997-04-14 15:54:39 +00:00
|
|
|
if (error != 0)
|
|
|
|
return error;
|
2002-02-27 18:32:23 +00:00
|
|
|
error = securelevel_gt(td->td_ucred, 0);
|
2001-09-26 20:20:05 +00:00
|
|
|
if (error != 0)
|
|
|
|
return error;
|
1996-02-01 07:36:34 +00:00
|
|
|
#endif
|
|
|
|
|
1995-02-06 23:20:17 +00:00
|
|
|
ss->flags |= OPEN;
|
|
|
|
ss->p = 0;
|
|
|
|
ss->signal_num = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
spigot_close(dev_t dev, int flags, int fmt, struct thread *td)
|
1995-02-06 23:20:17 +00:00
|
|
|
{
|
|
|
|
struct spigot_softc *ss = (struct spigot_softc *)&spigot_softc[UNIT(dev)];
|
|
|
|
|
|
|
|
ss->flags &= ~OPEN;
|
|
|
|
ss->p = 0;
|
|
|
|
ss->signal_num = 0;
|
|
|
|
|
|
|
|
outb(0xad6, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1995-02-06 23:20:17 +00:00
|
|
|
spigot_write(dev_t dev, struct uio *uio, int ioflag)
|
|
|
|
{
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1995-02-06 23:20:17 +00:00
|
|
|
spigot_read(dev_t dev, struct uio *uio, int ioflag)
|
|
|
|
{
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
spigot_ioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
|
1995-02-06 23:20:17 +00:00
|
|
|
{
|
1995-10-14 07:09:58 +00:00
|
|
|
int error;
|
1995-02-06 23:20:17 +00:00
|
|
|
struct spigot_softc *ss = (struct spigot_softc *)&spigot_softc[UNIT(dev)];
|
1995-09-01 00:25:18 +00:00
|
|
|
struct spigot_info *info;
|
1995-02-06 23:20:17 +00:00
|
|
|
|
1995-09-01 00:25:18 +00:00
|
|
|
if(!data) return(EINVAL);
|
1995-02-06 23:20:17 +00:00
|
|
|
switch(cmd){
|
|
|
|
case SPIGOT_SETINT:
|
2001-09-12 08:38:13 +00:00
|
|
|
ss->p = td->td_proc;
|
1995-02-06 23:20:17 +00:00
|
|
|
ss->signal_num = *((int *)data);
|
|
|
|
break;
|
|
|
|
case SPIGOT_IOPL_ON: /* allow access to the IO PAGE */
|
1995-11-29 01:07:59 +00:00
|
|
|
#if !defined(SPIGOT_UNSECURE)
|
2002-04-01 21:31:13 +00:00
|
|
|
error = suser(td);
|
1995-10-14 07:09:58 +00:00
|
|
|
if (error != 0)
|
|
|
|
return error;
|
2002-02-27 18:32:23 +00:00
|
|
|
error = securelevel_gt(td->td_ucred, 0);
|
2001-09-26 20:20:05 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
1995-11-29 01:07:59 +00:00
|
|
|
#endif
|
2001-09-12 08:38:13 +00:00
|
|
|
td->td_frame->tf_eflags |= PSL_IOPL;
|
1995-02-06 23:20:17 +00:00
|
|
|
break;
|
|
|
|
case SPIGOT_IOPL_OFF: /* deny access to the IO PAGE */
|
2001-09-12 08:38:13 +00:00
|
|
|
td->td_frame->tf_eflags &= ~PSL_IOPL;
|
1995-02-06 23:20:17 +00:00
|
|
|
break;
|
1995-09-01 00:25:18 +00:00
|
|
|
case SPIGOT_GET_INFO:
|
|
|
|
info = (struct spigot_info *)data;
|
|
|
|
info->maddr = ss->maddr;
|
|
|
|
info->irq = ss->irq;
|
|
|
|
break;
|
1995-02-06 23:20:17 +00:00
|
|
|
default:
|
|
|
|
return ENOTTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interrupt procedure.
|
|
|
|
* Just call a user level interrupt routine.
|
|
|
|
*/
|
1998-10-22 05:58:45 +00:00
|
|
|
static void
|
1995-02-06 23:20:17 +00:00
|
|
|
spigintr(int unit)
|
|
|
|
{
|
|
|
|
struct spigot_softc *ss = (struct spigot_softc *)&spigot_softc[unit];
|
|
|
|
|
2001-03-07 03:37:06 +00:00
|
|
|
if(ss->p && ss->signal_num) {
|
|
|
|
PROC_LOCK(ss->p);
|
1995-02-06 23:20:17 +00:00
|
|
|
psignal(ss->p, ss->signal_num);
|
2001-03-07 03:37:06 +00:00
|
|
|
PROC_UNLOCK(ss->p);
|
|
|
|
}
|
1995-02-06 23:20:17 +00:00
|
|
|
}
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
2003-03-25 00:07:06 +00:00
|
|
|
spigot_mmap(dev_t dev, vm_offset_t offset, vm_paddr_t *paddr, int nprot)
|
1995-02-06 23:20:17 +00:00
|
|
|
{
|
|
|
|
struct spigot_softc *ss = (struct spigot_softc *)&spigot_softc[0];
|
|
|
|
|
1995-08-01 07:07:42 +00:00
|
|
|
if(offset != 0) {
|
1995-09-01 00:25:18 +00:00
|
|
|
printf("spigot mmap failed, offset = 0x%x != 0x0\n", offset);
|
1995-08-29 16:44:46 +00:00
|
|
|
return -1;
|
1995-08-01 07:07:42 +00:00
|
|
|
}
|
1995-02-06 23:20:17 +00:00
|
|
|
|
|
|
|
if(nprot & PROT_EXEC)
|
1995-08-29 16:44:46 +00:00
|
|
|
return -1;
|
1995-02-06 23:20:17 +00:00
|
|
|
|
2003-02-25 03:21:22 +00:00
|
|
|
*paddr = ss->maddr;
|
|
|
|
return 0;
|
1995-02-06 23:20:17 +00:00
|
|
|
}
|