macros.fuc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. * Copyright 2013 Red Hat Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Ben Skeggs <bskeggs@redhat.com>
  23. */
  24. #include "os.h"
  25. #define GF100 0xc0
  26. #define GF117 0xd7
  27. #define GK100 0xe0
  28. #define GK110 0xf0
  29. #define GK208 0x108
  30. #define GM107 0x117
  31. #define NV_PGRAPH_TRAPPED_ADDR 0x400704
  32. #define NV_PGRAPH_TRAPPED_DATA_LO 0x400708
  33. #define NV_PGRAPH_TRAPPED_DATA_HI 0x40070c
  34. #define NV_PGRAPH_FE_OBJECT_TABLE(n) ((n) * 4 + 0x400700)
  35. #define NV_PGRAPH_FECS_INTR_ACK 0x409004
  36. #define NV_PGRAPH_FECS_INTR 0x409008
  37. #define NV_PGRAPH_FECS_INTR_FWMTHD 0x00000400
  38. #define NV_PGRAPH_FECS_INTR_CHSW 0x00000100
  39. #define NV_PGRAPH_FECS_INTR_FIFO 0x00000004
  40. #define NV_PGRAPH_FECS_INTR_MODE 0x40900c
  41. #define NV_PGRAPH_FECS_INTR_MODE_FIFO 0x00000004
  42. #define NV_PGRAPH_FECS_INTR_MODE_FIFO_LEVEL 0x00000004
  43. #define NV_PGRAPH_FECS_INTR_MODE_FIFO_EDGE 0x00000000
  44. #define NV_PGRAPH_FECS_INTR_EN_SET 0x409010
  45. #define NV_PGRAPH_FECS_INTR_EN_SET_FIFO 0x00000004
  46. #define NV_PGRAPH_FECS_INTR_ROUTE 0x40901c
  47. #define NV_PGRAPH_FECS_ACCESS 0x409048
  48. #define NV_PGRAPH_FECS_ACCESS_FIFO 0x00000002
  49. #define NV_PGRAPH_FECS_FIFO_DATA 0x409064
  50. #define NV_PGRAPH_FECS_FIFO_CMD 0x409068
  51. #define NV_PGRAPH_FECS_FIFO_ACK 0x409074
  52. #define NV_PGRAPH_FECS_CAPS 0x409108
  53. #define NV_PGRAPH_FECS_SIGNAL 0x409400
  54. #define NV_PGRAPH_FECS_IROUTE 0x409404
  55. #define NV_PGRAPH_FECS_BAR_MASK0 0x40940c
  56. #define NV_PGRAPH_FECS_BAR_MASK1 0x409410
  57. #define NV_PGRAPH_FECS_BAR 0x409414
  58. #define NV_PGRAPH_FECS_BAR_SET 0x409418
  59. #define NV_PGRAPH_FECS_RED_SWITCH 0x409614
  60. #define NV_PGRAPH_FECS_RED_SWITCH_ENABLE_ROP 0x00000400
  61. #define NV_PGRAPH_FECS_RED_SWITCH_ENABLE_GPC 0x00000200
  62. #define NV_PGRAPH_FECS_RED_SWITCH_ENABLE_MAIN 0x00000100
  63. #define NV_PGRAPH_FECS_RED_SWITCH_POWER_ROP 0x00000040
  64. #define NV_PGRAPH_FECS_RED_SWITCH_POWER_GPC 0x00000020
  65. #define NV_PGRAPH_FECS_RED_SWITCH_POWER_MAIN 0x00000010
  66. #define NV_PGRAPH_FECS_RED_SWITCH_PAUSE_GPC 0x00000002
  67. #define NV_PGRAPH_FECS_RED_SWITCH_PAUSE_MAIN 0x00000001
  68. #define NV_PGRAPH_FECS_MMCTX_SAVE_SWBASE 0x409700
  69. #define NV_PGRAPH_FECS_MMCTX_LOAD_SWBASE 0x409704
  70. #define NV_PGRAPH_FECS_MMCTX_LOAD_COUNT 0x40974c
  71. #define NV_PGRAPH_FECS_MMCTX_SAVE_SWBASE 0x409700
  72. #define NV_PGRAPH_FECS_MMCTX_LOAD_SWBASE 0x409704
  73. #define NV_PGRAPH_FECS_MMCTX_BASE 0x409710
  74. #define NV_PGRAPH_FECS_MMCTX_CTRL 0x409714
  75. #define NV_PGRAPH_FECS_MMCTX_MULTI_STRIDE 0x409718
  76. #define NV_PGRAPH_FECS_MMCTX_MULTI_MASK 0x40971c
  77. #define NV_PGRAPH_FECS_MMCTX_QUEUE 0x409720
  78. #define NV_PGRAPH_FECS_MMIO_BASE 0x409724
  79. #define NV_PGRAPH_FECS_MMIO_CTRL 0x409728
  80. #define NV_PGRAPH_FECS_MMIO_CTRL_BASE_ENABLE 0x00000001
  81. #define NV_PGRAPH_FECS_MMIO_RDVAL 0x40972c
  82. #define NV_PGRAPH_FECS_MMIO_WRVAL 0x409730
  83. #define NV_PGRAPH_FECS_MMCTX_LOAD_COUNT 0x40974c
  84. #if CHIPSET < GK110
  85. #define NV_PGRAPH_FECS_CC_SCRATCH_VAL(n) ((n) * 4 + 0x409800)
  86. #define NV_PGRAPH_FECS_CC_SCRATCH_SET(n) ((n) * 4 + 0x409820)
  87. #define NV_PGRAPH_FECS_CC_SCRATCH_CLR(n) ((n) * 4 + 0x409840)
  88. #define NV_PGRAPH_FECS_UNK86C 0x40986c
  89. #else
  90. #define NV_PGRAPH_FECS_CC_SCRATCH_VAL(n) ((n) * 4 + 0x409800)
  91. #define NV_PGRAPH_FECS_CC_SCRATCH_CLR(n) ((n) * 4 + 0x409840)
  92. #define NV_PGRAPH_FECS_UNK86C 0x40988c
  93. #define NV_PGRAPH_FECS_CC_SCRATCH_SET(n) ((n) * 4 + 0x4098c0)
  94. #endif
  95. #define NV_PGRAPH_FECS_STRANDS_CNT 0x409880
  96. #define NV_PGRAPH_FECS_STRAND_SAVE_SWBASE 0x409908
  97. #define NV_PGRAPH_FECS_STRAND_LOAD_SWBASE 0x40990c
  98. #define NV_PGRAPH_FECS_STRAND_WORDS 0x409910
  99. #define NV_PGRAPH_FECS_STRAND_DATA 0x409918
  100. #define NV_PGRAPH_FECS_STRAND_SELECT 0x40991c
  101. #define NV_PGRAPH_FECS_STRAND_CMD 0x409928
  102. #define NV_PGRAPH_FECS_STRAND_CMD_SEEK 0x00000001
  103. #define NV_PGRAPH_FECS_STRAND_CMD_GET_INFO 0x00000002
  104. #define NV_PGRAPH_FECS_STRAND_CMD_SAVE 0x00000003
  105. #define NV_PGRAPH_FECS_STRAND_CMD_LOAD 0x00000004
  106. #define NV_PGRAPH_FECS_STRAND_CMD_ACTIVATE_FILTER 0x0000000a
  107. #define NV_PGRAPH_FECS_STRAND_CMD_DEACTIVATE_FILTER 0x0000000b
  108. #define NV_PGRAPH_FECS_STRAND_CMD_ENABLE 0x0000000c
  109. #define NV_PGRAPH_FECS_STRAND_CMD_DISABLE 0x0000000d
  110. #define NV_PGRAPH_FECS_STRAND_FILTER 0x40993c
  111. #define NV_PGRAPH_FECS_MEM_BASE 0x409a04
  112. #define NV_PGRAPH_FECS_MEM_CHAN 0x409a0c
  113. #define NV_PGRAPH_FECS_MEM_CMD 0x409a10
  114. #define NV_PGRAPH_FECS_MEM_CMD_LOAD_CHAN 0x00000007
  115. #define NV_PGRAPH_FECS_MEM_TARGET 0x409a20
  116. #define NV_PGRAPH_FECS_MEM_TARGET_UNK31 0x80000000
  117. #define NV_PGRAPH_FECS_MEM_TARGET_AS 0x0000001f
  118. #define NV_PGRAPH_FECS_MEM_TARGET_AS_VM 0x00000001
  119. #define NV_PGRAPH_FECS_MEM_TARGET_AS_VRAM 0x00000002
  120. #define NV_PGRAPH_FECS_CHAN_ADDR 0x409b00
  121. #define NV_PGRAPH_FECS_CHAN_NEXT 0x409b04
  122. #define NV_PGRAPH_FECS_CHSW 0x409b0c
  123. #define NV_PGRAPH_FECS_CHSW_ACK 0x00000001
  124. #define NV_PGRAPH_FECS_INTR_UP_SET 0x409c1c
  125. #define NV_PGRAPH_FECS_INTR_UP_EN 0x409c24
  126. #define NV_PGRAPH_GPCX_GPCCS_INTR_ACK 0x41a004
  127. #define NV_PGRAPH_GPCX_GPCCS_INTR 0x41a008
  128. #define NV_PGRAPH_GPCX_GPCCS_INTR_FIFO 0x00000004
  129. #define NV_PGRAPH_GPCX_GPCCS_INTR_EN_SET 0x41a010
  130. #define NV_PGRAPH_GPCX_GPCCS_INTR_EN_SET_FIFO 0x00000004
  131. #define NV_PGRAPH_GPCX_GPCCS_INTR_ROUTE 0x41a01c
  132. #define NV_PGRAPH_GPCX_GPCCS_ACCESS 0x41a048
  133. #define NV_PGRAPH_GPCX_GPCCS_ACCESS_FIFO 0x00000002
  134. #define NV_PGRAPH_GPCX_GPCCS_FIFO_DATA 0x41a064
  135. #define NV_PGRAPH_GPCX_GPCCS_FIFO_CMD 0x41a068
  136. #define NV_PGRAPH_GPCX_GPCCS_FIFO_ACK 0x41a074
  137. #define NV_PGRAPH_GPCX_GPCCS_UNITS 0x41a608
  138. #define NV_PGRAPH_GPCX_GPCCS_CAPS 0x41a108
  139. #define NV_PGRAPH_GPCX_GPCCS_RED_SWITCH 0x41a614
  140. #define NV_PGRAPH_GPCX_GPCCS_RED_SWITCH_UNK11 0x00000800
  141. #define NV_PGRAPH_GPCX_GPCCS_RED_SWITCH_ENABLE 0x00000200
  142. #define NV_PGRAPH_GPCX_GPCCS_RED_SWITCH_POWER 0x00000020
  143. #define NV_PGRAPH_GPCX_GPCCS_RED_SWITCH_PAUSE 0x00000002
  144. #define NV_PGRAPH_GPCX_GPCCS_MYINDEX 0x41a618
  145. #define NV_PGRAPH_GPCX_GPCCS_MMCTX_SAVE_SWBASE 0x41a700
  146. #define NV_PGRAPH_GPCX_GPCCS_MMCTX_LOAD_SWBASE 0x41a704
  147. #define NV_PGRAPH_GPCX_GPCCS_MMIO_BASE 0x41a724
  148. #define NV_PGRAPH_GPCX_GPCCS_MMIO_CTRL 0x41a728
  149. #define NV_PGRAPH_GPCX_GPCCS_MMIO_CTRL_BASE_ENABLE 0x00000001
  150. #define NV_PGRAPH_GPCX_GPCCS_MMIO_RDVAL 0x41a72c
  151. #define NV_PGRAPH_GPCX_GPCCS_MMIO_WRVAL 0x41a730
  152. #define NV_PGRAPH_GPCX_GPCCS_MMCTX_LOAD_COUNT 0x41a74c
  153. #if CHIPSET < GK110
  154. #define NV_PGRAPH_GPCX_GPCCS_CC_SCRATCH_VAL(n) ((n) * 4 + 0x41a800)
  155. #define NV_PGRAPH_GPCX_GPCCS_CC_SCRATCH_SET(n) ((n) * 4 + 0x41a820)
  156. #define NV_PGRAPH_GPCX_GPCCS_CC_SCRATCH_CLR(n) ((n) * 4 + 0x41a840)
  157. #define NV_PGRAPH_GPCX_GPCCS_UNK86C 0x41a86c
  158. #else
  159. #define NV_PGRAPH_GPCX_GPCCS_CC_SCRATCH_VAL(n) ((n) * 4 + 0x41a800)
  160. #define NV_PGRAPH_GPCX_GPCCS_CC_SCRATCH_CLR(n) ((n) * 4 + 0x41a840)
  161. #define NV_PGRAPH_GPCX_GPCCS_UNK86C 0x41a88c
  162. #define NV_PGRAPH_GPCX_GPCCS_CC_SCRATCH_SET(n) ((n) * 4 + 0x41a8c0)
  163. #endif
  164. #define NV_PGRAPH_GPCX_GPCCS_STRAND_SELECT 0x41a91c
  165. #define NV_PGRAPH_GPCX_GPCCS_STRAND_CMD 0x41a928
  166. #define NV_PGRAPH_GPCX_GPCCS_STRAND_CMD_SAVE 0x00000003
  167. #define NV_PGRAPH_GPCX_GPCCS_STRAND_CMD_LOAD 0x00000004
  168. #define NV_PGRAPH_GPCX_GPCCS_MEM_BASE 0x41aa04
  169. #define NV_PGRAPH_GPCX_GPCCS_TPC_STATUS 0x41acfc
  170. #define NV_PGRAPH_GPC0_TPC0 0x504000
  171. #define NV_PGRAPH_GPC0_TPC0__SIZE 0x000800
  172. #define NV_PGRAPH_GPC0_TPCX_STRAND_INDEX 0x501d60
  173. #define NV_PGRAPH_GPC0_TPCX_STRAND_INDEX_ALL 0x0000003f
  174. #define NV_PGRAPH_GPC0_TPCX_STRAND_DATA 0x501d98
  175. #define NV_PGRAPH_GPC0_TPCX_STRAND_SELECT 0x501d9c
  176. #define NV_PGRAPH_GPC0_TPCX_STRAND_CMD 0x501da8
  177. #define NV_PGRAPH_GPC0_TPCX_STRAND_CMD_SEEK 0x00000001
  178. #define NV_PGRAPH_GPC0_TPCX_STRAND_CMD_GET_INFO 0x00000002
  179. #define NV_PGRAPH_GPC0_TPCX_STRAND_CMD_SAVE 0x00000003
  180. #define NV_PGRAPH_GPC0_TPCX_STRAND_CMD_LOAD 0x00000004
  181. #define NV_PGRAPH_GPC0_TPCX_STRAND_CMD_ENABLE 0x0000000c
  182. #define NV_PGRAPH_GPC0_TPCX_STRAND_CMD_DISABLE 0x0000000d
  183. #define NV_PGRAPH_GPC0_TPCX_STRAND_MEM_BASE 0x501dc4
  184. #define NV_TPC_STRAND_INDEX 0x560
  185. #define NV_TPC_STRAND_CNT 0x570
  186. #define NV_TPC_STRAND_SAVE_SWBASE 0x588
  187. #define NV_TPC_STRAND_LOAD_SWBASE 0x58c
  188. #define NV_TPC_STRAND_WORDS 0x590
  189. #define mmctx_data(r,c) .b32 (((c - 1) << 26) | r)
  190. #define queue_init .skip 72 // (2 * 4) + ((8 * 4) * 2)
  191. #define T_WAIT 0
  192. #define T_MMCTX 1
  193. #define T_STRWAIT 2
  194. #define T_STRINIT 3
  195. #define T_AUTO 4
  196. #define T_CHAN 5
  197. #define T_LOAD 6
  198. #define T_SAVE 7
  199. #define T_LCHAN 8
  200. #define T_LCTXH 9
  201. #define T_STRTPC 10
  202. #if CHIPSET < GK208
  203. #define imm32(reg,val) /*
  204. */ movw reg ((val) & 0x0000ffff) /*
  205. */ sethi reg ((val) & 0xffff0000)
  206. #else
  207. #define imm32(reg,val) /*
  208. */ mov reg (val)
  209. #endif
  210. #define nv_mkio(rv,r,i) /*
  211. */ imm32(rv, (((r) & 0xffc) << 6) | ((i) << 2))
  212. #define hash #
  213. #define fn(a) a
  214. #if CHIPSET < GK208
  215. #define call(a) call fn(hash)a
  216. #else
  217. #define call(a) lcall fn(hash)a
  218. #endif
  219. #define nv_iord(rv,r,i) /*
  220. */ nv_mkio(rv,r,i) /*
  221. */ iord rv I[rv]
  222. #define nv_iowr(r,i,rv) /*
  223. */ nv_mkio($r0,r,i) /*
  224. */ iowr I[$r0] rv /*
  225. */ clear b32 $r0
  226. #define nv_rd32(reg,addr) /*
  227. */ imm32($r14, addr) /*
  228. */ call(nv_rd32) /*
  229. */ mov b32 reg $r15
  230. #define nv_wr32(addr,reg) /*
  231. */ mov b32 $r15 reg /*
  232. */ imm32($r14, addr) /*
  233. */ call(nv_wr32)
  234. #define trace_set(bit) /*
  235. */ clear b32 $r9 /*
  236. */ bset $r9 bit /*
  237. */ nv_iowr(NV_PGRAPH_FECS_CC_SCRATCH_SET(7), 0, $r9)
  238. #define trace_clr(bit) /*
  239. */ clear b32 $r9 /*
  240. */ bset $r9 bit /*
  241. */ nv_iowr(NV_PGRAPH_FECS_CC_SCRATCH_CLR(7), 0, $r9)