1 | /* |
---|
2 | * AMBA Plug & Play Bus Driver |
---|
3 | * |
---|
4 | * This driver hook performs bus scanning. |
---|
5 | * |
---|
6 | * COPYRIGHT (c) 2011. |
---|
7 | * Aeroflex Gaisler |
---|
8 | * |
---|
9 | * The license and distribution terms for this file may be |
---|
10 | * found in the file LICENSE in this distribution or at |
---|
11 | * http://www.rtems.com/license/LICENSE. |
---|
12 | */ |
---|
13 | |
---|
14 | #include <bsp.h> |
---|
15 | #include <ambapp.h> |
---|
16 | |
---|
17 | /* AMBA Plug&Play information description. |
---|
18 | * |
---|
19 | * After software has scanned AMBA PnP it builds a tree to make |
---|
20 | * it easier for drivers to work with the bus architecture. |
---|
21 | */ |
---|
22 | struct ambapp_bus ambapp_plb; |
---|
23 | |
---|
24 | /* GRLIB extended IRQ controller register */ |
---|
25 | extern void leon3_ext_irq_init(void); |
---|
26 | |
---|
27 | /* Pointers to Interrupt Controller configuration registers */ |
---|
28 | volatile struct irqmp_regs *LEON3_IrqCtrl_Regs; |
---|
29 | |
---|
30 | /* |
---|
31 | * amba_initialize |
---|
32 | * |
---|
33 | * Must be called just before drivers are initialized. |
---|
34 | * Used to scan system bus. Probes for AHB masters, AHB slaves and |
---|
35 | * APB slaves. Addresses to configuration areas of the AHB masters, |
---|
36 | * AHB slaves, APB slaves and APB master are storeds in |
---|
37 | * amba_ahb_masters, amba_ahb_slaves and amba. |
---|
38 | */ |
---|
39 | |
---|
40 | void amba_initialize(void) |
---|
41 | { |
---|
42 | int icsel; |
---|
43 | struct ambapp_dev *adev; |
---|
44 | |
---|
45 | /* Scan AMBA Plug&Play read-only information. The routine builds a PnP |
---|
46 | * tree into ambapp_plb in RAM, after this we never access the PnP |
---|
47 | * information in hardware directly any more. |
---|
48 | * Since on Processor Local Bus (PLB) memory mapping is 1:1 |
---|
49 | */ |
---|
50 | ambapp_scan(&ambapp_plb, LEON3_IO_AREA, NULL, NULL); |
---|
51 | |
---|
52 | /* Find LEON3 Interrupt controller */ |
---|
53 | adev = (void *)ambapp_for_each(&ambapp_plb, (OPTIONS_ALL|OPTIONS_APB_SLVS), |
---|
54 | VENDOR_GAISLER, GAISLER_IRQMP, |
---|
55 | ambapp_find_by_idx, NULL); |
---|
56 | if (adev == NULL) { |
---|
57 | /* PANIC IRQ controller not found! |
---|
58 | * |
---|
59 | * What else can we do but stop ... |
---|
60 | */ |
---|
61 | asm volatile( "mov 1, %g1; ta 0x0" ); |
---|
62 | } |
---|
63 | |
---|
64 | LEON3_IrqCtrl_Regs = (volatile struct irqmp_regs *)DEV_TO_APB(adev)->start; |
---|
65 | if ((LEON3_IrqCtrl_Regs->ampctrl >> 28) > 0) { |
---|
66 | /* IRQ Controller has support for multiple IRQ Controllers, each |
---|
67 | * CPU can be routed to different Controllers, we find out which |
---|
68 | * controller by looking at the IRQCTRL Select Register for this CPU. |
---|
69 | * Each Controller is located at a 4KByte offset. |
---|
70 | */ |
---|
71 | icsel = LEON3_IrqCtrl_Regs->icsel[LEON3_Cpu_Index/8]; |
---|
72 | icsel = (icsel >> ((7 - (LEON3_Cpu_Index & 0x7)) * 4)) & 0xf; |
---|
73 | LEON3_IrqCtrl_Regs += icsel; |
---|
74 | LEON3_IrqCtrl_Regs->mask[LEON3_Cpu_Index] = 0; |
---|
75 | LEON3_IrqCtrl_Regs->force[LEON3_Cpu_Index] = 0; |
---|
76 | LEON3_IrqCtrl_Regs->iclear = 0xffffffff; |
---|
77 | } |
---|
78 | |
---|
79 | /* Init Extended IRQ controller if available */ |
---|
80 | leon3_ext_irq_init(); |
---|
81 | |
---|
82 | /* find GP Timer */ |
---|
83 | adev = (void *)ambapp_for_each(&ambapp_plb, (OPTIONS_ALL|OPTIONS_APB_SLVS), |
---|
84 | VENDOR_GAISLER, GAISLER_GPTIMER, |
---|
85 | ambapp_find_by_idx, NULL); |
---|
86 | if (adev) { |
---|
87 | LEON3_Timer_Regs = (volatile struct gptimer_regs *)DEV_TO_APB(adev)->start; |
---|
88 | |
---|
89 | /* Register AMBA Bus Frequency */ |
---|
90 | ambapp_freq_init(&ambapp_plb, adev, |
---|
91 | (LEON3_Timer_Regs->scaler_reload + 1) * 1000000); |
---|
92 | } |
---|
93 | } |
---|