rs690.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. /*
  2. * Copyright 2008 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. * Copyright 2009 Jerome Glisse.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. * OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors: Dave Airlie
  25. * Alex Deucher
  26. * Jerome Glisse
  27. */
  28. #include "drmP.h"
  29. #include "radeon.h"
  30. #include "atom.h"
  31. #include "rs690d.h"
  32. static int rs690_mc_wait_for_idle(struct radeon_device *rdev)
  33. {
  34. unsigned i;
  35. uint32_t tmp;
  36. for (i = 0; i < rdev->usec_timeout; i++) {
  37. /* read MC_STATUS */
  38. tmp = RREG32_MC(R_000090_MC_SYSTEM_STATUS);
  39. if (G_000090_MC_SYSTEM_IDLE(tmp))
  40. return 0;
  41. udelay(1);
  42. }
  43. return -1;
  44. }
  45. static void rs690_gpu_init(struct radeon_device *rdev)
  46. {
  47. /* FIXME: HDP same place on rs690 ? */
  48. r100_hdp_reset(rdev);
  49. /* FIXME: is this correct ? */
  50. r420_pipes_init(rdev);
  51. if (rs690_mc_wait_for_idle(rdev)) {
  52. printk(KERN_WARNING "Failed to wait MC idle while "
  53. "programming pipes. Bad things might happen.\n");
  54. }
  55. }
  56. void rs690_pm_info(struct radeon_device *rdev)
  57. {
  58. int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
  59. struct _ATOM_INTEGRATED_SYSTEM_INFO *info;
  60. struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 *info_v2;
  61. void *ptr;
  62. uint16_t data_offset;
  63. uint8_t frev, crev;
  64. fixed20_12 tmp;
  65. atom_parse_data_header(rdev->mode_info.atom_context, index, NULL,
  66. &frev, &crev, &data_offset);
  67. ptr = rdev->mode_info.atom_context->bios + data_offset;
  68. info = (struct _ATOM_INTEGRATED_SYSTEM_INFO *)ptr;
  69. info_v2 = (struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 *)ptr;
  70. /* Get various system informations from bios */
  71. switch (crev) {
  72. case 1:
  73. tmp.full = rfixed_const(100);
  74. rdev->pm.igp_sideport_mclk.full = rfixed_const(info->ulBootUpMemoryClock);
  75. rdev->pm.igp_sideport_mclk.full = rfixed_div(rdev->pm.igp_sideport_mclk, tmp);
  76. rdev->pm.igp_system_mclk.full = rfixed_const(le16_to_cpu(info->usK8MemoryClock));
  77. rdev->pm.igp_ht_link_clk.full = rfixed_const(le16_to_cpu(info->usFSBClock));
  78. rdev->pm.igp_ht_link_width.full = rfixed_const(info->ucHTLinkWidth);
  79. break;
  80. case 2:
  81. tmp.full = rfixed_const(100);
  82. rdev->pm.igp_sideport_mclk.full = rfixed_const(info_v2->ulBootUpSidePortClock);
  83. rdev->pm.igp_sideport_mclk.full = rfixed_div(rdev->pm.igp_sideport_mclk, tmp);
  84. rdev->pm.igp_system_mclk.full = rfixed_const(info_v2->ulBootUpUMAClock);
  85. rdev->pm.igp_system_mclk.full = rfixed_div(rdev->pm.igp_system_mclk, tmp);
  86. rdev->pm.igp_ht_link_clk.full = rfixed_const(info_v2->ulHTLinkFreq);
  87. rdev->pm.igp_ht_link_clk.full = rfixed_div(rdev->pm.igp_ht_link_clk, tmp);
  88. rdev->pm.igp_ht_link_width.full = rfixed_const(le16_to_cpu(info_v2->usMinHTLinkWidth));
  89. break;
  90. default:
  91. tmp.full = rfixed_const(100);
  92. /* We assume the slower possible clock ie worst case */
  93. /* DDR 333Mhz */
  94. rdev->pm.igp_sideport_mclk.full = rfixed_const(333);
  95. /* FIXME: system clock ? */
  96. rdev->pm.igp_system_mclk.full = rfixed_const(100);
  97. rdev->pm.igp_system_mclk.full = rfixed_div(rdev->pm.igp_system_mclk, tmp);
  98. rdev->pm.igp_ht_link_clk.full = rfixed_const(200);
  99. rdev->pm.igp_ht_link_width.full = rfixed_const(8);
  100. DRM_ERROR("No integrated system info for your GPU, using safe default\n");
  101. break;
  102. }
  103. /* Compute various bandwidth */
  104. /* k8_bandwidth = (memory_clk / 2) * 2 * 8 * 0.5 = memory_clk * 4 */
  105. tmp.full = rfixed_const(4);
  106. rdev->pm.k8_bandwidth.full = rfixed_mul(rdev->pm.igp_system_mclk, tmp);
  107. /* ht_bandwidth = ht_clk * 2 * ht_width / 8 * 0.8
  108. * = ht_clk * ht_width / 5
  109. */
  110. tmp.full = rfixed_const(5);
  111. rdev->pm.ht_bandwidth.full = rfixed_mul(rdev->pm.igp_ht_link_clk,
  112. rdev->pm.igp_ht_link_width);
  113. rdev->pm.ht_bandwidth.full = rfixed_div(rdev->pm.ht_bandwidth, tmp);
  114. if (tmp.full < rdev->pm.max_bandwidth.full) {
  115. /* HT link is a limiting factor */
  116. rdev->pm.max_bandwidth.full = tmp.full;
  117. }
  118. /* sideport_bandwidth = (sideport_clk / 2) * 2 * 2 * 0.7
  119. * = (sideport_clk * 14) / 10
  120. */
  121. tmp.full = rfixed_const(14);
  122. rdev->pm.sideport_bandwidth.full = rfixed_mul(rdev->pm.igp_sideport_mclk, tmp);
  123. tmp.full = rfixed_const(10);
  124. rdev->pm.sideport_bandwidth.full = rfixed_div(rdev->pm.sideport_bandwidth, tmp);
  125. }
  126. void rs690_vram_info(struct radeon_device *rdev)
  127. {
  128. uint32_t tmp;
  129. fixed20_12 a;
  130. rs400_gart_adjust_size(rdev);
  131. /* DDR for all card after R300 & IGP */
  132. rdev->mc.vram_is_ddr = true;
  133. /* FIXME: is this correct for RS690/RS740 ? */
  134. tmp = RREG32(RADEON_MEM_CNTL);
  135. if (tmp & R300_MEM_NUM_CHANNELS_MASK) {
  136. rdev->mc.vram_width = 128;
  137. } else {
  138. rdev->mc.vram_width = 64;
  139. }
  140. rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
  141. rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
  142. rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
  143. rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
  144. rs690_pm_info(rdev);
  145. /* FIXME: we should enforce default clock in case GPU is not in
  146. * default setup
  147. */
  148. a.full = rfixed_const(100);
  149. rdev->pm.sclk.full = rfixed_const(rdev->clock.default_sclk);
  150. rdev->pm.sclk.full = rfixed_div(rdev->pm.sclk, a);
  151. a.full = rfixed_const(16);
  152. /* core_bandwidth = sclk(Mhz) * 16 */
  153. rdev->pm.core_bandwidth.full = rfixed_div(rdev->pm.sclk, a);
  154. }
  155. void rs690_line_buffer_adjust(struct radeon_device *rdev,
  156. struct drm_display_mode *mode1,
  157. struct drm_display_mode *mode2)
  158. {
  159. u32 tmp;
  160. /*
  161. * Line Buffer Setup
  162. * There is a single line buffer shared by both display controllers.
  163. * R_006520_DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
  164. * the display controllers. The paritioning can either be done
  165. * manually or via one of four preset allocations specified in bits 1:0:
  166. * 0 - line buffer is divided in half and shared between crtc
  167. * 1 - D1 gets 3/4 of the line buffer, D2 gets 1/4
  168. * 2 - D1 gets the whole buffer
  169. * 3 - D1 gets 1/4 of the line buffer, D2 gets 3/4
  170. * Setting bit 2 of R_006520_DC_LB_MEMORY_SPLIT controls switches to manual
  171. * allocation mode. In manual allocation mode, D1 always starts at 0,
  172. * D1 end/2 is specified in bits 14:4; D2 allocation follows D1.
  173. */
  174. tmp = RREG32(R_006520_DC_LB_MEMORY_SPLIT) & C_006520_DC_LB_MEMORY_SPLIT;
  175. tmp &= ~C_006520_DC_LB_MEMORY_SPLIT_MODE;
  176. /* auto */
  177. if (mode1 && mode2) {
  178. if (mode1->hdisplay > mode2->hdisplay) {
  179. if (mode1->hdisplay > 2560)
  180. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_3Q_D2_1Q;
  181. else
  182. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
  183. } else if (mode2->hdisplay > mode1->hdisplay) {
  184. if (mode2->hdisplay > 2560)
  185. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_1Q_D2_3Q;
  186. else
  187. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
  188. } else
  189. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
  190. } else if (mode1) {
  191. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_ONLY;
  192. } else if (mode2) {
  193. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_1Q_D2_3Q;
  194. }
  195. WREG32(R_006520_DC_LB_MEMORY_SPLIT, tmp);
  196. }
  197. struct rs690_watermark {
  198. u32 lb_request_fifo_depth;
  199. fixed20_12 num_line_pair;
  200. fixed20_12 estimated_width;
  201. fixed20_12 worst_case_latency;
  202. fixed20_12 consumption_rate;
  203. fixed20_12 active_time;
  204. fixed20_12 dbpp;
  205. fixed20_12 priority_mark_max;
  206. fixed20_12 priority_mark;
  207. fixed20_12 sclk;
  208. };
  209. void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
  210. struct radeon_crtc *crtc,
  211. struct rs690_watermark *wm)
  212. {
  213. struct drm_display_mode *mode = &crtc->base.mode;
  214. fixed20_12 a, b, c;
  215. fixed20_12 pclk, request_fifo_depth, tolerable_latency, estimated_width;
  216. fixed20_12 consumption_time, line_time, chunk_time, read_delay_latency;
  217. /* FIXME: detect IGP with sideport memory, i don't think there is any
  218. * such product available
  219. */
  220. bool sideport = false;
  221. if (!crtc->base.enabled) {
  222. /* FIXME: wouldn't it better to set priority mark to maximum */
  223. wm->lb_request_fifo_depth = 4;
  224. return;
  225. }
  226. if (crtc->vsc.full > rfixed_const(2))
  227. wm->num_line_pair.full = rfixed_const(2);
  228. else
  229. wm->num_line_pair.full = rfixed_const(1);
  230. b.full = rfixed_const(mode->crtc_hdisplay);
  231. c.full = rfixed_const(256);
  232. a.full = rfixed_mul(wm->num_line_pair, b);
  233. request_fifo_depth.full = rfixed_div(a, c);
  234. if (a.full < rfixed_const(4)) {
  235. wm->lb_request_fifo_depth = 4;
  236. } else {
  237. wm->lb_request_fifo_depth = rfixed_trunc(request_fifo_depth);
  238. }
  239. /* Determine consumption rate
  240. * pclk = pixel clock period(ns) = 1000 / (mode.clock / 1000)
  241. * vtaps = number of vertical taps,
  242. * vsc = vertical scaling ratio, defined as source/destination
  243. * hsc = horizontal scaling ration, defined as source/destination
  244. */
  245. a.full = rfixed_const(mode->clock);
  246. b.full = rfixed_const(1000);
  247. a.full = rfixed_div(a, b);
  248. pclk.full = rfixed_div(b, a);
  249. if (crtc->rmx_type != RMX_OFF) {
  250. b.full = rfixed_const(2);
  251. if (crtc->vsc.full > b.full)
  252. b.full = crtc->vsc.full;
  253. b.full = rfixed_mul(b, crtc->hsc);
  254. c.full = rfixed_const(2);
  255. b.full = rfixed_div(b, c);
  256. consumption_time.full = rfixed_div(pclk, b);
  257. } else {
  258. consumption_time.full = pclk.full;
  259. }
  260. a.full = rfixed_const(1);
  261. wm->consumption_rate.full = rfixed_div(a, consumption_time);
  262. /* Determine line time
  263. * LineTime = total time for one line of displayhtotal
  264. * LineTime = total number of horizontal pixels
  265. * pclk = pixel clock period(ns)
  266. */
  267. a.full = rfixed_const(crtc->base.mode.crtc_htotal);
  268. line_time.full = rfixed_mul(a, pclk);
  269. /* Determine active time
  270. * ActiveTime = time of active region of display within one line,
  271. * hactive = total number of horizontal active pixels
  272. * htotal = total number of horizontal pixels
  273. */
  274. a.full = rfixed_const(crtc->base.mode.crtc_htotal);
  275. b.full = rfixed_const(crtc->base.mode.crtc_hdisplay);
  276. wm->active_time.full = rfixed_mul(line_time, b);
  277. wm->active_time.full = rfixed_div(wm->active_time, a);
  278. /* Maximun bandwidth is the minimun bandwidth of all component */
  279. rdev->pm.max_bandwidth = rdev->pm.core_bandwidth;
  280. if (sideport) {
  281. if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
  282. rdev->pm.sideport_bandwidth.full)
  283. rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
  284. read_delay_latency.full = rfixed_const(370 * 800 * 1000);
  285. read_delay_latency.full = rfixed_div(read_delay_latency,
  286. rdev->pm.igp_sideport_mclk);
  287. } else {
  288. if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
  289. rdev->pm.k8_bandwidth.full)
  290. rdev->pm.max_bandwidth = rdev->pm.k8_bandwidth;
  291. if (rdev->pm.max_bandwidth.full > rdev->pm.ht_bandwidth.full &&
  292. rdev->pm.ht_bandwidth.full)
  293. rdev->pm.max_bandwidth = rdev->pm.ht_bandwidth;
  294. read_delay_latency.full = rfixed_const(5000);
  295. }
  296. /* sclk = system clocks(ns) = 1000 / max_bandwidth / 16 */
  297. a.full = rfixed_const(16);
  298. rdev->pm.sclk.full = rfixed_mul(rdev->pm.max_bandwidth, a);
  299. a.full = rfixed_const(1000);
  300. rdev->pm.sclk.full = rfixed_div(a, rdev->pm.sclk);
  301. /* Determine chunk time
  302. * ChunkTime = the time it takes the DCP to send one chunk of data
  303. * to the LB which consists of pipeline delay and inter chunk gap
  304. * sclk = system clock(ns)
  305. */
  306. a.full = rfixed_const(256 * 13);
  307. chunk_time.full = rfixed_mul(rdev->pm.sclk, a);
  308. a.full = rfixed_const(10);
  309. chunk_time.full = rfixed_div(chunk_time, a);
  310. /* Determine the worst case latency
  311. * NumLinePair = Number of line pairs to request(1=2 lines, 2=4 lines)
  312. * WorstCaseLatency = worst case time from urgent to when the MC starts
  313. * to return data
  314. * READ_DELAY_IDLE_MAX = constant of 1us
  315. * ChunkTime = time it takes the DCP to send one chunk of data to the LB
  316. * which consists of pipeline delay and inter chunk gap
  317. */
  318. if (rfixed_trunc(wm->num_line_pair) > 1) {
  319. a.full = rfixed_const(3);
  320. wm->worst_case_latency.full = rfixed_mul(a, chunk_time);
  321. wm->worst_case_latency.full += read_delay_latency.full;
  322. } else {
  323. a.full = rfixed_const(2);
  324. wm->worst_case_latency.full = rfixed_mul(a, chunk_time);
  325. wm->worst_case_latency.full += read_delay_latency.full;
  326. }
  327. /* Determine the tolerable latency
  328. * TolerableLatency = Any given request has only 1 line time
  329. * for the data to be returned
  330. * LBRequestFifoDepth = Number of chunk requests the LB can
  331. * put into the request FIFO for a display
  332. * LineTime = total time for one line of display
  333. * ChunkTime = the time it takes the DCP to send one chunk
  334. * of data to the LB which consists of
  335. * pipeline delay and inter chunk gap
  336. */
  337. if ((2+wm->lb_request_fifo_depth) >= rfixed_trunc(request_fifo_depth)) {
  338. tolerable_latency.full = line_time.full;
  339. } else {
  340. tolerable_latency.full = rfixed_const(wm->lb_request_fifo_depth - 2);
  341. tolerable_latency.full = request_fifo_depth.full - tolerable_latency.full;
  342. tolerable_latency.full = rfixed_mul(tolerable_latency, chunk_time);
  343. tolerable_latency.full = line_time.full - tolerable_latency.full;
  344. }
  345. /* We assume worst case 32bits (4 bytes) */
  346. wm->dbpp.full = rfixed_const(4 * 8);
  347. /* Determine the maximum priority mark
  348. * width = viewport width in pixels
  349. */
  350. a.full = rfixed_const(16);
  351. wm->priority_mark_max.full = rfixed_const(crtc->base.mode.crtc_hdisplay);
  352. wm->priority_mark_max.full = rfixed_div(wm->priority_mark_max, a);
  353. /* Determine estimated width */
  354. estimated_width.full = tolerable_latency.full - wm->worst_case_latency.full;
  355. estimated_width.full = rfixed_div(estimated_width, consumption_time);
  356. if (rfixed_trunc(estimated_width) > crtc->base.mode.crtc_hdisplay) {
  357. wm->priority_mark.full = rfixed_const(10);
  358. } else {
  359. a.full = rfixed_const(16);
  360. wm->priority_mark.full = rfixed_div(estimated_width, a);
  361. wm->priority_mark.full = wm->priority_mark_max.full - wm->priority_mark.full;
  362. }
  363. }
  364. void rs690_bandwidth_update(struct radeon_device *rdev)
  365. {
  366. struct drm_display_mode *mode0 = NULL;
  367. struct drm_display_mode *mode1 = NULL;
  368. struct rs690_watermark wm0;
  369. struct rs690_watermark wm1;
  370. u32 tmp;
  371. fixed20_12 priority_mark02, priority_mark12, fill_rate;
  372. fixed20_12 a, b;
  373. if (rdev->mode_info.crtcs[0]->base.enabled)
  374. mode0 = &rdev->mode_info.crtcs[0]->base.mode;
  375. if (rdev->mode_info.crtcs[1]->base.enabled)
  376. mode1 = &rdev->mode_info.crtcs[1]->base.mode;
  377. /*
  378. * Set display0/1 priority up in the memory controller for
  379. * modes if the user specifies HIGH for displaypriority
  380. * option.
  381. */
  382. if (rdev->disp_priority == 2) {
  383. tmp = RREG32_MC(R_000104_MC_INIT_MISC_LAT_TIMER);
  384. tmp &= C_000104_MC_DISP0R_INIT_LAT;
  385. tmp &= C_000104_MC_DISP1R_INIT_LAT;
  386. if (mode0)
  387. tmp |= S_000104_MC_DISP0R_INIT_LAT(1);
  388. if (mode1)
  389. tmp |= S_000104_MC_DISP1R_INIT_LAT(1);
  390. WREG32_MC(R_000104_MC_INIT_MISC_LAT_TIMER, tmp);
  391. }
  392. rs690_line_buffer_adjust(rdev, mode0, mode1);
  393. if ((rdev->family == CHIP_RS690) || (rdev->family == CHIP_RS740))
  394. WREG32(R_006C9C_DCP_CONTROL, 0);
  395. if ((rdev->family == CHIP_RS780) || (rdev->family == CHIP_RS880))
  396. WREG32(R_006C9C_DCP_CONTROL, 2);
  397. rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[0], &wm0);
  398. rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[1], &wm1);
  399. tmp = (wm0.lb_request_fifo_depth - 1);
  400. tmp |= (wm1.lb_request_fifo_depth - 1) << 16;
  401. WREG32(R_006D58_LB_MAX_REQ_OUTSTANDING, tmp);
  402. if (mode0 && mode1) {
  403. if (rfixed_trunc(wm0.dbpp) > 64)
  404. a.full = rfixed_mul(wm0.dbpp, wm0.num_line_pair);
  405. else
  406. a.full = wm0.num_line_pair.full;
  407. if (rfixed_trunc(wm1.dbpp) > 64)
  408. b.full = rfixed_mul(wm1.dbpp, wm1.num_line_pair);
  409. else
  410. b.full = wm1.num_line_pair.full;
  411. a.full += b.full;
  412. fill_rate.full = rfixed_div(wm0.sclk, a);
  413. if (wm0.consumption_rate.full > fill_rate.full) {
  414. b.full = wm0.consumption_rate.full - fill_rate.full;
  415. b.full = rfixed_mul(b, wm0.active_time);
  416. a.full = rfixed_mul(wm0.worst_case_latency,
  417. wm0.consumption_rate);
  418. a.full = a.full + b.full;
  419. b.full = rfixed_const(16 * 1000);
  420. priority_mark02.full = rfixed_div(a, b);
  421. } else {
  422. a.full = rfixed_mul(wm0.worst_case_latency,
  423. wm0.consumption_rate);
  424. b.full = rfixed_const(16 * 1000);
  425. priority_mark02.full = rfixed_div(a, b);
  426. }
  427. if (wm1.consumption_rate.full > fill_rate.full) {
  428. b.full = wm1.consumption_rate.full - fill_rate.full;
  429. b.full = rfixed_mul(b, wm1.active_time);
  430. a.full = rfixed_mul(wm1.worst_case_latency,
  431. wm1.consumption_rate);
  432. a.full = a.full + b.full;
  433. b.full = rfixed_const(16 * 1000);
  434. priority_mark12.full = rfixed_div(a, b);
  435. } else {
  436. a.full = rfixed_mul(wm1.worst_case_latency,
  437. wm1.consumption_rate);
  438. b.full = rfixed_const(16 * 1000);
  439. priority_mark12.full = rfixed_div(a, b);
  440. }
  441. if (wm0.priority_mark.full > priority_mark02.full)
  442. priority_mark02.full = wm0.priority_mark.full;
  443. if (rfixed_trunc(priority_mark02) < 0)
  444. priority_mark02.full = 0;
  445. if (wm0.priority_mark_max.full > priority_mark02.full)
  446. priority_mark02.full = wm0.priority_mark_max.full;
  447. if (wm1.priority_mark.full > priority_mark12.full)
  448. priority_mark12.full = wm1.priority_mark.full;
  449. if (rfixed_trunc(priority_mark12) < 0)
  450. priority_mark12.full = 0;
  451. if (wm1.priority_mark_max.full > priority_mark12.full)
  452. priority_mark12.full = wm1.priority_mark_max.full;
  453. WREG32(R_006548_D1MODE_PRIORITY_A_CNT, rfixed_trunc(priority_mark02));
  454. WREG32(R_00654C_D1MODE_PRIORITY_B_CNT, rfixed_trunc(priority_mark02));
  455. WREG32(R_006D48_D2MODE_PRIORITY_A_CNT, rfixed_trunc(priority_mark12));
  456. WREG32(R_006D4C_D2MODE_PRIORITY_B_CNT, rfixed_trunc(priority_mark12));
  457. } else if (mode0) {
  458. if (rfixed_trunc(wm0.dbpp) > 64)
  459. a.full = rfixed_mul(wm0.dbpp, wm0.num_line_pair);
  460. else
  461. a.full = wm0.num_line_pair.full;
  462. fill_rate.full = rfixed_div(wm0.sclk, a);
  463. if (wm0.consumption_rate.full > fill_rate.full) {
  464. b.full = wm0.consumption_rate.full - fill_rate.full;
  465. b.full = rfixed_mul(b, wm0.active_time);
  466. a.full = rfixed_mul(wm0.worst_case_latency,
  467. wm0.consumption_rate);
  468. a.full = a.full + b.full;
  469. b.full = rfixed_const(16 * 1000);
  470. priority_mark02.full = rfixed_div(a, b);
  471. } else {
  472. a.full = rfixed_mul(wm0.worst_case_latency,
  473. wm0.consumption_rate);
  474. b.full = rfixed_const(16 * 1000);
  475. priority_mark02.full = rfixed_div(a, b);
  476. }
  477. if (wm0.priority_mark.full > priority_mark02.full)
  478. priority_mark02.full = wm0.priority_mark.full;
  479. if (rfixed_trunc(priority_mark02) < 0)
  480. priority_mark02.full = 0;
  481. if (wm0.priority_mark_max.full > priority_mark02.full)
  482. priority_mark02.full = wm0.priority_mark_max.full;
  483. WREG32(R_006548_D1MODE_PRIORITY_A_CNT, rfixed_trunc(priority_mark02));
  484. WREG32(R_00654C_D1MODE_PRIORITY_B_CNT, rfixed_trunc(priority_mark02));
  485. WREG32(R_006D48_D2MODE_PRIORITY_A_CNT,
  486. S_006D48_D2MODE_PRIORITY_A_OFF(1));
  487. WREG32(R_006D4C_D2MODE_PRIORITY_B_CNT,
  488. S_006D4C_D2MODE_PRIORITY_B_OFF(1));
  489. } else {
  490. if (rfixed_trunc(wm1.dbpp) > 64)
  491. a.full = rfixed_mul(wm1.dbpp, wm1.num_line_pair);
  492. else
  493. a.full = wm1.num_line_pair.full;
  494. fill_rate.full = rfixed_div(wm1.sclk, a);
  495. if (wm1.consumption_rate.full > fill_rate.full) {
  496. b.full = wm1.consumption_rate.full - fill_rate.full;
  497. b.full = rfixed_mul(b, wm1.active_time);
  498. a.full = rfixed_mul(wm1.worst_case_latency,
  499. wm1.consumption_rate);
  500. a.full = a.full + b.full;
  501. b.full = rfixed_const(16 * 1000);
  502. priority_mark12.full = rfixed_div(a, b);
  503. } else {
  504. a.full = rfixed_mul(wm1.worst_case_latency,
  505. wm1.consumption_rate);
  506. b.full = rfixed_const(16 * 1000);
  507. priority_mark12.full = rfixed_div(a, b);
  508. }
  509. if (wm1.priority_mark.full > priority_mark12.full)
  510. priority_mark12.full = wm1.priority_mark.full;
  511. if (rfixed_trunc(priority_mark12) < 0)
  512. priority_mark12.full = 0;
  513. if (wm1.priority_mark_max.full > priority_mark12.full)
  514. priority_mark12.full = wm1.priority_mark_max.full;
  515. WREG32(R_006548_D1MODE_PRIORITY_A_CNT,
  516. S_006548_D1MODE_PRIORITY_A_OFF(1));
  517. WREG32(R_00654C_D1MODE_PRIORITY_B_CNT,
  518. S_00654C_D1MODE_PRIORITY_B_OFF(1));
  519. WREG32(R_006D48_D2MODE_PRIORITY_A_CNT, rfixed_trunc(priority_mark12));
  520. WREG32(R_006D4C_D2MODE_PRIORITY_B_CNT, rfixed_trunc(priority_mark12));
  521. }
  522. }
  523. uint32_t rs690_mc_rreg(struct radeon_device *rdev, uint32_t reg)
  524. {
  525. uint32_t r;
  526. WREG32(R_000078_MC_INDEX, S_000078_MC_IND_ADDR(reg));
  527. r = RREG32(R_00007C_MC_DATA);
  528. WREG32(R_000078_MC_INDEX, ~C_000078_MC_IND_ADDR);
  529. return r;
  530. }
  531. void rs690_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  532. {
  533. WREG32(R_000078_MC_INDEX, S_000078_MC_IND_ADDR(reg) |
  534. S_000078_MC_IND_WR_EN(1));
  535. WREG32(R_00007C_MC_DATA, v);
  536. WREG32(R_000078_MC_INDEX, 0x7F);
  537. }
  538. void rs690_mc_program(struct radeon_device *rdev)
  539. {
  540. struct rv515_mc_save save;
  541. /* Stops all mc clients */
  542. rv515_mc_stop(rdev, &save);
  543. /* Wait for mc idle */
  544. if (rs690_mc_wait_for_idle(rdev))
  545. dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
  546. /* Program MC, should be a 32bits limited address space */
  547. WREG32_MC(R_000100_MCCFG_FB_LOCATION,
  548. S_000100_MC_FB_START(rdev->mc.vram_start >> 16) |
  549. S_000100_MC_FB_TOP(rdev->mc.vram_end >> 16));
  550. WREG32(R_000134_HDP_FB_LOCATION,
  551. S_000134_HDP_FB_START(rdev->mc.vram_start >> 16));
  552. rv515_mc_resume(rdev, &save);
  553. }
  554. static int rs690_startup(struct radeon_device *rdev)
  555. {
  556. int r;
  557. rs690_mc_program(rdev);
  558. /* Resume clock */
  559. rv515_clock_startup(rdev);
  560. /* Initialize GPU configuration (# pipes, ...) */
  561. rs690_gpu_init(rdev);
  562. /* Initialize GART (initialize after TTM so we can allocate
  563. * memory through TTM but finalize after TTM) */
  564. r = rs400_gart_enable(rdev);
  565. if (r)
  566. return r;
  567. /* Enable IRQ */
  568. rdev->irq.sw_int = true;
  569. rs600_irq_set(rdev);
  570. /* 1M ring buffer */
  571. r = r100_cp_init(rdev, 1024 * 1024);
  572. if (r) {
  573. dev_err(rdev->dev, "failled initializing CP (%d).\n", r);
  574. return r;
  575. }
  576. r = r100_wb_init(rdev);
  577. if (r)
  578. dev_err(rdev->dev, "failled initializing WB (%d).\n", r);
  579. r = r100_ib_init(rdev);
  580. if (r) {
  581. dev_err(rdev->dev, "failled initializing IB (%d).\n", r);
  582. return r;
  583. }
  584. return 0;
  585. }
  586. int rs690_resume(struct radeon_device *rdev)
  587. {
  588. /* Make sur GART are not working */
  589. rs400_gart_disable(rdev);
  590. /* Resume clock before doing reset */
  591. rv515_clock_startup(rdev);
  592. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  593. if (radeon_gpu_reset(rdev)) {
  594. dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  595. RREG32(R_000E40_RBBM_STATUS),
  596. RREG32(R_0007C0_CP_STAT));
  597. }
  598. /* post */
  599. atom_asic_init(rdev->mode_info.atom_context);
  600. /* Resume clock after posting */
  601. rv515_clock_startup(rdev);
  602. return rs690_startup(rdev);
  603. }
  604. int rs690_suspend(struct radeon_device *rdev)
  605. {
  606. r100_cp_disable(rdev);
  607. r100_wb_disable(rdev);
  608. rs600_irq_disable(rdev);
  609. rs400_gart_disable(rdev);
  610. return 0;
  611. }
  612. void rs690_fini(struct radeon_device *rdev)
  613. {
  614. rs690_suspend(rdev);
  615. r100_cp_fini(rdev);
  616. r100_wb_fini(rdev);
  617. r100_ib_fini(rdev);
  618. radeon_gem_fini(rdev);
  619. rs400_gart_fini(rdev);
  620. radeon_irq_kms_fini(rdev);
  621. radeon_fence_driver_fini(rdev);
  622. radeon_object_fini(rdev);
  623. radeon_atombios_fini(rdev);
  624. kfree(rdev->bios);
  625. rdev->bios = NULL;
  626. }
  627. int rs690_init(struct radeon_device *rdev)
  628. {
  629. int r;
  630. /* Disable VGA */
  631. rv515_vga_render_disable(rdev);
  632. /* Initialize scratch registers */
  633. radeon_scratch_init(rdev);
  634. /* Initialize surface registers */
  635. radeon_surface_init(rdev);
  636. /* TODO: disable VGA need to use VGA request */
  637. /* BIOS*/
  638. if (!radeon_get_bios(rdev)) {
  639. if (ASIC_IS_AVIVO(rdev))
  640. return -EINVAL;
  641. }
  642. if (rdev->is_atom_bios) {
  643. r = radeon_atombios_init(rdev);
  644. if (r)
  645. return r;
  646. } else {
  647. dev_err(rdev->dev, "Expecting atombios for RV515 GPU\n");
  648. return -EINVAL;
  649. }
  650. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  651. if (radeon_gpu_reset(rdev)) {
  652. dev_warn(rdev->dev,
  653. "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  654. RREG32(R_000E40_RBBM_STATUS),
  655. RREG32(R_0007C0_CP_STAT));
  656. }
  657. /* check if cards are posted or not */
  658. if (!radeon_card_posted(rdev) && rdev->bios) {
  659. DRM_INFO("GPU not posted. posting now...\n");
  660. atom_asic_init(rdev->mode_info.atom_context);
  661. }
  662. /* Initialize clocks */
  663. radeon_get_clock_info(rdev->ddev);
  664. /* Initialize power management */
  665. radeon_pm_init(rdev);
  666. /* Get vram informations */
  667. rs690_vram_info(rdev);
  668. /* Initialize memory controller (also test AGP) */
  669. r = r420_mc_init(rdev);
  670. if (r)
  671. return r;
  672. rv515_debugfs(rdev);
  673. /* Fence driver */
  674. r = radeon_fence_driver_init(rdev);
  675. if (r)
  676. return r;
  677. r = radeon_irq_kms_init(rdev);
  678. if (r)
  679. return r;
  680. /* Memory manager */
  681. r = radeon_object_init(rdev);
  682. if (r)
  683. return r;
  684. r = rs400_gart_init(rdev);
  685. if (r)
  686. return r;
  687. rs600_set_safe_registers(rdev);
  688. rdev->accel_working = true;
  689. r = rs690_startup(rdev);
  690. if (r) {
  691. /* Somethings want wront with the accel init stop accel */
  692. dev_err(rdev->dev, "Disabling GPU acceleration\n");
  693. rs690_suspend(rdev);
  694. r100_cp_fini(rdev);
  695. r100_wb_fini(rdev);
  696. r100_ib_fini(rdev);
  697. rs400_gart_fini(rdev);
  698. radeon_irq_kms_fini(rdev);
  699. rdev->accel_working = false;
  700. }
  701. return 0;
  702. }