1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup raspberrypi |
---|
7 | * |
---|
8 | * @brief Raspberry pi secondary CPU and IPI HW initialization |
---|
9 | */ |
---|
10 | |
---|
11 | /* |
---|
12 | * Copyright (c) 2016 Pavel Pisa <pisa@cmp.felk.cvut.cz> |
---|
13 | * |
---|
14 | * Czech Technical University in Prague |
---|
15 | * Zikova 1903/4 |
---|
16 | * 166 36 Praha 6 |
---|
17 | * Czech Republic |
---|
18 | * |
---|
19 | * Reuses some ideas from Rohini Kulkarni <krohini1593@gmail.com> |
---|
20 | * GSoC 2015 project and Altera Cyclone-V SMP code |
---|
21 | * by embedded brains GmbH |
---|
22 | * |
---|
23 | * Redistribution and use in source and binary forms, with or without |
---|
24 | * modification, are permitted provided that the following conditions |
---|
25 | * are met: |
---|
26 | * 1. Redistributions of source code must retain the above copyright |
---|
27 | * notice, this list of conditions and the following disclaimer. |
---|
28 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
29 | * notice, this list of conditions and the following disclaimer in the |
---|
30 | * documentation and/or other materials provided with the distribution. |
---|
31 | * |
---|
32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
33 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
34 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
35 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
36 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
37 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
38 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
39 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
40 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
41 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
42 | * POSSIBILITY OF SUCH DAMAGE. |
---|
43 | */ |
---|
44 | |
---|
45 | #include <rtems/score/smpimpl.h> |
---|
46 | |
---|
47 | #include <bsp/start.h> |
---|
48 | #include <bsp/raspberrypi.h> |
---|
49 | #include <bsp.h> |
---|
50 | #include <bsp/arm-cp15-start.h> |
---|
51 | #include <libcpu/arm-cp15.h> |
---|
52 | #include <rtems.h> |
---|
53 | #include <bsp/irq-generic.h> |
---|
54 | #include <assert.h> |
---|
55 | |
---|
56 | void rpi_ipi_initialize(void) |
---|
57 | { |
---|
58 | uint32_t cpu_index_self = _SMP_Get_current_processor(); |
---|
59 | |
---|
60 | /* |
---|
61 | * Includes support only for mailbox 3 interrupt. |
---|
62 | * Further interrupt support has to be added. This will have to be integrated |
---|
63 | * with existing interrupt support for Raspberry Pi |
---|
64 | */ |
---|
65 | |
---|
66 | /* reset mailbox 3 contents to zero */ |
---|
67 | BCM2835_REG(BCM2836_MAILBOX_3_READ_CLEAR_BASE + 0x10 * cpu_index_self) = 0xffffffff; |
---|
68 | |
---|
69 | BCM2835_REG(BCM2836_MAILBOX_IRQ_CTRL(cpu_index_self)) = |
---|
70 | BCM2836_MAILBOX_IRQ_CTRL_MBOX3_IRQ; |
---|
71 | } |
---|
72 | |
---|
73 | void rpi_start_rtems_on_secondary_processor(void) |
---|
74 | { |
---|
75 | uint32_t ctrl; |
---|
76 | |
---|
77 | /* Change the VBAR from the start to the normal vector table */ |
---|
78 | arm_cp15_set_vector_base_address(bsp_vector_table_begin); |
---|
79 | |
---|
80 | ctrl = arm_cp15_start_setup_mmu_and_cache( |
---|
81 | 0, |
---|
82 | ARM_CP15_CTRL_AFE | ARM_CP15_CTRL_Z |
---|
83 | ); |
---|
84 | |
---|
85 | rpi_ipi_initialize(); |
---|
86 | |
---|
87 | arm_cp15_set_domain_access_control( |
---|
88 | ARM_CP15_DAC_DOMAIN(ARM_MMU_DEFAULT_CLIENT_DOMAIN, ARM_CP15_DAC_CLIENT) |
---|
89 | ); |
---|
90 | |
---|
91 | /* FIXME: Sharing the translation table between processors is brittle */ |
---|
92 | arm_cp15_set_translation_table_base( |
---|
93 | (uint32_t *) bsp_translation_table_base |
---|
94 | ); |
---|
95 | |
---|
96 | ctrl |= ARM_CP15_CTRL_I | ARM_CP15_CTRL_C | ARM_CP15_CTRL_M; |
---|
97 | ctrl &= ~ARM_CP15_CTRL_V; |
---|
98 | arm_cp15_set_control(ctrl); |
---|
99 | |
---|
100 | _SMP_Start_multitasking_on_secondary_processor(_Per_CPU_Get()); |
---|
101 | } |
---|