1 | /* Setup/glue to attach VME DMA driver to the beatnik BSP */ |
---|
2 | |
---|
3 | /* |
---|
4 | * Authorship |
---|
5 | * ---------- |
---|
6 | * This software ('beatnik' RTEMS BSP for MVME6100 and MVME5500) was |
---|
7 | * created by Till Straumann <strauman@slac.stanford.edu>, 2005-2007, |
---|
8 | * Stanford Linear Accelerator Center, Stanford University. |
---|
9 | * |
---|
10 | * Acknowledgement of sponsorship |
---|
11 | * ------------------------------ |
---|
12 | * The 'beatnik' BSP was produced by |
---|
13 | * the Stanford Linear Accelerator Center, Stanford University, |
---|
14 | * under Contract DE-AC03-76SFO0515 with the Department of Energy. |
---|
15 | * |
---|
16 | * Government disclaimer of liability |
---|
17 | * ---------------------------------- |
---|
18 | * Neither the United States nor the United States Department of Energy, |
---|
19 | * nor any of their employees, makes any warranty, express or implied, or |
---|
20 | * assumes any legal liability or responsibility for the accuracy, |
---|
21 | * completeness, or usefulness of any data, apparatus, product, or process |
---|
22 | * disclosed, or represents that its use would not infringe privately owned |
---|
23 | * rights. |
---|
24 | * |
---|
25 | * Stanford disclaimer of liability |
---|
26 | * -------------------------------- |
---|
27 | * Stanford University makes no representations or warranties, express or |
---|
28 | * implied, nor assumes any liability for the use of this software. |
---|
29 | * |
---|
30 | * Stanford disclaimer of copyright |
---|
31 | * -------------------------------- |
---|
32 | * Stanford University, owner of the copyright, hereby disclaims its |
---|
33 | * copyright and all other rights in this software. Hence, anyone may |
---|
34 | * freely use it for any purpose without restriction. |
---|
35 | * |
---|
36 | * Maintenance of notices |
---|
37 | * ---------------------- |
---|
38 | * In the interest of clarity regarding the origin and status of this |
---|
39 | * SLAC software, this and all the preceding Stanford University notices |
---|
40 | * are to remain affixed to any copy or derivative of this software made |
---|
41 | * or distributed by the recipient and are to be affixed to any copy of |
---|
42 | * software made or distributed by the recipient that contains a copy or |
---|
43 | * derivative of this software. |
---|
44 | * |
---|
45 | * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03 |
---|
46 | */ |
---|
47 | |
---|
48 | #include <stdio.h> |
---|
49 | #include <stdint.h> |
---|
50 | #include <rtems.h> |
---|
51 | #include <bsp.h> |
---|
52 | #include <bsp/VME.h> |
---|
53 | #include <bsp/vmeTsi148.h> |
---|
54 | #include <bsp/vmeUniverse.h> |
---|
55 | #include <bsp/VMEDMA.h> |
---|
56 | #include <bsp/vmeTsi148DMA.h> |
---|
57 | #include <bsp/vmeUniverseDMA.h> |
---|
58 | #include <bsp/bspVmeDmaList.h> |
---|
59 | |
---|
60 | typedef struct DmaOpsRec_ { |
---|
61 | int (*setup)(int, uint32_t, uint32_t, void *); |
---|
62 | int (*start)(int, uint32_t, uint32_t, uint32_t); |
---|
63 | uint32_t (*status)(int); |
---|
64 | VMEDmaListClass listClass; |
---|
65 | } DmaOpsRec, *DmaOps; |
---|
66 | |
---|
67 | static DmaOpsRec universeOps = { |
---|
68 | vmeUniverseDmaSetup, |
---|
69 | vmeUniverseDmaStart, |
---|
70 | vmeUniverseDmaStatus, |
---|
71 | &vmeUniverseDmaListClass, |
---|
72 | }; |
---|
73 | |
---|
74 | static DmaOpsRec tsiOps = { |
---|
75 | vmeTsi148DmaSetup, |
---|
76 | vmeTsi148DmaStart, |
---|
77 | vmeTsi148DmaStatus, |
---|
78 | &vmeTsi148DmaListClass, |
---|
79 | }; |
---|
80 | |
---|
81 | static int setup(int a, uint32_t b, uint32_t c, void *d); |
---|
82 | static int start(int a, uint32_t b, uint32_t c, uint32_t d); |
---|
83 | static uint32_t status(int a); |
---|
84 | |
---|
85 | static DmaOpsRec jumpstartOps = { |
---|
86 | setup, |
---|
87 | start, |
---|
88 | status, |
---|
89 | 0 |
---|
90 | }; |
---|
91 | |
---|
92 | static DmaOps dmaOps = &jumpstartOps; |
---|
93 | |
---|
94 | static DmaOps selectOps() |
---|
95 | { |
---|
96 | return (MVME6100 != BSP_getBoardType()) ? |
---|
97 | &universeOps : &tsiOps; |
---|
98 | } |
---|
99 | |
---|
100 | static int |
---|
101 | setup(int a, uint32_t b, uint32_t c, void *d) |
---|
102 | { |
---|
103 | return (dmaOps=selectOps())->setup(a,b,c,d); |
---|
104 | } |
---|
105 | |
---|
106 | static int |
---|
107 | start(int a, uint32_t b, uint32_t c, uint32_t d) |
---|
108 | { |
---|
109 | return (dmaOps=selectOps())->start(a,b,c,d); |
---|
110 | } |
---|
111 | |
---|
112 | static uint32_t |
---|
113 | status(int a) |
---|
114 | { |
---|
115 | return (dmaOps=selectOps())->status(a); |
---|
116 | } |
---|
117 | |
---|
118 | |
---|
119 | int |
---|
120 | BSP_VMEDmaSetup(int channel, uint32_t bus_mode, uint32_t xfer_mode, void *custom_setup) |
---|
121 | { |
---|
122 | return dmaOps->setup(channel, bus_mode, xfer_mode, custom_setup); |
---|
123 | } |
---|
124 | |
---|
125 | int |
---|
126 | BSP_VMEDmaStart(int channel, uint32_t pci_addr, uint32_t vme_addr, uint32_t n_bytes) |
---|
127 | { |
---|
128 | return dmaOps->start(channel, pci_addr, vme_addr, n_bytes); |
---|
129 | } |
---|
130 | |
---|
131 | uint32_t |
---|
132 | BSP_VMEDmaStatus(int channel) |
---|
133 | { |
---|
134 | return dmaOps->status(channel); |
---|
135 | } |
---|
136 | |
---|
137 | BSP_VMEDmaListDescriptor |
---|
138 | BSP_VMEDmaListDescriptorSetup( |
---|
139 | BSP_VMEDmaListDescriptor d, |
---|
140 | uint32_t attr_mask, |
---|
141 | uint32_t xfer_mode, |
---|
142 | uint32_t pci_addr, |
---|
143 | uint32_t vme_addr, |
---|
144 | uint32_t n_bytes) |
---|
145 | { |
---|
146 | VMEDmaListClass pc; |
---|
147 | if ( !d ) { |
---|
148 | if ( ! (pc = dmaOps->listClass) ) { |
---|
149 | pc = (dmaOps = selectOps())->listClass; |
---|
150 | } |
---|
151 | return BSP_VMEDmaListDescriptorNewTool( |
---|
152 | pc, |
---|
153 | attr_mask, |
---|
154 | xfer_mode, |
---|
155 | pci_addr, |
---|
156 | vme_addr, |
---|
157 | n_bytes); |
---|
158 | |
---|
159 | } |
---|
160 | return BSP_VMEDmaListDescriptorSetupTool(d, attr_mask, xfer_mode, pci_addr, vme_addr, n_bytes); |
---|
161 | } |
---|
162 | |
---|
163 | int |
---|
164 | BSP_VMEDmaListStart(int channel, BSP_VMEDmaListDescriptor list) |
---|
165 | { |
---|
166 | return BSP_VMEDmaListDescriptorStartTool(0, channel, list); |
---|
167 | } |
---|
168 | |
---|
169 | /* NOT thread safe! */ |
---|
170 | int |
---|
171 | BSP_VMEDmaInstallISR(int channel, BSP_VMEDmaIRQCallback cb, void *usr_arg) |
---|
172 | { |
---|
173 | int vec; |
---|
174 | BSP_VME_ISR_t curr; |
---|
175 | void *carg; |
---|
176 | |
---|
177 | if ( MVME6100 != BSP_getBoardType() ) { |
---|
178 | if ( channel != 0 ) |
---|
179 | return -1; |
---|
180 | |
---|
181 | vec = UNIV_DMA_INT_VEC; |
---|
182 | |
---|
183 | } else { |
---|
184 | if ( channel < 0 || channel > 1 ) |
---|
185 | return -1; |
---|
186 | |
---|
187 | vec = (channel ? TSI_DMA1_INT_VEC : TSI_DMA_INT_VEC ); |
---|
188 | } |
---|
189 | |
---|
190 | curr = BSP_getVME_isr(vec, &carg); |
---|
191 | |
---|
192 | if ( cb && curr ) { |
---|
193 | /* IRQ currently in use */ |
---|
194 | return -1; |
---|
195 | } |
---|
196 | |
---|
197 | if ( !cb && !curr ) { |
---|
198 | /* Allow uninstall if no handler is currently installed; |
---|
199 | * just make sure IRQ is disabled |
---|
200 | */ |
---|
201 | BSP_disableVME_int_lvl(vec); |
---|
202 | return 0; |
---|
203 | } |
---|
204 | |
---|
205 | if ( cb ) { |
---|
206 | if ( BSP_installVME_isr(vec, (BSP_VME_ISR_t)cb, usr_arg) ) |
---|
207 | return -4; |
---|
208 | BSP_enableVME_int_lvl(vec); |
---|
209 | } else { |
---|
210 | BSP_disableVME_int_lvl(vec); |
---|
211 | if ( BSP_removeVME_isr(vec, curr, carg) ) |
---|
212 | return -4; |
---|
213 | } |
---|
214 | return 0; |
---|
215 | } |
---|