18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* Copyright (c) 2014-2015 The Linux Foundation. All rights reserved. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * A call to __dcc_getchar() or __dcc_putchar() is typically followed by 58c2ecf20Sopenharmony_ci * a call to __dcc_getstatus(). We want to make sure that the CPU does 68c2ecf20Sopenharmony_ci * not speculative read the DCC status before executing the read or write 78c2ecf20Sopenharmony_ci * instruction. That's what the ISBs are for. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * The 'volatile' ensures that the compiler does not cache the status bits, 108c2ecf20Sopenharmony_ci * and instead reads the DCC register every time. 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci#ifndef __ASM_DCC_H 138c2ecf20Sopenharmony_ci#define __ASM_DCC_H 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <asm/barrier.h> 168c2ecf20Sopenharmony_ci#include <asm/sysreg.h> 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cistatic inline u32 __dcc_getstatus(void) 198c2ecf20Sopenharmony_ci{ 208c2ecf20Sopenharmony_ci return read_sysreg(mdccsr_el0); 218c2ecf20Sopenharmony_ci} 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cistatic inline char __dcc_getchar(void) 248c2ecf20Sopenharmony_ci{ 258c2ecf20Sopenharmony_ci char c = read_sysreg(dbgdtrrx_el0); 268c2ecf20Sopenharmony_ci isb(); 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci return c; 298c2ecf20Sopenharmony_ci} 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cistatic inline void __dcc_putchar(char c) 328c2ecf20Sopenharmony_ci{ 338c2ecf20Sopenharmony_ci /* 348c2ecf20Sopenharmony_ci * The typecast is to make absolutely certain that 'c' is 358c2ecf20Sopenharmony_ci * zero-extended. 368c2ecf20Sopenharmony_ci */ 378c2ecf20Sopenharmony_ci write_sysreg((unsigned char)c, dbgdtrtx_el0); 388c2ecf20Sopenharmony_ci isb(); 398c2ecf20Sopenharmony_ci} 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#endif 42