xref: /rk3399_ARM-atf/plat/rockchip/common/include/plat_macros.S (revision 9ff67fa6f25c5a0285eec27f3e86362ae535aac3)
16fba6e04STony Xie/*
26fba6e04STony Xie * Copyright (c) 2014-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#ifndef __ROCKCHIP_PLAT_MACROS_S__
316fba6e04STony Xie#define __ROCKCHIP_PLAT_MACROS_S__
326fba6e04STony Xie
336fba6e04STony Xie#include <cci.h>
346fba6e04STony Xie#include <gic_common.h>
356fba6e04STony Xie#include <gicv2.h>
366fba6e04STony Xie#include <gicv3.h>
376fba6e04STony Xie#include <platform_def.h>
386fba6e04STony Xie
396fba6e04STony Xie.section .rodata.gic_reg_name, "aS"
406fba6e04STony Xie/* Applicable only to GICv2 and GICv3 with SRE disabled (legacy mode) */
416fba6e04STony Xiegicc_regs:
426fba6e04STony Xie	.asciz "gicc_hppir", "gicc_ahppir", "gicc_ctlr", ""
436fba6e04STony Xie
446fba6e04STony Xie/* Applicable only to GICv3 with SRE enabled */
456fba6e04STony Xieicc_regs:
466fba6e04STony Xie	.asciz "icc_hppir0_el1", "icc_hppir1_el1", "icc_ctlr_el3", ""
476fba6e04STony Xie
486fba6e04STony Xie/* Registers common to both GICv2 and GICv3 */
496fba6e04STony Xiegicd_pend_reg:
506fba6e04STony Xie	.asciz "gicd_ispendr regs (Offsets 0x200 - 0x278)\n"	\
516fba6e04STony Xie		" Offset:\t\t\tvalue\n"
526fba6e04STony Xienewline:
536fba6e04STony Xie	.asciz "\n"
546fba6e04STony Xiespacer:
556fba6e04STony Xie	.asciz ":\t\t0x"
566fba6e04STony Xie
57*9ff67fa6SGerald Lejeune.section .rodata.cci_reg_name, "aS"
58*9ff67fa6SGerald Lejeunecci_iface_regs:
59*9ff67fa6SGerald Lejeune	.asciz "cci_snoop_ctrl_cluster0", "cci_snoop_ctrl_cluster1" , ""
60*9ff67fa6SGerald Lejeune
616fba6e04STony Xie	/* ---------------------------------------------
626fba6e04STony Xie	 * The below utility macro prints out relevant GIC
63*9ff67fa6SGerald Lejeune	 * and CCI registers whenever an unhandled
64*9ff67fa6SGerald Lejeune	 * exception is taken in BL31.
656fba6e04STony Xie	 * Expects: GICD base in x16, GICC base in x17
666fba6e04STony Xie	 * Clobbers: x0 - x10, sp
676fba6e04STony Xie	 * ---------------------------------------------
686fba6e04STony Xie	 */
69*9ff67fa6SGerald Lejeune	.macro plat_crash_print_regs
706fba6e04STony Xie
716fba6e04STony Xie	mov_imm	x16, PLAT_RK_GICD_BASE
726fba6e04STony Xie	mov_imm	x17, PLAT_RK_GICC_BASE
736fba6e04STony Xie
746fba6e04STony Xie	/* Check for GICv3 system register access */
756fba6e04STony Xie	mrs	x7, id_aa64pfr0_el1
766fba6e04STony Xie	ubfx	x7, x7, #ID_AA64PFR0_GIC_SHIFT, #ID_AA64PFR0_GIC_WIDTH
776fba6e04STony Xie	cmp	x7, #1
786fba6e04STony Xie	b.ne	print_gicv2
796fba6e04STony Xie
806fba6e04STony Xie	/* Check for SRE enable */
816fba6e04STony Xie	mrs	x8, ICC_SRE_EL3
826fba6e04STony Xie	tst	x8, #ICC_SRE_SRE_BIT
836fba6e04STony Xie	b.eq	print_gicv2
846fba6e04STony Xie
856fba6e04STony Xie	/* Load the icc reg list to x6 */
866fba6e04STony Xie	adr	x6, icc_regs
876fba6e04STony Xie	/* Load the icc regs to gp regs used by str_in_crash_buf_print */
886fba6e04STony Xie	mrs	x8, ICC_HPPIR0_EL1
896fba6e04STony Xie	mrs	x9, ICC_HPPIR1_EL1
906fba6e04STony Xie	mrs	x10, ICC_CTLR_EL3
916fba6e04STony Xie	/* Store to the crash buf and print to console */
926fba6e04STony Xie	bl	str_in_crash_buf_print
936fba6e04STony Xie	b	print_gic_common
946fba6e04STony Xie
956fba6e04STony Xieprint_gicv2:
966fba6e04STony Xie	/* Load the gicc reg list to x6 */
976fba6e04STony Xie	adr	x6, gicc_regs
986fba6e04STony Xie	/* Load the gicc regs to gp regs used by str_in_crash_buf_print */
996fba6e04STony Xie	ldr	w8, [x17, #GICC_HPPIR]
1006fba6e04STony Xie	ldr	w9, [x17, #GICC_AHPPIR]
1016fba6e04STony Xie	ldr	w10, [x17, #GICC_CTLR]
1026fba6e04STony Xie	/* Store to the crash buf and print to console */
1036fba6e04STony Xie	bl	str_in_crash_buf_print
1046fba6e04STony Xie
1056fba6e04STony Xieprint_gic_common:
1066fba6e04STony Xie	/* Print the GICD_ISPENDR regs */
1076fba6e04STony Xie	add	x7, x16, #GICD_ISPENDR
1086fba6e04STony Xie	adr	x4, gicd_pend_reg
1096fba6e04STony Xie	bl	asm_print_str
1106fba6e04STony Xiegicd_ispendr_loop:
1116fba6e04STony Xie	sub	x4, x7, x16
1126fba6e04STony Xie	cmp	x4, #0x280
1136fba6e04STony Xie	b.eq	exit_print_gic_regs
1146fba6e04STony Xie	bl	asm_print_hex
1156fba6e04STony Xie
1166fba6e04STony Xie	adr	x4, spacer
1176fba6e04STony Xie	bl	asm_print_str
1186fba6e04STony Xie
1196fba6e04STony Xie	ldr	x4, [x7], #8
1206fba6e04STony Xie	bl	asm_print_hex
1216fba6e04STony Xie
1226fba6e04STony Xie	adr	x4, newline
1236fba6e04STony Xie	bl	asm_print_str
1246fba6e04STony Xie	b	gicd_ispendr_loop
1256fba6e04STony Xieexit_print_gic_regs:
1266fba6e04STony Xie
1276fba6e04STony Xie#if PLATFORM_CLUSTER_COUNT > 1
1286fba6e04STony Xie	adr	x6, cci_iface_regs
1296fba6e04STony Xie	/* Store in x7 the base address of the first interface */
1306fba6e04STony Xie	mov_imm	x7, (PLAT_RK_CCI_BASE + SLAVE_IFACE_OFFSET(	\
1316fba6e04STony Xie			PLAT_RK_CCI_CLUSTER0_SL_IFACE_IX))
1326fba6e04STony Xie	ldr	w8, [x7, #SNOOP_CTRL_REG]
1336fba6e04STony Xie	/* Store in x7 the base address of the second interface */
1346fba6e04STony Xie	mov_imm	x7, (PLAT_RK_CCI_BASE + SLAVE_IFACE_OFFSET(	\
1356fba6e04STony Xie			PLAT_RK_CCI_CLUSTER1_SL_IFACE_IX))
1366fba6e04STony Xie	ldr	w9, [x7, #SNOOP_CTRL_REG]
1376fba6e04STony Xie	/* Store to the crash buf and print to console */
1386fba6e04STony Xie	bl	str_in_crash_buf_print
1396fba6e04STony Xie#endif
1406fba6e04STony Xie	.endm
1416fba6e04STony Xie
1426fba6e04STony Xie#endif /* __ROCKCHIP_PLAT_MACROS_S__ */
143