1 | /* Standard VME bridge configuration for MVME5500, MVME6100 */ |
---|
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 <rtems.h> |
---|
49 | #include <rtems/bspIo.h> |
---|
50 | #include <bsp.h> |
---|
51 | #include <bsp/VME.h> |
---|
52 | #include <bsp/VMEConfig.h> |
---|
53 | #include <bsp/irq.h> |
---|
54 | #include <bsp/vmeUniverse.h> |
---|
55 | #define _VME_TSI148_DECLARE_SHOW_ROUTINES |
---|
56 | #include <bsp/vmeTsi148.h> |
---|
57 | #include <libcpu/bat.h> |
---|
58 | |
---|
59 | /* Use a weak alias for the VME configuration. |
---|
60 | * This permits individual applications to override |
---|
61 | * this routine. |
---|
62 | * They may even create an 'empty' |
---|
63 | * |
---|
64 | * void BSP_vme_config(void) {} |
---|
65 | * |
---|
66 | * which will avoid linking in the Universe driver |
---|
67 | * at all :-). |
---|
68 | */ |
---|
69 | |
---|
70 | void BSP_vme_config(void) __attribute__ (( weak, alias("__BSP_default_vme_config") )); |
---|
71 | |
---|
72 | typedef struct { |
---|
73 | int (*xlate_adrs)(int, int, unsigned long, unsigned long, unsigned long *); |
---|
74 | int (*install_isr)(unsigned long, BSP_VME_ISR_t, void *); |
---|
75 | int (*remove_isr)(unsigned long, BSP_VME_ISR_t, void *); |
---|
76 | BSP_VME_ISR_t (*get_isr)(unsigned long vector, void **); |
---|
77 | int (*enable_int_lvl)(unsigned int); |
---|
78 | int (*disable_int_lvl)(unsigned int); |
---|
79 | int (*outbound_p_cfg)(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long); |
---|
80 | int (*inbound_p_cfg) (unsigned long, unsigned long, unsigned long, unsigned long, unsigned long); |
---|
81 | void (*outbound_p_show)(FILE*); |
---|
82 | void (*inbound_p_show) (FILE*); |
---|
83 | void (*reset_bus)(void); |
---|
84 | int (*install_irq_mgr)(int, int, int, ...); |
---|
85 | } VMEOpsRec, *VMEOps; |
---|
86 | |
---|
87 | static VMEOpsRec uniOpsRec = { |
---|
88 | xlate_adrs: vmeUniverseXlateAddr, |
---|
89 | install_isr: vmeUniverseInstallISR, |
---|
90 | remove_isr: vmeUniverseRemoveISR, |
---|
91 | get_isr: vmeUniverseISRGet, |
---|
92 | enable_int_lvl: vmeUniverseIntEnable, |
---|
93 | disable_int_lvl: vmeUniverseIntDisable, |
---|
94 | outbound_p_cfg: vmeUniverseMasterPortCfg, |
---|
95 | inbound_p_cfg: vmeUniverseSlavePortCfg, |
---|
96 | outbound_p_show: vmeUniverseMasterPortsShow, |
---|
97 | inbound_p_show: vmeUniverseSlavePortsShow, |
---|
98 | reset_bus: vmeUniverseResetBus, |
---|
99 | install_irq_mgr: vmeUniverseInstallIrqMgrAlt, |
---|
100 | }; |
---|
101 | |
---|
102 | static VMEOpsRec tsiOpsRec = { |
---|
103 | xlate_adrs: vmeTsi148XlateAddr, |
---|
104 | install_isr: vmeTsi148InstallISR, |
---|
105 | remove_isr: vmeTsi148RemoveISR, |
---|
106 | get_isr: vmeTsi148ISRGet, |
---|
107 | enable_int_lvl: vmeTsi148IntEnable, |
---|
108 | disable_int_lvl: vmeTsi148IntDisable, |
---|
109 | outbound_p_cfg: vmeTsi148OutboundPortCfg, |
---|
110 | inbound_p_cfg: vmeTsi148InboundPortCfg, |
---|
111 | outbound_p_show: vmeTsi148OutboundPortsShow, |
---|
112 | inbound_p_show: vmeTsi148InboundPortsShow, |
---|
113 | reset_bus: vmeTsi148ResetBus, |
---|
114 | install_irq_mgr: vmeTsi148InstallIrqMgrAlt, |
---|
115 | }; |
---|
116 | |
---|
117 | static VMEOps theOps = 0; |
---|
118 | |
---|
119 | int |
---|
120 | BSP_vme2local_adrs(unsigned long am, unsigned long vmeaddr, unsigned long *plocaladdr) |
---|
121 | { |
---|
122 | int rval=theOps->xlate_adrs(1,0,am,vmeaddr,plocaladdr); |
---|
123 | *plocaladdr+=PCI_MEM_BASE; |
---|
124 | return rval; |
---|
125 | } |
---|
126 | |
---|
127 | int |
---|
128 | BSP_local2vme_adrs(unsigned long am, unsigned long localaddr, unsigned long *pvmeaddr) |
---|
129 | { |
---|
130 | return theOps->xlate_adrs(0, 0, am,localaddr+PCI_DRAM_OFFSET,pvmeaddr); |
---|
131 | } |
---|
132 | |
---|
133 | int |
---|
134 | BSP_installVME_isr(unsigned long vector, BSP_VME_ISR_t handler, void *arg) |
---|
135 | { |
---|
136 | return theOps->install_isr(vector, handler, arg); |
---|
137 | } |
---|
138 | |
---|
139 | int |
---|
140 | BSP_removeVME_isr(unsigned long vector, BSP_VME_ISR_t handler, void *arg) |
---|
141 | { |
---|
142 | return theOps->remove_isr(vector, handler, arg); |
---|
143 | } |
---|
144 | |
---|
145 | /* retrieve the currently installed ISR for a given vector */ |
---|
146 | BSP_VME_ISR_t |
---|
147 | BSP_getVME_isr(unsigned long vector, void **parg) |
---|
148 | { |
---|
149 | return theOps->get_isr(vector, parg); |
---|
150 | } |
---|
151 | |
---|
152 | int |
---|
153 | BSP_enableVME_int_lvl(unsigned int level) |
---|
154 | { |
---|
155 | return theOps->enable_int_lvl(level); |
---|
156 | } |
---|
157 | |
---|
158 | int |
---|
159 | BSP_disableVME_int_lvl(unsigned int level) |
---|
160 | { |
---|
161 | return theOps->disable_int_lvl(level); |
---|
162 | } |
---|
163 | |
---|
164 | int |
---|
165 | BSP_VMEOutboundPortCfg( |
---|
166 | unsigned long port, |
---|
167 | unsigned long address_space, |
---|
168 | unsigned long vme_address, |
---|
169 | unsigned long pci_address, |
---|
170 | unsigned long size) |
---|
171 | { |
---|
172 | return theOps->outbound_p_cfg(port, address_space, vme_address, pci_address, size); |
---|
173 | } |
---|
174 | |
---|
175 | int |
---|
176 | BSP_VMEInboundPortCfg( |
---|
177 | unsigned long port, |
---|
178 | unsigned long address_space, |
---|
179 | unsigned long vme_address, |
---|
180 | unsigned long pci_address, |
---|
181 | unsigned long size) |
---|
182 | { |
---|
183 | return theOps->inbound_p_cfg(port, address_space, vme_address, pci_address, size); |
---|
184 | } |
---|
185 | |
---|
186 | void |
---|
187 | BSP_VMEOutboundPortsShow(FILE *f) |
---|
188 | { |
---|
189 | theOps->outbound_p_show(f); |
---|
190 | } |
---|
191 | |
---|
192 | void |
---|
193 | BSP_VMEInboundPortsShow(FILE *f) |
---|
194 | { |
---|
195 | theOps->inbound_p_show(f); |
---|
196 | } |
---|
197 | |
---|
198 | void |
---|
199 | BSP_VMEResetBus(void) |
---|
200 | { |
---|
201 | theOps->reset_bus(); |
---|
202 | } |
---|
203 | |
---|
204 | static unsigned short |
---|
205 | tsi_clear_errors(int quiet) |
---|
206 | { |
---|
207 | unsigned long v; |
---|
208 | unsigned short rval; |
---|
209 | v = vmeTsi148ClearVMEBusErrors(0); |
---|
210 | |
---|
211 | /* return bits 8..23 of VEAT; set bit 15 to make sure rval is nonzero on error */ |
---|
212 | rval = v ? ((v>>8) & 0xffff) | (1<<15) : 0; |
---|
213 | return rval; |
---|
214 | } |
---|
215 | |
---|
216 | void |
---|
217 | __BSP_default_vme_config(void) |
---|
218 | { |
---|
219 | int err = 1; |
---|
220 | if ( 0 == vmeUniverseInit() ) { |
---|
221 | theOps = &uniOpsRec; |
---|
222 | vmeUniverseReset(); |
---|
223 | } else if ( 0 == vmeTsi148Init() ) { |
---|
224 | theOps = &tsiOpsRec; |
---|
225 | vmeTsi148Reset(); |
---|
226 | _BSP_clear_vmebridge_errors = tsi_clear_errors; |
---|
227 | } else |
---|
228 | return; /* no VME bridge found chip */ |
---|
229 | |
---|
230 | /* map VME address ranges */ |
---|
231 | BSP_VMEOutboundPortCfg( |
---|
232 | 0, |
---|
233 | VME_AM_EXT_SUP_DATA, |
---|
234 | _VME_A32_WIN0_ON_VME, |
---|
235 | _VME_A32_WIN0_ON_PCI, |
---|
236 | 0x0e000000 |
---|
237 | ); |
---|
238 | BSP_VMEOutboundPortCfg( |
---|
239 | 1, |
---|
240 | VME_AM_STD_SUP_DATA, |
---|
241 | 0x00000000, |
---|
242 | _VME_A24_ON_PCI, |
---|
243 | 0x00ff0000); |
---|
244 | BSP_VMEOutboundPortCfg( |
---|
245 | 2, |
---|
246 | VME_AM_SUP_SHORT_IO, |
---|
247 | 0x00000000, |
---|
248 | _VME_A16_ON_PCI, |
---|
249 | 0x00010000); |
---|
250 | |
---|
251 | #ifdef _VME_CSR_ON_PCI |
---|
252 | /* Map VME64 CSR */ |
---|
253 | BSP_VMEOutboundPortCfg( |
---|
254 | 7, |
---|
255 | VME_AM_CSR, |
---|
256 | 0, |
---|
257 | _VME_CSR_ON_PCI, |
---|
258 | 0x01000000); |
---|
259 | #endif |
---|
260 | |
---|
261 | #ifdef _VME_DRAM_OFFSET |
---|
262 | /* map our memory to VME */ |
---|
263 | BSP_VMEInboundPortCfg( |
---|
264 | 0, |
---|
265 | VME_AM_EXT_SUP_DATA | VME_AM_IS_MEMORY, |
---|
266 | _VME_DRAM_OFFSET, |
---|
267 | PCI_DRAM_OFFSET, |
---|
268 | BSP_mem_size); |
---|
269 | #endif |
---|
270 | |
---|
271 | /* stdio is not yet initialized; the driver will revert to printk */ |
---|
272 | BSP_VMEOutboundPortsShow(0); |
---|
273 | BSP_VMEInboundPortsShow(0); |
---|
274 | |
---|
275 | switch (BSP_getBoardType()) { |
---|
276 | case MVME6100: |
---|
277 | err = theOps->install_irq_mgr( |
---|
278 | VMETSI148_IRQ_MGR_FLAG_SHARED, |
---|
279 | 0, BSP_IRQ_GPP_0 + 20, |
---|
280 | 1, BSP_IRQ_GPP_0 + 21, |
---|
281 | 2, BSP_IRQ_GPP_0 + 22, |
---|
282 | 3, BSP_IRQ_GPP_0 + 23, |
---|
283 | -1); |
---|
284 | break; |
---|
285 | |
---|
286 | case MVME5500: |
---|
287 | err = theOps->install_irq_mgr( |
---|
288 | VMEUNIVERSE_IRQ_MGR_FLAG_SHARED | |
---|
289 | VMEUNIVERSE_IRQ_MGR_FLAG_PW_WORKAROUND, |
---|
290 | 0, BSP_IRQ_GPP_0 + 12, |
---|
291 | 1, BSP_IRQ_GPP_0 + 13, |
---|
292 | 2, BSP_IRQ_GPP_0 + 14, |
---|
293 | 3, BSP_IRQ_GPP_0 + 15, |
---|
294 | -1); |
---|
295 | break; |
---|
296 | |
---|
297 | default: |
---|
298 | printk("WARNING: unknown board; "); |
---|
299 | break; |
---|
300 | } |
---|
301 | if ( err ) |
---|
302 | printk("VME interrupt manager NOT INSTALLED (error: %i)\n", err); |
---|
303 | } |
---|