Dave Airlie | f26c473 | 2006-01-02 17:18:39 +1100 | [diff] [blame] | 1 | /* radeon_cp.c -- CP support for Radeon -*- linux-c -*- */ |
| 2 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas. |
| 4 | * Copyright 2000 VA Linux Systems, Inc., Fremont, California. |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 5 | * Copyright 2007 Advanced Micro Devices, Inc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * All Rights Reserved. |
| 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 9 | * copy of this software and associated documentation files (the "Software"), |
| 10 | * to deal in the Software without restriction, including without limitation |
| 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 12 | * and/or sell copies of the Software, and to permit persons to whom the |
| 13 | * Software is furnished to do so, subject to the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice (including the next |
| 16 | * paragraph) shall be included in all copies or substantial portions of the |
| 17 | * Software. |
| 18 | * |
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 22 | * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 23 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 24 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 25 | * DEALINGS IN THE SOFTWARE. |
| 26 | * |
| 27 | * Authors: |
| 28 | * Kevin E. Martin <martin@valinux.com> |
| 29 | * Gareth Hughes <gareth@valinux.com> |
| 30 | */ |
| 31 | |
Paul Gortmaker | e0cd360 | 2011-08-30 11:04:30 -0400 | [diff] [blame] | 32 | #include <linux/module.h> |
| 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include "drmP.h" |
| 35 | #include "drm.h" |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 36 | #include "drm_sarea.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include "radeon_drm.h" |
| 38 | #include "radeon_drv.h" |
Dave Airlie | 414ed53 | 2005-08-16 20:43:16 +1000 | [diff] [blame] | 39 | #include "r300_reg.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | #define RADEON_FIFO_DEBUG 0 |
| 42 | |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 43 | /* Firmware Names */ |
| 44 | #define FIRMWARE_R100 "radeon/R100_cp.bin" |
| 45 | #define FIRMWARE_R200 "radeon/R200_cp.bin" |
| 46 | #define FIRMWARE_R300 "radeon/R300_cp.bin" |
| 47 | #define FIRMWARE_R420 "radeon/R420_cp.bin" |
| 48 | #define FIRMWARE_RS690 "radeon/RS690_cp.bin" |
| 49 | #define FIRMWARE_RS600 "radeon/RS600_cp.bin" |
| 50 | #define FIRMWARE_R520 "radeon/R520_cp.bin" |
| 51 | |
| 52 | MODULE_FIRMWARE(FIRMWARE_R100); |
| 53 | MODULE_FIRMWARE(FIRMWARE_R200); |
| 54 | MODULE_FIRMWARE(FIRMWARE_R300); |
| 55 | MODULE_FIRMWARE(FIRMWARE_R420); |
| 56 | MODULE_FIRMWARE(FIRMWARE_RS690); |
| 57 | MODULE_FIRMWARE(FIRMWARE_RS600); |
| 58 | MODULE_FIRMWARE(FIRMWARE_R520); |
| 59 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 60 | static int radeon_do_cleanup_cp(struct drm_device * dev); |
Jerome Glisse | 54f961a | 2008-08-13 09:46:31 +1000 | [diff] [blame] | 61 | static void radeon_do_cp_start(drm_radeon_private_t * dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 63 | u32 radeon_read_ring_rptr(drm_radeon_private_t *dev_priv, u32 off) |
David Miller | b07fa02 | 2009-02-12 02:15:37 -0800 | [diff] [blame] | 64 | { |
| 65 | u32 val; |
| 66 | |
| 67 | if (dev_priv->flags & RADEON_IS_AGP) { |
| 68 | val = DRM_READ32(dev_priv->ring_rptr, off); |
| 69 | } else { |
| 70 | val = *(((volatile u32 *) |
| 71 | dev_priv->ring_rptr->handle) + |
| 72 | (off / sizeof(u32))); |
| 73 | val = le32_to_cpu(val); |
| 74 | } |
| 75 | return val; |
| 76 | } |
| 77 | |
| 78 | u32 radeon_get_ring_head(drm_radeon_private_t *dev_priv) |
| 79 | { |
| 80 | if (dev_priv->writeback_works) |
| 81 | return radeon_read_ring_rptr(dev_priv, 0); |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 82 | else { |
| 83 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) |
| 84 | return RADEON_READ(R600_CP_RB_RPTR); |
| 85 | else |
| 86 | return RADEON_READ(RADEON_CP_RB_RPTR); |
| 87 | } |
David Miller | b07fa02 | 2009-02-12 02:15:37 -0800 | [diff] [blame] | 88 | } |
| 89 | |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 90 | void radeon_write_ring_rptr(drm_radeon_private_t *dev_priv, u32 off, u32 val) |
David Miller | b07fa02 | 2009-02-12 02:15:37 -0800 | [diff] [blame] | 91 | { |
| 92 | if (dev_priv->flags & RADEON_IS_AGP) |
| 93 | DRM_WRITE32(dev_priv->ring_rptr, off, val); |
| 94 | else |
| 95 | *(((volatile u32 *) dev_priv->ring_rptr->handle) + |
| 96 | (off / sizeof(u32))) = cpu_to_le32(val); |
| 97 | } |
| 98 | |
| 99 | void radeon_set_ring_head(drm_radeon_private_t *dev_priv, u32 val) |
| 100 | { |
| 101 | radeon_write_ring_rptr(dev_priv, 0, val); |
| 102 | } |
| 103 | |
| 104 | u32 radeon_get_scratch(drm_radeon_private_t *dev_priv, int index) |
| 105 | { |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 106 | if (dev_priv->writeback_works) { |
| 107 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) |
| 108 | return radeon_read_ring_rptr(dev_priv, |
| 109 | R600_SCRATCHOFF(index)); |
| 110 | else |
| 111 | return radeon_read_ring_rptr(dev_priv, |
| 112 | RADEON_SCRATCHOFF(index)); |
| 113 | } else { |
| 114 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) |
| 115 | return RADEON_READ(R600_SCRATCH_REG0 + 4*index); |
| 116 | else |
| 117 | return RADEON_READ(RADEON_SCRATCH_REG0 + 4*index); |
| 118 | } |
David Miller | b07fa02 | 2009-02-12 02:15:37 -0800 | [diff] [blame] | 119 | } |
| 120 | |
Alex Deucher | befb73c | 2009-02-24 14:02:13 -0500 | [diff] [blame] | 121 | u32 RADEON_READ_MM(drm_radeon_private_t *dev_priv, int addr) |
| 122 | { |
| 123 | u32 ret; |
| 124 | |
| 125 | if (addr < 0x10000) |
| 126 | ret = DRM_READ32(dev_priv->mmio, addr); |
| 127 | else { |
| 128 | DRM_WRITE32(dev_priv->mmio, RADEON_MM_INDEX, addr); |
| 129 | ret = DRM_READ32(dev_priv->mmio, RADEON_MM_DATA); |
| 130 | } |
| 131 | |
| 132 | return ret; |
| 133 | } |
| 134 | |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 135 | static u32 R500_READ_MCIND(drm_radeon_private_t *dev_priv, int addr) |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 136 | { |
| 137 | u32 ret; |
| 138 | RADEON_WRITE(R520_MC_IND_INDEX, 0x7f0000 | (addr & 0xff)); |
| 139 | ret = RADEON_READ(R520_MC_IND_DATA); |
| 140 | RADEON_WRITE(R520_MC_IND_INDEX, 0); |
| 141 | return ret; |
| 142 | } |
| 143 | |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 144 | static u32 RS480_READ_MCIND(drm_radeon_private_t *dev_priv, int addr) |
| 145 | { |
| 146 | u32 ret; |
| 147 | RADEON_WRITE(RS480_NB_MC_INDEX, addr & 0xff); |
| 148 | ret = RADEON_READ(RS480_NB_MC_DATA); |
| 149 | RADEON_WRITE(RS480_NB_MC_INDEX, 0xff); |
| 150 | return ret; |
| 151 | } |
| 152 | |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 153 | static u32 RS690_READ_MCIND(drm_radeon_private_t *dev_priv, int addr) |
| 154 | { |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 155 | u32 ret; |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 156 | RADEON_WRITE(RS690_MC_INDEX, (addr & RS690_MC_INDEX_MASK)); |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 157 | ret = RADEON_READ(RS690_MC_DATA); |
| 158 | RADEON_WRITE(RS690_MC_INDEX, RS690_MC_INDEX_MASK); |
| 159 | return ret; |
| 160 | } |
| 161 | |
Alex Deucher | c1556f7 | 2009-02-25 16:57:49 -0500 | [diff] [blame] | 162 | static u32 RS600_READ_MCIND(drm_radeon_private_t *dev_priv, int addr) |
| 163 | { |
| 164 | u32 ret; |
| 165 | RADEON_WRITE(RS600_MC_INDEX, ((addr & RS600_MC_ADDR_MASK) | |
| 166 | RS600_MC_IND_CITF_ARB0)); |
| 167 | ret = RADEON_READ(RS600_MC_DATA); |
| 168 | return ret; |
| 169 | } |
| 170 | |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 171 | static u32 IGP_READ_MCIND(drm_radeon_private_t *dev_priv, int addr) |
| 172 | { |
Alex Deucher | f0738e9 | 2008-10-16 17:12:02 +1000 | [diff] [blame] | 173 | if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690) || |
| 174 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS740)) |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 175 | return RS690_READ_MCIND(dev_priv, addr); |
Alex Deucher | c1556f7 | 2009-02-25 16:57:49 -0500 | [diff] [blame] | 176 | else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS600) |
| 177 | return RS600_READ_MCIND(dev_priv, addr); |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 178 | else |
| 179 | return RS480_READ_MCIND(dev_priv, addr); |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 180 | } |
| 181 | |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 182 | u32 radeon_read_fb_location(drm_radeon_private_t *dev_priv) |
| 183 | { |
| 184 | |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 185 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RV770) |
| 186 | return RADEON_READ(R700_MC_VM_FB_LOCATION); |
| 187 | else if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) |
| 188 | return RADEON_READ(R600_MC_VM_FB_LOCATION); |
| 189 | else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV515) |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 190 | return R500_READ_MCIND(dev_priv, RV515_MC_FB_LOCATION); |
Alex Deucher | f0738e9 | 2008-10-16 17:12:02 +1000 | [diff] [blame] | 191 | else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690) || |
| 192 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS740)) |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 193 | return RS690_READ_MCIND(dev_priv, RS690_MC_FB_LOCATION); |
Alex Deucher | c1556f7 | 2009-02-25 16:57:49 -0500 | [diff] [blame] | 194 | else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS600) |
| 195 | return RS600_READ_MCIND(dev_priv, RS600_MC_FB_LOCATION); |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 196 | else if ((dev_priv->flags & RADEON_FAMILY_MASK) > CHIP_RV515) |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 197 | return R500_READ_MCIND(dev_priv, R520_MC_FB_LOCATION); |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 198 | else |
| 199 | return RADEON_READ(RADEON_MC_FB_LOCATION); |
| 200 | } |
| 201 | |
| 202 | static void radeon_write_fb_location(drm_radeon_private_t *dev_priv, u32 fb_loc) |
| 203 | { |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 204 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RV770) |
| 205 | RADEON_WRITE(R700_MC_VM_FB_LOCATION, fb_loc); |
| 206 | else if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) |
| 207 | RADEON_WRITE(R600_MC_VM_FB_LOCATION, fb_loc); |
| 208 | else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV515) |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 209 | R500_WRITE_MCIND(RV515_MC_FB_LOCATION, fb_loc); |
Alex Deucher | f0738e9 | 2008-10-16 17:12:02 +1000 | [diff] [blame] | 210 | else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690) || |
| 211 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS740)) |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 212 | RS690_WRITE_MCIND(RS690_MC_FB_LOCATION, fb_loc); |
Alex Deucher | c1556f7 | 2009-02-25 16:57:49 -0500 | [diff] [blame] | 213 | else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS600) |
| 214 | RS600_WRITE_MCIND(RS600_MC_FB_LOCATION, fb_loc); |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 215 | else if ((dev_priv->flags & RADEON_FAMILY_MASK) > CHIP_RV515) |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 216 | R500_WRITE_MCIND(R520_MC_FB_LOCATION, fb_loc); |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 217 | else |
| 218 | RADEON_WRITE(RADEON_MC_FB_LOCATION, fb_loc); |
| 219 | } |
| 220 | |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 221 | void radeon_write_agp_location(drm_radeon_private_t *dev_priv, u32 agp_loc) |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 222 | { |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 223 | /*R6xx/R7xx: AGP_TOP and BOT are actually 18 bits each */ |
| 224 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RV770) { |
| 225 | RADEON_WRITE(R700_MC_VM_AGP_BOT, agp_loc & 0xffff); /* FIX ME */ |
| 226 | RADEON_WRITE(R700_MC_VM_AGP_TOP, (agp_loc >> 16) & 0xffff); |
| 227 | } else if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) { |
| 228 | RADEON_WRITE(R600_MC_VM_AGP_BOT, agp_loc & 0xffff); /* FIX ME */ |
| 229 | RADEON_WRITE(R600_MC_VM_AGP_TOP, (agp_loc >> 16) & 0xffff); |
| 230 | } else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV515) |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 231 | R500_WRITE_MCIND(RV515_MC_AGP_LOCATION, agp_loc); |
Alex Deucher | f0738e9 | 2008-10-16 17:12:02 +1000 | [diff] [blame] | 232 | else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690) || |
| 233 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS740)) |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 234 | RS690_WRITE_MCIND(RS690_MC_AGP_LOCATION, agp_loc); |
Alex Deucher | c1556f7 | 2009-02-25 16:57:49 -0500 | [diff] [blame] | 235 | else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS600) |
| 236 | RS600_WRITE_MCIND(RS600_MC_AGP_LOCATION, agp_loc); |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 237 | else if ((dev_priv->flags & RADEON_FAMILY_MASK) > CHIP_RV515) |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 238 | R500_WRITE_MCIND(R520_MC_AGP_LOCATION, agp_loc); |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 239 | else |
| 240 | RADEON_WRITE(RADEON_MC_AGP_LOCATION, agp_loc); |
| 241 | } |
| 242 | |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 243 | void radeon_write_agp_base(drm_radeon_private_t *dev_priv, u64 agp_base) |
Dave Airlie | 70b13d5 | 2008-06-19 11:40:44 +1000 | [diff] [blame] | 244 | { |
| 245 | u32 agp_base_hi = upper_32_bits(agp_base); |
| 246 | u32 agp_base_lo = agp_base & 0xffffffff; |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 247 | u32 r6xx_agp_base = (agp_base >> 22) & 0x3ffff; |
Dave Airlie | 70b13d5 | 2008-06-19 11:40:44 +1000 | [diff] [blame] | 248 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 249 | /* R6xx/R7xx must be aligned to a 4MB boundary */ |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 250 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RV770) |
| 251 | RADEON_WRITE(R700_MC_VM_AGP_BASE, r6xx_agp_base); |
| 252 | else if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) |
| 253 | RADEON_WRITE(R600_MC_VM_AGP_BASE, r6xx_agp_base); |
| 254 | else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV515) { |
Dave Airlie | 70b13d5 | 2008-06-19 11:40:44 +1000 | [diff] [blame] | 255 | R500_WRITE_MCIND(RV515_MC_AGP_BASE, agp_base_lo); |
| 256 | R500_WRITE_MCIND(RV515_MC_AGP_BASE_2, agp_base_hi); |
Alex Deucher | f0738e9 | 2008-10-16 17:12:02 +1000 | [diff] [blame] | 257 | } else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690) || |
| 258 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS740)) { |
Dave Airlie | 70b13d5 | 2008-06-19 11:40:44 +1000 | [diff] [blame] | 259 | RS690_WRITE_MCIND(RS690_MC_AGP_BASE, agp_base_lo); |
| 260 | RS690_WRITE_MCIND(RS690_MC_AGP_BASE_2, agp_base_hi); |
Alex Deucher | c1556f7 | 2009-02-25 16:57:49 -0500 | [diff] [blame] | 261 | } else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS600) { |
| 262 | RS600_WRITE_MCIND(RS600_AGP_BASE, agp_base_lo); |
| 263 | RS600_WRITE_MCIND(RS600_AGP_BASE_2, agp_base_hi); |
Dave Airlie | 70b13d5 | 2008-06-19 11:40:44 +1000 | [diff] [blame] | 264 | } else if ((dev_priv->flags & RADEON_FAMILY_MASK) > CHIP_RV515) { |
| 265 | R500_WRITE_MCIND(R520_MC_AGP_BASE, agp_base_lo); |
| 266 | R500_WRITE_MCIND(R520_MC_AGP_BASE_2, agp_base_hi); |
Alex Deucher | b2ceddf | 2008-10-17 09:19:33 +1000 | [diff] [blame] | 267 | } else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS400) || |
| 268 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS480)) { |
Alex Deucher | 5cfb695 | 2008-06-19 12:38:29 +1000 | [diff] [blame] | 269 | RADEON_WRITE(RADEON_AGP_BASE, agp_base_lo); |
Alex Deucher | b2ceddf | 2008-10-17 09:19:33 +1000 | [diff] [blame] | 270 | RADEON_WRITE(RS480_AGP_BASE_2, agp_base_hi); |
Dave Airlie | 70b13d5 | 2008-06-19 11:40:44 +1000 | [diff] [blame] | 271 | } else { |
| 272 | RADEON_WRITE(RADEON_AGP_BASE, agp_base_lo); |
| 273 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R200) |
| 274 | RADEON_WRITE(RADEON_AGP_BASE_2, agp_base_hi); |
| 275 | } |
| 276 | } |
| 277 | |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 278 | void radeon_enable_bm(struct drm_radeon_private *dev_priv) |
Dave Airlie | dd8d7cb | 2009-02-20 13:28:59 +1000 | [diff] [blame] | 279 | { |
| 280 | u32 tmp; |
| 281 | /* Turn on bus mastering */ |
| 282 | if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690) || |
| 283 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS740)) { |
| 284 | /* rs600/rs690/rs740 */ |
| 285 | tmp = RADEON_READ(RADEON_BUS_CNTL) & ~RS600_BUS_MASTER_DIS; |
| 286 | RADEON_WRITE(RADEON_BUS_CNTL, tmp); |
| 287 | } else if (((dev_priv->flags & RADEON_FAMILY_MASK) <= CHIP_RV350) || |
| 288 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R420) || |
| 289 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS400) || |
| 290 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS480)) { |
| 291 | /* r1xx, r2xx, r300, r(v)350, r420/r481, rs400/rs480 */ |
| 292 | tmp = RADEON_READ(RADEON_BUS_CNTL) & ~RADEON_BUS_MASTER_DIS; |
| 293 | RADEON_WRITE(RADEON_BUS_CNTL, tmp); |
| 294 | } /* PCIE cards appears to not need this */ |
| 295 | } |
| 296 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 297 | static int RADEON_READ_PLL(struct drm_device * dev, int addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | { |
| 299 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 300 | |
| 301 | RADEON_WRITE8(RADEON_CLOCK_CNTL_INDEX, addr & 0x1f); |
| 302 | return RADEON_READ(RADEON_CLOCK_CNTL_DATA); |
| 303 | } |
| 304 | |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 305 | static u32 RADEON_READ_PCIE(drm_radeon_private_t *dev_priv, int addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | { |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 307 | RADEON_WRITE8(RADEON_PCIE_INDEX, addr & 0xff); |
| 308 | return RADEON_READ(RADEON_PCIE_DATA); |
| 309 | } |
| 310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | #if RADEON_FIFO_DEBUG |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 312 | static void radeon_status(drm_radeon_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | { |
Harvey Harrison | bf9d892 | 2008-04-30 00:55:10 -0700 | [diff] [blame] | 314 | printk("%s:\n", __func__); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 315 | printk("RBBM_STATUS = 0x%08x\n", |
| 316 | (unsigned int)RADEON_READ(RADEON_RBBM_STATUS)); |
| 317 | printk("CP_RB_RTPR = 0x%08x\n", |
| 318 | (unsigned int)RADEON_READ(RADEON_CP_RB_RPTR)); |
| 319 | printk("CP_RB_WTPR = 0x%08x\n", |
| 320 | (unsigned int)RADEON_READ(RADEON_CP_RB_WPTR)); |
| 321 | printk("AIC_CNTL = 0x%08x\n", |
| 322 | (unsigned int)RADEON_READ(RADEON_AIC_CNTL)); |
| 323 | printk("AIC_STAT = 0x%08x\n", |
| 324 | (unsigned int)RADEON_READ(RADEON_AIC_STAT)); |
| 325 | printk("AIC_PT_BASE = 0x%08x\n", |
| 326 | (unsigned int)RADEON_READ(RADEON_AIC_PT_BASE)); |
| 327 | printk("TLB_ADDR = 0x%08x\n", |
| 328 | (unsigned int)RADEON_READ(RADEON_AIC_TLB_ADDR)); |
| 329 | printk("TLB_DATA = 0x%08x\n", |
| 330 | (unsigned int)RADEON_READ(RADEON_AIC_TLB_DATA)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | } |
| 332 | #endif |
| 333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | /* ================================================================ |
| 335 | * Engine, FIFO control |
| 336 | */ |
| 337 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 338 | static int radeon_do_pixcache_flush(drm_radeon_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | { |
| 340 | u32 tmp; |
| 341 | int i; |
| 342 | |
| 343 | dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE; |
| 344 | |
Alex Deucher | 259434a | 2008-05-28 11:51:12 +1000 | [diff] [blame] | 345 | if ((dev_priv->flags & RADEON_FAMILY_MASK) <= CHIP_RV280) { |
| 346 | tmp = RADEON_READ(RADEON_RB3D_DSTCACHE_CTLSTAT); |
| 347 | tmp |= RADEON_RB3D_DC_FLUSH_ALL; |
| 348 | RADEON_WRITE(RADEON_RB3D_DSTCACHE_CTLSTAT, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
Alex Deucher | 259434a | 2008-05-28 11:51:12 +1000 | [diff] [blame] | 350 | for (i = 0; i < dev_priv->usec_timeout; i++) { |
| 351 | if (!(RADEON_READ(RADEON_RB3D_DSTCACHE_CTLSTAT) |
| 352 | & RADEON_RB3D_DC_BUSY)) { |
| 353 | return 0; |
| 354 | } |
| 355 | DRM_UDELAY(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | } |
Alex Deucher | 259434a | 2008-05-28 11:51:12 +1000 | [diff] [blame] | 357 | } else { |
Jerome Glisse | 54f961a | 2008-08-13 09:46:31 +1000 | [diff] [blame] | 358 | /* don't flush or purge cache here or lockup */ |
| 359 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | #if RADEON_FIFO_DEBUG |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 363 | DRM_ERROR("failed!\n"); |
| 364 | radeon_status(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | #endif |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 366 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 369 | static int radeon_do_wait_for_fifo(drm_radeon_private_t * dev_priv, int entries) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | { |
| 371 | int i; |
| 372 | |
| 373 | dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE; |
| 374 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 375 | for (i = 0; i < dev_priv->usec_timeout; i++) { |
| 376 | int slots = (RADEON_READ(RADEON_RBBM_STATUS) |
| 377 | & RADEON_RBBM_FIFOCNT_MASK); |
| 378 | if (slots >= entries) |
| 379 | return 0; |
| 380 | DRM_UDELAY(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | } |
Dave Airlie | 6c7be29 | 2008-09-01 08:51:52 +1000 | [diff] [blame] | 382 | DRM_DEBUG("wait for fifo failed status : 0x%08X 0x%08X\n", |
Jerome Glisse | 54f961a | 2008-08-13 09:46:31 +1000 | [diff] [blame] | 383 | RADEON_READ(RADEON_RBBM_STATUS), |
| 384 | RADEON_READ(R300_VAP_CNTL_STATUS)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
| 386 | #if RADEON_FIFO_DEBUG |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 387 | DRM_ERROR("failed!\n"); |
| 388 | radeon_status(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | #endif |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 390 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 393 | static int radeon_do_wait_for_idle(drm_radeon_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | { |
| 395 | int i, ret; |
| 396 | |
| 397 | dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE; |
| 398 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 399 | ret = radeon_do_wait_for_fifo(dev_priv, 64); |
| 400 | if (ret) |
| 401 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 403 | for (i = 0; i < dev_priv->usec_timeout; i++) { |
| 404 | if (!(RADEON_READ(RADEON_RBBM_STATUS) |
| 405 | & RADEON_RBBM_ACTIVE)) { |
| 406 | radeon_do_pixcache_flush(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | return 0; |
| 408 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 409 | DRM_UDELAY(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | } |
Dave Airlie | 6c7be29 | 2008-09-01 08:51:52 +1000 | [diff] [blame] | 411 | DRM_DEBUG("wait idle failed status : 0x%08X 0x%08X\n", |
Jerome Glisse | 54f961a | 2008-08-13 09:46:31 +1000 | [diff] [blame] | 412 | RADEON_READ(RADEON_RBBM_STATUS), |
| 413 | RADEON_READ(R300_VAP_CNTL_STATUS)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
| 415 | #if RADEON_FIFO_DEBUG |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 416 | DRM_ERROR("failed!\n"); |
| 417 | radeon_status(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | #endif |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 419 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Michel Dänzer | 57b54ea | 2010-04-02 16:59:06 +0000 | [diff] [blame] | 422 | static void radeon_init_pipes(struct drm_device *dev) |
Alex Deucher | 5b92c40 | 2008-05-28 11:57:40 +1000 | [diff] [blame] | 423 | { |
Michel Dänzer | 57b54ea | 2010-04-02 16:59:06 +0000 | [diff] [blame] | 424 | drm_radeon_private_t *dev_priv = dev->dev_private; |
Alex Deucher | 5b92c40 | 2008-05-28 11:57:40 +1000 | [diff] [blame] | 425 | uint32_t gb_tile_config, gb_pipe_sel = 0; |
| 426 | |
Alex Deucher | f779b3e | 2009-08-19 19:11:39 -0400 | [diff] [blame] | 427 | if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV530) { |
| 428 | uint32_t z_pipe_sel = RADEON_READ(RV530_GB_PIPE_SELECT2); |
| 429 | if ((z_pipe_sel & 3) == 3) |
| 430 | dev_priv->num_z_pipes = 2; |
| 431 | else |
| 432 | dev_priv->num_z_pipes = 1; |
| 433 | } else |
| 434 | dev_priv->num_z_pipes = 1; |
| 435 | |
Alex Deucher | 5b92c40 | 2008-05-28 11:57:40 +1000 | [diff] [blame] | 436 | /* RS4xx/RS6xx/R4xx/R5xx */ |
| 437 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R420) { |
| 438 | gb_pipe_sel = RADEON_READ(R400_GB_PIPE_SELECT); |
| 439 | dev_priv->num_gb_pipes = ((gb_pipe_sel >> 12) & 0x3) + 1; |
Tormod Volden | 94f7bf6 | 2010-04-22 16:57:32 -0400 | [diff] [blame] | 440 | /* SE cards have 1 pipe */ |
| 441 | if ((dev->pdev->device == 0x5e4c) || |
| 442 | (dev->pdev->device == 0x5e4f)) |
| 443 | dev_priv->num_gb_pipes = 1; |
Alex Deucher | 5b92c40 | 2008-05-28 11:57:40 +1000 | [diff] [blame] | 444 | } else { |
| 445 | /* R3xx */ |
Michel Dänzer | 57b54ea | 2010-04-02 16:59:06 +0000 | [diff] [blame] | 446 | if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R300 && |
| 447 | dev->pdev->device != 0x4144) || |
Tormod Volden | 94f7bf6 | 2010-04-22 16:57:32 -0400 | [diff] [blame] | 448 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R350 && |
| 449 | dev->pdev->device != 0x4148)) { |
Alex Deucher | 5b92c40 | 2008-05-28 11:57:40 +1000 | [diff] [blame] | 450 | dev_priv->num_gb_pipes = 2; |
| 451 | } else { |
Tormod Volden | 94f7bf6 | 2010-04-22 16:57:32 -0400 | [diff] [blame] | 452 | /* RV3xx/R300 AD/R350 AH */ |
Alex Deucher | 5b92c40 | 2008-05-28 11:57:40 +1000 | [diff] [blame] | 453 | dev_priv->num_gb_pipes = 1; |
| 454 | } |
| 455 | } |
| 456 | DRM_INFO("Num pipes: %d\n", dev_priv->num_gb_pipes); |
| 457 | |
| 458 | gb_tile_config = (R300_ENABLE_TILING | R300_TILE_SIZE_16 /*| R300_SUBPIXEL_1_16*/); |
| 459 | |
| 460 | switch (dev_priv->num_gb_pipes) { |
| 461 | case 2: gb_tile_config |= R300_PIPE_COUNT_R300; break; |
| 462 | case 3: gb_tile_config |= R300_PIPE_COUNT_R420_3P; break; |
| 463 | case 4: gb_tile_config |= R300_PIPE_COUNT_R420; break; |
| 464 | default: |
| 465 | case 1: gb_tile_config |= R300_PIPE_COUNT_RV350; break; |
| 466 | } |
| 467 | |
| 468 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RV515) { |
| 469 | RADEON_WRITE_PLL(R500_DYN_SCLK_PWMEM_PIPE, (1 | ((gb_pipe_sel >> 8) & 0xf) << 4)); |
Maciej Cencora | af7ae35 | 2009-03-24 01:48:50 +0100 | [diff] [blame] | 470 | RADEON_WRITE(R300_SU_REG_DEST, ((1 << dev_priv->num_gb_pipes) - 1)); |
Alex Deucher | 5b92c40 | 2008-05-28 11:57:40 +1000 | [diff] [blame] | 471 | } |
| 472 | RADEON_WRITE(R300_GB_TILE_CONFIG, gb_tile_config); |
| 473 | radeon_do_wait_for_idle(dev_priv); |
| 474 | RADEON_WRITE(R300_DST_PIPE_CONFIG, RADEON_READ(R300_DST_PIPE_CONFIG) | R300_PIPE_AUTO_CONFIG); |
| 475 | RADEON_WRITE(R300_RB2D_DSTCACHE_MODE, (RADEON_READ(R300_RB2D_DSTCACHE_MODE) | |
| 476 | R300_DC_AUTOFLUSH_ENABLE | |
| 477 | R300_DC_DC_DISABLE_IGNORE_PE)); |
| 478 | |
| 479 | |
| 480 | } |
| 481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | /* ================================================================ |
| 483 | * CP control, initialization |
| 484 | */ |
| 485 | |
| 486 | /* Load the microcode for the CP */ |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 487 | static int radeon_cp_init_microcode(drm_radeon_private_t *dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | { |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 489 | struct platform_device *pdev; |
| 490 | const char *fw_name = NULL; |
| 491 | int err; |
| 492 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 493 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 495 | pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0); |
| 496 | err = IS_ERR(pdev); |
| 497 | if (err) { |
| 498 | printk(KERN_ERR "radeon_cp: Failed to register firmware\n"); |
| 499 | return -EINVAL; |
| 500 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
Alex Deucher | 9f18409 | 2008-05-28 11:21:25 +1000 | [diff] [blame] | 502 | if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R100) || |
| 503 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV100) || |
| 504 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV200) || |
| 505 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS100) || |
| 506 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS200)) { |
| 507 | DRM_INFO("Loading R100 Microcode\n"); |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 508 | fw_name = FIRMWARE_R100; |
Alex Deucher | 9f18409 | 2008-05-28 11:21:25 +1000 | [diff] [blame] | 509 | } else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R200) || |
| 510 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV250) || |
| 511 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV280) || |
| 512 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS300)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | DRM_INFO("Loading R200 Microcode\n"); |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 514 | fw_name = FIRMWARE_R200; |
Alex Deucher | 9f18409 | 2008-05-28 11:21:25 +1000 | [diff] [blame] | 515 | } else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R300) || |
| 516 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R350) || |
| 517 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV350) || |
| 518 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV380) || |
Alex Deucher | b2ceddf | 2008-10-17 09:19:33 +1000 | [diff] [blame] | 519 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS400) || |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 520 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS480)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | DRM_INFO("Loading R300 Microcode\n"); |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 522 | fw_name = FIRMWARE_R300; |
Alex Deucher | 9f18409 | 2008-05-28 11:21:25 +1000 | [diff] [blame] | 523 | } else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R420) || |
Alex Deucher | edc6f38 | 2008-10-17 09:21:45 +1000 | [diff] [blame] | 524 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R423) || |
Alex Deucher | 9f18409 | 2008-05-28 11:21:25 +1000 | [diff] [blame] | 525 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV410)) { |
| 526 | DRM_INFO("Loading R400 Microcode\n"); |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 527 | fw_name = FIRMWARE_R420; |
Alex Deucher | f0738e9 | 2008-10-16 17:12:02 +1000 | [diff] [blame] | 528 | } else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690) || |
| 529 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS740)) { |
| 530 | DRM_INFO("Loading RS690/RS740 Microcode\n"); |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 531 | fw_name = FIRMWARE_RS690; |
Alex Deucher | c1556f7 | 2009-02-25 16:57:49 -0500 | [diff] [blame] | 532 | } else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS600) { |
| 533 | DRM_INFO("Loading RS600 Microcode\n"); |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 534 | fw_name = FIRMWARE_RS600; |
Alex Deucher | 9f18409 | 2008-05-28 11:21:25 +1000 | [diff] [blame] | 535 | } else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV515) || |
| 536 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R520) || |
| 537 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV530) || |
| 538 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R580) || |
| 539 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV560) || |
| 540 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV570)) { |
| 541 | DRM_INFO("Loading R500 Microcode\n"); |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 542 | fw_name = FIRMWARE_R520; |
| 543 | } |
| 544 | |
| 545 | err = request_firmware(&dev_priv->me_fw, fw_name, &pdev->dev); |
| 546 | platform_device_unregister(pdev); |
| 547 | if (err) { |
| 548 | printk(KERN_ERR "radeon_cp: Failed to load firmware \"%s\"\n", |
| 549 | fw_name); |
| 550 | } else if (dev_priv->me_fw->size % 8) { |
| 551 | printk(KERN_ERR |
| 552 | "radeon_cp: Bogus length %zu in firmware \"%s\"\n", |
| 553 | dev_priv->me_fw->size, fw_name); |
| 554 | err = -EINVAL; |
| 555 | release_firmware(dev_priv->me_fw); |
| 556 | dev_priv->me_fw = NULL; |
| 557 | } |
| 558 | return err; |
| 559 | } |
| 560 | |
| 561 | static void radeon_cp_load_microcode(drm_radeon_private_t *dev_priv) |
| 562 | { |
| 563 | const __be32 *fw_data; |
| 564 | int i, size; |
| 565 | |
| 566 | radeon_do_wait_for_idle(dev_priv); |
| 567 | |
| 568 | if (dev_priv->me_fw) { |
| 569 | size = dev_priv->me_fw->size / 4; |
| 570 | fw_data = (const __be32 *)&dev_priv->me_fw->data[0]; |
| 571 | RADEON_WRITE(RADEON_CP_ME_RAM_ADDR, 0); |
| 572 | for (i = 0; i < size; i += 2) { |
Alex Deucher | 9f18409 | 2008-05-28 11:21:25 +1000 | [diff] [blame] | 573 | RADEON_WRITE(RADEON_CP_ME_RAM_DATAH, |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 574 | be32_to_cpup(&fw_data[i])); |
Alex Deucher | 9f18409 | 2008-05-28 11:21:25 +1000 | [diff] [blame] | 575 | RADEON_WRITE(RADEON_CP_ME_RAM_DATAL, |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 576 | be32_to_cpup(&fw_data[i + 1])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | } |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | /* Flush any pending commands to the CP. This should only be used just |
| 582 | * prior to a wait for idle, as it informs the engine that the command |
| 583 | * stream is ending. |
| 584 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 585 | static void radeon_do_cp_flush(drm_radeon_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 587 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | #if 0 |
| 589 | u32 tmp; |
| 590 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 591 | tmp = RADEON_READ(RADEON_CP_RB_WPTR) | (1 << 31); |
| 592 | RADEON_WRITE(RADEON_CP_RB_WPTR, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | #endif |
| 594 | } |
| 595 | |
| 596 | /* Wait for the CP to go idle. |
| 597 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 598 | int radeon_do_cp_idle(drm_radeon_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | { |
| 600 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 601 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 603 | BEGIN_RING(6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | |
| 605 | RADEON_PURGE_CACHE(); |
| 606 | RADEON_PURGE_ZCACHE(); |
| 607 | RADEON_WAIT_UNTIL_IDLE(); |
| 608 | |
| 609 | ADVANCE_RING(); |
| 610 | COMMIT_RING(); |
| 611 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 612 | return radeon_do_wait_for_idle(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | /* Start the Command Processor. |
| 616 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 617 | static void radeon_do_cp_start(drm_radeon_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | { |
| 619 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 620 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 622 | radeon_do_wait_for_idle(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 624 | RADEON_WRITE(RADEON_CP_CSQ_CNTL, dev_priv->cp_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
| 626 | dev_priv->cp_running = 1; |
| 627 | |
Alex Deucher | aadd4e1 | 2009-09-21 14:48:45 +1000 | [diff] [blame] | 628 | /* on r420, any DMA from CP to system memory while 2D is active |
| 629 | * can cause a hang. workaround is to queue a CP RESYNC token |
| 630 | */ |
| 631 | if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R420) { |
| 632 | BEGIN_RING(3); |
| 633 | OUT_RING(CP_PACKET0(R300_CP_RESYNC_ADDR, 1)); |
| 634 | OUT_RING(5); /* scratch reg 5 */ |
| 635 | OUT_RING(0xdeadbeef); |
| 636 | ADVANCE_RING(); |
| 637 | COMMIT_RING(); |
| 638 | } |
| 639 | |
Jerome Glisse | 54f961a | 2008-08-13 09:46:31 +1000 | [diff] [blame] | 640 | BEGIN_RING(8); |
| 641 | /* isync can only be written through cp on r5xx write it here */ |
| 642 | OUT_RING(CP_PACKET0(RADEON_ISYNC_CNTL, 0)); |
| 643 | OUT_RING(RADEON_ISYNC_ANY2D_IDLE3D | |
| 644 | RADEON_ISYNC_ANY3D_IDLE2D | |
| 645 | RADEON_ISYNC_WAIT_IDLEGUI | |
| 646 | RADEON_ISYNC_CPSCRATCH_IDLEGUI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | RADEON_PURGE_CACHE(); |
| 648 | RADEON_PURGE_ZCACHE(); |
| 649 | RADEON_WAIT_UNTIL_IDLE(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | ADVANCE_RING(); |
| 651 | COMMIT_RING(); |
Jerome Glisse | 54f961a | 2008-08-13 09:46:31 +1000 | [diff] [blame] | 652 | |
| 653 | dev_priv->track_flush |= RADEON_FLUSH_EMITED | RADEON_PURGE_EMITED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | /* Reset the Command Processor. This will not flush any pending |
| 657 | * commands, so you must wait for the CP command stream to complete |
| 658 | * before calling this routine. |
| 659 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 660 | static void radeon_do_cp_reset(drm_radeon_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | { |
| 662 | u32 cur_read_ptr; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 663 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 665 | cur_read_ptr = RADEON_READ(RADEON_CP_RB_RPTR); |
| 666 | RADEON_WRITE(RADEON_CP_RB_WPTR, cur_read_ptr); |
| 667 | SET_RING_HEAD(dev_priv, cur_read_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | dev_priv->ring.tail = cur_read_ptr; |
| 669 | } |
| 670 | |
| 671 | /* Stop the Command Processor. This will not flush any pending |
| 672 | * commands, so you must flush the command stream and wait for the CP |
| 673 | * to go idle before calling this routine. |
| 674 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 675 | static void radeon_do_cp_stop(drm_radeon_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | { |
Alex Deucher | aadd4e1 | 2009-09-21 14:48:45 +1000 | [diff] [blame] | 677 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 678 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | |
Alex Deucher | aadd4e1 | 2009-09-21 14:48:45 +1000 | [diff] [blame] | 680 | /* finish the pending CP_RESYNC token */ |
| 681 | if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R420) { |
| 682 | BEGIN_RING(2); |
| 683 | OUT_RING(CP_PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0)); |
| 684 | OUT_RING(R300_RB3D_DC_FINISH); |
| 685 | ADVANCE_RING(); |
| 686 | COMMIT_RING(); |
| 687 | radeon_do_wait_for_idle(dev_priv); |
| 688 | } |
| 689 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 690 | RADEON_WRITE(RADEON_CP_CSQ_CNTL, RADEON_CSQ_PRIDIS_INDDIS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | |
| 692 | dev_priv->cp_running = 0; |
| 693 | } |
| 694 | |
| 695 | /* Reset the engine. This will stop the CP if it is running. |
| 696 | */ |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 697 | static int radeon_do_engine_reset(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | { |
| 699 | drm_radeon_private_t *dev_priv = dev->dev_private; |
Alex Deucher | d396db3 | 2008-05-28 11:54:06 +1000 | [diff] [blame] | 700 | u32 clock_cntl_index = 0, mclk_cntl = 0, rbbm_soft_reset; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 701 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 703 | radeon_do_pixcache_flush(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | |
Alex Deucher | d396db3 | 2008-05-28 11:54:06 +1000 | [diff] [blame] | 705 | if ((dev_priv->flags & RADEON_FAMILY_MASK) <= CHIP_RV410) { |
| 706 | /* may need something similar for newer chips */ |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 707 | clock_cntl_index = RADEON_READ(RADEON_CLOCK_CNTL_INDEX); |
| 708 | mclk_cntl = RADEON_READ_PLL(dev, RADEON_MCLK_CNTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 710 | RADEON_WRITE_PLL(RADEON_MCLK_CNTL, (mclk_cntl | |
| 711 | RADEON_FORCEON_MCLKA | |
| 712 | RADEON_FORCEON_MCLKB | |
| 713 | RADEON_FORCEON_YCLKA | |
| 714 | RADEON_FORCEON_YCLKB | |
| 715 | RADEON_FORCEON_MC | |
| 716 | RADEON_FORCEON_AIC)); |
Alex Deucher | d396db3 | 2008-05-28 11:54:06 +1000 | [diff] [blame] | 717 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | |
Alex Deucher | d396db3 | 2008-05-28 11:54:06 +1000 | [diff] [blame] | 719 | rbbm_soft_reset = RADEON_READ(RADEON_RBBM_SOFT_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | |
Alex Deucher | d396db3 | 2008-05-28 11:54:06 +1000 | [diff] [blame] | 721 | RADEON_WRITE(RADEON_RBBM_SOFT_RESET, (rbbm_soft_reset | |
| 722 | RADEON_SOFT_RESET_CP | |
| 723 | RADEON_SOFT_RESET_HI | |
| 724 | RADEON_SOFT_RESET_SE | |
| 725 | RADEON_SOFT_RESET_RE | |
| 726 | RADEON_SOFT_RESET_PP | |
| 727 | RADEON_SOFT_RESET_E2 | |
| 728 | RADEON_SOFT_RESET_RB)); |
| 729 | RADEON_READ(RADEON_RBBM_SOFT_RESET); |
| 730 | RADEON_WRITE(RADEON_RBBM_SOFT_RESET, (rbbm_soft_reset & |
| 731 | ~(RADEON_SOFT_RESET_CP | |
| 732 | RADEON_SOFT_RESET_HI | |
| 733 | RADEON_SOFT_RESET_SE | |
| 734 | RADEON_SOFT_RESET_RE | |
| 735 | RADEON_SOFT_RESET_PP | |
| 736 | RADEON_SOFT_RESET_E2 | |
| 737 | RADEON_SOFT_RESET_RB))); |
| 738 | RADEON_READ(RADEON_RBBM_SOFT_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | |
Alex Deucher | d396db3 | 2008-05-28 11:54:06 +1000 | [diff] [blame] | 740 | if ((dev_priv->flags & RADEON_FAMILY_MASK) <= CHIP_RV410) { |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 741 | RADEON_WRITE_PLL(RADEON_MCLK_CNTL, mclk_cntl); |
| 742 | RADEON_WRITE(RADEON_CLOCK_CNTL_INDEX, clock_cntl_index); |
| 743 | RADEON_WRITE(RADEON_RBBM_SOFT_RESET, rbbm_soft_reset); |
| 744 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | |
Alex Deucher | 5b92c40 | 2008-05-28 11:57:40 +1000 | [diff] [blame] | 746 | /* setup the raster pipes */ |
| 747 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R300) |
Michel Dänzer | 57b54ea | 2010-04-02 16:59:06 +0000 | [diff] [blame] | 748 | radeon_init_pipes(dev); |
Alex Deucher | 5b92c40 | 2008-05-28 11:57:40 +1000 | [diff] [blame] | 749 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | /* Reset the CP ring */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 751 | radeon_do_cp_reset(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | |
| 753 | /* The CP is no longer running after an engine reset */ |
| 754 | dev_priv->cp_running = 0; |
| 755 | |
| 756 | /* Reset any pending vertex, indirect buffers */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 757 | radeon_freelist_reset(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | |
| 759 | return 0; |
| 760 | } |
| 761 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 762 | static void radeon_cp_init_ring_buffer(struct drm_device * dev, |
etienne | 3d16118 | 2009-02-20 09:44:45 +1000 | [diff] [blame] | 763 | drm_radeon_private_t *dev_priv, |
| 764 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | { |
etienne | 3d16118 | 2009-02-20 09:44:45 +1000 | [diff] [blame] | 766 | struct drm_radeon_master_private *master_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | u32 ring_start, cur_read_ptr; |
Dave Airlie | bc5f452 | 2007-11-05 12:50:58 +1000 | [diff] [blame] | 768 | |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 769 | /* Initialize the memory controller. With new memory map, the fb location |
| 770 | * is not changed, it should have been properly initialized already. Part |
| 771 | * of the problem is that the code below is bogus, assuming the GART is |
| 772 | * always appended to the fb which is not necessarily the case |
| 773 | */ |
| 774 | if (!dev_priv->new_memmap) |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 775 | radeon_write_fb_location(dev_priv, |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 776 | ((dev_priv->gart_vm_start - 1) & 0xffff0000) |
| 777 | | (dev_priv->fb_location >> 16)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | |
| 779 | #if __OS_HAS_AGP |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 780 | if (dev_priv->flags & RADEON_IS_AGP) { |
Dave Airlie | 70b13d5 | 2008-06-19 11:40:44 +1000 | [diff] [blame] | 781 | radeon_write_agp_base(dev_priv, dev->agp->base); |
| 782 | |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 783 | radeon_write_agp_location(dev_priv, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 784 | (((dev_priv->gart_vm_start - 1 + |
| 785 | dev_priv->gart_size) & 0xffff0000) | |
| 786 | (dev_priv->gart_vm_start >> 16))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | |
| 788 | ring_start = (dev_priv->cp_ring->offset |
| 789 | - dev->agp->base |
| 790 | + dev_priv->gart_vm_start); |
Ivan Kokshaysky | b0917bd | 2005-10-26 11:05:25 +0100 | [diff] [blame] | 791 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | #endif |
| 793 | ring_start = (dev_priv->cp_ring->offset |
Ivan Kokshaysky | b0917bd | 2005-10-26 11:05:25 +0100 | [diff] [blame] | 794 | - (unsigned long)dev->sg->virtual |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | + dev_priv->gart_vm_start); |
| 796 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 797 | RADEON_WRITE(RADEON_CP_RB_BASE, ring_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | |
| 799 | /* Set the write pointer delay */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 800 | RADEON_WRITE(RADEON_CP_RB_WPTR_DELAY, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | |
| 802 | /* Initialize the ring buffer's read and write pointers */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 803 | cur_read_ptr = RADEON_READ(RADEON_CP_RB_RPTR); |
| 804 | RADEON_WRITE(RADEON_CP_RB_WPTR, cur_read_ptr); |
| 805 | SET_RING_HEAD(dev_priv, cur_read_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | dev_priv->ring.tail = cur_read_ptr; |
| 807 | |
| 808 | #if __OS_HAS_AGP |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 809 | if (dev_priv->flags & RADEON_IS_AGP) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 810 | RADEON_WRITE(RADEON_CP_RB_RPTR_ADDR, |
| 811 | dev_priv->ring_rptr->offset |
| 812 | - dev->agp->base + dev_priv->gart_vm_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | } else |
| 814 | #endif |
| 815 | { |
David Miller | e8a8943 | 2009-02-12 02:15:44 -0800 | [diff] [blame] | 816 | RADEON_WRITE(RADEON_CP_RB_RPTR_ADDR, |
| 817 | dev_priv->ring_rptr->offset |
| 818 | - ((unsigned long) dev->sg->virtual) |
| 819 | + dev_priv->gart_vm_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | } |
| 821 | |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 822 | /* Set ring buffer size */ |
| 823 | #ifdef __BIG_ENDIAN |
| 824 | RADEON_WRITE(RADEON_CP_RB_CNTL, |
Roland Scheidegger | 576cc45 | 2008-02-07 14:59:24 +1000 | [diff] [blame] | 825 | RADEON_BUF_SWAP_32BIT | |
| 826 | (dev_priv->ring.fetch_size_l2ow << 18) | |
| 827 | (dev_priv->ring.rptr_update_l2qw << 8) | |
| 828 | dev_priv->ring.size_l2qw); |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 829 | #else |
Roland Scheidegger | 576cc45 | 2008-02-07 14:59:24 +1000 | [diff] [blame] | 830 | RADEON_WRITE(RADEON_CP_RB_CNTL, |
| 831 | (dev_priv->ring.fetch_size_l2ow << 18) | |
| 832 | (dev_priv->ring.rptr_update_l2qw << 8) | |
| 833 | dev_priv->ring.size_l2qw); |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 834 | #endif |
| 835 | |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 836 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | /* Initialize the scratch register pointer. This will cause |
| 838 | * the scratch register values to be written out to memory |
| 839 | * whenever they are updated. |
| 840 | * |
| 841 | * We simply put this behind the ring read pointer, this works |
| 842 | * with PCI GART as well as (whatever kind of) AGP GART |
| 843 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 844 | RADEON_WRITE(RADEON_SCRATCH_ADDR, RADEON_READ(RADEON_CP_RB_RPTR_ADDR) |
| 845 | + RADEON_SCRATCH_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 847 | RADEON_WRITE(RADEON_SCRATCH_UMSK, 0x7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | |
Dave Airlie | dd8d7cb | 2009-02-20 13:28:59 +1000 | [diff] [blame] | 849 | radeon_enable_bm(dev_priv); |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 850 | |
David Miller | b07fa02 | 2009-02-12 02:15:37 -0800 | [diff] [blame] | 851 | radeon_write_ring_rptr(dev_priv, RADEON_SCRATCHOFF(0), 0); |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 852 | RADEON_WRITE(RADEON_LAST_FRAME_REG, 0); |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 853 | |
David Miller | b07fa02 | 2009-02-12 02:15:37 -0800 | [diff] [blame] | 854 | radeon_write_ring_rptr(dev_priv, RADEON_SCRATCHOFF(1), 0); |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 855 | RADEON_WRITE(RADEON_LAST_DISPATCH_REG, 0); |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 856 | |
David Miller | b07fa02 | 2009-02-12 02:15:37 -0800 | [diff] [blame] | 857 | radeon_write_ring_rptr(dev_priv, RADEON_SCRATCHOFF(2), 0); |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 858 | RADEON_WRITE(RADEON_LAST_CLEAR_REG, 0); |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 859 | |
etienne | 3d16118 | 2009-02-20 09:44:45 +1000 | [diff] [blame] | 860 | /* reset sarea copies of these */ |
| 861 | master_priv = file_priv->master->driver_priv; |
| 862 | if (master_priv->sarea_priv) { |
| 863 | master_priv->sarea_priv->last_frame = 0; |
| 864 | master_priv->sarea_priv->last_dispatch = 0; |
| 865 | master_priv->sarea_priv->last_clear = 0; |
| 866 | } |
| 867 | |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 868 | radeon_do_wait_for_idle(dev_priv); |
| 869 | |
| 870 | /* Sync everything up */ |
| 871 | RADEON_WRITE(RADEON_ISYNC_CNTL, |
| 872 | (RADEON_ISYNC_ANY2D_IDLE3D | |
| 873 | RADEON_ISYNC_ANY3D_IDLE2D | |
| 874 | RADEON_ISYNC_WAIT_IDLEGUI | |
| 875 | RADEON_ISYNC_CPSCRATCH_IDLEGUI)); |
| 876 | |
| 877 | } |
| 878 | |
| 879 | static void radeon_test_writeback(drm_radeon_private_t * dev_priv) |
| 880 | { |
| 881 | u32 tmp; |
| 882 | |
Dave Airlie | 6b79d52 | 2008-09-02 10:10:16 +1000 | [diff] [blame] | 883 | /* Start with assuming that writeback doesn't work */ |
| 884 | dev_priv->writeback_works = 0; |
| 885 | |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 886 | /* Writeback doesn't seem to work everywhere, test it here and possibly |
| 887 | * enable it if it appears to work |
| 888 | */ |
David Miller | b07fa02 | 2009-02-12 02:15:37 -0800 | [diff] [blame] | 889 | radeon_write_ring_rptr(dev_priv, RADEON_SCRATCHOFF(1), 0); |
| 890 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 891 | RADEON_WRITE(RADEON_SCRATCH_REG1, 0xdeadbeef); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 893 | for (tmp = 0; tmp < dev_priv->usec_timeout; tmp++) { |
David Miller | b07fa02 | 2009-02-12 02:15:37 -0800 | [diff] [blame] | 894 | u32 val; |
| 895 | |
| 896 | val = radeon_read_ring_rptr(dev_priv, RADEON_SCRATCHOFF(1)); |
| 897 | if (val == 0xdeadbeef) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | break; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 899 | DRM_UDELAY(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | } |
| 901 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 902 | if (tmp < dev_priv->usec_timeout) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | dev_priv->writeback_works = 1; |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 904 | DRM_INFO("writeback test succeeded in %d usecs\n", tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | } else { |
| 906 | dev_priv->writeback_works = 0; |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 907 | DRM_INFO("writeback test failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | } |
Dave Airlie | 689b9d7 | 2005-09-30 17:09:07 +1000 | [diff] [blame] | 909 | if (radeon_no_wb == 1) { |
| 910 | dev_priv->writeback_works = 0; |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 911 | DRM_INFO("writeback forced off\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | } |
Michel Dänzer | ae1b1a48 | 2006-08-07 20:37:46 +1000 | [diff] [blame] | 913 | |
| 914 | if (!dev_priv->writeback_works) { |
| 915 | /* Disable writeback to avoid unnecessary bus master transfer */ |
| 916 | RADEON_WRITE(RADEON_CP_RB_CNTL, RADEON_READ(RADEON_CP_RB_CNTL) | |
| 917 | RADEON_RB_NO_UPDATE); |
| 918 | RADEON_WRITE(RADEON_SCRATCH_UMSK, 0); |
| 919 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | } |
| 921 | |
Dave Airlie | f2b04cd | 2007-05-08 15:19:23 +1000 | [diff] [blame] | 922 | /* Enable or disable IGP GART on the chip */ |
| 923 | static void radeon_set_igpgart(drm_radeon_private_t * dev_priv, int on) |
| 924 | { |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 925 | u32 temp; |
| 926 | |
| 927 | if (on) { |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 928 | DRM_DEBUG("programming igp gart %08X %08lX %08X\n", |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 929 | dev_priv->gart_vm_start, |
| 930 | (long)dev_priv->gart_info.bus_addr, |
| 931 | dev_priv->gart_size); |
| 932 | |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 933 | temp = IGP_READ_MCIND(dev_priv, RS480_MC_MISC_CNTL); |
Alex Deucher | f0738e9 | 2008-10-16 17:12:02 +1000 | [diff] [blame] | 934 | if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690) || |
| 935 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS740)) |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 936 | IGP_WRITE_MCIND(RS480_MC_MISC_CNTL, (RS480_GART_INDEX_REG_EN | |
| 937 | RS690_BLOCK_GFX_D3_EN)); |
| 938 | else |
| 939 | IGP_WRITE_MCIND(RS480_MC_MISC_CNTL, RS480_GART_INDEX_REG_EN); |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 940 | |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 941 | IGP_WRITE_MCIND(RS480_AGP_ADDRESS_SPACE_SIZE, (RS480_GART_EN | |
| 942 | RS480_VA_SIZE_32MB)); |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 943 | |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 944 | temp = IGP_READ_MCIND(dev_priv, RS480_GART_FEATURE_ID); |
| 945 | IGP_WRITE_MCIND(RS480_GART_FEATURE_ID, (RS480_HANG_EN | |
| 946 | RS480_TLB_ENABLE | |
| 947 | RS480_GTW_LAC_EN | |
| 948 | RS480_1LEVEL_GART)); |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 949 | |
Dave Airlie | fa0d71b | 2008-05-28 11:27:01 +1000 | [diff] [blame] | 950 | temp = dev_priv->gart_info.bus_addr & 0xfffff000; |
| 951 | temp |= (upper_32_bits(dev_priv->gart_info.bus_addr) & 0xff) << 4; |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 952 | IGP_WRITE_MCIND(RS480_GART_BASE, temp); |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 953 | |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 954 | temp = IGP_READ_MCIND(dev_priv, RS480_AGP_MODE_CNTL); |
| 955 | IGP_WRITE_MCIND(RS480_AGP_MODE_CNTL, ((1 << RS480_REQ_TYPE_SNOOP_SHIFT) | |
| 956 | RS480_REQ_TYPE_SNOOP_DIS)); |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 957 | |
Alex Deucher | 5cfb695 | 2008-06-19 12:38:29 +1000 | [diff] [blame] | 958 | radeon_write_agp_base(dev_priv, dev_priv->gart_vm_start); |
Dave Airlie | 3722bfc | 2008-05-28 11:28:27 +1000 | [diff] [blame] | 959 | |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 960 | dev_priv->gart_size = 32*1024*1024; |
| 961 | temp = (((dev_priv->gart_vm_start - 1 + dev_priv->gart_size) & |
| 962 | 0xffff0000) | (dev_priv->gart_vm_start >> 16)); |
| 963 | |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 964 | radeon_write_agp_location(dev_priv, temp); |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 965 | |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 966 | temp = IGP_READ_MCIND(dev_priv, RS480_AGP_ADDRESS_SPACE_SIZE); |
| 967 | IGP_WRITE_MCIND(RS480_AGP_ADDRESS_SPACE_SIZE, (RS480_GART_EN | |
| 968 | RS480_VA_SIZE_32MB)); |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 969 | |
| 970 | do { |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 971 | temp = IGP_READ_MCIND(dev_priv, RS480_GART_CACHE_CNTRL); |
| 972 | if ((temp & RS480_GART_CACHE_INVALIDATE) == 0) |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 973 | break; |
| 974 | DRM_UDELAY(1); |
| 975 | } while (1); |
| 976 | |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 977 | IGP_WRITE_MCIND(RS480_GART_CACHE_CNTRL, |
| 978 | RS480_GART_CACHE_INVALIDATE); |
Alex Deucher | 2735977 | 2008-05-28 12:54:16 +1000 | [diff] [blame] | 979 | |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 980 | do { |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 981 | temp = IGP_READ_MCIND(dev_priv, RS480_GART_CACHE_CNTRL); |
| 982 | if ((temp & RS480_GART_CACHE_INVALIDATE) == 0) |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 983 | break; |
| 984 | DRM_UDELAY(1); |
| 985 | } while (1); |
| 986 | |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 987 | IGP_WRITE_MCIND(RS480_GART_CACHE_CNTRL, 0); |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 988 | } else { |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 989 | IGP_WRITE_MCIND(RS480_AGP_ADDRESS_SPACE_SIZE, 0); |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | |
Alex Deucher | c1556f7 | 2009-02-25 16:57:49 -0500 | [diff] [blame] | 993 | /* Enable or disable IGP GART on the chip */ |
| 994 | static void rs600_set_igpgart(drm_radeon_private_t *dev_priv, int on) |
| 995 | { |
| 996 | u32 temp; |
| 997 | int i; |
| 998 | |
| 999 | if (on) { |
| 1000 | DRM_DEBUG("programming igp gart %08X %08lX %08X\n", |
| 1001 | dev_priv->gart_vm_start, |
| 1002 | (long)dev_priv->gart_info.bus_addr, |
| 1003 | dev_priv->gart_size); |
| 1004 | |
| 1005 | IGP_WRITE_MCIND(RS600_MC_PT0_CNTL, (RS600_EFFECTIVE_L2_CACHE_SIZE(6) | |
| 1006 | RS600_EFFECTIVE_L2_QUEUE_SIZE(6))); |
| 1007 | |
| 1008 | for (i = 0; i < 19; i++) |
| 1009 | IGP_WRITE_MCIND(RS600_MC_PT0_CLIENT0_CNTL + i, |
| 1010 | (RS600_ENABLE_TRANSLATION_MODE_OVERRIDE | |
| 1011 | RS600_SYSTEM_ACCESS_MODE_IN_SYS | |
| 1012 | RS600_SYSTEM_APERTURE_UNMAPPED_ACCESS_PASSTHROUGH | |
| 1013 | RS600_EFFECTIVE_L1_CACHE_SIZE(3) | |
| 1014 | RS600_ENABLE_FRAGMENT_PROCESSING | |
| 1015 | RS600_EFFECTIVE_L1_QUEUE_SIZE(3))); |
| 1016 | |
| 1017 | IGP_WRITE_MCIND(RS600_MC_PT0_CONTEXT0_CNTL, (RS600_ENABLE_PAGE_TABLE | |
| 1018 | RS600_PAGE_TABLE_TYPE_FLAT)); |
| 1019 | |
| 1020 | /* disable all other contexts */ |
| 1021 | for (i = 1; i < 8; i++) |
| 1022 | IGP_WRITE_MCIND(RS600_MC_PT0_CONTEXT0_CNTL + i, 0); |
| 1023 | |
| 1024 | /* setup the page table aperture */ |
| 1025 | IGP_WRITE_MCIND(RS600_MC_PT0_CONTEXT0_FLAT_BASE_ADDR, |
| 1026 | dev_priv->gart_info.bus_addr); |
| 1027 | IGP_WRITE_MCIND(RS600_MC_PT0_CONTEXT0_FLAT_START_ADDR, |
| 1028 | dev_priv->gart_vm_start); |
| 1029 | IGP_WRITE_MCIND(RS600_MC_PT0_CONTEXT0_FLAT_END_ADDR, |
| 1030 | (dev_priv->gart_vm_start + dev_priv->gart_size - 1)); |
| 1031 | IGP_WRITE_MCIND(RS600_MC_PT0_CONTEXT0_DEFAULT_READ_ADDR, 0); |
| 1032 | |
| 1033 | /* setup the system aperture */ |
| 1034 | IGP_WRITE_MCIND(RS600_MC_PT0_SYSTEM_APERTURE_LOW_ADDR, |
| 1035 | dev_priv->gart_vm_start); |
| 1036 | IGP_WRITE_MCIND(RS600_MC_PT0_SYSTEM_APERTURE_HIGH_ADDR, |
| 1037 | (dev_priv->gart_vm_start + dev_priv->gart_size - 1)); |
| 1038 | |
| 1039 | /* enable page tables */ |
| 1040 | temp = IGP_READ_MCIND(dev_priv, RS600_MC_PT0_CNTL); |
| 1041 | IGP_WRITE_MCIND(RS600_MC_PT0_CNTL, (temp | RS600_ENABLE_PT)); |
| 1042 | |
| 1043 | temp = IGP_READ_MCIND(dev_priv, RS600_MC_CNTL1); |
| 1044 | IGP_WRITE_MCIND(RS600_MC_CNTL1, (temp | RS600_ENABLE_PAGE_TABLES)); |
| 1045 | |
| 1046 | /* invalidate the cache */ |
| 1047 | temp = IGP_READ_MCIND(dev_priv, RS600_MC_PT0_CNTL); |
| 1048 | |
| 1049 | temp &= ~(RS600_INVALIDATE_ALL_L1_TLBS | RS600_INVALIDATE_L2_CACHE); |
| 1050 | IGP_WRITE_MCIND(RS600_MC_PT0_CNTL, temp); |
| 1051 | temp = IGP_READ_MCIND(dev_priv, RS600_MC_PT0_CNTL); |
| 1052 | |
| 1053 | temp |= RS600_INVALIDATE_ALL_L1_TLBS | RS600_INVALIDATE_L2_CACHE; |
| 1054 | IGP_WRITE_MCIND(RS600_MC_PT0_CNTL, temp); |
| 1055 | temp = IGP_READ_MCIND(dev_priv, RS600_MC_PT0_CNTL); |
| 1056 | |
| 1057 | temp &= ~(RS600_INVALIDATE_ALL_L1_TLBS | RS600_INVALIDATE_L2_CACHE); |
| 1058 | IGP_WRITE_MCIND(RS600_MC_PT0_CNTL, temp); |
| 1059 | temp = IGP_READ_MCIND(dev_priv, RS600_MC_PT0_CNTL); |
| 1060 | |
| 1061 | } else { |
| 1062 | IGP_WRITE_MCIND(RS600_MC_PT0_CNTL, 0); |
| 1063 | temp = IGP_READ_MCIND(dev_priv, RS600_MC_CNTL1); |
| 1064 | temp &= ~RS600_ENABLE_PAGE_TABLES; |
| 1065 | IGP_WRITE_MCIND(RS600_MC_CNTL1, temp); |
| 1066 | } |
| 1067 | } |
| 1068 | |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 1069 | static void radeon_set_pciegart(drm_radeon_private_t * dev_priv, int on) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | { |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 1071 | u32 tmp = RADEON_READ_PCIE(dev_priv, RADEON_PCIE_TX_GART_CNTL); |
| 1072 | if (on) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 1074 | DRM_DEBUG("programming pcie %08X %08lX %08X\n", |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1075 | dev_priv->gart_vm_start, |
| 1076 | (long)dev_priv->gart_info.bus_addr, |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 1077 | dev_priv->gart_size); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1078 | RADEON_WRITE_PCIE(RADEON_PCIE_TX_DISCARD_RD_ADDR_LO, |
| 1079 | dev_priv->gart_vm_start); |
| 1080 | RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_BASE, |
| 1081 | dev_priv->gart_info.bus_addr); |
| 1082 | RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_START_LO, |
| 1083 | dev_priv->gart_vm_start); |
| 1084 | RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_END_LO, |
| 1085 | dev_priv->gart_vm_start + |
| 1086 | dev_priv->gart_size - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 1088 | radeon_write_agp_location(dev_priv, 0xffffffc0); /* ?? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1090 | RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_CNTL, |
| 1091 | RADEON_PCIE_TX_GART_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | } else { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1093 | RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_CNTL, |
| 1094 | tmp & ~RADEON_PCIE_TX_GART_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | } |
| 1096 | } |
| 1097 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | /* Enable or disable PCI GART on the chip */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1099 | static void radeon_set_pcigart(drm_radeon_private_t * dev_priv, int on) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | { |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 1101 | u32 tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 1103 | if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690) || |
Alex Deucher | f0738e9 | 2008-10-16 17:12:02 +1000 | [diff] [blame] | 1104 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS740) || |
Alex Deucher | 45e5190 | 2008-05-28 13:28:59 +1000 | [diff] [blame] | 1105 | (dev_priv->flags & RADEON_IS_IGPGART)) { |
Dave Airlie | f2b04cd | 2007-05-08 15:19:23 +1000 | [diff] [blame] | 1106 | radeon_set_igpgart(dev_priv, on); |
| 1107 | return; |
| 1108 | } |
| 1109 | |
Alex Deucher | c1556f7 | 2009-02-25 16:57:49 -0500 | [diff] [blame] | 1110 | if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS600) { |
| 1111 | rs600_set_igpgart(dev_priv, on); |
| 1112 | return; |
| 1113 | } |
| 1114 | |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1115 | if (dev_priv->flags & RADEON_IS_PCIE) { |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 1116 | radeon_set_pciegart(dev_priv, on); |
| 1117 | return; |
| 1118 | } |
| 1119 | |
Dave Airlie | bc5f452 | 2007-11-05 12:50:58 +1000 | [diff] [blame] | 1120 | tmp = RADEON_READ(RADEON_AIC_CNTL); |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 1121 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1122 | if (on) { |
| 1123 | RADEON_WRITE(RADEON_AIC_CNTL, |
| 1124 | tmp | RADEON_PCIGART_TRANSLATE_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | |
| 1126 | /* set PCI GART page-table base address |
| 1127 | */ |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 1128 | RADEON_WRITE(RADEON_AIC_PT_BASE, dev_priv->gart_info.bus_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | |
| 1130 | /* set address range for PCI address translate |
| 1131 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1132 | RADEON_WRITE(RADEON_AIC_LO_ADDR, dev_priv->gart_vm_start); |
| 1133 | RADEON_WRITE(RADEON_AIC_HI_ADDR, dev_priv->gart_vm_start |
| 1134 | + dev_priv->gart_size - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | |
| 1136 | /* Turn off AGP aperture -- is this required for PCI GART? |
| 1137 | */ |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 1138 | radeon_write_agp_location(dev_priv, 0xffffffc0); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1139 | RADEON_WRITE(RADEON_AGP_COMMAND, 0); /* clear AGP_COMMAND */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | } else { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1141 | RADEON_WRITE(RADEON_AIC_CNTL, |
| 1142 | tmp & ~RADEON_PCIGART_TRANSLATE_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | } |
| 1144 | } |
| 1145 | |
David Miller | 6abf6bb | 2009-02-14 01:51:07 -0800 | [diff] [blame] | 1146 | static int radeon_setup_pcigart_surface(drm_radeon_private_t *dev_priv) |
| 1147 | { |
| 1148 | struct drm_ati_pcigart_info *gart_info = &dev_priv->gart_info; |
| 1149 | struct radeon_virt_surface *vp; |
| 1150 | int i; |
| 1151 | |
| 1152 | for (i = 0; i < RADEON_MAX_SURFACES * 2; i++) { |
| 1153 | if (!dev_priv->virt_surfaces[i].file_priv || |
| 1154 | dev_priv->virt_surfaces[i].file_priv == PCIGART_FILE_PRIV) |
| 1155 | break; |
| 1156 | } |
| 1157 | if (i >= 2 * RADEON_MAX_SURFACES) |
| 1158 | return -ENOMEM; |
| 1159 | vp = &dev_priv->virt_surfaces[i]; |
| 1160 | |
| 1161 | for (i = 0; i < RADEON_MAX_SURFACES; i++) { |
| 1162 | struct radeon_surface *sp = &dev_priv->surfaces[i]; |
| 1163 | if (sp->refcount) |
| 1164 | continue; |
| 1165 | |
| 1166 | vp->surface_index = i; |
| 1167 | vp->lower = gart_info->bus_addr; |
| 1168 | vp->upper = vp->lower + gart_info->table_size; |
| 1169 | vp->flags = 0; |
| 1170 | vp->file_priv = PCIGART_FILE_PRIV; |
| 1171 | |
| 1172 | sp->refcount = 1; |
| 1173 | sp->lower = vp->lower; |
| 1174 | sp->upper = vp->upper; |
| 1175 | sp->flags = 0; |
| 1176 | |
| 1177 | RADEON_WRITE(RADEON_SURFACE0_INFO + 16 * i, sp->flags); |
| 1178 | RADEON_WRITE(RADEON_SURFACE0_LOWER_BOUND + 16 * i, sp->lower); |
| 1179 | RADEON_WRITE(RADEON_SURFACE0_UPPER_BOUND + 16 * i, sp->upper); |
| 1180 | return 0; |
| 1181 | } |
| 1182 | |
| 1183 | return -ENOMEM; |
| 1184 | } |
| 1185 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1186 | static int radeon_do_init_cp(struct drm_device *dev, drm_radeon_init_t *init, |
| 1187 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | { |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 1189 | drm_radeon_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1190 | struct drm_radeon_master_private *master_priv = file_priv->master->driver_priv; |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 1191 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1192 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | |
Dave Airlie | f3dd5c3 | 2006-03-25 18:09:46 +1100 | [diff] [blame] | 1194 | /* if we require new memory map but we don't have it fail */ |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1195 | if ((dev_priv->flags & RADEON_NEW_MEMMAP) && !dev_priv->new_memmap) { |
Dave Airlie | b15ec36 | 2006-08-19 17:43:52 +1000 | [diff] [blame] | 1196 | DRM_ERROR("Cannot initialise DRM on this card\nThis card requires a new X.org DDX for 3D\n"); |
Dave Airlie | f3dd5c3 | 2006-03-25 18:09:46 +1100 | [diff] [blame] | 1197 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1198 | return -EINVAL; |
Dave Airlie | f3dd5c3 | 2006-03-25 18:09:46 +1100 | [diff] [blame] | 1199 | } |
| 1200 | |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1201 | if (init->is_pci && (dev_priv->flags & RADEON_IS_AGP)) { |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 1202 | DRM_DEBUG("Forcing AGP card to PCI mode\n"); |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1203 | dev_priv->flags &= ~RADEON_IS_AGP; |
| 1204 | } else if (!(dev_priv->flags & (RADEON_IS_AGP | RADEON_IS_PCI | RADEON_IS_PCIE)) |
Dave Airlie | b15ec36 | 2006-08-19 17:43:52 +1000 | [diff] [blame] | 1205 | && !init->is_pci) { |
| 1206 | DRM_DEBUG("Restoring AGP flag\n"); |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1207 | dev_priv->flags |= RADEON_IS_AGP; |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 1208 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1210 | if ((!(dev_priv->flags & RADEON_IS_AGP)) && !dev->sg) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1211 | DRM_ERROR("PCI GART memory not allocated!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1213 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | dev_priv->usec_timeout = init->usec_timeout; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1217 | if (dev_priv->usec_timeout < 1 || |
| 1218 | dev_priv->usec_timeout > RADEON_MAX_USEC_TIMEOUT) { |
| 1219 | DRM_DEBUG("TIMEOUT problem!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1221 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | } |
| 1223 | |
Dave Airlie | ddbee33 | 2007-07-11 12:16:01 +1000 | [diff] [blame] | 1224 | /* Enable vblank on CRTC1 for older X servers |
| 1225 | */ |
| 1226 | dev_priv->vblank_crtc = DRM_RADEON_VBLANK_CRTC1; |
| 1227 | |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 1228 | switch(init->func) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | case RADEON_INIT_R200_CP: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1230 | dev_priv->microcode_version = UCODE_R200; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | break; |
| 1232 | case RADEON_INIT_R300_CP: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1233 | dev_priv->microcode_version = UCODE_R300; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | break; |
| 1235 | default: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1236 | dev_priv->microcode_version = UCODE_R100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | dev_priv->do_boxes = 0; |
| 1240 | dev_priv->cp_mode = init->cp_mode; |
| 1241 | |
| 1242 | /* We don't support anything other than bus-mastering ring mode, |
| 1243 | * but the ring can be in either AGP or PCI space for the ring |
| 1244 | * read pointer. |
| 1245 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1246 | if ((init->cp_mode != RADEON_CSQ_PRIBM_INDDIS) && |
| 1247 | (init->cp_mode != RADEON_CSQ_PRIBM_INDBM)) { |
| 1248 | DRM_DEBUG("BAD cp_mode (%x)!\n", init->cp_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1250 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | } |
| 1252 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1253 | switch (init->fb_bpp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | case 16: |
| 1255 | dev_priv->color_fmt = RADEON_COLOR_FORMAT_RGB565; |
| 1256 | break; |
| 1257 | case 32: |
| 1258 | default: |
| 1259 | dev_priv->color_fmt = RADEON_COLOR_FORMAT_ARGB8888; |
| 1260 | break; |
| 1261 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1262 | dev_priv->front_offset = init->front_offset; |
| 1263 | dev_priv->front_pitch = init->front_pitch; |
| 1264 | dev_priv->back_offset = init->back_offset; |
| 1265 | dev_priv->back_pitch = init->back_pitch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1267 | switch (init->depth_bpp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | case 16: |
| 1269 | dev_priv->depth_fmt = RADEON_DEPTH_FORMAT_16BIT_INT_Z; |
| 1270 | break; |
| 1271 | case 32: |
| 1272 | default: |
| 1273 | dev_priv->depth_fmt = RADEON_DEPTH_FORMAT_24BIT_INT_Z; |
| 1274 | break; |
| 1275 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1276 | dev_priv->depth_offset = init->depth_offset; |
| 1277 | dev_priv->depth_pitch = init->depth_pitch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | |
| 1279 | /* Hardware state for depth clears. Remove this if/when we no |
| 1280 | * longer clear the depth buffer with a 3D rectangle. Hard-code |
| 1281 | * all values to prevent unwanted 3D state from slipping through |
| 1282 | * and screwing with the clear operation. |
| 1283 | */ |
| 1284 | dev_priv->depth_clear.rb3d_cntl = (RADEON_PLANE_MASK_ENABLE | |
| 1285 | (dev_priv->color_fmt << 10) | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1286 | (dev_priv->microcode_version == |
| 1287 | UCODE_R100 ? RADEON_ZBLOCK16 : 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1289 | dev_priv->depth_clear.rb3d_zstencilcntl = |
| 1290 | (dev_priv->depth_fmt | |
| 1291 | RADEON_Z_TEST_ALWAYS | |
| 1292 | RADEON_STENCIL_TEST_ALWAYS | |
| 1293 | RADEON_STENCIL_S_FAIL_REPLACE | |
| 1294 | RADEON_STENCIL_ZPASS_REPLACE | |
| 1295 | RADEON_STENCIL_ZFAIL_REPLACE | RADEON_Z_WRITE_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | |
| 1297 | dev_priv->depth_clear.se_cntl = (RADEON_FFACE_CULL_CW | |
| 1298 | RADEON_BFACE_SOLID | |
| 1299 | RADEON_FFACE_SOLID | |
| 1300 | RADEON_FLAT_SHADE_VTX_LAST | |
| 1301 | RADEON_DIFFUSE_SHADE_FLAT | |
| 1302 | RADEON_ALPHA_SHADE_FLAT | |
| 1303 | RADEON_SPECULAR_SHADE_FLAT | |
| 1304 | RADEON_FOG_SHADE_FLAT | |
| 1305 | RADEON_VTX_PIX_CENTER_OGL | |
| 1306 | RADEON_ROUND_MODE_TRUNC | |
| 1307 | RADEON_ROUND_PREC_8TH_PIX); |
| 1308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | dev_priv->ring_offset = init->ring_offset; |
| 1311 | dev_priv->ring_rptr_offset = init->ring_rptr_offset; |
| 1312 | dev_priv->buffers_offset = init->buffers_offset; |
| 1313 | dev_priv->gart_textures_offset = init->gart_textures_offset; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1314 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1315 | master_priv->sarea = drm_getsarea(dev); |
| 1316 | if (!master_priv->sarea) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | DRM_ERROR("could not find sarea!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1319 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | } |
| 1321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | dev_priv->cp_ring = drm_core_findmap(dev, init->ring_offset); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1323 | if (!dev_priv->cp_ring) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | DRM_ERROR("could not find cp ring region!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1326 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | } |
| 1328 | dev_priv->ring_rptr = drm_core_findmap(dev, init->ring_rptr_offset); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1329 | if (!dev_priv->ring_rptr) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | DRM_ERROR("could not find ring read pointer!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1332 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | } |
Dave Airlie | d1f2b55 | 2005-08-05 22:11:22 +1000 | [diff] [blame] | 1334 | dev->agp_buffer_token = init->buffers_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1336 | if (!dev->agp_buffer_map) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | DRM_ERROR("could not find dma buffer region!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1339 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | } |
| 1341 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1342 | if (init->gart_textures_offset) { |
| 1343 | dev_priv->gart_textures = |
| 1344 | drm_core_findmap(dev, init->gart_textures_offset); |
| 1345 | if (!dev_priv->gart_textures) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | DRM_ERROR("could not find GART texture region!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1348 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | } |
| 1350 | } |
| 1351 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | #if __OS_HAS_AGP |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1353 | if (dev_priv->flags & RADEON_IS_AGP) { |
Dave Airlie | 9b8d5a1 | 2009-02-07 11:15:41 +1000 | [diff] [blame] | 1354 | drm_core_ioremap_wc(dev_priv->cp_ring, dev); |
| 1355 | drm_core_ioremap_wc(dev_priv->ring_rptr, dev); |
| 1356 | drm_core_ioremap_wc(dev->agp_buffer_map, dev); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1357 | if (!dev_priv->cp_ring->handle || |
| 1358 | !dev_priv->ring_rptr->handle || |
| 1359 | !dev->agp_buffer_map->handle) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | DRM_ERROR("could not find ioremap agp regions!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1362 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | } |
| 1364 | } else |
| 1365 | #endif |
| 1366 | { |
Benjamin Herrenschmidt | 41c2e75 | 2009-02-02 16:55:47 +1100 | [diff] [blame] | 1367 | dev_priv->cp_ring->handle = |
| 1368 | (void *)(unsigned long)dev_priv->cp_ring->offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | dev_priv->ring_rptr->handle = |
Benjamin Herrenschmidt | 41c2e75 | 2009-02-02 16:55:47 +1100 | [diff] [blame] | 1370 | (void *)(unsigned long)dev_priv->ring_rptr->offset; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1371 | dev->agp_buffer_map->handle = |
Benjamin Herrenschmidt | 41c2e75 | 2009-02-02 16:55:47 +1100 | [diff] [blame] | 1372 | (void *)(unsigned long)dev->agp_buffer_map->offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1374 | DRM_DEBUG("dev_priv->cp_ring->handle %p\n", |
| 1375 | dev_priv->cp_ring->handle); |
| 1376 | DRM_DEBUG("dev_priv->ring_rptr->handle %p\n", |
| 1377 | dev_priv->ring_rptr->handle); |
| 1378 | DRM_DEBUG("dev->agp_buffer_map->handle %p\n", |
| 1379 | dev->agp_buffer_map->handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | } |
| 1381 | |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 1382 | dev_priv->fb_location = (radeon_read_fb_location(dev_priv) & 0xffff) << 16; |
Dave Airlie | bc5f452 | 2007-11-05 12:50:58 +1000 | [diff] [blame] | 1383 | dev_priv->fb_size = |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 1384 | ((radeon_read_fb_location(dev_priv) & 0xffff0000u) + 0x10000) |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 1385 | - dev_priv->fb_location; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1387 | dev_priv->front_pitch_offset = (((dev_priv->front_pitch / 64) << 22) | |
| 1388 | ((dev_priv->front_offset |
| 1389 | + dev_priv->fb_location) >> 10)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1391 | dev_priv->back_pitch_offset = (((dev_priv->back_pitch / 64) << 22) | |
| 1392 | ((dev_priv->back_offset |
| 1393 | + dev_priv->fb_location) >> 10)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1395 | dev_priv->depth_pitch_offset = (((dev_priv->depth_pitch / 64) << 22) | |
| 1396 | ((dev_priv->depth_offset |
| 1397 | + dev_priv->fb_location) >> 10)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | |
| 1399 | dev_priv->gart_size = init->gart_size; |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 1400 | |
| 1401 | /* New let's set the memory map ... */ |
| 1402 | if (dev_priv->new_memmap) { |
| 1403 | u32 base = 0; |
| 1404 | |
| 1405 | DRM_INFO("Setting GART location based on new memory map\n"); |
| 1406 | |
| 1407 | /* If using AGP, try to locate the AGP aperture at the same |
| 1408 | * location in the card and on the bus, though we have to |
| 1409 | * align it down. |
| 1410 | */ |
| 1411 | #if __OS_HAS_AGP |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1412 | if (dev_priv->flags & RADEON_IS_AGP) { |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 1413 | base = dev->agp->base; |
| 1414 | /* Check if valid */ |
Michel Dänzer | 80b2c38 | 2007-02-18 18:03:21 +1100 | [diff] [blame] | 1415 | if ((base + dev_priv->gart_size - 1) >= dev_priv->fb_location && |
| 1416 | base < (dev_priv->fb_location + dev_priv->fb_size - 1)) { |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 1417 | DRM_INFO("Can't use AGP base @0x%08lx, won't fit\n", |
| 1418 | dev->agp->base); |
| 1419 | base = 0; |
| 1420 | } |
| 1421 | } |
| 1422 | #endif |
| 1423 | /* If not or if AGP is at 0 (Macs), try to put it elsewhere */ |
| 1424 | if (base == 0) { |
| 1425 | base = dev_priv->fb_location + dev_priv->fb_size; |
Michel Dänzer | 80b2c38 | 2007-02-18 18:03:21 +1100 | [diff] [blame] | 1426 | if (base < dev_priv->fb_location || |
| 1427 | ((base + dev_priv->gart_size) & 0xfffffffful) < base) |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 1428 | base = dev_priv->fb_location |
| 1429 | - dev_priv->gart_size; |
Dave Airlie | bc5f452 | 2007-11-05 12:50:58 +1000 | [diff] [blame] | 1430 | } |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 1431 | dev_priv->gart_vm_start = base & 0xffc00000u; |
| 1432 | if (dev_priv->gart_vm_start != base) |
| 1433 | DRM_INFO("GART aligned down from 0x%08x to 0x%08x\n", |
| 1434 | base, dev_priv->gart_vm_start); |
| 1435 | } else { |
| 1436 | DRM_INFO("Setting GART location based on old memory map\n"); |
| 1437 | dev_priv->gart_vm_start = dev_priv->fb_location + |
| 1438 | RADEON_READ(RADEON_CONFIG_APER_SIZE); |
| 1439 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | |
| 1441 | #if __OS_HAS_AGP |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1442 | if (dev_priv->flags & RADEON_IS_AGP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1444 | - dev->agp->base |
| 1445 | + dev_priv->gart_vm_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | else |
| 1447 | #endif |
| 1448 | dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset |
Ivan Kokshaysky | b0917bd | 2005-10-26 11:05:25 +0100 | [diff] [blame] | 1449 | - (unsigned long)dev->sg->virtual |
| 1450 | + dev_priv->gart_vm_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1452 | DRM_DEBUG("dev_priv->gart_size %d\n", dev_priv->gart_size); |
| 1453 | DRM_DEBUG("dev_priv->gart_vm_start 0x%x\n", dev_priv->gart_vm_start); |
| 1454 | DRM_DEBUG("dev_priv->gart_buffers_offset 0x%lx\n", |
| 1455 | dev_priv->gart_buffers_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1457 | dev_priv->ring.start = (u32 *) dev_priv->cp_ring->handle; |
| 1458 | dev_priv->ring.end = ((u32 *) dev_priv->cp_ring->handle |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | + init->ring_size / sizeof(u32)); |
| 1460 | dev_priv->ring.size = init->ring_size; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1461 | dev_priv->ring.size_l2qw = drm_order(init->ring_size / 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | |
Roland Scheidegger | 576cc45 | 2008-02-07 14:59:24 +1000 | [diff] [blame] | 1463 | dev_priv->ring.rptr_update = /* init->rptr_update */ 4096; |
| 1464 | dev_priv->ring.rptr_update_l2qw = drm_order( /* init->rptr_update */ 4096 / 8); |
| 1465 | |
| 1466 | dev_priv->ring.fetch_size = /* init->fetch_size */ 32; |
| 1467 | dev_priv->ring.fetch_size_l2ow = drm_order( /* init->fetch_size */ 32 / 16); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1468 | dev_priv->ring.tail_mask = (dev_priv->ring.size / sizeof(u32)) - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | |
| 1470 | dev_priv->ring.high_mark = RADEON_RING_HIGH_MARK; |
| 1471 | |
| 1472 | #if __OS_HAS_AGP |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1473 | if (dev_priv->flags & RADEON_IS_AGP) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | /* Turn off PCI GART */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1475 | radeon_set_pcigart(dev_priv, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | } else |
| 1477 | #endif |
| 1478 | { |
David Miller | 6abf6bb | 2009-02-14 01:51:07 -0800 | [diff] [blame] | 1479 | u32 sctrl; |
| 1480 | int ret; |
| 1481 | |
Dave Airlie | b05c238 | 2008-03-17 10:24:24 +1000 | [diff] [blame] | 1482 | dev_priv->gart_info.table_mask = DMA_BIT_MASK(32); |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 1483 | /* if we have an offset set from userspace */ |
Dave Airlie | f2b04cd | 2007-05-08 15:19:23 +1000 | [diff] [blame] | 1484 | if (dev_priv->pcigart_offset_set) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1485 | dev_priv->gart_info.bus_addr = |
Benjamin Herrenschmidt | 41c2e75 | 2009-02-02 16:55:47 +1100 | [diff] [blame] | 1486 | (resource_size_t)dev_priv->pcigart_offset + dev_priv->fb_location; |
Dave Airlie | f26c473 | 2006-01-02 17:18:39 +1100 | [diff] [blame] | 1487 | dev_priv->gart_info.mapping.offset = |
Dave Airlie | 7fc8686 | 2007-11-05 10:45:27 +1000 | [diff] [blame] | 1488 | dev_priv->pcigart_offset + dev_priv->fb_aper_offset; |
Dave Airlie | f26c473 | 2006-01-02 17:18:39 +1100 | [diff] [blame] | 1489 | dev_priv->gart_info.mapping.size = |
Dave Airlie | f2b04cd | 2007-05-08 15:19:23 +1000 | [diff] [blame] | 1490 | dev_priv->gart_info.table_size; |
Dave Airlie | f26c473 | 2006-01-02 17:18:39 +1100 | [diff] [blame] | 1491 | |
Dave Airlie | 242e3df | 2008-07-15 15:48:05 +1000 | [diff] [blame] | 1492 | drm_core_ioremap_wc(&dev_priv->gart_info.mapping, dev); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1493 | dev_priv->gart_info.addr = |
Dave Airlie | f26c473 | 2006-01-02 17:18:39 +1100 | [diff] [blame] | 1494 | dev_priv->gart_info.mapping.handle; |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 1495 | |
Dave Airlie | f2b04cd | 2007-05-08 15:19:23 +1000 | [diff] [blame] | 1496 | if (dev_priv->flags & RADEON_IS_PCIE) |
| 1497 | dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_PCIE; |
| 1498 | else |
| 1499 | dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_PCI; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1500 | dev_priv->gart_info.gart_table_location = |
| 1501 | DRM_ATI_GART_FB; |
| 1502 | |
Dave Airlie | f26c473 | 2006-01-02 17:18:39 +1100 | [diff] [blame] | 1503 | DRM_DEBUG("Setting phys_pci_gart to %p %08lX\n", |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1504 | dev_priv->gart_info.addr, |
| 1505 | dev_priv->pcigart_offset); |
| 1506 | } else { |
Dave Airlie | f2b04cd | 2007-05-08 15:19:23 +1000 | [diff] [blame] | 1507 | if (dev_priv->flags & RADEON_IS_IGPGART) |
| 1508 | dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_IGP; |
| 1509 | else |
| 1510 | dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_PCI; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1511 | dev_priv->gart_info.gart_table_location = |
| 1512 | DRM_ATI_GART_MAIN; |
Dave Airlie | f26c473 | 2006-01-02 17:18:39 +1100 | [diff] [blame] | 1513 | dev_priv->gart_info.addr = NULL; |
| 1514 | dev_priv->gart_info.bus_addr = 0; |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1515 | if (dev_priv->flags & RADEON_IS_PCIE) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1516 | DRM_ERROR |
| 1517 | ("Cannot use PCI Express without GART in FB memory\n"); |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 1518 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1519 | return -EINVAL; |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 1520 | } |
| 1521 | } |
| 1522 | |
David Miller | 6abf6bb | 2009-02-14 01:51:07 -0800 | [diff] [blame] | 1523 | sctrl = RADEON_READ(RADEON_SURFACE_CNTL); |
| 1524 | RADEON_WRITE(RADEON_SURFACE_CNTL, 0); |
Alex Deucher | c1556f7 | 2009-02-25 16:57:49 -0500 | [diff] [blame] | 1525 | if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS600) |
| 1526 | ret = r600_page_table_init(dev); |
| 1527 | else |
| 1528 | ret = drm_ati_pcigart_init(dev, &dev_priv->gart_info); |
David Miller | 6abf6bb | 2009-02-14 01:51:07 -0800 | [diff] [blame] | 1529 | RADEON_WRITE(RADEON_SURFACE_CNTL, sctrl); |
| 1530 | |
| 1531 | if (!ret) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1532 | DRM_ERROR("failed to init PCI GART!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1534 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | } |
| 1536 | |
David Miller | 6abf6bb | 2009-02-14 01:51:07 -0800 | [diff] [blame] | 1537 | ret = radeon_setup_pcigart_surface(dev_priv); |
| 1538 | if (ret) { |
| 1539 | DRM_ERROR("failed to setup GART surface!\n"); |
Alex Deucher | c1556f7 | 2009-02-25 16:57:49 -0500 | [diff] [blame] | 1540 | if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS600) |
| 1541 | r600_page_table_cleanup(dev, &dev_priv->gart_info); |
| 1542 | else |
| 1543 | drm_ati_pcigart_cleanup(dev, &dev_priv->gart_info); |
David Miller | 6abf6bb | 2009-02-14 01:51:07 -0800 | [diff] [blame] | 1544 | radeon_do_cleanup_cp(dev); |
| 1545 | return ret; |
| 1546 | } |
| 1547 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | /* Turn on PCI GART */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1549 | radeon_set_pcigart(dev_priv, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | } |
| 1551 | |
Ben Hutchings | 70967ab | 2009-08-29 14:53:51 +0100 | [diff] [blame] | 1552 | if (!dev_priv->me_fw) { |
| 1553 | int err = radeon_cp_init_microcode(dev_priv); |
| 1554 | if (err) { |
| 1555 | DRM_ERROR("Failed to load firmware!\n"); |
| 1556 | radeon_do_cleanup_cp(dev); |
| 1557 | return err; |
| 1558 | } |
| 1559 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1560 | radeon_cp_load_microcode(dev_priv); |
etienne | 3d16118 | 2009-02-20 09:44:45 +1000 | [diff] [blame] | 1561 | radeon_cp_init_ring_buffer(dev, dev_priv, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 | |
| 1563 | dev_priv->last_buf = 0; |
| 1564 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1565 | radeon_do_engine_reset(dev); |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 1566 | radeon_test_writeback(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | |
| 1568 | return 0; |
| 1569 | } |
| 1570 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 1571 | static int radeon_do_cleanup_cp(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | { |
| 1573 | drm_radeon_private_t *dev_priv = dev->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1574 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | |
| 1576 | /* Make sure interrupts are disabled here because the uninstall ioctl |
| 1577 | * may not have been called from userspace and after dev_private |
| 1578 | * is freed, it's too late. |
| 1579 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1580 | if (dev->irq_enabled) |
| 1581 | drm_irq_uninstall(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | |
| 1583 | #if __OS_HAS_AGP |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1584 | if (dev_priv->flags & RADEON_IS_AGP) { |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 1585 | if (dev_priv->cp_ring != NULL) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1586 | drm_core_ioremapfree(dev_priv->cp_ring, dev); |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 1587 | dev_priv->cp_ring = NULL; |
| 1588 | } |
| 1589 | if (dev_priv->ring_rptr != NULL) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1590 | drm_core_ioremapfree(dev_priv->ring_rptr, dev); |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 1591 | dev_priv->ring_rptr = NULL; |
| 1592 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1593 | if (dev->agp_buffer_map != NULL) { |
| 1594 | drm_core_ioremapfree(dev->agp_buffer_map, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | dev->agp_buffer_map = NULL; |
| 1596 | } |
| 1597 | } else |
| 1598 | #endif |
| 1599 | { |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 1600 | |
| 1601 | if (dev_priv->gart_info.bus_addr) { |
| 1602 | /* Turn off PCI GART */ |
| 1603 | radeon_set_pcigart(dev_priv, 0); |
Alex Deucher | c1556f7 | 2009-02-25 16:57:49 -0500 | [diff] [blame] | 1604 | if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS600) |
| 1605 | r600_page_table_cleanup(dev, &dev_priv->gart_info); |
| 1606 | else { |
| 1607 | if (!drm_ati_pcigart_cleanup(dev, &dev_priv->gart_info)) |
| 1608 | DRM_ERROR("failed to cleanup PCI GART!\n"); |
| 1609 | } |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 1610 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1611 | |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 1612 | if (dev_priv->gart_info.gart_table_location == DRM_ATI_GART_FB) |
| 1613 | { |
Dave Airlie | f26c473 | 2006-01-02 17:18:39 +1100 | [diff] [blame] | 1614 | drm_core_ioremapfree(&dev_priv->gart_info.mapping, dev); |
Hannes Eder | 8f497aa | 2009-03-05 20:14:18 +0100 | [diff] [blame] | 1615 | dev_priv->gart_info.addr = NULL; |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 1616 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | /* only clear to the start of flags */ |
| 1619 | memset(dev_priv, 0, offsetof(drm_radeon_private_t, flags)); |
| 1620 | |
| 1621 | return 0; |
| 1622 | } |
| 1623 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1624 | /* This code will reinit the Radeon CP hardware after a resume from disc. |
| 1625 | * AFAIK, it would be very difficult to pickle the state at suspend time, so |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1626 | * here we make sure that all Radeon hardware initialisation is re-done without |
| 1627 | * affecting running applications. |
| 1628 | * |
| 1629 | * Charl P. Botha <http://cpbotha.net> |
| 1630 | */ |
etienne | 3d16118 | 2009-02-20 09:44:45 +1000 | [diff] [blame] | 1631 | static int radeon_do_resume_cp(struct drm_device *dev, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | { |
| 1633 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 1634 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1635 | if (!dev_priv) { |
| 1636 | DRM_ERROR("Called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1637 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | DRM_DEBUG("Starting radeon_do_resume_cp()\n"); |
| 1641 | |
| 1642 | #if __OS_HAS_AGP |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1643 | if (dev_priv->flags & RADEON_IS_AGP) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | /* Turn off PCI GART */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1645 | radeon_set_pcigart(dev_priv, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | } else |
| 1647 | #endif |
| 1648 | { |
| 1649 | /* Turn on PCI GART */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1650 | radeon_set_pcigart(dev_priv, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | } |
| 1652 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1653 | radeon_cp_load_microcode(dev_priv); |
etienne | 3d16118 | 2009-02-20 09:44:45 +1000 | [diff] [blame] | 1654 | radeon_cp_init_ring_buffer(dev, dev_priv, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | |
Dave Airlie | 566d84d | 2010-02-24 17:17:13 +1000 | [diff] [blame] | 1656 | dev_priv->have_z_offset = 0; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1657 | radeon_do_engine_reset(dev); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1658 | radeon_irq_set_state(dev, RADEON_SW_INT_ENABLE, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | |
| 1660 | DRM_DEBUG("radeon_do_resume_cp() complete\n"); |
| 1661 | |
| 1662 | return 0; |
| 1663 | } |
| 1664 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1665 | int radeon_cp_init(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | { |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 1667 | drm_radeon_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1668 | drm_radeon_init_t *init = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1670 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1672 | if (init->func == RADEON_INIT_R300_CP) |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 1673 | r300_init_reg_flags(dev); |
Dave Airlie | 414ed53 | 2005-08-16 20:43:16 +1000 | [diff] [blame] | 1674 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1675 | switch (init->func) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | case RADEON_INIT_CP: |
| 1677 | case RADEON_INIT_R200_CP: |
| 1678 | case RADEON_INIT_R300_CP: |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1679 | return radeon_do_init_cp(dev, init, file_priv); |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 1680 | case RADEON_INIT_R600_CP: |
| 1681 | return r600_do_init_cp(dev, init, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | case RADEON_CLEANUP_CP: |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 1683 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) |
| 1684 | return r600_do_cleanup_cp(dev); |
| 1685 | else |
| 1686 | return radeon_do_cleanup_cp(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1687 | } |
| 1688 | |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1689 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | } |
| 1691 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1692 | int radeon_cp_start(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | drm_radeon_private_t *dev_priv = dev->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1695 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1697 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1699 | if (dev_priv->cp_running) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 1700 | DRM_DEBUG("while CP running\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | return 0; |
| 1702 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1703 | if (dev_priv->cp_mode == RADEON_CSQ_PRIDIS_INDDIS) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 1704 | DRM_DEBUG("called with bogus CP mode (%d)\n", |
| 1705 | dev_priv->cp_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | return 0; |
| 1707 | } |
| 1708 | |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 1709 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) |
| 1710 | r600_do_cp_start(dev_priv); |
| 1711 | else |
| 1712 | radeon_do_cp_start(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | |
| 1714 | return 0; |
| 1715 | } |
| 1716 | |
| 1717 | /* Stop the CP. The engine must have been idled before calling this |
| 1718 | * routine. |
| 1719 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1720 | int radeon_cp_stop(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | drm_radeon_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1723 | drm_radeon_cp_stop_t *stop = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | int ret; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1725 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1727 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | if (!dev_priv->cp_running) |
| 1730 | return 0; |
| 1731 | |
| 1732 | /* Flush any pending CP commands. This ensures any outstanding |
| 1733 | * commands are exectuted by the engine before we turn it off. |
| 1734 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1735 | if (stop->flush) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1736 | radeon_do_cp_flush(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | /* If we fail to make the engine go idle, we return an error |
| 1740 | * code so that the DRM ioctl wrapper can try again. |
| 1741 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1742 | if (stop->idle) { |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 1743 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) |
| 1744 | ret = r600_do_cp_idle(dev_priv); |
| 1745 | else |
| 1746 | ret = radeon_do_cp_idle(dev_priv); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1747 | if (ret) |
| 1748 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | /* Finally, we can turn off the CP. If the engine isn't idle, |
| 1752 | * we will get some dropped triangles as they won't be fully |
| 1753 | * rendered before the CP is shut down. |
| 1754 | */ |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 1755 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) |
| 1756 | r600_do_cp_stop(dev_priv); |
| 1757 | else |
| 1758 | radeon_do_cp_stop(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | |
| 1760 | /* Reset the engine */ |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 1761 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) |
| 1762 | r600_do_engine_reset(dev); |
| 1763 | else |
| 1764 | radeon_do_engine_reset(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | |
| 1766 | return 0; |
| 1767 | } |
| 1768 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 1769 | void radeon_do_release(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | { |
| 1771 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 1772 | int i, ret; |
| 1773 | |
| 1774 | if (dev_priv) { |
| 1775 | if (dev_priv->cp_running) { |
| 1776 | /* Stop the cp */ |
Dave Airlie | 53c379e | 2009-03-09 12:12:28 +1000 | [diff] [blame] | 1777 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) { |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 1778 | while ((ret = r600_do_cp_idle(dev_priv)) != 0) { |
| 1779 | DRM_DEBUG("radeon_do_cp_idle %d\n", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | #ifdef __linux__ |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 1781 | schedule(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | #else |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 1783 | tsleep(&ret, PZERO, "rdnrel", 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | #endif |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 1785 | } |
| 1786 | } else { |
| 1787 | while ((ret = radeon_do_cp_idle(dev_priv)) != 0) { |
| 1788 | DRM_DEBUG("radeon_do_cp_idle %d\n", ret); |
| 1789 | #ifdef __linux__ |
| 1790 | schedule(); |
| 1791 | #else |
| 1792 | tsleep(&ret, PZERO, "rdnrel", 1); |
| 1793 | #endif |
| 1794 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | } |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 1796 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) { |
| 1797 | r600_do_cp_stop(dev_priv); |
| 1798 | r600_do_engine_reset(dev); |
| 1799 | } else { |
| 1800 | radeon_do_cp_stop(dev_priv); |
| 1801 | radeon_do_engine_reset(dev); |
| 1802 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 1805 | if ((dev_priv->flags & RADEON_FAMILY_MASK) < CHIP_R600) { |
| 1806 | /* Disable *all* interrupts */ |
| 1807 | if (dev_priv->mmio) /* remove this after permanent addmaps */ |
| 1808 | RADEON_WRITE(RADEON_GEN_INT_CNTL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 1810 | if (dev_priv->mmio) { /* remove all surfaces */ |
| 1811 | for (i = 0; i < RADEON_MAX_SURFACES; i++) { |
| 1812 | RADEON_WRITE(RADEON_SURFACE0_INFO + 16 * i, 0); |
| 1813 | RADEON_WRITE(RADEON_SURFACE0_LOWER_BOUND + |
| 1814 | 16 * i, 0); |
| 1815 | RADEON_WRITE(RADEON_SURFACE0_UPPER_BOUND + |
| 1816 | 16 * i, 0); |
| 1817 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | } |
| 1819 | } |
| 1820 | |
| 1821 | /* Free memory heap structures */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1822 | radeon_mem_takedown(&(dev_priv->gart_heap)); |
| 1823 | radeon_mem_takedown(&(dev_priv->fb_heap)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | |
| 1825 | /* deallocate kernel resources */ |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 1826 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) |
| 1827 | r600_do_cleanup_cp(dev); |
| 1828 | else |
| 1829 | radeon_do_cleanup_cp(dev); |
Jesper Juhl | c69a6ca | 2012-04-09 22:49:57 +0200 | [diff] [blame] | 1830 | release_firmware(dev_priv->me_fw); |
| 1831 | dev_priv->me_fw = NULL; |
| 1832 | release_firmware(dev_priv->pfp_fw); |
| 1833 | dev_priv->pfp_fw = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | } |
| 1835 | } |
| 1836 | |
| 1837 | /* Just reset the CP ring. Called as part of an X Server engine reset. |
| 1838 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1839 | int radeon_cp_reset(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | drm_radeon_private_t *dev_priv = dev->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1842 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1844 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1846 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 1847 | DRM_DEBUG("called before init done\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1848 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | } |
| 1850 | |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 1851 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) |
| 1852 | r600_do_cp_reset(dev_priv); |
| 1853 | else |
| 1854 | radeon_do_cp_reset(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | |
| 1856 | /* The CP is no longer running after an engine reset */ |
| 1857 | dev_priv->cp_running = 0; |
| 1858 | |
| 1859 | return 0; |
| 1860 | } |
| 1861 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1862 | int radeon_cp_idle(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | drm_radeon_private_t *dev_priv = dev->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1865 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1867 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 1869 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) |
| 1870 | return r600_do_cp_idle(dev_priv); |
| 1871 | else |
| 1872 | return radeon_do_cp_idle(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | /* Added by Charl P. Botha to call radeon_do_resume_cp(). |
| 1876 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1877 | int radeon_cp_resume(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | { |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 1879 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 1880 | DRM_DEBUG("\n"); |
| 1881 | |
| 1882 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) |
| 1883 | return r600_do_resume_cp(dev, file_priv); |
| 1884 | else |
| 1885 | return radeon_do_resume_cp(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | } |
| 1887 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1888 | int radeon_engine_reset(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | { |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 1890 | drm_radeon_private_t *dev_priv = dev->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1891 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1893 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 1895 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) |
| 1896 | return r600_do_engine_reset(dev); |
| 1897 | else |
| 1898 | return radeon_do_engine_reset(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | } |
| 1900 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | /* ================================================================ |
| 1902 | * Fullscreen mode |
| 1903 | */ |
| 1904 | |
| 1905 | /* KW: Deprecated to say the least: |
| 1906 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1907 | int radeon_fullscreen(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | { |
| 1909 | return 0; |
| 1910 | } |
| 1911 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | /* ================================================================ |
| 1913 | * Freelist management |
| 1914 | */ |
| 1915 | |
| 1916 | /* Original comment: FIXME: ROTATE_BUFS is a hack to cycle through |
| 1917 | * bufs until freelist code is used. Note this hides a problem with |
| 1918 | * the scratch register * (used to keep track of last buffer |
| 1919 | * completed) being written to before * the last buffer has actually |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1920 | * completed rendering. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | * |
| 1922 | * KW: It's also a good way to find free buffers quickly. |
| 1923 | * |
| 1924 | * KW: Ideally this loop wouldn't exist, and freelist_get wouldn't |
| 1925 | * sleep. However, bugs in older versions of radeon_accel.c mean that |
| 1926 | * we essentially have to do this, else old clients will break. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1927 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | * However, it does leave open a potential deadlock where all the |
| 1929 | * buffers are held by other clients, which can't release them because |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1930 | * they can't get the lock. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | */ |
| 1932 | |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 1933 | struct drm_buf *radeon_freelist_get(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | { |
Dave Airlie | cdd55a2 | 2007-07-11 16:32:08 +1000 | [diff] [blame] | 1935 | struct drm_device_dma *dma = dev->dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 1937 | drm_radeon_buf_priv_t *buf_priv; |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 1938 | struct drm_buf *buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | int i, t; |
| 1940 | int start; |
| 1941 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1942 | if (++dev_priv->last_buf >= dma->buf_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | dev_priv->last_buf = 0; |
| 1944 | |
| 1945 | start = dev_priv->last_buf; |
| 1946 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1947 | for (t = 0; t < dev_priv->usec_timeout; t++) { |
David Miller | b07fa02 | 2009-02-12 02:15:37 -0800 | [diff] [blame] | 1948 | u32 done_age = GET_SCRATCH(dev_priv, 1); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1949 | DRM_DEBUG("done_age = %d\n", done_age); |
Robert Noland | 0a5c1e6 | 2009-10-20 07:23:07 -0500 | [diff] [blame] | 1950 | for (i = 0; i < dma->buf_count; i++) { |
| 1951 | buf = dma->buflist[start]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | buf_priv = buf->dev_private; |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1953 | if (buf->file_priv == NULL || (buf->pending && |
| 1954 | buf_priv->age <= |
| 1955 | done_age)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | dev_priv->stats.requested_bufs++; |
| 1957 | buf->pending = 0; |
| 1958 | return buf; |
| 1959 | } |
Robert Noland | 0a5c1e6 | 2009-10-20 07:23:07 -0500 | [diff] [blame] | 1960 | if (++start >= dma->buf_count) |
| 1961 | start = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | if (t) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1965 | DRM_UDELAY(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | dev_priv->stats.freelist_loops++; |
| 1967 | } |
| 1968 | } |
| 1969 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | return NULL; |
| 1971 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1972 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 1973 | void radeon_freelist_reset(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | { |
Dave Airlie | cdd55a2 | 2007-07-11 16:32:08 +1000 | [diff] [blame] | 1975 | struct drm_device_dma *dma = dev->dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 1977 | int i; |
| 1978 | |
| 1979 | dev_priv->last_buf = 0; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1980 | for (i = 0; i < dma->buf_count; i++) { |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 1981 | struct drm_buf *buf = dma->buflist[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | drm_radeon_buf_priv_t *buf_priv = buf->dev_private; |
| 1983 | buf_priv->age = 0; |
| 1984 | } |
| 1985 | } |
| 1986 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | /* ================================================================ |
| 1988 | * CP command submission |
| 1989 | */ |
| 1990 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1991 | int radeon_wait_ring(drm_radeon_private_t * dev_priv, int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | { |
| 1993 | drm_radeon_ring_buffer_t *ring = &dev_priv->ring; |
| 1994 | int i; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1995 | u32 last_head = GET_RING_HEAD(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1997 | for (i = 0; i < dev_priv->usec_timeout; i++) { |
| 1998 | u32 head = GET_RING_HEAD(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | |
| 2000 | ring->space = (head - ring->tail) * sizeof(u32); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 2001 | if (ring->space <= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | ring->space += ring->size; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 2003 | if (ring->space > n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | return 0; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 2005 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE; |
| 2007 | |
| 2008 | if (head != last_head) |
| 2009 | i = 0; |
| 2010 | last_head = head; |
| 2011 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 2012 | DRM_UDELAY(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | /* FIXME: This return value is ignored in the BEGIN_RING macro! */ |
| 2016 | #if RADEON_FIFO_DEBUG |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 2017 | radeon_status(dev_priv); |
| 2018 | DRM_ERROR("failed!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | #endif |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 2020 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 2023 | static int radeon_cp_get_buffers(struct drm_device *dev, |
| 2024 | struct drm_file *file_priv, |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 2025 | struct drm_dma * d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | { |
| 2027 | int i; |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 2028 | struct drm_buf *buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 2030 | for (i = d->granted_count; i < d->request_count; i++) { |
| 2031 | buf = radeon_freelist_get(dev); |
| 2032 | if (!buf) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 2033 | return -EBUSY; /* NOTE: broken client */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 2035 | buf->file_priv = file_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 2037 | if (DRM_COPY_TO_USER(&d->request_indices[i], &buf->idx, |
| 2038 | sizeof(buf->idx))) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 2039 | return -EFAULT; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 2040 | if (DRM_COPY_TO_USER(&d->request_sizes[i], &buf->total, |
| 2041 | sizeof(buf->total))) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 2042 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | |
| 2044 | d->granted_count++; |
| 2045 | } |
| 2046 | return 0; |
| 2047 | } |
| 2048 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 2049 | int radeon_cp_buffers(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | { |
Dave Airlie | cdd55a2 | 2007-07-11 16:32:08 +1000 | [diff] [blame] | 2051 | struct drm_device_dma *dma = dev->dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | int ret = 0; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 2053 | struct drm_dma *d = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 2055 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | /* Please don't send us buffers. |
| 2058 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 2059 | if (d->send_count != 0) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 2060 | DRM_ERROR("Process %d trying to send %d buffers via drmDMA\n", |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 2061 | DRM_CURRENTPID, d->send_count); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 2062 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | } |
| 2064 | |
| 2065 | /* We'll send you buffers. |
| 2066 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 2067 | if (d->request_count < 0 || d->request_count > dma->buf_count) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 2068 | DRM_ERROR("Process %d trying to get %d buffers (of %d max)\n", |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 2069 | DRM_CURRENTPID, d->request_count, dma->buf_count); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 2070 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | } |
| 2072 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 2073 | d->granted_count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 2075 | if (d->request_count) { |
| 2076 | ret = radeon_cp_get_buffers(dev, file_priv, d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2077 | } |
| 2078 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | return ret; |
| 2080 | } |
| 2081 | |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 2082 | int radeon_driver_load(struct drm_device *dev, unsigned long flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | { |
| 2084 | drm_radeon_private_t *dev_priv; |
| 2085 | int ret = 0; |
| 2086 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 2087 | dev_priv = kzalloc(sizeof(drm_radeon_private_t), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | if (dev_priv == NULL) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 2089 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | dev->dev_private = (void *)dev_priv; |
| 2092 | dev_priv->flags = flags; |
| 2093 | |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 2094 | switch (flags & RADEON_FAMILY_MASK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | case CHIP_R100: |
| 2096 | case CHIP_RV200: |
| 2097 | case CHIP_R200: |
| 2098 | case CHIP_R300: |
Dave Airlie | b15ec36 | 2006-08-19 17:43:52 +1000 | [diff] [blame] | 2099 | case CHIP_R350: |
Dave Airlie | 414ed53 | 2005-08-16 20:43:16 +1000 | [diff] [blame] | 2100 | case CHIP_R420: |
Alex Deucher | edc6f38 | 2008-10-17 09:21:45 +1000 | [diff] [blame] | 2101 | case CHIP_R423: |
Dave Airlie | b15ec36 | 2006-08-19 17:43:52 +1000 | [diff] [blame] | 2102 | case CHIP_RV410: |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 2103 | case CHIP_RV515: |
| 2104 | case CHIP_R520: |
| 2105 | case CHIP_RV570: |
| 2106 | case CHIP_R580: |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 2107 | dev_priv->flags |= RADEON_HAS_HIERZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | break; |
| 2109 | default: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 2110 | /* all other chips have no hierarchical z buffer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | break; |
| 2112 | } |
Dave Airlie | 414ed53 | 2005-08-16 20:43:16 +1000 | [diff] [blame] | 2113 | |
Dave Airlie | 466e69b | 2011-12-19 11:15:29 +0000 | [diff] [blame] | 2114 | pci_set_master(dev->pdev); |
| 2115 | |
Dave Airlie | 8410ea3 | 2010-12-15 03:16:38 +1000 | [diff] [blame] | 2116 | if (drm_pci_device_is_agp(dev)) |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 2117 | dev_priv->flags |= RADEON_IS_AGP; |
Jon Mason | 58b6542 | 2011-06-27 16:07:50 +0000 | [diff] [blame] | 2118 | else if (pci_is_pcie(dev->pdev)) |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 2119 | dev_priv->flags |= RADEON_IS_PCIE; |
Dave Airlie | b15ec36 | 2006-08-19 17:43:52 +1000 | [diff] [blame] | 2120 | else |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 2121 | dev_priv->flags |= RADEON_IS_PCI; |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 2122 | |
Jordan Crouse | 01d73a6 | 2010-05-27 13:40:24 -0600 | [diff] [blame] | 2123 | ret = drm_addmap(dev, pci_resource_start(dev->pdev, 2), |
| 2124 | pci_resource_len(dev->pdev, 2), _DRM_REGISTERS, |
Dave Airlie | 78538bf | 2008-11-11 17:56:16 +1000 | [diff] [blame] | 2125 | _DRM_READ_ONLY | _DRM_DRIVER, &dev_priv->mmio); |
| 2126 | if (ret != 0) |
| 2127 | return ret; |
| 2128 | |
Keith Packard | 5244021 | 2008-11-18 09:30:25 -0800 | [diff] [blame] | 2129 | ret = drm_vblank_init(dev, 2); |
| 2130 | if (ret) { |
| 2131 | radeon_driver_unload(dev); |
| 2132 | return ret; |
| 2133 | } |
| 2134 | |
Dave Airlie | 414ed53 | 2005-08-16 20:43:16 +1000 | [diff] [blame] | 2135 | DRM_DEBUG("%s card detected\n", |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 2136 | ((dev_priv->flags & RADEON_IS_AGP) ? "AGP" : (((dev_priv->flags & RADEON_IS_PCIE) ? "PCIE" : "PCI")))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | return ret; |
| 2138 | } |
| 2139 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 2140 | int radeon_master_create(struct drm_device *dev, struct drm_master *master) |
| 2141 | { |
| 2142 | struct drm_radeon_master_private *master_priv; |
| 2143 | unsigned long sareapage; |
| 2144 | int ret; |
| 2145 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 2146 | master_priv = kzalloc(sizeof(*master_priv), GFP_KERNEL); |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 2147 | if (!master_priv) |
| 2148 | return -ENOMEM; |
| 2149 | |
| 2150 | /* prebuild the SAREA */ |
Dave Airlie | bdf539a | 2008-12-18 16:56:11 +1000 | [diff] [blame] | 2151 | sareapage = max_t(unsigned long, SAREA_MAX, PAGE_SIZE); |
Dave Airlie | df4f7fe | 2009-06-11 16:16:10 +1000 | [diff] [blame] | 2152 | ret = drm_addmap(dev, 0, sareapage, _DRM_SHM, _DRM_CONTAINS_LOCK, |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 2153 | &master_priv->sarea); |
| 2154 | if (ret) { |
| 2155 | DRM_ERROR("SAREA setup failed\n"); |
Jiri Slaby | 5eb2261 | 2010-01-06 17:39:31 +0100 | [diff] [blame] | 2156 | kfree(master_priv); |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 2157 | return ret; |
| 2158 | } |
| 2159 | master_priv->sarea_priv = master_priv->sarea->handle + sizeof(struct drm_sarea); |
| 2160 | master_priv->sarea_priv->pfCurrentPage = 0; |
| 2161 | |
| 2162 | master->driver_priv = master_priv; |
| 2163 | return 0; |
| 2164 | } |
| 2165 | |
| 2166 | void radeon_master_destroy(struct drm_device *dev, struct drm_master *master) |
| 2167 | { |
| 2168 | struct drm_radeon_master_private *master_priv = master->driver_priv; |
| 2169 | |
| 2170 | if (!master_priv) |
| 2171 | return; |
| 2172 | |
| 2173 | if (master_priv->sarea_priv && |
| 2174 | master_priv->sarea_priv->pfCurrentPage != 0) |
| 2175 | radeon_cp_dispatch_flip(dev, master); |
| 2176 | |
| 2177 | master_priv->sarea_priv = NULL; |
| 2178 | if (master_priv->sarea) |
Dave Airlie | 4e74f36 | 2008-12-19 10:23:14 +1100 | [diff] [blame] | 2179 | drm_rmmap_locked(dev, master_priv->sarea); |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 2180 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 2181 | kfree(master_priv); |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 2182 | |
| 2183 | master->driver_priv = NULL; |
| 2184 | } |
| 2185 | |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 2186 | /* Create mappings for registers and framebuffer so userland doesn't necessarily |
| 2187 | * have to find them. |
| 2188 | */ |
| 2189 | int radeon_driver_firstopen(struct drm_device *dev) |
Dave Airlie | 836cf04 | 2005-07-10 19:27:04 +1000 | [diff] [blame] | 2190 | { |
| 2191 | int ret; |
| 2192 | drm_local_map_t *map; |
| 2193 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 2194 | |
Dave Airlie | f2b04cd | 2007-05-08 15:19:23 +1000 | [diff] [blame] | 2195 | dev_priv->gart_info.table_size = RADEON_PCIGART_TABLE_SIZE; |
| 2196 | |
Jordan Crouse | 01d73a6 | 2010-05-27 13:40:24 -0600 | [diff] [blame] | 2197 | dev_priv->fb_aper_offset = pci_resource_start(dev->pdev, 0); |
Dave Airlie | 7fc8686 | 2007-11-05 10:45:27 +1000 | [diff] [blame] | 2198 | ret = drm_addmap(dev, dev_priv->fb_aper_offset, |
Jordan Crouse | 01d73a6 | 2010-05-27 13:40:24 -0600 | [diff] [blame] | 2199 | pci_resource_len(dev->pdev, 0), _DRM_FRAME_BUFFER, |
Dave Airlie | 836cf04 | 2005-07-10 19:27:04 +1000 | [diff] [blame] | 2200 | _DRM_WRITE_COMBINING, &map); |
| 2201 | if (ret != 0) |
| 2202 | return ret; |
| 2203 | |
| 2204 | return 0; |
| 2205 | } |
| 2206 | |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 2207 | int radeon_driver_unload(struct drm_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2208 | { |
| 2209 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 2210 | |
| 2211 | DRM_DEBUG("\n"); |
Dave Airlie | 78538bf | 2008-11-11 17:56:16 +1000 | [diff] [blame] | 2212 | |
| 2213 | drm_rmmap(dev, dev_priv->mmio); |
| 2214 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 2215 | kfree(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | |
| 2217 | dev->dev_private = NULL; |
| 2218 | return 0; |
| 2219 | } |
Dave Airlie | 4247ca9 | 2009-02-20 13:28:34 +1000 | [diff] [blame] | 2220 | |
| 2221 | void radeon_commit_ring(drm_radeon_private_t *dev_priv) |
| 2222 | { |
| 2223 | int i; |
| 2224 | u32 *ring; |
| 2225 | int tail_aligned; |
| 2226 | |
| 2227 | /* check if the ring is padded out to 16-dword alignment */ |
| 2228 | |
Dave Airlie | 9863871 | 2009-06-04 07:08:13 +1000 | [diff] [blame] | 2229 | tail_aligned = dev_priv->ring.tail & (RADEON_RING_ALIGN-1); |
Dave Airlie | 4247ca9 | 2009-02-20 13:28:34 +1000 | [diff] [blame] | 2230 | if (tail_aligned) { |
Dave Airlie | 9863871 | 2009-06-04 07:08:13 +1000 | [diff] [blame] | 2231 | int num_p2 = RADEON_RING_ALIGN - tail_aligned; |
Dave Airlie | 4247ca9 | 2009-02-20 13:28:34 +1000 | [diff] [blame] | 2232 | |
| 2233 | ring = dev_priv->ring.start; |
| 2234 | /* pad with some CP_PACKET2 */ |
| 2235 | for (i = 0; i < num_p2; i++) |
| 2236 | ring[dev_priv->ring.tail + i] = CP_PACKET2(); |
| 2237 | |
| 2238 | dev_priv->ring.tail += i; |
| 2239 | |
| 2240 | dev_priv->ring.space -= num_p2 * sizeof(u32); |
| 2241 | } |
| 2242 | |
| 2243 | dev_priv->ring.tail &= dev_priv->ring.tail_mask; |
| 2244 | |
| 2245 | DRM_MEMORYBARRIER(); |
| 2246 | GET_RING_HEAD( dev_priv ); |
| 2247 | |
Alex Deucher | c05ce08 | 2009-02-24 16:22:29 -0500 | [diff] [blame] | 2248 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) { |
| 2249 | RADEON_WRITE(R600_CP_RB_WPTR, dev_priv->ring.tail); |
| 2250 | /* read from PCI bus to ensure correct posting */ |
| 2251 | RADEON_READ(R600_CP_RB_RPTR); |
| 2252 | } else { |
| 2253 | RADEON_WRITE(RADEON_CP_RB_WPTR, dev_priv->ring.tail); |
| 2254 | /* read from PCI bus to ensure correct posting */ |
| 2255 | RADEON_READ(RADEON_CP_RB_RPTR); |
| 2256 | } |
Dave Airlie | 4247ca9 | 2009-02-20 13:28:34 +1000 | [diff] [blame] | 2257 | } |