sys_riscv.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (C) 2012 Regents of the University of California
  3. * Copyright (C) 2014 Darius Rad <darius@bluespec.com>
  4. * Copyright (C) 2017 SiFive
  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, version 2.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/syscalls.h>
  16. #include <asm/cmpxchg.h>
  17. #include <asm/unistd.h>
  18. static long riscv_sys_mmap(unsigned long addr, unsigned long len,
  19. unsigned long prot, unsigned long flags,
  20. unsigned long fd, off_t offset,
  21. unsigned long page_shift_offset)
  22. {
  23. if (unlikely(offset & (~PAGE_MASK >> page_shift_offset)))
  24. return -EINVAL;
  25. return sys_mmap_pgoff(addr, len, prot, flags, fd,
  26. offset >> (PAGE_SHIFT - page_shift_offset));
  27. }
  28. #ifdef CONFIG_64BIT
  29. SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
  30. unsigned long, prot, unsigned long, flags,
  31. unsigned long, fd, off_t, offset)
  32. {
  33. return riscv_sys_mmap(addr, len, prot, flags, fd, offset, 0);
  34. }
  35. #else
  36. SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
  37. unsigned long, prot, unsigned long, flags,
  38. unsigned long, fd, off_t, offset)
  39. {
  40. /*
  41. * Note that the shift for mmap2 is constant (12),
  42. * regardless of PAGE_SIZE
  43. */
  44. return riscv_sys_mmap(addr, len, prot, flags, fd, offset, 12);
  45. }
  46. #endif /* !CONFIG_64BIT */