]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/i386/isa/spigot.c
This commit was generated by cvs2svn to compensate for changes in r74481,
[FreeBSD/FreeBSD.git] / 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
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$
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/kernel.h>
60 #include        <sys/conf.h>
61 #include        <sys/proc.h>
62 #include        <sys/signalvar.h>
63 #include        <sys/mman.h>
64 #include        <sys/bus.h>
65
66 #include        <machine/frame.h>
67 #include        <machine/md_var.h>
68 #include        <machine/spigot.h>
69 #include        <machine/psl.h>
70
71 #include        <i386/isa/isa_device.h>
72
73 static struct spigot_softc {
74         u_long          flags;
75         u_long          maddr;
76         struct proc     *p;
77         u_long          signal_num;
78         u_short         irq;
79 } spigot_softc[NSPIGOT];
80
81 /* flags in softc */
82 #define OPEN            0x01
83 #define ALIVE           0x02
84
85 #define UNIT(dev) minor(dev)
86
87 static int      spigot_probe(struct isa_device *id);
88 static int      spigot_attach(struct isa_device *id);
89
90 struct isa_driver       spigotdriver = {
91         INTR_TYPE_MISC,
92         spigot_probe,
93         spigot_attach,
94         "spigot"
95 };
96 COMPAT_ISA_DRIVER(spigot, spigotdriver);
97
98 static  d_open_t        spigot_open;
99 static  d_close_t       spigot_close;
100 static  d_read_t        spigot_read;
101 static  d_write_t       spigot_write;
102 static  d_ioctl_t       spigot_ioctl;
103 static  d_mmap_t        spigot_mmap;
104
105 #define CDEV_MAJOR 11
106 static struct cdevsw spigot_cdevsw = {
107         /* open */      spigot_open,
108         /* close */     spigot_close,
109         /* read */      spigot_read,
110         /* write */     spigot_write,
111         /* ioctl */     spigot_ioctl,
112         /* poll */      nopoll,
113         /* mmap */      spigot_mmap,
114         /* strategy */  nostrategy,
115         /* name */      "spigot",
116         /* maj */       CDEV_MAJOR,
117         /* dump */      nodump,
118         /* psize */     nopsize,
119         /* flags */     0,
120         /* bmaj */      -1
121 };
122
123 static ointhand2_t      spigintr;
124
125 static int
126 spigot_probe(struct isa_device *devp)
127 {
128 int                     status;
129 struct  spigot_softc    *ss=(struct spigot_softc *)&spigot_softc[devp->id_unit];
130 static int once;
131
132         if (!once++)
133                 cdevsw_add(&spigot_cdevsw);
134
135         ss->flags = 0;
136         ss->maddr = 0;
137         ss->irq = 0;
138
139         if(devp->id_iobase != 0xad6 || inb(0xad9) == 0xff) 
140                 status = 0;     /* not found */
141         else {
142                 status = 1;     /* found */
143                 ss->flags |= ALIVE;
144         }
145
146         return(status);
147 }
148
149 static int
150 spigot_attach(struct isa_device *devp)
151 {
152         int     unit;
153         struct  spigot_softc    *ss= &spigot_softc[unit = devp->id_unit];
154
155         devp->id_ointr = spigintr;
156         ss->maddr = kvtop(devp->id_maddr);
157         ss->irq = devp->id_irq;
158         make_dev(&spigot_cdevsw, unit, 0, 0, 0644, "spigot%d", unit);
159         return 1;
160 }
161
162 static  int
163 spigot_open(dev_t dev, int flags, int fmt, struct proc *p)
164 {
165 int                     error;
166 struct  spigot_softc    *ss = (struct spigot_softc *)&spigot_softc[UNIT(dev)];
167
168         if((ss->flags & ALIVE) == 0)
169                 return ENXIO;
170
171         if(ss->flags & OPEN)
172                 return EBUSY;
173
174 #if !defined(SPIGOT_UNSECURE)
175         /*
176          * Don't allow open() unless the process has sufficient privileges,
177          * since mapping the i/o page and granting i/o privilege would
178          * require sufficient privilege soon and nothing much can be done
179          * without them.
180          */
181         error = suser(p);
182         if (error != 0)
183                 return error;
184         if (securelevel > 0)
185                 return EPERM;
186 #endif
187
188         ss->flags |= OPEN;
189         ss->p = 0;
190         ss->signal_num = 0;
191
192         return 0;
193 }
194
195 static  int
196 spigot_close(dev_t dev, int flags, int fmt, struct proc *p)
197 {
198 struct  spigot_softc    *ss = (struct spigot_softc *)&spigot_softc[UNIT(dev)];
199
200         ss->flags &= ~OPEN;
201         ss->p = 0;
202         ss->signal_num = 0;
203
204         outb(0xad6, 0);
205
206         return 0;
207 }
208
209 static  int
210 spigot_write(dev_t dev, struct uio *uio, int ioflag)
211 {
212         return ENXIO;
213 }
214
215 static  int
216 spigot_read(dev_t dev, struct uio *uio, int ioflag)
217 {
218         return ENXIO;
219 }
220
221
222 static  int
223 spigot_ioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
224 {
225 int                     error;
226 struct  spigot_softc    *ss = (struct spigot_softc *)&spigot_softc[UNIT(dev)];
227 struct  spigot_info     *info;
228
229         if(!data) return(EINVAL);
230         switch(cmd){
231         case    SPIGOT_SETINT:
232                 ss->p = p;
233                 ss->signal_num = *((int *)data);
234                 break;
235         case    SPIGOT_IOPL_ON: /* allow access to the IO PAGE */
236 #if !defined(SPIGOT_UNSECURE)
237                 error = suser(p);
238                 if (error != 0)
239                         return error;
240                 if (securelevel > 0)
241                         return EPERM;
242 #endif
243                 p->p_md.md_regs->tf_eflags |= PSL_IOPL;
244                 break;
245         case    SPIGOT_IOPL_OFF: /* deny access to the IO PAGE */
246                 p->p_md.md_regs->tf_eflags &= ~PSL_IOPL;
247                 break;
248         case    SPIGOT_GET_INFO:
249                 info = (struct spigot_info *)data;
250                 info->maddr  = ss->maddr;
251                 info->irq = ss->irq;
252                 break;
253         default:
254                 return ENOTTY;
255         }
256
257         return 0;
258 }
259
260 /*
261  * Interrupt procedure.
262  * Just call a user level interrupt routine.
263  */
264 static void
265 spigintr(int unit)
266 {
267 struct  spigot_softc    *ss = (struct spigot_softc *)&spigot_softc[unit];
268
269         if(ss->p && ss->signal_num) {
270                 PROC_LOCK(ss->p);
271                 psignal(ss->p, ss->signal_num);
272                 PROC_UNLOCK(ss->p);
273         }
274 }
275
276 static  int
277 spigot_mmap(dev_t dev, vm_offset_t offset, int nprot)
278 {
279 struct  spigot_softc    *ss = (struct spigot_softc *)&spigot_softc[0];
280
281         if(offset != 0) {
282                 printf("spigot mmap failed, offset = 0x%x != 0x0\n", offset);
283                 return -1;
284         }
285
286         if(nprot & PROT_EXEC)
287                 return -1;
288
289         return i386_btop(ss->maddr);
290 }