xref: /linux/arch/loongarch/vdso/vgetcpu.c (revision 6f7e6393d1ce636bb7ec77a7fe7b77458fddf701)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Fast user context implementation of getcpu()
4  */
5 
6 #include <asm/vdso.h>
7 
8 static __always_inline int read_cpu_id(void)
9 {
10 	int cpu_id;
11 
12 #ifdef CONFIG_64BIT
13 	__asm__ __volatile__(
14 	"	rdtime.d $zero, %0\n"
15 	: "=r" (cpu_id)
16 	:
17 	: "memory");
18 #else
19 	__asm__ __volatile__(
20 	"	rdtimel.w $zero, %0\n"
21 	: "=r" (cpu_id)
22 	:
23 	: "memory");
24 #endif
25 
26 	return cpu_id;
27 }
28 
29 extern
30 int __vdso_getcpu(unsigned int *cpu, unsigned int *node, void *unused);
31 int __vdso_getcpu(unsigned int *cpu, unsigned int *node, void *unused)
32 {
33 	int cpu_id;
34 
35 	cpu_id = read_cpu_id();
36 
37 	if (cpu)
38 		*cpu = cpu_id;
39 
40 	if (node)
41 		*node = vdso_u_arch_data.pdata[cpu_id].node;
42 
43 	return 0;
44 }
45