xref: /OK3568_Linux_fs/kernel/arch/arm64/include/asm/dcc.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /* Copyright (c) 2014-2015 The Linux Foundation. All rights reserved.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * A call to __dcc_getchar() or __dcc_putchar() is typically followed by
5*4882a593Smuzhiyun  * a call to __dcc_getstatus().  We want to make sure that the CPU does
6*4882a593Smuzhiyun  * not speculative read the DCC status before executing the read or write
7*4882a593Smuzhiyun  * instruction.  That's what the ISBs are for.
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * The 'volatile' ensures that the compiler does not cache the status bits,
10*4882a593Smuzhiyun  * and instead reads the DCC register every time.
11*4882a593Smuzhiyun  */
12*4882a593Smuzhiyun #ifndef __ASM_DCC_H
13*4882a593Smuzhiyun #define __ASM_DCC_H
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #include <asm/barrier.h>
16*4882a593Smuzhiyun #include <asm/sysreg.h>
17*4882a593Smuzhiyun 
__dcc_getstatus(void)18*4882a593Smuzhiyun static inline u32 __dcc_getstatus(void)
19*4882a593Smuzhiyun {
20*4882a593Smuzhiyun 	return read_sysreg(mdccsr_el0);
21*4882a593Smuzhiyun }
22*4882a593Smuzhiyun 
__dcc_getchar(void)23*4882a593Smuzhiyun static inline char __dcc_getchar(void)
24*4882a593Smuzhiyun {
25*4882a593Smuzhiyun 	char c = read_sysreg(dbgdtrrx_el0);
26*4882a593Smuzhiyun 	isb();
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun 	return c;
29*4882a593Smuzhiyun }
30*4882a593Smuzhiyun 
__dcc_putchar(char c)31*4882a593Smuzhiyun static inline void __dcc_putchar(char c)
32*4882a593Smuzhiyun {
33*4882a593Smuzhiyun 	/*
34*4882a593Smuzhiyun 	 * The typecast is to make absolutely certain that 'c' is
35*4882a593Smuzhiyun 	 * zero-extended.
36*4882a593Smuzhiyun 	 */
37*4882a593Smuzhiyun 	write_sysreg((unsigned char)c, dbgdtrtx_el0);
38*4882a593Smuzhiyun 	isb();
39*4882a593Smuzhiyun }
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun #endif
42