xref: /linux/arch/loongarch/include/asm/vdso/vdso.h (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
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 _ASM_VDSO_VDSO_H
8 #define _ASM_VDSO_VDSO_H
9 
10 #ifndef __ASSEMBLY__
11 
12 #include <asm/asm.h>
13 #include <asm/page.h>
14 #include <asm/vdso.h>
15 
16 struct vdso_pcpu_data {
17 	u32 node;
18 } ____cacheline_aligned_in_smp;
19 
20 struct loongarch_vdso_data {
21 	struct vdso_pcpu_data pdata[NR_CPUS];
22 	struct vdso_rng_data rng_data;
23 };
24 
25 /*
26  * The layout of vvar:
27  *
28  *                      high
29  * +---------------------+--------------------------+
30  * | loongarch vdso data | LOONGARCH_VDSO_DATA_SIZE |
31  * +---------------------+--------------------------+
32  * |  time-ns vdso data  |        PAGE_SIZE         |
33  * +---------------------+--------------------------+
34  * |  generic vdso data  |        PAGE_SIZE         |
35  * +---------------------+--------------------------+
36  *                      low
37  */
38 #define LOONGARCH_VDSO_DATA_SIZE PAGE_ALIGN(sizeof(struct loongarch_vdso_data))
39 #define LOONGARCH_VDSO_DATA_PAGES (LOONGARCH_VDSO_DATA_SIZE >> PAGE_SHIFT)
40 
41 enum vvar_pages {
42 	VVAR_GENERIC_PAGE_OFFSET,
43 	VVAR_TIMENS_PAGE_OFFSET,
44 	VVAR_LOONGARCH_PAGES_START,
45 	VVAR_LOONGARCH_PAGES_END = VVAR_LOONGARCH_PAGES_START + LOONGARCH_VDSO_DATA_PAGES - 1,
46 	VVAR_NR_PAGES,
47 };
48 
49 #define VVAR_SIZE (VVAR_NR_PAGES << PAGE_SHIFT)
50 
51 static inline unsigned long get_vdso_base(void)
52 {
53 	unsigned long addr;
54 
55 	__asm__(
56 	" la.pcrel %0, _start\n"
57 	: "=r" (addr)
58 	:
59 	:);
60 
61 	return addr;
62 }
63 
64 static inline unsigned long get_vdso_data(void)
65 {
66 	return get_vdso_base() - VVAR_SIZE;
67 }
68 
69 #endif /* __ASSEMBLY__ */
70 
71 #endif
72