coprocessor.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * include/asm-xtensa/coprocessor.h
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 2003 - 2007 Tensilica Inc.
  9. */
  10. #ifndef _XTENSA_COPROCESSOR_H
  11. #define _XTENSA_COPROCESSOR_H
  12. #include <linux/stringify.h>
  13. #include <variant/core.h>
  14. #include <variant/tie.h>
  15. #include <asm/types.h>
  16. #ifdef __ASSEMBLY__
  17. # include <variant/tie-asm.h>
  18. .macro xchal_sa_start a b
  19. .set .Lxchal_pofs_, 0
  20. .set .Lxchal_ofs_, 0
  21. .endm
  22. .macro xchal_sa_align ptr minofs maxofs ofsalign totalign
  23. .set .Lxchal_ofs_, .Lxchal_ofs_ + .Lxchal_pofs_ + \totalign - 1
  24. .set .Lxchal_ofs_, (.Lxchal_ofs_ & -\totalign) - .Lxchal_pofs_
  25. .endm
  26. #define _SELECT ( XTHAL_SAS_TIE | XTHAL_SAS_OPT \
  27. | XTHAL_SAS_CC \
  28. | XTHAL_SAS_CALR | XTHAL_SAS_CALE )
  29. .macro save_xtregs_opt ptr clb at1 at2 at3 at4 offset
  30. .if XTREGS_OPT_SIZE > 0
  31. addi \clb, \ptr, \offset
  32. xchal_ncp_store \clb \at1 \at2 \at3 \at4 select=_SELECT
  33. .endif
  34. .endm
  35. .macro load_xtregs_opt ptr clb at1 at2 at3 at4 offset
  36. .if XTREGS_OPT_SIZE > 0
  37. addi \clb, \ptr, \offset
  38. xchal_ncp_load \clb \at1 \at2 \at3 \at4 select=_SELECT
  39. .endif
  40. .endm
  41. #undef _SELECT
  42. #define _SELECT ( XTHAL_SAS_TIE | XTHAL_SAS_OPT \
  43. | XTHAL_SAS_NOCC \
  44. | XTHAL_SAS_CALR | XTHAL_SAS_CALE | XTHAL_SAS_GLOB )
  45. .macro save_xtregs_user ptr clb at1 at2 at3 at4 offset
  46. .if XTREGS_USER_SIZE > 0
  47. addi \clb, \ptr, \offset
  48. xchal_ncp_store \clb \at1 \at2 \at3 \at4 select=_SELECT
  49. .endif
  50. .endm
  51. .macro load_xtregs_user ptr clb at1 at2 at3 at4 offset
  52. .if XTREGS_USER_SIZE > 0
  53. addi \clb, \ptr, \offset
  54. xchal_ncp_load \clb \at1 \at2 \at3 \at4 select=_SELECT
  55. .endif
  56. .endm
  57. #undef _SELECT
  58. #endif /* __ASSEMBLY__ */
  59. /*
  60. * XTENSA_HAVE_COPROCESSOR(x) returns 1 if coprocessor x is configured.
  61. *
  62. * XTENSA_HAVE_IO_PORT(x) returns 1 if io-port x is configured.
  63. *
  64. */
  65. #define XTENSA_HAVE_COPROCESSOR(x) \
  66. ((XCHAL_CP_MASK ^ XCHAL_CP_PORT_MASK) & (1 << (x)))
  67. #define XTENSA_HAVE_COPROCESSORS \
  68. (XCHAL_CP_MASK ^ XCHAL_CP_PORT_MASK)
  69. #define XTENSA_HAVE_IO_PORT(x) \
  70. (XCHAL_CP_PORT_MASK & (1 << (x)))
  71. #define XTENSA_HAVE_IO_PORTS \
  72. XCHAL_CP_PORT_MASK
  73. #ifndef __ASSEMBLY__
  74. #if XCHAL_HAVE_CP
  75. #define RSR_CPENABLE(x) do { \
  76. __asm__ __volatile__("rsr %0, cpenable" : "=a" (x)); \
  77. } while(0);
  78. #define WSR_CPENABLE(x) do { \
  79. __asm__ __volatile__("wsr %0, cpenable; rsync" :: "a" (x)); \
  80. } while(0);
  81. #endif /* XCHAL_HAVE_CP */
  82. /*
  83. * Additional registers.
  84. * We define three types of additional registers:
  85. * ext: extra registers that are used by the compiler
  86. * cpn: optional registers that can be used by a user application
  87. * cpX: coprocessor registers that can only be used if the corresponding
  88. * CPENABLE bit is set.
  89. */
  90. #define XCHAL_SA_REG(list,cc,abi,type,y,name,z,align,size,...) \
  91. __REG ## list (cc, abi, type, name, size, align)
  92. #define __REG0(cc,abi,t,name,s,a) __REG0_ ## cc (abi,name)
  93. #define __REG1(cc,abi,t,name,s,a) __REG1_ ## cc (name)
  94. #define __REG2(cc,abi,type,...) __REG2_ ## type (__VA_ARGS__)
  95. #define __REG0_0(abi,name)
  96. #define __REG0_1(abi,name) __REG0_1 ## abi (name)
  97. #define __REG0_10(name) __u32 name;
  98. #define __REG0_11(name) __u32 name;
  99. #define __REG0_12(name)
  100. #define __REG1_0(name) __u32 name;
  101. #define __REG1_1(name)
  102. #define __REG2_0(n,s,a) __u32 name;
  103. #define __REG2_1(n,s,a) unsigned char n[s] __attribute__ ((aligned(a)));
  104. #define __REG2_2(n,s,a) unsigned char n[s] __attribute__ ((aligned(a)));
  105. typedef struct { XCHAL_NCP_SA_LIST(0) } xtregs_opt_t
  106. __attribute__ ((aligned (XCHAL_NCP_SA_ALIGN)));
  107. typedef struct { XCHAL_NCP_SA_LIST(1) } xtregs_user_t
  108. __attribute__ ((aligned (XCHAL_NCP_SA_ALIGN)));
  109. #if XTENSA_HAVE_COPROCESSORS
  110. typedef struct { XCHAL_CP0_SA_LIST(2) } xtregs_cp0_t
  111. __attribute__ ((aligned (XCHAL_CP0_SA_ALIGN)));
  112. typedef struct { XCHAL_CP1_SA_LIST(2) } xtregs_cp1_t
  113. __attribute__ ((aligned (XCHAL_CP1_SA_ALIGN)));
  114. typedef struct { XCHAL_CP2_SA_LIST(2) } xtregs_cp2_t
  115. __attribute__ ((aligned (XCHAL_CP2_SA_ALIGN)));
  116. typedef struct { XCHAL_CP3_SA_LIST(2) } xtregs_cp3_t
  117. __attribute__ ((aligned (XCHAL_CP3_SA_ALIGN)));
  118. typedef struct { XCHAL_CP4_SA_LIST(2) } xtregs_cp4_t
  119. __attribute__ ((aligned (XCHAL_CP4_SA_ALIGN)));
  120. typedef struct { XCHAL_CP5_SA_LIST(2) } xtregs_cp5_t
  121. __attribute__ ((aligned (XCHAL_CP5_SA_ALIGN)));
  122. typedef struct { XCHAL_CP6_SA_LIST(2) } xtregs_cp6_t
  123. __attribute__ ((aligned (XCHAL_CP6_SA_ALIGN)));
  124. typedef struct { XCHAL_CP7_SA_LIST(2) } xtregs_cp7_t
  125. __attribute__ ((aligned (XCHAL_CP7_SA_ALIGN)));
  126. extern struct thread_info* coprocessor_owner[XCHAL_CP_MAX];
  127. extern void coprocessor_save(void*, int);
  128. extern void coprocessor_load(void*, int);
  129. extern void coprocessor_flush(struct thread_info*, int);
  130. extern void coprocessor_restore(struct thread_info*, int);
  131. extern void coprocessor_release_all(struct thread_info*);
  132. extern void coprocessor_flush_all(struct thread_info*);
  133. static inline void coprocessor_clear_cpenable(void)
  134. {
  135. unsigned long i = 0;
  136. WSR_CPENABLE(i);
  137. }
  138. #endif /* XTENSA_HAVE_COPROCESSORS */
  139. #endif /* !__ASSEMBLY__ */
  140. #endif /* _XTENSA_COPROCESSOR_H */