xref: /rk3399_ARM-atf/plat/rockchip/common/rockchip_gicv2.c (revision ed81f3ebbfb5abc7d0d250fbc71f297a904d71ae)
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 <gicv2.h>
336fba6e04STony Xie #include <platform_def.h>
34*ed81f3ebSSandrine Bailleux #include <utils.h>
356fba6e04STony Xie 
366fba6e04STony Xie /******************************************************************************
376fba6e04STony Xie  * The following functions are defined as weak to allow a platform to override
386fba6e04STony Xie  * the way the GICv2 driver is initialised and used.
396fba6e04STony Xie  *****************************************************************************/
406fba6e04STony Xie #pragma weak plat_rockchip_gic_driver_init
416fba6e04STony Xie #pragma weak plat_rockchip_gic_init
426fba6e04STony Xie #pragma weak plat_rockchip_gic_cpuif_enable
436fba6e04STony Xie #pragma weak plat_rockchip_gic_cpuif_disable
446fba6e04STony Xie #pragma weak plat_rockchip_gic_pcpu_init
456fba6e04STony Xie 
466fba6e04STony Xie /******************************************************************************
476fba6e04STony Xie  * On a GICv2 system, the Group 1 secure interrupts are treated as Group 0
486fba6e04STony Xie  * interrupts.
496fba6e04STony Xie  *****************************************************************************/
506fba6e04STony Xie const unsigned int g0_interrupt_array[] = {
516fba6e04STony Xie 	PLAT_RK_G1S_IRQS,
526fba6e04STony Xie };
536fba6e04STony Xie 
546fba6e04STony Xie /*
556fba6e04STony Xie  * Ideally `rockchip_gic_data` structure definition should be a `const` but it
566fba6e04STony Xie  * is kept as modifiable for overwriting with different GICD and GICC base when
576fba6e04STony Xie  * running on FVP with VE memory map.
586fba6e04STony Xie  */
596fba6e04STony Xie gicv2_driver_data_t rockchip_gic_data = {
606fba6e04STony Xie 	.gicd_base = PLAT_RK_GICD_BASE,
616fba6e04STony Xie 	.gicc_base = PLAT_RK_GICC_BASE,
626fba6e04STony Xie 	.g0_interrupt_num = ARRAY_SIZE(g0_interrupt_array),
636fba6e04STony Xie 	.g0_interrupt_array = g0_interrupt_array,
646fba6e04STony Xie };
656fba6e04STony Xie 
666fba6e04STony Xie /******************************************************************************
676fba6e04STony Xie  * RockChip common helper to initialize the GICv2 only driver.
686fba6e04STony Xie  *****************************************************************************/
696fba6e04STony Xie void plat_rockchip_gic_driver_init(void)
706fba6e04STony Xie {
716fba6e04STony Xie 	gicv2_driver_init(&rockchip_gic_data);
726fba6e04STony Xie }
736fba6e04STony Xie 
746fba6e04STony Xie void plat_rockchip_gic_init(void)
756fba6e04STony Xie {
766fba6e04STony Xie 	gicv2_distif_init();
776fba6e04STony Xie 	gicv2_pcpu_distif_init();
786fba6e04STony Xie 	gicv2_cpuif_enable();
796fba6e04STony Xie }
806fba6e04STony Xie 
816fba6e04STony Xie /******************************************************************************
826fba6e04STony Xie  * RockChip common helper to enable the GICv2 CPU interface
836fba6e04STony Xie  *****************************************************************************/
846fba6e04STony Xie void plat_rockchip_gic_cpuif_enable(void)
856fba6e04STony Xie {
866fba6e04STony Xie 	gicv2_cpuif_enable();
876fba6e04STony Xie }
886fba6e04STony Xie 
896fba6e04STony Xie /******************************************************************************
906fba6e04STony Xie  * RockChip common helper to disable the GICv2 CPU interface
916fba6e04STony Xie  *****************************************************************************/
926fba6e04STony Xie void plat_rockchip_gic_cpuif_disable(void)
936fba6e04STony Xie {
946fba6e04STony Xie 	gicv2_cpuif_disable();
956fba6e04STony Xie }
966fba6e04STony Xie 
976fba6e04STony Xie /******************************************************************************
986fba6e04STony Xie  * RockChip common helper to initialize the per cpu distributor interface
996fba6e04STony Xie  * in GICv2
1006fba6e04STony Xie  *****************************************************************************/
1016fba6e04STony Xie void plat_rockchip_gic_pcpu_init(void)
1026fba6e04STony Xie {
1036fba6e04STony Xie 	gicv2_pcpu_distif_init();
1046fba6e04STony Xie }
105