Commit | Line | Data |
---|---|---|
c52d0d30 | 1 | /* |
ebb5e78c AS |
2 | * Copyright (C) 2015 Imagination Technologies |
3 | * Author: Alex Smith <alex.smith@imgtec.com> | |
c52d0d30 | 4 | * |
ebb5e78c AS |
5 | * This program is free software; you can redistribute it and/or modify it |
6 | * under the terms of the GNU General Public License as published by the | |
7 | * Free Software Foundation; either version 2 of the License, or (at your | |
8 | * option) any later version. | |
c52d0d30 DD |
9 | */ |
10 | ||
c52d0d30 DD |
11 | #include <linux/binfmts.h> |
12 | #include <linux/elf.h> | |
ebb5e78c AS |
13 | #include <linux/err.h> |
14 | #include <linux/init.h> | |
a7f4df4e AS |
15 | #include <linux/ioport.h> |
16 | #include <linux/irqchip/mips-gic.h> | |
ebb5e78c AS |
17 | #include <linux/mm.h> |
18 | #include <linux/sched.h> | |
19 | #include <linux/slab.h> | |
a7f4df4e | 20 | #include <linux/timekeeper_internal.h> |
c52d0d30 | 21 | |
ebb5e78c | 22 | #include <asm/abi.h> |
c52d0d30 | 23 | #include <asm/vdso.h> |
ebb5e78c AS |
24 | |
25 | /* Kernel-provided data used by the VDSO. */ | |
26 | static union mips_vdso_data vdso_data __page_aligned_data; | |
c52d0d30 DD |
27 | |
28 | /* | |
a7f4df4e | 29 | * Mapping for the VDSO data/GIC pages. The real pages are mapped manually, as |
ebb5e78c AS |
30 | * what we map and where within the area they are mapped is determined at |
31 | * runtime. | |
c52d0d30 | 32 | */ |
ebb5e78c AS |
33 | static struct page *no_pages[] = { NULL }; |
34 | static struct vm_special_mapping vdso_vvar_mapping = { | |
35 | .name = "[vvar]", | |
36 | .pages = no_pages, | |
37 | }; | |
c52d0d30 | 38 | |
ebb5e78c | 39 | static void __init init_vdso_image(struct mips_vdso_image *image) |
c52d0d30 | 40 | { |
ebb5e78c AS |
41 | unsigned long num_pages, i; |
42 | ||
43 | BUG_ON(!PAGE_ALIGNED(image->data)); | |
44 | BUG_ON(!PAGE_ALIGNED(image->size)); | |
45 | ||
46 | num_pages = image->size / PAGE_SIZE; | |
47 | ||
48 | for (i = 0; i < num_pages; i++) { | |
49 | image->mapping.pages[i] = | |
50 | virt_to_page(image->data + (i * PAGE_SIZE)); | |
51 | } | |
c52d0d30 DD |
52 | } |
53 | ||
54 | static int __init init_vdso(void) | |
55 | { | |
ebb5e78c AS |
56 | init_vdso_image(&vdso_image); |
57 | ||
58 | #ifdef CONFIG_MIPS32_O32 | |
59 | init_vdso_image(&vdso_image_o32); | |
c52d0d30 DD |
60 | #endif |
61 | ||
ebb5e78c AS |
62 | #ifdef CONFIG_MIPS32_N32 |
63 | init_vdso_image(&vdso_image_n32); | |
64 | #endif | |
c52d0d30 | 65 | |
c52d0d30 DD |
66 | return 0; |
67 | } | |
1ed84537 | 68 | subsys_initcall(init_vdso); |
c52d0d30 | 69 | |
a7f4df4e AS |
70 | void update_vsyscall(struct timekeeper *tk) |
71 | { | |
72 | vdso_data_write_begin(&vdso_data); | |
73 | ||
74 | vdso_data.xtime_sec = tk->xtime_sec; | |
75 | vdso_data.xtime_nsec = tk->tkr_mono.xtime_nsec; | |
76 | vdso_data.wall_to_mono_sec = tk->wall_to_monotonic.tv_sec; | |
77 | vdso_data.wall_to_mono_nsec = tk->wall_to_monotonic.tv_nsec; | |
78 | vdso_data.cs_shift = tk->tkr_mono.shift; | |
79 | ||
80 | vdso_data.clock_mode = tk->tkr_mono.clock->archdata.vdso_clock_mode; | |
81 | if (vdso_data.clock_mode != VDSO_CLOCK_NONE) { | |
82 | vdso_data.cs_mult = tk->tkr_mono.mult; | |
83 | vdso_data.cs_cycle_last = tk->tkr_mono.cycle_last; | |
84 | vdso_data.cs_mask = tk->tkr_mono.mask; | |
85 | } | |
86 | ||
87 | vdso_data_write_end(&vdso_data); | |
88 | } | |
89 | ||
90 | void update_vsyscall_tz(void) | |
91 | { | |
92 | if (vdso_data.clock_mode != VDSO_CLOCK_NONE) { | |
93 | vdso_data.tz_minuteswest = sys_tz.tz_minuteswest; | |
94 | vdso_data.tz_dsttime = sys_tz.tz_dsttime; | |
95 | } | |
96 | } | |
97 | ||
c52d0d30 DD |
98 | int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) |
99 | { | |
ebb5e78c | 100 | struct mips_vdso_image *image = current->thread.abi->vdso; |
c52d0d30 | 101 | struct mm_struct *mm = current->mm; |
a7f4df4e | 102 | unsigned long gic_size, vvar_size, size, base, data_addr, vdso_addr; |
ebb5e78c | 103 | struct vm_area_struct *vma; |
a7f4df4e | 104 | struct resource gic_res; |
ebb5e78c | 105 | int ret; |
c52d0d30 | 106 | |
69048176 MH |
107 | if (down_write_killable(&mm->mmap_sem)) |
108 | return -EINTR; | |
c52d0d30 | 109 | |
a7f4df4e AS |
110 | /* |
111 | * Determine total area size. This includes the VDSO data itself, the | |
112 | * data page, and the GIC user page if present. Always create a mapping | |
113 | * for the GIC user area if the GIC is present regardless of whether it | |
114 | * is the current clocksource, in case it comes into use later on. We | |
115 | * only map a page even though the total area is 64K, as we only need | |
116 | * the counter registers at the start. | |
117 | */ | |
118 | gic_size = gic_present ? PAGE_SIZE : 0; | |
119 | vvar_size = gic_size + PAGE_SIZE; | |
120 | size = vvar_size + image->size; | |
121 | ||
122 | base = get_unmapped_area(NULL, 0, size, 0, 0); | |
ebb5e78c AS |
123 | if (IS_ERR_VALUE(base)) { |
124 | ret = base; | |
125 | goto out; | |
c52d0d30 DD |
126 | } |
127 | ||
a7f4df4e AS |
128 | data_addr = base + gic_size; |
129 | vdso_addr = data_addr + PAGE_SIZE; | |
ebb5e78c | 130 | |
a7f4df4e | 131 | vma = _install_special_mapping(mm, base, vvar_size, |
ebb5e78c AS |
132 | VM_READ | VM_MAYREAD, |
133 | &vdso_vvar_mapping); | |
134 | if (IS_ERR(vma)) { | |
135 | ret = PTR_ERR(vma); | |
136 | goto out; | |
137 | } | |
c52d0d30 | 138 | |
a7f4df4e AS |
139 | /* Map GIC user page. */ |
140 | if (gic_size) { | |
141 | ret = gic_get_usm_range(&gic_res); | |
142 | if (ret) | |
143 | goto out; | |
144 | ||
145 | ret = io_remap_pfn_range(vma, base, | |
146 | gic_res.start >> PAGE_SHIFT, | |
147 | gic_size, | |
148 | pgprot_noncached(PAGE_READONLY)); | |
149 | if (ret) | |
150 | goto out; | |
151 | } | |
152 | ||
ebb5e78c | 153 | /* Map data page. */ |
a7f4df4e | 154 | ret = remap_pfn_range(vma, data_addr, |
ebb5e78c AS |
155 | virt_to_phys(&vdso_data) >> PAGE_SHIFT, |
156 | PAGE_SIZE, PAGE_READONLY); | |
c52d0d30 | 157 | if (ret) |
ebb5e78c AS |
158 | goto out; |
159 | ||
160 | /* Map VDSO image. */ | |
161 | vma = _install_special_mapping(mm, vdso_addr, image->size, | |
162 | VM_READ | VM_EXEC | | |
163 | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC, | |
164 | &image->mapping); | |
165 | if (IS_ERR(vma)) { | |
166 | ret = PTR_ERR(vma); | |
167 | goto out; | |
168 | } | |
c52d0d30 | 169 | |
ebb5e78c AS |
170 | mm->context.vdso = (void *)vdso_addr; |
171 | ret = 0; | |
c52d0d30 | 172 | |
ebb5e78c | 173 | out: |
c52d0d30 DD |
174 | up_write(&mm->mmap_sem); |
175 | return ret; | |
176 | } |