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