evergreen_blit_kms.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. /*
  2. * Copyright 2010 Advanced Micro Devices, 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 (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * 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) AND/OR ITS SUPPLIERS 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 OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Alex Deucher <alexander.deucher@amd.com>
  25. */
  26. #include "drmP.h"
  27. #include "drm.h"
  28. #include "radeon_drm.h"
  29. #include "radeon.h"
  30. #include "evergreend.h"
  31. #include "evergreen_blit_shaders.h"
  32. #include "cayman_blit_shaders.h"
  33. #include "radeon_blit_common.h"
  34. /* emits 17 */
  35. static void
  36. set_render_target(struct radeon_device *rdev, int format,
  37. int w, int h, u64 gpu_addr)
  38. {
  39. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  40. u32 cb_color_info;
  41. int pitch, slice;
  42. h = ALIGN(h, 8);
  43. if (h < 8)
  44. h = 8;
  45. cb_color_info = CB_FORMAT(format) |
  46. CB_SOURCE_FORMAT(CB_SF_EXPORT_NORM) |
  47. CB_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  48. pitch = (w / 8) - 1;
  49. slice = ((w * h) / 64) - 1;
  50. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 15));
  51. radeon_ring_write(ring, (CB_COLOR0_BASE - PACKET3_SET_CONTEXT_REG_START) >> 2);
  52. radeon_ring_write(ring, gpu_addr >> 8);
  53. radeon_ring_write(ring, pitch);
  54. radeon_ring_write(ring, slice);
  55. radeon_ring_write(ring, 0);
  56. radeon_ring_write(ring, cb_color_info);
  57. radeon_ring_write(ring, 0);
  58. radeon_ring_write(ring, (w - 1) | ((h - 1) << 16));
  59. radeon_ring_write(ring, 0);
  60. radeon_ring_write(ring, 0);
  61. radeon_ring_write(ring, 0);
  62. radeon_ring_write(ring, 0);
  63. radeon_ring_write(ring, 0);
  64. radeon_ring_write(ring, 0);
  65. radeon_ring_write(ring, 0);
  66. radeon_ring_write(ring, 0);
  67. }
  68. /* emits 5dw */
  69. static void
  70. cp_set_surface_sync(struct radeon_device *rdev,
  71. u32 sync_type, u32 size,
  72. u64 mc_addr)
  73. {
  74. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  75. u32 cp_coher_size;
  76. if (size == 0xffffffff)
  77. cp_coher_size = 0xffffffff;
  78. else
  79. cp_coher_size = ((size + 255) >> 8);
  80. if (rdev->family >= CHIP_CAYMAN) {
  81. /* CP_COHER_CNTL2 has to be set manually when submitting a surface_sync
  82. * to the RB directly. For IBs, the CP programs this as part of the
  83. * surface_sync packet.
  84. */
  85. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  86. radeon_ring_write(ring, (0x85e8 - PACKET3_SET_CONFIG_REG_START) >> 2);
  87. radeon_ring_write(ring, 0); /* CP_COHER_CNTL2 */
  88. }
  89. radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
  90. radeon_ring_write(ring, sync_type);
  91. radeon_ring_write(ring, cp_coher_size);
  92. radeon_ring_write(ring, mc_addr >> 8);
  93. radeon_ring_write(ring, 10); /* poll interval */
  94. }
  95. /* emits 11dw + 1 surface sync = 16dw */
  96. static void
  97. set_shaders(struct radeon_device *rdev)
  98. {
  99. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  100. u64 gpu_addr;
  101. /* VS */
  102. gpu_addr = rdev->r600_blit.shader_gpu_addr + rdev->r600_blit.vs_offset;
  103. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 3));
  104. radeon_ring_write(ring, (SQ_PGM_START_VS - PACKET3_SET_CONTEXT_REG_START) >> 2);
  105. radeon_ring_write(ring, gpu_addr >> 8);
  106. radeon_ring_write(ring, 2);
  107. radeon_ring_write(ring, 0);
  108. /* PS */
  109. gpu_addr = rdev->r600_blit.shader_gpu_addr + rdev->r600_blit.ps_offset;
  110. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 4));
  111. radeon_ring_write(ring, (SQ_PGM_START_PS - PACKET3_SET_CONTEXT_REG_START) >> 2);
  112. radeon_ring_write(ring, gpu_addr >> 8);
  113. radeon_ring_write(ring, 1);
  114. radeon_ring_write(ring, 0);
  115. radeon_ring_write(ring, 2);
  116. gpu_addr = rdev->r600_blit.shader_gpu_addr + rdev->r600_blit.vs_offset;
  117. cp_set_surface_sync(rdev, PACKET3_SH_ACTION_ENA, 512, gpu_addr);
  118. }
  119. /* emits 10 + 1 sync (5) = 15 */
  120. static void
  121. set_vtx_resource(struct radeon_device *rdev, u64 gpu_addr)
  122. {
  123. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  124. u32 sq_vtx_constant_word2, sq_vtx_constant_word3;
  125. /* high addr, stride */
  126. sq_vtx_constant_word2 = SQ_VTXC_BASE_ADDR_HI(upper_32_bits(gpu_addr) & 0xff) |
  127. SQ_VTXC_STRIDE(16);
  128. #ifdef __BIG_ENDIAN
  129. sq_vtx_constant_word2 |= SQ_VTXC_ENDIAN_SWAP(SQ_ENDIAN_8IN32);
  130. #endif
  131. /* xyzw swizzles */
  132. sq_vtx_constant_word3 = SQ_VTCX_SEL_X(SQ_SEL_X) |
  133. SQ_VTCX_SEL_Y(SQ_SEL_Y) |
  134. SQ_VTCX_SEL_Z(SQ_SEL_Z) |
  135. SQ_VTCX_SEL_W(SQ_SEL_W);
  136. radeon_ring_write(ring, PACKET3(PACKET3_SET_RESOURCE, 8));
  137. radeon_ring_write(ring, 0x580);
  138. radeon_ring_write(ring, gpu_addr & 0xffffffff);
  139. radeon_ring_write(ring, 48 - 1); /* size */
  140. radeon_ring_write(ring, sq_vtx_constant_word2);
  141. radeon_ring_write(ring, sq_vtx_constant_word3);
  142. radeon_ring_write(ring, 0);
  143. radeon_ring_write(ring, 0);
  144. radeon_ring_write(ring, 0);
  145. radeon_ring_write(ring, S__SQ_CONSTANT_TYPE(SQ_TEX_VTX_VALID_BUFFER));
  146. if ((rdev->family == CHIP_CEDAR) ||
  147. (rdev->family == CHIP_PALM) ||
  148. (rdev->family == CHIP_SUMO) ||
  149. (rdev->family == CHIP_SUMO2) ||
  150. (rdev->family == CHIP_CAICOS))
  151. cp_set_surface_sync(rdev,
  152. PACKET3_TC_ACTION_ENA, 48, gpu_addr);
  153. else
  154. cp_set_surface_sync(rdev,
  155. PACKET3_VC_ACTION_ENA, 48, gpu_addr);
  156. }
  157. /* emits 10 */
  158. static void
  159. set_tex_resource(struct radeon_device *rdev,
  160. int format, int w, int h, int pitch,
  161. u64 gpu_addr, u32 size)
  162. {
  163. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  164. u32 sq_tex_resource_word0, sq_tex_resource_word1;
  165. u32 sq_tex_resource_word4, sq_tex_resource_word7;
  166. if (h < 1)
  167. h = 1;
  168. sq_tex_resource_word0 = TEX_DIM(SQ_TEX_DIM_2D);
  169. sq_tex_resource_word0 |= ((((pitch >> 3) - 1) << 6) |
  170. ((w - 1) << 18));
  171. sq_tex_resource_word1 = ((h - 1) << 0) |
  172. TEX_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  173. /* xyzw swizzles */
  174. sq_tex_resource_word4 = TEX_DST_SEL_X(SQ_SEL_X) |
  175. TEX_DST_SEL_Y(SQ_SEL_Y) |
  176. TEX_DST_SEL_Z(SQ_SEL_Z) |
  177. TEX_DST_SEL_W(SQ_SEL_W);
  178. sq_tex_resource_word7 = format |
  179. S__SQ_CONSTANT_TYPE(SQ_TEX_VTX_VALID_TEXTURE);
  180. cp_set_surface_sync(rdev,
  181. PACKET3_TC_ACTION_ENA, size, gpu_addr);
  182. radeon_ring_write(ring, PACKET3(PACKET3_SET_RESOURCE, 8));
  183. radeon_ring_write(ring, 0);
  184. radeon_ring_write(ring, sq_tex_resource_word0);
  185. radeon_ring_write(ring, sq_tex_resource_word1);
  186. radeon_ring_write(ring, gpu_addr >> 8);
  187. radeon_ring_write(ring, gpu_addr >> 8);
  188. radeon_ring_write(ring, sq_tex_resource_word4);
  189. radeon_ring_write(ring, 0);
  190. radeon_ring_write(ring, 0);
  191. radeon_ring_write(ring, sq_tex_resource_word7);
  192. }
  193. /* emits 12 */
  194. static void
  195. set_scissors(struct radeon_device *rdev, int x1, int y1,
  196. int x2, int y2)
  197. {
  198. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  199. /* workaround some hw bugs */
  200. if (x2 == 0)
  201. x1 = 1;
  202. if (y2 == 0)
  203. y1 = 1;
  204. if (rdev->family >= CHIP_CAYMAN) {
  205. if ((x2 == 1) && (y2 == 1))
  206. x2 = 2;
  207. }
  208. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
  209. radeon_ring_write(ring, (PA_SC_SCREEN_SCISSOR_TL - PACKET3_SET_CONTEXT_REG_START) >> 2);
  210. radeon_ring_write(ring, (x1 << 0) | (y1 << 16));
  211. radeon_ring_write(ring, (x2 << 0) | (y2 << 16));
  212. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
  213. radeon_ring_write(ring, (PA_SC_GENERIC_SCISSOR_TL - PACKET3_SET_CONTEXT_REG_START) >> 2);
  214. radeon_ring_write(ring, (x1 << 0) | (y1 << 16) | (1 << 31));
  215. radeon_ring_write(ring, (x2 << 0) | (y2 << 16));
  216. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
  217. radeon_ring_write(ring, (PA_SC_WINDOW_SCISSOR_TL - PACKET3_SET_CONTEXT_REG_START) >> 2);
  218. radeon_ring_write(ring, (x1 << 0) | (y1 << 16) | (1 << 31));
  219. radeon_ring_write(ring, (x2 << 0) | (y2 << 16));
  220. }
  221. /* emits 10 */
  222. static void
  223. draw_auto(struct radeon_device *rdev)
  224. {
  225. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  226. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  227. radeon_ring_write(ring, (VGT_PRIMITIVE_TYPE - PACKET3_SET_CONFIG_REG_START) >> 2);
  228. radeon_ring_write(ring, DI_PT_RECTLIST);
  229. radeon_ring_write(ring, PACKET3(PACKET3_INDEX_TYPE, 0));
  230. radeon_ring_write(ring,
  231. #ifdef __BIG_ENDIAN
  232. (2 << 2) |
  233. #endif
  234. DI_INDEX_SIZE_16_BIT);
  235. radeon_ring_write(ring, PACKET3(PACKET3_NUM_INSTANCES, 0));
  236. radeon_ring_write(ring, 1);
  237. radeon_ring_write(ring, PACKET3(PACKET3_DRAW_INDEX_AUTO, 1));
  238. radeon_ring_write(ring, 3);
  239. radeon_ring_write(ring, DI_SRC_SEL_AUTO_INDEX);
  240. }
  241. /* emits 39 */
  242. static void
  243. set_default_state(struct radeon_device *rdev)
  244. {
  245. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  246. u32 sq_config, sq_gpr_resource_mgmt_1, sq_gpr_resource_mgmt_2, sq_gpr_resource_mgmt_3;
  247. u32 sq_thread_resource_mgmt, sq_thread_resource_mgmt_2;
  248. u32 sq_stack_resource_mgmt_1, sq_stack_resource_mgmt_2, sq_stack_resource_mgmt_3;
  249. int num_ps_gprs, num_vs_gprs, num_temp_gprs;
  250. int num_gs_gprs, num_es_gprs, num_hs_gprs, num_ls_gprs;
  251. int num_ps_threads, num_vs_threads, num_gs_threads, num_es_threads;
  252. int num_hs_threads, num_ls_threads;
  253. int num_ps_stack_entries, num_vs_stack_entries, num_gs_stack_entries, num_es_stack_entries;
  254. int num_hs_stack_entries, num_ls_stack_entries;
  255. u64 gpu_addr;
  256. int dwords;
  257. /* set clear context state */
  258. radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
  259. radeon_ring_write(ring, 0);
  260. if (rdev->family < CHIP_CAYMAN) {
  261. switch (rdev->family) {
  262. case CHIP_CEDAR:
  263. default:
  264. num_ps_gprs = 93;
  265. num_vs_gprs = 46;
  266. num_temp_gprs = 4;
  267. num_gs_gprs = 31;
  268. num_es_gprs = 31;
  269. num_hs_gprs = 23;
  270. num_ls_gprs = 23;
  271. num_ps_threads = 96;
  272. num_vs_threads = 16;
  273. num_gs_threads = 16;
  274. num_es_threads = 16;
  275. num_hs_threads = 16;
  276. num_ls_threads = 16;
  277. num_ps_stack_entries = 42;
  278. num_vs_stack_entries = 42;
  279. num_gs_stack_entries = 42;
  280. num_es_stack_entries = 42;
  281. num_hs_stack_entries = 42;
  282. num_ls_stack_entries = 42;
  283. break;
  284. case CHIP_REDWOOD:
  285. num_ps_gprs = 93;
  286. num_vs_gprs = 46;
  287. num_temp_gprs = 4;
  288. num_gs_gprs = 31;
  289. num_es_gprs = 31;
  290. num_hs_gprs = 23;
  291. num_ls_gprs = 23;
  292. num_ps_threads = 128;
  293. num_vs_threads = 20;
  294. num_gs_threads = 20;
  295. num_es_threads = 20;
  296. num_hs_threads = 20;
  297. num_ls_threads = 20;
  298. num_ps_stack_entries = 42;
  299. num_vs_stack_entries = 42;
  300. num_gs_stack_entries = 42;
  301. num_es_stack_entries = 42;
  302. num_hs_stack_entries = 42;
  303. num_ls_stack_entries = 42;
  304. break;
  305. case CHIP_JUNIPER:
  306. num_ps_gprs = 93;
  307. num_vs_gprs = 46;
  308. num_temp_gprs = 4;
  309. num_gs_gprs = 31;
  310. num_es_gprs = 31;
  311. num_hs_gprs = 23;
  312. num_ls_gprs = 23;
  313. num_ps_threads = 128;
  314. num_vs_threads = 20;
  315. num_gs_threads = 20;
  316. num_es_threads = 20;
  317. num_hs_threads = 20;
  318. num_ls_threads = 20;
  319. num_ps_stack_entries = 85;
  320. num_vs_stack_entries = 85;
  321. num_gs_stack_entries = 85;
  322. num_es_stack_entries = 85;
  323. num_hs_stack_entries = 85;
  324. num_ls_stack_entries = 85;
  325. break;
  326. case CHIP_CYPRESS:
  327. case CHIP_HEMLOCK:
  328. num_ps_gprs = 93;
  329. num_vs_gprs = 46;
  330. num_temp_gprs = 4;
  331. num_gs_gprs = 31;
  332. num_es_gprs = 31;
  333. num_hs_gprs = 23;
  334. num_ls_gprs = 23;
  335. num_ps_threads = 128;
  336. num_vs_threads = 20;
  337. num_gs_threads = 20;
  338. num_es_threads = 20;
  339. num_hs_threads = 20;
  340. num_ls_threads = 20;
  341. num_ps_stack_entries = 85;
  342. num_vs_stack_entries = 85;
  343. num_gs_stack_entries = 85;
  344. num_es_stack_entries = 85;
  345. num_hs_stack_entries = 85;
  346. num_ls_stack_entries = 85;
  347. break;
  348. case CHIP_PALM:
  349. num_ps_gprs = 93;
  350. num_vs_gprs = 46;
  351. num_temp_gprs = 4;
  352. num_gs_gprs = 31;
  353. num_es_gprs = 31;
  354. num_hs_gprs = 23;
  355. num_ls_gprs = 23;
  356. num_ps_threads = 96;
  357. num_vs_threads = 16;
  358. num_gs_threads = 16;
  359. num_es_threads = 16;
  360. num_hs_threads = 16;
  361. num_ls_threads = 16;
  362. num_ps_stack_entries = 42;
  363. num_vs_stack_entries = 42;
  364. num_gs_stack_entries = 42;
  365. num_es_stack_entries = 42;
  366. num_hs_stack_entries = 42;
  367. num_ls_stack_entries = 42;
  368. break;
  369. case CHIP_SUMO:
  370. num_ps_gprs = 93;
  371. num_vs_gprs = 46;
  372. num_temp_gprs = 4;
  373. num_gs_gprs = 31;
  374. num_es_gprs = 31;
  375. num_hs_gprs = 23;
  376. num_ls_gprs = 23;
  377. num_ps_threads = 96;
  378. num_vs_threads = 25;
  379. num_gs_threads = 25;
  380. num_es_threads = 25;
  381. num_hs_threads = 25;
  382. num_ls_threads = 25;
  383. num_ps_stack_entries = 42;
  384. num_vs_stack_entries = 42;
  385. num_gs_stack_entries = 42;
  386. num_es_stack_entries = 42;
  387. num_hs_stack_entries = 42;
  388. num_ls_stack_entries = 42;
  389. break;
  390. case CHIP_SUMO2:
  391. num_ps_gprs = 93;
  392. num_vs_gprs = 46;
  393. num_temp_gprs = 4;
  394. num_gs_gprs = 31;
  395. num_es_gprs = 31;
  396. num_hs_gprs = 23;
  397. num_ls_gprs = 23;
  398. num_ps_threads = 96;
  399. num_vs_threads = 25;
  400. num_gs_threads = 25;
  401. num_es_threads = 25;
  402. num_hs_threads = 25;
  403. num_ls_threads = 25;
  404. num_ps_stack_entries = 85;
  405. num_vs_stack_entries = 85;
  406. num_gs_stack_entries = 85;
  407. num_es_stack_entries = 85;
  408. num_hs_stack_entries = 85;
  409. num_ls_stack_entries = 85;
  410. break;
  411. case CHIP_BARTS:
  412. num_ps_gprs = 93;
  413. num_vs_gprs = 46;
  414. num_temp_gprs = 4;
  415. num_gs_gprs = 31;
  416. num_es_gprs = 31;
  417. num_hs_gprs = 23;
  418. num_ls_gprs = 23;
  419. num_ps_threads = 128;
  420. num_vs_threads = 20;
  421. num_gs_threads = 20;
  422. num_es_threads = 20;
  423. num_hs_threads = 20;
  424. num_ls_threads = 20;
  425. num_ps_stack_entries = 85;
  426. num_vs_stack_entries = 85;
  427. num_gs_stack_entries = 85;
  428. num_es_stack_entries = 85;
  429. num_hs_stack_entries = 85;
  430. num_ls_stack_entries = 85;
  431. break;
  432. case CHIP_TURKS:
  433. num_ps_gprs = 93;
  434. num_vs_gprs = 46;
  435. num_temp_gprs = 4;
  436. num_gs_gprs = 31;
  437. num_es_gprs = 31;
  438. num_hs_gprs = 23;
  439. num_ls_gprs = 23;
  440. num_ps_threads = 128;
  441. num_vs_threads = 20;
  442. num_gs_threads = 20;
  443. num_es_threads = 20;
  444. num_hs_threads = 20;
  445. num_ls_threads = 20;
  446. num_ps_stack_entries = 42;
  447. num_vs_stack_entries = 42;
  448. num_gs_stack_entries = 42;
  449. num_es_stack_entries = 42;
  450. num_hs_stack_entries = 42;
  451. num_ls_stack_entries = 42;
  452. break;
  453. case CHIP_CAICOS:
  454. num_ps_gprs = 93;
  455. num_vs_gprs = 46;
  456. num_temp_gprs = 4;
  457. num_gs_gprs = 31;
  458. num_es_gprs = 31;
  459. num_hs_gprs = 23;
  460. num_ls_gprs = 23;
  461. num_ps_threads = 128;
  462. num_vs_threads = 10;
  463. num_gs_threads = 10;
  464. num_es_threads = 10;
  465. num_hs_threads = 10;
  466. num_ls_threads = 10;
  467. num_ps_stack_entries = 42;
  468. num_vs_stack_entries = 42;
  469. num_gs_stack_entries = 42;
  470. num_es_stack_entries = 42;
  471. num_hs_stack_entries = 42;
  472. num_ls_stack_entries = 42;
  473. break;
  474. }
  475. if ((rdev->family == CHIP_CEDAR) ||
  476. (rdev->family == CHIP_PALM) ||
  477. (rdev->family == CHIP_SUMO) ||
  478. (rdev->family == CHIP_SUMO2) ||
  479. (rdev->family == CHIP_CAICOS))
  480. sq_config = 0;
  481. else
  482. sq_config = VC_ENABLE;
  483. sq_config |= (EXPORT_SRC_C |
  484. CS_PRIO(0) |
  485. LS_PRIO(0) |
  486. HS_PRIO(0) |
  487. PS_PRIO(0) |
  488. VS_PRIO(1) |
  489. GS_PRIO(2) |
  490. ES_PRIO(3));
  491. sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(num_ps_gprs) |
  492. NUM_VS_GPRS(num_vs_gprs) |
  493. NUM_CLAUSE_TEMP_GPRS(num_temp_gprs));
  494. sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(num_gs_gprs) |
  495. NUM_ES_GPRS(num_es_gprs));
  496. sq_gpr_resource_mgmt_3 = (NUM_HS_GPRS(num_hs_gprs) |
  497. NUM_LS_GPRS(num_ls_gprs));
  498. sq_thread_resource_mgmt = (NUM_PS_THREADS(num_ps_threads) |
  499. NUM_VS_THREADS(num_vs_threads) |
  500. NUM_GS_THREADS(num_gs_threads) |
  501. NUM_ES_THREADS(num_es_threads));
  502. sq_thread_resource_mgmt_2 = (NUM_HS_THREADS(num_hs_threads) |
  503. NUM_LS_THREADS(num_ls_threads));
  504. sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(num_ps_stack_entries) |
  505. NUM_VS_STACK_ENTRIES(num_vs_stack_entries));
  506. sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(num_gs_stack_entries) |
  507. NUM_ES_STACK_ENTRIES(num_es_stack_entries));
  508. sq_stack_resource_mgmt_3 = (NUM_HS_STACK_ENTRIES(num_hs_stack_entries) |
  509. NUM_LS_STACK_ENTRIES(num_ls_stack_entries));
  510. /* disable dyn gprs */
  511. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  512. radeon_ring_write(ring, (SQ_DYN_GPR_CNTL_PS_FLUSH_REQ - PACKET3_SET_CONFIG_REG_START) >> 2);
  513. radeon_ring_write(ring, 0);
  514. /* setup LDS */
  515. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  516. radeon_ring_write(ring, (SQ_LDS_RESOURCE_MGMT - PACKET3_SET_CONFIG_REG_START) >> 2);
  517. radeon_ring_write(ring, 0x10001000);
  518. /* SQ config */
  519. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 11));
  520. radeon_ring_write(ring, (SQ_CONFIG - PACKET3_SET_CONFIG_REG_START) >> 2);
  521. radeon_ring_write(ring, sq_config);
  522. radeon_ring_write(ring, sq_gpr_resource_mgmt_1);
  523. radeon_ring_write(ring, sq_gpr_resource_mgmt_2);
  524. radeon_ring_write(ring, sq_gpr_resource_mgmt_3);
  525. radeon_ring_write(ring, 0);
  526. radeon_ring_write(ring, 0);
  527. radeon_ring_write(ring, sq_thread_resource_mgmt);
  528. radeon_ring_write(ring, sq_thread_resource_mgmt_2);
  529. radeon_ring_write(ring, sq_stack_resource_mgmt_1);
  530. radeon_ring_write(ring, sq_stack_resource_mgmt_2);
  531. radeon_ring_write(ring, sq_stack_resource_mgmt_3);
  532. }
  533. /* CONTEXT_CONTROL */
  534. radeon_ring_write(ring, 0xc0012800);
  535. radeon_ring_write(ring, 0x80000000);
  536. radeon_ring_write(ring, 0x80000000);
  537. /* SQ_VTX_BASE_VTX_LOC */
  538. radeon_ring_write(ring, 0xc0026f00);
  539. radeon_ring_write(ring, 0x00000000);
  540. radeon_ring_write(ring, 0x00000000);
  541. radeon_ring_write(ring, 0x00000000);
  542. /* SET_SAMPLER */
  543. radeon_ring_write(ring, 0xc0036e00);
  544. radeon_ring_write(ring, 0x00000000);
  545. radeon_ring_write(ring, 0x00000012);
  546. radeon_ring_write(ring, 0x00000000);
  547. radeon_ring_write(ring, 0x00000000);
  548. /* set to DX10/11 mode */
  549. radeon_ring_write(ring, PACKET3(PACKET3_MODE_CONTROL, 0));
  550. radeon_ring_write(ring, 1);
  551. /* emit an IB pointing at default state */
  552. dwords = ALIGN(rdev->r600_blit.state_len, 0x10);
  553. gpu_addr = rdev->r600_blit.shader_gpu_addr + rdev->r600_blit.state_offset;
  554. radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
  555. radeon_ring_write(ring, gpu_addr & 0xFFFFFFFC);
  556. radeon_ring_write(ring, upper_32_bits(gpu_addr) & 0xFF);
  557. radeon_ring_write(ring, dwords);
  558. }
  559. int evergreen_blit_init(struct radeon_device *rdev)
  560. {
  561. u32 obj_size;
  562. int i, r, dwords;
  563. void *ptr;
  564. u32 packet2s[16];
  565. int num_packet2s = 0;
  566. rdev->r600_blit.primitives.set_render_target = set_render_target;
  567. rdev->r600_blit.primitives.cp_set_surface_sync = cp_set_surface_sync;
  568. rdev->r600_blit.primitives.set_shaders = set_shaders;
  569. rdev->r600_blit.primitives.set_vtx_resource = set_vtx_resource;
  570. rdev->r600_blit.primitives.set_tex_resource = set_tex_resource;
  571. rdev->r600_blit.primitives.set_scissors = set_scissors;
  572. rdev->r600_blit.primitives.draw_auto = draw_auto;
  573. rdev->r600_blit.primitives.set_default_state = set_default_state;
  574. rdev->r600_blit.ring_size_common = 55; /* shaders + def state */
  575. rdev->r600_blit.ring_size_common += 16; /* fence emit for VB IB */
  576. rdev->r600_blit.ring_size_common += 5; /* done copy */
  577. rdev->r600_blit.ring_size_common += 16; /* fence emit for done copy */
  578. rdev->r600_blit.ring_size_per_loop = 74;
  579. if (rdev->family >= CHIP_CAYMAN)
  580. rdev->r600_blit.ring_size_per_loop += 9; /* additional DWs for surface sync */
  581. rdev->r600_blit.max_dim = 16384;
  582. /* pin copy shader into vram if already initialized */
  583. if (rdev->r600_blit.shader_obj)
  584. goto done;
  585. mutex_init(&rdev->r600_blit.mutex);
  586. rdev->r600_blit.state_offset = 0;
  587. if (rdev->family < CHIP_CAYMAN)
  588. rdev->r600_blit.state_len = evergreen_default_size;
  589. else
  590. rdev->r600_blit.state_len = cayman_default_size;
  591. dwords = rdev->r600_blit.state_len;
  592. while (dwords & 0xf) {
  593. packet2s[num_packet2s++] = cpu_to_le32(PACKET2(0));
  594. dwords++;
  595. }
  596. obj_size = dwords * 4;
  597. obj_size = ALIGN(obj_size, 256);
  598. rdev->r600_blit.vs_offset = obj_size;
  599. if (rdev->family < CHIP_CAYMAN)
  600. obj_size += evergreen_vs_size * 4;
  601. else
  602. obj_size += cayman_vs_size * 4;
  603. obj_size = ALIGN(obj_size, 256);
  604. rdev->r600_blit.ps_offset = obj_size;
  605. if (rdev->family < CHIP_CAYMAN)
  606. obj_size += evergreen_ps_size * 4;
  607. else
  608. obj_size += cayman_ps_size * 4;
  609. obj_size = ALIGN(obj_size, 256);
  610. r = radeon_bo_create(rdev, obj_size, PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM,
  611. &rdev->r600_blit.shader_obj);
  612. if (r) {
  613. DRM_ERROR("evergreen failed to allocate shader\n");
  614. return r;
  615. }
  616. DRM_DEBUG("evergreen blit allocated bo %08x vs %08x ps %08x\n",
  617. obj_size,
  618. rdev->r600_blit.vs_offset, rdev->r600_blit.ps_offset);
  619. r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
  620. if (unlikely(r != 0))
  621. return r;
  622. r = radeon_bo_kmap(rdev->r600_blit.shader_obj, &ptr);
  623. if (r) {
  624. DRM_ERROR("failed to map blit object %d\n", r);
  625. return r;
  626. }
  627. if (rdev->family < CHIP_CAYMAN) {
  628. memcpy_toio(ptr + rdev->r600_blit.state_offset,
  629. evergreen_default_state, rdev->r600_blit.state_len * 4);
  630. if (num_packet2s)
  631. memcpy_toio(ptr + rdev->r600_blit.state_offset + (rdev->r600_blit.state_len * 4),
  632. packet2s, num_packet2s * 4);
  633. for (i = 0; i < evergreen_vs_size; i++)
  634. *(u32 *)((unsigned long)ptr + rdev->r600_blit.vs_offset + i * 4) = cpu_to_le32(evergreen_vs[i]);
  635. for (i = 0; i < evergreen_ps_size; i++)
  636. *(u32 *)((unsigned long)ptr + rdev->r600_blit.ps_offset + i * 4) = cpu_to_le32(evergreen_ps[i]);
  637. } else {
  638. memcpy_toio(ptr + rdev->r600_blit.state_offset,
  639. cayman_default_state, rdev->r600_blit.state_len * 4);
  640. if (num_packet2s)
  641. memcpy_toio(ptr + rdev->r600_blit.state_offset + (rdev->r600_blit.state_len * 4),
  642. packet2s, num_packet2s * 4);
  643. for (i = 0; i < cayman_vs_size; i++)
  644. *(u32 *)((unsigned long)ptr + rdev->r600_blit.vs_offset + i * 4) = cpu_to_le32(cayman_vs[i]);
  645. for (i = 0; i < cayman_ps_size; i++)
  646. *(u32 *)((unsigned long)ptr + rdev->r600_blit.ps_offset + i * 4) = cpu_to_le32(cayman_ps[i]);
  647. }
  648. radeon_bo_kunmap(rdev->r600_blit.shader_obj);
  649. radeon_bo_unreserve(rdev->r600_blit.shader_obj);
  650. done:
  651. r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
  652. if (unlikely(r != 0))
  653. return r;
  654. r = radeon_bo_pin(rdev->r600_blit.shader_obj, RADEON_GEM_DOMAIN_VRAM,
  655. &rdev->r600_blit.shader_gpu_addr);
  656. radeon_bo_unreserve(rdev->r600_blit.shader_obj);
  657. if (r) {
  658. dev_err(rdev->dev, "(%d) pin blit object failed\n", r);
  659. return r;
  660. }
  661. radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size);
  662. return 0;
  663. }