source: rtems/bsps/arm/raspberrypi/start/bspstart.c

Last change on this file was bb8ae78, checked in by Christian Mauderer <christian.mauderer@…>, on 03/09/20 at 22:00:58

bsp/raspberry: Add a bsp_fdt_map_intr().

Fixes #3903

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup arm_start
5 *
6 * @brief Raspberry pi startup code.
7 */
8
9/*
10 * Copyright (c) 2013 by Alan Cudmore
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *
15 *  http://www.rtems.org/license/LICENSE
16 */
17
18#include <bsp.h>
19#include <bsp/bootcard.h>
20#include <bsp/irq-generic.h>
21#include <bsp/irq.h>
22#include <bsp/linker-symbols.h>
23#include <bsp/stackalloc.h>
24#include <bsp/raspberrypi.h>
25#include <bsp/vc.h>
26#include <bsp/fdt.h>
27
28#include <libfdt.h>
29
30static const struct {
31    uint32_t code;
32    const char* label;
33} rpi_codes[] =
34{
35    { 0x900021, "A+ 1.1 (512MB)" },
36    { 0x900032, "B+ 1.2 (512MB)" },
37    { 0x900092, "Zero 1.2 (512MB)" },
38    { 0x900093, "Zero 1.3 (512MB)" },
39    { 0x9000c1, "Zero W 1.1 (512MB)" },
40    { 0x9020e0, "3A+ 1.0 (512MB)" },
41    { 0x920092, "Zero 1.2 (512MB)" },
42    { 0x920093, "Zero 1.3 (512MB)" },
43    { 0x900061, "CM 1.1 (512MB)" },
44    { 0xa01040, "2B 1.0 (1GB)" },
45    { 0xa01041, "2B 1.1 (1GB)" },
46    { 0xa02082, "3B 1.2 (1GB)" },
47    { 0xa020a0, "CM3 1.0 (1GB)" },
48    { 0xa020d3, "3B+ 1.3 (1GB)" },
49    { 0xa21041, "2B 1.1 (1GB)" },
50    { 0xa22042, "2B 1,2 (with BCM2837) (1GB)" },
51    { 0xa22082, "3B 1.2 (1GB)" },
52    { 0xa220a0, "CM3 1.0 (1GB)" },
53    { 0xa32082, "3B 1.2 (1GB)" },
54    { 0xa52082, "3B 1.2 (1GB)" },
55    { 0xa22083, "3B 1.3 (1GB)" },
56    { 0xa02100, "CM3+ 1.0 (1GB)" },
57    { 0xa03111, "4B 1.1 (1GB)" },
58    { 0xb03111, "4B 1.1 (2GB)" },
59    { 0xc03111, "4B 1.1 (4GB)" },
60};
61
62static const char* rpi_types[] = {
63    "A",
64    "B",
65    "A+",
66    "B+",
67    "2B",
68    "Alpha (early prototype)",
69    "CM1",
70    "3B",
71    "Zero",
72    "CM3",
73    "Zero W",
74    "3B+",
75    "3A+",
76    "Internal use only",
77    "CM3+",
78    "4B",
79};
80
81static const char* rpi_mem[] =
82{
83    "256MB",
84    "512MB",
85    "1GB",
86    "2GB",
87    "4GB"
88};
89
90#define NUMOF(_s) (sizeof(_s) / sizeof(_s[0]))
91
92void *raspberrypi_get_reg_of_node(const void *fdt, int node)
93{
94  int len;
95  const uint32_t *val;
96
97  val = fdt_getprop(fdt, node, "reg", &len);
98  if (val == NULL || len < 4) {
99    return NULL;
100  }
101
102  return (BUS_TO_PHY((void *) fdt32_to_cpu(val[0])));
103}
104
105#ifdef BSP_FDT_IS_SUPPORTED
106uint32_t bsp_fdt_map_intr(const uint32_t *intr, size_t icells)
107{
108  uint32_t controller = intr[0];
109  uint32_t source = intr[1];
110
111  switch ( controller ) {
112    case 0:
113        return source + BCM2835_IRQ_ID_BASIC_BASE_ID;
114        break;
115    case 1:
116        return source + BCM2835_IRQ_SET1_MIN;
117        break;
118    case 2:
119        return source + BCM2835_IRQ_SET2_MIN;
120        break;
121    default:
122        return BSP_INTERRUPT_VECTOR_INVALID;
123        break;
124  }
125}
126#endif /* BSP_FDT_IS_SUPPORTED */
127
128void bsp_start(void)
129{
130    bcm2835_get_board_spec_entries spec = { 0 };
131
132    printk("\nRTEMS RPi ");
133    if (bcm2835_mailbox_get_board_revision( &spec ) >= 0) {
134        size_t i;
135        for (i = 0; i < NUMOF(rpi_codes); ++i) {
136            if (rpi_codes[i].code == spec.spec) {
137                printk("%s [%08x]", rpi_codes[i].label, spec.spec);
138                break;
139            }
140        }
141        if (i >= NUMOF(rpi_codes)) {
142            uint32_t type = (spec.spec >> 4) & 0xff;
143            uint32_t mem = (spec.spec >> (4 + 4 + 8 + 4)) & 0xf;
144            printk(" unknown code [%08x] ", spec.spec);
145            if (type < NUMOF(rpi_types))
146                printk(rpi_types[type]);
147            else
148                printk("type: %02x", type);
149            if (mem < NUMOF(rpi_mem))
150                printk(" %s", rpi_mem[mem]);
151            else
152                printk(" mem: %x", mem);
153        }
154        printk("\n");
155    }
156    else {
157        printk(": ERROR reading mailbox\n");
158    }
159
160    bsp_interrupt_initialize();
161}
Note: See TracBrowser for help on using the repository browser.