xref: /rk3399_ARM-atf/plat/rockchip/common/rockchip_gicv3.c (revision 3d8256b2a1ef1195aed86bef7378e83d0a61a91b)
16fba6e04STony Xie /*
26fba6e04STony Xie  * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
36fba6e04STony Xie  *
46fba6e04STony Xie  * Redistribution and use in source and binary forms, with or without
56fba6e04STony Xie  * modification, are permitted provided that the following conditions are met:
66fba6e04STony Xie  *
76fba6e04STony Xie  * Redistributions of source code must retain the above copyright notice, this
86fba6e04STony Xie  * list of conditions and the following disclaimer.
96fba6e04STony Xie  *
106fba6e04STony Xie  * Redistributions in binary form must reproduce the above copyright notice,
116fba6e04STony Xie  * this list of conditions and the following disclaimer in the documentation
126fba6e04STony Xie  * and/or other materials provided with the distribution.
136fba6e04STony Xie  *
146fba6e04STony Xie  * Neither the name of ARM nor the names of its contributors may be used
156fba6e04STony Xie  * to endorse or promote products derived from this software without specific
166fba6e04STony Xie  * prior written permission.
176fba6e04STony Xie  *
186fba6e04STony Xie  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
196fba6e04STony Xie  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
206fba6e04STony Xie  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
216fba6e04STony Xie  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
226fba6e04STony Xie  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
236fba6e04STony Xie  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
246fba6e04STony Xie  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
256fba6e04STony Xie  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
266fba6e04STony Xie  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
276fba6e04STony Xie  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
286fba6e04STony Xie  * POSSIBILITY OF SUCH DAMAGE.
296fba6e04STony Xie  */
306fba6e04STony Xie 
316fba6e04STony Xie #include <bl_common.h>
326fba6e04STony Xie #include <gicv3.h>
336fba6e04STony Xie #include <platform.h>
346fba6e04STony Xie #include <platform_def.h>
35ed81f3ebSSandrine Bailleux #include <utils.h>
366fba6e04STony Xie 
376fba6e04STony Xie /******************************************************************************
386fba6e04STony Xie  * The following functions are defined as weak to allow a platform to override
396fba6e04STony Xie  * the way the GICv3 driver is initialised and used.
406fba6e04STony Xie  *****************************************************************************/
416fba6e04STony Xie #pragma weak plat_rockchip_gic_driver_init
426fba6e04STony Xie #pragma weak plat_rockchip_gic_init
436fba6e04STony Xie #pragma weak plat_rockchip_gic_cpuif_enable
446fba6e04STony Xie #pragma weak plat_rockchip_gic_cpuif_disable
456fba6e04STony Xie #pragma weak plat_rockchip_gic_pcpu_init
466fba6e04STony Xie 
476fba6e04STony Xie /* The GICv3 driver only needs to be initialized in EL3 */
486fba6e04STony Xie uintptr_t rdistif_base_addrs[PLATFORM_CORE_COUNT];
496fba6e04STony Xie 
506fba6e04STony Xie /* Array of Group1 secure interrupts to be configured by the gic driver */
516fba6e04STony Xie const unsigned int g1s_interrupt_array[] = {
526fba6e04STony Xie 	PLAT_RK_G1S_IRQS
536fba6e04STony Xie };
546fba6e04STony Xie 
556fba6e04STony Xie /* Array of Group0 interrupts to be configured by the gic driver */
566fba6e04STony Xie const unsigned int g0_interrupt_array[] = {
576fba6e04STony Xie 	PLAT_RK_G0_IRQS
586fba6e04STony Xie };
596fba6e04STony Xie 
606fba6e04STony Xie static unsigned int plat_rockchip_mpidr_to_core_pos(unsigned long mpidr)
616fba6e04STony Xie {
626fba6e04STony Xie 	return (unsigned int)plat_core_pos_by_mpidr(mpidr);
636fba6e04STony Xie }
646fba6e04STony Xie 
656fba6e04STony Xie const gicv3_driver_data_t rockchip_gic_data = {
666fba6e04STony Xie 	.gicd_base = PLAT_RK_GICD_BASE,
676fba6e04STony Xie 	.gicr_base = PLAT_RK_GICR_BASE,
686fba6e04STony Xie 	.g0_interrupt_num = ARRAY_SIZE(g0_interrupt_array),
696fba6e04STony Xie 	.g1s_interrupt_num = ARRAY_SIZE(g1s_interrupt_array),
706fba6e04STony Xie 	.g0_interrupt_array = g0_interrupt_array,
716fba6e04STony Xie 	.g1s_interrupt_array = g1s_interrupt_array,
726fba6e04STony Xie 	.rdistif_num = PLATFORM_CORE_COUNT,
736fba6e04STony Xie 	.rdistif_base_addrs = rdistif_base_addrs,
746fba6e04STony Xie 	.mpidr_to_core_pos = plat_rockchip_mpidr_to_core_pos,
756fba6e04STony Xie };
766fba6e04STony Xie 
776fba6e04STony Xie void plat_rockchip_gic_driver_init(void)
786fba6e04STony Xie {
796fba6e04STony Xie 	/*
806fba6e04STony Xie 	 * The GICv3 driver is initialized in EL3 and does not need
816fba6e04STony Xie 	 * to be initialized again in SEL1. This is because the S-EL1
826fba6e04STony Xie 	 * can use GIC system registers to manage interrupts and does
836fba6e04STony Xie 	 * not need GIC interface base addresses to be configured.
846fba6e04STony Xie 	 */
85*3d8256b2SMasahiro Yamada #ifdef IMAGE_BL31
866fba6e04STony Xie 	gicv3_driver_init(&rockchip_gic_data);
876fba6e04STony Xie #endif
886fba6e04STony Xie }
896fba6e04STony Xie 
906fba6e04STony Xie /******************************************************************************
916fba6e04STony Xie  * RockChip common helper to initialize the GIC. Only invoked
926fba6e04STony Xie  * by BL31
936fba6e04STony Xie  *****************************************************************************/
946fba6e04STony Xie void plat_rockchip_gic_init(void)
956fba6e04STony Xie {
966fba6e04STony Xie 	gicv3_distif_init();
976fba6e04STony Xie 	gicv3_rdistif_init(plat_my_core_pos());
986fba6e04STony Xie 	gicv3_cpuif_enable(plat_my_core_pos());
996fba6e04STony Xie }
1006fba6e04STony Xie 
1016fba6e04STony Xie /******************************************************************************
1026fba6e04STony Xie  * RockChip common helper to enable the GIC CPU interface
1036fba6e04STony Xie  *****************************************************************************/
1046fba6e04STony Xie void plat_rockchip_gic_cpuif_enable(void)
1056fba6e04STony Xie {
1066fba6e04STony Xie 	gicv3_cpuif_enable(plat_my_core_pos());
1076fba6e04STony Xie }
1086fba6e04STony Xie 
1096fba6e04STony Xie /******************************************************************************
1106fba6e04STony Xie  * RockChip common helper to disable the GIC CPU interface
1116fba6e04STony Xie  *****************************************************************************/
1126fba6e04STony Xie void plat_rockchip_gic_cpuif_disable(void)
1136fba6e04STony Xie {
1146fba6e04STony Xie 	gicv3_cpuif_disable(plat_my_core_pos());
1156fba6e04STony Xie }
1166fba6e04STony Xie 
1176fba6e04STony Xie /******************************************************************************
1186fba6e04STony Xie  * RockChip common helper to initialize the per-cpu redistributor interface
1196fba6e04STony Xie  * in GICv3
1206fba6e04STony Xie  *****************************************************************************/
1216fba6e04STony Xie void plat_rockchip_gic_pcpu_init(void)
1226fba6e04STony Xie {
1236fba6e04STony Xie 	gicv3_rdistif_init(plat_my_core_pos());
1246fba6e04STony Xie }
125