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> |
| 29 | #include "drmP.h" |
| 30 | #include "drm.h" |
| 31 | #include "radeon_drm.h" |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 32 | #include "radeon_reg.h" |
| 33 | #include "radeon.h" |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 34 | #include "r100d.h" |
Jerome Glisse | d455090 | 2009-10-01 10:12:06 +0200 | [diff] [blame] | 35 | #include "rs100d.h" |
| 36 | #include "rv200d.h" |
| 37 | #include "rv250d.h" |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 38 | |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 39 | #include <linux/firmware.h> |
| 40 | #include <linux/platform_device.h> |
| 41 | |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 42 | #include "r100_reg_safe.h" |
| 43 | #include "rn50_reg_safe.h" |
| 44 | |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 45 | /* Firmware Names */ |
| 46 | #define FIRMWARE_R100 "radeon/R100_cp.bin" |
| 47 | #define FIRMWARE_R200 "radeon/R200_cp.bin" |
| 48 | #define FIRMWARE_R300 "radeon/R300_cp.bin" |
| 49 | #define FIRMWARE_R420 "radeon/R420_cp.bin" |
| 50 | #define FIRMWARE_RS690 "radeon/RS690_cp.bin" |
| 51 | #define FIRMWARE_RS600 "radeon/RS600_cp.bin" |
| 52 | #define FIRMWARE_R520 "radeon/R520_cp.bin" |
| 53 | |
| 54 | MODULE_FIRMWARE(FIRMWARE_R100); |
| 55 | MODULE_FIRMWARE(FIRMWARE_R200); |
| 56 | MODULE_FIRMWARE(FIRMWARE_R300); |
| 57 | MODULE_FIRMWARE(FIRMWARE_R420); |
| 58 | MODULE_FIRMWARE(FIRMWARE_RS690); |
| 59 | MODULE_FIRMWARE(FIRMWARE_RS600); |
| 60 | MODULE_FIRMWARE(FIRMWARE_R520); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 61 | |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 62 | #include "r100_track.h" |
| 63 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 64 | /* This files gather functions specifics to: |
| 65 | * r100,rv100,rs100,rv200,rs200,r200,rv250,rs300,rv280 |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 66 | */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 67 | |
Alex Deucher | 05a05c5 | 2009-12-04 14:53:41 -0500 | [diff] [blame] | 68 | /* hpd for digital panel detect/disconnect */ |
| 69 | bool r100_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd) |
| 70 | { |
| 71 | bool connected = false; |
| 72 | |
| 73 | switch (hpd) { |
| 74 | case RADEON_HPD_1: |
| 75 | if (RREG32(RADEON_FP_GEN_CNTL) & RADEON_FP_DETECT_SENSE) |
| 76 | connected = true; |
| 77 | break; |
| 78 | case RADEON_HPD_2: |
| 79 | if (RREG32(RADEON_FP2_GEN_CNTL) & RADEON_FP2_DETECT_SENSE) |
| 80 | connected = true; |
| 81 | break; |
| 82 | default: |
| 83 | break; |
| 84 | } |
| 85 | return connected; |
| 86 | } |
| 87 | |
| 88 | void r100_hpd_set_polarity(struct radeon_device *rdev, |
| 89 | enum radeon_hpd_id hpd) |
| 90 | { |
| 91 | u32 tmp; |
| 92 | bool connected = r100_hpd_sense(rdev, hpd); |
| 93 | |
| 94 | switch (hpd) { |
| 95 | case RADEON_HPD_1: |
| 96 | tmp = RREG32(RADEON_FP_GEN_CNTL); |
| 97 | if (connected) |
| 98 | tmp &= ~RADEON_FP_DETECT_INT_POL; |
| 99 | else |
| 100 | tmp |= RADEON_FP_DETECT_INT_POL; |
| 101 | WREG32(RADEON_FP_GEN_CNTL, tmp); |
| 102 | break; |
| 103 | case RADEON_HPD_2: |
| 104 | tmp = RREG32(RADEON_FP2_GEN_CNTL); |
| 105 | if (connected) |
| 106 | tmp &= ~RADEON_FP2_DETECT_INT_POL; |
| 107 | else |
| 108 | tmp |= RADEON_FP2_DETECT_INT_POL; |
| 109 | WREG32(RADEON_FP2_GEN_CNTL, tmp); |
| 110 | break; |
| 111 | default: |
| 112 | break; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | void r100_hpd_init(struct radeon_device *rdev) |
| 117 | { |
| 118 | struct drm_device *dev = rdev->ddev; |
| 119 | struct drm_connector *connector; |
| 120 | |
| 121 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 122 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
| 123 | switch (radeon_connector->hpd.hpd) { |
| 124 | case RADEON_HPD_1: |
| 125 | rdev->irq.hpd[0] = true; |
| 126 | break; |
| 127 | case RADEON_HPD_2: |
| 128 | rdev->irq.hpd[1] = true; |
| 129 | break; |
| 130 | default: |
| 131 | break; |
| 132 | } |
| 133 | } |
| 134 | r100_irq_set(rdev); |
| 135 | } |
| 136 | |
| 137 | void r100_hpd_fini(struct radeon_device *rdev) |
| 138 | { |
| 139 | struct drm_device *dev = rdev->ddev; |
| 140 | struct drm_connector *connector; |
| 141 | |
| 142 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 143 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
| 144 | switch (radeon_connector->hpd.hpd) { |
| 145 | case RADEON_HPD_1: |
| 146 | rdev->irq.hpd[0] = false; |
| 147 | break; |
| 148 | case RADEON_HPD_2: |
| 149 | rdev->irq.hpd[1] = false; |
| 150 | break; |
| 151 | default: |
| 152 | break; |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 157 | /* |
| 158 | * PCI GART |
| 159 | */ |
| 160 | void r100_pci_gart_tlb_flush(struct radeon_device *rdev) |
| 161 | { |
| 162 | /* TODO: can we do somethings here ? */ |
| 163 | /* It seems hw only cache one entry so we should discard this |
| 164 | * entry otherwise if first GPU GART read hit this entry it |
| 165 | * could end up in wrong address. */ |
| 166 | } |
| 167 | |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 168 | int r100_pci_gart_init(struct radeon_device *rdev) |
| 169 | { |
| 170 | int r; |
| 171 | |
| 172 | if (rdev->gart.table.ram.ptr) { |
| 173 | WARN(1, "R100 PCI GART already initialized.\n"); |
| 174 | return 0; |
| 175 | } |
| 176 | /* Initialize common gart structure */ |
| 177 | r = radeon_gart_init(rdev); |
| 178 | if (r) |
| 179 | return r; |
| 180 | rdev->gart.table_size = rdev->gart.num_gpu_pages * 4; |
| 181 | rdev->asic->gart_tlb_flush = &r100_pci_gart_tlb_flush; |
| 182 | rdev->asic->gart_set_page = &r100_pci_gart_set_page; |
| 183 | return radeon_gart_table_ram_alloc(rdev); |
| 184 | } |
| 185 | |
Dave Airlie | 17e15b0 | 2009-11-05 15:36:53 +1000 | [diff] [blame] | 186 | /* required on r1xx, r2xx, r300, r(v)350, r420/r481, rs400/rs480 */ |
| 187 | void r100_enable_bm(struct radeon_device *rdev) |
| 188 | { |
| 189 | uint32_t tmp; |
| 190 | /* Enable bus mastering */ |
| 191 | tmp = RREG32(RADEON_BUS_CNTL) & ~RADEON_BUS_MASTER_DIS; |
| 192 | WREG32(RADEON_BUS_CNTL, tmp); |
| 193 | } |
| 194 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 195 | int r100_pci_gart_enable(struct radeon_device *rdev) |
| 196 | { |
| 197 | uint32_t tmp; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 198 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 199 | /* discard memory request outside of configured range */ |
| 200 | tmp = RREG32(RADEON_AIC_CNTL) | RADEON_DIS_OUT_OF_PCI_GART_ACCESS; |
| 201 | WREG32(RADEON_AIC_CNTL, tmp); |
| 202 | /* set address range for PCI address translate */ |
| 203 | WREG32(RADEON_AIC_LO_ADDR, rdev->mc.gtt_location); |
| 204 | tmp = rdev->mc.gtt_location + rdev->mc.gtt_size - 1; |
| 205 | WREG32(RADEON_AIC_HI_ADDR, tmp); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 206 | /* set PCI GART page-table base address */ |
| 207 | WREG32(RADEON_AIC_PT_BASE, rdev->gart.table_addr); |
| 208 | tmp = RREG32(RADEON_AIC_CNTL) | RADEON_PCIGART_TRANSLATE_EN; |
| 209 | WREG32(RADEON_AIC_CNTL, tmp); |
| 210 | r100_pci_gart_tlb_flush(rdev); |
| 211 | rdev->gart.ready = true; |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | void r100_pci_gart_disable(struct radeon_device *rdev) |
| 216 | { |
| 217 | uint32_t tmp; |
| 218 | |
| 219 | /* discard memory request outside of configured range */ |
| 220 | tmp = RREG32(RADEON_AIC_CNTL) | RADEON_DIS_OUT_OF_PCI_GART_ACCESS; |
| 221 | WREG32(RADEON_AIC_CNTL, tmp & ~RADEON_PCIGART_TRANSLATE_EN); |
| 222 | WREG32(RADEON_AIC_LO_ADDR, 0); |
| 223 | WREG32(RADEON_AIC_HI_ADDR, 0); |
| 224 | } |
| 225 | |
| 226 | int r100_pci_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr) |
| 227 | { |
| 228 | if (i < 0 || i > rdev->gart.num_gpu_pages) { |
| 229 | return -EINVAL; |
| 230 | } |
Dave Airlie | ed10f95 | 2009-06-29 18:29:11 +1000 | [diff] [blame] | 231 | rdev->gart.table.ram.ptr[i] = cpu_to_le32(lower_32_bits(addr)); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 232 | return 0; |
| 233 | } |
| 234 | |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 235 | void r100_pci_gart_fini(struct radeon_device *rdev) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 236 | { |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 237 | r100_pci_gart_disable(rdev); |
| 238 | radeon_gart_table_ram_free(rdev); |
| 239 | radeon_gart_fini(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 240 | } |
| 241 | |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 242 | int r100_irq_set(struct radeon_device *rdev) |
| 243 | { |
| 244 | uint32_t tmp = 0; |
| 245 | |
| 246 | if (rdev->irq.sw_int) { |
| 247 | tmp |= RADEON_SW_INT_ENABLE; |
| 248 | } |
| 249 | if (rdev->irq.crtc_vblank_int[0]) { |
| 250 | tmp |= RADEON_CRTC_VBLANK_MASK; |
| 251 | } |
| 252 | if (rdev->irq.crtc_vblank_int[1]) { |
| 253 | tmp |= RADEON_CRTC2_VBLANK_MASK; |
| 254 | } |
Alex Deucher | 05a05c5 | 2009-12-04 14:53:41 -0500 | [diff] [blame] | 255 | if (rdev->irq.hpd[0]) { |
| 256 | tmp |= RADEON_FP_DETECT_MASK; |
| 257 | } |
| 258 | if (rdev->irq.hpd[1]) { |
| 259 | tmp |= RADEON_FP2_DETECT_MASK; |
| 260 | } |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 261 | WREG32(RADEON_GEN_INT_CNTL, tmp); |
| 262 | return 0; |
| 263 | } |
| 264 | |
Jerome Glisse | 9f022dd | 2009-09-11 15:35:22 +0200 | [diff] [blame] | 265 | void r100_irq_disable(struct radeon_device *rdev) |
| 266 | { |
| 267 | u32 tmp; |
| 268 | |
| 269 | WREG32(R_000040_GEN_INT_CNTL, 0); |
| 270 | /* Wait and acknowledge irq */ |
| 271 | mdelay(1); |
| 272 | tmp = RREG32(R_000044_GEN_INT_STATUS); |
| 273 | WREG32(R_000044_GEN_INT_STATUS, tmp); |
| 274 | } |
| 275 | |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 276 | static inline uint32_t r100_irq_ack(struct radeon_device *rdev) |
| 277 | { |
| 278 | uint32_t irqs = RREG32(RADEON_GEN_INT_STATUS); |
Alex Deucher | 05a05c5 | 2009-12-04 14:53:41 -0500 | [diff] [blame] | 279 | uint32_t irq_mask = RADEON_SW_INT_TEST | |
| 280 | RADEON_CRTC_VBLANK_STAT | RADEON_CRTC2_VBLANK_STAT | |
| 281 | RADEON_FP_DETECT_STAT | RADEON_FP2_DETECT_STAT; |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 282 | |
| 283 | if (irqs) { |
| 284 | WREG32(RADEON_GEN_INT_STATUS, irqs); |
| 285 | } |
| 286 | return irqs & irq_mask; |
| 287 | } |
| 288 | |
| 289 | int r100_irq_process(struct radeon_device *rdev) |
| 290 | { |
Alex Deucher | 3e5cb98 | 2009-10-16 12:21:24 -0400 | [diff] [blame] | 291 | uint32_t status, msi_rearm; |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 292 | bool queue_hotplug = false; |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 293 | |
| 294 | status = r100_irq_ack(rdev); |
| 295 | if (!status) { |
| 296 | return IRQ_NONE; |
| 297 | } |
Jerome Glisse | a513c18 | 2009-09-09 22:23:07 +0200 | [diff] [blame] | 298 | if (rdev->shutdown) { |
| 299 | return IRQ_NONE; |
| 300 | } |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 301 | while (status) { |
| 302 | /* SW interrupt */ |
| 303 | if (status & RADEON_SW_INT_TEST) { |
| 304 | radeon_fence_process(rdev); |
| 305 | } |
| 306 | /* Vertical blank interrupts */ |
| 307 | if (status & RADEON_CRTC_VBLANK_STAT) { |
| 308 | drm_handle_vblank(rdev->ddev, 0); |
| 309 | } |
| 310 | if (status & RADEON_CRTC2_VBLANK_STAT) { |
| 311 | drm_handle_vblank(rdev->ddev, 1); |
| 312 | } |
Alex Deucher | 05a05c5 | 2009-12-04 14:53:41 -0500 | [diff] [blame] | 313 | if (status & RADEON_FP_DETECT_STAT) { |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 314 | queue_hotplug = true; |
| 315 | DRM_DEBUG("HPD1\n"); |
Alex Deucher | 05a05c5 | 2009-12-04 14:53:41 -0500 | [diff] [blame] | 316 | } |
| 317 | if (status & RADEON_FP2_DETECT_STAT) { |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 318 | queue_hotplug = true; |
| 319 | DRM_DEBUG("HPD2\n"); |
Alex Deucher | 05a05c5 | 2009-12-04 14:53:41 -0500 | [diff] [blame] | 320 | } |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 321 | status = r100_irq_ack(rdev); |
| 322 | } |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 323 | if (queue_hotplug) |
| 324 | queue_work(rdev->wq, &rdev->hotplug_work); |
Alex Deucher | 3e5cb98 | 2009-10-16 12:21:24 -0400 | [diff] [blame] | 325 | if (rdev->msi_enabled) { |
| 326 | switch (rdev->family) { |
| 327 | case CHIP_RS400: |
| 328 | case CHIP_RS480: |
| 329 | msi_rearm = RREG32(RADEON_AIC_CNTL) & ~RS400_MSI_REARM; |
| 330 | WREG32(RADEON_AIC_CNTL, msi_rearm); |
| 331 | WREG32(RADEON_AIC_CNTL, msi_rearm | RS400_MSI_REARM); |
| 332 | break; |
| 333 | default: |
| 334 | msi_rearm = RREG32(RADEON_MSI_REARM_EN) & ~RV370_MSI_REARM_EN; |
| 335 | WREG32(RADEON_MSI_REARM_EN, msi_rearm); |
| 336 | WREG32(RADEON_MSI_REARM_EN, msi_rearm | RV370_MSI_REARM_EN); |
| 337 | break; |
| 338 | } |
| 339 | } |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 340 | return IRQ_HANDLED; |
| 341 | } |
| 342 | |
| 343 | u32 r100_get_vblank_counter(struct radeon_device *rdev, int crtc) |
| 344 | { |
| 345 | if (crtc == 0) |
| 346 | return RREG32(RADEON_CRTC_CRNT_FRAME); |
| 347 | else |
| 348 | return RREG32(RADEON_CRTC2_CRNT_FRAME); |
| 349 | } |
| 350 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 351 | void r100_fence_ring_emit(struct radeon_device *rdev, |
| 352 | struct radeon_fence *fence) |
| 353 | { |
| 354 | /* Who ever call radeon_fence_emit should call ring_lock and ask |
| 355 | * for enough space (today caller are ib schedule and buffer move) */ |
| 356 | /* Wait until IDLE & CLEAN */ |
| 357 | radeon_ring_write(rdev, PACKET0(0x1720, 0)); |
| 358 | radeon_ring_write(rdev, (1 << 16) | (1 << 17)); |
| 359 | /* Emit fence sequence & fire IRQ */ |
| 360 | radeon_ring_write(rdev, PACKET0(rdev->fence_drv.scratch_reg, 0)); |
| 361 | radeon_ring_write(rdev, fence->seq); |
| 362 | radeon_ring_write(rdev, PACKET0(RADEON_GEN_INT_STATUS, 0)); |
| 363 | radeon_ring_write(rdev, RADEON_SW_INT_FIRE); |
| 364 | } |
| 365 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 366 | int r100_wb_init(struct radeon_device *rdev) |
| 367 | { |
| 368 | int r; |
| 369 | |
| 370 | if (rdev->wb.wb_obj == NULL) { |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 371 | r = radeon_bo_create(rdev, NULL, RADEON_GPU_PAGE_SIZE, true, |
| 372 | RADEON_GEM_DOMAIN_GTT, |
| 373 | &rdev->wb.wb_obj); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 374 | if (r) { |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 375 | dev_err(rdev->dev, "(%d) create WB buffer failed\n", r); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 376 | return r; |
| 377 | } |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 378 | r = radeon_bo_reserve(rdev->wb.wb_obj, false); |
| 379 | if (unlikely(r != 0)) |
| 380 | return r; |
| 381 | r = radeon_bo_pin(rdev->wb.wb_obj, RADEON_GEM_DOMAIN_GTT, |
| 382 | &rdev->wb.gpu_addr); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 383 | if (r) { |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 384 | dev_err(rdev->dev, "(%d) pin WB buffer failed\n", r); |
| 385 | radeon_bo_unreserve(rdev->wb.wb_obj); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 386 | return r; |
| 387 | } |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 388 | r = radeon_bo_kmap(rdev->wb.wb_obj, (void **)&rdev->wb.wb); |
| 389 | radeon_bo_unreserve(rdev->wb.wb_obj); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 390 | if (r) { |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 391 | dev_err(rdev->dev, "(%d) map WB buffer failed\n", r); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 392 | return r; |
| 393 | } |
| 394 | } |
Jerome Glisse | 9f022dd | 2009-09-11 15:35:22 +0200 | [diff] [blame] | 395 | WREG32(R_000774_SCRATCH_ADDR, rdev->wb.gpu_addr); |
| 396 | WREG32(R_00070C_CP_RB_RPTR_ADDR, |
| 397 | S_00070C_RB_RPTR_ADDR((rdev->wb.gpu_addr + 1024) >> 2)); |
| 398 | WREG32(R_000770_SCRATCH_UMSK, 0xff); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 399 | return 0; |
| 400 | } |
| 401 | |
Jerome Glisse | 9f022dd | 2009-09-11 15:35:22 +0200 | [diff] [blame] | 402 | void r100_wb_disable(struct radeon_device *rdev) |
| 403 | { |
| 404 | WREG32(R_000770_SCRATCH_UMSK, 0); |
| 405 | } |
| 406 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 407 | void r100_wb_fini(struct radeon_device *rdev) |
| 408 | { |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 409 | int r; |
| 410 | |
Jerome Glisse | 9f022dd | 2009-09-11 15:35:22 +0200 | [diff] [blame] | 411 | r100_wb_disable(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 412 | if (rdev->wb.wb_obj) { |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 413 | r = radeon_bo_reserve(rdev->wb.wb_obj, false); |
| 414 | if (unlikely(r != 0)) { |
| 415 | dev_err(rdev->dev, "(%d) can't finish WB\n", r); |
| 416 | return; |
| 417 | } |
| 418 | radeon_bo_kunmap(rdev->wb.wb_obj); |
| 419 | radeon_bo_unpin(rdev->wb.wb_obj); |
| 420 | radeon_bo_unreserve(rdev->wb.wb_obj); |
| 421 | radeon_bo_unref(&rdev->wb.wb_obj); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 422 | rdev->wb.wb = NULL; |
| 423 | rdev->wb.wb_obj = NULL; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | int r100_copy_blit(struct radeon_device *rdev, |
| 428 | uint64_t src_offset, |
| 429 | uint64_t dst_offset, |
| 430 | unsigned num_pages, |
| 431 | struct radeon_fence *fence) |
| 432 | { |
| 433 | uint32_t cur_pages; |
| 434 | uint32_t stride_bytes = PAGE_SIZE; |
| 435 | uint32_t pitch; |
| 436 | uint32_t stride_pixels; |
| 437 | unsigned ndw; |
| 438 | int num_loops; |
| 439 | int r = 0; |
| 440 | |
| 441 | /* radeon limited to 16k stride */ |
| 442 | stride_bytes &= 0x3fff; |
| 443 | /* radeon pitch is /64 */ |
| 444 | pitch = stride_bytes / 64; |
| 445 | stride_pixels = stride_bytes / 4; |
| 446 | num_loops = DIV_ROUND_UP(num_pages, 8191); |
| 447 | |
| 448 | /* Ask for enough room for blit + flush + fence */ |
| 449 | ndw = 64 + (10 * num_loops); |
| 450 | r = radeon_ring_lock(rdev, ndw); |
| 451 | if (r) { |
| 452 | DRM_ERROR("radeon: moving bo (%d) asking for %u dw.\n", r, ndw); |
| 453 | return -EINVAL; |
| 454 | } |
| 455 | while (num_pages > 0) { |
| 456 | cur_pages = num_pages; |
| 457 | if (cur_pages > 8191) { |
| 458 | cur_pages = 8191; |
| 459 | } |
| 460 | num_pages -= cur_pages; |
| 461 | |
| 462 | /* pages are in Y direction - height |
| 463 | page width in X direction - width */ |
| 464 | radeon_ring_write(rdev, PACKET3(PACKET3_BITBLT_MULTI, 8)); |
| 465 | radeon_ring_write(rdev, |
| 466 | RADEON_GMC_SRC_PITCH_OFFSET_CNTL | |
| 467 | RADEON_GMC_DST_PITCH_OFFSET_CNTL | |
| 468 | RADEON_GMC_SRC_CLIPPING | |
| 469 | RADEON_GMC_DST_CLIPPING | |
| 470 | RADEON_GMC_BRUSH_NONE | |
| 471 | (RADEON_COLOR_FORMAT_ARGB8888 << 8) | |
| 472 | RADEON_GMC_SRC_DATATYPE_COLOR | |
| 473 | RADEON_ROP3_S | |
| 474 | RADEON_DP_SRC_SOURCE_MEMORY | |
| 475 | RADEON_GMC_CLR_CMP_CNTL_DIS | |
| 476 | RADEON_GMC_WR_MSK_DIS); |
| 477 | radeon_ring_write(rdev, (pitch << 22) | (src_offset >> 10)); |
| 478 | radeon_ring_write(rdev, (pitch << 22) | (dst_offset >> 10)); |
| 479 | radeon_ring_write(rdev, (0x1fff) | (0x1fff << 16)); |
| 480 | radeon_ring_write(rdev, 0); |
| 481 | radeon_ring_write(rdev, (0x1fff) | (0x1fff << 16)); |
| 482 | radeon_ring_write(rdev, num_pages); |
| 483 | radeon_ring_write(rdev, num_pages); |
| 484 | radeon_ring_write(rdev, cur_pages | (stride_pixels << 16)); |
| 485 | } |
| 486 | radeon_ring_write(rdev, PACKET0(RADEON_DSTCACHE_CTLSTAT, 0)); |
| 487 | radeon_ring_write(rdev, RADEON_RB2D_DC_FLUSH_ALL); |
| 488 | radeon_ring_write(rdev, PACKET0(RADEON_WAIT_UNTIL, 0)); |
| 489 | radeon_ring_write(rdev, |
| 490 | RADEON_WAIT_2D_IDLECLEAN | |
| 491 | RADEON_WAIT_HOST_IDLECLEAN | |
| 492 | RADEON_WAIT_DMA_GUI_IDLE); |
| 493 | if (fence) { |
| 494 | r = radeon_fence_emit(rdev, fence); |
| 495 | } |
| 496 | radeon_ring_unlock_commit(rdev); |
| 497 | return r; |
| 498 | } |
| 499 | |
Jerome Glisse | 4560023 | 2009-09-09 22:23:45 +0200 | [diff] [blame] | 500 | static int r100_cp_wait_for_idle(struct radeon_device *rdev) |
| 501 | { |
| 502 | unsigned i; |
| 503 | u32 tmp; |
| 504 | |
| 505 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 506 | tmp = RREG32(R_000E40_RBBM_STATUS); |
| 507 | if (!G_000E40_CP_CMDSTRM_BUSY(tmp)) { |
| 508 | return 0; |
| 509 | } |
| 510 | udelay(1); |
| 511 | } |
| 512 | return -1; |
| 513 | } |
| 514 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 515 | void r100_ring_start(struct radeon_device *rdev) |
| 516 | { |
| 517 | int r; |
| 518 | |
| 519 | r = radeon_ring_lock(rdev, 2); |
| 520 | if (r) { |
| 521 | return; |
| 522 | } |
| 523 | radeon_ring_write(rdev, PACKET0(RADEON_ISYNC_CNTL, 0)); |
| 524 | radeon_ring_write(rdev, |
| 525 | RADEON_ISYNC_ANY2D_IDLE3D | |
| 526 | RADEON_ISYNC_ANY3D_IDLE2D | |
| 527 | RADEON_ISYNC_WAIT_IDLEGUI | |
| 528 | RADEON_ISYNC_CPSCRATCH_IDLEGUI); |
| 529 | radeon_ring_unlock_commit(rdev); |
| 530 | } |
| 531 | |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 532 | |
| 533 | /* Load the microcode for the CP */ |
| 534 | static int r100_cp_init_microcode(struct radeon_device *rdev) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 535 | { |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 536 | struct platform_device *pdev; |
| 537 | const char *fw_name = NULL; |
| 538 | int err; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 539 | |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 540 | DRM_DEBUG("\n"); |
| 541 | |
| 542 | pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0); |
| 543 | err = IS_ERR(pdev); |
| 544 | if (err) { |
| 545 | printk(KERN_ERR "radeon_cp: Failed to register firmware\n"); |
| 546 | return -EINVAL; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 547 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 548 | if ((rdev->family == CHIP_R100) || (rdev->family == CHIP_RV100) || |
| 549 | (rdev->family == CHIP_RV200) || (rdev->family == CHIP_RS100) || |
| 550 | (rdev->family == CHIP_RS200)) { |
| 551 | DRM_INFO("Loading R100 Microcode\n"); |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 552 | fw_name = FIRMWARE_R100; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 553 | } else if ((rdev->family == CHIP_R200) || |
| 554 | (rdev->family == CHIP_RV250) || |
| 555 | (rdev->family == CHIP_RV280) || |
| 556 | (rdev->family == CHIP_RS300)) { |
| 557 | DRM_INFO("Loading R200 Microcode\n"); |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 558 | fw_name = FIRMWARE_R200; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 559 | } else if ((rdev->family == CHIP_R300) || |
| 560 | (rdev->family == CHIP_R350) || |
| 561 | (rdev->family == CHIP_RV350) || |
| 562 | (rdev->family == CHIP_RV380) || |
| 563 | (rdev->family == CHIP_RS400) || |
| 564 | (rdev->family == CHIP_RS480)) { |
| 565 | DRM_INFO("Loading R300 Microcode\n"); |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 566 | fw_name = FIRMWARE_R300; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 567 | } else if ((rdev->family == CHIP_R420) || |
| 568 | (rdev->family == CHIP_R423) || |
| 569 | (rdev->family == CHIP_RV410)) { |
| 570 | DRM_INFO("Loading R400 Microcode\n"); |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 571 | fw_name = FIRMWARE_R420; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 572 | } else if ((rdev->family == CHIP_RS690) || |
| 573 | (rdev->family == CHIP_RS740)) { |
| 574 | DRM_INFO("Loading RS690/RS740 Microcode\n"); |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 575 | fw_name = FIRMWARE_RS690; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 576 | } else if (rdev->family == CHIP_RS600) { |
| 577 | DRM_INFO("Loading RS600 Microcode\n"); |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 578 | fw_name = FIRMWARE_RS600; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 579 | } else if ((rdev->family == CHIP_RV515) || |
| 580 | (rdev->family == CHIP_R520) || |
| 581 | (rdev->family == CHIP_RV530) || |
| 582 | (rdev->family == CHIP_R580) || |
| 583 | (rdev->family == CHIP_RV560) || |
| 584 | (rdev->family == CHIP_RV570)) { |
| 585 | DRM_INFO("Loading R500 Microcode\n"); |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 586 | fw_name = FIRMWARE_R520; |
| 587 | } |
| 588 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 589 | err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev); |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 590 | platform_device_unregister(pdev); |
| 591 | if (err) { |
| 592 | printk(KERN_ERR "radeon_cp: Failed to load firmware \"%s\"\n", |
| 593 | fw_name); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 594 | } else if (rdev->me_fw->size % 8) { |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 595 | printk(KERN_ERR |
| 596 | "radeon_cp: Bogus length %zu in firmware \"%s\"\n", |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 597 | rdev->me_fw->size, fw_name); |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 598 | err = -EINVAL; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 599 | release_firmware(rdev->me_fw); |
| 600 | rdev->me_fw = NULL; |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 601 | } |
| 602 | return err; |
| 603 | } |
Jerome Glisse | d455090 | 2009-10-01 10:12:06 +0200 | [diff] [blame] | 604 | |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 605 | static void r100_cp_load_microcode(struct radeon_device *rdev) |
| 606 | { |
| 607 | const __be32 *fw_data; |
| 608 | int i, size; |
| 609 | |
| 610 | if (r100_gui_wait_for_idle(rdev)) { |
| 611 | printk(KERN_WARNING "Failed to wait GUI idle while " |
| 612 | "programming pipes. Bad things might happen.\n"); |
| 613 | } |
| 614 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 615 | if (rdev->me_fw) { |
| 616 | size = rdev->me_fw->size / 4; |
| 617 | fw_data = (const __be32 *)&rdev->me_fw->data[0]; |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 618 | WREG32(RADEON_CP_ME_RAM_ADDR, 0); |
| 619 | for (i = 0; i < size; i += 2) { |
| 620 | WREG32(RADEON_CP_ME_RAM_DATAH, |
| 621 | be32_to_cpup(&fw_data[i])); |
| 622 | WREG32(RADEON_CP_ME_RAM_DATAL, |
| 623 | be32_to_cpup(&fw_data[i + 1])); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | int r100_cp_init(struct radeon_device *rdev, unsigned ring_size) |
| 629 | { |
| 630 | unsigned rb_bufsz; |
| 631 | unsigned rb_blksz; |
| 632 | unsigned max_fetch; |
| 633 | unsigned pre_write_timer; |
| 634 | unsigned pre_write_limit; |
| 635 | unsigned indirect2_start; |
| 636 | unsigned indirect1_start; |
| 637 | uint32_t tmp; |
| 638 | int r; |
| 639 | |
| 640 | if (r100_debugfs_cp_init(rdev)) { |
| 641 | DRM_ERROR("Failed to register debugfs file for CP !\n"); |
| 642 | } |
| 643 | /* Reset CP */ |
| 644 | tmp = RREG32(RADEON_CP_CSQ_STAT); |
| 645 | if ((tmp & (1 << 31))) { |
| 646 | DRM_INFO("radeon: cp busy (0x%08X) resetting\n", tmp); |
| 647 | WREG32(RADEON_CP_CSQ_MODE, 0); |
| 648 | WREG32(RADEON_CP_CSQ_CNTL, 0); |
| 649 | WREG32(RADEON_RBBM_SOFT_RESET, RADEON_SOFT_RESET_CP); |
| 650 | tmp = RREG32(RADEON_RBBM_SOFT_RESET); |
| 651 | mdelay(2); |
| 652 | WREG32(RADEON_RBBM_SOFT_RESET, 0); |
| 653 | tmp = RREG32(RADEON_RBBM_SOFT_RESET); |
| 654 | mdelay(2); |
| 655 | tmp = RREG32(RADEON_CP_CSQ_STAT); |
| 656 | if ((tmp & (1 << 31))) { |
| 657 | DRM_INFO("radeon: cp reset failed (0x%08X)\n", tmp); |
| 658 | } |
| 659 | } else { |
| 660 | DRM_INFO("radeon: cp idle (0x%08X)\n", tmp); |
| 661 | } |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 662 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 663 | if (!rdev->me_fw) { |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 664 | r = r100_cp_init_microcode(rdev); |
| 665 | if (r) { |
| 666 | DRM_ERROR("Failed to load firmware!\n"); |
| 667 | return r; |
| 668 | } |
| 669 | } |
| 670 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 671 | /* Align ring size */ |
| 672 | rb_bufsz = drm_order(ring_size / 8); |
| 673 | ring_size = (1 << (rb_bufsz + 1)) * 4; |
| 674 | r100_cp_load_microcode(rdev); |
| 675 | r = radeon_ring_init(rdev, ring_size); |
| 676 | if (r) { |
| 677 | return r; |
| 678 | } |
| 679 | /* Each time the cp read 1024 bytes (16 dword/quadword) update |
| 680 | * the rptr copy in system ram */ |
| 681 | rb_blksz = 9; |
| 682 | /* cp will read 128bytes at a time (4 dwords) */ |
| 683 | max_fetch = 1; |
| 684 | rdev->cp.align_mask = 16 - 1; |
| 685 | /* Write to CP_RB_WPTR will be delayed for pre_write_timer clocks */ |
| 686 | pre_write_timer = 64; |
| 687 | /* Force CP_RB_WPTR write if written more than one time before the |
| 688 | * delay expire |
| 689 | */ |
| 690 | pre_write_limit = 0; |
| 691 | /* Setup the cp cache like this (cache size is 96 dwords) : |
| 692 | * RING 0 to 15 |
| 693 | * INDIRECT1 16 to 79 |
| 694 | * INDIRECT2 80 to 95 |
| 695 | * So ring cache size is 16dwords (> (2 * max_fetch = 2 * 4dwords)) |
| 696 | * indirect1 cache size is 64dwords (> (2 * max_fetch = 2 * 4dwords)) |
| 697 | * indirect2 cache size is 16dwords (> (2 * max_fetch = 2 * 4dwords)) |
| 698 | * Idea being that most of the gpu cmd will be through indirect1 buffer |
| 699 | * so it gets the bigger cache. |
| 700 | */ |
| 701 | indirect2_start = 80; |
| 702 | indirect1_start = 16; |
| 703 | /* cp setup */ |
| 704 | WREG32(0x718, pre_write_timer | (pre_write_limit << 28)); |
Alex Deucher | d6f2893 | 2009-11-02 16:01:27 -0500 | [diff] [blame] | 705 | tmp = (REG_SET(RADEON_RB_BUFSZ, rb_bufsz) | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 706 | REG_SET(RADEON_RB_BLKSZ, rb_blksz) | |
| 707 | REG_SET(RADEON_MAX_FETCH, max_fetch) | |
| 708 | RADEON_RB_NO_UPDATE); |
Alex Deucher | d6f2893 | 2009-11-02 16:01:27 -0500 | [diff] [blame] | 709 | #ifdef __BIG_ENDIAN |
| 710 | tmp |= RADEON_BUF_SWAP_32BIT; |
| 711 | #endif |
| 712 | WREG32(RADEON_CP_RB_CNTL, tmp); |
| 713 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 714 | /* Set ring address */ |
| 715 | DRM_INFO("radeon: ring at 0x%016lX\n", (unsigned long)rdev->cp.gpu_addr); |
| 716 | WREG32(RADEON_CP_RB_BASE, rdev->cp.gpu_addr); |
| 717 | /* Force read & write ptr to 0 */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 718 | WREG32(RADEON_CP_RB_CNTL, tmp | RADEON_RB_RPTR_WR_ENA); |
| 719 | WREG32(RADEON_CP_RB_RPTR_WR, 0); |
| 720 | WREG32(RADEON_CP_RB_WPTR, 0); |
| 721 | WREG32(RADEON_CP_RB_CNTL, tmp); |
| 722 | udelay(10); |
| 723 | rdev->cp.rptr = RREG32(RADEON_CP_RB_RPTR); |
| 724 | rdev->cp.wptr = RREG32(RADEON_CP_RB_WPTR); |
| 725 | /* Set cp mode to bus mastering & enable cp*/ |
| 726 | WREG32(RADEON_CP_CSQ_MODE, |
| 727 | REG_SET(RADEON_INDIRECT2_START, indirect2_start) | |
| 728 | REG_SET(RADEON_INDIRECT1_START, indirect1_start)); |
| 729 | WREG32(0x718, 0); |
| 730 | WREG32(0x744, 0x00004D4D); |
| 731 | WREG32(RADEON_CP_CSQ_CNTL, RADEON_CSQ_PRIBM_INDBM); |
| 732 | radeon_ring_start(rdev); |
| 733 | r = radeon_ring_test(rdev); |
| 734 | if (r) { |
| 735 | DRM_ERROR("radeon: cp isn't working (%d).\n", r); |
| 736 | return r; |
| 737 | } |
| 738 | rdev->cp.ready = true; |
| 739 | return 0; |
| 740 | } |
| 741 | |
| 742 | void r100_cp_fini(struct radeon_device *rdev) |
| 743 | { |
Jerome Glisse | 4560023 | 2009-09-09 22:23:45 +0200 | [diff] [blame] | 744 | if (r100_cp_wait_for_idle(rdev)) { |
| 745 | DRM_ERROR("Wait for CP idle timeout, shutting down CP.\n"); |
| 746 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 747 | /* Disable ring */ |
Jerome Glisse | a18d7ea | 2009-09-09 22:23:27 +0200 | [diff] [blame] | 748 | r100_cp_disable(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 749 | radeon_ring_fini(rdev); |
| 750 | DRM_INFO("radeon: cp finalized\n"); |
| 751 | } |
| 752 | |
| 753 | void r100_cp_disable(struct radeon_device *rdev) |
| 754 | { |
| 755 | /* Disable ring */ |
| 756 | rdev->cp.ready = false; |
| 757 | WREG32(RADEON_CP_CSQ_MODE, 0); |
| 758 | WREG32(RADEON_CP_CSQ_CNTL, 0); |
| 759 | if (r100_gui_wait_for_idle(rdev)) { |
| 760 | printk(KERN_WARNING "Failed to wait GUI idle while " |
| 761 | "programming pipes. Bad things might happen.\n"); |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | int r100_cp_reset(struct radeon_device *rdev) |
| 766 | { |
| 767 | uint32_t tmp; |
| 768 | bool reinit_cp; |
| 769 | int i; |
| 770 | |
| 771 | reinit_cp = rdev->cp.ready; |
| 772 | rdev->cp.ready = false; |
| 773 | WREG32(RADEON_CP_CSQ_MODE, 0); |
| 774 | WREG32(RADEON_CP_CSQ_CNTL, 0); |
| 775 | WREG32(RADEON_RBBM_SOFT_RESET, RADEON_SOFT_RESET_CP); |
| 776 | (void)RREG32(RADEON_RBBM_SOFT_RESET); |
| 777 | udelay(200); |
| 778 | WREG32(RADEON_RBBM_SOFT_RESET, 0); |
| 779 | /* Wait to prevent race in RBBM_STATUS */ |
| 780 | mdelay(1); |
| 781 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 782 | tmp = RREG32(RADEON_RBBM_STATUS); |
| 783 | if (!(tmp & (1 << 16))) { |
| 784 | DRM_INFO("CP reset succeed (RBBM_STATUS=0x%08X)\n", |
| 785 | tmp); |
| 786 | if (reinit_cp) { |
| 787 | return r100_cp_init(rdev, rdev->cp.ring_size); |
| 788 | } |
| 789 | return 0; |
| 790 | } |
| 791 | DRM_UDELAY(1); |
| 792 | } |
| 793 | tmp = RREG32(RADEON_RBBM_STATUS); |
| 794 | DRM_ERROR("Failed to reset CP (RBBM_STATUS=0x%08X)!\n", tmp); |
| 795 | return -1; |
| 796 | } |
| 797 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 798 | void r100_cp_commit(struct radeon_device *rdev) |
| 799 | { |
| 800 | WREG32(RADEON_CP_RB_WPTR, rdev->cp.wptr); |
| 801 | (void)RREG32(RADEON_CP_RB_WPTR); |
| 802 | } |
| 803 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 804 | |
| 805 | /* |
| 806 | * CS functions |
| 807 | */ |
| 808 | int r100_cs_parse_packet0(struct radeon_cs_parser *p, |
| 809 | struct radeon_cs_packet *pkt, |
Jerome Glisse | 068a117 | 2009-06-17 13:28:30 +0200 | [diff] [blame] | 810 | const unsigned *auth, unsigned n, |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 811 | radeon_packet0_check_t check) |
| 812 | { |
| 813 | unsigned reg; |
| 814 | unsigned i, j, m; |
| 815 | unsigned idx; |
| 816 | int r; |
| 817 | |
| 818 | idx = pkt->idx + 1; |
| 819 | reg = pkt->reg; |
Jerome Glisse | 068a117 | 2009-06-17 13:28:30 +0200 | [diff] [blame] | 820 | /* Check that register fall into register range |
| 821 | * determined by the number of entry (n) in the |
| 822 | * safe register bitmap. |
| 823 | */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 824 | if (pkt->one_reg_wr) { |
| 825 | if ((reg >> 7) > n) { |
| 826 | return -EINVAL; |
| 827 | } |
| 828 | } else { |
| 829 | if (((reg + (pkt->count << 2)) >> 7) > n) { |
| 830 | return -EINVAL; |
| 831 | } |
| 832 | } |
| 833 | for (i = 0; i <= pkt->count; i++, idx++) { |
| 834 | j = (reg >> 7); |
| 835 | m = 1 << ((reg >> 2) & 31); |
| 836 | if (auth[j] & m) { |
| 837 | r = check(p, pkt, idx, reg); |
| 838 | if (r) { |
| 839 | return r; |
| 840 | } |
| 841 | } |
| 842 | if (pkt->one_reg_wr) { |
| 843 | if (!(auth[j] & m)) { |
| 844 | break; |
| 845 | } |
| 846 | } else { |
| 847 | reg += 4; |
| 848 | } |
| 849 | } |
| 850 | return 0; |
| 851 | } |
| 852 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 853 | void r100_cs_dump_packet(struct radeon_cs_parser *p, |
| 854 | struct radeon_cs_packet *pkt) |
| 855 | { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 856 | volatile uint32_t *ib; |
| 857 | unsigned i; |
| 858 | unsigned idx; |
| 859 | |
| 860 | ib = p->ib->ptr; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 861 | idx = pkt->idx; |
| 862 | for (i = 0; i <= (pkt->count + 1); i++, idx++) { |
| 863 | DRM_INFO("ib[%d]=0x%08X\n", idx, ib[idx]); |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | /** |
| 868 | * r100_cs_packet_parse() - parse cp packet and point ib index to next packet |
| 869 | * @parser: parser structure holding parsing context. |
| 870 | * @pkt: where to store packet informations |
| 871 | * |
| 872 | * Assume that chunk_ib_index is properly set. Will return -EINVAL |
| 873 | * if packet is bigger than remaining ib size. or if packets is unknown. |
| 874 | **/ |
| 875 | int r100_cs_packet_parse(struct radeon_cs_parser *p, |
| 876 | struct radeon_cs_packet *pkt, |
| 877 | unsigned idx) |
| 878 | { |
| 879 | struct radeon_cs_chunk *ib_chunk = &p->chunks[p->chunk_ib_idx]; |
Roel Kluin | fa99239 | 2009-08-03 14:20:32 +0200 | [diff] [blame] | 880 | uint32_t header; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 881 | |
| 882 | if (idx >= ib_chunk->length_dw) { |
| 883 | DRM_ERROR("Can not parse packet at %d after CS end %d !\n", |
| 884 | idx, ib_chunk->length_dw); |
| 885 | return -EINVAL; |
| 886 | } |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 887 | header = radeon_get_ib_value(p, idx); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 888 | pkt->idx = idx; |
| 889 | pkt->type = CP_PACKET_GET_TYPE(header); |
| 890 | pkt->count = CP_PACKET_GET_COUNT(header); |
| 891 | switch (pkt->type) { |
| 892 | case PACKET_TYPE0: |
| 893 | pkt->reg = CP_PACKET0_GET_REG(header); |
| 894 | pkt->one_reg_wr = CP_PACKET0_GET_ONE_REG_WR(header); |
| 895 | break; |
| 896 | case PACKET_TYPE3: |
| 897 | pkt->opcode = CP_PACKET3_GET_OPCODE(header); |
| 898 | break; |
| 899 | case PACKET_TYPE2: |
| 900 | pkt->count = -1; |
| 901 | break; |
| 902 | default: |
| 903 | DRM_ERROR("Unknown packet type %d at %d !\n", pkt->type, idx); |
| 904 | return -EINVAL; |
| 905 | } |
| 906 | if ((pkt->count + 1 + pkt->idx) >= ib_chunk->length_dw) { |
| 907 | DRM_ERROR("Packet (%d:%d:%d) end after CS buffer (%d) !\n", |
| 908 | pkt->idx, pkt->type, pkt->count, ib_chunk->length_dw); |
| 909 | return -EINVAL; |
| 910 | } |
| 911 | return 0; |
| 912 | } |
| 913 | |
| 914 | /** |
Dave Airlie | 531369e | 2009-06-29 11:21:25 +1000 | [diff] [blame] | 915 | * r100_cs_packet_next_vline() - parse userspace VLINE packet |
| 916 | * @parser: parser structure holding parsing context. |
| 917 | * |
| 918 | * Userspace sends a special sequence for VLINE waits. |
| 919 | * PACKET0 - VLINE_START_END + value |
| 920 | * PACKET0 - WAIT_UNTIL +_value |
| 921 | * RELOC (P3) - crtc_id in reloc. |
| 922 | * |
| 923 | * This function parses this and relocates the VLINE START END |
| 924 | * and WAIT UNTIL packets to the correct crtc. |
| 925 | * It also detects a switched off crtc and nulls out the |
| 926 | * wait in that case. |
| 927 | */ |
| 928 | int r100_cs_packet_parse_vline(struct radeon_cs_parser *p) |
| 929 | { |
Dave Airlie | 531369e | 2009-06-29 11:21:25 +1000 | [diff] [blame] | 930 | struct drm_mode_object *obj; |
| 931 | struct drm_crtc *crtc; |
| 932 | struct radeon_crtc *radeon_crtc; |
| 933 | struct radeon_cs_packet p3reloc, waitreloc; |
| 934 | int crtc_id; |
| 935 | int r; |
| 936 | uint32_t header, h_idx, reg; |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 937 | volatile uint32_t *ib; |
Dave Airlie | 531369e | 2009-06-29 11:21:25 +1000 | [diff] [blame] | 938 | |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 939 | ib = p->ib->ptr; |
Dave Airlie | 531369e | 2009-06-29 11:21:25 +1000 | [diff] [blame] | 940 | |
| 941 | /* parse the wait until */ |
| 942 | r = r100_cs_packet_parse(p, &waitreloc, p->idx); |
| 943 | if (r) |
| 944 | return r; |
| 945 | |
| 946 | /* check its a wait until and only 1 count */ |
| 947 | if (waitreloc.reg != RADEON_WAIT_UNTIL || |
| 948 | waitreloc.count != 0) { |
| 949 | DRM_ERROR("vline wait had illegal wait until segment\n"); |
| 950 | r = -EINVAL; |
| 951 | return r; |
| 952 | } |
| 953 | |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 954 | 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] | 955 | DRM_ERROR("vline wait had illegal wait until\n"); |
| 956 | r = -EINVAL; |
| 957 | return r; |
| 958 | } |
| 959 | |
| 960 | /* jump over the NOP */ |
Alex Deucher | 90ebd06 | 2009-09-25 16:39:24 -0400 | [diff] [blame] | 961 | r = r100_cs_packet_parse(p, &p3reloc, p->idx + waitreloc.count + 2); |
Dave Airlie | 531369e | 2009-06-29 11:21:25 +1000 | [diff] [blame] | 962 | if (r) |
| 963 | return r; |
| 964 | |
| 965 | h_idx = p->idx - 2; |
Alex Deucher | 90ebd06 | 2009-09-25 16:39:24 -0400 | [diff] [blame] | 966 | p->idx += waitreloc.count + 2; |
| 967 | p->idx += p3reloc.count + 2; |
Dave Airlie | 531369e | 2009-06-29 11:21:25 +1000 | [diff] [blame] | 968 | |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 969 | header = radeon_get_ib_value(p, h_idx); |
| 970 | crtc_id = radeon_get_ib_value(p, h_idx + 5); |
Dave Airlie | d4ac6a0 | 2009-10-08 11:32:49 +1000 | [diff] [blame] | 971 | reg = CP_PACKET0_GET_REG(header); |
Dave Airlie | 531369e | 2009-06-29 11:21:25 +1000 | [diff] [blame] | 972 | mutex_lock(&p->rdev->ddev->mode_config.mutex); |
| 973 | obj = drm_mode_object_find(p->rdev->ddev, crtc_id, DRM_MODE_OBJECT_CRTC); |
| 974 | if (!obj) { |
| 975 | DRM_ERROR("cannot find crtc %d\n", crtc_id); |
| 976 | r = -EINVAL; |
| 977 | goto out; |
| 978 | } |
| 979 | crtc = obj_to_crtc(obj); |
| 980 | radeon_crtc = to_radeon_crtc(crtc); |
| 981 | crtc_id = radeon_crtc->crtc_id; |
| 982 | |
| 983 | if (!crtc->enabled) { |
| 984 | /* 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] | 985 | ib[h_idx + 2] = PACKET2(0); |
| 986 | ib[h_idx + 3] = PACKET2(0); |
Dave Airlie | 531369e | 2009-06-29 11:21:25 +1000 | [diff] [blame] | 987 | } else if (crtc_id == 1) { |
| 988 | switch (reg) { |
| 989 | case AVIVO_D1MODE_VLINE_START_END: |
Alex Deucher | 90ebd06 | 2009-09-25 16:39:24 -0400 | [diff] [blame] | 990 | header &= ~R300_CP_PACKET0_REG_MASK; |
Dave Airlie | 531369e | 2009-06-29 11:21:25 +1000 | [diff] [blame] | 991 | header |= AVIVO_D2MODE_VLINE_START_END >> 2; |
| 992 | break; |
| 993 | case RADEON_CRTC_GUI_TRIG_VLINE: |
Alex Deucher | 90ebd06 | 2009-09-25 16:39:24 -0400 | [diff] [blame] | 994 | header &= ~R300_CP_PACKET0_REG_MASK; |
Dave Airlie | 531369e | 2009-06-29 11:21:25 +1000 | [diff] [blame] | 995 | header |= RADEON_CRTC2_GUI_TRIG_VLINE >> 2; |
| 996 | break; |
| 997 | default: |
| 998 | DRM_ERROR("unknown crtc reloc\n"); |
| 999 | r = -EINVAL; |
| 1000 | goto out; |
| 1001 | } |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1002 | ib[h_idx] = header; |
| 1003 | ib[h_idx + 3] |= RADEON_ENG_DISPLAY_SELECT_CRTC1; |
Dave Airlie | 531369e | 2009-06-29 11:21:25 +1000 | [diff] [blame] | 1004 | } |
| 1005 | out: |
| 1006 | mutex_unlock(&p->rdev->ddev->mode_config.mutex); |
| 1007 | return r; |
| 1008 | } |
| 1009 | |
| 1010 | /** |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1011 | * r100_cs_packet_next_reloc() - parse next packet which should be reloc packet3 |
| 1012 | * @parser: parser structure holding parsing context. |
| 1013 | * @data: pointer to relocation data |
| 1014 | * @offset_start: starting offset |
| 1015 | * @offset_mask: offset mask (to align start offset on) |
| 1016 | * @reloc: reloc informations |
| 1017 | * |
| 1018 | * Check next packet is relocation packet3, do bo validation and compute |
| 1019 | * GPU offset using the provided start. |
| 1020 | **/ |
| 1021 | int r100_cs_packet_next_reloc(struct radeon_cs_parser *p, |
| 1022 | struct radeon_cs_reloc **cs_reloc) |
| 1023 | { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1024 | struct radeon_cs_chunk *relocs_chunk; |
| 1025 | struct radeon_cs_packet p3reloc; |
| 1026 | unsigned idx; |
| 1027 | int r; |
| 1028 | |
| 1029 | if (p->chunk_relocs_idx == -1) { |
| 1030 | DRM_ERROR("No relocation chunk !\n"); |
| 1031 | return -EINVAL; |
| 1032 | } |
| 1033 | *cs_reloc = NULL; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1034 | relocs_chunk = &p->chunks[p->chunk_relocs_idx]; |
| 1035 | r = r100_cs_packet_parse(p, &p3reloc, p->idx); |
| 1036 | if (r) { |
| 1037 | return r; |
| 1038 | } |
| 1039 | p->idx += p3reloc.count + 2; |
| 1040 | if (p3reloc.type != PACKET_TYPE3 || p3reloc.opcode != PACKET3_NOP) { |
| 1041 | DRM_ERROR("No packet3 for relocation for packet at %d.\n", |
| 1042 | p3reloc.idx); |
| 1043 | r100_cs_dump_packet(p, &p3reloc); |
| 1044 | return -EINVAL; |
| 1045 | } |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1046 | idx = radeon_get_ib_value(p, p3reloc.idx + 1); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1047 | if (idx >= relocs_chunk->length_dw) { |
| 1048 | DRM_ERROR("Relocs at %d after relocations chunk end %d !\n", |
| 1049 | idx, relocs_chunk->length_dw); |
| 1050 | r100_cs_dump_packet(p, &p3reloc); |
| 1051 | return -EINVAL; |
| 1052 | } |
| 1053 | /* FIXME: we assume reloc size is 4 dwords */ |
| 1054 | *cs_reloc = p->relocs_ptr[(idx / 4)]; |
| 1055 | return 0; |
| 1056 | } |
| 1057 | |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1058 | static int r100_get_vtx_size(uint32_t vtx_fmt) |
| 1059 | { |
| 1060 | int vtx_size; |
| 1061 | vtx_size = 2; |
| 1062 | /* ordered according to bits in spec */ |
| 1063 | if (vtx_fmt & RADEON_SE_VTX_FMT_W0) |
| 1064 | vtx_size++; |
| 1065 | if (vtx_fmt & RADEON_SE_VTX_FMT_FPCOLOR) |
| 1066 | vtx_size += 3; |
| 1067 | if (vtx_fmt & RADEON_SE_VTX_FMT_FPALPHA) |
| 1068 | vtx_size++; |
| 1069 | if (vtx_fmt & RADEON_SE_VTX_FMT_PKCOLOR) |
| 1070 | vtx_size++; |
| 1071 | if (vtx_fmt & RADEON_SE_VTX_FMT_FPSPEC) |
| 1072 | vtx_size += 3; |
| 1073 | if (vtx_fmt & RADEON_SE_VTX_FMT_FPFOG) |
| 1074 | vtx_size++; |
| 1075 | if (vtx_fmt & RADEON_SE_VTX_FMT_PKSPEC) |
| 1076 | vtx_size++; |
| 1077 | if (vtx_fmt & RADEON_SE_VTX_FMT_ST0) |
| 1078 | vtx_size += 2; |
| 1079 | if (vtx_fmt & RADEON_SE_VTX_FMT_ST1) |
| 1080 | vtx_size += 2; |
| 1081 | if (vtx_fmt & RADEON_SE_VTX_FMT_Q1) |
| 1082 | vtx_size++; |
| 1083 | if (vtx_fmt & RADEON_SE_VTX_FMT_ST2) |
| 1084 | vtx_size += 2; |
| 1085 | if (vtx_fmt & RADEON_SE_VTX_FMT_Q2) |
| 1086 | vtx_size++; |
| 1087 | if (vtx_fmt & RADEON_SE_VTX_FMT_ST3) |
| 1088 | vtx_size += 2; |
| 1089 | if (vtx_fmt & RADEON_SE_VTX_FMT_Q3) |
| 1090 | vtx_size++; |
| 1091 | if (vtx_fmt & RADEON_SE_VTX_FMT_Q0) |
| 1092 | vtx_size++; |
| 1093 | /* blend weight */ |
| 1094 | if (vtx_fmt & (0x7 << 15)) |
| 1095 | vtx_size += (vtx_fmt >> 15) & 0x7; |
| 1096 | if (vtx_fmt & RADEON_SE_VTX_FMT_N0) |
| 1097 | vtx_size += 3; |
| 1098 | if (vtx_fmt & RADEON_SE_VTX_FMT_XY1) |
| 1099 | vtx_size += 2; |
| 1100 | if (vtx_fmt & RADEON_SE_VTX_FMT_Z1) |
| 1101 | vtx_size++; |
| 1102 | if (vtx_fmt & RADEON_SE_VTX_FMT_W1) |
| 1103 | vtx_size++; |
| 1104 | if (vtx_fmt & RADEON_SE_VTX_FMT_N1) |
| 1105 | vtx_size++; |
| 1106 | if (vtx_fmt & RADEON_SE_VTX_FMT_Z) |
| 1107 | vtx_size++; |
| 1108 | return vtx_size; |
| 1109 | } |
| 1110 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1111 | static int r100_packet0_check(struct radeon_cs_parser *p, |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1112 | struct radeon_cs_packet *pkt, |
| 1113 | unsigned idx, unsigned reg) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1114 | { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1115 | struct radeon_cs_reloc *reloc; |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1116 | struct r100_cs_track *track; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1117 | volatile uint32_t *ib; |
| 1118 | uint32_t tmp; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1119 | int r; |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1120 | int i, face; |
Dave Airlie | e024e11 | 2009-06-24 09:48:08 +1000 | [diff] [blame] | 1121 | u32 tile_flags = 0; |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1122 | u32 idx_value; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1123 | |
| 1124 | ib = p->ib->ptr; |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1125 | track = (struct r100_cs_track *)p->track; |
| 1126 | |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1127 | idx_value = radeon_get_ib_value(p, idx); |
| 1128 | |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1129 | switch (reg) { |
| 1130 | case RADEON_CRTC_GUI_TRIG_VLINE: |
| 1131 | r = r100_cs_packet_parse_vline(p); |
| 1132 | if (r) { |
| 1133 | DRM_ERROR("No reloc for ib[%d]=0x%04X\n", |
| 1134 | idx, reg); |
| 1135 | r100_cs_dump_packet(p, pkt); |
| 1136 | return r; |
| 1137 | } |
| 1138 | break; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1139 | /* FIXME: only allow PACKET3 blit? easier to check for out of |
| 1140 | * range access */ |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1141 | case RADEON_DST_PITCH_OFFSET: |
| 1142 | case RADEON_SRC_PITCH_OFFSET: |
| 1143 | r = r100_reloc_pitch_offset(p, pkt, idx, reg); |
| 1144 | if (r) |
| 1145 | return r; |
| 1146 | break; |
| 1147 | case RADEON_RB3D_DEPTHOFFSET: |
| 1148 | r = r100_cs_packet_next_reloc(p, &reloc); |
| 1149 | if (r) { |
| 1150 | DRM_ERROR("No reloc for ib[%d]=0x%04X\n", |
| 1151 | idx, reg); |
| 1152 | r100_cs_dump_packet(p, pkt); |
| 1153 | return r; |
| 1154 | } |
| 1155 | track->zb.robj = reloc->robj; |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1156 | track->zb.offset = idx_value; |
| 1157 | ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1158 | break; |
| 1159 | case RADEON_RB3D_COLOROFFSET: |
| 1160 | r = r100_cs_packet_next_reloc(p, &reloc); |
| 1161 | if (r) { |
| 1162 | DRM_ERROR("No reloc for ib[%d]=0x%04X\n", |
| 1163 | idx, reg); |
| 1164 | r100_cs_dump_packet(p, pkt); |
| 1165 | return r; |
| 1166 | } |
| 1167 | track->cb[0].robj = reloc->robj; |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1168 | track->cb[0].offset = idx_value; |
| 1169 | ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1170 | break; |
| 1171 | case RADEON_PP_TXOFFSET_0: |
| 1172 | case RADEON_PP_TXOFFSET_1: |
| 1173 | case RADEON_PP_TXOFFSET_2: |
| 1174 | i = (reg - RADEON_PP_TXOFFSET_0) / 24; |
| 1175 | r = r100_cs_packet_next_reloc(p, &reloc); |
| 1176 | if (r) { |
| 1177 | DRM_ERROR("No reloc for ib[%d]=0x%04X\n", |
| 1178 | idx, reg); |
| 1179 | r100_cs_dump_packet(p, pkt); |
| 1180 | return r; |
| 1181 | } |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1182 | ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1183 | track->textures[i].robj = reloc->robj; |
| 1184 | break; |
| 1185 | case RADEON_PP_CUBIC_OFFSET_T0_0: |
| 1186 | case RADEON_PP_CUBIC_OFFSET_T0_1: |
| 1187 | case RADEON_PP_CUBIC_OFFSET_T0_2: |
| 1188 | case RADEON_PP_CUBIC_OFFSET_T0_3: |
| 1189 | case RADEON_PP_CUBIC_OFFSET_T0_4: |
| 1190 | i = (reg - RADEON_PP_CUBIC_OFFSET_T0_0) / 4; |
| 1191 | r = r100_cs_packet_next_reloc(p, &reloc); |
| 1192 | if (r) { |
| 1193 | DRM_ERROR("No reloc for ib[%d]=0x%04X\n", |
| 1194 | idx, reg); |
| 1195 | r100_cs_dump_packet(p, pkt); |
| 1196 | return r; |
| 1197 | } |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1198 | track->textures[0].cube_info[i].offset = idx_value; |
| 1199 | ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1200 | track->textures[0].cube_info[i].robj = reloc->robj; |
| 1201 | break; |
| 1202 | case RADEON_PP_CUBIC_OFFSET_T1_0: |
| 1203 | case RADEON_PP_CUBIC_OFFSET_T1_1: |
| 1204 | case RADEON_PP_CUBIC_OFFSET_T1_2: |
| 1205 | case RADEON_PP_CUBIC_OFFSET_T1_3: |
| 1206 | case RADEON_PP_CUBIC_OFFSET_T1_4: |
| 1207 | i = (reg - RADEON_PP_CUBIC_OFFSET_T1_0) / 4; |
| 1208 | r = r100_cs_packet_next_reloc(p, &reloc); |
| 1209 | if (r) { |
| 1210 | DRM_ERROR("No reloc for ib[%d]=0x%04X\n", |
| 1211 | idx, reg); |
| 1212 | r100_cs_dump_packet(p, pkt); |
| 1213 | return r; |
| 1214 | } |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1215 | track->textures[1].cube_info[i].offset = idx_value; |
| 1216 | ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1217 | track->textures[1].cube_info[i].robj = reloc->robj; |
| 1218 | break; |
| 1219 | case RADEON_PP_CUBIC_OFFSET_T2_0: |
| 1220 | case RADEON_PP_CUBIC_OFFSET_T2_1: |
| 1221 | case RADEON_PP_CUBIC_OFFSET_T2_2: |
| 1222 | case RADEON_PP_CUBIC_OFFSET_T2_3: |
| 1223 | case RADEON_PP_CUBIC_OFFSET_T2_4: |
| 1224 | i = (reg - RADEON_PP_CUBIC_OFFSET_T2_0) / 4; |
| 1225 | r = r100_cs_packet_next_reloc(p, &reloc); |
| 1226 | if (r) { |
| 1227 | DRM_ERROR("No reloc for ib[%d]=0x%04X\n", |
| 1228 | idx, reg); |
| 1229 | r100_cs_dump_packet(p, pkt); |
| 1230 | return r; |
| 1231 | } |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1232 | track->textures[2].cube_info[i].offset = idx_value; |
| 1233 | ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1234 | track->textures[2].cube_info[i].robj = reloc->robj; |
| 1235 | break; |
| 1236 | case RADEON_RE_WIDTH_HEIGHT: |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1237 | track->maxy = ((idx_value >> 16) & 0x7FF); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1238 | break; |
| 1239 | case RADEON_RB3D_COLORPITCH: |
| 1240 | r = r100_cs_packet_next_reloc(p, &reloc); |
| 1241 | if (r) { |
| 1242 | DRM_ERROR("No reloc for ib[%d]=0x%04X\n", |
| 1243 | idx, reg); |
| 1244 | r100_cs_dump_packet(p, pkt); |
| 1245 | return r; |
| 1246 | } |
Dave Airlie | e024e11 | 2009-06-24 09:48:08 +1000 | [diff] [blame] | 1247 | |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1248 | if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) |
| 1249 | tile_flags |= RADEON_COLOR_TILE_ENABLE; |
| 1250 | if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO) |
| 1251 | tile_flags |= RADEON_COLOR_MICROTILE_ENABLE; |
Dave Airlie | e024e11 | 2009-06-24 09:48:08 +1000 | [diff] [blame] | 1252 | |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1253 | tmp = idx_value & ~(0x7 << 16); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1254 | tmp |= tile_flags; |
| 1255 | ib[idx] = tmp; |
| 1256 | |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1257 | track->cb[0].pitch = idx_value & RADEON_COLORPITCH_MASK; |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1258 | break; |
| 1259 | case RADEON_RB3D_DEPTHPITCH: |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1260 | track->zb.pitch = idx_value & RADEON_DEPTHPITCH_MASK; |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1261 | break; |
| 1262 | case RADEON_RB3D_CNTL: |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1263 | switch ((idx_value >> RADEON_RB3D_COLOR_FORMAT_SHIFT) & 0x1f) { |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1264 | case 7: |
| 1265 | case 8: |
| 1266 | case 9: |
| 1267 | case 11: |
| 1268 | case 12: |
| 1269 | track->cb[0].cpp = 1; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1270 | break; |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1271 | case 3: |
| 1272 | case 4: |
| 1273 | case 15: |
| 1274 | track->cb[0].cpp = 2; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1275 | break; |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1276 | case 6: |
| 1277 | track->cb[0].cpp = 4; |
Dave Airlie | 17782d9 | 2009-08-21 10:07:54 +1000 | [diff] [blame] | 1278 | break; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1279 | default: |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1280 | DRM_ERROR("Invalid color buffer format (%d) !\n", |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1281 | ((idx_value >> RADEON_RB3D_COLOR_FORMAT_SHIFT) & 0x1f)); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1282 | return -EINVAL; |
| 1283 | } |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1284 | track->z_enabled = !!(idx_value & RADEON_Z_ENABLE); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1285 | break; |
| 1286 | case RADEON_RB3D_ZSTENCILCNTL: |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1287 | switch (idx_value & 0xf) { |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1288 | case 0: |
| 1289 | track->zb.cpp = 2; |
| 1290 | break; |
| 1291 | case 2: |
| 1292 | case 3: |
| 1293 | case 4: |
| 1294 | case 5: |
| 1295 | case 9: |
| 1296 | case 11: |
| 1297 | track->zb.cpp = 4; |
| 1298 | break; |
| 1299 | default: |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1300 | break; |
| 1301 | } |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1302 | break; |
| 1303 | case RADEON_RB3D_ZPASS_ADDR: |
| 1304 | r = r100_cs_packet_next_reloc(p, &reloc); |
| 1305 | if (r) { |
| 1306 | DRM_ERROR("No reloc for ib[%d]=0x%04X\n", |
| 1307 | idx, reg); |
| 1308 | r100_cs_dump_packet(p, pkt); |
| 1309 | return r; |
| 1310 | } |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1311 | ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1312 | break; |
| 1313 | case RADEON_PP_CNTL: |
| 1314 | { |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1315 | uint32_t temp = idx_value >> 4; |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1316 | for (i = 0; i < track->num_texture; i++) |
| 1317 | track->textures[i].enabled = !!(temp & (1 << i)); |
| 1318 | } |
| 1319 | break; |
| 1320 | case RADEON_SE_VF_CNTL: |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1321 | track->vap_vf_cntl = idx_value; |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1322 | break; |
| 1323 | case RADEON_SE_VTX_FMT: |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1324 | track->vtx_size = r100_get_vtx_size(idx_value); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1325 | break; |
| 1326 | case RADEON_PP_TEX_SIZE_0: |
| 1327 | case RADEON_PP_TEX_SIZE_1: |
| 1328 | case RADEON_PP_TEX_SIZE_2: |
| 1329 | i = (reg - RADEON_PP_TEX_SIZE_0) / 8; |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1330 | track->textures[i].width = (idx_value & RADEON_TEX_USIZE_MASK) + 1; |
| 1331 | track->textures[i].height = ((idx_value & RADEON_TEX_VSIZE_MASK) >> RADEON_TEX_VSIZE_SHIFT) + 1; |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1332 | break; |
| 1333 | case RADEON_PP_TEX_PITCH_0: |
| 1334 | case RADEON_PP_TEX_PITCH_1: |
| 1335 | case RADEON_PP_TEX_PITCH_2: |
| 1336 | i = (reg - RADEON_PP_TEX_PITCH_0) / 8; |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1337 | track->textures[i].pitch = idx_value + 32; |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1338 | break; |
| 1339 | case RADEON_PP_TXFILTER_0: |
| 1340 | case RADEON_PP_TXFILTER_1: |
| 1341 | case RADEON_PP_TXFILTER_2: |
| 1342 | i = (reg - RADEON_PP_TXFILTER_0) / 24; |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1343 | track->textures[i].num_levels = ((idx_value & RADEON_MAX_MIP_LEVEL_MASK) |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1344 | >> RADEON_MAX_MIP_LEVEL_SHIFT); |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1345 | tmp = (idx_value >> 23) & 0x7; |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1346 | if (tmp == 2 || tmp == 6) |
| 1347 | track->textures[i].roundup_w = false; |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1348 | tmp = (idx_value >> 27) & 0x7; |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1349 | if (tmp == 2 || tmp == 6) |
| 1350 | track->textures[i].roundup_h = false; |
| 1351 | break; |
| 1352 | case RADEON_PP_TXFORMAT_0: |
| 1353 | case RADEON_PP_TXFORMAT_1: |
| 1354 | case RADEON_PP_TXFORMAT_2: |
| 1355 | i = (reg - RADEON_PP_TXFORMAT_0) / 24; |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1356 | if (idx_value & RADEON_TXFORMAT_NON_POWER2) { |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1357 | track->textures[i].use_pitch = 1; |
| 1358 | } else { |
| 1359 | track->textures[i].use_pitch = 0; |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1360 | track->textures[i].width = 1 << ((idx_value >> RADEON_TXFORMAT_WIDTH_SHIFT) & RADEON_TXFORMAT_WIDTH_MASK); |
| 1361 | 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] | 1362 | } |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1363 | if (idx_value & RADEON_TXFORMAT_CUBIC_MAP_ENABLE) |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1364 | track->textures[i].tex_coord_type = 2; |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1365 | switch ((idx_value & RADEON_TXFORMAT_FORMAT_MASK)) { |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1366 | case RADEON_TXFORMAT_I8: |
| 1367 | case RADEON_TXFORMAT_RGB332: |
| 1368 | case RADEON_TXFORMAT_Y8: |
| 1369 | track->textures[i].cpp = 1; |
| 1370 | break; |
| 1371 | case RADEON_TXFORMAT_AI88: |
| 1372 | case RADEON_TXFORMAT_ARGB1555: |
| 1373 | case RADEON_TXFORMAT_RGB565: |
| 1374 | case RADEON_TXFORMAT_ARGB4444: |
| 1375 | case RADEON_TXFORMAT_VYUY422: |
| 1376 | case RADEON_TXFORMAT_YVYU422: |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1377 | case RADEON_TXFORMAT_SHADOW16: |
| 1378 | case RADEON_TXFORMAT_LDUDV655: |
| 1379 | case RADEON_TXFORMAT_DUDV88: |
| 1380 | track->textures[i].cpp = 2; |
| 1381 | break; |
| 1382 | case RADEON_TXFORMAT_ARGB8888: |
| 1383 | case RADEON_TXFORMAT_RGBA8888: |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1384 | case RADEON_TXFORMAT_SHADOW32: |
| 1385 | case RADEON_TXFORMAT_LDUDUV8888: |
| 1386 | track->textures[i].cpp = 4; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1387 | break; |
Dave Airlie | d785d78 | 2009-12-07 13:16:06 +1000 | [diff] [blame] | 1388 | case RADEON_TXFORMAT_DXT1: |
| 1389 | track->textures[i].cpp = 1; |
| 1390 | track->textures[i].compress_format = R100_TRACK_COMP_DXT1; |
| 1391 | break; |
| 1392 | case RADEON_TXFORMAT_DXT23: |
| 1393 | case RADEON_TXFORMAT_DXT45: |
| 1394 | track->textures[i].cpp = 1; |
| 1395 | track->textures[i].compress_format = R100_TRACK_COMP_DXT35; |
| 1396 | break; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1397 | } |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1398 | track->textures[i].cube_info[4].width = 1 << ((idx_value >> 16) & 0xf); |
| 1399 | track->textures[i].cube_info[4].height = 1 << ((idx_value >> 20) & 0xf); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1400 | break; |
| 1401 | case RADEON_PP_CUBIC_FACES_0: |
| 1402 | case RADEON_PP_CUBIC_FACES_1: |
| 1403 | case RADEON_PP_CUBIC_FACES_2: |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1404 | tmp = idx_value; |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1405 | i = (reg - RADEON_PP_CUBIC_FACES_0) / 4; |
| 1406 | for (face = 0; face < 4; face++) { |
| 1407 | track->textures[i].cube_info[face].width = 1 << ((tmp >> (face * 8)) & 0xf); |
| 1408 | track->textures[i].cube_info[face].height = 1 << ((tmp >> ((face * 8) + 4)) & 0xf); |
| 1409 | } |
| 1410 | break; |
| 1411 | default: |
| 1412 | printk(KERN_ERR "Forbidden register 0x%04X in cs at %d\n", |
| 1413 | reg, idx); |
| 1414 | return -EINVAL; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1415 | } |
| 1416 | return 0; |
| 1417 | } |
| 1418 | |
Jerome Glisse | 068a117 | 2009-06-17 13:28:30 +0200 | [diff] [blame] | 1419 | int r100_cs_track_check_pkt3_indx_buffer(struct radeon_cs_parser *p, |
| 1420 | struct radeon_cs_packet *pkt, |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 1421 | struct radeon_bo *robj) |
Jerome Glisse | 068a117 | 2009-06-17 13:28:30 +0200 | [diff] [blame] | 1422 | { |
Jerome Glisse | 068a117 | 2009-06-17 13:28:30 +0200 | [diff] [blame] | 1423 | unsigned idx; |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1424 | u32 value; |
Jerome Glisse | 068a117 | 2009-06-17 13:28:30 +0200 | [diff] [blame] | 1425 | idx = pkt->idx + 1; |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1426 | value = radeon_get_ib_value(p, idx + 2); |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 1427 | if ((value + 1) > radeon_bo_size(robj)) { |
Jerome Glisse | 068a117 | 2009-06-17 13:28:30 +0200 | [diff] [blame] | 1428 | DRM_ERROR("[drm] Buffer too small for PACKET3 INDX_BUFFER " |
| 1429 | "(need %u have %lu) !\n", |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1430 | value + 1, |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 1431 | radeon_bo_size(robj)); |
Jerome Glisse | 068a117 | 2009-06-17 13:28:30 +0200 | [diff] [blame] | 1432 | return -EINVAL; |
| 1433 | } |
| 1434 | return 0; |
| 1435 | } |
| 1436 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1437 | static int r100_packet3_check(struct radeon_cs_parser *p, |
| 1438 | struct radeon_cs_packet *pkt) |
| 1439 | { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1440 | struct radeon_cs_reloc *reloc; |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1441 | struct r100_cs_track *track; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1442 | unsigned idx; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1443 | volatile uint32_t *ib; |
| 1444 | int r; |
| 1445 | |
| 1446 | ib = p->ib->ptr; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1447 | idx = pkt->idx + 1; |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1448 | track = (struct r100_cs_track *)p->track; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1449 | switch (pkt->opcode) { |
| 1450 | case PACKET3_3D_LOAD_VBPNTR: |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1451 | r = r100_packet3_load_vbpntr(p, pkt, idx); |
| 1452 | if (r) |
| 1453 | return r; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1454 | break; |
| 1455 | case PACKET3_INDX_BUFFER: |
| 1456 | r = r100_cs_packet_next_reloc(p, &reloc); |
| 1457 | if (r) { |
| 1458 | DRM_ERROR("No reloc for packet3 %d\n", pkt->opcode); |
| 1459 | r100_cs_dump_packet(p, pkt); |
| 1460 | return r; |
| 1461 | } |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1462 | 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] | 1463 | r = r100_cs_track_check_pkt3_indx_buffer(p, pkt, reloc->robj); |
| 1464 | if (r) { |
| 1465 | return r; |
| 1466 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1467 | break; |
| 1468 | case 0x23: |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1469 | /* 3D_RNDR_GEN_INDX_PRIM on r100/r200 */ |
| 1470 | r = r100_cs_packet_next_reloc(p, &reloc); |
| 1471 | if (r) { |
| 1472 | DRM_ERROR("No reloc for packet3 %d\n", pkt->opcode); |
| 1473 | r100_cs_dump_packet(p, pkt); |
| 1474 | return r; |
| 1475 | } |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1476 | 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] | 1477 | track->num_arrays = 1; |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1478 | 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] | 1479 | |
| 1480 | track->arrays[0].robj = reloc->robj; |
| 1481 | track->arrays[0].esize = track->vtx_size; |
| 1482 | |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1483 | track->max_indx = radeon_get_ib_value(p, idx+1); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1484 | |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1485 | track->vap_vf_cntl = radeon_get_ib_value(p, idx+3); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1486 | track->immd_dwords = pkt->count - 1; |
| 1487 | r = r100_cs_track_check(p->rdev, track); |
| 1488 | if (r) |
| 1489 | return r; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1490 | break; |
| 1491 | case PACKET3_3D_DRAW_IMMD: |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1492 | if (((radeon_get_ib_value(p, idx + 1) >> 4) & 0x3) != 3) { |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1493 | DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n"); |
| 1494 | return -EINVAL; |
| 1495 | } |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1496 | track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1497 | track->immd_dwords = pkt->count - 1; |
| 1498 | r = r100_cs_track_check(p->rdev, track); |
| 1499 | if (r) |
| 1500 | return r; |
| 1501 | break; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1502 | /* triggers drawing using in-packet vertex data */ |
| 1503 | case PACKET3_3D_DRAW_IMMD_2: |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1504 | if (((radeon_get_ib_value(p, idx) >> 4) & 0x3) != 3) { |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1505 | DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n"); |
| 1506 | return -EINVAL; |
| 1507 | } |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1508 | track->vap_vf_cntl = radeon_get_ib_value(p, idx); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1509 | track->immd_dwords = pkt->count; |
| 1510 | r = r100_cs_track_check(p->rdev, track); |
| 1511 | if (r) |
| 1512 | return r; |
| 1513 | break; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1514 | /* triggers drawing using in-packet vertex data */ |
| 1515 | case PACKET3_3D_DRAW_VBUF_2: |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1516 | track->vap_vf_cntl = radeon_get_ib_value(p, idx); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1517 | r = r100_cs_track_check(p->rdev, track); |
| 1518 | if (r) |
| 1519 | return r; |
| 1520 | break; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1521 | /* triggers drawing of vertex buffers setup elsewhere */ |
| 1522 | case PACKET3_3D_DRAW_INDX_2: |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1523 | track->vap_vf_cntl = radeon_get_ib_value(p, idx); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1524 | r = r100_cs_track_check(p->rdev, track); |
| 1525 | if (r) |
| 1526 | return r; |
| 1527 | break; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1528 | /* triggers drawing using indices to vertex buffer */ |
| 1529 | case PACKET3_3D_DRAW_VBUF: |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1530 | track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1531 | r = r100_cs_track_check(p->rdev, track); |
| 1532 | if (r) |
| 1533 | return r; |
| 1534 | break; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1535 | /* triggers drawing of vertex buffers setup elsewhere */ |
| 1536 | case PACKET3_3D_DRAW_INDX: |
Dave Airlie | 513bcb4 | 2009-09-23 16:56:27 +1000 | [diff] [blame] | 1537 | track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1538 | r = r100_cs_track_check(p->rdev, track); |
| 1539 | if (r) |
| 1540 | return r; |
| 1541 | break; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1542 | /* triggers drawing using indices to vertex buffer */ |
| 1543 | case PACKET3_NOP: |
| 1544 | break; |
| 1545 | default: |
| 1546 | DRM_ERROR("Packet3 opcode %x not supported\n", pkt->opcode); |
| 1547 | return -EINVAL; |
| 1548 | } |
| 1549 | return 0; |
| 1550 | } |
| 1551 | |
| 1552 | int r100_cs_parse(struct radeon_cs_parser *p) |
| 1553 | { |
| 1554 | struct radeon_cs_packet pkt; |
Jerome Glisse | 9f022dd | 2009-09-11 15:35:22 +0200 | [diff] [blame] | 1555 | struct r100_cs_track *track; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1556 | int r; |
| 1557 | |
Jerome Glisse | 9f022dd | 2009-09-11 15:35:22 +0200 | [diff] [blame] | 1558 | track = kzalloc(sizeof(*track), GFP_KERNEL); |
| 1559 | r100_cs_track_clear(p->rdev, track); |
| 1560 | p->track = track; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1561 | do { |
| 1562 | r = r100_cs_packet_parse(p, &pkt, p->idx); |
| 1563 | if (r) { |
| 1564 | return r; |
| 1565 | } |
| 1566 | p->idx += pkt.count + 2; |
| 1567 | switch (pkt.type) { |
Jerome Glisse | 068a117 | 2009-06-17 13:28:30 +0200 | [diff] [blame] | 1568 | case PACKET_TYPE0: |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 1569 | if (p->rdev->family >= CHIP_R200) |
| 1570 | r = r100_cs_parse_packet0(p, &pkt, |
| 1571 | p->rdev->config.r100.reg_safe_bm, |
| 1572 | p->rdev->config.r100.reg_safe_bm_size, |
| 1573 | &r200_packet0_check); |
| 1574 | else |
| 1575 | r = r100_cs_parse_packet0(p, &pkt, |
| 1576 | p->rdev->config.r100.reg_safe_bm, |
| 1577 | p->rdev->config.r100.reg_safe_bm_size, |
| 1578 | &r100_packet0_check); |
Jerome Glisse | 068a117 | 2009-06-17 13:28:30 +0200 | [diff] [blame] | 1579 | break; |
| 1580 | case PACKET_TYPE2: |
| 1581 | break; |
| 1582 | case PACKET_TYPE3: |
| 1583 | r = r100_packet3_check(p, &pkt); |
| 1584 | break; |
| 1585 | default: |
| 1586 | DRM_ERROR("Unknown packet type %d !\n", |
| 1587 | pkt.type); |
| 1588 | return -EINVAL; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1589 | } |
| 1590 | if (r) { |
| 1591 | return r; |
| 1592 | } |
| 1593 | } while (p->idx < p->chunks[p->chunk_ib_idx].length_dw); |
| 1594 | return 0; |
| 1595 | } |
| 1596 | |
| 1597 | |
| 1598 | /* |
| 1599 | * Global GPU functions |
| 1600 | */ |
| 1601 | void r100_errata(struct radeon_device *rdev) |
| 1602 | { |
| 1603 | rdev->pll_errata = 0; |
| 1604 | |
| 1605 | if (rdev->family == CHIP_RV200 || rdev->family == CHIP_RS200) { |
| 1606 | rdev->pll_errata |= CHIP_ERRATA_PLL_DUMMYREADS; |
| 1607 | } |
| 1608 | |
| 1609 | if (rdev->family == CHIP_RV100 || |
| 1610 | rdev->family == CHIP_RS100 || |
| 1611 | rdev->family == CHIP_RS200) { |
| 1612 | rdev->pll_errata |= CHIP_ERRATA_PLL_DELAY; |
| 1613 | } |
| 1614 | } |
| 1615 | |
| 1616 | /* Wait for vertical sync on primary CRTC */ |
| 1617 | void r100_gpu_wait_for_vsync(struct radeon_device *rdev) |
| 1618 | { |
| 1619 | uint32_t crtc_gen_cntl, tmp; |
| 1620 | int i; |
| 1621 | |
| 1622 | crtc_gen_cntl = RREG32(RADEON_CRTC_GEN_CNTL); |
| 1623 | if ((crtc_gen_cntl & RADEON_CRTC_DISP_REQ_EN_B) || |
| 1624 | !(crtc_gen_cntl & RADEON_CRTC_EN)) { |
| 1625 | return; |
| 1626 | } |
| 1627 | /* Clear the CRTC_VBLANK_SAVE bit */ |
| 1628 | WREG32(RADEON_CRTC_STATUS, RADEON_CRTC_VBLANK_SAVE_CLEAR); |
| 1629 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 1630 | tmp = RREG32(RADEON_CRTC_STATUS); |
| 1631 | if (tmp & RADEON_CRTC_VBLANK_SAVE) { |
| 1632 | return; |
| 1633 | } |
| 1634 | DRM_UDELAY(1); |
| 1635 | } |
| 1636 | } |
| 1637 | |
| 1638 | /* Wait for vertical sync on secondary CRTC */ |
| 1639 | void r100_gpu_wait_for_vsync2(struct radeon_device *rdev) |
| 1640 | { |
| 1641 | uint32_t crtc2_gen_cntl, tmp; |
| 1642 | int i; |
| 1643 | |
| 1644 | crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL); |
| 1645 | if ((crtc2_gen_cntl & RADEON_CRTC2_DISP_REQ_EN_B) || |
| 1646 | !(crtc2_gen_cntl & RADEON_CRTC2_EN)) |
| 1647 | return; |
| 1648 | |
| 1649 | /* Clear the CRTC_VBLANK_SAVE bit */ |
| 1650 | WREG32(RADEON_CRTC2_STATUS, RADEON_CRTC2_VBLANK_SAVE_CLEAR); |
| 1651 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 1652 | tmp = RREG32(RADEON_CRTC2_STATUS); |
| 1653 | if (tmp & RADEON_CRTC2_VBLANK_SAVE) { |
| 1654 | return; |
| 1655 | } |
| 1656 | DRM_UDELAY(1); |
| 1657 | } |
| 1658 | } |
| 1659 | |
| 1660 | int r100_rbbm_fifo_wait_for_entry(struct radeon_device *rdev, unsigned n) |
| 1661 | { |
| 1662 | unsigned i; |
| 1663 | uint32_t tmp; |
| 1664 | |
| 1665 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 1666 | tmp = RREG32(RADEON_RBBM_STATUS) & RADEON_RBBM_FIFOCNT_MASK; |
| 1667 | if (tmp >= n) { |
| 1668 | return 0; |
| 1669 | } |
| 1670 | DRM_UDELAY(1); |
| 1671 | } |
| 1672 | return -1; |
| 1673 | } |
| 1674 | |
| 1675 | int r100_gui_wait_for_idle(struct radeon_device *rdev) |
| 1676 | { |
| 1677 | unsigned i; |
| 1678 | uint32_t tmp; |
| 1679 | |
| 1680 | if (r100_rbbm_fifo_wait_for_entry(rdev, 64)) { |
| 1681 | printk(KERN_WARNING "radeon: wait for empty RBBM fifo failed !" |
| 1682 | " Bad things might happen.\n"); |
| 1683 | } |
| 1684 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 1685 | tmp = RREG32(RADEON_RBBM_STATUS); |
| 1686 | if (!(tmp & (1 << 31))) { |
| 1687 | return 0; |
| 1688 | } |
| 1689 | DRM_UDELAY(1); |
| 1690 | } |
| 1691 | return -1; |
| 1692 | } |
| 1693 | |
| 1694 | int r100_mc_wait_for_idle(struct radeon_device *rdev) |
| 1695 | { |
| 1696 | unsigned i; |
| 1697 | uint32_t tmp; |
| 1698 | |
| 1699 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 1700 | /* read MC_STATUS */ |
| 1701 | tmp = RREG32(0x0150); |
| 1702 | if (tmp & (1 << 2)) { |
| 1703 | return 0; |
| 1704 | } |
| 1705 | DRM_UDELAY(1); |
| 1706 | } |
| 1707 | return -1; |
| 1708 | } |
| 1709 | |
| 1710 | void r100_gpu_init(struct radeon_device *rdev) |
| 1711 | { |
| 1712 | /* TODO: anythings to do here ? pipes ? */ |
| 1713 | r100_hdp_reset(rdev); |
| 1714 | } |
| 1715 | |
Dave Airlie | 23956df | 2009-11-23 12:01:09 +1000 | [diff] [blame] | 1716 | void r100_hdp_flush(struct radeon_device *rdev) |
| 1717 | { |
| 1718 | u32 tmp; |
| 1719 | tmp = RREG32(RADEON_HOST_PATH_CNTL); |
| 1720 | tmp |= RADEON_HDP_READ_BUFFER_INVALIDATE; |
| 1721 | WREG32(RADEON_HOST_PATH_CNTL, tmp); |
| 1722 | } |
| 1723 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1724 | void r100_hdp_reset(struct radeon_device *rdev) |
| 1725 | { |
| 1726 | uint32_t tmp; |
| 1727 | |
| 1728 | tmp = RREG32(RADEON_HOST_PATH_CNTL) & RADEON_HDP_APER_CNTL; |
| 1729 | tmp |= (7 << 28); |
| 1730 | WREG32(RADEON_HOST_PATH_CNTL, tmp | RADEON_HDP_SOFT_RESET | RADEON_HDP_READ_BUFFER_INVALIDATE); |
| 1731 | (void)RREG32(RADEON_HOST_PATH_CNTL); |
| 1732 | udelay(200); |
| 1733 | WREG32(RADEON_RBBM_SOFT_RESET, 0); |
| 1734 | WREG32(RADEON_HOST_PATH_CNTL, tmp); |
| 1735 | (void)RREG32(RADEON_HOST_PATH_CNTL); |
| 1736 | } |
| 1737 | |
| 1738 | int r100_rb2d_reset(struct radeon_device *rdev) |
| 1739 | { |
| 1740 | uint32_t tmp; |
| 1741 | int i; |
| 1742 | |
| 1743 | WREG32(RADEON_RBBM_SOFT_RESET, RADEON_SOFT_RESET_E2); |
| 1744 | (void)RREG32(RADEON_RBBM_SOFT_RESET); |
| 1745 | udelay(200); |
| 1746 | WREG32(RADEON_RBBM_SOFT_RESET, 0); |
| 1747 | /* Wait to prevent race in RBBM_STATUS */ |
| 1748 | mdelay(1); |
| 1749 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 1750 | tmp = RREG32(RADEON_RBBM_STATUS); |
| 1751 | if (!(tmp & (1 << 26))) { |
| 1752 | DRM_INFO("RB2D reset succeed (RBBM_STATUS=0x%08X)\n", |
| 1753 | tmp); |
| 1754 | return 0; |
| 1755 | } |
| 1756 | DRM_UDELAY(1); |
| 1757 | } |
| 1758 | tmp = RREG32(RADEON_RBBM_STATUS); |
| 1759 | DRM_ERROR("Failed to reset RB2D (RBBM_STATUS=0x%08X)!\n", tmp); |
| 1760 | return -1; |
| 1761 | } |
| 1762 | |
| 1763 | int r100_gpu_reset(struct radeon_device *rdev) |
| 1764 | { |
| 1765 | uint32_t status; |
| 1766 | |
| 1767 | /* reset order likely matter */ |
| 1768 | status = RREG32(RADEON_RBBM_STATUS); |
| 1769 | /* reset HDP */ |
| 1770 | r100_hdp_reset(rdev); |
| 1771 | /* reset rb2d */ |
| 1772 | if (status & ((1 << 17) | (1 << 18) | (1 << 27))) { |
| 1773 | r100_rb2d_reset(rdev); |
| 1774 | } |
| 1775 | /* TODO: reset 3D engine */ |
| 1776 | /* reset CP */ |
| 1777 | status = RREG32(RADEON_RBBM_STATUS); |
| 1778 | if (status & (1 << 16)) { |
| 1779 | r100_cp_reset(rdev); |
| 1780 | } |
| 1781 | /* Check if GPU is idle */ |
| 1782 | status = RREG32(RADEON_RBBM_STATUS); |
| 1783 | if (status & (1 << 31)) { |
| 1784 | DRM_ERROR("Failed to reset GPU (RBBM_STATUS=0x%08X)\n", status); |
| 1785 | return -1; |
| 1786 | } |
| 1787 | DRM_INFO("GPU reset succeed (RBBM_STATUS=0x%08X)\n", status); |
| 1788 | return 0; |
| 1789 | } |
| 1790 | |
Alex Deucher | 92cde00 | 2009-12-04 10:55:12 -0500 | [diff] [blame] | 1791 | void r100_set_common_regs(struct radeon_device *rdev) |
| 1792 | { |
| 1793 | /* set these so they don't interfere with anything */ |
| 1794 | WREG32(RADEON_OV0_SCALE_CNTL, 0); |
| 1795 | WREG32(RADEON_SUBPIC_CNTL, 0); |
| 1796 | WREG32(RADEON_VIPH_CONTROL, 0); |
| 1797 | WREG32(RADEON_I2C_CNTL_1, 0); |
| 1798 | WREG32(RADEON_DVI_I2C_CNTL_1, 0); |
| 1799 | WREG32(RADEON_CAP0_TRIG_CNTL, 0); |
| 1800 | WREG32(RADEON_CAP1_TRIG_CNTL, 0); |
| 1801 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1802 | |
| 1803 | /* |
| 1804 | * VRAM info |
| 1805 | */ |
| 1806 | static void r100_vram_get_type(struct radeon_device *rdev) |
| 1807 | { |
| 1808 | uint32_t tmp; |
| 1809 | |
| 1810 | rdev->mc.vram_is_ddr = false; |
| 1811 | if (rdev->flags & RADEON_IS_IGP) |
| 1812 | rdev->mc.vram_is_ddr = true; |
| 1813 | else if (RREG32(RADEON_MEM_SDRAM_MODE_REG) & RADEON_MEM_CFG_TYPE_DDR) |
| 1814 | rdev->mc.vram_is_ddr = true; |
| 1815 | if ((rdev->family == CHIP_RV100) || |
| 1816 | (rdev->family == CHIP_RS100) || |
| 1817 | (rdev->family == CHIP_RS200)) { |
| 1818 | tmp = RREG32(RADEON_MEM_CNTL); |
| 1819 | if (tmp & RV100_HALF_MODE) { |
| 1820 | rdev->mc.vram_width = 32; |
| 1821 | } else { |
| 1822 | rdev->mc.vram_width = 64; |
| 1823 | } |
| 1824 | if (rdev->flags & RADEON_SINGLE_CRTC) { |
| 1825 | rdev->mc.vram_width /= 4; |
| 1826 | rdev->mc.vram_is_ddr = true; |
| 1827 | } |
| 1828 | } else if (rdev->family <= CHIP_RV280) { |
| 1829 | tmp = RREG32(RADEON_MEM_CNTL); |
| 1830 | if (tmp & RADEON_MEM_NUM_CHANNELS_MASK) { |
| 1831 | rdev->mc.vram_width = 128; |
| 1832 | } else { |
| 1833 | rdev->mc.vram_width = 64; |
| 1834 | } |
| 1835 | } else { |
| 1836 | /* newer IGPs */ |
| 1837 | rdev->mc.vram_width = 128; |
| 1838 | } |
| 1839 | } |
| 1840 | |
Dave Airlie | 2a0f891 | 2009-07-11 04:44:47 +1000 | [diff] [blame] | 1841 | static u32 r100_get_accessible_vram(struct radeon_device *rdev) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1842 | { |
Dave Airlie | 2a0f891 | 2009-07-11 04:44:47 +1000 | [diff] [blame] | 1843 | u32 aper_size; |
| 1844 | u8 byte; |
| 1845 | |
| 1846 | aper_size = RREG32(RADEON_CONFIG_APER_SIZE); |
| 1847 | |
| 1848 | /* Set HDP_APER_CNTL only on cards that are known not to be broken, |
| 1849 | * that is has the 2nd generation multifunction PCI interface |
| 1850 | */ |
| 1851 | if (rdev->family == CHIP_RV280 || |
| 1852 | rdev->family >= CHIP_RV350) { |
| 1853 | WREG32_P(RADEON_HOST_PATH_CNTL, RADEON_HDP_APER_CNTL, |
| 1854 | ~RADEON_HDP_APER_CNTL); |
| 1855 | DRM_INFO("Generation 2 PCI interface, using max accessible memory\n"); |
| 1856 | return aper_size * 2; |
| 1857 | } |
| 1858 | |
| 1859 | /* Older cards have all sorts of funny issues to deal with. First |
| 1860 | * check if it's a multifunction card by reading the PCI config |
| 1861 | * header type... Limit those to one aperture size |
| 1862 | */ |
| 1863 | pci_read_config_byte(rdev->pdev, 0xe, &byte); |
| 1864 | if (byte & 0x80) { |
| 1865 | DRM_INFO("Generation 1 PCI interface in multifunction mode\n"); |
| 1866 | DRM_INFO("Limiting VRAM to one aperture\n"); |
| 1867 | return aper_size; |
| 1868 | } |
| 1869 | |
| 1870 | /* Single function older card. We read HDP_APER_CNTL to see how the BIOS |
| 1871 | * have set it up. We don't write this as it's broken on some ASICs but |
| 1872 | * we expect the BIOS to have done the right thing (might be too optimistic...) |
| 1873 | */ |
| 1874 | if (RREG32(RADEON_HOST_PATH_CNTL) & RADEON_HDP_APER_CNTL) |
| 1875 | return aper_size * 2; |
| 1876 | return aper_size; |
| 1877 | } |
| 1878 | |
| 1879 | void r100_vram_init_sizes(struct radeon_device *rdev) |
| 1880 | { |
| 1881 | u64 config_aper_size; |
| 1882 | u32 accessible; |
| 1883 | |
| 1884 | config_aper_size = RREG32(RADEON_CONFIG_APER_SIZE); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1885 | |
| 1886 | if (rdev->flags & RADEON_IS_IGP) { |
| 1887 | uint32_t tom; |
| 1888 | /* read NB_TOM to get the amount of ram stolen for the GPU */ |
| 1889 | tom = RREG32(RADEON_NB_TOM); |
Dave Airlie | 7a50f01 | 2009-07-21 20:39:30 +1000 | [diff] [blame] | 1890 | rdev->mc.real_vram_size = (((tom >> 16) - (tom & 0xffff) + 1) << 16); |
Dave Airlie | 3e43d82 | 2009-07-09 15:04:18 +1000 | [diff] [blame] | 1891 | /* for IGPs we need to keep VRAM where it was put by the BIOS */ |
| 1892 | rdev->mc.vram_location = (tom & 0xffff) << 16; |
Dave Airlie | 7a50f01 | 2009-07-21 20:39:30 +1000 | [diff] [blame] | 1893 | WREG32(RADEON_CONFIG_MEMSIZE, rdev->mc.real_vram_size); |
| 1894 | rdev->mc.mc_vram_size = rdev->mc.real_vram_size; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1895 | } else { |
Dave Airlie | 7a50f01 | 2009-07-21 20:39:30 +1000 | [diff] [blame] | 1896 | rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1897 | /* Some production boards of m6 will report 0 |
| 1898 | * if it's 8 MB |
| 1899 | */ |
Dave Airlie | 7a50f01 | 2009-07-21 20:39:30 +1000 | [diff] [blame] | 1900 | if (rdev->mc.real_vram_size == 0) { |
| 1901 | rdev->mc.real_vram_size = 8192 * 1024; |
| 1902 | WREG32(RADEON_CONFIG_MEMSIZE, rdev->mc.real_vram_size); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1903 | } |
Dave Airlie | 3e43d82 | 2009-07-09 15:04:18 +1000 | [diff] [blame] | 1904 | /* let driver place VRAM */ |
| 1905 | rdev->mc.vram_location = 0xFFFFFFFFUL; |
Dave Airlie | 2a0f891 | 2009-07-11 04:44:47 +1000 | [diff] [blame] | 1906 | /* Fix for RN50, M6, M7 with 8/16/32(??) MBs of VRAM - |
| 1907 | * Novell bug 204882 + along with lots of ubuntu ones */ |
Dave Airlie | 7a50f01 | 2009-07-21 20:39:30 +1000 | [diff] [blame] | 1908 | if (config_aper_size > rdev->mc.real_vram_size) |
| 1909 | rdev->mc.mc_vram_size = config_aper_size; |
| 1910 | else |
| 1911 | rdev->mc.mc_vram_size = rdev->mc.real_vram_size; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1912 | } |
| 1913 | |
Dave Airlie | 2a0f891 | 2009-07-11 04:44:47 +1000 | [diff] [blame] | 1914 | /* work out accessible VRAM */ |
| 1915 | accessible = r100_get_accessible_vram(rdev); |
| 1916 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1917 | rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0); |
| 1918 | rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0); |
Dave Airlie | 2a0f891 | 2009-07-11 04:44:47 +1000 | [diff] [blame] | 1919 | |
| 1920 | if (accessible > rdev->mc.aper_size) |
| 1921 | accessible = rdev->mc.aper_size; |
| 1922 | |
Dave Airlie | 7a50f01 | 2009-07-21 20:39:30 +1000 | [diff] [blame] | 1923 | if (rdev->mc.mc_vram_size > rdev->mc.aper_size) |
| 1924 | rdev->mc.mc_vram_size = rdev->mc.aper_size; |
| 1925 | |
| 1926 | if (rdev->mc.real_vram_size > rdev->mc.aper_size) |
| 1927 | rdev->mc.real_vram_size = rdev->mc.aper_size; |
Dave Airlie | 2a0f891 | 2009-07-11 04:44:47 +1000 | [diff] [blame] | 1928 | } |
| 1929 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 1930 | void r100_vga_set_state(struct radeon_device *rdev, bool state) |
| 1931 | { |
| 1932 | uint32_t temp; |
| 1933 | |
| 1934 | temp = RREG32(RADEON_CONFIG_CNTL); |
| 1935 | if (state == false) { |
| 1936 | temp &= ~(1<<8); |
| 1937 | temp |= (1<<9); |
| 1938 | } else { |
| 1939 | temp &= ~(1<<9); |
| 1940 | } |
| 1941 | WREG32(RADEON_CONFIG_CNTL, temp); |
| 1942 | } |
| 1943 | |
Dave Airlie | 2a0f891 | 2009-07-11 04:44:47 +1000 | [diff] [blame] | 1944 | void r100_vram_info(struct radeon_device *rdev) |
| 1945 | { |
| 1946 | r100_vram_get_type(rdev); |
| 1947 | |
| 1948 | r100_vram_init_sizes(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1949 | } |
| 1950 | |
| 1951 | |
| 1952 | /* |
| 1953 | * Indirect registers accessor |
| 1954 | */ |
| 1955 | void r100_pll_errata_after_index(struct radeon_device *rdev) |
| 1956 | { |
| 1957 | if (!(rdev->pll_errata & CHIP_ERRATA_PLL_DUMMYREADS)) { |
| 1958 | return; |
| 1959 | } |
| 1960 | (void)RREG32(RADEON_CLOCK_CNTL_DATA); |
| 1961 | (void)RREG32(RADEON_CRTC_GEN_CNTL); |
| 1962 | } |
| 1963 | |
| 1964 | static void r100_pll_errata_after_data(struct radeon_device *rdev) |
| 1965 | { |
| 1966 | /* This workarounds is necessary on RV100, RS100 and RS200 chips |
| 1967 | * or the chip could hang on a subsequent access |
| 1968 | */ |
| 1969 | if (rdev->pll_errata & CHIP_ERRATA_PLL_DELAY) { |
| 1970 | udelay(5000); |
| 1971 | } |
| 1972 | |
| 1973 | /* This function is required to workaround a hardware bug in some (all?) |
| 1974 | * revisions of the R300. This workaround should be called after every |
| 1975 | * CLOCK_CNTL_INDEX register access. If not, register reads afterward |
| 1976 | * may not be correct. |
| 1977 | */ |
| 1978 | if (rdev->pll_errata & CHIP_ERRATA_R300_CG) { |
| 1979 | uint32_t save, tmp; |
| 1980 | |
| 1981 | save = RREG32(RADEON_CLOCK_CNTL_INDEX); |
| 1982 | tmp = save & ~(0x3f | RADEON_PLL_WR_EN); |
| 1983 | WREG32(RADEON_CLOCK_CNTL_INDEX, tmp); |
| 1984 | tmp = RREG32(RADEON_CLOCK_CNTL_DATA); |
| 1985 | WREG32(RADEON_CLOCK_CNTL_INDEX, save); |
| 1986 | } |
| 1987 | } |
| 1988 | |
| 1989 | uint32_t r100_pll_rreg(struct radeon_device *rdev, uint32_t reg) |
| 1990 | { |
| 1991 | uint32_t data; |
| 1992 | |
| 1993 | WREG8(RADEON_CLOCK_CNTL_INDEX, reg & 0x3f); |
| 1994 | r100_pll_errata_after_index(rdev); |
| 1995 | data = RREG32(RADEON_CLOCK_CNTL_DATA); |
| 1996 | r100_pll_errata_after_data(rdev); |
| 1997 | return data; |
| 1998 | } |
| 1999 | |
| 2000 | void r100_pll_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v) |
| 2001 | { |
| 2002 | WREG8(RADEON_CLOCK_CNTL_INDEX, ((reg & 0x3f) | RADEON_PLL_WR_EN)); |
| 2003 | r100_pll_errata_after_index(rdev); |
| 2004 | WREG32(RADEON_CLOCK_CNTL_DATA, v); |
| 2005 | r100_pll_errata_after_data(rdev); |
| 2006 | } |
| 2007 | |
Jerome Glisse | d455090 | 2009-10-01 10:12:06 +0200 | [diff] [blame] | 2008 | void r100_set_safe_registers(struct radeon_device *rdev) |
Jerome Glisse | 068a117 | 2009-06-17 13:28:30 +0200 | [diff] [blame] | 2009 | { |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2010 | if (ASIC_IS_RN50(rdev)) { |
| 2011 | rdev->config.r100.reg_safe_bm = rn50_reg_safe_bm; |
| 2012 | rdev->config.r100.reg_safe_bm_size = ARRAY_SIZE(rn50_reg_safe_bm); |
| 2013 | } else if (rdev->family < CHIP_R200) { |
| 2014 | rdev->config.r100.reg_safe_bm = r100_reg_safe_bm; |
| 2015 | rdev->config.r100.reg_safe_bm_size = ARRAY_SIZE(r100_reg_safe_bm); |
| 2016 | } else { |
Jerome Glisse | d455090 | 2009-10-01 10:12:06 +0200 | [diff] [blame] | 2017 | r200_set_safe_registers(rdev); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2018 | } |
Jerome Glisse | 068a117 | 2009-06-17 13:28:30 +0200 | [diff] [blame] | 2019 | } |
| 2020 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 2021 | /* |
| 2022 | * Debugfs info |
| 2023 | */ |
| 2024 | #if defined(CONFIG_DEBUG_FS) |
| 2025 | static int r100_debugfs_rbbm_info(struct seq_file *m, void *data) |
| 2026 | { |
| 2027 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 2028 | struct drm_device *dev = node->minor->dev; |
| 2029 | struct radeon_device *rdev = dev->dev_private; |
| 2030 | uint32_t reg, value; |
| 2031 | unsigned i; |
| 2032 | |
| 2033 | seq_printf(m, "RBBM_STATUS 0x%08x\n", RREG32(RADEON_RBBM_STATUS)); |
| 2034 | seq_printf(m, "RBBM_CMDFIFO_STAT 0x%08x\n", RREG32(0xE7C)); |
| 2035 | seq_printf(m, "CP_STAT 0x%08x\n", RREG32(RADEON_CP_STAT)); |
| 2036 | for (i = 0; i < 64; i++) { |
| 2037 | WREG32(RADEON_RBBM_CMDFIFO_ADDR, i | 0x100); |
| 2038 | reg = (RREG32(RADEON_RBBM_CMDFIFO_DATA) - 1) >> 2; |
| 2039 | WREG32(RADEON_RBBM_CMDFIFO_ADDR, i); |
| 2040 | value = RREG32(RADEON_RBBM_CMDFIFO_DATA); |
| 2041 | seq_printf(m, "[0x%03X] 0x%04X=0x%08X\n", i, reg, value); |
| 2042 | } |
| 2043 | return 0; |
| 2044 | } |
| 2045 | |
| 2046 | static int r100_debugfs_cp_ring_info(struct seq_file *m, void *data) |
| 2047 | { |
| 2048 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 2049 | struct drm_device *dev = node->minor->dev; |
| 2050 | struct radeon_device *rdev = dev->dev_private; |
| 2051 | uint32_t rdp, wdp; |
| 2052 | unsigned count, i, j; |
| 2053 | |
| 2054 | radeon_ring_free_size(rdev); |
| 2055 | rdp = RREG32(RADEON_CP_RB_RPTR); |
| 2056 | wdp = RREG32(RADEON_CP_RB_WPTR); |
| 2057 | count = (rdp + rdev->cp.ring_size - wdp) & rdev->cp.ptr_mask; |
| 2058 | seq_printf(m, "CP_STAT 0x%08x\n", RREG32(RADEON_CP_STAT)); |
| 2059 | seq_printf(m, "CP_RB_WPTR 0x%08x\n", wdp); |
| 2060 | seq_printf(m, "CP_RB_RPTR 0x%08x\n", rdp); |
| 2061 | seq_printf(m, "%u free dwords in ring\n", rdev->cp.ring_free_dw); |
| 2062 | seq_printf(m, "%u dwords in ring\n", count); |
| 2063 | for (j = 0; j <= count; j++) { |
| 2064 | i = (rdp + j) & rdev->cp.ptr_mask; |
| 2065 | seq_printf(m, "r[%04d]=0x%08x\n", i, rdev->cp.ring[i]); |
| 2066 | } |
| 2067 | return 0; |
| 2068 | } |
| 2069 | |
| 2070 | |
| 2071 | static int r100_debugfs_cp_csq_fifo(struct seq_file *m, void *data) |
| 2072 | { |
| 2073 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 2074 | struct drm_device *dev = node->minor->dev; |
| 2075 | struct radeon_device *rdev = dev->dev_private; |
| 2076 | uint32_t csq_stat, csq2_stat, tmp; |
| 2077 | unsigned r_rptr, r_wptr, ib1_rptr, ib1_wptr, ib2_rptr, ib2_wptr; |
| 2078 | unsigned i; |
| 2079 | |
| 2080 | seq_printf(m, "CP_STAT 0x%08x\n", RREG32(RADEON_CP_STAT)); |
| 2081 | seq_printf(m, "CP_CSQ_MODE 0x%08x\n", RREG32(RADEON_CP_CSQ_MODE)); |
| 2082 | csq_stat = RREG32(RADEON_CP_CSQ_STAT); |
| 2083 | csq2_stat = RREG32(RADEON_CP_CSQ2_STAT); |
| 2084 | r_rptr = (csq_stat >> 0) & 0x3ff; |
| 2085 | r_wptr = (csq_stat >> 10) & 0x3ff; |
| 2086 | ib1_rptr = (csq_stat >> 20) & 0x3ff; |
| 2087 | ib1_wptr = (csq2_stat >> 0) & 0x3ff; |
| 2088 | ib2_rptr = (csq2_stat >> 10) & 0x3ff; |
| 2089 | ib2_wptr = (csq2_stat >> 20) & 0x3ff; |
| 2090 | seq_printf(m, "CP_CSQ_STAT 0x%08x\n", csq_stat); |
| 2091 | seq_printf(m, "CP_CSQ2_STAT 0x%08x\n", csq2_stat); |
| 2092 | seq_printf(m, "Ring rptr %u\n", r_rptr); |
| 2093 | seq_printf(m, "Ring wptr %u\n", r_wptr); |
| 2094 | seq_printf(m, "Indirect1 rptr %u\n", ib1_rptr); |
| 2095 | seq_printf(m, "Indirect1 wptr %u\n", ib1_wptr); |
| 2096 | seq_printf(m, "Indirect2 rptr %u\n", ib2_rptr); |
| 2097 | seq_printf(m, "Indirect2 wptr %u\n", ib2_wptr); |
| 2098 | /* FIXME: 0, 128, 640 depends on fifo setup see cp_init_kms |
| 2099 | * 128 = indirect1_start * 8 & 640 = indirect2_start * 8 */ |
| 2100 | seq_printf(m, "Ring fifo:\n"); |
| 2101 | for (i = 0; i < 256; i++) { |
| 2102 | WREG32(RADEON_CP_CSQ_ADDR, i << 2); |
| 2103 | tmp = RREG32(RADEON_CP_CSQ_DATA); |
| 2104 | seq_printf(m, "rfifo[%04d]=0x%08X\n", i, tmp); |
| 2105 | } |
| 2106 | seq_printf(m, "Indirect1 fifo:\n"); |
| 2107 | for (i = 256; i <= 512; i++) { |
| 2108 | WREG32(RADEON_CP_CSQ_ADDR, i << 2); |
| 2109 | tmp = RREG32(RADEON_CP_CSQ_DATA); |
| 2110 | seq_printf(m, "ib1fifo[%04d]=0x%08X\n", i, tmp); |
| 2111 | } |
| 2112 | seq_printf(m, "Indirect2 fifo:\n"); |
| 2113 | for (i = 640; i < ib1_wptr; i++) { |
| 2114 | WREG32(RADEON_CP_CSQ_ADDR, i << 2); |
| 2115 | tmp = RREG32(RADEON_CP_CSQ_DATA); |
| 2116 | seq_printf(m, "ib2fifo[%04d]=0x%08X\n", i, tmp); |
| 2117 | } |
| 2118 | return 0; |
| 2119 | } |
| 2120 | |
| 2121 | static int r100_debugfs_mc_info(struct seq_file *m, void *data) |
| 2122 | { |
| 2123 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 2124 | struct drm_device *dev = node->minor->dev; |
| 2125 | struct radeon_device *rdev = dev->dev_private; |
| 2126 | uint32_t tmp; |
| 2127 | |
| 2128 | tmp = RREG32(RADEON_CONFIG_MEMSIZE); |
| 2129 | seq_printf(m, "CONFIG_MEMSIZE 0x%08x\n", tmp); |
| 2130 | tmp = RREG32(RADEON_MC_FB_LOCATION); |
| 2131 | seq_printf(m, "MC_FB_LOCATION 0x%08x\n", tmp); |
| 2132 | tmp = RREG32(RADEON_BUS_CNTL); |
| 2133 | seq_printf(m, "BUS_CNTL 0x%08x\n", tmp); |
| 2134 | tmp = RREG32(RADEON_MC_AGP_LOCATION); |
| 2135 | seq_printf(m, "MC_AGP_LOCATION 0x%08x\n", tmp); |
| 2136 | tmp = RREG32(RADEON_AGP_BASE); |
| 2137 | seq_printf(m, "AGP_BASE 0x%08x\n", tmp); |
| 2138 | tmp = RREG32(RADEON_HOST_PATH_CNTL); |
| 2139 | seq_printf(m, "HOST_PATH_CNTL 0x%08x\n", tmp); |
| 2140 | tmp = RREG32(0x01D0); |
| 2141 | seq_printf(m, "AIC_CTRL 0x%08x\n", tmp); |
| 2142 | tmp = RREG32(RADEON_AIC_LO_ADDR); |
| 2143 | seq_printf(m, "AIC_LO_ADDR 0x%08x\n", tmp); |
| 2144 | tmp = RREG32(RADEON_AIC_HI_ADDR); |
| 2145 | seq_printf(m, "AIC_HI_ADDR 0x%08x\n", tmp); |
| 2146 | tmp = RREG32(0x01E4); |
| 2147 | seq_printf(m, "AIC_TLB_ADDR 0x%08x\n", tmp); |
| 2148 | return 0; |
| 2149 | } |
| 2150 | |
| 2151 | static struct drm_info_list r100_debugfs_rbbm_list[] = { |
| 2152 | {"r100_rbbm_info", r100_debugfs_rbbm_info, 0, NULL}, |
| 2153 | }; |
| 2154 | |
| 2155 | static struct drm_info_list r100_debugfs_cp_list[] = { |
| 2156 | {"r100_cp_ring_info", r100_debugfs_cp_ring_info, 0, NULL}, |
| 2157 | {"r100_cp_csq_fifo", r100_debugfs_cp_csq_fifo, 0, NULL}, |
| 2158 | }; |
| 2159 | |
| 2160 | static struct drm_info_list r100_debugfs_mc_info_list[] = { |
| 2161 | {"r100_mc_info", r100_debugfs_mc_info, 0, NULL}, |
| 2162 | }; |
| 2163 | #endif |
| 2164 | |
| 2165 | int r100_debugfs_rbbm_init(struct radeon_device *rdev) |
| 2166 | { |
| 2167 | #if defined(CONFIG_DEBUG_FS) |
| 2168 | return radeon_debugfs_add_files(rdev, r100_debugfs_rbbm_list, 1); |
| 2169 | #else |
| 2170 | return 0; |
| 2171 | #endif |
| 2172 | } |
| 2173 | |
| 2174 | int r100_debugfs_cp_init(struct radeon_device *rdev) |
| 2175 | { |
| 2176 | #if defined(CONFIG_DEBUG_FS) |
| 2177 | return radeon_debugfs_add_files(rdev, r100_debugfs_cp_list, 2); |
| 2178 | #else |
| 2179 | return 0; |
| 2180 | #endif |
| 2181 | } |
| 2182 | |
| 2183 | int r100_debugfs_mc_info_init(struct radeon_device *rdev) |
| 2184 | { |
| 2185 | #if defined(CONFIG_DEBUG_FS) |
| 2186 | return radeon_debugfs_add_files(rdev, r100_debugfs_mc_info_list, 1); |
| 2187 | #else |
| 2188 | return 0; |
| 2189 | #endif |
| 2190 | } |
Dave Airlie | e024e11 | 2009-06-24 09:48:08 +1000 | [diff] [blame] | 2191 | |
| 2192 | int r100_set_surface_reg(struct radeon_device *rdev, int reg, |
| 2193 | uint32_t tiling_flags, uint32_t pitch, |
| 2194 | uint32_t offset, uint32_t obj_size) |
| 2195 | { |
| 2196 | int surf_index = reg * 16; |
| 2197 | int flags = 0; |
| 2198 | |
| 2199 | /* r100/r200 divide by 16 */ |
| 2200 | if (rdev->family < CHIP_R300) |
| 2201 | flags = pitch / 16; |
| 2202 | else |
| 2203 | flags = pitch / 8; |
| 2204 | |
| 2205 | if (rdev->family <= CHIP_RS200) { |
| 2206 | if ((tiling_flags & (RADEON_TILING_MACRO|RADEON_TILING_MICRO)) |
| 2207 | == (RADEON_TILING_MACRO|RADEON_TILING_MICRO)) |
| 2208 | flags |= RADEON_SURF_TILE_COLOR_BOTH; |
| 2209 | if (tiling_flags & RADEON_TILING_MACRO) |
| 2210 | flags |= RADEON_SURF_TILE_COLOR_MACRO; |
| 2211 | } else if (rdev->family <= CHIP_RV280) { |
| 2212 | if (tiling_flags & (RADEON_TILING_MACRO)) |
| 2213 | flags |= R200_SURF_TILE_COLOR_MACRO; |
| 2214 | if (tiling_flags & RADEON_TILING_MICRO) |
| 2215 | flags |= R200_SURF_TILE_COLOR_MICRO; |
| 2216 | } else { |
| 2217 | if (tiling_flags & RADEON_TILING_MACRO) |
| 2218 | flags |= R300_SURF_TILE_MACRO; |
| 2219 | if (tiling_flags & RADEON_TILING_MICRO) |
| 2220 | flags |= R300_SURF_TILE_MICRO; |
| 2221 | } |
| 2222 | |
Michel Dänzer | c88f9f0 | 2009-09-15 17:09:30 +0200 | [diff] [blame] | 2223 | if (tiling_flags & RADEON_TILING_SWAP_16BIT) |
| 2224 | flags |= RADEON_SURF_AP0_SWP_16BPP | RADEON_SURF_AP1_SWP_16BPP; |
| 2225 | if (tiling_flags & RADEON_TILING_SWAP_32BIT) |
| 2226 | flags |= RADEON_SURF_AP0_SWP_32BPP | RADEON_SURF_AP1_SWP_32BPP; |
| 2227 | |
Dave Airlie | e024e11 | 2009-06-24 09:48:08 +1000 | [diff] [blame] | 2228 | DRM_DEBUG("writing surface %d %d %x %x\n", reg, flags, offset, offset+obj_size-1); |
| 2229 | WREG32(RADEON_SURFACE0_INFO + surf_index, flags); |
| 2230 | WREG32(RADEON_SURFACE0_LOWER_BOUND + surf_index, offset); |
| 2231 | WREG32(RADEON_SURFACE0_UPPER_BOUND + surf_index, offset + obj_size - 1); |
| 2232 | return 0; |
| 2233 | } |
| 2234 | |
| 2235 | void r100_clear_surface_reg(struct radeon_device *rdev, int reg) |
| 2236 | { |
| 2237 | int surf_index = reg * 16; |
| 2238 | WREG32(RADEON_SURFACE0_INFO + surf_index, 0); |
| 2239 | } |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 2240 | |
| 2241 | void r100_bandwidth_update(struct radeon_device *rdev) |
| 2242 | { |
| 2243 | fixed20_12 trcd_ff, trp_ff, tras_ff, trbs_ff, tcas_ff; |
| 2244 | fixed20_12 sclk_ff, mclk_ff, sclk_eff_ff, sclk_delay_ff; |
| 2245 | fixed20_12 peak_disp_bw, mem_bw, pix_clk, pix_clk2, temp_ff, crit_point_ff; |
| 2246 | uint32_t temp, data, mem_trcd, mem_trp, mem_tras; |
| 2247 | fixed20_12 memtcas_ff[8] = { |
| 2248 | fixed_init(1), |
| 2249 | fixed_init(2), |
| 2250 | fixed_init(3), |
| 2251 | fixed_init(0), |
| 2252 | fixed_init_half(1), |
| 2253 | fixed_init_half(2), |
| 2254 | fixed_init(0), |
| 2255 | }; |
| 2256 | fixed20_12 memtcas_rs480_ff[8] = { |
| 2257 | fixed_init(0), |
| 2258 | fixed_init(1), |
| 2259 | fixed_init(2), |
| 2260 | fixed_init(3), |
| 2261 | fixed_init(0), |
| 2262 | fixed_init_half(1), |
| 2263 | fixed_init_half(2), |
| 2264 | fixed_init_half(3), |
| 2265 | }; |
| 2266 | fixed20_12 memtcas2_ff[8] = { |
| 2267 | fixed_init(0), |
| 2268 | fixed_init(1), |
| 2269 | fixed_init(2), |
| 2270 | fixed_init(3), |
| 2271 | fixed_init(4), |
| 2272 | fixed_init(5), |
| 2273 | fixed_init(6), |
| 2274 | fixed_init(7), |
| 2275 | }; |
| 2276 | fixed20_12 memtrbs[8] = { |
| 2277 | fixed_init(1), |
| 2278 | fixed_init_half(1), |
| 2279 | fixed_init(2), |
| 2280 | fixed_init_half(2), |
| 2281 | fixed_init(3), |
| 2282 | fixed_init_half(3), |
| 2283 | fixed_init(4), |
| 2284 | fixed_init_half(4) |
| 2285 | }; |
| 2286 | fixed20_12 memtrbs_r4xx[8] = { |
| 2287 | fixed_init(4), |
| 2288 | fixed_init(5), |
| 2289 | fixed_init(6), |
| 2290 | fixed_init(7), |
| 2291 | fixed_init(8), |
| 2292 | fixed_init(9), |
| 2293 | fixed_init(10), |
| 2294 | fixed_init(11) |
| 2295 | }; |
| 2296 | fixed20_12 min_mem_eff; |
| 2297 | fixed20_12 mc_latency_sclk, mc_latency_mclk, k1; |
| 2298 | fixed20_12 cur_latency_mclk, cur_latency_sclk; |
| 2299 | fixed20_12 disp_latency, disp_latency_overhead, disp_drain_rate, |
| 2300 | disp_drain_rate2, read_return_rate; |
| 2301 | fixed20_12 time_disp1_drop_priority; |
| 2302 | int c; |
| 2303 | int cur_size = 16; /* in octawords */ |
| 2304 | int critical_point = 0, critical_point2; |
| 2305 | /* uint32_t read_return_rate, time_disp1_drop_priority; */ |
| 2306 | int stop_req, max_stop_req; |
| 2307 | struct drm_display_mode *mode1 = NULL; |
| 2308 | struct drm_display_mode *mode2 = NULL; |
| 2309 | uint32_t pixel_bytes1 = 0; |
| 2310 | uint32_t pixel_bytes2 = 0; |
| 2311 | |
| 2312 | if (rdev->mode_info.crtcs[0]->base.enabled) { |
| 2313 | mode1 = &rdev->mode_info.crtcs[0]->base.mode; |
| 2314 | pixel_bytes1 = rdev->mode_info.crtcs[0]->base.fb->bits_per_pixel / 8; |
| 2315 | } |
Dave Airlie | dfee561 | 2009-10-02 09:19:09 +1000 | [diff] [blame] | 2316 | if (!(rdev->flags & RADEON_SINGLE_CRTC)) { |
| 2317 | if (rdev->mode_info.crtcs[1]->base.enabled) { |
| 2318 | mode2 = &rdev->mode_info.crtcs[1]->base.mode; |
| 2319 | pixel_bytes2 = rdev->mode_info.crtcs[1]->base.fb->bits_per_pixel / 8; |
| 2320 | } |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 2321 | } |
| 2322 | |
| 2323 | min_mem_eff.full = rfixed_const_8(0); |
| 2324 | /* get modes */ |
| 2325 | if ((rdev->disp_priority == 2) && ASIC_IS_R300(rdev)) { |
| 2326 | uint32_t mc_init_misc_lat_timer = RREG32(R300_MC_INIT_MISC_LAT_TIMER); |
| 2327 | mc_init_misc_lat_timer &= ~(R300_MC_DISP1R_INIT_LAT_MASK << R300_MC_DISP1R_INIT_LAT_SHIFT); |
| 2328 | mc_init_misc_lat_timer &= ~(R300_MC_DISP0R_INIT_LAT_MASK << R300_MC_DISP0R_INIT_LAT_SHIFT); |
| 2329 | /* check crtc enables */ |
| 2330 | if (mode2) |
| 2331 | mc_init_misc_lat_timer |= (1 << R300_MC_DISP1R_INIT_LAT_SHIFT); |
| 2332 | if (mode1) |
| 2333 | mc_init_misc_lat_timer |= (1 << R300_MC_DISP0R_INIT_LAT_SHIFT); |
| 2334 | WREG32(R300_MC_INIT_MISC_LAT_TIMER, mc_init_misc_lat_timer); |
| 2335 | } |
| 2336 | |
| 2337 | /* |
| 2338 | * determine is there is enough bw for current mode |
| 2339 | */ |
| 2340 | mclk_ff.full = rfixed_const(rdev->clock.default_mclk); |
| 2341 | temp_ff.full = rfixed_const(100); |
| 2342 | mclk_ff.full = rfixed_div(mclk_ff, temp_ff); |
| 2343 | sclk_ff.full = rfixed_const(rdev->clock.default_sclk); |
| 2344 | sclk_ff.full = rfixed_div(sclk_ff, temp_ff); |
| 2345 | |
| 2346 | temp = (rdev->mc.vram_width / 8) * (rdev->mc.vram_is_ddr ? 2 : 1); |
| 2347 | temp_ff.full = rfixed_const(temp); |
| 2348 | mem_bw.full = rfixed_mul(mclk_ff, temp_ff); |
| 2349 | |
| 2350 | pix_clk.full = 0; |
| 2351 | pix_clk2.full = 0; |
| 2352 | peak_disp_bw.full = 0; |
| 2353 | if (mode1) { |
| 2354 | temp_ff.full = rfixed_const(1000); |
| 2355 | pix_clk.full = rfixed_const(mode1->clock); /* convert to fixed point */ |
| 2356 | pix_clk.full = rfixed_div(pix_clk, temp_ff); |
| 2357 | temp_ff.full = rfixed_const(pixel_bytes1); |
| 2358 | peak_disp_bw.full += rfixed_mul(pix_clk, temp_ff); |
| 2359 | } |
| 2360 | if (mode2) { |
| 2361 | temp_ff.full = rfixed_const(1000); |
| 2362 | pix_clk2.full = rfixed_const(mode2->clock); /* convert to fixed point */ |
| 2363 | pix_clk2.full = rfixed_div(pix_clk2, temp_ff); |
| 2364 | temp_ff.full = rfixed_const(pixel_bytes2); |
| 2365 | peak_disp_bw.full += rfixed_mul(pix_clk2, temp_ff); |
| 2366 | } |
| 2367 | |
| 2368 | mem_bw.full = rfixed_mul(mem_bw, min_mem_eff); |
| 2369 | if (peak_disp_bw.full >= mem_bw.full) { |
| 2370 | DRM_ERROR("You may not have enough display bandwidth for current mode\n" |
| 2371 | "If you have flickering problem, try to lower resolution, refresh rate, or color depth\n"); |
| 2372 | } |
| 2373 | |
| 2374 | /* Get values from the EXT_MEM_CNTL register...converting its contents. */ |
| 2375 | temp = RREG32(RADEON_MEM_TIMING_CNTL); |
| 2376 | if ((rdev->family == CHIP_RV100) || (rdev->flags & RADEON_IS_IGP)) { /* RV100, M6, IGPs */ |
| 2377 | mem_trcd = ((temp >> 2) & 0x3) + 1; |
| 2378 | mem_trp = ((temp & 0x3)) + 1; |
| 2379 | mem_tras = ((temp & 0x70) >> 4) + 1; |
| 2380 | } else if (rdev->family == CHIP_R300 || |
| 2381 | rdev->family == CHIP_R350) { /* r300, r350 */ |
| 2382 | mem_trcd = (temp & 0x7) + 1; |
| 2383 | mem_trp = ((temp >> 8) & 0x7) + 1; |
| 2384 | mem_tras = ((temp >> 11) & 0xf) + 4; |
| 2385 | } else if (rdev->family == CHIP_RV350 || |
| 2386 | rdev->family <= CHIP_RV380) { |
| 2387 | /* rv3x0 */ |
| 2388 | mem_trcd = (temp & 0x7) + 3; |
| 2389 | mem_trp = ((temp >> 8) & 0x7) + 3; |
| 2390 | mem_tras = ((temp >> 11) & 0xf) + 6; |
| 2391 | } else if (rdev->family == CHIP_R420 || |
| 2392 | rdev->family == CHIP_R423 || |
| 2393 | rdev->family == CHIP_RV410) { |
| 2394 | /* r4xx */ |
| 2395 | mem_trcd = (temp & 0xf) + 3; |
| 2396 | if (mem_trcd > 15) |
| 2397 | mem_trcd = 15; |
| 2398 | mem_trp = ((temp >> 8) & 0xf) + 3; |
| 2399 | if (mem_trp > 15) |
| 2400 | mem_trp = 15; |
| 2401 | mem_tras = ((temp >> 12) & 0x1f) + 6; |
| 2402 | if (mem_tras > 31) |
| 2403 | mem_tras = 31; |
| 2404 | } else { /* RV200, R200 */ |
| 2405 | mem_trcd = (temp & 0x7) + 1; |
| 2406 | mem_trp = ((temp >> 8) & 0x7) + 1; |
| 2407 | mem_tras = ((temp >> 12) & 0xf) + 4; |
| 2408 | } |
| 2409 | /* convert to FF */ |
| 2410 | trcd_ff.full = rfixed_const(mem_trcd); |
| 2411 | trp_ff.full = rfixed_const(mem_trp); |
| 2412 | tras_ff.full = rfixed_const(mem_tras); |
| 2413 | |
| 2414 | /* Get values from the MEM_SDRAM_MODE_REG register...converting its */ |
| 2415 | temp = RREG32(RADEON_MEM_SDRAM_MODE_REG); |
| 2416 | data = (temp & (7 << 20)) >> 20; |
| 2417 | if ((rdev->family == CHIP_RV100) || rdev->flags & RADEON_IS_IGP) { |
| 2418 | if (rdev->family == CHIP_RS480) /* don't think rs400 */ |
| 2419 | tcas_ff = memtcas_rs480_ff[data]; |
| 2420 | else |
| 2421 | tcas_ff = memtcas_ff[data]; |
| 2422 | } else |
| 2423 | tcas_ff = memtcas2_ff[data]; |
| 2424 | |
| 2425 | if (rdev->family == CHIP_RS400 || |
| 2426 | rdev->family == CHIP_RS480) { |
| 2427 | /* extra cas latency stored in bits 23-25 0-4 clocks */ |
| 2428 | data = (temp >> 23) & 0x7; |
| 2429 | if (data < 5) |
| 2430 | tcas_ff.full += rfixed_const(data); |
| 2431 | } |
| 2432 | |
| 2433 | if (ASIC_IS_R300(rdev) && !(rdev->flags & RADEON_IS_IGP)) { |
| 2434 | /* on the R300, Tcas is included in Trbs. |
| 2435 | */ |
| 2436 | temp = RREG32(RADEON_MEM_CNTL); |
| 2437 | data = (R300_MEM_NUM_CHANNELS_MASK & temp); |
| 2438 | if (data == 1) { |
| 2439 | if (R300_MEM_USE_CD_CH_ONLY & temp) { |
| 2440 | temp = RREG32(R300_MC_IND_INDEX); |
| 2441 | temp &= ~R300_MC_IND_ADDR_MASK; |
| 2442 | temp |= R300_MC_READ_CNTL_CD_mcind; |
| 2443 | WREG32(R300_MC_IND_INDEX, temp); |
| 2444 | temp = RREG32(R300_MC_IND_DATA); |
| 2445 | data = (R300_MEM_RBS_POSITION_C_MASK & temp); |
| 2446 | } else { |
| 2447 | temp = RREG32(R300_MC_READ_CNTL_AB); |
| 2448 | data = (R300_MEM_RBS_POSITION_A_MASK & temp); |
| 2449 | } |
| 2450 | } else { |
| 2451 | temp = RREG32(R300_MC_READ_CNTL_AB); |
| 2452 | data = (R300_MEM_RBS_POSITION_A_MASK & temp); |
| 2453 | } |
| 2454 | if (rdev->family == CHIP_RV410 || |
| 2455 | rdev->family == CHIP_R420 || |
| 2456 | rdev->family == CHIP_R423) |
| 2457 | trbs_ff = memtrbs_r4xx[data]; |
| 2458 | else |
| 2459 | trbs_ff = memtrbs[data]; |
| 2460 | tcas_ff.full += trbs_ff.full; |
| 2461 | } |
| 2462 | |
| 2463 | sclk_eff_ff.full = sclk_ff.full; |
| 2464 | |
| 2465 | if (rdev->flags & RADEON_IS_AGP) { |
| 2466 | fixed20_12 agpmode_ff; |
| 2467 | agpmode_ff.full = rfixed_const(radeon_agpmode); |
| 2468 | temp_ff.full = rfixed_const_666(16); |
| 2469 | sclk_eff_ff.full -= rfixed_mul(agpmode_ff, temp_ff); |
| 2470 | } |
| 2471 | /* TODO PCIE lanes may affect this - agpmode == 16?? */ |
| 2472 | |
| 2473 | if (ASIC_IS_R300(rdev)) { |
| 2474 | sclk_delay_ff.full = rfixed_const(250); |
| 2475 | } else { |
| 2476 | if ((rdev->family == CHIP_RV100) || |
| 2477 | rdev->flags & RADEON_IS_IGP) { |
| 2478 | if (rdev->mc.vram_is_ddr) |
| 2479 | sclk_delay_ff.full = rfixed_const(41); |
| 2480 | else |
| 2481 | sclk_delay_ff.full = rfixed_const(33); |
| 2482 | } else { |
| 2483 | if (rdev->mc.vram_width == 128) |
| 2484 | sclk_delay_ff.full = rfixed_const(57); |
| 2485 | else |
| 2486 | sclk_delay_ff.full = rfixed_const(41); |
| 2487 | } |
| 2488 | } |
| 2489 | |
| 2490 | mc_latency_sclk.full = rfixed_div(sclk_delay_ff, sclk_eff_ff); |
| 2491 | |
| 2492 | if (rdev->mc.vram_is_ddr) { |
| 2493 | if (rdev->mc.vram_width == 32) { |
| 2494 | k1.full = rfixed_const(40); |
| 2495 | c = 3; |
| 2496 | } else { |
| 2497 | k1.full = rfixed_const(20); |
| 2498 | c = 1; |
| 2499 | } |
| 2500 | } else { |
| 2501 | k1.full = rfixed_const(40); |
| 2502 | c = 3; |
| 2503 | } |
| 2504 | |
| 2505 | temp_ff.full = rfixed_const(2); |
| 2506 | mc_latency_mclk.full = rfixed_mul(trcd_ff, temp_ff); |
| 2507 | temp_ff.full = rfixed_const(c); |
| 2508 | mc_latency_mclk.full += rfixed_mul(tcas_ff, temp_ff); |
| 2509 | temp_ff.full = rfixed_const(4); |
| 2510 | mc_latency_mclk.full += rfixed_mul(tras_ff, temp_ff); |
| 2511 | mc_latency_mclk.full += rfixed_mul(trp_ff, temp_ff); |
| 2512 | mc_latency_mclk.full += k1.full; |
| 2513 | |
| 2514 | mc_latency_mclk.full = rfixed_div(mc_latency_mclk, mclk_ff); |
| 2515 | mc_latency_mclk.full += rfixed_div(temp_ff, sclk_eff_ff); |
| 2516 | |
| 2517 | /* |
| 2518 | HW cursor time assuming worst case of full size colour cursor. |
| 2519 | */ |
| 2520 | temp_ff.full = rfixed_const((2 * (cur_size - (rdev->mc.vram_is_ddr + 1)))); |
| 2521 | temp_ff.full += trcd_ff.full; |
| 2522 | if (temp_ff.full < tras_ff.full) |
| 2523 | temp_ff.full = tras_ff.full; |
| 2524 | cur_latency_mclk.full = rfixed_div(temp_ff, mclk_ff); |
| 2525 | |
| 2526 | temp_ff.full = rfixed_const(cur_size); |
| 2527 | cur_latency_sclk.full = rfixed_div(temp_ff, sclk_eff_ff); |
| 2528 | /* |
| 2529 | Find the total latency for the display data. |
| 2530 | */ |
Michel Dänzer | b5fc901 | 2009-10-08 10:44:10 +0200 | [diff] [blame] | 2531 | disp_latency_overhead.full = rfixed_const(8); |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 2532 | disp_latency_overhead.full = rfixed_div(disp_latency_overhead, sclk_ff); |
| 2533 | mc_latency_mclk.full += disp_latency_overhead.full + cur_latency_mclk.full; |
| 2534 | mc_latency_sclk.full += disp_latency_overhead.full + cur_latency_sclk.full; |
| 2535 | |
| 2536 | if (mc_latency_mclk.full > mc_latency_sclk.full) |
| 2537 | disp_latency.full = mc_latency_mclk.full; |
| 2538 | else |
| 2539 | disp_latency.full = mc_latency_sclk.full; |
| 2540 | |
| 2541 | /* setup Max GRPH_STOP_REQ default value */ |
| 2542 | if (ASIC_IS_RV100(rdev)) |
| 2543 | max_stop_req = 0x5c; |
| 2544 | else |
| 2545 | max_stop_req = 0x7c; |
| 2546 | |
| 2547 | if (mode1) { |
| 2548 | /* CRTC1 |
| 2549 | Set GRPH_BUFFER_CNTL register using h/w defined optimal values. |
| 2550 | GRPH_STOP_REQ <= MIN[ 0x7C, (CRTC_H_DISP + 1) * (bit depth) / 0x10 ] |
| 2551 | */ |
| 2552 | stop_req = mode1->hdisplay * pixel_bytes1 / 16; |
| 2553 | |
| 2554 | if (stop_req > max_stop_req) |
| 2555 | stop_req = max_stop_req; |
| 2556 | |
| 2557 | /* |
| 2558 | Find the drain rate of the display buffer. |
| 2559 | */ |
| 2560 | temp_ff.full = rfixed_const((16/pixel_bytes1)); |
| 2561 | disp_drain_rate.full = rfixed_div(pix_clk, temp_ff); |
| 2562 | |
| 2563 | /* |
| 2564 | Find the critical point of the display buffer. |
| 2565 | */ |
| 2566 | crit_point_ff.full = rfixed_mul(disp_drain_rate, disp_latency); |
| 2567 | crit_point_ff.full += rfixed_const_half(0); |
| 2568 | |
| 2569 | critical_point = rfixed_trunc(crit_point_ff); |
| 2570 | |
| 2571 | if (rdev->disp_priority == 2) { |
| 2572 | critical_point = 0; |
| 2573 | } |
| 2574 | |
| 2575 | /* |
| 2576 | The critical point should never be above max_stop_req-4. Setting |
| 2577 | GRPH_CRITICAL_CNTL = 0 will thus force high priority all the time. |
| 2578 | */ |
| 2579 | if (max_stop_req - critical_point < 4) |
| 2580 | critical_point = 0; |
| 2581 | |
| 2582 | if (critical_point == 0 && mode2 && rdev->family == CHIP_R300) { |
| 2583 | /* some R300 cards have problem with this set to 0, when CRTC2 is enabled.*/ |
| 2584 | critical_point = 0x10; |
| 2585 | } |
| 2586 | |
| 2587 | temp = RREG32(RADEON_GRPH_BUFFER_CNTL); |
| 2588 | temp &= ~(RADEON_GRPH_STOP_REQ_MASK); |
| 2589 | temp |= (stop_req << RADEON_GRPH_STOP_REQ_SHIFT); |
| 2590 | temp &= ~(RADEON_GRPH_START_REQ_MASK); |
| 2591 | if ((rdev->family == CHIP_R350) && |
| 2592 | (stop_req > 0x15)) { |
| 2593 | stop_req -= 0x10; |
| 2594 | } |
| 2595 | temp |= (stop_req << RADEON_GRPH_START_REQ_SHIFT); |
| 2596 | temp |= RADEON_GRPH_BUFFER_SIZE; |
| 2597 | temp &= ~(RADEON_GRPH_CRITICAL_CNTL | |
| 2598 | RADEON_GRPH_CRITICAL_AT_SOF | |
| 2599 | RADEON_GRPH_STOP_CNTL); |
| 2600 | /* |
| 2601 | Write the result into the register. |
| 2602 | */ |
| 2603 | WREG32(RADEON_GRPH_BUFFER_CNTL, ((temp & ~RADEON_GRPH_CRITICAL_POINT_MASK) | |
| 2604 | (critical_point << RADEON_GRPH_CRITICAL_POINT_SHIFT))); |
| 2605 | |
| 2606 | #if 0 |
| 2607 | if ((rdev->family == CHIP_RS400) || |
| 2608 | (rdev->family == CHIP_RS480)) { |
| 2609 | /* attempt to program RS400 disp regs correctly ??? */ |
| 2610 | temp = RREG32(RS400_DISP1_REG_CNTL); |
| 2611 | temp &= ~(RS400_DISP1_START_REQ_LEVEL_MASK | |
| 2612 | RS400_DISP1_STOP_REQ_LEVEL_MASK); |
| 2613 | WREG32(RS400_DISP1_REQ_CNTL1, (temp | |
| 2614 | (critical_point << RS400_DISP1_START_REQ_LEVEL_SHIFT) | |
| 2615 | (critical_point << RS400_DISP1_STOP_REQ_LEVEL_SHIFT))); |
| 2616 | temp = RREG32(RS400_DMIF_MEM_CNTL1); |
| 2617 | temp &= ~(RS400_DISP1_CRITICAL_POINT_START_MASK | |
| 2618 | RS400_DISP1_CRITICAL_POINT_STOP_MASK); |
| 2619 | WREG32(RS400_DMIF_MEM_CNTL1, (temp | |
| 2620 | (critical_point << RS400_DISP1_CRITICAL_POINT_START_SHIFT) | |
| 2621 | (critical_point << RS400_DISP1_CRITICAL_POINT_STOP_SHIFT))); |
| 2622 | } |
| 2623 | #endif |
| 2624 | |
| 2625 | DRM_DEBUG("GRPH_BUFFER_CNTL from to %x\n", |
| 2626 | /* (unsigned int)info->SavedReg->grph_buffer_cntl, */ |
| 2627 | (unsigned int)RREG32(RADEON_GRPH_BUFFER_CNTL)); |
| 2628 | } |
| 2629 | |
| 2630 | if (mode2) { |
| 2631 | u32 grph2_cntl; |
| 2632 | stop_req = mode2->hdisplay * pixel_bytes2 / 16; |
| 2633 | |
| 2634 | if (stop_req > max_stop_req) |
| 2635 | stop_req = max_stop_req; |
| 2636 | |
| 2637 | /* |
| 2638 | Find the drain rate of the display buffer. |
| 2639 | */ |
| 2640 | temp_ff.full = rfixed_const((16/pixel_bytes2)); |
| 2641 | disp_drain_rate2.full = rfixed_div(pix_clk2, temp_ff); |
| 2642 | |
| 2643 | grph2_cntl = RREG32(RADEON_GRPH2_BUFFER_CNTL); |
| 2644 | grph2_cntl &= ~(RADEON_GRPH_STOP_REQ_MASK); |
| 2645 | grph2_cntl |= (stop_req << RADEON_GRPH_STOP_REQ_SHIFT); |
| 2646 | grph2_cntl &= ~(RADEON_GRPH_START_REQ_MASK); |
| 2647 | if ((rdev->family == CHIP_R350) && |
| 2648 | (stop_req > 0x15)) { |
| 2649 | stop_req -= 0x10; |
| 2650 | } |
| 2651 | grph2_cntl |= (stop_req << RADEON_GRPH_START_REQ_SHIFT); |
| 2652 | grph2_cntl |= RADEON_GRPH_BUFFER_SIZE; |
| 2653 | grph2_cntl &= ~(RADEON_GRPH_CRITICAL_CNTL | |
| 2654 | RADEON_GRPH_CRITICAL_AT_SOF | |
| 2655 | RADEON_GRPH_STOP_CNTL); |
| 2656 | |
| 2657 | if ((rdev->family == CHIP_RS100) || |
| 2658 | (rdev->family == CHIP_RS200)) |
| 2659 | critical_point2 = 0; |
| 2660 | else { |
| 2661 | temp = (rdev->mc.vram_width * rdev->mc.vram_is_ddr + 1)/128; |
| 2662 | temp_ff.full = rfixed_const(temp); |
| 2663 | temp_ff.full = rfixed_mul(mclk_ff, temp_ff); |
| 2664 | if (sclk_ff.full < temp_ff.full) |
| 2665 | temp_ff.full = sclk_ff.full; |
| 2666 | |
| 2667 | read_return_rate.full = temp_ff.full; |
| 2668 | |
| 2669 | if (mode1) { |
| 2670 | temp_ff.full = read_return_rate.full - disp_drain_rate.full; |
| 2671 | time_disp1_drop_priority.full = rfixed_div(crit_point_ff, temp_ff); |
| 2672 | } else { |
| 2673 | time_disp1_drop_priority.full = 0; |
| 2674 | } |
| 2675 | crit_point_ff.full = disp_latency.full + time_disp1_drop_priority.full + disp_latency.full; |
| 2676 | crit_point_ff.full = rfixed_mul(crit_point_ff, disp_drain_rate2); |
| 2677 | crit_point_ff.full += rfixed_const_half(0); |
| 2678 | |
| 2679 | critical_point2 = rfixed_trunc(crit_point_ff); |
| 2680 | |
| 2681 | if (rdev->disp_priority == 2) { |
| 2682 | critical_point2 = 0; |
| 2683 | } |
| 2684 | |
| 2685 | if (max_stop_req - critical_point2 < 4) |
| 2686 | critical_point2 = 0; |
| 2687 | |
| 2688 | } |
| 2689 | |
| 2690 | if (critical_point2 == 0 && rdev->family == CHIP_R300) { |
| 2691 | /* some R300 cards have problem with this set to 0 */ |
| 2692 | critical_point2 = 0x10; |
| 2693 | } |
| 2694 | |
| 2695 | WREG32(RADEON_GRPH2_BUFFER_CNTL, ((grph2_cntl & ~RADEON_GRPH_CRITICAL_POINT_MASK) | |
| 2696 | (critical_point2 << RADEON_GRPH_CRITICAL_POINT_SHIFT))); |
| 2697 | |
| 2698 | if ((rdev->family == CHIP_RS400) || |
| 2699 | (rdev->family == CHIP_RS480)) { |
| 2700 | #if 0 |
| 2701 | /* attempt to program RS400 disp2 regs correctly ??? */ |
| 2702 | temp = RREG32(RS400_DISP2_REQ_CNTL1); |
| 2703 | temp &= ~(RS400_DISP2_START_REQ_LEVEL_MASK | |
| 2704 | RS400_DISP2_STOP_REQ_LEVEL_MASK); |
| 2705 | WREG32(RS400_DISP2_REQ_CNTL1, (temp | |
| 2706 | (critical_point2 << RS400_DISP1_START_REQ_LEVEL_SHIFT) | |
| 2707 | (critical_point2 << RS400_DISP1_STOP_REQ_LEVEL_SHIFT))); |
| 2708 | temp = RREG32(RS400_DISP2_REQ_CNTL2); |
| 2709 | temp &= ~(RS400_DISP2_CRITICAL_POINT_START_MASK | |
| 2710 | RS400_DISP2_CRITICAL_POINT_STOP_MASK); |
| 2711 | WREG32(RS400_DISP2_REQ_CNTL2, (temp | |
| 2712 | (critical_point2 << RS400_DISP2_CRITICAL_POINT_START_SHIFT) | |
| 2713 | (critical_point2 << RS400_DISP2_CRITICAL_POINT_STOP_SHIFT))); |
| 2714 | #endif |
| 2715 | WREG32(RS400_DISP2_REQ_CNTL1, 0x105DC1CC); |
| 2716 | WREG32(RS400_DISP2_REQ_CNTL2, 0x2749D000); |
| 2717 | WREG32(RS400_DMIF_MEM_CNTL1, 0x29CA71DC); |
| 2718 | WREG32(RS400_DISP1_REQ_CNTL1, 0x28FBC3AC); |
| 2719 | } |
| 2720 | |
| 2721 | DRM_DEBUG("GRPH2_BUFFER_CNTL from to %x\n", |
| 2722 | (unsigned int)RREG32(RADEON_GRPH2_BUFFER_CNTL)); |
| 2723 | } |
| 2724 | } |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2725 | |
| 2726 | static inline void r100_cs_track_texture_print(struct r100_cs_track_texture *t) |
| 2727 | { |
| 2728 | DRM_ERROR("pitch %d\n", t->pitch); |
Mathias Fröhlich | ceb776b | 2009-10-19 12:50:41 -0400 | [diff] [blame] | 2729 | DRM_ERROR("use_pitch %d\n", t->use_pitch); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2730 | DRM_ERROR("width %d\n", t->width); |
Mathias Fröhlich | ceb776b | 2009-10-19 12:50:41 -0400 | [diff] [blame] | 2731 | DRM_ERROR("width_11 %d\n", t->width_11); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2732 | DRM_ERROR("height %d\n", t->height); |
Mathias Fröhlich | ceb776b | 2009-10-19 12:50:41 -0400 | [diff] [blame] | 2733 | DRM_ERROR("height_11 %d\n", t->height_11); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2734 | DRM_ERROR("num levels %d\n", t->num_levels); |
| 2735 | DRM_ERROR("depth %d\n", t->txdepth); |
| 2736 | DRM_ERROR("bpp %d\n", t->cpp); |
| 2737 | DRM_ERROR("coordinate type %d\n", t->tex_coord_type); |
| 2738 | DRM_ERROR("width round to power of 2 %d\n", t->roundup_w); |
| 2739 | 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] | 2740 | DRM_ERROR("compress format %d\n", t->compress_format); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2741 | } |
| 2742 | |
| 2743 | static int r100_cs_track_cube(struct radeon_device *rdev, |
| 2744 | struct r100_cs_track *track, unsigned idx) |
| 2745 | { |
| 2746 | unsigned face, w, h; |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 2747 | struct radeon_bo *cube_robj; |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2748 | unsigned long size; |
| 2749 | |
| 2750 | for (face = 0; face < 5; face++) { |
| 2751 | cube_robj = track->textures[idx].cube_info[face].robj; |
| 2752 | w = track->textures[idx].cube_info[face].width; |
| 2753 | h = track->textures[idx].cube_info[face].height; |
| 2754 | |
| 2755 | size = w * h; |
| 2756 | size *= track->textures[idx].cpp; |
| 2757 | |
| 2758 | size += track->textures[idx].cube_info[face].offset; |
| 2759 | |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 2760 | if (size > radeon_bo_size(cube_robj)) { |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2761 | DRM_ERROR("Cube texture offset greater than object size %lu %lu\n", |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 2762 | size, radeon_bo_size(cube_robj)); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2763 | r100_cs_track_texture_print(&track->textures[idx]); |
| 2764 | return -1; |
| 2765 | } |
| 2766 | } |
| 2767 | return 0; |
| 2768 | } |
| 2769 | |
Dave Airlie | d785d78 | 2009-12-07 13:16:06 +1000 | [diff] [blame] | 2770 | static int r100_track_compress_size(int compress_format, int w, int h) |
| 2771 | { |
| 2772 | int block_width, block_height, block_bytes; |
| 2773 | int wblocks, hblocks; |
| 2774 | int min_wblocks; |
| 2775 | int sz; |
| 2776 | |
| 2777 | block_width = 4; |
| 2778 | block_height = 4; |
| 2779 | |
| 2780 | switch (compress_format) { |
| 2781 | case R100_TRACK_COMP_DXT1: |
| 2782 | block_bytes = 8; |
| 2783 | min_wblocks = 4; |
| 2784 | break; |
| 2785 | default: |
| 2786 | case R100_TRACK_COMP_DXT35: |
| 2787 | block_bytes = 16; |
| 2788 | min_wblocks = 2; |
| 2789 | break; |
| 2790 | } |
| 2791 | |
| 2792 | hblocks = (h + block_height - 1) / block_height; |
| 2793 | wblocks = (w + block_width - 1) / block_width; |
| 2794 | if (wblocks < min_wblocks) |
| 2795 | wblocks = min_wblocks; |
| 2796 | sz = wblocks * hblocks * block_bytes; |
| 2797 | return sz; |
| 2798 | } |
| 2799 | |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2800 | static int r100_cs_track_texture_check(struct radeon_device *rdev, |
| 2801 | struct r100_cs_track *track) |
| 2802 | { |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 2803 | struct radeon_bo *robj; |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2804 | unsigned long size; |
| 2805 | unsigned u, i, w, h; |
| 2806 | int ret; |
| 2807 | |
| 2808 | for (u = 0; u < track->num_texture; u++) { |
| 2809 | if (!track->textures[u].enabled) |
| 2810 | continue; |
| 2811 | robj = track->textures[u].robj; |
| 2812 | if (robj == NULL) { |
| 2813 | DRM_ERROR("No texture bound to unit %u\n", u); |
| 2814 | return -EINVAL; |
| 2815 | } |
| 2816 | size = 0; |
| 2817 | for (i = 0; i <= track->textures[u].num_levels; i++) { |
| 2818 | if (track->textures[u].use_pitch) { |
| 2819 | if (rdev->family < CHIP_R300) |
| 2820 | w = (track->textures[u].pitch / track->textures[u].cpp) / (1 << i); |
| 2821 | else |
| 2822 | w = track->textures[u].pitch / (1 << i); |
| 2823 | } else { |
Mathias Fröhlich | ceb776b | 2009-10-19 12:50:41 -0400 | [diff] [blame] | 2824 | w = track->textures[u].width; |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2825 | if (rdev->family >= CHIP_RV515) |
| 2826 | w |= track->textures[u].width_11; |
Mathias Fröhlich | ceb776b | 2009-10-19 12:50:41 -0400 | [diff] [blame] | 2827 | w = w / (1 << i); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2828 | if (track->textures[u].roundup_w) |
| 2829 | w = roundup_pow_of_two(w); |
| 2830 | } |
Mathias Fröhlich | ceb776b | 2009-10-19 12:50:41 -0400 | [diff] [blame] | 2831 | h = track->textures[u].height; |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2832 | if (rdev->family >= CHIP_RV515) |
| 2833 | h |= track->textures[u].height_11; |
Mathias Fröhlich | ceb776b | 2009-10-19 12:50:41 -0400 | [diff] [blame] | 2834 | h = h / (1 << i); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2835 | if (track->textures[u].roundup_h) |
| 2836 | h = roundup_pow_of_two(h); |
Dave Airlie | d785d78 | 2009-12-07 13:16:06 +1000 | [diff] [blame] | 2837 | if (track->textures[u].compress_format) { |
| 2838 | |
| 2839 | size += r100_track_compress_size(track->textures[u].compress_format, w, h); |
| 2840 | /* compressed textures are block based */ |
| 2841 | } else |
| 2842 | size += w * h; |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2843 | } |
| 2844 | size *= track->textures[u].cpp; |
Dave Airlie | d785d78 | 2009-12-07 13:16:06 +1000 | [diff] [blame] | 2845 | |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2846 | switch (track->textures[u].tex_coord_type) { |
| 2847 | case 0: |
| 2848 | break; |
| 2849 | case 1: |
| 2850 | size *= (1 << track->textures[u].txdepth); |
| 2851 | break; |
| 2852 | case 2: |
| 2853 | if (track->separate_cube) { |
| 2854 | ret = r100_cs_track_cube(rdev, track, u); |
| 2855 | if (ret) |
| 2856 | return ret; |
| 2857 | } else |
| 2858 | size *= 6; |
| 2859 | break; |
| 2860 | default: |
| 2861 | DRM_ERROR("Invalid texture coordinate type %u for unit " |
| 2862 | "%u\n", track->textures[u].tex_coord_type, u); |
| 2863 | return -EINVAL; |
| 2864 | } |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 2865 | if (size > radeon_bo_size(robj)) { |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2866 | DRM_ERROR("Texture of unit %u needs %lu bytes but is " |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 2867 | "%lu\n", u, size, radeon_bo_size(robj)); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2868 | r100_cs_track_texture_print(&track->textures[u]); |
| 2869 | return -EINVAL; |
| 2870 | } |
| 2871 | } |
| 2872 | return 0; |
| 2873 | } |
| 2874 | |
| 2875 | int r100_cs_track_check(struct radeon_device *rdev, struct r100_cs_track *track) |
| 2876 | { |
| 2877 | unsigned i; |
| 2878 | unsigned long size; |
| 2879 | unsigned prim_walk; |
| 2880 | unsigned nverts; |
| 2881 | |
| 2882 | for (i = 0; i < track->num_cb; i++) { |
| 2883 | if (track->cb[i].robj == NULL) { |
Marek Olšák | 46c64d4 | 2009-12-17 06:02:28 +0100 | [diff] [blame^] | 2884 | if (!(track->fastfill || track->color_channel_mask || |
| 2885 | track->blend_read_enable)) { |
| 2886 | continue; |
| 2887 | } |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2888 | DRM_ERROR("[drm] No buffer for color buffer %d !\n", i); |
| 2889 | return -EINVAL; |
| 2890 | } |
| 2891 | size = track->cb[i].pitch * track->cb[i].cpp * track->maxy; |
| 2892 | size += track->cb[i].offset; |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 2893 | if (size > radeon_bo_size(track->cb[i].robj)) { |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2894 | DRM_ERROR("[drm] Buffer too small for color buffer %d " |
| 2895 | "(need %lu have %lu) !\n", i, size, |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 2896 | radeon_bo_size(track->cb[i].robj)); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2897 | DRM_ERROR("[drm] color buffer %d (%u %u %u %u)\n", |
| 2898 | i, track->cb[i].pitch, track->cb[i].cpp, |
| 2899 | track->cb[i].offset, track->maxy); |
| 2900 | return -EINVAL; |
| 2901 | } |
| 2902 | } |
| 2903 | if (track->z_enabled) { |
| 2904 | if (track->zb.robj == NULL) { |
| 2905 | DRM_ERROR("[drm] No buffer for z buffer !\n"); |
| 2906 | return -EINVAL; |
| 2907 | } |
| 2908 | size = track->zb.pitch * track->zb.cpp * track->maxy; |
| 2909 | size += track->zb.offset; |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 2910 | if (size > radeon_bo_size(track->zb.robj)) { |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2911 | DRM_ERROR("[drm] Buffer too small for z buffer " |
| 2912 | "(need %lu have %lu) !\n", size, |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 2913 | radeon_bo_size(track->zb.robj)); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2914 | DRM_ERROR("[drm] zbuffer (%u %u %u %u)\n", |
| 2915 | track->zb.pitch, track->zb.cpp, |
| 2916 | track->zb.offset, track->maxy); |
| 2917 | return -EINVAL; |
| 2918 | } |
| 2919 | } |
| 2920 | prim_walk = (track->vap_vf_cntl >> 4) & 0x3; |
| 2921 | nverts = (track->vap_vf_cntl >> 16) & 0xFFFF; |
| 2922 | switch (prim_walk) { |
| 2923 | case 1: |
| 2924 | for (i = 0; i < track->num_arrays; i++) { |
| 2925 | size = track->arrays[i].esize * track->max_indx * 4; |
| 2926 | if (track->arrays[i].robj == NULL) { |
| 2927 | DRM_ERROR("(PW %u) Vertex array %u no buffer " |
| 2928 | "bound\n", prim_walk, i); |
| 2929 | return -EINVAL; |
| 2930 | } |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 2931 | if (size > radeon_bo_size(track->arrays[i].robj)) { |
| 2932 | dev_err(rdev->dev, "(PW %u) Vertex array %u " |
| 2933 | "need %lu dwords have %lu dwords\n", |
| 2934 | prim_walk, i, size >> 2, |
| 2935 | radeon_bo_size(track->arrays[i].robj) |
| 2936 | >> 2); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2937 | DRM_ERROR("Max indices %u\n", track->max_indx); |
| 2938 | return -EINVAL; |
| 2939 | } |
| 2940 | } |
| 2941 | break; |
| 2942 | case 2: |
| 2943 | for (i = 0; i < track->num_arrays; i++) { |
| 2944 | size = track->arrays[i].esize * (nverts - 1) * 4; |
| 2945 | if (track->arrays[i].robj == NULL) { |
| 2946 | DRM_ERROR("(PW %u) Vertex array %u no buffer " |
| 2947 | "bound\n", prim_walk, i); |
| 2948 | return -EINVAL; |
| 2949 | } |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 2950 | if (size > radeon_bo_size(track->arrays[i].robj)) { |
| 2951 | dev_err(rdev->dev, "(PW %u) Vertex array %u " |
| 2952 | "need %lu dwords have %lu dwords\n", |
| 2953 | prim_walk, i, size >> 2, |
| 2954 | radeon_bo_size(track->arrays[i].robj) |
| 2955 | >> 2); |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 2956 | return -EINVAL; |
| 2957 | } |
| 2958 | } |
| 2959 | break; |
| 2960 | case 3: |
| 2961 | size = track->vtx_size * nverts; |
| 2962 | if (size != track->immd_dwords) { |
| 2963 | DRM_ERROR("IMMD draw %u dwors but needs %lu dwords\n", |
| 2964 | track->immd_dwords, size); |
| 2965 | DRM_ERROR("VAP_VF_CNTL.NUM_VERTICES %u, VTX_SIZE %u\n", |
| 2966 | nverts, track->vtx_size); |
| 2967 | return -EINVAL; |
| 2968 | } |
| 2969 | break; |
| 2970 | default: |
| 2971 | DRM_ERROR("[drm] Invalid primitive walk %d for VAP_VF_CNTL\n", |
| 2972 | prim_walk); |
| 2973 | return -EINVAL; |
| 2974 | } |
| 2975 | return r100_cs_track_texture_check(rdev, track); |
| 2976 | } |
| 2977 | |
| 2978 | void r100_cs_track_clear(struct radeon_device *rdev, struct r100_cs_track *track) |
| 2979 | { |
| 2980 | unsigned i, face; |
| 2981 | |
| 2982 | if (rdev->family < CHIP_R300) { |
| 2983 | track->num_cb = 1; |
| 2984 | if (rdev->family <= CHIP_RS200) |
| 2985 | track->num_texture = 3; |
| 2986 | else |
| 2987 | track->num_texture = 6; |
| 2988 | track->maxy = 2048; |
| 2989 | track->separate_cube = 1; |
| 2990 | } else { |
| 2991 | track->num_cb = 4; |
| 2992 | track->num_texture = 16; |
| 2993 | track->maxy = 4096; |
| 2994 | track->separate_cube = 0; |
| 2995 | } |
| 2996 | |
| 2997 | for (i = 0; i < track->num_cb; i++) { |
| 2998 | track->cb[i].robj = NULL; |
| 2999 | track->cb[i].pitch = 8192; |
| 3000 | track->cb[i].cpp = 16; |
| 3001 | track->cb[i].offset = 0; |
| 3002 | } |
| 3003 | track->z_enabled = true; |
| 3004 | track->zb.robj = NULL; |
| 3005 | track->zb.pitch = 8192; |
| 3006 | track->zb.cpp = 4; |
| 3007 | track->zb.offset = 0; |
| 3008 | track->vtx_size = 0x7F; |
| 3009 | track->immd_dwords = 0xFFFFFFFFUL; |
| 3010 | track->num_arrays = 11; |
| 3011 | track->max_indx = 0x00FFFFFFUL; |
| 3012 | for (i = 0; i < track->num_arrays; i++) { |
| 3013 | track->arrays[i].robj = NULL; |
| 3014 | track->arrays[i].esize = 0x7F; |
| 3015 | } |
| 3016 | for (i = 0; i < track->num_texture; i++) { |
Dave Airlie | d785d78 | 2009-12-07 13:16:06 +1000 | [diff] [blame] | 3017 | track->textures[i].compress_format = R100_TRACK_COMP_NONE; |
Dave Airlie | 551ebd8 | 2009-09-01 15:25:57 +1000 | [diff] [blame] | 3018 | track->textures[i].pitch = 16536; |
| 3019 | track->textures[i].width = 16536; |
| 3020 | track->textures[i].height = 16536; |
| 3021 | track->textures[i].width_11 = 1 << 11; |
| 3022 | track->textures[i].height_11 = 1 << 11; |
| 3023 | track->textures[i].num_levels = 12; |
| 3024 | if (rdev->family <= CHIP_RS200) { |
| 3025 | track->textures[i].tex_coord_type = 0; |
| 3026 | track->textures[i].txdepth = 0; |
| 3027 | } else { |
| 3028 | track->textures[i].txdepth = 16; |
| 3029 | track->textures[i].tex_coord_type = 1; |
| 3030 | } |
| 3031 | track->textures[i].cpp = 64; |
| 3032 | track->textures[i].robj = NULL; |
| 3033 | /* CS IB emission code makes sure texture unit are disabled */ |
| 3034 | track->textures[i].enabled = false; |
| 3035 | track->textures[i].roundup_w = true; |
| 3036 | track->textures[i].roundup_h = true; |
| 3037 | if (track->separate_cube) |
| 3038 | for (face = 0; face < 5; face++) { |
| 3039 | track->textures[i].cube_info[face].robj = NULL; |
| 3040 | track->textures[i].cube_info[face].width = 16536; |
| 3041 | track->textures[i].cube_info[face].height = 16536; |
| 3042 | track->textures[i].cube_info[face].offset = 0; |
| 3043 | } |
| 3044 | } |
| 3045 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3046 | |
| 3047 | int r100_ring_test(struct radeon_device *rdev) |
| 3048 | { |
| 3049 | uint32_t scratch; |
| 3050 | uint32_t tmp = 0; |
| 3051 | unsigned i; |
| 3052 | int r; |
| 3053 | |
| 3054 | r = radeon_scratch_get(rdev, &scratch); |
| 3055 | if (r) { |
| 3056 | DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r); |
| 3057 | return r; |
| 3058 | } |
| 3059 | WREG32(scratch, 0xCAFEDEAD); |
| 3060 | r = radeon_ring_lock(rdev, 2); |
| 3061 | if (r) { |
| 3062 | DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r); |
| 3063 | radeon_scratch_free(rdev, scratch); |
| 3064 | return r; |
| 3065 | } |
| 3066 | radeon_ring_write(rdev, PACKET0(scratch, 0)); |
| 3067 | radeon_ring_write(rdev, 0xDEADBEEF); |
| 3068 | radeon_ring_unlock_commit(rdev); |
| 3069 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 3070 | tmp = RREG32(scratch); |
| 3071 | if (tmp == 0xDEADBEEF) { |
| 3072 | break; |
| 3073 | } |
| 3074 | DRM_UDELAY(1); |
| 3075 | } |
| 3076 | if (i < rdev->usec_timeout) { |
| 3077 | DRM_INFO("ring test succeeded in %d usecs\n", i); |
| 3078 | } else { |
| 3079 | DRM_ERROR("radeon: ring test failed (sracth(0x%04X)=0x%08X)\n", |
| 3080 | scratch, tmp); |
| 3081 | r = -EINVAL; |
| 3082 | } |
| 3083 | radeon_scratch_free(rdev, scratch); |
| 3084 | return r; |
| 3085 | } |
| 3086 | |
| 3087 | void r100_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib) |
| 3088 | { |
| 3089 | radeon_ring_write(rdev, PACKET0(RADEON_CP_IB_BASE, 1)); |
| 3090 | radeon_ring_write(rdev, ib->gpu_addr); |
| 3091 | radeon_ring_write(rdev, ib->length_dw); |
| 3092 | } |
| 3093 | |
| 3094 | int r100_ib_test(struct radeon_device *rdev) |
| 3095 | { |
| 3096 | struct radeon_ib *ib; |
| 3097 | uint32_t scratch; |
| 3098 | uint32_t tmp = 0; |
| 3099 | unsigned i; |
| 3100 | int r; |
| 3101 | |
| 3102 | r = radeon_scratch_get(rdev, &scratch); |
| 3103 | if (r) { |
| 3104 | DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r); |
| 3105 | return r; |
| 3106 | } |
| 3107 | WREG32(scratch, 0xCAFEDEAD); |
| 3108 | r = radeon_ib_get(rdev, &ib); |
| 3109 | if (r) { |
| 3110 | return r; |
| 3111 | } |
| 3112 | ib->ptr[0] = PACKET0(scratch, 0); |
| 3113 | ib->ptr[1] = 0xDEADBEEF; |
| 3114 | ib->ptr[2] = PACKET2(0); |
| 3115 | ib->ptr[3] = PACKET2(0); |
| 3116 | ib->ptr[4] = PACKET2(0); |
| 3117 | ib->ptr[5] = PACKET2(0); |
| 3118 | ib->ptr[6] = PACKET2(0); |
| 3119 | ib->ptr[7] = PACKET2(0); |
| 3120 | ib->length_dw = 8; |
| 3121 | r = radeon_ib_schedule(rdev, ib); |
| 3122 | if (r) { |
| 3123 | radeon_scratch_free(rdev, scratch); |
| 3124 | radeon_ib_free(rdev, &ib); |
| 3125 | return r; |
| 3126 | } |
| 3127 | r = radeon_fence_wait(ib->fence, false); |
| 3128 | if (r) { |
| 3129 | return r; |
| 3130 | } |
| 3131 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 3132 | tmp = RREG32(scratch); |
| 3133 | if (tmp == 0xDEADBEEF) { |
| 3134 | break; |
| 3135 | } |
| 3136 | DRM_UDELAY(1); |
| 3137 | } |
| 3138 | if (i < rdev->usec_timeout) { |
| 3139 | DRM_INFO("ib test succeeded in %u usecs\n", i); |
| 3140 | } else { |
| 3141 | DRM_ERROR("radeon: ib test failed (sracth(0x%04X)=0x%08X)\n", |
| 3142 | scratch, tmp); |
| 3143 | r = -EINVAL; |
| 3144 | } |
| 3145 | radeon_scratch_free(rdev, scratch); |
| 3146 | radeon_ib_free(rdev, &ib); |
| 3147 | return r; |
| 3148 | } |
Jerome Glisse | 9f022dd | 2009-09-11 15:35:22 +0200 | [diff] [blame] | 3149 | |
| 3150 | void r100_ib_fini(struct radeon_device *rdev) |
| 3151 | { |
| 3152 | radeon_ib_pool_fini(rdev); |
| 3153 | } |
| 3154 | |
| 3155 | int r100_ib_init(struct radeon_device *rdev) |
| 3156 | { |
| 3157 | int r; |
| 3158 | |
| 3159 | r = radeon_ib_pool_init(rdev); |
| 3160 | if (r) { |
| 3161 | dev_err(rdev->dev, "failled initializing IB pool (%d).\n", r); |
| 3162 | r100_ib_fini(rdev); |
| 3163 | return r; |
| 3164 | } |
| 3165 | r = r100_ib_test(rdev); |
| 3166 | if (r) { |
| 3167 | dev_err(rdev->dev, "failled testing IB (%d).\n", r); |
| 3168 | r100_ib_fini(rdev); |
| 3169 | return r; |
| 3170 | } |
| 3171 | return 0; |
| 3172 | } |
| 3173 | |
| 3174 | void r100_mc_stop(struct radeon_device *rdev, struct r100_mc_save *save) |
| 3175 | { |
| 3176 | /* Shutdown CP we shouldn't need to do that but better be safe than |
| 3177 | * sorry |
| 3178 | */ |
| 3179 | rdev->cp.ready = false; |
| 3180 | WREG32(R_000740_CP_CSQ_CNTL, 0); |
| 3181 | |
| 3182 | /* Save few CRTC registers */ |
Jerome Glisse | ca6ffc6 | 2009-10-01 10:20:52 +0200 | [diff] [blame] | 3183 | save->GENMO_WT = RREG8(R_0003C2_GENMO_WT); |
Jerome Glisse | 9f022dd | 2009-09-11 15:35:22 +0200 | [diff] [blame] | 3184 | save->CRTC_EXT_CNTL = RREG32(R_000054_CRTC_EXT_CNTL); |
| 3185 | save->CRTC_GEN_CNTL = RREG32(R_000050_CRTC_GEN_CNTL); |
| 3186 | save->CUR_OFFSET = RREG32(R_000260_CUR_OFFSET); |
| 3187 | if (!(rdev->flags & RADEON_SINGLE_CRTC)) { |
| 3188 | save->CRTC2_GEN_CNTL = RREG32(R_0003F8_CRTC2_GEN_CNTL); |
| 3189 | save->CUR2_OFFSET = RREG32(R_000360_CUR2_OFFSET); |
| 3190 | } |
| 3191 | |
| 3192 | /* Disable VGA aperture access */ |
Jerome Glisse | ca6ffc6 | 2009-10-01 10:20:52 +0200 | [diff] [blame] | 3193 | 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] | 3194 | /* Disable cursor, overlay, crtc */ |
| 3195 | WREG32(R_000260_CUR_OFFSET, save->CUR_OFFSET | S_000260_CUR_LOCK(1)); |
| 3196 | WREG32(R_000054_CRTC_EXT_CNTL, save->CRTC_EXT_CNTL | |
| 3197 | S_000054_CRTC_DISPLAY_DIS(1)); |
| 3198 | WREG32(R_000050_CRTC_GEN_CNTL, |
| 3199 | (C_000050_CRTC_CUR_EN & save->CRTC_GEN_CNTL) | |
| 3200 | S_000050_CRTC_DISP_REQ_EN_B(1)); |
| 3201 | WREG32(R_000420_OV0_SCALE_CNTL, |
| 3202 | C_000420_OV0_OVERLAY_EN & RREG32(R_000420_OV0_SCALE_CNTL)); |
| 3203 | WREG32(R_000260_CUR_OFFSET, C_000260_CUR_LOCK & save->CUR_OFFSET); |
| 3204 | if (!(rdev->flags & RADEON_SINGLE_CRTC)) { |
| 3205 | WREG32(R_000360_CUR2_OFFSET, save->CUR2_OFFSET | |
| 3206 | S_000360_CUR2_LOCK(1)); |
| 3207 | WREG32(R_0003F8_CRTC2_GEN_CNTL, |
| 3208 | (C_0003F8_CRTC2_CUR_EN & save->CRTC2_GEN_CNTL) | |
| 3209 | S_0003F8_CRTC2_DISPLAY_DIS(1) | |
| 3210 | S_0003F8_CRTC2_DISP_REQ_EN_B(1)); |
| 3211 | WREG32(R_000360_CUR2_OFFSET, |
| 3212 | C_000360_CUR2_LOCK & save->CUR2_OFFSET); |
| 3213 | } |
| 3214 | } |
| 3215 | |
| 3216 | void r100_mc_resume(struct radeon_device *rdev, struct r100_mc_save *save) |
| 3217 | { |
| 3218 | /* Update base address for crtc */ |
| 3219 | WREG32(R_00023C_DISPLAY_BASE_ADDR, rdev->mc.vram_location); |
| 3220 | if (!(rdev->flags & RADEON_SINGLE_CRTC)) { |
| 3221 | WREG32(R_00033C_CRTC2_DISPLAY_BASE_ADDR, |
| 3222 | rdev->mc.vram_location); |
| 3223 | } |
| 3224 | /* Restore CRTC registers */ |
Jerome Glisse | ca6ffc6 | 2009-10-01 10:20:52 +0200 | [diff] [blame] | 3225 | WREG8(R_0003C2_GENMO_WT, save->GENMO_WT); |
Jerome Glisse | 9f022dd | 2009-09-11 15:35:22 +0200 | [diff] [blame] | 3226 | WREG32(R_000054_CRTC_EXT_CNTL, save->CRTC_EXT_CNTL); |
| 3227 | WREG32(R_000050_CRTC_GEN_CNTL, save->CRTC_GEN_CNTL); |
| 3228 | if (!(rdev->flags & RADEON_SINGLE_CRTC)) { |
| 3229 | WREG32(R_0003F8_CRTC2_GEN_CNTL, save->CRTC2_GEN_CNTL); |
| 3230 | } |
| 3231 | } |
Jerome Glisse | ca6ffc6 | 2009-10-01 10:20:52 +0200 | [diff] [blame] | 3232 | |
| 3233 | void r100_vga_render_disable(struct radeon_device *rdev) |
| 3234 | { |
Jerome Glisse | d455090 | 2009-10-01 10:12:06 +0200 | [diff] [blame] | 3235 | u32 tmp; |
Jerome Glisse | ca6ffc6 | 2009-10-01 10:20:52 +0200 | [diff] [blame] | 3236 | |
Jerome Glisse | d455090 | 2009-10-01 10:12:06 +0200 | [diff] [blame] | 3237 | tmp = RREG8(R_0003C2_GENMO_WT); |
Jerome Glisse | ca6ffc6 | 2009-10-01 10:20:52 +0200 | [diff] [blame] | 3238 | WREG8(R_0003C2_GENMO_WT, C_0003C2_VGA_RAM_EN & tmp); |
| 3239 | } |
Jerome Glisse | d455090 | 2009-10-01 10:12:06 +0200 | [diff] [blame] | 3240 | |
| 3241 | static void r100_debugfs(struct radeon_device *rdev) |
| 3242 | { |
| 3243 | int r; |
| 3244 | |
| 3245 | r = r100_debugfs_mc_info_init(rdev); |
| 3246 | if (r) |
| 3247 | dev_warn(rdev->dev, "Failed to create r100_mc debugfs file.\n"); |
| 3248 | } |
| 3249 | |
| 3250 | static void r100_mc_program(struct radeon_device *rdev) |
| 3251 | { |
| 3252 | struct r100_mc_save save; |
| 3253 | |
| 3254 | /* Stops all mc clients */ |
| 3255 | r100_mc_stop(rdev, &save); |
| 3256 | if (rdev->flags & RADEON_IS_AGP) { |
| 3257 | WREG32(R_00014C_MC_AGP_LOCATION, |
| 3258 | S_00014C_MC_AGP_START(rdev->mc.gtt_start >> 16) | |
| 3259 | S_00014C_MC_AGP_TOP(rdev->mc.gtt_end >> 16)); |
| 3260 | WREG32(R_000170_AGP_BASE, lower_32_bits(rdev->mc.agp_base)); |
| 3261 | if (rdev->family > CHIP_RV200) |
| 3262 | WREG32(R_00015C_AGP_BASE_2, |
| 3263 | upper_32_bits(rdev->mc.agp_base) & 0xff); |
| 3264 | } else { |
| 3265 | WREG32(R_00014C_MC_AGP_LOCATION, 0x0FFFFFFF); |
| 3266 | WREG32(R_000170_AGP_BASE, 0); |
| 3267 | if (rdev->family > CHIP_RV200) |
| 3268 | WREG32(R_00015C_AGP_BASE_2, 0); |
| 3269 | } |
| 3270 | /* Wait for mc idle */ |
| 3271 | if (r100_mc_wait_for_idle(rdev)) |
| 3272 | dev_warn(rdev->dev, "Wait for MC idle timeout.\n"); |
| 3273 | /* Program MC, should be a 32bits limited address space */ |
| 3274 | WREG32(R_000148_MC_FB_LOCATION, |
| 3275 | S_000148_MC_FB_START(rdev->mc.vram_start >> 16) | |
| 3276 | S_000148_MC_FB_TOP(rdev->mc.vram_end >> 16)); |
| 3277 | r100_mc_resume(rdev, &save); |
| 3278 | } |
| 3279 | |
| 3280 | void r100_clock_startup(struct radeon_device *rdev) |
| 3281 | { |
| 3282 | u32 tmp; |
| 3283 | |
| 3284 | if (radeon_dynclks != -1 && radeon_dynclks) |
| 3285 | radeon_legacy_set_clock_gating(rdev, 1); |
| 3286 | /* We need to force on some of the block */ |
| 3287 | tmp = RREG32_PLL(R_00000D_SCLK_CNTL); |
| 3288 | tmp |= S_00000D_FORCE_CP(1) | S_00000D_FORCE_VIP(1); |
| 3289 | if ((rdev->family == CHIP_RV250) || (rdev->family == CHIP_RV280)) |
| 3290 | tmp |= S_00000D_FORCE_DISP1(1) | S_00000D_FORCE_DISP2(1); |
| 3291 | WREG32_PLL(R_00000D_SCLK_CNTL, tmp); |
| 3292 | } |
| 3293 | |
| 3294 | static int r100_startup(struct radeon_device *rdev) |
| 3295 | { |
| 3296 | int r; |
| 3297 | |
Alex Deucher | 92cde00 | 2009-12-04 10:55:12 -0500 | [diff] [blame] | 3298 | /* set common regs */ |
| 3299 | r100_set_common_regs(rdev); |
| 3300 | /* program mc */ |
Jerome Glisse | d455090 | 2009-10-01 10:12:06 +0200 | [diff] [blame] | 3301 | r100_mc_program(rdev); |
| 3302 | /* Resume clock */ |
| 3303 | r100_clock_startup(rdev); |
| 3304 | /* Initialize GPU configuration (# pipes, ...) */ |
| 3305 | r100_gpu_init(rdev); |
| 3306 | /* Initialize GART (initialize after TTM so we can allocate |
| 3307 | * memory through TTM but finalize after TTM) */ |
Dave Airlie | 17e15b0 | 2009-11-05 15:36:53 +1000 | [diff] [blame] | 3308 | r100_enable_bm(rdev); |
Jerome Glisse | d455090 | 2009-10-01 10:12:06 +0200 | [diff] [blame] | 3309 | if (rdev->flags & RADEON_IS_PCI) { |
| 3310 | r = r100_pci_gart_enable(rdev); |
| 3311 | if (r) |
| 3312 | return r; |
| 3313 | } |
| 3314 | /* Enable IRQ */ |
Jerome Glisse | d455090 | 2009-10-01 10:12:06 +0200 | [diff] [blame] | 3315 | r100_irq_set(rdev); |
| 3316 | /* 1M ring buffer */ |
| 3317 | r = r100_cp_init(rdev, 1024 * 1024); |
| 3318 | if (r) { |
| 3319 | dev_err(rdev->dev, "failled initializing CP (%d).\n", r); |
| 3320 | return r; |
| 3321 | } |
| 3322 | r = r100_wb_init(rdev); |
| 3323 | if (r) |
| 3324 | dev_err(rdev->dev, "failled initializing WB (%d).\n", r); |
| 3325 | r = r100_ib_init(rdev); |
| 3326 | if (r) { |
| 3327 | dev_err(rdev->dev, "failled initializing IB (%d).\n", r); |
| 3328 | return r; |
| 3329 | } |
| 3330 | return 0; |
| 3331 | } |
| 3332 | |
| 3333 | int r100_resume(struct radeon_device *rdev) |
| 3334 | { |
| 3335 | /* Make sur GART are not working */ |
| 3336 | if (rdev->flags & RADEON_IS_PCI) |
| 3337 | r100_pci_gart_disable(rdev); |
| 3338 | /* Resume clock before doing reset */ |
| 3339 | r100_clock_startup(rdev); |
| 3340 | /* Reset gpu before posting otherwise ATOM will enter infinite loop */ |
| 3341 | if (radeon_gpu_reset(rdev)) { |
| 3342 | dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n", |
| 3343 | RREG32(R_000E40_RBBM_STATUS), |
| 3344 | RREG32(R_0007C0_CP_STAT)); |
| 3345 | } |
| 3346 | /* post */ |
| 3347 | radeon_combios_asic_init(rdev->ddev); |
| 3348 | /* Resume clock after posting */ |
| 3349 | r100_clock_startup(rdev); |
Dave Airlie | 550e2d9 | 2009-12-09 14:15:38 +1000 | [diff] [blame] | 3350 | /* Initialize surface registers */ |
| 3351 | radeon_surface_init(rdev); |
Jerome Glisse | d455090 | 2009-10-01 10:12:06 +0200 | [diff] [blame] | 3352 | return r100_startup(rdev); |
| 3353 | } |
| 3354 | |
| 3355 | int r100_suspend(struct radeon_device *rdev) |
| 3356 | { |
| 3357 | r100_cp_disable(rdev); |
| 3358 | r100_wb_disable(rdev); |
| 3359 | r100_irq_disable(rdev); |
| 3360 | if (rdev->flags & RADEON_IS_PCI) |
| 3361 | r100_pci_gart_disable(rdev); |
| 3362 | return 0; |
| 3363 | } |
| 3364 | |
| 3365 | void r100_fini(struct radeon_device *rdev) |
| 3366 | { |
| 3367 | r100_suspend(rdev); |
| 3368 | r100_cp_fini(rdev); |
| 3369 | r100_wb_fini(rdev); |
| 3370 | r100_ib_fini(rdev); |
| 3371 | radeon_gem_fini(rdev); |
| 3372 | if (rdev->flags & RADEON_IS_PCI) |
| 3373 | r100_pci_gart_fini(rdev); |
| 3374 | radeon_irq_kms_fini(rdev); |
| 3375 | radeon_fence_driver_fini(rdev); |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 3376 | radeon_bo_fini(rdev); |
Jerome Glisse | d455090 | 2009-10-01 10:12:06 +0200 | [diff] [blame] | 3377 | radeon_atombios_fini(rdev); |
| 3378 | kfree(rdev->bios); |
| 3379 | rdev->bios = NULL; |
| 3380 | } |
| 3381 | |
| 3382 | int r100_mc_init(struct radeon_device *rdev) |
| 3383 | { |
| 3384 | int r; |
| 3385 | u32 tmp; |
| 3386 | |
| 3387 | /* Setup GPU memory space */ |
| 3388 | rdev->mc.vram_location = 0xFFFFFFFFUL; |
| 3389 | rdev->mc.gtt_location = 0xFFFFFFFFUL; |
| 3390 | if (rdev->flags & RADEON_IS_IGP) { |
| 3391 | tmp = G_00015C_MC_FB_START(RREG32(R_00015C_NB_TOM)); |
| 3392 | rdev->mc.vram_location = tmp << 16; |
| 3393 | } |
| 3394 | if (rdev->flags & RADEON_IS_AGP) { |
| 3395 | r = radeon_agp_init(rdev); |
| 3396 | if (r) { |
| 3397 | printk(KERN_WARNING "[drm] Disabling AGP\n"); |
| 3398 | rdev->flags &= ~RADEON_IS_AGP; |
| 3399 | rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024; |
| 3400 | } else { |
| 3401 | rdev->mc.gtt_location = rdev->mc.agp_base; |
| 3402 | } |
| 3403 | } |
| 3404 | r = radeon_mc_setup(rdev); |
| 3405 | if (r) |
| 3406 | return r; |
| 3407 | return 0; |
| 3408 | } |
| 3409 | |
| 3410 | int r100_init(struct radeon_device *rdev) |
| 3411 | { |
| 3412 | int r; |
| 3413 | |
Jerome Glisse | d455090 | 2009-10-01 10:12:06 +0200 | [diff] [blame] | 3414 | /* Register debugfs file specific to this group of asics */ |
| 3415 | r100_debugfs(rdev); |
| 3416 | /* Disable VGA */ |
| 3417 | r100_vga_render_disable(rdev); |
| 3418 | /* Initialize scratch registers */ |
| 3419 | radeon_scratch_init(rdev); |
| 3420 | /* Initialize surface registers */ |
| 3421 | radeon_surface_init(rdev); |
| 3422 | /* TODO: disable VGA need to use VGA request */ |
| 3423 | /* BIOS*/ |
| 3424 | if (!radeon_get_bios(rdev)) { |
| 3425 | if (ASIC_IS_AVIVO(rdev)) |
| 3426 | return -EINVAL; |
| 3427 | } |
| 3428 | if (rdev->is_atom_bios) { |
| 3429 | dev_err(rdev->dev, "Expecting combios for RS400/RS480 GPU\n"); |
| 3430 | return -EINVAL; |
| 3431 | } else { |
| 3432 | r = radeon_combios_init(rdev); |
| 3433 | if (r) |
| 3434 | return r; |
| 3435 | } |
| 3436 | /* Reset gpu before posting otherwise ATOM will enter infinite loop */ |
| 3437 | if (radeon_gpu_reset(rdev)) { |
| 3438 | dev_warn(rdev->dev, |
| 3439 | "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n", |
| 3440 | RREG32(R_000E40_RBBM_STATUS), |
| 3441 | RREG32(R_0007C0_CP_STAT)); |
| 3442 | } |
| 3443 | /* check if cards are posted or not */ |
Dave Airlie | 72542d7 | 2009-12-01 14:06:31 +1000 | [diff] [blame] | 3444 | if (radeon_boot_test_post_card(rdev) == false) |
| 3445 | return -EINVAL; |
Jerome Glisse | d455090 | 2009-10-01 10:12:06 +0200 | [diff] [blame] | 3446 | /* Set asic errata */ |
| 3447 | r100_errata(rdev); |
| 3448 | /* Initialize clocks */ |
| 3449 | radeon_get_clock_info(rdev->ddev); |
Rafał Miłecki | 6234077 | 2009-12-15 21:46:58 +0100 | [diff] [blame] | 3450 | /* Initialize power management */ |
| 3451 | radeon_pm_init(rdev); |
Jerome Glisse | d455090 | 2009-10-01 10:12:06 +0200 | [diff] [blame] | 3452 | /* Get vram informations */ |
| 3453 | r100_vram_info(rdev); |
| 3454 | /* Initialize memory controller (also test AGP) */ |
| 3455 | r = r100_mc_init(rdev); |
| 3456 | if (r) |
| 3457 | return r; |
| 3458 | /* Fence driver */ |
| 3459 | r = radeon_fence_driver_init(rdev); |
| 3460 | if (r) |
| 3461 | return r; |
| 3462 | r = radeon_irq_kms_init(rdev); |
| 3463 | if (r) |
| 3464 | return r; |
| 3465 | /* Memory manager */ |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 3466 | r = radeon_bo_init(rdev); |
Jerome Glisse | d455090 | 2009-10-01 10:12:06 +0200 | [diff] [blame] | 3467 | if (r) |
| 3468 | return r; |
| 3469 | if (rdev->flags & RADEON_IS_PCI) { |
| 3470 | r = r100_pci_gart_init(rdev); |
| 3471 | if (r) |
| 3472 | return r; |
| 3473 | } |
| 3474 | r100_set_safe_registers(rdev); |
| 3475 | rdev->accel_working = true; |
| 3476 | r = r100_startup(rdev); |
| 3477 | if (r) { |
| 3478 | /* Somethings want wront with the accel init stop accel */ |
| 3479 | dev_err(rdev->dev, "Disabling GPU acceleration\n"); |
| 3480 | r100_suspend(rdev); |
| 3481 | r100_cp_fini(rdev); |
| 3482 | r100_wb_fini(rdev); |
| 3483 | r100_ib_fini(rdev); |
| 3484 | if (rdev->flags & RADEON_IS_PCI) |
| 3485 | r100_pci_gart_fini(rdev); |
| 3486 | radeon_irq_kms_fini(rdev); |
| 3487 | rdev->accel_working = false; |
| 3488 | } |
| 3489 | return 0; |
| 3490 | } |