162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/* Copyright (c) 2014-2015 The Linux Foundation. All rights reserved.
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * A call to __dcc_getchar() or __dcc_putchar() is typically followed by
562306a36Sopenharmony_ci * a call to __dcc_getstatus().  We want to make sure that the CPU does
662306a36Sopenharmony_ci * not speculative read the DCC status before executing the read or write
762306a36Sopenharmony_ci * instruction.  That's what the ISBs are for.
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * The 'volatile' ensures that the compiler does not cache the status bits,
1062306a36Sopenharmony_ci * and instead reads the DCC register every time.
1162306a36Sopenharmony_ci */
1262306a36Sopenharmony_ci#ifndef __ASM_DCC_H
1362306a36Sopenharmony_ci#define __ASM_DCC_H
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#include <asm/barrier.h>
1662306a36Sopenharmony_ci#include <asm/sysreg.h>
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_cistatic inline u32 __dcc_getstatus(void)
1962306a36Sopenharmony_ci{
2062306a36Sopenharmony_ci	return read_sysreg(mdccsr_el0);
2162306a36Sopenharmony_ci}
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_cistatic inline char __dcc_getchar(void)
2462306a36Sopenharmony_ci{
2562306a36Sopenharmony_ci	char c = read_sysreg(dbgdtrrx_el0);
2662306a36Sopenharmony_ci	isb();
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci	return c;
2962306a36Sopenharmony_ci}
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_cistatic inline void __dcc_putchar(char c)
3262306a36Sopenharmony_ci{
3362306a36Sopenharmony_ci	/*
3462306a36Sopenharmony_ci	 * The typecast is to make absolutely certain that 'c' is
3562306a36Sopenharmony_ci	 * zero-extended.
3662306a36Sopenharmony_ci	 */
3762306a36Sopenharmony_ci	write_sysreg((unsigned char)c, dbgdtrtx_el0);
3862306a36Sopenharmony_ci	isb();
3962306a36Sopenharmony_ci}
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci#endif
42