rs690.c 26 KB

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