1/*
2 * Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <drivers/arm/cci.h>
8#include <drivers/arm/gic_common.h>
9#include <drivers/arm/gicv2.h>
10#include <platform_def.h>
11
12.section .rodata.gic_reg_name, "aS"
13gicc_regs:
14	.asciz "gicc_hppir", "gicc_ahppir", "gicc_ctlr", ""
15gicd_pend_reg:
16	.asciz "gicd_ispendr regs (Offsets 0x200 - 0x278)\n"	\
17		" Offset:\t\t\tvalue\n"
18newline:
19	.asciz "\n"
20spacer:
21	.asciz ":\t\t0x"
22
23.section .rodata.cci_reg_name, "aS"
24cci_iface_regs:
25	.asciz "cci_snoop_ctrl_cluster0", "cci_snoop_ctrl_cluster1" , ""
26
27	/* ---------------------------------------------
28	 * The below macro prints out relevant GIC and
29	 * CCI registers whenever an unhandled exception
30	 * is taken in BL31.
31	 * Clobbers: x0 - x10, x26, x27, sp
32	 * ---------------------------------------------
33	 */
34	.macro plat_crash_print_regs
35	mov_imm x26, BASE_GICD_BASE
36	mov_imm x27, BASE_GICC_BASE
37	/* Load the gicc reg list to x6 */
38	adr	x6, gicc_regs
39	/* Load the gicc regs to gp regs used by str_in_crash_buf_print */
40	ldr	w8, [x27, #GICC_HPPIR]
41	ldr	w9, [x27, #GICC_AHPPIR]
42	ldr	w10, [x27, #GICC_CTLR]
43	/* Store to the crash buf and print to console */
44	bl	str_in_crash_buf_print
45
46	/* Print the GICD_ISPENDR regs */
47	add	x7, x26, #GICD_ISPENDR
48	adr	x4, gicd_pend_reg
49	bl	asm_print_str
50gicd_ispendr_loop:
51	sub	x4, x7, x26
52	cmp	x4, #0x280
53	b.eq	exit_print_gic_regs
54	bl	asm_print_hex
55
56	adr	x4, spacer
57	bl	asm_print_str
58
59	ldr	x4, [x7], #8
60	bl	asm_print_hex
61
62	adr	x4, newline
63	bl	asm_print_str
64	b	gicd_ispendr_loop
65exit_print_gic_regs:
66
67	adr	x6, cci_iface_regs
68	/* Store in x7 the base address of the first interface */
69	mov_imm	x7, (PLAT_MT_CCI_BASE + SLAVE_IFACE_OFFSET(	\
70			PLAT_MT_CCI_CLUSTER0_SL_IFACE_IX))
71	ldr	w8, [x7, #SNOOP_CTRL_REG]
72	/* Store in x7 the base address of the second interface */
73	mov_imm	x7, (PLAT_MT_CCI_BASE + SLAVE_IFACE_OFFSET(	\
74			PLAT_MT_CCI_CLUSTER1_SL_IFACE_IX))
75	ldr	w9, [x7, #SNOOP_CTRL_REG]
76	/* Store to the crash buf and print to console */
77	bl	str_in_crash_buf_print
78	.endm
79