rs690.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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 "radeon_asic.h"
  31. #include "atom.h"
  32. #include "rs690d.h"
  33. static int rs690_mc_wait_for_idle(struct radeon_device *rdev)
  34. {
  35. unsigned i;
  36. uint32_t tmp;
  37. for (i = 0; i < rdev->usec_timeout; i++) {
  38. /* read MC_STATUS */
  39. tmp = RREG32_MC(R_000090_MC_SYSTEM_STATUS);
  40. if (G_000090_MC_SYSTEM_IDLE(tmp))
  41. return 0;
  42. udelay(1);
  43. }
  44. return -1;
  45. }
  46. static void rs690_gpu_init(struct radeon_device *rdev)
  47. {
  48. /* FIXME: HDP same place on rs690 ? */
  49. r100_hdp_reset(rdev);
  50. /* FIXME: is this correct ? */
  51. r420_pipes_init(rdev);
  52. if (rs690_mc_wait_for_idle(rdev)) {
  53. printk(KERN_WARNING "Failed to wait MC idle while "
  54. "programming pipes. Bad things might happen.\n");
  55. }
  56. }
  57. void rs690_pm_info(struct radeon_device *rdev)
  58. {
  59. int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
  60. struct _ATOM_INTEGRATED_SYSTEM_INFO *info;
  61. struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 *info_v2;
  62. void *ptr;
  63. uint16_t data_offset;
  64. uint8_t frev, crev;
  65. fixed20_12 tmp;
  66. atom_parse_data_header(rdev->mode_info.atom_context, index, NULL,
  67. &frev, &crev, &data_offset);
  68. ptr = rdev->mode_info.atom_context->bios + data_offset;
  69. info = (struct _ATOM_INTEGRATED_SYSTEM_INFO *)ptr;
  70. info_v2 = (struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 *)ptr;
  71. /* Get various system informations from bios */
  72. switch (crev) {
  73. case 1:
  74. tmp.full = rfixed_const(100);
  75. rdev->pm.igp_sideport_mclk.full = rfixed_const(info->ulBootUpMemoryClock);
  76. rdev->pm.igp_sideport_mclk.full = rfixed_div(rdev->pm.igp_sideport_mclk, tmp);
  77. rdev->pm.igp_system_mclk.full = rfixed_const(le16_to_cpu(info->usK8MemoryClock));
  78. rdev->pm.igp_ht_link_clk.full = rfixed_const(le16_to_cpu(info->usFSBClock));
  79. rdev->pm.igp_ht_link_width.full = rfixed_const(info->ucHTLinkWidth);
  80. break;
  81. case 2:
  82. tmp.full = rfixed_const(100);
  83. rdev->pm.igp_sideport_mclk.full = rfixed_const(info_v2->ulBootUpSidePortClock);
  84. rdev->pm.igp_sideport_mclk.full = rfixed_div(rdev->pm.igp_sideport_mclk, tmp);
  85. rdev->pm.igp_system_mclk.full = rfixed_const(info_v2->ulBootUpUMAClock);
  86. rdev->pm.igp_system_mclk.full = rfixed_div(rdev->pm.igp_system_mclk, tmp);
  87. rdev->pm.igp_ht_link_clk.full = rfixed_const(info_v2->ulHTLinkFreq);
  88. rdev->pm.igp_ht_link_clk.full = rfixed_div(rdev->pm.igp_ht_link_clk, tmp);
  89. rdev->pm.igp_ht_link_width.full = rfixed_const(le16_to_cpu(info_v2->usMinHTLinkWidth));
  90. break;
  91. default:
  92. tmp.full = rfixed_const(100);
  93. /* We assume the slower possible clock ie worst case */
  94. /* DDR 333Mhz */
  95. rdev->pm.igp_sideport_mclk.full = rfixed_const(333);
  96. /* FIXME: system clock ? */
  97. rdev->pm.igp_system_mclk.full = rfixed_const(100);
  98. rdev->pm.igp_system_mclk.full = rfixed_div(rdev->pm.igp_system_mclk, tmp);
  99. rdev->pm.igp_ht_link_clk.full = rfixed_const(200);
  100. rdev->pm.igp_ht_link_width.full = rfixed_const(8);
  101. DRM_ERROR("No integrated system info for your GPU, using safe default\n");
  102. break;
  103. }
  104. /* Compute various bandwidth */
  105. /* k8_bandwidth = (memory_clk / 2) * 2 * 8 * 0.5 = memory_clk * 4 */
  106. tmp.full = rfixed_const(4);
  107. rdev->pm.k8_bandwidth.full = rfixed_mul(rdev->pm.igp_system_mclk, tmp);
  108. /* ht_bandwidth = ht_clk * 2 * ht_width / 8 * 0.8
  109. * = ht_clk * ht_width / 5
  110. */
  111. tmp.full = rfixed_const(5);
  112. rdev->pm.ht_bandwidth.full = rfixed_mul(rdev->pm.igp_ht_link_clk,
  113. rdev->pm.igp_ht_link_width);
  114. rdev->pm.ht_bandwidth.full = rfixed_div(rdev->pm.ht_bandwidth, tmp);
  115. if (tmp.full < rdev->pm.max_bandwidth.full) {
  116. /* HT link is a limiting factor */
  117. rdev->pm.max_bandwidth.full = tmp.full;
  118. }
  119. /* sideport_bandwidth = (sideport_clk / 2) * 2 * 2 * 0.7
  120. * = (sideport_clk * 14) / 10
  121. */
  122. tmp.full = rfixed_const(14);
  123. rdev->pm.sideport_bandwidth.full = rfixed_mul(rdev->pm.igp_sideport_mclk, tmp);
  124. tmp.full = rfixed_const(10);
  125. rdev->pm.sideport_bandwidth.full = rfixed_div(rdev->pm.sideport_bandwidth, tmp);
  126. }
  127. void rs690_mc_init(struct radeon_device *rdev)
  128. {
  129. fixed20_12 a;
  130. u64 base;
  131. rs400_gart_adjust_size(rdev);
  132. rdev->mc.vram_is_ddr = true;
  133. rdev->mc.vram_width = 128;
  134. rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
  135. rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
  136. rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
  137. rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
  138. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  139. base = RREG32_MC(R_000100_MCCFG_FB_LOCATION);
  140. base = G_000100_MC_FB_START(base) << 16;
  141. rs690_pm_info(rdev);
  142. /* FIXME: we should enforce default clock in case GPU is not in
  143. * default setup
  144. */
  145. a.full = rfixed_const(100);
  146. rdev->pm.sclk.full = rfixed_const(rdev->clock.default_sclk);
  147. rdev->pm.sclk.full = rfixed_div(rdev->pm.sclk, a);
  148. a.full = rfixed_const(16);
  149. /* core_bandwidth = sclk(Mhz) * 16 */
  150. rdev->pm.core_bandwidth.full = rfixed_div(rdev->pm.sclk, a);
  151. rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
  152. radeon_vram_location(rdev, &rdev->mc, base);
  153. radeon_gtt_location(rdev, &rdev->mc);
  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_div(b, c);
  233. request_fifo_depth.full = rfixed_mul(a, wm->num_line_pair);
  234. request_fifo_depth.full = rfixed_ceil(request_fifo_depth);
  235. if (a.full < rfixed_const(4)) {
  236. wm->lb_request_fifo_depth = 4;
  237. } else {
  238. wm->lb_request_fifo_depth = rfixed_trunc(request_fifo_depth);
  239. }
  240. /* Determine consumption rate
  241. * pclk = pixel clock period(ns) = 1000 / (mode.clock / 1000)
  242. * vtaps = number of vertical taps,
  243. * vsc = vertical scaling ratio, defined as source/destination
  244. * hsc = horizontal scaling ration, defined as source/destination
  245. */
  246. a.full = rfixed_const(mode->clock);
  247. b.full = rfixed_const(1000);
  248. a.full = rfixed_div(a, b);
  249. pclk.full = rfixed_div(b, a);
  250. if (crtc->rmx_type != RMX_OFF) {
  251. b.full = rfixed_const(2);
  252. if (crtc->vsc.full > b.full)
  253. b.full = crtc->vsc.full;
  254. b.full = rfixed_mul(b, crtc->hsc);
  255. c.full = rfixed_const(2);
  256. b.full = rfixed_div(b, c);
  257. consumption_time.full = rfixed_div(pclk, b);
  258. } else {
  259. consumption_time.full = pclk.full;
  260. }
  261. a.full = rfixed_const(1);
  262. wm->consumption_rate.full = rfixed_div(a, consumption_time);
  263. /* Determine line time
  264. * LineTime = total time for one line of displayhtotal
  265. * LineTime = total number of horizontal pixels
  266. * pclk = pixel clock period(ns)
  267. */
  268. a.full = rfixed_const(crtc->base.mode.crtc_htotal);
  269. line_time.full = rfixed_mul(a, pclk);
  270. /* Determine active time
  271. * ActiveTime = time of active region of display within one line,
  272. * hactive = total number of horizontal active pixels
  273. * htotal = total number of horizontal pixels
  274. */
  275. a.full = rfixed_const(crtc->base.mode.crtc_htotal);
  276. b.full = rfixed_const(crtc->base.mode.crtc_hdisplay);
  277. wm->active_time.full = rfixed_mul(line_time, b);
  278. wm->active_time.full = rfixed_div(wm->active_time, a);
  279. /* Maximun bandwidth is the minimun bandwidth of all component */
  280. rdev->pm.max_bandwidth = rdev->pm.core_bandwidth;
  281. if (sideport) {
  282. if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
  283. rdev->pm.sideport_bandwidth.full)
  284. rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
  285. read_delay_latency.full = rfixed_const(370 * 800 * 1000);
  286. read_delay_latency.full = rfixed_div(read_delay_latency,
  287. rdev->pm.igp_sideport_mclk);
  288. } else {
  289. if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
  290. rdev->pm.k8_bandwidth.full)
  291. rdev->pm.max_bandwidth = rdev->pm.k8_bandwidth;
  292. if (rdev->pm.max_bandwidth.full > rdev->pm.ht_bandwidth.full &&
  293. rdev->pm.ht_bandwidth.full)
  294. rdev->pm.max_bandwidth = rdev->pm.ht_bandwidth;
  295. read_delay_latency.full = rfixed_const(5000);
  296. }
  297. /* sclk = system clocks(ns) = 1000 / max_bandwidth / 16 */
  298. a.full = rfixed_const(16);
  299. rdev->pm.sclk.full = rfixed_mul(rdev->pm.max_bandwidth, a);
  300. a.full = rfixed_const(1000);
  301. rdev->pm.sclk.full = rfixed_div(a, rdev->pm.sclk);
  302. /* Determine chunk time
  303. * ChunkTime = the time it takes the DCP to send one chunk of data
  304. * to the LB which consists of pipeline delay and inter chunk gap
  305. * sclk = system clock(ns)
  306. */
  307. a.full = rfixed_const(256 * 13);
  308. chunk_time.full = rfixed_mul(rdev->pm.sclk, a);
  309. a.full = rfixed_const(10);
  310. chunk_time.full = rfixed_div(chunk_time, a);
  311. /* Determine the worst case latency
  312. * NumLinePair = Number of line pairs to request(1=2 lines, 2=4 lines)
  313. * WorstCaseLatency = worst case time from urgent to when the MC starts
  314. * to return data
  315. * READ_DELAY_IDLE_MAX = constant of 1us
  316. * ChunkTime = time it takes the DCP to send one chunk of data to the LB
  317. * which consists of pipeline delay and inter chunk gap
  318. */
  319. if (rfixed_trunc(wm->num_line_pair) > 1) {
  320. a.full = rfixed_const(3);
  321. wm->worst_case_latency.full = rfixed_mul(a, chunk_time);
  322. wm->worst_case_latency.full += read_delay_latency.full;
  323. } else {
  324. a.full = rfixed_const(2);
  325. wm->worst_case_latency.full = rfixed_mul(a, chunk_time);
  326. wm->worst_case_latency.full += read_delay_latency.full;
  327. }
  328. /* Determine the tolerable latency
  329. * TolerableLatency = Any given request has only 1 line time
  330. * for the data to be returned
  331. * LBRequestFifoDepth = Number of chunk requests the LB can
  332. * put into the request FIFO for a display
  333. * LineTime = total time for one line of display
  334. * ChunkTime = the time it takes the DCP to send one chunk
  335. * of data to the LB which consists of
  336. * pipeline delay and inter chunk gap
  337. */
  338. if ((2+wm->lb_request_fifo_depth) >= rfixed_trunc(request_fifo_depth)) {
  339. tolerable_latency.full = line_time.full;
  340. } else {
  341. tolerable_latency.full = rfixed_const(wm->lb_request_fifo_depth - 2);
  342. tolerable_latency.full = request_fifo_depth.full - tolerable_latency.full;
  343. tolerable_latency.full = rfixed_mul(tolerable_latency, chunk_time);
  344. tolerable_latency.full = line_time.full - tolerable_latency.full;
  345. }
  346. /* We assume worst case 32bits (4 bytes) */
  347. wm->dbpp.full = rfixed_const(4 * 8);
  348. /* Determine the maximum priority mark
  349. * width = viewport width in pixels
  350. */
  351. a.full = rfixed_const(16);
  352. wm->priority_mark_max.full = rfixed_const(crtc->base.mode.crtc_hdisplay);
  353. wm->priority_mark_max.full = rfixed_div(wm->priority_mark_max, a);
  354. wm->priority_mark_max.full = rfixed_ceil(wm->priority_mark_max);
  355. /* Determine estimated width */
  356. estimated_width.full = tolerable_latency.full - wm->worst_case_latency.full;
  357. estimated_width.full = rfixed_div(estimated_width, consumption_time);
  358. if (rfixed_trunc(estimated_width) > crtc->base.mode.crtc_hdisplay) {
  359. wm->priority_mark.full = rfixed_const(10);
  360. } else {
  361. a.full = rfixed_const(16);
  362. wm->priority_mark.full = rfixed_div(estimated_width, a);
  363. wm->priority_mark.full = rfixed_ceil(wm->priority_mark);
  364. wm->priority_mark.full = wm->priority_mark_max.full - wm->priority_mark.full;
  365. }
  366. }
  367. void rs690_bandwidth_update(struct radeon_device *rdev)
  368. {
  369. struct drm_display_mode *mode0 = NULL;
  370. struct drm_display_mode *mode1 = NULL;
  371. struct rs690_watermark wm0;
  372. struct rs690_watermark wm1;
  373. u32 tmp;
  374. fixed20_12 priority_mark02, priority_mark12, fill_rate;
  375. fixed20_12 a, b;
  376. if (rdev->mode_info.crtcs[0]->base.enabled)
  377. mode0 = &rdev->mode_info.crtcs[0]->base.mode;
  378. if (rdev->mode_info.crtcs[1]->base.enabled)
  379. mode1 = &rdev->mode_info.crtcs[1]->base.mode;
  380. /*
  381. * Set display0/1 priority up in the memory controller for
  382. * modes if the user specifies HIGH for displaypriority
  383. * option.
  384. */
  385. if (rdev->disp_priority == 2) {
  386. tmp = RREG32_MC(R_000104_MC_INIT_MISC_LAT_TIMER);
  387. tmp &= C_000104_MC_DISP0R_INIT_LAT;
  388. tmp &= C_000104_MC_DISP1R_INIT_LAT;
  389. if (mode0)
  390. tmp |= S_000104_MC_DISP0R_INIT_LAT(1);
  391. if (mode1)
  392. tmp |= S_000104_MC_DISP1R_INIT_LAT(1);
  393. WREG32_MC(R_000104_MC_INIT_MISC_LAT_TIMER, tmp);
  394. }
  395. rs690_line_buffer_adjust(rdev, mode0, mode1);
  396. if ((rdev->family == CHIP_RS690) || (rdev->family == CHIP_RS740))
  397. WREG32(R_006C9C_DCP_CONTROL, 0);
  398. if ((rdev->family == CHIP_RS780) || (rdev->family == CHIP_RS880))
  399. WREG32(R_006C9C_DCP_CONTROL, 2);
  400. rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[0], &wm0);
  401. rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[1], &wm1);
  402. tmp = (wm0.lb_request_fifo_depth - 1);
  403. tmp |= (wm1.lb_request_fifo_depth - 1) << 16;
  404. WREG32(R_006D58_LB_MAX_REQ_OUTSTANDING, tmp);
  405. if (mode0 && mode1) {
  406. if (rfixed_trunc(wm0.dbpp) > 64)
  407. a.full = rfixed_mul(wm0.dbpp, wm0.num_line_pair);
  408. else
  409. a.full = wm0.num_line_pair.full;
  410. if (rfixed_trunc(wm1.dbpp) > 64)
  411. b.full = rfixed_mul(wm1.dbpp, wm1.num_line_pair);
  412. else
  413. b.full = wm1.num_line_pair.full;
  414. a.full += b.full;
  415. fill_rate.full = rfixed_div(wm0.sclk, a);
  416. if (wm0.consumption_rate.full > fill_rate.full) {
  417. b.full = wm0.consumption_rate.full - fill_rate.full;
  418. b.full = rfixed_mul(b, wm0.active_time);
  419. a.full = rfixed_mul(wm0.worst_case_latency,
  420. wm0.consumption_rate);
  421. a.full = a.full + b.full;
  422. b.full = rfixed_const(16 * 1000);
  423. priority_mark02.full = rfixed_div(a, b);
  424. } else {
  425. a.full = rfixed_mul(wm0.worst_case_latency,
  426. wm0.consumption_rate);
  427. b.full = rfixed_const(16 * 1000);
  428. priority_mark02.full = rfixed_div(a, b);
  429. }
  430. if (wm1.consumption_rate.full > fill_rate.full) {
  431. b.full = wm1.consumption_rate.full - fill_rate.full;
  432. b.full = rfixed_mul(b, wm1.active_time);
  433. a.full = rfixed_mul(wm1.worst_case_latency,
  434. wm1.consumption_rate);
  435. a.full = a.full + b.full;
  436. b.full = rfixed_const(16 * 1000);
  437. priority_mark12.full = rfixed_div(a, b);
  438. } else {
  439. a.full = rfixed_mul(wm1.worst_case_latency,
  440. wm1.consumption_rate);
  441. b.full = rfixed_const(16 * 1000);
  442. priority_mark12.full = rfixed_div(a, b);
  443. }
  444. if (wm0.priority_mark.full > priority_mark02.full)
  445. priority_mark02.full = wm0.priority_mark.full;
  446. if (rfixed_trunc(priority_mark02) < 0)
  447. priority_mark02.full = 0;
  448. if (wm0.priority_mark_max.full > priority_mark02.full)
  449. priority_mark02.full = wm0.priority_mark_max.full;
  450. if (wm1.priority_mark.full > priority_mark12.full)
  451. priority_mark12.full = wm1.priority_mark.full;
  452. if (rfixed_trunc(priority_mark12) < 0)
  453. priority_mark12.full = 0;
  454. if (wm1.priority_mark_max.full > priority_mark12.full)
  455. priority_mark12.full = wm1.priority_mark_max.full;
  456. WREG32(R_006548_D1MODE_PRIORITY_A_CNT, rfixed_trunc(priority_mark02));
  457. WREG32(R_00654C_D1MODE_PRIORITY_B_CNT, rfixed_trunc(priority_mark02));
  458. WREG32(R_006D48_D2MODE_PRIORITY_A_CNT, rfixed_trunc(priority_mark12));
  459. WREG32(R_006D4C_D2MODE_PRIORITY_B_CNT, rfixed_trunc(priority_mark12));
  460. } else if (mode0) {
  461. if (rfixed_trunc(wm0.dbpp) > 64)
  462. a.full = rfixed_mul(wm0.dbpp, wm0.num_line_pair);
  463. else
  464. a.full = wm0.num_line_pair.full;
  465. fill_rate.full = rfixed_div(wm0.sclk, a);
  466. if (wm0.consumption_rate.full > fill_rate.full) {
  467. b.full = wm0.consumption_rate.full - fill_rate.full;
  468. b.full = rfixed_mul(b, wm0.active_time);
  469. a.full = rfixed_mul(wm0.worst_case_latency,
  470. wm0.consumption_rate);
  471. a.full = a.full + b.full;
  472. b.full = rfixed_const(16 * 1000);
  473. priority_mark02.full = rfixed_div(a, b);
  474. } else {
  475. a.full = rfixed_mul(wm0.worst_case_latency,
  476. wm0.consumption_rate);
  477. b.full = rfixed_const(16 * 1000);
  478. priority_mark02.full = rfixed_div(a, b);
  479. }
  480. if (wm0.priority_mark.full > priority_mark02.full)
  481. priority_mark02.full = wm0.priority_mark.full;
  482. if (rfixed_trunc(priority_mark02) < 0)
  483. priority_mark02.full = 0;
  484. if (wm0.priority_mark_max.full > priority_mark02.full)
  485. priority_mark02.full = wm0.priority_mark_max.full;
  486. WREG32(R_006548_D1MODE_PRIORITY_A_CNT, rfixed_trunc(priority_mark02));
  487. WREG32(R_00654C_D1MODE_PRIORITY_B_CNT, rfixed_trunc(priority_mark02));
  488. WREG32(R_006D48_D2MODE_PRIORITY_A_CNT,
  489. S_006D48_D2MODE_PRIORITY_A_OFF(1));
  490. WREG32(R_006D4C_D2MODE_PRIORITY_B_CNT,
  491. S_006D4C_D2MODE_PRIORITY_B_OFF(1));
  492. } else {
  493. if (rfixed_trunc(wm1.dbpp) > 64)
  494. a.full = rfixed_mul(wm1.dbpp, wm1.num_line_pair);
  495. else
  496. a.full = wm1.num_line_pair.full;
  497. fill_rate.full = rfixed_div(wm1.sclk, a);
  498. if (wm1.consumption_rate.full > fill_rate.full) {
  499. b.full = wm1.consumption_rate.full - fill_rate.full;
  500. b.full = rfixed_mul(b, wm1.active_time);
  501. a.full = rfixed_mul(wm1.worst_case_latency,
  502. wm1.consumption_rate);
  503. a.full = a.full + b.full;
  504. b.full = rfixed_const(16 * 1000);
  505. priority_mark12.full = rfixed_div(a, b);
  506. } else {
  507. a.full = rfixed_mul(wm1.worst_case_latency,
  508. wm1.consumption_rate);
  509. b.full = rfixed_const(16 * 1000);
  510. priority_mark12.full = rfixed_div(a, b);
  511. }
  512. if (wm1.priority_mark.full > priority_mark12.full)
  513. priority_mark12.full = wm1.priority_mark.full;
  514. if (rfixed_trunc(priority_mark12) < 0)
  515. priority_mark12.full = 0;
  516. if (wm1.priority_mark_max.full > priority_mark12.full)
  517. priority_mark12.full = wm1.priority_mark_max.full;
  518. WREG32(R_006548_D1MODE_PRIORITY_A_CNT,
  519. S_006548_D1MODE_PRIORITY_A_OFF(1));
  520. WREG32(R_00654C_D1MODE_PRIORITY_B_CNT,
  521. S_00654C_D1MODE_PRIORITY_B_OFF(1));
  522. WREG32(R_006D48_D2MODE_PRIORITY_A_CNT, rfixed_trunc(priority_mark12));
  523. WREG32(R_006D4C_D2MODE_PRIORITY_B_CNT, rfixed_trunc(priority_mark12));
  524. }
  525. }
  526. uint32_t rs690_mc_rreg(struct radeon_device *rdev, uint32_t reg)
  527. {
  528. uint32_t r;
  529. WREG32(R_000078_MC_INDEX, S_000078_MC_IND_ADDR(reg));
  530. r = RREG32(R_00007C_MC_DATA);
  531. WREG32(R_000078_MC_INDEX, ~C_000078_MC_IND_ADDR);
  532. return r;
  533. }
  534. void rs690_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  535. {
  536. WREG32(R_000078_MC_INDEX, S_000078_MC_IND_ADDR(reg) |
  537. S_000078_MC_IND_WR_EN(1));
  538. WREG32(R_00007C_MC_DATA, v);
  539. WREG32(R_000078_MC_INDEX, 0x7F);
  540. }
  541. void rs690_mc_program(struct radeon_device *rdev)
  542. {
  543. struct rv515_mc_save save;
  544. /* Stops all mc clients */
  545. rv515_mc_stop(rdev, &save);
  546. /* Wait for mc idle */
  547. if (rs690_mc_wait_for_idle(rdev))
  548. dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
  549. /* Program MC, should be a 32bits limited address space */
  550. WREG32_MC(R_000100_MCCFG_FB_LOCATION,
  551. S_000100_MC_FB_START(rdev->mc.vram_start >> 16) |
  552. S_000100_MC_FB_TOP(rdev->mc.vram_end >> 16));
  553. WREG32(R_000134_HDP_FB_LOCATION,
  554. S_000134_HDP_FB_START(rdev->mc.vram_start >> 16));
  555. rv515_mc_resume(rdev, &save);
  556. }
  557. static int rs690_startup(struct radeon_device *rdev)
  558. {
  559. int r;
  560. rs690_mc_program(rdev);
  561. /* Resume clock */
  562. rv515_clock_startup(rdev);
  563. /* Initialize GPU configuration (# pipes, ...) */
  564. rs690_gpu_init(rdev);
  565. /* Initialize GART (initialize after TTM so we can allocate
  566. * memory through TTM but finalize after TTM) */
  567. r = rs400_gart_enable(rdev);
  568. if (r)
  569. return r;
  570. /* Enable IRQ */
  571. rs600_irq_set(rdev);
  572. rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
  573. /* 1M ring buffer */
  574. r = r100_cp_init(rdev, 1024 * 1024);
  575. if (r) {
  576. dev_err(rdev->dev, "failled initializing CP (%d).\n", r);
  577. return r;
  578. }
  579. r = r100_wb_init(rdev);
  580. if (r)
  581. dev_err(rdev->dev, "failled initializing WB (%d).\n", r);
  582. r = r100_ib_init(rdev);
  583. if (r) {
  584. dev_err(rdev->dev, "failled initializing IB (%d).\n", r);
  585. return r;
  586. }
  587. return 0;
  588. }
  589. int rs690_resume(struct radeon_device *rdev)
  590. {
  591. /* Make sur GART are not working */
  592. rs400_gart_disable(rdev);
  593. /* Resume clock before doing reset */
  594. rv515_clock_startup(rdev);
  595. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  596. if (radeon_gpu_reset(rdev)) {
  597. dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  598. RREG32(R_000E40_RBBM_STATUS),
  599. RREG32(R_0007C0_CP_STAT));
  600. }
  601. /* post */
  602. atom_asic_init(rdev->mode_info.atom_context);
  603. /* Resume clock after posting */
  604. rv515_clock_startup(rdev);
  605. /* Initialize surface registers */
  606. radeon_surface_init(rdev);
  607. return rs690_startup(rdev);
  608. }
  609. int rs690_suspend(struct radeon_device *rdev)
  610. {
  611. r100_cp_disable(rdev);
  612. r100_wb_disable(rdev);
  613. rs600_irq_disable(rdev);
  614. rs400_gart_disable(rdev);
  615. return 0;
  616. }
  617. void rs690_fini(struct radeon_device *rdev)
  618. {
  619. radeon_pm_fini(rdev);
  620. r100_cp_fini(rdev);
  621. r100_wb_fini(rdev);
  622. r100_ib_fini(rdev);
  623. radeon_gem_fini(rdev);
  624. rs400_gart_fini(rdev);
  625. radeon_irq_kms_fini(rdev);
  626. radeon_fence_driver_fini(rdev);
  627. radeon_bo_fini(rdev);
  628. radeon_atombios_fini(rdev);
  629. kfree(rdev->bios);
  630. rdev->bios = NULL;
  631. }
  632. int rs690_init(struct radeon_device *rdev)
  633. {
  634. int r;
  635. /* Disable VGA */
  636. rv515_vga_render_disable(rdev);
  637. /* Initialize scratch registers */
  638. radeon_scratch_init(rdev);
  639. /* Initialize surface registers */
  640. radeon_surface_init(rdev);
  641. /* TODO: disable VGA need to use VGA request */
  642. /* BIOS*/
  643. if (!radeon_get_bios(rdev)) {
  644. if (ASIC_IS_AVIVO(rdev))
  645. return -EINVAL;
  646. }
  647. if (rdev->is_atom_bios) {
  648. r = radeon_atombios_init(rdev);
  649. if (r)
  650. return r;
  651. } else {
  652. dev_err(rdev->dev, "Expecting atombios for RV515 GPU\n");
  653. return -EINVAL;
  654. }
  655. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  656. if (radeon_gpu_reset(rdev)) {
  657. dev_warn(rdev->dev,
  658. "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  659. RREG32(R_000E40_RBBM_STATUS),
  660. RREG32(R_0007C0_CP_STAT));
  661. }
  662. /* check if cards are posted or not */
  663. if (radeon_boot_test_post_card(rdev) == false)
  664. return -EINVAL;
  665. /* Initialize clocks */
  666. radeon_get_clock_info(rdev->ddev);
  667. /* Initialize power management */
  668. radeon_pm_init(rdev);
  669. /* initialize memory controller */
  670. rs690_mc_init(rdev);
  671. rv515_debugfs(rdev);
  672. /* Fence driver */
  673. r = radeon_fence_driver_init(rdev);
  674. if (r)
  675. return r;
  676. r = radeon_irq_kms_init(rdev);
  677. if (r)
  678. return r;
  679. /* Memory manager */
  680. r = radeon_bo_init(rdev);
  681. if (r)
  682. return r;
  683. r = rs400_gart_init(rdev);
  684. if (r)
  685. return r;
  686. rs600_set_safe_registers(rdev);
  687. rdev->accel_working = true;
  688. r = rs690_startup(rdev);
  689. if (r) {
  690. /* Somethings want wront with the accel init stop accel */
  691. dev_err(rdev->dev, "Disabling GPU acceleration\n");
  692. r100_cp_fini(rdev);
  693. r100_wb_fini(rdev);
  694. r100_ib_fini(rdev);
  695. rs400_gart_fini(rdev);
  696. radeon_irq_kms_fini(rdev);
  697. rdev->accel_working = false;
  698. }
  699. return 0;
  700. }