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 | */ |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 28 | /* RS600 / Radeon X1250/X1270 integrated GPU |
| 29 | * |
| 30 | * This file gather function specific to RS600 which is the IGP of |
| 31 | * the X1250/X1270 family supporting intel CPU (while RS690/RS740 |
| 32 | * is the X1250/X1270 supporting AMD CPU). The display engine are |
| 33 | * the avivo one, bios is an atombios, 3D block are the one of the |
| 34 | * R4XX family. The GART is different from the RS400 one and is very |
| 35 | * close to the one of the R600 family (R600 likely being an evolution |
| 36 | * of the RS600 GART block). |
| 37 | */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 38 | #include "drmP.h" |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 39 | #include "radeon.h" |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 40 | #include "atom.h" |
| 41 | #include "rs600d.h" |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 42 | |
Dave Airlie | 3f7dc91a | 2009-08-27 11:10:15 +1000 | [diff] [blame] | 43 | #include "rs600_reg_safe.h" |
| 44 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 45 | void rs600_gpu_init(struct radeon_device *rdev); |
| 46 | int rs600_mc_wait_for_idle(struct radeon_device *rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 47 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 48 | /* |
| 49 | * GART. |
| 50 | */ |
| 51 | void rs600_gart_tlb_flush(struct radeon_device *rdev) |
| 52 | { |
| 53 | uint32_t tmp; |
| 54 | |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 55 | tmp = RREG32_MC(R_000100_MC_PT0_CNTL); |
| 56 | tmp &= C_000100_INVALIDATE_ALL_L1_TLBS & C_000100_INVALIDATE_L2_CACHE; |
| 57 | WREG32_MC(R_000100_MC_PT0_CNTL, tmp); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 58 | |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 59 | tmp = RREG32_MC(R_000100_MC_PT0_CNTL); |
| 60 | tmp |= S_000100_INVALIDATE_ALL_L1_TLBS(1) & S_000100_INVALIDATE_L2_CACHE(1); |
| 61 | WREG32_MC(R_000100_MC_PT0_CNTL, tmp); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 62 | |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 63 | tmp = RREG32_MC(R_000100_MC_PT0_CNTL); |
| 64 | tmp &= C_000100_INVALIDATE_ALL_L1_TLBS & C_000100_INVALIDATE_L2_CACHE; |
| 65 | WREG32_MC(R_000100_MC_PT0_CNTL, tmp); |
| 66 | tmp = RREG32_MC(R_000100_MC_PT0_CNTL); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 67 | } |
| 68 | |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 69 | int rs600_gart_init(struct radeon_device *rdev) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 70 | { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 71 | int r; |
| 72 | |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 73 | if (rdev->gart.table.vram.robj) { |
| 74 | WARN(1, "RS600 GART already initialized.\n"); |
| 75 | return 0; |
| 76 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 77 | /* Initialize common gart structure */ |
| 78 | r = radeon_gart_init(rdev); |
| 79 | if (r) { |
| 80 | return r; |
| 81 | } |
| 82 | rdev->gart.table_size = rdev->gart.num_gpu_pages * 8; |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 83 | return radeon_gart_table_vram_alloc(rdev); |
| 84 | } |
| 85 | |
| 86 | int rs600_gart_enable(struct radeon_device *rdev) |
| 87 | { |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 88 | u32 tmp; |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 89 | int r, i; |
| 90 | |
| 91 | if (rdev->gart.table.vram.robj == NULL) { |
| 92 | dev_err(rdev->dev, "No VRAM object for PCIE GART.\n"); |
| 93 | return -EINVAL; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 94 | } |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 95 | r = radeon_gart_table_vram_pin(rdev); |
| 96 | if (r) |
| 97 | return r; |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 98 | /* Enable bus master */ |
| 99 | tmp = RREG32(R_00004C_BUS_CNTL) & C_00004C_BUS_MASTER_DIS; |
| 100 | WREG32(R_00004C_BUS_CNTL, tmp); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 101 | /* FIXME: setup default page */ |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 102 | WREG32_MC(R_000100_MC_PT0_CNTL, |
Alex Deucher | 4f15d24 | 2009-12-05 17:55:37 -0500 | [diff] [blame^] | 103 | (S_000100_EFFECTIVE_L2_CACHE_SIZE(6) | |
| 104 | S_000100_EFFECTIVE_L2_QUEUE_SIZE(6))); |
| 105 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 106 | for (i = 0; i < 19; i++) { |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 107 | WREG32_MC(R_00016C_MC_PT0_CLIENT0_CNTL + i, |
Alex Deucher | 4f15d24 | 2009-12-05 17:55:37 -0500 | [diff] [blame^] | 108 | S_00016C_ENABLE_TRANSLATION_MODE_OVERRIDE(1) | |
| 109 | S_00016C_SYSTEM_ACCESS_MODE_MASK( |
| 110 | V_00016C_SYSTEM_ACCESS_MODE_NOT_IN_SYS) | |
| 111 | S_00016C_SYSTEM_APERTURE_UNMAPPED_ACCESS( |
| 112 | V_00016C_SYSTEM_APERTURE_UNMAPPED_PASSTHROUGH) | |
| 113 | S_00016C_EFFECTIVE_L1_CACHE_SIZE(3) | |
| 114 | S_00016C_ENABLE_FRAGMENT_PROCESSING(1) | |
| 115 | S_00016C_EFFECTIVE_L1_QUEUE_SIZE(3)); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 116 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 117 | /* enable first context */ |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 118 | WREG32_MC(R_000102_MC_PT0_CONTEXT0_CNTL, |
Alex Deucher | 4f15d24 | 2009-12-05 17:55:37 -0500 | [diff] [blame^] | 119 | S_000102_ENABLE_PAGE_TABLE(1) | |
| 120 | S_000102_PAGE_TABLE_DEPTH(V_000102_PAGE_TABLE_FLAT)); |
| 121 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 122 | /* disable all other contexts */ |
Alex Deucher | 4f15d24 | 2009-12-05 17:55:37 -0500 | [diff] [blame^] | 123 | for (i = 1; i < 8; i++) |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 124 | WREG32_MC(R_000102_MC_PT0_CONTEXT0_CNTL + i, 0); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 125 | |
| 126 | /* setup the page table */ |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 127 | WREG32_MC(R_00012C_MC_PT0_CONTEXT0_FLAT_BASE_ADDR, |
Alex Deucher | 4f15d24 | 2009-12-05 17:55:37 -0500 | [diff] [blame^] | 128 | rdev->gart.table_addr); |
| 129 | WREG32_MC(R_00013C_MC_PT0_CONTEXT0_FLAT_START_ADDR, rdev->mc.gtt_start); |
| 130 | WREG32_MC(R_00014C_MC_PT0_CONTEXT0_FLAT_END_ADDR, rdev->mc.gtt_end); |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 131 | WREG32_MC(R_00011C_MC_PT0_CONTEXT0_DEFAULT_READ_ADDR, 0); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 132 | |
Alex Deucher | 4f15d24 | 2009-12-05 17:55:37 -0500 | [diff] [blame^] | 133 | /* System context maps to VRAM space */ |
| 134 | WREG32_MC(R_000112_MC_PT0_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start); |
| 135 | WREG32_MC(R_000114_MC_PT0_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end); |
| 136 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 137 | /* enable page tables */ |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 138 | tmp = RREG32_MC(R_000100_MC_PT0_CNTL); |
| 139 | WREG32_MC(R_000100_MC_PT0_CNTL, (tmp | S_000100_ENABLE_PT(1))); |
| 140 | tmp = RREG32_MC(R_000009_MC_CNTL1); |
| 141 | WREG32_MC(R_000009_MC_CNTL1, (tmp | S_000009_ENABLE_PAGE_TABLES(1))); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 142 | rs600_gart_tlb_flush(rdev); |
| 143 | rdev->gart.ready = true; |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | void rs600_gart_disable(struct radeon_device *rdev) |
| 148 | { |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 149 | u32 tmp; |
| 150 | int r; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 151 | |
| 152 | /* FIXME: disable out of gart access */ |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 153 | WREG32_MC(R_000100_MC_PT0_CNTL, 0); |
| 154 | tmp = RREG32_MC(R_000009_MC_CNTL1); |
| 155 | WREG32_MC(R_000009_MC_CNTL1, tmp & C_000009_ENABLE_PAGE_TABLES); |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 156 | if (rdev->gart.table.vram.robj) { |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 157 | r = radeon_bo_reserve(rdev->gart.table.vram.robj, false); |
| 158 | if (r == 0) { |
| 159 | radeon_bo_kunmap(rdev->gart.table.vram.robj); |
| 160 | radeon_bo_unpin(rdev->gart.table.vram.robj); |
| 161 | radeon_bo_unreserve(rdev->gart.table.vram.robj); |
| 162 | } |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
| 166 | void rs600_gart_fini(struct radeon_device *rdev) |
| 167 | { |
| 168 | rs600_gart_disable(rdev); |
| 169 | radeon_gart_table_vram_free(rdev); |
| 170 | radeon_gart_fini(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | #define R600_PTE_VALID (1 << 0) |
| 174 | #define R600_PTE_SYSTEM (1 << 1) |
| 175 | #define R600_PTE_SNOOPED (1 << 2) |
| 176 | #define R600_PTE_READABLE (1 << 5) |
| 177 | #define R600_PTE_WRITEABLE (1 << 6) |
| 178 | |
| 179 | int rs600_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr) |
| 180 | { |
| 181 | void __iomem *ptr = (void *)rdev->gart.table.vram.ptr; |
| 182 | |
| 183 | if (i < 0 || i > rdev->gart.num_gpu_pages) { |
| 184 | return -EINVAL; |
| 185 | } |
| 186 | addr = addr & 0xFFFFFFFFFFFFF000ULL; |
| 187 | addr |= R600_PTE_VALID | R600_PTE_SYSTEM | R600_PTE_SNOOPED; |
| 188 | addr |= R600_PTE_READABLE | R600_PTE_WRITEABLE; |
| 189 | writeq(addr, ((void __iomem *)ptr) + (i * 8)); |
| 190 | return 0; |
| 191 | } |
| 192 | |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 193 | int rs600_irq_set(struct radeon_device *rdev) |
| 194 | { |
| 195 | uint32_t tmp = 0; |
| 196 | uint32_t mode_int = 0; |
| 197 | |
| 198 | if (rdev->irq.sw_int) { |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 199 | tmp |= S_000040_SW_INT_EN(1); |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 200 | } |
| 201 | if (rdev->irq.crtc_vblank_int[0]) { |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 202 | mode_int |= S_006540_D1MODE_VBLANK_INT_MASK(1); |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 203 | } |
| 204 | if (rdev->irq.crtc_vblank_int[1]) { |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 205 | mode_int |= S_006540_D2MODE_VBLANK_INT_MASK(1); |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 206 | } |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 207 | WREG32(R_000040_GEN_INT_CNTL, tmp); |
| 208 | WREG32(R_006540_DxMODE_INT_MASK, mode_int); |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | static inline uint32_t rs600_irq_ack(struct radeon_device *rdev, u32 *r500_disp_int) |
| 213 | { |
Jerome Glisse | 01ceae8 | 2009-10-07 11:08:22 +0200 | [diff] [blame] | 214 | uint32_t irqs = RREG32(R_000044_GEN_INT_STATUS); |
| 215 | uint32_t irq_mask = ~C_000044_SW_INT; |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 216 | |
Jerome Glisse | 01ceae8 | 2009-10-07 11:08:22 +0200 | [diff] [blame] | 217 | if (G_000044_DISPLAY_INT_STAT(irqs)) { |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 218 | *r500_disp_int = RREG32(R_007EDC_DISP_INTERRUPT_STATUS); |
| 219 | if (G_007EDC_LB_D1_VBLANK_INTERRUPT(*r500_disp_int)) { |
| 220 | WREG32(R_006534_D1MODE_VBLANK_STATUS, |
| 221 | S_006534_D1MODE_VBLANK_ACK(1)); |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 222 | } |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 223 | if (G_007EDC_LB_D2_VBLANK_INTERRUPT(*r500_disp_int)) { |
| 224 | WREG32(R_006D34_D2MODE_VBLANK_STATUS, |
| 225 | S_006D34_D2MODE_VBLANK_ACK(1)); |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 226 | } |
| 227 | } else { |
| 228 | *r500_disp_int = 0; |
| 229 | } |
| 230 | |
| 231 | if (irqs) { |
Jerome Glisse | 01ceae8 | 2009-10-07 11:08:22 +0200 | [diff] [blame] | 232 | WREG32(R_000044_GEN_INT_STATUS, irqs); |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 233 | } |
| 234 | return irqs & irq_mask; |
| 235 | } |
| 236 | |
Jerome Glisse | ac447df | 2009-09-30 22:18:43 +0200 | [diff] [blame] | 237 | void rs600_irq_disable(struct radeon_device *rdev) |
| 238 | { |
| 239 | u32 tmp; |
| 240 | |
| 241 | WREG32(R_000040_GEN_INT_CNTL, 0); |
| 242 | WREG32(R_006540_DxMODE_INT_MASK, 0); |
| 243 | /* Wait and acknowledge irq */ |
| 244 | mdelay(1); |
| 245 | rs600_irq_ack(rdev, &tmp); |
| 246 | } |
| 247 | |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 248 | int rs600_irq_process(struct radeon_device *rdev) |
| 249 | { |
Alex Deucher | 3e5cb98 | 2009-10-16 12:21:24 -0400 | [diff] [blame] | 250 | uint32_t status, msi_rearm; |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 251 | uint32_t r500_disp_int; |
| 252 | |
| 253 | status = rs600_irq_ack(rdev, &r500_disp_int); |
| 254 | if (!status && !r500_disp_int) { |
| 255 | return IRQ_NONE; |
| 256 | } |
| 257 | while (status || r500_disp_int) { |
| 258 | /* SW interrupt */ |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 259 | if (G_000040_SW_INT_EN(status)) |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 260 | radeon_fence_process(rdev); |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 261 | /* Vertical blank interrupts */ |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 262 | if (G_007EDC_LB_D1_VBLANK_INTERRUPT(r500_disp_int)) |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 263 | drm_handle_vblank(rdev->ddev, 0); |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 264 | if (G_007EDC_LB_D2_VBLANK_INTERRUPT(r500_disp_int)) |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 265 | drm_handle_vblank(rdev->ddev, 1); |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 266 | status = rs600_irq_ack(rdev, &r500_disp_int); |
| 267 | } |
Alex Deucher | 3e5cb98 | 2009-10-16 12:21:24 -0400 | [diff] [blame] | 268 | if (rdev->msi_enabled) { |
| 269 | switch (rdev->family) { |
| 270 | case CHIP_RS600: |
| 271 | case CHIP_RS690: |
| 272 | case CHIP_RS740: |
| 273 | msi_rearm = RREG32(RADEON_BUS_CNTL) & ~RS600_MSI_REARM; |
| 274 | WREG32(RADEON_BUS_CNTL, msi_rearm); |
| 275 | WREG32(RADEON_BUS_CNTL, msi_rearm | RS600_MSI_REARM); |
| 276 | break; |
| 277 | default: |
| 278 | msi_rearm = RREG32(RADEON_MSI_REARM_EN) & ~RV370_MSI_REARM_EN; |
| 279 | WREG32(RADEON_MSI_REARM_EN, msi_rearm); |
| 280 | WREG32(RADEON_MSI_REARM_EN, msi_rearm | RV370_MSI_REARM_EN); |
| 281 | break; |
| 282 | } |
| 283 | } |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 284 | return IRQ_HANDLED; |
| 285 | } |
| 286 | |
| 287 | u32 rs600_get_vblank_counter(struct radeon_device *rdev, int crtc) |
| 288 | { |
| 289 | if (crtc == 0) |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 290 | return RREG32(R_0060A4_D1CRTC_STATUS_FRAME_COUNT); |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 291 | else |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 292 | return RREG32(R_0068A4_D2CRTC_STATUS_FRAME_COUNT); |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 293 | } |
| 294 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 295 | int rs600_mc_wait_for_idle(struct radeon_device *rdev) |
| 296 | { |
| 297 | unsigned i; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 298 | |
| 299 | for (i = 0; i < rdev->usec_timeout; i++) { |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 300 | if (G_000000_MC_IDLE(RREG32_MC(R_000000_MC_STATUS))) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 301 | return 0; |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 302 | udelay(1); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 303 | } |
| 304 | return -1; |
| 305 | } |
| 306 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 307 | void rs600_gpu_init(struct radeon_device *rdev) |
| 308 | { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 309 | r100_hdp_reset(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 310 | r420_pipes_init(rdev); |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 311 | /* Wait for mc idle */ |
| 312 | if (rs600_mc_wait_for_idle(rdev)) |
| 313 | dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 314 | } |
| 315 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 316 | void rs600_vram_info(struct radeon_device *rdev) |
| 317 | { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 318 | rdev->mc.vram_is_ddr = true; |
| 319 | rdev->mc.vram_width = 128; |
Alex Deucher | 722f294 | 2009-12-03 16:18:19 -0500 | [diff] [blame] | 320 | |
| 321 | rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE); |
| 322 | rdev->mc.mc_vram_size = rdev->mc.real_vram_size; |
| 323 | |
| 324 | rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0); |
| 325 | rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0); |
Alex Deucher | 0088dbd | 2009-12-03 16:28:02 -0500 | [diff] [blame] | 326 | |
| 327 | if (rdev->mc.mc_vram_size > rdev->mc.aper_size) |
| 328 | rdev->mc.mc_vram_size = rdev->mc.aper_size; |
| 329 | |
| 330 | if (rdev->mc.real_vram_size > rdev->mc.aper_size) |
| 331 | rdev->mc.real_vram_size = rdev->mc.aper_size; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 332 | } |
| 333 | |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 334 | void rs600_bandwidth_update(struct radeon_device *rdev) |
| 335 | { |
| 336 | /* FIXME: implement, should this be like rs690 ? */ |
| 337 | } |
| 338 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 339 | uint32_t rs600_mc_rreg(struct radeon_device *rdev, uint32_t reg) |
| 340 | { |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 341 | WREG32(R_000070_MC_IND_INDEX, S_000070_MC_IND_ADDR(reg) | |
| 342 | S_000070_MC_IND_CITF_ARB0(1)); |
| 343 | return RREG32(R_000074_MC_IND_DATA); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | void rs600_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v) |
| 347 | { |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 348 | WREG32(R_000070_MC_IND_INDEX, S_000070_MC_IND_ADDR(reg) | |
| 349 | S_000070_MC_IND_CITF_ARB0(1) | S_000070_MC_IND_WR_EN(1)); |
| 350 | WREG32(R_000074_MC_IND_DATA, v); |
| 351 | } |
| 352 | |
| 353 | void rs600_debugfs(struct radeon_device *rdev) |
| 354 | { |
| 355 | if (r100_debugfs_rbbm_init(rdev)) |
| 356 | DRM_ERROR("Failed to register debugfs file for RBBM !\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 357 | } |
Dave Airlie | 3f7dc91a | 2009-08-27 11:10:15 +1000 | [diff] [blame] | 358 | |
Jerome Glisse | 3bc6853 | 2009-10-01 09:39:24 +0200 | [diff] [blame] | 359 | void rs600_set_safe_registers(struct radeon_device *rdev) |
Dave Airlie | 3f7dc91a | 2009-08-27 11:10:15 +1000 | [diff] [blame] | 360 | { |
| 361 | rdev->config.r300.reg_safe_bm = rs600_reg_safe_bm; |
| 362 | rdev->config.r300.reg_safe_bm_size = ARRAY_SIZE(rs600_reg_safe_bm); |
Jerome Glisse | 3bc6853 | 2009-10-01 09:39:24 +0200 | [diff] [blame] | 363 | } |
| 364 | |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 365 | static void rs600_mc_program(struct radeon_device *rdev) |
| 366 | { |
| 367 | struct rv515_mc_save save; |
| 368 | |
| 369 | /* Stops all mc clients */ |
| 370 | rv515_mc_stop(rdev, &save); |
| 371 | |
| 372 | /* Wait for mc idle */ |
| 373 | if (rs600_mc_wait_for_idle(rdev)) |
| 374 | dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n"); |
| 375 | |
| 376 | /* FIXME: What does AGP means for such chipset ? */ |
| 377 | WREG32_MC(R_000005_MC_AGP_LOCATION, 0x0FFFFFFF); |
| 378 | WREG32_MC(R_000006_AGP_BASE, 0); |
| 379 | WREG32_MC(R_000007_AGP_BASE_2, 0); |
| 380 | /* Program MC */ |
| 381 | WREG32_MC(R_000004_MC_FB_LOCATION, |
| 382 | S_000004_MC_FB_START(rdev->mc.vram_start >> 16) | |
| 383 | S_000004_MC_FB_TOP(rdev->mc.vram_end >> 16)); |
| 384 | WREG32(R_000134_HDP_FB_LOCATION, |
| 385 | S_000134_HDP_FB_START(rdev->mc.vram_start >> 16)); |
| 386 | |
| 387 | rv515_mc_resume(rdev, &save); |
| 388 | } |
| 389 | |
| 390 | static int rs600_startup(struct radeon_device *rdev) |
| 391 | { |
| 392 | int r; |
| 393 | |
| 394 | rs600_mc_program(rdev); |
| 395 | /* Resume clock */ |
| 396 | rv515_clock_startup(rdev); |
| 397 | /* Initialize GPU configuration (# pipes, ...) */ |
| 398 | rs600_gpu_init(rdev); |
| 399 | /* Initialize GART (initialize after TTM so we can allocate |
| 400 | * memory through TTM but finalize after TTM) */ |
| 401 | r = rs600_gart_enable(rdev); |
| 402 | if (r) |
| 403 | return r; |
| 404 | /* Enable IRQ */ |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 405 | rs600_irq_set(rdev); |
| 406 | /* 1M ring buffer */ |
| 407 | r = r100_cp_init(rdev, 1024 * 1024); |
| 408 | if (r) { |
| 409 | dev_err(rdev->dev, "failled initializing CP (%d).\n", r); |
| 410 | return r; |
| 411 | } |
| 412 | r = r100_wb_init(rdev); |
| 413 | if (r) |
| 414 | dev_err(rdev->dev, "failled initializing WB (%d).\n", r); |
| 415 | r = r100_ib_init(rdev); |
| 416 | if (r) { |
| 417 | dev_err(rdev->dev, "failled initializing IB (%d).\n", r); |
| 418 | return r; |
| 419 | } |
| 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | int rs600_resume(struct radeon_device *rdev) |
| 424 | { |
| 425 | /* Make sur GART are not working */ |
| 426 | rs600_gart_disable(rdev); |
| 427 | /* Resume clock before doing reset */ |
| 428 | rv515_clock_startup(rdev); |
| 429 | /* Reset gpu before posting otherwise ATOM will enter infinite loop */ |
| 430 | if (radeon_gpu_reset(rdev)) { |
| 431 | dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n", |
| 432 | RREG32(R_000E40_RBBM_STATUS), |
| 433 | RREG32(R_0007C0_CP_STAT)); |
| 434 | } |
| 435 | /* post */ |
| 436 | atom_asic_init(rdev->mode_info.atom_context); |
| 437 | /* Resume clock after posting */ |
| 438 | rv515_clock_startup(rdev); |
| 439 | return rs600_startup(rdev); |
| 440 | } |
| 441 | |
| 442 | int rs600_suspend(struct radeon_device *rdev) |
| 443 | { |
| 444 | r100_cp_disable(rdev); |
| 445 | r100_wb_disable(rdev); |
Jerome Glisse | ac447df | 2009-09-30 22:18:43 +0200 | [diff] [blame] | 446 | rs600_irq_disable(rdev); |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 447 | rs600_gart_disable(rdev); |
| 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | void rs600_fini(struct radeon_device *rdev) |
| 452 | { |
| 453 | rs600_suspend(rdev); |
| 454 | r100_cp_fini(rdev); |
| 455 | r100_wb_fini(rdev); |
| 456 | r100_ib_fini(rdev); |
| 457 | radeon_gem_fini(rdev); |
| 458 | rs600_gart_fini(rdev); |
| 459 | radeon_irq_kms_fini(rdev); |
| 460 | radeon_fence_driver_fini(rdev); |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 461 | radeon_bo_fini(rdev); |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 462 | radeon_atombios_fini(rdev); |
| 463 | kfree(rdev->bios); |
| 464 | rdev->bios = NULL; |
| 465 | } |
| 466 | |
Jerome Glisse | 3bc6853 | 2009-10-01 09:39:24 +0200 | [diff] [blame] | 467 | int rs600_init(struct radeon_device *rdev) |
| 468 | { |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 469 | int r; |
| 470 | |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 471 | /* Disable VGA */ |
| 472 | rv515_vga_render_disable(rdev); |
| 473 | /* Initialize scratch registers */ |
| 474 | radeon_scratch_init(rdev); |
| 475 | /* Initialize surface registers */ |
| 476 | radeon_surface_init(rdev); |
| 477 | /* BIOS */ |
| 478 | if (!radeon_get_bios(rdev)) { |
| 479 | if (ASIC_IS_AVIVO(rdev)) |
| 480 | return -EINVAL; |
| 481 | } |
| 482 | if (rdev->is_atom_bios) { |
| 483 | r = radeon_atombios_init(rdev); |
| 484 | if (r) |
| 485 | return r; |
| 486 | } else { |
| 487 | dev_err(rdev->dev, "Expecting atombios for RS600 GPU\n"); |
| 488 | return -EINVAL; |
| 489 | } |
| 490 | /* Reset gpu before posting otherwise ATOM will enter infinite loop */ |
| 491 | if (radeon_gpu_reset(rdev)) { |
| 492 | dev_warn(rdev->dev, |
| 493 | "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n", |
| 494 | RREG32(R_000E40_RBBM_STATUS), |
| 495 | RREG32(R_0007C0_CP_STAT)); |
| 496 | } |
| 497 | /* check if cards are posted or not */ |
Dave Airlie | 72542d7 | 2009-12-01 14:06:31 +1000 | [diff] [blame] | 498 | if (radeon_boot_test_post_card(rdev) == false) |
| 499 | return -EINVAL; |
| 500 | |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 501 | /* Initialize clocks */ |
| 502 | radeon_get_clock_info(rdev->ddev); |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 503 | /* Initialize power management */ |
| 504 | radeon_pm_init(rdev); |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 505 | /* Get vram informations */ |
| 506 | rs600_vram_info(rdev); |
| 507 | /* Initialize memory controller (also test AGP) */ |
| 508 | r = r420_mc_init(rdev); |
| 509 | if (r) |
| 510 | return r; |
| 511 | rs600_debugfs(rdev); |
| 512 | /* Fence driver */ |
| 513 | r = radeon_fence_driver_init(rdev); |
| 514 | if (r) |
| 515 | return r; |
| 516 | r = radeon_irq_kms_init(rdev); |
| 517 | if (r) |
| 518 | return r; |
| 519 | /* Memory manager */ |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 520 | r = radeon_bo_init(rdev); |
Jerome Glisse | c010f80 | 2009-09-30 22:09:06 +0200 | [diff] [blame] | 521 | if (r) |
| 522 | return r; |
| 523 | r = rs600_gart_init(rdev); |
| 524 | if (r) |
| 525 | return r; |
| 526 | rs600_set_safe_registers(rdev); |
| 527 | rdev->accel_working = true; |
| 528 | r = rs600_startup(rdev); |
| 529 | if (r) { |
| 530 | /* Somethings want wront with the accel init stop accel */ |
| 531 | dev_err(rdev->dev, "Disabling GPU acceleration\n"); |
| 532 | rs600_suspend(rdev); |
| 533 | r100_cp_fini(rdev); |
| 534 | r100_wb_fini(rdev); |
| 535 | r100_ib_fini(rdev); |
| 536 | rs600_gart_fini(rdev); |
| 537 | radeon_irq_kms_fini(rdev); |
| 538 | rdev->accel_working = false; |
| 539 | } |
Dave Airlie | 3f7dc91a | 2009-08-27 11:10:15 +1000 | [diff] [blame] | 540 | return 0; |
| 541 | } |