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.org/license/LICENSE. |
---|
12 | */ |
---|
13 | |
---|
14 | #include <bsp.h> |
---|
15 | #include <bsp/fatal.h> |
---|
16 | #include <leon.h> |
---|
17 | #include <ambapp.h> |
---|
18 | |
---|
19 | unsigned int leon3_timer_prescaler __attribute__((weak)) = 0; |
---|
20 | int leon3_timer_core_index __attribute__((weak)) = 0; |
---|
21 | |
---|
22 | /* AMBA Plug&Play information description. |
---|
23 | * |
---|
24 | * After software has scanned AMBA PnP it builds a tree to make |
---|
25 | * it easier for drivers to work with the bus architecture. |
---|
26 | */ |
---|
27 | struct ambapp_bus ambapp_plb; |
---|
28 | |
---|
29 | /* If RTEMS_DRVMGR_STARTUP is defined extra code is added that |
---|
30 | * registers the GRLIB AMBA PnP bus driver as root driver. |
---|
31 | */ |
---|
32 | #ifdef RTEMS_DRVMGR_STARTUP |
---|
33 | #include <drvmgr/drvmgr.h> |
---|
34 | #include <drvmgr/ambapp_bus_grlib.h> |
---|
35 | |
---|
36 | extern void gptimer_register_drv (void); |
---|
37 | extern void apbuart_cons_register_drv(void); |
---|
38 | /* All drivers included by BSP, this is overridden by the user by including |
---|
39 | * the drvmgr_confdefs.h. By default the Timer and UART driver are included. |
---|
40 | */ |
---|
41 | struct drvmgr_drv_reg_func drvmgr_drivers[] __attribute__((weak)) = |
---|
42 | { |
---|
43 | {gptimer_register_drv}, |
---|
44 | {apbuart_cons_register_drv}, |
---|
45 | {NULL} /* End array with NULL */ |
---|
46 | }; |
---|
47 | |
---|
48 | /* Driver resources configuration for AMBA root bus. It is declared weak |
---|
49 | * so that the user may override it, if the defualt settings are not |
---|
50 | * enough. |
---|
51 | */ |
---|
52 | struct drvmgr_bus_res grlib_drv_resources __attribute__((weak)) = |
---|
53 | { |
---|
54 | .next = NULL, |
---|
55 | .resource = |
---|
56 | { |
---|
57 | RES_EMPTY, |
---|
58 | } |
---|
59 | }; |
---|
60 | |
---|
61 | /* GRLIB AMBA bus configuration (the LEON3 root bus configuration) */ |
---|
62 | struct grlib_config grlib_bus_config = |
---|
63 | { |
---|
64 | &ambapp_plb, /* AMBAPP bus setup */ |
---|
65 | &grlib_drv_resources, /* Driver configuration */ |
---|
66 | }; |
---|
67 | #endif |
---|
68 | |
---|
69 | rtems_interrupt_lock LEON3_IrqCtrl_Lock = |
---|
70 | RTEMS_INTERRUPT_LOCK_INITIALIZER("LEON3 IrqCtrl"); |
---|
71 | |
---|
72 | /* Pointers to Interrupt Controller configuration registers */ |
---|
73 | volatile struct irqmp_regs *LEON3_IrqCtrl_Regs; |
---|
74 | struct ambapp_dev *irqmp_dev; |
---|
75 | struct ambapp_dev *timer_dev; |
---|
76 | |
---|
77 | /* |
---|
78 | * amba_initialize |
---|
79 | * |
---|
80 | * Must be called just before drivers are initialized. |
---|
81 | * Used to scan system bus. Probes for AHB masters, AHB slaves and |
---|
82 | * APB slaves. Addresses to configuration areas of the AHB masters, |
---|
83 | * AHB slaves, APB slaves and APB master are storeds in |
---|
84 | * amba_ahb_masters, amba_ahb_slaves and amba. |
---|
85 | */ |
---|
86 | |
---|
87 | void amba_initialize(void) |
---|
88 | { |
---|
89 | int icsel; |
---|
90 | struct ambapp_dev *adev; |
---|
91 | |
---|
92 | /* Scan AMBA Plug&Play read-only information. The routine builds a PnP |
---|
93 | * tree into ambapp_plb in RAM, after this we never access the PnP |
---|
94 | * information in hardware directly any more. |
---|
95 | * Since on Processor Local Bus (PLB) memory mapping is 1:1 |
---|
96 | */ |
---|
97 | ambapp_scan(&ambapp_plb, LEON3_IO_AREA, NULL, NULL); |
---|
98 | |
---|
99 | /* Find LEON3 Interrupt controller */ |
---|
100 | adev = (void *)ambapp_for_each(&ambapp_plb, (OPTIONS_ALL|OPTIONS_APB_SLVS), |
---|
101 | VENDOR_GAISLER, GAISLER_IRQMP, |
---|
102 | ambapp_find_by_idx, NULL); |
---|
103 | if (adev == NULL) { |
---|
104 | /* PANIC IRQ controller not found! |
---|
105 | * |
---|
106 | * What else can we do but stop ... |
---|
107 | */ |
---|
108 | bsp_fatal(LEON3_FATAL_NO_IRQMP_CONTROLLER); |
---|
109 | } |
---|
110 | |
---|
111 | LEON3_IrqCtrl_Regs = (volatile struct irqmp_regs *)DEV_TO_APB(adev)->start; |
---|
112 | irqmp_dev = adev; |
---|
113 | if ((LEON3_IrqCtrl_Regs->ampctrl >> 28) > 0) { |
---|
114 | /* IRQ Controller has support for multiple IRQ Controllers, each |
---|
115 | * CPU can be routed to different Controllers, we find out which |
---|
116 | * controller by looking at the IRQCTRL Select Register for this CPU. |
---|
117 | * Each Controller is located at a 4KByte offset. |
---|
118 | */ |
---|
119 | icsel = LEON3_IrqCtrl_Regs->icsel[LEON3_Cpu_Index/8]; |
---|
120 | icsel = (icsel >> ((7 - (LEON3_Cpu_Index & 0x7)) * 4)) & 0xf; |
---|
121 | LEON3_IrqCtrl_Regs += icsel; |
---|
122 | } |
---|
123 | LEON3_IrqCtrl_Regs->mask[LEON3_Cpu_Index] = 0; |
---|
124 | LEON3_IrqCtrl_Regs->force[LEON3_Cpu_Index] = 0; |
---|
125 | LEON3_IrqCtrl_Regs->iclear = 0xffffffff; |
---|
126 | |
---|
127 | /* Init Extended IRQ controller if available */ |
---|
128 | leon3_ext_irq_init(); |
---|
129 | |
---|
130 | /* If we are running without Driver Manager at startup, we must still |
---|
131 | * assure that Timer and Console UART is working. So we can not |
---|
132 | * depend on the DrvMgr capable Timer and Console UART drivers, |
---|
133 | * instead we use the small-footprint drivers. |
---|
134 | */ |
---|
135 | #ifndef RTEMS_DRVMGR_STARTUP |
---|
136 | /* find GP Timer */ |
---|
137 | adev = (void *)ambapp_for_each(&ambapp_plb, (OPTIONS_ALL|OPTIONS_APB_SLVS), |
---|
138 | VENDOR_GAISLER, GAISLER_GPTIMER, |
---|
139 | ambapp_find_by_idx, &leon3_timer_core_index); |
---|
140 | if (adev) { |
---|
141 | LEON3_Timer_Regs = (volatile struct gptimer_regs *)DEV_TO_APB(adev)->start; |
---|
142 | timer_dev = adev; |
---|
143 | |
---|
144 | /* Register AMBA Bus Frequency */ |
---|
145 | ambapp_freq_init( |
---|
146 | &ambapp_plb, |
---|
147 | timer_dev, |
---|
148 | (LEON3_Timer_Regs->scaler_reload + 1) |
---|
149 | * LEON3_GPTIMER_0_FREQUENCY_SET_BY_BOOT_LOADER |
---|
150 | ); |
---|
151 | /* Set user prescaler configuration. Use this to increase accuracy of timer |
---|
152 | * and accociated services like cpucounter. |
---|
153 | * Note that minimum value is the number of timer instances present in |
---|
154 | * GRTIMER/GPTIMER hardware. See HW manual. |
---|
155 | */ |
---|
156 | if (leon3_timer_prescaler) |
---|
157 | LEON3_Timer_Regs->scaler_reload = leon3_timer_prescaler; |
---|
158 | } |
---|
159 | #else |
---|
160 | /* Register Root bus, Use GRLIB AMBA PnP bus as root bus for LEON3 */ |
---|
161 | ambapp_grlib_root_register(&grlib_bus_config); |
---|
162 | #endif |
---|
163 | } |
---|