Back to home page

LXR

 
 

    


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

0001 /* Standard VME bridge configuration for MVME5500, MVME6100 */
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 <rtems.h>
0049 #include <rtems/bspIo.h>
0050 #include <bsp.h>
0051 #include <bsp/VME.h>
0052 #include <bsp/VMEConfig.h>
0053 #include <bsp/irq.h>
0054 #include <bsp/vmeUniverse.h>
0055 #define _VME_TSI148_DECLARE_SHOW_ROUTINES
0056 #include <bsp/vmeTsi148.h>
0057 #include <libcpu/bat.h>
0058 
0059 /* Use a weak alias for the VME configuration.
0060  * This permits individual applications to override
0061  * this routine.
0062  * They may even create an 'empty'
0063  *
0064  *    void BSP_vme_config(void) {}
0065  *
0066  * which will avoid linking in the Universe driver
0067  * at all :-).
0068  */
0069 
0070 void BSP_vme_config(void) __attribute__ (( weak, alias("__BSP_default_vme_config") ));
0071 
0072 typedef struct {
0073     int             (*xlate_adrs)(int, int, unsigned long, unsigned long, unsigned long *);
0074     int             (*install_isr)(unsigned long, BSP_VME_ISR_t, void *);
0075     int             (*remove_isr)(unsigned long, BSP_VME_ISR_t, void *);
0076     BSP_VME_ISR_t   (*get_isr)(unsigned long vector, void **);
0077     int             (*enable_int_lvl)(unsigned int);
0078     int             (*disable_int_lvl)(unsigned int);
0079     int             (*outbound_p_cfg)(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long);
0080     int             (*inbound_p_cfg) (unsigned long, unsigned long, unsigned long, unsigned long, unsigned long);
0081     void            (*outbound_p_show)(FILE*);
0082     void            (*inbound_p_show) (FILE*);
0083     void            (*reset_bus)(void);
0084     int             (*install_irq_mgr)(int, int, int, ...);
0085 } VMEOpsRec, *VMEOps;
0086 
0087 static VMEOpsRec uniOpsRec = {
0088     xlate_adrs:         vmeUniverseXlateAddr,
0089     install_isr:        vmeUniverseInstallISR,
0090     remove_isr:         vmeUniverseRemoveISR,
0091     get_isr:            vmeUniverseISRGet,
0092     enable_int_lvl:     vmeUniverseIntEnable,
0093     disable_int_lvl:    vmeUniverseIntDisable,
0094     outbound_p_cfg:     vmeUniverseMasterPortCfg,
0095     inbound_p_cfg:      vmeUniverseSlavePortCfg,
0096     outbound_p_show:    vmeUniverseMasterPortsShow,
0097     inbound_p_show:     vmeUniverseSlavePortsShow,
0098     reset_bus:          vmeUniverseResetBus,
0099     install_irq_mgr:    vmeUniverseInstallIrqMgrAlt,
0100 };
0101 
0102 static VMEOpsRec tsiOpsRec = {
0103     xlate_adrs:         vmeTsi148XlateAddr,
0104     install_isr:        vmeTsi148InstallISR,
0105     remove_isr:         vmeTsi148RemoveISR,
0106     get_isr:            vmeTsi148ISRGet,
0107     enable_int_lvl:     vmeTsi148IntEnable,
0108     disable_int_lvl:    vmeTsi148IntDisable,
0109     outbound_p_cfg:     vmeTsi148OutboundPortCfg,
0110     inbound_p_cfg:      vmeTsi148InboundPortCfg,
0111     outbound_p_show:    vmeTsi148OutboundPortsShow,
0112     inbound_p_show:     vmeTsi148InboundPortsShow,
0113     reset_bus:          vmeTsi148ResetBus,
0114     install_irq_mgr:    vmeTsi148InstallIrqMgrAlt,
0115 };
0116 
0117 static VMEOps theOps = 0;
0118 
0119 int
0120 BSP_vme2local_adrs(unsigned long am, unsigned long vmeaddr, unsigned long *plocaladdr)
0121 {
0122 int rval=theOps->xlate_adrs(1,0,am,vmeaddr,plocaladdr);
0123     *plocaladdr+=PCI_MEM_BASE;
0124     return rval;
0125 }
0126 
0127 int
0128 BSP_local2vme_adrs(unsigned long am, unsigned long localaddr, unsigned long *pvmeaddr)
0129 {
0130     return theOps->xlate_adrs(0, 0, am,localaddr+PCI_DRAM_OFFSET,pvmeaddr);
0131 }
0132 
0133 int
0134 BSP_installVME_isr(unsigned long vector, BSP_VME_ISR_t handler, void *arg)
0135 {
0136     return theOps->install_isr(vector, handler, arg);
0137 }
0138 
0139 int
0140 BSP_removeVME_isr(unsigned long vector, BSP_VME_ISR_t handler, void *arg)
0141 {
0142     return theOps->remove_isr(vector, handler, arg);
0143 }
0144 
0145 /* retrieve the currently installed ISR for a given vector */
0146 BSP_VME_ISR_t
0147 BSP_getVME_isr(unsigned long vector, void **parg)
0148 {
0149     return theOps->get_isr(vector, parg);
0150 }
0151 
0152 int
0153 BSP_enableVME_int_lvl(unsigned int level)
0154 {
0155     return theOps->enable_int_lvl(level);
0156 }
0157 
0158 int
0159 BSP_disableVME_int_lvl(unsigned int level)
0160 {
0161     return theOps->disable_int_lvl(level);
0162 }
0163 
0164 int
0165 BSP_VMEOutboundPortCfg(
0166     unsigned long port,
0167     unsigned long address_space,
0168     unsigned long vme_address,
0169     unsigned long pci_address,
0170     unsigned long size)
0171 {
0172     return theOps->outbound_p_cfg(port, address_space, vme_address, pci_address, size);
0173 }
0174 
0175 int
0176 BSP_VMEInboundPortCfg(
0177     unsigned long port,
0178     unsigned long address_space,
0179     unsigned long vme_address,
0180     unsigned long pci_address,
0181     unsigned long size)
0182 {
0183     return theOps->inbound_p_cfg(port, address_space, vme_address, pci_address, size);
0184 }
0185 
0186 void
0187 BSP_VMEOutboundPortsShow(FILE *f)
0188 {
0189     theOps->outbound_p_show(f);
0190 }
0191 
0192 void
0193 BSP_VMEInboundPortsShow(FILE *f)
0194 {
0195     theOps->inbound_p_show(f);
0196 }
0197 
0198 void
0199 BSP_VMEResetBus(void)
0200 {
0201     theOps->reset_bus();
0202 }
0203 
0204 static unsigned short
0205 tsi_clear_errors(int quiet)
0206 {
0207 unsigned long   v;
0208 unsigned short  rval;
0209     v = vmeTsi148ClearVMEBusErrors(0);
0210 
0211     /* return bits 8..23 of VEAT; set bit 15 to make sure rval is nonzero on error */
0212     rval =  v ? ((v>>8) & 0xffff) | (1<<15) : 0;
0213     return rval;
0214 }
0215 
0216 void
0217 __BSP_default_vme_config(void)
0218 {
0219 int err = 1;
0220     if ( 0 == vmeUniverseInit() ) {
0221         theOps = &uniOpsRec;
0222         vmeUniverseReset();
0223     } else if ( 0 == vmeTsi148Init() ) {
0224         theOps = &tsiOpsRec;
0225         vmeTsi148Reset();
0226         _BSP_clear_vmebridge_errors = tsi_clear_errors;
0227     } else 
0228         return; /* no VME bridge found chip */
0229 
0230   /* map VME address ranges */
0231   BSP_VMEOutboundPortCfg(
0232     0,
0233     VME_AM_EXT_SUP_DATA,
0234     _VME_A32_WIN0_ON_VME,
0235     _VME_A32_WIN0_ON_PCI,
0236     0x0e000000
0237     );
0238   BSP_VMEOutboundPortCfg(
0239     1,
0240     VME_AM_STD_SUP_DATA,
0241     0x00000000,
0242     _VME_A24_ON_PCI,
0243     0x00ff0000);
0244   BSP_VMEOutboundPortCfg(
0245     2,
0246     VME_AM_SUP_SHORT_IO,
0247     0x00000000,
0248     _VME_A16_ON_PCI,
0249     0x00010000);
0250 
0251 #ifdef _VME_CSR_ON_PCI
0252   /* Map VME64 CSR */
0253   BSP_VMEOutboundPortCfg(
0254           7,
0255           VME_AM_CSR,
0256           0,
0257           _VME_CSR_ON_PCI,
0258           0x01000000);
0259 #endif
0260 
0261 #ifdef _VME_DRAM_OFFSET
0262   /* map our memory to VME */
0263   BSP_VMEInboundPortCfg(
0264     0,
0265     VME_AM_EXT_SUP_DATA | VME_AM_IS_MEMORY,
0266     _VME_DRAM_OFFSET,
0267     PCI_DRAM_OFFSET,
0268     BSP_mem_size);
0269 #endif
0270 
0271   /* stdio is not yet initialized; the driver will revert to printk */
0272   BSP_VMEOutboundPortsShow(0);
0273   BSP_VMEInboundPortsShow(0);
0274 
0275   switch (BSP_getBoardType()) {
0276     case MVME6100:
0277         err = theOps->install_irq_mgr(
0278                     VMETSI148_IRQ_MGR_FLAG_SHARED,
0279                     0, BSP_IRQ_GPP_0 + 20,
0280                     1, BSP_IRQ_GPP_0 + 21,
0281                     2, BSP_IRQ_GPP_0 + 22,
0282                     3, BSP_IRQ_GPP_0 + 23,
0283                     -1);
0284     break;
0285 
0286     case MVME5500:
0287         err = theOps->install_irq_mgr(
0288                     VMEUNIVERSE_IRQ_MGR_FLAG_SHARED |
0289                     VMEUNIVERSE_IRQ_MGR_FLAG_PW_WORKAROUND,
0290                     0, BSP_IRQ_GPP_0 + 12,
0291                     1, BSP_IRQ_GPP_0 + 13,
0292                     2, BSP_IRQ_GPP_0 + 14,
0293                     3, BSP_IRQ_GPP_0 + 15,
0294                     -1);
0295     break;
0296 
0297     default:
0298         printk("WARNING: unknown board; ");
0299     break;
0300   }
0301   if ( err )
0302     printk("VME interrupt manager NOT INSTALLED (error: %i)\n", err);
0303 }