2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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.
24 * Authors: Dave Airlie
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <dev/drm2/drmP.h>
34 #include "radeon_asic.h"
38 int rs690_mc_wait_for_idle(struct radeon_device *rdev)
43 for (i = 0; i < rdev->usec_timeout; i++) {
45 tmp = RREG32_MC(R_000090_MC_SYSTEM_STATUS);
46 if (G_000090_MC_SYSTEM_IDLE(tmp))
53 static void rs690_gpu_init(struct radeon_device *rdev)
55 /* FIXME: is this correct ? */
56 r420_pipes_init(rdev);
57 if (rs690_mc_wait_for_idle(rdev)) {
58 DRM_ERROR("Failed to wait MC idle while "
59 "programming pipes. Bad things might happen.\n");
64 struct _ATOM_INTEGRATED_SYSTEM_INFO info;
65 struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_v2;
68 void rs690_pm_info(struct radeon_device *rdev)
70 int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
76 if (atom_parse_data_header(rdev->mode_info.atom_context, index, NULL,
77 &frev, &crev, &data_offset)) {
78 info = (union igp_info *)((uintptr_t)rdev->mode_info.atom_context->bios + data_offset);
80 /* Get various system informations from bios */
83 tmp.full = dfixed_const(100);
84 rdev->pm.igp_sideport_mclk.full = dfixed_const(le32_to_cpu(info->info.ulBootUpMemoryClock));
85 rdev->pm.igp_sideport_mclk.full = dfixed_div(rdev->pm.igp_sideport_mclk, tmp);
86 if (le16_to_cpu(info->info.usK8MemoryClock))
87 rdev->pm.igp_system_mclk.full = dfixed_const(le16_to_cpu(info->info.usK8MemoryClock));
88 else if (rdev->clock.default_mclk) {
89 rdev->pm.igp_system_mclk.full = dfixed_const(rdev->clock.default_mclk);
90 rdev->pm.igp_system_mclk.full = dfixed_div(rdev->pm.igp_system_mclk, tmp);
92 rdev->pm.igp_system_mclk.full = dfixed_const(400);
93 rdev->pm.igp_ht_link_clk.full = dfixed_const(le16_to_cpu(info->info.usFSBClock));
94 rdev->pm.igp_ht_link_width.full = dfixed_const(info->info.ucHTLinkWidth);
97 tmp.full = dfixed_const(100);
98 rdev->pm.igp_sideport_mclk.full = dfixed_const(le32_to_cpu(info->info_v2.ulBootUpSidePortClock));
99 rdev->pm.igp_sideport_mclk.full = dfixed_div(rdev->pm.igp_sideport_mclk, tmp);
100 if (le32_to_cpu(info->info_v2.ulBootUpUMAClock))
101 rdev->pm.igp_system_mclk.full = dfixed_const(le32_to_cpu(info->info_v2.ulBootUpUMAClock));
102 else if (rdev->clock.default_mclk)
103 rdev->pm.igp_system_mclk.full = dfixed_const(rdev->clock.default_mclk);
105 rdev->pm.igp_system_mclk.full = dfixed_const(66700);
106 rdev->pm.igp_system_mclk.full = dfixed_div(rdev->pm.igp_system_mclk, tmp);
107 rdev->pm.igp_ht_link_clk.full = dfixed_const(le32_to_cpu(info->info_v2.ulHTLinkFreq));
108 rdev->pm.igp_ht_link_clk.full = dfixed_div(rdev->pm.igp_ht_link_clk, tmp);
109 rdev->pm.igp_ht_link_width.full = dfixed_const(le16_to_cpu(info->info_v2.usMinHTLinkWidth));
112 /* We assume the slower possible clock ie worst case */
113 rdev->pm.igp_sideport_mclk.full = dfixed_const(200);
114 rdev->pm.igp_system_mclk.full = dfixed_const(200);
115 rdev->pm.igp_ht_link_clk.full = dfixed_const(1000);
116 rdev->pm.igp_ht_link_width.full = dfixed_const(8);
117 DRM_ERROR("No integrated system info for your GPU, using safe default\n");
121 /* We assume the slower possible clock ie worst case */
122 rdev->pm.igp_sideport_mclk.full = dfixed_const(200);
123 rdev->pm.igp_system_mclk.full = dfixed_const(200);
124 rdev->pm.igp_ht_link_clk.full = dfixed_const(1000);
125 rdev->pm.igp_ht_link_width.full = dfixed_const(8);
126 DRM_ERROR("No integrated system info for your GPU, using safe default\n");
128 /* Compute various bandwidth */
129 /* k8_bandwidth = (memory_clk / 2) * 2 * 8 * 0.5 = memory_clk * 4 */
130 tmp.full = dfixed_const(4);
131 rdev->pm.k8_bandwidth.full = dfixed_mul(rdev->pm.igp_system_mclk, tmp);
132 /* ht_bandwidth = ht_clk * 2 * ht_width / 8 * 0.8
133 * = ht_clk * ht_width / 5
135 tmp.full = dfixed_const(5);
136 rdev->pm.ht_bandwidth.full = dfixed_mul(rdev->pm.igp_ht_link_clk,
137 rdev->pm.igp_ht_link_width);
138 rdev->pm.ht_bandwidth.full = dfixed_div(rdev->pm.ht_bandwidth, tmp);
139 if (tmp.full < rdev->pm.max_bandwidth.full) {
140 /* HT link is a limiting factor */
141 rdev->pm.max_bandwidth.full = tmp.full;
143 /* sideport_bandwidth = (sideport_clk / 2) * 2 * 2 * 0.7
144 * = (sideport_clk * 14) / 10
146 tmp.full = dfixed_const(14);
147 rdev->pm.sideport_bandwidth.full = dfixed_mul(rdev->pm.igp_sideport_mclk, tmp);
148 tmp.full = dfixed_const(10);
149 rdev->pm.sideport_bandwidth.full = dfixed_div(rdev->pm.sideport_bandwidth, tmp);
152 static void rs690_mc_init(struct radeon_device *rdev)
156 rs400_gart_adjust_size(rdev);
157 rdev->mc.vram_is_ddr = true;
158 rdev->mc.vram_width = 128;
159 rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
160 rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
161 rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
162 rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
163 rdev->mc.visible_vram_size = rdev->mc.aper_size;
164 base = RREG32_MC(R_000100_MCCFG_FB_LOCATION);
165 base = G_000100_MC_FB_START(base) << 16;
166 rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
168 radeon_vram_location(rdev, &rdev->mc, base);
169 rdev->mc.gtt_base_align = rdev->mc.gtt_size - 1;
170 radeon_gtt_location(rdev, &rdev->mc);
171 radeon_update_bandwidth_info(rdev);
174 void rs690_line_buffer_adjust(struct radeon_device *rdev,
175 struct drm_display_mode *mode1,
176 struct drm_display_mode *mode2)
182 * There is a single line buffer shared by both display controllers.
183 * R_006520_DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
184 * the display controllers. The paritioning can either be done
185 * manually or via one of four preset allocations specified in bits 1:0:
186 * 0 - line buffer is divided in half and shared between crtc
187 * 1 - D1 gets 3/4 of the line buffer, D2 gets 1/4
188 * 2 - D1 gets the whole buffer
189 * 3 - D1 gets 1/4 of the line buffer, D2 gets 3/4
190 * Setting bit 2 of R_006520_DC_LB_MEMORY_SPLIT controls switches to manual
191 * allocation mode. In manual allocation mode, D1 always starts at 0,
192 * D1 end/2 is specified in bits 14:4; D2 allocation follows D1.
194 tmp = RREG32(R_006520_DC_LB_MEMORY_SPLIT) & C_006520_DC_LB_MEMORY_SPLIT;
195 tmp &= ~C_006520_DC_LB_MEMORY_SPLIT_MODE;
197 if (mode1 && mode2) {
198 if (mode1->hdisplay > mode2->hdisplay) {
199 if (mode1->hdisplay > 2560)
200 tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_3Q_D2_1Q;
202 tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
203 } else if (mode2->hdisplay > mode1->hdisplay) {
204 if (mode2->hdisplay > 2560)
205 tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_1Q_D2_3Q;
207 tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
209 tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
211 tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_ONLY;
213 tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_1Q_D2_3Q;
215 WREG32(R_006520_DC_LB_MEMORY_SPLIT, tmp);
218 struct rs690_watermark {
219 u32 lb_request_fifo_depth;
220 fixed20_12 num_line_pair;
221 fixed20_12 estimated_width;
222 fixed20_12 worst_case_latency;
223 fixed20_12 consumption_rate;
224 fixed20_12 active_time;
226 fixed20_12 priority_mark_max;
227 fixed20_12 priority_mark;
231 static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
232 struct radeon_crtc *crtc,
233 struct rs690_watermark *wm)
235 struct drm_display_mode *mode = &crtc->base.mode;
237 fixed20_12 pclk, request_fifo_depth, tolerable_latency, estimated_width;
238 fixed20_12 consumption_time, line_time, chunk_time, read_delay_latency;
240 if (!crtc->base.enabled) {
241 /* FIXME: wouldn't it better to set priority mark to maximum */
242 wm->lb_request_fifo_depth = 4;
246 if (crtc->vsc.full > dfixed_const(2))
247 wm->num_line_pair.full = dfixed_const(2);
249 wm->num_line_pair.full = dfixed_const(1);
251 b.full = dfixed_const(mode->crtc_hdisplay);
252 c.full = dfixed_const(256);
253 a.full = dfixed_div(b, c);
254 request_fifo_depth.full = dfixed_mul(a, wm->num_line_pair);
255 request_fifo_depth.full = dfixed_ceil(request_fifo_depth);
256 if (a.full < dfixed_const(4)) {
257 wm->lb_request_fifo_depth = 4;
259 wm->lb_request_fifo_depth = dfixed_trunc(request_fifo_depth);
262 /* Determine consumption rate
263 * pclk = pixel clock period(ns) = 1000 / (mode.clock / 1000)
264 * vtaps = number of vertical taps,
265 * vsc = vertical scaling ratio, defined as source/destination
266 * hsc = horizontal scaling ration, defined as source/destination
268 a.full = dfixed_const(mode->clock);
269 b.full = dfixed_const(1000);
270 a.full = dfixed_div(a, b);
271 pclk.full = dfixed_div(b, a);
272 if (crtc->rmx_type != RMX_OFF) {
273 b.full = dfixed_const(2);
274 if (crtc->vsc.full > b.full)
275 b.full = crtc->vsc.full;
276 b.full = dfixed_mul(b, crtc->hsc);
277 c.full = dfixed_const(2);
278 b.full = dfixed_div(b, c);
279 consumption_time.full = dfixed_div(pclk, b);
281 consumption_time.full = pclk.full;
283 a.full = dfixed_const(1);
284 wm->consumption_rate.full = dfixed_div(a, consumption_time);
287 /* Determine line time
288 * LineTime = total time for one line of displayhtotal
289 * LineTime = total number of horizontal pixels
290 * pclk = pixel clock period(ns)
292 a.full = dfixed_const(crtc->base.mode.crtc_htotal);
293 line_time.full = dfixed_mul(a, pclk);
295 /* Determine active time
296 * ActiveTime = time of active region of display within one line,
297 * hactive = total number of horizontal active pixels
298 * htotal = total number of horizontal pixels
300 a.full = dfixed_const(crtc->base.mode.crtc_htotal);
301 b.full = dfixed_const(crtc->base.mode.crtc_hdisplay);
302 wm->active_time.full = dfixed_mul(line_time, b);
303 wm->active_time.full = dfixed_div(wm->active_time, a);
305 /* Maximun bandwidth is the minimun bandwidth of all component */
306 rdev->pm.max_bandwidth = rdev->pm.core_bandwidth;
307 if (rdev->mc.igp_sideport_enabled) {
308 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
309 rdev->pm.sideport_bandwidth.full)
310 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
312 read_delay_latency.full = dfixed_const(370 * 800 * 1000);
313 #endif /* DUMBBELL_WIP */
314 read_delay_latency.full = UINT_MAX;
315 read_delay_latency.full = dfixed_div(read_delay_latency,
316 rdev->pm.igp_sideport_mclk);
318 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
319 rdev->pm.k8_bandwidth.full)
320 rdev->pm.max_bandwidth = rdev->pm.k8_bandwidth;
321 if (rdev->pm.max_bandwidth.full > rdev->pm.ht_bandwidth.full &&
322 rdev->pm.ht_bandwidth.full)
323 rdev->pm.max_bandwidth = rdev->pm.ht_bandwidth;
324 read_delay_latency.full = dfixed_const(5000);
327 /* sclk = system clocks(ns) = 1000 / max_bandwidth / 16 */
328 a.full = dfixed_const(16);
329 rdev->pm.sclk.full = dfixed_mul(rdev->pm.max_bandwidth, a);
330 a.full = dfixed_const(1000);
331 rdev->pm.sclk.full = dfixed_div(a, rdev->pm.sclk);
332 /* Determine chunk time
333 * ChunkTime = the time it takes the DCP to send one chunk of data
334 * to the LB which consists of pipeline delay and inter chunk gap
335 * sclk = system clock(ns)
337 a.full = dfixed_const(256 * 13);
338 chunk_time.full = dfixed_mul(rdev->pm.sclk, a);
339 a.full = dfixed_const(10);
340 chunk_time.full = dfixed_div(chunk_time, a);
342 /* Determine the worst case latency
343 * NumLinePair = Number of line pairs to request(1=2 lines, 2=4 lines)
344 * WorstCaseLatency = worst case time from urgent to when the MC starts
346 * READ_DELAY_IDLE_MAX = constant of 1us
347 * ChunkTime = time it takes the DCP to send one chunk of data to the LB
348 * which consists of pipeline delay and inter chunk gap
350 if (dfixed_trunc(wm->num_line_pair) > 1) {
351 a.full = dfixed_const(3);
352 wm->worst_case_latency.full = dfixed_mul(a, chunk_time);
353 wm->worst_case_latency.full += read_delay_latency.full;
355 a.full = dfixed_const(2);
356 wm->worst_case_latency.full = dfixed_mul(a, chunk_time);
357 wm->worst_case_latency.full += read_delay_latency.full;
360 /* Determine the tolerable latency
361 * TolerableLatency = Any given request has only 1 line time
362 * for the data to be returned
363 * LBRequestFifoDepth = Number of chunk requests the LB can
364 * put into the request FIFO for a display
365 * LineTime = total time for one line of display
366 * ChunkTime = the time it takes the DCP to send one chunk
367 * of data to the LB which consists of
368 * pipeline delay and inter chunk gap
370 if ((2+wm->lb_request_fifo_depth) >= dfixed_trunc(request_fifo_depth)) {
371 tolerable_latency.full = line_time.full;
373 tolerable_latency.full = dfixed_const(wm->lb_request_fifo_depth - 2);
374 tolerable_latency.full = request_fifo_depth.full - tolerable_latency.full;
375 tolerable_latency.full = dfixed_mul(tolerable_latency, chunk_time);
376 tolerable_latency.full = line_time.full - tolerable_latency.full;
378 /* We assume worst case 32bits (4 bytes) */
379 wm->dbpp.full = dfixed_const(4 * 8);
381 /* Determine the maximum priority mark
382 * width = viewport width in pixels
384 a.full = dfixed_const(16);
385 wm->priority_mark_max.full = dfixed_const(crtc->base.mode.crtc_hdisplay);
386 wm->priority_mark_max.full = dfixed_div(wm->priority_mark_max, a);
387 wm->priority_mark_max.full = dfixed_ceil(wm->priority_mark_max);
389 /* Determine estimated width */
390 estimated_width.full = tolerable_latency.full - wm->worst_case_latency.full;
391 estimated_width.full = dfixed_div(estimated_width, consumption_time);
392 if (dfixed_trunc(estimated_width) > crtc->base.mode.crtc_hdisplay) {
393 wm->priority_mark.full = dfixed_const(10);
395 a.full = dfixed_const(16);
396 wm->priority_mark.full = dfixed_div(estimated_width, a);
397 wm->priority_mark.full = dfixed_ceil(wm->priority_mark);
398 wm->priority_mark.full = wm->priority_mark_max.full - wm->priority_mark.full;
402 void rs690_bandwidth_update(struct radeon_device *rdev)
404 struct drm_display_mode *mode0 = NULL;
405 struct drm_display_mode *mode1 = NULL;
406 struct rs690_watermark wm0;
407 struct rs690_watermark wm1;
409 u32 d1mode_priority_a_cnt = S_006548_D1MODE_PRIORITY_A_OFF(1);
410 u32 d2mode_priority_a_cnt = S_006548_D1MODE_PRIORITY_A_OFF(1);
411 fixed20_12 priority_mark02, priority_mark12, fill_rate;
414 radeon_update_display_priority(rdev);
416 if (rdev->mode_info.crtcs[0]->base.enabled)
417 mode0 = &rdev->mode_info.crtcs[0]->base.mode;
418 if (rdev->mode_info.crtcs[1]->base.enabled)
419 mode1 = &rdev->mode_info.crtcs[1]->base.mode;
421 * Set display0/1 priority up in the memory controller for
422 * modes if the user specifies HIGH for displaypriority
425 if ((rdev->disp_priority == 2) &&
426 ((rdev->family == CHIP_RS690) || (rdev->family == CHIP_RS740))) {
427 tmp = RREG32_MC(R_000104_MC_INIT_MISC_LAT_TIMER);
428 tmp &= C_000104_MC_DISP0R_INIT_LAT;
429 tmp &= C_000104_MC_DISP1R_INIT_LAT;
431 tmp |= S_000104_MC_DISP0R_INIT_LAT(1);
433 tmp |= S_000104_MC_DISP1R_INIT_LAT(1);
434 WREG32_MC(R_000104_MC_INIT_MISC_LAT_TIMER, tmp);
436 rs690_line_buffer_adjust(rdev, mode0, mode1);
438 if ((rdev->family == CHIP_RS690) || (rdev->family == CHIP_RS740))
439 WREG32(R_006C9C_DCP_CONTROL, 0);
440 if ((rdev->family == CHIP_RS780) || (rdev->family == CHIP_RS880))
441 WREG32(R_006C9C_DCP_CONTROL, 2);
443 rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[0], &wm0);
444 rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[1], &wm1);
446 tmp = (wm0.lb_request_fifo_depth - 1);
447 tmp |= (wm1.lb_request_fifo_depth - 1) << 16;
448 WREG32(R_006D58_LB_MAX_REQ_OUTSTANDING, tmp);
450 if (mode0 && mode1) {
451 if (dfixed_trunc(wm0.dbpp) > 64)
452 a.full = dfixed_mul(wm0.dbpp, wm0.num_line_pair);
454 a.full = wm0.num_line_pair.full;
455 if (dfixed_trunc(wm1.dbpp) > 64)
456 b.full = dfixed_mul(wm1.dbpp, wm1.num_line_pair);
458 b.full = wm1.num_line_pair.full;
460 fill_rate.full = dfixed_div(wm0.sclk, a);
461 if (wm0.consumption_rate.full > fill_rate.full) {
462 b.full = wm0.consumption_rate.full - fill_rate.full;
463 b.full = dfixed_mul(b, wm0.active_time);
464 a.full = dfixed_mul(wm0.worst_case_latency,
465 wm0.consumption_rate);
466 a.full = a.full + b.full;
467 b.full = dfixed_const(16 * 1000);
468 priority_mark02.full = dfixed_div(a, b);
470 a.full = dfixed_mul(wm0.worst_case_latency,
471 wm0.consumption_rate);
472 b.full = dfixed_const(16 * 1000);
473 priority_mark02.full = dfixed_div(a, b);
475 if (wm1.consumption_rate.full > fill_rate.full) {
476 b.full = wm1.consumption_rate.full - fill_rate.full;
477 b.full = dfixed_mul(b, wm1.active_time);
478 a.full = dfixed_mul(wm1.worst_case_latency,
479 wm1.consumption_rate);
480 a.full = a.full + b.full;
481 b.full = dfixed_const(16 * 1000);
482 priority_mark12.full = dfixed_div(a, b);
484 a.full = dfixed_mul(wm1.worst_case_latency,
485 wm1.consumption_rate);
486 b.full = dfixed_const(16 * 1000);
487 priority_mark12.full = dfixed_div(a, b);
489 if (wm0.priority_mark.full > priority_mark02.full)
490 priority_mark02.full = wm0.priority_mark.full;
491 if (dfixed_trunc(priority_mark02) < 0)
492 priority_mark02.full = 0;
493 if (wm0.priority_mark_max.full > priority_mark02.full)
494 priority_mark02.full = wm0.priority_mark_max.full;
495 if (wm1.priority_mark.full > priority_mark12.full)
496 priority_mark12.full = wm1.priority_mark.full;
497 if (dfixed_trunc(priority_mark12) < 0)
498 priority_mark12.full = 0;
499 if (wm1.priority_mark_max.full > priority_mark12.full)
500 priority_mark12.full = wm1.priority_mark_max.full;
501 d1mode_priority_a_cnt = dfixed_trunc(priority_mark02);
502 d2mode_priority_a_cnt = dfixed_trunc(priority_mark12);
503 if (rdev->disp_priority == 2) {
504 d1mode_priority_a_cnt |= S_006548_D1MODE_PRIORITY_A_ALWAYS_ON(1);
505 d2mode_priority_a_cnt |= S_006D48_D2MODE_PRIORITY_A_ALWAYS_ON(1);
508 if (dfixed_trunc(wm0.dbpp) > 64)
509 a.full = dfixed_mul(wm0.dbpp, wm0.num_line_pair);
511 a.full = wm0.num_line_pair.full;
512 fill_rate.full = dfixed_div(wm0.sclk, a);
513 if (wm0.consumption_rate.full > fill_rate.full) {
514 b.full = wm0.consumption_rate.full - fill_rate.full;
515 b.full = dfixed_mul(b, wm0.active_time);
516 a.full = dfixed_mul(wm0.worst_case_latency,
517 wm0.consumption_rate);
518 a.full = a.full + b.full;
519 b.full = dfixed_const(16 * 1000);
520 priority_mark02.full = dfixed_div(a, b);
522 a.full = dfixed_mul(wm0.worst_case_latency,
523 wm0.consumption_rate);
524 b.full = dfixed_const(16 * 1000);
525 priority_mark02.full = dfixed_div(a, b);
527 if (wm0.priority_mark.full > priority_mark02.full)
528 priority_mark02.full = wm0.priority_mark.full;
529 if (dfixed_trunc(priority_mark02) < 0)
530 priority_mark02.full = 0;
531 if (wm0.priority_mark_max.full > priority_mark02.full)
532 priority_mark02.full = wm0.priority_mark_max.full;
533 d1mode_priority_a_cnt = dfixed_trunc(priority_mark02);
534 if (rdev->disp_priority == 2)
535 d1mode_priority_a_cnt |= S_006548_D1MODE_PRIORITY_A_ALWAYS_ON(1);
537 if (dfixed_trunc(wm1.dbpp) > 64)
538 a.full = dfixed_mul(wm1.dbpp, wm1.num_line_pair);
540 a.full = wm1.num_line_pair.full;
541 fill_rate.full = dfixed_div(wm1.sclk, a);
542 if (wm1.consumption_rate.full > fill_rate.full) {
543 b.full = wm1.consumption_rate.full - fill_rate.full;
544 b.full = dfixed_mul(b, wm1.active_time);
545 a.full = dfixed_mul(wm1.worst_case_latency,
546 wm1.consumption_rate);
547 a.full = a.full + b.full;
548 b.full = dfixed_const(16 * 1000);
549 priority_mark12.full = dfixed_div(a, b);
551 a.full = dfixed_mul(wm1.worst_case_latency,
552 wm1.consumption_rate);
553 b.full = dfixed_const(16 * 1000);
554 priority_mark12.full = dfixed_div(a, b);
556 if (wm1.priority_mark.full > priority_mark12.full)
557 priority_mark12.full = wm1.priority_mark.full;
558 if (dfixed_trunc(priority_mark12) < 0)
559 priority_mark12.full = 0;
560 if (wm1.priority_mark_max.full > priority_mark12.full)
561 priority_mark12.full = wm1.priority_mark_max.full;
562 d2mode_priority_a_cnt = dfixed_trunc(priority_mark12);
563 if (rdev->disp_priority == 2)
564 d2mode_priority_a_cnt |= S_006D48_D2MODE_PRIORITY_A_ALWAYS_ON(1);
567 WREG32(R_006548_D1MODE_PRIORITY_A_CNT, d1mode_priority_a_cnt);
568 WREG32(R_00654C_D1MODE_PRIORITY_B_CNT, d1mode_priority_a_cnt);
569 WREG32(R_006D48_D2MODE_PRIORITY_A_CNT, d2mode_priority_a_cnt);
570 WREG32(R_006D4C_D2MODE_PRIORITY_B_CNT, d2mode_priority_a_cnt);
573 uint32_t rs690_mc_rreg(struct radeon_device *rdev, uint32_t reg)
577 WREG32(R_000078_MC_INDEX, S_000078_MC_IND_ADDR(reg));
578 r = RREG32(R_00007C_MC_DATA);
579 WREG32(R_000078_MC_INDEX, ~C_000078_MC_IND_ADDR);
583 void rs690_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
585 WREG32(R_000078_MC_INDEX, S_000078_MC_IND_ADDR(reg) |
586 S_000078_MC_IND_WR_EN(1));
587 WREG32(R_00007C_MC_DATA, v);
588 WREG32(R_000078_MC_INDEX, 0x7F);
591 static void rs690_mc_program(struct radeon_device *rdev)
593 struct rv515_mc_save save;
595 /* Stops all mc clients */
596 rv515_mc_stop(rdev, &save);
598 /* Wait for mc idle */
599 if (rs690_mc_wait_for_idle(rdev))
600 dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
601 /* Program MC, should be a 32bits limited address space */
602 WREG32_MC(R_000100_MCCFG_FB_LOCATION,
603 S_000100_MC_FB_START(rdev->mc.vram_start >> 16) |
604 S_000100_MC_FB_TOP(rdev->mc.vram_end >> 16));
605 WREG32(R_000134_HDP_FB_LOCATION,
606 S_000134_HDP_FB_START(rdev->mc.vram_start >> 16));
608 rv515_mc_resume(rdev, &save);
611 static int rs690_startup(struct radeon_device *rdev)
615 rs690_mc_program(rdev);
617 rv515_clock_startup(rdev);
618 /* Initialize GPU configuration (# pipes, ...) */
619 rs690_gpu_init(rdev);
620 /* Initialize GART (initialize after TTM so we can allocate
621 * memory through TTM but finalize after TTM) */
622 r = rs400_gart_enable(rdev);
626 /* allocate wb buffer */
627 r = radeon_wb_init(rdev);
631 r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
633 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
639 rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
641 r = r100_cp_init(rdev, 1024 * 1024);
643 dev_err(rdev->dev, "failed initializing CP (%d).\n", r);
647 r = radeon_ib_pool_init(rdev);
649 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
653 r = r600_audio_init(rdev);
655 dev_err(rdev->dev, "failed initializing audio\n");
662 int rs690_resume(struct radeon_device *rdev)
666 /* Make sur GART are not working */
667 rs400_gart_disable(rdev);
668 /* Resume clock before doing reset */
669 rv515_clock_startup(rdev);
670 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
671 if (radeon_asic_reset(rdev)) {
672 dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
673 RREG32(R_000E40_RBBM_STATUS),
674 RREG32(R_0007C0_CP_STAT));
677 atom_asic_init(rdev->mode_info.atom_context);
678 /* Resume clock after posting */
679 rv515_clock_startup(rdev);
680 /* Initialize surface registers */
681 radeon_surface_init(rdev);
683 rdev->accel_working = true;
684 r = rs690_startup(rdev);
686 rdev->accel_working = false;
691 int rs690_suspend(struct radeon_device *rdev)
693 r600_audio_fini(rdev);
694 r100_cp_disable(rdev);
695 radeon_wb_disable(rdev);
696 rs600_irq_disable(rdev);
697 rs400_gart_disable(rdev);
701 void rs690_fini(struct radeon_device *rdev)
703 r600_audio_fini(rdev);
705 radeon_wb_fini(rdev);
706 radeon_ib_pool_fini(rdev);
707 radeon_gem_fini(rdev);
708 rs400_gart_fini(rdev);
709 radeon_irq_kms_fini(rdev);
710 radeon_fence_driver_fini(rdev);
711 radeon_bo_fini(rdev);
712 radeon_atombios_fini(rdev);
713 free(rdev->bios, DRM_MEM_DRIVER);
717 int rs690_init(struct radeon_device *rdev)
722 rv515_vga_render_disable(rdev);
723 /* Initialize scratch registers */
724 radeon_scratch_init(rdev);
725 /* Initialize surface registers */
726 radeon_surface_init(rdev);
727 /* restore some register to sane defaults */
728 r100_restore_sanity(rdev);
729 /* TODO: disable VGA need to use VGA request */
731 if (!radeon_get_bios(rdev)) {
732 if (ASIC_IS_AVIVO(rdev))
735 if (rdev->is_atom_bios) {
736 r = radeon_atombios_init(rdev);
740 dev_err(rdev->dev, "Expecting atombios for RV515 GPU\n");
743 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
744 if (radeon_asic_reset(rdev)) {
746 "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
747 RREG32(R_000E40_RBBM_STATUS),
748 RREG32(R_0007C0_CP_STAT));
750 /* check if cards are posted or not */
751 if (radeon_boot_test_post_card(rdev) == false)
754 /* Initialize clocks */
755 radeon_get_clock_info(rdev->ddev);
756 /* initialize memory controller */
760 r = radeon_fence_driver_init(rdev);
763 r = radeon_irq_kms_init(rdev);
767 r = radeon_bo_init(rdev);
770 r = rs400_gart_init(rdev);
773 rs600_set_safe_registers(rdev);
775 rdev->accel_working = true;
776 r = rs690_startup(rdev);
778 /* Somethings want wront with the accel init stop accel */
779 dev_err(rdev->dev, "Disabling GPU acceleration\n");
781 radeon_wb_fini(rdev);
782 radeon_ib_pool_fini(rdev);
783 rs400_gart_fini(rdev);
784 radeon_irq_kms_fini(rdev);
785 rdev->accel_working = false;