1 1.1 riastrad /* $NetBSD: radeon_r100.c,v 1.2 2021/12/18 23:45:43 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright 2008 Advanced Micro Devices, Inc. 5 1.1 riastrad * Copyright 2008 Red Hat Inc. 6 1.1 riastrad * Copyright 2009 Jerome Glisse. 7 1.1 riastrad * 8 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 9 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 10 1.1 riastrad * to deal in the Software without restriction, including without limitation 11 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 13 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 14 1.1 riastrad * 15 1.1 riastrad * The above copyright notice and this permission notice shall be included in 16 1.1 riastrad * all copies or substantial portions of the Software. 17 1.1 riastrad * 18 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 1.1 riastrad * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 22 1.1 riastrad * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 23 1.1 riastrad * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 1.1 riastrad * OTHER DEALINGS IN THE SOFTWARE. 25 1.1 riastrad * 26 1.1 riastrad * Authors: Dave Airlie 27 1.1 riastrad * Alex Deucher 28 1.1 riastrad * Jerome Glisse 29 1.1 riastrad */ 30 1.2 riastrad 31 1.1 riastrad #include <sys/cdefs.h> 32 1.1 riastrad __KERNEL_RCSID(0, "$NetBSD: radeon_r100.c,v 1.2 2021/12/18 23:45:43 riastradh Exp $"); 33 1.1 riastrad 34 1.2 riastrad #include <linux/firmware.h> 35 1.2 riastrad #include <linux/module.h> 36 1.2 riastrad #include <linux/pci.h> 37 1.1 riastrad #include <linux/seq_file.h> 38 1.1 riastrad #include <linux/slab.h> 39 1.2 riastrad 40 1.2 riastrad #include <drm/drm_debugfs.h> 41 1.2 riastrad #include <drm/drm_device.h> 42 1.2 riastrad #include <drm/drm_file.h> 43 1.2 riastrad #include <drm/drm_fourcc.h> 44 1.2 riastrad #include <drm/drm_vblank.h> 45 1.1 riastrad #include <drm/radeon_drm.h> 46 1.2 riastrad 47 1.2 riastrad #include "atom.h" 48 1.2 riastrad #include "r100_reg_safe.h" 49 1.2 riastrad #include "r100d.h" 50 1.1 riastrad #include "radeon.h" 51 1.1 riastrad #include "radeon_asic.h" 52 1.2 riastrad #include "radeon_reg.h" 53 1.2 riastrad #include "rn50_reg_safe.h" 54 1.1 riastrad #include "rs100d.h" 55 1.1 riastrad #include "rv200d.h" 56 1.1 riastrad #include "rv250d.h" 57 1.1 riastrad 58 1.1 riastrad /* Firmware Names */ 59 1.1 riastrad #define FIRMWARE_R100 "radeon/R100_cp.bin" 60 1.1 riastrad #define FIRMWARE_R200 "radeon/R200_cp.bin" 61 1.1 riastrad #define FIRMWARE_R300 "radeon/R300_cp.bin" 62 1.1 riastrad #define FIRMWARE_R420 "radeon/R420_cp.bin" 63 1.1 riastrad #define FIRMWARE_RS690 "radeon/RS690_cp.bin" 64 1.1 riastrad #define FIRMWARE_RS600 "radeon/RS600_cp.bin" 65 1.1 riastrad #define FIRMWARE_R520 "radeon/R520_cp.bin" 66 1.1 riastrad 67 1.1 riastrad MODULE_FIRMWARE(FIRMWARE_R100); 68 1.1 riastrad MODULE_FIRMWARE(FIRMWARE_R200); 69 1.1 riastrad MODULE_FIRMWARE(FIRMWARE_R300); 70 1.1 riastrad MODULE_FIRMWARE(FIRMWARE_R420); 71 1.1 riastrad MODULE_FIRMWARE(FIRMWARE_RS690); 72 1.1 riastrad MODULE_FIRMWARE(FIRMWARE_RS600); 73 1.1 riastrad MODULE_FIRMWARE(FIRMWARE_R520); 74 1.1 riastrad 75 1.1 riastrad #include "r100_track.h" 76 1.1 riastrad 77 1.1 riastrad /* This files gather functions specifics to: 78 1.1 riastrad * r100,rv100,rs100,rv200,rs200,r200,rv250,rs300,rv280 79 1.1 riastrad * and others in some cases. 80 1.1 riastrad */ 81 1.1 riastrad 82 1.1 riastrad static bool r100_is_in_vblank(struct radeon_device *rdev, int crtc) 83 1.1 riastrad { 84 1.1 riastrad if (crtc == 0) { 85 1.1 riastrad if (RREG32(RADEON_CRTC_STATUS) & RADEON_CRTC_VBLANK_CUR) 86 1.1 riastrad return true; 87 1.1 riastrad else 88 1.1 riastrad return false; 89 1.1 riastrad } else { 90 1.1 riastrad if (RREG32(RADEON_CRTC2_STATUS) & RADEON_CRTC2_VBLANK_CUR) 91 1.1 riastrad return true; 92 1.1 riastrad else 93 1.1 riastrad return false; 94 1.1 riastrad } 95 1.1 riastrad } 96 1.1 riastrad 97 1.1 riastrad static bool r100_is_counter_moving(struct radeon_device *rdev, int crtc) 98 1.1 riastrad { 99 1.1 riastrad u32 vline1, vline2; 100 1.1 riastrad 101 1.1 riastrad if (crtc == 0) { 102 1.1 riastrad vline1 = (RREG32(RADEON_CRTC_VLINE_CRNT_VLINE) >> 16) & RADEON_CRTC_V_TOTAL; 103 1.1 riastrad vline2 = (RREG32(RADEON_CRTC_VLINE_CRNT_VLINE) >> 16) & RADEON_CRTC_V_TOTAL; 104 1.1 riastrad } else { 105 1.1 riastrad vline1 = (RREG32(RADEON_CRTC2_VLINE_CRNT_VLINE) >> 16) & RADEON_CRTC_V_TOTAL; 106 1.1 riastrad vline2 = (RREG32(RADEON_CRTC2_VLINE_CRNT_VLINE) >> 16) & RADEON_CRTC_V_TOTAL; 107 1.1 riastrad } 108 1.1 riastrad if (vline1 != vline2) 109 1.1 riastrad return true; 110 1.1 riastrad else 111 1.1 riastrad return false; 112 1.1 riastrad } 113 1.1 riastrad 114 1.1 riastrad /** 115 1.1 riastrad * r100_wait_for_vblank - vblank wait asic callback. 116 1.1 riastrad * 117 1.1 riastrad * @rdev: radeon_device pointer 118 1.1 riastrad * @crtc: crtc to wait for vblank on 119 1.1 riastrad * 120 1.1 riastrad * Wait for vblank on the requested crtc (r1xx-r4xx). 121 1.1 riastrad */ 122 1.1 riastrad void r100_wait_for_vblank(struct radeon_device *rdev, int crtc) 123 1.1 riastrad { 124 1.1 riastrad unsigned i = 0; 125 1.1 riastrad 126 1.1 riastrad if (crtc >= rdev->num_crtc) 127 1.1 riastrad return; 128 1.1 riastrad 129 1.1 riastrad if (crtc == 0) { 130 1.1 riastrad if (!(RREG32(RADEON_CRTC_GEN_CNTL) & RADEON_CRTC_EN)) 131 1.1 riastrad return; 132 1.1 riastrad } else { 133 1.1 riastrad if (!(RREG32(RADEON_CRTC2_GEN_CNTL) & RADEON_CRTC2_EN)) 134 1.1 riastrad return; 135 1.1 riastrad } 136 1.1 riastrad 137 1.1 riastrad /* depending on when we hit vblank, we may be close to active; if so, 138 1.1 riastrad * wait for another frame. 139 1.1 riastrad */ 140 1.1 riastrad while (r100_is_in_vblank(rdev, crtc)) { 141 1.1 riastrad if (i++ % 100 == 0) { 142 1.1 riastrad if (!r100_is_counter_moving(rdev, crtc)) 143 1.1 riastrad break; 144 1.1 riastrad } 145 1.1 riastrad } 146 1.1 riastrad 147 1.1 riastrad while (!r100_is_in_vblank(rdev, crtc)) { 148 1.1 riastrad if (i++ % 100 == 0) { 149 1.1 riastrad if (!r100_is_counter_moving(rdev, crtc)) 150 1.1 riastrad break; 151 1.1 riastrad } 152 1.1 riastrad } 153 1.1 riastrad } 154 1.1 riastrad 155 1.1 riastrad /** 156 1.1 riastrad * r100_page_flip - pageflip callback. 157 1.1 riastrad * 158 1.1 riastrad * @rdev: radeon_device pointer 159 1.1 riastrad * @crtc_id: crtc to cleanup pageflip on 160 1.1 riastrad * @crtc_base: new address of the crtc (GPU MC address) 161 1.1 riastrad * 162 1.1 riastrad * Does the actual pageflip (r1xx-r4xx). 163 1.1 riastrad * During vblank we take the crtc lock and wait for the update_pending 164 1.1 riastrad * bit to go high, when it does, we release the lock, and allow the 165 1.1 riastrad * double buffered update to take place. 166 1.1 riastrad */ 167 1.2 riastrad void r100_page_flip(struct radeon_device *rdev, int crtc_id, u64 crtc_base, bool async) 168 1.1 riastrad { 169 1.1 riastrad struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id]; 170 1.1 riastrad u32 tmp = ((u32)crtc_base) | RADEON_CRTC_OFFSET__OFFSET_LOCK; 171 1.1 riastrad int i; 172 1.1 riastrad 173 1.1 riastrad /* Lock the graphics update lock */ 174 1.1 riastrad /* update the scanout addresses */ 175 1.1 riastrad WREG32(RADEON_CRTC_OFFSET + radeon_crtc->crtc_offset, tmp); 176 1.1 riastrad 177 1.1 riastrad /* Wait for update_pending to go high. */ 178 1.1 riastrad for (i = 0; i < rdev->usec_timeout; i++) { 179 1.1 riastrad if (RREG32(RADEON_CRTC_OFFSET + radeon_crtc->crtc_offset) & RADEON_CRTC_OFFSET__GUI_TRIG_OFFSET) 180 1.1 riastrad break; 181 1.1 riastrad udelay(1); 182 1.1 riastrad } 183 1.1 riastrad DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n"); 184 1.1 riastrad 185 1.1 riastrad /* Unlock the lock, so double-buffering can take place inside vblank */ 186 1.1 riastrad tmp &= ~RADEON_CRTC_OFFSET__OFFSET_LOCK; 187 1.1 riastrad WREG32(RADEON_CRTC_OFFSET + radeon_crtc->crtc_offset, tmp); 188 1.1 riastrad 189 1.1 riastrad } 190 1.1 riastrad 191 1.1 riastrad /** 192 1.1 riastrad * r100_page_flip_pending - check if page flip is still pending 193 1.1 riastrad * 194 1.1 riastrad * @rdev: radeon_device pointer 195 1.1 riastrad * @crtc_id: crtc to check 196 1.1 riastrad * 197 1.1 riastrad * Check if the last pagefilp is still pending (r1xx-r4xx). 198 1.1 riastrad * Returns the current update pending status. 199 1.1 riastrad */ 200 1.1 riastrad bool r100_page_flip_pending(struct radeon_device *rdev, int crtc_id) 201 1.1 riastrad { 202 1.1 riastrad struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id]; 203 1.1 riastrad 204 1.1 riastrad /* Return current update_pending status: */ 205 1.1 riastrad return !!(RREG32(RADEON_CRTC_OFFSET + radeon_crtc->crtc_offset) & 206 1.1 riastrad RADEON_CRTC_OFFSET__GUI_TRIG_OFFSET); 207 1.1 riastrad } 208 1.1 riastrad 209 1.1 riastrad /** 210 1.1 riastrad * r100_pm_get_dynpm_state - look up dynpm power state callback. 211 1.1 riastrad * 212 1.1 riastrad * @rdev: radeon_device pointer 213 1.1 riastrad * 214 1.1 riastrad * Look up the optimal power state based on the 215 1.1 riastrad * current state of the GPU (r1xx-r5xx). 216 1.1 riastrad * Used for dynpm only. 217 1.1 riastrad */ 218 1.1 riastrad void r100_pm_get_dynpm_state(struct radeon_device *rdev) 219 1.1 riastrad { 220 1.1 riastrad int i; 221 1.1 riastrad rdev->pm.dynpm_can_upclock = true; 222 1.1 riastrad rdev->pm.dynpm_can_downclock = true; 223 1.1 riastrad 224 1.1 riastrad switch (rdev->pm.dynpm_planned_action) { 225 1.1 riastrad case DYNPM_ACTION_MINIMUM: 226 1.1 riastrad rdev->pm.requested_power_state_index = 0; 227 1.1 riastrad rdev->pm.dynpm_can_downclock = false; 228 1.1 riastrad break; 229 1.1 riastrad case DYNPM_ACTION_DOWNCLOCK: 230 1.1 riastrad if (rdev->pm.current_power_state_index == 0) { 231 1.1 riastrad rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index; 232 1.1 riastrad rdev->pm.dynpm_can_downclock = false; 233 1.1 riastrad } else { 234 1.1 riastrad if (rdev->pm.active_crtc_count > 1) { 235 1.1 riastrad for (i = 0; i < rdev->pm.num_power_states; i++) { 236 1.1 riastrad if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY) 237 1.1 riastrad continue; 238 1.1 riastrad else if (i >= rdev->pm.current_power_state_index) { 239 1.1 riastrad rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index; 240 1.1 riastrad break; 241 1.1 riastrad } else { 242 1.1 riastrad rdev->pm.requested_power_state_index = i; 243 1.1 riastrad break; 244 1.1 riastrad } 245 1.1 riastrad } 246 1.1 riastrad } else 247 1.1 riastrad rdev->pm.requested_power_state_index = 248 1.1 riastrad rdev->pm.current_power_state_index - 1; 249 1.1 riastrad } 250 1.1 riastrad /* don't use the power state if crtcs are active and no display flag is set */ 251 1.1 riastrad if ((rdev->pm.active_crtc_count > 0) && 252 1.1 riastrad (rdev->pm.power_state[rdev->pm.requested_power_state_index].clock_info[0].flags & 253 1.1 riastrad RADEON_PM_MODE_NO_DISPLAY)) { 254 1.1 riastrad rdev->pm.requested_power_state_index++; 255 1.1 riastrad } 256 1.1 riastrad break; 257 1.1 riastrad case DYNPM_ACTION_UPCLOCK: 258 1.1 riastrad if (rdev->pm.current_power_state_index == (rdev->pm.num_power_states - 1)) { 259 1.1 riastrad rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index; 260 1.1 riastrad rdev->pm.dynpm_can_upclock = false; 261 1.1 riastrad } else { 262 1.1 riastrad if (rdev->pm.active_crtc_count > 1) { 263 1.1 riastrad for (i = (rdev->pm.num_power_states - 1); i >= 0; i--) { 264 1.1 riastrad if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY) 265 1.1 riastrad continue; 266 1.1 riastrad else if (i <= rdev->pm.current_power_state_index) { 267 1.1 riastrad rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index; 268 1.1 riastrad break; 269 1.1 riastrad } else { 270 1.1 riastrad rdev->pm.requested_power_state_index = i; 271 1.1 riastrad break; 272 1.1 riastrad } 273 1.1 riastrad } 274 1.1 riastrad } else 275 1.1 riastrad rdev->pm.requested_power_state_index = 276 1.1 riastrad rdev->pm.current_power_state_index + 1; 277 1.1 riastrad } 278 1.1 riastrad break; 279 1.1 riastrad case DYNPM_ACTION_DEFAULT: 280 1.1 riastrad rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index; 281 1.1 riastrad rdev->pm.dynpm_can_upclock = false; 282 1.1 riastrad break; 283 1.1 riastrad case DYNPM_ACTION_NONE: 284 1.1 riastrad default: 285 1.1 riastrad DRM_ERROR("Requested mode for not defined action\n"); 286 1.1 riastrad return; 287 1.1 riastrad } 288 1.1 riastrad /* only one clock mode per power state */ 289 1.1 riastrad rdev->pm.requested_clock_mode_index = 0; 290 1.1 riastrad 291 1.1 riastrad DRM_DEBUG_DRIVER("Requested: e: %d m: %d p: %d\n", 292 1.1 riastrad rdev->pm.power_state[rdev->pm.requested_power_state_index]. 293 1.1 riastrad clock_info[rdev->pm.requested_clock_mode_index].sclk, 294 1.1 riastrad rdev->pm.power_state[rdev->pm.requested_power_state_index]. 295 1.1 riastrad clock_info[rdev->pm.requested_clock_mode_index].mclk, 296 1.1 riastrad rdev->pm.power_state[rdev->pm.requested_power_state_index]. 297 1.1 riastrad pcie_lanes); 298 1.1 riastrad } 299 1.1 riastrad 300 1.1 riastrad /** 301 1.1 riastrad * r100_pm_init_profile - Initialize power profiles callback. 302 1.1 riastrad * 303 1.1 riastrad * @rdev: radeon_device pointer 304 1.1 riastrad * 305 1.1 riastrad * Initialize the power states used in profile mode 306 1.1 riastrad * (r1xx-r3xx). 307 1.1 riastrad * Used for profile mode only. 308 1.1 riastrad */ 309 1.1 riastrad void r100_pm_init_profile(struct radeon_device *rdev) 310 1.1 riastrad { 311 1.1 riastrad /* default */ 312 1.1 riastrad rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index; 313 1.1 riastrad rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; 314 1.1 riastrad rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0; 315 1.1 riastrad rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0; 316 1.1 riastrad /* low sh */ 317 1.1 riastrad rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 0; 318 1.1 riastrad rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 0; 319 1.1 riastrad rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0; 320 1.1 riastrad rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0; 321 1.1 riastrad /* mid sh */ 322 1.1 riastrad rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 0; 323 1.1 riastrad rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 0; 324 1.1 riastrad rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0; 325 1.1 riastrad rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0; 326 1.1 riastrad /* high sh */ 327 1.1 riastrad rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 0; 328 1.1 riastrad rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; 329 1.1 riastrad rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0; 330 1.1 riastrad rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0; 331 1.1 riastrad /* low mh */ 332 1.1 riastrad rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 0; 333 1.1 riastrad rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; 334 1.1 riastrad rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0; 335 1.1 riastrad rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0; 336 1.1 riastrad /* mid mh */ 337 1.1 riastrad rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 0; 338 1.1 riastrad rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; 339 1.1 riastrad rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0; 340 1.1 riastrad rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0; 341 1.1 riastrad /* high mh */ 342 1.1 riastrad rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 0; 343 1.1 riastrad rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; 344 1.1 riastrad rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0; 345 1.1 riastrad rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0; 346 1.1 riastrad } 347 1.1 riastrad 348 1.1 riastrad /** 349 1.1 riastrad * r100_pm_misc - set additional pm hw parameters callback. 350 1.1 riastrad * 351 1.1 riastrad * @rdev: radeon_device pointer 352 1.1 riastrad * 353 1.1 riastrad * Set non-clock parameters associated with a power state 354 1.1 riastrad * (voltage, pcie lanes, etc.) (r1xx-r4xx). 355 1.1 riastrad */ 356 1.1 riastrad void r100_pm_misc(struct radeon_device *rdev) 357 1.1 riastrad { 358 1.1 riastrad int requested_index = rdev->pm.requested_power_state_index; 359 1.1 riastrad struct radeon_power_state *ps = &rdev->pm.power_state[requested_index]; 360 1.1 riastrad struct radeon_voltage *voltage = &ps->clock_info[0].voltage; 361 1.1 riastrad u32 tmp, sclk_cntl, sclk_cntl2, sclk_more_cntl; 362 1.1 riastrad 363 1.1 riastrad if ((voltage->type == VOLTAGE_GPIO) && (voltage->gpio.valid)) { 364 1.1 riastrad if (ps->misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) { 365 1.1 riastrad tmp = RREG32(voltage->gpio.reg); 366 1.1 riastrad if (voltage->active_high) 367 1.1 riastrad tmp |= voltage->gpio.mask; 368 1.1 riastrad else 369 1.1 riastrad tmp &= ~(voltage->gpio.mask); 370 1.1 riastrad WREG32(voltage->gpio.reg, tmp); 371 1.1 riastrad if (voltage->delay) 372 1.1 riastrad udelay(voltage->delay); 373 1.1 riastrad } else { 374 1.1 riastrad tmp = RREG32(voltage->gpio.reg); 375 1.1 riastrad if (voltage->active_high) 376 1.1 riastrad tmp &= ~voltage->gpio.mask; 377 1.1 riastrad else 378 1.1 riastrad tmp |= voltage->gpio.mask; 379 1.1 riastrad WREG32(voltage->gpio.reg, tmp); 380 1.1 riastrad if (voltage->delay) 381 1.1 riastrad udelay(voltage->delay); 382 1.1 riastrad } 383 1.1 riastrad } 384 1.1 riastrad 385 1.1 riastrad sclk_cntl = RREG32_PLL(SCLK_CNTL); 386 1.1 riastrad sclk_cntl2 = RREG32_PLL(SCLK_CNTL2); 387 1.1 riastrad sclk_cntl2 &= ~REDUCED_SPEED_SCLK_SEL(3); 388 1.1 riastrad sclk_more_cntl = RREG32_PLL(SCLK_MORE_CNTL); 389 1.1 riastrad sclk_more_cntl &= ~VOLTAGE_DELAY_SEL(3); 390 1.1 riastrad if (ps->misc & ATOM_PM_MISCINFO_ASIC_REDUCED_SPEED_SCLK_EN) { 391 1.1 riastrad sclk_more_cntl |= REDUCED_SPEED_SCLK_EN; 392 1.1 riastrad if (ps->misc & ATOM_PM_MISCINFO_DYN_CLK_3D_IDLE) 393 1.1 riastrad sclk_cntl2 |= REDUCED_SPEED_SCLK_MODE; 394 1.1 riastrad else 395 1.1 riastrad sclk_cntl2 &= ~REDUCED_SPEED_SCLK_MODE; 396 1.1 riastrad if (ps->misc & ATOM_PM_MISCINFO_DYNAMIC_CLOCK_DIVIDER_BY_2) 397 1.1 riastrad sclk_cntl2 |= REDUCED_SPEED_SCLK_SEL(0); 398 1.1 riastrad else if (ps->misc & ATOM_PM_MISCINFO_DYNAMIC_CLOCK_DIVIDER_BY_4) 399 1.1 riastrad sclk_cntl2 |= REDUCED_SPEED_SCLK_SEL(2); 400 1.1 riastrad } else 401 1.1 riastrad sclk_more_cntl &= ~REDUCED_SPEED_SCLK_EN; 402 1.1 riastrad 403 1.1 riastrad if (ps->misc & ATOM_PM_MISCINFO_ASIC_DYNAMIC_VOLTAGE_EN) { 404 1.1 riastrad sclk_more_cntl |= IO_CG_VOLTAGE_DROP; 405 1.1 riastrad if (voltage->delay) { 406 1.1 riastrad sclk_more_cntl |= VOLTAGE_DROP_SYNC; 407 1.1 riastrad switch (voltage->delay) { 408 1.1 riastrad case 33: 409 1.1 riastrad sclk_more_cntl |= VOLTAGE_DELAY_SEL(0); 410 1.1 riastrad break; 411 1.1 riastrad case 66: 412 1.1 riastrad sclk_more_cntl |= VOLTAGE_DELAY_SEL(1); 413 1.1 riastrad break; 414 1.1 riastrad case 99: 415 1.1 riastrad sclk_more_cntl |= VOLTAGE_DELAY_SEL(2); 416 1.1 riastrad break; 417 1.1 riastrad case 132: 418 1.1 riastrad sclk_more_cntl |= VOLTAGE_DELAY_SEL(3); 419 1.1 riastrad break; 420 1.1 riastrad } 421 1.1 riastrad } else 422 1.1 riastrad sclk_more_cntl &= ~VOLTAGE_DROP_SYNC; 423 1.1 riastrad } else 424 1.1 riastrad sclk_more_cntl &= ~IO_CG_VOLTAGE_DROP; 425 1.1 riastrad 426 1.1 riastrad if (ps->misc & ATOM_PM_MISCINFO_DYNAMIC_HDP_BLOCK_EN) 427 1.1 riastrad sclk_cntl &= ~FORCE_HDP; 428 1.1 riastrad else 429 1.1 riastrad sclk_cntl |= FORCE_HDP; 430 1.1 riastrad 431 1.1 riastrad WREG32_PLL(SCLK_CNTL, sclk_cntl); 432 1.1 riastrad WREG32_PLL(SCLK_CNTL2, sclk_cntl2); 433 1.1 riastrad WREG32_PLL(SCLK_MORE_CNTL, sclk_more_cntl); 434 1.1 riastrad 435 1.1 riastrad /* set pcie lanes */ 436 1.1 riastrad if ((rdev->flags & RADEON_IS_PCIE) && 437 1.1 riastrad !(rdev->flags & RADEON_IS_IGP) && 438 1.1 riastrad rdev->asic->pm.set_pcie_lanes && 439 1.1 riastrad (ps->pcie_lanes != 440 1.1 riastrad rdev->pm.power_state[rdev->pm.current_power_state_index].pcie_lanes)) { 441 1.1 riastrad radeon_set_pcie_lanes(rdev, 442 1.1 riastrad ps->pcie_lanes); 443 1.1 riastrad DRM_DEBUG_DRIVER("Setting: p: %d\n", ps->pcie_lanes); 444 1.1 riastrad } 445 1.1 riastrad } 446 1.1 riastrad 447 1.1 riastrad /** 448 1.1 riastrad * r100_pm_prepare - pre-power state change callback. 449 1.1 riastrad * 450 1.1 riastrad * @rdev: radeon_device pointer 451 1.1 riastrad * 452 1.1 riastrad * Prepare for a power state change (r1xx-r4xx). 453 1.1 riastrad */ 454 1.1 riastrad void r100_pm_prepare(struct radeon_device *rdev) 455 1.1 riastrad { 456 1.1 riastrad struct drm_device *ddev = rdev->ddev; 457 1.1 riastrad struct drm_crtc *crtc; 458 1.1 riastrad struct radeon_crtc *radeon_crtc; 459 1.1 riastrad u32 tmp; 460 1.1 riastrad 461 1.1 riastrad /* disable any active CRTCs */ 462 1.1 riastrad list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) { 463 1.1 riastrad radeon_crtc = to_radeon_crtc(crtc); 464 1.1 riastrad if (radeon_crtc->enabled) { 465 1.1 riastrad if (radeon_crtc->crtc_id) { 466 1.1 riastrad tmp = RREG32(RADEON_CRTC2_GEN_CNTL); 467 1.1 riastrad tmp |= RADEON_CRTC2_DISP_REQ_EN_B; 468 1.1 riastrad WREG32(RADEON_CRTC2_GEN_CNTL, tmp); 469 1.1 riastrad } else { 470 1.1 riastrad tmp = RREG32(RADEON_CRTC_GEN_CNTL); 471 1.1 riastrad tmp |= RADEON_CRTC_DISP_REQ_EN_B; 472 1.1 riastrad WREG32(RADEON_CRTC_GEN_CNTL, tmp); 473 1.1 riastrad } 474 1.1 riastrad } 475 1.1 riastrad } 476 1.1 riastrad } 477 1.1 riastrad 478 1.1 riastrad /** 479 1.1 riastrad * r100_pm_finish - post-power state change callback. 480 1.1 riastrad * 481 1.1 riastrad * @rdev: radeon_device pointer 482 1.1 riastrad * 483 1.1 riastrad * Clean up after a power state change (r1xx-r4xx). 484 1.1 riastrad */ 485 1.1 riastrad void r100_pm_finish(struct radeon_device *rdev) 486 1.1 riastrad { 487 1.1 riastrad struct drm_device *ddev = rdev->ddev; 488 1.1 riastrad struct drm_crtc *crtc; 489 1.1 riastrad struct radeon_crtc *radeon_crtc; 490 1.1 riastrad u32 tmp; 491 1.1 riastrad 492 1.1 riastrad /* enable any active CRTCs */ 493 1.1 riastrad list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) { 494 1.1 riastrad radeon_crtc = to_radeon_crtc(crtc); 495 1.1 riastrad if (radeon_crtc->enabled) { 496 1.1 riastrad if (radeon_crtc->crtc_id) { 497 1.1 riastrad tmp = RREG32(RADEON_CRTC2_GEN_CNTL); 498 1.1 riastrad tmp &= ~RADEON_CRTC2_DISP_REQ_EN_B; 499 1.1 riastrad WREG32(RADEON_CRTC2_GEN_CNTL, tmp); 500 1.1 riastrad } else { 501 1.1 riastrad tmp = RREG32(RADEON_CRTC_GEN_CNTL); 502 1.1 riastrad tmp &= ~RADEON_CRTC_DISP_REQ_EN_B; 503 1.1 riastrad WREG32(RADEON_CRTC_GEN_CNTL, tmp); 504 1.1 riastrad } 505 1.1 riastrad } 506 1.1 riastrad } 507 1.1 riastrad } 508 1.1 riastrad 509 1.1 riastrad /** 510 1.1 riastrad * r100_gui_idle - gui idle callback. 511 1.1 riastrad * 512 1.1 riastrad * @rdev: radeon_device pointer 513 1.1 riastrad * 514 1.1 riastrad * Check of the GUI (2D/3D engines) are idle (r1xx-r5xx). 515 1.1 riastrad * Returns true if idle, false if not. 516 1.1 riastrad */ 517 1.1 riastrad bool r100_gui_idle(struct radeon_device *rdev) 518 1.1 riastrad { 519 1.1 riastrad if (RREG32(RADEON_RBBM_STATUS) & RADEON_RBBM_ACTIVE) 520 1.1 riastrad return false; 521 1.1 riastrad else 522 1.1 riastrad return true; 523 1.1 riastrad } 524 1.1 riastrad 525 1.1 riastrad /* hpd for digital panel detect/disconnect */ 526 1.1 riastrad /** 527 1.1 riastrad * r100_hpd_sense - hpd sense callback. 528 1.1 riastrad * 529 1.1 riastrad * @rdev: radeon_device pointer 530 1.1 riastrad * @hpd: hpd (hotplug detect) pin 531 1.1 riastrad * 532 1.1 riastrad * Checks if a digital monitor is connected (r1xx-r4xx). 533 1.1 riastrad * Returns true if connected, false if not connected. 534 1.1 riastrad */ 535 1.1 riastrad bool r100_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd) 536 1.1 riastrad { 537 1.1 riastrad bool connected = false; 538 1.1 riastrad 539 1.1 riastrad switch (hpd) { 540 1.1 riastrad case RADEON_HPD_1: 541 1.1 riastrad if (RREG32(RADEON_FP_GEN_CNTL) & RADEON_FP_DETECT_SENSE) 542 1.1 riastrad connected = true; 543 1.1 riastrad break; 544 1.1 riastrad case RADEON_HPD_2: 545 1.1 riastrad if (RREG32(RADEON_FP2_GEN_CNTL) & RADEON_FP2_DETECT_SENSE) 546 1.1 riastrad connected = true; 547 1.1 riastrad break; 548 1.1 riastrad default: 549 1.1 riastrad break; 550 1.1 riastrad } 551 1.1 riastrad return connected; 552 1.1 riastrad } 553 1.1 riastrad 554 1.1 riastrad /** 555 1.1 riastrad * r100_hpd_set_polarity - hpd set polarity callback. 556 1.1 riastrad * 557 1.1 riastrad * @rdev: radeon_device pointer 558 1.1 riastrad * @hpd: hpd (hotplug detect) pin 559 1.1 riastrad * 560 1.1 riastrad * Set the polarity of the hpd pin (r1xx-r4xx). 561 1.1 riastrad */ 562 1.1 riastrad void r100_hpd_set_polarity(struct radeon_device *rdev, 563 1.1 riastrad enum radeon_hpd_id hpd) 564 1.1 riastrad { 565 1.1 riastrad u32 tmp; 566 1.1 riastrad bool connected = r100_hpd_sense(rdev, hpd); 567 1.1 riastrad 568 1.1 riastrad switch (hpd) { 569 1.1 riastrad case RADEON_HPD_1: 570 1.1 riastrad tmp = RREG32(RADEON_FP_GEN_CNTL); 571 1.1 riastrad if (connected) 572 1.1 riastrad tmp &= ~RADEON_FP_DETECT_INT_POL; 573 1.1 riastrad else 574 1.1 riastrad tmp |= RADEON_FP_DETECT_INT_POL; 575 1.1 riastrad WREG32(RADEON_FP_GEN_CNTL, tmp); 576 1.1 riastrad break; 577 1.1 riastrad case RADEON_HPD_2: 578 1.1 riastrad tmp = RREG32(RADEON_FP2_GEN_CNTL); 579 1.1 riastrad if (connected) 580 1.1 riastrad tmp &= ~RADEON_FP2_DETECT_INT_POL; 581 1.1 riastrad else 582 1.1 riastrad tmp |= RADEON_FP2_DETECT_INT_POL; 583 1.1 riastrad WREG32(RADEON_FP2_GEN_CNTL, tmp); 584 1.1 riastrad break; 585 1.1 riastrad default: 586 1.1 riastrad break; 587 1.1 riastrad } 588 1.1 riastrad } 589 1.1 riastrad 590 1.1 riastrad /** 591 1.1 riastrad * r100_hpd_init - hpd setup callback. 592 1.1 riastrad * 593 1.1 riastrad * @rdev: radeon_device pointer 594 1.1 riastrad * 595 1.1 riastrad * Setup the hpd pins used by the card (r1xx-r4xx). 596 1.1 riastrad * Set the polarity, and enable the hpd interrupts. 597 1.1 riastrad */ 598 1.1 riastrad void r100_hpd_init(struct radeon_device *rdev) 599 1.1 riastrad { 600 1.1 riastrad struct drm_device *dev = rdev->ddev; 601 1.1 riastrad struct drm_connector *connector; 602 1.1 riastrad unsigned enable = 0; 603 1.1 riastrad 604 1.1 riastrad list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 605 1.1 riastrad struct radeon_connector *radeon_connector = to_radeon_connector(connector); 606 1.2 riastrad if (radeon_connector->hpd.hpd != RADEON_HPD_NONE) 607 1.2 riastrad enable |= 1 << radeon_connector->hpd.hpd; 608 1.1 riastrad radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd); 609 1.1 riastrad } 610 1.1 riastrad radeon_irq_kms_enable_hpd(rdev, enable); 611 1.1 riastrad } 612 1.1 riastrad 613 1.1 riastrad /** 614 1.1 riastrad * r100_hpd_fini - hpd tear down callback. 615 1.1 riastrad * 616 1.1 riastrad * @rdev: radeon_device pointer 617 1.1 riastrad * 618 1.1 riastrad * Tear down the hpd pins used by the card (r1xx-r4xx). 619 1.1 riastrad * Disable the hpd interrupts. 620 1.1 riastrad */ 621 1.1 riastrad void r100_hpd_fini(struct radeon_device *rdev) 622 1.1 riastrad { 623 1.1 riastrad struct drm_device *dev = rdev->ddev; 624 1.1 riastrad struct drm_connector *connector; 625 1.1 riastrad unsigned disable = 0; 626 1.1 riastrad 627 1.1 riastrad list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 628 1.1 riastrad struct radeon_connector *radeon_connector = to_radeon_connector(connector); 629 1.2 riastrad if (radeon_connector->hpd.hpd != RADEON_HPD_NONE) 630 1.2 riastrad disable |= 1 << radeon_connector->hpd.hpd; 631 1.1 riastrad } 632 1.1 riastrad radeon_irq_kms_disable_hpd(rdev, disable); 633 1.1 riastrad } 634 1.1 riastrad 635 1.1 riastrad /* 636 1.1 riastrad * PCI GART 637 1.1 riastrad */ 638 1.1 riastrad void r100_pci_gart_tlb_flush(struct radeon_device *rdev) 639 1.1 riastrad { 640 1.1 riastrad /* TODO: can we do somethings here ? */ 641 1.1 riastrad /* It seems hw only cache one entry so we should discard this 642 1.1 riastrad * entry otherwise if first GPU GART read hit this entry it 643 1.1 riastrad * could end up in wrong address. */ 644 1.1 riastrad } 645 1.1 riastrad 646 1.1 riastrad int r100_pci_gart_init(struct radeon_device *rdev) 647 1.1 riastrad { 648 1.1 riastrad int r; 649 1.1 riastrad 650 1.1 riastrad if (rdev->gart.ptr) { 651 1.1 riastrad WARN(1, "R100 PCI GART already initialized\n"); 652 1.1 riastrad return 0; 653 1.1 riastrad } 654 1.1 riastrad /* Initialize common gart structure */ 655 1.1 riastrad r = radeon_gart_init(rdev); 656 1.1 riastrad if (r) 657 1.1 riastrad return r; 658 1.1 riastrad rdev->gart.table_size = rdev->gart.num_gpu_pages * 4; 659 1.1 riastrad rdev->asic->gart.tlb_flush = &r100_pci_gart_tlb_flush; 660 1.1 riastrad rdev->asic->gart.get_page_entry = &r100_pci_gart_get_page_entry; 661 1.1 riastrad rdev->asic->gart.set_page = &r100_pci_gart_set_page; 662 1.1 riastrad return radeon_gart_table_ram_alloc(rdev); 663 1.1 riastrad } 664 1.1 riastrad 665 1.1 riastrad int r100_pci_gart_enable(struct radeon_device *rdev) 666 1.1 riastrad { 667 1.1 riastrad uint32_t tmp; 668 1.1 riastrad 669 1.1 riastrad /* discard memory request outside of configured range */ 670 1.1 riastrad tmp = RREG32(RADEON_AIC_CNTL) | RADEON_DIS_OUT_OF_PCI_GART_ACCESS; 671 1.1 riastrad WREG32(RADEON_AIC_CNTL, tmp); 672 1.1 riastrad /* set address range for PCI address translate */ 673 1.1 riastrad WREG32(RADEON_AIC_LO_ADDR, rdev->mc.gtt_start); 674 1.1 riastrad WREG32(RADEON_AIC_HI_ADDR, rdev->mc.gtt_end); 675 1.1 riastrad /* set PCI GART page-table base address */ 676 1.1 riastrad WREG32(RADEON_AIC_PT_BASE, rdev->gart.table_addr); 677 1.1 riastrad tmp = RREG32(RADEON_AIC_CNTL) | RADEON_PCIGART_TRANSLATE_EN; 678 1.1 riastrad WREG32(RADEON_AIC_CNTL, tmp); 679 1.1 riastrad r100_pci_gart_tlb_flush(rdev); 680 1.1 riastrad DRM_INFO("PCI GART of %uM enabled (table at 0x%016llX).\n", 681 1.1 riastrad (unsigned)(rdev->mc.gtt_size >> 20), 682 1.1 riastrad (unsigned long long)rdev->gart.table_addr); 683 1.1 riastrad rdev->gart.ready = true; 684 1.1 riastrad return 0; 685 1.1 riastrad } 686 1.1 riastrad 687 1.1 riastrad void r100_pci_gart_disable(struct radeon_device *rdev) 688 1.1 riastrad { 689 1.1 riastrad uint32_t tmp; 690 1.1 riastrad 691 1.1 riastrad /* discard memory request outside of configured range */ 692 1.1 riastrad tmp = RREG32(RADEON_AIC_CNTL) | RADEON_DIS_OUT_OF_PCI_GART_ACCESS; 693 1.1 riastrad WREG32(RADEON_AIC_CNTL, tmp & ~RADEON_PCIGART_TRANSLATE_EN); 694 1.1 riastrad WREG32(RADEON_AIC_LO_ADDR, 0); 695 1.1 riastrad WREG32(RADEON_AIC_HI_ADDR, 0); 696 1.1 riastrad } 697 1.1 riastrad 698 1.1 riastrad uint64_t r100_pci_gart_get_page_entry(uint64_t addr, uint32_t flags) 699 1.1 riastrad { 700 1.1 riastrad return addr; 701 1.1 riastrad } 702 1.1 riastrad 703 1.1 riastrad void r100_pci_gart_set_page(struct radeon_device *rdev, unsigned i, 704 1.1 riastrad uint64_t entry) 705 1.1 riastrad { 706 1.1 riastrad u32 *gtt = rdev->gart.ptr; 707 1.1 riastrad gtt[i] = cpu_to_le32(lower_32_bits(entry)); 708 1.1 riastrad } 709 1.1 riastrad 710 1.1 riastrad void r100_pci_gart_fini(struct radeon_device *rdev) 711 1.1 riastrad { 712 1.1 riastrad radeon_gart_fini(rdev); 713 1.1 riastrad r100_pci_gart_disable(rdev); 714 1.1 riastrad radeon_gart_table_ram_free(rdev); 715 1.1 riastrad } 716 1.1 riastrad 717 1.1 riastrad int r100_irq_set(struct radeon_device *rdev) 718 1.1 riastrad { 719 1.1 riastrad uint32_t tmp = 0; 720 1.1 riastrad 721 1.1 riastrad if (!rdev->irq.installed) { 722 1.1 riastrad WARN(1, "Can't enable IRQ/MSI because no handler is installed\n"); 723 1.1 riastrad WREG32(R_000040_GEN_INT_CNTL, 0); 724 1.1 riastrad return -EINVAL; 725 1.1 riastrad } 726 1.1 riastrad if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) { 727 1.1 riastrad tmp |= RADEON_SW_INT_ENABLE; 728 1.1 riastrad } 729 1.1 riastrad if (rdev->irq.crtc_vblank_int[0] || 730 1.1 riastrad atomic_read(&rdev->irq.pflip[0])) { 731 1.1 riastrad tmp |= RADEON_CRTC_VBLANK_MASK; 732 1.1 riastrad } 733 1.1 riastrad if (rdev->irq.crtc_vblank_int[1] || 734 1.1 riastrad atomic_read(&rdev->irq.pflip[1])) { 735 1.1 riastrad tmp |= RADEON_CRTC2_VBLANK_MASK; 736 1.1 riastrad } 737 1.1 riastrad if (rdev->irq.hpd[0]) { 738 1.1 riastrad tmp |= RADEON_FP_DETECT_MASK; 739 1.1 riastrad } 740 1.1 riastrad if (rdev->irq.hpd[1]) { 741 1.1 riastrad tmp |= RADEON_FP2_DETECT_MASK; 742 1.1 riastrad } 743 1.1 riastrad WREG32(RADEON_GEN_INT_CNTL, tmp); 744 1.1 riastrad 745 1.1 riastrad /* read back to post the write */ 746 1.1 riastrad RREG32(RADEON_GEN_INT_CNTL); 747 1.1 riastrad 748 1.1 riastrad return 0; 749 1.1 riastrad } 750 1.1 riastrad 751 1.1 riastrad void r100_irq_disable(struct radeon_device *rdev) 752 1.1 riastrad { 753 1.1 riastrad u32 tmp; 754 1.1 riastrad 755 1.1 riastrad WREG32(R_000040_GEN_INT_CNTL, 0); 756 1.1 riastrad /* Wait and acknowledge irq */ 757 1.1 riastrad mdelay(1); 758 1.1 riastrad tmp = RREG32(R_000044_GEN_INT_STATUS); 759 1.1 riastrad WREG32(R_000044_GEN_INT_STATUS, tmp); 760 1.1 riastrad } 761 1.1 riastrad 762 1.1 riastrad static uint32_t r100_irq_ack(struct radeon_device *rdev) 763 1.1 riastrad { 764 1.1 riastrad uint32_t irqs = RREG32(RADEON_GEN_INT_STATUS); 765 1.1 riastrad uint32_t irq_mask = RADEON_SW_INT_TEST | 766 1.1 riastrad RADEON_CRTC_VBLANK_STAT | RADEON_CRTC2_VBLANK_STAT | 767 1.1 riastrad RADEON_FP_DETECT_STAT | RADEON_FP2_DETECT_STAT; 768 1.1 riastrad 769 1.1 riastrad if (irqs) { 770 1.1 riastrad WREG32(RADEON_GEN_INT_STATUS, irqs); 771 1.1 riastrad } 772 1.1 riastrad return irqs & irq_mask; 773 1.1 riastrad } 774 1.1 riastrad 775 1.1 riastrad int r100_irq_process(struct radeon_device *rdev) 776 1.1 riastrad { 777 1.1 riastrad uint32_t status, msi_rearm; 778 1.1 riastrad bool queue_hotplug = false; 779 1.1 riastrad 780 1.1 riastrad status = r100_irq_ack(rdev); 781 1.1 riastrad if (!status) { 782 1.1 riastrad return IRQ_NONE; 783 1.1 riastrad } 784 1.1 riastrad if (rdev->shutdown) { 785 1.1 riastrad return IRQ_NONE; 786 1.1 riastrad } 787 1.1 riastrad while (status) { 788 1.1 riastrad /* SW interrupt */ 789 1.1 riastrad if (status & RADEON_SW_INT_TEST) { 790 1.1 riastrad radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX); 791 1.1 riastrad } 792 1.1 riastrad /* Vertical blank interrupts */ 793 1.1 riastrad if (status & RADEON_CRTC_VBLANK_STAT) { 794 1.1 riastrad if (rdev->irq.crtc_vblank_int[0]) { 795 1.1 riastrad drm_handle_vblank(rdev->ddev, 0); 796 1.1 riastrad #ifdef __NetBSD__ 797 1.1 riastrad spin_lock(&rdev->irq.vblank_lock); 798 1.1 riastrad rdev->pm.vblank_sync = true; 799 1.1 riastrad DRM_SPIN_WAKEUP_ONE(&rdev->irq.vblank_queue, &rdev->irq.vblank_lock); 800 1.1 riastrad spin_unlock(&rdev->irq.vblank_lock); 801 1.1 riastrad #else 802 1.1 riastrad rdev->pm.vblank_sync = true; 803 1.1 riastrad wake_up(&rdev->irq.vblank_queue); 804 1.1 riastrad #endif 805 1.1 riastrad } 806 1.1 riastrad if (atomic_read(&rdev->irq.pflip[0])) 807 1.1 riastrad radeon_crtc_handle_vblank(rdev, 0); 808 1.1 riastrad } 809 1.1 riastrad if (status & RADEON_CRTC2_VBLANK_STAT) { 810 1.1 riastrad if (rdev->irq.crtc_vblank_int[1]) { 811 1.1 riastrad drm_handle_vblank(rdev->ddev, 1); 812 1.1 riastrad #ifdef __NetBSD__ 813 1.1 riastrad spin_lock(&rdev->irq.vblank_lock); 814 1.1 riastrad rdev->pm.vblank_sync = true; 815 1.1 riastrad DRM_SPIN_WAKEUP_ONE(&rdev->irq.vblank_queue, &rdev->irq.vblank_lock); 816 1.1 riastrad spin_unlock(&rdev->irq.vblank_lock); 817 1.1 riastrad #else 818 1.1 riastrad rdev->pm.vblank_sync = true; 819 1.1 riastrad wake_up(&rdev->irq.vblank_queue); 820 1.1 riastrad #endif 821 1.1 riastrad } 822 1.1 riastrad if (atomic_read(&rdev->irq.pflip[1])) 823 1.1 riastrad radeon_crtc_handle_vblank(rdev, 1); 824 1.1 riastrad } 825 1.1 riastrad if (status & RADEON_FP_DETECT_STAT) { 826 1.1 riastrad queue_hotplug = true; 827 1.1 riastrad DRM_DEBUG("HPD1\n"); 828 1.1 riastrad } 829 1.1 riastrad if (status & RADEON_FP2_DETECT_STAT) { 830 1.1 riastrad queue_hotplug = true; 831 1.1 riastrad DRM_DEBUG("HPD2\n"); 832 1.1 riastrad } 833 1.1 riastrad status = r100_irq_ack(rdev); 834 1.1 riastrad } 835 1.1 riastrad if (queue_hotplug) 836 1.1 riastrad schedule_delayed_work(&rdev->hotplug_work, 0); 837 1.1 riastrad if (rdev->msi_enabled) { 838 1.1 riastrad switch (rdev->family) { 839 1.1 riastrad case CHIP_RS400: 840 1.1 riastrad case CHIP_RS480: 841 1.1 riastrad msi_rearm = RREG32(RADEON_AIC_CNTL) & ~RS400_MSI_REARM; 842 1.1 riastrad WREG32(RADEON_AIC_CNTL, msi_rearm); 843 1.1 riastrad WREG32(RADEON_AIC_CNTL, msi_rearm | RS400_MSI_REARM); 844 1.1 riastrad break; 845 1.1 riastrad default: 846 1.1 riastrad WREG32(RADEON_MSI_REARM_EN, RV370_MSI_REARM_EN); 847 1.1 riastrad break; 848 1.1 riastrad } 849 1.1 riastrad } 850 1.1 riastrad return IRQ_HANDLED; 851 1.1 riastrad } 852 1.1 riastrad 853 1.1 riastrad u32 r100_get_vblank_counter(struct radeon_device *rdev, int crtc) 854 1.1 riastrad { 855 1.1 riastrad if (crtc == 0) 856 1.1 riastrad return RREG32(RADEON_CRTC_CRNT_FRAME); 857 1.1 riastrad else 858 1.1 riastrad return RREG32(RADEON_CRTC2_CRNT_FRAME); 859 1.1 riastrad } 860 1.1 riastrad 861 1.1 riastrad /** 862 1.1 riastrad * r100_ring_hdp_flush - flush Host Data Path via the ring buffer 863 1.1 riastrad * rdev: radeon device structure 864 1.1 riastrad * ring: ring buffer struct for emitting packets 865 1.1 riastrad */ 866 1.1 riastrad static void r100_ring_hdp_flush(struct radeon_device *rdev, struct radeon_ring *ring) 867 1.1 riastrad { 868 1.1 riastrad radeon_ring_write(ring, PACKET0(RADEON_HOST_PATH_CNTL, 0)); 869 1.1 riastrad radeon_ring_write(ring, rdev->config.r100.hdp_cntl | 870 1.1 riastrad RADEON_HDP_READ_BUFFER_INVALIDATE); 871 1.1 riastrad radeon_ring_write(ring, PACKET0(RADEON_HOST_PATH_CNTL, 0)); 872 1.1 riastrad radeon_ring_write(ring, rdev->config.r100.hdp_cntl); 873 1.1 riastrad } 874 1.1 riastrad 875 1.1 riastrad /* Who ever call radeon_fence_emit should call ring_lock and ask 876 1.1 riastrad * for enough space (today caller are ib schedule and buffer move) */ 877 1.1 riastrad void r100_fence_ring_emit(struct radeon_device *rdev, 878 1.1 riastrad struct radeon_fence *fence) 879 1.1 riastrad { 880 1.1 riastrad struct radeon_ring *ring = &rdev->ring[fence->ring]; 881 1.1 riastrad 882 1.1 riastrad /* We have to make sure that caches are flushed before 883 1.1 riastrad * CPU might read something from VRAM. */ 884 1.1 riastrad radeon_ring_write(ring, PACKET0(RADEON_RB3D_DSTCACHE_CTLSTAT, 0)); 885 1.1 riastrad radeon_ring_write(ring, RADEON_RB3D_DC_FLUSH_ALL); 886 1.1 riastrad radeon_ring_write(ring, PACKET0(RADEON_RB3D_ZCACHE_CTLSTAT, 0)); 887 1.1 riastrad radeon_ring_write(ring, RADEON_RB3D_ZC_FLUSH_ALL); 888 1.1 riastrad /* Wait until IDLE & CLEAN */ 889 1.1 riastrad radeon_ring_write(ring, PACKET0(RADEON_WAIT_UNTIL, 0)); 890 1.1 riastrad radeon_ring_write(ring, RADEON_WAIT_2D_IDLECLEAN | RADEON_WAIT_3D_IDLECLEAN); 891 1.1 riastrad r100_ring_hdp_flush(rdev, ring); 892 1.1 riastrad /* Emit fence sequence & fire IRQ */ 893 1.1 riastrad radeon_ring_write(ring, PACKET0(rdev->fence_drv[fence->ring].scratch_reg, 0)); 894 1.1 riastrad radeon_ring_write(ring, fence->seq); 895 1.1 riastrad radeon_ring_write(ring, PACKET0(RADEON_GEN_INT_STATUS, 0)); 896 1.1 riastrad radeon_ring_write(ring, RADEON_SW_INT_FIRE); 897 1.1 riastrad } 898 1.1 riastrad 899 1.1 riastrad bool r100_semaphore_ring_emit(struct radeon_device *rdev, 900 1.1 riastrad struct radeon_ring *ring, 901 1.1 riastrad struct radeon_semaphore *semaphore, 902 1.1 riastrad bool emit_wait) 903 1.1 riastrad { 904 1.1 riastrad /* Unused on older asics, since we don't have semaphores or multiple rings */ 905 1.1 riastrad BUG(); 906 1.1 riastrad return false; 907 1.1 riastrad } 908 1.1 riastrad 909 1.1 riastrad struct radeon_fence *r100_copy_blit(struct radeon_device *rdev, 910 1.1 riastrad uint64_t src_offset, 911 1.1 riastrad uint64_t dst_offset, 912 1.1 riastrad unsigned num_gpu_pages, 913 1.2 riastrad struct dma_resv *resv) 914 1.1 riastrad { 915 1.1 riastrad struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; 916 1.1 riastrad struct radeon_fence *fence; 917 1.1 riastrad uint32_t cur_pages; 918 1.1 riastrad uint32_t stride_bytes = RADEON_GPU_PAGE_SIZE; 919 1.1 riastrad uint32_t pitch; 920 1.1 riastrad uint32_t stride_pixels; 921 1.1 riastrad unsigned ndw; 922 1.1 riastrad int num_loops; 923 1.1 riastrad int r = 0; 924 1.1 riastrad 925 1.1 riastrad /* radeon limited to 16k stride */ 926 1.1 riastrad stride_bytes &= 0x3fff; 927 1.1 riastrad /* radeon pitch is /64 */ 928 1.1 riastrad pitch = stride_bytes / 64; 929 1.1 riastrad stride_pixels = stride_bytes / 4; 930 1.1 riastrad num_loops = DIV_ROUND_UP(num_gpu_pages, 8191); 931 1.1 riastrad 932 1.1 riastrad /* Ask for enough room for blit + flush + fence */ 933 1.1 riastrad ndw = 64 + (10 * num_loops); 934 1.1 riastrad r = radeon_ring_lock(rdev, ring, ndw); 935 1.1 riastrad if (r) { 936 1.1 riastrad DRM_ERROR("radeon: moving bo (%d) asking for %u dw.\n", r, ndw); 937 1.1 riastrad return ERR_PTR(-EINVAL); 938 1.1 riastrad } 939 1.1 riastrad while (num_gpu_pages > 0) { 940 1.1 riastrad cur_pages = num_gpu_pages; 941 1.1 riastrad if (cur_pages > 8191) { 942 1.1 riastrad cur_pages = 8191; 943 1.1 riastrad } 944 1.1 riastrad num_gpu_pages -= cur_pages; 945 1.1 riastrad 946 1.1 riastrad /* pages are in Y direction - height 947 1.1 riastrad page width in X direction - width */ 948 1.1 riastrad radeon_ring_write(ring, PACKET3(PACKET3_BITBLT_MULTI, 8)); 949 1.1 riastrad radeon_ring_write(ring, 950 1.1 riastrad RADEON_GMC_SRC_PITCH_OFFSET_CNTL | 951 1.1 riastrad RADEON_GMC_DST_PITCH_OFFSET_CNTL | 952 1.1 riastrad RADEON_GMC_SRC_CLIPPING | 953 1.1 riastrad RADEON_GMC_DST_CLIPPING | 954 1.1 riastrad RADEON_GMC_BRUSH_NONE | 955 1.1 riastrad (RADEON_COLOR_FORMAT_ARGB8888 << 8) | 956 1.1 riastrad RADEON_GMC_SRC_DATATYPE_COLOR | 957 1.1 riastrad RADEON_ROP3_S | 958 1.1 riastrad RADEON_DP_SRC_SOURCE_MEMORY | 959 1.1 riastrad RADEON_GMC_CLR_CMP_CNTL_DIS | 960 1.1 riastrad RADEON_GMC_WR_MSK_DIS); 961 1.1 riastrad radeon_ring_write(ring, (pitch << 22) | (src_offset >> 10)); 962 1.1 riastrad radeon_ring_write(ring, (pitch << 22) | (dst_offset >> 10)); 963 1.1 riastrad radeon_ring_write(ring, (0x1fff) | (0x1fff << 16)); 964 1.1 riastrad radeon_ring_write(ring, 0); 965 1.1 riastrad radeon_ring_write(ring, (0x1fff) | (0x1fff << 16)); 966 1.1 riastrad radeon_ring_write(ring, num_gpu_pages); 967 1.1 riastrad radeon_ring_write(ring, num_gpu_pages); 968 1.1 riastrad radeon_ring_write(ring, cur_pages | (stride_pixels << 16)); 969 1.1 riastrad } 970 1.1 riastrad radeon_ring_write(ring, PACKET0(RADEON_DSTCACHE_CTLSTAT, 0)); 971 1.1 riastrad radeon_ring_write(ring, RADEON_RB2D_DC_FLUSH_ALL); 972 1.1 riastrad radeon_ring_write(ring, PACKET0(RADEON_WAIT_UNTIL, 0)); 973 1.1 riastrad radeon_ring_write(ring, 974 1.1 riastrad RADEON_WAIT_2D_IDLECLEAN | 975 1.1 riastrad RADEON_WAIT_HOST_IDLECLEAN | 976 1.1 riastrad RADEON_WAIT_DMA_GUI_IDLE); 977 1.1 riastrad r = radeon_fence_emit(rdev, &fence, RADEON_RING_TYPE_GFX_INDEX); 978 1.1 riastrad if (r) { 979 1.1 riastrad radeon_ring_unlock_undo(rdev, ring); 980 1.1 riastrad return ERR_PTR(r); 981 1.1 riastrad } 982 1.1 riastrad radeon_ring_unlock_commit(rdev, ring, false); 983 1.1 riastrad return fence; 984 1.1 riastrad } 985 1.1 riastrad 986 1.1 riastrad static int r100_cp_wait_for_idle(struct radeon_device *rdev) 987 1.1 riastrad { 988 1.1 riastrad unsigned i; 989 1.1 riastrad u32 tmp; 990 1.1 riastrad 991 1.1 riastrad for (i = 0; i < rdev->usec_timeout; i++) { 992 1.1 riastrad tmp = RREG32(R_000E40_RBBM_STATUS); 993 1.1 riastrad if (!G_000E40_CP_CMDSTRM_BUSY(tmp)) { 994 1.1 riastrad return 0; 995 1.1 riastrad } 996 1.1 riastrad udelay(1); 997 1.1 riastrad } 998 1.1 riastrad return -1; 999 1.1 riastrad } 1000 1.1 riastrad 1001 1.1 riastrad void r100_ring_start(struct radeon_device *rdev, struct radeon_ring *ring) 1002 1.1 riastrad { 1003 1.1 riastrad int r; 1004 1.1 riastrad 1005 1.1 riastrad r = radeon_ring_lock(rdev, ring, 2); 1006 1.1 riastrad if (r) { 1007 1.1 riastrad return; 1008 1.1 riastrad } 1009 1.1 riastrad radeon_ring_write(ring, PACKET0(RADEON_ISYNC_CNTL, 0)); 1010 1.1 riastrad radeon_ring_write(ring, 1011 1.1 riastrad RADEON_ISYNC_ANY2D_IDLE3D | 1012 1.1 riastrad RADEON_ISYNC_ANY3D_IDLE2D | 1013 1.1 riastrad RADEON_ISYNC_WAIT_IDLEGUI | 1014 1.1 riastrad RADEON_ISYNC_CPSCRATCH_IDLEGUI); 1015 1.1 riastrad radeon_ring_unlock_commit(rdev, ring, false); 1016 1.1 riastrad } 1017 1.1 riastrad 1018 1.1 riastrad 1019 1.1 riastrad /* Load the microcode for the CP */ 1020 1.1 riastrad static int r100_cp_init_microcode(struct radeon_device *rdev) 1021 1.1 riastrad { 1022 1.1 riastrad const char *fw_name = NULL; 1023 1.1 riastrad int err; 1024 1.1 riastrad 1025 1.1 riastrad DRM_DEBUG_KMS("\n"); 1026 1.1 riastrad 1027 1.1 riastrad if ((rdev->family == CHIP_R100) || (rdev->family == CHIP_RV100) || 1028 1.1 riastrad (rdev->family == CHIP_RV200) || (rdev->family == CHIP_RS100) || 1029 1.1 riastrad (rdev->family == CHIP_RS200)) { 1030 1.1 riastrad DRM_INFO("Loading R100 Microcode\n"); 1031 1.1 riastrad fw_name = FIRMWARE_R100; 1032 1.1 riastrad } else if ((rdev->family == CHIP_R200) || 1033 1.1 riastrad (rdev->family == CHIP_RV250) || 1034 1.1 riastrad (rdev->family == CHIP_RV280) || 1035 1.1 riastrad (rdev->family == CHIP_RS300)) { 1036 1.1 riastrad DRM_INFO("Loading R200 Microcode\n"); 1037 1.1 riastrad fw_name = FIRMWARE_R200; 1038 1.1 riastrad } else if ((rdev->family == CHIP_R300) || 1039 1.1 riastrad (rdev->family == CHIP_R350) || 1040 1.1 riastrad (rdev->family == CHIP_RV350) || 1041 1.1 riastrad (rdev->family == CHIP_RV380) || 1042 1.1 riastrad (rdev->family == CHIP_RS400) || 1043 1.1 riastrad (rdev->family == CHIP_RS480)) { 1044 1.1 riastrad DRM_INFO("Loading R300 Microcode\n"); 1045 1.1 riastrad fw_name = FIRMWARE_R300; 1046 1.1 riastrad } else if ((rdev->family == CHIP_R420) || 1047 1.1 riastrad (rdev->family == CHIP_R423) || 1048 1.1 riastrad (rdev->family == CHIP_RV410)) { 1049 1.1 riastrad DRM_INFO("Loading R400 Microcode\n"); 1050 1.1 riastrad fw_name = FIRMWARE_R420; 1051 1.1 riastrad } else if ((rdev->family == CHIP_RS690) || 1052 1.1 riastrad (rdev->family == CHIP_RS740)) { 1053 1.1 riastrad DRM_INFO("Loading RS690/RS740 Microcode\n"); 1054 1.1 riastrad fw_name = FIRMWARE_RS690; 1055 1.1 riastrad } else if (rdev->family == CHIP_RS600) { 1056 1.1 riastrad DRM_INFO("Loading RS600 Microcode\n"); 1057 1.1 riastrad fw_name = FIRMWARE_RS600; 1058 1.1 riastrad } else if ((rdev->family == CHIP_RV515) || 1059 1.1 riastrad (rdev->family == CHIP_R520) || 1060 1.1 riastrad (rdev->family == CHIP_RV530) || 1061 1.1 riastrad (rdev->family == CHIP_R580) || 1062 1.1 riastrad (rdev->family == CHIP_RV560) || 1063 1.1 riastrad (rdev->family == CHIP_RV570)) { 1064 1.1 riastrad DRM_INFO("Loading R500 Microcode\n"); 1065 1.1 riastrad fw_name = FIRMWARE_R520; 1066 1.1 riastrad } 1067 1.1 riastrad 1068 1.1 riastrad err = request_firmware(&rdev->me_fw, fw_name, rdev->dev); 1069 1.1 riastrad if (err) { 1070 1.2 riastrad pr_err("radeon_cp: Failed to load firmware \"%s\"\n", fw_name); 1071 1.1 riastrad } else if (rdev->me_fw->size % 8) { 1072 1.2 riastrad pr_err("radeon_cp: Bogus length %zu in firmware \"%s\"\n", 1073 1.1 riastrad rdev->me_fw->size, fw_name); 1074 1.1 riastrad err = -EINVAL; 1075 1.1 riastrad release_firmware(rdev->me_fw); 1076 1.1 riastrad rdev->me_fw = NULL; 1077 1.1 riastrad } 1078 1.1 riastrad return err; 1079 1.1 riastrad } 1080 1.1 riastrad 1081 1.1 riastrad u32 r100_gfx_get_rptr(struct radeon_device *rdev, 1082 1.1 riastrad struct radeon_ring *ring) 1083 1.1 riastrad { 1084 1.1 riastrad u32 rptr; 1085 1.1 riastrad 1086 1.1 riastrad if (rdev->wb.enabled) 1087 1.1 riastrad rptr = le32_to_cpu(rdev->wb.wb[ring->rptr_offs/4]); 1088 1.1 riastrad else 1089 1.1 riastrad rptr = RREG32(RADEON_CP_RB_RPTR); 1090 1.1 riastrad 1091 1.1 riastrad return rptr; 1092 1.1 riastrad } 1093 1.1 riastrad 1094 1.1 riastrad u32 r100_gfx_get_wptr(struct radeon_device *rdev, 1095 1.1 riastrad struct radeon_ring *ring) 1096 1.1 riastrad { 1097 1.2 riastrad return RREG32(RADEON_CP_RB_WPTR); 1098 1.1 riastrad } 1099 1.1 riastrad 1100 1.1 riastrad void r100_gfx_set_wptr(struct radeon_device *rdev, 1101 1.1 riastrad struct radeon_ring *ring) 1102 1.1 riastrad { 1103 1.1 riastrad WREG32(RADEON_CP_RB_WPTR, ring->wptr); 1104 1.1 riastrad (void)RREG32(RADEON_CP_RB_WPTR); 1105 1.1 riastrad } 1106 1.1 riastrad 1107 1.1 riastrad static void r100_cp_load_microcode(struct radeon_device *rdev) 1108 1.1 riastrad { 1109 1.1 riastrad const __be32 *fw_data; 1110 1.1 riastrad int i, size; 1111 1.1 riastrad 1112 1.1 riastrad if (r100_gui_wait_for_idle(rdev)) { 1113 1.2 riastrad pr_warn("Failed to wait GUI idle while programming pipes. Bad things might happen.\n"); 1114 1.1 riastrad } 1115 1.1 riastrad 1116 1.1 riastrad if (rdev->me_fw) { 1117 1.1 riastrad size = rdev->me_fw->size / 4; 1118 1.1 riastrad fw_data = (const __be32 *)rdev->me_fw->data; 1119 1.1 riastrad WREG32(RADEON_CP_ME_RAM_ADDR, 0); 1120 1.1 riastrad for (i = 0; i < size; i += 2) { 1121 1.1 riastrad WREG32(RADEON_CP_ME_RAM_DATAH, 1122 1.1 riastrad be32_to_cpup(&fw_data[i])); 1123 1.1 riastrad WREG32(RADEON_CP_ME_RAM_DATAL, 1124 1.1 riastrad be32_to_cpup(&fw_data[i + 1])); 1125 1.1 riastrad } 1126 1.1 riastrad } 1127 1.1 riastrad } 1128 1.1 riastrad 1129 1.1 riastrad int r100_cp_init(struct radeon_device *rdev, unsigned ring_size) 1130 1.1 riastrad { 1131 1.1 riastrad struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; 1132 1.1 riastrad unsigned rb_bufsz; 1133 1.1 riastrad unsigned rb_blksz; 1134 1.1 riastrad unsigned max_fetch; 1135 1.1 riastrad unsigned pre_write_timer; 1136 1.1 riastrad unsigned pre_write_limit; 1137 1.1 riastrad unsigned indirect2_start; 1138 1.1 riastrad unsigned indirect1_start; 1139 1.1 riastrad uint32_t tmp; 1140 1.1 riastrad int r; 1141 1.1 riastrad 1142 1.1 riastrad if (r100_debugfs_cp_init(rdev)) { 1143 1.1 riastrad DRM_ERROR("Failed to register debugfs file for CP !\n"); 1144 1.1 riastrad } 1145 1.1 riastrad if (!rdev->me_fw) { 1146 1.1 riastrad r = r100_cp_init_microcode(rdev); 1147 1.1 riastrad if (r) { 1148 1.1 riastrad DRM_ERROR("Failed to load firmware!\n"); 1149 1.1 riastrad return r; 1150 1.1 riastrad } 1151 1.1 riastrad } 1152 1.1 riastrad 1153 1.1 riastrad /* Align ring size */ 1154 1.1 riastrad rb_bufsz = order_base_2(ring_size / 8); 1155 1.1 riastrad ring_size = (1 << (rb_bufsz + 1)) * 4; 1156 1.1 riastrad r100_cp_load_microcode(rdev); 1157 1.1 riastrad r = radeon_ring_init(rdev, ring, ring_size, RADEON_WB_CP_RPTR_OFFSET, 1158 1.1 riastrad RADEON_CP_PACKET2); 1159 1.1 riastrad if (r) { 1160 1.1 riastrad return r; 1161 1.1 riastrad } 1162 1.1 riastrad /* Each time the cp read 1024 bytes (16 dword/quadword) update 1163 1.1 riastrad * the rptr copy in system ram */ 1164 1.1 riastrad rb_blksz = 9; 1165 1.1 riastrad /* cp will read 128bytes at a time (4 dwords) */ 1166 1.1 riastrad max_fetch = 1; 1167 1.1 riastrad ring->align_mask = 16 - 1; 1168 1.1 riastrad /* Write to CP_RB_WPTR will be delayed for pre_write_timer clocks */ 1169 1.1 riastrad pre_write_timer = 64; 1170 1.1 riastrad /* Force CP_RB_WPTR write if written more than one time before the 1171 1.1 riastrad * delay expire 1172 1.1 riastrad */ 1173 1.1 riastrad pre_write_limit = 0; 1174 1.1 riastrad /* Setup the cp cache like this (cache size is 96 dwords) : 1175 1.1 riastrad * RING 0 to 15 1176 1.1 riastrad * INDIRECT1 16 to 79 1177 1.1 riastrad * INDIRECT2 80 to 95 1178 1.1 riastrad * So ring cache size is 16dwords (> (2 * max_fetch = 2 * 4dwords)) 1179 1.1 riastrad * indirect1 cache size is 64dwords (> (2 * max_fetch = 2 * 4dwords)) 1180 1.1 riastrad * indirect2 cache size is 16dwords (> (2 * max_fetch = 2 * 4dwords)) 1181 1.1 riastrad * Idea being that most of the gpu cmd will be through indirect1 buffer 1182 1.1 riastrad * so it gets the bigger cache. 1183 1.1 riastrad */ 1184 1.1 riastrad indirect2_start = 80; 1185 1.1 riastrad indirect1_start = 16; 1186 1.1 riastrad /* cp setup */ 1187 1.1 riastrad WREG32(0x718, pre_write_timer | (pre_write_limit << 28)); 1188 1.1 riastrad tmp = (REG_SET(RADEON_RB_BUFSZ, rb_bufsz) | 1189 1.1 riastrad REG_SET(RADEON_RB_BLKSZ, rb_blksz) | 1190 1.1 riastrad REG_SET(RADEON_MAX_FETCH, max_fetch)); 1191 1.1 riastrad #ifdef __BIG_ENDIAN 1192 1.1 riastrad tmp |= RADEON_BUF_SWAP_32BIT; 1193 1.1 riastrad #endif 1194 1.1 riastrad WREG32(RADEON_CP_RB_CNTL, tmp | RADEON_RB_NO_UPDATE); 1195 1.1 riastrad 1196 1.1 riastrad /* Set ring address */ 1197 1.1 riastrad DRM_INFO("radeon: ring at 0x%016lX\n", (unsigned long)ring->gpu_addr); 1198 1.1 riastrad WREG32(RADEON_CP_RB_BASE, ring->gpu_addr); 1199 1.1 riastrad /* Force read & write ptr to 0 */ 1200 1.1 riastrad WREG32(RADEON_CP_RB_CNTL, tmp | RADEON_RB_RPTR_WR_ENA | RADEON_RB_NO_UPDATE); 1201 1.1 riastrad WREG32(RADEON_CP_RB_RPTR_WR, 0); 1202 1.1 riastrad ring->wptr = 0; 1203 1.1 riastrad WREG32(RADEON_CP_RB_WPTR, ring->wptr); 1204 1.1 riastrad 1205 1.1 riastrad /* set the wb address whether it's enabled or not */ 1206 1.1 riastrad WREG32(R_00070C_CP_RB_RPTR_ADDR, 1207 1.1 riastrad S_00070C_RB_RPTR_ADDR((rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) >> 2)); 1208 1.1 riastrad WREG32(R_000774_SCRATCH_ADDR, rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET); 1209 1.1 riastrad 1210 1.1 riastrad if (rdev->wb.enabled) 1211 1.1 riastrad WREG32(R_000770_SCRATCH_UMSK, 0xff); 1212 1.1 riastrad else { 1213 1.1 riastrad tmp |= RADEON_RB_NO_UPDATE; 1214 1.1 riastrad WREG32(R_000770_SCRATCH_UMSK, 0); 1215 1.1 riastrad } 1216 1.1 riastrad 1217 1.1 riastrad WREG32(RADEON_CP_RB_CNTL, tmp); 1218 1.1 riastrad udelay(10); 1219 1.1 riastrad /* Set cp mode to bus mastering & enable cp*/ 1220 1.1 riastrad WREG32(RADEON_CP_CSQ_MODE, 1221 1.1 riastrad REG_SET(RADEON_INDIRECT2_START, indirect2_start) | 1222 1.1 riastrad REG_SET(RADEON_INDIRECT1_START, indirect1_start)); 1223 1.1 riastrad WREG32(RADEON_CP_RB_WPTR_DELAY, 0); 1224 1.1 riastrad WREG32(RADEON_CP_CSQ_MODE, 0x00004D4D); 1225 1.1 riastrad WREG32(RADEON_CP_CSQ_CNTL, RADEON_CSQ_PRIBM_INDBM); 1226 1.1 riastrad 1227 1.1 riastrad /* at this point everything should be setup correctly to enable master */ 1228 1.1 riastrad pci_set_master(rdev->pdev); 1229 1.1 riastrad 1230 1.1 riastrad radeon_ring_start(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]); 1231 1.1 riastrad r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, ring); 1232 1.1 riastrad if (r) { 1233 1.1 riastrad DRM_ERROR("radeon: cp isn't working (%d).\n", r); 1234 1.1 riastrad return r; 1235 1.1 riastrad } 1236 1.1 riastrad ring->ready = true; 1237 1.1 riastrad radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size); 1238 1.1 riastrad 1239 1.1 riastrad if (!ring->rptr_save_reg /* not resuming from suspend */ 1240 1.1 riastrad && radeon_ring_supports_scratch_reg(rdev, ring)) { 1241 1.1 riastrad r = radeon_scratch_get(rdev, &ring->rptr_save_reg); 1242 1.1 riastrad if (r) { 1243 1.1 riastrad DRM_ERROR("failed to get scratch reg for rptr save (%d).\n", r); 1244 1.1 riastrad ring->rptr_save_reg = 0; 1245 1.1 riastrad } 1246 1.1 riastrad } 1247 1.1 riastrad return 0; 1248 1.1 riastrad } 1249 1.1 riastrad 1250 1.1 riastrad void r100_cp_fini(struct radeon_device *rdev) 1251 1.1 riastrad { 1252 1.1 riastrad if (r100_cp_wait_for_idle(rdev)) { 1253 1.1 riastrad DRM_ERROR("Wait for CP idle timeout, shutting down CP.\n"); 1254 1.1 riastrad } 1255 1.1 riastrad /* Disable ring */ 1256 1.1 riastrad r100_cp_disable(rdev); 1257 1.1 riastrad radeon_scratch_free(rdev, rdev->ring[RADEON_RING_TYPE_GFX_INDEX].rptr_save_reg); 1258 1.1 riastrad radeon_ring_fini(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]); 1259 1.1 riastrad DRM_INFO("radeon: cp finalized\n"); 1260 1.1 riastrad } 1261 1.1 riastrad 1262 1.1 riastrad void r100_cp_disable(struct radeon_device *rdev) 1263 1.1 riastrad { 1264 1.1 riastrad /* Disable ring */ 1265 1.1 riastrad radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size); 1266 1.1 riastrad rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false; 1267 1.1 riastrad WREG32(RADEON_CP_CSQ_MODE, 0); 1268 1.1 riastrad WREG32(RADEON_CP_CSQ_CNTL, 0); 1269 1.1 riastrad WREG32(R_000770_SCRATCH_UMSK, 0); 1270 1.1 riastrad if (r100_gui_wait_for_idle(rdev)) { 1271 1.2 riastrad pr_warn("Failed to wait GUI idle while programming pipes. Bad things might happen.\n"); 1272 1.1 riastrad } 1273 1.1 riastrad } 1274 1.1 riastrad 1275 1.1 riastrad /* 1276 1.1 riastrad * CS functions 1277 1.1 riastrad */ 1278 1.1 riastrad int r100_reloc_pitch_offset(struct radeon_cs_parser *p, 1279 1.1 riastrad struct radeon_cs_packet *pkt, 1280 1.1 riastrad unsigned idx, 1281 1.1 riastrad unsigned reg) 1282 1.1 riastrad { 1283 1.1 riastrad int r; 1284 1.1 riastrad u32 tile_flags = 0; 1285 1.1 riastrad u32 tmp; 1286 1.1 riastrad struct radeon_bo_list *reloc; 1287 1.1 riastrad u32 value; 1288 1.1 riastrad 1289 1.1 riastrad r = radeon_cs_packet_next_reloc(p, &reloc, 0); 1290 1.1 riastrad if (r) { 1291 1.1 riastrad DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1292 1.1 riastrad idx, reg); 1293 1.1 riastrad radeon_cs_dump_packet(p, pkt); 1294 1.1 riastrad return r; 1295 1.1 riastrad } 1296 1.1 riastrad 1297 1.1 riastrad value = radeon_get_ib_value(p, idx); 1298 1.1 riastrad tmp = value & 0x003fffff; 1299 1.1 riastrad tmp += (((u32)reloc->gpu_offset) >> 10); 1300 1.1 riastrad 1301 1.1 riastrad if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) { 1302 1.1 riastrad if (reloc->tiling_flags & RADEON_TILING_MACRO) 1303 1.1 riastrad tile_flags |= RADEON_DST_TILE_MACRO; 1304 1.1 riastrad if (reloc->tiling_flags & RADEON_TILING_MICRO) { 1305 1.1 riastrad if (reg == RADEON_SRC_PITCH_OFFSET) { 1306 1.1 riastrad DRM_ERROR("Cannot src blit from microtiled surface\n"); 1307 1.1 riastrad radeon_cs_dump_packet(p, pkt); 1308 1.1 riastrad return -EINVAL; 1309 1.1 riastrad } 1310 1.1 riastrad tile_flags |= RADEON_DST_TILE_MICRO; 1311 1.1 riastrad } 1312 1.1 riastrad 1313 1.1 riastrad tmp |= tile_flags; 1314 1.1 riastrad p->ib.ptr[idx] = (value & 0x3fc00000) | tmp; 1315 1.1 riastrad } else 1316 1.1 riastrad p->ib.ptr[idx] = (value & 0xffc00000) | tmp; 1317 1.1 riastrad return 0; 1318 1.1 riastrad } 1319 1.1 riastrad 1320 1.1 riastrad int r100_packet3_load_vbpntr(struct radeon_cs_parser *p, 1321 1.1 riastrad struct radeon_cs_packet *pkt, 1322 1.1 riastrad int idx) 1323 1.1 riastrad { 1324 1.1 riastrad unsigned c, i; 1325 1.1 riastrad struct radeon_bo_list *reloc; 1326 1.1 riastrad struct r100_cs_track *track; 1327 1.1 riastrad int r = 0; 1328 1.1 riastrad volatile uint32_t *ib; 1329 1.1 riastrad u32 idx_value; 1330 1.1 riastrad 1331 1.1 riastrad ib = p->ib.ptr; 1332 1.1 riastrad track = (struct r100_cs_track *)p->track; 1333 1.1 riastrad c = radeon_get_ib_value(p, idx++) & 0x1F; 1334 1.1 riastrad if (c > 16) { 1335 1.1 riastrad DRM_ERROR("Only 16 vertex buffers are allowed %d\n", 1336 1.1 riastrad pkt->opcode); 1337 1.1 riastrad radeon_cs_dump_packet(p, pkt); 1338 1.1 riastrad return -EINVAL; 1339 1.1 riastrad } 1340 1.1 riastrad track->num_arrays = c; 1341 1.1 riastrad for (i = 0; i < (c - 1); i+=2, idx+=3) { 1342 1.1 riastrad r = radeon_cs_packet_next_reloc(p, &reloc, 0); 1343 1.1 riastrad if (r) { 1344 1.1 riastrad DRM_ERROR("No reloc for packet3 %d\n", 1345 1.1 riastrad pkt->opcode); 1346 1.1 riastrad radeon_cs_dump_packet(p, pkt); 1347 1.1 riastrad return r; 1348 1.1 riastrad } 1349 1.1 riastrad idx_value = radeon_get_ib_value(p, idx); 1350 1.1 riastrad ib[idx+1] = radeon_get_ib_value(p, idx + 1) + ((u32)reloc->gpu_offset); 1351 1.1 riastrad 1352 1.1 riastrad track->arrays[i + 0].esize = idx_value >> 8; 1353 1.1 riastrad track->arrays[i + 0].robj = reloc->robj; 1354 1.1 riastrad track->arrays[i + 0].esize &= 0x7F; 1355 1.1 riastrad r = radeon_cs_packet_next_reloc(p, &reloc, 0); 1356 1.1 riastrad if (r) { 1357 1.1 riastrad DRM_ERROR("No reloc for packet3 %d\n", 1358 1.1 riastrad pkt->opcode); 1359 1.1 riastrad radeon_cs_dump_packet(p, pkt); 1360 1.1 riastrad return r; 1361 1.1 riastrad } 1362 1.1 riastrad ib[idx+2] = radeon_get_ib_value(p, idx + 2) + ((u32)reloc->gpu_offset); 1363 1.1 riastrad track->arrays[i + 1].robj = reloc->robj; 1364 1.1 riastrad track->arrays[i + 1].esize = idx_value >> 24; 1365 1.1 riastrad track->arrays[i + 1].esize &= 0x7F; 1366 1.1 riastrad } 1367 1.1 riastrad if (c & 1) { 1368 1.1 riastrad r = radeon_cs_packet_next_reloc(p, &reloc, 0); 1369 1.1 riastrad if (r) { 1370 1.1 riastrad DRM_ERROR("No reloc for packet3 %d\n", 1371 1.1 riastrad pkt->opcode); 1372 1.1 riastrad radeon_cs_dump_packet(p, pkt); 1373 1.1 riastrad return r; 1374 1.1 riastrad } 1375 1.1 riastrad idx_value = radeon_get_ib_value(p, idx); 1376 1.1 riastrad ib[idx+1] = radeon_get_ib_value(p, idx + 1) + ((u32)reloc->gpu_offset); 1377 1.1 riastrad track->arrays[i + 0].robj = reloc->robj; 1378 1.1 riastrad track->arrays[i + 0].esize = idx_value >> 8; 1379 1.1 riastrad track->arrays[i + 0].esize &= 0x7F; 1380 1.1 riastrad } 1381 1.1 riastrad return r; 1382 1.1 riastrad } 1383 1.1 riastrad 1384 1.1 riastrad int r100_cs_parse_packet0(struct radeon_cs_parser *p, 1385 1.1 riastrad struct radeon_cs_packet *pkt, 1386 1.1 riastrad const unsigned *auth, unsigned n, 1387 1.1 riastrad radeon_packet0_check_t check) 1388 1.1 riastrad { 1389 1.1 riastrad unsigned reg; 1390 1.1 riastrad unsigned i, j, m; 1391 1.1 riastrad unsigned idx; 1392 1.1 riastrad int r; 1393 1.1 riastrad 1394 1.1 riastrad idx = pkt->idx + 1; 1395 1.1 riastrad reg = pkt->reg; 1396 1.1 riastrad /* Check that register fall into register range 1397 1.1 riastrad * determined by the number of entry (n) in the 1398 1.1 riastrad * safe register bitmap. 1399 1.1 riastrad */ 1400 1.1 riastrad if (pkt->one_reg_wr) { 1401 1.1 riastrad if ((reg >> 7) > n) { 1402 1.1 riastrad return -EINVAL; 1403 1.1 riastrad } 1404 1.1 riastrad } else { 1405 1.1 riastrad if (((reg + (pkt->count << 2)) >> 7) > n) { 1406 1.1 riastrad return -EINVAL; 1407 1.1 riastrad } 1408 1.1 riastrad } 1409 1.1 riastrad for (i = 0; i <= pkt->count; i++, idx++) { 1410 1.1 riastrad j = (reg >> 7); 1411 1.1 riastrad m = 1 << ((reg >> 2) & 31); 1412 1.1 riastrad if (auth[j] & m) { 1413 1.1 riastrad r = check(p, pkt, idx, reg); 1414 1.1 riastrad if (r) { 1415 1.1 riastrad return r; 1416 1.1 riastrad } 1417 1.1 riastrad } 1418 1.1 riastrad if (pkt->one_reg_wr) { 1419 1.1 riastrad if (!(auth[j] & m)) { 1420 1.1 riastrad break; 1421 1.1 riastrad } 1422 1.1 riastrad } else { 1423 1.1 riastrad reg += 4; 1424 1.1 riastrad } 1425 1.1 riastrad } 1426 1.1 riastrad return 0; 1427 1.1 riastrad } 1428 1.1 riastrad 1429 1.1 riastrad /** 1430 1.1 riastrad * r100_cs_packet_next_vline() - parse userspace VLINE packet 1431 1.1 riastrad * @parser: parser structure holding parsing context. 1432 1.1 riastrad * 1433 1.1 riastrad * Userspace sends a special sequence for VLINE waits. 1434 1.1 riastrad * PACKET0 - VLINE_START_END + value 1435 1.1 riastrad * PACKET0 - WAIT_UNTIL +_value 1436 1.1 riastrad * RELOC (P3) - crtc_id in reloc. 1437 1.1 riastrad * 1438 1.1 riastrad * This function parses this and relocates the VLINE START END 1439 1.1 riastrad * and WAIT UNTIL packets to the correct crtc. 1440 1.1 riastrad * It also detects a switched off crtc and nulls out the 1441 1.1 riastrad * wait in that case. 1442 1.1 riastrad */ 1443 1.1 riastrad int r100_cs_packet_parse_vline(struct radeon_cs_parser *p) 1444 1.1 riastrad { 1445 1.1 riastrad struct drm_crtc *crtc; 1446 1.1 riastrad struct radeon_crtc *radeon_crtc; 1447 1.1 riastrad struct radeon_cs_packet p3reloc, waitreloc; 1448 1.1 riastrad int crtc_id; 1449 1.1 riastrad int r; 1450 1.1 riastrad uint32_t header, h_idx, reg; 1451 1.1 riastrad volatile uint32_t *ib; 1452 1.1 riastrad 1453 1.1 riastrad ib = p->ib.ptr; 1454 1.1 riastrad 1455 1.1 riastrad /* parse the wait until */ 1456 1.1 riastrad r = radeon_cs_packet_parse(p, &waitreloc, p->idx); 1457 1.1 riastrad if (r) 1458 1.1 riastrad return r; 1459 1.1 riastrad 1460 1.1 riastrad /* check its a wait until and only 1 count */ 1461 1.1 riastrad if (waitreloc.reg != RADEON_WAIT_UNTIL || 1462 1.1 riastrad waitreloc.count != 0) { 1463 1.1 riastrad DRM_ERROR("vline wait had illegal wait until segment\n"); 1464 1.1 riastrad return -EINVAL; 1465 1.1 riastrad } 1466 1.1 riastrad 1467 1.1 riastrad if (radeon_get_ib_value(p, waitreloc.idx + 1) != RADEON_WAIT_CRTC_VLINE) { 1468 1.1 riastrad DRM_ERROR("vline wait had illegal wait until\n"); 1469 1.1 riastrad return -EINVAL; 1470 1.1 riastrad } 1471 1.1 riastrad 1472 1.1 riastrad /* jump over the NOP */ 1473 1.1 riastrad r = radeon_cs_packet_parse(p, &p3reloc, p->idx + waitreloc.count + 2); 1474 1.1 riastrad if (r) 1475 1.1 riastrad return r; 1476 1.1 riastrad 1477 1.1 riastrad h_idx = p->idx - 2; 1478 1.1 riastrad p->idx += waitreloc.count + 2; 1479 1.1 riastrad p->idx += p3reloc.count + 2; 1480 1.1 riastrad 1481 1.1 riastrad header = radeon_get_ib_value(p, h_idx); 1482 1.1 riastrad crtc_id = radeon_get_ib_value(p, h_idx + 5); 1483 1.1 riastrad reg = R100_CP_PACKET0_GET_REG(header); 1484 1.2 riastrad crtc = drm_crtc_find(p->rdev->ddev, p->filp, crtc_id); 1485 1.1 riastrad if (!crtc) { 1486 1.1 riastrad DRM_ERROR("cannot find crtc %d\n", crtc_id); 1487 1.1 riastrad return -ENOENT; 1488 1.1 riastrad } 1489 1.1 riastrad radeon_crtc = to_radeon_crtc(crtc); 1490 1.1 riastrad crtc_id = radeon_crtc->crtc_id; 1491 1.1 riastrad 1492 1.1 riastrad if (!crtc->enabled) { 1493 1.1 riastrad /* if the CRTC isn't enabled - we need to nop out the wait until */ 1494 1.1 riastrad ib[h_idx + 2] = PACKET2(0); 1495 1.1 riastrad ib[h_idx + 3] = PACKET2(0); 1496 1.1 riastrad } else if (crtc_id == 1) { 1497 1.1 riastrad switch (reg) { 1498 1.1 riastrad case AVIVO_D1MODE_VLINE_START_END: 1499 1.1 riastrad header &= ~R300_CP_PACKET0_REG_MASK; 1500 1.1 riastrad header |= AVIVO_D2MODE_VLINE_START_END >> 2; 1501 1.1 riastrad break; 1502 1.1 riastrad case RADEON_CRTC_GUI_TRIG_VLINE: 1503 1.1 riastrad header &= ~R300_CP_PACKET0_REG_MASK; 1504 1.1 riastrad header |= RADEON_CRTC2_GUI_TRIG_VLINE >> 2; 1505 1.1 riastrad break; 1506 1.1 riastrad default: 1507 1.1 riastrad DRM_ERROR("unknown crtc reloc\n"); 1508 1.1 riastrad return -EINVAL; 1509 1.1 riastrad } 1510 1.1 riastrad ib[h_idx] = header; 1511 1.1 riastrad ib[h_idx + 3] |= RADEON_ENG_DISPLAY_SELECT_CRTC1; 1512 1.1 riastrad } 1513 1.1 riastrad 1514 1.1 riastrad return 0; 1515 1.1 riastrad } 1516 1.1 riastrad 1517 1.1 riastrad static int r100_get_vtx_size(uint32_t vtx_fmt) 1518 1.1 riastrad { 1519 1.1 riastrad int vtx_size; 1520 1.1 riastrad vtx_size = 2; 1521 1.1 riastrad /* ordered according to bits in spec */ 1522 1.1 riastrad if (vtx_fmt & RADEON_SE_VTX_FMT_W0) 1523 1.1 riastrad vtx_size++; 1524 1.1 riastrad if (vtx_fmt & RADEON_SE_VTX_FMT_FPCOLOR) 1525 1.1 riastrad vtx_size += 3; 1526 1.1 riastrad if (vtx_fmt & RADEON_SE_VTX_FMT_FPALPHA) 1527 1.1 riastrad vtx_size++; 1528 1.1 riastrad if (vtx_fmt & RADEON_SE_VTX_FMT_PKCOLOR) 1529 1.1 riastrad vtx_size++; 1530 1.1 riastrad if (vtx_fmt & RADEON_SE_VTX_FMT_FPSPEC) 1531 1.1 riastrad vtx_size += 3; 1532 1.1 riastrad if (vtx_fmt & RADEON_SE_VTX_FMT_FPFOG) 1533 1.1 riastrad vtx_size++; 1534 1.1 riastrad if (vtx_fmt & RADEON_SE_VTX_FMT_PKSPEC) 1535 1.1 riastrad vtx_size++; 1536 1.1 riastrad if (vtx_fmt & RADEON_SE_VTX_FMT_ST0) 1537 1.1 riastrad vtx_size += 2; 1538 1.1 riastrad if (vtx_fmt & RADEON_SE_VTX_FMT_ST1) 1539 1.1 riastrad vtx_size += 2; 1540 1.1 riastrad if (vtx_fmt & RADEON_SE_VTX_FMT_Q1) 1541 1.1 riastrad vtx_size++; 1542 1.1 riastrad if (vtx_fmt & RADEON_SE_VTX_FMT_ST2) 1543 1.1 riastrad vtx_size += 2; 1544 1.1 riastrad if (vtx_fmt & RADEON_SE_VTX_FMT_Q2) 1545 1.1 riastrad vtx_size++; 1546 1.1 riastrad if (vtx_fmt & RADEON_SE_VTX_FMT_ST3) 1547 1.1 riastrad vtx_size += 2; 1548 1.1 riastrad if (vtx_fmt & RADEON_SE_VTX_FMT_Q3) 1549 1.1 riastrad vtx_size++; 1550 1.1 riastrad if (vtx_fmt & RADEON_SE_VTX_FMT_Q0) 1551 1.1 riastrad vtx_size++; 1552 1.1 riastrad /* blend weight */ 1553 1.1 riastrad if (vtx_fmt & (0x7 << 15)) 1554 1.1 riastrad vtx_size += (vtx_fmt >> 15) & 0x7; 1555 1.1 riastrad if (vtx_fmt & RADEON_SE_VTX_FMT_N0) 1556 1.1 riastrad vtx_size += 3; 1557 1.1 riastrad if (vtx_fmt & RADEON_SE_VTX_FMT_XY1) 1558 1.1 riastrad vtx_size += 2; 1559 1.1 riastrad if (vtx_fmt & RADEON_SE_VTX_FMT_Z1) 1560 1.1 riastrad vtx_size++; 1561 1.1 riastrad if (vtx_fmt & RADEON_SE_VTX_FMT_W1) 1562 1.1 riastrad vtx_size++; 1563 1.1 riastrad if (vtx_fmt & RADEON_SE_VTX_FMT_N1) 1564 1.1 riastrad vtx_size++; 1565 1.1 riastrad if (vtx_fmt & RADEON_SE_VTX_FMT_Z) 1566 1.1 riastrad vtx_size++; 1567 1.1 riastrad return vtx_size; 1568 1.1 riastrad } 1569 1.1 riastrad 1570 1.1 riastrad static int r100_packet0_check(struct radeon_cs_parser *p, 1571 1.1 riastrad struct radeon_cs_packet *pkt, 1572 1.1 riastrad unsigned idx, unsigned reg) 1573 1.1 riastrad { 1574 1.1 riastrad struct radeon_bo_list *reloc; 1575 1.1 riastrad struct r100_cs_track *track; 1576 1.1 riastrad volatile uint32_t *ib; 1577 1.1 riastrad uint32_t tmp; 1578 1.1 riastrad int r; 1579 1.1 riastrad int i, face; 1580 1.1 riastrad u32 tile_flags = 0; 1581 1.1 riastrad u32 idx_value; 1582 1.1 riastrad 1583 1.1 riastrad ib = p->ib.ptr; 1584 1.1 riastrad track = (struct r100_cs_track *)p->track; 1585 1.1 riastrad 1586 1.1 riastrad idx_value = radeon_get_ib_value(p, idx); 1587 1.1 riastrad 1588 1.1 riastrad switch (reg) { 1589 1.1 riastrad case RADEON_CRTC_GUI_TRIG_VLINE: 1590 1.1 riastrad r = r100_cs_packet_parse_vline(p); 1591 1.1 riastrad if (r) { 1592 1.1 riastrad DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1593 1.1 riastrad idx, reg); 1594 1.1 riastrad radeon_cs_dump_packet(p, pkt); 1595 1.1 riastrad return r; 1596 1.1 riastrad } 1597 1.1 riastrad break; 1598 1.1 riastrad /* FIXME: only allow PACKET3 blit? easier to check for out of 1599 1.1 riastrad * range access */ 1600 1.1 riastrad case RADEON_DST_PITCH_OFFSET: 1601 1.1 riastrad case RADEON_SRC_PITCH_OFFSET: 1602 1.1 riastrad r = r100_reloc_pitch_offset(p, pkt, idx, reg); 1603 1.1 riastrad if (r) 1604 1.1 riastrad return r; 1605 1.1 riastrad break; 1606 1.1 riastrad case RADEON_RB3D_DEPTHOFFSET: 1607 1.1 riastrad r = radeon_cs_packet_next_reloc(p, &reloc, 0); 1608 1.1 riastrad if (r) { 1609 1.1 riastrad DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1610 1.1 riastrad idx, reg); 1611 1.1 riastrad radeon_cs_dump_packet(p, pkt); 1612 1.1 riastrad return r; 1613 1.1 riastrad } 1614 1.1 riastrad track->zb.robj = reloc->robj; 1615 1.1 riastrad track->zb.offset = idx_value; 1616 1.1 riastrad track->zb_dirty = true; 1617 1.1 riastrad ib[idx] = idx_value + ((u32)reloc->gpu_offset); 1618 1.1 riastrad break; 1619 1.1 riastrad case RADEON_RB3D_COLOROFFSET: 1620 1.1 riastrad r = radeon_cs_packet_next_reloc(p, &reloc, 0); 1621 1.1 riastrad if (r) { 1622 1.1 riastrad DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1623 1.1 riastrad idx, reg); 1624 1.1 riastrad radeon_cs_dump_packet(p, pkt); 1625 1.1 riastrad return r; 1626 1.1 riastrad } 1627 1.1 riastrad track->cb[0].robj = reloc->robj; 1628 1.1 riastrad track->cb[0].offset = idx_value; 1629 1.1 riastrad track->cb_dirty = true; 1630 1.1 riastrad ib[idx] = idx_value + ((u32)reloc->gpu_offset); 1631 1.1 riastrad break; 1632 1.1 riastrad case RADEON_PP_TXOFFSET_0: 1633 1.1 riastrad case RADEON_PP_TXOFFSET_1: 1634 1.1 riastrad case RADEON_PP_TXOFFSET_2: 1635 1.1 riastrad i = (reg - RADEON_PP_TXOFFSET_0) / 24; 1636 1.1 riastrad r = radeon_cs_packet_next_reloc(p, &reloc, 0); 1637 1.1 riastrad if (r) { 1638 1.1 riastrad DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1639 1.1 riastrad idx, reg); 1640 1.1 riastrad radeon_cs_dump_packet(p, pkt); 1641 1.1 riastrad return r; 1642 1.1 riastrad } 1643 1.1 riastrad if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) { 1644 1.1 riastrad if (reloc->tiling_flags & RADEON_TILING_MACRO) 1645 1.1 riastrad tile_flags |= RADEON_TXO_MACRO_TILE; 1646 1.1 riastrad if (reloc->tiling_flags & RADEON_TILING_MICRO) 1647 1.1 riastrad tile_flags |= RADEON_TXO_MICRO_TILE_X2; 1648 1.1 riastrad 1649 1.1 riastrad tmp = idx_value & ~(0x7 << 2); 1650 1.1 riastrad tmp |= tile_flags; 1651 1.1 riastrad ib[idx] = tmp + ((u32)reloc->gpu_offset); 1652 1.1 riastrad } else 1653 1.1 riastrad ib[idx] = idx_value + ((u32)reloc->gpu_offset); 1654 1.1 riastrad track->textures[i].robj = reloc->robj; 1655 1.1 riastrad track->tex_dirty = true; 1656 1.1 riastrad break; 1657 1.1 riastrad case RADEON_PP_CUBIC_OFFSET_T0_0: 1658 1.1 riastrad case RADEON_PP_CUBIC_OFFSET_T0_1: 1659 1.1 riastrad case RADEON_PP_CUBIC_OFFSET_T0_2: 1660 1.1 riastrad case RADEON_PP_CUBIC_OFFSET_T0_3: 1661 1.1 riastrad case RADEON_PP_CUBIC_OFFSET_T0_4: 1662 1.1 riastrad i = (reg - RADEON_PP_CUBIC_OFFSET_T0_0) / 4; 1663 1.1 riastrad r = radeon_cs_packet_next_reloc(p, &reloc, 0); 1664 1.1 riastrad if (r) { 1665 1.1 riastrad DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1666 1.1 riastrad idx, reg); 1667 1.1 riastrad radeon_cs_dump_packet(p, pkt); 1668 1.1 riastrad return r; 1669 1.1 riastrad } 1670 1.1 riastrad track->textures[0].cube_info[i].offset = idx_value; 1671 1.1 riastrad ib[idx] = idx_value + ((u32)reloc->gpu_offset); 1672 1.1 riastrad track->textures[0].cube_info[i].robj = reloc->robj; 1673 1.1 riastrad track->tex_dirty = true; 1674 1.1 riastrad break; 1675 1.1 riastrad case RADEON_PP_CUBIC_OFFSET_T1_0: 1676 1.1 riastrad case RADEON_PP_CUBIC_OFFSET_T1_1: 1677 1.1 riastrad case RADEON_PP_CUBIC_OFFSET_T1_2: 1678 1.1 riastrad case RADEON_PP_CUBIC_OFFSET_T1_3: 1679 1.1 riastrad case RADEON_PP_CUBIC_OFFSET_T1_4: 1680 1.1 riastrad i = (reg - RADEON_PP_CUBIC_OFFSET_T1_0) / 4; 1681 1.1 riastrad r = radeon_cs_packet_next_reloc(p, &reloc, 0); 1682 1.1 riastrad if (r) { 1683 1.1 riastrad DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1684 1.1 riastrad idx, reg); 1685 1.1 riastrad radeon_cs_dump_packet(p, pkt); 1686 1.1 riastrad return r; 1687 1.1 riastrad } 1688 1.1 riastrad track->textures[1].cube_info[i].offset = idx_value; 1689 1.1 riastrad ib[idx] = idx_value + ((u32)reloc->gpu_offset); 1690 1.1 riastrad track->textures[1].cube_info[i].robj = reloc->robj; 1691 1.1 riastrad track->tex_dirty = true; 1692 1.1 riastrad break; 1693 1.1 riastrad case RADEON_PP_CUBIC_OFFSET_T2_0: 1694 1.1 riastrad case RADEON_PP_CUBIC_OFFSET_T2_1: 1695 1.1 riastrad case RADEON_PP_CUBIC_OFFSET_T2_2: 1696 1.1 riastrad case RADEON_PP_CUBIC_OFFSET_T2_3: 1697 1.1 riastrad case RADEON_PP_CUBIC_OFFSET_T2_4: 1698 1.1 riastrad i = (reg - RADEON_PP_CUBIC_OFFSET_T2_0) / 4; 1699 1.1 riastrad r = radeon_cs_packet_next_reloc(p, &reloc, 0); 1700 1.1 riastrad if (r) { 1701 1.1 riastrad DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1702 1.1 riastrad idx, reg); 1703 1.1 riastrad radeon_cs_dump_packet(p, pkt); 1704 1.1 riastrad return r; 1705 1.1 riastrad } 1706 1.1 riastrad track->textures[2].cube_info[i].offset = idx_value; 1707 1.1 riastrad ib[idx] = idx_value + ((u32)reloc->gpu_offset); 1708 1.1 riastrad track->textures[2].cube_info[i].robj = reloc->robj; 1709 1.1 riastrad track->tex_dirty = true; 1710 1.1 riastrad break; 1711 1.1 riastrad case RADEON_RE_WIDTH_HEIGHT: 1712 1.1 riastrad track->maxy = ((idx_value >> 16) & 0x7FF); 1713 1.1 riastrad track->cb_dirty = true; 1714 1.1 riastrad track->zb_dirty = true; 1715 1.1 riastrad break; 1716 1.1 riastrad case RADEON_RB3D_COLORPITCH: 1717 1.1 riastrad r = radeon_cs_packet_next_reloc(p, &reloc, 0); 1718 1.1 riastrad if (r) { 1719 1.1 riastrad DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1720 1.1 riastrad idx, reg); 1721 1.1 riastrad radeon_cs_dump_packet(p, pkt); 1722 1.1 riastrad return r; 1723 1.1 riastrad } 1724 1.1 riastrad if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) { 1725 1.1 riastrad if (reloc->tiling_flags & RADEON_TILING_MACRO) 1726 1.1 riastrad tile_flags |= RADEON_COLOR_TILE_ENABLE; 1727 1.1 riastrad if (reloc->tiling_flags & RADEON_TILING_MICRO) 1728 1.1 riastrad tile_flags |= RADEON_COLOR_MICROTILE_ENABLE; 1729 1.1 riastrad 1730 1.1 riastrad tmp = idx_value & ~(0x7 << 16); 1731 1.1 riastrad tmp |= tile_flags; 1732 1.1 riastrad ib[idx] = tmp; 1733 1.1 riastrad } else 1734 1.1 riastrad ib[idx] = idx_value; 1735 1.1 riastrad 1736 1.1 riastrad track->cb[0].pitch = idx_value & RADEON_COLORPITCH_MASK; 1737 1.1 riastrad track->cb_dirty = true; 1738 1.1 riastrad break; 1739 1.1 riastrad case RADEON_RB3D_DEPTHPITCH: 1740 1.1 riastrad track->zb.pitch = idx_value & RADEON_DEPTHPITCH_MASK; 1741 1.1 riastrad track->zb_dirty = true; 1742 1.1 riastrad break; 1743 1.1 riastrad case RADEON_RB3D_CNTL: 1744 1.1 riastrad switch ((idx_value >> RADEON_RB3D_COLOR_FORMAT_SHIFT) & 0x1f) { 1745 1.1 riastrad case 7: 1746 1.1 riastrad case 8: 1747 1.1 riastrad case 9: 1748 1.1 riastrad case 11: 1749 1.1 riastrad case 12: 1750 1.1 riastrad track->cb[0].cpp = 1; 1751 1.1 riastrad break; 1752 1.1 riastrad case 3: 1753 1.1 riastrad case 4: 1754 1.1 riastrad case 15: 1755 1.1 riastrad track->cb[0].cpp = 2; 1756 1.1 riastrad break; 1757 1.1 riastrad case 6: 1758 1.1 riastrad track->cb[0].cpp = 4; 1759 1.1 riastrad break; 1760 1.1 riastrad default: 1761 1.1 riastrad DRM_ERROR("Invalid color buffer format (%d) !\n", 1762 1.1 riastrad ((idx_value >> RADEON_RB3D_COLOR_FORMAT_SHIFT) & 0x1f)); 1763 1.1 riastrad return -EINVAL; 1764 1.1 riastrad } 1765 1.1 riastrad track->z_enabled = !!(idx_value & RADEON_Z_ENABLE); 1766 1.1 riastrad track->cb_dirty = true; 1767 1.1 riastrad track->zb_dirty = true; 1768 1.1 riastrad break; 1769 1.1 riastrad case RADEON_RB3D_ZSTENCILCNTL: 1770 1.1 riastrad switch (idx_value & 0xf) { 1771 1.1 riastrad case 0: 1772 1.1 riastrad track->zb.cpp = 2; 1773 1.1 riastrad break; 1774 1.1 riastrad case 2: 1775 1.1 riastrad case 3: 1776 1.1 riastrad case 4: 1777 1.1 riastrad case 5: 1778 1.1 riastrad case 9: 1779 1.1 riastrad case 11: 1780 1.1 riastrad track->zb.cpp = 4; 1781 1.1 riastrad break; 1782 1.1 riastrad default: 1783 1.1 riastrad break; 1784 1.1 riastrad } 1785 1.1 riastrad track->zb_dirty = true; 1786 1.1 riastrad break; 1787 1.1 riastrad case RADEON_RB3D_ZPASS_ADDR: 1788 1.1 riastrad r = radeon_cs_packet_next_reloc(p, &reloc, 0); 1789 1.1 riastrad if (r) { 1790 1.1 riastrad DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 1791 1.1 riastrad idx, reg); 1792 1.1 riastrad radeon_cs_dump_packet(p, pkt); 1793 1.1 riastrad return r; 1794 1.1 riastrad } 1795 1.1 riastrad ib[idx] = idx_value + ((u32)reloc->gpu_offset); 1796 1.1 riastrad break; 1797 1.1 riastrad case RADEON_PP_CNTL: 1798 1.1 riastrad { 1799 1.1 riastrad uint32_t temp = idx_value >> 4; 1800 1.1 riastrad for (i = 0; i < track->num_texture; i++) 1801 1.1 riastrad track->textures[i].enabled = !!(temp & (1 << i)); 1802 1.1 riastrad track->tex_dirty = true; 1803 1.1 riastrad } 1804 1.1 riastrad break; 1805 1.1 riastrad case RADEON_SE_VF_CNTL: 1806 1.1 riastrad track->vap_vf_cntl = idx_value; 1807 1.1 riastrad break; 1808 1.1 riastrad case RADEON_SE_VTX_FMT: 1809 1.1 riastrad track->vtx_size = r100_get_vtx_size(idx_value); 1810 1.1 riastrad break; 1811 1.1 riastrad case RADEON_PP_TEX_SIZE_0: 1812 1.1 riastrad case RADEON_PP_TEX_SIZE_1: 1813 1.1 riastrad case RADEON_PP_TEX_SIZE_2: 1814 1.1 riastrad i = (reg - RADEON_PP_TEX_SIZE_0) / 8; 1815 1.1 riastrad track->textures[i].width = (idx_value & RADEON_TEX_USIZE_MASK) + 1; 1816 1.1 riastrad track->textures[i].height = ((idx_value & RADEON_TEX_VSIZE_MASK) >> RADEON_TEX_VSIZE_SHIFT) + 1; 1817 1.1 riastrad track->tex_dirty = true; 1818 1.1 riastrad break; 1819 1.1 riastrad case RADEON_PP_TEX_PITCH_0: 1820 1.1 riastrad case RADEON_PP_TEX_PITCH_1: 1821 1.1 riastrad case RADEON_PP_TEX_PITCH_2: 1822 1.1 riastrad i = (reg - RADEON_PP_TEX_PITCH_0) / 8; 1823 1.1 riastrad track->textures[i].pitch = idx_value + 32; 1824 1.1 riastrad track->tex_dirty = true; 1825 1.1 riastrad break; 1826 1.1 riastrad case RADEON_PP_TXFILTER_0: 1827 1.1 riastrad case RADEON_PP_TXFILTER_1: 1828 1.1 riastrad case RADEON_PP_TXFILTER_2: 1829 1.1 riastrad i = (reg - RADEON_PP_TXFILTER_0) / 24; 1830 1.1 riastrad track->textures[i].num_levels = ((idx_value & RADEON_MAX_MIP_LEVEL_MASK) 1831 1.1 riastrad >> RADEON_MAX_MIP_LEVEL_SHIFT); 1832 1.1 riastrad tmp = (idx_value >> 23) & 0x7; 1833 1.1 riastrad if (tmp == 2 || tmp == 6) 1834 1.1 riastrad track->textures[i].roundup_w = false; 1835 1.1 riastrad tmp = (idx_value >> 27) & 0x7; 1836 1.1 riastrad if (tmp == 2 || tmp == 6) 1837 1.1 riastrad track->textures[i].roundup_h = false; 1838 1.1 riastrad track->tex_dirty = true; 1839 1.1 riastrad break; 1840 1.1 riastrad case RADEON_PP_TXFORMAT_0: 1841 1.1 riastrad case RADEON_PP_TXFORMAT_1: 1842 1.1 riastrad case RADEON_PP_TXFORMAT_2: 1843 1.1 riastrad i = (reg - RADEON_PP_TXFORMAT_0) / 24; 1844 1.1 riastrad if (idx_value & RADEON_TXFORMAT_NON_POWER2) { 1845 1.2 riastrad track->textures[i].use_pitch = true; 1846 1.1 riastrad } else { 1847 1.2 riastrad track->textures[i].use_pitch = false; 1848 1.2 riastrad track->textures[i].width = 1 << ((idx_value & RADEON_TXFORMAT_WIDTH_MASK) >> RADEON_TXFORMAT_WIDTH_SHIFT); 1849 1.2 riastrad track->textures[i].height = 1 << ((idx_value & RADEON_TXFORMAT_HEIGHT_MASK) >> RADEON_TXFORMAT_HEIGHT_SHIFT); 1850 1.1 riastrad } 1851 1.1 riastrad if (idx_value & RADEON_TXFORMAT_CUBIC_MAP_ENABLE) 1852 1.1 riastrad track->textures[i].tex_coord_type = 2; 1853 1.1 riastrad switch ((idx_value & RADEON_TXFORMAT_FORMAT_MASK)) { 1854 1.1 riastrad case RADEON_TXFORMAT_I8: 1855 1.1 riastrad case RADEON_TXFORMAT_RGB332: 1856 1.1 riastrad case RADEON_TXFORMAT_Y8: 1857 1.1 riastrad track->textures[i].cpp = 1; 1858 1.1 riastrad track->textures[i].compress_format = R100_TRACK_COMP_NONE; 1859 1.1 riastrad break; 1860 1.1 riastrad case RADEON_TXFORMAT_AI88: 1861 1.1 riastrad case RADEON_TXFORMAT_ARGB1555: 1862 1.1 riastrad case RADEON_TXFORMAT_RGB565: 1863 1.1 riastrad case RADEON_TXFORMAT_ARGB4444: 1864 1.1 riastrad case RADEON_TXFORMAT_VYUY422: 1865 1.1 riastrad case RADEON_TXFORMAT_YVYU422: 1866 1.1 riastrad case RADEON_TXFORMAT_SHADOW16: 1867 1.1 riastrad case RADEON_TXFORMAT_LDUDV655: 1868 1.1 riastrad case RADEON_TXFORMAT_DUDV88: 1869 1.1 riastrad track->textures[i].cpp = 2; 1870 1.1 riastrad track->textures[i].compress_format = R100_TRACK_COMP_NONE; 1871 1.1 riastrad break; 1872 1.1 riastrad case RADEON_TXFORMAT_ARGB8888: 1873 1.1 riastrad case RADEON_TXFORMAT_RGBA8888: 1874 1.1 riastrad case RADEON_TXFORMAT_SHADOW32: 1875 1.1 riastrad case RADEON_TXFORMAT_LDUDUV8888: 1876 1.1 riastrad track->textures[i].cpp = 4; 1877 1.1 riastrad track->textures[i].compress_format = R100_TRACK_COMP_NONE; 1878 1.1 riastrad break; 1879 1.1 riastrad case RADEON_TXFORMAT_DXT1: 1880 1.1 riastrad track->textures[i].cpp = 1; 1881 1.1 riastrad track->textures[i].compress_format = R100_TRACK_COMP_DXT1; 1882 1.1 riastrad break; 1883 1.1 riastrad case RADEON_TXFORMAT_DXT23: 1884 1.1 riastrad case RADEON_TXFORMAT_DXT45: 1885 1.1 riastrad track->textures[i].cpp = 1; 1886 1.1 riastrad track->textures[i].compress_format = R100_TRACK_COMP_DXT35; 1887 1.1 riastrad break; 1888 1.1 riastrad } 1889 1.1 riastrad track->textures[i].cube_info[4].width = 1 << ((idx_value >> 16) & 0xf); 1890 1.1 riastrad track->textures[i].cube_info[4].height = 1 << ((idx_value >> 20) & 0xf); 1891 1.1 riastrad track->tex_dirty = true; 1892 1.1 riastrad break; 1893 1.1 riastrad case RADEON_PP_CUBIC_FACES_0: 1894 1.1 riastrad case RADEON_PP_CUBIC_FACES_1: 1895 1.1 riastrad case RADEON_PP_CUBIC_FACES_2: 1896 1.1 riastrad tmp = idx_value; 1897 1.1 riastrad i = (reg - RADEON_PP_CUBIC_FACES_0) / 4; 1898 1.1 riastrad for (face = 0; face < 4; face++) { 1899 1.1 riastrad track->textures[i].cube_info[face].width = 1 << ((tmp >> (face * 8)) & 0xf); 1900 1.1 riastrad track->textures[i].cube_info[face].height = 1 << ((tmp >> ((face * 8) + 4)) & 0xf); 1901 1.1 riastrad } 1902 1.1 riastrad track->tex_dirty = true; 1903 1.1 riastrad break; 1904 1.1 riastrad default: 1905 1.2 riastrad pr_err("Forbidden register 0x%04X in cs at %d\n", reg, idx); 1906 1.1 riastrad return -EINVAL; 1907 1.1 riastrad } 1908 1.1 riastrad return 0; 1909 1.1 riastrad } 1910 1.1 riastrad 1911 1.1 riastrad int r100_cs_track_check_pkt3_indx_buffer(struct radeon_cs_parser *p, 1912 1.1 riastrad struct radeon_cs_packet *pkt, 1913 1.1 riastrad struct radeon_bo *robj) 1914 1.1 riastrad { 1915 1.1 riastrad unsigned idx; 1916 1.1 riastrad u32 value; 1917 1.1 riastrad idx = pkt->idx + 1; 1918 1.1 riastrad value = radeon_get_ib_value(p, idx + 2); 1919 1.1 riastrad if ((value + 1) > radeon_bo_size(robj)) { 1920 1.1 riastrad DRM_ERROR("[drm] Buffer too small for PACKET3 INDX_BUFFER " 1921 1.1 riastrad "(need %u have %lu) !\n", 1922 1.1 riastrad value + 1, 1923 1.1 riastrad radeon_bo_size(robj)); 1924 1.1 riastrad return -EINVAL; 1925 1.1 riastrad } 1926 1.1 riastrad return 0; 1927 1.1 riastrad } 1928 1.1 riastrad 1929 1.1 riastrad static int r100_packet3_check(struct radeon_cs_parser *p, 1930 1.1 riastrad struct radeon_cs_packet *pkt) 1931 1.1 riastrad { 1932 1.1 riastrad struct radeon_bo_list *reloc; 1933 1.1 riastrad struct r100_cs_track *track; 1934 1.1 riastrad unsigned idx; 1935 1.1 riastrad volatile uint32_t *ib; 1936 1.1 riastrad int r; 1937 1.1 riastrad 1938 1.1 riastrad ib = p->ib.ptr; 1939 1.1 riastrad idx = pkt->idx + 1; 1940 1.1 riastrad track = (struct r100_cs_track *)p->track; 1941 1.1 riastrad switch (pkt->opcode) { 1942 1.1 riastrad case PACKET3_3D_LOAD_VBPNTR: 1943 1.1 riastrad r = r100_packet3_load_vbpntr(p, pkt, idx); 1944 1.1 riastrad if (r) 1945 1.1 riastrad return r; 1946 1.1 riastrad break; 1947 1.1 riastrad case PACKET3_INDX_BUFFER: 1948 1.1 riastrad r = radeon_cs_packet_next_reloc(p, &reloc, 0); 1949 1.1 riastrad if (r) { 1950 1.1 riastrad DRM_ERROR("No reloc for packet3 %d\n", pkt->opcode); 1951 1.1 riastrad radeon_cs_dump_packet(p, pkt); 1952 1.1 riastrad return r; 1953 1.1 riastrad } 1954 1.1 riastrad ib[idx+1] = radeon_get_ib_value(p, idx+1) + ((u32)reloc->gpu_offset); 1955 1.1 riastrad r = r100_cs_track_check_pkt3_indx_buffer(p, pkt, reloc->robj); 1956 1.1 riastrad if (r) { 1957 1.1 riastrad return r; 1958 1.1 riastrad } 1959 1.1 riastrad break; 1960 1.1 riastrad case 0x23: 1961 1.1 riastrad /* 3D_RNDR_GEN_INDX_PRIM on r100/r200 */ 1962 1.1 riastrad r = radeon_cs_packet_next_reloc(p, &reloc, 0); 1963 1.1 riastrad if (r) { 1964 1.1 riastrad DRM_ERROR("No reloc for packet3 %d\n", pkt->opcode); 1965 1.1 riastrad radeon_cs_dump_packet(p, pkt); 1966 1.1 riastrad return r; 1967 1.1 riastrad } 1968 1.1 riastrad ib[idx] = radeon_get_ib_value(p, idx) + ((u32)reloc->gpu_offset); 1969 1.1 riastrad track->num_arrays = 1; 1970 1.1 riastrad track->vtx_size = r100_get_vtx_size(radeon_get_ib_value(p, idx + 2)); 1971 1.1 riastrad 1972 1.1 riastrad track->arrays[0].robj = reloc->robj; 1973 1.1 riastrad track->arrays[0].esize = track->vtx_size; 1974 1.1 riastrad 1975 1.1 riastrad track->max_indx = radeon_get_ib_value(p, idx+1); 1976 1.1 riastrad 1977 1.1 riastrad track->vap_vf_cntl = radeon_get_ib_value(p, idx+3); 1978 1.1 riastrad track->immd_dwords = pkt->count - 1; 1979 1.1 riastrad r = r100_cs_track_check(p->rdev, track); 1980 1.1 riastrad if (r) 1981 1.1 riastrad return r; 1982 1.1 riastrad break; 1983 1.1 riastrad case PACKET3_3D_DRAW_IMMD: 1984 1.1 riastrad if (((radeon_get_ib_value(p, idx + 1) >> 4) & 0x3) != 3) { 1985 1.1 riastrad DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n"); 1986 1.1 riastrad return -EINVAL; 1987 1.1 riastrad } 1988 1.1 riastrad track->vtx_size = r100_get_vtx_size(radeon_get_ib_value(p, idx + 0)); 1989 1.1 riastrad track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1); 1990 1.1 riastrad track->immd_dwords = pkt->count - 1; 1991 1.1 riastrad r = r100_cs_track_check(p->rdev, track); 1992 1.1 riastrad if (r) 1993 1.1 riastrad return r; 1994 1.1 riastrad break; 1995 1.1 riastrad /* triggers drawing using in-packet vertex data */ 1996 1.1 riastrad case PACKET3_3D_DRAW_IMMD_2: 1997 1.1 riastrad if (((radeon_get_ib_value(p, idx) >> 4) & 0x3) != 3) { 1998 1.1 riastrad DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n"); 1999 1.1 riastrad return -EINVAL; 2000 1.1 riastrad } 2001 1.1 riastrad track->vap_vf_cntl = radeon_get_ib_value(p, idx); 2002 1.1 riastrad track->immd_dwords = pkt->count; 2003 1.1 riastrad r = r100_cs_track_check(p->rdev, track); 2004 1.1 riastrad if (r) 2005 1.1 riastrad return r; 2006 1.1 riastrad break; 2007 1.1 riastrad /* triggers drawing using in-packet vertex data */ 2008 1.1 riastrad case PACKET3_3D_DRAW_VBUF_2: 2009 1.1 riastrad track->vap_vf_cntl = radeon_get_ib_value(p, idx); 2010 1.1 riastrad r = r100_cs_track_check(p->rdev, track); 2011 1.1 riastrad if (r) 2012 1.1 riastrad return r; 2013 1.1 riastrad break; 2014 1.1 riastrad /* triggers drawing of vertex buffers setup elsewhere */ 2015 1.1 riastrad case PACKET3_3D_DRAW_INDX_2: 2016 1.1 riastrad track->vap_vf_cntl = radeon_get_ib_value(p, idx); 2017 1.1 riastrad r = r100_cs_track_check(p->rdev, track); 2018 1.1 riastrad if (r) 2019 1.1 riastrad return r; 2020 1.1 riastrad break; 2021 1.1 riastrad /* triggers drawing using indices to vertex buffer */ 2022 1.1 riastrad case PACKET3_3D_DRAW_VBUF: 2023 1.1 riastrad track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1); 2024 1.1 riastrad r = r100_cs_track_check(p->rdev, track); 2025 1.1 riastrad if (r) 2026 1.1 riastrad return r; 2027 1.1 riastrad break; 2028 1.1 riastrad /* triggers drawing of vertex buffers setup elsewhere */ 2029 1.1 riastrad case PACKET3_3D_DRAW_INDX: 2030 1.1 riastrad track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1); 2031 1.1 riastrad r = r100_cs_track_check(p->rdev, track); 2032 1.1 riastrad if (r) 2033 1.1 riastrad return r; 2034 1.1 riastrad break; 2035 1.1 riastrad /* triggers drawing using indices to vertex buffer */ 2036 1.1 riastrad case PACKET3_3D_CLEAR_HIZ: 2037 1.1 riastrad case PACKET3_3D_CLEAR_ZMASK: 2038 1.1 riastrad if (p->rdev->hyperz_filp != p->filp) 2039 1.1 riastrad return -EINVAL; 2040 1.1 riastrad break; 2041 1.1 riastrad case PACKET3_NOP: 2042 1.1 riastrad break; 2043 1.1 riastrad default: 2044 1.1 riastrad DRM_ERROR("Packet3 opcode %x not supported\n", pkt->opcode); 2045 1.1 riastrad return -EINVAL; 2046 1.1 riastrad } 2047 1.1 riastrad return 0; 2048 1.1 riastrad } 2049 1.1 riastrad 2050 1.1 riastrad int r100_cs_parse(struct radeon_cs_parser *p) 2051 1.1 riastrad { 2052 1.1 riastrad struct radeon_cs_packet pkt; 2053 1.1 riastrad struct r100_cs_track *track; 2054 1.1 riastrad int r; 2055 1.1 riastrad 2056 1.1 riastrad track = kzalloc(sizeof(*track), GFP_KERNEL); 2057 1.1 riastrad if (!track) 2058 1.1 riastrad return -ENOMEM; 2059 1.1 riastrad r100_cs_track_clear(p->rdev, track); 2060 1.1 riastrad p->track = track; 2061 1.1 riastrad do { 2062 1.1 riastrad r = radeon_cs_packet_parse(p, &pkt, p->idx); 2063 1.1 riastrad if (r) { 2064 1.1 riastrad return r; 2065 1.1 riastrad } 2066 1.1 riastrad p->idx += pkt.count + 2; 2067 1.1 riastrad switch (pkt.type) { 2068 1.1 riastrad case RADEON_PACKET_TYPE0: 2069 1.1 riastrad if (p->rdev->family >= CHIP_R200) 2070 1.1 riastrad r = r100_cs_parse_packet0(p, &pkt, 2071 1.1 riastrad p->rdev->config.r100.reg_safe_bm, 2072 1.1 riastrad p->rdev->config.r100.reg_safe_bm_size, 2073 1.1 riastrad &r200_packet0_check); 2074 1.1 riastrad else 2075 1.1 riastrad r = r100_cs_parse_packet0(p, &pkt, 2076 1.1 riastrad p->rdev->config.r100.reg_safe_bm, 2077 1.1 riastrad p->rdev->config.r100.reg_safe_bm_size, 2078 1.1 riastrad &r100_packet0_check); 2079 1.1 riastrad break; 2080 1.1 riastrad case RADEON_PACKET_TYPE2: 2081 1.1 riastrad break; 2082 1.1 riastrad case RADEON_PACKET_TYPE3: 2083 1.1 riastrad r = r100_packet3_check(p, &pkt); 2084 1.1 riastrad break; 2085 1.1 riastrad default: 2086 1.1 riastrad DRM_ERROR("Unknown packet type %d !\n", 2087 1.1 riastrad pkt.type); 2088 1.1 riastrad return -EINVAL; 2089 1.1 riastrad } 2090 1.1 riastrad if (r) 2091 1.1 riastrad return r; 2092 1.1 riastrad } while (p->idx < p->chunk_ib->length_dw); 2093 1.1 riastrad return 0; 2094 1.1 riastrad } 2095 1.1 riastrad 2096 1.1 riastrad static void r100_cs_track_texture_print(struct r100_cs_track_texture *t) 2097 1.1 riastrad { 2098 1.1 riastrad DRM_ERROR("pitch %d\n", t->pitch); 2099 1.1 riastrad DRM_ERROR("use_pitch %d\n", t->use_pitch); 2100 1.1 riastrad DRM_ERROR("width %d\n", t->width); 2101 1.1 riastrad DRM_ERROR("width_11 %d\n", t->width_11); 2102 1.1 riastrad DRM_ERROR("height %d\n", t->height); 2103 1.1 riastrad DRM_ERROR("height_11 %d\n", t->height_11); 2104 1.1 riastrad DRM_ERROR("num levels %d\n", t->num_levels); 2105 1.1 riastrad DRM_ERROR("depth %d\n", t->txdepth); 2106 1.1 riastrad DRM_ERROR("bpp %d\n", t->cpp); 2107 1.1 riastrad DRM_ERROR("coordinate type %d\n", t->tex_coord_type); 2108 1.1 riastrad DRM_ERROR("width round to power of 2 %d\n", t->roundup_w); 2109 1.1 riastrad DRM_ERROR("height round to power of 2 %d\n", t->roundup_h); 2110 1.1 riastrad DRM_ERROR("compress format %d\n", t->compress_format); 2111 1.1 riastrad } 2112 1.1 riastrad 2113 1.1 riastrad static int r100_track_compress_size(int compress_format, int w, int h) 2114 1.1 riastrad { 2115 1.1 riastrad int block_width, block_height, block_bytes; 2116 1.1 riastrad int wblocks, hblocks; 2117 1.1 riastrad int min_wblocks; 2118 1.1 riastrad int sz; 2119 1.1 riastrad 2120 1.1 riastrad block_width = 4; 2121 1.1 riastrad block_height = 4; 2122 1.1 riastrad 2123 1.1 riastrad switch (compress_format) { 2124 1.1 riastrad case R100_TRACK_COMP_DXT1: 2125 1.1 riastrad block_bytes = 8; 2126 1.1 riastrad min_wblocks = 4; 2127 1.1 riastrad break; 2128 1.1 riastrad default: 2129 1.1 riastrad case R100_TRACK_COMP_DXT35: 2130 1.1 riastrad block_bytes = 16; 2131 1.1 riastrad min_wblocks = 2; 2132 1.1 riastrad break; 2133 1.1 riastrad } 2134 1.1 riastrad 2135 1.1 riastrad hblocks = (h + block_height - 1) / block_height; 2136 1.1 riastrad wblocks = (w + block_width - 1) / block_width; 2137 1.1 riastrad if (wblocks < min_wblocks) 2138 1.1 riastrad wblocks = min_wblocks; 2139 1.1 riastrad sz = wblocks * hblocks * block_bytes; 2140 1.1 riastrad return sz; 2141 1.1 riastrad } 2142 1.1 riastrad 2143 1.1 riastrad static int r100_cs_track_cube(struct radeon_device *rdev, 2144 1.1 riastrad struct r100_cs_track *track, unsigned idx) 2145 1.1 riastrad { 2146 1.1 riastrad unsigned face, w, h; 2147 1.1 riastrad struct radeon_bo *cube_robj; 2148 1.1 riastrad unsigned long size; 2149 1.1 riastrad unsigned compress_format = track->textures[idx].compress_format; 2150 1.1 riastrad 2151 1.1 riastrad for (face = 0; face < 5; face++) { 2152 1.1 riastrad cube_robj = track->textures[idx].cube_info[face].robj; 2153 1.1 riastrad w = track->textures[idx].cube_info[face].width; 2154 1.1 riastrad h = track->textures[idx].cube_info[face].height; 2155 1.1 riastrad 2156 1.1 riastrad if (compress_format) { 2157 1.1 riastrad size = r100_track_compress_size(compress_format, w, h); 2158 1.1 riastrad } else 2159 1.1 riastrad size = w * h; 2160 1.1 riastrad size *= track->textures[idx].cpp; 2161 1.1 riastrad 2162 1.1 riastrad size += track->textures[idx].cube_info[face].offset; 2163 1.1 riastrad 2164 1.1 riastrad if (size > radeon_bo_size(cube_robj)) { 2165 1.1 riastrad DRM_ERROR("Cube texture offset greater than object size %lu %lu\n", 2166 1.1 riastrad size, radeon_bo_size(cube_robj)); 2167 1.1 riastrad r100_cs_track_texture_print(&track->textures[idx]); 2168 1.1 riastrad return -1; 2169 1.1 riastrad } 2170 1.1 riastrad } 2171 1.1 riastrad return 0; 2172 1.1 riastrad } 2173 1.1 riastrad 2174 1.1 riastrad static int r100_cs_track_texture_check(struct radeon_device *rdev, 2175 1.1 riastrad struct r100_cs_track *track) 2176 1.1 riastrad { 2177 1.1 riastrad struct radeon_bo *robj; 2178 1.1 riastrad unsigned long size; 2179 1.1 riastrad unsigned u, i, w, h, d; 2180 1.1 riastrad int ret; 2181 1.1 riastrad 2182 1.1 riastrad for (u = 0; u < track->num_texture; u++) { 2183 1.1 riastrad if (!track->textures[u].enabled) 2184 1.1 riastrad continue; 2185 1.1 riastrad if (track->textures[u].lookup_disable) 2186 1.1 riastrad continue; 2187 1.1 riastrad robj = track->textures[u].robj; 2188 1.1 riastrad if (robj == NULL) { 2189 1.1 riastrad DRM_ERROR("No texture bound to unit %u\n", u); 2190 1.1 riastrad return -EINVAL; 2191 1.1 riastrad } 2192 1.1 riastrad size = 0; 2193 1.1 riastrad for (i = 0; i <= track->textures[u].num_levels; i++) { 2194 1.1 riastrad if (track->textures[u].use_pitch) { 2195 1.1 riastrad if (rdev->family < CHIP_R300) 2196 1.1 riastrad w = (track->textures[u].pitch / track->textures[u].cpp) / (1 << i); 2197 1.1 riastrad else 2198 1.1 riastrad w = track->textures[u].pitch / (1 << i); 2199 1.1 riastrad } else { 2200 1.1 riastrad w = track->textures[u].width; 2201 1.1 riastrad if (rdev->family >= CHIP_RV515) 2202 1.1 riastrad w |= track->textures[u].width_11; 2203 1.1 riastrad w = w / (1 << i); 2204 1.1 riastrad if (track->textures[u].roundup_w) 2205 1.1 riastrad w = roundup_pow_of_two(w); 2206 1.1 riastrad } 2207 1.1 riastrad h = track->textures[u].height; 2208 1.1 riastrad if (rdev->family >= CHIP_RV515) 2209 1.1 riastrad h |= track->textures[u].height_11; 2210 1.1 riastrad h = h / (1 << i); 2211 1.1 riastrad if (track->textures[u].roundup_h) 2212 1.1 riastrad h = roundup_pow_of_two(h); 2213 1.1 riastrad if (track->textures[u].tex_coord_type == 1) { 2214 1.1 riastrad d = (1 << track->textures[u].txdepth) / (1 << i); 2215 1.1 riastrad if (!d) 2216 1.1 riastrad d = 1; 2217 1.1 riastrad } else { 2218 1.1 riastrad d = 1; 2219 1.1 riastrad } 2220 1.1 riastrad if (track->textures[u].compress_format) { 2221 1.1 riastrad 2222 1.1 riastrad size += r100_track_compress_size(track->textures[u].compress_format, w, h) * d; 2223 1.1 riastrad /* compressed textures are block based */ 2224 1.1 riastrad } else 2225 1.1 riastrad size += w * h * d; 2226 1.1 riastrad } 2227 1.1 riastrad size *= track->textures[u].cpp; 2228 1.1 riastrad 2229 1.1 riastrad switch (track->textures[u].tex_coord_type) { 2230 1.1 riastrad case 0: 2231 1.1 riastrad case 1: 2232 1.1 riastrad break; 2233 1.1 riastrad case 2: 2234 1.1 riastrad if (track->separate_cube) { 2235 1.1 riastrad ret = r100_cs_track_cube(rdev, track, u); 2236 1.1 riastrad if (ret) 2237 1.1 riastrad return ret; 2238 1.1 riastrad } else 2239 1.1 riastrad size *= 6; 2240 1.1 riastrad break; 2241 1.1 riastrad default: 2242 1.1 riastrad DRM_ERROR("Invalid texture coordinate type %u for unit " 2243 1.1 riastrad "%u\n", track->textures[u].tex_coord_type, u); 2244 1.1 riastrad return -EINVAL; 2245 1.1 riastrad } 2246 1.1 riastrad if (size > radeon_bo_size(robj)) { 2247 1.1 riastrad DRM_ERROR("Texture of unit %u needs %lu bytes but is " 2248 1.1 riastrad "%lu\n", u, size, radeon_bo_size(robj)); 2249 1.1 riastrad r100_cs_track_texture_print(&track->textures[u]); 2250 1.1 riastrad return -EINVAL; 2251 1.1 riastrad } 2252 1.1 riastrad } 2253 1.1 riastrad return 0; 2254 1.1 riastrad } 2255 1.1 riastrad 2256 1.1 riastrad int r100_cs_track_check(struct radeon_device *rdev, struct r100_cs_track *track) 2257 1.1 riastrad { 2258 1.1 riastrad unsigned i; 2259 1.1 riastrad unsigned long size; 2260 1.1 riastrad unsigned prim_walk; 2261 1.1 riastrad unsigned nverts; 2262 1.1 riastrad unsigned num_cb = track->cb_dirty ? track->num_cb : 0; 2263 1.1 riastrad 2264 1.1 riastrad if (num_cb && !track->zb_cb_clear && !track->color_channel_mask && 2265 1.1 riastrad !track->blend_read_enable) 2266 1.1 riastrad num_cb = 0; 2267 1.1 riastrad 2268 1.1 riastrad for (i = 0; i < num_cb; i++) { 2269 1.1 riastrad if (track->cb[i].robj == NULL) { 2270 1.1 riastrad DRM_ERROR("[drm] No buffer for color buffer %d !\n", i); 2271 1.1 riastrad return -EINVAL; 2272 1.1 riastrad } 2273 1.1 riastrad size = track->cb[i].pitch * track->cb[i].cpp * track->maxy; 2274 1.1 riastrad size += track->cb[i].offset; 2275 1.1 riastrad if (size > radeon_bo_size(track->cb[i].robj)) { 2276 1.1 riastrad DRM_ERROR("[drm] Buffer too small for color buffer %d " 2277 1.1 riastrad "(need %lu have %lu) !\n", i, size, 2278 1.1 riastrad radeon_bo_size(track->cb[i].robj)); 2279 1.1 riastrad DRM_ERROR("[drm] color buffer %d (%u %u %u %u)\n", 2280 1.1 riastrad i, track->cb[i].pitch, track->cb[i].cpp, 2281 1.1 riastrad track->cb[i].offset, track->maxy); 2282 1.1 riastrad return -EINVAL; 2283 1.1 riastrad } 2284 1.1 riastrad } 2285 1.1 riastrad track->cb_dirty = false; 2286 1.1 riastrad 2287 1.1 riastrad if (track->zb_dirty && track->z_enabled) { 2288 1.1 riastrad if (track->zb.robj == NULL) { 2289 1.1 riastrad DRM_ERROR("[drm] No buffer for z buffer !\n"); 2290 1.1 riastrad return -EINVAL; 2291 1.1 riastrad } 2292 1.1 riastrad size = track->zb.pitch * track->zb.cpp * track->maxy; 2293 1.1 riastrad size += track->zb.offset; 2294 1.1 riastrad if (size > radeon_bo_size(track->zb.robj)) { 2295 1.1 riastrad DRM_ERROR("[drm] Buffer too small for z buffer " 2296 1.1 riastrad "(need %lu have %lu) !\n", size, 2297 1.1 riastrad radeon_bo_size(track->zb.robj)); 2298 1.1 riastrad DRM_ERROR("[drm] zbuffer (%u %u %u %u)\n", 2299 1.1 riastrad track->zb.pitch, track->zb.cpp, 2300 1.1 riastrad track->zb.offset, track->maxy); 2301 1.1 riastrad return -EINVAL; 2302 1.1 riastrad } 2303 1.1 riastrad } 2304 1.1 riastrad track->zb_dirty = false; 2305 1.1 riastrad 2306 1.1 riastrad if (track->aa_dirty && track->aaresolve) { 2307 1.1 riastrad if (track->aa.robj == NULL) { 2308 1.1 riastrad DRM_ERROR("[drm] No buffer for AA resolve buffer %d !\n", i); 2309 1.1 riastrad return -EINVAL; 2310 1.1 riastrad } 2311 1.1 riastrad /* I believe the format comes from colorbuffer0. */ 2312 1.1 riastrad size = track->aa.pitch * track->cb[0].cpp * track->maxy; 2313 1.1 riastrad size += track->aa.offset; 2314 1.1 riastrad if (size > radeon_bo_size(track->aa.robj)) { 2315 1.1 riastrad DRM_ERROR("[drm] Buffer too small for AA resolve buffer %d " 2316 1.1 riastrad "(need %lu have %lu) !\n", i, size, 2317 1.1 riastrad radeon_bo_size(track->aa.robj)); 2318 1.1 riastrad DRM_ERROR("[drm] AA resolve buffer %d (%u %u %u %u)\n", 2319 1.1 riastrad i, track->aa.pitch, track->cb[0].cpp, 2320 1.1 riastrad track->aa.offset, track->maxy); 2321 1.1 riastrad return -EINVAL; 2322 1.1 riastrad } 2323 1.1 riastrad } 2324 1.1 riastrad track->aa_dirty = false; 2325 1.1 riastrad 2326 1.1 riastrad prim_walk = (track->vap_vf_cntl >> 4) & 0x3; 2327 1.1 riastrad if (track->vap_vf_cntl & (1 << 14)) { 2328 1.1 riastrad nverts = track->vap_alt_nverts; 2329 1.1 riastrad } else { 2330 1.1 riastrad nverts = (track->vap_vf_cntl >> 16) & 0xFFFF; 2331 1.1 riastrad } 2332 1.1 riastrad switch (prim_walk) { 2333 1.1 riastrad case 1: 2334 1.1 riastrad for (i = 0; i < track->num_arrays; i++) { 2335 1.1 riastrad size = track->arrays[i].esize * track->max_indx * 4; 2336 1.1 riastrad if (track->arrays[i].robj == NULL) { 2337 1.1 riastrad DRM_ERROR("(PW %u) Vertex array %u no buffer " 2338 1.1 riastrad "bound\n", prim_walk, i); 2339 1.1 riastrad return -EINVAL; 2340 1.1 riastrad } 2341 1.1 riastrad if (size > radeon_bo_size(track->arrays[i].robj)) { 2342 1.1 riastrad dev_err(rdev->dev, "(PW %u) Vertex array %u " 2343 1.1 riastrad "need %lu dwords have %lu dwords\n", 2344 1.1 riastrad prim_walk, i, size >> 2, 2345 1.1 riastrad radeon_bo_size(track->arrays[i].robj) 2346 1.1 riastrad >> 2); 2347 1.1 riastrad DRM_ERROR("Max indices %u\n", track->max_indx); 2348 1.1 riastrad return -EINVAL; 2349 1.1 riastrad } 2350 1.1 riastrad } 2351 1.1 riastrad break; 2352 1.1 riastrad case 2: 2353 1.1 riastrad for (i = 0; i < track->num_arrays; i++) { 2354 1.1 riastrad size = track->arrays[i].esize * (nverts - 1) * 4; 2355 1.1 riastrad if (track->arrays[i].robj == NULL) { 2356 1.1 riastrad DRM_ERROR("(PW %u) Vertex array %u no buffer " 2357 1.1 riastrad "bound\n", prim_walk, i); 2358 1.1 riastrad return -EINVAL; 2359 1.1 riastrad } 2360 1.1 riastrad if (size > radeon_bo_size(track->arrays[i].robj)) { 2361 1.1 riastrad dev_err(rdev->dev, "(PW %u) Vertex array %u " 2362 1.1 riastrad "need %lu dwords have %lu dwords\n", 2363 1.1 riastrad prim_walk, i, size >> 2, 2364 1.1 riastrad radeon_bo_size(track->arrays[i].robj) 2365 1.1 riastrad >> 2); 2366 1.1 riastrad return -EINVAL; 2367 1.1 riastrad } 2368 1.1 riastrad } 2369 1.1 riastrad break; 2370 1.1 riastrad case 3: 2371 1.1 riastrad size = track->vtx_size * nverts; 2372 1.1 riastrad if (size != track->immd_dwords) { 2373 1.1 riastrad DRM_ERROR("IMMD draw %u dwors but needs %lu dwords\n", 2374 1.1 riastrad track->immd_dwords, size); 2375 1.1 riastrad DRM_ERROR("VAP_VF_CNTL.NUM_VERTICES %u, VTX_SIZE %u\n", 2376 1.1 riastrad nverts, track->vtx_size); 2377 1.1 riastrad return -EINVAL; 2378 1.1 riastrad } 2379 1.1 riastrad break; 2380 1.1 riastrad default: 2381 1.1 riastrad DRM_ERROR("[drm] Invalid primitive walk %d for VAP_VF_CNTL\n", 2382 1.1 riastrad prim_walk); 2383 1.1 riastrad return -EINVAL; 2384 1.1 riastrad } 2385 1.1 riastrad 2386 1.1 riastrad if (track->tex_dirty) { 2387 1.1 riastrad track->tex_dirty = false; 2388 1.1 riastrad return r100_cs_track_texture_check(rdev, track); 2389 1.1 riastrad } 2390 1.1 riastrad return 0; 2391 1.1 riastrad } 2392 1.1 riastrad 2393 1.1 riastrad void r100_cs_track_clear(struct radeon_device *rdev, struct r100_cs_track *track) 2394 1.1 riastrad { 2395 1.1 riastrad unsigned i, face; 2396 1.1 riastrad 2397 1.1 riastrad track->cb_dirty = true; 2398 1.1 riastrad track->zb_dirty = true; 2399 1.1 riastrad track->tex_dirty = true; 2400 1.1 riastrad track->aa_dirty = true; 2401 1.1 riastrad 2402 1.1 riastrad if (rdev->family < CHIP_R300) { 2403 1.1 riastrad track->num_cb = 1; 2404 1.1 riastrad if (rdev->family <= CHIP_RS200) 2405 1.1 riastrad track->num_texture = 3; 2406 1.1 riastrad else 2407 1.1 riastrad track->num_texture = 6; 2408 1.1 riastrad track->maxy = 2048; 2409 1.2 riastrad track->separate_cube = true; 2410 1.1 riastrad } else { 2411 1.1 riastrad track->num_cb = 4; 2412 1.1 riastrad track->num_texture = 16; 2413 1.1 riastrad track->maxy = 4096; 2414 1.2 riastrad track->separate_cube = false; 2415 1.1 riastrad track->aaresolve = false; 2416 1.1 riastrad track->aa.robj = NULL; 2417 1.1 riastrad } 2418 1.1 riastrad 2419 1.1 riastrad for (i = 0; i < track->num_cb; i++) { 2420 1.1 riastrad track->cb[i].robj = NULL; 2421 1.1 riastrad track->cb[i].pitch = 8192; 2422 1.1 riastrad track->cb[i].cpp = 16; 2423 1.1 riastrad track->cb[i].offset = 0; 2424 1.1 riastrad } 2425 1.1 riastrad track->z_enabled = true; 2426 1.1 riastrad track->zb.robj = NULL; 2427 1.1 riastrad track->zb.pitch = 8192; 2428 1.1 riastrad track->zb.cpp = 4; 2429 1.1 riastrad track->zb.offset = 0; 2430 1.1 riastrad track->vtx_size = 0x7F; 2431 1.1 riastrad track->immd_dwords = 0xFFFFFFFFUL; 2432 1.1 riastrad track->num_arrays = 11; 2433 1.1 riastrad track->max_indx = 0x00FFFFFFUL; 2434 1.1 riastrad for (i = 0; i < track->num_arrays; i++) { 2435 1.1 riastrad track->arrays[i].robj = NULL; 2436 1.1 riastrad track->arrays[i].esize = 0x7F; 2437 1.1 riastrad } 2438 1.1 riastrad for (i = 0; i < track->num_texture; i++) { 2439 1.1 riastrad track->textures[i].compress_format = R100_TRACK_COMP_NONE; 2440 1.1 riastrad track->textures[i].pitch = 16536; 2441 1.1 riastrad track->textures[i].width = 16536; 2442 1.1 riastrad track->textures[i].height = 16536; 2443 1.1 riastrad track->textures[i].width_11 = 1 << 11; 2444 1.1 riastrad track->textures[i].height_11 = 1 << 11; 2445 1.1 riastrad track->textures[i].num_levels = 12; 2446 1.1 riastrad if (rdev->family <= CHIP_RS200) { 2447 1.1 riastrad track->textures[i].tex_coord_type = 0; 2448 1.1 riastrad track->textures[i].txdepth = 0; 2449 1.1 riastrad } else { 2450 1.1 riastrad track->textures[i].txdepth = 16; 2451 1.1 riastrad track->textures[i].tex_coord_type = 1; 2452 1.1 riastrad } 2453 1.1 riastrad track->textures[i].cpp = 64; 2454 1.1 riastrad track->textures[i].robj = NULL; 2455 1.1 riastrad /* CS IB emission code makes sure texture unit are disabled */ 2456 1.1 riastrad track->textures[i].enabled = false; 2457 1.1 riastrad track->textures[i].lookup_disable = false; 2458 1.1 riastrad track->textures[i].roundup_w = true; 2459 1.1 riastrad track->textures[i].roundup_h = true; 2460 1.1 riastrad if (track->separate_cube) 2461 1.1 riastrad for (face = 0; face < 5; face++) { 2462 1.1 riastrad track->textures[i].cube_info[face].robj = NULL; 2463 1.1 riastrad track->textures[i].cube_info[face].width = 16536; 2464 1.1 riastrad track->textures[i].cube_info[face].height = 16536; 2465 1.1 riastrad track->textures[i].cube_info[face].offset = 0; 2466 1.1 riastrad } 2467 1.1 riastrad } 2468 1.1 riastrad } 2469 1.1 riastrad 2470 1.1 riastrad /* 2471 1.1 riastrad * Global GPU functions 2472 1.1 riastrad */ 2473 1.1 riastrad static void r100_errata(struct radeon_device *rdev) 2474 1.1 riastrad { 2475 1.1 riastrad rdev->pll_errata = 0; 2476 1.1 riastrad 2477 1.1 riastrad if (rdev->family == CHIP_RV200 || rdev->family == CHIP_RS200) { 2478 1.1 riastrad rdev->pll_errata |= CHIP_ERRATA_PLL_DUMMYREADS; 2479 1.1 riastrad } 2480 1.1 riastrad 2481 1.1 riastrad if (rdev->family == CHIP_RV100 || 2482 1.1 riastrad rdev->family == CHIP_RS100 || 2483 1.1 riastrad rdev->family == CHIP_RS200) { 2484 1.1 riastrad rdev->pll_errata |= CHIP_ERRATA_PLL_DELAY; 2485 1.1 riastrad } 2486 1.1 riastrad } 2487 1.1 riastrad 2488 1.1 riastrad static int r100_rbbm_fifo_wait_for_entry(struct radeon_device *rdev, unsigned n) 2489 1.1 riastrad { 2490 1.1 riastrad unsigned i; 2491 1.1 riastrad uint32_t tmp; 2492 1.1 riastrad 2493 1.1 riastrad for (i = 0; i < rdev->usec_timeout; i++) { 2494 1.1 riastrad tmp = RREG32(RADEON_RBBM_STATUS) & RADEON_RBBM_FIFOCNT_MASK; 2495 1.1 riastrad if (tmp >= n) { 2496 1.1 riastrad return 0; 2497 1.1 riastrad } 2498 1.2 riastrad udelay(1); 2499 1.1 riastrad } 2500 1.1 riastrad return -1; 2501 1.1 riastrad } 2502 1.1 riastrad 2503 1.1 riastrad int r100_gui_wait_for_idle(struct radeon_device *rdev) 2504 1.1 riastrad { 2505 1.1 riastrad unsigned i; 2506 1.1 riastrad uint32_t tmp; 2507 1.1 riastrad 2508 1.1 riastrad if (r100_rbbm_fifo_wait_for_entry(rdev, 64)) { 2509 1.2 riastrad pr_warn("radeon: wait for empty RBBM fifo failed! Bad things might happen.\n"); 2510 1.1 riastrad } 2511 1.1 riastrad for (i = 0; i < rdev->usec_timeout; i++) { 2512 1.1 riastrad tmp = RREG32(RADEON_RBBM_STATUS); 2513 1.1 riastrad if (!(tmp & RADEON_RBBM_ACTIVE)) { 2514 1.1 riastrad return 0; 2515 1.1 riastrad } 2516 1.2 riastrad udelay(1); 2517 1.1 riastrad } 2518 1.1 riastrad return -1; 2519 1.1 riastrad } 2520 1.1 riastrad 2521 1.1 riastrad int r100_mc_wait_for_idle(struct radeon_device *rdev) 2522 1.1 riastrad { 2523 1.1 riastrad unsigned i; 2524 1.1 riastrad uint32_t tmp; 2525 1.1 riastrad 2526 1.1 riastrad for (i = 0; i < rdev->usec_timeout; i++) { 2527 1.1 riastrad /* read MC_STATUS */ 2528 1.1 riastrad tmp = RREG32(RADEON_MC_STATUS); 2529 1.1 riastrad if (tmp & RADEON_MC_IDLE) { 2530 1.1 riastrad return 0; 2531 1.1 riastrad } 2532 1.2 riastrad udelay(1); 2533 1.1 riastrad } 2534 1.1 riastrad return -1; 2535 1.1 riastrad } 2536 1.1 riastrad 2537 1.1 riastrad bool r100_gpu_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring) 2538 1.1 riastrad { 2539 1.1 riastrad u32 rbbm_status; 2540 1.1 riastrad 2541 1.1 riastrad rbbm_status = RREG32(R_000E40_RBBM_STATUS); 2542 1.1 riastrad if (!G_000E40_GUI_ACTIVE(rbbm_status)) { 2543 1.1 riastrad radeon_ring_lockup_update(rdev, ring); 2544 1.1 riastrad return false; 2545 1.1 riastrad } 2546 1.1 riastrad return radeon_ring_test_lockup(rdev, ring); 2547 1.1 riastrad } 2548 1.1 riastrad 2549 1.1 riastrad /* required on r1xx, r2xx, r300, r(v)350, r420/r481, rs400/rs480 */ 2550 1.1 riastrad void r100_enable_bm(struct radeon_device *rdev) 2551 1.1 riastrad { 2552 1.1 riastrad uint32_t tmp; 2553 1.1 riastrad /* Enable bus mastering */ 2554 1.1 riastrad tmp = RREG32(RADEON_BUS_CNTL) & ~RADEON_BUS_MASTER_DIS; 2555 1.1 riastrad WREG32(RADEON_BUS_CNTL, tmp); 2556 1.1 riastrad } 2557 1.1 riastrad 2558 1.1 riastrad void r100_bm_disable(struct radeon_device *rdev) 2559 1.1 riastrad { 2560 1.1 riastrad u32 tmp; 2561 1.1 riastrad 2562 1.1 riastrad /* disable bus mastering */ 2563 1.1 riastrad tmp = RREG32(R_000030_BUS_CNTL); 2564 1.1 riastrad WREG32(R_000030_BUS_CNTL, (tmp & 0xFFFFFFFF) | 0x00000044); 2565 1.1 riastrad mdelay(1); 2566 1.1 riastrad WREG32(R_000030_BUS_CNTL, (tmp & 0xFFFFFFFF) | 0x00000042); 2567 1.1 riastrad mdelay(1); 2568 1.1 riastrad WREG32(R_000030_BUS_CNTL, (tmp & 0xFFFFFFFF) | 0x00000040); 2569 1.1 riastrad tmp = RREG32(RADEON_BUS_CNTL); 2570 1.1 riastrad mdelay(1); 2571 1.1 riastrad pci_clear_master(rdev->pdev); 2572 1.1 riastrad mdelay(1); 2573 1.1 riastrad } 2574 1.1 riastrad 2575 1.2 riastrad int r100_asic_reset(struct radeon_device *rdev, bool hard) 2576 1.1 riastrad { 2577 1.1 riastrad struct r100_mc_save save; 2578 1.1 riastrad u32 status, tmp; 2579 1.1 riastrad int ret = 0; 2580 1.1 riastrad 2581 1.1 riastrad status = RREG32(R_000E40_RBBM_STATUS); 2582 1.1 riastrad if (!G_000E40_GUI_ACTIVE(status)) { 2583 1.1 riastrad return 0; 2584 1.1 riastrad } 2585 1.1 riastrad r100_mc_stop(rdev, &save); 2586 1.1 riastrad status = RREG32(R_000E40_RBBM_STATUS); 2587 1.1 riastrad dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status); 2588 1.1 riastrad /* stop CP */ 2589 1.1 riastrad WREG32(RADEON_CP_CSQ_CNTL, 0); 2590 1.1 riastrad tmp = RREG32(RADEON_CP_RB_CNTL); 2591 1.1 riastrad WREG32(RADEON_CP_RB_CNTL, tmp | RADEON_RB_RPTR_WR_ENA); 2592 1.1 riastrad WREG32(RADEON_CP_RB_RPTR_WR, 0); 2593 1.1 riastrad WREG32(RADEON_CP_RB_WPTR, 0); 2594 1.1 riastrad WREG32(RADEON_CP_RB_CNTL, tmp); 2595 1.1 riastrad /* save PCI state */ 2596 1.1 riastrad pci_save_state(rdev->pdev); 2597 1.1 riastrad /* disable bus mastering */ 2598 1.1 riastrad r100_bm_disable(rdev); 2599 1.1 riastrad WREG32(R_0000F0_RBBM_SOFT_RESET, S_0000F0_SOFT_RESET_SE(1) | 2600 1.1 riastrad S_0000F0_SOFT_RESET_RE(1) | 2601 1.1 riastrad S_0000F0_SOFT_RESET_PP(1) | 2602 1.1 riastrad S_0000F0_SOFT_RESET_RB(1)); 2603 1.1 riastrad RREG32(R_0000F0_RBBM_SOFT_RESET); 2604 1.1 riastrad mdelay(500); 2605 1.1 riastrad WREG32(R_0000F0_RBBM_SOFT_RESET, 0); 2606 1.1 riastrad mdelay(1); 2607 1.1 riastrad status = RREG32(R_000E40_RBBM_STATUS); 2608 1.1 riastrad dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status); 2609 1.1 riastrad /* reset CP */ 2610 1.1 riastrad WREG32(R_0000F0_RBBM_SOFT_RESET, S_0000F0_SOFT_RESET_CP(1)); 2611 1.1 riastrad RREG32(R_0000F0_RBBM_SOFT_RESET); 2612 1.1 riastrad mdelay(500); 2613 1.1 riastrad WREG32(R_0000F0_RBBM_SOFT_RESET, 0); 2614 1.1 riastrad mdelay(1); 2615 1.1 riastrad status = RREG32(R_000E40_RBBM_STATUS); 2616 1.1 riastrad dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status); 2617 1.1 riastrad /* restore PCI & busmastering */ 2618 1.1 riastrad pci_restore_state(rdev->pdev); 2619 1.1 riastrad r100_enable_bm(rdev); 2620 1.1 riastrad /* Check if GPU is idle */ 2621 1.1 riastrad if (G_000E40_SE_BUSY(status) || G_000E40_RE_BUSY(status) || 2622 1.1 riastrad G_000E40_TAM_BUSY(status) || G_000E40_PB_BUSY(status)) { 2623 1.1 riastrad dev_err(rdev->dev, "failed to reset GPU\n"); 2624 1.1 riastrad ret = -1; 2625 1.1 riastrad } else 2626 1.1 riastrad dev_info(rdev->dev, "GPU reset succeed\n"); 2627 1.1 riastrad r100_mc_resume(rdev, &save); 2628 1.1 riastrad return ret; 2629 1.1 riastrad } 2630 1.1 riastrad 2631 1.1 riastrad void r100_set_common_regs(struct radeon_device *rdev) 2632 1.1 riastrad { 2633 1.1 riastrad struct drm_device *dev = rdev->ddev; 2634 1.1 riastrad bool force_dac2 = false; 2635 1.1 riastrad u32 tmp; 2636 1.1 riastrad 2637 1.1 riastrad /* set these so they don't interfere with anything */ 2638 1.1 riastrad WREG32(RADEON_OV0_SCALE_CNTL, 0); 2639 1.1 riastrad WREG32(RADEON_SUBPIC_CNTL, 0); 2640 1.1 riastrad WREG32(RADEON_VIPH_CONTROL, 0); 2641 1.1 riastrad WREG32(RADEON_I2C_CNTL_1, 0); 2642 1.1 riastrad WREG32(RADEON_DVI_I2C_CNTL_1, 0); 2643 1.1 riastrad WREG32(RADEON_CAP0_TRIG_CNTL, 0); 2644 1.1 riastrad WREG32(RADEON_CAP1_TRIG_CNTL, 0); 2645 1.1 riastrad 2646 1.1 riastrad /* always set up dac2 on rn50 and some rv100 as lots 2647 1.1 riastrad * of servers seem to wire it up to a VGA port but 2648 1.1 riastrad * don't report it in the bios connector 2649 1.1 riastrad * table. 2650 1.1 riastrad */ 2651 1.1 riastrad switch (dev->pdev->device) { 2652 1.1 riastrad /* RN50 */ 2653 1.1 riastrad case 0x515e: 2654 1.1 riastrad case 0x5969: 2655 1.1 riastrad force_dac2 = true; 2656 1.1 riastrad break; 2657 1.1 riastrad /* RV100*/ 2658 1.1 riastrad case 0x5159: 2659 1.1 riastrad case 0x515a: 2660 1.1 riastrad /* DELL triple head servers */ 2661 1.1 riastrad if ((dev->pdev->subsystem_vendor == 0x1028 /* DELL */) && 2662 1.1 riastrad ((dev->pdev->subsystem_device == 0x016c) || 2663 1.1 riastrad (dev->pdev->subsystem_device == 0x016d) || 2664 1.1 riastrad (dev->pdev->subsystem_device == 0x016e) || 2665 1.1 riastrad (dev->pdev->subsystem_device == 0x016f) || 2666 1.1 riastrad (dev->pdev->subsystem_device == 0x0170) || 2667 1.1 riastrad (dev->pdev->subsystem_device == 0x017d) || 2668 1.1 riastrad (dev->pdev->subsystem_device == 0x017e) || 2669 1.1 riastrad (dev->pdev->subsystem_device == 0x0183) || 2670 1.1 riastrad (dev->pdev->subsystem_device == 0x018a) || 2671 1.1 riastrad (dev->pdev->subsystem_device == 0x019a))) 2672 1.1 riastrad force_dac2 = true; 2673 1.1 riastrad break; 2674 1.1 riastrad } 2675 1.1 riastrad 2676 1.1 riastrad if (force_dac2) { 2677 1.1 riastrad u32 disp_hw_debug = RREG32(RADEON_DISP_HW_DEBUG); 2678 1.1 riastrad u32 tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL); 2679 1.1 riastrad u32 dac2_cntl = RREG32(RADEON_DAC_CNTL2); 2680 1.1 riastrad 2681 1.1 riastrad /* For CRT on DAC2, don't turn it on if BIOS didn't 2682 1.1 riastrad enable it, even it's detected. 2683 1.1 riastrad */ 2684 1.1 riastrad 2685 1.1 riastrad /* force it to crtc0 */ 2686 1.1 riastrad dac2_cntl &= ~RADEON_DAC2_DAC_CLK_SEL; 2687 1.1 riastrad dac2_cntl |= RADEON_DAC2_DAC2_CLK_SEL; 2688 1.1 riastrad disp_hw_debug |= RADEON_CRT2_DISP1_SEL; 2689 1.1 riastrad 2690 1.1 riastrad /* set up the TV DAC */ 2691 1.1 riastrad tv_dac_cntl &= ~(RADEON_TV_DAC_PEDESTAL | 2692 1.1 riastrad RADEON_TV_DAC_STD_MASK | 2693 1.1 riastrad RADEON_TV_DAC_RDACPD | 2694 1.1 riastrad RADEON_TV_DAC_GDACPD | 2695 1.1 riastrad RADEON_TV_DAC_BDACPD | 2696 1.1 riastrad RADEON_TV_DAC_BGADJ_MASK | 2697 1.1 riastrad RADEON_TV_DAC_DACADJ_MASK); 2698 1.1 riastrad tv_dac_cntl |= (RADEON_TV_DAC_NBLANK | 2699 1.1 riastrad RADEON_TV_DAC_NHOLD | 2700 1.1 riastrad RADEON_TV_DAC_STD_PS2 | 2701 1.1 riastrad (0x58 << 16)); 2702 1.1 riastrad 2703 1.1 riastrad WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl); 2704 1.1 riastrad WREG32(RADEON_DISP_HW_DEBUG, disp_hw_debug); 2705 1.1 riastrad WREG32(RADEON_DAC_CNTL2, dac2_cntl); 2706 1.1 riastrad } 2707 1.1 riastrad 2708 1.1 riastrad /* switch PM block to ACPI mode */ 2709 1.1 riastrad tmp = RREG32_PLL(RADEON_PLL_PWRMGT_CNTL); 2710 1.1 riastrad tmp &= ~RADEON_PM_MODE_SEL; 2711 1.1 riastrad WREG32_PLL(RADEON_PLL_PWRMGT_CNTL, tmp); 2712 1.1 riastrad 2713 1.1 riastrad } 2714 1.1 riastrad 2715 1.1 riastrad /* 2716 1.1 riastrad * VRAM info 2717 1.1 riastrad */ 2718 1.1 riastrad static void r100_vram_get_type(struct radeon_device *rdev) 2719 1.1 riastrad { 2720 1.1 riastrad uint32_t tmp; 2721 1.1 riastrad 2722 1.1 riastrad rdev->mc.vram_is_ddr = false; 2723 1.1 riastrad if (rdev->flags & RADEON_IS_IGP) 2724 1.1 riastrad rdev->mc.vram_is_ddr = true; 2725 1.1 riastrad else if (RREG32(RADEON_MEM_SDRAM_MODE_REG) & RADEON_MEM_CFG_TYPE_DDR) 2726 1.1 riastrad rdev->mc.vram_is_ddr = true; 2727 1.1 riastrad if ((rdev->family == CHIP_RV100) || 2728 1.1 riastrad (rdev->family == CHIP_RS100) || 2729 1.1 riastrad (rdev->family == CHIP_RS200)) { 2730 1.1 riastrad tmp = RREG32(RADEON_MEM_CNTL); 2731 1.1 riastrad if (tmp & RV100_HALF_MODE) { 2732 1.1 riastrad rdev->mc.vram_width = 32; 2733 1.1 riastrad } else { 2734 1.1 riastrad rdev->mc.vram_width = 64; 2735 1.1 riastrad } 2736 1.1 riastrad if (rdev->flags & RADEON_SINGLE_CRTC) { 2737 1.1 riastrad rdev->mc.vram_width /= 4; 2738 1.1 riastrad rdev->mc.vram_is_ddr = true; 2739 1.1 riastrad } 2740 1.1 riastrad } else if (rdev->family <= CHIP_RV280) { 2741 1.1 riastrad tmp = RREG32(RADEON_MEM_CNTL); 2742 1.1 riastrad if (tmp & RADEON_MEM_NUM_CHANNELS_MASK) { 2743 1.1 riastrad rdev->mc.vram_width = 128; 2744 1.1 riastrad } else { 2745 1.1 riastrad rdev->mc.vram_width = 64; 2746 1.1 riastrad } 2747 1.1 riastrad } else { 2748 1.1 riastrad /* newer IGPs */ 2749 1.1 riastrad rdev->mc.vram_width = 128; 2750 1.1 riastrad } 2751 1.1 riastrad } 2752 1.1 riastrad 2753 1.1 riastrad static u32 r100_get_accessible_vram(struct radeon_device *rdev) 2754 1.1 riastrad { 2755 1.1 riastrad u32 aper_size; 2756 1.1 riastrad u8 byte; 2757 1.1 riastrad 2758 1.1 riastrad aper_size = RREG32(RADEON_CONFIG_APER_SIZE); 2759 1.1 riastrad 2760 1.1 riastrad /* Set HDP_APER_CNTL only on cards that are known not to be broken, 2761 1.1 riastrad * that is has the 2nd generation multifunction PCI interface 2762 1.1 riastrad */ 2763 1.1 riastrad if (rdev->family == CHIP_RV280 || 2764 1.1 riastrad rdev->family >= CHIP_RV350) { 2765 1.1 riastrad WREG32_P(RADEON_HOST_PATH_CNTL, RADEON_HDP_APER_CNTL, 2766 1.1 riastrad ~RADEON_HDP_APER_CNTL); 2767 1.1 riastrad DRM_INFO("Generation 2 PCI interface, using max accessible memory\n"); 2768 1.1 riastrad return aper_size * 2; 2769 1.1 riastrad } 2770 1.1 riastrad 2771 1.1 riastrad /* Older cards have all sorts of funny issues to deal with. First 2772 1.1 riastrad * check if it's a multifunction card by reading the PCI config 2773 1.1 riastrad * header type... Limit those to one aperture size 2774 1.1 riastrad */ 2775 1.1 riastrad pci_read_config_byte(rdev->pdev, 0xe, &byte); 2776 1.1 riastrad if (byte & 0x80) { 2777 1.1 riastrad DRM_INFO("Generation 1 PCI interface in multifunction mode\n"); 2778 1.1 riastrad DRM_INFO("Limiting VRAM to one aperture\n"); 2779 1.1 riastrad return aper_size; 2780 1.1 riastrad } 2781 1.1 riastrad 2782 1.1 riastrad /* Single function older card. We read HDP_APER_CNTL to see how the BIOS 2783 1.1 riastrad * have set it up. We don't write this as it's broken on some ASICs but 2784 1.1 riastrad * we expect the BIOS to have done the right thing (might be too optimistic...) 2785 1.1 riastrad */ 2786 1.1 riastrad if (RREG32(RADEON_HOST_PATH_CNTL) & RADEON_HDP_APER_CNTL) 2787 1.1 riastrad return aper_size * 2; 2788 1.1 riastrad return aper_size; 2789 1.1 riastrad } 2790 1.1 riastrad 2791 1.1 riastrad void r100_vram_init_sizes(struct radeon_device *rdev) 2792 1.1 riastrad { 2793 1.1 riastrad u64 config_aper_size; 2794 1.1 riastrad 2795 1.1 riastrad /* work out accessible VRAM */ 2796 1.1 riastrad rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0); 2797 1.1 riastrad rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0); 2798 1.1 riastrad rdev->mc.visible_vram_size = r100_get_accessible_vram(rdev); 2799 1.1 riastrad /* FIXME we don't use the second aperture yet when we could use it */ 2800 1.1 riastrad if (rdev->mc.visible_vram_size > rdev->mc.aper_size) 2801 1.1 riastrad rdev->mc.visible_vram_size = rdev->mc.aper_size; 2802 1.1 riastrad config_aper_size = RREG32(RADEON_CONFIG_APER_SIZE); 2803 1.1 riastrad if (rdev->flags & RADEON_IS_IGP) { 2804 1.1 riastrad uint32_t tom; 2805 1.1 riastrad /* read NB_TOM to get the amount of ram stolen for the GPU */ 2806 1.1 riastrad tom = RREG32(RADEON_NB_TOM); 2807 1.1 riastrad rdev->mc.real_vram_size = (((tom >> 16) - (tom & 0xffff) + 1) << 16); 2808 1.1 riastrad WREG32(RADEON_CONFIG_MEMSIZE, rdev->mc.real_vram_size); 2809 1.1 riastrad rdev->mc.mc_vram_size = rdev->mc.real_vram_size; 2810 1.1 riastrad } else { 2811 1.1 riastrad rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE); 2812 1.1 riastrad /* Some production boards of m6 will report 0 2813 1.1 riastrad * if it's 8 MB 2814 1.1 riastrad */ 2815 1.1 riastrad if (rdev->mc.real_vram_size == 0) { 2816 1.1 riastrad rdev->mc.real_vram_size = 8192 * 1024; 2817 1.1 riastrad WREG32(RADEON_CONFIG_MEMSIZE, rdev->mc.real_vram_size); 2818 1.1 riastrad } 2819 1.1 riastrad /* Fix for RN50, M6, M7 with 8/16/32(??) MBs of VRAM - 2820 1.1 riastrad * Novell bug 204882 + along with lots of ubuntu ones 2821 1.1 riastrad */ 2822 1.1 riastrad if (rdev->mc.aper_size > config_aper_size) 2823 1.1 riastrad config_aper_size = rdev->mc.aper_size; 2824 1.1 riastrad 2825 1.1 riastrad if (config_aper_size > rdev->mc.real_vram_size) 2826 1.1 riastrad rdev->mc.mc_vram_size = config_aper_size; 2827 1.1 riastrad else 2828 1.1 riastrad rdev->mc.mc_vram_size = rdev->mc.real_vram_size; 2829 1.1 riastrad } 2830 1.1 riastrad } 2831 1.1 riastrad 2832 1.1 riastrad void r100_vga_set_state(struct radeon_device *rdev, bool state) 2833 1.1 riastrad { 2834 1.1 riastrad uint32_t temp; 2835 1.1 riastrad 2836 1.1 riastrad temp = RREG32(RADEON_CONFIG_CNTL); 2837 1.2 riastrad if (!state) { 2838 1.1 riastrad temp &= ~RADEON_CFG_VGA_RAM_EN; 2839 1.1 riastrad temp |= RADEON_CFG_VGA_IO_DIS; 2840 1.1 riastrad } else { 2841 1.1 riastrad temp &= ~RADEON_CFG_VGA_IO_DIS; 2842 1.1 riastrad } 2843 1.1 riastrad WREG32(RADEON_CONFIG_CNTL, temp); 2844 1.1 riastrad } 2845 1.1 riastrad 2846 1.1 riastrad static void r100_mc_init(struct radeon_device *rdev) 2847 1.1 riastrad { 2848 1.1 riastrad u64 base; 2849 1.1 riastrad 2850 1.1 riastrad r100_vram_get_type(rdev); 2851 1.1 riastrad r100_vram_init_sizes(rdev); 2852 1.1 riastrad base = rdev->mc.aper_base; 2853 1.1 riastrad if (rdev->flags & RADEON_IS_IGP) 2854 1.1 riastrad base = (RREG32(RADEON_NB_TOM) & 0xffff) << 16; 2855 1.1 riastrad radeon_vram_location(rdev, &rdev->mc, base); 2856 1.1 riastrad rdev->mc.gtt_base_align = 0; 2857 1.1 riastrad if (!(rdev->flags & RADEON_IS_AGP)) 2858 1.1 riastrad radeon_gtt_location(rdev, &rdev->mc); 2859 1.1 riastrad radeon_update_bandwidth_info(rdev); 2860 1.1 riastrad } 2861 1.1 riastrad 2862 1.1 riastrad 2863 1.1 riastrad /* 2864 1.1 riastrad * Indirect registers accessor 2865 1.1 riastrad */ 2866 1.1 riastrad void r100_pll_errata_after_index(struct radeon_device *rdev) 2867 1.1 riastrad { 2868 1.1 riastrad if (rdev->pll_errata & CHIP_ERRATA_PLL_DUMMYREADS) { 2869 1.1 riastrad (void)RREG32(RADEON_CLOCK_CNTL_DATA); 2870 1.1 riastrad (void)RREG32(RADEON_CRTC_GEN_CNTL); 2871 1.1 riastrad } 2872 1.1 riastrad } 2873 1.1 riastrad 2874 1.1 riastrad static void r100_pll_errata_after_data(struct radeon_device *rdev) 2875 1.1 riastrad { 2876 1.1 riastrad /* This workarounds is necessary on RV100, RS100 and RS200 chips 2877 1.1 riastrad * or the chip could hang on a subsequent access 2878 1.1 riastrad */ 2879 1.1 riastrad if (rdev->pll_errata & CHIP_ERRATA_PLL_DELAY) { 2880 1.1 riastrad mdelay(5); 2881 1.1 riastrad } 2882 1.1 riastrad 2883 1.1 riastrad /* This function is required to workaround a hardware bug in some (all?) 2884 1.1 riastrad * revisions of the R300. This workaround should be called after every 2885 1.1 riastrad * CLOCK_CNTL_INDEX register access. If not, register reads afterward 2886 1.1 riastrad * may not be correct. 2887 1.1 riastrad */ 2888 1.1 riastrad if (rdev->pll_errata & CHIP_ERRATA_R300_CG) { 2889 1.1 riastrad uint32_t save, tmp; 2890 1.1 riastrad 2891 1.1 riastrad save = RREG32(RADEON_CLOCK_CNTL_INDEX); 2892 1.1 riastrad tmp = save & ~(0x3f | RADEON_PLL_WR_EN); 2893 1.1 riastrad WREG32(RADEON_CLOCK_CNTL_INDEX, tmp); 2894 1.1 riastrad tmp = RREG32(RADEON_CLOCK_CNTL_DATA); 2895 1.1 riastrad WREG32(RADEON_CLOCK_CNTL_INDEX, save); 2896 1.1 riastrad } 2897 1.1 riastrad } 2898 1.1 riastrad 2899 1.1 riastrad uint32_t r100_pll_rreg(struct radeon_device *rdev, uint32_t reg) 2900 1.1 riastrad { 2901 1.1 riastrad unsigned long flags; 2902 1.1 riastrad uint32_t data; 2903 1.1 riastrad 2904 1.1 riastrad spin_lock_irqsave(&rdev->pll_idx_lock, flags); 2905 1.1 riastrad WREG8(RADEON_CLOCK_CNTL_INDEX, reg & 0x3f); 2906 1.1 riastrad r100_pll_errata_after_index(rdev); 2907 1.1 riastrad data = RREG32(RADEON_CLOCK_CNTL_DATA); 2908 1.1 riastrad r100_pll_errata_after_data(rdev); 2909 1.1 riastrad spin_unlock_irqrestore(&rdev->pll_idx_lock, flags); 2910 1.1 riastrad return data; 2911 1.1 riastrad } 2912 1.1 riastrad 2913 1.1 riastrad void r100_pll_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v) 2914 1.1 riastrad { 2915 1.1 riastrad unsigned long flags; 2916 1.1 riastrad 2917 1.1 riastrad spin_lock_irqsave(&rdev->pll_idx_lock, flags); 2918 1.1 riastrad WREG8(RADEON_CLOCK_CNTL_INDEX, ((reg & 0x3f) | RADEON_PLL_WR_EN)); 2919 1.1 riastrad r100_pll_errata_after_index(rdev); 2920 1.1 riastrad WREG32(RADEON_CLOCK_CNTL_DATA, v); 2921 1.1 riastrad r100_pll_errata_after_data(rdev); 2922 1.1 riastrad spin_unlock_irqrestore(&rdev->pll_idx_lock, flags); 2923 1.1 riastrad } 2924 1.1 riastrad 2925 1.1 riastrad static void r100_set_safe_registers(struct radeon_device *rdev) 2926 1.1 riastrad { 2927 1.1 riastrad if (ASIC_IS_RN50(rdev)) { 2928 1.1 riastrad rdev->config.r100.reg_safe_bm = rn50_reg_safe_bm; 2929 1.1 riastrad rdev->config.r100.reg_safe_bm_size = ARRAY_SIZE(rn50_reg_safe_bm); 2930 1.1 riastrad } else if (rdev->family < CHIP_R200) { 2931 1.1 riastrad rdev->config.r100.reg_safe_bm = r100_reg_safe_bm; 2932 1.1 riastrad rdev->config.r100.reg_safe_bm_size = ARRAY_SIZE(r100_reg_safe_bm); 2933 1.1 riastrad } else { 2934 1.1 riastrad r200_set_safe_registers(rdev); 2935 1.1 riastrad } 2936 1.1 riastrad } 2937 1.1 riastrad 2938 1.1 riastrad /* 2939 1.1 riastrad * Debugfs info 2940 1.1 riastrad */ 2941 1.1 riastrad #if defined(CONFIG_DEBUG_FS) 2942 1.1 riastrad static int r100_debugfs_rbbm_info(struct seq_file *m, void *data) 2943 1.1 riastrad { 2944 1.1 riastrad struct drm_info_node *node = (struct drm_info_node *) m->private; 2945 1.1 riastrad struct drm_device *dev = node->minor->dev; 2946 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 2947 1.1 riastrad uint32_t reg, value; 2948 1.1 riastrad unsigned i; 2949 1.1 riastrad 2950 1.1 riastrad seq_printf(m, "RBBM_STATUS 0x%08x\n", RREG32(RADEON_RBBM_STATUS)); 2951 1.1 riastrad seq_printf(m, "RBBM_CMDFIFO_STAT 0x%08x\n", RREG32(0xE7C)); 2952 1.1 riastrad seq_printf(m, "CP_STAT 0x%08x\n", RREG32(RADEON_CP_STAT)); 2953 1.1 riastrad for (i = 0; i < 64; i++) { 2954 1.1 riastrad WREG32(RADEON_RBBM_CMDFIFO_ADDR, i | 0x100); 2955 1.1 riastrad reg = (RREG32(RADEON_RBBM_CMDFIFO_DATA) - 1) >> 2; 2956 1.1 riastrad WREG32(RADEON_RBBM_CMDFIFO_ADDR, i); 2957 1.1 riastrad value = RREG32(RADEON_RBBM_CMDFIFO_DATA); 2958 1.1 riastrad seq_printf(m, "[0x%03X] 0x%04X=0x%08X\n", i, reg, value); 2959 1.1 riastrad } 2960 1.1 riastrad return 0; 2961 1.1 riastrad } 2962 1.1 riastrad 2963 1.1 riastrad static int r100_debugfs_cp_ring_info(struct seq_file *m, void *data) 2964 1.1 riastrad { 2965 1.1 riastrad struct drm_info_node *node = (struct drm_info_node *) m->private; 2966 1.1 riastrad struct drm_device *dev = node->minor->dev; 2967 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 2968 1.1 riastrad struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; 2969 1.1 riastrad uint32_t rdp, wdp; 2970 1.1 riastrad unsigned count, i, j; 2971 1.1 riastrad 2972 1.1 riastrad radeon_ring_free_size(rdev, ring); 2973 1.1 riastrad rdp = RREG32(RADEON_CP_RB_RPTR); 2974 1.1 riastrad wdp = RREG32(RADEON_CP_RB_WPTR); 2975 1.1 riastrad count = (rdp + ring->ring_size - wdp) & ring->ptr_mask; 2976 1.1 riastrad seq_printf(m, "CP_STAT 0x%08x\n", RREG32(RADEON_CP_STAT)); 2977 1.1 riastrad seq_printf(m, "CP_RB_WPTR 0x%08x\n", wdp); 2978 1.1 riastrad seq_printf(m, "CP_RB_RPTR 0x%08x\n", rdp); 2979 1.1 riastrad seq_printf(m, "%u free dwords in ring\n", ring->ring_free_dw); 2980 1.1 riastrad seq_printf(m, "%u dwords in ring\n", count); 2981 1.1 riastrad if (ring->ready) { 2982 1.1 riastrad for (j = 0; j <= count; j++) { 2983 1.1 riastrad i = (rdp + j) & ring->ptr_mask; 2984 1.1 riastrad seq_printf(m, "r[%04d]=0x%08x\n", i, ring->ring[i]); 2985 1.1 riastrad } 2986 1.1 riastrad } 2987 1.1 riastrad return 0; 2988 1.1 riastrad } 2989 1.1 riastrad 2990 1.1 riastrad 2991 1.1 riastrad static int r100_debugfs_cp_csq_fifo(struct seq_file *m, void *data) 2992 1.1 riastrad { 2993 1.1 riastrad struct drm_info_node *node = (struct drm_info_node *) m->private; 2994 1.1 riastrad struct drm_device *dev = node->minor->dev; 2995 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 2996 1.1 riastrad uint32_t csq_stat, csq2_stat, tmp; 2997 1.1 riastrad unsigned r_rptr, r_wptr, ib1_rptr, ib1_wptr, ib2_rptr, ib2_wptr; 2998 1.1 riastrad unsigned i; 2999 1.1 riastrad 3000 1.1 riastrad seq_printf(m, "CP_STAT 0x%08x\n", RREG32(RADEON_CP_STAT)); 3001 1.1 riastrad seq_printf(m, "CP_CSQ_MODE 0x%08x\n", RREG32(RADEON_CP_CSQ_MODE)); 3002 1.1 riastrad csq_stat = RREG32(RADEON_CP_CSQ_STAT); 3003 1.1 riastrad csq2_stat = RREG32(RADEON_CP_CSQ2_STAT); 3004 1.1 riastrad r_rptr = (csq_stat >> 0) & 0x3ff; 3005 1.1 riastrad r_wptr = (csq_stat >> 10) & 0x3ff; 3006 1.1 riastrad ib1_rptr = (csq_stat >> 20) & 0x3ff; 3007 1.1 riastrad ib1_wptr = (csq2_stat >> 0) & 0x3ff; 3008 1.1 riastrad ib2_rptr = (csq2_stat >> 10) & 0x3ff; 3009 1.1 riastrad ib2_wptr = (csq2_stat >> 20) & 0x3ff; 3010 1.1 riastrad seq_printf(m, "CP_CSQ_STAT 0x%08x\n", csq_stat); 3011 1.1 riastrad seq_printf(m, "CP_CSQ2_STAT 0x%08x\n", csq2_stat); 3012 1.1 riastrad seq_printf(m, "Ring rptr %u\n", r_rptr); 3013 1.1 riastrad seq_printf(m, "Ring wptr %u\n", r_wptr); 3014 1.1 riastrad seq_printf(m, "Indirect1 rptr %u\n", ib1_rptr); 3015 1.1 riastrad seq_printf(m, "Indirect1 wptr %u\n", ib1_wptr); 3016 1.1 riastrad seq_printf(m, "Indirect2 rptr %u\n", ib2_rptr); 3017 1.1 riastrad seq_printf(m, "Indirect2 wptr %u\n", ib2_wptr); 3018 1.1 riastrad /* FIXME: 0, 128, 640 depends on fifo setup see cp_init_kms 3019 1.1 riastrad * 128 = indirect1_start * 8 & 640 = indirect2_start * 8 */ 3020 1.1 riastrad seq_printf(m, "Ring fifo:\n"); 3021 1.1 riastrad for (i = 0; i < 256; i++) { 3022 1.1 riastrad WREG32(RADEON_CP_CSQ_ADDR, i << 2); 3023 1.1 riastrad tmp = RREG32(RADEON_CP_CSQ_DATA); 3024 1.1 riastrad seq_printf(m, "rfifo[%04d]=0x%08X\n", i, tmp); 3025 1.1 riastrad } 3026 1.1 riastrad seq_printf(m, "Indirect1 fifo:\n"); 3027 1.1 riastrad for (i = 256; i <= 512; i++) { 3028 1.1 riastrad WREG32(RADEON_CP_CSQ_ADDR, i << 2); 3029 1.1 riastrad tmp = RREG32(RADEON_CP_CSQ_DATA); 3030 1.1 riastrad seq_printf(m, "ib1fifo[%04d]=0x%08X\n", i, tmp); 3031 1.1 riastrad } 3032 1.1 riastrad seq_printf(m, "Indirect2 fifo:\n"); 3033 1.1 riastrad for (i = 640; i < ib1_wptr; i++) { 3034 1.1 riastrad WREG32(RADEON_CP_CSQ_ADDR, i << 2); 3035 1.1 riastrad tmp = RREG32(RADEON_CP_CSQ_DATA); 3036 1.1 riastrad seq_printf(m, "ib2fifo[%04d]=0x%08X\n", i, tmp); 3037 1.1 riastrad } 3038 1.1 riastrad return 0; 3039 1.1 riastrad } 3040 1.1 riastrad 3041 1.1 riastrad static int r100_debugfs_mc_info(struct seq_file *m, void *data) 3042 1.1 riastrad { 3043 1.1 riastrad struct drm_info_node *node = (struct drm_info_node *) m->private; 3044 1.1 riastrad struct drm_device *dev = node->minor->dev; 3045 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 3046 1.1 riastrad uint32_t tmp; 3047 1.1 riastrad 3048 1.1 riastrad tmp = RREG32(RADEON_CONFIG_MEMSIZE); 3049 1.1 riastrad seq_printf(m, "CONFIG_MEMSIZE 0x%08x\n", tmp); 3050 1.1 riastrad tmp = RREG32(RADEON_MC_FB_LOCATION); 3051 1.1 riastrad seq_printf(m, "MC_FB_LOCATION 0x%08x\n", tmp); 3052 1.1 riastrad tmp = RREG32(RADEON_BUS_CNTL); 3053 1.1 riastrad seq_printf(m, "BUS_CNTL 0x%08x\n", tmp); 3054 1.1 riastrad tmp = RREG32(RADEON_MC_AGP_LOCATION); 3055 1.1 riastrad seq_printf(m, "MC_AGP_LOCATION 0x%08x\n", tmp); 3056 1.1 riastrad tmp = RREG32(RADEON_AGP_BASE); 3057 1.1 riastrad seq_printf(m, "AGP_BASE 0x%08x\n", tmp); 3058 1.1 riastrad tmp = RREG32(RADEON_HOST_PATH_CNTL); 3059 1.1 riastrad seq_printf(m, "HOST_PATH_CNTL 0x%08x\n", tmp); 3060 1.1 riastrad tmp = RREG32(0x01D0); 3061 1.1 riastrad seq_printf(m, "AIC_CTRL 0x%08x\n", tmp); 3062 1.1 riastrad tmp = RREG32(RADEON_AIC_LO_ADDR); 3063 1.1 riastrad seq_printf(m, "AIC_LO_ADDR 0x%08x\n", tmp); 3064 1.1 riastrad tmp = RREG32(RADEON_AIC_HI_ADDR); 3065 1.1 riastrad seq_printf(m, "AIC_HI_ADDR 0x%08x\n", tmp); 3066 1.1 riastrad tmp = RREG32(0x01E4); 3067 1.1 riastrad seq_printf(m, "AIC_TLB_ADDR 0x%08x\n", tmp); 3068 1.1 riastrad return 0; 3069 1.1 riastrad } 3070 1.1 riastrad 3071 1.1 riastrad static struct drm_info_list r100_debugfs_rbbm_list[] = { 3072 1.1 riastrad {"r100_rbbm_info", r100_debugfs_rbbm_info, 0, NULL}, 3073 1.1 riastrad }; 3074 1.1 riastrad 3075 1.1 riastrad static struct drm_info_list r100_debugfs_cp_list[] = { 3076 1.1 riastrad {"r100_cp_ring_info", r100_debugfs_cp_ring_info, 0, NULL}, 3077 1.1 riastrad {"r100_cp_csq_fifo", r100_debugfs_cp_csq_fifo, 0, NULL}, 3078 1.1 riastrad }; 3079 1.1 riastrad 3080 1.1 riastrad static struct drm_info_list r100_debugfs_mc_info_list[] = { 3081 1.1 riastrad {"r100_mc_info", r100_debugfs_mc_info, 0, NULL}, 3082 1.1 riastrad }; 3083 1.1 riastrad #endif 3084 1.1 riastrad 3085 1.1 riastrad int r100_debugfs_rbbm_init(struct radeon_device *rdev) 3086 1.1 riastrad { 3087 1.1 riastrad #if defined(CONFIG_DEBUG_FS) 3088 1.1 riastrad return radeon_debugfs_add_files(rdev, r100_debugfs_rbbm_list, 1); 3089 1.1 riastrad #else 3090 1.1 riastrad return 0; 3091 1.1 riastrad #endif 3092 1.1 riastrad } 3093 1.1 riastrad 3094 1.1 riastrad int r100_debugfs_cp_init(struct radeon_device *rdev) 3095 1.1 riastrad { 3096 1.1 riastrad #if defined(CONFIG_DEBUG_FS) 3097 1.1 riastrad return radeon_debugfs_add_files(rdev, r100_debugfs_cp_list, 2); 3098 1.1 riastrad #else 3099 1.1 riastrad return 0; 3100 1.1 riastrad #endif 3101 1.1 riastrad } 3102 1.1 riastrad 3103 1.1 riastrad int r100_debugfs_mc_info_init(struct radeon_device *rdev) 3104 1.1 riastrad { 3105 1.1 riastrad #if defined(CONFIG_DEBUG_FS) 3106 1.1 riastrad return radeon_debugfs_add_files(rdev, r100_debugfs_mc_info_list, 1); 3107 1.1 riastrad #else 3108 1.1 riastrad return 0; 3109 1.1 riastrad #endif 3110 1.1 riastrad } 3111 1.1 riastrad 3112 1.1 riastrad int r100_set_surface_reg(struct radeon_device *rdev, int reg, 3113 1.1 riastrad uint32_t tiling_flags, uint32_t pitch, 3114 1.1 riastrad uint32_t offset, uint32_t obj_size) 3115 1.1 riastrad { 3116 1.1 riastrad int surf_index = reg * 16; 3117 1.1 riastrad int flags = 0; 3118 1.1 riastrad 3119 1.1 riastrad if (rdev->family <= CHIP_RS200) { 3120 1.1 riastrad if ((tiling_flags & (RADEON_TILING_MACRO|RADEON_TILING_MICRO)) 3121 1.1 riastrad == (RADEON_TILING_MACRO|RADEON_TILING_MICRO)) 3122 1.1 riastrad flags |= RADEON_SURF_TILE_COLOR_BOTH; 3123 1.1 riastrad if (tiling_flags & RADEON_TILING_MACRO) 3124 1.1 riastrad flags |= RADEON_SURF_TILE_COLOR_MACRO; 3125 1.1 riastrad /* setting pitch to 0 disables tiling */ 3126 1.1 riastrad if ((tiling_flags & (RADEON_TILING_MACRO|RADEON_TILING_MICRO)) 3127 1.1 riastrad == 0) 3128 1.1 riastrad pitch = 0; 3129 1.1 riastrad } else if (rdev->family <= CHIP_RV280) { 3130 1.1 riastrad if (tiling_flags & (RADEON_TILING_MACRO)) 3131 1.1 riastrad flags |= R200_SURF_TILE_COLOR_MACRO; 3132 1.1 riastrad if (tiling_flags & RADEON_TILING_MICRO) 3133 1.1 riastrad flags |= R200_SURF_TILE_COLOR_MICRO; 3134 1.1 riastrad } else { 3135 1.1 riastrad if (tiling_flags & RADEON_TILING_MACRO) 3136 1.1 riastrad flags |= R300_SURF_TILE_MACRO; 3137 1.1 riastrad if (tiling_flags & RADEON_TILING_MICRO) 3138 1.1 riastrad flags |= R300_SURF_TILE_MICRO; 3139 1.1 riastrad } 3140 1.1 riastrad 3141 1.1 riastrad if (tiling_flags & RADEON_TILING_SWAP_16BIT) 3142 1.1 riastrad flags |= RADEON_SURF_AP0_SWP_16BPP | RADEON_SURF_AP1_SWP_16BPP; 3143 1.1 riastrad if (tiling_flags & RADEON_TILING_SWAP_32BIT) 3144 1.1 riastrad flags |= RADEON_SURF_AP0_SWP_32BPP | RADEON_SURF_AP1_SWP_32BPP; 3145 1.1 riastrad 3146 1.1 riastrad /* r100/r200 divide by 16 */ 3147 1.1 riastrad if (rdev->family < CHIP_R300) 3148 1.1 riastrad flags |= pitch / 16; 3149 1.1 riastrad else 3150 1.1 riastrad flags |= pitch / 8; 3151 1.1 riastrad 3152 1.1 riastrad 3153 1.1 riastrad DRM_DEBUG_KMS("writing surface %d %d %x %x\n", reg, flags, offset, offset+obj_size-1); 3154 1.1 riastrad WREG32(RADEON_SURFACE0_INFO + surf_index, flags); 3155 1.1 riastrad WREG32(RADEON_SURFACE0_LOWER_BOUND + surf_index, offset); 3156 1.1 riastrad WREG32(RADEON_SURFACE0_UPPER_BOUND + surf_index, offset + obj_size - 1); 3157 1.1 riastrad return 0; 3158 1.1 riastrad } 3159 1.1 riastrad 3160 1.1 riastrad void r100_clear_surface_reg(struct radeon_device *rdev, int reg) 3161 1.1 riastrad { 3162 1.1 riastrad int surf_index = reg * 16; 3163 1.1 riastrad WREG32(RADEON_SURFACE0_INFO + surf_index, 0); 3164 1.1 riastrad } 3165 1.1 riastrad 3166 1.1 riastrad void r100_bandwidth_update(struct radeon_device *rdev) 3167 1.1 riastrad { 3168 1.1 riastrad fixed20_12 trcd_ff, trp_ff, tras_ff, trbs_ff, tcas_ff; 3169 1.1 riastrad fixed20_12 sclk_ff, mclk_ff, sclk_eff_ff, sclk_delay_ff; 3170 1.2 riastrad fixed20_12 peak_disp_bw, mem_bw, pix_clk, pix_clk2, temp_ff; 3171 1.2 riastrad fixed20_12 crit_point_ff = {0}; 3172 1.1 riastrad uint32_t temp, data, mem_trcd, mem_trp, mem_tras; 3173 1.1 riastrad fixed20_12 memtcas_ff[8] = { 3174 1.1 riastrad dfixed_init(1), 3175 1.1 riastrad dfixed_init(2), 3176 1.1 riastrad dfixed_init(3), 3177 1.1 riastrad dfixed_init(0), 3178 1.1 riastrad dfixed_init_half(1), 3179 1.1 riastrad dfixed_init_half(2), 3180 1.1 riastrad dfixed_init(0), 3181 1.1 riastrad }; 3182 1.1 riastrad fixed20_12 memtcas_rs480_ff[8] = { 3183 1.1 riastrad dfixed_init(0), 3184 1.1 riastrad dfixed_init(1), 3185 1.1 riastrad dfixed_init(2), 3186 1.1 riastrad dfixed_init(3), 3187 1.1 riastrad dfixed_init(0), 3188 1.1 riastrad dfixed_init_half(1), 3189 1.1 riastrad dfixed_init_half(2), 3190 1.1 riastrad dfixed_init_half(3), 3191 1.1 riastrad }; 3192 1.1 riastrad fixed20_12 memtcas2_ff[8] = { 3193 1.1 riastrad dfixed_init(0), 3194 1.1 riastrad dfixed_init(1), 3195 1.1 riastrad dfixed_init(2), 3196 1.1 riastrad dfixed_init(3), 3197 1.1 riastrad dfixed_init(4), 3198 1.1 riastrad dfixed_init(5), 3199 1.1 riastrad dfixed_init(6), 3200 1.1 riastrad dfixed_init(7), 3201 1.1 riastrad }; 3202 1.1 riastrad fixed20_12 memtrbs[8] = { 3203 1.1 riastrad dfixed_init(1), 3204 1.1 riastrad dfixed_init_half(1), 3205 1.1 riastrad dfixed_init(2), 3206 1.1 riastrad dfixed_init_half(2), 3207 1.1 riastrad dfixed_init(3), 3208 1.1 riastrad dfixed_init_half(3), 3209 1.1 riastrad dfixed_init(4), 3210 1.1 riastrad dfixed_init_half(4) 3211 1.1 riastrad }; 3212 1.1 riastrad fixed20_12 memtrbs_r4xx[8] = { 3213 1.1 riastrad dfixed_init(4), 3214 1.1 riastrad dfixed_init(5), 3215 1.1 riastrad dfixed_init(6), 3216 1.1 riastrad dfixed_init(7), 3217 1.1 riastrad dfixed_init(8), 3218 1.1 riastrad dfixed_init(9), 3219 1.1 riastrad dfixed_init(10), 3220 1.1 riastrad dfixed_init(11) 3221 1.1 riastrad }; 3222 1.1 riastrad fixed20_12 min_mem_eff; 3223 1.1 riastrad fixed20_12 mc_latency_sclk, mc_latency_mclk, k1; 3224 1.1 riastrad fixed20_12 cur_latency_mclk, cur_latency_sclk; 3225 1.2 riastrad fixed20_12 disp_latency, disp_latency_overhead, disp_drain_rate = {0}, 3226 1.1 riastrad disp_drain_rate2, read_return_rate; 3227 1.1 riastrad fixed20_12 time_disp1_drop_priority; 3228 1.1 riastrad int c; 3229 1.1 riastrad int cur_size = 16; /* in octawords */ 3230 1.1 riastrad int critical_point = 0, critical_point2; 3231 1.1 riastrad /* uint32_t read_return_rate, time_disp1_drop_priority; */ 3232 1.1 riastrad int stop_req, max_stop_req; 3233 1.1 riastrad struct drm_display_mode *mode1 = NULL; 3234 1.1 riastrad struct drm_display_mode *mode2 = NULL; 3235 1.1 riastrad uint32_t pixel_bytes1 = 0; 3236 1.1 riastrad uint32_t pixel_bytes2 = 0; 3237 1.1 riastrad 3238 1.1 riastrad /* Guess line buffer size to be 8192 pixels */ 3239 1.1 riastrad u32 lb_size = 8192; 3240 1.1 riastrad 3241 1.1 riastrad if (!rdev->mode_info.mode_config_initialized) 3242 1.1 riastrad return; 3243 1.1 riastrad 3244 1.1 riastrad crit_point_ff.full = 0; 3245 1.1 riastrad disp_drain_rate.full = 0; 3246 1.1 riastrad 3247 1.1 riastrad radeon_update_display_priority(rdev); 3248 1.1 riastrad 3249 1.1 riastrad if (rdev->mode_info.crtcs[0]->base.enabled) { 3250 1.2 riastrad const struct drm_framebuffer *fb = 3251 1.2 riastrad rdev->mode_info.crtcs[0]->base.primary->fb; 3252 1.2 riastrad 3253 1.1 riastrad mode1 = &rdev->mode_info.crtcs[0]->base.mode; 3254 1.2 riastrad pixel_bytes1 = fb->format->cpp[0]; 3255 1.1 riastrad } 3256 1.1 riastrad if (!(rdev->flags & RADEON_SINGLE_CRTC)) { 3257 1.1 riastrad if (rdev->mode_info.crtcs[1]->base.enabled) { 3258 1.2 riastrad const struct drm_framebuffer *fb = 3259 1.2 riastrad rdev->mode_info.crtcs[1]->base.primary->fb; 3260 1.2 riastrad 3261 1.1 riastrad mode2 = &rdev->mode_info.crtcs[1]->base.mode; 3262 1.2 riastrad pixel_bytes2 = fb->format->cpp[0]; 3263 1.1 riastrad } 3264 1.1 riastrad } 3265 1.1 riastrad 3266 1.1 riastrad min_mem_eff.full = dfixed_const_8(0); 3267 1.1 riastrad /* get modes */ 3268 1.1 riastrad if ((rdev->disp_priority == 2) && ASIC_IS_R300(rdev)) { 3269 1.1 riastrad uint32_t mc_init_misc_lat_timer = RREG32(R300_MC_INIT_MISC_LAT_TIMER); 3270 1.1 riastrad mc_init_misc_lat_timer &= ~(R300_MC_DISP1R_INIT_LAT_MASK << R300_MC_DISP1R_INIT_LAT_SHIFT); 3271 1.1 riastrad mc_init_misc_lat_timer &= ~(R300_MC_DISP0R_INIT_LAT_MASK << R300_MC_DISP0R_INIT_LAT_SHIFT); 3272 1.1 riastrad /* check crtc enables */ 3273 1.1 riastrad if (mode2) 3274 1.1 riastrad mc_init_misc_lat_timer |= (1 << R300_MC_DISP1R_INIT_LAT_SHIFT); 3275 1.1 riastrad if (mode1) 3276 1.1 riastrad mc_init_misc_lat_timer |= (1 << R300_MC_DISP0R_INIT_LAT_SHIFT); 3277 1.1 riastrad WREG32(R300_MC_INIT_MISC_LAT_TIMER, mc_init_misc_lat_timer); 3278 1.1 riastrad } 3279 1.1 riastrad 3280 1.1 riastrad /* 3281 1.1 riastrad * determine is there is enough bw for current mode 3282 1.1 riastrad */ 3283 1.1 riastrad sclk_ff = rdev->pm.sclk; 3284 1.1 riastrad mclk_ff = rdev->pm.mclk; 3285 1.1 riastrad 3286 1.1 riastrad temp = (rdev->mc.vram_width / 8) * (rdev->mc.vram_is_ddr ? 2 : 1); 3287 1.1 riastrad temp_ff.full = dfixed_const(temp); 3288 1.1 riastrad mem_bw.full = dfixed_mul(mclk_ff, temp_ff); 3289 1.1 riastrad 3290 1.1 riastrad pix_clk.full = 0; 3291 1.1 riastrad pix_clk2.full = 0; 3292 1.1 riastrad peak_disp_bw.full = 0; 3293 1.1 riastrad if (mode1) { 3294 1.1 riastrad temp_ff.full = dfixed_const(1000); 3295 1.1 riastrad pix_clk.full = dfixed_const(mode1->clock); /* convert to fixed point */ 3296 1.1 riastrad pix_clk.full = dfixed_div(pix_clk, temp_ff); 3297 1.1 riastrad temp_ff.full = dfixed_const(pixel_bytes1); 3298 1.1 riastrad peak_disp_bw.full += dfixed_mul(pix_clk, temp_ff); 3299 1.1 riastrad } 3300 1.1 riastrad if (mode2) { 3301 1.1 riastrad temp_ff.full = dfixed_const(1000); 3302 1.1 riastrad pix_clk2.full = dfixed_const(mode2->clock); /* convert to fixed point */ 3303 1.1 riastrad pix_clk2.full = dfixed_div(pix_clk2, temp_ff); 3304 1.1 riastrad temp_ff.full = dfixed_const(pixel_bytes2); 3305 1.1 riastrad peak_disp_bw.full += dfixed_mul(pix_clk2, temp_ff); 3306 1.1 riastrad } 3307 1.1 riastrad 3308 1.1 riastrad mem_bw.full = dfixed_mul(mem_bw, min_mem_eff); 3309 1.1 riastrad if (peak_disp_bw.full >= mem_bw.full) { 3310 1.1 riastrad DRM_ERROR("You may not have enough display bandwidth for current mode\n" 3311 1.1 riastrad "If you have flickering problem, try to lower resolution, refresh rate, or color depth\n"); 3312 1.1 riastrad } 3313 1.1 riastrad 3314 1.1 riastrad /* Get values from the EXT_MEM_CNTL register...converting its contents. */ 3315 1.1 riastrad temp = RREG32(RADEON_MEM_TIMING_CNTL); 3316 1.1 riastrad if ((rdev->family == CHIP_RV100) || (rdev->flags & RADEON_IS_IGP)) { /* RV100, M6, IGPs */ 3317 1.1 riastrad mem_trcd = ((temp >> 2) & 0x3) + 1; 3318 1.1 riastrad mem_trp = ((temp & 0x3)) + 1; 3319 1.1 riastrad mem_tras = ((temp & 0x70) >> 4) + 1; 3320 1.1 riastrad } else if (rdev->family == CHIP_R300 || 3321 1.1 riastrad rdev->family == CHIP_R350) { /* r300, r350 */ 3322 1.1 riastrad mem_trcd = (temp & 0x7) + 1; 3323 1.1 riastrad mem_trp = ((temp >> 8) & 0x7) + 1; 3324 1.1 riastrad mem_tras = ((temp >> 11) & 0xf) + 4; 3325 1.1 riastrad } else if (rdev->family == CHIP_RV350 || 3326 1.2 riastrad rdev->family == CHIP_RV380) { 3327 1.1 riastrad /* rv3x0 */ 3328 1.1 riastrad mem_trcd = (temp & 0x7) + 3; 3329 1.1 riastrad mem_trp = ((temp >> 8) & 0x7) + 3; 3330 1.1 riastrad mem_tras = ((temp >> 11) & 0xf) + 6; 3331 1.1 riastrad } else if (rdev->family == CHIP_R420 || 3332 1.1 riastrad rdev->family == CHIP_R423 || 3333 1.1 riastrad rdev->family == CHIP_RV410) { 3334 1.1 riastrad /* r4xx */ 3335 1.1 riastrad mem_trcd = (temp & 0xf) + 3; 3336 1.1 riastrad if (mem_trcd > 15) 3337 1.1 riastrad mem_trcd = 15; 3338 1.1 riastrad mem_trp = ((temp >> 8) & 0xf) + 3; 3339 1.1 riastrad if (mem_trp > 15) 3340 1.1 riastrad mem_trp = 15; 3341 1.1 riastrad mem_tras = ((temp >> 12) & 0x1f) + 6; 3342 1.1 riastrad if (mem_tras > 31) 3343 1.1 riastrad mem_tras = 31; 3344 1.1 riastrad } else { /* RV200, R200 */ 3345 1.1 riastrad mem_trcd = (temp & 0x7) + 1; 3346 1.1 riastrad mem_trp = ((temp >> 8) & 0x7) + 1; 3347 1.1 riastrad mem_tras = ((temp >> 12) & 0xf) + 4; 3348 1.1 riastrad } 3349 1.1 riastrad /* convert to FF */ 3350 1.1 riastrad trcd_ff.full = dfixed_const(mem_trcd); 3351 1.1 riastrad trp_ff.full = dfixed_const(mem_trp); 3352 1.1 riastrad tras_ff.full = dfixed_const(mem_tras); 3353 1.1 riastrad 3354 1.1 riastrad /* Get values from the MEM_SDRAM_MODE_REG register...converting its */ 3355 1.1 riastrad temp = RREG32(RADEON_MEM_SDRAM_MODE_REG); 3356 1.1 riastrad data = (temp & (7 << 20)) >> 20; 3357 1.1 riastrad if ((rdev->family == CHIP_RV100) || rdev->flags & RADEON_IS_IGP) { 3358 1.1 riastrad if (rdev->family == CHIP_RS480) /* don't think rs400 */ 3359 1.1 riastrad tcas_ff = memtcas_rs480_ff[data]; 3360 1.1 riastrad else 3361 1.1 riastrad tcas_ff = memtcas_ff[data]; 3362 1.1 riastrad } else 3363 1.1 riastrad tcas_ff = memtcas2_ff[data]; 3364 1.1 riastrad 3365 1.1 riastrad if (rdev->family == CHIP_RS400 || 3366 1.1 riastrad rdev->family == CHIP_RS480) { 3367 1.1 riastrad /* extra cas latency stored in bits 23-25 0-4 clocks */ 3368 1.1 riastrad data = (temp >> 23) & 0x7; 3369 1.1 riastrad if (data < 5) 3370 1.1 riastrad tcas_ff.full += dfixed_const(data); 3371 1.1 riastrad } 3372 1.1 riastrad 3373 1.1 riastrad if (ASIC_IS_R300(rdev) && !(rdev->flags & RADEON_IS_IGP)) { 3374 1.1 riastrad /* on the R300, Tcas is included in Trbs. 3375 1.1 riastrad */ 3376 1.1 riastrad temp = RREG32(RADEON_MEM_CNTL); 3377 1.1 riastrad data = (R300_MEM_NUM_CHANNELS_MASK & temp); 3378 1.1 riastrad if (data == 1) { 3379 1.1 riastrad if (R300_MEM_USE_CD_CH_ONLY & temp) { 3380 1.1 riastrad temp = RREG32(R300_MC_IND_INDEX); 3381 1.1 riastrad temp &= ~R300_MC_IND_ADDR_MASK; 3382 1.1 riastrad temp |= R300_MC_READ_CNTL_CD_mcind; 3383 1.1 riastrad WREG32(R300_MC_IND_INDEX, temp); 3384 1.1 riastrad temp = RREG32(R300_MC_IND_DATA); 3385 1.1 riastrad data = (R300_MEM_RBS_POSITION_C_MASK & temp); 3386 1.1 riastrad } else { 3387 1.1 riastrad temp = RREG32(R300_MC_READ_CNTL_AB); 3388 1.1 riastrad data = (R300_MEM_RBS_POSITION_A_MASK & temp); 3389 1.1 riastrad } 3390 1.1 riastrad } else { 3391 1.1 riastrad temp = RREG32(R300_MC_READ_CNTL_AB); 3392 1.1 riastrad data = (R300_MEM_RBS_POSITION_A_MASK & temp); 3393 1.1 riastrad } 3394 1.1 riastrad if (rdev->family == CHIP_RV410 || 3395 1.1 riastrad rdev->family == CHIP_R420 || 3396 1.1 riastrad rdev->family == CHIP_R423) 3397 1.1 riastrad trbs_ff = memtrbs_r4xx[data]; 3398 1.1 riastrad else 3399 1.1 riastrad trbs_ff = memtrbs[data]; 3400 1.1 riastrad tcas_ff.full += trbs_ff.full; 3401 1.1 riastrad } 3402 1.1 riastrad 3403 1.1 riastrad sclk_eff_ff.full = sclk_ff.full; 3404 1.1 riastrad 3405 1.1 riastrad if (rdev->flags & RADEON_IS_AGP) { 3406 1.1 riastrad fixed20_12 agpmode_ff; 3407 1.1 riastrad agpmode_ff.full = dfixed_const(radeon_agpmode); 3408 1.1 riastrad temp_ff.full = dfixed_const_666(16); 3409 1.1 riastrad sclk_eff_ff.full -= dfixed_mul(agpmode_ff, temp_ff); 3410 1.1 riastrad } 3411 1.1 riastrad /* TODO PCIE lanes may affect this - agpmode == 16?? */ 3412 1.1 riastrad 3413 1.1 riastrad if (ASIC_IS_R300(rdev)) { 3414 1.1 riastrad sclk_delay_ff.full = dfixed_const(250); 3415 1.1 riastrad } else { 3416 1.1 riastrad if ((rdev->family == CHIP_RV100) || 3417 1.1 riastrad rdev->flags & RADEON_IS_IGP) { 3418 1.1 riastrad if (rdev->mc.vram_is_ddr) 3419 1.1 riastrad sclk_delay_ff.full = dfixed_const(41); 3420 1.1 riastrad else 3421 1.1 riastrad sclk_delay_ff.full = dfixed_const(33); 3422 1.1 riastrad } else { 3423 1.1 riastrad if (rdev->mc.vram_width == 128) 3424 1.1 riastrad sclk_delay_ff.full = dfixed_const(57); 3425 1.1 riastrad else 3426 1.1 riastrad sclk_delay_ff.full = dfixed_const(41); 3427 1.1 riastrad } 3428 1.1 riastrad } 3429 1.1 riastrad 3430 1.1 riastrad mc_latency_sclk.full = dfixed_div(sclk_delay_ff, sclk_eff_ff); 3431 1.1 riastrad 3432 1.1 riastrad if (rdev->mc.vram_is_ddr) { 3433 1.1 riastrad if (rdev->mc.vram_width == 32) { 3434 1.1 riastrad k1.full = dfixed_const(40); 3435 1.1 riastrad c = 3; 3436 1.1 riastrad } else { 3437 1.1 riastrad k1.full = dfixed_const(20); 3438 1.1 riastrad c = 1; 3439 1.1 riastrad } 3440 1.1 riastrad } else { 3441 1.1 riastrad k1.full = dfixed_const(40); 3442 1.1 riastrad c = 3; 3443 1.1 riastrad } 3444 1.1 riastrad 3445 1.1 riastrad temp_ff.full = dfixed_const(2); 3446 1.1 riastrad mc_latency_mclk.full = dfixed_mul(trcd_ff, temp_ff); 3447 1.1 riastrad temp_ff.full = dfixed_const(c); 3448 1.1 riastrad mc_latency_mclk.full += dfixed_mul(tcas_ff, temp_ff); 3449 1.1 riastrad temp_ff.full = dfixed_const(4); 3450 1.1 riastrad mc_latency_mclk.full += dfixed_mul(tras_ff, temp_ff); 3451 1.1 riastrad mc_latency_mclk.full += dfixed_mul(trp_ff, temp_ff); 3452 1.1 riastrad mc_latency_mclk.full += k1.full; 3453 1.1 riastrad 3454 1.1 riastrad mc_latency_mclk.full = dfixed_div(mc_latency_mclk, mclk_ff); 3455 1.1 riastrad mc_latency_mclk.full += dfixed_div(temp_ff, sclk_eff_ff); 3456 1.1 riastrad 3457 1.1 riastrad /* 3458 1.1 riastrad HW cursor time assuming worst case of full size colour cursor. 3459 1.1 riastrad */ 3460 1.1 riastrad temp_ff.full = dfixed_const((2 * (cur_size - (rdev->mc.vram_is_ddr + 1)))); 3461 1.1 riastrad temp_ff.full += trcd_ff.full; 3462 1.1 riastrad if (temp_ff.full < tras_ff.full) 3463 1.1 riastrad temp_ff.full = tras_ff.full; 3464 1.1 riastrad cur_latency_mclk.full = dfixed_div(temp_ff, mclk_ff); 3465 1.1 riastrad 3466 1.1 riastrad temp_ff.full = dfixed_const(cur_size); 3467 1.1 riastrad cur_latency_sclk.full = dfixed_div(temp_ff, sclk_eff_ff); 3468 1.1 riastrad /* 3469 1.1 riastrad Find the total latency for the display data. 3470 1.1 riastrad */ 3471 1.1 riastrad disp_latency_overhead.full = dfixed_const(8); 3472 1.1 riastrad disp_latency_overhead.full = dfixed_div(disp_latency_overhead, sclk_ff); 3473 1.1 riastrad mc_latency_mclk.full += disp_latency_overhead.full + cur_latency_mclk.full; 3474 1.1 riastrad mc_latency_sclk.full += disp_latency_overhead.full + cur_latency_sclk.full; 3475 1.1 riastrad 3476 1.1 riastrad if (mc_latency_mclk.full > mc_latency_sclk.full) 3477 1.1 riastrad disp_latency.full = mc_latency_mclk.full; 3478 1.1 riastrad else 3479 1.1 riastrad disp_latency.full = mc_latency_sclk.full; 3480 1.1 riastrad 3481 1.1 riastrad /* setup Max GRPH_STOP_REQ default value */ 3482 1.1 riastrad if (ASIC_IS_RV100(rdev)) 3483 1.1 riastrad max_stop_req = 0x5c; 3484 1.1 riastrad else 3485 1.1 riastrad max_stop_req = 0x7c; 3486 1.1 riastrad 3487 1.1 riastrad if (mode1) { 3488 1.1 riastrad /* CRTC1 3489 1.1 riastrad Set GRPH_BUFFER_CNTL register using h/w defined optimal values. 3490 1.1 riastrad GRPH_STOP_REQ <= MIN[ 0x7C, (CRTC_H_DISP + 1) * (bit depth) / 0x10 ] 3491 1.1 riastrad */ 3492 1.1 riastrad stop_req = mode1->hdisplay * pixel_bytes1 / 16; 3493 1.1 riastrad 3494 1.1 riastrad if (stop_req > max_stop_req) 3495 1.1 riastrad stop_req = max_stop_req; 3496 1.1 riastrad 3497 1.1 riastrad /* 3498 1.1 riastrad Find the drain rate of the display buffer. 3499 1.1 riastrad */ 3500 1.1 riastrad temp_ff.full = dfixed_const((16/pixel_bytes1)); 3501 1.1 riastrad disp_drain_rate.full = dfixed_div(pix_clk, temp_ff); 3502 1.1 riastrad 3503 1.1 riastrad /* 3504 1.1 riastrad Find the critical point of the display buffer. 3505 1.1 riastrad */ 3506 1.1 riastrad crit_point_ff.full = dfixed_mul(disp_drain_rate, disp_latency); 3507 1.1 riastrad crit_point_ff.full += dfixed_const_half(0); 3508 1.1 riastrad 3509 1.1 riastrad critical_point = dfixed_trunc(crit_point_ff); 3510 1.1 riastrad 3511 1.1 riastrad if (rdev->disp_priority == 2) { 3512 1.1 riastrad critical_point = 0; 3513 1.1 riastrad } 3514 1.1 riastrad 3515 1.1 riastrad /* 3516 1.1 riastrad The critical point should never be above max_stop_req-4. Setting 3517 1.1 riastrad GRPH_CRITICAL_CNTL = 0 will thus force high priority all the time. 3518 1.1 riastrad */ 3519 1.1 riastrad if (max_stop_req - critical_point < 4) 3520 1.1 riastrad critical_point = 0; 3521 1.1 riastrad 3522 1.1 riastrad if (critical_point == 0 && mode2 && rdev->family == CHIP_R300) { 3523 1.1 riastrad /* some R300 cards have problem with this set to 0, when CRTC2 is enabled.*/ 3524 1.1 riastrad critical_point = 0x10; 3525 1.1 riastrad } 3526 1.1 riastrad 3527 1.1 riastrad temp = RREG32(RADEON_GRPH_BUFFER_CNTL); 3528 1.1 riastrad temp &= ~(RADEON_GRPH_STOP_REQ_MASK); 3529 1.1 riastrad temp |= (stop_req << RADEON_GRPH_STOP_REQ_SHIFT); 3530 1.1 riastrad temp &= ~(RADEON_GRPH_START_REQ_MASK); 3531 1.1 riastrad if ((rdev->family == CHIP_R350) && 3532 1.1 riastrad (stop_req > 0x15)) { 3533 1.1 riastrad stop_req -= 0x10; 3534 1.1 riastrad } 3535 1.1 riastrad temp |= (stop_req << RADEON_GRPH_START_REQ_SHIFT); 3536 1.1 riastrad temp |= RADEON_GRPH_BUFFER_SIZE; 3537 1.1 riastrad temp &= ~(RADEON_GRPH_CRITICAL_CNTL | 3538 1.1 riastrad RADEON_GRPH_CRITICAL_AT_SOF | 3539 1.1 riastrad RADEON_GRPH_STOP_CNTL); 3540 1.1 riastrad /* 3541 1.1 riastrad Write the result into the register. 3542 1.1 riastrad */ 3543 1.1 riastrad WREG32(RADEON_GRPH_BUFFER_CNTL, ((temp & ~RADEON_GRPH_CRITICAL_POINT_MASK) | 3544 1.1 riastrad (critical_point << RADEON_GRPH_CRITICAL_POINT_SHIFT))); 3545 1.1 riastrad 3546 1.1 riastrad #if 0 3547 1.1 riastrad if ((rdev->family == CHIP_RS400) || 3548 1.1 riastrad (rdev->family == CHIP_RS480)) { 3549 1.1 riastrad /* attempt to program RS400 disp regs correctly ??? */ 3550 1.1 riastrad temp = RREG32(RS400_DISP1_REG_CNTL); 3551 1.1 riastrad temp &= ~(RS400_DISP1_START_REQ_LEVEL_MASK | 3552 1.1 riastrad RS400_DISP1_STOP_REQ_LEVEL_MASK); 3553 1.1 riastrad WREG32(RS400_DISP1_REQ_CNTL1, (temp | 3554 1.1 riastrad (critical_point << RS400_DISP1_START_REQ_LEVEL_SHIFT) | 3555 1.1 riastrad (critical_point << RS400_DISP1_STOP_REQ_LEVEL_SHIFT))); 3556 1.1 riastrad temp = RREG32(RS400_DMIF_MEM_CNTL1); 3557 1.1 riastrad temp &= ~(RS400_DISP1_CRITICAL_POINT_START_MASK | 3558 1.1 riastrad RS400_DISP1_CRITICAL_POINT_STOP_MASK); 3559 1.1 riastrad WREG32(RS400_DMIF_MEM_CNTL1, (temp | 3560 1.1 riastrad (critical_point << RS400_DISP1_CRITICAL_POINT_START_SHIFT) | 3561 1.1 riastrad (critical_point << RS400_DISP1_CRITICAL_POINT_STOP_SHIFT))); 3562 1.1 riastrad } 3563 1.1 riastrad #endif 3564 1.1 riastrad 3565 1.1 riastrad DRM_DEBUG_KMS("GRPH_BUFFER_CNTL from to %x\n", 3566 1.1 riastrad /* (unsigned int)info->SavedReg->grph_buffer_cntl, */ 3567 1.1 riastrad (unsigned int)RREG32(RADEON_GRPH_BUFFER_CNTL)); 3568 1.1 riastrad } 3569 1.1 riastrad 3570 1.1 riastrad if (mode2) { 3571 1.1 riastrad u32 grph2_cntl; 3572 1.1 riastrad stop_req = mode2->hdisplay * pixel_bytes2 / 16; 3573 1.1 riastrad 3574 1.1 riastrad if (stop_req > max_stop_req) 3575 1.1 riastrad stop_req = max_stop_req; 3576 1.1 riastrad 3577 1.1 riastrad /* 3578 1.1 riastrad Find the drain rate of the display buffer. 3579 1.1 riastrad */ 3580 1.1 riastrad temp_ff.full = dfixed_const((16/pixel_bytes2)); 3581 1.1 riastrad disp_drain_rate2.full = dfixed_div(pix_clk2, temp_ff); 3582 1.1 riastrad 3583 1.1 riastrad grph2_cntl = RREG32(RADEON_GRPH2_BUFFER_CNTL); 3584 1.1 riastrad grph2_cntl &= ~(RADEON_GRPH_STOP_REQ_MASK); 3585 1.1 riastrad grph2_cntl |= (stop_req << RADEON_GRPH_STOP_REQ_SHIFT); 3586 1.1 riastrad grph2_cntl &= ~(RADEON_GRPH_START_REQ_MASK); 3587 1.1 riastrad if ((rdev->family == CHIP_R350) && 3588 1.1 riastrad (stop_req > 0x15)) { 3589 1.1 riastrad stop_req -= 0x10; 3590 1.1 riastrad } 3591 1.1 riastrad grph2_cntl |= (stop_req << RADEON_GRPH_START_REQ_SHIFT); 3592 1.1 riastrad grph2_cntl |= RADEON_GRPH_BUFFER_SIZE; 3593 1.1 riastrad grph2_cntl &= ~(RADEON_GRPH_CRITICAL_CNTL | 3594 1.1 riastrad RADEON_GRPH_CRITICAL_AT_SOF | 3595 1.1 riastrad RADEON_GRPH_STOP_CNTL); 3596 1.1 riastrad 3597 1.1 riastrad if ((rdev->family == CHIP_RS100) || 3598 1.1 riastrad (rdev->family == CHIP_RS200)) 3599 1.1 riastrad critical_point2 = 0; 3600 1.1 riastrad else { 3601 1.1 riastrad temp = (rdev->mc.vram_width * rdev->mc.vram_is_ddr + 1)/128; 3602 1.1 riastrad temp_ff.full = dfixed_const(temp); 3603 1.1 riastrad temp_ff.full = dfixed_mul(mclk_ff, temp_ff); 3604 1.1 riastrad if (sclk_ff.full < temp_ff.full) 3605 1.1 riastrad temp_ff.full = sclk_ff.full; 3606 1.1 riastrad 3607 1.1 riastrad read_return_rate.full = temp_ff.full; 3608 1.1 riastrad 3609 1.1 riastrad if (mode1) { 3610 1.1 riastrad temp_ff.full = read_return_rate.full - disp_drain_rate.full; 3611 1.1 riastrad time_disp1_drop_priority.full = dfixed_div(crit_point_ff, temp_ff); 3612 1.1 riastrad } else { 3613 1.1 riastrad time_disp1_drop_priority.full = 0; 3614 1.1 riastrad } 3615 1.1 riastrad crit_point_ff.full = disp_latency.full + time_disp1_drop_priority.full + disp_latency.full; 3616 1.1 riastrad crit_point_ff.full = dfixed_mul(crit_point_ff, disp_drain_rate2); 3617 1.1 riastrad crit_point_ff.full += dfixed_const_half(0); 3618 1.1 riastrad 3619 1.1 riastrad critical_point2 = dfixed_trunc(crit_point_ff); 3620 1.1 riastrad 3621 1.1 riastrad if (rdev->disp_priority == 2) { 3622 1.1 riastrad critical_point2 = 0; 3623 1.1 riastrad } 3624 1.1 riastrad 3625 1.1 riastrad if (max_stop_req - critical_point2 < 4) 3626 1.1 riastrad critical_point2 = 0; 3627 1.1 riastrad 3628 1.1 riastrad } 3629 1.1 riastrad 3630 1.1 riastrad if (critical_point2 == 0 && rdev->family == CHIP_R300) { 3631 1.1 riastrad /* some R300 cards have problem with this set to 0 */ 3632 1.1 riastrad critical_point2 = 0x10; 3633 1.1 riastrad } 3634 1.1 riastrad 3635 1.1 riastrad WREG32(RADEON_GRPH2_BUFFER_CNTL, ((grph2_cntl & ~RADEON_GRPH_CRITICAL_POINT_MASK) | 3636 1.1 riastrad (critical_point2 << RADEON_GRPH_CRITICAL_POINT_SHIFT))); 3637 1.1 riastrad 3638 1.1 riastrad if ((rdev->family == CHIP_RS400) || 3639 1.1 riastrad (rdev->family == CHIP_RS480)) { 3640 1.1 riastrad #if 0 3641 1.1 riastrad /* attempt to program RS400 disp2 regs correctly ??? */ 3642 1.1 riastrad temp = RREG32(RS400_DISP2_REQ_CNTL1); 3643 1.1 riastrad temp &= ~(RS400_DISP2_START_REQ_LEVEL_MASK | 3644 1.1 riastrad RS400_DISP2_STOP_REQ_LEVEL_MASK); 3645 1.1 riastrad WREG32(RS400_DISP2_REQ_CNTL1, (temp | 3646 1.1 riastrad (critical_point2 << RS400_DISP1_START_REQ_LEVEL_SHIFT) | 3647 1.1 riastrad (critical_point2 << RS400_DISP1_STOP_REQ_LEVEL_SHIFT))); 3648 1.1 riastrad temp = RREG32(RS400_DISP2_REQ_CNTL2); 3649 1.1 riastrad temp &= ~(RS400_DISP2_CRITICAL_POINT_START_MASK | 3650 1.1 riastrad RS400_DISP2_CRITICAL_POINT_STOP_MASK); 3651 1.1 riastrad WREG32(RS400_DISP2_REQ_CNTL2, (temp | 3652 1.1 riastrad (critical_point2 << RS400_DISP2_CRITICAL_POINT_START_SHIFT) | 3653 1.1 riastrad (critical_point2 << RS400_DISP2_CRITICAL_POINT_STOP_SHIFT))); 3654 1.1 riastrad #endif 3655 1.1 riastrad WREG32(RS400_DISP2_REQ_CNTL1, 0x105DC1CC); 3656 1.1 riastrad WREG32(RS400_DISP2_REQ_CNTL2, 0x2749D000); 3657 1.1 riastrad WREG32(RS400_DMIF_MEM_CNTL1, 0x29CA71DC); 3658 1.1 riastrad WREG32(RS400_DISP1_REQ_CNTL1, 0x28FBC3AC); 3659 1.1 riastrad } 3660 1.1 riastrad 3661 1.1 riastrad DRM_DEBUG_KMS("GRPH2_BUFFER_CNTL from to %x\n", 3662 1.1 riastrad (unsigned int)RREG32(RADEON_GRPH2_BUFFER_CNTL)); 3663 1.1 riastrad } 3664 1.1 riastrad 3665 1.1 riastrad /* Save number of lines the linebuffer leads before the scanout */ 3666 1.1 riastrad if (mode1) 3667 1.1 riastrad rdev->mode_info.crtcs[0]->lb_vblank_lead_lines = DIV_ROUND_UP(lb_size, mode1->crtc_hdisplay); 3668 1.1 riastrad 3669 1.1 riastrad if (mode2) 3670 1.1 riastrad rdev->mode_info.crtcs[1]->lb_vblank_lead_lines = DIV_ROUND_UP(lb_size, mode2->crtc_hdisplay); 3671 1.1 riastrad } 3672 1.1 riastrad 3673 1.1 riastrad int r100_ring_test(struct radeon_device *rdev, struct radeon_ring *ring) 3674 1.1 riastrad { 3675 1.1 riastrad uint32_t scratch; 3676 1.1 riastrad uint32_t tmp = 0; 3677 1.1 riastrad unsigned i; 3678 1.1 riastrad int r; 3679 1.1 riastrad 3680 1.1 riastrad r = radeon_scratch_get(rdev, &scratch); 3681 1.1 riastrad if (r) { 3682 1.1 riastrad DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r); 3683 1.1 riastrad return r; 3684 1.1 riastrad } 3685 1.1 riastrad WREG32(scratch, 0xCAFEDEAD); 3686 1.1 riastrad r = radeon_ring_lock(rdev, ring, 2); 3687 1.1 riastrad if (r) { 3688 1.1 riastrad DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r); 3689 1.1 riastrad radeon_scratch_free(rdev, scratch); 3690 1.1 riastrad return r; 3691 1.1 riastrad } 3692 1.1 riastrad radeon_ring_write(ring, PACKET0(scratch, 0)); 3693 1.1 riastrad radeon_ring_write(ring, 0xDEADBEEF); 3694 1.1 riastrad radeon_ring_unlock_commit(rdev, ring, false); 3695 1.1 riastrad for (i = 0; i < rdev->usec_timeout; i++) { 3696 1.1 riastrad tmp = RREG32(scratch); 3697 1.1 riastrad if (tmp == 0xDEADBEEF) { 3698 1.1 riastrad break; 3699 1.1 riastrad } 3700 1.2 riastrad udelay(1); 3701 1.1 riastrad } 3702 1.1 riastrad if (i < rdev->usec_timeout) { 3703 1.1 riastrad DRM_INFO("ring test succeeded in %d usecs\n", i); 3704 1.1 riastrad } else { 3705 1.1 riastrad DRM_ERROR("radeon: ring test failed (scratch(0x%04X)=0x%08X)\n", 3706 1.1 riastrad scratch, tmp); 3707 1.1 riastrad r = -EINVAL; 3708 1.1 riastrad } 3709 1.1 riastrad radeon_scratch_free(rdev, scratch); 3710 1.1 riastrad return r; 3711 1.1 riastrad } 3712 1.1 riastrad 3713 1.1 riastrad void r100_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib) 3714 1.1 riastrad { 3715 1.1 riastrad struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; 3716 1.1 riastrad 3717 1.1 riastrad if (ring->rptr_save_reg) { 3718 1.1 riastrad u32 next_rptr = ring->wptr + 2 + 3; 3719 1.1 riastrad radeon_ring_write(ring, PACKET0(ring->rptr_save_reg, 0)); 3720 1.1 riastrad radeon_ring_write(ring, next_rptr); 3721 1.1 riastrad } 3722 1.1 riastrad 3723 1.1 riastrad radeon_ring_write(ring, PACKET0(RADEON_CP_IB_BASE, 1)); 3724 1.1 riastrad radeon_ring_write(ring, ib->gpu_addr); 3725 1.1 riastrad radeon_ring_write(ring, ib->length_dw); 3726 1.1 riastrad } 3727 1.1 riastrad 3728 1.1 riastrad int r100_ib_test(struct radeon_device *rdev, struct radeon_ring *ring) 3729 1.1 riastrad { 3730 1.1 riastrad struct radeon_ib ib; 3731 1.1 riastrad uint32_t scratch; 3732 1.1 riastrad uint32_t tmp = 0; 3733 1.1 riastrad unsigned i; 3734 1.1 riastrad int r; 3735 1.1 riastrad 3736 1.1 riastrad r = radeon_scratch_get(rdev, &scratch); 3737 1.1 riastrad if (r) { 3738 1.1 riastrad DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r); 3739 1.1 riastrad return r; 3740 1.1 riastrad } 3741 1.1 riastrad WREG32(scratch, 0xCAFEDEAD); 3742 1.1 riastrad r = radeon_ib_get(rdev, RADEON_RING_TYPE_GFX_INDEX, &ib, NULL, 256); 3743 1.1 riastrad if (r) { 3744 1.1 riastrad DRM_ERROR("radeon: failed to get ib (%d).\n", r); 3745 1.1 riastrad goto free_scratch; 3746 1.1 riastrad } 3747 1.1 riastrad ib.ptr[0] = PACKET0(scratch, 0); 3748 1.1 riastrad ib.ptr[1] = 0xDEADBEEF; 3749 1.1 riastrad ib.ptr[2] = PACKET2(0); 3750 1.1 riastrad ib.ptr[3] = PACKET2(0); 3751 1.1 riastrad ib.ptr[4] = PACKET2(0); 3752 1.1 riastrad ib.ptr[5] = PACKET2(0); 3753 1.1 riastrad ib.ptr[6] = PACKET2(0); 3754 1.1 riastrad ib.ptr[7] = PACKET2(0); 3755 1.1 riastrad ib.length_dw = 8; 3756 1.1 riastrad r = radeon_ib_schedule(rdev, &ib, NULL, false); 3757 1.1 riastrad if (r) { 3758 1.1 riastrad DRM_ERROR("radeon: failed to schedule ib (%d).\n", r); 3759 1.1 riastrad goto free_ib; 3760 1.1 riastrad } 3761 1.2 riastrad r = radeon_fence_wait_timeout(ib.fence, false, usecs_to_jiffies( 3762 1.2 riastrad RADEON_USEC_IB_TEST_TIMEOUT)); 3763 1.2 riastrad if (r < 0) { 3764 1.1 riastrad DRM_ERROR("radeon: fence wait failed (%d).\n", r); 3765 1.1 riastrad goto free_ib; 3766 1.2 riastrad } else if (r == 0) { 3767 1.2 riastrad DRM_ERROR("radeon: fence wait timed out.\n"); 3768 1.2 riastrad r = -ETIMEDOUT; 3769 1.2 riastrad goto free_ib; 3770 1.1 riastrad } 3771 1.2 riastrad r = 0; 3772 1.1 riastrad for (i = 0; i < rdev->usec_timeout; i++) { 3773 1.1 riastrad tmp = RREG32(scratch); 3774 1.1 riastrad if (tmp == 0xDEADBEEF) { 3775 1.1 riastrad break; 3776 1.1 riastrad } 3777 1.2 riastrad udelay(1); 3778 1.1 riastrad } 3779 1.1 riastrad if (i < rdev->usec_timeout) { 3780 1.1 riastrad DRM_INFO("ib test succeeded in %u usecs\n", i); 3781 1.1 riastrad } else { 3782 1.1 riastrad DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n", 3783 1.1 riastrad scratch, tmp); 3784 1.1 riastrad r = -EINVAL; 3785 1.1 riastrad } 3786 1.1 riastrad free_ib: 3787 1.1 riastrad radeon_ib_free(rdev, &ib); 3788 1.1 riastrad free_scratch: 3789 1.1 riastrad radeon_scratch_free(rdev, scratch); 3790 1.1 riastrad return r; 3791 1.1 riastrad } 3792 1.1 riastrad 3793 1.1 riastrad void r100_mc_stop(struct radeon_device *rdev, struct r100_mc_save *save) 3794 1.1 riastrad { 3795 1.1 riastrad /* Shutdown CP we shouldn't need to do that but better be safe than 3796 1.1 riastrad * sorry 3797 1.1 riastrad */ 3798 1.1 riastrad rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false; 3799 1.1 riastrad WREG32(R_000740_CP_CSQ_CNTL, 0); 3800 1.1 riastrad 3801 1.1 riastrad /* Save few CRTC registers */ 3802 1.1 riastrad save->GENMO_WT = RREG8(R_0003C2_GENMO_WT); 3803 1.1 riastrad save->CRTC_EXT_CNTL = RREG32(R_000054_CRTC_EXT_CNTL); 3804 1.1 riastrad save->CRTC_GEN_CNTL = RREG32(R_000050_CRTC_GEN_CNTL); 3805 1.1 riastrad save->CUR_OFFSET = RREG32(R_000260_CUR_OFFSET); 3806 1.1 riastrad if (!(rdev->flags & RADEON_SINGLE_CRTC)) { 3807 1.1 riastrad save->CRTC2_GEN_CNTL = RREG32(R_0003F8_CRTC2_GEN_CNTL); 3808 1.1 riastrad save->CUR2_OFFSET = RREG32(R_000360_CUR2_OFFSET); 3809 1.1 riastrad } 3810 1.1 riastrad 3811 1.1 riastrad /* Disable VGA aperture access */ 3812 1.1 riastrad WREG8(R_0003C2_GENMO_WT, C_0003C2_VGA_RAM_EN & save->GENMO_WT); 3813 1.1 riastrad /* Disable cursor, overlay, crtc */ 3814 1.1 riastrad WREG32(R_000260_CUR_OFFSET, save->CUR_OFFSET | S_000260_CUR_LOCK(1)); 3815 1.1 riastrad WREG32(R_000054_CRTC_EXT_CNTL, save->CRTC_EXT_CNTL | 3816 1.1 riastrad S_000054_CRTC_DISPLAY_DIS(1)); 3817 1.1 riastrad WREG32(R_000050_CRTC_GEN_CNTL, 3818 1.1 riastrad (C_000050_CRTC_CUR_EN & save->CRTC_GEN_CNTL) | 3819 1.1 riastrad S_000050_CRTC_DISP_REQ_EN_B(1)); 3820 1.1 riastrad WREG32(R_000420_OV0_SCALE_CNTL, 3821 1.1 riastrad C_000420_OV0_OVERLAY_EN & RREG32(R_000420_OV0_SCALE_CNTL)); 3822 1.1 riastrad WREG32(R_000260_CUR_OFFSET, C_000260_CUR_LOCK & save->CUR_OFFSET); 3823 1.1 riastrad if (!(rdev->flags & RADEON_SINGLE_CRTC)) { 3824 1.1 riastrad WREG32(R_000360_CUR2_OFFSET, save->CUR2_OFFSET | 3825 1.1 riastrad S_000360_CUR2_LOCK(1)); 3826 1.1 riastrad WREG32(R_0003F8_CRTC2_GEN_CNTL, 3827 1.1 riastrad (C_0003F8_CRTC2_CUR_EN & save->CRTC2_GEN_CNTL) | 3828 1.1 riastrad S_0003F8_CRTC2_DISPLAY_DIS(1) | 3829 1.1 riastrad S_0003F8_CRTC2_DISP_REQ_EN_B(1)); 3830 1.1 riastrad WREG32(R_000360_CUR2_OFFSET, 3831 1.1 riastrad C_000360_CUR2_LOCK & save->CUR2_OFFSET); 3832 1.1 riastrad } 3833 1.1 riastrad } 3834 1.1 riastrad 3835 1.1 riastrad void r100_mc_resume(struct radeon_device *rdev, struct r100_mc_save *save) 3836 1.1 riastrad { 3837 1.1 riastrad /* Update base address for crtc */ 3838 1.1 riastrad WREG32(R_00023C_DISPLAY_BASE_ADDR, rdev->mc.vram_start); 3839 1.1 riastrad if (!(rdev->flags & RADEON_SINGLE_CRTC)) { 3840 1.1 riastrad WREG32(R_00033C_CRTC2_DISPLAY_BASE_ADDR, rdev->mc.vram_start); 3841 1.1 riastrad } 3842 1.1 riastrad /* Restore CRTC registers */ 3843 1.1 riastrad WREG8(R_0003C2_GENMO_WT, save->GENMO_WT); 3844 1.1 riastrad WREG32(R_000054_CRTC_EXT_CNTL, save->CRTC_EXT_CNTL); 3845 1.1 riastrad WREG32(R_000050_CRTC_GEN_CNTL, save->CRTC_GEN_CNTL); 3846 1.1 riastrad if (!(rdev->flags & RADEON_SINGLE_CRTC)) { 3847 1.1 riastrad WREG32(R_0003F8_CRTC2_GEN_CNTL, save->CRTC2_GEN_CNTL); 3848 1.1 riastrad } 3849 1.1 riastrad } 3850 1.1 riastrad 3851 1.1 riastrad void r100_vga_render_disable(struct radeon_device *rdev) 3852 1.1 riastrad { 3853 1.1 riastrad u32 tmp; 3854 1.1 riastrad 3855 1.1 riastrad tmp = RREG8(R_0003C2_GENMO_WT); 3856 1.1 riastrad WREG8(R_0003C2_GENMO_WT, C_0003C2_VGA_RAM_EN & tmp); 3857 1.1 riastrad } 3858 1.1 riastrad 3859 1.1 riastrad static void r100_debugfs(struct radeon_device *rdev) 3860 1.1 riastrad { 3861 1.1 riastrad int r; 3862 1.1 riastrad 3863 1.1 riastrad r = r100_debugfs_mc_info_init(rdev); 3864 1.1 riastrad if (r) 3865 1.1 riastrad dev_warn(rdev->dev, "Failed to create r100_mc debugfs file.\n"); 3866 1.1 riastrad } 3867 1.1 riastrad 3868 1.1 riastrad static void r100_mc_program(struct radeon_device *rdev) 3869 1.1 riastrad { 3870 1.1 riastrad struct r100_mc_save save; 3871 1.1 riastrad 3872 1.1 riastrad /* Stops all mc clients */ 3873 1.1 riastrad r100_mc_stop(rdev, &save); 3874 1.1 riastrad if (rdev->flags & RADEON_IS_AGP) { 3875 1.1 riastrad WREG32(R_00014C_MC_AGP_LOCATION, 3876 1.1 riastrad S_00014C_MC_AGP_START(rdev->mc.gtt_start >> 16) | 3877 1.1 riastrad S_00014C_MC_AGP_TOP(rdev->mc.gtt_end >> 16)); 3878 1.1 riastrad WREG32(R_000170_AGP_BASE, lower_32_bits(rdev->mc.agp_base)); 3879 1.1 riastrad if (rdev->family > CHIP_RV200) 3880 1.1 riastrad WREG32(R_00015C_AGP_BASE_2, 3881 1.1 riastrad upper_32_bits(rdev->mc.agp_base) & 0xff); 3882 1.1 riastrad } else { 3883 1.1 riastrad WREG32(R_00014C_MC_AGP_LOCATION, 0x0FFFFFFF); 3884 1.1 riastrad WREG32(R_000170_AGP_BASE, 0); 3885 1.1 riastrad if (rdev->family > CHIP_RV200) 3886 1.1 riastrad WREG32(R_00015C_AGP_BASE_2, 0); 3887 1.1 riastrad } 3888 1.1 riastrad /* Wait for mc idle */ 3889 1.1 riastrad if (r100_mc_wait_for_idle(rdev)) 3890 1.1 riastrad dev_warn(rdev->dev, "Wait for MC idle timeout.\n"); 3891 1.1 riastrad /* Program MC, should be a 32bits limited address space */ 3892 1.1 riastrad WREG32(R_000148_MC_FB_LOCATION, 3893 1.1 riastrad S_000148_MC_FB_START(rdev->mc.vram_start >> 16) | 3894 1.1 riastrad S_000148_MC_FB_TOP(rdev->mc.vram_end >> 16)); 3895 1.1 riastrad r100_mc_resume(rdev, &save); 3896 1.1 riastrad } 3897 1.1 riastrad 3898 1.1 riastrad static void r100_clock_startup(struct radeon_device *rdev) 3899 1.1 riastrad { 3900 1.1 riastrad u32 tmp; 3901 1.1 riastrad 3902 1.1 riastrad if (radeon_dynclks != -1 && radeon_dynclks) 3903 1.1 riastrad radeon_legacy_set_clock_gating(rdev, 1); 3904 1.1 riastrad /* We need to force on some of the block */ 3905 1.1 riastrad tmp = RREG32_PLL(R_00000D_SCLK_CNTL); 3906 1.1 riastrad tmp |= S_00000D_FORCE_CP(1) | S_00000D_FORCE_VIP(1); 3907 1.1 riastrad if ((rdev->family == CHIP_RV250) || (rdev->family == CHIP_RV280)) 3908 1.1 riastrad tmp |= S_00000D_FORCE_DISP1(1) | S_00000D_FORCE_DISP2(1); 3909 1.1 riastrad WREG32_PLL(R_00000D_SCLK_CNTL, tmp); 3910 1.1 riastrad } 3911 1.1 riastrad 3912 1.1 riastrad static int r100_startup(struct radeon_device *rdev) 3913 1.1 riastrad { 3914 1.1 riastrad int r; 3915 1.1 riastrad 3916 1.1 riastrad /* set common regs */ 3917 1.1 riastrad r100_set_common_regs(rdev); 3918 1.1 riastrad /* program mc */ 3919 1.1 riastrad r100_mc_program(rdev); 3920 1.1 riastrad /* Resume clock */ 3921 1.1 riastrad r100_clock_startup(rdev); 3922 1.1 riastrad /* Initialize GART (initialize after TTM so we can allocate 3923 1.1 riastrad * memory through TTM but finalize after TTM) */ 3924 1.1 riastrad r100_enable_bm(rdev); 3925 1.1 riastrad if (rdev->flags & RADEON_IS_PCI) { 3926 1.1 riastrad r = r100_pci_gart_enable(rdev); 3927 1.1 riastrad if (r) 3928 1.1 riastrad return r; 3929 1.1 riastrad } 3930 1.1 riastrad 3931 1.1 riastrad /* allocate wb buffer */ 3932 1.1 riastrad r = radeon_wb_init(rdev); 3933 1.1 riastrad if (r) 3934 1.1 riastrad return r; 3935 1.1 riastrad 3936 1.1 riastrad r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX); 3937 1.1 riastrad if (r) { 3938 1.1 riastrad dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r); 3939 1.1 riastrad return r; 3940 1.1 riastrad } 3941 1.1 riastrad 3942 1.1 riastrad /* Enable IRQ */ 3943 1.1 riastrad if (!rdev->irq.installed) { 3944 1.1 riastrad r = radeon_irq_kms_init(rdev); 3945 1.1 riastrad if (r) 3946 1.1 riastrad return r; 3947 1.1 riastrad } 3948 1.1 riastrad 3949 1.1 riastrad r100_irq_set(rdev); 3950 1.1 riastrad rdev->config.r100.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL); 3951 1.1 riastrad /* 1M ring buffer */ 3952 1.1 riastrad r = r100_cp_init(rdev, 1024 * 1024); 3953 1.1 riastrad if (r) { 3954 1.1 riastrad dev_err(rdev->dev, "failed initializing CP (%d).\n", r); 3955 1.1 riastrad return r; 3956 1.1 riastrad } 3957 1.1 riastrad 3958 1.1 riastrad r = radeon_ib_pool_init(rdev); 3959 1.1 riastrad if (r) { 3960 1.1 riastrad dev_err(rdev->dev, "IB initialization failed (%d).\n", r); 3961 1.1 riastrad return r; 3962 1.1 riastrad } 3963 1.1 riastrad 3964 1.1 riastrad return 0; 3965 1.1 riastrad } 3966 1.1 riastrad 3967 1.1 riastrad int r100_resume(struct radeon_device *rdev) 3968 1.1 riastrad { 3969 1.1 riastrad int r; 3970 1.1 riastrad 3971 1.1 riastrad /* Make sur GART are not working */ 3972 1.1 riastrad if (rdev->flags & RADEON_IS_PCI) 3973 1.1 riastrad r100_pci_gart_disable(rdev); 3974 1.1 riastrad /* Resume clock before doing reset */ 3975 1.1 riastrad r100_clock_startup(rdev); 3976 1.1 riastrad /* Reset gpu before posting otherwise ATOM will enter infinite loop */ 3977 1.1 riastrad if (radeon_asic_reset(rdev)) { 3978 1.1 riastrad dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n", 3979 1.1 riastrad RREG32(R_000E40_RBBM_STATUS), 3980 1.1 riastrad RREG32(R_0007C0_CP_STAT)); 3981 1.1 riastrad } 3982 1.1 riastrad /* post */ 3983 1.1 riastrad radeon_combios_asic_init(rdev->ddev); 3984 1.1 riastrad /* Resume clock after posting */ 3985 1.1 riastrad r100_clock_startup(rdev); 3986 1.1 riastrad /* Initialize surface registers */ 3987 1.1 riastrad radeon_surface_init(rdev); 3988 1.1 riastrad 3989 1.1 riastrad rdev->accel_working = true; 3990 1.1 riastrad r = r100_startup(rdev); 3991 1.1 riastrad if (r) { 3992 1.1 riastrad rdev->accel_working = false; 3993 1.1 riastrad } 3994 1.1 riastrad return r; 3995 1.1 riastrad } 3996 1.1 riastrad 3997 1.1 riastrad int r100_suspend(struct radeon_device *rdev) 3998 1.1 riastrad { 3999 1.1 riastrad radeon_pm_suspend(rdev); 4000 1.1 riastrad r100_cp_disable(rdev); 4001 1.1 riastrad radeon_wb_disable(rdev); 4002 1.1 riastrad r100_irq_disable(rdev); 4003 1.1 riastrad if (rdev->flags & RADEON_IS_PCI) 4004 1.1 riastrad r100_pci_gart_disable(rdev); 4005 1.1 riastrad return 0; 4006 1.1 riastrad } 4007 1.1 riastrad 4008 1.1 riastrad void r100_fini(struct radeon_device *rdev) 4009 1.1 riastrad { 4010 1.1 riastrad radeon_pm_fini(rdev); 4011 1.1 riastrad r100_cp_fini(rdev); 4012 1.1 riastrad radeon_wb_fini(rdev); 4013 1.1 riastrad radeon_ib_pool_fini(rdev); 4014 1.1 riastrad radeon_gem_fini(rdev); 4015 1.1 riastrad if (rdev->flags & RADEON_IS_PCI) 4016 1.1 riastrad r100_pci_gart_fini(rdev); 4017 1.1 riastrad radeon_agp_fini(rdev); 4018 1.1 riastrad radeon_irq_kms_fini(rdev); 4019 1.1 riastrad radeon_fence_driver_fini(rdev); 4020 1.1 riastrad radeon_bo_fini(rdev); 4021 1.1 riastrad radeon_atombios_fini(rdev); 4022 1.1 riastrad kfree(rdev->bios); 4023 1.1 riastrad rdev->bios = NULL; 4024 1.1 riastrad } 4025 1.1 riastrad 4026 1.1 riastrad /* 4027 1.1 riastrad * Due to how kexec works, it can leave the hw fully initialised when it 4028 1.1 riastrad * boots the new kernel. However doing our init sequence with the CP and 4029 1.1 riastrad * WB stuff setup causes GPU hangs on the RN50 at least. So at startup 4030 1.1 riastrad * do some quick sanity checks and restore sane values to avoid this 4031 1.1 riastrad * problem. 4032 1.1 riastrad */ 4033 1.1 riastrad void r100_restore_sanity(struct radeon_device *rdev) 4034 1.1 riastrad { 4035 1.1 riastrad u32 tmp; 4036 1.1 riastrad 4037 1.1 riastrad tmp = RREG32(RADEON_CP_CSQ_CNTL); 4038 1.1 riastrad if (tmp) { 4039 1.1 riastrad WREG32(RADEON_CP_CSQ_CNTL, 0); 4040 1.1 riastrad } 4041 1.1 riastrad tmp = RREG32(RADEON_CP_RB_CNTL); 4042 1.1 riastrad if (tmp) { 4043 1.1 riastrad WREG32(RADEON_CP_RB_CNTL, 0); 4044 1.1 riastrad } 4045 1.1 riastrad tmp = RREG32(RADEON_SCRATCH_UMSK); 4046 1.1 riastrad if (tmp) { 4047 1.1 riastrad WREG32(RADEON_SCRATCH_UMSK, 0); 4048 1.1 riastrad } 4049 1.1 riastrad } 4050 1.1 riastrad 4051 1.1 riastrad int r100_init(struct radeon_device *rdev) 4052 1.1 riastrad { 4053 1.1 riastrad int r; 4054 1.1 riastrad 4055 1.1 riastrad /* Register debugfs file specific to this group of asics */ 4056 1.1 riastrad r100_debugfs(rdev); 4057 1.1 riastrad /* Disable VGA */ 4058 1.1 riastrad r100_vga_render_disable(rdev); 4059 1.1 riastrad /* Initialize scratch registers */ 4060 1.1 riastrad radeon_scratch_init(rdev); 4061 1.1 riastrad /* Initialize surface registers */ 4062 1.1 riastrad radeon_surface_init(rdev); 4063 1.1 riastrad /* sanity check some register to avoid hangs like after kexec */ 4064 1.1 riastrad r100_restore_sanity(rdev); 4065 1.1 riastrad /* TODO: disable VGA need to use VGA request */ 4066 1.1 riastrad /* BIOS*/ 4067 1.1 riastrad if (!radeon_get_bios(rdev)) { 4068 1.1 riastrad if (ASIC_IS_AVIVO(rdev)) 4069 1.1 riastrad return -EINVAL; 4070 1.1 riastrad } 4071 1.1 riastrad if (rdev->is_atom_bios) { 4072 1.1 riastrad dev_err(rdev->dev, "Expecting combios for RS400/RS480 GPU\n"); 4073 1.1 riastrad return -EINVAL; 4074 1.1 riastrad } else { 4075 1.1 riastrad r = radeon_combios_init(rdev); 4076 1.1 riastrad if (r) 4077 1.1 riastrad return r; 4078 1.1 riastrad } 4079 1.1 riastrad /* Reset gpu before posting otherwise ATOM will enter infinite loop */ 4080 1.1 riastrad if (radeon_asic_reset(rdev)) { 4081 1.1 riastrad dev_warn(rdev->dev, 4082 1.1 riastrad "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n", 4083 1.1 riastrad RREG32(R_000E40_RBBM_STATUS), 4084 1.1 riastrad RREG32(R_0007C0_CP_STAT)); 4085 1.1 riastrad } 4086 1.1 riastrad /* check if cards are posted or not */ 4087 1.1 riastrad if (radeon_boot_test_post_card(rdev) == false) 4088 1.1 riastrad return -EINVAL; 4089 1.1 riastrad /* Set asic errata */ 4090 1.1 riastrad r100_errata(rdev); 4091 1.1 riastrad /* Initialize clocks */ 4092 1.1 riastrad radeon_get_clock_info(rdev->ddev); 4093 1.1 riastrad /* initialize AGP */ 4094 1.1 riastrad if (rdev->flags & RADEON_IS_AGP) { 4095 1.1 riastrad r = radeon_agp_init(rdev); 4096 1.1 riastrad if (r) { 4097 1.1 riastrad radeon_agp_disable(rdev); 4098 1.1 riastrad } 4099 1.1 riastrad } 4100 1.1 riastrad /* initialize VRAM */ 4101 1.1 riastrad r100_mc_init(rdev); 4102 1.1 riastrad /* Fence driver */ 4103 1.1 riastrad r = radeon_fence_driver_init(rdev); 4104 1.1 riastrad if (r) 4105 1.1 riastrad return r; 4106 1.1 riastrad /* Memory manager */ 4107 1.1 riastrad r = radeon_bo_init(rdev); 4108 1.1 riastrad if (r) 4109 1.1 riastrad return r; 4110 1.1 riastrad if (rdev->flags & RADEON_IS_PCI) { 4111 1.1 riastrad r = r100_pci_gart_init(rdev); 4112 1.1 riastrad if (r) 4113 1.1 riastrad return r; 4114 1.1 riastrad } 4115 1.1 riastrad r100_set_safe_registers(rdev); 4116 1.1 riastrad 4117 1.1 riastrad /* Initialize power management */ 4118 1.1 riastrad radeon_pm_init(rdev); 4119 1.1 riastrad 4120 1.1 riastrad rdev->accel_working = true; 4121 1.1 riastrad r = r100_startup(rdev); 4122 1.1 riastrad if (r) { 4123 1.1 riastrad /* Somethings want wront with the accel init stop accel */ 4124 1.1 riastrad dev_err(rdev->dev, "Disabling GPU acceleration\n"); 4125 1.1 riastrad r100_cp_fini(rdev); 4126 1.1 riastrad radeon_wb_fini(rdev); 4127 1.1 riastrad radeon_ib_pool_fini(rdev); 4128 1.1 riastrad radeon_irq_kms_fini(rdev); 4129 1.1 riastrad if (rdev->flags & RADEON_IS_PCI) 4130 1.1 riastrad r100_pci_gart_fini(rdev); 4131 1.1 riastrad rdev->accel_working = false; 4132 1.1 riastrad } 4133 1.1 riastrad return 0; 4134 1.1 riastrad } 4135 1.1 riastrad 4136 1.1 riastrad uint32_t r100_mm_rreg_slow(struct radeon_device *rdev, uint32_t reg) 4137 1.1 riastrad { 4138 1.1 riastrad unsigned long flags; 4139 1.1 riastrad uint32_t ret; 4140 1.1 riastrad 4141 1.1 riastrad spin_lock_irqsave(&rdev->mmio_idx_lock, flags); 4142 1.1 riastrad #ifdef __NetBSD__ 4143 1.1 riastrad bus_space_write_4(rdev->rmmio_bst, rdev->rmmio_bsh, 4144 1.1 riastrad RADEON_MM_INDEX, reg); 4145 1.1 riastrad ret = bus_space_read_4(rdev->rmmio_bst, rdev->rmmio_bsh, 4146 1.1 riastrad RADEON_MM_DATA); 4147 1.1 riastrad #else 4148 1.1 riastrad writel(reg, ((void __iomem *)rdev->rmmio) + RADEON_MM_INDEX); 4149 1.1 riastrad ret = readl(((void __iomem *)rdev->rmmio) + RADEON_MM_DATA); 4150 1.1 riastrad #endif 4151 1.1 riastrad spin_unlock_irqrestore(&rdev->mmio_idx_lock, flags); 4152 1.1 riastrad return ret; 4153 1.1 riastrad } 4154 1.1 riastrad 4155 1.1 riastrad void r100_mm_wreg_slow(struct radeon_device *rdev, uint32_t reg, uint32_t v) 4156 1.1 riastrad { 4157 1.1 riastrad unsigned long flags; 4158 1.1 riastrad 4159 1.1 riastrad spin_lock_irqsave(&rdev->mmio_idx_lock, flags); 4160 1.1 riastrad #ifdef __NetBSD__ 4161 1.1 riastrad bus_space_write_4(rdev->rmmio_bst, rdev->rmmio_bsh, 4162 1.1 riastrad RADEON_MM_INDEX, reg); 4163 1.1 riastrad bus_space_write_4(rdev->rmmio_bst, rdev->rmmio_bsh, 4164 1.1 riastrad RADEON_MM_DATA, v); 4165 1.1 riastrad #else 4166 1.1 riastrad writel(reg, ((void __iomem *)rdev->rmmio) + RADEON_MM_INDEX); 4167 1.1 riastrad writel(v, ((void __iomem *)rdev->rmmio) + RADEON_MM_DATA); 4168 1.1 riastrad #endif 4169 1.1 riastrad spin_unlock_irqrestore(&rdev->mmio_idx_lock, flags); 4170 1.1 riastrad } 4171 1.1 riastrad 4172 1.1 riastrad u32 r100_io_rreg(struct radeon_device *rdev, u32 reg) 4173 1.1 riastrad { 4174 1.1 riastrad #ifdef __NetBSD__ 4175 1.1 riastrad if (reg < rdev->rio_mem_size) { 4176 1.1 riastrad return bus_space_read_4(rdev->rio_mem_bst, rdev->rio_mem_bsh, 4177 1.1 riastrad reg); 4178 1.1 riastrad } else { 4179 1.1 riastrad bus_space_write_4(rdev->rio_mem_bst, rdev->rio_mem_bsh, 4180 1.1 riastrad RADEON_MM_INDEX, reg); 4181 1.1 riastrad return bus_space_read_4(rdev->rio_mem_bst, rdev->rio_mem_bsh, 4182 1.1 riastrad RADEON_MM_DATA); 4183 1.1 riastrad } 4184 1.1 riastrad #else 4185 1.1 riastrad if (reg < rdev->rio_mem_size) 4186 1.1 riastrad return ioread32(rdev->rio_mem + reg); 4187 1.1 riastrad else { 4188 1.1 riastrad iowrite32(reg, rdev->rio_mem + RADEON_MM_INDEX); 4189 1.1 riastrad return ioread32(rdev->rio_mem + RADEON_MM_DATA); 4190 1.1 riastrad } 4191 1.1 riastrad #endif 4192 1.1 riastrad } 4193 1.1 riastrad 4194 1.1 riastrad void r100_io_wreg(struct radeon_device *rdev, u32 reg, u32 v) 4195 1.1 riastrad { 4196 1.1 riastrad #ifdef __NetBSD__ 4197 1.1 riastrad if (reg < rdev->rio_mem_size) { 4198 1.1 riastrad bus_space_write_4(rdev->rio_mem_bst, rdev->rio_mem_bsh, reg, 4199 1.1 riastrad v); 4200 1.1 riastrad } else { 4201 1.1 riastrad bus_space_write_4(rdev->rio_mem_bst, rdev->rio_mem_bsh, 4202 1.1 riastrad RADEON_MM_INDEX, reg); 4203 1.1 riastrad bus_space_write_4(rdev->rio_mem_bst, rdev->rio_mem_bsh, 4204 1.1 riastrad RADEON_MM_DATA, v); 4205 1.1 riastrad } 4206 1.1 riastrad #else 4207 1.1 riastrad if (reg < rdev->rio_mem_size) 4208 1.1 riastrad iowrite32(v, rdev->rio_mem + reg); 4209 1.1 riastrad else { 4210 1.1 riastrad iowrite32(reg, rdev->rio_mem + RADEON_MM_INDEX); 4211 1.1 riastrad iowrite32(v, rdev->rio_mem + RADEON_MM_DATA); 4212 1.1 riastrad } 4213 1.1 riastrad #endif 4214 1.1 riastrad } 4215