Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:52

0001 /* Setup/glue to attach VME DMA driver to the beatnik BSP */
0002 
0003 /* 
0004  * Authorship
0005  * ----------
0006  * This software ('beatnik' RTEMS BSP for MVME6100 and MVME5500) was
0007  *     created by Till Straumann <strauman@slac.stanford.edu>, 2005-2007,
0008  *     Stanford Linear Accelerator Center, Stanford University.
0009  * 
0010  * Acknowledgement of sponsorship
0011  * ------------------------------
0012  * The 'beatnik' BSP was produced by
0013  *     the Stanford Linear Accelerator Center, Stanford University,
0014  *     under Contract DE-AC03-76SFO0515 with the Department of Energy.
0015  * 
0016  * Government disclaimer of liability
0017  * ----------------------------------
0018  * Neither the United States nor the United States Department of Energy,
0019  * nor any of their employees, makes any warranty, express or implied, or
0020  * assumes any legal liability or responsibility for the accuracy,
0021  * completeness, or usefulness of any data, apparatus, product, or process
0022  * disclosed, or represents that its use would not infringe privately owned
0023  * rights.
0024  * 
0025  * Stanford disclaimer of liability
0026  * --------------------------------
0027  * Stanford University makes no representations or warranties, express or
0028  * implied, nor assumes any liability for the use of this software.
0029  * 
0030  * Stanford disclaimer of copyright
0031  * --------------------------------
0032  * Stanford University, owner of the copyright, hereby disclaims its
0033  * copyright and all other rights in this software.  Hence, anyone may
0034  * freely use it for any purpose without restriction.  
0035  * 
0036  * Maintenance of notices
0037  * ----------------------
0038  * In the interest of clarity regarding the origin and status of this
0039  * SLAC software, this and all the preceding Stanford University notices
0040  * are to remain affixed to any copy or derivative of this software made
0041  * or distributed by the recipient and are to be affixed to any copy of
0042  * software made or distributed by the recipient that contains a copy or
0043  * derivative of this software.
0044  * 
0045  * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
0046  */ 
0047 
0048 #include <stdio.h>
0049 #include <stdint.h>
0050 #include <rtems.h>
0051 #include <bsp.h>
0052 #include <bsp/VME.h>
0053 #include <bsp/vmeTsi148.h>
0054 #include <bsp/vmeUniverse.h>
0055 #include <bsp/VMEDMA.h>
0056 #include <bsp/vmeTsi148DMA.h>
0057 #include <bsp/vmeUniverseDMA.h>
0058 #include <bsp/bspVmeDmaList.h>
0059 
0060 typedef struct DmaOpsRec_ {
0061     int             (*setup)(int, uint32_t, uint32_t, void *);
0062     int             (*start)(int, uint32_t, uint32_t, uint32_t);
0063     uint32_t        (*status)(int);
0064     VMEDmaListClass listClass;
0065 } DmaOpsRec, *DmaOps;
0066 
0067 static DmaOpsRec universeOps = {
0068     vmeUniverseDmaSetup,
0069     vmeUniverseDmaStart,
0070     vmeUniverseDmaStatus,
0071     &vmeUniverseDmaListClass,
0072 };
0073 
0074 static DmaOpsRec tsiOps = {
0075     vmeTsi148DmaSetup,
0076     vmeTsi148DmaStart,
0077     vmeTsi148DmaStatus,
0078     &vmeTsi148DmaListClass,
0079 };
0080 
0081 static int      setup(int a, uint32_t b, uint32_t c, void *d);
0082 static int      start(int a, uint32_t b, uint32_t c, uint32_t d);
0083 static uint32_t status(int a);
0084 
0085 static DmaOpsRec jumpstartOps = {
0086     setup,
0087     start,
0088     status,
0089     0
0090 };
0091 
0092 static DmaOps dmaOps = &jumpstartOps;
0093 
0094 static DmaOps selectOps()
0095 {
0096     return (MVME6100 != BSP_getBoardType()) ?
0097                 &universeOps : &tsiOps;
0098 }
0099 
0100 static int
0101 setup(int a, uint32_t b, uint32_t c, void *d)
0102 {
0103     return (dmaOps=selectOps())->setup(a,b,c,d);
0104 }
0105 
0106 static int
0107 start(int a, uint32_t b, uint32_t c, uint32_t d)
0108 {
0109     return (dmaOps=selectOps())->start(a,b,c,d);
0110 }
0111 
0112 static uint32_t
0113 status(int a)
0114 {
0115     return (dmaOps=selectOps())->status(a);
0116 }
0117 
0118 
0119 int
0120 BSP_VMEDmaSetup(int channel, uint32_t bus_mode, uint32_t xfer_mode, void *custom_setup)
0121 {
0122     return dmaOps->setup(channel, bus_mode, xfer_mode, custom_setup);
0123 }
0124 
0125 int
0126 BSP_VMEDmaStart(int channel, uint32_t pci_addr, uint32_t vme_addr, uint32_t n_bytes)
0127 {
0128     return dmaOps->start(channel, pci_addr, vme_addr, n_bytes);
0129 }
0130 
0131 uint32_t
0132 BSP_VMEDmaStatus(int channel)
0133 {
0134     return dmaOps->status(channel);
0135 }
0136 
0137 BSP_VMEDmaListDescriptor
0138 BSP_VMEDmaListDescriptorSetup(
0139         BSP_VMEDmaListDescriptor d,
0140         uint32_t                 attr_mask,
0141         uint32_t                 xfer_mode,
0142         uint32_t                 pci_addr,
0143         uint32_t                 vme_addr,
0144         uint32_t                 n_bytes)
0145 {
0146 VMEDmaListClass pc;
0147     if ( !d ) {
0148         if ( ! (pc = dmaOps->listClass) ) {
0149             pc = (dmaOps = selectOps())->listClass; 
0150         }
0151         return BSP_VMEDmaListDescriptorNewTool(
0152                     pc,
0153                     attr_mask,
0154                     xfer_mode,
0155                     pci_addr,
0156                     vme_addr,
0157                     n_bytes);
0158                     
0159     }
0160     return BSP_VMEDmaListDescriptorSetupTool(d, attr_mask, xfer_mode, pci_addr, vme_addr, n_bytes);
0161 }
0162 
0163 int
0164 BSP_VMEDmaListStart(int channel, BSP_VMEDmaListDescriptor list)
0165 {
0166     return BSP_VMEDmaListDescriptorStartTool(0, channel, list);
0167 }
0168 
0169 /* NOT thread safe! */
0170 int
0171 BSP_VMEDmaInstallISR(int channel, BSP_VMEDmaIRQCallback cb, void *usr_arg)
0172 {
0173 int vec;
0174 BSP_VME_ISR_t curr;
0175 void          *carg;
0176 
0177     if ( MVME6100 != BSP_getBoardType() ) {
0178         if ( channel != 0 )
0179             return -1;
0180 
0181         vec = UNIV_DMA_INT_VEC;
0182 
0183     } else {
0184         if ( channel < 0 || channel > 1 )
0185             return -1;
0186 
0187         vec  = (channel ? TSI_DMA1_INT_VEC : TSI_DMA_INT_VEC );
0188     }
0189 
0190     curr = BSP_getVME_isr(vec, &carg);
0191 
0192     if ( cb && curr ) {
0193         /* IRQ currently in use */
0194         return -1;
0195     }
0196 
0197     if ( !cb && !curr ) {
0198         /* Allow uninstall if no handler is currently installed;
0199          * just make sure IRQ is disabled
0200          */
0201         BSP_disableVME_int_lvl(vec);
0202         return 0;
0203     }
0204     
0205     if ( cb ) {
0206         if ( BSP_installVME_isr(vec, (BSP_VME_ISR_t)cb, usr_arg) )
0207             return -4;
0208         BSP_enableVME_int_lvl(vec);
0209     } else {
0210         BSP_disableVME_int_lvl(vec);
0211         if ( BSP_removeVME_isr(vec, curr, carg) )
0212             return -4;
0213     }
0214     return 0;
0215 }