rs690.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  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. fixed20_12 a;
  129. rs400_gart_adjust_size(rdev);
  130. /* DDR for all card after R300 & IGP */
  131. rdev->mc.vram_is_ddr = true;
  132. rdev->mc.vram_width = 128;
  133. rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
  134. rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
  135. rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
  136. rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
  137. rs690_pm_info(rdev);
  138. /* FIXME: we should enforce default clock in case GPU is not in
  139. * default setup
  140. */
  141. a.full = rfixed_const(100);
  142. rdev->pm.sclk.full = rfixed_const(rdev->clock.default_sclk);
  143. rdev->pm.sclk.full = rfixed_div(rdev->pm.sclk, a);
  144. a.full = rfixed_const(16);
  145. /* core_bandwidth = sclk(Mhz) * 16 */
  146. rdev->pm.core_bandwidth.full = rfixed_div(rdev->pm.sclk, a);
  147. }
  148. void rs690_line_buffer_adjust(struct radeon_device *rdev,
  149. struct drm_display_mode *mode1,
  150. struct drm_display_mode *mode2)
  151. {
  152. u32 tmp;
  153. /*
  154. * Line Buffer Setup
  155. * There is a single line buffer shared by both display controllers.
  156. * R_006520_DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
  157. * the display controllers. The paritioning can either be done
  158. * manually or via one of four preset allocations specified in bits 1:0:
  159. * 0 - line buffer is divided in half and shared between crtc
  160. * 1 - D1 gets 3/4 of the line buffer, D2 gets 1/4
  161. * 2 - D1 gets the whole buffer
  162. * 3 - D1 gets 1/4 of the line buffer, D2 gets 3/4
  163. * Setting bit 2 of R_006520_DC_LB_MEMORY_SPLIT controls switches to manual
  164. * allocation mode. In manual allocation mode, D1 always starts at 0,
  165. * D1 end/2 is specified in bits 14:4; D2 allocation follows D1.
  166. */
  167. tmp = RREG32(R_006520_DC_LB_MEMORY_SPLIT) & C_006520_DC_LB_MEMORY_SPLIT;
  168. tmp &= ~C_006520_DC_LB_MEMORY_SPLIT_MODE;
  169. /* auto */
  170. if (mode1 && mode2) {
  171. if (mode1->hdisplay > mode2->hdisplay) {
  172. if (mode1->hdisplay > 2560)
  173. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_3Q_D2_1Q;
  174. else
  175. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
  176. } else if (mode2->hdisplay > mode1->hdisplay) {
  177. if (mode2->hdisplay > 2560)
  178. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_1Q_D2_3Q;
  179. else
  180. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
  181. } else
  182. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
  183. } else if (mode1) {
  184. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_ONLY;
  185. } else if (mode2) {
  186. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_1Q_D2_3Q;
  187. }
  188. WREG32(R_006520_DC_LB_MEMORY_SPLIT, tmp);
  189. }
  190. struct rs690_watermark {
  191. u32 lb_request_fifo_depth;
  192. fixed20_12 num_line_pair;
  193. fixed20_12 estimated_width;
  194. fixed20_12 worst_case_latency;
  195. fixed20_12 consumption_rate;
  196. fixed20_12 active_time;
  197. fixed20_12 dbpp;
  198. fixed20_12 priority_mark_max;
  199. fixed20_12 priority_mark;
  200. fixed20_12 sclk;
  201. };
  202. void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
  203. struct radeon_crtc *crtc,
  204. struct rs690_watermark *wm)
  205. {
  206. struct drm_display_mode *mode = &crtc->base.mode;
  207. fixed20_12 a, b, c;
  208. fixed20_12 pclk, request_fifo_depth, tolerable_latency, estimated_width;
  209. fixed20_12 consumption_time, line_time, chunk_time, read_delay_latency;
  210. /* FIXME: detect IGP with sideport memory, i don't think there is any
  211. * such product available
  212. */
  213. bool sideport = false;
  214. if (!crtc->base.enabled) {
  215. /* FIXME: wouldn't it better to set priority mark to maximum */
  216. wm->lb_request_fifo_depth = 4;
  217. return;
  218. }
  219. if (crtc->vsc.full > rfixed_const(2))
  220. wm->num_line_pair.full = rfixed_const(2);
  221. else
  222. wm->num_line_pair.full = rfixed_const(1);
  223. b.full = rfixed_const(mode->crtc_hdisplay);
  224. c.full = rfixed_const(256);
  225. a.full = rfixed_mul(wm->num_line_pair, b);
  226. request_fifo_depth.full = rfixed_div(a, c);
  227. if (a.full < rfixed_const(4)) {
  228. wm->lb_request_fifo_depth = 4;
  229. } else {
  230. wm->lb_request_fifo_depth = rfixed_trunc(request_fifo_depth);
  231. }
  232. /* Determine consumption rate
  233. * pclk = pixel clock period(ns) = 1000 / (mode.clock / 1000)
  234. * vtaps = number of vertical taps,
  235. * vsc = vertical scaling ratio, defined as source/destination
  236. * hsc = horizontal scaling ration, defined as source/destination
  237. */
  238. a.full = rfixed_const(mode->clock);
  239. b.full = rfixed_const(1000);
  240. a.full = rfixed_div(a, b);
  241. pclk.full = rfixed_div(b, a);
  242. if (crtc->rmx_type != RMX_OFF) {
  243. b.full = rfixed_const(2);
  244. if (crtc->vsc.full > b.full)
  245. b.full = crtc->vsc.full;
  246. b.full = rfixed_mul(b, crtc->hsc);
  247. c.full = rfixed_const(2);
  248. b.full = rfixed_div(b, c);
  249. consumption_time.full = rfixed_div(pclk, b);
  250. } else {
  251. consumption_time.full = pclk.full;
  252. }
  253. a.full = rfixed_const(1);
  254. wm->consumption_rate.full = rfixed_div(a, consumption_time);
  255. /* Determine line time
  256. * LineTime = total time for one line of displayhtotal
  257. * LineTime = total number of horizontal pixels
  258. * pclk = pixel clock period(ns)
  259. */
  260. a.full = rfixed_const(crtc->base.mode.crtc_htotal);
  261. line_time.full = rfixed_mul(a, pclk);
  262. /* Determine active time
  263. * ActiveTime = time of active region of display within one line,
  264. * hactive = total number of horizontal active pixels
  265. * htotal = total number of horizontal pixels
  266. */
  267. a.full = rfixed_const(crtc->base.mode.crtc_htotal);
  268. b.full = rfixed_const(crtc->base.mode.crtc_hdisplay);
  269. wm->active_time.full = rfixed_mul(line_time, b);
  270. wm->active_time.full = rfixed_div(wm->active_time, a);
  271. /* Maximun bandwidth is the minimun bandwidth of all component */
  272. rdev->pm.max_bandwidth = rdev->pm.core_bandwidth;
  273. if (sideport) {
  274. if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
  275. rdev->pm.sideport_bandwidth.full)
  276. rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
  277. read_delay_latency.full = rfixed_const(370 * 800 * 1000);
  278. read_delay_latency.full = rfixed_div(read_delay_latency,
  279. rdev->pm.igp_sideport_mclk);
  280. } else {
  281. if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
  282. rdev->pm.k8_bandwidth.full)
  283. rdev->pm.max_bandwidth = rdev->pm.k8_bandwidth;
  284. if (rdev->pm.max_bandwidth.full > rdev->pm.ht_bandwidth.full &&
  285. rdev->pm.ht_bandwidth.full)
  286. rdev->pm.max_bandwidth = rdev->pm.ht_bandwidth;
  287. read_delay_latency.full = rfixed_const(5000);
  288. }
  289. /* sclk = system clocks(ns) = 1000 / max_bandwidth / 16 */
  290. a.full = rfixed_const(16);
  291. rdev->pm.sclk.full = rfixed_mul(rdev->pm.max_bandwidth, a);
  292. a.full = rfixed_const(1000);
  293. rdev->pm.sclk.full = rfixed_div(a, rdev->pm.sclk);
  294. /* Determine chunk time
  295. * ChunkTime = the time it takes the DCP to send one chunk of data
  296. * to the LB which consists of pipeline delay and inter chunk gap
  297. * sclk = system clock(ns)
  298. */
  299. a.full = rfixed_const(256 * 13);
  300. chunk_time.full = rfixed_mul(rdev->pm.sclk, a);
  301. a.full = rfixed_const(10);
  302. chunk_time.full = rfixed_div(chunk_time, a);
  303. /* Determine the worst case latency
  304. * NumLinePair = Number of line pairs to request(1=2 lines, 2=4 lines)
  305. * WorstCaseLatency = worst case time from urgent to when the MC starts
  306. * to return data
  307. * READ_DELAY_IDLE_MAX = constant of 1us
  308. * ChunkTime = time it takes the DCP to send one chunk of data to the LB
  309. * which consists of pipeline delay and inter chunk gap
  310. */
  311. if (rfixed_trunc(wm->num_line_pair) > 1) {
  312. a.full = rfixed_const(3);
  313. wm->worst_case_latency.full = rfixed_mul(a, chunk_time);
  314. wm->worst_case_latency.full += read_delay_latency.full;
  315. } else {
  316. a.full = rfixed_const(2);
  317. wm->worst_case_latency.full = rfixed_mul(a, chunk_time);
  318. wm->worst_case_latency.full += read_delay_latency.full;
  319. }
  320. /* Determine the tolerable latency
  321. * TolerableLatency = Any given request has only 1 line time
  322. * for the data to be returned
  323. * LBRequestFifoDepth = Number of chunk requests the LB can
  324. * put into the request FIFO for a display
  325. * LineTime = total time for one line of display
  326. * ChunkTime = the time it takes the DCP to send one chunk
  327. * of data to the LB which consists of
  328. * pipeline delay and inter chunk gap
  329. */
  330. if ((2+wm->lb_request_fifo_depth) >= rfixed_trunc(request_fifo_depth)) {
  331. tolerable_latency.full = line_time.full;
  332. } else {
  333. tolerable_latency.full = rfixed_const(wm->lb_request_fifo_depth - 2);
  334. tolerable_latency.full = request_fifo_depth.full - tolerable_latency.full;
  335. tolerable_latency.full = rfixed_mul(tolerable_latency, chunk_time);
  336. tolerable_latency.full = line_time.full - tolerable_latency.full;
  337. }
  338. /* We assume worst case 32bits (4 bytes) */
  339. wm->dbpp.full = rfixed_const(4 * 8);
  340. /* Determine the maximum priority mark
  341. * width = viewport width in pixels
  342. */
  343. a.full = rfixed_const(16);
  344. wm->priority_mark_max.full = rfixed_const(crtc->base.mode.crtc_hdisplay);
  345. wm->priority_mark_max.full = rfixed_div(wm->priority_mark_max, a);
  346. /* Determine estimated width */
  347. estimated_width.full = tolerable_latency.full - wm->worst_case_latency.full;
  348. estimated_width.full = rfixed_div(estimated_width, consumption_time);
  349. if (rfixed_trunc(estimated_width) > crtc->base.mode.crtc_hdisplay) {
  350. wm->priority_mark.full = rfixed_const(10);
  351. } else {
  352. a.full = rfixed_const(16);
  353. wm->priority_mark.full = rfixed_div(estimated_width, a);
  354. wm->priority_mark.full = wm->priority_mark_max.full - wm->priority_mark.full;
  355. }
  356. }
  357. void rs690_bandwidth_update(struct radeon_device *rdev)
  358. {
  359. struct drm_display_mode *mode0 = NULL;
  360. struct drm_display_mode *mode1 = NULL;
  361. struct rs690_watermark wm0;
  362. struct rs690_watermark wm1;
  363. u32 tmp;
  364. fixed20_12 priority_mark02, priority_mark12, fill_rate;
  365. fixed20_12 a, b;
  366. if (rdev->mode_info.crtcs[0]->base.enabled)
  367. mode0 = &rdev->mode_info.crtcs[0]->base.mode;
  368. if (rdev->mode_info.crtcs[1]->base.enabled)
  369. mode1 = &rdev->mode_info.crtcs[1]->base.mode;
  370. /*
  371. * Set display0/1 priority up in the memory controller for
  372. * modes if the user specifies HIGH for displaypriority
  373. * option.
  374. */
  375. if (rdev->disp_priority == 2) {
  376. tmp = RREG32_MC(R_000104_MC_INIT_MISC_LAT_TIMER);
  377. tmp &= C_000104_MC_DISP0R_INIT_LAT;
  378. tmp &= C_000104_MC_DISP1R_INIT_LAT;
  379. if (mode0)
  380. tmp |= S_000104_MC_DISP0R_INIT_LAT(1);
  381. if (mode1)
  382. tmp |= S_000104_MC_DISP1R_INIT_LAT(1);
  383. WREG32_MC(R_000104_MC_INIT_MISC_LAT_TIMER, tmp);
  384. }
  385. rs690_line_buffer_adjust(rdev, mode0, mode1);
  386. if ((rdev->family == CHIP_RS690) || (rdev->family == CHIP_RS740))
  387. WREG32(R_006C9C_DCP_CONTROL, 0);
  388. if ((rdev->family == CHIP_RS780) || (rdev->family == CHIP_RS880))
  389. WREG32(R_006C9C_DCP_CONTROL, 2);
  390. rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[0], &wm0);
  391. rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[1], &wm1);
  392. tmp = (wm0.lb_request_fifo_depth - 1);
  393. tmp |= (wm1.lb_request_fifo_depth - 1) << 16;
  394. WREG32(R_006D58_LB_MAX_REQ_OUTSTANDING, tmp);
  395. if (mode0 && mode1) {
  396. if (rfixed_trunc(wm0.dbpp) > 64)
  397. a.full = rfixed_mul(wm0.dbpp, wm0.num_line_pair);
  398. else
  399. a.full = wm0.num_line_pair.full;
  400. if (rfixed_trunc(wm1.dbpp) > 64)
  401. b.full = rfixed_mul(wm1.dbpp, wm1.num_line_pair);
  402. else
  403. b.full = wm1.num_line_pair.full;
  404. a.full += b.full;
  405. fill_rate.full = rfixed_div(wm0.sclk, a);
  406. if (wm0.consumption_rate.full > fill_rate.full) {
  407. b.full = wm0.consumption_rate.full - fill_rate.full;
  408. b.full = rfixed_mul(b, wm0.active_time);
  409. a.full = rfixed_mul(wm0.worst_case_latency,
  410. wm0.consumption_rate);
  411. a.full = a.full + b.full;
  412. b.full = rfixed_const(16 * 1000);
  413. priority_mark02.full = rfixed_div(a, b);
  414. } else {
  415. a.full = rfixed_mul(wm0.worst_case_latency,
  416. wm0.consumption_rate);
  417. b.full = rfixed_const(16 * 1000);
  418. priority_mark02.full = rfixed_div(a, b);
  419. }
  420. if (wm1.consumption_rate.full > fill_rate.full) {
  421. b.full = wm1.consumption_rate.full - fill_rate.full;
  422. b.full = rfixed_mul(b, wm1.active_time);
  423. a.full = rfixed_mul(wm1.worst_case_latency,
  424. wm1.consumption_rate);
  425. a.full = a.full + b.full;
  426. b.full = rfixed_const(16 * 1000);
  427. priority_mark12.full = rfixed_div(a, b);
  428. } else {
  429. a.full = rfixed_mul(wm1.worst_case_latency,
  430. wm1.consumption_rate);
  431. b.full = rfixed_const(16 * 1000);
  432. priority_mark12.full = rfixed_div(a, b);
  433. }
  434. if (wm0.priority_mark.full > priority_mark02.full)
  435. priority_mark02.full = wm0.priority_mark.full;
  436. if (rfixed_trunc(priority_mark02) < 0)
  437. priority_mark02.full = 0;
  438. if (wm0.priority_mark_max.full > priority_mark02.full)
  439. priority_mark02.full = wm0.priority_mark_max.full;
  440. if (wm1.priority_mark.full > priority_mark12.full)
  441. priority_mark12.full = wm1.priority_mark.full;
  442. if (rfixed_trunc(priority_mark12) < 0)
  443. priority_mark12.full = 0;
  444. if (wm1.priority_mark_max.full > priority_mark12.full)
  445. priority_mark12.full = wm1.priority_mark_max.full;
  446. WREG32(R_006548_D1MODE_PRIORITY_A_CNT, rfixed_trunc(priority_mark02));
  447. WREG32(R_00654C_D1MODE_PRIORITY_B_CNT, rfixed_trunc(priority_mark02));
  448. WREG32(R_006D48_D2MODE_PRIORITY_A_CNT, rfixed_trunc(priority_mark12));
  449. WREG32(R_006D4C_D2MODE_PRIORITY_B_CNT, rfixed_trunc(priority_mark12));
  450. } else if (mode0) {
  451. if (rfixed_trunc(wm0.dbpp) > 64)
  452. a.full = rfixed_mul(wm0.dbpp, wm0.num_line_pair);
  453. else
  454. a.full = wm0.num_line_pair.full;
  455. fill_rate.full = rfixed_div(wm0.sclk, a);
  456. if (wm0.consumption_rate.full > fill_rate.full) {
  457. b.full = wm0.consumption_rate.full - fill_rate.full;
  458. b.full = rfixed_mul(b, wm0.active_time);
  459. a.full = rfixed_mul(wm0.worst_case_latency,
  460. wm0.consumption_rate);
  461. a.full = a.full + b.full;
  462. b.full = rfixed_const(16 * 1000);
  463. priority_mark02.full = rfixed_div(a, b);
  464. } else {
  465. a.full = rfixed_mul(wm0.worst_case_latency,
  466. wm0.consumption_rate);
  467. b.full = rfixed_const(16 * 1000);
  468. priority_mark02.full = rfixed_div(a, b);
  469. }
  470. if (wm0.priority_mark.full > priority_mark02.full)
  471. priority_mark02.full = wm0.priority_mark.full;
  472. if (rfixed_trunc(priority_mark02) < 0)
  473. priority_mark02.full = 0;
  474. if (wm0.priority_mark_max.full > priority_mark02.full)
  475. priority_mark02.full = wm0.priority_mark_max.full;
  476. WREG32(R_006548_D1MODE_PRIORITY_A_CNT, rfixed_trunc(priority_mark02));
  477. WREG32(R_00654C_D1MODE_PRIORITY_B_CNT, rfixed_trunc(priority_mark02));
  478. WREG32(R_006D48_D2MODE_PRIORITY_A_CNT,
  479. S_006D48_D2MODE_PRIORITY_A_OFF(1));
  480. WREG32(R_006D4C_D2MODE_PRIORITY_B_CNT,
  481. S_006D4C_D2MODE_PRIORITY_B_OFF(1));
  482. } else {
  483. if (rfixed_trunc(wm1.dbpp) > 64)
  484. a.full = rfixed_mul(wm1.dbpp, wm1.num_line_pair);
  485. else
  486. a.full = wm1.num_line_pair.full;
  487. fill_rate.full = rfixed_div(wm1.sclk, a);
  488. if (wm1.consumption_rate.full > fill_rate.full) {
  489. b.full = wm1.consumption_rate.full - fill_rate.full;
  490. b.full = rfixed_mul(b, wm1.active_time);
  491. a.full = rfixed_mul(wm1.worst_case_latency,
  492. wm1.consumption_rate);
  493. a.full = a.full + b.full;
  494. b.full = rfixed_const(16 * 1000);
  495. priority_mark12.full = rfixed_div(a, b);
  496. } else {
  497. a.full = rfixed_mul(wm1.worst_case_latency,
  498. wm1.consumption_rate);
  499. b.full = rfixed_const(16 * 1000);
  500. priority_mark12.full = rfixed_div(a, b);
  501. }
  502. if (wm1.priority_mark.full > priority_mark12.full)
  503. priority_mark12.full = wm1.priority_mark.full;
  504. if (rfixed_trunc(priority_mark12) < 0)
  505. priority_mark12.full = 0;
  506. if (wm1.priority_mark_max.full > priority_mark12.full)
  507. priority_mark12.full = wm1.priority_mark_max.full;
  508. WREG32(R_006548_D1MODE_PRIORITY_A_CNT,
  509. S_006548_D1MODE_PRIORITY_A_OFF(1));
  510. WREG32(R_00654C_D1MODE_PRIORITY_B_CNT,
  511. S_00654C_D1MODE_PRIORITY_B_OFF(1));
  512. WREG32(R_006D48_D2MODE_PRIORITY_A_CNT, rfixed_trunc(priority_mark12));
  513. WREG32(R_006D4C_D2MODE_PRIORITY_B_CNT, rfixed_trunc(priority_mark12));
  514. }
  515. }
  516. uint32_t rs690_mc_rreg(struct radeon_device *rdev, uint32_t reg)
  517. {
  518. uint32_t r;
  519. WREG32(R_000078_MC_INDEX, S_000078_MC_IND_ADDR(reg));
  520. r = RREG32(R_00007C_MC_DATA);
  521. WREG32(R_000078_MC_INDEX, ~C_000078_MC_IND_ADDR);
  522. return r;
  523. }
  524. void rs690_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  525. {
  526. WREG32(R_000078_MC_INDEX, S_000078_MC_IND_ADDR(reg) |
  527. S_000078_MC_IND_WR_EN(1));
  528. WREG32(R_00007C_MC_DATA, v);
  529. WREG32(R_000078_MC_INDEX, 0x7F);
  530. }
  531. void rs690_mc_program(struct radeon_device *rdev)
  532. {
  533. struct rv515_mc_save save;
  534. /* Stops all mc clients */
  535. rv515_mc_stop(rdev, &save);
  536. /* Wait for mc idle */
  537. if (rs690_mc_wait_for_idle(rdev))
  538. dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
  539. /* Program MC, should be a 32bits limited address space */
  540. WREG32_MC(R_000100_MCCFG_FB_LOCATION,
  541. S_000100_MC_FB_START(rdev->mc.vram_start >> 16) |
  542. S_000100_MC_FB_TOP(rdev->mc.vram_end >> 16));
  543. WREG32(R_000134_HDP_FB_LOCATION,
  544. S_000134_HDP_FB_START(rdev->mc.vram_start >> 16));
  545. rv515_mc_resume(rdev, &save);
  546. }
  547. static int rs690_startup(struct radeon_device *rdev)
  548. {
  549. int r;
  550. rs690_mc_program(rdev);
  551. /* Resume clock */
  552. rv515_clock_startup(rdev);
  553. /* Initialize GPU configuration (# pipes, ...) */
  554. rs690_gpu_init(rdev);
  555. /* Initialize GART (initialize after TTM so we can allocate
  556. * memory through TTM but finalize after TTM) */
  557. r = rs400_gart_enable(rdev);
  558. if (r)
  559. return r;
  560. /* Enable IRQ */
  561. rs600_irq_set(rdev);
  562. /* 1M ring buffer */
  563. r = r100_cp_init(rdev, 1024 * 1024);
  564. if (r) {
  565. dev_err(rdev->dev, "failled initializing CP (%d).\n", r);
  566. return r;
  567. }
  568. r = r100_wb_init(rdev);
  569. if (r)
  570. dev_err(rdev->dev, "failled initializing WB (%d).\n", r);
  571. r = r100_ib_init(rdev);
  572. if (r) {
  573. dev_err(rdev->dev, "failled initializing IB (%d).\n", r);
  574. return r;
  575. }
  576. return 0;
  577. }
  578. int rs690_resume(struct radeon_device *rdev)
  579. {
  580. /* Make sur GART are not working */
  581. rs400_gart_disable(rdev);
  582. /* Resume clock before doing reset */
  583. rv515_clock_startup(rdev);
  584. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  585. if (radeon_gpu_reset(rdev)) {
  586. dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  587. RREG32(R_000E40_RBBM_STATUS),
  588. RREG32(R_0007C0_CP_STAT));
  589. }
  590. /* post */
  591. atom_asic_init(rdev->mode_info.atom_context);
  592. /* Resume clock after posting */
  593. rv515_clock_startup(rdev);
  594. return rs690_startup(rdev);
  595. }
  596. int rs690_suspend(struct radeon_device *rdev)
  597. {
  598. r100_cp_disable(rdev);
  599. r100_wb_disable(rdev);
  600. rs600_irq_disable(rdev);
  601. rs400_gart_disable(rdev);
  602. return 0;
  603. }
  604. void rs690_fini(struct radeon_device *rdev)
  605. {
  606. rs690_suspend(rdev);
  607. r100_cp_fini(rdev);
  608. r100_wb_fini(rdev);
  609. r100_ib_fini(rdev);
  610. radeon_gem_fini(rdev);
  611. rs400_gart_fini(rdev);
  612. radeon_irq_kms_fini(rdev);
  613. radeon_fence_driver_fini(rdev);
  614. radeon_bo_fini(rdev);
  615. radeon_atombios_fini(rdev);
  616. kfree(rdev->bios);
  617. rdev->bios = NULL;
  618. }
  619. int rs690_init(struct radeon_device *rdev)
  620. {
  621. int r;
  622. /* Disable VGA */
  623. rv515_vga_render_disable(rdev);
  624. /* Initialize scratch registers */
  625. radeon_scratch_init(rdev);
  626. /* Initialize surface registers */
  627. radeon_surface_init(rdev);
  628. /* TODO: disable VGA need to use VGA request */
  629. /* BIOS*/
  630. if (!radeon_get_bios(rdev)) {
  631. if (ASIC_IS_AVIVO(rdev))
  632. return -EINVAL;
  633. }
  634. if (rdev->is_atom_bios) {
  635. r = radeon_atombios_init(rdev);
  636. if (r)
  637. return r;
  638. } else {
  639. dev_err(rdev->dev, "Expecting atombios for RV515 GPU\n");
  640. return -EINVAL;
  641. }
  642. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  643. if (radeon_gpu_reset(rdev)) {
  644. dev_warn(rdev->dev,
  645. "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  646. RREG32(R_000E40_RBBM_STATUS),
  647. RREG32(R_0007C0_CP_STAT));
  648. }
  649. /* check if cards are posted or not */
  650. if (radeon_boot_test_post_card(rdev) == false)
  651. return -EINVAL;
  652. /* Initialize clocks */
  653. radeon_get_clock_info(rdev->ddev);
  654. /* Initialize power management */
  655. radeon_pm_init(rdev);
  656. /* Get vram informations */
  657. rs690_vram_info(rdev);
  658. /* Initialize memory controller (also test AGP) */
  659. r = r420_mc_init(rdev);
  660. if (r)
  661. return r;
  662. rv515_debugfs(rdev);
  663. /* Fence driver */
  664. r = radeon_fence_driver_init(rdev);
  665. if (r)
  666. return r;
  667. r = radeon_irq_kms_init(rdev);
  668. if (r)
  669. return r;
  670. /* Memory manager */
  671. r = radeon_bo_init(rdev);
  672. if (r)
  673. return r;
  674. r = rs400_gart_init(rdev);
  675. if (r)
  676. return r;
  677. rs600_set_safe_registers(rdev);
  678. rdev->accel_working = true;
  679. r = rs690_startup(rdev);
  680. if (r) {
  681. /* Somethings want wront with the accel init stop accel */
  682. dev_err(rdev->dev, "Disabling GPU acceleration\n");
  683. rs690_suspend(rdev);
  684. r100_cp_fini(rdev);
  685. r100_wb_fini(rdev);
  686. r100_ib_fini(rdev);
  687. rs400_gart_fini(rdev);
  688. radeon_irq_kms_fini(rdev);
  689. rdev->accel_working = false;
  690. }
  691. return 0;
  692. }