source: drsdaq/VME/struck/sis1100/V2.02/dev/pci/sis1100_open.c@ 23

Last change on this file since 23 was 22, checked in by ogrimm, 16 years ago
First commit of drsdaq program
File size: 5.7 KB
Line 
1/* $ZEL: sis1100_open.c,v 1.5 2004/02/10 16:29:44 wuestner Exp $ */
2
3/*
4 * Copyright (c) 2001-2004 Peter Wuestner. 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
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#include "sis1100_sc.h"
29
30static void
31_sis1100_open(struct sis1100_softc* sc, struct sis1100_fdata* fd, int idx)
32{
33 SEM_LOCK(sc->sem_fdata_list);
34 list_add(&fd->list, &sc->fdata_list_head);
35 SEM_UNLOCK(sc->sem_fdata_list);
36
37 fd->fifo_mode=0; /* can't be changed for sdram and sharc */
38 fd->vmespace_am=9; /* useless for sdram and sharc */
39 fd->vmespace_datasize=4; /* useless for sdram and sharc */
40 fd->last_prot_err=0;
41 fd->sig=0;
42 fd->owned_irqs=0; /* useless for sdram and sharc */
43 fd->mindmalen_r=24;
44 fd->mindmalen_w=400;
45 fd->mmapdma.valid=0;
46 sc->fdatalist[idx]=fd;
47}
48
49#ifdef __NetBSD__
50int
51sis1100_open(dev_t dev, int flag, int mode, struct proc *p)
52{
53 struct sis1100_softc* sc;
54 struct sis1100_fdata* fd;
55 unsigned int _minor=minor(dev);
56 unsigned int card=(_minor&sis1100_MINORCARDMASK)>>sis1100_MINORCARDSHIFT;
57 unsigned int subdev=(_minor&sis1100_MINORTYPEMASK)>>sis1100_MINORTYPESHIFT;
58 unsigned int idx=_minor&(sis1100_MINORUTMASK);
59
60 if (card >= sis1100cfdriver.cd_ndevs || !sis1100cfdriver.cd_devs[card]) {
61 pINFOsc("open: _minor=%d card=%d idx=%d, returning ENXIO",
62 _minor, card, idx);
63 return ENXIO;
64 }
65
66 sc=SIS1100SC(dev);
67
68 if (sc->fdatalist[idx])
69 return EBUSY;
70
71 fd=malloc(sizeof(struct sis1100_fdata), M_DEVBUF, M_WAITOK);
72 if (!fd) return ENOMEM;
73 fd->p=p;
74
75 fd->sig=0;
76 fd->subdev=subdev;
77
78 simple_lock(&sc->lock_sc_inuse);
79 sc->sc_inuse++;
80 simple_unlock(&sc->sc_inuse);
81
82 sc->fdatalist[idx]=fd;
83 _sis1100_open(sc, fd, idx);
84
85 return 0;
86}
87
88#elif __linux__
89
90int
91sis1100_open(struct inode *inode, struct file *file)
92{
93 struct sis1100_softc* sc;
94 struct sis1100_fdata* fd;
95 unsigned int _minor=iminor(inode);
96 unsigned int card=(_minor&sis1100_MINORCARDMASK)>>sis1100_MINORCARDSHIFT;
97 unsigned int subdev=(_minor&sis1100_MINORTYPEMASK)>>sis1100_MINORTYPESHIFT;
98 unsigned int idx=_minor&sis1100_MINORUTMASK;
99
100 if (card >= sis1100_MAXCARDS || !sis1100_devdata[card]) {
101 printk(KERN_INFO "sis1100 open: returning ENXIO\n");
102 return -ENXIO; /*ENODEV*/
103 }
104 sc=sis1100_devdata[card];
105
106 if (sc->fdatalist[idx]) {
107 return -EBUSY;
108 }
109
110 fd=kmalloc(sizeof(struct sis1100_fdata), GFP_KERNEL);
111 if (!fd) return -ENOMEM;
112 fd->sc=sc;
113 fd->subdev=subdev;
114 file->private_data = fd;
115
116 _sis1100_open(sc, fd, idx);
117
118 return 0;
119}
120#endif
121
122static void
123_sis1100_close(struct sis1100_softc* sc, struct sis1100_fdata* fd, int idx)
124{
125 u_int32_t mask;
126
127 switch (sc->remote_hw) {
128 case sis1100_hw_vme:
129 if (fd->owned_irqs & SIS3100_IRQS) {
130 sis3100writeremreg(sc, vme_irq_sc,
131 (fd->owned_irqs & SIS3100_IRQS)<<16, 0);
132 }
133 break;
134 case sis1100_hw_camac:
135 if (fd->owned_irqs & SIS5100_IRQS) {
136 /*sis5100writeremreg(sc, vme_irq_sc,
137 (fd->owned_irqs & SIS5100_IRQS)<<16, 0);*/
138 }
139 break;
140 case sis1100_hw_pci: break; /* do nothing */
141 case sis1100_hw_f1: break; /* do nothing */
142 case sis1100_hw_vertex: break; /* do nothing */
143 case sis1100_hw_invalid: break; /* do nothing */
144 }
145
146 mask=0;
147 if (fd->owned_irqs & SIS1100_FRONT_IRQS) {
148 mask|=(fd->owned_irqs & SIS1100_FRONT_IRQS)>>4;
149 }
150 if (fd->owned_irqs & SIS1100_MBX0_IRQ) {
151 mask|=irq_mbx0;
152 }
153 if (mask) sis1100_disable_irq(sc, 0, mask);
154
155 /*if (fd->mmapdma.valid) sis1100_dma_free(sc, fd, 0);*/
156 SEM_LOCK(sc->sem_fdata_list);
157 list_del(&fd->list);
158 SEM_UNLOCK(sc->sem_fdata_list);
159 sc->fdatalist[idx]=0;
160}
161
162#ifdef __NetBSD__
163int
164sis1100_close(dev_t dev, int flag, int mode, struct proc *p)
165{
166 struct sis1100_softc* sc=SIS1100SC(dev);
167 struct sis1100_fdata* fd=SIS1100FD(dev);
168 unsigned int minor=minor(dev);
169 unsigned int idx=minor&(sis1100_MINORUTMASK);
170
171
172 _sis1100_close(sc, fd, idx);
173
174 free(fd, M_DEVBUF);
175 simple_lock(&sc->lock_sc_inuse);
176 sc->sc_inuse--;
177 simple_unlock(&sc->sc_inuse);
178 return 0;
179}
180#elif __linux__
181int
182sis1100_release(struct inode *inode, struct file *file)
183{
184 struct sis1100_softc* sc=SIS1100SC(file);
185 struct sis1100_fdata* fd=SIS1100FD(file);
186 unsigned int _minor=iminor(inode);
187 unsigned int idx=_minor&(sis1100_MINORUTMASK);
188
189 _sis1100_close(sc, fd, idx);
190
191 kfree(fd);
192 return 0;
193}
194#endif
Note: See TracBrowser for help on using the repository browser.