nvc0_graph.fuc 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. /* fuc microcode util functions for nvc0 PGRAPH
  2. *
  3. * Copyright 2011 Red Hat Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors: Ben Skeggs
  24. */
  25. define(`mmctx_data', `.b32 eval((($2 - 1) << 26) | $1)')
  26. define(`queue_init', `.skip eval((2 * 4) + ((8 * 4) * 2))')
  27. ifdef(`include_code', `
  28. // Error codes
  29. define(`E_BAD_COMMAND', 0x01)
  30. define(`E_CMD_OVERFLOW', 0x02)
  31. // Util macros to help with debugging ucode hangs etc
  32. define(`T_WAIT', 0)
  33. define(`T_MMCTX', 1)
  34. define(`T_STRWAIT', 2)
  35. define(`T_STRINIT', 3)
  36. define(`T_AUTO', 4)
  37. define(`T_CHAN', 5)
  38. define(`T_LOAD', 6)
  39. define(`T_SAVE', 7)
  40. define(`T_LCHAN', 8)
  41. define(`T_LCTXH', 9)
  42. define(`trace_set', `
  43. mov $r8 0x83c
  44. shl b32 $r8 6
  45. clear b32 $r9
  46. bset $r9 $1
  47. iowr I[$r8 + 0x000] $r9 // CC_SCRATCH[7]
  48. ')
  49. define(`trace_clr', `
  50. mov $r8 0x85c
  51. shl b32 $r8 6
  52. clear b32 $r9
  53. bset $r9 $1
  54. iowr I[$r8 + 0x000] $r9 // CC_SCRATCH[7]
  55. ')
  56. // queue_put - add request to queue
  57. //
  58. // In : $r13 queue pointer
  59. // $r14 command
  60. // $r15 data
  61. //
  62. queue_put:
  63. // make sure we have space..
  64. ld b32 $r8 D[$r13 + 0x0] // GET
  65. ld b32 $r9 D[$r13 + 0x4] // PUT
  66. xor $r8 8
  67. cmpu b32 $r8 $r9
  68. bra ne queue_put_next
  69. mov $r15 E_CMD_OVERFLOW
  70. call error
  71. ret
  72. // store cmd/data on queue
  73. queue_put_next:
  74. and $r8 $r9 7
  75. shl b32 $r8 3
  76. add b32 $r8 $r13
  77. add b32 $r8 8
  78. st b32 D[$r8 + 0x0] $r14
  79. st b32 D[$r8 + 0x4] $r15
  80. // update PUT
  81. add b32 $r9 1
  82. and $r9 0xf
  83. st b32 D[$r13 + 0x4] $r9
  84. ret
  85. // queue_get - fetch request from queue
  86. //
  87. // In : $r13 queue pointer
  88. //
  89. // Out: $p1 clear on success (data available)
  90. // $r14 command
  91. // $r15 data
  92. //
  93. queue_get:
  94. bset $flags $p1
  95. ld b32 $r8 D[$r13 + 0x0] // GET
  96. ld b32 $r9 D[$r13 + 0x4] // PUT
  97. cmpu b32 $r8 $r9
  98. bra e queue_get_done
  99. // fetch first cmd/data pair
  100. and $r9 $r8 7
  101. shl b32 $r9 3
  102. add b32 $r9 $r13
  103. add b32 $r9 8
  104. ld b32 $r14 D[$r9 + 0x0]
  105. ld b32 $r15 D[$r9 + 0x4]
  106. // update GET
  107. add b32 $r8 1
  108. and $r8 0xf
  109. st b32 D[$r13 + 0x0] $r8
  110. bclr $flags $p1
  111. queue_get_done:
  112. ret
  113. // nv_rd32 - read 32-bit value from nv register
  114. //
  115. // In : $r14 register
  116. // Out: $r15 value
  117. //
  118. nv_rd32:
  119. mov $r11 0x728
  120. shl b32 $r11 6
  121. mov b32 $r12 $r14
  122. bset $r12 31 // MMIO_CTRL_PENDING
  123. iowr I[$r11 + 0x000] $r12 // MMIO_CTRL
  124. nv_rd32_wait:
  125. iord $r12 I[$r11 + 0x000]
  126. xbit $r12 $r12 31
  127. bra ne nv_rd32_wait
  128. mov $r10 6 // DONE_MMIO_RD
  129. call wait_doneo
  130. iord $r15 I[$r11 + 0x100] // MMIO_RDVAL
  131. ret
  132. // nv_wr32 - write 32-bit value to nv register
  133. //
  134. // In : $r14 register
  135. // $r15 value
  136. //
  137. nv_wr32:
  138. mov $r11 0x728
  139. shl b32 $r11 6
  140. iowr I[$r11 + 0x200] $r15 // MMIO_WRVAL
  141. mov b32 $r12 $r14
  142. bset $r12 31 // MMIO_CTRL_PENDING
  143. bset $r12 30 // MMIO_CTRL_WRITE
  144. iowr I[$r11 + 0x000] $r12 // MMIO_CTRL
  145. nv_wr32_wait:
  146. iord $r12 I[$r11 + 0x000]
  147. xbit $r12 $r12 31
  148. bra ne nv_wr32_wait
  149. ret
  150. // (re)set watchdog timer
  151. //
  152. // In : $r15 timeout
  153. //
  154. watchdog_reset:
  155. mov $r8 0x430
  156. shl b32 $r8 6
  157. bset $r15 31
  158. iowr I[$r8 + 0x000] $r15
  159. ret
  160. // clear watchdog timer
  161. watchdog_clear:
  162. mov $r8 0x430
  163. shl b32 $r8 6
  164. iowr I[$r8 + 0x000] $r0
  165. ret
  166. // wait_done{z,o} - wait on FUC_DONE bit to become clear/set
  167. //
  168. // In : $r10 bit to wait on
  169. //
  170. define(`wait_done', `
  171. $1:
  172. trace_set(T_WAIT);
  173. mov $r8 0x818
  174. shl b32 $r8 6
  175. iowr I[$r8 + 0x000] $r10 // CC_SCRATCH[6] = wait bit
  176. wait_done_$1:
  177. mov $r8 0x400
  178. shl b32 $r8 6
  179. iord $r8 I[$r8 + 0x000] // DONE
  180. xbit $r8 $r8 $r10
  181. bra $2 wait_done_$1
  182. trace_clr(T_WAIT)
  183. ret
  184. ')
  185. wait_done(wait_donez, ne)
  186. wait_done(wait_doneo, e)
  187. // mmctx_size - determine size of a mmio list transfer
  188. //
  189. // In : $r14 mmio list head
  190. // $r15 mmio list tail
  191. // Out: $r15 transfer size (in bytes)
  192. //
  193. mmctx_size:
  194. clear b32 $r9
  195. nv_mmctx_size_loop:
  196. ld b32 $r8 D[$r14]
  197. shr b32 $r8 26
  198. add b32 $r8 1
  199. shl b32 $r8 2
  200. add b32 $r9 $r8
  201. add b32 $r14 4
  202. cmpu b32 $r14 $r15
  203. bra ne nv_mmctx_size_loop
  204. mov b32 $r15 $r9
  205. ret
  206. // mmctx_xfer - execute a list of mmio transfers
  207. //
  208. // In : $r10 flags
  209. // bit 0: direction (0 = save, 1 = load)
  210. // bit 1: set if first transfer
  211. // bit 2: set if last transfer
  212. // $r11 base
  213. // $r12 mmio list head
  214. // $r13 mmio list tail
  215. // $r14 multi_stride
  216. // $r15 multi_mask
  217. //
  218. mmctx_xfer:
  219. trace_set(T_MMCTX)
  220. mov $r8 0x710
  221. shl b32 $r8 6
  222. clear b32 $r9
  223. or $r11 $r11
  224. bra e mmctx_base_disabled
  225. iowr I[$r8 + 0x000] $r11 // MMCTX_BASE
  226. bset $r9 0 // BASE_EN
  227. mmctx_base_disabled:
  228. or $r14 $r14
  229. bra e mmctx_multi_disabled
  230. iowr I[$r8 + 0x200] $r14 // MMCTX_MULTI_STRIDE
  231. iowr I[$r8 + 0x300] $r15 // MMCTX_MULTI_MASK
  232. bset $r9 1 // MULTI_EN
  233. mmctx_multi_disabled:
  234. add b32 $r8 0x100
  235. xbit $r11 $r10 0
  236. shl b32 $r11 16 // DIR
  237. bset $r11 12 // QLIMIT = 0x10
  238. xbit $r14 $r10 1
  239. shl b32 $r14 17
  240. or $r11 $r14 // START_TRIGGER
  241. iowr I[$r8 + 0x000] $r11 // MMCTX_CTRL
  242. // loop over the mmio list, and send requests to the hw
  243. mmctx_exec_loop:
  244. // wait for space in mmctx queue
  245. mmctx_wait_free:
  246. iord $r14 I[$r8 + 0x000] // MMCTX_CTRL
  247. and $r14 0x1f
  248. bra e mmctx_wait_free
  249. // queue up an entry
  250. ld b32 $r14 D[$r12]
  251. or $r14 $r9
  252. iowr I[$r8 + 0x300] $r14
  253. add b32 $r12 4
  254. cmpu b32 $r12 $r13
  255. bra ne mmctx_exec_loop
  256. xbit $r11 $r10 2
  257. bra ne mmctx_stop
  258. // wait for queue to empty
  259. mmctx_fini_wait:
  260. iord $r11 I[$r8 + 0x000] // MMCTX_CTRL
  261. and $r11 0x1f
  262. cmpu b32 $r11 0x10
  263. bra ne mmctx_fini_wait
  264. mov $r10 2 // DONE_MMCTX
  265. call wait_donez
  266. bra mmctx_done
  267. mmctx_stop:
  268. xbit $r11 $r10 0
  269. shl b32 $r11 16 // DIR
  270. bset $r11 12 // QLIMIT = 0x10
  271. bset $r11 18 // STOP_TRIGGER
  272. iowr I[$r8 + 0x000] $r11 // MMCTX_CTRL
  273. mmctx_stop_wait:
  274. // wait for STOP_TRIGGER to clear
  275. iord $r11 I[$r8 + 0x000] // MMCTX_CTRL
  276. xbit $r11 $r11 18
  277. bra ne mmctx_stop_wait
  278. mmctx_done:
  279. trace_clr(T_MMCTX)
  280. ret
  281. // Wait for DONE_STRAND
  282. //
  283. strand_wait:
  284. push $r10
  285. mov $r10 2
  286. call wait_donez
  287. pop $r10
  288. ret
  289. // unknown - call before issuing strand commands
  290. //
  291. strand_pre:
  292. mov $r8 0x4afc
  293. sethi $r8 0x20000
  294. mov $r9 0xc
  295. iowr I[$r8] $r9
  296. call strand_wait
  297. ret
  298. // unknown - call after issuing strand commands
  299. //
  300. strand_post:
  301. mov $r8 0x4afc
  302. sethi $r8 0x20000
  303. mov $r9 0xd
  304. iowr I[$r8] $r9
  305. call strand_wait
  306. ret
  307. // Selects strand set?!
  308. //
  309. // In: $r14 id
  310. //
  311. strand_set:
  312. mov $r10 0x4ffc
  313. sethi $r10 0x20000
  314. sub b32 $r11 $r10 0x500
  315. mov $r12 0xf
  316. iowr I[$r10 + 0x000] $r12 // 0x93c = 0xf
  317. mov $r12 0xb
  318. iowr I[$r11 + 0x000] $r12 // 0x928 = 0xb
  319. call strand_wait
  320. iowr I[$r10 + 0x000] $r14 // 0x93c = <id>
  321. mov $r12 0xa
  322. iowr I[$r11 + 0x000] $r12 // 0x928 = 0xa
  323. call strand_wait
  324. ret
  325. // Initialise strand context data
  326. //
  327. // In : $r15 context base
  328. // Out: $r15 context size (in bytes)
  329. //
  330. // Strandset(?) 3 hardcoded currently
  331. //
  332. strand_ctx_init:
  333. trace_set(T_STRINIT)
  334. call strand_pre
  335. mov $r14 3
  336. call strand_set
  337. mov $r10 0x46fc
  338. sethi $r10 0x20000
  339. add b32 $r11 $r10 0x400
  340. iowr I[$r10 + 0x100] $r0 // STRAND_FIRST_GENE = 0
  341. mov $r12 1
  342. iowr I[$r11 + 0x000] $r12 // STRAND_CMD = LATCH_FIRST_GENE
  343. call strand_wait
  344. sub b32 $r12 $r0 1
  345. iowr I[$r10 + 0x000] $r12 // STRAND_GENE_CNT = 0xffffffff
  346. mov $r12 2
  347. iowr I[$r11 + 0x000] $r12 // STRAND_CMD = LATCH_GENE_CNT
  348. call strand_wait
  349. call strand_post
  350. // read the size of each strand, poke the context offset of
  351. // each into STRAND_{SAVE,LOAD}_SWBASE now, no need to worry
  352. // about it later then.
  353. mov $r8 0x880
  354. shl b32 $r8 6
  355. iord $r9 I[$r8 + 0x000] // STRANDS
  356. add b32 $r8 0x2200
  357. shr b32 $r14 $r15 8
  358. ctx_init_strand_loop:
  359. iowr I[$r8 + 0x000] $r14 // STRAND_SAVE_SWBASE
  360. iowr I[$r8 + 0x100] $r14 // STRAND_LOAD_SWBASE
  361. iord $r10 I[$r8 + 0x200] // STRAND_SIZE
  362. shr b32 $r10 6
  363. add b32 $r10 1
  364. add b32 $r14 $r10
  365. add b32 $r8 4
  366. sub b32 $r9 1
  367. bra ne ctx_init_strand_loop
  368. shl b32 $r14 8
  369. sub b32 $r15 $r14 $r15
  370. trace_clr(T_STRINIT)
  371. ret
  372. ')