source: rtems/c/src/lib/libbsp/sparc/leon3/amba/amba.c @ 7579e25

4.115
Last change on this file since 7579e25 was 7579e25, checked in by Sebastian Huber <sebastian.huber@…>, on 11/25/13 at 07:46:19

bsp/leon3: New BSP variant leon3_qemu

  • Property mode set to 100644
File size: 3.2 KB
Line 
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 */
22struct ambapp_bus ambapp_plb;
23
24/* GRLIB extended IRQ controller register */
25extern void leon3_ext_irq_init(void);
26
27/* Pointers to Interrupt Controller configuration registers */
28volatile 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
40void amba_initialize(void)
41{
42#ifndef LEON3_QEMU
43  int icsel;
44  struct ambapp_dev *adev;
45
46  /* Scan AMBA Plug&Play read-only information. The routine builds a PnP
47   * tree into ambapp_plb in RAM, after this we never access the PnP
48   * information in hardware directly any more.
49   * Since on Processor Local Bus (PLB) memory mapping is 1:1
50   */
51  ambapp_scan(&ambapp_plb, LEON3_IO_AREA, NULL, NULL);
52
53  /* Find LEON3 Interrupt controller */
54  adev = (void *)ambapp_for_each(&ambapp_plb, (OPTIONS_ALL|OPTIONS_APB_SLVS),
55                                 VENDOR_GAISLER, GAISLER_IRQMP,
56                                 ambapp_find_by_idx, NULL);
57  if (adev == NULL) {
58    /* PANIC IRQ controller not found!
59     *
60     *  What else can we do but stop ...
61     */
62    asm volatile( "mov 1, %g1; ta 0x0" );
63  }
64
65  LEON3_IrqCtrl_Regs = (volatile struct irqmp_regs *)DEV_TO_APB(adev)->start;
66  if ((LEON3_IrqCtrl_Regs->ampctrl >> 28) > 0) {
67    /* IRQ Controller has support for multiple IRQ Controllers, each
68     * CPU can be routed to different Controllers, we find out which
69     * controller by looking at the IRQCTRL Select Register for this CPU.
70     * Each Controller is located at a 4KByte offset.
71     */
72    icsel = LEON3_IrqCtrl_Regs->icsel[LEON3_Cpu_Index/8];
73    icsel = (icsel >> ((7 - (LEON3_Cpu_Index & 0x7)) * 4)) & 0xf;
74    LEON3_IrqCtrl_Regs += icsel;
75    LEON3_IrqCtrl_Regs->mask[LEON3_Cpu_Index] = 0;
76    LEON3_IrqCtrl_Regs->force[LEON3_Cpu_Index] = 0;
77    LEON3_IrqCtrl_Regs->iclear = 0xffffffff;
78  }
79
80  /* Init Extended IRQ controller if available */
81  leon3_ext_irq_init();
82
83  /* find GP Timer */
84  adev = (void *)ambapp_for_each(&ambapp_plb, (OPTIONS_ALL|OPTIONS_APB_SLVS),
85                                 VENDOR_GAISLER, GAISLER_GPTIMER,
86                                 ambapp_find_by_idx, NULL);
87  if (adev) {
88    LEON3_Timer_Regs = (volatile struct gptimer_regs *)DEV_TO_APB(adev)->start;
89
90    /* Register AMBA Bus Frequency */
91    ambapp_freq_init(&ambapp_plb, adev,
92                     (LEON3_Timer_Regs->scaler_reload + 1) * 1000000);
93  }
94#else /* LEON3_QEMU */
95  LEON3_IrqCtrl_Regs = (volatile struct irqmp_regs *)0x80000200;
96#endif /* LEON3_QEMU */
97}
Note: See TracBrowser for help on using the repository browser.