uaccess.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (C) 2011 Texas Instruments Incorporated
  3. * Author: Mark Salter <msalter@redhat.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #ifndef _ASM_C6X_UACCESS_H
  10. #define _ASM_C6X_UACCESS_H
  11. #include <linux/types.h>
  12. #include <linux/compiler.h>
  13. #include <linux/string.h>
  14. #ifdef CONFIG_ACCESS_CHECK
  15. #define __access_ok _access_ok
  16. #endif
  17. /*
  18. * __copy_from_user/copy_to_user are based on ones in asm-generic/uaccess.h
  19. *
  20. * C6X supports unaligned 32 and 64 bit loads and stores.
  21. */
  22. static inline __must_check long __copy_from_user(void *to,
  23. const void __user *from, unsigned long n)
  24. {
  25. u32 tmp32;
  26. u64 tmp64;
  27. if (__builtin_constant_p(n)) {
  28. switch (n) {
  29. case 1:
  30. *(u8 *)to = *(u8 __force *)from;
  31. return 0;
  32. case 4:
  33. asm volatile ("ldnw .d1t1 *%2,%0\n"
  34. "nop 4\n"
  35. "stnw .d1t1 %0,*%1\n"
  36. : "=&a"(tmp32)
  37. : "A"(to), "a"(from)
  38. : "memory");
  39. return 0;
  40. case 8:
  41. asm volatile ("ldndw .d1t1 *%2,%0\n"
  42. "nop 4\n"
  43. "stndw .d1t1 %0,*%1\n"
  44. : "=&a"(tmp64)
  45. : "a"(to), "a"(from)
  46. : "memory");
  47. return 0;
  48. default:
  49. break;
  50. }
  51. }
  52. memcpy(to, (const void __force *)from, n);
  53. return 0;
  54. }
  55. static inline __must_check long __copy_to_user(void __user *to,
  56. const void *from, unsigned long n)
  57. {
  58. u32 tmp32;
  59. u64 tmp64;
  60. if (__builtin_constant_p(n)) {
  61. switch (n) {
  62. case 1:
  63. *(u8 __force *)to = *(u8 *)from;
  64. return 0;
  65. case 4:
  66. asm volatile ("ldnw .d1t1 *%2,%0\n"
  67. "nop 4\n"
  68. "stnw .d1t1 %0,*%1\n"
  69. : "=&a"(tmp32)
  70. : "a"(to), "a"(from)
  71. : "memory");
  72. return 0;
  73. case 8:
  74. asm volatile ("ldndw .d1t1 *%2,%0\n"
  75. "nop 4\n"
  76. "stndw .d1t1 %0,*%1\n"
  77. : "=&a"(tmp64)
  78. : "a"(to), "a"(from)
  79. : "memory");
  80. return 0;
  81. default:
  82. break;
  83. }
  84. }
  85. memcpy((void __force *)to, from, n);
  86. return 0;
  87. }
  88. #define __copy_to_user __copy_to_user
  89. #define __copy_from_user __copy_from_user
  90. extern int _access_ok(unsigned long addr, unsigned long size);
  91. #ifdef CONFIG_ACCESS_CHECK
  92. #define __access_ok _access_ok
  93. #endif
  94. #include <asm-generic/uaccess.h>
  95. #endif /* _ASM_C6X_UACCESS_H */