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.16 2008/08/02 01:14:42 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>
61 #include <sys/device.h>
64 #include <sys/signalvar.h>
67 #include <machine/frame.h>
68 #include <machine/md_var.h>
69 #include <machine/spigot.h>
70 #include <machine/psl.h>
72 #include <bus/isa/isa_device.h>
74 static struct spigot_softc
{
80 } spigot_softc
[NSPIGOT
];
86 #define UNIT(dev) minor(dev)
88 static int spigot_probe(struct isa_device
*id
);
89 static int spigot_attach(struct isa_device
*id
);
91 struct isa_driver spigotdriver
= {spigot_probe
, spigot_attach
, "spigot"};
93 static d_open_t spigot_open
;
94 static d_close_t spigot_close
;
95 static d_read_t spigot_read
;
96 static d_write_t spigot_write
;
97 static d_ioctl_t spigot_ioctl
;
98 static d_mmap_t spigot_mmap
;
100 #define CDEV_MAJOR 11
101 static struct dev_ops spigot_ops
= {
102 { "spigot", CDEV_MAJOR
, 0 },
103 .d_open
= spigot_open
,
104 .d_close
= spigot_close
,
105 .d_read
= spigot_read
,
106 .d_write
= spigot_write
,
107 .d_ioctl
= spigot_ioctl
,
108 .d_mmap
= spigot_mmap
,
111 static void spigintr(void *);
114 spigot_probe(struct isa_device
*devp
)
116 struct spigot_softc
*ss
;
119 ss
= (struct spigot_softc
*)&spigot_softc
[devp
->id_unit
];
124 if(devp
->id_iobase
!= 0xad6 || inb(0xad9) == 0xff)
125 status
= 0; /* not found */
127 status
= 1; /* found */
135 spigot_attach(struct isa_device
*devp
)
138 struct spigot_softc
*ss
= &spigot_softc
[unit
= devp
->id_unit
];
140 devp
->id_intr
= (inthand2_t
*)spigintr
;
141 ss
->maddr
= kvtop(devp
->id_maddr
);
142 ss
->irq
= devp
->id_irq
;
143 dev_ops_add(&spigot_ops
, -1, unit
);
144 make_dev(&spigot_ops
, unit
, 0, 0, 0644, "spigot%d", unit
);
149 spigot_open(struct dev_open_args
*ap
)
151 cdev_t dev
= ap
->a_head
.a_dev
;
153 struct spigot_softc
*ss
;
155 ss
= (struct spigot_softc
*)&spigot_softc
[UNIT(dev
)];
157 if((ss
->flags
& ALIVE
) == 0)
163 #if !defined(SPIGOT_UNSECURE)
165 * Don't allow open() unless the process has sufficient privileges,
166 * since mapping the i/o page and granting i/o privilege would
167 * require sufficient privilege soon and nothing much can be done
170 error
= priv_check_cred(ap
->a_cred
, PRIV_ROOT
, 0);
185 spigot_close(struct dev_close_args
*ap
)
187 cdev_t dev
= ap
->a_head
.a_dev
;
188 struct spigot_softc
*ss
;
190 ss
= (struct spigot_softc
*)&spigot_softc
[UNIT(dev
)];
201 spigot_write(struct dev_write_args
*ap
)
207 spigot_read(struct dev_read_args
*ap
)
214 spigot_ioctl(struct dev_ioctl_args
*ap
)
216 cdev_t dev
= ap
->a_head
.a_dev
;
217 caddr_t data
= ap
->a_data
;
219 struct spigot_softc
*ss
;
220 struct spigot_info
*info
;
222 ss
= (struct spigot_softc
*)&spigot_softc
[UNIT(dev
)];
228 if (*(int *)data
< 0 || *(int *)data
> _SIG_MAXSIG
)
231 ss
->signal_num
= *((int *)data
);
233 case SPIGOT_IOPL_ON
: /* allow access to the IO PAGE */
234 #if !defined(SPIGOT_UNSECURE)
235 error
= priv_check_cred(ap
->a_cred
, PRIV_ROOT
, 0);
241 curthread
->td_lwp
->lwp_md
.md_regs
->tf_eflags
|= PSL_IOPL
;
243 case SPIGOT_IOPL_OFF
: /* deny access to the IO PAGE */
244 curthread
->td_lwp
->lwp_md
.md_regs
->tf_eflags
&= ~PSL_IOPL
;
246 case SPIGOT_GET_INFO
:
247 info
= (struct spigot_info
*)data
;
248 info
->maddr
= ss
->maddr
;
259 * Interrupt procedure.
260 * Just call a user level interrupt routine.
266 struct spigot_softc
*ss
;
268 ss
= (struct spigot_softc
*)&spigot_softc
[unit
];
269 if(ss
->p
&& ss
->signal_num
)
270 ksignal(ss
->p
, ss
->signal_num
);
274 spigot_mmap(struct dev_mmap_args
*ap
)
276 struct spigot_softc
*ss
;
278 ss
= (struct spigot_softc
*)&spigot_softc
[0];
279 if (ap
->a_offset
!= 0)
281 if (ap
->a_nprot
& PROT_EXEC
)
283 ap
->a_result
= i386_btop(ss
->maddr
);