FreeBSD/Linux Kernel Cross Reference
sys/i386/isa/spigot.c
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 ftp://ftp.cs.uwm.edu/pub/FreeBSD.
30 * The library contains the source that I can release as well as several
31 * object modules and functions that allows one to read spigot data.
32 * See the code for spigot_grab.c that is included with the library
33 * 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/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 <sys/param.h>
55 #include <sys/systm.h>
56 #include <sys/kernel.h>
57 #include <sys/conf.h>
58 #include <sys/ioctl.h>
59 #include <sys/proc.h>
60 #include <sys/signalvar.h>
61 #include <sys/file.h>
62 #include <sys/uio.h>
63 #include <sys/malloc.h>
64 #include <sys/errno.h>
65 #include <sys/mman.h>
66 #ifdef DEVFS
67 #include <sys/devfsext.h>
68 #endif /* DEVFS */
69
70 #include <machine/frame.h>
71 #include <machine/md_var.h>
72 #include <machine/spigot.h>
73 #include <machine/psl.h>
74
75 #include <i386/isa/isa_device.h>
76
77 static struct spigot_softc {
78 u_long flags;
79 u_long maddr;
80 struct proc *p;
81 u_long signal_num;
82 u_short irq;
83 #ifdef DEVFS
84 void *devfs_token;
85 #endif
86 } spigot_softc[NSPIGOT];
87
88 /* flags in softc */
89 #define OPEN 0x01
90 #define ALIVE 0x02
91
92 #define UNIT(dev) minor(dev)
93
94 static int spigot_probe(struct isa_device *id);
95 static int spigot_attach(struct isa_device *id);
96
97 struct isa_driver spigotdriver = {spigot_probe, spigot_attach, "spigot"};
98
99 static d_open_t spigot_open;
100 static d_close_t spigot_close;
101 static d_read_t spigot_read;
102 static d_write_t spigot_write;
103 static d_ioctl_t spigot_ioctl;
104 static d_select_t spigot_select;
105 static d_mmap_t spigot_mmap;
106
107 #define CDEV_MAJOR 11
108 static struct cdevsw spigot_cdevsw =
109 { spigot_open, spigot_close, spigot_read, spigot_write, /*11*/
110 spigot_ioctl, nostop, nullreset, nodevtotty,/* Spigot */
111 spigot_select, spigot_mmap, NULL, "spigot", NULL, -1 };
112
113 static int
114 spigot_probe(struct isa_device *devp)
115 {
116 int status;
117 struct spigot_softc *ss=(struct spigot_softc *)&spigot_softc[devp->id_unit];
118
119 ss->flags = 0;
120 ss->maddr = 0;
121 ss->irq = 0;
122
123 if(devp->id_iobase != 0xad6 || inb(0xad9) == 0xff)
124 status = 0; /* not found */
125 else {
126 status = 1; /* found */
127 ss->flags |= ALIVE;
128 }
129
130 return(status);
131 }
132
133 static int
134 spigot_attach(struct isa_device *devp)
135 {
136 int unit;
137 struct spigot_softc *ss= &spigot_softc[unit = devp->id_unit];
138
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 struct spigot_softc *ss = (struct spigot_softc *)&spigot_softc[UNIT(dev)];
154
155 if((ss->flags & ALIVE) == 0)
156 return ENXIO;
157
158 if(ss->flags & OPEN)
159 return EBUSY;
160
161 #if !defined(SPIGOT_UNSECURE)
162 /* Since we can't map the i/o page, don't allow open unless suser */
163 if(suser(p->p_ucred, &p->p_acflag) != 0)
164 return EPERM;
165 #endif
166
167 ss->flags |= OPEN;
168 ss->p = 0;
169 ss->signal_num = 0;
170
171 return 0;
172 }
173
174 static int
175 spigot_close(dev_t dev, int flags, int fmt, struct proc *p)
176 {
177 struct spigot_softc *ss = (struct spigot_softc *)&spigot_softc[UNIT(dev)];
178
179 ss->flags &= ~OPEN;
180 ss->p = 0;
181 ss->signal_num = 0;
182
183 outb(0xad6, 0);
184
185 return 0;
186 }
187
188 static int
189 spigot_write(dev_t dev, struct uio *uio, int ioflag)
190 {
191 return ENXIO;
192 }
193
194 static int
195 spigot_read(dev_t dev, struct uio *uio, int ioflag)
196 {
197 return ENXIO;
198 }
199
200
201 static int
202 spigot_ioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
203 {
204 int error;
205 struct spigot_softc *ss = (struct spigot_softc *)&spigot_softc[UNIT(dev)];
206 struct trapframe *fp;
207 struct spigot_info *info;
208
209 if(!data) return(EINVAL);
210 switch(cmd){
211 case SPIGOT_SETINT:
212 ss->p = p;
213 ss->signal_num = *((int *)data);
214 break;
215 case SPIGOT_IOPL_ON: /* allow access to the IO PAGE */
216 #if !defined(SPIGOT_UNSECURE)
217 error = suser(p->p_ucred, &p->p_acflag);
218 if (error != 0)
219 return error;
220 #endif
221 fp=(struct trapframe *)p->p_md.md_regs;
222 fp->tf_eflags |= PSL_IOPL;
223 break;
224 case SPIGOT_IOPL_OFF: /* deny access to the IO PAGE */
225 fp=(struct trapframe *)p->p_md.md_regs;
226 fp->tf_eflags &= ~PSL_IOPL;
227 break;
228 case SPIGOT_GET_INFO:
229 info = (struct spigot_info *)data;
230 info->maddr = ss->maddr;
231 info->irq = ss->irq;
232 break;
233 default:
234 return ENOTTY;
235 }
236
237 return 0;
238 }
239
240 static int
241 spigot_select(dev_t dev, int rw, struct proc *p)
242 {
243
244 return ENXIO;
245 }
246
247 /*
248 * Interrupt procedure.
249 * Just call a user level interrupt routine.
250 */
251 void
252 spigintr(int unit)
253 {
254 struct spigot_softc *ss = (struct spigot_softc *)&spigot_softc[unit];
255
256 if(ss->p && ss->signal_num)
257 psignal(ss->p, ss->signal_num);
258 }
259
260 static int
261 spigot_mmap(dev_t dev, vm_offset_t offset, int nprot)
262 {
263 struct spigot_softc *ss = (struct spigot_softc *)&spigot_softc[0];
264
265 if(offset != 0) {
266 printf("spigot mmap failed, offset = 0x%x != 0x0\n", offset);
267 return -1;
268 }
269
270 if(nprot & PROT_EXEC)
271 return -1;
272
273 return i386_btop(ss->maddr);
274 }
275
276
277 static spigot_devsw_installed = 0;
278
279 static void spigot_drvinit(void *unused)
280 {
281 dev_t dev;
282
283 if( ! spigot_devsw_installed ) {
284 dev = makedev(CDEV_MAJOR, 0);
285 cdevsw_add(&dev,&spigot_cdevsw, NULL);
286 spigot_devsw_installed = 1;
287 }
288 }
289
290 SYSINIT(spigotdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,spigot_drvinit,NULL)
291
292
293 #endif /* NSPIGOT */
Cache object: caaeafff36c8d15f05e83d65d39eda15
|