1771fe6b9SJerome Glisse /* 2771fe6b9SJerome Glisse * Copyright 2008 Advanced Micro Devices, Inc. 3771fe6b9SJerome Glisse * Copyright 2008 Red Hat Inc. 4771fe6b9SJerome Glisse * Copyright 2009 Jerome Glisse. 5771fe6b9SJerome Glisse * 6771fe6b9SJerome Glisse * Permission is hereby granted, free of charge, to any person obtaining a 7771fe6b9SJerome Glisse * copy of this software and associated documentation files (the "Software"), 8771fe6b9SJerome Glisse * to deal in the Software without restriction, including without limitation 9771fe6b9SJerome Glisse * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10771fe6b9SJerome Glisse * and/or sell copies of the Software, and to permit persons to whom the 11771fe6b9SJerome Glisse * Software is furnished to do so, subject to the following conditions: 12771fe6b9SJerome Glisse * 13771fe6b9SJerome Glisse * The above copyright notice and this permission notice shall be included in 14771fe6b9SJerome Glisse * all copies or substantial portions of the Software. 15771fe6b9SJerome Glisse * 16771fe6b9SJerome Glisse * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17771fe6b9SJerome Glisse * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18771fe6b9SJerome Glisse * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19771fe6b9SJerome Glisse * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20771fe6b9SJerome Glisse * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21771fe6b9SJerome Glisse * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22771fe6b9SJerome Glisse * OTHER DEALINGS IN THE SOFTWARE. 23771fe6b9SJerome Glisse * 24771fe6b9SJerome Glisse * Authors: Dave Airlie 25771fe6b9SJerome Glisse * Alex Deucher 26771fe6b9SJerome Glisse * Jerome Glisse 27771fe6b9SJerome Glisse */ 28771fe6b9SJerome Glisse #include <linux/seq_file.h> 295a0e3ad6STejun Heo #include <linux/slab.h> 30771fe6b9SJerome Glisse #include "drmP.h" 31771fe6b9SJerome Glisse #include "drm.h" 32771fe6b9SJerome Glisse #include "radeon_drm.h" 33771fe6b9SJerome Glisse #include "radeon_reg.h" 34771fe6b9SJerome Glisse #include "radeon.h" 35e6990375SDaniel Vetter #include "radeon_asic.h" 363ce0a23dSJerome Glisse #include "r100d.h" 37d4550907SJerome Glisse #include "rs100d.h" 38d4550907SJerome Glisse #include "rv200d.h" 39d4550907SJerome Glisse #include "rv250d.h" 40*49e02b73SAlex Deucher #include "atom.h" 413ce0a23dSJerome Glisse 4270967ab9SBen Hutchings #include <linux/firmware.h> 4370967ab9SBen Hutchings #include <linux/platform_device.h> 4470967ab9SBen Hutchings 45551ebd83SDave Airlie #include "r100_reg_safe.h" 46551ebd83SDave Airlie #include "rn50_reg_safe.h" 47551ebd83SDave Airlie 4870967ab9SBen Hutchings /* Firmware Names */ 4970967ab9SBen Hutchings #define FIRMWARE_R100 "radeon/R100_cp.bin" 5070967ab9SBen Hutchings #define FIRMWARE_R200 "radeon/R200_cp.bin" 5170967ab9SBen Hutchings #define FIRMWARE_R300 "radeon/R300_cp.bin" 5270967ab9SBen Hutchings #define FIRMWARE_R420 "radeon/R420_cp.bin" 5370967ab9SBen Hutchings #define FIRMWARE_RS690 "radeon/RS690_cp.bin" 5470967ab9SBen Hutchings #define FIRMWARE_RS600 "radeon/RS600_cp.bin" 5570967ab9SBen Hutchings #define FIRMWARE_R520 "radeon/R520_cp.bin" 5670967ab9SBen Hutchings 5770967ab9SBen Hutchings MODULE_FIRMWARE(FIRMWARE_R100); 5870967ab9SBen Hutchings MODULE_FIRMWARE(FIRMWARE_R200); 5970967ab9SBen Hutchings MODULE_FIRMWARE(FIRMWARE_R300); 6070967ab9SBen Hutchings MODULE_FIRMWARE(FIRMWARE_R420); 6170967ab9SBen Hutchings MODULE_FIRMWARE(FIRMWARE_RS690); 6270967ab9SBen Hutchings MODULE_FIRMWARE(FIRMWARE_RS600); 6370967ab9SBen Hutchings MODULE_FIRMWARE(FIRMWARE_R520); 64771fe6b9SJerome Glisse 65551ebd83SDave Airlie #include "r100_track.h" 66551ebd83SDave Airlie 67771fe6b9SJerome Glisse /* This files gather functions specifics to: 68771fe6b9SJerome Glisse * r100,rv100,rs100,rv200,rs200,r200,rv250,rs300,rv280 69771fe6b9SJerome Glisse */ 70771fe6b9SJerome Glisse 71a48b9b4eSAlex Deucher void r100_get_power_state(struct radeon_device *rdev, 72a48b9b4eSAlex Deucher enum radeon_pm_action action) 73a48b9b4eSAlex Deucher { 74a48b9b4eSAlex Deucher int i; 75a48b9b4eSAlex Deucher rdev->pm.can_upclock = true; 76a48b9b4eSAlex Deucher rdev->pm.can_downclock = true; 77a48b9b4eSAlex Deucher 78a48b9b4eSAlex Deucher switch (action) { 79a48b9b4eSAlex Deucher case PM_ACTION_MINIMUM: 80a48b9b4eSAlex Deucher rdev->pm.requested_power_state_index = 0; 81a48b9b4eSAlex Deucher rdev->pm.can_downclock = false; 82a48b9b4eSAlex Deucher break; 83a48b9b4eSAlex Deucher case PM_ACTION_DOWNCLOCK: 84a48b9b4eSAlex Deucher if (rdev->pm.current_power_state_index == 0) { 85a48b9b4eSAlex Deucher rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index; 86a48b9b4eSAlex Deucher rdev->pm.can_downclock = false; 87a48b9b4eSAlex Deucher } else { 88a48b9b4eSAlex Deucher if (rdev->pm.active_crtc_count > 1) { 89a48b9b4eSAlex Deucher for (i = 0; i < rdev->pm.num_power_states; i++) { 90a48b9b4eSAlex Deucher if (rdev->pm.power_state[i].flags & RADEON_PM_SINGLE_DISPLAY_ONLY) 91a48b9b4eSAlex Deucher continue; 92a48b9b4eSAlex Deucher else if (i >= rdev->pm.current_power_state_index) { 93a48b9b4eSAlex Deucher rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index; 94a48b9b4eSAlex Deucher break; 95a48b9b4eSAlex Deucher } else { 96a48b9b4eSAlex Deucher rdev->pm.requested_power_state_index = i; 97a48b9b4eSAlex Deucher break; 98a48b9b4eSAlex Deucher } 99a48b9b4eSAlex Deucher } 100a48b9b4eSAlex Deucher } else 101a48b9b4eSAlex Deucher rdev->pm.requested_power_state_index = 102a48b9b4eSAlex Deucher rdev->pm.current_power_state_index - 1; 103a48b9b4eSAlex Deucher } 104a48b9b4eSAlex Deucher break; 105a48b9b4eSAlex Deucher case PM_ACTION_UPCLOCK: 106a48b9b4eSAlex Deucher if (rdev->pm.current_power_state_index == (rdev->pm.num_power_states - 1)) { 107a48b9b4eSAlex Deucher rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index; 108a48b9b4eSAlex Deucher rdev->pm.can_upclock = false; 109a48b9b4eSAlex Deucher } else { 110a48b9b4eSAlex Deucher if (rdev->pm.active_crtc_count > 1) { 111a48b9b4eSAlex Deucher for (i = (rdev->pm.num_power_states - 1); i >= 0; i--) { 112a48b9b4eSAlex Deucher if (rdev->pm.power_state[i].flags & RADEON_PM_SINGLE_DISPLAY_ONLY) 113a48b9b4eSAlex Deucher continue; 114a48b9b4eSAlex Deucher else if (i <= rdev->pm.current_power_state_index) { 115a48b9b4eSAlex Deucher rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index; 116a48b9b4eSAlex Deucher break; 117a48b9b4eSAlex Deucher } else { 118a48b9b4eSAlex Deucher rdev->pm.requested_power_state_index = i; 119a48b9b4eSAlex Deucher break; 120a48b9b4eSAlex Deucher } 121a48b9b4eSAlex Deucher } 122a48b9b4eSAlex Deucher } else 123a48b9b4eSAlex Deucher rdev->pm.requested_power_state_index = 124a48b9b4eSAlex Deucher rdev->pm.current_power_state_index + 1; 125a48b9b4eSAlex Deucher } 126a48b9b4eSAlex Deucher break; 12758e21dffSAlex Deucher case PM_ACTION_DEFAULT: 12858e21dffSAlex Deucher rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index; 12958e21dffSAlex Deucher rdev->pm.can_upclock = false; 13058e21dffSAlex Deucher break; 131a48b9b4eSAlex Deucher case PM_ACTION_NONE: 132a48b9b4eSAlex Deucher default: 133a48b9b4eSAlex Deucher DRM_ERROR("Requested mode for not defined action\n"); 134a48b9b4eSAlex Deucher return; 135a48b9b4eSAlex Deucher } 136a48b9b4eSAlex Deucher /* only one clock mode per power state */ 137a48b9b4eSAlex Deucher rdev->pm.requested_clock_mode_index = 0; 138a48b9b4eSAlex Deucher 139a48b9b4eSAlex Deucher DRM_INFO("Requested: e: %d m: %d p: %d\n", 140a48b9b4eSAlex Deucher rdev->pm.power_state[rdev->pm.requested_power_state_index]. 141a48b9b4eSAlex Deucher clock_info[rdev->pm.requested_clock_mode_index].sclk, 142a48b9b4eSAlex Deucher rdev->pm.power_state[rdev->pm.requested_power_state_index]. 143a48b9b4eSAlex Deucher clock_info[rdev->pm.requested_clock_mode_index].mclk, 144a48b9b4eSAlex Deucher rdev->pm.power_state[rdev->pm.requested_power_state_index]. 14579daedc9SAlex Deucher pcie_lanes); 146a48b9b4eSAlex Deucher } 147a48b9b4eSAlex Deucher 148bae6b562SAlex Deucher void r100_set_power_state(struct radeon_device *rdev) 149bae6b562SAlex Deucher { 150a48b9b4eSAlex Deucher u32 sclk, mclk; 151a48b9b4eSAlex Deucher 152a48b9b4eSAlex Deucher if (rdev->pm.current_power_state_index == rdev->pm.requested_power_state_index) 153bae6b562SAlex Deucher return; 154bae6b562SAlex Deucher 155a48b9b4eSAlex Deucher if (radeon_gui_idle(rdev)) { 156a48b9b4eSAlex Deucher 157a48b9b4eSAlex Deucher sclk = rdev->pm.power_state[rdev->pm.requested_power_state_index]. 158a48b9b4eSAlex Deucher clock_info[rdev->pm.requested_clock_mode_index].sclk; 159a48b9b4eSAlex Deucher if (sclk > rdev->clock.default_sclk) 160a48b9b4eSAlex Deucher sclk = rdev->clock.default_sclk; 161a48b9b4eSAlex Deucher 162a48b9b4eSAlex Deucher mclk = rdev->pm.power_state[rdev->pm.requested_power_state_index]. 163a48b9b4eSAlex Deucher clock_info[rdev->pm.requested_clock_mode_index].mclk; 164a48b9b4eSAlex Deucher if (mclk > rdev->clock.default_mclk) 165a48b9b4eSAlex Deucher mclk = rdev->clock.default_mclk; 166a48b9b4eSAlex Deucher /* don't change the mclk with multiple crtcs */ 167a48b9b4eSAlex Deucher if (rdev->pm.active_crtc_count > 1) 168a48b9b4eSAlex Deucher mclk = rdev->clock.default_mclk; 169bae6b562SAlex Deucher 170bae6b562SAlex Deucher /* set pcie lanes */ 171bae6b562SAlex Deucher /* TODO */ 172bae6b562SAlex Deucher 173bae6b562SAlex Deucher /* set voltage */ 174bae6b562SAlex Deucher /* TODO */ 175bae6b562SAlex Deucher 176bae6b562SAlex Deucher /* set engine clock */ 177a48b9b4eSAlex Deucher if (sclk != rdev->pm.current_sclk) { 178bae6b562SAlex Deucher radeon_sync_with_vblank(rdev); 179bae6b562SAlex Deucher radeon_pm_debug_check_in_vbl(rdev, false); 180a48b9b4eSAlex Deucher radeon_set_engine_clock(rdev, sclk); 181bae6b562SAlex Deucher radeon_pm_debug_check_in_vbl(rdev, true); 182a48b9b4eSAlex Deucher rdev->pm.current_sclk = sclk; 183a48b9b4eSAlex Deucher DRM_INFO("Setting: e: %d\n", sclk); 184a48b9b4eSAlex Deucher } 185bae6b562SAlex Deucher 186bae6b562SAlex Deucher #if 0 187bae6b562SAlex Deucher /* set memory clock */ 188a48b9b4eSAlex Deucher if (rdev->asic->set_memory_clock && (mclk != rdev->pm.current_mclk)) { 189bae6b562SAlex Deucher radeon_sync_with_vblank(rdev); 190bae6b562SAlex Deucher radeon_pm_debug_check_in_vbl(rdev, false); 191a48b9b4eSAlex Deucher radeon_set_memory_clock(rdev, mclk); 192bae6b562SAlex Deucher radeon_pm_debug_check_in_vbl(rdev, true); 193a48b9b4eSAlex Deucher rdev->pm.current_mclk = mclk; 194a48b9b4eSAlex Deucher DRM_INFO("Setting: m: %d\n", mclk); 195bae6b562SAlex Deucher } 196bae6b562SAlex Deucher #endif 197bae6b562SAlex Deucher 198a48b9b4eSAlex Deucher rdev->pm.current_power_state_index = rdev->pm.requested_power_state_index; 199a48b9b4eSAlex Deucher rdev->pm.current_clock_mode_index = rdev->pm.requested_clock_mode_index; 200a48b9b4eSAlex Deucher } else 201a48b9b4eSAlex Deucher DRM_INFO("GUI not idle!!!\n"); 202bae6b562SAlex Deucher } 203bae6b562SAlex Deucher 204*49e02b73SAlex Deucher void r100_pm_misc(struct radeon_device *rdev) 205*49e02b73SAlex Deucher { 206*49e02b73SAlex Deucher #if 0 207*49e02b73SAlex Deucher int requested_index = rdev->pm.requested_power_state_index; 208*49e02b73SAlex Deucher struct radeon_power_state *ps = &rdev->pm.power_state[requested_index]; 209*49e02b73SAlex Deucher struct radeon_voltage *voltage = &ps->clock_info[0].voltage; 210*49e02b73SAlex Deucher u32 tmp, sclk_cntl, sclk_cntl2, sclk_more_cntl; 211*49e02b73SAlex Deucher 212*49e02b73SAlex Deucher if ((voltage->type == VOLTAGE_GPIO) && (voltage->gpio.valid)) { 213*49e02b73SAlex Deucher if (ps->misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) { 214*49e02b73SAlex Deucher tmp = RREG32(voltage->gpio.reg); 215*49e02b73SAlex Deucher if (voltage->active_high) 216*49e02b73SAlex Deucher tmp |= voltage->gpio.mask; 217*49e02b73SAlex Deucher else 218*49e02b73SAlex Deucher tmp &= ~(voltage->gpio.mask); 219*49e02b73SAlex Deucher WREG32(voltage->gpio.reg, tmp); 220*49e02b73SAlex Deucher if (voltage->delay) 221*49e02b73SAlex Deucher udelay(voltage->delay); 222*49e02b73SAlex Deucher } else { 223*49e02b73SAlex Deucher tmp = RREG32(voltage->gpio.reg); 224*49e02b73SAlex Deucher if (voltage->active_high) 225*49e02b73SAlex Deucher tmp &= ~voltage->gpio.mask; 226*49e02b73SAlex Deucher else 227*49e02b73SAlex Deucher tmp |= voltage->gpio.mask; 228*49e02b73SAlex Deucher WREG32(voltage->gpio.reg, tmp); 229*49e02b73SAlex Deucher if (voltage->delay) 230*49e02b73SAlex Deucher udelay(voltage->delay); 231*49e02b73SAlex Deucher } 232*49e02b73SAlex Deucher } 233*49e02b73SAlex Deucher 234*49e02b73SAlex Deucher sclk_cntl = RREG32_PLL(SCLK_CNTL); 235*49e02b73SAlex Deucher sclk_cntl2 = RREG32_PLL(SCLK_CNTL2); 236*49e02b73SAlex Deucher sclk_cntl2 &= ~REDUCED_SPEED_SCLK_SEL(3); 237*49e02b73SAlex Deucher sclk_more_cntl = RREG32_PLL(SCLK_MORE_CNTL); 238*49e02b73SAlex Deucher sclk_more_cntl &= ~VOLTAGE_DELAY_SEL(3); 239*49e02b73SAlex Deucher if (ps->misc & ATOM_PM_MISCINFO_ASIC_REDUCED_SPEED_SCLK_EN) { 240*49e02b73SAlex Deucher sclk_more_cntl |= REDUCED_SPEED_SCLK_EN; 241*49e02b73SAlex Deucher if (ps->misc & ATOM_PM_MISCINFO_DYN_CLK_3D_IDLE) 242*49e02b73SAlex Deucher sclk_cntl2 |= REDUCED_SPEED_SCLK_MODE; 243*49e02b73SAlex Deucher else 244*49e02b73SAlex Deucher sclk_cntl2 &= ~REDUCED_SPEED_SCLK_MODE; 245*49e02b73SAlex Deucher if (ps->misc & ATOM_PM_MISCINFO_DYNAMIC_CLOCK_DIVIDER_BY_2) 246*49e02b73SAlex Deucher sclk_cntl2 |= REDUCED_SPEED_SCLK_SEL(0); 247*49e02b73SAlex Deucher else if (ps->misc & ATOM_PM_MISCINFO_DYNAMIC_CLOCK_DIVIDER_BY_4) 248*49e02b73SAlex Deucher sclk_cntl2 |= REDUCED_SPEED_SCLK_SEL(2); 249*49e02b73SAlex Deucher } else 250*49e02b73SAlex Deucher sclk_more_cntl &= ~REDUCED_SPEED_SCLK_EN; 251*49e02b73SAlex Deucher 252*49e02b73SAlex Deucher if (ps->misc & ATOM_PM_MISCINFO_ASIC_DYNAMIC_VOLTAGE_EN) { 253*49e02b73SAlex Deucher sclk_more_cntl |= IO_CG_VOLTAGE_DROP; 254*49e02b73SAlex Deucher if (voltage->delay) { 255*49e02b73SAlex Deucher sclk_more_cntl |= VOLTAGE_DROP_SYNC; 256*49e02b73SAlex Deucher switch (voltage->delay) { 257*49e02b73SAlex Deucher case 33: 258*49e02b73SAlex Deucher sclk_more_cntl |= VOLTAGE_DELAY_SEL(0); 259*49e02b73SAlex Deucher break; 260*49e02b73SAlex Deucher case 66: 261*49e02b73SAlex Deucher sclk_more_cntl |= VOLTAGE_DELAY_SEL(1); 262*49e02b73SAlex Deucher break; 263*49e02b73SAlex Deucher case 99: 264*49e02b73SAlex Deucher sclk_more_cntl |= VOLTAGE_DELAY_SEL(2); 265*49e02b73SAlex Deucher break; 266*49e02b73SAlex Deucher case 132: 267*49e02b73SAlex Deucher sclk_more_cntl |= VOLTAGE_DELAY_SEL(3); 268*49e02b73SAlex Deucher break; 269*49e02b73SAlex Deucher } 270*49e02b73SAlex Deucher } else 271*49e02b73SAlex Deucher sclk_more_cntl &= ~VOLTAGE_DROP_SYNC; 272*49e02b73SAlex Deucher } else 273*49e02b73SAlex Deucher sclk_more_cntl &= ~IO_CG_VOLTAGE_DROP; 274*49e02b73SAlex Deucher 275*49e02b73SAlex Deucher if (ps->misc & ATOM_PM_MISCINFO_DYNAMIC_HDP_BLOCK_EN) 276*49e02b73SAlex Deucher sclk_cntl &= ~FORCE_HDP; 277*49e02b73SAlex Deucher else 278*49e02b73SAlex Deucher sclk_cntl |= FORCE_HDP; 279*49e02b73SAlex Deucher 280*49e02b73SAlex Deucher WREG32_PLL(SCLK_CNTL, sclk_cntl); 281*49e02b73SAlex Deucher WREG32_PLL(SCLK_CNTL2, sclk_cntl2); 282*49e02b73SAlex Deucher WREG32_PLL(SCLK_MORE_CNTL, sclk_more_cntl); 283*49e02b73SAlex Deucher 284*49e02b73SAlex Deucher /* set pcie lanes */ 285*49e02b73SAlex Deucher if ((rdev->flags & RADEON_IS_PCIE) && 286*49e02b73SAlex Deucher !(rdev->flags & RADEON_IS_IGP) && 287*49e02b73SAlex Deucher rdev->asic->set_pcie_lanes && 288*49e02b73SAlex Deucher (ps->pcie_lanes != 289*49e02b73SAlex Deucher rdev->pm.power_state[rdev->pm.current_power_state_index].pcie_lanes)) { 290*49e02b73SAlex Deucher radeon_set_pcie_lanes(rdev, 291*49e02b73SAlex Deucher ps->pcie_lanes); 292*49e02b73SAlex Deucher DRM_INFO("Setting: p: %d\n", ps->pcie_lanes); 293*49e02b73SAlex Deucher } 294*49e02b73SAlex Deucher #endif 295*49e02b73SAlex Deucher } 296*49e02b73SAlex Deucher 297*49e02b73SAlex Deucher void r100_pm_prepare(struct radeon_device *rdev) 298*49e02b73SAlex Deucher { 299*49e02b73SAlex Deucher struct drm_device *ddev = rdev->ddev; 300*49e02b73SAlex Deucher struct drm_crtc *crtc; 301*49e02b73SAlex Deucher struct radeon_crtc *radeon_crtc; 302*49e02b73SAlex Deucher u32 tmp; 303*49e02b73SAlex Deucher 304*49e02b73SAlex Deucher /* disable any active CRTCs */ 305*49e02b73SAlex Deucher list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) { 306*49e02b73SAlex Deucher radeon_crtc = to_radeon_crtc(crtc); 307*49e02b73SAlex Deucher if (radeon_crtc->enabled) { 308*49e02b73SAlex Deucher if (radeon_crtc->crtc_id) { 309*49e02b73SAlex Deucher tmp = RREG32(RADEON_CRTC2_GEN_CNTL); 310*49e02b73SAlex Deucher tmp |= RADEON_CRTC2_DISP_REQ_EN_B; 311*49e02b73SAlex Deucher WREG32(RADEON_CRTC2_GEN_CNTL, tmp); 312*49e02b73SAlex Deucher } else { 313*49e02b73SAlex Deucher tmp = RREG32(RADEON_CRTC_GEN_CNTL); 314*49e02b73SAlex Deucher tmp |= RADEON_CRTC_DISP_REQ_EN_B; 315*49e02b73SAlex Deucher WREG32(RADEON_CRTC_GEN_CNTL, tmp); 316*49e02b73SAlex Deucher } 317*49e02b73SAlex Deucher } 318*49e02b73SAlex Deucher } 319*49e02b73SAlex Deucher } 320*49e02b73SAlex Deucher 321*49e02b73SAlex Deucher void r100_pm_finish(struct radeon_device *rdev) 322*49e02b73SAlex Deucher { 323*49e02b73SAlex Deucher struct drm_device *ddev = rdev->ddev; 324*49e02b73SAlex Deucher struct drm_crtc *crtc; 325*49e02b73SAlex Deucher struct radeon_crtc *radeon_crtc; 326*49e02b73SAlex Deucher u32 tmp; 327*49e02b73SAlex Deucher 328*49e02b73SAlex Deucher /* enable any active CRTCs */ 329*49e02b73SAlex Deucher list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) { 330*49e02b73SAlex Deucher radeon_crtc = to_radeon_crtc(crtc); 331*49e02b73SAlex Deucher if (radeon_crtc->enabled) { 332*49e02b73SAlex Deucher if (radeon_crtc->crtc_id) { 333*49e02b73SAlex Deucher tmp = RREG32(RADEON_CRTC2_GEN_CNTL); 334*49e02b73SAlex Deucher tmp &= ~RADEON_CRTC2_DISP_REQ_EN_B; 335*49e02b73SAlex Deucher WREG32(RADEON_CRTC2_GEN_CNTL, tmp); 336*49e02b73SAlex Deucher } else { 337*49e02b73SAlex Deucher tmp = RREG32(RADEON_CRTC_GEN_CNTL); 338*49e02b73SAlex Deucher tmp &= ~RADEON_CRTC_DISP_REQ_EN_B; 339*49e02b73SAlex Deucher WREG32(RADEON_CRTC_GEN_CNTL, tmp); 340*49e02b73SAlex Deucher } 341*49e02b73SAlex Deucher } 342*49e02b73SAlex Deucher } 343*49e02b73SAlex Deucher } 344*49e02b73SAlex Deucher 345def9ba9cSAlex Deucher bool r100_gui_idle(struct radeon_device *rdev) 346def9ba9cSAlex Deucher { 347def9ba9cSAlex Deucher if (RREG32(RADEON_RBBM_STATUS) & RADEON_RBBM_ACTIVE) 348def9ba9cSAlex Deucher return false; 349def9ba9cSAlex Deucher else 350def9ba9cSAlex Deucher return true; 351def9ba9cSAlex Deucher } 352def9ba9cSAlex Deucher 35305a05c50SAlex Deucher /* hpd for digital panel detect/disconnect */ 35405a05c50SAlex Deucher bool r100_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd) 35505a05c50SAlex Deucher { 35605a05c50SAlex Deucher bool connected = false; 35705a05c50SAlex Deucher 35805a05c50SAlex Deucher switch (hpd) { 35905a05c50SAlex Deucher case RADEON_HPD_1: 36005a05c50SAlex Deucher if (RREG32(RADEON_FP_GEN_CNTL) & RADEON_FP_DETECT_SENSE) 36105a05c50SAlex Deucher connected = true; 36205a05c50SAlex Deucher break; 36305a05c50SAlex Deucher case RADEON_HPD_2: 36405a05c50SAlex Deucher if (RREG32(RADEON_FP2_GEN_CNTL) & RADEON_FP2_DETECT_SENSE) 36505a05c50SAlex Deucher connected = true; 36605a05c50SAlex Deucher break; 36705a05c50SAlex Deucher default: 36805a05c50SAlex Deucher break; 36905a05c50SAlex Deucher } 37005a05c50SAlex Deucher return connected; 37105a05c50SAlex Deucher } 37205a05c50SAlex Deucher 37305a05c50SAlex Deucher void r100_hpd_set_polarity(struct radeon_device *rdev, 37405a05c50SAlex Deucher enum radeon_hpd_id hpd) 37505a05c50SAlex Deucher { 37605a05c50SAlex Deucher u32 tmp; 37705a05c50SAlex Deucher bool connected = r100_hpd_sense(rdev, hpd); 37805a05c50SAlex Deucher 37905a05c50SAlex Deucher switch (hpd) { 38005a05c50SAlex Deucher case RADEON_HPD_1: 38105a05c50SAlex Deucher tmp = RREG32(RADEON_FP_GEN_CNTL); 38205a05c50SAlex Deucher if (connected) 38305a05c50SAlex Deucher tmp &= ~RADEON_FP_DETECT_INT_POL; 38405a05c50SAlex Deucher else 38505a05c50SAlex Deucher tmp |= RADEON_FP_DETECT_INT_POL; 38605a05c50SAlex Deucher WREG32(RADEON_FP_GEN_CNTL, tmp); 38705a05c50SAlex Deucher break; 38805a05c50SAlex Deucher case RADEON_HPD_2: 38905a05c50SAlex Deucher tmp = RREG32(RADEON_FP2_GEN_CNTL); 39005a05c50SAlex Deucher if (connected) 39105a05c50SAlex Deucher tmp &= ~RADEON_FP2_DETECT_INT_POL; 39205a05c50SAlex Deucher else 39305a05c50SAlex Deucher tmp |= RADEON_FP2_DETECT_INT_POL; 39405a05c50SAlex Deucher WREG32(RADEON_FP2_GEN_CNTL, tmp); 39505a05c50SAlex Deucher break; 39605a05c50SAlex Deucher default: 39705a05c50SAlex Deucher break; 39805a05c50SAlex Deucher } 39905a05c50SAlex Deucher } 40005a05c50SAlex Deucher 40105a05c50SAlex Deucher void r100_hpd_init(struct radeon_device *rdev) 40205a05c50SAlex Deucher { 40305a05c50SAlex Deucher struct drm_device *dev = rdev->ddev; 40405a05c50SAlex Deucher struct drm_connector *connector; 40505a05c50SAlex Deucher 40605a05c50SAlex Deucher list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 40705a05c50SAlex Deucher struct radeon_connector *radeon_connector = to_radeon_connector(connector); 40805a05c50SAlex Deucher switch (radeon_connector->hpd.hpd) { 40905a05c50SAlex Deucher case RADEON_HPD_1: 41005a05c50SAlex Deucher rdev->irq.hpd[0] = true; 41105a05c50SAlex Deucher break; 41205a05c50SAlex Deucher case RADEON_HPD_2: 41305a05c50SAlex Deucher rdev->irq.hpd[1] = true; 41405a05c50SAlex Deucher break; 41505a05c50SAlex Deucher default: 41605a05c50SAlex Deucher break; 41705a05c50SAlex Deucher } 41805a05c50SAlex Deucher } 419003e69f9SJerome Glisse if (rdev->irq.installed) 42005a05c50SAlex Deucher r100_irq_set(rdev); 42105a05c50SAlex Deucher } 42205a05c50SAlex Deucher 42305a05c50SAlex Deucher void r100_hpd_fini(struct radeon_device *rdev) 42405a05c50SAlex Deucher { 42505a05c50SAlex Deucher struct drm_device *dev = rdev->ddev; 42605a05c50SAlex Deucher struct drm_connector *connector; 42705a05c50SAlex Deucher 42805a05c50SAlex Deucher list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 42905a05c50SAlex Deucher struct radeon_connector *radeon_connector = to_radeon_connector(connector); 43005a05c50SAlex Deucher switch (radeon_connector->hpd.hpd) { 43105a05c50SAlex Deucher case RADEON_HPD_1: 43205a05c50SAlex Deucher rdev->irq.hpd[0] = false; 43305a05c50SAlex Deucher break; 43405a05c50SAlex Deucher case RADEON_HPD_2: 43505a05c50SAlex Deucher rdev->irq.hpd[1] = false; 43605a05c50SAlex Deucher break; 43705a05c50SAlex Deucher default: 43805a05c50SAlex Deucher break; 43905a05c50SAlex Deucher } 44005a05c50SAlex Deucher } 44105a05c50SAlex Deucher } 44205a05c50SAlex Deucher 443771fe6b9SJerome Glisse /* 444771fe6b9SJerome Glisse * PCI GART 445771fe6b9SJerome Glisse */ 446771fe6b9SJerome Glisse void r100_pci_gart_tlb_flush(struct radeon_device *rdev) 447771fe6b9SJerome Glisse { 448771fe6b9SJerome Glisse /* TODO: can we do somethings here ? */ 449771fe6b9SJerome Glisse /* It seems hw only cache one entry so we should discard this 450771fe6b9SJerome Glisse * entry otherwise if first GPU GART read hit this entry it 451771fe6b9SJerome Glisse * could end up in wrong address. */ 452771fe6b9SJerome Glisse } 453771fe6b9SJerome Glisse 4544aac0473SJerome Glisse int r100_pci_gart_init(struct radeon_device *rdev) 4554aac0473SJerome Glisse { 4564aac0473SJerome Glisse int r; 4574aac0473SJerome Glisse 4584aac0473SJerome Glisse if (rdev->gart.table.ram.ptr) { 4594aac0473SJerome Glisse WARN(1, "R100 PCI GART already initialized.\n"); 4604aac0473SJerome Glisse return 0; 4614aac0473SJerome Glisse } 4624aac0473SJerome Glisse /* Initialize common gart structure */ 4634aac0473SJerome Glisse r = radeon_gart_init(rdev); 4644aac0473SJerome Glisse if (r) 4654aac0473SJerome Glisse return r; 4664aac0473SJerome Glisse rdev->gart.table_size = rdev->gart.num_gpu_pages * 4; 4674aac0473SJerome Glisse rdev->asic->gart_tlb_flush = &r100_pci_gart_tlb_flush; 4684aac0473SJerome Glisse rdev->asic->gart_set_page = &r100_pci_gart_set_page; 4694aac0473SJerome Glisse return radeon_gart_table_ram_alloc(rdev); 4704aac0473SJerome Glisse } 4714aac0473SJerome Glisse 47217e15b0cSDave Airlie /* required on r1xx, r2xx, r300, r(v)350, r420/r481, rs400/rs480 */ 47317e15b0cSDave Airlie void r100_enable_bm(struct radeon_device *rdev) 47417e15b0cSDave Airlie { 47517e15b0cSDave Airlie uint32_t tmp; 47617e15b0cSDave Airlie /* Enable bus mastering */ 47717e15b0cSDave Airlie tmp = RREG32(RADEON_BUS_CNTL) & ~RADEON_BUS_MASTER_DIS; 47817e15b0cSDave Airlie WREG32(RADEON_BUS_CNTL, tmp); 47917e15b0cSDave Airlie } 48017e15b0cSDave Airlie 481771fe6b9SJerome Glisse int r100_pci_gart_enable(struct radeon_device *rdev) 482771fe6b9SJerome Glisse { 483771fe6b9SJerome Glisse uint32_t tmp; 484771fe6b9SJerome Glisse 48582568565SDave Airlie radeon_gart_restore(rdev); 486771fe6b9SJerome Glisse /* discard memory request outside of configured range */ 487771fe6b9SJerome Glisse tmp = RREG32(RADEON_AIC_CNTL) | RADEON_DIS_OUT_OF_PCI_GART_ACCESS; 488771fe6b9SJerome Glisse WREG32(RADEON_AIC_CNTL, tmp); 489771fe6b9SJerome Glisse /* set address range for PCI address translate */ 490d594e46aSJerome Glisse WREG32(RADEON_AIC_LO_ADDR, rdev->mc.gtt_start); 491d594e46aSJerome Glisse WREG32(RADEON_AIC_HI_ADDR, rdev->mc.gtt_end); 492771fe6b9SJerome Glisse /* set PCI GART page-table base address */ 493771fe6b9SJerome Glisse WREG32(RADEON_AIC_PT_BASE, rdev->gart.table_addr); 494771fe6b9SJerome Glisse tmp = RREG32(RADEON_AIC_CNTL) | RADEON_PCIGART_TRANSLATE_EN; 495771fe6b9SJerome Glisse WREG32(RADEON_AIC_CNTL, tmp); 496771fe6b9SJerome Glisse r100_pci_gart_tlb_flush(rdev); 497771fe6b9SJerome Glisse rdev->gart.ready = true; 498771fe6b9SJerome Glisse return 0; 499771fe6b9SJerome Glisse } 500771fe6b9SJerome Glisse 501771fe6b9SJerome Glisse void r100_pci_gart_disable(struct radeon_device *rdev) 502771fe6b9SJerome Glisse { 503771fe6b9SJerome Glisse uint32_t tmp; 504771fe6b9SJerome Glisse 505771fe6b9SJerome Glisse /* discard memory request outside of configured range */ 506771fe6b9SJerome Glisse tmp = RREG32(RADEON_AIC_CNTL) | RADEON_DIS_OUT_OF_PCI_GART_ACCESS; 507771fe6b9SJerome Glisse WREG32(RADEON_AIC_CNTL, tmp & ~RADEON_PCIGART_TRANSLATE_EN); 508771fe6b9SJerome Glisse WREG32(RADEON_AIC_LO_ADDR, 0); 509771fe6b9SJerome Glisse WREG32(RADEON_AIC_HI_ADDR, 0); 510771fe6b9SJerome Glisse } 511771fe6b9SJerome Glisse 512771fe6b9SJerome Glisse int r100_pci_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr) 513771fe6b9SJerome Glisse { 514771fe6b9SJerome Glisse if (i < 0 || i > rdev->gart.num_gpu_pages) { 515771fe6b9SJerome Glisse return -EINVAL; 516771fe6b9SJerome Glisse } 517ed10f95dSDave Airlie rdev->gart.table.ram.ptr[i] = cpu_to_le32(lower_32_bits(addr)); 518771fe6b9SJerome Glisse return 0; 519771fe6b9SJerome Glisse } 520771fe6b9SJerome Glisse 5214aac0473SJerome Glisse void r100_pci_gart_fini(struct radeon_device *rdev) 522771fe6b9SJerome Glisse { 523f9274562SJerome Glisse radeon_gart_fini(rdev); 524771fe6b9SJerome Glisse r100_pci_gart_disable(rdev); 5254aac0473SJerome Glisse radeon_gart_table_ram_free(rdev); 526771fe6b9SJerome Glisse } 527771fe6b9SJerome Glisse 5287ed220d7SMichel Dänzer int r100_irq_set(struct radeon_device *rdev) 5297ed220d7SMichel Dänzer { 5307ed220d7SMichel Dänzer uint32_t tmp = 0; 5317ed220d7SMichel Dänzer 532003e69f9SJerome Glisse if (!rdev->irq.installed) { 533003e69f9SJerome Glisse WARN(1, "Can't enable IRQ/MSI because no handler is installed.\n"); 534003e69f9SJerome Glisse WREG32(R_000040_GEN_INT_CNTL, 0); 535003e69f9SJerome Glisse return -EINVAL; 536003e69f9SJerome Glisse } 5377ed220d7SMichel Dänzer if (rdev->irq.sw_int) { 5387ed220d7SMichel Dänzer tmp |= RADEON_SW_INT_ENABLE; 5397ed220d7SMichel Dänzer } 5402031f77cSAlex Deucher if (rdev->irq.gui_idle) { 5412031f77cSAlex Deucher tmp |= RADEON_GUI_IDLE_MASK; 5422031f77cSAlex Deucher } 5437ed220d7SMichel Dänzer if (rdev->irq.crtc_vblank_int[0]) { 5447ed220d7SMichel Dänzer tmp |= RADEON_CRTC_VBLANK_MASK; 5457ed220d7SMichel Dänzer } 5467ed220d7SMichel Dänzer if (rdev->irq.crtc_vblank_int[1]) { 5477ed220d7SMichel Dänzer tmp |= RADEON_CRTC2_VBLANK_MASK; 5487ed220d7SMichel Dänzer } 54905a05c50SAlex Deucher if (rdev->irq.hpd[0]) { 55005a05c50SAlex Deucher tmp |= RADEON_FP_DETECT_MASK; 55105a05c50SAlex Deucher } 55205a05c50SAlex Deucher if (rdev->irq.hpd[1]) { 55305a05c50SAlex Deucher tmp |= RADEON_FP2_DETECT_MASK; 55405a05c50SAlex Deucher } 5557ed220d7SMichel Dänzer WREG32(RADEON_GEN_INT_CNTL, tmp); 5567ed220d7SMichel Dänzer return 0; 5577ed220d7SMichel Dänzer } 5587ed220d7SMichel Dänzer 5599f022ddfSJerome Glisse void r100_irq_disable(struct radeon_device *rdev) 5609f022ddfSJerome Glisse { 5619f022ddfSJerome Glisse u32 tmp; 5629f022ddfSJerome Glisse 5639f022ddfSJerome Glisse WREG32(R_000040_GEN_INT_CNTL, 0); 5649f022ddfSJerome Glisse /* Wait and acknowledge irq */ 5659f022ddfSJerome Glisse mdelay(1); 5669f022ddfSJerome Glisse tmp = RREG32(R_000044_GEN_INT_STATUS); 5679f022ddfSJerome Glisse WREG32(R_000044_GEN_INT_STATUS, tmp); 5689f022ddfSJerome Glisse } 5699f022ddfSJerome Glisse 5707ed220d7SMichel Dänzer static inline uint32_t r100_irq_ack(struct radeon_device *rdev) 5717ed220d7SMichel Dänzer { 5727ed220d7SMichel Dänzer uint32_t irqs = RREG32(RADEON_GEN_INT_STATUS); 57305a05c50SAlex Deucher uint32_t irq_mask = RADEON_SW_INT_TEST | 57405a05c50SAlex Deucher RADEON_CRTC_VBLANK_STAT | RADEON_CRTC2_VBLANK_STAT | 57505a05c50SAlex Deucher RADEON_FP_DETECT_STAT | RADEON_FP2_DETECT_STAT; 5767ed220d7SMichel Dänzer 5772031f77cSAlex Deucher /* the interrupt works, but the status bit is permanently asserted */ 5782031f77cSAlex Deucher if (rdev->irq.gui_idle && radeon_gui_idle(rdev)) { 5792031f77cSAlex Deucher if (!rdev->irq.gui_idle_acked) 5802031f77cSAlex Deucher irq_mask |= RADEON_GUI_IDLE_STAT; 5812031f77cSAlex Deucher } 5822031f77cSAlex Deucher 5837ed220d7SMichel Dänzer if (irqs) { 5847ed220d7SMichel Dänzer WREG32(RADEON_GEN_INT_STATUS, irqs); 5857ed220d7SMichel Dänzer } 5867ed220d7SMichel Dänzer return irqs & irq_mask; 5877ed220d7SMichel Dänzer } 5887ed220d7SMichel Dänzer 5897ed220d7SMichel Dänzer int r100_irq_process(struct radeon_device *rdev) 5907ed220d7SMichel Dänzer { 5913e5cb98dSAlex Deucher uint32_t status, msi_rearm; 592d4877cf2SAlex Deucher bool queue_hotplug = false; 5937ed220d7SMichel Dänzer 5942031f77cSAlex Deucher /* reset gui idle ack. the status bit is broken */ 5952031f77cSAlex Deucher rdev->irq.gui_idle_acked = false; 5962031f77cSAlex Deucher 5977ed220d7SMichel Dänzer status = r100_irq_ack(rdev); 5987ed220d7SMichel Dänzer if (!status) { 5997ed220d7SMichel Dänzer return IRQ_NONE; 6007ed220d7SMichel Dänzer } 601a513c184SJerome Glisse if (rdev->shutdown) { 602a513c184SJerome Glisse return IRQ_NONE; 603a513c184SJerome Glisse } 6047ed220d7SMichel Dänzer while (status) { 6057ed220d7SMichel Dänzer /* SW interrupt */ 6067ed220d7SMichel Dänzer if (status & RADEON_SW_INT_TEST) { 6077ed220d7SMichel Dänzer radeon_fence_process(rdev); 6087ed220d7SMichel Dänzer } 6092031f77cSAlex Deucher /* gui idle interrupt */ 6102031f77cSAlex Deucher if (status & RADEON_GUI_IDLE_STAT) { 6112031f77cSAlex Deucher rdev->irq.gui_idle_acked = true; 6122031f77cSAlex Deucher rdev->pm.gui_idle = true; 6132031f77cSAlex Deucher wake_up(&rdev->irq.idle_queue); 6142031f77cSAlex Deucher } 6157ed220d7SMichel Dänzer /* Vertical blank interrupts */ 6167ed220d7SMichel Dänzer if (status & RADEON_CRTC_VBLANK_STAT) { 6177ed220d7SMichel Dänzer drm_handle_vblank(rdev->ddev, 0); 618839461d3SRafał Miłecki rdev->pm.vblank_sync = true; 61973a6d3fcSRafał Miłecki wake_up(&rdev->irq.vblank_queue); 6207ed220d7SMichel Dänzer } 6217ed220d7SMichel Dänzer if (status & RADEON_CRTC2_VBLANK_STAT) { 6227ed220d7SMichel Dänzer drm_handle_vblank(rdev->ddev, 1); 623839461d3SRafał Miłecki rdev->pm.vblank_sync = true; 62473a6d3fcSRafał Miłecki wake_up(&rdev->irq.vblank_queue); 6257ed220d7SMichel Dänzer } 62605a05c50SAlex Deucher if (status & RADEON_FP_DETECT_STAT) { 627d4877cf2SAlex Deucher queue_hotplug = true; 628d4877cf2SAlex Deucher DRM_DEBUG("HPD1\n"); 62905a05c50SAlex Deucher } 63005a05c50SAlex Deucher if (status & RADEON_FP2_DETECT_STAT) { 631d4877cf2SAlex Deucher queue_hotplug = true; 632d4877cf2SAlex Deucher DRM_DEBUG("HPD2\n"); 63305a05c50SAlex Deucher } 6347ed220d7SMichel Dänzer status = r100_irq_ack(rdev); 6357ed220d7SMichel Dänzer } 6362031f77cSAlex Deucher /* reset gui idle ack. the status bit is broken */ 6372031f77cSAlex Deucher rdev->irq.gui_idle_acked = false; 638d4877cf2SAlex Deucher if (queue_hotplug) 639d4877cf2SAlex Deucher queue_work(rdev->wq, &rdev->hotplug_work); 6403e5cb98dSAlex Deucher if (rdev->msi_enabled) { 6413e5cb98dSAlex Deucher switch (rdev->family) { 6423e5cb98dSAlex Deucher case CHIP_RS400: 6433e5cb98dSAlex Deucher case CHIP_RS480: 6443e5cb98dSAlex Deucher msi_rearm = RREG32(RADEON_AIC_CNTL) & ~RS400_MSI_REARM; 6453e5cb98dSAlex Deucher WREG32(RADEON_AIC_CNTL, msi_rearm); 6463e5cb98dSAlex Deucher WREG32(RADEON_AIC_CNTL, msi_rearm | RS400_MSI_REARM); 6473e5cb98dSAlex Deucher break; 6483e5cb98dSAlex Deucher default: 6493e5cb98dSAlex Deucher msi_rearm = RREG32(RADEON_MSI_REARM_EN) & ~RV370_MSI_REARM_EN; 6503e5cb98dSAlex Deucher WREG32(RADEON_MSI_REARM_EN, msi_rearm); 6513e5cb98dSAlex Deucher WREG32(RADEON_MSI_REARM_EN, msi_rearm | RV370_MSI_REARM_EN); 6523e5cb98dSAlex Deucher break; 6533e5cb98dSAlex Deucher } 6543e5cb98dSAlex Deucher } 6557ed220d7SMichel Dänzer return IRQ_HANDLED; 6567ed220d7SMichel Dänzer } 6577ed220d7SMichel Dänzer 6587ed220d7SMichel Dänzer u32 r100_get_vblank_counter(struct radeon_device *rdev, int crtc) 6597ed220d7SMichel Dänzer { 6607ed220d7SMichel Dänzer if (crtc == 0) 6617ed220d7SMichel Dänzer return RREG32(RADEON_CRTC_CRNT_FRAME); 6627ed220d7SMichel Dänzer else 6637ed220d7SMichel Dänzer return RREG32(RADEON_CRTC2_CRNT_FRAME); 6647ed220d7SMichel Dänzer } 6657ed220d7SMichel Dänzer 6669e5b2af7SPauli Nieminen /* Who ever call radeon_fence_emit should call ring_lock and ask 6679e5b2af7SPauli Nieminen * for enough space (today caller are ib schedule and buffer move) */ 668771fe6b9SJerome Glisse void r100_fence_ring_emit(struct radeon_device *rdev, 669771fe6b9SJerome Glisse struct radeon_fence *fence) 670771fe6b9SJerome Glisse { 6719e5b2af7SPauli Nieminen /* We have to make sure that caches are flushed before 6729e5b2af7SPauli Nieminen * CPU might read something from VRAM. */ 6739e5b2af7SPauli Nieminen radeon_ring_write(rdev, PACKET0(RADEON_RB3D_DSTCACHE_CTLSTAT, 0)); 6749e5b2af7SPauli Nieminen radeon_ring_write(rdev, RADEON_RB3D_DC_FLUSH_ALL); 6759e5b2af7SPauli Nieminen radeon_ring_write(rdev, PACKET0(RADEON_RB3D_ZCACHE_CTLSTAT, 0)); 6769e5b2af7SPauli Nieminen radeon_ring_write(rdev, RADEON_RB3D_ZC_FLUSH_ALL); 677771fe6b9SJerome Glisse /* Wait until IDLE & CLEAN */ 6784612dc97SAlex Deucher radeon_ring_write(rdev, PACKET0(RADEON_WAIT_UNTIL, 0)); 6794612dc97SAlex Deucher radeon_ring_write(rdev, RADEON_WAIT_2D_IDLECLEAN | RADEON_WAIT_3D_IDLECLEAN); 680cafe6609SJerome Glisse radeon_ring_write(rdev, PACKET0(RADEON_HOST_PATH_CNTL, 0)); 681cafe6609SJerome Glisse radeon_ring_write(rdev, rdev->config.r100.hdp_cntl | 682cafe6609SJerome Glisse RADEON_HDP_READ_BUFFER_INVALIDATE); 683cafe6609SJerome Glisse radeon_ring_write(rdev, PACKET0(RADEON_HOST_PATH_CNTL, 0)); 684cafe6609SJerome Glisse radeon_ring_write(rdev, rdev->config.r100.hdp_cntl); 685771fe6b9SJerome Glisse /* Emit fence sequence & fire IRQ */ 686771fe6b9SJerome Glisse radeon_ring_write(rdev, PACKET0(rdev->fence_drv.scratch_reg, 0)); 687771fe6b9SJerome Glisse radeon_ring_write(rdev, fence->seq); 688771fe6b9SJerome Glisse radeon_ring_write(rdev, PACKET0(RADEON_GEN_INT_STATUS, 0)); 689771fe6b9SJerome Glisse radeon_ring_write(rdev, RADEON_SW_INT_FIRE); 690771fe6b9SJerome Glisse } 691771fe6b9SJerome Glisse 692771fe6b9SJerome Glisse int r100_wb_init(struct radeon_device *rdev) 693771fe6b9SJerome Glisse { 694771fe6b9SJerome Glisse int r; 695771fe6b9SJerome Glisse 696771fe6b9SJerome Glisse if (rdev->wb.wb_obj == NULL) { 6974c788679SJerome Glisse r = radeon_bo_create(rdev, NULL, RADEON_GPU_PAGE_SIZE, true, 698771fe6b9SJerome Glisse RADEON_GEM_DOMAIN_GTT, 6994c788679SJerome Glisse &rdev->wb.wb_obj); 700771fe6b9SJerome Glisse if (r) { 7014c788679SJerome Glisse dev_err(rdev->dev, "(%d) create WB buffer failed\n", r); 702771fe6b9SJerome Glisse return r; 703771fe6b9SJerome Glisse } 7044c788679SJerome Glisse r = radeon_bo_reserve(rdev->wb.wb_obj, false); 7054c788679SJerome Glisse if (unlikely(r != 0)) 7064c788679SJerome Glisse return r; 7074c788679SJerome Glisse r = radeon_bo_pin(rdev->wb.wb_obj, RADEON_GEM_DOMAIN_GTT, 708771fe6b9SJerome Glisse &rdev->wb.gpu_addr); 709771fe6b9SJerome Glisse if (r) { 7104c788679SJerome Glisse dev_err(rdev->dev, "(%d) pin WB buffer failed\n", r); 7114c788679SJerome Glisse radeon_bo_unreserve(rdev->wb.wb_obj); 712771fe6b9SJerome Glisse return r; 713771fe6b9SJerome Glisse } 7144c788679SJerome Glisse r = radeon_bo_kmap(rdev->wb.wb_obj, (void **)&rdev->wb.wb); 7154c788679SJerome Glisse radeon_bo_unreserve(rdev->wb.wb_obj); 716771fe6b9SJerome Glisse if (r) { 7174c788679SJerome Glisse dev_err(rdev->dev, "(%d) map WB buffer failed\n", r); 718771fe6b9SJerome Glisse return r; 719771fe6b9SJerome Glisse } 720771fe6b9SJerome Glisse } 7219f022ddfSJerome Glisse WREG32(R_000774_SCRATCH_ADDR, rdev->wb.gpu_addr); 7229f022ddfSJerome Glisse WREG32(R_00070C_CP_RB_RPTR_ADDR, 7239f022ddfSJerome Glisse S_00070C_RB_RPTR_ADDR((rdev->wb.gpu_addr + 1024) >> 2)); 7249f022ddfSJerome Glisse WREG32(R_000770_SCRATCH_UMSK, 0xff); 725771fe6b9SJerome Glisse return 0; 726771fe6b9SJerome Glisse } 727771fe6b9SJerome Glisse 7289f022ddfSJerome Glisse void r100_wb_disable(struct radeon_device *rdev) 7299f022ddfSJerome Glisse { 7309f022ddfSJerome Glisse WREG32(R_000770_SCRATCH_UMSK, 0); 7319f022ddfSJerome Glisse } 7329f022ddfSJerome Glisse 733771fe6b9SJerome Glisse void r100_wb_fini(struct radeon_device *rdev) 734771fe6b9SJerome Glisse { 7354c788679SJerome Glisse int r; 7364c788679SJerome Glisse 7379f022ddfSJerome Glisse r100_wb_disable(rdev); 738771fe6b9SJerome Glisse if (rdev->wb.wb_obj) { 7394c788679SJerome Glisse r = radeon_bo_reserve(rdev->wb.wb_obj, false); 7404c788679SJerome Glisse if (unlikely(r != 0)) { 7414c788679SJerome Glisse dev_err(rdev->dev, "(%d) can't finish WB\n", r); 7424c788679SJerome Glisse return; 7434c788679SJerome Glisse } 7444c788679SJerome Glisse radeon_bo_kunmap(rdev->wb.wb_obj); 7454c788679SJerome Glisse radeon_bo_unpin(rdev->wb.wb_obj); 7464c788679SJerome Glisse radeon_bo_unreserve(rdev->wb.wb_obj); 7474c788679SJerome Glisse radeon_bo_unref(&rdev->wb.wb_obj); 748771fe6b9SJerome Glisse rdev->wb.wb = NULL; 749771fe6b9SJerome Glisse rdev->wb.wb_obj = NULL; 750771fe6b9SJerome Glisse } 751771fe6b9SJerome Glisse } 752771fe6b9SJerome Glisse 753771fe6b9SJerome Glisse int r100_copy_blit(struct radeon_device *rdev, 754771fe6b9SJerome Glisse uint64_t src_offset, 755771fe6b9SJerome Glisse uint64_t dst_offset, 756771fe6b9SJerome Glisse unsigned num_pages, 757771fe6b9SJerome Glisse struct radeon_fence *fence) 758771fe6b9SJerome Glisse { 759771fe6b9SJerome Glisse uint32_t cur_pages; 760771fe6b9SJerome Glisse uint32_t stride_bytes = PAGE_SIZE; 761771fe6b9SJerome Glisse uint32_t pitch; 762771fe6b9SJerome Glisse uint32_t stride_pixels; 763771fe6b9SJerome Glisse unsigned ndw; 764771fe6b9SJerome Glisse int num_loops; 765771fe6b9SJerome Glisse int r = 0; 766771fe6b9SJerome Glisse 767771fe6b9SJerome Glisse /* radeon limited to 16k stride */ 768771fe6b9SJerome Glisse stride_bytes &= 0x3fff; 769771fe6b9SJerome Glisse /* radeon pitch is /64 */ 770771fe6b9SJerome Glisse pitch = stride_bytes / 64; 771771fe6b9SJerome Glisse stride_pixels = stride_bytes / 4; 772771fe6b9SJerome Glisse num_loops = DIV_ROUND_UP(num_pages, 8191); 773771fe6b9SJerome Glisse 774771fe6b9SJerome Glisse /* Ask for enough room for blit + flush + fence */ 775771fe6b9SJerome Glisse ndw = 64 + (10 * num_loops); 776771fe6b9SJerome Glisse r = radeon_ring_lock(rdev, ndw); 777771fe6b9SJerome Glisse if (r) { 778771fe6b9SJerome Glisse DRM_ERROR("radeon: moving bo (%d) asking for %u dw.\n", r, ndw); 779771fe6b9SJerome Glisse return -EINVAL; 780771fe6b9SJerome Glisse } 781771fe6b9SJerome Glisse while (num_pages > 0) { 782771fe6b9SJerome Glisse cur_pages = num_pages; 783771fe6b9SJerome Glisse if (cur_pages > 8191) { 784771fe6b9SJerome Glisse cur_pages = 8191; 785771fe6b9SJerome Glisse } 786771fe6b9SJerome Glisse num_pages -= cur_pages; 787771fe6b9SJerome Glisse 788771fe6b9SJerome Glisse /* pages are in Y direction - height 789771fe6b9SJerome Glisse page width in X direction - width */ 790771fe6b9SJerome Glisse radeon_ring_write(rdev, PACKET3(PACKET3_BITBLT_MULTI, 8)); 791771fe6b9SJerome Glisse radeon_ring_write(rdev, 792771fe6b9SJerome Glisse RADEON_GMC_SRC_PITCH_OFFSET_CNTL | 793771fe6b9SJerome Glisse RADEON_GMC_DST_PITCH_OFFSET_CNTL | 794771fe6b9SJerome Glisse RADEON_GMC_SRC_CLIPPING | 795771fe6b9SJerome Glisse RADEON_GMC_DST_CLIPPING | 796771fe6b9SJerome Glisse RADEON_GMC_BRUSH_NONE | 797771fe6b9SJerome Glisse (RADEON_COLOR_FORMAT_ARGB8888 << 8) | 798771fe6b9SJerome Glisse RADEON_GMC_SRC_DATATYPE_COLOR | 799771fe6b9SJerome Glisse RADEON_ROP3_S | 800771fe6b9SJerome Glisse RADEON_DP_SRC_SOURCE_MEMORY | 801771fe6b9SJerome Glisse RADEON_GMC_CLR_CMP_CNTL_DIS | 802771fe6b9SJerome Glisse RADEON_GMC_WR_MSK_DIS); 803771fe6b9SJerome Glisse radeon_ring_write(rdev, (pitch << 22) | (src_offset >> 10)); 804771fe6b9SJerome Glisse radeon_ring_write(rdev, (pitch << 22) | (dst_offset >> 10)); 805771fe6b9SJerome Glisse radeon_ring_write(rdev, (0x1fff) | (0x1fff << 16)); 806771fe6b9SJerome Glisse radeon_ring_write(rdev, 0); 807771fe6b9SJerome Glisse radeon_ring_write(rdev, (0x1fff) | (0x1fff << 16)); 808771fe6b9SJerome Glisse radeon_ring_write(rdev, num_pages); 809771fe6b9SJerome Glisse radeon_ring_write(rdev, num_pages); 810771fe6b9SJerome Glisse radeon_ring_write(rdev, cur_pages | (stride_pixels << 16)); 811771fe6b9SJerome Glisse } 812771fe6b9SJerome Glisse radeon_ring_write(rdev, PACKET0(RADEON_DSTCACHE_CTLSTAT, 0)); 813771fe6b9SJerome Glisse radeon_ring_write(rdev, RADEON_RB2D_DC_FLUSH_ALL); 814771fe6b9SJerome Glisse radeon_ring_write(rdev, PACKET0(RADEON_WAIT_UNTIL, 0)); 815771fe6b9SJerome Glisse radeon_ring_write(rdev, 816771fe6b9SJerome Glisse RADEON_WAIT_2D_IDLECLEAN | 817771fe6b9SJerome Glisse RADEON_WAIT_HOST_IDLECLEAN | 818771fe6b9SJerome Glisse RADEON_WAIT_DMA_GUI_IDLE); 819771fe6b9SJerome Glisse if (fence) { 820771fe6b9SJerome Glisse r = radeon_fence_emit(rdev, fence); 821771fe6b9SJerome Glisse } 822771fe6b9SJerome Glisse radeon_ring_unlock_commit(rdev); 823771fe6b9SJerome Glisse return r; 824771fe6b9SJerome Glisse } 825771fe6b9SJerome Glisse 82645600232SJerome Glisse static int r100_cp_wait_for_idle(struct radeon_device *rdev) 82745600232SJerome Glisse { 82845600232SJerome Glisse unsigned i; 82945600232SJerome Glisse u32 tmp; 83045600232SJerome Glisse 83145600232SJerome Glisse for (i = 0; i < rdev->usec_timeout; i++) { 83245600232SJerome Glisse tmp = RREG32(R_000E40_RBBM_STATUS); 83345600232SJerome Glisse if (!G_000E40_CP_CMDSTRM_BUSY(tmp)) { 83445600232SJerome Glisse return 0; 83545600232SJerome Glisse } 83645600232SJerome Glisse udelay(1); 83745600232SJerome Glisse } 83845600232SJerome Glisse return -1; 83945600232SJerome Glisse } 84045600232SJerome Glisse 841771fe6b9SJerome Glisse void r100_ring_start(struct radeon_device *rdev) 842771fe6b9SJerome Glisse { 843771fe6b9SJerome Glisse int r; 844771fe6b9SJerome Glisse 845771fe6b9SJerome Glisse r = radeon_ring_lock(rdev, 2); 846771fe6b9SJerome Glisse if (r) { 847771fe6b9SJerome Glisse return; 848771fe6b9SJerome Glisse } 849771fe6b9SJerome Glisse radeon_ring_write(rdev, PACKET0(RADEON_ISYNC_CNTL, 0)); 850771fe6b9SJerome Glisse radeon_ring_write(rdev, 851771fe6b9SJerome Glisse RADEON_ISYNC_ANY2D_IDLE3D | 852771fe6b9SJerome Glisse RADEON_ISYNC_ANY3D_IDLE2D | 853771fe6b9SJerome Glisse RADEON_ISYNC_WAIT_IDLEGUI | 854771fe6b9SJerome Glisse RADEON_ISYNC_CPSCRATCH_IDLEGUI); 855771fe6b9SJerome Glisse radeon_ring_unlock_commit(rdev); 856771fe6b9SJerome Glisse } 857771fe6b9SJerome Glisse 85870967ab9SBen Hutchings 85970967ab9SBen Hutchings /* Load the microcode for the CP */ 86070967ab9SBen Hutchings static int r100_cp_init_microcode(struct radeon_device *rdev) 861771fe6b9SJerome Glisse { 86270967ab9SBen Hutchings struct platform_device *pdev; 86370967ab9SBen Hutchings const char *fw_name = NULL; 86470967ab9SBen Hutchings int err; 865771fe6b9SJerome Glisse 86670967ab9SBen Hutchings DRM_DEBUG("\n"); 86770967ab9SBen Hutchings 86870967ab9SBen Hutchings pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0); 86970967ab9SBen Hutchings err = IS_ERR(pdev); 87070967ab9SBen Hutchings if (err) { 87170967ab9SBen Hutchings printk(KERN_ERR "radeon_cp: Failed to register firmware\n"); 87270967ab9SBen Hutchings return -EINVAL; 873771fe6b9SJerome Glisse } 874771fe6b9SJerome Glisse if ((rdev->family == CHIP_R100) || (rdev->family == CHIP_RV100) || 875771fe6b9SJerome Glisse (rdev->family == CHIP_RV200) || (rdev->family == CHIP_RS100) || 876771fe6b9SJerome Glisse (rdev->family == CHIP_RS200)) { 877771fe6b9SJerome Glisse DRM_INFO("Loading R100 Microcode\n"); 87870967ab9SBen Hutchings fw_name = FIRMWARE_R100; 879771fe6b9SJerome Glisse } else if ((rdev->family == CHIP_R200) || 880771fe6b9SJerome Glisse (rdev->family == CHIP_RV250) || 881771fe6b9SJerome Glisse (rdev->family == CHIP_RV280) || 882771fe6b9SJerome Glisse (rdev->family == CHIP_RS300)) { 883771fe6b9SJerome Glisse DRM_INFO("Loading R200 Microcode\n"); 88470967ab9SBen Hutchings fw_name = FIRMWARE_R200; 885771fe6b9SJerome Glisse } else if ((rdev->family == CHIP_R300) || 886771fe6b9SJerome Glisse (rdev->family == CHIP_R350) || 887771fe6b9SJerome Glisse (rdev->family == CHIP_RV350) || 888771fe6b9SJerome Glisse (rdev->family == CHIP_RV380) || 889771fe6b9SJerome Glisse (rdev->family == CHIP_RS400) || 890771fe6b9SJerome Glisse (rdev->family == CHIP_RS480)) { 891771fe6b9SJerome Glisse DRM_INFO("Loading R300 Microcode\n"); 89270967ab9SBen Hutchings fw_name = FIRMWARE_R300; 893771fe6b9SJerome Glisse } else if ((rdev->family == CHIP_R420) || 894771fe6b9SJerome Glisse (rdev->family == CHIP_R423) || 895771fe6b9SJerome Glisse (rdev->family == CHIP_RV410)) { 896771fe6b9SJerome Glisse DRM_INFO("Loading R400 Microcode\n"); 89770967ab9SBen Hutchings fw_name = FIRMWARE_R420; 898771fe6b9SJerome Glisse } else if ((rdev->family == CHIP_RS690) || 899771fe6b9SJerome Glisse (rdev->family == CHIP_RS740)) { 900771fe6b9SJerome Glisse DRM_INFO("Loading RS690/RS740 Microcode\n"); 90170967ab9SBen Hutchings fw_name = FIRMWARE_RS690; 902771fe6b9SJerome Glisse } else if (rdev->family == CHIP_RS600) { 903771fe6b9SJerome Glisse DRM_INFO("Loading RS600 Microcode\n"); 90470967ab9SBen Hutchings fw_name = FIRMWARE_RS600; 905771fe6b9SJerome Glisse } else if ((rdev->family == CHIP_RV515) || 906771fe6b9SJerome Glisse (rdev->family == CHIP_R520) || 907771fe6b9SJerome Glisse (rdev->family == CHIP_RV530) || 908771fe6b9SJerome Glisse (rdev->family == CHIP_R580) || 909771fe6b9SJerome Glisse (rdev->family == CHIP_RV560) || 910771fe6b9SJerome Glisse (rdev->family == CHIP_RV570)) { 911771fe6b9SJerome Glisse DRM_INFO("Loading R500 Microcode\n"); 91270967ab9SBen Hutchings fw_name = FIRMWARE_R520; 91370967ab9SBen Hutchings } 91470967ab9SBen Hutchings 9153ce0a23dSJerome Glisse err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev); 91670967ab9SBen Hutchings platform_device_unregister(pdev); 91770967ab9SBen Hutchings if (err) { 91870967ab9SBen Hutchings printk(KERN_ERR "radeon_cp: Failed to load firmware \"%s\"\n", 91970967ab9SBen Hutchings fw_name); 9203ce0a23dSJerome Glisse } else if (rdev->me_fw->size % 8) { 92170967ab9SBen Hutchings printk(KERN_ERR 92270967ab9SBen Hutchings "radeon_cp: Bogus length %zu in firmware \"%s\"\n", 9233ce0a23dSJerome Glisse rdev->me_fw->size, fw_name); 92470967ab9SBen Hutchings err = -EINVAL; 9253ce0a23dSJerome Glisse release_firmware(rdev->me_fw); 9263ce0a23dSJerome Glisse rdev->me_fw = NULL; 92770967ab9SBen Hutchings } 92870967ab9SBen Hutchings return err; 92970967ab9SBen Hutchings } 930d4550907SJerome Glisse 93170967ab9SBen Hutchings static void r100_cp_load_microcode(struct radeon_device *rdev) 93270967ab9SBen Hutchings { 93370967ab9SBen Hutchings const __be32 *fw_data; 93470967ab9SBen Hutchings int i, size; 93570967ab9SBen Hutchings 93670967ab9SBen Hutchings if (r100_gui_wait_for_idle(rdev)) { 93770967ab9SBen Hutchings printk(KERN_WARNING "Failed to wait GUI idle while " 93870967ab9SBen Hutchings "programming pipes. Bad things might happen.\n"); 93970967ab9SBen Hutchings } 94070967ab9SBen Hutchings 9413ce0a23dSJerome Glisse if (rdev->me_fw) { 9423ce0a23dSJerome Glisse size = rdev->me_fw->size / 4; 9433ce0a23dSJerome Glisse fw_data = (const __be32 *)&rdev->me_fw->data[0]; 94470967ab9SBen Hutchings WREG32(RADEON_CP_ME_RAM_ADDR, 0); 94570967ab9SBen Hutchings for (i = 0; i < size; i += 2) { 94670967ab9SBen Hutchings WREG32(RADEON_CP_ME_RAM_DATAH, 94770967ab9SBen Hutchings be32_to_cpup(&fw_data[i])); 94870967ab9SBen Hutchings WREG32(RADEON_CP_ME_RAM_DATAL, 94970967ab9SBen Hutchings be32_to_cpup(&fw_data[i + 1])); 950771fe6b9SJerome Glisse } 951771fe6b9SJerome Glisse } 952771fe6b9SJerome Glisse } 953771fe6b9SJerome Glisse 954771fe6b9SJerome Glisse int r100_cp_init(struct radeon_device *rdev, unsigned ring_size) 955771fe6b9SJerome Glisse { 956771fe6b9SJerome Glisse unsigned rb_bufsz; 957771fe6b9SJerome Glisse unsigned rb_blksz; 958771fe6b9SJerome Glisse unsigned max_fetch; 959771fe6b9SJerome Glisse unsigned pre_write_timer; 960771fe6b9SJerome Glisse unsigned pre_write_limit; 961771fe6b9SJerome Glisse unsigned indirect2_start; 962771fe6b9SJerome Glisse unsigned indirect1_start; 963771fe6b9SJerome Glisse uint32_t tmp; 964771fe6b9SJerome Glisse int r; 965771fe6b9SJerome Glisse 966771fe6b9SJerome Glisse if (r100_debugfs_cp_init(rdev)) { 967771fe6b9SJerome Glisse DRM_ERROR("Failed to register debugfs file for CP !\n"); 968771fe6b9SJerome Glisse } 9693ce0a23dSJerome Glisse if (!rdev->me_fw) { 97070967ab9SBen Hutchings r = r100_cp_init_microcode(rdev); 97170967ab9SBen Hutchings if (r) { 97270967ab9SBen Hutchings DRM_ERROR("Failed to load firmware!\n"); 97370967ab9SBen Hutchings return r; 97470967ab9SBen Hutchings } 97570967ab9SBen Hutchings } 97670967ab9SBen Hutchings 977771fe6b9SJerome Glisse /* Align ring size */ 978771fe6b9SJerome Glisse rb_bufsz = drm_order(ring_size / 8); 979771fe6b9SJerome Glisse ring_size = (1 << (rb_bufsz + 1)) * 4; 980771fe6b9SJerome Glisse r100_cp_load_microcode(rdev); 981771fe6b9SJerome Glisse r = radeon_ring_init(rdev, ring_size); 982771fe6b9SJerome Glisse if (r) { 983771fe6b9SJerome Glisse return r; 984771fe6b9SJerome Glisse } 985771fe6b9SJerome Glisse /* Each time the cp read 1024 bytes (16 dword/quadword) update 986771fe6b9SJerome Glisse * the rptr copy in system ram */ 987771fe6b9SJerome Glisse rb_blksz = 9; 988771fe6b9SJerome Glisse /* cp will read 128bytes at a time (4 dwords) */ 989771fe6b9SJerome Glisse max_fetch = 1; 990771fe6b9SJerome Glisse rdev->cp.align_mask = 16 - 1; 991771fe6b9SJerome Glisse /* Write to CP_RB_WPTR will be delayed for pre_write_timer clocks */ 992771fe6b9SJerome Glisse pre_write_timer = 64; 993771fe6b9SJerome Glisse /* Force CP_RB_WPTR write if written more than one time before the 994771fe6b9SJerome Glisse * delay expire 995771fe6b9SJerome Glisse */ 996771fe6b9SJerome Glisse pre_write_limit = 0; 997771fe6b9SJerome Glisse /* Setup the cp cache like this (cache size is 96 dwords) : 998771fe6b9SJerome Glisse * RING 0 to 15 999771fe6b9SJerome Glisse * INDIRECT1 16 to 79 1000771fe6b9SJerome Glisse * INDIRECT2 80 to 95 1001771fe6b9SJerome Glisse * So ring cache size is 16dwords (> (2 * max_fetch = 2 * 4dwords)) 1002771fe6b9SJerome Glisse * indirect1 cache size is 64dwords (> (2 * max_fetch = 2 * 4dwords)) 1003771fe6b9SJerome Glisse * indirect2 cache size is 16dwords (> (2 * max_fetch = 2 * 4dwords)) 1004771fe6b9SJerome Glisse * Idea being that most of the gpu cmd will be through indirect1 buffer 1005771fe6b9SJerome Glisse * so it gets the bigger cache. 1006771fe6b9SJerome Glisse */ 1007771fe6b9SJerome Glisse indirect2_start = 80; 1008771fe6b9SJerome Glisse indirect1_start = 16; 1009771fe6b9SJerome Glisse /* cp setup */ 1010771fe6b9SJerome Glisse WREG32(0x718, pre_write_timer | (pre_write_limit << 28)); 1011d6f28938SAlex Deucher tmp = (REG_SET(RADEON_RB_BUFSZ, rb_bufsz) | 1012771fe6b9SJerome Glisse REG_SET(RADEON_RB_BLKSZ, rb_blksz) | 1013771fe6b9SJerome Glisse REG_SET(RADEON_MAX_FETCH, max_fetch) | 1014771fe6b9SJerome Glisse RADEON_RB_NO_UPDATE); 1015d6f28938SAlex Deucher #ifdef __BIG_ENDIAN 1016d6f28938SAlex Deucher tmp |= RADEON_BUF_SWAP_32BIT; 1017d6f28938SAlex Deucher #endif 1018d6f28938SAlex Deucher WREG32(RADEON_CP_RB_CNTL, tmp); 1019d6f28938SAlex Deucher 1020771fe6b9SJerome Glisse /* Set ring address */ 1021771fe6b9SJerome Glisse DRM_INFO("radeon: ring at 0x%016lX\n", (unsigned long)rdev->cp.gpu_addr); 1022771fe6b9SJerome Glisse WREG32(RADEON_CP_RB_BASE, rdev->cp.gpu_addr); 1023771fe6b9SJerome Glisse /* Force read & write ptr to 0 */ 1024771fe6b9SJerome Glisse WREG32(RADEON_CP_RB_CNTL, tmp | RADEON_RB_RPTR_WR_ENA); 1025771fe6b9SJerome Glisse WREG32(RADEON_CP_RB_RPTR_WR, 0); 1026771fe6b9SJerome Glisse WREG32(RADEON_CP_RB_WPTR, 0); 1027771fe6b9SJerome Glisse WREG32(RADEON_CP_RB_CNTL, tmp); 1028771fe6b9SJerome Glisse udelay(10); 1029771fe6b9SJerome Glisse rdev->cp.rptr = RREG32(RADEON_CP_RB_RPTR); 1030771fe6b9SJerome Glisse rdev->cp.wptr = RREG32(RADEON_CP_RB_WPTR); 10319e5786bdSDave Airlie /* protect against crazy HW on resume */ 10329e5786bdSDave Airlie rdev->cp.wptr &= rdev->cp.ptr_mask; 1033771fe6b9SJerome Glisse /* Set cp mode to bus mastering & enable cp*/ 1034771fe6b9SJerome Glisse WREG32(RADEON_CP_CSQ_MODE, 1035771fe6b9SJerome Glisse REG_SET(RADEON_INDIRECT2_START, indirect2_start) | 1036771fe6b9SJerome Glisse REG_SET(RADEON_INDIRECT1_START, indirect1_start)); 1037771fe6b9SJerome Glisse WREG32(0x718, 0); 1038771fe6b9SJerome Glisse WREG32(0x744, 0x00004D4D); 1039771fe6b9SJerome Glisse WREG32(RADEON_CP_CSQ_CNTL, RADEON_CSQ_PRIBM_INDBM); 1040771fe6b9SJerome Glisse radeon_ring_start(rdev); 1041771fe6b9SJerome Glisse r = radeon_ring_test(rdev); 1042771fe6b9SJerome Glisse if (r) { 1043771fe6b9SJerome Glisse DRM_ERROR("radeon: cp isn't working (%d).\n", r); 1044771fe6b9SJerome Glisse return r; 1045771fe6b9SJerome Glisse } 1046771fe6b9SJerome Glisse rdev->cp.ready = true; 1047771fe6b9SJerome Glisse return 0; 1048771fe6b9SJerome Glisse } 1049771fe6b9SJerome Glisse 1050771fe6b9SJerome Glisse void r100_cp_fini(struct radeon_device *rdev) 1051771fe6b9SJerome Glisse { 105245600232SJerome Glisse if (r100_cp_wait_for_idle(rdev)) { 105345600232SJerome Glisse DRM_ERROR("Wait for CP idle timeout, shutting down CP.\n"); 105445600232SJerome Glisse } 1055771fe6b9SJerome Glisse /* Disable ring */ 1056a18d7ea1SJerome Glisse r100_cp_disable(rdev); 1057771fe6b9SJerome Glisse radeon_ring_fini(rdev); 1058771fe6b9SJerome Glisse DRM_INFO("radeon: cp finalized\n"); 1059771fe6b9SJerome Glisse } 1060771fe6b9SJerome Glisse 1061771fe6b9SJerome Glisse void r100_cp_disable(struct radeon_device *rdev) 1062771fe6b9SJerome Glisse { 1063771fe6b9SJerome Glisse /* Disable ring */ 1064771fe6b9SJerome Glisse rdev->cp.ready = false; 1065771fe6b9SJerome Glisse WREG32(RADEON_CP_CSQ_MODE, 0); 1066771fe6b9SJerome Glisse WREG32(RADEON_CP_CSQ_CNTL, 0); 1067771fe6b9SJerome Glisse if (r100_gui_wait_for_idle(rdev)) { 1068771fe6b9SJerome Glisse printk(KERN_WARNING "Failed to wait GUI idle while " 1069771fe6b9SJerome Glisse "programming pipes. Bad things might happen.\n"); 1070771fe6b9SJerome Glisse } 1071771fe6b9SJerome Glisse } 1072771fe6b9SJerome Glisse 10733ce0a23dSJerome Glisse void r100_cp_commit(struct radeon_device *rdev) 10743ce0a23dSJerome Glisse { 10753ce0a23dSJerome Glisse WREG32(RADEON_CP_RB_WPTR, rdev->cp.wptr); 10763ce0a23dSJerome Glisse (void)RREG32(RADEON_CP_RB_WPTR); 10773ce0a23dSJerome Glisse } 10783ce0a23dSJerome Glisse 1079771fe6b9SJerome Glisse 1080771fe6b9SJerome Glisse /* 1081771fe6b9SJerome Glisse * CS functions 1082771fe6b9SJerome Glisse */ 1083771fe6b9SJerome Glisse int r100_cs_parse_packet0(struct radeon_cs_parser *p, 1084771fe6b9SJerome Glisse struct radeon_cs_packet *pkt, 1085068a117cSJerome Glisse const unsigned *auth, unsigned n, 1086771fe6b9SJerome Glisse radeon_packet0_check_t check) 1087771fe6b9SJerome Glisse { 1088771fe6b9SJerome Glisse unsigned reg; 1089771fe6b9SJerome Glisse unsigned i, j, m; 1090771fe6b9SJerome Glisse unsigned idx; 1091771fe6b9SJerome Glisse int r; 1092771fe6b9SJerome Glisse 1093771fe6b9SJerome Glisse idx = pkt->idx + 1; 1094771fe6b9SJerome Glisse reg = pkt->reg; 1095068a117cSJerome Glisse /* Check that register fall into register range 1096068a117cSJerome Glisse * determined by the number of entry (n) in the 1097068a117cSJerome Glisse * safe register bitmap. 1098068a117cSJerome Glisse */ 1099771fe6b9SJerome Glisse if (pkt->one_reg_wr) { 1100771fe6b9SJerome Glisse if ((reg >> 7) > n) { 1101771fe6b9SJerome Glisse return -EINVAL; 1102771fe6b9SJerome Glisse } 1103771fe6b9SJerome Glisse } else { 1104771fe6b9SJerome Glisse if (((reg + (pkt->count << 2)) >> 7) > n) { 1105771fe6b9SJerome Glisse return -EINVAL; 1106771fe6b9SJerome Glisse } 1107771fe6b9SJerome Glisse } 1108771fe6b9SJerome Glisse for (i = 0; i <= pkt->count; i++, idx++) { 1109771fe6b9SJerome Glisse j = (reg >> 7); 1110771fe6b9SJerome Glisse m = 1 << ((reg >> 2) & 31); 1111771fe6b9SJerome Glisse if (auth[j] & m) { 1112771fe6b9SJerome Glisse r = check(p, pkt, idx, reg); 1113771fe6b9SJerome Glisse if (r) { 1114771fe6b9SJerome Glisse return r; 1115771fe6b9SJerome Glisse } 1116771fe6b9SJerome Glisse } 1117771fe6b9SJerome Glisse if (pkt->one_reg_wr) { 1118771fe6b9SJerome Glisse if (!(auth[j] & m)) { 1119771fe6b9SJerome Glisse break; 1120771fe6b9SJerome Glisse } 1121771fe6b9SJerome Glisse } else { 1122771fe6b9SJerome Glisse reg += 4; 1123771fe6b9SJerome Glisse } 1124771fe6b9SJerome Glisse } 1125771fe6b9SJerome Glisse return 0; 1126771fe6b9SJerome Glisse } 1127771fe6b9SJerome Glisse 1128771fe6b9SJerome Glisse void r100_cs_dump_packet(struct radeon_cs_parser *p, 1129771fe6b9SJerome Glisse struct radeon_cs_packet *pkt) 1130771fe6b9SJerome Glisse { 1131771fe6b9SJerome Glisse volatile uint32_t *ib; 1132771fe6b9SJerome Glisse unsigned i; 1133771fe6b9SJerome Glisse unsigned idx; 1134771fe6b9SJerome Glisse 1135771fe6b9SJerome Glisse ib = p->ib->ptr; 1136771fe6b9SJerome Glisse idx = pkt->idx; 1137771fe6b9SJerome Glisse for (i = 0; i <= (pkt->count + 1); i++, idx++) { 1138771fe6b9SJerome Glisse DRM_INFO("ib[%d]=0x%08X\n", idx, ib[idx]); 1139771fe6b9SJerome Glisse } 1140771fe6b9SJerome Glisse } 1141771fe6b9SJerome Glisse 1142771fe6b9SJerome Glisse /** 1143771fe6b9SJerome Glisse * r100_cs_packet_parse() - parse cp packet and point ib index to next packet 1144771fe6b9SJerome Glisse * @parser: parser structure holding parsing context. 1145771fe6b9SJerome Glisse * @pkt: where to store packet informations 1146771fe6b9SJerome Glisse * 1147771fe6b9SJerome Glisse * Assume that chunk_ib_index is properly set. Will return -EINVAL 1148771fe6b9SJerome Glisse * if packet is bigger than remaining ib size. or if packets is unknown. 1149771fe6b9SJerome Glisse **/ 1150771fe6b9SJerome Glisse int r100_cs_packet_parse(struct radeon_cs_parser *p, 1151771fe6b9SJerome Glisse struct radeon_cs_packet *pkt, 1152771fe6b9SJerome Glisse unsigned idx) 1153771fe6b9SJerome Glisse { 1154771fe6b9SJerome Glisse struct radeon_cs_chunk *ib_chunk = &p->chunks[p->chunk_ib_idx]; 1155fa99239cSRoel Kluin uint32_t header; 1156771fe6b9SJerome Glisse 1157771fe6b9SJerome Glisse if (idx >= ib_chunk->length_dw) { 1158771fe6b9SJerome Glisse DRM_ERROR("Can not parse packet at %d after CS end %d !\n", 1159771fe6b9SJerome Glisse idx, ib_chunk->length_dw); 1160771fe6b9SJerome Glisse return -EINVAL; 1161771fe6b9SJerome Glisse } 1162513bcb46SDave Airlie header = radeon_get_ib_value(p, idx); 1163771fe6b9SJerome Glisse pkt->idx = idx; 1164771fe6b9SJerome Glisse pkt->type = CP_PACKET_GET_TYPE(header); 1165771fe6b9SJerome Glisse pkt->count = CP_PACKET_GET_COUNT(header); 1166771fe6b9SJerome Glisse switch (pkt->type) { 1167771fe6b9SJerome Glisse case PACKET_TYPE0: 1168771fe6b9SJerome Glisse pkt->reg = CP_PACKET0_GET_REG(header); 1169771fe6b9SJerome Glisse pkt->one_reg_wr = CP_PACKET0_GET_ONE_REG_WR(header); 1170771fe6b9SJerome Glisse break; 1171771fe6b9SJerome Glisse case PACKET_TYPE3: 1172771fe6b9SJerome Glisse pkt->opcode = CP_PACKET3_GET_OPCODE(header); 1173771fe6b9SJerome Glisse break; 1174771fe6b9SJerome Glisse case PACKET_TYPE2: 1175771fe6b9SJerome Glisse pkt->count = -1; 1176771fe6b9SJerome Glisse break; 1177771fe6b9SJerome Glisse default: 1178771fe6b9SJerome Glisse DRM_ERROR("Unknown packet type %d at %d !\n", pkt->type, idx); 1179771fe6b9SJerome Glisse return -EINVAL; 1180771fe6b9SJerome Glisse } 1181771fe6b9SJerome Glisse if ((pkt->count + 1 + pkt->idx) >= ib_chunk->length_dw) { 1182771fe6b9SJerome Glisse DRM_ERROR("Packet (%d:%d:%d) end after CS buffer (%d) !\n", 1183771fe6b9SJerome Glisse pkt->idx, pkt->type, pkt->count, ib_chunk->length_dw); 1184771fe6b9SJerome Glisse return -EINVAL; 1185771fe6b9SJerome Glisse } 1186771fe6b9SJerome Glisse return 0; 1187771fe6b9SJerome Glisse } 1188771fe6b9SJerome Glisse 1189771fe6b9SJerome Glisse /** 1190531369e6SDave Airlie * r100_cs_packet_next_vline() - parse userspace VLINE packet 1191531369e6SDave Airlie * @parser: parser structure holding parsing context. 1192531369e6SDave Airlie * 1193531369e6SDave Airlie * Userspace sends a special sequence for VLINE waits. 1194531369e6SDave Airlie * PACKET0 - VLINE_START_END + value 1195531369e6SDave Airlie * PACKET0 - WAIT_UNTIL +_value 1196531369e6SDave Airlie * RELOC (P3) - crtc_id in reloc. 1197531369e6SDave Airlie * 1198531369e6SDave Airlie * This function parses this and relocates the VLINE START END 1199531369e6SDave Airlie * and WAIT UNTIL packets to the correct crtc. 1200531369e6SDave Airlie * It also detects a switched off crtc and nulls out the 1201531369e6SDave Airlie * wait in that case. 1202531369e6SDave Airlie */ 1203531369e6SDave Airlie int r100_cs_packet_parse_vline(struct radeon_cs_parser *p) 1204531369e6SDave Airlie { 1205531369e6SDave Airlie struct drm_mode_object *obj; 1206531369e6SDave Airlie struct drm_crtc *crtc; 1207531369e6SDave Airlie struct radeon_crtc *radeon_crtc; 1208531369e6SDave Airlie struct radeon_cs_packet p3reloc, waitreloc; 1209531369e6SDave Airlie int crtc_id; 1210531369e6SDave Airlie int r; 1211531369e6SDave Airlie uint32_t header, h_idx, reg; 1212513bcb46SDave Airlie volatile uint32_t *ib; 1213531369e6SDave Airlie 1214513bcb46SDave Airlie ib = p->ib->ptr; 1215531369e6SDave Airlie 1216531369e6SDave Airlie /* parse the wait until */ 1217531369e6SDave Airlie r = r100_cs_packet_parse(p, &waitreloc, p->idx); 1218531369e6SDave Airlie if (r) 1219531369e6SDave Airlie return r; 1220531369e6SDave Airlie 1221531369e6SDave Airlie /* check its a wait until and only 1 count */ 1222531369e6SDave Airlie if (waitreloc.reg != RADEON_WAIT_UNTIL || 1223531369e6SDave Airlie waitreloc.count != 0) { 1224531369e6SDave Airlie DRM_ERROR("vline wait had illegal wait until segment\n"); 1225531369e6SDave Airlie r = -EINVAL; 1226531369e6SDave Airlie return r; 1227531369e6SDave Airlie } 1228531369e6SDave Airlie 1229513bcb46SDave Airlie if (radeon_get_ib_value(p, waitreloc.idx + 1) != RADEON_WAIT_CRTC_VLINE) { 1230531369e6SDave Airlie DRM_ERROR("vline wait had illegal wait until\n"); 1231531369e6SDave Airlie r = -EINVAL; 1232531369e6SDave Airlie return r; 1233531369e6SDave Airlie } 1234531369e6SDave Airlie 1235531369e6SDave Airlie /* jump over the NOP */ 123690ebd065SAlex Deucher r = r100_cs_packet_parse(p, &p3reloc, p->idx + waitreloc.count + 2); 1237531369e6SDave Airlie if (r) 1238531369e6SDave Airlie return r; 1239531369e6SDave Airlie 1240531369e6SDave Airlie h_idx = p->idx - 2; 124190ebd065SAlex Deucher p->idx += waitreloc.count + 2; 124290ebd065SAlex Deucher p->idx += p3reloc.count + 2; 1243531369e6SDave Airlie 1244513bcb46SDave Airlie header = radeon_get_ib_value(p, h_idx); 1245513bcb46SDave Airlie crtc_id = radeon_get_ib_value(p, h_idx + 5); 1246d4ac6a05SDave Airlie reg = CP_PACKET0_GET_REG(header); 1247531369e6SDave Airlie mutex_lock(&p->rdev->ddev->mode_config.mutex); 1248531369e6SDave Airlie obj = drm_mode_object_find(p->rdev->ddev, crtc_id, DRM_MODE_OBJECT_CRTC); 1249531369e6SDave Airlie if (!obj) { 1250531369e6SDave Airlie DRM_ERROR("cannot find crtc %d\n", crtc_id); 1251531369e6SDave Airlie r = -EINVAL; 1252531369e6SDave Airlie goto out; 1253531369e6SDave Airlie } 1254531369e6SDave Airlie crtc = obj_to_crtc(obj); 1255531369e6SDave Airlie radeon_crtc = to_radeon_crtc(crtc); 1256531369e6SDave Airlie crtc_id = radeon_crtc->crtc_id; 1257531369e6SDave Airlie 1258531369e6SDave Airlie if (!crtc->enabled) { 1259531369e6SDave Airlie /* if the CRTC isn't enabled - we need to nop out the wait until */ 1260513bcb46SDave Airlie ib[h_idx + 2] = PACKET2(0); 1261513bcb46SDave Airlie ib[h_idx + 3] = PACKET2(0); 1262531369e6SDave Airlie } else if (crtc_id == 1) { 1263531369e6SDave Airlie switch (reg) { 1264531369e6SDave Airlie case AVIVO_D1MODE_VLINE_START_END: 126590ebd065SAlex Deucher header &= ~R300_CP_PACKET0_REG_MASK; 1266531369e6SDave Airlie header |= AVIVO_D2MODE_VLINE_START_END >> 2; 1267531369e6SDave Airlie break; 1268531369e6SDave Airlie case RADEON_CRTC_GUI_TRIG_VLINE: 126990ebd065SAlex Deucher header &= ~R300_CP_PACKET0_REG_MASK; 1270531369e6SDave Airlie header |= RADEON_CRTC2_GUI_TRIG_VLINE >> 2; 1271531369e6SDave Airlie break; 1272531369e6SDave Airlie default: 1273531369e6SDave Airlie DRM_ERROR("unknown crtc reloc\n"); 1274531369e6SDave Airlie r = -EINVAL; 1275531369e6SDave Airlie goto out; 1276531369e6SDave Airlie } 1277513bcb46SDave Airlie ib[h_idx] = header; 1278513bcb46SDave Airlie ib[h_idx + 3] |= RADEON_ENG_DISPLAY_SELECT_CRTC1; 1279531369e6SDave Airlie } 1280531369e6SDave Airlie out: 1281531369e6SDave Airlie mutex_unlock(&p->rdev->ddev->mode_config.mutex); 1282531369e6SDave Airlie return r; 1283531369e6SDave Airlie } 1284531369e6SDave Airlie 1285531369e6SDave Airlie /** 1286771fe6b9SJerome Glisse * r100_cs_packet_next_reloc() - parse next packet which should be reloc packet3 1287771fe6b9SJerome Glisse * @parser: parser structure holding parsing context. 1288771fe6b9SJerome Glisse * @data: pointer to relocation data 1289771fe6b9SJerome Glisse * @offset_start: starting offset 1290771fe6b9SJerome Glisse * @offset_mask: offset mask (to align start offset on) 1291771fe6b9SJerome Glisse * @reloc: reloc informations 1292771fe6b9SJerome Glisse * 1293771fe6b9SJerome Glisse * Check next packet is relocation packet3, do bo validation and compute 1294771fe6b9SJerome Glisse * GPU offset using the provided start. 1295771fe6b9SJerome Glisse **/ 1296771fe6b9SJerome Glisse int r100_cs_packet_next_reloc(struct radeon_cs_parser *p, 1297771fe6b9SJerome Glisse struct radeon_cs_reloc **cs_reloc) 1298771fe6b9SJerome Glisse { 1299771fe6b9SJerome Glisse struct radeon_cs_chunk *relocs_chunk; 1300771fe6b9SJerome Glisse struct radeon_cs_packet p3reloc; 1301771fe6b9SJerome Glisse unsigned idx; 1302771fe6b9SJerome Glisse int r; 1303771fe6b9SJerome Glisse 1304771fe6b9SJerome Glisse if (p->chunk_relocs_idx == -1) { 1305771fe6b9SJerome Glisse DRM_ERROR("No relocation chunk !\n"); 1306771fe6b9SJerome Glisse return -EINVAL; 1307771fe6b9SJerome Glisse } 1308771fe6b9SJerome Glisse *cs_reloc = NULL; 1309771fe6b9SJerome Glisse relocs_chunk = &p->chunks[p->chunk_relocs_idx]; 1310771fe6b9SJerome Glisse r = r100_cs_packet_parse(p, &p3reloc, p->idx); 1311771fe6b9SJerome Glisse if (r) { 1312771fe6b9SJerome Glisse return r; 1313771fe6b9SJerome Glisse } 1314771fe6b9SJerome Glisse p->idx += p3reloc.count + 2; 1315771fe6b9SJerome Glisse if (p3reloc.type != PACKET_TYPE3 || p3reloc.opcode != PACKET3_NOP) { 1316771fe6b9SJerome Glisse DRM_ERROR("No packet3 for relocation for packet at %d.\n", 1317771fe6b9SJerome Glisse p3reloc.idx); 1318771fe6b9SJerome Glisse r100_cs_dump_packet(p, &p3reloc); 1319771fe6b9SJerome Glisse return -EINVAL; 1320771fe6b9SJerome Glisse } 1321513bcb46SDave Airlie idx = radeon_get_ib_value(p, p3reloc.idx + 1); 1322771fe6b9SJerome Glisse if (idx >= relocs_chunk->length_dw) { 1323771fe6b9SJerome Glisse DRM_ERROR("Relocs at %d after relocations chunk end %d !\n", 1324771fe6b9SJerome Glisse idx, relocs_chunk->length_dw); 1325771fe6b9SJerome Glisse r100_cs_dump_packet(p, &p3reloc); 1326771fe6b9SJerome Glisse return -EINVAL; 1327771fe6b9SJerome Glisse } 1328771fe6b9SJerome Glisse /* FIXME: we assume reloc size is 4 dwords */ 1329771fe6b9SJerome Glisse *cs_reloc = p->relocs_ptr[(idx / 4)]; 1330771fe6b9SJerome Glisse return 0; 1331771fe6b9SJerome Glisse } 1332771fe6b9SJerome Glisse 1333551ebd83SDave Airlie static int r100_get_vtx_size(uint32_t vtx_fmt) 1334551ebd83SDave Airlie { 1335551ebd83SDave Airlie int vtx_size; 1336551ebd83SDave Airlie vtx_size = 2; 1337551ebd83SDave Airlie /* ordered according to bits in spec */ 1338551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_W0) 1339551ebd83SDave Airlie vtx_size++; 1340551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_FPCOLOR) 1341551ebd83SDave Airlie vtx_size += 3; 1342551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_FPALPHA) 1343551ebd83SDave Airlie vtx_size++; 1344551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_PKCOLOR) 1345551ebd83SDave Airlie vtx_size++; 1346551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_FPSPEC) 1347551ebd83SDave Airlie vtx_size += 3; 1348551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_FPFOG) 1349551ebd83SDave Airlie vtx_size++; 1350551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_PKSPEC) 1351551ebd83SDave Airlie vtx_size++; 1352551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_ST0) 1353551ebd83SDave Airlie vtx_size += 2; 1354551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_ST1) 1355551ebd83SDave Airlie vtx_size += 2; 1356551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_Q1) 1357551ebd83SDave Airlie vtx_size++; 1358551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_ST2) 1359551ebd83SDave Airlie vtx_size += 2; 1360551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_Q2) 1361551ebd83SDave Airlie vtx_size++; 1362551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_ST3) 1363551ebd83SDave Airlie vtx_size += 2; 1364551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_Q3) 1365551ebd83SDave Airlie vtx_size++; 1366551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_Q0) 1367551ebd83SDave Airlie vtx_size++; 1368551ebd83SDave Airlie /* blend weight */ 1369551ebd83SDave Airlie if (vtx_fmt & (0x7 << 15)) 1370551ebd83SDave Airlie vtx_size += (vtx_fmt >> 15) & 0x7; 1371551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_N0) 1372551ebd83SDave Airlie vtx_size += 3; 1373551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_XY1) 1374551ebd83SDave Airlie vtx_size += 2; 1375551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_Z1) 1376551ebd83SDave Airlie vtx_size++; 1377551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_W1) 1378551ebd83SDave Airlie vtx_size++; 1379551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_N1) 1380551ebd83SDave Airlie vtx_size++; 1381551ebd83SDave Airlie if (vtx_fmt & RADEON_SE_VTX_FMT_Z) 1382551ebd83SDave Airlie vtx_size++; 1383551ebd83SDave Airlie return vtx_size; 1384551ebd83SDave Airlie } 1385551ebd83SDave Airlie 1386771fe6b9SJerome Glisse static int r100_packet0_check(struct radeon_cs_parser *p, 1387551ebd83SDave Airlie struct radeon_cs_packet *pkt, 1388551ebd83SDave Airlie unsigned idx, unsigned reg) 1389771fe6b9SJerome Glisse { 1390771fe6b9SJerome Glisse struct radeon_cs_reloc *reloc; 1391551ebd83SDave Airlie struct r100_cs_track *track; 1392771fe6b9SJerome Glisse volatile uint32_t *ib; 1393771fe6b9SJerome Glisse uint32_t tmp; 1394771fe6b9SJerome Glisse int r; 1395551ebd83SDave Airlie int i, face; 1396e024e110SDave Airlie u32 tile_flags = 0; 1397513bcb46SDave Airlie u32 idx_value; 1398771fe6b9SJerome Glisse 1399771fe6b9SJerome Glisse ib = p->ib->ptr; 1400551ebd83SDave Airlie track = (struct r100_cs_track *)p->track; 1401551ebd83SDave Airlie 1402513bcb46SDave Airlie idx_value = radeon_get_ib_value(p, idx); 1403513bcb46SDave Airlie 1404771fe6b9SJerome Glisse switch (reg) { 1405531369e6SDave Airlie case RADEON_CRTC_GUI_TRIG_VLINE: 1406531369e6SDave Airlie r = r100_cs_packet_parse_vline(p); 1407531369e6SDave Airlie if (r) { 1408531369e6SDave Airlie DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1409531369e6SDave Airlie idx, reg); 1410531369e6SDave Airlie r100_cs_dump_packet(p, pkt); 1411531369e6SDave Airlie return r; 1412531369e6SDave Airlie } 1413531369e6SDave Airlie break; 1414771fe6b9SJerome Glisse /* FIXME: only allow PACKET3 blit? easier to check for out of 1415771fe6b9SJerome Glisse * range access */ 1416771fe6b9SJerome Glisse case RADEON_DST_PITCH_OFFSET: 1417771fe6b9SJerome Glisse case RADEON_SRC_PITCH_OFFSET: 1418551ebd83SDave Airlie r = r100_reloc_pitch_offset(p, pkt, idx, reg); 1419551ebd83SDave Airlie if (r) 1420551ebd83SDave Airlie return r; 1421551ebd83SDave Airlie break; 1422551ebd83SDave Airlie case RADEON_RB3D_DEPTHOFFSET: 1423771fe6b9SJerome Glisse r = r100_cs_packet_next_reloc(p, &reloc); 1424771fe6b9SJerome Glisse if (r) { 1425771fe6b9SJerome Glisse DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1426771fe6b9SJerome Glisse idx, reg); 1427771fe6b9SJerome Glisse r100_cs_dump_packet(p, pkt); 1428771fe6b9SJerome Glisse return r; 1429771fe6b9SJerome Glisse } 1430551ebd83SDave Airlie track->zb.robj = reloc->robj; 1431513bcb46SDave Airlie track->zb.offset = idx_value; 1432513bcb46SDave Airlie ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset); 1433771fe6b9SJerome Glisse break; 1434771fe6b9SJerome Glisse case RADEON_RB3D_COLOROFFSET: 1435551ebd83SDave Airlie r = r100_cs_packet_next_reloc(p, &reloc); 1436551ebd83SDave Airlie if (r) { 1437551ebd83SDave Airlie DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1438551ebd83SDave Airlie idx, reg); 1439551ebd83SDave Airlie r100_cs_dump_packet(p, pkt); 1440551ebd83SDave Airlie return r; 1441551ebd83SDave Airlie } 1442551ebd83SDave Airlie track->cb[0].robj = reloc->robj; 1443513bcb46SDave Airlie track->cb[0].offset = idx_value; 1444513bcb46SDave Airlie ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset); 1445551ebd83SDave Airlie break; 1446771fe6b9SJerome Glisse case RADEON_PP_TXOFFSET_0: 1447771fe6b9SJerome Glisse case RADEON_PP_TXOFFSET_1: 1448771fe6b9SJerome Glisse case RADEON_PP_TXOFFSET_2: 1449551ebd83SDave Airlie i = (reg - RADEON_PP_TXOFFSET_0) / 24; 1450771fe6b9SJerome Glisse r = r100_cs_packet_next_reloc(p, &reloc); 1451771fe6b9SJerome Glisse if (r) { 1452771fe6b9SJerome Glisse DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1453771fe6b9SJerome Glisse idx, reg); 1454771fe6b9SJerome Glisse r100_cs_dump_packet(p, pkt); 1455771fe6b9SJerome Glisse return r; 1456771fe6b9SJerome Glisse } 1457513bcb46SDave Airlie ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset); 1458551ebd83SDave Airlie track->textures[i].robj = reloc->robj; 1459771fe6b9SJerome Glisse break; 1460551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T0_0: 1461551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T0_1: 1462551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T0_2: 1463551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T0_3: 1464551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T0_4: 1465551ebd83SDave Airlie i = (reg - RADEON_PP_CUBIC_OFFSET_T0_0) / 4; 1466551ebd83SDave Airlie r = r100_cs_packet_next_reloc(p, &reloc); 1467551ebd83SDave Airlie if (r) { 1468551ebd83SDave Airlie DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1469551ebd83SDave Airlie idx, reg); 1470551ebd83SDave Airlie r100_cs_dump_packet(p, pkt); 1471551ebd83SDave Airlie return r; 1472551ebd83SDave Airlie } 1473513bcb46SDave Airlie track->textures[0].cube_info[i].offset = idx_value; 1474513bcb46SDave Airlie ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset); 1475551ebd83SDave Airlie track->textures[0].cube_info[i].robj = reloc->robj; 1476551ebd83SDave Airlie break; 1477551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T1_0: 1478551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T1_1: 1479551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T1_2: 1480551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T1_3: 1481551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T1_4: 1482551ebd83SDave Airlie i = (reg - RADEON_PP_CUBIC_OFFSET_T1_0) / 4; 1483551ebd83SDave Airlie r = r100_cs_packet_next_reloc(p, &reloc); 1484551ebd83SDave Airlie if (r) { 1485551ebd83SDave Airlie DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1486551ebd83SDave Airlie idx, reg); 1487551ebd83SDave Airlie r100_cs_dump_packet(p, pkt); 1488551ebd83SDave Airlie return r; 1489551ebd83SDave Airlie } 1490513bcb46SDave Airlie track->textures[1].cube_info[i].offset = idx_value; 1491513bcb46SDave Airlie ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset); 1492551ebd83SDave Airlie track->textures[1].cube_info[i].robj = reloc->robj; 1493551ebd83SDave Airlie break; 1494551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T2_0: 1495551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T2_1: 1496551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T2_2: 1497551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T2_3: 1498551ebd83SDave Airlie case RADEON_PP_CUBIC_OFFSET_T2_4: 1499551ebd83SDave Airlie i = (reg - RADEON_PP_CUBIC_OFFSET_T2_0) / 4; 1500551ebd83SDave Airlie r = r100_cs_packet_next_reloc(p, &reloc); 1501551ebd83SDave Airlie if (r) { 1502551ebd83SDave Airlie DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1503551ebd83SDave Airlie idx, reg); 1504551ebd83SDave Airlie r100_cs_dump_packet(p, pkt); 1505551ebd83SDave Airlie return r; 1506551ebd83SDave Airlie } 1507513bcb46SDave Airlie track->textures[2].cube_info[i].offset = idx_value; 1508513bcb46SDave Airlie ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset); 1509551ebd83SDave Airlie track->textures[2].cube_info[i].robj = reloc->robj; 1510551ebd83SDave Airlie break; 1511551ebd83SDave Airlie case RADEON_RE_WIDTH_HEIGHT: 1512513bcb46SDave Airlie track->maxy = ((idx_value >> 16) & 0x7FF); 1513551ebd83SDave Airlie break; 1514e024e110SDave Airlie case RADEON_RB3D_COLORPITCH: 1515e024e110SDave Airlie r = r100_cs_packet_next_reloc(p, &reloc); 1516e024e110SDave Airlie if (r) { 1517e024e110SDave Airlie DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1518e024e110SDave Airlie idx, reg); 1519e024e110SDave Airlie r100_cs_dump_packet(p, pkt); 1520e024e110SDave Airlie return r; 1521e024e110SDave Airlie } 1522e024e110SDave Airlie 1523e024e110SDave Airlie if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) 1524e024e110SDave Airlie tile_flags |= RADEON_COLOR_TILE_ENABLE; 1525e024e110SDave Airlie if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO) 1526e024e110SDave Airlie tile_flags |= RADEON_COLOR_MICROTILE_ENABLE; 1527e024e110SDave Airlie 1528513bcb46SDave Airlie tmp = idx_value & ~(0x7 << 16); 1529e024e110SDave Airlie tmp |= tile_flags; 1530e024e110SDave Airlie ib[idx] = tmp; 1531551ebd83SDave Airlie 1532513bcb46SDave Airlie track->cb[0].pitch = idx_value & RADEON_COLORPITCH_MASK; 1533551ebd83SDave Airlie break; 1534551ebd83SDave Airlie case RADEON_RB3D_DEPTHPITCH: 1535513bcb46SDave Airlie track->zb.pitch = idx_value & RADEON_DEPTHPITCH_MASK; 1536551ebd83SDave Airlie break; 1537551ebd83SDave Airlie case RADEON_RB3D_CNTL: 1538513bcb46SDave Airlie switch ((idx_value >> RADEON_RB3D_COLOR_FORMAT_SHIFT) & 0x1f) { 1539551ebd83SDave Airlie case 7: 1540551ebd83SDave Airlie case 8: 1541551ebd83SDave Airlie case 9: 1542551ebd83SDave Airlie case 11: 1543551ebd83SDave Airlie case 12: 1544551ebd83SDave Airlie track->cb[0].cpp = 1; 1545551ebd83SDave Airlie break; 1546551ebd83SDave Airlie case 3: 1547551ebd83SDave Airlie case 4: 1548551ebd83SDave Airlie case 15: 1549551ebd83SDave Airlie track->cb[0].cpp = 2; 1550551ebd83SDave Airlie break; 1551551ebd83SDave Airlie case 6: 1552551ebd83SDave Airlie track->cb[0].cpp = 4; 1553551ebd83SDave Airlie break; 1554551ebd83SDave Airlie default: 1555551ebd83SDave Airlie DRM_ERROR("Invalid color buffer format (%d) !\n", 1556513bcb46SDave Airlie ((idx_value >> RADEON_RB3D_COLOR_FORMAT_SHIFT) & 0x1f)); 1557551ebd83SDave Airlie return -EINVAL; 1558551ebd83SDave Airlie } 1559513bcb46SDave Airlie track->z_enabled = !!(idx_value & RADEON_Z_ENABLE); 1560551ebd83SDave Airlie break; 1561551ebd83SDave Airlie case RADEON_RB3D_ZSTENCILCNTL: 1562513bcb46SDave Airlie switch (idx_value & 0xf) { 1563551ebd83SDave Airlie case 0: 1564551ebd83SDave Airlie track->zb.cpp = 2; 1565551ebd83SDave Airlie break; 1566551ebd83SDave Airlie case 2: 1567551ebd83SDave Airlie case 3: 1568551ebd83SDave Airlie case 4: 1569551ebd83SDave Airlie case 5: 1570551ebd83SDave Airlie case 9: 1571551ebd83SDave Airlie case 11: 1572551ebd83SDave Airlie track->zb.cpp = 4; 1573551ebd83SDave Airlie break; 1574551ebd83SDave Airlie default: 1575551ebd83SDave Airlie break; 1576551ebd83SDave Airlie } 1577e024e110SDave Airlie break; 157817782d99SDave Airlie case RADEON_RB3D_ZPASS_ADDR: 157917782d99SDave Airlie r = r100_cs_packet_next_reloc(p, &reloc); 158017782d99SDave Airlie if (r) { 158117782d99SDave Airlie DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 158217782d99SDave Airlie idx, reg); 158317782d99SDave Airlie r100_cs_dump_packet(p, pkt); 158417782d99SDave Airlie return r; 158517782d99SDave Airlie } 1586513bcb46SDave Airlie ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset); 158717782d99SDave Airlie break; 1588551ebd83SDave Airlie case RADEON_PP_CNTL: 1589551ebd83SDave Airlie { 1590513bcb46SDave Airlie uint32_t temp = idx_value >> 4; 1591551ebd83SDave Airlie for (i = 0; i < track->num_texture; i++) 1592551ebd83SDave Airlie track->textures[i].enabled = !!(temp & (1 << i)); 1593551ebd83SDave Airlie } 1594551ebd83SDave Airlie break; 1595551ebd83SDave Airlie case RADEON_SE_VF_CNTL: 1596513bcb46SDave Airlie track->vap_vf_cntl = idx_value; 1597551ebd83SDave Airlie break; 1598551ebd83SDave Airlie case RADEON_SE_VTX_FMT: 1599513bcb46SDave Airlie track->vtx_size = r100_get_vtx_size(idx_value); 1600551ebd83SDave Airlie break; 1601551ebd83SDave Airlie case RADEON_PP_TEX_SIZE_0: 1602551ebd83SDave Airlie case RADEON_PP_TEX_SIZE_1: 1603551ebd83SDave Airlie case RADEON_PP_TEX_SIZE_2: 1604551ebd83SDave Airlie i = (reg - RADEON_PP_TEX_SIZE_0) / 8; 1605513bcb46SDave Airlie track->textures[i].width = (idx_value & RADEON_TEX_USIZE_MASK) + 1; 1606513bcb46SDave Airlie track->textures[i].height = ((idx_value & RADEON_TEX_VSIZE_MASK) >> RADEON_TEX_VSIZE_SHIFT) + 1; 1607551ebd83SDave Airlie break; 1608551ebd83SDave Airlie case RADEON_PP_TEX_PITCH_0: 1609551ebd83SDave Airlie case RADEON_PP_TEX_PITCH_1: 1610551ebd83SDave Airlie case RADEON_PP_TEX_PITCH_2: 1611551ebd83SDave Airlie i = (reg - RADEON_PP_TEX_PITCH_0) / 8; 1612513bcb46SDave Airlie track->textures[i].pitch = idx_value + 32; 1613551ebd83SDave Airlie break; 1614551ebd83SDave Airlie case RADEON_PP_TXFILTER_0: 1615551ebd83SDave Airlie case RADEON_PP_TXFILTER_1: 1616551ebd83SDave Airlie case RADEON_PP_TXFILTER_2: 1617551ebd83SDave Airlie i = (reg - RADEON_PP_TXFILTER_0) / 24; 1618513bcb46SDave Airlie track->textures[i].num_levels = ((idx_value & RADEON_MAX_MIP_LEVEL_MASK) 1619551ebd83SDave Airlie >> RADEON_MAX_MIP_LEVEL_SHIFT); 1620513bcb46SDave Airlie tmp = (idx_value >> 23) & 0x7; 1621551ebd83SDave Airlie if (tmp == 2 || tmp == 6) 1622551ebd83SDave Airlie track->textures[i].roundup_w = false; 1623513bcb46SDave Airlie tmp = (idx_value >> 27) & 0x7; 1624551ebd83SDave Airlie if (tmp == 2 || tmp == 6) 1625551ebd83SDave Airlie track->textures[i].roundup_h = false; 1626551ebd83SDave Airlie break; 1627551ebd83SDave Airlie case RADEON_PP_TXFORMAT_0: 1628551ebd83SDave Airlie case RADEON_PP_TXFORMAT_1: 1629551ebd83SDave Airlie case RADEON_PP_TXFORMAT_2: 1630551ebd83SDave Airlie i = (reg - RADEON_PP_TXFORMAT_0) / 24; 1631513bcb46SDave Airlie if (idx_value & RADEON_TXFORMAT_NON_POWER2) { 1632551ebd83SDave Airlie track->textures[i].use_pitch = 1; 1633551ebd83SDave Airlie } else { 1634551ebd83SDave Airlie track->textures[i].use_pitch = 0; 1635513bcb46SDave Airlie track->textures[i].width = 1 << ((idx_value >> RADEON_TXFORMAT_WIDTH_SHIFT) & RADEON_TXFORMAT_WIDTH_MASK); 1636513bcb46SDave Airlie track->textures[i].height = 1 << ((idx_value >> RADEON_TXFORMAT_HEIGHT_SHIFT) & RADEON_TXFORMAT_HEIGHT_MASK); 1637551ebd83SDave Airlie } 1638513bcb46SDave Airlie if (idx_value & RADEON_TXFORMAT_CUBIC_MAP_ENABLE) 1639551ebd83SDave Airlie track->textures[i].tex_coord_type = 2; 1640513bcb46SDave Airlie switch ((idx_value & RADEON_TXFORMAT_FORMAT_MASK)) { 1641551ebd83SDave Airlie case RADEON_TXFORMAT_I8: 1642551ebd83SDave Airlie case RADEON_TXFORMAT_RGB332: 1643551ebd83SDave Airlie case RADEON_TXFORMAT_Y8: 1644551ebd83SDave Airlie track->textures[i].cpp = 1; 1645551ebd83SDave Airlie break; 1646551ebd83SDave Airlie case RADEON_TXFORMAT_AI88: 1647551ebd83SDave Airlie case RADEON_TXFORMAT_ARGB1555: 1648551ebd83SDave Airlie case RADEON_TXFORMAT_RGB565: 1649551ebd83SDave Airlie case RADEON_TXFORMAT_ARGB4444: 1650551ebd83SDave Airlie case RADEON_TXFORMAT_VYUY422: 1651551ebd83SDave Airlie case RADEON_TXFORMAT_YVYU422: 1652551ebd83SDave Airlie case RADEON_TXFORMAT_SHADOW16: 1653551ebd83SDave Airlie case RADEON_TXFORMAT_LDUDV655: 1654551ebd83SDave Airlie case RADEON_TXFORMAT_DUDV88: 1655551ebd83SDave Airlie track->textures[i].cpp = 2; 1656551ebd83SDave Airlie break; 1657551ebd83SDave Airlie case RADEON_TXFORMAT_ARGB8888: 1658551ebd83SDave Airlie case RADEON_TXFORMAT_RGBA8888: 1659551ebd83SDave Airlie case RADEON_TXFORMAT_SHADOW32: 1660551ebd83SDave Airlie case RADEON_TXFORMAT_LDUDUV8888: 1661551ebd83SDave Airlie track->textures[i].cpp = 4; 1662551ebd83SDave Airlie break; 1663d785d78bSDave Airlie case RADEON_TXFORMAT_DXT1: 1664d785d78bSDave Airlie track->textures[i].cpp = 1; 1665d785d78bSDave Airlie track->textures[i].compress_format = R100_TRACK_COMP_DXT1; 1666d785d78bSDave Airlie break; 1667d785d78bSDave Airlie case RADEON_TXFORMAT_DXT23: 1668d785d78bSDave Airlie case RADEON_TXFORMAT_DXT45: 1669d785d78bSDave Airlie track->textures[i].cpp = 1; 1670d785d78bSDave Airlie track->textures[i].compress_format = R100_TRACK_COMP_DXT35; 1671d785d78bSDave Airlie break; 1672551ebd83SDave Airlie } 1673513bcb46SDave Airlie track->textures[i].cube_info[4].width = 1 << ((idx_value >> 16) & 0xf); 1674513bcb46SDave Airlie track->textures[i].cube_info[4].height = 1 << ((idx_value >> 20) & 0xf); 1675551ebd83SDave Airlie break; 1676551ebd83SDave Airlie case RADEON_PP_CUBIC_FACES_0: 1677551ebd83SDave Airlie case RADEON_PP_CUBIC_FACES_1: 1678551ebd83SDave Airlie case RADEON_PP_CUBIC_FACES_2: 1679513bcb46SDave Airlie tmp = idx_value; 1680551ebd83SDave Airlie i = (reg - RADEON_PP_CUBIC_FACES_0) / 4; 1681551ebd83SDave Airlie for (face = 0; face < 4; face++) { 1682551ebd83SDave Airlie track->textures[i].cube_info[face].width = 1 << ((tmp >> (face * 8)) & 0xf); 1683551ebd83SDave Airlie track->textures[i].cube_info[face].height = 1 << ((tmp >> ((face * 8) + 4)) & 0xf); 1684551ebd83SDave Airlie } 1685551ebd83SDave Airlie break; 1686771fe6b9SJerome Glisse default: 1687551ebd83SDave Airlie printk(KERN_ERR "Forbidden register 0x%04X in cs at %d\n", 1688551ebd83SDave Airlie reg, idx); 1689551ebd83SDave Airlie return -EINVAL; 1690771fe6b9SJerome Glisse } 1691771fe6b9SJerome Glisse return 0; 1692771fe6b9SJerome Glisse } 1693771fe6b9SJerome Glisse 1694068a117cSJerome Glisse int r100_cs_track_check_pkt3_indx_buffer(struct radeon_cs_parser *p, 1695068a117cSJerome Glisse struct radeon_cs_packet *pkt, 16964c788679SJerome Glisse struct radeon_bo *robj) 1697068a117cSJerome Glisse { 1698068a117cSJerome Glisse unsigned idx; 1699513bcb46SDave Airlie u32 value; 1700068a117cSJerome Glisse idx = pkt->idx + 1; 1701513bcb46SDave Airlie value = radeon_get_ib_value(p, idx + 2); 17024c788679SJerome Glisse if ((value + 1) > radeon_bo_size(robj)) { 1703068a117cSJerome Glisse DRM_ERROR("[drm] Buffer too small for PACKET3 INDX_BUFFER " 1704068a117cSJerome Glisse "(need %u have %lu) !\n", 1705513bcb46SDave Airlie value + 1, 17064c788679SJerome Glisse radeon_bo_size(robj)); 1707068a117cSJerome Glisse return -EINVAL; 1708068a117cSJerome Glisse } 1709068a117cSJerome Glisse return 0; 1710068a117cSJerome Glisse } 1711068a117cSJerome Glisse 1712771fe6b9SJerome Glisse static int r100_packet3_check(struct radeon_cs_parser *p, 1713771fe6b9SJerome Glisse struct radeon_cs_packet *pkt) 1714771fe6b9SJerome Glisse { 1715771fe6b9SJerome Glisse struct radeon_cs_reloc *reloc; 1716551ebd83SDave Airlie struct r100_cs_track *track; 1717771fe6b9SJerome Glisse unsigned idx; 1718771fe6b9SJerome Glisse volatile uint32_t *ib; 1719771fe6b9SJerome Glisse int r; 1720771fe6b9SJerome Glisse 1721771fe6b9SJerome Glisse ib = p->ib->ptr; 1722771fe6b9SJerome Glisse idx = pkt->idx + 1; 1723551ebd83SDave Airlie track = (struct r100_cs_track *)p->track; 1724771fe6b9SJerome Glisse switch (pkt->opcode) { 1725771fe6b9SJerome Glisse case PACKET3_3D_LOAD_VBPNTR: 1726513bcb46SDave Airlie r = r100_packet3_load_vbpntr(p, pkt, idx); 1727513bcb46SDave Airlie if (r) 1728771fe6b9SJerome Glisse return r; 1729771fe6b9SJerome Glisse break; 1730771fe6b9SJerome Glisse case PACKET3_INDX_BUFFER: 1731771fe6b9SJerome Glisse r = r100_cs_packet_next_reloc(p, &reloc); 1732771fe6b9SJerome Glisse if (r) { 1733771fe6b9SJerome Glisse DRM_ERROR("No reloc for packet3 %d\n", pkt->opcode); 1734771fe6b9SJerome Glisse r100_cs_dump_packet(p, pkt); 1735771fe6b9SJerome Glisse return r; 1736771fe6b9SJerome Glisse } 1737513bcb46SDave Airlie ib[idx+1] = radeon_get_ib_value(p, idx+1) + ((u32)reloc->lobj.gpu_offset); 1738068a117cSJerome Glisse r = r100_cs_track_check_pkt3_indx_buffer(p, pkt, reloc->robj); 1739068a117cSJerome Glisse if (r) { 1740068a117cSJerome Glisse return r; 1741068a117cSJerome Glisse } 1742771fe6b9SJerome Glisse break; 1743771fe6b9SJerome Glisse case 0x23: 1744771fe6b9SJerome Glisse /* 3D_RNDR_GEN_INDX_PRIM on r100/r200 */ 1745771fe6b9SJerome Glisse r = r100_cs_packet_next_reloc(p, &reloc); 1746771fe6b9SJerome Glisse if (r) { 1747771fe6b9SJerome Glisse DRM_ERROR("No reloc for packet3 %d\n", pkt->opcode); 1748771fe6b9SJerome Glisse r100_cs_dump_packet(p, pkt); 1749771fe6b9SJerome Glisse return r; 1750771fe6b9SJerome Glisse } 1751513bcb46SDave Airlie ib[idx] = radeon_get_ib_value(p, idx) + ((u32)reloc->lobj.gpu_offset); 1752551ebd83SDave Airlie track->num_arrays = 1; 1753513bcb46SDave Airlie track->vtx_size = r100_get_vtx_size(radeon_get_ib_value(p, idx + 2)); 1754551ebd83SDave Airlie 1755551ebd83SDave Airlie track->arrays[0].robj = reloc->robj; 1756551ebd83SDave Airlie track->arrays[0].esize = track->vtx_size; 1757551ebd83SDave Airlie 1758513bcb46SDave Airlie track->max_indx = radeon_get_ib_value(p, idx+1); 1759551ebd83SDave Airlie 1760513bcb46SDave Airlie track->vap_vf_cntl = radeon_get_ib_value(p, idx+3); 1761551ebd83SDave Airlie track->immd_dwords = pkt->count - 1; 1762551ebd83SDave Airlie r = r100_cs_track_check(p->rdev, track); 1763551ebd83SDave Airlie if (r) 1764551ebd83SDave Airlie return r; 1765771fe6b9SJerome Glisse break; 1766771fe6b9SJerome Glisse case PACKET3_3D_DRAW_IMMD: 1767513bcb46SDave Airlie if (((radeon_get_ib_value(p, idx + 1) >> 4) & 0x3) != 3) { 1768551ebd83SDave Airlie DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n"); 1769551ebd83SDave Airlie return -EINVAL; 1770551ebd83SDave Airlie } 1771cf57fc7aSAlex Deucher track->vtx_size = r100_get_vtx_size(radeon_get_ib_value(p, idx + 0)); 1772513bcb46SDave Airlie track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1); 1773551ebd83SDave Airlie track->immd_dwords = pkt->count - 1; 1774551ebd83SDave Airlie r = r100_cs_track_check(p->rdev, track); 1775551ebd83SDave Airlie if (r) 1776551ebd83SDave Airlie return r; 1777551ebd83SDave Airlie break; 1778771fe6b9SJerome Glisse /* triggers drawing using in-packet vertex data */ 1779771fe6b9SJerome Glisse case PACKET3_3D_DRAW_IMMD_2: 1780513bcb46SDave Airlie if (((radeon_get_ib_value(p, idx) >> 4) & 0x3) != 3) { 1781551ebd83SDave Airlie DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n"); 1782551ebd83SDave Airlie return -EINVAL; 1783551ebd83SDave Airlie } 1784513bcb46SDave Airlie track->vap_vf_cntl = radeon_get_ib_value(p, idx); 1785551ebd83SDave Airlie track->immd_dwords = pkt->count; 1786551ebd83SDave Airlie r = r100_cs_track_check(p->rdev, track); 1787551ebd83SDave Airlie if (r) 1788551ebd83SDave Airlie return r; 1789551ebd83SDave Airlie break; 1790771fe6b9SJerome Glisse /* triggers drawing using in-packet vertex data */ 1791771fe6b9SJerome Glisse case PACKET3_3D_DRAW_VBUF_2: 1792513bcb46SDave Airlie track->vap_vf_cntl = radeon_get_ib_value(p, idx); 1793551ebd83SDave Airlie r = r100_cs_track_check(p->rdev, track); 1794551ebd83SDave Airlie if (r) 1795551ebd83SDave Airlie return r; 1796551ebd83SDave Airlie break; 1797771fe6b9SJerome Glisse /* triggers drawing of vertex buffers setup elsewhere */ 1798771fe6b9SJerome Glisse case PACKET3_3D_DRAW_INDX_2: 1799513bcb46SDave Airlie track->vap_vf_cntl = radeon_get_ib_value(p, idx); 1800551ebd83SDave Airlie r = r100_cs_track_check(p->rdev, track); 1801551ebd83SDave Airlie if (r) 1802551ebd83SDave Airlie return r; 1803551ebd83SDave Airlie break; 1804771fe6b9SJerome Glisse /* triggers drawing using indices to vertex buffer */ 1805771fe6b9SJerome Glisse case PACKET3_3D_DRAW_VBUF: 1806513bcb46SDave Airlie track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1); 1807551ebd83SDave Airlie r = r100_cs_track_check(p->rdev, track); 1808551ebd83SDave Airlie if (r) 1809551ebd83SDave Airlie return r; 1810551ebd83SDave Airlie break; 1811771fe6b9SJerome Glisse /* triggers drawing of vertex buffers setup elsewhere */ 1812771fe6b9SJerome Glisse case PACKET3_3D_DRAW_INDX: 1813513bcb46SDave Airlie track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1); 1814551ebd83SDave Airlie r = r100_cs_track_check(p->rdev, track); 1815551ebd83SDave Airlie if (r) 1816551ebd83SDave Airlie return r; 1817551ebd83SDave Airlie break; 1818771fe6b9SJerome Glisse /* triggers drawing using indices to vertex buffer */ 1819771fe6b9SJerome Glisse case PACKET3_NOP: 1820771fe6b9SJerome Glisse break; 1821771fe6b9SJerome Glisse default: 1822771fe6b9SJerome Glisse DRM_ERROR("Packet3 opcode %x not supported\n", pkt->opcode); 1823771fe6b9SJerome Glisse return -EINVAL; 1824771fe6b9SJerome Glisse } 1825771fe6b9SJerome Glisse return 0; 1826771fe6b9SJerome Glisse } 1827771fe6b9SJerome Glisse 1828771fe6b9SJerome Glisse int r100_cs_parse(struct radeon_cs_parser *p) 1829771fe6b9SJerome Glisse { 1830771fe6b9SJerome Glisse struct radeon_cs_packet pkt; 18319f022ddfSJerome Glisse struct r100_cs_track *track; 1832771fe6b9SJerome Glisse int r; 1833771fe6b9SJerome Glisse 18349f022ddfSJerome Glisse track = kzalloc(sizeof(*track), GFP_KERNEL); 18359f022ddfSJerome Glisse r100_cs_track_clear(p->rdev, track); 18369f022ddfSJerome Glisse p->track = track; 1837771fe6b9SJerome Glisse do { 1838771fe6b9SJerome Glisse r = r100_cs_packet_parse(p, &pkt, p->idx); 1839771fe6b9SJerome Glisse if (r) { 1840771fe6b9SJerome Glisse return r; 1841771fe6b9SJerome Glisse } 1842771fe6b9SJerome Glisse p->idx += pkt.count + 2; 1843771fe6b9SJerome Glisse switch (pkt.type) { 1844771fe6b9SJerome Glisse case PACKET_TYPE0: 1845551ebd83SDave Airlie if (p->rdev->family >= CHIP_R200) 1846551ebd83SDave Airlie r = r100_cs_parse_packet0(p, &pkt, 1847551ebd83SDave Airlie p->rdev->config.r100.reg_safe_bm, 1848551ebd83SDave Airlie p->rdev->config.r100.reg_safe_bm_size, 1849551ebd83SDave Airlie &r200_packet0_check); 1850551ebd83SDave Airlie else 1851551ebd83SDave Airlie r = r100_cs_parse_packet0(p, &pkt, 1852551ebd83SDave Airlie p->rdev->config.r100.reg_safe_bm, 1853551ebd83SDave Airlie p->rdev->config.r100.reg_safe_bm_size, 1854551ebd83SDave Airlie &r100_packet0_check); 1855771fe6b9SJerome Glisse break; 1856771fe6b9SJerome Glisse case PACKET_TYPE2: 1857771fe6b9SJerome Glisse break; 1858771fe6b9SJerome Glisse case PACKET_TYPE3: 1859771fe6b9SJerome Glisse r = r100_packet3_check(p, &pkt); 1860771fe6b9SJerome Glisse break; 1861771fe6b9SJerome Glisse default: 1862771fe6b9SJerome Glisse DRM_ERROR("Unknown packet type %d !\n", 1863771fe6b9SJerome Glisse pkt.type); 1864771fe6b9SJerome Glisse return -EINVAL; 1865771fe6b9SJerome Glisse } 1866771fe6b9SJerome Glisse if (r) { 1867771fe6b9SJerome Glisse return r; 1868771fe6b9SJerome Glisse } 1869771fe6b9SJerome Glisse } while (p->idx < p->chunks[p->chunk_ib_idx].length_dw); 1870771fe6b9SJerome Glisse return 0; 1871771fe6b9SJerome Glisse } 1872771fe6b9SJerome Glisse 1873771fe6b9SJerome Glisse 1874771fe6b9SJerome Glisse /* 1875771fe6b9SJerome Glisse * Global GPU functions 1876771fe6b9SJerome Glisse */ 1877771fe6b9SJerome Glisse void r100_errata(struct radeon_device *rdev) 1878771fe6b9SJerome Glisse { 1879771fe6b9SJerome Glisse rdev->pll_errata = 0; 1880771fe6b9SJerome Glisse 1881771fe6b9SJerome Glisse if (rdev->family == CHIP_RV200 || rdev->family == CHIP_RS200) { 1882771fe6b9SJerome Glisse rdev->pll_errata |= CHIP_ERRATA_PLL_DUMMYREADS; 1883771fe6b9SJerome Glisse } 1884771fe6b9SJerome Glisse 1885771fe6b9SJerome Glisse if (rdev->family == CHIP_RV100 || 1886771fe6b9SJerome Glisse rdev->family == CHIP_RS100 || 1887771fe6b9SJerome Glisse rdev->family == CHIP_RS200) { 1888771fe6b9SJerome Glisse rdev->pll_errata |= CHIP_ERRATA_PLL_DELAY; 1889771fe6b9SJerome Glisse } 1890771fe6b9SJerome Glisse } 1891771fe6b9SJerome Glisse 1892771fe6b9SJerome Glisse /* Wait for vertical sync on primary CRTC */ 1893771fe6b9SJerome Glisse void r100_gpu_wait_for_vsync(struct radeon_device *rdev) 1894771fe6b9SJerome Glisse { 1895771fe6b9SJerome Glisse uint32_t crtc_gen_cntl, tmp; 1896771fe6b9SJerome Glisse int i; 1897771fe6b9SJerome Glisse 1898771fe6b9SJerome Glisse crtc_gen_cntl = RREG32(RADEON_CRTC_GEN_CNTL); 1899771fe6b9SJerome Glisse if ((crtc_gen_cntl & RADEON_CRTC_DISP_REQ_EN_B) || 1900771fe6b9SJerome Glisse !(crtc_gen_cntl & RADEON_CRTC_EN)) { 1901771fe6b9SJerome Glisse return; 1902771fe6b9SJerome Glisse } 1903771fe6b9SJerome Glisse /* Clear the CRTC_VBLANK_SAVE bit */ 1904771fe6b9SJerome Glisse WREG32(RADEON_CRTC_STATUS, RADEON_CRTC_VBLANK_SAVE_CLEAR); 1905771fe6b9SJerome Glisse for (i = 0; i < rdev->usec_timeout; i++) { 1906771fe6b9SJerome Glisse tmp = RREG32(RADEON_CRTC_STATUS); 1907771fe6b9SJerome Glisse if (tmp & RADEON_CRTC_VBLANK_SAVE) { 1908771fe6b9SJerome Glisse return; 1909771fe6b9SJerome Glisse } 1910771fe6b9SJerome Glisse DRM_UDELAY(1); 1911771fe6b9SJerome Glisse } 1912771fe6b9SJerome Glisse } 1913771fe6b9SJerome Glisse 1914771fe6b9SJerome Glisse /* Wait for vertical sync on secondary CRTC */ 1915771fe6b9SJerome Glisse void r100_gpu_wait_for_vsync2(struct radeon_device *rdev) 1916771fe6b9SJerome Glisse { 1917771fe6b9SJerome Glisse uint32_t crtc2_gen_cntl, tmp; 1918771fe6b9SJerome Glisse int i; 1919771fe6b9SJerome Glisse 1920771fe6b9SJerome Glisse crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL); 1921771fe6b9SJerome Glisse if ((crtc2_gen_cntl & RADEON_CRTC2_DISP_REQ_EN_B) || 1922771fe6b9SJerome Glisse !(crtc2_gen_cntl & RADEON_CRTC2_EN)) 1923771fe6b9SJerome Glisse return; 1924771fe6b9SJerome Glisse 1925771fe6b9SJerome Glisse /* Clear the CRTC_VBLANK_SAVE bit */ 1926771fe6b9SJerome Glisse WREG32(RADEON_CRTC2_STATUS, RADEON_CRTC2_VBLANK_SAVE_CLEAR); 1927771fe6b9SJerome Glisse for (i = 0; i < rdev->usec_timeout; i++) { 1928771fe6b9SJerome Glisse tmp = RREG32(RADEON_CRTC2_STATUS); 1929771fe6b9SJerome Glisse if (tmp & RADEON_CRTC2_VBLANK_SAVE) { 1930771fe6b9SJerome Glisse return; 1931771fe6b9SJerome Glisse } 1932771fe6b9SJerome Glisse DRM_UDELAY(1); 1933771fe6b9SJerome Glisse } 1934771fe6b9SJerome Glisse } 1935771fe6b9SJerome Glisse 1936771fe6b9SJerome Glisse int r100_rbbm_fifo_wait_for_entry(struct radeon_device *rdev, unsigned n) 1937771fe6b9SJerome Glisse { 1938771fe6b9SJerome Glisse unsigned i; 1939771fe6b9SJerome Glisse uint32_t tmp; 1940771fe6b9SJerome Glisse 1941771fe6b9SJerome Glisse for (i = 0; i < rdev->usec_timeout; i++) { 1942771fe6b9SJerome Glisse tmp = RREG32(RADEON_RBBM_STATUS) & RADEON_RBBM_FIFOCNT_MASK; 1943771fe6b9SJerome Glisse if (tmp >= n) { 1944771fe6b9SJerome Glisse return 0; 1945771fe6b9SJerome Glisse } 1946771fe6b9SJerome Glisse DRM_UDELAY(1); 1947771fe6b9SJerome Glisse } 1948771fe6b9SJerome Glisse return -1; 1949771fe6b9SJerome Glisse } 1950771fe6b9SJerome Glisse 1951771fe6b9SJerome Glisse int r100_gui_wait_for_idle(struct radeon_device *rdev) 1952771fe6b9SJerome Glisse { 1953771fe6b9SJerome Glisse unsigned i; 1954771fe6b9SJerome Glisse uint32_t tmp; 1955771fe6b9SJerome Glisse 1956771fe6b9SJerome Glisse if (r100_rbbm_fifo_wait_for_entry(rdev, 64)) { 1957771fe6b9SJerome Glisse printk(KERN_WARNING "radeon: wait for empty RBBM fifo failed !" 1958771fe6b9SJerome Glisse " Bad things might happen.\n"); 1959771fe6b9SJerome Glisse } 1960771fe6b9SJerome Glisse for (i = 0; i < rdev->usec_timeout; i++) { 1961771fe6b9SJerome Glisse tmp = RREG32(RADEON_RBBM_STATUS); 19624612dc97SAlex Deucher if (!(tmp & RADEON_RBBM_ACTIVE)) { 1963771fe6b9SJerome Glisse return 0; 1964771fe6b9SJerome Glisse } 1965771fe6b9SJerome Glisse DRM_UDELAY(1); 1966771fe6b9SJerome Glisse } 1967771fe6b9SJerome Glisse return -1; 1968771fe6b9SJerome Glisse } 1969771fe6b9SJerome Glisse 1970771fe6b9SJerome Glisse int r100_mc_wait_for_idle(struct radeon_device *rdev) 1971771fe6b9SJerome Glisse { 1972771fe6b9SJerome Glisse unsigned i; 1973771fe6b9SJerome Glisse uint32_t tmp; 1974771fe6b9SJerome Glisse 1975771fe6b9SJerome Glisse for (i = 0; i < rdev->usec_timeout; i++) { 1976771fe6b9SJerome Glisse /* read MC_STATUS */ 19774612dc97SAlex Deucher tmp = RREG32(RADEON_MC_STATUS); 19784612dc97SAlex Deucher if (tmp & RADEON_MC_IDLE) { 1979771fe6b9SJerome Glisse return 0; 1980771fe6b9SJerome Glisse } 1981771fe6b9SJerome Glisse DRM_UDELAY(1); 1982771fe6b9SJerome Glisse } 1983771fe6b9SJerome Glisse return -1; 1984771fe6b9SJerome Glisse } 1985771fe6b9SJerome Glisse 1986225758d8SJerome Glisse void r100_gpu_lockup_update(struct r100_gpu_lockup *lockup, struct radeon_cp *cp) 1987771fe6b9SJerome Glisse { 1988225758d8SJerome Glisse lockup->last_cp_rptr = cp->rptr; 1989225758d8SJerome Glisse lockup->last_jiffies = jiffies; 1990771fe6b9SJerome Glisse } 1991771fe6b9SJerome Glisse 1992225758d8SJerome Glisse /** 1993225758d8SJerome Glisse * r100_gpu_cp_is_lockup() - check if CP is lockup by recording information 1994225758d8SJerome Glisse * @rdev: radeon device structure 1995225758d8SJerome Glisse * @lockup: r100_gpu_lockup structure holding CP lockup tracking informations 1996225758d8SJerome Glisse * @cp: radeon_cp structure holding CP information 1997225758d8SJerome Glisse * 1998225758d8SJerome Glisse * We don't need to initialize the lockup tracking information as we will either 1999225758d8SJerome Glisse * have CP rptr to a different value of jiffies wrap around which will force 2000225758d8SJerome Glisse * initialization of the lockup tracking informations. 2001225758d8SJerome Glisse * 2002225758d8SJerome Glisse * A possible false positivie is if we get call after while and last_cp_rptr == 2003225758d8SJerome Glisse * the current CP rptr, even if it's unlikely it might happen. To avoid this 2004225758d8SJerome Glisse * if the elapsed time since last call is bigger than 2 second than we return 2005225758d8SJerome Glisse * false and update the tracking information. Due to this the caller must call 2006225758d8SJerome Glisse * r100_gpu_cp_is_lockup several time in less than 2sec for lockup to be reported 2007225758d8SJerome Glisse * the fencing code should be cautious about that. 2008225758d8SJerome Glisse * 2009225758d8SJerome Glisse * Caller should write to the ring to force CP to do something so we don't get 2010225758d8SJerome Glisse * false positive when CP is just gived nothing to do. 2011225758d8SJerome Glisse * 2012225758d8SJerome Glisse **/ 2013225758d8SJerome Glisse bool r100_gpu_cp_is_lockup(struct radeon_device *rdev, struct r100_gpu_lockup *lockup, struct radeon_cp *cp) 2014771fe6b9SJerome Glisse { 2015225758d8SJerome Glisse unsigned long cjiffies, elapsed; 2016771fe6b9SJerome Glisse 2017225758d8SJerome Glisse cjiffies = jiffies; 2018225758d8SJerome Glisse if (!time_after(cjiffies, lockup->last_jiffies)) { 2019225758d8SJerome Glisse /* likely a wrap around */ 2020225758d8SJerome Glisse lockup->last_cp_rptr = cp->rptr; 2021225758d8SJerome Glisse lockup->last_jiffies = jiffies; 2022225758d8SJerome Glisse return false; 2023225758d8SJerome Glisse } 2024225758d8SJerome Glisse if (cp->rptr != lockup->last_cp_rptr) { 2025225758d8SJerome Glisse /* CP is still working no lockup */ 2026225758d8SJerome Glisse lockup->last_cp_rptr = cp->rptr; 2027225758d8SJerome Glisse lockup->last_jiffies = jiffies; 2028225758d8SJerome Glisse return false; 2029225758d8SJerome Glisse } 2030225758d8SJerome Glisse elapsed = jiffies_to_msecs(cjiffies - lockup->last_jiffies); 2031225758d8SJerome Glisse if (elapsed >= 3000) { 2032225758d8SJerome Glisse /* very likely the improbable case where current 2033225758d8SJerome Glisse * rptr is equal to last recorded, a while ago, rptr 2034225758d8SJerome Glisse * this is more likely a false positive update tracking 2035225758d8SJerome Glisse * information which should force us to be recall at 2036225758d8SJerome Glisse * latter point 2037225758d8SJerome Glisse */ 2038225758d8SJerome Glisse lockup->last_cp_rptr = cp->rptr; 2039225758d8SJerome Glisse lockup->last_jiffies = jiffies; 2040225758d8SJerome Glisse return false; 2041225758d8SJerome Glisse } 2042225758d8SJerome Glisse if (elapsed >= 1000) { 2043225758d8SJerome Glisse dev_err(rdev->dev, "GPU lockup CP stall for more than %lumsec\n", elapsed); 2044225758d8SJerome Glisse return true; 2045225758d8SJerome Glisse } 2046225758d8SJerome Glisse /* give a chance to the GPU ... */ 2047225758d8SJerome Glisse return false; 2048771fe6b9SJerome Glisse } 2049771fe6b9SJerome Glisse 2050225758d8SJerome Glisse bool r100_gpu_is_lockup(struct radeon_device *rdev) 2051771fe6b9SJerome Glisse { 2052225758d8SJerome Glisse u32 rbbm_status; 2053225758d8SJerome Glisse int r; 2054771fe6b9SJerome Glisse 2055225758d8SJerome Glisse rbbm_status = RREG32(R_000E40_RBBM_STATUS); 2056225758d8SJerome Glisse if (!G_000E40_GUI_ACTIVE(rbbm_status)) { 2057225758d8SJerome Glisse r100_gpu_lockup_update(&rdev->config.r100.lockup, &rdev->cp); 2058225758d8SJerome Glisse return false; 2059225758d8SJerome Glisse } 2060225758d8SJerome Glisse /* force CP activities */ 2061225758d8SJerome Glisse r = radeon_ring_lock(rdev, 2); 2062225758d8SJerome Glisse if (!r) { 2063225758d8SJerome Glisse /* PACKET2 NOP */ 2064225758d8SJerome Glisse radeon_ring_write(rdev, 0x80000000); 2065225758d8SJerome Glisse radeon_ring_write(rdev, 0x80000000); 2066225758d8SJerome Glisse radeon_ring_unlock_commit(rdev); 2067225758d8SJerome Glisse } 2068225758d8SJerome Glisse rdev->cp.rptr = RREG32(RADEON_CP_RB_RPTR); 2069225758d8SJerome Glisse return r100_gpu_cp_is_lockup(rdev, &rdev->config.r100.lockup, &rdev->cp); 2070225758d8SJerome Glisse } 2071225758d8SJerome Glisse 207290aca4d2SJerome Glisse void r100_bm_disable(struct radeon_device *rdev) 207390aca4d2SJerome Glisse { 207490aca4d2SJerome Glisse u32 tmp; 207590aca4d2SJerome Glisse 207690aca4d2SJerome Glisse /* disable bus mastering */ 207790aca4d2SJerome Glisse tmp = RREG32(R_000030_BUS_CNTL); 207890aca4d2SJerome Glisse WREG32(R_000030_BUS_CNTL, (tmp & 0xFFFFFFFF) | 0x00000044); 2079771fe6b9SJerome Glisse mdelay(1); 208090aca4d2SJerome Glisse WREG32(R_000030_BUS_CNTL, (tmp & 0xFFFFFFFF) | 0x00000042); 208190aca4d2SJerome Glisse mdelay(1); 208290aca4d2SJerome Glisse WREG32(R_000030_BUS_CNTL, (tmp & 0xFFFFFFFF) | 0x00000040); 208390aca4d2SJerome Glisse tmp = RREG32(RADEON_BUS_CNTL); 208490aca4d2SJerome Glisse mdelay(1); 208590aca4d2SJerome Glisse pci_read_config_word(rdev->pdev, 0x4, (u16*)&tmp); 208690aca4d2SJerome Glisse pci_write_config_word(rdev->pdev, 0x4, tmp & 0xFFFB); 208790aca4d2SJerome Glisse mdelay(1); 208890aca4d2SJerome Glisse } 208990aca4d2SJerome Glisse 2090a2d07b74SJerome Glisse int r100_asic_reset(struct radeon_device *rdev) 2091771fe6b9SJerome Glisse { 209290aca4d2SJerome Glisse struct r100_mc_save save; 209390aca4d2SJerome Glisse u32 status, tmp; 2094771fe6b9SJerome Glisse 209590aca4d2SJerome Glisse r100_mc_stop(rdev, &save); 209690aca4d2SJerome Glisse status = RREG32(R_000E40_RBBM_STATUS); 209790aca4d2SJerome Glisse if (!G_000E40_GUI_ACTIVE(status)) { 2098771fe6b9SJerome Glisse return 0; 2099771fe6b9SJerome Glisse } 210090aca4d2SJerome Glisse status = RREG32(R_000E40_RBBM_STATUS); 210190aca4d2SJerome Glisse dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status); 210290aca4d2SJerome Glisse /* stop CP */ 210390aca4d2SJerome Glisse WREG32(RADEON_CP_CSQ_CNTL, 0); 210490aca4d2SJerome Glisse tmp = RREG32(RADEON_CP_RB_CNTL); 210590aca4d2SJerome Glisse WREG32(RADEON_CP_RB_CNTL, tmp | RADEON_RB_RPTR_WR_ENA); 210690aca4d2SJerome Glisse WREG32(RADEON_CP_RB_RPTR_WR, 0); 210790aca4d2SJerome Glisse WREG32(RADEON_CP_RB_WPTR, 0); 210890aca4d2SJerome Glisse WREG32(RADEON_CP_RB_CNTL, tmp); 210990aca4d2SJerome Glisse /* save PCI state */ 211090aca4d2SJerome Glisse pci_save_state(rdev->pdev); 211190aca4d2SJerome Glisse /* disable bus mastering */ 211290aca4d2SJerome Glisse r100_bm_disable(rdev); 211390aca4d2SJerome Glisse WREG32(R_0000F0_RBBM_SOFT_RESET, S_0000F0_SOFT_RESET_SE(1) | 211490aca4d2SJerome Glisse S_0000F0_SOFT_RESET_RE(1) | 211590aca4d2SJerome Glisse S_0000F0_SOFT_RESET_PP(1) | 211690aca4d2SJerome Glisse S_0000F0_SOFT_RESET_RB(1)); 211790aca4d2SJerome Glisse RREG32(R_0000F0_RBBM_SOFT_RESET); 211890aca4d2SJerome Glisse mdelay(500); 211990aca4d2SJerome Glisse WREG32(R_0000F0_RBBM_SOFT_RESET, 0); 212090aca4d2SJerome Glisse mdelay(1); 212190aca4d2SJerome Glisse status = RREG32(R_000E40_RBBM_STATUS); 212290aca4d2SJerome Glisse dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status); 2123771fe6b9SJerome Glisse /* reset CP */ 212490aca4d2SJerome Glisse WREG32(R_0000F0_RBBM_SOFT_RESET, S_0000F0_SOFT_RESET_CP(1)); 212590aca4d2SJerome Glisse RREG32(R_0000F0_RBBM_SOFT_RESET); 212690aca4d2SJerome Glisse mdelay(500); 212790aca4d2SJerome Glisse WREG32(R_0000F0_RBBM_SOFT_RESET, 0); 212890aca4d2SJerome Glisse mdelay(1); 212990aca4d2SJerome Glisse status = RREG32(R_000E40_RBBM_STATUS); 213090aca4d2SJerome Glisse dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status); 213190aca4d2SJerome Glisse /* restore PCI & busmastering */ 213290aca4d2SJerome Glisse pci_restore_state(rdev->pdev); 213390aca4d2SJerome Glisse r100_enable_bm(rdev); 2134771fe6b9SJerome Glisse /* Check if GPU is idle */ 213590aca4d2SJerome Glisse if (G_000E40_SE_BUSY(status) || G_000E40_RE_BUSY(status) || 213690aca4d2SJerome Glisse G_000E40_TAM_BUSY(status) || G_000E40_PB_BUSY(status)) { 213790aca4d2SJerome Glisse dev_err(rdev->dev, "failed to reset GPU\n"); 213890aca4d2SJerome Glisse rdev->gpu_lockup = true; 2139771fe6b9SJerome Glisse return -1; 2140771fe6b9SJerome Glisse } 214190aca4d2SJerome Glisse r100_mc_resume(rdev, &save); 214290aca4d2SJerome Glisse dev_info(rdev->dev, "GPU reset succeed\n"); 2143771fe6b9SJerome Glisse return 0; 2144771fe6b9SJerome Glisse } 2145771fe6b9SJerome Glisse 214692cde00cSAlex Deucher void r100_set_common_regs(struct radeon_device *rdev) 214792cde00cSAlex Deucher { 21482739d49cSAlex Deucher struct drm_device *dev = rdev->ddev; 21492739d49cSAlex Deucher bool force_dac2 = false; 2150d668046cSDave Airlie u32 tmp; 21512739d49cSAlex Deucher 215292cde00cSAlex Deucher /* set these so they don't interfere with anything */ 215392cde00cSAlex Deucher WREG32(RADEON_OV0_SCALE_CNTL, 0); 215492cde00cSAlex Deucher WREG32(RADEON_SUBPIC_CNTL, 0); 215592cde00cSAlex Deucher WREG32(RADEON_VIPH_CONTROL, 0); 215692cde00cSAlex Deucher WREG32(RADEON_I2C_CNTL_1, 0); 215792cde00cSAlex Deucher WREG32(RADEON_DVI_I2C_CNTL_1, 0); 215892cde00cSAlex Deucher WREG32(RADEON_CAP0_TRIG_CNTL, 0); 215992cde00cSAlex Deucher WREG32(RADEON_CAP1_TRIG_CNTL, 0); 21602739d49cSAlex Deucher 21612739d49cSAlex Deucher /* always set up dac2 on rn50 and some rv100 as lots 21622739d49cSAlex Deucher * of servers seem to wire it up to a VGA port but 21632739d49cSAlex Deucher * don't report it in the bios connector 21642739d49cSAlex Deucher * table. 21652739d49cSAlex Deucher */ 21662739d49cSAlex Deucher switch (dev->pdev->device) { 21672739d49cSAlex Deucher /* RN50 */ 21682739d49cSAlex Deucher case 0x515e: 21692739d49cSAlex Deucher case 0x5969: 21702739d49cSAlex Deucher force_dac2 = true; 21712739d49cSAlex Deucher break; 21722739d49cSAlex Deucher /* RV100*/ 21732739d49cSAlex Deucher case 0x5159: 21742739d49cSAlex Deucher case 0x515a: 21752739d49cSAlex Deucher /* DELL triple head servers */ 21762739d49cSAlex Deucher if ((dev->pdev->subsystem_vendor == 0x1028 /* DELL */) && 21772739d49cSAlex Deucher ((dev->pdev->subsystem_device == 0x016c) || 21782739d49cSAlex Deucher (dev->pdev->subsystem_device == 0x016d) || 21792739d49cSAlex Deucher (dev->pdev->subsystem_device == 0x016e) || 21802739d49cSAlex Deucher (dev->pdev->subsystem_device == 0x016f) || 21812739d49cSAlex Deucher (dev->pdev->subsystem_device == 0x0170) || 21822739d49cSAlex Deucher (dev->pdev->subsystem_device == 0x017d) || 21832739d49cSAlex Deucher (dev->pdev->subsystem_device == 0x017e) || 21842739d49cSAlex Deucher (dev->pdev->subsystem_device == 0x0183) || 21852739d49cSAlex Deucher (dev->pdev->subsystem_device == 0x018a) || 21862739d49cSAlex Deucher (dev->pdev->subsystem_device == 0x019a))) 21872739d49cSAlex Deucher force_dac2 = true; 21882739d49cSAlex Deucher break; 21892739d49cSAlex Deucher } 21902739d49cSAlex Deucher 21912739d49cSAlex Deucher if (force_dac2) { 21922739d49cSAlex Deucher u32 disp_hw_debug = RREG32(RADEON_DISP_HW_DEBUG); 21932739d49cSAlex Deucher u32 tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL); 21942739d49cSAlex Deucher u32 dac2_cntl = RREG32(RADEON_DAC_CNTL2); 21952739d49cSAlex Deucher 21962739d49cSAlex Deucher /* For CRT on DAC2, don't turn it on if BIOS didn't 21972739d49cSAlex Deucher enable it, even it's detected. 21982739d49cSAlex Deucher */ 21992739d49cSAlex Deucher 22002739d49cSAlex Deucher /* force it to crtc0 */ 22012739d49cSAlex Deucher dac2_cntl &= ~RADEON_DAC2_DAC_CLK_SEL; 22022739d49cSAlex Deucher dac2_cntl |= RADEON_DAC2_DAC2_CLK_SEL; 22032739d49cSAlex Deucher disp_hw_debug |= RADEON_CRT2_DISP1_SEL; 22042739d49cSAlex Deucher 22052739d49cSAlex Deucher /* set up the TV DAC */ 22062739d49cSAlex Deucher tv_dac_cntl &= ~(RADEON_TV_DAC_PEDESTAL | 22072739d49cSAlex Deucher RADEON_TV_DAC_STD_MASK | 22082739d49cSAlex Deucher RADEON_TV_DAC_RDACPD | 22092739d49cSAlex Deucher RADEON_TV_DAC_GDACPD | 22102739d49cSAlex Deucher RADEON_TV_DAC_BDACPD | 22112739d49cSAlex Deucher RADEON_TV_DAC_BGADJ_MASK | 22122739d49cSAlex Deucher RADEON_TV_DAC_DACADJ_MASK); 22132739d49cSAlex Deucher tv_dac_cntl |= (RADEON_TV_DAC_NBLANK | 22142739d49cSAlex Deucher RADEON_TV_DAC_NHOLD | 22152739d49cSAlex Deucher RADEON_TV_DAC_STD_PS2 | 22162739d49cSAlex Deucher (0x58 << 16)); 22172739d49cSAlex Deucher 22182739d49cSAlex Deucher WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl); 22192739d49cSAlex Deucher WREG32(RADEON_DISP_HW_DEBUG, disp_hw_debug); 22202739d49cSAlex Deucher WREG32(RADEON_DAC_CNTL2, dac2_cntl); 22212739d49cSAlex Deucher } 2222d668046cSDave Airlie 2223d668046cSDave Airlie /* switch PM block to ACPI mode */ 2224d668046cSDave Airlie tmp = RREG32_PLL(RADEON_PLL_PWRMGT_CNTL); 2225d668046cSDave Airlie tmp &= ~RADEON_PM_MODE_SEL; 2226d668046cSDave Airlie WREG32_PLL(RADEON_PLL_PWRMGT_CNTL, tmp); 2227d668046cSDave Airlie 222892cde00cSAlex Deucher } 2229771fe6b9SJerome Glisse 2230771fe6b9SJerome Glisse /* 2231771fe6b9SJerome Glisse * VRAM info 2232771fe6b9SJerome Glisse */ 2233771fe6b9SJerome Glisse static void r100_vram_get_type(struct radeon_device *rdev) 2234771fe6b9SJerome Glisse { 2235771fe6b9SJerome Glisse uint32_t tmp; 2236771fe6b9SJerome Glisse 2237771fe6b9SJerome Glisse rdev->mc.vram_is_ddr = false; 2238771fe6b9SJerome Glisse if (rdev->flags & RADEON_IS_IGP) 2239771fe6b9SJerome Glisse rdev->mc.vram_is_ddr = true; 2240771fe6b9SJerome Glisse else if (RREG32(RADEON_MEM_SDRAM_MODE_REG) & RADEON_MEM_CFG_TYPE_DDR) 2241771fe6b9SJerome Glisse rdev->mc.vram_is_ddr = true; 2242771fe6b9SJerome Glisse if ((rdev->family == CHIP_RV100) || 2243771fe6b9SJerome Glisse (rdev->family == CHIP_RS100) || 2244771fe6b9SJerome Glisse (rdev->family == CHIP_RS200)) { 2245771fe6b9SJerome Glisse tmp = RREG32(RADEON_MEM_CNTL); 2246771fe6b9SJerome Glisse if (tmp & RV100_HALF_MODE) { 2247771fe6b9SJerome Glisse rdev->mc.vram_width = 32; 2248771fe6b9SJerome Glisse } else { 2249771fe6b9SJerome Glisse rdev->mc.vram_width = 64; 2250771fe6b9SJerome Glisse } 2251771fe6b9SJerome Glisse if (rdev->flags & RADEON_SINGLE_CRTC) { 2252771fe6b9SJerome Glisse rdev->mc.vram_width /= 4; 2253771fe6b9SJerome Glisse rdev->mc.vram_is_ddr = true; 2254771fe6b9SJerome Glisse } 2255771fe6b9SJerome Glisse } else if (rdev->family <= CHIP_RV280) { 2256771fe6b9SJerome Glisse tmp = RREG32(RADEON_MEM_CNTL); 2257771fe6b9SJerome Glisse if (tmp & RADEON_MEM_NUM_CHANNELS_MASK) { 2258771fe6b9SJerome Glisse rdev->mc.vram_width = 128; 2259771fe6b9SJerome Glisse } else { 2260771fe6b9SJerome Glisse rdev->mc.vram_width = 64; 2261771fe6b9SJerome Glisse } 2262771fe6b9SJerome Glisse } else { 2263771fe6b9SJerome Glisse /* newer IGPs */ 2264771fe6b9SJerome Glisse rdev->mc.vram_width = 128; 2265771fe6b9SJerome Glisse } 2266771fe6b9SJerome Glisse } 2267771fe6b9SJerome Glisse 22682a0f8918SDave Airlie static u32 r100_get_accessible_vram(struct radeon_device *rdev) 2269771fe6b9SJerome Glisse { 22702a0f8918SDave Airlie u32 aper_size; 22712a0f8918SDave Airlie u8 byte; 22722a0f8918SDave Airlie 22732a0f8918SDave Airlie aper_size = RREG32(RADEON_CONFIG_APER_SIZE); 22742a0f8918SDave Airlie 22752a0f8918SDave Airlie /* Set HDP_APER_CNTL only on cards that are known not to be broken, 22762a0f8918SDave Airlie * that is has the 2nd generation multifunction PCI interface 22772a0f8918SDave Airlie */ 22782a0f8918SDave Airlie if (rdev->family == CHIP_RV280 || 22792a0f8918SDave Airlie rdev->family >= CHIP_RV350) { 22802a0f8918SDave Airlie WREG32_P(RADEON_HOST_PATH_CNTL, RADEON_HDP_APER_CNTL, 22812a0f8918SDave Airlie ~RADEON_HDP_APER_CNTL); 22822a0f8918SDave Airlie DRM_INFO("Generation 2 PCI interface, using max accessible memory\n"); 22832a0f8918SDave Airlie return aper_size * 2; 22842a0f8918SDave Airlie } 22852a0f8918SDave Airlie 22862a0f8918SDave Airlie /* Older cards have all sorts of funny issues to deal with. First 22872a0f8918SDave Airlie * check if it's a multifunction card by reading the PCI config 22882a0f8918SDave Airlie * header type... Limit those to one aperture size 22892a0f8918SDave Airlie */ 22902a0f8918SDave Airlie pci_read_config_byte(rdev->pdev, 0xe, &byte); 22912a0f8918SDave Airlie if (byte & 0x80) { 22922a0f8918SDave Airlie DRM_INFO("Generation 1 PCI interface in multifunction mode\n"); 22932a0f8918SDave Airlie DRM_INFO("Limiting VRAM to one aperture\n"); 22942a0f8918SDave Airlie return aper_size; 22952a0f8918SDave Airlie } 22962a0f8918SDave Airlie 22972a0f8918SDave Airlie /* Single function older card. We read HDP_APER_CNTL to see how the BIOS 22982a0f8918SDave Airlie * have set it up. We don't write this as it's broken on some ASICs but 22992a0f8918SDave Airlie * we expect the BIOS to have done the right thing (might be too optimistic...) 23002a0f8918SDave Airlie */ 23012a0f8918SDave Airlie if (RREG32(RADEON_HOST_PATH_CNTL) & RADEON_HDP_APER_CNTL) 23022a0f8918SDave Airlie return aper_size * 2; 23032a0f8918SDave Airlie return aper_size; 23042a0f8918SDave Airlie } 23052a0f8918SDave Airlie 23062a0f8918SDave Airlie void r100_vram_init_sizes(struct radeon_device *rdev) 23072a0f8918SDave Airlie { 23082a0f8918SDave Airlie u64 config_aper_size; 23092a0f8918SDave Airlie 2310d594e46aSJerome Glisse /* work out accessible VRAM */ 2311d594e46aSJerome Glisse rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0); 2312d594e46aSJerome Glisse rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0); 231351e5fcd3SJerome Glisse rdev->mc.visible_vram_size = r100_get_accessible_vram(rdev); 231451e5fcd3SJerome Glisse /* FIXME we don't use the second aperture yet when we could use it */ 231551e5fcd3SJerome Glisse if (rdev->mc.visible_vram_size > rdev->mc.aper_size) 231651e5fcd3SJerome Glisse rdev->mc.visible_vram_size = rdev->mc.aper_size; 23172a0f8918SDave Airlie config_aper_size = RREG32(RADEON_CONFIG_APER_SIZE); 2318771fe6b9SJerome Glisse if (rdev->flags & RADEON_IS_IGP) { 2319771fe6b9SJerome Glisse uint32_t tom; 2320771fe6b9SJerome Glisse /* read NB_TOM to get the amount of ram stolen for the GPU */ 2321771fe6b9SJerome Glisse tom = RREG32(RADEON_NB_TOM); 23227a50f01aSDave Airlie rdev->mc.real_vram_size = (((tom >> 16) - (tom & 0xffff) + 1) << 16); 23237a50f01aSDave Airlie WREG32(RADEON_CONFIG_MEMSIZE, rdev->mc.real_vram_size); 23247a50f01aSDave Airlie rdev->mc.mc_vram_size = rdev->mc.real_vram_size; 2325771fe6b9SJerome Glisse } else { 23267a50f01aSDave Airlie rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE); 2327771fe6b9SJerome Glisse /* Some production boards of m6 will report 0 2328771fe6b9SJerome Glisse * if it's 8 MB 2329771fe6b9SJerome Glisse */ 23307a50f01aSDave Airlie if (rdev->mc.real_vram_size == 0) { 23317a50f01aSDave Airlie rdev->mc.real_vram_size = 8192 * 1024; 23327a50f01aSDave Airlie WREG32(RADEON_CONFIG_MEMSIZE, rdev->mc.real_vram_size); 2333771fe6b9SJerome Glisse } 23342a0f8918SDave Airlie /* Fix for RN50, M6, M7 with 8/16/32(??) MBs of VRAM - 2335d594e46aSJerome Glisse * Novell bug 204882 + along with lots of ubuntu ones 2336d594e46aSJerome Glisse */ 23377a50f01aSDave Airlie if (config_aper_size > rdev->mc.real_vram_size) 23387a50f01aSDave Airlie rdev->mc.mc_vram_size = config_aper_size; 23397a50f01aSDave Airlie else 23407a50f01aSDave Airlie rdev->mc.mc_vram_size = rdev->mc.real_vram_size; 2341771fe6b9SJerome Glisse } 2342d594e46aSJerome Glisse } 23432a0f8918SDave Airlie 234428d52043SDave Airlie void r100_vga_set_state(struct radeon_device *rdev, bool state) 234528d52043SDave Airlie { 234628d52043SDave Airlie uint32_t temp; 234728d52043SDave Airlie 234828d52043SDave Airlie temp = RREG32(RADEON_CONFIG_CNTL); 234928d52043SDave Airlie if (state == false) { 235028d52043SDave Airlie temp &= ~(1<<8); 235128d52043SDave Airlie temp |= (1<<9); 235228d52043SDave Airlie } else { 235328d52043SDave Airlie temp &= ~(1<<9); 235428d52043SDave Airlie } 235528d52043SDave Airlie WREG32(RADEON_CONFIG_CNTL, temp); 235628d52043SDave Airlie } 235728d52043SDave Airlie 2358d594e46aSJerome Glisse void r100_mc_init(struct radeon_device *rdev) 23592a0f8918SDave Airlie { 2360d594e46aSJerome Glisse u64 base; 23612a0f8918SDave Airlie 2362d594e46aSJerome Glisse r100_vram_get_type(rdev); 23632a0f8918SDave Airlie r100_vram_init_sizes(rdev); 2364d594e46aSJerome Glisse base = rdev->mc.aper_base; 2365d594e46aSJerome Glisse if (rdev->flags & RADEON_IS_IGP) 2366d594e46aSJerome Glisse base = (RREG32(RADEON_NB_TOM) & 0xffff) << 16; 2367d594e46aSJerome Glisse radeon_vram_location(rdev, &rdev->mc, base); 2368d594e46aSJerome Glisse if (!(rdev->flags & RADEON_IS_AGP)) 2369d594e46aSJerome Glisse radeon_gtt_location(rdev, &rdev->mc); 2370f47299c5SAlex Deucher radeon_update_bandwidth_info(rdev); 2371771fe6b9SJerome Glisse } 2372771fe6b9SJerome Glisse 2373771fe6b9SJerome Glisse 2374771fe6b9SJerome Glisse /* 2375771fe6b9SJerome Glisse * Indirect registers accessor 2376771fe6b9SJerome Glisse */ 2377771fe6b9SJerome Glisse void r100_pll_errata_after_index(struct radeon_device *rdev) 2378771fe6b9SJerome Glisse { 2379771fe6b9SJerome Glisse if (!(rdev->pll_errata & CHIP_ERRATA_PLL_DUMMYREADS)) { 2380771fe6b9SJerome Glisse return; 2381771fe6b9SJerome Glisse } 2382771fe6b9SJerome Glisse (void)RREG32(RADEON_CLOCK_CNTL_DATA); 2383771fe6b9SJerome Glisse (void)RREG32(RADEON_CRTC_GEN_CNTL); 2384771fe6b9SJerome Glisse } 2385771fe6b9SJerome Glisse 2386771fe6b9SJerome Glisse static void r100_pll_errata_after_data(struct radeon_device *rdev) 2387771fe6b9SJerome Glisse { 2388771fe6b9SJerome Glisse /* This workarounds is necessary on RV100, RS100 and RS200 chips 2389771fe6b9SJerome Glisse * or the chip could hang on a subsequent access 2390771fe6b9SJerome Glisse */ 2391771fe6b9SJerome Glisse if (rdev->pll_errata & CHIP_ERRATA_PLL_DELAY) { 2392771fe6b9SJerome Glisse udelay(5000); 2393771fe6b9SJerome Glisse } 2394771fe6b9SJerome Glisse 2395771fe6b9SJerome Glisse /* This function is required to workaround a hardware bug in some (all?) 2396771fe6b9SJerome Glisse * revisions of the R300. This workaround should be called after every 2397771fe6b9SJerome Glisse * CLOCK_CNTL_INDEX register access. If not, register reads afterward 2398771fe6b9SJerome Glisse * may not be correct. 2399771fe6b9SJerome Glisse */ 2400771fe6b9SJerome Glisse if (rdev->pll_errata & CHIP_ERRATA_R300_CG) { 2401771fe6b9SJerome Glisse uint32_t save, tmp; 2402771fe6b9SJerome Glisse 2403771fe6b9SJerome Glisse save = RREG32(RADEON_CLOCK_CNTL_INDEX); 2404771fe6b9SJerome Glisse tmp = save & ~(0x3f | RADEON_PLL_WR_EN); 2405771fe6b9SJerome Glisse WREG32(RADEON_CLOCK_CNTL_INDEX, tmp); 2406771fe6b9SJerome Glisse tmp = RREG32(RADEON_CLOCK_CNTL_DATA); 2407771fe6b9SJerome Glisse WREG32(RADEON_CLOCK_CNTL_INDEX, save); 2408771fe6b9SJerome Glisse } 2409771fe6b9SJerome Glisse } 2410771fe6b9SJerome Glisse 2411771fe6b9SJerome Glisse uint32_t r100_pll_rreg(struct radeon_device *rdev, uint32_t reg) 2412771fe6b9SJerome Glisse { 2413771fe6b9SJerome Glisse uint32_t data; 2414771fe6b9SJerome Glisse 2415771fe6b9SJerome Glisse WREG8(RADEON_CLOCK_CNTL_INDEX, reg & 0x3f); 2416771fe6b9SJerome Glisse r100_pll_errata_after_index(rdev); 2417771fe6b9SJerome Glisse data = RREG32(RADEON_CLOCK_CNTL_DATA); 2418771fe6b9SJerome Glisse r100_pll_errata_after_data(rdev); 2419771fe6b9SJerome Glisse return data; 2420771fe6b9SJerome Glisse } 2421771fe6b9SJerome Glisse 2422771fe6b9SJerome Glisse void r100_pll_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v) 2423771fe6b9SJerome Glisse { 2424771fe6b9SJerome Glisse WREG8(RADEON_CLOCK_CNTL_INDEX, ((reg & 0x3f) | RADEON_PLL_WR_EN)); 2425771fe6b9SJerome Glisse r100_pll_errata_after_index(rdev); 2426771fe6b9SJerome Glisse WREG32(RADEON_CLOCK_CNTL_DATA, v); 2427771fe6b9SJerome Glisse r100_pll_errata_after_data(rdev); 2428771fe6b9SJerome Glisse } 2429771fe6b9SJerome Glisse 2430d4550907SJerome Glisse void r100_set_safe_registers(struct radeon_device *rdev) 2431068a117cSJerome Glisse { 2432551ebd83SDave Airlie if (ASIC_IS_RN50(rdev)) { 2433551ebd83SDave Airlie rdev->config.r100.reg_safe_bm = rn50_reg_safe_bm; 2434551ebd83SDave Airlie rdev->config.r100.reg_safe_bm_size = ARRAY_SIZE(rn50_reg_safe_bm); 2435551ebd83SDave Airlie } else if (rdev->family < CHIP_R200) { 2436551ebd83SDave Airlie rdev->config.r100.reg_safe_bm = r100_reg_safe_bm; 2437551ebd83SDave Airlie rdev->config.r100.reg_safe_bm_size = ARRAY_SIZE(r100_reg_safe_bm); 2438551ebd83SDave Airlie } else { 2439d4550907SJerome Glisse r200_set_safe_registers(rdev); 2440551ebd83SDave Airlie } 2441068a117cSJerome Glisse } 2442068a117cSJerome Glisse 2443771fe6b9SJerome Glisse /* 2444771fe6b9SJerome Glisse * Debugfs info 2445771fe6b9SJerome Glisse */ 2446771fe6b9SJerome Glisse #if defined(CONFIG_DEBUG_FS) 2447771fe6b9SJerome Glisse static int r100_debugfs_rbbm_info(struct seq_file *m, void *data) 2448771fe6b9SJerome Glisse { 2449771fe6b9SJerome Glisse struct drm_info_node *node = (struct drm_info_node *) m->private; 2450771fe6b9SJerome Glisse struct drm_device *dev = node->minor->dev; 2451771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 2452771fe6b9SJerome Glisse uint32_t reg, value; 2453771fe6b9SJerome Glisse unsigned i; 2454771fe6b9SJerome Glisse 2455771fe6b9SJerome Glisse seq_printf(m, "RBBM_STATUS 0x%08x\n", RREG32(RADEON_RBBM_STATUS)); 2456771fe6b9SJerome Glisse seq_printf(m, "RBBM_CMDFIFO_STAT 0x%08x\n", RREG32(0xE7C)); 2457771fe6b9SJerome Glisse seq_printf(m, "CP_STAT 0x%08x\n", RREG32(RADEON_CP_STAT)); 2458771fe6b9SJerome Glisse for (i = 0; i < 64; i++) { 2459771fe6b9SJerome Glisse WREG32(RADEON_RBBM_CMDFIFO_ADDR, i | 0x100); 2460771fe6b9SJerome Glisse reg = (RREG32(RADEON_RBBM_CMDFIFO_DATA) - 1) >> 2; 2461771fe6b9SJerome Glisse WREG32(RADEON_RBBM_CMDFIFO_ADDR, i); 2462771fe6b9SJerome Glisse value = RREG32(RADEON_RBBM_CMDFIFO_DATA); 2463771fe6b9SJerome Glisse seq_printf(m, "[0x%03X] 0x%04X=0x%08X\n", i, reg, value); 2464771fe6b9SJerome Glisse } 2465771fe6b9SJerome Glisse return 0; 2466771fe6b9SJerome Glisse } 2467771fe6b9SJerome Glisse 2468771fe6b9SJerome Glisse static int r100_debugfs_cp_ring_info(struct seq_file *m, void *data) 2469771fe6b9SJerome Glisse { 2470771fe6b9SJerome Glisse struct drm_info_node *node = (struct drm_info_node *) m->private; 2471771fe6b9SJerome Glisse struct drm_device *dev = node->minor->dev; 2472771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 2473771fe6b9SJerome Glisse uint32_t rdp, wdp; 2474771fe6b9SJerome Glisse unsigned count, i, j; 2475771fe6b9SJerome Glisse 2476771fe6b9SJerome Glisse radeon_ring_free_size(rdev); 2477771fe6b9SJerome Glisse rdp = RREG32(RADEON_CP_RB_RPTR); 2478771fe6b9SJerome Glisse wdp = RREG32(RADEON_CP_RB_WPTR); 2479771fe6b9SJerome Glisse count = (rdp + rdev->cp.ring_size - wdp) & rdev->cp.ptr_mask; 2480771fe6b9SJerome Glisse seq_printf(m, "CP_STAT 0x%08x\n", RREG32(RADEON_CP_STAT)); 2481771fe6b9SJerome Glisse seq_printf(m, "CP_RB_WPTR 0x%08x\n", wdp); 2482771fe6b9SJerome Glisse seq_printf(m, "CP_RB_RPTR 0x%08x\n", rdp); 2483771fe6b9SJerome Glisse seq_printf(m, "%u free dwords in ring\n", rdev->cp.ring_free_dw); 2484771fe6b9SJerome Glisse seq_printf(m, "%u dwords in ring\n", count); 2485771fe6b9SJerome Glisse for (j = 0; j <= count; j++) { 2486771fe6b9SJerome Glisse i = (rdp + j) & rdev->cp.ptr_mask; 2487771fe6b9SJerome Glisse seq_printf(m, "r[%04d]=0x%08x\n", i, rdev->cp.ring[i]); 2488771fe6b9SJerome Glisse } 2489771fe6b9SJerome Glisse return 0; 2490771fe6b9SJerome Glisse } 2491771fe6b9SJerome Glisse 2492771fe6b9SJerome Glisse 2493771fe6b9SJerome Glisse static int r100_debugfs_cp_csq_fifo(struct seq_file *m, void *data) 2494771fe6b9SJerome Glisse { 2495771fe6b9SJerome Glisse struct drm_info_node *node = (struct drm_info_node *) m->private; 2496771fe6b9SJerome Glisse struct drm_device *dev = node->minor->dev; 2497771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 2498771fe6b9SJerome Glisse uint32_t csq_stat, csq2_stat, tmp; 2499771fe6b9SJerome Glisse unsigned r_rptr, r_wptr, ib1_rptr, ib1_wptr, ib2_rptr, ib2_wptr; 2500771fe6b9SJerome Glisse unsigned i; 2501771fe6b9SJerome Glisse 2502771fe6b9SJerome Glisse seq_printf(m, "CP_STAT 0x%08x\n", RREG32(RADEON_CP_STAT)); 2503771fe6b9SJerome Glisse seq_printf(m, "CP_CSQ_MODE 0x%08x\n", RREG32(RADEON_CP_CSQ_MODE)); 2504771fe6b9SJerome Glisse csq_stat = RREG32(RADEON_CP_CSQ_STAT); 2505771fe6b9SJerome Glisse csq2_stat = RREG32(RADEON_CP_CSQ2_STAT); 2506771fe6b9SJerome Glisse r_rptr = (csq_stat >> 0) & 0x3ff; 2507771fe6b9SJerome Glisse r_wptr = (csq_stat >> 10) & 0x3ff; 2508771fe6b9SJerome Glisse ib1_rptr = (csq_stat >> 20) & 0x3ff; 2509771fe6b9SJerome Glisse ib1_wptr = (csq2_stat >> 0) & 0x3ff; 2510771fe6b9SJerome Glisse ib2_rptr = (csq2_stat >> 10) & 0x3ff; 2511771fe6b9SJerome Glisse ib2_wptr = (csq2_stat >> 20) & 0x3ff; 2512771fe6b9SJerome Glisse seq_printf(m, "CP_CSQ_STAT 0x%08x\n", csq_stat); 2513771fe6b9SJerome Glisse seq_printf(m, "CP_CSQ2_STAT 0x%08x\n", csq2_stat); 2514771fe6b9SJerome Glisse seq_printf(m, "Ring rptr %u\n", r_rptr); 2515771fe6b9SJerome Glisse seq_printf(m, "Ring wptr %u\n", r_wptr); 2516771fe6b9SJerome Glisse seq_printf(m, "Indirect1 rptr %u\n", ib1_rptr); 2517771fe6b9SJerome Glisse seq_printf(m, "Indirect1 wptr %u\n", ib1_wptr); 2518771fe6b9SJerome Glisse seq_printf(m, "Indirect2 rptr %u\n", ib2_rptr); 2519771fe6b9SJerome Glisse seq_printf(m, "Indirect2 wptr %u\n", ib2_wptr); 2520771fe6b9SJerome Glisse /* FIXME: 0, 128, 640 depends on fifo setup see cp_init_kms 2521771fe6b9SJerome Glisse * 128 = indirect1_start * 8 & 640 = indirect2_start * 8 */ 2522771fe6b9SJerome Glisse seq_printf(m, "Ring fifo:\n"); 2523771fe6b9SJerome Glisse for (i = 0; i < 256; i++) { 2524771fe6b9SJerome Glisse WREG32(RADEON_CP_CSQ_ADDR, i << 2); 2525771fe6b9SJerome Glisse tmp = RREG32(RADEON_CP_CSQ_DATA); 2526771fe6b9SJerome Glisse seq_printf(m, "rfifo[%04d]=0x%08X\n", i, tmp); 2527771fe6b9SJerome Glisse } 2528771fe6b9SJerome Glisse seq_printf(m, "Indirect1 fifo:\n"); 2529771fe6b9SJerome Glisse for (i = 256; i <= 512; i++) { 2530771fe6b9SJerome Glisse WREG32(RADEON_CP_CSQ_ADDR, i << 2); 2531771fe6b9SJerome Glisse tmp = RREG32(RADEON_CP_CSQ_DATA); 2532771fe6b9SJerome Glisse seq_printf(m, "ib1fifo[%04d]=0x%08X\n", i, tmp); 2533771fe6b9SJerome Glisse } 2534771fe6b9SJerome Glisse seq_printf(m, "Indirect2 fifo:\n"); 2535771fe6b9SJerome Glisse for (i = 640; i < ib1_wptr; i++) { 2536771fe6b9SJerome Glisse WREG32(RADEON_CP_CSQ_ADDR, i << 2); 2537771fe6b9SJerome Glisse tmp = RREG32(RADEON_CP_CSQ_DATA); 2538771fe6b9SJerome Glisse seq_printf(m, "ib2fifo[%04d]=0x%08X\n", i, tmp); 2539771fe6b9SJerome Glisse } 2540771fe6b9SJerome Glisse return 0; 2541771fe6b9SJerome Glisse } 2542771fe6b9SJerome Glisse 2543771fe6b9SJerome Glisse static int r100_debugfs_mc_info(struct seq_file *m, void *data) 2544771fe6b9SJerome Glisse { 2545771fe6b9SJerome Glisse struct drm_info_node *node = (struct drm_info_node *) m->private; 2546771fe6b9SJerome Glisse struct drm_device *dev = node->minor->dev; 2547771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 2548771fe6b9SJerome Glisse uint32_t tmp; 2549771fe6b9SJerome Glisse 2550771fe6b9SJerome Glisse tmp = RREG32(RADEON_CONFIG_MEMSIZE); 2551771fe6b9SJerome Glisse seq_printf(m, "CONFIG_MEMSIZE 0x%08x\n", tmp); 2552771fe6b9SJerome Glisse tmp = RREG32(RADEON_MC_FB_LOCATION); 2553771fe6b9SJerome Glisse seq_printf(m, "MC_FB_LOCATION 0x%08x\n", tmp); 2554771fe6b9SJerome Glisse tmp = RREG32(RADEON_BUS_CNTL); 2555771fe6b9SJerome Glisse seq_printf(m, "BUS_CNTL 0x%08x\n", tmp); 2556771fe6b9SJerome Glisse tmp = RREG32(RADEON_MC_AGP_LOCATION); 2557771fe6b9SJerome Glisse seq_printf(m, "MC_AGP_LOCATION 0x%08x\n", tmp); 2558771fe6b9SJerome Glisse tmp = RREG32(RADEON_AGP_BASE); 2559771fe6b9SJerome Glisse seq_printf(m, "AGP_BASE 0x%08x\n", tmp); 2560771fe6b9SJerome Glisse tmp = RREG32(RADEON_HOST_PATH_CNTL); 2561771fe6b9SJerome Glisse seq_printf(m, "HOST_PATH_CNTL 0x%08x\n", tmp); 2562771fe6b9SJerome Glisse tmp = RREG32(0x01D0); 2563771fe6b9SJerome Glisse seq_printf(m, "AIC_CTRL 0x%08x\n", tmp); 2564771fe6b9SJerome Glisse tmp = RREG32(RADEON_AIC_LO_ADDR); 2565771fe6b9SJerome Glisse seq_printf(m, "AIC_LO_ADDR 0x%08x\n", tmp); 2566771fe6b9SJerome Glisse tmp = RREG32(RADEON_AIC_HI_ADDR); 2567771fe6b9SJerome Glisse seq_printf(m, "AIC_HI_ADDR 0x%08x\n", tmp); 2568771fe6b9SJerome Glisse tmp = RREG32(0x01E4); 2569771fe6b9SJerome Glisse seq_printf(m, "AIC_TLB_ADDR 0x%08x\n", tmp); 2570771fe6b9SJerome Glisse return 0; 2571771fe6b9SJerome Glisse } 2572771fe6b9SJerome Glisse 2573771fe6b9SJerome Glisse static struct drm_info_list r100_debugfs_rbbm_list[] = { 2574771fe6b9SJerome Glisse {"r100_rbbm_info", r100_debugfs_rbbm_info, 0, NULL}, 2575771fe6b9SJerome Glisse }; 2576771fe6b9SJerome Glisse 2577771fe6b9SJerome Glisse static struct drm_info_list r100_debugfs_cp_list[] = { 2578771fe6b9SJerome Glisse {"r100_cp_ring_info", r100_debugfs_cp_ring_info, 0, NULL}, 2579771fe6b9SJerome Glisse {"r100_cp_csq_fifo", r100_debugfs_cp_csq_fifo, 0, NULL}, 2580771fe6b9SJerome Glisse }; 2581771fe6b9SJerome Glisse 2582771fe6b9SJerome Glisse static struct drm_info_list r100_debugfs_mc_info_list[] = { 2583771fe6b9SJerome Glisse {"r100_mc_info", r100_debugfs_mc_info, 0, NULL}, 2584771fe6b9SJerome Glisse }; 2585771fe6b9SJerome Glisse #endif 2586771fe6b9SJerome Glisse 2587771fe6b9SJerome Glisse int r100_debugfs_rbbm_init(struct radeon_device *rdev) 2588771fe6b9SJerome Glisse { 2589771fe6b9SJerome Glisse #if defined(CONFIG_DEBUG_FS) 2590771fe6b9SJerome Glisse return radeon_debugfs_add_files(rdev, r100_debugfs_rbbm_list, 1); 2591771fe6b9SJerome Glisse #else 2592771fe6b9SJerome Glisse return 0; 2593771fe6b9SJerome Glisse #endif 2594771fe6b9SJerome Glisse } 2595771fe6b9SJerome Glisse 2596771fe6b9SJerome Glisse int r100_debugfs_cp_init(struct radeon_device *rdev) 2597771fe6b9SJerome Glisse { 2598771fe6b9SJerome Glisse #if defined(CONFIG_DEBUG_FS) 2599771fe6b9SJerome Glisse return radeon_debugfs_add_files(rdev, r100_debugfs_cp_list, 2); 2600771fe6b9SJerome Glisse #else 2601771fe6b9SJerome Glisse return 0; 2602771fe6b9SJerome Glisse #endif 2603771fe6b9SJerome Glisse } 2604771fe6b9SJerome Glisse 2605771fe6b9SJerome Glisse int r100_debugfs_mc_info_init(struct radeon_device *rdev) 2606771fe6b9SJerome Glisse { 2607771fe6b9SJerome Glisse #if defined(CONFIG_DEBUG_FS) 2608771fe6b9SJerome Glisse return radeon_debugfs_add_files(rdev, r100_debugfs_mc_info_list, 1); 2609771fe6b9SJerome Glisse #else 2610771fe6b9SJerome Glisse return 0; 2611771fe6b9SJerome Glisse #endif 2612771fe6b9SJerome Glisse } 2613e024e110SDave Airlie 2614e024e110SDave Airlie int r100_set_surface_reg(struct radeon_device *rdev, int reg, 2615e024e110SDave Airlie uint32_t tiling_flags, uint32_t pitch, 2616e024e110SDave Airlie uint32_t offset, uint32_t obj_size) 2617e024e110SDave Airlie { 2618e024e110SDave Airlie int surf_index = reg * 16; 2619e024e110SDave Airlie int flags = 0; 2620e024e110SDave Airlie 2621e024e110SDave Airlie /* r100/r200 divide by 16 */ 2622e024e110SDave Airlie if (rdev->family < CHIP_R300) 2623e024e110SDave Airlie flags = pitch / 16; 2624e024e110SDave Airlie else 2625e024e110SDave Airlie flags = pitch / 8; 2626e024e110SDave Airlie 2627e024e110SDave Airlie if (rdev->family <= CHIP_RS200) { 2628e024e110SDave Airlie if ((tiling_flags & (RADEON_TILING_MACRO|RADEON_TILING_MICRO)) 2629e024e110SDave Airlie == (RADEON_TILING_MACRO|RADEON_TILING_MICRO)) 2630e024e110SDave Airlie flags |= RADEON_SURF_TILE_COLOR_BOTH; 2631e024e110SDave Airlie if (tiling_flags & RADEON_TILING_MACRO) 2632e024e110SDave Airlie flags |= RADEON_SURF_TILE_COLOR_MACRO; 2633e024e110SDave Airlie } else if (rdev->family <= CHIP_RV280) { 2634e024e110SDave Airlie if (tiling_flags & (RADEON_TILING_MACRO)) 2635e024e110SDave Airlie flags |= R200_SURF_TILE_COLOR_MACRO; 2636e024e110SDave Airlie if (tiling_flags & RADEON_TILING_MICRO) 2637e024e110SDave Airlie flags |= R200_SURF_TILE_COLOR_MICRO; 2638e024e110SDave Airlie } else { 2639e024e110SDave Airlie if (tiling_flags & RADEON_TILING_MACRO) 2640e024e110SDave Airlie flags |= R300_SURF_TILE_MACRO; 2641e024e110SDave Airlie if (tiling_flags & RADEON_TILING_MICRO) 2642e024e110SDave Airlie flags |= R300_SURF_TILE_MICRO; 2643e024e110SDave Airlie } 2644e024e110SDave Airlie 2645c88f9f0cSMichel Dänzer if (tiling_flags & RADEON_TILING_SWAP_16BIT) 2646c88f9f0cSMichel Dänzer flags |= RADEON_SURF_AP0_SWP_16BPP | RADEON_SURF_AP1_SWP_16BPP; 2647c88f9f0cSMichel Dänzer if (tiling_flags & RADEON_TILING_SWAP_32BIT) 2648c88f9f0cSMichel Dänzer flags |= RADEON_SURF_AP0_SWP_32BPP | RADEON_SURF_AP1_SWP_32BPP; 2649c88f9f0cSMichel Dänzer 2650e024e110SDave Airlie DRM_DEBUG("writing surface %d %d %x %x\n", reg, flags, offset, offset+obj_size-1); 2651e024e110SDave Airlie WREG32(RADEON_SURFACE0_INFO + surf_index, flags); 2652e024e110SDave Airlie WREG32(RADEON_SURFACE0_LOWER_BOUND + surf_index, offset); 2653e024e110SDave Airlie WREG32(RADEON_SURFACE0_UPPER_BOUND + surf_index, offset + obj_size - 1); 2654e024e110SDave Airlie return 0; 2655e024e110SDave Airlie } 2656e024e110SDave Airlie 2657e024e110SDave Airlie void r100_clear_surface_reg(struct radeon_device *rdev, int reg) 2658e024e110SDave Airlie { 2659e024e110SDave Airlie int surf_index = reg * 16; 2660e024e110SDave Airlie WREG32(RADEON_SURFACE0_INFO + surf_index, 0); 2661e024e110SDave Airlie } 2662c93bb85bSJerome Glisse 2663c93bb85bSJerome Glisse void r100_bandwidth_update(struct radeon_device *rdev) 2664c93bb85bSJerome Glisse { 2665c93bb85bSJerome Glisse fixed20_12 trcd_ff, trp_ff, tras_ff, trbs_ff, tcas_ff; 2666c93bb85bSJerome Glisse fixed20_12 sclk_ff, mclk_ff, sclk_eff_ff, sclk_delay_ff; 2667c93bb85bSJerome Glisse fixed20_12 peak_disp_bw, mem_bw, pix_clk, pix_clk2, temp_ff, crit_point_ff; 2668c93bb85bSJerome Glisse uint32_t temp, data, mem_trcd, mem_trp, mem_tras; 2669c93bb85bSJerome Glisse fixed20_12 memtcas_ff[8] = { 2670c93bb85bSJerome Glisse fixed_init(1), 2671c93bb85bSJerome Glisse fixed_init(2), 2672c93bb85bSJerome Glisse fixed_init(3), 2673c93bb85bSJerome Glisse fixed_init(0), 2674c93bb85bSJerome Glisse fixed_init_half(1), 2675c93bb85bSJerome Glisse fixed_init_half(2), 2676c93bb85bSJerome Glisse fixed_init(0), 2677c93bb85bSJerome Glisse }; 2678c93bb85bSJerome Glisse fixed20_12 memtcas_rs480_ff[8] = { 2679c93bb85bSJerome Glisse fixed_init(0), 2680c93bb85bSJerome Glisse fixed_init(1), 2681c93bb85bSJerome Glisse fixed_init(2), 2682c93bb85bSJerome Glisse fixed_init(3), 2683c93bb85bSJerome Glisse fixed_init(0), 2684c93bb85bSJerome Glisse fixed_init_half(1), 2685c93bb85bSJerome Glisse fixed_init_half(2), 2686c93bb85bSJerome Glisse fixed_init_half(3), 2687c93bb85bSJerome Glisse }; 2688c93bb85bSJerome Glisse fixed20_12 memtcas2_ff[8] = { 2689c93bb85bSJerome Glisse fixed_init(0), 2690c93bb85bSJerome Glisse fixed_init(1), 2691c93bb85bSJerome Glisse fixed_init(2), 2692c93bb85bSJerome Glisse fixed_init(3), 2693c93bb85bSJerome Glisse fixed_init(4), 2694c93bb85bSJerome Glisse fixed_init(5), 2695c93bb85bSJerome Glisse fixed_init(6), 2696c93bb85bSJerome Glisse fixed_init(7), 2697c93bb85bSJerome Glisse }; 2698c93bb85bSJerome Glisse fixed20_12 memtrbs[8] = { 2699c93bb85bSJerome Glisse fixed_init(1), 2700c93bb85bSJerome Glisse fixed_init_half(1), 2701c93bb85bSJerome Glisse fixed_init(2), 2702c93bb85bSJerome Glisse fixed_init_half(2), 2703c93bb85bSJerome Glisse fixed_init(3), 2704c93bb85bSJerome Glisse fixed_init_half(3), 2705c93bb85bSJerome Glisse fixed_init(4), 2706c93bb85bSJerome Glisse fixed_init_half(4) 2707c93bb85bSJerome Glisse }; 2708c93bb85bSJerome Glisse fixed20_12 memtrbs_r4xx[8] = { 2709c93bb85bSJerome Glisse fixed_init(4), 2710c93bb85bSJerome Glisse fixed_init(5), 2711c93bb85bSJerome Glisse fixed_init(6), 2712c93bb85bSJerome Glisse fixed_init(7), 2713c93bb85bSJerome Glisse fixed_init(8), 2714c93bb85bSJerome Glisse fixed_init(9), 2715c93bb85bSJerome Glisse fixed_init(10), 2716c93bb85bSJerome Glisse fixed_init(11) 2717c93bb85bSJerome Glisse }; 2718c93bb85bSJerome Glisse fixed20_12 min_mem_eff; 2719c93bb85bSJerome Glisse fixed20_12 mc_latency_sclk, mc_latency_mclk, k1; 2720c93bb85bSJerome Glisse fixed20_12 cur_latency_mclk, cur_latency_sclk; 2721c93bb85bSJerome Glisse fixed20_12 disp_latency, disp_latency_overhead, disp_drain_rate, 2722c93bb85bSJerome Glisse disp_drain_rate2, read_return_rate; 2723c93bb85bSJerome Glisse fixed20_12 time_disp1_drop_priority; 2724c93bb85bSJerome Glisse int c; 2725c93bb85bSJerome Glisse int cur_size = 16; /* in octawords */ 2726c93bb85bSJerome Glisse int critical_point = 0, critical_point2; 2727c93bb85bSJerome Glisse /* uint32_t read_return_rate, time_disp1_drop_priority; */ 2728c93bb85bSJerome Glisse int stop_req, max_stop_req; 2729c93bb85bSJerome Glisse struct drm_display_mode *mode1 = NULL; 2730c93bb85bSJerome Glisse struct drm_display_mode *mode2 = NULL; 2731c93bb85bSJerome Glisse uint32_t pixel_bytes1 = 0; 2732c93bb85bSJerome Glisse uint32_t pixel_bytes2 = 0; 2733c93bb85bSJerome Glisse 2734f46c0120SAlex Deucher radeon_update_display_priority(rdev); 2735f46c0120SAlex Deucher 2736c93bb85bSJerome Glisse if (rdev->mode_info.crtcs[0]->base.enabled) { 2737c93bb85bSJerome Glisse mode1 = &rdev->mode_info.crtcs[0]->base.mode; 2738c93bb85bSJerome Glisse pixel_bytes1 = rdev->mode_info.crtcs[0]->base.fb->bits_per_pixel / 8; 2739c93bb85bSJerome Glisse } 2740dfee5614SDave Airlie if (!(rdev->flags & RADEON_SINGLE_CRTC)) { 2741c93bb85bSJerome Glisse if (rdev->mode_info.crtcs[1]->base.enabled) { 2742c93bb85bSJerome Glisse mode2 = &rdev->mode_info.crtcs[1]->base.mode; 2743c93bb85bSJerome Glisse pixel_bytes2 = rdev->mode_info.crtcs[1]->base.fb->bits_per_pixel / 8; 2744c93bb85bSJerome Glisse } 2745dfee5614SDave Airlie } 2746c93bb85bSJerome Glisse 2747c93bb85bSJerome Glisse min_mem_eff.full = rfixed_const_8(0); 2748c93bb85bSJerome Glisse /* get modes */ 2749c93bb85bSJerome Glisse if ((rdev->disp_priority == 2) && ASIC_IS_R300(rdev)) { 2750c93bb85bSJerome Glisse uint32_t mc_init_misc_lat_timer = RREG32(R300_MC_INIT_MISC_LAT_TIMER); 2751c93bb85bSJerome Glisse mc_init_misc_lat_timer &= ~(R300_MC_DISP1R_INIT_LAT_MASK << R300_MC_DISP1R_INIT_LAT_SHIFT); 2752c93bb85bSJerome Glisse mc_init_misc_lat_timer &= ~(R300_MC_DISP0R_INIT_LAT_MASK << R300_MC_DISP0R_INIT_LAT_SHIFT); 2753c93bb85bSJerome Glisse /* check crtc enables */ 2754c93bb85bSJerome Glisse if (mode2) 2755c93bb85bSJerome Glisse mc_init_misc_lat_timer |= (1 << R300_MC_DISP1R_INIT_LAT_SHIFT); 2756c93bb85bSJerome Glisse if (mode1) 2757c93bb85bSJerome Glisse mc_init_misc_lat_timer |= (1 << R300_MC_DISP0R_INIT_LAT_SHIFT); 2758c93bb85bSJerome Glisse WREG32(R300_MC_INIT_MISC_LAT_TIMER, mc_init_misc_lat_timer); 2759c93bb85bSJerome Glisse } 2760c93bb85bSJerome Glisse 2761c93bb85bSJerome Glisse /* 2762c93bb85bSJerome Glisse * determine is there is enough bw for current mode 2763c93bb85bSJerome Glisse */ 2764f47299c5SAlex Deucher sclk_ff = rdev->pm.sclk; 2765f47299c5SAlex Deucher mclk_ff = rdev->pm.mclk; 2766c93bb85bSJerome Glisse 2767c93bb85bSJerome Glisse temp = (rdev->mc.vram_width / 8) * (rdev->mc.vram_is_ddr ? 2 : 1); 2768c93bb85bSJerome Glisse temp_ff.full = rfixed_const(temp); 2769c93bb85bSJerome Glisse mem_bw.full = rfixed_mul(mclk_ff, temp_ff); 2770c93bb85bSJerome Glisse 2771c93bb85bSJerome Glisse pix_clk.full = 0; 2772c93bb85bSJerome Glisse pix_clk2.full = 0; 2773c93bb85bSJerome Glisse peak_disp_bw.full = 0; 2774c93bb85bSJerome Glisse if (mode1) { 2775c93bb85bSJerome Glisse temp_ff.full = rfixed_const(1000); 2776c93bb85bSJerome Glisse pix_clk.full = rfixed_const(mode1->clock); /* convert to fixed point */ 2777c93bb85bSJerome Glisse pix_clk.full = rfixed_div(pix_clk, temp_ff); 2778c93bb85bSJerome Glisse temp_ff.full = rfixed_const(pixel_bytes1); 2779c93bb85bSJerome Glisse peak_disp_bw.full += rfixed_mul(pix_clk, temp_ff); 2780c93bb85bSJerome Glisse } 2781c93bb85bSJerome Glisse if (mode2) { 2782c93bb85bSJerome Glisse temp_ff.full = rfixed_const(1000); 2783c93bb85bSJerome Glisse pix_clk2.full = rfixed_const(mode2->clock); /* convert to fixed point */ 2784c93bb85bSJerome Glisse pix_clk2.full = rfixed_div(pix_clk2, temp_ff); 2785c93bb85bSJerome Glisse temp_ff.full = rfixed_const(pixel_bytes2); 2786c93bb85bSJerome Glisse peak_disp_bw.full += rfixed_mul(pix_clk2, temp_ff); 2787c93bb85bSJerome Glisse } 2788c93bb85bSJerome Glisse 2789c93bb85bSJerome Glisse mem_bw.full = rfixed_mul(mem_bw, min_mem_eff); 2790c93bb85bSJerome Glisse if (peak_disp_bw.full >= mem_bw.full) { 2791c93bb85bSJerome Glisse DRM_ERROR("You may not have enough display bandwidth for current mode\n" 2792c93bb85bSJerome Glisse "If you have flickering problem, try to lower resolution, refresh rate, or color depth\n"); 2793c93bb85bSJerome Glisse } 2794c93bb85bSJerome Glisse 2795c93bb85bSJerome Glisse /* Get values from the EXT_MEM_CNTL register...converting its contents. */ 2796c93bb85bSJerome Glisse temp = RREG32(RADEON_MEM_TIMING_CNTL); 2797c93bb85bSJerome Glisse if ((rdev->family == CHIP_RV100) || (rdev->flags & RADEON_IS_IGP)) { /* RV100, M6, IGPs */ 2798c93bb85bSJerome Glisse mem_trcd = ((temp >> 2) & 0x3) + 1; 2799c93bb85bSJerome Glisse mem_trp = ((temp & 0x3)) + 1; 2800c93bb85bSJerome Glisse mem_tras = ((temp & 0x70) >> 4) + 1; 2801c93bb85bSJerome Glisse } else if (rdev->family == CHIP_R300 || 2802c93bb85bSJerome Glisse rdev->family == CHIP_R350) { /* r300, r350 */ 2803c93bb85bSJerome Glisse mem_trcd = (temp & 0x7) + 1; 2804c93bb85bSJerome Glisse mem_trp = ((temp >> 8) & 0x7) + 1; 2805c93bb85bSJerome Glisse mem_tras = ((temp >> 11) & 0xf) + 4; 2806c93bb85bSJerome Glisse } else if (rdev->family == CHIP_RV350 || 2807c93bb85bSJerome Glisse rdev->family <= CHIP_RV380) { 2808c93bb85bSJerome Glisse /* rv3x0 */ 2809c93bb85bSJerome Glisse mem_trcd = (temp & 0x7) + 3; 2810c93bb85bSJerome Glisse mem_trp = ((temp >> 8) & 0x7) + 3; 2811c93bb85bSJerome Glisse mem_tras = ((temp >> 11) & 0xf) + 6; 2812c93bb85bSJerome Glisse } else if (rdev->family == CHIP_R420 || 2813c93bb85bSJerome Glisse rdev->family == CHIP_R423 || 2814c93bb85bSJerome Glisse rdev->family == CHIP_RV410) { 2815c93bb85bSJerome Glisse /* r4xx */ 2816c93bb85bSJerome Glisse mem_trcd = (temp & 0xf) + 3; 2817c93bb85bSJerome Glisse if (mem_trcd > 15) 2818c93bb85bSJerome Glisse mem_trcd = 15; 2819c93bb85bSJerome Glisse mem_trp = ((temp >> 8) & 0xf) + 3; 2820c93bb85bSJerome Glisse if (mem_trp > 15) 2821c93bb85bSJerome Glisse mem_trp = 15; 2822c93bb85bSJerome Glisse mem_tras = ((temp >> 12) & 0x1f) + 6; 2823c93bb85bSJerome Glisse if (mem_tras > 31) 2824c93bb85bSJerome Glisse mem_tras = 31; 2825c93bb85bSJerome Glisse } else { /* RV200, R200 */ 2826c93bb85bSJerome Glisse mem_trcd = (temp & 0x7) + 1; 2827c93bb85bSJerome Glisse mem_trp = ((temp >> 8) & 0x7) + 1; 2828c93bb85bSJerome Glisse mem_tras = ((temp >> 12) & 0xf) + 4; 2829c93bb85bSJerome Glisse } 2830c93bb85bSJerome Glisse /* convert to FF */ 2831c93bb85bSJerome Glisse trcd_ff.full = rfixed_const(mem_trcd); 2832c93bb85bSJerome Glisse trp_ff.full = rfixed_const(mem_trp); 2833c93bb85bSJerome Glisse tras_ff.full = rfixed_const(mem_tras); 2834c93bb85bSJerome Glisse 2835c93bb85bSJerome Glisse /* Get values from the MEM_SDRAM_MODE_REG register...converting its */ 2836c93bb85bSJerome Glisse temp = RREG32(RADEON_MEM_SDRAM_MODE_REG); 2837c93bb85bSJerome Glisse data = (temp & (7 << 20)) >> 20; 2838c93bb85bSJerome Glisse if ((rdev->family == CHIP_RV100) || rdev->flags & RADEON_IS_IGP) { 2839c93bb85bSJerome Glisse if (rdev->family == CHIP_RS480) /* don't think rs400 */ 2840c93bb85bSJerome Glisse tcas_ff = memtcas_rs480_ff[data]; 2841c93bb85bSJerome Glisse else 2842c93bb85bSJerome Glisse tcas_ff = memtcas_ff[data]; 2843c93bb85bSJerome Glisse } else 2844c93bb85bSJerome Glisse tcas_ff = memtcas2_ff[data]; 2845c93bb85bSJerome Glisse 2846c93bb85bSJerome Glisse if (rdev->family == CHIP_RS400 || 2847c93bb85bSJerome Glisse rdev->family == CHIP_RS480) { 2848c93bb85bSJerome Glisse /* extra cas latency stored in bits 23-25 0-4 clocks */ 2849c93bb85bSJerome Glisse data = (temp >> 23) & 0x7; 2850c93bb85bSJerome Glisse if (data < 5) 2851c93bb85bSJerome Glisse tcas_ff.full += rfixed_const(data); 2852c93bb85bSJerome Glisse } 2853c93bb85bSJerome Glisse 2854c93bb85bSJerome Glisse if (ASIC_IS_R300(rdev) && !(rdev->flags & RADEON_IS_IGP)) { 2855c93bb85bSJerome Glisse /* on the R300, Tcas is included in Trbs. 2856c93bb85bSJerome Glisse */ 2857c93bb85bSJerome Glisse temp = RREG32(RADEON_MEM_CNTL); 2858c93bb85bSJerome Glisse data = (R300_MEM_NUM_CHANNELS_MASK & temp); 2859c93bb85bSJerome Glisse if (data == 1) { 2860c93bb85bSJerome Glisse if (R300_MEM_USE_CD_CH_ONLY & temp) { 2861c93bb85bSJerome Glisse temp = RREG32(R300_MC_IND_INDEX); 2862c93bb85bSJerome Glisse temp &= ~R300_MC_IND_ADDR_MASK; 2863c93bb85bSJerome Glisse temp |= R300_MC_READ_CNTL_CD_mcind; 2864c93bb85bSJerome Glisse WREG32(R300_MC_IND_INDEX, temp); 2865c93bb85bSJerome Glisse temp = RREG32(R300_MC_IND_DATA); 2866c93bb85bSJerome Glisse data = (R300_MEM_RBS_POSITION_C_MASK & temp); 2867c93bb85bSJerome Glisse } else { 2868c93bb85bSJerome Glisse temp = RREG32(R300_MC_READ_CNTL_AB); 2869c93bb85bSJerome Glisse data = (R300_MEM_RBS_POSITION_A_MASK & temp); 2870c93bb85bSJerome Glisse } 2871c93bb85bSJerome Glisse } else { 2872c93bb85bSJerome Glisse temp = RREG32(R300_MC_READ_CNTL_AB); 2873c93bb85bSJerome Glisse data = (R300_MEM_RBS_POSITION_A_MASK & temp); 2874c93bb85bSJerome Glisse } 2875c93bb85bSJerome Glisse if (rdev->family == CHIP_RV410 || 2876c93bb85bSJerome Glisse rdev->family == CHIP_R420 || 2877c93bb85bSJerome Glisse rdev->family == CHIP_R423) 2878c93bb85bSJerome Glisse trbs_ff = memtrbs_r4xx[data]; 2879c93bb85bSJerome Glisse else 2880c93bb85bSJerome Glisse trbs_ff = memtrbs[data]; 2881c93bb85bSJerome Glisse tcas_ff.full += trbs_ff.full; 2882c93bb85bSJerome Glisse } 2883c93bb85bSJerome Glisse 2884c93bb85bSJerome Glisse sclk_eff_ff.full = sclk_ff.full; 2885c93bb85bSJerome Glisse 2886c93bb85bSJerome Glisse if (rdev->flags & RADEON_IS_AGP) { 2887c93bb85bSJerome Glisse fixed20_12 agpmode_ff; 2888c93bb85bSJerome Glisse agpmode_ff.full = rfixed_const(radeon_agpmode); 2889c93bb85bSJerome Glisse temp_ff.full = rfixed_const_666(16); 2890c93bb85bSJerome Glisse sclk_eff_ff.full -= rfixed_mul(agpmode_ff, temp_ff); 2891c93bb85bSJerome Glisse } 2892c93bb85bSJerome Glisse /* TODO PCIE lanes may affect this - agpmode == 16?? */ 2893c93bb85bSJerome Glisse 2894c93bb85bSJerome Glisse if (ASIC_IS_R300(rdev)) { 2895c93bb85bSJerome Glisse sclk_delay_ff.full = rfixed_const(250); 2896c93bb85bSJerome Glisse } else { 2897c93bb85bSJerome Glisse if ((rdev->family == CHIP_RV100) || 2898c93bb85bSJerome Glisse rdev->flags & RADEON_IS_IGP) { 2899c93bb85bSJerome Glisse if (rdev->mc.vram_is_ddr) 2900c93bb85bSJerome Glisse sclk_delay_ff.full = rfixed_const(41); 2901c93bb85bSJerome Glisse else 2902c93bb85bSJerome Glisse sclk_delay_ff.full = rfixed_const(33); 2903c93bb85bSJerome Glisse } else { 2904c93bb85bSJerome Glisse if (rdev->mc.vram_width == 128) 2905c93bb85bSJerome Glisse sclk_delay_ff.full = rfixed_const(57); 2906c93bb85bSJerome Glisse else 2907c93bb85bSJerome Glisse sclk_delay_ff.full = rfixed_const(41); 2908c93bb85bSJerome Glisse } 2909c93bb85bSJerome Glisse } 2910c93bb85bSJerome Glisse 2911c93bb85bSJerome Glisse mc_latency_sclk.full = rfixed_div(sclk_delay_ff, sclk_eff_ff); 2912c93bb85bSJerome Glisse 2913c93bb85bSJerome Glisse if (rdev->mc.vram_is_ddr) { 2914c93bb85bSJerome Glisse if (rdev->mc.vram_width == 32) { 2915c93bb85bSJerome Glisse k1.full = rfixed_const(40); 2916c93bb85bSJerome Glisse c = 3; 2917c93bb85bSJerome Glisse } else { 2918c93bb85bSJerome Glisse k1.full = rfixed_const(20); 2919c93bb85bSJerome Glisse c = 1; 2920c93bb85bSJerome Glisse } 2921c93bb85bSJerome Glisse } else { 2922c93bb85bSJerome Glisse k1.full = rfixed_const(40); 2923c93bb85bSJerome Glisse c = 3; 2924c93bb85bSJerome Glisse } 2925c93bb85bSJerome Glisse 2926c93bb85bSJerome Glisse temp_ff.full = rfixed_const(2); 2927c93bb85bSJerome Glisse mc_latency_mclk.full = rfixed_mul(trcd_ff, temp_ff); 2928c93bb85bSJerome Glisse temp_ff.full = rfixed_const(c); 2929c93bb85bSJerome Glisse mc_latency_mclk.full += rfixed_mul(tcas_ff, temp_ff); 2930c93bb85bSJerome Glisse temp_ff.full = rfixed_const(4); 2931c93bb85bSJerome Glisse mc_latency_mclk.full += rfixed_mul(tras_ff, temp_ff); 2932c93bb85bSJerome Glisse mc_latency_mclk.full += rfixed_mul(trp_ff, temp_ff); 2933c93bb85bSJerome Glisse mc_latency_mclk.full += k1.full; 2934c93bb85bSJerome Glisse 2935c93bb85bSJerome Glisse mc_latency_mclk.full = rfixed_div(mc_latency_mclk, mclk_ff); 2936c93bb85bSJerome Glisse mc_latency_mclk.full += rfixed_div(temp_ff, sclk_eff_ff); 2937c93bb85bSJerome Glisse 2938c93bb85bSJerome Glisse /* 2939c93bb85bSJerome Glisse HW cursor time assuming worst case of full size colour cursor. 2940c93bb85bSJerome Glisse */ 2941c93bb85bSJerome Glisse temp_ff.full = rfixed_const((2 * (cur_size - (rdev->mc.vram_is_ddr + 1)))); 2942c93bb85bSJerome Glisse temp_ff.full += trcd_ff.full; 2943c93bb85bSJerome Glisse if (temp_ff.full < tras_ff.full) 2944c93bb85bSJerome Glisse temp_ff.full = tras_ff.full; 2945c93bb85bSJerome Glisse cur_latency_mclk.full = rfixed_div(temp_ff, mclk_ff); 2946c93bb85bSJerome Glisse 2947c93bb85bSJerome Glisse temp_ff.full = rfixed_const(cur_size); 2948c93bb85bSJerome Glisse cur_latency_sclk.full = rfixed_div(temp_ff, sclk_eff_ff); 2949c93bb85bSJerome Glisse /* 2950c93bb85bSJerome Glisse Find the total latency for the display data. 2951c93bb85bSJerome Glisse */ 2952b5fc9010SMichel Dänzer disp_latency_overhead.full = rfixed_const(8); 2953c93bb85bSJerome Glisse disp_latency_overhead.full = rfixed_div(disp_latency_overhead, sclk_ff); 2954c93bb85bSJerome Glisse mc_latency_mclk.full += disp_latency_overhead.full + cur_latency_mclk.full; 2955c93bb85bSJerome Glisse mc_latency_sclk.full += disp_latency_overhead.full + cur_latency_sclk.full; 2956c93bb85bSJerome Glisse 2957c93bb85bSJerome Glisse if (mc_latency_mclk.full > mc_latency_sclk.full) 2958c93bb85bSJerome Glisse disp_latency.full = mc_latency_mclk.full; 2959c93bb85bSJerome Glisse else 2960c93bb85bSJerome Glisse disp_latency.full = mc_latency_sclk.full; 2961c93bb85bSJerome Glisse 2962c93bb85bSJerome Glisse /* setup Max GRPH_STOP_REQ default value */ 2963c93bb85bSJerome Glisse if (ASIC_IS_RV100(rdev)) 2964c93bb85bSJerome Glisse max_stop_req = 0x5c; 2965c93bb85bSJerome Glisse else 2966c93bb85bSJerome Glisse max_stop_req = 0x7c; 2967c93bb85bSJerome Glisse 2968c93bb85bSJerome Glisse if (mode1) { 2969c93bb85bSJerome Glisse /* CRTC1 2970c93bb85bSJerome Glisse Set GRPH_BUFFER_CNTL register using h/w defined optimal values. 2971c93bb85bSJerome Glisse GRPH_STOP_REQ <= MIN[ 0x7C, (CRTC_H_DISP + 1) * (bit depth) / 0x10 ] 2972c93bb85bSJerome Glisse */ 2973c93bb85bSJerome Glisse stop_req = mode1->hdisplay * pixel_bytes1 / 16; 2974c93bb85bSJerome Glisse 2975c93bb85bSJerome Glisse if (stop_req > max_stop_req) 2976c93bb85bSJerome Glisse stop_req = max_stop_req; 2977c93bb85bSJerome Glisse 2978c93bb85bSJerome Glisse /* 2979c93bb85bSJerome Glisse Find the drain rate of the display buffer. 2980c93bb85bSJerome Glisse */ 2981c93bb85bSJerome Glisse temp_ff.full = rfixed_const((16/pixel_bytes1)); 2982c93bb85bSJerome Glisse disp_drain_rate.full = rfixed_div(pix_clk, temp_ff); 2983c93bb85bSJerome Glisse 2984c93bb85bSJerome Glisse /* 2985c93bb85bSJerome Glisse Find the critical point of the display buffer. 2986c93bb85bSJerome Glisse */ 2987c93bb85bSJerome Glisse crit_point_ff.full = rfixed_mul(disp_drain_rate, disp_latency); 2988c93bb85bSJerome Glisse crit_point_ff.full += rfixed_const_half(0); 2989c93bb85bSJerome Glisse 2990c93bb85bSJerome Glisse critical_point = rfixed_trunc(crit_point_ff); 2991c93bb85bSJerome Glisse 2992c93bb85bSJerome Glisse if (rdev->disp_priority == 2) { 2993c93bb85bSJerome Glisse critical_point = 0; 2994c93bb85bSJerome Glisse } 2995c93bb85bSJerome Glisse 2996c93bb85bSJerome Glisse /* 2997c93bb85bSJerome Glisse The critical point should never be above max_stop_req-4. Setting 2998c93bb85bSJerome Glisse GRPH_CRITICAL_CNTL = 0 will thus force high priority all the time. 2999c93bb85bSJerome Glisse */ 3000c93bb85bSJerome Glisse if (max_stop_req - critical_point < 4) 3001c93bb85bSJerome Glisse critical_point = 0; 3002c93bb85bSJerome Glisse 3003c93bb85bSJerome Glisse if (critical_point == 0 && mode2 && rdev->family == CHIP_R300) { 3004c93bb85bSJerome Glisse /* some R300 cards have problem with this set to 0, when CRTC2 is enabled.*/ 3005c93bb85bSJerome Glisse critical_point = 0x10; 3006c93bb85bSJerome Glisse } 3007c93bb85bSJerome Glisse 3008c93bb85bSJerome Glisse temp = RREG32(RADEON_GRPH_BUFFER_CNTL); 3009c93bb85bSJerome Glisse temp &= ~(RADEON_GRPH_STOP_REQ_MASK); 3010c93bb85bSJerome Glisse temp |= (stop_req << RADEON_GRPH_STOP_REQ_SHIFT); 3011c93bb85bSJerome Glisse temp &= ~(RADEON_GRPH_START_REQ_MASK); 3012c93bb85bSJerome Glisse if ((rdev->family == CHIP_R350) && 3013c93bb85bSJerome Glisse (stop_req > 0x15)) { 3014c93bb85bSJerome Glisse stop_req -= 0x10; 3015c93bb85bSJerome Glisse } 3016c93bb85bSJerome Glisse temp |= (stop_req << RADEON_GRPH_START_REQ_SHIFT); 3017c93bb85bSJerome Glisse temp |= RADEON_GRPH_BUFFER_SIZE; 3018c93bb85bSJerome Glisse temp &= ~(RADEON_GRPH_CRITICAL_CNTL | 3019c93bb85bSJerome Glisse RADEON_GRPH_CRITICAL_AT_SOF | 3020c93bb85bSJerome Glisse RADEON_GRPH_STOP_CNTL); 3021c93bb85bSJerome Glisse /* 3022c93bb85bSJerome Glisse Write the result into the register. 3023c93bb85bSJerome Glisse */ 3024c93bb85bSJerome Glisse WREG32(RADEON_GRPH_BUFFER_CNTL, ((temp & ~RADEON_GRPH_CRITICAL_POINT_MASK) | 3025c93bb85bSJerome Glisse (critical_point << RADEON_GRPH_CRITICAL_POINT_SHIFT))); 3026c93bb85bSJerome Glisse 3027c93bb85bSJerome Glisse #if 0 3028c93bb85bSJerome Glisse if ((rdev->family == CHIP_RS400) || 3029c93bb85bSJerome Glisse (rdev->family == CHIP_RS480)) { 3030c93bb85bSJerome Glisse /* attempt to program RS400 disp regs correctly ??? */ 3031c93bb85bSJerome Glisse temp = RREG32(RS400_DISP1_REG_CNTL); 3032c93bb85bSJerome Glisse temp &= ~(RS400_DISP1_START_REQ_LEVEL_MASK | 3033c93bb85bSJerome Glisse RS400_DISP1_STOP_REQ_LEVEL_MASK); 3034c93bb85bSJerome Glisse WREG32(RS400_DISP1_REQ_CNTL1, (temp | 3035c93bb85bSJerome Glisse (critical_point << RS400_DISP1_START_REQ_LEVEL_SHIFT) | 3036c93bb85bSJerome Glisse (critical_point << RS400_DISP1_STOP_REQ_LEVEL_SHIFT))); 3037c93bb85bSJerome Glisse temp = RREG32(RS400_DMIF_MEM_CNTL1); 3038c93bb85bSJerome Glisse temp &= ~(RS400_DISP1_CRITICAL_POINT_START_MASK | 3039c93bb85bSJerome Glisse RS400_DISP1_CRITICAL_POINT_STOP_MASK); 3040c93bb85bSJerome Glisse WREG32(RS400_DMIF_MEM_CNTL1, (temp | 3041c93bb85bSJerome Glisse (critical_point << RS400_DISP1_CRITICAL_POINT_START_SHIFT) | 3042c93bb85bSJerome Glisse (critical_point << RS400_DISP1_CRITICAL_POINT_STOP_SHIFT))); 3043c93bb85bSJerome Glisse } 3044c93bb85bSJerome Glisse #endif 3045c93bb85bSJerome Glisse 3046c93bb85bSJerome Glisse DRM_DEBUG("GRPH_BUFFER_CNTL from to %x\n", 3047c93bb85bSJerome Glisse /* (unsigned int)info->SavedReg->grph_buffer_cntl, */ 3048c93bb85bSJerome Glisse (unsigned int)RREG32(RADEON_GRPH_BUFFER_CNTL)); 3049c93bb85bSJerome Glisse } 3050c93bb85bSJerome Glisse 3051c93bb85bSJerome Glisse if (mode2) { 3052c93bb85bSJerome Glisse u32 grph2_cntl; 3053c93bb85bSJerome Glisse stop_req = mode2->hdisplay * pixel_bytes2 / 16; 3054c93bb85bSJerome Glisse 3055c93bb85bSJerome Glisse if (stop_req > max_stop_req) 3056c93bb85bSJerome Glisse stop_req = max_stop_req; 3057c93bb85bSJerome Glisse 3058c93bb85bSJerome Glisse /* 3059c93bb85bSJerome Glisse Find the drain rate of the display buffer. 3060c93bb85bSJerome Glisse */ 3061c93bb85bSJerome Glisse temp_ff.full = rfixed_const((16/pixel_bytes2)); 3062c93bb85bSJerome Glisse disp_drain_rate2.full = rfixed_div(pix_clk2, temp_ff); 3063c93bb85bSJerome Glisse 3064c93bb85bSJerome Glisse grph2_cntl = RREG32(RADEON_GRPH2_BUFFER_CNTL); 3065c93bb85bSJerome Glisse grph2_cntl &= ~(RADEON_GRPH_STOP_REQ_MASK); 3066c93bb85bSJerome Glisse grph2_cntl |= (stop_req << RADEON_GRPH_STOP_REQ_SHIFT); 3067c93bb85bSJerome Glisse grph2_cntl &= ~(RADEON_GRPH_START_REQ_MASK); 3068c93bb85bSJerome Glisse if ((rdev->family == CHIP_R350) && 3069c93bb85bSJerome Glisse (stop_req > 0x15)) { 3070c93bb85bSJerome Glisse stop_req -= 0x10; 3071c93bb85bSJerome Glisse } 3072c93bb85bSJerome Glisse grph2_cntl |= (stop_req << RADEON_GRPH_START_REQ_SHIFT); 3073c93bb85bSJerome Glisse grph2_cntl |= RADEON_GRPH_BUFFER_SIZE; 3074c93bb85bSJerome Glisse grph2_cntl &= ~(RADEON_GRPH_CRITICAL_CNTL | 3075c93bb85bSJerome Glisse RADEON_GRPH_CRITICAL_AT_SOF | 3076c93bb85bSJerome Glisse RADEON_GRPH_STOP_CNTL); 3077c93bb85bSJerome Glisse 3078c93bb85bSJerome Glisse if ((rdev->family == CHIP_RS100) || 3079c93bb85bSJerome Glisse (rdev->family == CHIP_RS200)) 3080c93bb85bSJerome Glisse critical_point2 = 0; 3081c93bb85bSJerome Glisse else { 3082c93bb85bSJerome Glisse temp = (rdev->mc.vram_width * rdev->mc.vram_is_ddr + 1)/128; 3083c93bb85bSJerome Glisse temp_ff.full = rfixed_const(temp); 3084c93bb85bSJerome Glisse temp_ff.full = rfixed_mul(mclk_ff, temp_ff); 3085c93bb85bSJerome Glisse if (sclk_ff.full < temp_ff.full) 3086c93bb85bSJerome Glisse temp_ff.full = sclk_ff.full; 3087c93bb85bSJerome Glisse 3088c93bb85bSJerome Glisse read_return_rate.full = temp_ff.full; 3089c93bb85bSJerome Glisse 3090c93bb85bSJerome Glisse if (mode1) { 3091c93bb85bSJerome Glisse temp_ff.full = read_return_rate.full - disp_drain_rate.full; 3092c93bb85bSJerome Glisse time_disp1_drop_priority.full = rfixed_div(crit_point_ff, temp_ff); 3093c93bb85bSJerome Glisse } else { 3094c93bb85bSJerome Glisse time_disp1_drop_priority.full = 0; 3095c93bb85bSJerome Glisse } 3096c93bb85bSJerome Glisse crit_point_ff.full = disp_latency.full + time_disp1_drop_priority.full + disp_latency.full; 3097c93bb85bSJerome Glisse crit_point_ff.full = rfixed_mul(crit_point_ff, disp_drain_rate2); 3098c93bb85bSJerome Glisse crit_point_ff.full += rfixed_const_half(0); 3099c93bb85bSJerome Glisse 3100c93bb85bSJerome Glisse critical_point2 = rfixed_trunc(crit_point_ff); 3101c93bb85bSJerome Glisse 3102c93bb85bSJerome Glisse if (rdev->disp_priority == 2) { 3103c93bb85bSJerome Glisse critical_point2 = 0; 3104c93bb85bSJerome Glisse } 3105c93bb85bSJerome Glisse 3106c93bb85bSJerome Glisse if (max_stop_req - critical_point2 < 4) 3107c93bb85bSJerome Glisse critical_point2 = 0; 3108c93bb85bSJerome Glisse 3109c93bb85bSJerome Glisse } 3110c93bb85bSJerome Glisse 3111c93bb85bSJerome Glisse if (critical_point2 == 0 && rdev->family == CHIP_R300) { 3112c93bb85bSJerome Glisse /* some R300 cards have problem with this set to 0 */ 3113c93bb85bSJerome Glisse critical_point2 = 0x10; 3114c93bb85bSJerome Glisse } 3115c93bb85bSJerome Glisse 3116c93bb85bSJerome Glisse WREG32(RADEON_GRPH2_BUFFER_CNTL, ((grph2_cntl & ~RADEON_GRPH_CRITICAL_POINT_MASK) | 3117c93bb85bSJerome Glisse (critical_point2 << RADEON_GRPH_CRITICAL_POINT_SHIFT))); 3118c93bb85bSJerome Glisse 3119c93bb85bSJerome Glisse if ((rdev->family == CHIP_RS400) || 3120c93bb85bSJerome Glisse (rdev->family == CHIP_RS480)) { 3121c93bb85bSJerome Glisse #if 0 3122c93bb85bSJerome Glisse /* attempt to program RS400 disp2 regs correctly ??? */ 3123c93bb85bSJerome Glisse temp = RREG32(RS400_DISP2_REQ_CNTL1); 3124c93bb85bSJerome Glisse temp &= ~(RS400_DISP2_START_REQ_LEVEL_MASK | 3125c93bb85bSJerome Glisse RS400_DISP2_STOP_REQ_LEVEL_MASK); 3126c93bb85bSJerome Glisse WREG32(RS400_DISP2_REQ_CNTL1, (temp | 3127c93bb85bSJerome Glisse (critical_point2 << RS400_DISP1_START_REQ_LEVEL_SHIFT) | 3128c93bb85bSJerome Glisse (critical_point2 << RS400_DISP1_STOP_REQ_LEVEL_SHIFT))); 3129c93bb85bSJerome Glisse temp = RREG32(RS400_DISP2_REQ_CNTL2); 3130c93bb85bSJerome Glisse temp &= ~(RS400_DISP2_CRITICAL_POINT_START_MASK | 3131c93bb85bSJerome Glisse RS400_DISP2_CRITICAL_POINT_STOP_MASK); 3132c93bb85bSJerome Glisse WREG32(RS400_DISP2_REQ_CNTL2, (temp | 3133c93bb85bSJerome Glisse (critical_point2 << RS400_DISP2_CRITICAL_POINT_START_SHIFT) | 3134c93bb85bSJerome Glisse (critical_point2 << RS400_DISP2_CRITICAL_POINT_STOP_SHIFT))); 3135c93bb85bSJerome Glisse #endif 3136c93bb85bSJerome Glisse WREG32(RS400_DISP2_REQ_CNTL1, 0x105DC1CC); 3137c93bb85bSJerome Glisse WREG32(RS400_DISP2_REQ_CNTL2, 0x2749D000); 3138c93bb85bSJerome Glisse WREG32(RS400_DMIF_MEM_CNTL1, 0x29CA71DC); 3139c93bb85bSJerome Glisse WREG32(RS400_DISP1_REQ_CNTL1, 0x28FBC3AC); 3140c93bb85bSJerome Glisse } 3141c93bb85bSJerome Glisse 3142c93bb85bSJerome Glisse DRM_DEBUG("GRPH2_BUFFER_CNTL from to %x\n", 3143c93bb85bSJerome Glisse (unsigned int)RREG32(RADEON_GRPH2_BUFFER_CNTL)); 3144c93bb85bSJerome Glisse } 3145c93bb85bSJerome Glisse } 3146551ebd83SDave Airlie 3147551ebd83SDave Airlie static inline void r100_cs_track_texture_print(struct r100_cs_track_texture *t) 3148551ebd83SDave Airlie { 3149551ebd83SDave Airlie DRM_ERROR("pitch %d\n", t->pitch); 3150ceb776bcSMathias Fröhlich DRM_ERROR("use_pitch %d\n", t->use_pitch); 3151551ebd83SDave Airlie DRM_ERROR("width %d\n", t->width); 3152ceb776bcSMathias Fröhlich DRM_ERROR("width_11 %d\n", t->width_11); 3153551ebd83SDave Airlie DRM_ERROR("height %d\n", t->height); 3154ceb776bcSMathias Fröhlich DRM_ERROR("height_11 %d\n", t->height_11); 3155551ebd83SDave Airlie DRM_ERROR("num levels %d\n", t->num_levels); 3156551ebd83SDave Airlie DRM_ERROR("depth %d\n", t->txdepth); 3157551ebd83SDave Airlie DRM_ERROR("bpp %d\n", t->cpp); 3158551ebd83SDave Airlie DRM_ERROR("coordinate type %d\n", t->tex_coord_type); 3159551ebd83SDave Airlie DRM_ERROR("width round to power of 2 %d\n", t->roundup_w); 3160551ebd83SDave Airlie DRM_ERROR("height round to power of 2 %d\n", t->roundup_h); 3161d785d78bSDave Airlie DRM_ERROR("compress format %d\n", t->compress_format); 3162551ebd83SDave Airlie } 3163551ebd83SDave Airlie 3164551ebd83SDave Airlie static int r100_cs_track_cube(struct radeon_device *rdev, 3165551ebd83SDave Airlie struct r100_cs_track *track, unsigned idx) 3166551ebd83SDave Airlie { 3167551ebd83SDave Airlie unsigned face, w, h; 31684c788679SJerome Glisse struct radeon_bo *cube_robj; 3169551ebd83SDave Airlie unsigned long size; 3170551ebd83SDave Airlie 3171551ebd83SDave Airlie for (face = 0; face < 5; face++) { 3172551ebd83SDave Airlie cube_robj = track->textures[idx].cube_info[face].robj; 3173551ebd83SDave Airlie w = track->textures[idx].cube_info[face].width; 3174551ebd83SDave Airlie h = track->textures[idx].cube_info[face].height; 3175551ebd83SDave Airlie 3176551ebd83SDave Airlie size = w * h; 3177551ebd83SDave Airlie size *= track->textures[idx].cpp; 3178551ebd83SDave Airlie 3179551ebd83SDave Airlie size += track->textures[idx].cube_info[face].offset; 3180551ebd83SDave Airlie 31814c788679SJerome Glisse if (size > radeon_bo_size(cube_robj)) { 3182551ebd83SDave Airlie DRM_ERROR("Cube texture offset greater than object size %lu %lu\n", 31834c788679SJerome Glisse size, radeon_bo_size(cube_robj)); 3184551ebd83SDave Airlie r100_cs_track_texture_print(&track->textures[idx]); 3185551ebd83SDave Airlie return -1; 3186551ebd83SDave Airlie } 3187551ebd83SDave Airlie } 3188551ebd83SDave Airlie return 0; 3189551ebd83SDave Airlie } 3190551ebd83SDave Airlie 3191d785d78bSDave Airlie static int r100_track_compress_size(int compress_format, int w, int h) 3192d785d78bSDave Airlie { 3193d785d78bSDave Airlie int block_width, block_height, block_bytes; 3194d785d78bSDave Airlie int wblocks, hblocks; 3195d785d78bSDave Airlie int min_wblocks; 3196d785d78bSDave Airlie int sz; 3197d785d78bSDave Airlie 3198d785d78bSDave Airlie block_width = 4; 3199d785d78bSDave Airlie block_height = 4; 3200d785d78bSDave Airlie 3201d785d78bSDave Airlie switch (compress_format) { 3202d785d78bSDave Airlie case R100_TRACK_COMP_DXT1: 3203d785d78bSDave Airlie block_bytes = 8; 3204d785d78bSDave Airlie min_wblocks = 4; 3205d785d78bSDave Airlie break; 3206d785d78bSDave Airlie default: 3207d785d78bSDave Airlie case R100_TRACK_COMP_DXT35: 3208d785d78bSDave Airlie block_bytes = 16; 3209d785d78bSDave Airlie min_wblocks = 2; 3210d785d78bSDave Airlie break; 3211d785d78bSDave Airlie } 3212d785d78bSDave Airlie 3213d785d78bSDave Airlie hblocks = (h + block_height - 1) / block_height; 3214d785d78bSDave Airlie wblocks = (w + block_width - 1) / block_width; 3215d785d78bSDave Airlie if (wblocks < min_wblocks) 3216d785d78bSDave Airlie wblocks = min_wblocks; 3217d785d78bSDave Airlie sz = wblocks * hblocks * block_bytes; 3218d785d78bSDave Airlie return sz; 3219d785d78bSDave Airlie } 3220d785d78bSDave Airlie 3221551ebd83SDave Airlie static int r100_cs_track_texture_check(struct radeon_device *rdev, 3222551ebd83SDave Airlie struct r100_cs_track *track) 3223551ebd83SDave Airlie { 32244c788679SJerome Glisse struct radeon_bo *robj; 3225551ebd83SDave Airlie unsigned long size; 3226b73c5f8bSMarek Olšák unsigned u, i, w, h, d; 3227551ebd83SDave Airlie int ret; 3228551ebd83SDave Airlie 3229551ebd83SDave Airlie for (u = 0; u < track->num_texture; u++) { 3230551ebd83SDave Airlie if (!track->textures[u].enabled) 3231551ebd83SDave Airlie continue; 3232551ebd83SDave Airlie robj = track->textures[u].robj; 3233551ebd83SDave Airlie if (robj == NULL) { 3234551ebd83SDave Airlie DRM_ERROR("No texture bound to unit %u\n", u); 3235551ebd83SDave Airlie return -EINVAL; 3236551ebd83SDave Airlie } 3237551ebd83SDave Airlie size = 0; 3238551ebd83SDave Airlie for (i = 0; i <= track->textures[u].num_levels; i++) { 3239551ebd83SDave Airlie if (track->textures[u].use_pitch) { 3240551ebd83SDave Airlie if (rdev->family < CHIP_R300) 3241551ebd83SDave Airlie w = (track->textures[u].pitch / track->textures[u].cpp) / (1 << i); 3242551ebd83SDave Airlie else 3243551ebd83SDave Airlie w = track->textures[u].pitch / (1 << i); 3244551ebd83SDave Airlie } else { 3245ceb776bcSMathias Fröhlich w = track->textures[u].width; 3246551ebd83SDave Airlie if (rdev->family >= CHIP_RV515) 3247551ebd83SDave Airlie w |= track->textures[u].width_11; 3248ceb776bcSMathias Fröhlich w = w / (1 << i); 3249551ebd83SDave Airlie if (track->textures[u].roundup_w) 3250551ebd83SDave Airlie w = roundup_pow_of_two(w); 3251551ebd83SDave Airlie } 3252ceb776bcSMathias Fröhlich h = track->textures[u].height; 3253551ebd83SDave Airlie if (rdev->family >= CHIP_RV515) 3254551ebd83SDave Airlie h |= track->textures[u].height_11; 3255ceb776bcSMathias Fröhlich h = h / (1 << i); 3256551ebd83SDave Airlie if (track->textures[u].roundup_h) 3257551ebd83SDave Airlie h = roundup_pow_of_two(h); 3258b73c5f8bSMarek Olšák if (track->textures[u].tex_coord_type == 1) { 3259b73c5f8bSMarek Olšák d = (1 << track->textures[u].txdepth) / (1 << i); 3260b73c5f8bSMarek Olšák if (!d) 3261b73c5f8bSMarek Olšák d = 1; 3262b73c5f8bSMarek Olšák } else { 3263b73c5f8bSMarek Olšák d = 1; 3264b73c5f8bSMarek Olšák } 3265d785d78bSDave Airlie if (track->textures[u].compress_format) { 3266d785d78bSDave Airlie 3267b73c5f8bSMarek Olšák size += r100_track_compress_size(track->textures[u].compress_format, w, h) * d; 3268d785d78bSDave Airlie /* compressed textures are block based */ 3269d785d78bSDave Airlie } else 3270b73c5f8bSMarek Olšák size += w * h * d; 3271551ebd83SDave Airlie } 3272551ebd83SDave Airlie size *= track->textures[u].cpp; 3273d785d78bSDave Airlie 3274551ebd83SDave Airlie switch (track->textures[u].tex_coord_type) { 3275551ebd83SDave Airlie case 0: 3276551ebd83SDave Airlie case 1: 3277551ebd83SDave Airlie break; 3278551ebd83SDave Airlie case 2: 3279551ebd83SDave Airlie if (track->separate_cube) { 3280551ebd83SDave Airlie ret = r100_cs_track_cube(rdev, track, u); 3281551ebd83SDave Airlie if (ret) 3282551ebd83SDave Airlie return ret; 3283551ebd83SDave Airlie } else 3284551ebd83SDave Airlie size *= 6; 3285551ebd83SDave Airlie break; 3286551ebd83SDave Airlie default: 3287551ebd83SDave Airlie DRM_ERROR("Invalid texture coordinate type %u for unit " 3288551ebd83SDave Airlie "%u\n", track->textures[u].tex_coord_type, u); 3289551ebd83SDave Airlie return -EINVAL; 3290551ebd83SDave Airlie } 32914c788679SJerome Glisse if (size > radeon_bo_size(robj)) { 3292551ebd83SDave Airlie DRM_ERROR("Texture of unit %u needs %lu bytes but is " 32934c788679SJerome Glisse "%lu\n", u, size, radeon_bo_size(robj)); 3294551ebd83SDave Airlie r100_cs_track_texture_print(&track->textures[u]); 3295551ebd83SDave Airlie return -EINVAL; 3296551ebd83SDave Airlie } 3297551ebd83SDave Airlie } 3298551ebd83SDave Airlie return 0; 3299551ebd83SDave Airlie } 3300551ebd83SDave Airlie 3301551ebd83SDave Airlie int r100_cs_track_check(struct radeon_device *rdev, struct r100_cs_track *track) 3302551ebd83SDave Airlie { 3303551ebd83SDave Airlie unsigned i; 3304551ebd83SDave Airlie unsigned long size; 3305551ebd83SDave Airlie unsigned prim_walk; 3306551ebd83SDave Airlie unsigned nverts; 3307551ebd83SDave Airlie 3308551ebd83SDave Airlie for (i = 0; i < track->num_cb; i++) { 3309551ebd83SDave Airlie if (track->cb[i].robj == NULL) { 331046c64d4bSMarek Olšák if (!(track->fastfill || track->color_channel_mask || 331146c64d4bSMarek Olšák track->blend_read_enable)) { 331246c64d4bSMarek Olšák continue; 331346c64d4bSMarek Olšák } 3314551ebd83SDave Airlie DRM_ERROR("[drm] No buffer for color buffer %d !\n", i); 3315551ebd83SDave Airlie return -EINVAL; 3316551ebd83SDave Airlie } 3317551ebd83SDave Airlie size = track->cb[i].pitch * track->cb[i].cpp * track->maxy; 3318551ebd83SDave Airlie size += track->cb[i].offset; 33194c788679SJerome Glisse if (size > radeon_bo_size(track->cb[i].robj)) { 3320551ebd83SDave Airlie DRM_ERROR("[drm] Buffer too small for color buffer %d " 3321551ebd83SDave Airlie "(need %lu have %lu) !\n", i, size, 33224c788679SJerome Glisse radeon_bo_size(track->cb[i].robj)); 3323551ebd83SDave Airlie DRM_ERROR("[drm] color buffer %d (%u %u %u %u)\n", 3324551ebd83SDave Airlie i, track->cb[i].pitch, track->cb[i].cpp, 3325551ebd83SDave Airlie track->cb[i].offset, track->maxy); 3326551ebd83SDave Airlie return -EINVAL; 3327551ebd83SDave Airlie } 3328551ebd83SDave Airlie } 3329551ebd83SDave Airlie if (track->z_enabled) { 3330551ebd83SDave Airlie if (track->zb.robj == NULL) { 3331551ebd83SDave Airlie DRM_ERROR("[drm] No buffer for z buffer !\n"); 3332551ebd83SDave Airlie return -EINVAL; 3333551ebd83SDave Airlie } 3334551ebd83SDave Airlie size = track->zb.pitch * track->zb.cpp * track->maxy; 3335551ebd83SDave Airlie size += track->zb.offset; 33364c788679SJerome Glisse if (size > radeon_bo_size(track->zb.robj)) { 3337551ebd83SDave Airlie DRM_ERROR("[drm] Buffer too small for z buffer " 3338551ebd83SDave Airlie "(need %lu have %lu) !\n", size, 33394c788679SJerome Glisse radeon_bo_size(track->zb.robj)); 3340551ebd83SDave Airlie DRM_ERROR("[drm] zbuffer (%u %u %u %u)\n", 3341551ebd83SDave Airlie track->zb.pitch, track->zb.cpp, 3342551ebd83SDave Airlie track->zb.offset, track->maxy); 3343551ebd83SDave Airlie return -EINVAL; 3344551ebd83SDave Airlie } 3345551ebd83SDave Airlie } 3346551ebd83SDave Airlie prim_walk = (track->vap_vf_cntl >> 4) & 0x3; 3347cae94b0aSMarek Olšák if (track->vap_vf_cntl & (1 << 14)) { 3348cae94b0aSMarek Olšák nverts = track->vap_alt_nverts; 3349cae94b0aSMarek Olšák } else { 3350551ebd83SDave Airlie nverts = (track->vap_vf_cntl >> 16) & 0xFFFF; 3351cae94b0aSMarek Olšák } 3352551ebd83SDave Airlie switch (prim_walk) { 3353551ebd83SDave Airlie case 1: 3354551ebd83SDave Airlie for (i = 0; i < track->num_arrays; i++) { 3355551ebd83SDave Airlie size = track->arrays[i].esize * track->max_indx * 4; 3356551ebd83SDave Airlie if (track->arrays[i].robj == NULL) { 3357551ebd83SDave Airlie DRM_ERROR("(PW %u) Vertex array %u no buffer " 3358551ebd83SDave Airlie "bound\n", prim_walk, i); 3359551ebd83SDave Airlie return -EINVAL; 3360551ebd83SDave Airlie } 33614c788679SJerome Glisse if (size > radeon_bo_size(track->arrays[i].robj)) { 33624c788679SJerome Glisse dev_err(rdev->dev, "(PW %u) Vertex array %u " 33634c788679SJerome Glisse "need %lu dwords have %lu dwords\n", 33644c788679SJerome Glisse prim_walk, i, size >> 2, 33654c788679SJerome Glisse radeon_bo_size(track->arrays[i].robj) 33664c788679SJerome Glisse >> 2); 3367551ebd83SDave Airlie DRM_ERROR("Max indices %u\n", track->max_indx); 3368551ebd83SDave Airlie return -EINVAL; 3369551ebd83SDave Airlie } 3370551ebd83SDave Airlie } 3371551ebd83SDave Airlie break; 3372551ebd83SDave Airlie case 2: 3373551ebd83SDave Airlie for (i = 0; i < track->num_arrays; i++) { 3374551ebd83SDave Airlie size = track->arrays[i].esize * (nverts - 1) * 4; 3375551ebd83SDave Airlie if (track->arrays[i].robj == NULL) { 3376551ebd83SDave Airlie DRM_ERROR("(PW %u) Vertex array %u no buffer " 3377551ebd83SDave Airlie "bound\n", prim_walk, i); 3378551ebd83SDave Airlie return -EINVAL; 3379551ebd83SDave Airlie } 33804c788679SJerome Glisse if (size > radeon_bo_size(track->arrays[i].robj)) { 33814c788679SJerome Glisse dev_err(rdev->dev, "(PW %u) Vertex array %u " 33824c788679SJerome Glisse "need %lu dwords have %lu dwords\n", 33834c788679SJerome Glisse prim_walk, i, size >> 2, 33844c788679SJerome Glisse radeon_bo_size(track->arrays[i].robj) 33854c788679SJerome Glisse >> 2); 3386551ebd83SDave Airlie return -EINVAL; 3387551ebd83SDave Airlie } 3388551ebd83SDave Airlie } 3389551ebd83SDave Airlie break; 3390551ebd83SDave Airlie case 3: 3391551ebd83SDave Airlie size = track->vtx_size * nverts; 3392551ebd83SDave Airlie if (size != track->immd_dwords) { 3393551ebd83SDave Airlie DRM_ERROR("IMMD draw %u dwors but needs %lu dwords\n", 3394551ebd83SDave Airlie track->immd_dwords, size); 3395551ebd83SDave Airlie DRM_ERROR("VAP_VF_CNTL.NUM_VERTICES %u, VTX_SIZE %u\n", 3396551ebd83SDave Airlie nverts, track->vtx_size); 3397551ebd83SDave Airlie return -EINVAL; 3398551ebd83SDave Airlie } 3399551ebd83SDave Airlie break; 3400551ebd83SDave Airlie default: 3401551ebd83SDave Airlie DRM_ERROR("[drm] Invalid primitive walk %d for VAP_VF_CNTL\n", 3402551ebd83SDave Airlie prim_walk); 3403551ebd83SDave Airlie return -EINVAL; 3404551ebd83SDave Airlie } 3405551ebd83SDave Airlie return r100_cs_track_texture_check(rdev, track); 3406551ebd83SDave Airlie } 3407551ebd83SDave Airlie 3408551ebd83SDave Airlie void r100_cs_track_clear(struct radeon_device *rdev, struct r100_cs_track *track) 3409551ebd83SDave Airlie { 3410551ebd83SDave Airlie unsigned i, face; 3411551ebd83SDave Airlie 3412551ebd83SDave Airlie if (rdev->family < CHIP_R300) { 3413551ebd83SDave Airlie track->num_cb = 1; 3414551ebd83SDave Airlie if (rdev->family <= CHIP_RS200) 3415551ebd83SDave Airlie track->num_texture = 3; 3416551ebd83SDave Airlie else 3417551ebd83SDave Airlie track->num_texture = 6; 3418551ebd83SDave Airlie track->maxy = 2048; 3419551ebd83SDave Airlie track->separate_cube = 1; 3420551ebd83SDave Airlie } else { 3421551ebd83SDave Airlie track->num_cb = 4; 3422551ebd83SDave Airlie track->num_texture = 16; 3423551ebd83SDave Airlie track->maxy = 4096; 3424551ebd83SDave Airlie track->separate_cube = 0; 3425551ebd83SDave Airlie } 3426551ebd83SDave Airlie 3427551ebd83SDave Airlie for (i = 0; i < track->num_cb; i++) { 3428551ebd83SDave Airlie track->cb[i].robj = NULL; 3429551ebd83SDave Airlie track->cb[i].pitch = 8192; 3430551ebd83SDave Airlie track->cb[i].cpp = 16; 3431551ebd83SDave Airlie track->cb[i].offset = 0; 3432551ebd83SDave Airlie } 3433551ebd83SDave Airlie track->z_enabled = true; 3434551ebd83SDave Airlie track->zb.robj = NULL; 3435551ebd83SDave Airlie track->zb.pitch = 8192; 3436551ebd83SDave Airlie track->zb.cpp = 4; 3437551ebd83SDave Airlie track->zb.offset = 0; 3438551ebd83SDave Airlie track->vtx_size = 0x7F; 3439551ebd83SDave Airlie track->immd_dwords = 0xFFFFFFFFUL; 3440551ebd83SDave Airlie track->num_arrays = 11; 3441551ebd83SDave Airlie track->max_indx = 0x00FFFFFFUL; 3442551ebd83SDave Airlie for (i = 0; i < track->num_arrays; i++) { 3443551ebd83SDave Airlie track->arrays[i].robj = NULL; 3444551ebd83SDave Airlie track->arrays[i].esize = 0x7F; 3445551ebd83SDave Airlie } 3446551ebd83SDave Airlie for (i = 0; i < track->num_texture; i++) { 3447d785d78bSDave Airlie track->textures[i].compress_format = R100_TRACK_COMP_NONE; 3448551ebd83SDave Airlie track->textures[i].pitch = 16536; 3449551ebd83SDave Airlie track->textures[i].width = 16536; 3450551ebd83SDave Airlie track->textures[i].height = 16536; 3451551ebd83SDave Airlie track->textures[i].width_11 = 1 << 11; 3452551ebd83SDave Airlie track->textures[i].height_11 = 1 << 11; 3453551ebd83SDave Airlie track->textures[i].num_levels = 12; 3454551ebd83SDave Airlie if (rdev->family <= CHIP_RS200) { 3455551ebd83SDave Airlie track->textures[i].tex_coord_type = 0; 3456551ebd83SDave Airlie track->textures[i].txdepth = 0; 3457551ebd83SDave Airlie } else { 3458551ebd83SDave Airlie track->textures[i].txdepth = 16; 3459551ebd83SDave Airlie track->textures[i].tex_coord_type = 1; 3460551ebd83SDave Airlie } 3461551ebd83SDave Airlie track->textures[i].cpp = 64; 3462551ebd83SDave Airlie track->textures[i].robj = NULL; 3463551ebd83SDave Airlie /* CS IB emission code makes sure texture unit are disabled */ 3464551ebd83SDave Airlie track->textures[i].enabled = false; 3465551ebd83SDave Airlie track->textures[i].roundup_w = true; 3466551ebd83SDave Airlie track->textures[i].roundup_h = true; 3467551ebd83SDave Airlie if (track->separate_cube) 3468551ebd83SDave Airlie for (face = 0; face < 5; face++) { 3469551ebd83SDave Airlie track->textures[i].cube_info[face].robj = NULL; 3470551ebd83SDave Airlie track->textures[i].cube_info[face].width = 16536; 3471551ebd83SDave Airlie track->textures[i].cube_info[face].height = 16536; 3472551ebd83SDave Airlie track->textures[i].cube_info[face].offset = 0; 3473551ebd83SDave Airlie } 3474551ebd83SDave Airlie } 3475551ebd83SDave Airlie } 34763ce0a23dSJerome Glisse 34773ce0a23dSJerome Glisse int r100_ring_test(struct radeon_device *rdev) 34783ce0a23dSJerome Glisse { 34793ce0a23dSJerome Glisse uint32_t scratch; 34803ce0a23dSJerome Glisse uint32_t tmp = 0; 34813ce0a23dSJerome Glisse unsigned i; 34823ce0a23dSJerome Glisse int r; 34833ce0a23dSJerome Glisse 34843ce0a23dSJerome Glisse r = radeon_scratch_get(rdev, &scratch); 34853ce0a23dSJerome Glisse if (r) { 34863ce0a23dSJerome Glisse DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r); 34873ce0a23dSJerome Glisse return r; 34883ce0a23dSJerome Glisse } 34893ce0a23dSJerome Glisse WREG32(scratch, 0xCAFEDEAD); 34903ce0a23dSJerome Glisse r = radeon_ring_lock(rdev, 2); 34913ce0a23dSJerome Glisse if (r) { 34923ce0a23dSJerome Glisse DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r); 34933ce0a23dSJerome Glisse radeon_scratch_free(rdev, scratch); 34943ce0a23dSJerome Glisse return r; 34953ce0a23dSJerome Glisse } 34963ce0a23dSJerome Glisse radeon_ring_write(rdev, PACKET0(scratch, 0)); 34973ce0a23dSJerome Glisse radeon_ring_write(rdev, 0xDEADBEEF); 34983ce0a23dSJerome Glisse radeon_ring_unlock_commit(rdev); 34993ce0a23dSJerome Glisse for (i = 0; i < rdev->usec_timeout; i++) { 35003ce0a23dSJerome Glisse tmp = RREG32(scratch); 35013ce0a23dSJerome Glisse if (tmp == 0xDEADBEEF) { 35023ce0a23dSJerome Glisse break; 35033ce0a23dSJerome Glisse } 35043ce0a23dSJerome Glisse DRM_UDELAY(1); 35053ce0a23dSJerome Glisse } 35063ce0a23dSJerome Glisse if (i < rdev->usec_timeout) { 35073ce0a23dSJerome Glisse DRM_INFO("ring test succeeded in %d usecs\n", i); 35083ce0a23dSJerome Glisse } else { 35093ce0a23dSJerome Glisse DRM_ERROR("radeon: ring test failed (sracth(0x%04X)=0x%08X)\n", 35103ce0a23dSJerome Glisse scratch, tmp); 35113ce0a23dSJerome Glisse r = -EINVAL; 35123ce0a23dSJerome Glisse } 35133ce0a23dSJerome Glisse radeon_scratch_free(rdev, scratch); 35143ce0a23dSJerome Glisse return r; 35153ce0a23dSJerome Glisse } 35163ce0a23dSJerome Glisse 35173ce0a23dSJerome Glisse void r100_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib) 35183ce0a23dSJerome Glisse { 35193ce0a23dSJerome Glisse radeon_ring_write(rdev, PACKET0(RADEON_CP_IB_BASE, 1)); 35203ce0a23dSJerome Glisse radeon_ring_write(rdev, ib->gpu_addr); 35213ce0a23dSJerome Glisse radeon_ring_write(rdev, ib->length_dw); 35223ce0a23dSJerome Glisse } 35233ce0a23dSJerome Glisse 35243ce0a23dSJerome Glisse int r100_ib_test(struct radeon_device *rdev) 35253ce0a23dSJerome Glisse { 35263ce0a23dSJerome Glisse struct radeon_ib *ib; 35273ce0a23dSJerome Glisse uint32_t scratch; 35283ce0a23dSJerome Glisse uint32_t tmp = 0; 35293ce0a23dSJerome Glisse unsigned i; 35303ce0a23dSJerome Glisse int r; 35313ce0a23dSJerome Glisse 35323ce0a23dSJerome Glisse r = radeon_scratch_get(rdev, &scratch); 35333ce0a23dSJerome Glisse if (r) { 35343ce0a23dSJerome Glisse DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r); 35353ce0a23dSJerome Glisse return r; 35363ce0a23dSJerome Glisse } 35373ce0a23dSJerome Glisse WREG32(scratch, 0xCAFEDEAD); 35383ce0a23dSJerome Glisse r = radeon_ib_get(rdev, &ib); 35393ce0a23dSJerome Glisse if (r) { 35403ce0a23dSJerome Glisse return r; 35413ce0a23dSJerome Glisse } 35423ce0a23dSJerome Glisse ib->ptr[0] = PACKET0(scratch, 0); 35433ce0a23dSJerome Glisse ib->ptr[1] = 0xDEADBEEF; 35443ce0a23dSJerome Glisse ib->ptr[2] = PACKET2(0); 35453ce0a23dSJerome Glisse ib->ptr[3] = PACKET2(0); 35463ce0a23dSJerome Glisse ib->ptr[4] = PACKET2(0); 35473ce0a23dSJerome Glisse ib->ptr[5] = PACKET2(0); 35483ce0a23dSJerome Glisse ib->ptr[6] = PACKET2(0); 35493ce0a23dSJerome Glisse ib->ptr[7] = PACKET2(0); 35503ce0a23dSJerome Glisse ib->length_dw = 8; 35513ce0a23dSJerome Glisse r = radeon_ib_schedule(rdev, ib); 35523ce0a23dSJerome Glisse if (r) { 35533ce0a23dSJerome Glisse radeon_scratch_free(rdev, scratch); 35543ce0a23dSJerome Glisse radeon_ib_free(rdev, &ib); 35553ce0a23dSJerome Glisse return r; 35563ce0a23dSJerome Glisse } 35573ce0a23dSJerome Glisse r = radeon_fence_wait(ib->fence, false); 35583ce0a23dSJerome Glisse if (r) { 35593ce0a23dSJerome Glisse return r; 35603ce0a23dSJerome Glisse } 35613ce0a23dSJerome Glisse for (i = 0; i < rdev->usec_timeout; i++) { 35623ce0a23dSJerome Glisse tmp = RREG32(scratch); 35633ce0a23dSJerome Glisse if (tmp == 0xDEADBEEF) { 35643ce0a23dSJerome Glisse break; 35653ce0a23dSJerome Glisse } 35663ce0a23dSJerome Glisse DRM_UDELAY(1); 35673ce0a23dSJerome Glisse } 35683ce0a23dSJerome Glisse if (i < rdev->usec_timeout) { 35693ce0a23dSJerome Glisse DRM_INFO("ib test succeeded in %u usecs\n", i); 35703ce0a23dSJerome Glisse } else { 35713ce0a23dSJerome Glisse DRM_ERROR("radeon: ib test failed (sracth(0x%04X)=0x%08X)\n", 35723ce0a23dSJerome Glisse scratch, tmp); 35733ce0a23dSJerome Glisse r = -EINVAL; 35743ce0a23dSJerome Glisse } 35753ce0a23dSJerome Glisse radeon_scratch_free(rdev, scratch); 35763ce0a23dSJerome Glisse radeon_ib_free(rdev, &ib); 35773ce0a23dSJerome Glisse return r; 35783ce0a23dSJerome Glisse } 35799f022ddfSJerome Glisse 35809f022ddfSJerome Glisse void r100_ib_fini(struct radeon_device *rdev) 35819f022ddfSJerome Glisse { 35829f022ddfSJerome Glisse radeon_ib_pool_fini(rdev); 35839f022ddfSJerome Glisse } 35849f022ddfSJerome Glisse 35859f022ddfSJerome Glisse int r100_ib_init(struct radeon_device *rdev) 35869f022ddfSJerome Glisse { 35879f022ddfSJerome Glisse int r; 35889f022ddfSJerome Glisse 35899f022ddfSJerome Glisse r = radeon_ib_pool_init(rdev); 35909f022ddfSJerome Glisse if (r) { 35919f022ddfSJerome Glisse dev_err(rdev->dev, "failled initializing IB pool (%d).\n", r); 35929f022ddfSJerome Glisse r100_ib_fini(rdev); 35939f022ddfSJerome Glisse return r; 35949f022ddfSJerome Glisse } 35959f022ddfSJerome Glisse r = r100_ib_test(rdev); 35969f022ddfSJerome Glisse if (r) { 35979f022ddfSJerome Glisse dev_err(rdev->dev, "failled testing IB (%d).\n", r); 35989f022ddfSJerome Glisse r100_ib_fini(rdev); 35999f022ddfSJerome Glisse return r; 36009f022ddfSJerome Glisse } 36019f022ddfSJerome Glisse return 0; 36029f022ddfSJerome Glisse } 36039f022ddfSJerome Glisse 36049f022ddfSJerome Glisse void r100_mc_stop(struct radeon_device *rdev, struct r100_mc_save *save) 36059f022ddfSJerome Glisse { 36069f022ddfSJerome Glisse /* Shutdown CP we shouldn't need to do that but better be safe than 36079f022ddfSJerome Glisse * sorry 36089f022ddfSJerome Glisse */ 36099f022ddfSJerome Glisse rdev->cp.ready = false; 36109f022ddfSJerome Glisse WREG32(R_000740_CP_CSQ_CNTL, 0); 36119f022ddfSJerome Glisse 36129f022ddfSJerome Glisse /* Save few CRTC registers */ 3613ca6ffc64SJerome Glisse save->GENMO_WT = RREG8(R_0003C2_GENMO_WT); 36149f022ddfSJerome Glisse save->CRTC_EXT_CNTL = RREG32(R_000054_CRTC_EXT_CNTL); 36159f022ddfSJerome Glisse save->CRTC_GEN_CNTL = RREG32(R_000050_CRTC_GEN_CNTL); 36169f022ddfSJerome Glisse save->CUR_OFFSET = RREG32(R_000260_CUR_OFFSET); 36179f022ddfSJerome Glisse if (!(rdev->flags & RADEON_SINGLE_CRTC)) { 36189f022ddfSJerome Glisse save->CRTC2_GEN_CNTL = RREG32(R_0003F8_CRTC2_GEN_CNTL); 36199f022ddfSJerome Glisse save->CUR2_OFFSET = RREG32(R_000360_CUR2_OFFSET); 36209f022ddfSJerome Glisse } 36219f022ddfSJerome Glisse 36229f022ddfSJerome Glisse /* Disable VGA aperture access */ 3623ca6ffc64SJerome Glisse WREG8(R_0003C2_GENMO_WT, C_0003C2_VGA_RAM_EN & save->GENMO_WT); 36249f022ddfSJerome Glisse /* Disable cursor, overlay, crtc */ 36259f022ddfSJerome Glisse WREG32(R_000260_CUR_OFFSET, save->CUR_OFFSET | S_000260_CUR_LOCK(1)); 36269f022ddfSJerome Glisse WREG32(R_000054_CRTC_EXT_CNTL, save->CRTC_EXT_CNTL | 36279f022ddfSJerome Glisse S_000054_CRTC_DISPLAY_DIS(1)); 36289f022ddfSJerome Glisse WREG32(R_000050_CRTC_GEN_CNTL, 36299f022ddfSJerome Glisse (C_000050_CRTC_CUR_EN & save->CRTC_GEN_CNTL) | 36309f022ddfSJerome Glisse S_000050_CRTC_DISP_REQ_EN_B(1)); 36319f022ddfSJerome Glisse WREG32(R_000420_OV0_SCALE_CNTL, 36329f022ddfSJerome Glisse C_000420_OV0_OVERLAY_EN & RREG32(R_000420_OV0_SCALE_CNTL)); 36339f022ddfSJerome Glisse WREG32(R_000260_CUR_OFFSET, C_000260_CUR_LOCK & save->CUR_OFFSET); 36349f022ddfSJerome Glisse if (!(rdev->flags & RADEON_SINGLE_CRTC)) { 36359f022ddfSJerome Glisse WREG32(R_000360_CUR2_OFFSET, save->CUR2_OFFSET | 36369f022ddfSJerome Glisse S_000360_CUR2_LOCK(1)); 36379f022ddfSJerome Glisse WREG32(R_0003F8_CRTC2_GEN_CNTL, 36389f022ddfSJerome Glisse (C_0003F8_CRTC2_CUR_EN & save->CRTC2_GEN_CNTL) | 36399f022ddfSJerome Glisse S_0003F8_CRTC2_DISPLAY_DIS(1) | 36409f022ddfSJerome Glisse S_0003F8_CRTC2_DISP_REQ_EN_B(1)); 36419f022ddfSJerome Glisse WREG32(R_000360_CUR2_OFFSET, 36429f022ddfSJerome Glisse C_000360_CUR2_LOCK & save->CUR2_OFFSET); 36439f022ddfSJerome Glisse } 36449f022ddfSJerome Glisse } 36459f022ddfSJerome Glisse 36469f022ddfSJerome Glisse void r100_mc_resume(struct radeon_device *rdev, struct r100_mc_save *save) 36479f022ddfSJerome Glisse { 36489f022ddfSJerome Glisse /* Update base address for crtc */ 3649d594e46aSJerome Glisse WREG32(R_00023C_DISPLAY_BASE_ADDR, rdev->mc.vram_start); 36509f022ddfSJerome Glisse if (!(rdev->flags & RADEON_SINGLE_CRTC)) { 3651d594e46aSJerome Glisse WREG32(R_00033C_CRTC2_DISPLAY_BASE_ADDR, rdev->mc.vram_start); 36529f022ddfSJerome Glisse } 36539f022ddfSJerome Glisse /* Restore CRTC registers */ 3654ca6ffc64SJerome Glisse WREG8(R_0003C2_GENMO_WT, save->GENMO_WT); 36559f022ddfSJerome Glisse WREG32(R_000054_CRTC_EXT_CNTL, save->CRTC_EXT_CNTL); 36569f022ddfSJerome Glisse WREG32(R_000050_CRTC_GEN_CNTL, save->CRTC_GEN_CNTL); 36579f022ddfSJerome Glisse if (!(rdev->flags & RADEON_SINGLE_CRTC)) { 36589f022ddfSJerome Glisse WREG32(R_0003F8_CRTC2_GEN_CNTL, save->CRTC2_GEN_CNTL); 36599f022ddfSJerome Glisse } 36609f022ddfSJerome Glisse } 3661ca6ffc64SJerome Glisse 3662ca6ffc64SJerome Glisse void r100_vga_render_disable(struct radeon_device *rdev) 3663ca6ffc64SJerome Glisse { 3664ca6ffc64SJerome Glisse u32 tmp; 3665ca6ffc64SJerome Glisse 3666ca6ffc64SJerome Glisse tmp = RREG8(R_0003C2_GENMO_WT); 3667ca6ffc64SJerome Glisse WREG8(R_0003C2_GENMO_WT, C_0003C2_VGA_RAM_EN & tmp); 3668ca6ffc64SJerome Glisse } 3669d4550907SJerome Glisse 3670d4550907SJerome Glisse static void r100_debugfs(struct radeon_device *rdev) 3671d4550907SJerome Glisse { 3672d4550907SJerome Glisse int r; 3673d4550907SJerome Glisse 3674d4550907SJerome Glisse r = r100_debugfs_mc_info_init(rdev); 3675d4550907SJerome Glisse if (r) 3676d4550907SJerome Glisse dev_warn(rdev->dev, "Failed to create r100_mc debugfs file.\n"); 3677d4550907SJerome Glisse } 3678d4550907SJerome Glisse 3679d4550907SJerome Glisse static void r100_mc_program(struct radeon_device *rdev) 3680d4550907SJerome Glisse { 3681d4550907SJerome Glisse struct r100_mc_save save; 3682d4550907SJerome Glisse 3683d4550907SJerome Glisse /* Stops all mc clients */ 3684d4550907SJerome Glisse r100_mc_stop(rdev, &save); 3685d4550907SJerome Glisse if (rdev->flags & RADEON_IS_AGP) { 3686d4550907SJerome Glisse WREG32(R_00014C_MC_AGP_LOCATION, 3687d4550907SJerome Glisse S_00014C_MC_AGP_START(rdev->mc.gtt_start >> 16) | 3688d4550907SJerome Glisse S_00014C_MC_AGP_TOP(rdev->mc.gtt_end >> 16)); 3689d4550907SJerome Glisse WREG32(R_000170_AGP_BASE, lower_32_bits(rdev->mc.agp_base)); 3690d4550907SJerome Glisse if (rdev->family > CHIP_RV200) 3691d4550907SJerome Glisse WREG32(R_00015C_AGP_BASE_2, 3692d4550907SJerome Glisse upper_32_bits(rdev->mc.agp_base) & 0xff); 3693d4550907SJerome Glisse } else { 3694d4550907SJerome Glisse WREG32(R_00014C_MC_AGP_LOCATION, 0x0FFFFFFF); 3695d4550907SJerome Glisse WREG32(R_000170_AGP_BASE, 0); 3696d4550907SJerome Glisse if (rdev->family > CHIP_RV200) 3697d4550907SJerome Glisse WREG32(R_00015C_AGP_BASE_2, 0); 3698d4550907SJerome Glisse } 3699d4550907SJerome Glisse /* Wait for mc idle */ 3700d4550907SJerome Glisse if (r100_mc_wait_for_idle(rdev)) 3701d4550907SJerome Glisse dev_warn(rdev->dev, "Wait for MC idle timeout.\n"); 3702d4550907SJerome Glisse /* Program MC, should be a 32bits limited address space */ 3703d4550907SJerome Glisse WREG32(R_000148_MC_FB_LOCATION, 3704d4550907SJerome Glisse S_000148_MC_FB_START(rdev->mc.vram_start >> 16) | 3705d4550907SJerome Glisse S_000148_MC_FB_TOP(rdev->mc.vram_end >> 16)); 3706d4550907SJerome Glisse r100_mc_resume(rdev, &save); 3707d4550907SJerome Glisse } 3708d4550907SJerome Glisse 3709d4550907SJerome Glisse void r100_clock_startup(struct radeon_device *rdev) 3710d4550907SJerome Glisse { 3711d4550907SJerome Glisse u32 tmp; 3712d4550907SJerome Glisse 3713d4550907SJerome Glisse if (radeon_dynclks != -1 && radeon_dynclks) 3714d4550907SJerome Glisse radeon_legacy_set_clock_gating(rdev, 1); 3715d4550907SJerome Glisse /* We need to force on some of the block */ 3716d4550907SJerome Glisse tmp = RREG32_PLL(R_00000D_SCLK_CNTL); 3717d4550907SJerome Glisse tmp |= S_00000D_FORCE_CP(1) | S_00000D_FORCE_VIP(1); 3718d4550907SJerome Glisse if ((rdev->family == CHIP_RV250) || (rdev->family == CHIP_RV280)) 3719d4550907SJerome Glisse tmp |= S_00000D_FORCE_DISP1(1) | S_00000D_FORCE_DISP2(1); 3720d4550907SJerome Glisse WREG32_PLL(R_00000D_SCLK_CNTL, tmp); 3721d4550907SJerome Glisse } 3722d4550907SJerome Glisse 3723d4550907SJerome Glisse static int r100_startup(struct radeon_device *rdev) 3724d4550907SJerome Glisse { 3725d4550907SJerome Glisse int r; 3726d4550907SJerome Glisse 372792cde00cSAlex Deucher /* set common regs */ 372892cde00cSAlex Deucher r100_set_common_regs(rdev); 372992cde00cSAlex Deucher /* program mc */ 3730d4550907SJerome Glisse r100_mc_program(rdev); 3731d4550907SJerome Glisse /* Resume clock */ 3732d4550907SJerome Glisse r100_clock_startup(rdev); 3733d4550907SJerome Glisse /* Initialize GPU configuration (# pipes, ...) */ 373490aca4d2SJerome Glisse // r100_gpu_init(rdev); 3735d4550907SJerome Glisse /* Initialize GART (initialize after TTM so we can allocate 3736d4550907SJerome Glisse * memory through TTM but finalize after TTM) */ 373717e15b0cSDave Airlie r100_enable_bm(rdev); 3738d4550907SJerome Glisse if (rdev->flags & RADEON_IS_PCI) { 3739d4550907SJerome Glisse r = r100_pci_gart_enable(rdev); 3740d4550907SJerome Glisse if (r) 3741d4550907SJerome Glisse return r; 3742d4550907SJerome Glisse } 3743d4550907SJerome Glisse /* Enable IRQ */ 3744d4550907SJerome Glisse r100_irq_set(rdev); 3745cafe6609SJerome Glisse rdev->config.r100.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL); 3746d4550907SJerome Glisse /* 1M ring buffer */ 3747d4550907SJerome Glisse r = r100_cp_init(rdev, 1024 * 1024); 3748d4550907SJerome Glisse if (r) { 3749d4550907SJerome Glisse dev_err(rdev->dev, "failled initializing CP (%d).\n", r); 3750d4550907SJerome Glisse return r; 3751d4550907SJerome Glisse } 3752d4550907SJerome Glisse r = r100_wb_init(rdev); 3753d4550907SJerome Glisse if (r) 3754d4550907SJerome Glisse dev_err(rdev->dev, "failled initializing WB (%d).\n", r); 3755d4550907SJerome Glisse r = r100_ib_init(rdev); 3756d4550907SJerome Glisse if (r) { 3757d4550907SJerome Glisse dev_err(rdev->dev, "failled initializing IB (%d).\n", r); 3758d4550907SJerome Glisse return r; 3759d4550907SJerome Glisse } 3760d4550907SJerome Glisse return 0; 3761d4550907SJerome Glisse } 3762d4550907SJerome Glisse 3763d4550907SJerome Glisse int r100_resume(struct radeon_device *rdev) 3764d4550907SJerome Glisse { 3765d4550907SJerome Glisse /* Make sur GART are not working */ 3766d4550907SJerome Glisse if (rdev->flags & RADEON_IS_PCI) 3767d4550907SJerome Glisse r100_pci_gart_disable(rdev); 3768d4550907SJerome Glisse /* Resume clock before doing reset */ 3769d4550907SJerome Glisse r100_clock_startup(rdev); 3770d4550907SJerome Glisse /* Reset gpu before posting otherwise ATOM will enter infinite loop */ 3771a2d07b74SJerome Glisse if (radeon_asic_reset(rdev)) { 3772d4550907SJerome Glisse dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n", 3773d4550907SJerome Glisse RREG32(R_000E40_RBBM_STATUS), 3774d4550907SJerome Glisse RREG32(R_0007C0_CP_STAT)); 3775d4550907SJerome Glisse } 3776d4550907SJerome Glisse /* post */ 3777d4550907SJerome Glisse radeon_combios_asic_init(rdev->ddev); 3778d4550907SJerome Glisse /* Resume clock after posting */ 3779d4550907SJerome Glisse r100_clock_startup(rdev); 3780550e2d92SDave Airlie /* Initialize surface registers */ 3781550e2d92SDave Airlie radeon_surface_init(rdev); 3782d4550907SJerome Glisse return r100_startup(rdev); 3783d4550907SJerome Glisse } 3784d4550907SJerome Glisse 3785d4550907SJerome Glisse int r100_suspend(struct radeon_device *rdev) 3786d4550907SJerome Glisse { 3787d4550907SJerome Glisse r100_cp_disable(rdev); 3788d4550907SJerome Glisse r100_wb_disable(rdev); 3789d4550907SJerome Glisse r100_irq_disable(rdev); 3790d4550907SJerome Glisse if (rdev->flags & RADEON_IS_PCI) 3791d4550907SJerome Glisse r100_pci_gart_disable(rdev); 3792d4550907SJerome Glisse return 0; 3793d4550907SJerome Glisse } 3794d4550907SJerome Glisse 3795d4550907SJerome Glisse void r100_fini(struct radeon_device *rdev) 3796d4550907SJerome Glisse { 379729fb52caSAlex Deucher radeon_pm_fini(rdev); 3798d4550907SJerome Glisse r100_cp_fini(rdev); 3799d4550907SJerome Glisse r100_wb_fini(rdev); 3800d4550907SJerome Glisse r100_ib_fini(rdev); 3801d4550907SJerome Glisse radeon_gem_fini(rdev); 3802d4550907SJerome Glisse if (rdev->flags & RADEON_IS_PCI) 3803d4550907SJerome Glisse r100_pci_gart_fini(rdev); 3804d0269ed8SJerome Glisse radeon_agp_fini(rdev); 3805d4550907SJerome Glisse radeon_irq_kms_fini(rdev); 3806d4550907SJerome Glisse radeon_fence_driver_fini(rdev); 38074c788679SJerome Glisse radeon_bo_fini(rdev); 3808d4550907SJerome Glisse radeon_atombios_fini(rdev); 3809d4550907SJerome Glisse kfree(rdev->bios); 3810d4550907SJerome Glisse rdev->bios = NULL; 3811d4550907SJerome Glisse } 3812d4550907SJerome Glisse 3813d4550907SJerome Glisse int r100_init(struct radeon_device *rdev) 3814d4550907SJerome Glisse { 3815d4550907SJerome Glisse int r; 3816d4550907SJerome Glisse 3817d4550907SJerome Glisse /* Register debugfs file specific to this group of asics */ 3818d4550907SJerome Glisse r100_debugfs(rdev); 3819d4550907SJerome Glisse /* Disable VGA */ 3820d4550907SJerome Glisse r100_vga_render_disable(rdev); 3821d4550907SJerome Glisse /* Initialize scratch registers */ 3822d4550907SJerome Glisse radeon_scratch_init(rdev); 3823d4550907SJerome Glisse /* Initialize surface registers */ 3824d4550907SJerome Glisse radeon_surface_init(rdev); 3825d4550907SJerome Glisse /* TODO: disable VGA need to use VGA request */ 3826d4550907SJerome Glisse /* BIOS*/ 3827d4550907SJerome Glisse if (!radeon_get_bios(rdev)) { 3828d4550907SJerome Glisse if (ASIC_IS_AVIVO(rdev)) 3829d4550907SJerome Glisse return -EINVAL; 3830d4550907SJerome Glisse } 3831d4550907SJerome Glisse if (rdev->is_atom_bios) { 3832d4550907SJerome Glisse dev_err(rdev->dev, "Expecting combios for RS400/RS480 GPU\n"); 3833d4550907SJerome Glisse return -EINVAL; 3834d4550907SJerome Glisse } else { 3835d4550907SJerome Glisse r = radeon_combios_init(rdev); 3836d4550907SJerome Glisse if (r) 3837d4550907SJerome Glisse return r; 3838d4550907SJerome Glisse } 3839d4550907SJerome Glisse /* Reset gpu before posting otherwise ATOM will enter infinite loop */ 3840a2d07b74SJerome Glisse if (radeon_asic_reset(rdev)) { 3841d4550907SJerome Glisse dev_warn(rdev->dev, 3842d4550907SJerome Glisse "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n", 3843d4550907SJerome Glisse RREG32(R_000E40_RBBM_STATUS), 3844d4550907SJerome Glisse RREG32(R_0007C0_CP_STAT)); 3845d4550907SJerome Glisse } 3846d4550907SJerome Glisse /* check if cards are posted or not */ 384772542d77SDave Airlie if (radeon_boot_test_post_card(rdev) == false) 384872542d77SDave Airlie return -EINVAL; 3849d4550907SJerome Glisse /* Set asic errata */ 3850d4550907SJerome Glisse r100_errata(rdev); 3851d4550907SJerome Glisse /* Initialize clocks */ 3852d4550907SJerome Glisse radeon_get_clock_info(rdev->ddev); 38536234077dSRafał Miłecki /* Initialize power management */ 38546234077dSRafał Miłecki radeon_pm_init(rdev); 3855d594e46aSJerome Glisse /* initialize AGP */ 3856d594e46aSJerome Glisse if (rdev->flags & RADEON_IS_AGP) { 3857d594e46aSJerome Glisse r = radeon_agp_init(rdev); 3858d594e46aSJerome Glisse if (r) { 3859d594e46aSJerome Glisse radeon_agp_disable(rdev); 3860d594e46aSJerome Glisse } 3861d594e46aSJerome Glisse } 3862d594e46aSJerome Glisse /* initialize VRAM */ 3863d594e46aSJerome Glisse r100_mc_init(rdev); 3864d4550907SJerome Glisse /* Fence driver */ 3865d4550907SJerome Glisse r = radeon_fence_driver_init(rdev); 3866d4550907SJerome Glisse if (r) 3867d4550907SJerome Glisse return r; 3868d4550907SJerome Glisse r = radeon_irq_kms_init(rdev); 3869d4550907SJerome Glisse if (r) 3870d4550907SJerome Glisse return r; 3871d4550907SJerome Glisse /* Memory manager */ 38724c788679SJerome Glisse r = radeon_bo_init(rdev); 3873d4550907SJerome Glisse if (r) 3874d4550907SJerome Glisse return r; 3875d4550907SJerome Glisse if (rdev->flags & RADEON_IS_PCI) { 3876d4550907SJerome Glisse r = r100_pci_gart_init(rdev); 3877d4550907SJerome Glisse if (r) 3878d4550907SJerome Glisse return r; 3879d4550907SJerome Glisse } 3880d4550907SJerome Glisse r100_set_safe_registers(rdev); 3881d4550907SJerome Glisse rdev->accel_working = true; 3882d4550907SJerome Glisse r = r100_startup(rdev); 3883d4550907SJerome Glisse if (r) { 3884d4550907SJerome Glisse /* Somethings want wront with the accel init stop accel */ 3885d4550907SJerome Glisse dev_err(rdev->dev, "Disabling GPU acceleration\n"); 3886d4550907SJerome Glisse r100_cp_fini(rdev); 3887d4550907SJerome Glisse r100_wb_fini(rdev); 3888d4550907SJerome Glisse r100_ib_fini(rdev); 3889655efd3dSJerome Glisse radeon_irq_kms_fini(rdev); 3890d4550907SJerome Glisse if (rdev->flags & RADEON_IS_PCI) 3891d4550907SJerome Glisse r100_pci_gart_fini(rdev); 3892d4550907SJerome Glisse rdev->accel_working = false; 3893d4550907SJerome Glisse } 3894d4550907SJerome Glisse return 0; 3895d4550907SJerome Glisse } 3896