18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright 2012 Calxeda, Inc.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci#ifndef _ASM_ARM_PERCPU_H_
68c2ecf20Sopenharmony_ci#define _ASM_ARM_PERCPU_H_
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ciregister unsigned long current_stack_pointer asm ("sp");
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/*
118c2ecf20Sopenharmony_ci * Same as asm-generic/percpu.h, except that we store the per cpu offset
128c2ecf20Sopenharmony_ci * in the TPIDRPRW. TPIDRPRW only exists on V6K and V7
138c2ecf20Sopenharmony_ci */
148c2ecf20Sopenharmony_ci#if defined(CONFIG_SMP) && !defined(CONFIG_CPU_V6)
158c2ecf20Sopenharmony_cistatic inline void set_my_cpu_offset(unsigned long off)
168c2ecf20Sopenharmony_ci{
178c2ecf20Sopenharmony_ci	/* Set TPIDRPRW */
188c2ecf20Sopenharmony_ci	asm volatile("mcr p15, 0, %0, c13, c0, 4" : : "r" (off) : "memory");
198c2ecf20Sopenharmony_ci}
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistatic inline unsigned long __my_cpu_offset(void)
228c2ecf20Sopenharmony_ci{
238c2ecf20Sopenharmony_ci	unsigned long off;
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci	/*
268c2ecf20Sopenharmony_ci	 * Read TPIDRPRW.
278c2ecf20Sopenharmony_ci	 * We want to allow caching the value, so avoid using volatile and
288c2ecf20Sopenharmony_ci	 * instead use a fake stack read to hazard against barrier().
298c2ecf20Sopenharmony_ci	 */
308c2ecf20Sopenharmony_ci	asm("mrc p15, 0, %0, c13, c0, 4" : "=r" (off)
318c2ecf20Sopenharmony_ci		: "Q" (*(const unsigned long *)current_stack_pointer));
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	return off;
348c2ecf20Sopenharmony_ci}
358c2ecf20Sopenharmony_ci#define __my_cpu_offset __my_cpu_offset()
368c2ecf20Sopenharmony_ci#else
378c2ecf20Sopenharmony_ci#define set_my_cpu_offset(x)	do {} while(0)
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#endif /* CONFIG_SMP */
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#include <asm-generic/percpu.h>
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#endif /* _ASM_ARM_PERCPU_H_ */
44