LoongArch: Add vDSO syscall __vdso_getcpu()
[linux-2.6-microblaze.git] / arch / loongarch / include / asm / vdso / vdso.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Author: Huacai Chen <chenhuacai@loongson.cn>
4  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
5  */
6
7 #ifndef __ASSEMBLY__
8
9 #include <asm/asm.h>
10 #include <asm/page.h>
11 #include <asm/vdso.h>
12
13 struct vdso_pcpu_data {
14         u32 node;
15 } ____cacheline_aligned_in_smp;
16
17 struct loongarch_vdso_data {
18         struct vdso_pcpu_data pdata[NR_CPUS];
19         struct vdso_data data[CS_BASES]; /* Arch-independent data */
20 };
21
22 #define VDSO_DATA_SIZE PAGE_ALIGN(sizeof(struct loongarch_vdso_data))
23
24 static inline unsigned long get_vdso_base(void)
25 {
26         unsigned long addr;
27
28         __asm__(
29         " la.pcrel %0, _start\n"
30         : "=r" (addr)
31         :
32         :);
33
34         return addr;
35 }
36
37 static inline const struct vdso_data *get_vdso_data(void)
38 {
39         return (const struct vdso_data *)(get_vdso_base()
40                         - VDSO_DATA_SIZE + SMP_CACHE_BYTES * NR_CPUS);
41 }
42
43 #endif /* __ASSEMBLY__ */