powerpc/vdso: Combine start/size variables
[deliverable/linux.git] / arch / powerpc / kernel / vdso.c
CommitLineData
abe1ee3a 1
a7f290da 2/*
a7f290da
BH
3 * Copyright (C) 2004 Benjamin Herrenschmidt, IBM Corp.
4 * <benh@kernel.crashing.org>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
a7f290da
BH
12#include <linux/errno.h>
13#include <linux/sched.h>
14#include <linux/kernel.h>
15#include <linux/mm.h>
16#include <linux/smp.h>
a7f290da
BH
17#include <linux/stddef.h>
18#include <linux/unistd.h>
19#include <linux/slab.h>
20#include <linux/user.h>
21#include <linux/elf.h>
22#include <linux/security.h>
95f72d1e 23#include <linux/memblock.h>
a7f290da
BH
24
25#include <asm/pgtable.h>
a7f290da
BH
26#include <asm/processor.h>
27#include <asm/mmu.h>
28#include <asm/mmu_context.h>
d9b2b2a2 29#include <asm/prom.h>
a7f290da
BH
30#include <asm/machdep.h>
31#include <asm/cputable.h>
32#include <asm/sections.h>
e8222502 33#include <asm/firmware.h>
a7f290da
BH
34#include <asm/vdso.h>
35#include <asm/vdso_datapage.h>
b88c4767 36#include <asm/setup.h>
0909c8c2 37
a7f290da
BH
38#undef DEBUG
39
40#ifdef DEBUG
41#define DBG(fmt...) printk(fmt)
42#else
43#define DBG(fmt...)
44#endif
45
46/* Max supported size for symbol names */
47#define MAX_SYMNAME 64
48
348aa303
AS
49/* The alignment of the vDSO */
50#define VDSO_ALIGNMENT (1 << 16)
51
a7f290da
BH
52extern char vdso32_start, vdso32_end;
53static void *vdso32_kbase = &vdso32_start;
7ac9a137
BH
54static unsigned int vdso32_pages;
55static struct page **vdso32_pagelist;
a7f290da
BH
56unsigned long vdso32_sigtramp;
57unsigned long vdso32_rt_sigtramp;
58
59#ifdef CONFIG_PPC64
60extern char vdso64_start, vdso64_end;
61static void *vdso64_kbase = &vdso64_start;
7ac9a137
BH
62static unsigned int vdso64_pages;
63static struct page **vdso64_pagelist;
a7f290da
BH
64unsigned long vdso64_rt_sigtramp;
65#endif /* CONFIG_PPC64 */
66
7ac9a137
BH
67static int vdso_ready;
68
a7f290da
BH
69/*
70 * The vdso data page (aka. systemcfg for old ppc64 fans) is here.
71 * Once the early boot kernel code no longer needs to muck around
72 * with it, it will become dynamically allocated
73 */
74static union {
75 struct vdso_data data;
76 u8 page[PAGE_SIZE];
abe1ee3a 77} vdso_data_store __page_aligned_data;
a7f290da
BH
78struct vdso_data *vdso_data = &vdso_data_store.data;
79
80/* Format of the patch table */
81struct vdso_patch_def
82{
83 unsigned long ftr_mask, ftr_value;
84 const char *gen_name;
85 const char *fix_name;
86};
87
88/* Table of functions to patch based on the CPU type/revision
89 *
90 * Currently, we only change sync_dicache to do nothing on processors
91 * with a coherent icache
92 */
93static struct vdso_patch_def vdso_patches[] = {
94 {
95 CPU_FTR_COHERENT_ICACHE, CPU_FTR_COHERENT_ICACHE,
96 "__kernel_sync_dicache", "__kernel_sync_dicache_p5"
97 },
98 {
99 CPU_FTR_USE_TB, 0,
100 "__kernel_gettimeofday", NULL
101 },
7b5acbaa
BH
102 {
103 CPU_FTR_USE_TB, 0,
104 "__kernel_clock_gettime", NULL
105 },
106 {
107 CPU_FTR_USE_TB, 0,
108 "__kernel_clock_getres", NULL
109 },
110 {
111 CPU_FTR_USE_TB, 0,
112 "__kernel_get_tbfreq", NULL
113 },
fcb41a20
AZ
114 {
115 CPU_FTR_USE_TB, 0,
116 "__kernel_time", NULL
117 },
a7f290da
BH
118};
119
120/*
121 * Some infos carried around for each of them during parsing at
122 * boot time.
123 */
124struct lib32_elfinfo
125{
126 Elf32_Ehdr *hdr; /* ptr to ELF */
127 Elf32_Sym *dynsym; /* ptr to .dynsym section */
128 unsigned long dynsymsize; /* size of .dynsym section */
129 char *dynstr; /* ptr to .dynstr section */
130 unsigned long text; /* offset of .text section in .so */
131};
132
133struct lib64_elfinfo
134{
135 Elf64_Ehdr *hdr;
136 Elf64_Sym *dynsym;
137 unsigned long dynsymsize;
138 char *dynstr;
139 unsigned long text;
140};
141
142
a7f290da
BH
143/*
144 * This is called from binfmt_elf, we create the special vma for the
145 * vDSO and insert it into the mm struct tree
146 */
fc5243d9 147int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
a7f290da
BH
148{
149 struct mm_struct *mm = current->mm;
c13e4ca2 150 struct page **vdso_pagelist;
a7f290da
BH
151 unsigned long vdso_pages;
152 unsigned long vdso_base;
a5bba930 153 int rc;
a7f290da 154
7ac9a137
BH
155 if (!vdso_ready)
156 return 0;
157
a7f290da 158#ifdef CONFIG_PPC64
cab175f9 159 if (is_32bit_task()) {
c13e4ca2 160 vdso_pagelist = vdso32_pagelist;
a7f290da
BH
161 vdso_pages = vdso32_pages;
162 vdso_base = VDSO32_MBASE;
163 } else {
c13e4ca2 164 vdso_pagelist = vdso64_pagelist;
a7f290da 165 vdso_pages = vdso64_pages;
30d0b368
AB
166 /*
167 * On 64bit we don't have a preferred map address. This
168 * allows get_unmapped_area to find an area near other mmaps
169 * and most likely share a SLB entry.
170 */
171 vdso_base = 0;
a7f290da
BH
172 }
173#else
c13e4ca2 174 vdso_pagelist = vdso32_pagelist;
a7f290da
BH
175 vdso_pages = vdso32_pages;
176 vdso_base = VDSO32_MBASE;
177#endif
178
a5bba930 179 current->mm->context.vdso_base = 0;
a7f290da
BH
180
181 /* vDSO has a problem and was disabled, just don't "enable" it for the
182 * process
183 */
184 if (vdso_pages == 0)
185 return 0;
a7f290da
BH
186 /* Add a page to the vdso size for the data page */
187 vdso_pages ++;
188
189 /*
190 * pick a base address for the vDSO in process space. We try to put it
191 * at vdso_base which is the "natural" base for it, but we might fail
192 * and end up putting it elsewhere.
348aa303 193 * Add enough to the size so that the result can be aligned.
a7f290da 194 */
a5bba930 195 down_write(&mm->mmap_sem);
a7f290da 196 vdso_base = get_unmapped_area(NULL, vdso_base,
348aa303
AS
197 (vdso_pages << PAGE_SHIFT) +
198 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
199 0, 0);
a5bba930
BH
200 if (IS_ERR_VALUE(vdso_base)) {
201 rc = vdso_base;
202 goto fail_mmapsem;
a7f290da
BH
203 }
204
348aa303
AS
205 /* Add required alignment. */
206 vdso_base = ALIGN(vdso_base, VDSO_ALIGNMENT);
207
f2053f1a
AB
208 /*
209 * Put vDSO base into mm struct. We need to do this before calling
210 * install_special_mapping or the perf counter mmap tracking code
211 * will fail to recognise it as a vDSO (since arch_vma_name fails).
212 */
213 current->mm->context.vdso_base = vdso_base;
214
a7f290da
BH
215 /*
216 * our vma flags don't have VM_WRITE so by default, the process isn't
217 * allowed to write those pages.
218 * gdb can break that with ptrace interface, and thus trigger COW on
219 * those pages but it's then your responsibility to never do that on
220 * the "data" page of the vDSO or you'll stop getting kernel updates
221 * and your nice userland gettimeofday will be totally dead.
222 * It's fine to use that for setting breakpoints in the vDSO code
909af768 223 * pages though.
3a0cfadb 224 */
c13e4ca2
RM
225 rc = install_special_mapping(mm, vdso_base, vdso_pages << PAGE_SHIFT,
226 VM_READ|VM_EXEC|
909af768 227 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
c13e4ca2 228 vdso_pagelist);
f2053f1a
AB
229 if (rc) {
230 current->mm->context.vdso_base = 0;
c13e4ca2 231 goto fail_mmapsem;
f2053f1a 232 }
c13e4ca2 233
a7f290da 234 up_write(&mm->mmap_sem);
a7f290da 235 return 0;
a5bba930 236
a5bba930
BH
237 fail_mmapsem:
238 up_write(&mm->mmap_sem);
239 return rc;
240}
241
242const char *arch_vma_name(struct vm_area_struct *vma)
243{
244 if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso_base)
245 return "[vdso]";
246 return NULL;
a7f290da
BH
247}
248
a5bba930
BH
249
250
a7f290da
BH
251static void * __init find_section32(Elf32_Ehdr *ehdr, const char *secname,
252 unsigned long *size)
253{
254 Elf32_Shdr *sechdrs;
255 unsigned int i;
256 char *secnames;
257
258 /* Grab section headers and strings so we can tell who is who */
259 sechdrs = (void *)ehdr + ehdr->e_shoff;
260 secnames = (void *)ehdr + sechdrs[ehdr->e_shstrndx].sh_offset;
261
262 /* Find the section they want */
263 for (i = 1; i < ehdr->e_shnum; i++) {
264 if (strcmp(secnames+sechdrs[i].sh_name, secname) == 0) {
265 if (size)
266 *size = sechdrs[i].sh_size;
267 return (void *)ehdr + sechdrs[i].sh_offset;
268 }
269 }
270 *size = 0;
271 return NULL;
272}
273
274static Elf32_Sym * __init find_symbol32(struct lib32_elfinfo *lib,
275 const char *symname)
276{
277 unsigned int i;
278 char name[MAX_SYMNAME], *c;
279
280 for (i = 0; i < (lib->dynsymsize / sizeof(Elf32_Sym)); i++) {
281 if (lib->dynsym[i].st_name == 0)
282 continue;
283 strlcpy(name, lib->dynstr + lib->dynsym[i].st_name,
284 MAX_SYMNAME);
285 c = strchr(name, '@');
286 if (c)
287 *c = 0;
288 if (strcmp(symname, name) == 0)
289 return &lib->dynsym[i];
290 }
291 return NULL;
292}
293
294/* Note that we assume the section is .text and the symbol is relative to
295 * the library base
296 */
297static unsigned long __init find_function32(struct lib32_elfinfo *lib,
298 const char *symname)
299{
300 Elf32_Sym *sym = find_symbol32(lib, symname);
301
302 if (sym == NULL) {
303 printk(KERN_WARNING "vDSO32: function %s not found !\n",
304 symname);
305 return 0;
306 }
307 return sym->st_value - VDSO32_LBASE;
308}
309
cf8918fe
AB
310static int __init vdso_do_func_patch32(struct lib32_elfinfo *v32,
311 struct lib64_elfinfo *v64,
312 const char *orig, const char *fix)
a7f290da
BH
313{
314 Elf32_Sym *sym32_gen, *sym32_fix;
315
316 sym32_gen = find_symbol32(v32, orig);
317 if (sym32_gen == NULL) {
318 printk(KERN_ERR "vDSO32: Can't find symbol %s !\n", orig);
319 return -1;
320 }
321 if (fix == NULL) {
322 sym32_gen->st_name = 0;
323 return 0;
324 }
325 sym32_fix = find_symbol32(v32, fix);
326 if (sym32_fix == NULL) {
327 printk(KERN_ERR "vDSO32: Can't find symbol %s !\n", fix);
328 return -1;
329 }
330 sym32_gen->st_value = sym32_fix->st_value;
331 sym32_gen->st_size = sym32_fix->st_size;
332 sym32_gen->st_info = sym32_fix->st_info;
333 sym32_gen->st_other = sym32_fix->st_other;
334 sym32_gen->st_shndx = sym32_fix->st_shndx;
335
336 return 0;
337}
338
339
340#ifdef CONFIG_PPC64
341
342static void * __init find_section64(Elf64_Ehdr *ehdr, const char *secname,
343 unsigned long *size)
344{
345 Elf64_Shdr *sechdrs;
346 unsigned int i;
347 char *secnames;
348
349 /* Grab section headers and strings so we can tell who is who */
350 sechdrs = (void *)ehdr + ehdr->e_shoff;
351 secnames = (void *)ehdr + sechdrs[ehdr->e_shstrndx].sh_offset;
352
353 /* Find the section they want */
354 for (i = 1; i < ehdr->e_shnum; i++) {
355 if (strcmp(secnames+sechdrs[i].sh_name, secname) == 0) {
356 if (size)
357 *size = sechdrs[i].sh_size;
358 return (void *)ehdr + sechdrs[i].sh_offset;
359 }
360 }
361 if (size)
362 *size = 0;
363 return NULL;
364}
365
366static Elf64_Sym * __init find_symbol64(struct lib64_elfinfo *lib,
367 const char *symname)
368{
369 unsigned int i;
370 char name[MAX_SYMNAME], *c;
371
372 for (i = 0; i < (lib->dynsymsize / sizeof(Elf64_Sym)); i++) {
373 if (lib->dynsym[i].st_name == 0)
374 continue;
375 strlcpy(name, lib->dynstr + lib->dynsym[i].st_name,
376 MAX_SYMNAME);
377 c = strchr(name, '@');
378 if (c)
379 *c = 0;
380 if (strcmp(symname, name) == 0)
381 return &lib->dynsym[i];
382 }
383 return NULL;
384}
385
386/* Note that we assume the section is .text and the symbol is relative to
387 * the library base
388 */
389static unsigned long __init find_function64(struct lib64_elfinfo *lib,
390 const char *symname)
391{
392 Elf64_Sym *sym = find_symbol64(lib, symname);
393
394 if (sym == NULL) {
395 printk(KERN_WARNING "vDSO64: function %s not found !\n",
396 symname);
397 return 0;
398 }
399#ifdef VDS64_HAS_DESCRIPTORS
400 return *((u64 *)(vdso64_kbase + sym->st_value - VDSO64_LBASE)) -
401 VDSO64_LBASE;
402#else
403 return sym->st_value - VDSO64_LBASE;
404#endif
405}
406
cf8918fe
AB
407static int __init vdso_do_func_patch64(struct lib32_elfinfo *v32,
408 struct lib64_elfinfo *v64,
409 const char *orig, const char *fix)
a7f290da
BH
410{
411 Elf64_Sym *sym64_gen, *sym64_fix;
412
413 sym64_gen = find_symbol64(v64, orig);
414 if (sym64_gen == NULL) {
415 printk(KERN_ERR "vDSO64: Can't find symbol %s !\n", orig);
416 return -1;
417 }
418 if (fix == NULL) {
419 sym64_gen->st_name = 0;
420 return 0;
421 }
422 sym64_fix = find_symbol64(v64, fix);
423 if (sym64_fix == NULL) {
424 printk(KERN_ERR "vDSO64: Can't find symbol %s !\n", fix);
425 return -1;
426 }
427 sym64_gen->st_value = sym64_fix->st_value;
428 sym64_gen->st_size = sym64_fix->st_size;
429 sym64_gen->st_info = sym64_fix->st_info;
430 sym64_gen->st_other = sym64_fix->st_other;
431 sym64_gen->st_shndx = sym64_fix->st_shndx;
432
433 return 0;
434}
435
436#endif /* CONFIG_PPC64 */
437
438
439static __init int vdso_do_find_sections(struct lib32_elfinfo *v32,
440 struct lib64_elfinfo *v64)
441{
442 void *sect;
443
444 /*
445 * Locate symbol tables & text section
446 */
447
448 v32->dynsym = find_section32(v32->hdr, ".dynsym", &v32->dynsymsize);
449 v32->dynstr = find_section32(v32->hdr, ".dynstr", NULL);
450 if (v32->dynsym == NULL || v32->dynstr == NULL) {
451 printk(KERN_ERR "vDSO32: required symbol section not found\n");
452 return -1;
453 }
454 sect = find_section32(v32->hdr, ".text", NULL);
455 if (sect == NULL) {
456 printk(KERN_ERR "vDSO32: the .text section was not found\n");
457 return -1;
458 }
459 v32->text = sect - vdso32_kbase;
460
461#ifdef CONFIG_PPC64
462 v64->dynsym = find_section64(v64->hdr, ".dynsym", &v64->dynsymsize);
463 v64->dynstr = find_section64(v64->hdr, ".dynstr", NULL);
464 if (v64->dynsym == NULL || v64->dynstr == NULL) {
465 printk(KERN_ERR "vDSO64: required symbol section not found\n");
466 return -1;
467 }
468 sect = find_section64(v64->hdr, ".text", NULL);
469 if (sect == NULL) {
470 printk(KERN_ERR "vDSO64: the .text section was not found\n");
471 return -1;
472 }
473 v64->text = sect - vdso64_kbase;
474#endif /* CONFIG_PPC64 */
475
476 return 0;
477}
478
479static __init void vdso_setup_trampolines(struct lib32_elfinfo *v32,
480 struct lib64_elfinfo *v64)
481{
482 /*
483 * Find signal trampolines
484 */
485
486#ifdef CONFIG_PPC64
487 vdso64_rt_sigtramp = find_function64(v64, "__kernel_sigtramp_rt64");
488#endif
489 vdso32_sigtramp = find_function32(v32, "__kernel_sigtramp32");
490 vdso32_rt_sigtramp = find_function32(v32, "__kernel_sigtramp_rt32");
491}
492
493static __init int vdso_fixup_datapage(struct lib32_elfinfo *v32,
494 struct lib64_elfinfo *v64)
495{
496 Elf32_Sym *sym32;
497#ifdef CONFIG_PPC64
498 Elf64_Sym *sym64;
499
500 sym64 = find_symbol64(v64, "__kernel_datapage_offset");
501 if (sym64 == NULL) {
502 printk(KERN_ERR "vDSO64: Can't find symbol "
503 "__kernel_datapage_offset !\n");
504 return -1;
505 }
506 *((int *)(vdso64_kbase + sym64->st_value - VDSO64_LBASE)) =
507 (vdso64_pages << PAGE_SHIFT) -
508 (sym64->st_value - VDSO64_LBASE);
509#endif /* CONFIG_PPC64 */
510
511 sym32 = find_symbol32(v32, "__kernel_datapage_offset");
512 if (sym32 == NULL) {
513 printk(KERN_ERR "vDSO32: Can't find symbol "
514 "__kernel_datapage_offset !\n");
515 return -1;
516 }
517 *((int *)(vdso32_kbase + (sym32->st_value - VDSO32_LBASE))) =
518 (vdso32_pages << PAGE_SHIFT) -
519 (sym32->st_value - VDSO32_LBASE);
520
521 return 0;
522}
523
0909c8c2
BH
524
525static __init int vdso_fixup_features(struct lib32_elfinfo *v32,
526 struct lib64_elfinfo *v64)
527{
6e5c0775
ME
528 unsigned long size;
529 void *start;
0909c8c2
BH
530
531#ifdef CONFIG_PPC64
6e5c0775
ME
532 start = find_section64(v64->hdr, "__ftr_fixup", &size);
533 if (start)
0909c8c2 534 do_feature_fixups(cur_cpu_spec->cpu_features,
6e5c0775 535 start, start + size);
0909c8c2 536
6e5c0775
ME
537 start = find_section64(v64->hdr, "__mmu_ftr_fixup", &size);
538 if (start)
7c03d653 539 do_feature_fixups(cur_cpu_spec->mmu_features,
6e5c0775 540 start, start + size);
7c03d653 541
6e5c0775
ME
542 start = find_section64(v64->hdr, "__fw_ftr_fixup", &size);
543 if (start)
0909c8c2 544 do_feature_fixups(powerpc_firmware_features,
6e5c0775 545 start, start + size);
2d1b2027 546
6e5c0775
ME
547 start = find_section64(v64->hdr, "__lwsync_fixup", &size);
548 if (start)
2d1b2027 549 do_lwsync_fixups(cur_cpu_spec->cpu_features,
6e5c0775 550 start, start + size);
0909c8c2
BH
551#endif /* CONFIG_PPC64 */
552
6e5c0775
ME
553 start = find_section32(v32->hdr, "__ftr_fixup", &size);
554 if (start)
0909c8c2 555 do_feature_fixups(cur_cpu_spec->cpu_features,
6e5c0775 556 start, start + size);
0909c8c2 557
6e5c0775
ME
558 start = find_section32(v32->hdr, "__mmu_ftr_fixup", &size);
559 if (start)
7c03d653 560 do_feature_fixups(cur_cpu_spec->mmu_features,
6e5c0775 561 start, start + size);
7c03d653 562
0909c8c2 563#ifdef CONFIG_PPC64
6e5c0775
ME
564 start = find_section32(v32->hdr, "__fw_ftr_fixup", &size);
565 if (start)
0909c8c2 566 do_feature_fixups(powerpc_firmware_features,
6e5c0775 567 start, start + size);
0909c8c2
BH
568#endif /* CONFIG_PPC64 */
569
6e5c0775
ME
570 start = find_section32(v32->hdr, "__lwsync_fixup", &size);
571 if (start)
2d1b2027 572 do_lwsync_fixups(cur_cpu_spec->cpu_features,
6e5c0775 573 start, start + size);
2d1b2027 574
0909c8c2
BH
575 return 0;
576}
577
a7f290da
BH
578static __init int vdso_fixup_alt_funcs(struct lib32_elfinfo *v32,
579 struct lib64_elfinfo *v64)
580{
581 int i;
582
583 for (i = 0; i < ARRAY_SIZE(vdso_patches); i++) {
584 struct vdso_patch_def *patch = &vdso_patches[i];
585 int match = (cur_cpu_spec->cpu_features & patch->ftr_mask)
586 == patch->ftr_value;
587 if (!match)
588 continue;
589
590 DBG("replacing %s with %s...\n", patch->gen_name,
591 patch->fix_name ? "NONE" : patch->fix_name);
592
593 /*
594 * Patch the 32 bits and 64 bits symbols. Note that we do not
595 * patch the "." symbol on 64 bits.
596 * It would be easy to do, but doesn't seem to be necessary,
597 * patching the OPD symbol is enough.
598 */
599 vdso_do_func_patch32(v32, v64, patch->gen_name,
600 patch->fix_name);
601#ifdef CONFIG_PPC64
602 vdso_do_func_patch64(v32, v64, patch->gen_name,
603 patch->fix_name);
604#endif /* CONFIG_PPC64 */
605 }
606
607 return 0;
608}
609
610
611static __init int vdso_setup(void)
612{
613 struct lib32_elfinfo v32;
614 struct lib64_elfinfo v64;
615
616 v32.hdr = vdso32_kbase;
617#ifdef CONFIG_PPC64
618 v64.hdr = vdso64_kbase;
619#endif
620 if (vdso_do_find_sections(&v32, &v64))
621 return -1;
622
623 if (vdso_fixup_datapage(&v32, &v64))
624 return -1;
625
0909c8c2
BH
626 if (vdso_fixup_features(&v32, &v64))
627 return -1;
628
a7f290da
BH
629 if (vdso_fixup_alt_funcs(&v32, &v64))
630 return -1;
631
632 vdso_setup_trampolines(&v32, &v64);
633
634 return 0;
635}
636
637/*
638 * Called from setup_arch to initialize the bitmap of available
639 * syscalls in the systemcfg page
640 */
641static void __init vdso_setup_syscall_map(void)
642{
643 unsigned int i;
644 extern unsigned long *sys_call_table;
645 extern unsigned long sys_ni_syscall;
646
647
648 for (i = 0; i < __NR_syscalls; i++) {
649#ifdef CONFIG_PPC64
650 if (sys_call_table[i*2] != sys_ni_syscall)
651 vdso_data->syscall_map_64[i >> 5] |=
652 0x80000000UL >> (i & 0x1f);
653 if (sys_call_table[i*2+1] != sys_ni_syscall)
654 vdso_data->syscall_map_32[i >> 5] |=
655 0x80000000UL >> (i & 0x1f);
656#else /* CONFIG_PPC64 */
657 if (sys_call_table[i] != sys_ni_syscall)
658 vdso_data->syscall_map_32[i >> 5] |=
659 0x80000000UL >> (i & 0x1f);
660#endif /* CONFIG_PPC64 */
661 }
662}
663
18ad51dd 664#ifdef CONFIG_PPC64
061d19f2 665int vdso_getcpu_init(void)
18ad51dd
AB
666{
667 unsigned long cpu, node, val;
668
669 /*
9d378dfa
SW
670 * SPRG_VDSO contains the CPU in the bottom 16 bits and the NUMA node
671 * in the next 16 bits. The VDSO uses this to implement getcpu().
18ad51dd
AB
672 */
673 cpu = get_cpu();
674 WARN_ON_ONCE(cpu > 0xffff);
675
676 node = cpu_to_node(cpu);
677 WARN_ON_ONCE(node > 0xffff);
678
679 val = (cpu & 0xfff) | ((node & 0xffff) << 16);
9d378dfa
SW
680 mtspr(SPRN_SPRG_VDSO_WRITE, val);
681 get_paca()->sprg_vdso = val;
18ad51dd
AB
682
683 put_cpu();
684
685 return 0;
686}
687/* We need to call this before SMP init */
688early_initcall(vdso_getcpu_init);
689#endif
a7f290da 690
7ac9a137 691static int __init vdso_init(void)
a7f290da
BH
692{
693 int i;
694
695#ifdef CONFIG_PPC64
696 /*
06fe9fb4 697 * Fill up the "systemcfg" stuff for backward compatibility
a7f290da 698 */
31fe5bf6 699 strcpy((char *)vdso_data->eye_catcher, "SYSTEMCFG:PPC64");
a7f290da
BH
700 vdso_data->version.major = SYSTEMCFG_MAJOR;
701 vdso_data->version.minor = SYSTEMCFG_MINOR;
702 vdso_data->processor = mfspr(SPRN_PVR);
e8222502 703 /*
1d9a4731 704 * Fake the old platform number for pSeries and add
e8222502
BH
705 * in LPAR bit if necessary
706 */
1d9a4731 707 vdso_data->platform = 0x100;
e8222502
BH
708 if (firmware_has_feature(FW_FEATURE_LPAR))
709 vdso_data->platform |= 1;
95f72d1e 710 vdso_data->physicalMemorySize = memblock_phys_mem_size();
a7f290da
BH
711 vdso_data->dcache_size = ppc64_caches.dsize;
712 vdso_data->dcache_line_size = ppc64_caches.dline_size;
713 vdso_data->icache_size = ppc64_caches.isize;
714 vdso_data->icache_line_size = ppc64_caches.iline_size;
715
fbe48175
OJ
716 /* XXXOJN: Blocks should be added to ppc64_caches and used instead */
717 vdso_data->dcache_block_size = ppc64_caches.dline_size;
718 vdso_data->icache_block_size = ppc64_caches.iline_size;
719 vdso_data->dcache_log_block_size = ppc64_caches.log_dline_size;
720 vdso_data->icache_log_block_size = ppc64_caches.log_iline_size;
721
a7f290da
BH
722 /*
723 * Calculate the size of the 64 bits vDSO
724 */
725 vdso64_pages = (&vdso64_end - &vdso64_start) >> PAGE_SHIFT;
726 DBG("vdso64_kbase: %p, 0x%x pages\n", vdso64_kbase, vdso64_pages);
fbe48175
OJ
727#else
728 vdso_data->dcache_block_size = L1_CACHE_BYTES;
729 vdso_data->dcache_log_block_size = L1_CACHE_SHIFT;
730 vdso_data->icache_block_size = L1_CACHE_BYTES;
731 vdso_data->icache_log_block_size = L1_CACHE_SHIFT;
a7f290da
BH
732#endif /* CONFIG_PPC64 */
733
734
735 /*
736 * Calculate the size of the 32 bits vDSO
737 */
738 vdso32_pages = (&vdso32_end - &vdso32_start) >> PAGE_SHIFT;
739 DBG("vdso32_kbase: %p, 0x%x pages\n", vdso32_kbase, vdso32_pages);
740
741
742 /*
743 * Setup the syscall map in the vDOS
744 */
745 vdso_setup_syscall_map();
0909c8c2 746
a7f290da
BH
747 /*
748 * Initialize the vDSO images in memory, that is do necessary
749 * fixups of vDSO symbols, locate trampolines, etc...
750 */
751 if (vdso_setup()) {
752 printk(KERN_ERR "vDSO setup failure, not enabled !\n");
753 vdso32_pages = 0;
754#ifdef CONFIG_PPC64
755 vdso64_pages = 0;
756#endif
7ac9a137 757 return 0;
a7f290da
BH
758 }
759
760 /* Make sure pages are in the correct state */
7ac9a137
BH
761 vdso32_pagelist = kzalloc(sizeof(struct page *) * (vdso32_pages + 2),
762 GFP_KERNEL);
763 BUG_ON(vdso32_pagelist == NULL);
a7f290da
BH
764 for (i = 0; i < vdso32_pages; i++) {
765 struct page *pg = virt_to_page(vdso32_kbase + i*PAGE_SIZE);
766 ClearPageReserved(pg);
767 get_page(pg);
c13e4ca2 768 vdso32_pagelist[i] = pg;
a7f290da 769 }
c13e4ca2
RM
770 vdso32_pagelist[i++] = virt_to_page(vdso_data);
771 vdso32_pagelist[i] = NULL;
772
a7f290da 773#ifdef CONFIG_PPC64
7ac9a137
BH
774 vdso64_pagelist = kzalloc(sizeof(struct page *) * (vdso64_pages + 2),
775 GFP_KERNEL);
776 BUG_ON(vdso64_pagelist == NULL);
a7f290da
BH
777 for (i = 0; i < vdso64_pages; i++) {
778 struct page *pg = virt_to_page(vdso64_kbase + i*PAGE_SIZE);
779 ClearPageReserved(pg);
780 get_page(pg);
c13e4ca2 781 vdso64_pagelist[i] = pg;
a7f290da 782 }
c13e4ca2
RM
783 vdso64_pagelist[i++] = virt_to_page(vdso_data);
784 vdso64_pagelist[i] = NULL;
a7f290da
BH
785#endif /* CONFIG_PPC64 */
786
787 get_page(virt_to_page(vdso_data));
7ac9a137
BH
788
789 smp_wmb();
790 vdso_ready = 1;
791
792 return 0;
a7f290da 793}
7ac9a137 794arch_initcall(vdso_init);
This page took 0.682369 seconds and 5 git commands to generate.