1 /*
2 * Copyright (c) 2011 Aeroflex Gaisler
3 *
4 * BSD license:
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25
26 #ifndef _LEON3_AMBA_H__
27 #define _LEON3_AMBA_H__
28
29 #define LEON3_IO_AREA 0xfff00000
30 #define LEON3_CONF_AREA 0xff000
31 #define LEON3_AHB_SLAVE_CONF_AREA (1 << 11)
32
33 #define LEON3_AHB_CONF_WORDS 8
34 #define LEON3_APB_CONF_WORDS 2
35 #define LEON3_AHB_MASTERS 8
36 #define LEON3_AHB_SLAVES 8
37 #define LEON3_APB_SLAVES 16
38 #define LEON3_APBUARTS 8
39
40 /* Vendor codes */
41 #define VENDOR_GAISLER 1
42 #define VENDOR_PENDER 2
43 #define VENDOR_ESA 4
44 #define VENDOR_OPENCORES 8
45
46 /* Gaisler Research device id's */
47 #define GAISLER_LEON3 0x003
48 #define GAISLER_LEON3DSU 0x004
49 #define GAISLER_ETHAHB 0x005
50 #define GAISLER_APBMST 0x006
51 #define GAISLER_AHBUART 0x007
52 #define GAISLER_SRCTRL 0x008
53 #define GAISLER_SDCTRL 0x009
54 #define GAISLER_APBUART 0x00c
55 #define GAISLER_IRQMP 0x00d
56 #define GAISLER_AHBRAM 0x00e
57 #define GAISLER_GPTIMER 0x011
58 #define GAISLER_PCITRG 0x012
59 #define GAISLER_PCISBRG 0x013
60 #define GAISLER_PCIFBRG 0x014
61 #define GAISLER_PCITRACE 0x015
62 #define GAISLER_PCIDMA 0x016
63 #define GAISLER_AHBTRACE 0x017
64 #define GAISLER_ETHDSU 0x018
65 #define GAISLER_PIOPORT 0x01A
66 #define GAISLER_SPACEWIRE 0x01f
67
68 #define GAISLER_ETHMAC 0x01d
69 #define GAISLER_EHCI 0x026
70 #define GAISLER_UHCI 0x027
71
72 #define GAISLER_L2TIME 0xffd /* internal device: leon2 timer */
73 #define GAISLER_L2C 0xffe /* internal device: leon2compat */
74 #define GAISLER_PLUGPLAY 0xfff /* internal device: plug & play configarea */
75
76 #ifndef __ASSEMBLER__
77
78 extern inline char *
gaisler_device_str(int id)79 gaisler_device_str (int id)
80 {
81 switch (id)
82 {
83 case GAISLER_LEON3:
84 return "GAISLER_LEON3";
85 case GAISLER_LEON3DSU:
86 return "GAISLER_LEON3DSU";
87 case GAISLER_ETHAHB:
88 return "GAISLER_ETHAHB";
89 case GAISLER_APBMST:
90 return "GAISLER_APBMST";
91 case GAISLER_AHBUART:
92 return "GAISLER_AHBUART";
93 case GAISLER_SRCTRL:
94 return "GAISLER_SRCTRL";
95 case GAISLER_SDCTRL:
96 return "GAISLER_SDCTRL";
97 case GAISLER_APBUART:
98 return "GAISLER_APBUART";
99 case GAISLER_IRQMP:
100 return "GAISLER_IRQMP";
101 case GAISLER_AHBRAM:
102 return "GAISLER_AHBRAM";
103 case GAISLER_GPTIMER:
104 return "GAISLER_GPTIMER";
105 case GAISLER_PCITRG:
106 return "GAISLER_PCITRG";
107 case GAISLER_PCISBRG:
108 return "GAISLER_PCISBRG";
109 case GAISLER_PCIFBRG:
110 return "GAISLER_PCIFBRG";
111 case GAISLER_PCITRACE:
112 return "GAISLER_PCITRACE";
113 case GAISLER_AHBTRACE:
114 return "GAISLER_AHBTRACE";
115 case GAISLER_ETHDSU:
116 return "GAISLER_ETHDSU";
117 case GAISLER_PIOPORT:
118 return "GAISLER_PIOPORT";
119 case GAISLER_SPACEWIRE:
120 return "GAISLER_SPACEWIRE";
121
122
123 case GAISLER_L2TIME:
124 return "GAISLER_L2TIME";
125 case GAISLER_L2C:
126 return "GAISLER_L2C";
127 case GAISLER_PLUGPLAY:
128 return "GAISLER_PLUGPLAY";
129
130 default:
131 break;
132 }
133 return 0;
134 }
135
136 #endif
137
138 /* European Space Agency device id's */
139 #define ESA_LEON2 0x002
140 #define ESA_MCTRL 0x00f
141
142 #ifndef __ASSEMBLER__
143
144 extern inline char *
esa_device_str(int id)145 esa_device_str (int id)
146 {
147 switch (id)
148 {
149 case ESA_LEON2:
150 return "ESA_LEON2";
151 case ESA_MCTRL:
152 return "ESA_MCTRL";
153 default:
154 break;
155 }
156 return 0;
157 }
158
159 #endif
160
161 /* Opencores device id's */
162 #define OPENCORES_PCIBR 0x4
163 #define OPENCORES_ETHMAC 0x5
164
165 #ifndef __ASSEMBLER__
166
167 extern inline char *
opencores_device_str(int id)168 opencores_device_str (int id)
169 {
170 switch (id)
171 {
172 case OPENCORES_PCIBR:
173 return "OPENCORES_PCIBR";
174 case OPENCORES_ETHMAC:
175 return "OPENCORES_ETHMAC";
176 default:
177 break;
178 }
179 return 0;
180 }
181
182 extern inline char *
device_id2str(int vendor,int id)183 device_id2str (int vendor, int id)
184 {
185 switch (vendor)
186 {
187 case VENDOR_GAISLER:
188 return gaisler_device_str (id);
189 case VENDOR_ESA:
190 return esa_device_str (id);
191 case VENDOR_OPENCORES:
192 return opencores_device_str (id);
193 case VENDOR_PENDER:
194 default:
195 break;
196 }
197 return 0;
198 }
199
200 extern inline char *
vendor_id2str(int vendor)201 vendor_id2str (int vendor)
202 {
203 switch (vendor)
204 {
205 case VENDOR_GAISLER:
206 return "VENDOR_GAISLER";
207 case VENDOR_ESA:
208 return "VENDOR_ESA";
209 case VENDOR_OPENCORES:
210 return "VENDOR_OPENCORES";
211 case VENDOR_PENDER:
212 return "VENDOR_PENDER";
213 default:
214 break;
215 }
216 return 0;
217 }
218
219 #endif
220
221 /* Vendor codes */
222
223 /*
224 *
225 * Macros for manipulating Configuration registers
226 *
227 */
228
229 #define LEON3_BYPASS_LOAD_PA(x) (*((unsigned long*)x))
230 #define LEON3_BYPASS_STORE_PA(x,v) (*((unsigned long*)x) = (v))
231
232 #define amba_get_confword(tab, index, word) (*((tab).addr[(index)]+(word)))
233
234 #define amba_vendor(x) (((x) >> 24) & 0xff)
235
236 #define amba_device(x) (((x) >> 12) & 0xfff)
237
238 #define amba_ahb_get_membar(tab, index, nr) (*((tab).addr[(index)]+4+(nr)))
239
240 #define amba_apb_get_membar(tab, index) (*((tab).addr[(index)]+1))
241
242 #define amba_membar_start(mbar) (((mbar) & 0xfff00000) & (((mbar) & 0xfff0) << 16))
243
244 #define amba_iobar_start(base, iobar) ((base) | ((((iobar) & 0xfff00000)>>12) & (((iobar) & 0xfff0)<<4)) )
245
246 #define amba_irq(conf) ((conf) & 0xf)
247
248 #define amba_membar_type(mbar) ((mbar) & 0xf)
249
250 #define AMBA_TYPE_APBIO 0x1
251 #define AMBA_TYPE_MEM 0x2
252 #define AMBA_TYPE_AHBIO 0x3
253
254 #define AMBA_TYPE_AHBIO_ADDR(addr) (LEON3_IO_AREA | ((addr) >> 12))
255
256
257
258
259
260
261 #ifndef __ASSEMBLER__
262
263 /*
264 * The following defines the bits in the LEON UART Status Registers.
265 */
266
267 #define LEON_REG_UART_STATUS_DR 0x00000001 /* Data Ready */
268 #define LEON_REG_UART_STATUS_TSE 0x00000002 /* TX Send Register Empty */
269 #define LEON_REG_UART_STATUS_THE 0x00000004 /* TX Hold Register Empty */
270 #define LEON_REG_UART_STATUS_BR 0x00000008 /* Break Error */
271 #define LEON_REG_UART_STATUS_OE 0x00000010 /* RX Overrun Error */
272 #define LEON_REG_UART_STATUS_PE 0x00000020 /* RX Parity Error */
273 #define LEON_REG_UART_STATUS_FE 0x00000040 /* RX Framing Error */
274 #define LEON_REG_UART_STATUS_ERR 0x00000078 /* Error Mask */
275
276 /*
277 * The following defines the bits in the LEON UART Ctrl Registers.
278 */
279
280 #define LEON_REG_UART_CTRL_RE 0x00000001 /* Receiver enable */
281 #define LEON_REG_UART_CTRL_TE 0x00000002 /* Transmitter enable */
282 #define LEON_REG_UART_CTRL_RI 0x00000004 /* Receiver interrupt enable */
283 #define LEON_REG_UART_CTRL_TI 0x00000008 /* Transmitter interrupt enable */
284 #define LEON_REG_UART_CTRL_PS 0x00000010 /* Parity select */
285 #define LEON_REG_UART_CTRL_PE 0x00000020 /* Parity enable */
286 #define LEON_REG_UART_CTRL_FL 0x00000040 /* Flow control enable */
287 #define LEON_REG_UART_CTRL_LB 0x00000080 /* Loop Back enable */
288
289 #define LEON3_GPTIMER_EN 1
290 #define LEON3_GPTIMER_RL 2
291 #define LEON3_GPTIMER_LD 4
292 #define LEON3_GPTIMER_IRQEN 8
293 #define LEON3_GPTIMER_IP 0x10
294
295 #define LEON3_GPTIMER_CONFIG_TIMERMASK 0x7
296 #define LEON3_GPTIMER_CONFIG_SEPERATE (1<<8)
297
298 typedef struct
299 {
300 volatile unsigned int ilevel;
301 volatile unsigned int ipend;
302 volatile unsigned int iforce;
303 volatile unsigned int iclear;
304 volatile unsigned int notused00;
305 volatile unsigned int notused01;
306 volatile unsigned int notused02;
307 volatile unsigned int notused03;
308 volatile unsigned int notused10;
309 volatile unsigned int notused11;
310 volatile unsigned int notused12;
311 volatile unsigned int notused13;
312 volatile unsigned int notused20;
313 volatile unsigned int notused21;
314 volatile unsigned int notused22;
315 volatile unsigned int notused23;
316 volatile unsigned int mask[16];
317 } LEON3_IrqCtrl_Regs_Map;
318 extern volatile LEON3_IrqCtrl_Regs_Map *LEON3_IrqCtrl_Regs; /* in amba.c */
319
320 typedef struct
321 {
322 volatile unsigned int data;
323 volatile unsigned int status;
324 volatile unsigned int ctrl;
325 volatile unsigned int scaler;
326 } LEON23_APBUART_Regs_Map;
327 extern volatile LEON23_APBUART_Regs_Map *leon23_uarts[2]; /* in console.c */
328 extern unsigned int leon23_irqs[2]; /* in console.c */
329
330 typedef struct
331 {
332 volatile unsigned int val;
333 volatile unsigned int rld;
334 volatile unsigned int ctrl;
335 volatile unsigned int unused;
336 } LEON3_GpTimerElem_Regs_Map;
337
338
339 typedef struct
340 {
341 volatile unsigned int scalar;
342 volatile unsigned int scalar_reload;
343 volatile unsigned int config;
344 volatile unsigned int unused;
345 volatile LEON3_GpTimerElem_Regs_Map e[8];
346 } LEON3_GpTimer_Regs_Map;
347 #define LEON3_GPTIMER_CONFIG_NRTIMERS(c) ((c)->config & 0x7)
348 int Timer_getTimer1 (unsigned int **count, unsigned int **reload, unsigned int **ctrl); /* in timer.c */
349 int Timer_getTimer2 (unsigned int **count, unsigned int **reload, unsigned int **ctrl); /* in timer.c */
350 extern volatile LEON3_GpTimer_Regs_Map *LEON3_GpTimer_Regs;
351 extern unsigned long LEON3_GpTimer_Irq;
352
353 typedef struct
354 {
355 volatile unsigned int iodata;
356 volatile unsigned int ioout;
357 volatile unsigned int iodir;
358 volatile unsigned int irqmask;
359 volatile unsigned int irqpol;
360 volatile unsigned int irqedge;
361 } LEON3_IOPORT_Regs_Map;
362
363
364 /*
365 * Types and structure used for AMBA Plug & Play bus scanning
366 */
367 extern int amba_init_done;
368
369 #define AMBA_MAXAPB_DEVS 64
370 #define AMBA_MAXAPB_DEVS_PERBUS 16
371
372 typedef struct amba_device_table
373 {
374 int devnr; /* numbrer of devices on AHB or APB bus */
375 unsigned int *addr[16]; /* addresses to the devices configuration tables */
376 unsigned int allocbits[1]; /* 0=unallocated, 1=allocated driver */
377 } amba_device_table;
378
379 typedef struct amba_apbslv_device_table
380 {
381 int devnr; /* number of devices on AHB or APB bus */
382 unsigned int *addr[AMBA_MAXAPB_DEVS]; /* addresses to the devices configuration tables */
383 unsigned int apbmst[AMBA_MAXAPB_DEVS]; /* apb master if a entry is a apb slave */
384 unsigned int apbmstidx[AMBA_MAXAPB_DEVS]; /* apb master idx if a entry is a apb slave */
385 unsigned int allocbits[4]; /* 0=unallocated, 1=allocated driver */
386 } amba_apbslv_device_table;
387
388 typedef struct amba_confarea_type
389 {
390 amba_device_table ahbmst;
391 amba_device_table ahbslv;
392 amba_apbslv_device_table apbslv;
393 /*unsigned int apbmst; */
394 } amba_confarea_type;
395
396
397 extern unsigned long amba_find_apbslv_addr (unsigned long vendor,
398 unsigned long device,
399 unsigned long *irq);
400
401 // collect apb slaves
402 typedef struct amba_apb_device
403 {
404 unsigned int start, irq;
405 } amba_apb_device;
406 extern int amba_get_free_apbslv_devices (int vendor, int device,
407 amba_apb_device * dev, int nr);
408
409 // collect ahb slaves
410 typedef struct amba_ahb_device
411 {
412 unsigned int start[4], irq;
413 } amba_ahb_device;
414 extern int amba_get_free_ahbslv_devices (int vendor, int device,
415 amba_ahb_device * dev, int nr);
416
417
418 /*amba_scan.c*/
419 unsigned int leon3_getapbbase (register unsigned int vendor,
420 register unsigned int driver,
421 amba_apb_device * apbdevs, int c);
422
423 #endif //!__ASSEMBLER__
424
425
426
427
428
429 #endif
430