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