xref: /arm-trusted-firmware/plat/qti/common/inc/aarch64/plat_macros.S (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu/*
2*91f16700Schasinglulu * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
3*91f16700Schasinglulu * Copyright (c) 2018,2020, The Linux Foundation. All rights reserved.
4*91f16700Schasinglulu *
5*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause
6*91f16700Schasinglulu */
7*91f16700Schasinglulu
8*91f16700Schasinglulu#ifndef __PLAT_MACROS_S__
9*91f16700Schasinglulu#define __PLAT_MACROS_S__
10*91f16700Schasinglulu
11*91f16700Schasinglulu#include <drivers/arm/gic_common.h>
12*91f16700Schasinglulu#include <drivers/arm/gicv2.h>
13*91f16700Schasinglulu#include <drivers/arm/gicv3.h>
14*91f16700Schasinglulu
15*91f16700Schasinglulu#include <platform_def.h>
16*91f16700Schasinglulu
17*91f16700Schasinglulu.section .rodata.gic_reg_name, "aS"
18*91f16700Schasinglulu/* Applicable only to GICv2 and GICv3 with SRE disabled (legacy mode) */
19*91f16700Schasinglulugicc_regs:
20*91f16700Schasinglulu	.asciz "gicc_hppir", "gicc_ahppir", "gicc_ctlr", ""
21*91f16700Schasinglulu
22*91f16700Schasinglulu/* Applicable only to GICv3 with SRE enabled */
23*91f16700Schasingluluicc_regs:
24*91f16700Schasinglulu	.asciz "icc_hppir0_el1", "icc_hppir1_el1", "icc_ctlr_el3", ""
25*91f16700Schasinglulu
26*91f16700Schasinglulu/* Registers common to both GICv2 and GICv3 */
27*91f16700Schasinglulugicd_pend_reg:
28*91f16700Schasinglulu	.asciz "gicd_ispendr regs (Offsets 0x200 - 0x278)\n"	\
29*91f16700Schasinglulu		" Offset:\t\t\tvalue\n"
30*91f16700Schasinglulunewline:
31*91f16700Schasinglulu	.asciz "\n"
32*91f16700Schasingluluspacer:
33*91f16700Schasinglulu	.asciz ":\t\t0x"
34*91f16700Schasinglulu
35*91f16700Schasinglulu/** Macro : plat_crash_print_regs
36*91f16700Schasinglulu * This macro allows the crash reporting routine to print GIC registers
37*91f16700Schasinglulu * in case of an unhandled exception in BL31. This aids in debugging and
38*91f16700Schasinglulu * this macro can be defined to be empty in case GIC register reporting is
39*91f16700Schasinglulu * not desired.
40*91f16700Schasinglulu * The below required platform porting macro
41*91f16700Schasinglulu * prints out relevant GIC registers whenever an
42*91f16700Schasinglulu * unhandled exception is taken in BL31.
43*91f16700Schasinglulu * Clobbers: x0 - x10, x26, x27, sp
44*91f16700Schasinglulu * ---------------------------------------------
45*91f16700Schasinglulu */
46*91f16700Schasinglulu	.macro plat_crash_print_regs
47*91f16700Schasingluluprint_gic_regs:
48*91f16700Schasinglulu	ldr	x26, =QTI_GICD_BASE
49*91f16700Schasinglulu	ldr	x27, =QTI_GICC_BASE
50*91f16700Schasinglulu
51*91f16700Schasinglulu	/* Check for GICv3 system register access */
52*91f16700Schasinglulu	mrs	x7, id_aa64pfr0_el1
53*91f16700Schasinglulu	ubfx	x7, x7, #ID_AA64PFR0_GIC_SHIFT, #ID_AA64PFR0_GIC_WIDTH
54*91f16700Schasinglulu	cmp	x7, #1
55*91f16700Schasinglulu	b.ne	print_gicv2
56*91f16700Schasinglulu
57*91f16700Schasinglulu	/* Check for SRE enable */
58*91f16700Schasinglulu	mrs	x8, ICC_SRE_EL3
59*91f16700Schasinglulu	tst	x8, #ICC_SRE_SRE_BIT
60*91f16700Schasinglulu	b.eq	print_gicv2
61*91f16700Schasinglulu
62*91f16700Schasinglulu	/* Load the icc reg list to x6 */
63*91f16700Schasinglulu	adr	x6, icc_regs
64*91f16700Schasinglulu	/* Load the icc regs to gp regs used by str_in_crash_buf_print */
65*91f16700Schasinglulu	mrs	x8, ICC_HPPIR0_EL1
66*91f16700Schasinglulu	mrs	x9, ICC_HPPIR1_EL1
67*91f16700Schasinglulu	mrs	x10, ICC_CTLR_EL3
68*91f16700Schasinglulu	/* Store to the crash buf and print to console */
69*91f16700Schasinglulu	bl	str_in_crash_buf_print
70*91f16700Schasinglulu	b	print_gic_common
71*91f16700Schasinglulu
72*91f16700Schasingluluprint_gicv2:
73*91f16700Schasinglulu	/* Load the gicc reg list to x6 */
74*91f16700Schasinglulu	adr	x6, gicc_regs
75*91f16700Schasinglulu	/* Load the gicc regs to gp regs used by str_in_crash_buf_print */
76*91f16700Schasinglulu	ldr	w8, [x27, #GICC_HPPIR]
77*91f16700Schasinglulu	ldr	w9, [x27, #GICC_AHPPIR]
78*91f16700Schasinglulu	ldr	w10, [x27, #GICC_CTLR]
79*91f16700Schasinglulu	/* Store to the crash buf and print to console */
80*91f16700Schasinglulu	bl	str_in_crash_buf_print
81*91f16700Schasinglulu
82*91f16700Schasingluluprint_gic_common:
83*91f16700Schasinglulu	/* Print the GICD_ISPENDR regs */
84*91f16700Schasinglulu	add	x7, x26, #GICD_ISPENDR
85*91f16700Schasinglulu	adr	x4, gicd_pend_reg
86*91f16700Schasinglulu	bl	asm_print_str
87*91f16700Schasinglulugicd_ispendr_loop:
88*91f16700Schasinglulu	sub	x4, x7, x26
89*91f16700Schasinglulu	cmp	x4, #0x280
90*91f16700Schasinglulu	b.eq	exit_print_gic_regs
91*91f16700Schasinglulu	bl	asm_print_hex
92*91f16700Schasinglulu
93*91f16700Schasinglulu	adr	x4, spacer
94*91f16700Schasinglulu	bl	asm_print_str
95*91f16700Schasinglulu
96*91f16700Schasinglulu	ldr	x4, [x7], #8
97*91f16700Schasinglulu	bl	asm_print_hex
98*91f16700Schasinglulu
99*91f16700Schasinglulu	adr	x4, newline
100*91f16700Schasinglulu	bl	asm_print_str
101*91f16700Schasinglulu	b	gicd_ispendr_loop
102*91f16700Schasingluluexit_print_gic_regs:
103*91f16700Schasinglulu
104*91f16700Schasinglulu	.endm
105*91f16700Schasinglulu
106*91f16700Schasinglulu#endif /* __PLAT_MACROS_S__ */
107