source: rtems/c/src/lib/libbsp/powerpc/beatnik/vme/vme_dma.c @ b7a6d23a

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