rs690.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  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 <drm/drmP.h>
  29. #include "radeon.h"
  30. #include "radeon_asic.h"
  31. #include "radeon_audio.h"
  32. #include "atom.h"
  33. #include "rs690d.h"
  34. int rs690_mc_wait_for_idle(struct radeon_device *rdev)
  35. {
  36. unsigned i;
  37. uint32_t tmp;
  38. for (i = 0; i < rdev->usec_timeout; i++) {
  39. /* read MC_STATUS */
  40. tmp = RREG32_MC(R_000090_MC_SYSTEM_STATUS);
  41. if (G_000090_MC_SYSTEM_IDLE(tmp))
  42. return 0;
  43. udelay(1);
  44. }
  45. return -1;
  46. }
  47. static void rs690_gpu_init(struct radeon_device *rdev)
  48. {
  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. union igp_info {
  57. struct _ATOM_INTEGRATED_SYSTEM_INFO info;
  58. struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_v2;
  59. };
  60. void rs690_pm_info(struct radeon_device *rdev)
  61. {
  62. int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
  63. union igp_info *info;
  64. uint16_t data_offset;
  65. uint8_t frev, crev;
  66. fixed20_12 tmp;
  67. if (atom_parse_data_header(rdev->mode_info.atom_context, index, NULL,
  68. &frev, &crev, &data_offset)) {
  69. info = (union igp_info *)(rdev->mode_info.atom_context->bios + data_offset);
  70. /* Get various system informations from bios */
  71. switch (crev) {
  72. case 1:
  73. tmp.full = dfixed_const(100);
  74. rdev->pm.igp_sideport_mclk.full = dfixed_const(le32_to_cpu(info->info.ulBootUpMemoryClock));
  75. rdev->pm.igp_sideport_mclk.full = dfixed_div(rdev->pm.igp_sideport_mclk, tmp);
  76. if (le16_to_cpu(info->info.usK8MemoryClock))
  77. rdev->pm.igp_system_mclk.full = dfixed_const(le16_to_cpu(info->info.usK8MemoryClock));
  78. else if (rdev->clock.default_mclk) {
  79. rdev->pm.igp_system_mclk.full = dfixed_const(rdev->clock.default_mclk);
  80. rdev->pm.igp_system_mclk.full = dfixed_div(rdev->pm.igp_system_mclk, tmp);
  81. } else
  82. rdev->pm.igp_system_mclk.full = dfixed_const(400);
  83. rdev->pm.igp_ht_link_clk.full = dfixed_const(le16_to_cpu(info->info.usFSBClock));
  84. rdev->pm.igp_ht_link_width.full = dfixed_const(info->info.ucHTLinkWidth);
  85. break;
  86. case 2:
  87. tmp.full = dfixed_const(100);
  88. rdev->pm.igp_sideport_mclk.full = dfixed_const(le32_to_cpu(info->info_v2.ulBootUpSidePortClock));
  89. rdev->pm.igp_sideport_mclk.full = dfixed_div(rdev->pm.igp_sideport_mclk, tmp);
  90. if (le32_to_cpu(info->info_v2.ulBootUpUMAClock))
  91. rdev->pm.igp_system_mclk.full = dfixed_const(le32_to_cpu(info->info_v2.ulBootUpUMAClock));
  92. else if (rdev->clock.default_mclk)
  93. rdev->pm.igp_system_mclk.full = dfixed_const(rdev->clock.default_mclk);
  94. else
  95. rdev->pm.igp_system_mclk.full = dfixed_const(66700);
  96. rdev->pm.igp_system_mclk.full = dfixed_div(rdev->pm.igp_system_mclk, tmp);
  97. rdev->pm.igp_ht_link_clk.full = dfixed_const(le32_to_cpu(info->info_v2.ulHTLinkFreq));
  98. rdev->pm.igp_ht_link_clk.full = dfixed_div(rdev->pm.igp_ht_link_clk, tmp);
  99. rdev->pm.igp_ht_link_width.full = dfixed_const(le16_to_cpu(info->info_v2.usMinHTLinkWidth));
  100. break;
  101. default:
  102. /* We assume the slower possible clock ie worst case */
  103. rdev->pm.igp_sideport_mclk.full = dfixed_const(200);
  104. rdev->pm.igp_system_mclk.full = dfixed_const(200);
  105. rdev->pm.igp_ht_link_clk.full = dfixed_const(1000);
  106. rdev->pm.igp_ht_link_width.full = dfixed_const(8);
  107. DRM_ERROR("No integrated system info for your GPU, using safe default\n");
  108. break;
  109. }
  110. } else {
  111. /* We assume the slower possible clock ie worst case */
  112. rdev->pm.igp_sideport_mclk.full = dfixed_const(200);
  113. rdev->pm.igp_system_mclk.full = dfixed_const(200);
  114. rdev->pm.igp_ht_link_clk.full = dfixed_const(1000);
  115. rdev->pm.igp_ht_link_width.full = dfixed_const(8);
  116. DRM_ERROR("No integrated system info for your GPU, using safe default\n");
  117. }
  118. /* Compute various bandwidth */
  119. /* k8_bandwidth = (memory_clk / 2) * 2 * 8 * 0.5 = memory_clk * 4 */
  120. tmp.full = dfixed_const(4);
  121. rdev->pm.k8_bandwidth.full = dfixed_mul(rdev->pm.igp_system_mclk, tmp);
  122. /* ht_bandwidth = ht_clk * 2 * ht_width / 8 * 0.8
  123. * = ht_clk * ht_width / 5
  124. */
  125. tmp.full = dfixed_const(5);
  126. rdev->pm.ht_bandwidth.full = dfixed_mul(rdev->pm.igp_ht_link_clk,
  127. rdev->pm.igp_ht_link_width);
  128. rdev->pm.ht_bandwidth.full = dfixed_div(rdev->pm.ht_bandwidth, tmp);
  129. if (tmp.full < rdev->pm.max_bandwidth.full) {
  130. /* HT link is a limiting factor */
  131. rdev->pm.max_bandwidth.full = tmp.full;
  132. }
  133. /* sideport_bandwidth = (sideport_clk / 2) * 2 * 2 * 0.7
  134. * = (sideport_clk * 14) / 10
  135. */
  136. tmp.full = dfixed_const(14);
  137. rdev->pm.sideport_bandwidth.full = dfixed_mul(rdev->pm.igp_sideport_mclk, tmp);
  138. tmp.full = dfixed_const(10);
  139. rdev->pm.sideport_bandwidth.full = dfixed_div(rdev->pm.sideport_bandwidth, tmp);
  140. }
  141. static void rs690_mc_init(struct radeon_device *rdev)
  142. {
  143. u64 base;
  144. uint32_t h_addr, l_addr;
  145. unsigned long long k8_addr;
  146. rs400_gart_adjust_size(rdev);
  147. rdev->mc.vram_is_ddr = true;
  148. rdev->mc.vram_width = 128;
  149. rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
  150. rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
  151. rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
  152. rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
  153. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  154. base = RREG32_MC(R_000100_MCCFG_FB_LOCATION);
  155. base = G_000100_MC_FB_START(base) << 16;
  156. rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
  157. /* Some boards seem to be configured for 128MB of sideport memory,
  158. * but really only have 64MB. Just skip the sideport and use
  159. * UMA memory.
  160. */
  161. if (rdev->mc.igp_sideport_enabled &&
  162. (rdev->mc.real_vram_size == (384 * 1024 * 1024))) {
  163. base += 128 * 1024 * 1024;
  164. rdev->mc.real_vram_size -= 128 * 1024 * 1024;
  165. rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
  166. }
  167. /* Use K8 direct mapping for fast fb access. */
  168. rdev->fastfb_working = false;
  169. h_addr = G_00005F_K8_ADDR_EXT(RREG32_MC(R_00005F_MC_MISC_UMA_CNTL));
  170. l_addr = RREG32_MC(R_00001E_K8_FB_LOCATION);
  171. k8_addr = ((unsigned long long)h_addr) << 32 | l_addr;
  172. #if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
  173. if (k8_addr + rdev->mc.visible_vram_size < 0x100000000ULL)
  174. #endif
  175. {
  176. /* FastFB shall be used with UMA memory. Here it is simply disabled when sideport
  177. * memory is present.
  178. */
  179. if (rdev->mc.igp_sideport_enabled == false && radeon_fastfb == 1) {
  180. DRM_INFO("Direct mapping: aper base at 0x%llx, replaced by direct mapping base 0x%llx.\n",
  181. (unsigned long long)rdev->mc.aper_base, k8_addr);
  182. rdev->mc.aper_base = (resource_size_t)k8_addr;
  183. rdev->fastfb_working = true;
  184. }
  185. }
  186. rs690_pm_info(rdev);
  187. radeon_vram_location(rdev, &rdev->mc, base);
  188. rdev->mc.gtt_base_align = rdev->mc.gtt_size - 1;
  189. radeon_gtt_location(rdev, &rdev->mc);
  190. radeon_update_bandwidth_info(rdev);
  191. }
  192. void rs690_line_buffer_adjust(struct radeon_device *rdev,
  193. struct drm_display_mode *mode1,
  194. struct drm_display_mode *mode2)
  195. {
  196. u32 tmp;
  197. /* Guess line buffer size to be 8192 pixels */
  198. u32 lb_size = 8192;
  199. /*
  200. * Line Buffer Setup
  201. * There is a single line buffer shared by both display controllers.
  202. * R_006520_DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
  203. * the display controllers. The paritioning can either be done
  204. * manually or via one of four preset allocations specified in bits 1:0:
  205. * 0 - line buffer is divided in half and shared between crtc
  206. * 1 - D1 gets 3/4 of the line buffer, D2 gets 1/4
  207. * 2 - D1 gets the whole buffer
  208. * 3 - D1 gets 1/4 of the line buffer, D2 gets 3/4
  209. * Setting bit 2 of R_006520_DC_LB_MEMORY_SPLIT controls switches to manual
  210. * allocation mode. In manual allocation mode, D1 always starts at 0,
  211. * D1 end/2 is specified in bits 14:4; D2 allocation follows D1.
  212. */
  213. tmp = RREG32(R_006520_DC_LB_MEMORY_SPLIT) & C_006520_DC_LB_MEMORY_SPLIT;
  214. tmp &= ~C_006520_DC_LB_MEMORY_SPLIT_MODE;
  215. /* auto */
  216. if (mode1 && mode2) {
  217. if (mode1->hdisplay > mode2->hdisplay) {
  218. if (mode1->hdisplay > 2560)
  219. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_3Q_D2_1Q;
  220. else
  221. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
  222. } else if (mode2->hdisplay > mode1->hdisplay) {
  223. if (mode2->hdisplay > 2560)
  224. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_1Q_D2_3Q;
  225. else
  226. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
  227. } else
  228. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
  229. } else if (mode1) {
  230. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_ONLY;
  231. } else if (mode2) {
  232. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_1Q_D2_3Q;
  233. }
  234. WREG32(R_006520_DC_LB_MEMORY_SPLIT, tmp);
  235. /* Save number of lines the linebuffer leads before the scanout */
  236. if (mode1)
  237. rdev->mode_info.crtcs[0]->lb_vblank_lead_lines = DIV_ROUND_UP(lb_size, mode1->crtc_hdisplay);
  238. if (mode2)
  239. rdev->mode_info.crtcs[1]->lb_vblank_lead_lines = DIV_ROUND_UP(lb_size, mode2->crtc_hdisplay);
  240. }
  241. struct rs690_watermark {
  242. u32 lb_request_fifo_depth;
  243. fixed20_12 num_line_pair;
  244. fixed20_12 estimated_width;
  245. fixed20_12 worst_case_latency;
  246. fixed20_12 consumption_rate;
  247. fixed20_12 active_time;
  248. fixed20_12 dbpp;
  249. fixed20_12 priority_mark_max;
  250. fixed20_12 priority_mark;
  251. fixed20_12 sclk;
  252. };
  253. static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
  254. struct radeon_crtc *crtc,
  255. struct rs690_watermark *wm,
  256. bool low)
  257. {
  258. struct drm_display_mode *mode = &crtc->base.mode;
  259. fixed20_12 a, b, c;
  260. fixed20_12 pclk, request_fifo_depth, tolerable_latency, estimated_width;
  261. fixed20_12 consumption_time, line_time, chunk_time, read_delay_latency;
  262. fixed20_12 sclk, core_bandwidth, max_bandwidth;
  263. u32 selected_sclk;
  264. if (!crtc->base.enabled) {
  265. /* FIXME: wouldn't it better to set priority mark to maximum */
  266. wm->lb_request_fifo_depth = 4;
  267. return;
  268. }
  269. if (((rdev->family == CHIP_RS780) || (rdev->family == CHIP_RS880)) &&
  270. (rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled)
  271. selected_sclk = radeon_dpm_get_sclk(rdev, low);
  272. else
  273. selected_sclk = rdev->pm.current_sclk;
  274. /* sclk in Mhz */
  275. a.full = dfixed_const(100);
  276. sclk.full = dfixed_const(selected_sclk);
  277. sclk.full = dfixed_div(sclk, a);
  278. /* core_bandwidth = sclk(Mhz) * 16 */
  279. a.full = dfixed_const(16);
  280. core_bandwidth.full = dfixed_div(rdev->pm.sclk, a);
  281. if (crtc->vsc.full > dfixed_const(2))
  282. wm->num_line_pair.full = dfixed_const(2);
  283. else
  284. wm->num_line_pair.full = dfixed_const(1);
  285. b.full = dfixed_const(mode->crtc_hdisplay);
  286. c.full = dfixed_const(256);
  287. a.full = dfixed_div(b, c);
  288. request_fifo_depth.full = dfixed_mul(a, wm->num_line_pair);
  289. request_fifo_depth.full = dfixed_ceil(request_fifo_depth);
  290. if (a.full < dfixed_const(4)) {
  291. wm->lb_request_fifo_depth = 4;
  292. } else {
  293. wm->lb_request_fifo_depth = dfixed_trunc(request_fifo_depth);
  294. }
  295. /* Determine consumption rate
  296. * pclk = pixel clock period(ns) = 1000 / (mode.clock / 1000)
  297. * vtaps = number of vertical taps,
  298. * vsc = vertical scaling ratio, defined as source/destination
  299. * hsc = horizontal scaling ration, defined as source/destination
  300. */
  301. a.full = dfixed_const(mode->clock);
  302. b.full = dfixed_const(1000);
  303. a.full = dfixed_div(a, b);
  304. pclk.full = dfixed_div(b, a);
  305. if (crtc->rmx_type != RMX_OFF) {
  306. b.full = dfixed_const(2);
  307. if (crtc->vsc.full > b.full)
  308. b.full = crtc->vsc.full;
  309. b.full = dfixed_mul(b, crtc->hsc);
  310. c.full = dfixed_const(2);
  311. b.full = dfixed_div(b, c);
  312. consumption_time.full = dfixed_div(pclk, b);
  313. } else {
  314. consumption_time.full = pclk.full;
  315. }
  316. a.full = dfixed_const(1);
  317. wm->consumption_rate.full = dfixed_div(a, consumption_time);
  318. /* Determine line time
  319. * LineTime = total time for one line of displayhtotal
  320. * LineTime = total number of horizontal pixels
  321. * pclk = pixel clock period(ns)
  322. */
  323. a.full = dfixed_const(crtc->base.mode.crtc_htotal);
  324. line_time.full = dfixed_mul(a, pclk);
  325. /* Determine active time
  326. * ActiveTime = time of active region of display within one line,
  327. * hactive = total number of horizontal active pixels
  328. * htotal = total number of horizontal pixels
  329. */
  330. a.full = dfixed_const(crtc->base.mode.crtc_htotal);
  331. b.full = dfixed_const(crtc->base.mode.crtc_hdisplay);
  332. wm->active_time.full = dfixed_mul(line_time, b);
  333. wm->active_time.full = dfixed_div(wm->active_time, a);
  334. /* Maximun bandwidth is the minimun bandwidth of all component */
  335. max_bandwidth = core_bandwidth;
  336. if (rdev->mc.igp_sideport_enabled) {
  337. if (max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
  338. rdev->pm.sideport_bandwidth.full)
  339. max_bandwidth = rdev->pm.sideport_bandwidth;
  340. read_delay_latency.full = dfixed_const(370 * 800);
  341. a.full = dfixed_const(1000);
  342. b.full = dfixed_div(rdev->pm.igp_sideport_mclk, a);
  343. read_delay_latency.full = dfixed_div(read_delay_latency, b);
  344. read_delay_latency.full = dfixed_mul(read_delay_latency, a);
  345. } else {
  346. if (max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
  347. rdev->pm.k8_bandwidth.full)
  348. max_bandwidth = rdev->pm.k8_bandwidth;
  349. if (max_bandwidth.full > rdev->pm.ht_bandwidth.full &&
  350. rdev->pm.ht_bandwidth.full)
  351. max_bandwidth = rdev->pm.ht_bandwidth;
  352. read_delay_latency.full = dfixed_const(5000);
  353. }
  354. /* sclk = system clocks(ns) = 1000 / max_bandwidth / 16 */
  355. a.full = dfixed_const(16);
  356. sclk.full = dfixed_mul(max_bandwidth, a);
  357. a.full = dfixed_const(1000);
  358. sclk.full = dfixed_div(a, sclk);
  359. /* Determine chunk time
  360. * ChunkTime = the time it takes the DCP to send one chunk of data
  361. * to the LB which consists of pipeline delay and inter chunk gap
  362. * sclk = system clock(ns)
  363. */
  364. a.full = dfixed_const(256 * 13);
  365. chunk_time.full = dfixed_mul(sclk, a);
  366. a.full = dfixed_const(10);
  367. chunk_time.full = dfixed_div(chunk_time, a);
  368. /* Determine the worst case latency
  369. * NumLinePair = Number of line pairs to request(1=2 lines, 2=4 lines)
  370. * WorstCaseLatency = worst case time from urgent to when the MC starts
  371. * to return data
  372. * READ_DELAY_IDLE_MAX = constant of 1us
  373. * ChunkTime = time it takes the DCP to send one chunk of data to the LB
  374. * which consists of pipeline delay and inter chunk gap
  375. */
  376. if (dfixed_trunc(wm->num_line_pair) > 1) {
  377. a.full = dfixed_const(3);
  378. wm->worst_case_latency.full = dfixed_mul(a, chunk_time);
  379. wm->worst_case_latency.full += read_delay_latency.full;
  380. } else {
  381. a.full = dfixed_const(2);
  382. wm->worst_case_latency.full = dfixed_mul(a, chunk_time);
  383. wm->worst_case_latency.full += read_delay_latency.full;
  384. }
  385. /* Determine the tolerable latency
  386. * TolerableLatency = Any given request has only 1 line time
  387. * for the data to be returned
  388. * LBRequestFifoDepth = Number of chunk requests the LB can
  389. * put into the request FIFO for a display
  390. * LineTime = total time for one line of display
  391. * ChunkTime = the time it takes the DCP to send one chunk
  392. * of data to the LB which consists of
  393. * pipeline delay and inter chunk gap
  394. */
  395. if ((2+wm->lb_request_fifo_depth) >= dfixed_trunc(request_fifo_depth)) {
  396. tolerable_latency.full = line_time.full;
  397. } else {
  398. tolerable_latency.full = dfixed_const(wm->lb_request_fifo_depth - 2);
  399. tolerable_latency.full = request_fifo_depth.full - tolerable_latency.full;
  400. tolerable_latency.full = dfixed_mul(tolerable_latency, chunk_time);
  401. tolerable_latency.full = line_time.full - tolerable_latency.full;
  402. }
  403. /* We assume worst case 32bits (4 bytes) */
  404. wm->dbpp.full = dfixed_const(4 * 8);
  405. /* Determine the maximum priority mark
  406. * width = viewport width in pixels
  407. */
  408. a.full = dfixed_const(16);
  409. wm->priority_mark_max.full = dfixed_const(crtc->base.mode.crtc_hdisplay);
  410. wm->priority_mark_max.full = dfixed_div(wm->priority_mark_max, a);
  411. wm->priority_mark_max.full = dfixed_ceil(wm->priority_mark_max);
  412. /* Determine estimated width */
  413. estimated_width.full = tolerable_latency.full - wm->worst_case_latency.full;
  414. estimated_width.full = dfixed_div(estimated_width, consumption_time);
  415. if (dfixed_trunc(estimated_width) > crtc->base.mode.crtc_hdisplay) {
  416. wm->priority_mark.full = dfixed_const(10);
  417. } else {
  418. a.full = dfixed_const(16);
  419. wm->priority_mark.full = dfixed_div(estimated_width, a);
  420. wm->priority_mark.full = dfixed_ceil(wm->priority_mark);
  421. wm->priority_mark.full = wm->priority_mark_max.full - wm->priority_mark.full;
  422. }
  423. }
  424. static void rs690_compute_mode_priority(struct radeon_device *rdev,
  425. struct rs690_watermark *wm0,
  426. struct rs690_watermark *wm1,
  427. struct drm_display_mode *mode0,
  428. struct drm_display_mode *mode1,
  429. u32 *d1mode_priority_a_cnt,
  430. u32 *d2mode_priority_a_cnt)
  431. {
  432. fixed20_12 priority_mark02, priority_mark12, fill_rate;
  433. fixed20_12 a, b;
  434. *d1mode_priority_a_cnt = S_006548_D1MODE_PRIORITY_A_OFF(1);
  435. *d2mode_priority_a_cnt = S_006548_D1MODE_PRIORITY_A_OFF(1);
  436. if (mode0 && mode1) {
  437. if (dfixed_trunc(wm0->dbpp) > 64)
  438. a.full = dfixed_mul(wm0->dbpp, wm0->num_line_pair);
  439. else
  440. a.full = wm0->num_line_pair.full;
  441. if (dfixed_trunc(wm1->dbpp) > 64)
  442. b.full = dfixed_mul(wm1->dbpp, wm1->num_line_pair);
  443. else
  444. b.full = wm1->num_line_pair.full;
  445. a.full += b.full;
  446. fill_rate.full = dfixed_div(wm0->sclk, a);
  447. if (wm0->consumption_rate.full > fill_rate.full) {
  448. b.full = wm0->consumption_rate.full - fill_rate.full;
  449. b.full = dfixed_mul(b, wm0->active_time);
  450. a.full = dfixed_mul(wm0->worst_case_latency,
  451. wm0->consumption_rate);
  452. a.full = a.full + b.full;
  453. b.full = dfixed_const(16 * 1000);
  454. priority_mark02.full = dfixed_div(a, b);
  455. } else {
  456. a.full = dfixed_mul(wm0->worst_case_latency,
  457. wm0->consumption_rate);
  458. b.full = dfixed_const(16 * 1000);
  459. priority_mark02.full = dfixed_div(a, b);
  460. }
  461. if (wm1->consumption_rate.full > fill_rate.full) {
  462. b.full = wm1->consumption_rate.full - fill_rate.full;
  463. b.full = dfixed_mul(b, wm1->active_time);
  464. a.full = dfixed_mul(wm1->worst_case_latency,
  465. wm1->consumption_rate);
  466. a.full = a.full + b.full;
  467. b.full = dfixed_const(16 * 1000);
  468. priority_mark12.full = dfixed_div(a, b);
  469. } else {
  470. a.full = dfixed_mul(wm1->worst_case_latency,
  471. wm1->consumption_rate);
  472. b.full = dfixed_const(16 * 1000);
  473. priority_mark12.full = dfixed_div(a, b);
  474. }
  475. if (wm0->priority_mark.full > priority_mark02.full)
  476. priority_mark02.full = wm0->priority_mark.full;
  477. if (wm0->priority_mark_max.full > priority_mark02.full)
  478. priority_mark02.full = wm0->priority_mark_max.full;
  479. if (wm1->priority_mark.full > priority_mark12.full)
  480. priority_mark12.full = wm1->priority_mark.full;
  481. if (wm1->priority_mark_max.full > priority_mark12.full)
  482. priority_mark12.full = wm1->priority_mark_max.full;
  483. *d1mode_priority_a_cnt = dfixed_trunc(priority_mark02);
  484. *d2mode_priority_a_cnt = dfixed_trunc(priority_mark12);
  485. if (rdev->disp_priority == 2) {
  486. *d1mode_priority_a_cnt |= S_006548_D1MODE_PRIORITY_A_ALWAYS_ON(1);
  487. *d2mode_priority_a_cnt |= S_006D48_D2MODE_PRIORITY_A_ALWAYS_ON(1);
  488. }
  489. } else if (mode0) {
  490. if (dfixed_trunc(wm0->dbpp) > 64)
  491. a.full = dfixed_mul(wm0->dbpp, wm0->num_line_pair);
  492. else
  493. a.full = wm0->num_line_pair.full;
  494. fill_rate.full = dfixed_div(wm0->sclk, a);
  495. if (wm0->consumption_rate.full > fill_rate.full) {
  496. b.full = wm0->consumption_rate.full - fill_rate.full;
  497. b.full = dfixed_mul(b, wm0->active_time);
  498. a.full = dfixed_mul(wm0->worst_case_latency,
  499. wm0->consumption_rate);
  500. a.full = a.full + b.full;
  501. b.full = dfixed_const(16 * 1000);
  502. priority_mark02.full = dfixed_div(a, b);
  503. } else {
  504. a.full = dfixed_mul(wm0->worst_case_latency,
  505. wm0->consumption_rate);
  506. b.full = dfixed_const(16 * 1000);
  507. priority_mark02.full = dfixed_div(a, b);
  508. }
  509. if (wm0->priority_mark.full > priority_mark02.full)
  510. priority_mark02.full = wm0->priority_mark.full;
  511. if (wm0->priority_mark_max.full > priority_mark02.full)
  512. priority_mark02.full = wm0->priority_mark_max.full;
  513. *d1mode_priority_a_cnt = dfixed_trunc(priority_mark02);
  514. if (rdev->disp_priority == 2)
  515. *d1mode_priority_a_cnt |= S_006548_D1MODE_PRIORITY_A_ALWAYS_ON(1);
  516. } else if (mode1) {
  517. if (dfixed_trunc(wm1->dbpp) > 64)
  518. a.full = dfixed_mul(wm1->dbpp, wm1->num_line_pair);
  519. else
  520. a.full = wm1->num_line_pair.full;
  521. fill_rate.full = dfixed_div(wm1->sclk, a);
  522. if (wm1->consumption_rate.full > fill_rate.full) {
  523. b.full = wm1->consumption_rate.full - fill_rate.full;
  524. b.full = dfixed_mul(b, wm1->active_time);
  525. a.full = dfixed_mul(wm1->worst_case_latency,
  526. wm1->consumption_rate);
  527. a.full = a.full + b.full;
  528. b.full = dfixed_const(16 * 1000);
  529. priority_mark12.full = dfixed_div(a, b);
  530. } else {
  531. a.full = dfixed_mul(wm1->worst_case_latency,
  532. wm1->consumption_rate);
  533. b.full = dfixed_const(16 * 1000);
  534. priority_mark12.full = dfixed_div(a, b);
  535. }
  536. if (wm1->priority_mark.full > priority_mark12.full)
  537. priority_mark12.full = wm1->priority_mark.full;
  538. if (wm1->priority_mark_max.full > priority_mark12.full)
  539. priority_mark12.full = wm1->priority_mark_max.full;
  540. *d2mode_priority_a_cnt = dfixed_trunc(priority_mark12);
  541. if (rdev->disp_priority == 2)
  542. *d2mode_priority_a_cnt |= S_006D48_D2MODE_PRIORITY_A_ALWAYS_ON(1);
  543. }
  544. }
  545. void rs690_bandwidth_update(struct radeon_device *rdev)
  546. {
  547. struct drm_display_mode *mode0 = NULL;
  548. struct drm_display_mode *mode1 = NULL;
  549. struct rs690_watermark wm0_high, wm0_low;
  550. struct rs690_watermark wm1_high, wm1_low;
  551. u32 tmp;
  552. u32 d1mode_priority_a_cnt, d1mode_priority_b_cnt;
  553. u32 d2mode_priority_a_cnt, d2mode_priority_b_cnt;
  554. if (!rdev->mode_info.mode_config_initialized)
  555. return;
  556. radeon_update_display_priority(rdev);
  557. if (rdev->mode_info.crtcs[0]->base.enabled)
  558. mode0 = &rdev->mode_info.crtcs[0]->base.mode;
  559. if (rdev->mode_info.crtcs[1]->base.enabled)
  560. mode1 = &rdev->mode_info.crtcs[1]->base.mode;
  561. /*
  562. * Set display0/1 priority up in the memory controller for
  563. * modes if the user specifies HIGH for displaypriority
  564. * option.
  565. */
  566. if ((rdev->disp_priority == 2) &&
  567. ((rdev->family == CHIP_RS690) || (rdev->family == CHIP_RS740))) {
  568. tmp = RREG32_MC(R_000104_MC_INIT_MISC_LAT_TIMER);
  569. tmp &= C_000104_MC_DISP0R_INIT_LAT;
  570. tmp &= C_000104_MC_DISP1R_INIT_LAT;
  571. if (mode0)
  572. tmp |= S_000104_MC_DISP0R_INIT_LAT(1);
  573. if (mode1)
  574. tmp |= S_000104_MC_DISP1R_INIT_LAT(1);
  575. WREG32_MC(R_000104_MC_INIT_MISC_LAT_TIMER, tmp);
  576. }
  577. rs690_line_buffer_adjust(rdev, mode0, mode1);
  578. if ((rdev->family == CHIP_RS690) || (rdev->family == CHIP_RS740))
  579. WREG32(R_006C9C_DCP_CONTROL, 0);
  580. if ((rdev->family == CHIP_RS780) || (rdev->family == CHIP_RS880))
  581. WREG32(R_006C9C_DCP_CONTROL, 2);
  582. rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[0], &wm0_high, false);
  583. rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[1], &wm1_high, false);
  584. rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[0], &wm0_low, true);
  585. rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[1], &wm1_low, true);
  586. tmp = (wm0_high.lb_request_fifo_depth - 1);
  587. tmp |= (wm1_high.lb_request_fifo_depth - 1) << 16;
  588. WREG32(R_006D58_LB_MAX_REQ_OUTSTANDING, tmp);
  589. rs690_compute_mode_priority(rdev,
  590. &wm0_high, &wm1_high,
  591. mode0, mode1,
  592. &d1mode_priority_a_cnt, &d2mode_priority_a_cnt);
  593. rs690_compute_mode_priority(rdev,
  594. &wm0_low, &wm1_low,
  595. mode0, mode1,
  596. &d1mode_priority_b_cnt, &d2mode_priority_b_cnt);
  597. WREG32(R_006548_D1MODE_PRIORITY_A_CNT, d1mode_priority_a_cnt);
  598. WREG32(R_00654C_D1MODE_PRIORITY_B_CNT, d1mode_priority_b_cnt);
  599. WREG32(R_006D48_D2MODE_PRIORITY_A_CNT, d2mode_priority_a_cnt);
  600. WREG32(R_006D4C_D2MODE_PRIORITY_B_CNT, d2mode_priority_b_cnt);
  601. }
  602. uint32_t rs690_mc_rreg(struct radeon_device *rdev, uint32_t reg)
  603. {
  604. unsigned long flags;
  605. uint32_t r;
  606. spin_lock_irqsave(&rdev->mc_idx_lock, flags);
  607. WREG32(R_000078_MC_INDEX, S_000078_MC_IND_ADDR(reg));
  608. r = RREG32(R_00007C_MC_DATA);
  609. WREG32(R_000078_MC_INDEX, ~C_000078_MC_IND_ADDR);
  610. spin_unlock_irqrestore(&rdev->mc_idx_lock, flags);
  611. return r;
  612. }
  613. void rs690_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  614. {
  615. unsigned long flags;
  616. spin_lock_irqsave(&rdev->mc_idx_lock, flags);
  617. WREG32(R_000078_MC_INDEX, S_000078_MC_IND_ADDR(reg) |
  618. S_000078_MC_IND_WR_EN(1));
  619. WREG32(R_00007C_MC_DATA, v);
  620. WREG32(R_000078_MC_INDEX, 0x7F);
  621. spin_unlock_irqrestore(&rdev->mc_idx_lock, flags);
  622. }
  623. static void rs690_mc_program(struct radeon_device *rdev)
  624. {
  625. struct rv515_mc_save save;
  626. /* Stops all mc clients */
  627. rv515_mc_stop(rdev, &save);
  628. /* Wait for mc idle */
  629. if (rs690_mc_wait_for_idle(rdev))
  630. dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
  631. /* Program MC, should be a 32bits limited address space */
  632. WREG32_MC(R_000100_MCCFG_FB_LOCATION,
  633. S_000100_MC_FB_START(rdev->mc.vram_start >> 16) |
  634. S_000100_MC_FB_TOP(rdev->mc.vram_end >> 16));
  635. WREG32(R_000134_HDP_FB_LOCATION,
  636. S_000134_HDP_FB_START(rdev->mc.vram_start >> 16));
  637. rv515_mc_resume(rdev, &save);
  638. }
  639. static int rs690_startup(struct radeon_device *rdev)
  640. {
  641. int r;
  642. rs690_mc_program(rdev);
  643. /* Resume clock */
  644. rv515_clock_startup(rdev);
  645. /* Initialize GPU configuration (# pipes, ...) */
  646. rs690_gpu_init(rdev);
  647. /* Initialize GART (initialize after TTM so we can allocate
  648. * memory through TTM but finalize after TTM) */
  649. r = rs400_gart_enable(rdev);
  650. if (r)
  651. return r;
  652. /* allocate wb buffer */
  653. r = radeon_wb_init(rdev);
  654. if (r)
  655. return r;
  656. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  657. if (r) {
  658. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  659. return r;
  660. }
  661. /* Enable IRQ */
  662. if (!rdev->irq.installed) {
  663. r = radeon_irq_kms_init(rdev);
  664. if (r)
  665. return r;
  666. }
  667. rs600_irq_set(rdev);
  668. rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
  669. /* 1M ring buffer */
  670. r = r100_cp_init(rdev, 1024 * 1024);
  671. if (r) {
  672. dev_err(rdev->dev, "failed initializing CP (%d).\n", r);
  673. return r;
  674. }
  675. r = radeon_ib_pool_init(rdev);
  676. if (r) {
  677. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  678. return r;
  679. }
  680. r = radeon_audio_init(rdev);
  681. if (r) {
  682. dev_err(rdev->dev, "failed initializing audio\n");
  683. return r;
  684. }
  685. return 0;
  686. }
  687. int rs690_resume(struct radeon_device *rdev)
  688. {
  689. int r;
  690. /* Make sur GART are not working */
  691. rs400_gart_disable(rdev);
  692. /* Resume clock before doing reset */
  693. rv515_clock_startup(rdev);
  694. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  695. if (radeon_asic_reset(rdev)) {
  696. dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  697. RREG32(R_000E40_RBBM_STATUS),
  698. RREG32(R_0007C0_CP_STAT));
  699. }
  700. /* post */
  701. atom_asic_init(rdev->mode_info.atom_context);
  702. /* Resume clock after posting */
  703. rv515_clock_startup(rdev);
  704. /* Initialize surface registers */
  705. radeon_surface_init(rdev);
  706. rdev->accel_working = true;
  707. r = rs690_startup(rdev);
  708. if (r) {
  709. rdev->accel_working = false;
  710. }
  711. return r;
  712. }
  713. int rs690_suspend(struct radeon_device *rdev)
  714. {
  715. radeon_pm_suspend(rdev);
  716. radeon_audio_fini(rdev);
  717. r100_cp_disable(rdev);
  718. radeon_wb_disable(rdev);
  719. rs600_irq_disable(rdev);
  720. rs400_gart_disable(rdev);
  721. return 0;
  722. }
  723. void rs690_fini(struct radeon_device *rdev)
  724. {
  725. radeon_pm_fini(rdev);
  726. radeon_audio_fini(rdev);
  727. r100_cp_fini(rdev);
  728. radeon_wb_fini(rdev);
  729. radeon_ib_pool_fini(rdev);
  730. radeon_gem_fini(rdev);
  731. rs400_gart_fini(rdev);
  732. radeon_irq_kms_fini(rdev);
  733. radeon_fence_driver_fini(rdev);
  734. radeon_bo_fini(rdev);
  735. radeon_atombios_fini(rdev);
  736. kfree(rdev->bios);
  737. rdev->bios = NULL;
  738. }
  739. int rs690_init(struct radeon_device *rdev)
  740. {
  741. int r;
  742. /* Disable VGA */
  743. rv515_vga_render_disable(rdev);
  744. /* Initialize scratch registers */
  745. radeon_scratch_init(rdev);
  746. /* Initialize surface registers */
  747. radeon_surface_init(rdev);
  748. /* restore some register to sane defaults */
  749. r100_restore_sanity(rdev);
  750. /* TODO: disable VGA need to use VGA request */
  751. /* BIOS*/
  752. if (!radeon_get_bios(rdev)) {
  753. if (ASIC_IS_AVIVO(rdev))
  754. return -EINVAL;
  755. }
  756. if (rdev->is_atom_bios) {
  757. r = radeon_atombios_init(rdev);
  758. if (r)
  759. return r;
  760. } else {
  761. dev_err(rdev->dev, "Expecting atombios for RV515 GPU\n");
  762. return -EINVAL;
  763. }
  764. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  765. if (radeon_asic_reset(rdev)) {
  766. dev_warn(rdev->dev,
  767. "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  768. RREG32(R_000E40_RBBM_STATUS),
  769. RREG32(R_0007C0_CP_STAT));
  770. }
  771. /* check if cards are posted or not */
  772. if (radeon_boot_test_post_card(rdev) == false)
  773. return -EINVAL;
  774. /* Initialize clocks */
  775. radeon_get_clock_info(rdev->ddev);
  776. /* initialize memory controller */
  777. rs690_mc_init(rdev);
  778. rv515_debugfs(rdev);
  779. /* Fence driver */
  780. r = radeon_fence_driver_init(rdev);
  781. if (r)
  782. return r;
  783. /* Memory manager */
  784. r = radeon_bo_init(rdev);
  785. if (r)
  786. return r;
  787. r = rs400_gart_init(rdev);
  788. if (r)
  789. return r;
  790. rs600_set_safe_registers(rdev);
  791. /* Initialize power management */
  792. radeon_pm_init(rdev);
  793. rdev->accel_working = true;
  794. r = rs690_startup(rdev);
  795. if (r) {
  796. /* Somethings want wront with the accel init stop accel */
  797. dev_err(rdev->dev, "Disabling GPU acceleration\n");
  798. r100_cp_fini(rdev);
  799. radeon_wb_fini(rdev);
  800. radeon_ib_pool_fini(rdev);
  801. rs400_gart_fini(rdev);
  802. radeon_irq_kms_fini(rdev);
  803. rdev->accel_working = false;
  804. }
  805. return 0;
  806. }