xref: /rk3399_ARM-atf/plat/rockchip/common/rockchip_gicv2.c (revision 6fba6e0490584036fe1210986d6db439b22cb03e)
1*6fba6e04STony Xie /*
2*6fba6e04STony Xie  * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
3*6fba6e04STony Xie  *
4*6fba6e04STony Xie  * Redistribution and use in source and binary forms, with or without
5*6fba6e04STony Xie  * modification, are permitted provided that the following conditions are met:
6*6fba6e04STony Xie  *
7*6fba6e04STony Xie  * Redistributions of source code must retain the above copyright notice, this
8*6fba6e04STony Xie  * list of conditions and the following disclaimer.
9*6fba6e04STony Xie  *
10*6fba6e04STony Xie  * Redistributions in binary form must reproduce the above copyright notice,
11*6fba6e04STony Xie  * this list of conditions and the following disclaimer in the documentation
12*6fba6e04STony Xie  * and/or other materials provided with the distribution.
13*6fba6e04STony Xie  *
14*6fba6e04STony Xie  * Neither the name of ARM nor the names of its contributors may be used
15*6fba6e04STony Xie  * to endorse or promote products derived from this software without specific
16*6fba6e04STony Xie  * prior written permission.
17*6fba6e04STony Xie  *
18*6fba6e04STony Xie  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19*6fba6e04STony Xie  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*6fba6e04STony Xie  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*6fba6e04STony Xie  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22*6fba6e04STony Xie  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23*6fba6e04STony Xie  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24*6fba6e04STony Xie  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*6fba6e04STony Xie  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*6fba6e04STony Xie  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27*6fba6e04STony Xie  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28*6fba6e04STony Xie  * POSSIBILITY OF SUCH DAMAGE.
29*6fba6e04STony Xie  */
30*6fba6e04STony Xie 
31*6fba6e04STony Xie #include <bl_common.h>
32*6fba6e04STony Xie #include <gicv2.h>
33*6fba6e04STony Xie #include <platform_def.h>
34*6fba6e04STony Xie 
35*6fba6e04STony Xie /******************************************************************************
36*6fba6e04STony Xie  * The following functions are defined as weak to allow a platform to override
37*6fba6e04STony Xie  * the way the GICv2 driver is initialised and used.
38*6fba6e04STony Xie  *****************************************************************************/
39*6fba6e04STony Xie #pragma weak plat_rockchip_gic_driver_init
40*6fba6e04STony Xie #pragma weak plat_rockchip_gic_init
41*6fba6e04STony Xie #pragma weak plat_rockchip_gic_cpuif_enable
42*6fba6e04STony Xie #pragma weak plat_rockchip_gic_cpuif_disable
43*6fba6e04STony Xie #pragma weak plat_rockchip_gic_pcpu_init
44*6fba6e04STony Xie 
45*6fba6e04STony Xie /******************************************************************************
46*6fba6e04STony Xie  * On a GICv2 system, the Group 1 secure interrupts are treated as Group 0
47*6fba6e04STony Xie  * interrupts.
48*6fba6e04STony Xie  *****************************************************************************/
49*6fba6e04STony Xie const unsigned int g0_interrupt_array[] = {
50*6fba6e04STony Xie 	PLAT_RK_G1S_IRQS,
51*6fba6e04STony Xie };
52*6fba6e04STony Xie 
53*6fba6e04STony Xie /*
54*6fba6e04STony Xie  * Ideally `rockchip_gic_data` structure definition should be a `const` but it
55*6fba6e04STony Xie  * is kept as modifiable for overwriting with different GICD and GICC base when
56*6fba6e04STony Xie  * running on FVP with VE memory map.
57*6fba6e04STony Xie  */
58*6fba6e04STony Xie gicv2_driver_data_t rockchip_gic_data = {
59*6fba6e04STony Xie 	.gicd_base = PLAT_RK_GICD_BASE,
60*6fba6e04STony Xie 	.gicc_base = PLAT_RK_GICC_BASE,
61*6fba6e04STony Xie 	.g0_interrupt_num = ARRAY_SIZE(g0_interrupt_array),
62*6fba6e04STony Xie 	.g0_interrupt_array = g0_interrupt_array,
63*6fba6e04STony Xie };
64*6fba6e04STony Xie 
65*6fba6e04STony Xie /******************************************************************************
66*6fba6e04STony Xie  * RockChip common helper to initialize the GICv2 only driver.
67*6fba6e04STony Xie  *****************************************************************************/
68*6fba6e04STony Xie void plat_rockchip_gic_driver_init(void)
69*6fba6e04STony Xie {
70*6fba6e04STony Xie 	gicv2_driver_init(&rockchip_gic_data);
71*6fba6e04STony Xie }
72*6fba6e04STony Xie 
73*6fba6e04STony Xie void plat_rockchip_gic_init(void)
74*6fba6e04STony Xie {
75*6fba6e04STony Xie 	gicv2_distif_init();
76*6fba6e04STony Xie 	gicv2_pcpu_distif_init();
77*6fba6e04STony Xie 	gicv2_cpuif_enable();
78*6fba6e04STony Xie }
79*6fba6e04STony Xie 
80*6fba6e04STony Xie /******************************************************************************
81*6fba6e04STony Xie  * RockChip common helper to enable the GICv2 CPU interface
82*6fba6e04STony Xie  *****************************************************************************/
83*6fba6e04STony Xie void plat_rockchip_gic_cpuif_enable(void)
84*6fba6e04STony Xie {
85*6fba6e04STony Xie 	gicv2_cpuif_enable();
86*6fba6e04STony Xie }
87*6fba6e04STony Xie 
88*6fba6e04STony Xie /******************************************************************************
89*6fba6e04STony Xie  * RockChip common helper to disable the GICv2 CPU interface
90*6fba6e04STony Xie  *****************************************************************************/
91*6fba6e04STony Xie void plat_rockchip_gic_cpuif_disable(void)
92*6fba6e04STony Xie {
93*6fba6e04STony Xie 	gicv2_cpuif_disable();
94*6fba6e04STony Xie }
95*6fba6e04STony Xie 
96*6fba6e04STony Xie /******************************************************************************
97*6fba6e04STony Xie  * RockChip common helper to initialize the per cpu distributor interface
98*6fba6e04STony Xie  * in GICv2
99*6fba6e04STony Xie  *****************************************************************************/
100*6fba6e04STony Xie void plat_rockchip_gic_pcpu_init(void)
101*6fba6e04STony Xie {
102*6fba6e04STony Xie 	gicv2_pcpu_distif_init();
103*6fba6e04STony Xie }
104