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