sys.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. *
  14. * This file contains various random system calls that
  15. * have a non-standard calling sequence on the Linux/TILE
  16. * platform.
  17. */
  18. #include <linux/errno.h>
  19. #include <linux/sched.h>
  20. #include <linux/mm.h>
  21. #include <linux/smp.h>
  22. #include <linux/syscalls.h>
  23. #include <linux/mman.h>
  24. #include <linux/file.h>
  25. #include <linux/mempolicy.h>
  26. #include <linux/binfmts.h>
  27. #include <linux/fs.h>
  28. #include <linux/compat.h>
  29. #include <linux/uaccess.h>
  30. #include <linux/signal.h>
  31. #include <asm/syscalls.h>
  32. #include <asm/pgtable.h>
  33. #include <asm/homecache.h>
  34. #include <asm/cachectl.h>
  35. #include <asm/byteorder.h>
  36. #include <arch/chip.h>
  37. SYSCALL_DEFINE3(cacheflush, unsigned long, addr, unsigned long, len,
  38. unsigned long, flags)
  39. {
  40. /* DCACHE is not particularly effective if not bound to one cpu. */
  41. if (flags & DCACHE)
  42. homecache_evict(cpumask_of(raw_smp_processor_id()));
  43. if (flags & ICACHE)
  44. flush_remote(0, HV_FLUSH_EVICT_L1I, mm_cpumask(current->mm),
  45. 0, 0, 0, NULL, NULL, 0);
  46. return 0;
  47. }
  48. /*
  49. * Syscalls that pass 64-bit values on 32-bit systems normally
  50. * pass them as (low,high) word packed into the immediately adjacent
  51. * registers. If the low word naturally falls on an even register,
  52. * our ABI makes it work correctly; if not, we adjust it here.
  53. * Handling it here means we don't have to fix uclibc AND glibc AND
  54. * any other standard libcs we want to support.
  55. */
  56. #if !defined(__tilegx__) || defined(CONFIG_COMPAT)
  57. #ifdef __BIG_ENDIAN
  58. #define SYSCALL_PAIR(name) u32 name ## _hi, u32 name ## _lo
  59. #else
  60. #define SYSCALL_PAIR(name) u32 name ## _lo, u32 name ## _hi
  61. #endif
  62. ssize_t sys32_readahead(int fd, SYSCALL_PAIR(offset), u32 count)
  63. {
  64. return sys_readahead(fd, ((loff_t)offset_hi << 32) | offset_lo, count);
  65. }
  66. int sys32_fadvise64_64(int fd, SYSCALL_PAIR(offset),
  67. SYSCALL_PAIR(len), int advice)
  68. {
  69. return sys_fadvise64_64(fd, ((loff_t)offset_hi << 32) | offset_lo,
  70. ((loff_t)len_hi << 32) | len_lo, advice);
  71. }
  72. #endif /* 32-bit syscall wrappers */
  73. /* Note: used by the compat code even in 64-bit Linux. */
  74. SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
  75. unsigned long, prot, unsigned long, flags,
  76. unsigned long, fd, unsigned long, off_4k)
  77. {
  78. #define PAGE_ADJUST (PAGE_SHIFT - 12)
  79. if (off_4k & ((1 << PAGE_ADJUST) - 1))
  80. return -EINVAL;
  81. return sys_mmap_pgoff(addr, len, prot, flags, fd,
  82. off_4k >> PAGE_ADJUST);
  83. }
  84. #ifdef __tilegx__
  85. SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
  86. unsigned long, prot, unsigned long, flags,
  87. unsigned long, fd, off_t, offset)
  88. {
  89. if (offset & ((1 << PAGE_SHIFT) - 1))
  90. return -EINVAL;
  91. return sys_mmap_pgoff(addr, len, prot, flags, fd,
  92. offset >> PAGE_SHIFT);
  93. }
  94. #endif
  95. /* Provide the actual syscall number to call mapping. */
  96. #undef __SYSCALL
  97. #define __SYSCALL(nr, call) [nr] = (call),
  98. #ifndef __tilegx__
  99. /* See comments at the top of the file. */
  100. #define sys_fadvise64_64 sys32_fadvise64_64
  101. #define sys_readahead sys32_readahead
  102. #endif
  103. /* Call the assembly trampolines where necessary. */
  104. #undef sys_rt_sigreturn
  105. #define sys_rt_sigreturn _sys_rt_sigreturn
  106. #define sys_clone _sys_clone
  107. /*
  108. * Note that we can't include <linux/unistd.h> here since the header
  109. * guard will defeat us; <asm/unistd.h> checks for __SYSCALL as well.
  110. */
  111. void *sys_call_table[__NR_syscalls] = {
  112. [0 ... __NR_syscalls-1] = sys_ni_syscall,
  113. #include <asm/unistd.h>
  114. };