source: rtems/c/src/lib/libbsp/powerpc/qoriq/startup/bspstart.c @ 81eced53

5
Last change on this file since 81eced53 was 81eced53, checked in by Sebastian Huber <sebastian.huber@…>, on 01/15/18 at 12:54:45

bsp/qoriq: Fix bsp_fdt_map_intr()

Update #3085.

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup QorIQ
5 *
6 * @brief BSP startup.
7 */
8
9/*
10 * Copyright (c) 2010, 2017 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Dornierstr. 4
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.org/license/LICENSE.
21 */
22
23#include <libfdt.h>
24
25#include <rtems.h>
26#include <rtems/config.h>
27#include <rtems/counter.h>
28
29#include <libcpu/powerpc-utility.h>
30
31#include <bsp.h>
32#include <bsp/bootcard.h>
33#include <bsp/console-termios.h>
34#include <bsp/fatal.h>
35#include <bsp/fdt.h>
36#include <bsp/irq-generic.h>
37#include <bsp/linker-symbols.h>
38#include <bsp/mmu.h>
39#include <bsp/qoriq.h>
40#include <bsp/vectors.h>
41
42LINKER_SYMBOL(bsp_exc_vector_base);
43
44qoriq_start_spin_table *
45qoriq_start_spin_table_addr[QORIQ_CPU_COUNT / QORIQ_THREAD_COUNT];
46
47/* Configuration parameters for console driver, ... */
48unsigned int BSP_bus_frequency;
49
50/* Configuration parameter for clock driver, ... */
51uint32_t bsp_time_base_frequency;
52
53uint32_t qoriq_clock_frequency;
54
55static void initialize_frequency_parameters(void)
56{
57  const void *fdt = bsp_fdt_get();
58  int node;
59  int len;
60  fdt32_t *val_fdt;
61
62  node = fdt_node_offset_by_prop_value(fdt, -1, "device_type", "cpu", 4);
63
64  val_fdt = (fdt32_t *) fdt_getprop(fdt, node, "bus-frequency", &len);
65  if (val_fdt == NULL || len != 4) {
66    bsp_fatal(QORIQ_FATAL_FDT_NO_BUS_FREQUENCY);
67  }
68  BSP_bus_frequency = fdt32_to_cpu(*val_fdt) / QORIQ_BUS_CLOCK_DIVIDER;
69
70  val_fdt = (fdt32_t *) fdt_getprop(fdt, node, "timebase-frequency", &len);
71  if (val_fdt == NULL || len != 4) {
72    bsp_fatal(QORIQ_FATAL_FDT_NO_BUS_FREQUENCY);
73  }
74  bsp_time_base_frequency = fdt32_to_cpu(*val_fdt);
75
76  #ifdef __PPC_CPU_E6500__
77    val_fdt = (fdt32_t *) fdt_getprop(fdt, node, "clock-frequency", &len);
78    if (val_fdt == NULL || len != 4) {
79      bsp_fatal(QORIQ_FATAL_FDT_NO_CLOCK_FREQUENCY);
80    }
81    qoriq_clock_frequency = fdt32_to_cpu(*val_fdt);
82  #endif
83  rtems_counter_initialize_converter(fdt32_to_cpu(*val_fdt));
84}
85
86#define MTIVPR(base) \
87  __asm__ volatile ("mtivpr %0" : : "r" (base))
88
89#ifdef __powerpc64__
90#define VECTOR_TABLE_ENTRY_SIZE 32
91#else
92#define VECTOR_TABLE_ENTRY_SIZE 16
93#endif
94
95#define MTIVOR(vec, offset) \
96  do { \
97    __asm__ volatile ("mtspr " RTEMS_XSTRING(vec) ", %0" : : "r" (offset)); \
98    offset += VECTOR_TABLE_ENTRY_SIZE; \
99  } while (0)
100
101void qoriq_initialize_exceptions(void *interrupt_stack_begin)
102{
103  uintptr_t addr;
104
105  ppc_exc_initialize_interrupt_stack(
106    (uintptr_t) interrupt_stack_begin,
107    rtems_configuration_get_interrupt_stack_size()
108  );
109
110  addr = (uintptr_t) bsp_exc_vector_base;
111  MTIVPR(addr);
112  MTIVOR(BOOKE_IVOR0,  addr);
113  MTIVOR(BOOKE_IVOR1,  addr);
114  MTIVOR(BOOKE_IVOR2,  addr);
115  MTIVOR(BOOKE_IVOR3,  addr);
116  MTIVOR(BOOKE_IVOR4,  addr);
117  MTIVOR(BOOKE_IVOR5,  addr);
118  MTIVOR(BOOKE_IVOR6,  addr);
119#ifdef __PPC_CPU_E6500__
120  MTIVOR(BOOKE_IVOR7,  addr);
121#endif
122  MTIVOR(BOOKE_IVOR8,  addr);
123#ifdef __PPC_CPU_E6500__
124  MTIVOR(BOOKE_IVOR9,  addr);
125#endif
126  MTIVOR(BOOKE_IVOR10, addr);
127  MTIVOR(BOOKE_IVOR11, addr);
128  MTIVOR(BOOKE_IVOR12, addr);
129  MTIVOR(BOOKE_IVOR13, addr);
130  MTIVOR(BOOKE_IVOR14, addr);
131  MTIVOR(BOOKE_IVOR15, addr);
132  MTIVOR(BOOKE_IVOR32, addr);
133  MTIVOR(BOOKE_IVOR33, addr);
134#ifndef __PPC_CPU_E6500__
135  MTIVOR(BOOKE_IVOR34, addr);
136#endif
137  MTIVOR(BOOKE_IVOR35, addr);
138#ifdef __PPC_CPU_E6500__
139  MTIVOR(BOOKE_IVOR36, addr);
140  MTIVOR(BOOKE_IVOR37, addr);
141#ifndef QORIQ_IS_HYPERVISOR_GUEST
142  MTIVOR(BOOKE_IVOR38, addr);
143  MTIVOR(BOOKE_IVOR39, addr);
144  MTIVOR(BOOKE_IVOR40, addr);
145  MTIVOR(BOOKE_IVOR41, addr);
146  MTIVOR(BOOKE_IVOR42, addr);
147#endif
148#endif
149}
150
151void bsp_start(void)
152{
153  /*
154   * Get CPU identification dynamically. Note that the get_ppc_cpu_type() function
155   * store the result in global variables so that it can be used latter...
156   */
157  get_ppc_cpu_type();
158  get_ppc_cpu_revision();
159
160  initialize_frequency_parameters();
161
162  qoriq_initialize_exceptions(bsp_section_work_begin);
163  bsp_interrupt_initialize();
164
165  rtems_cache_coherent_add_area(
166    bsp_section_nocacheheap_begin,
167    (uintptr_t) bsp_section_nocacheheap_size
168  );
169
170#ifndef QORIQ_IS_HYPERVISOR_GUEST
171  /* Disable boot page translation */
172#if QORIQ_CHIP_IS_T_VARIANT(QORIQ_CHIP_VARIANT)
173  qoriq.lcc.bstar &= ~LCC_BSTAR_EN;
174#else
175  qoriq.lcc.bptr &= ~BPTR_EN;
176#endif
177#endif
178}
179
180uint32_t bsp_fdt_map_intr(const uint32_t *intr, size_t icells)
181{
182#ifndef QORIQ_IS_HYPERVISOR_GUEST
183  return intr[0] - 16;
184#else
185  return intr[0];
186#endif
187}
Note: See TracBrowser for help on using the repository browser.