source: rtems/bsps/arm/imx/start/bspstart.c @ c561bf4c

5
Last change on this file since c561bf4c was c561bf4c, checked in by Christian Mauderer <christian.mauderer@…>, on Feb 10, 2020 at 9:35:12 AM

bsp/imx: Allow GIC in different device tree node.

Update #3869.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 * Copyright (c) 2017 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <info@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#include <bsp.h>
16#include <bsp/bootcard.h>
17#include <bsp/fatal.h>
18#include <bsp/fdt.h>
19#include <bsp/irq-generic.h>
20#include <bsp/linker-symbols.h>
21
22#include <libfdt.h>
23
24#define MAGIC_IRQ_OFFSET 32
25
26void *imx_get_reg_of_node(const void *fdt, int node)
27{
28  int len;
29  const uint32_t *val;
30
31  val = fdt_getprop(fdt, node, "reg", &len);
32  if (val == NULL || len < 4) {
33    return NULL;
34  }
35
36  return (void *) fdt32_to_cpu(val[0]);
37}
38
39rtems_vector_number imx_get_irq_of_node(
40  const void *fdt,
41  int node,
42  size_t index
43)
44{
45  int len;
46  const uint32_t *val;
47
48  val = fdt_getprop(fdt, node, "interrupts", &len);
49  if (val == NULL || len < (int) ((index + 1) * 12)) {
50    return UINT32_MAX;
51  }
52
53  return fdt32_to_cpu(val[index * 3 + 1]) + MAGIC_IRQ_OFFSET;
54}
55
56uint32_t bsp_fdt_map_intr(const uint32_t *intr, size_t icells)
57{
58  return intr[1] + MAGIC_IRQ_OFFSET;
59}
60
61void arm_generic_timer_get_config(
62  uint32_t *frequency,
63  uint32_t *irq
64)
65{
66  const void *fdt;
67  int node;
68  int len;
69  const uint32_t *val;
70
71  fdt = bsp_fdt_get();
72  node = fdt_path_offset(fdt, "/timer");
73
74  val = fdt_getprop(fdt, node, "clock-frequency", &len);
75  if (val != NULL && len >= 4) {
76    *frequency = fdt32_to_cpu(val[0]);
77  } else {
78    bsp_fatal(IMX_FATAL_GENERIC_TIMER_FREQUENCY);
79  }
80
81  /* FIXME: Figure out how Linux gets a proper IRQ number */
82  *irq = imx_get_irq_of_node(fdt, node, 0) - 16;
83}
84
85uintptr_t imx_gic_dist_base;
86
87static void imx_find_gic(const void *fdt)
88{
89  int node;
90
91  node = fdt_path_offset(fdt, "/interrupt-controller");
92  if (node < 0) {
93    node = fdt_path_offset(fdt, "/soc/interrupt-controller");
94  }
95  imx_gic_dist_base = (uintptr_t) imx_get_reg_of_node(fdt, node);
96}
97
98void bsp_start(void)
99{
100  imx_find_gic(bsp_fdt_get());
101  bsp_interrupt_initialize();
102  rtems_cache_coherent_add_area(
103    bsp_section_nocacheheap_begin,
104    (uintptr_t) bsp_section_nocacheheap_size
105  );
106}
Note: See TracBrowser for help on using the repository browser.