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. |
| 5 | * All Rights Reserved. |
| 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | * copy of this software and associated documentation files (the "Software"), |
| 9 | * to deal in the Software without restriction, including without limitation |
| 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | * and/or sell copies of the Software, and to permit persons to whom the |
| 12 | * Software is furnished to do so, subject to the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the next |
| 15 | * paragraph) shall be included in all copies or substantial portions of the |
| 16 | * Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 21 | * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 22 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 23 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 24 | * DEALINGS IN THE SOFTWARE. |
| 25 | * |
| 26 | * Authors: |
| 27 | * Kevin E. Martin <martin@valinux.com> |
| 28 | * Gareth Hughes <gareth@valinux.com> |
| 29 | */ |
| 30 | |
| 31 | #include "drmP.h" |
| 32 | #include "drm.h" |
| 33 | #include "radeon_drm.h" |
| 34 | #include "radeon_drv.h" |
Dave Airlie | 414ed53 | 2005-08-16 20:43:16 +1000 | [diff] [blame] | 35 | #include "r300_reg.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Alex Deucher | 9f18409 | 2008-05-28 11:21:25 +1000 | [diff] [blame] | 37 | #include "radeon_microcode.h" |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #define RADEON_FIFO_DEBUG 0 |
| 40 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 41 | static int radeon_do_cleanup_cp(struct drm_device * dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 43 | static u32 RADEON_READ_MCIND(drm_radeon_private_t *dev_priv, int addr) |
| 44 | { |
| 45 | u32 ret; |
| 46 | RADEON_WRITE(R520_MC_IND_INDEX, 0x7f0000 | (addr & 0xff)); |
| 47 | ret = RADEON_READ(R520_MC_IND_DATA); |
| 48 | RADEON_WRITE(R520_MC_IND_INDEX, 0); |
| 49 | return ret; |
| 50 | } |
| 51 | |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 52 | static u32 RS690_READ_MCIND(drm_radeon_private_t *dev_priv, int addr) |
| 53 | { |
| 54 | RADEON_WRITE(RS690_MC_INDEX, (addr & RS690_MC_INDEX_MASK)); |
| 55 | return RADEON_READ(RS690_MC_DATA); |
| 56 | } |
| 57 | |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 58 | u32 radeon_read_fb_location(drm_radeon_private_t *dev_priv) |
| 59 | { |
| 60 | |
| 61 | if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV515) |
| 62 | return RADEON_READ_MCIND(dev_priv, RV515_MC_FB_LOCATION); |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 63 | else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690) |
| 64 | return RS690_READ_MCIND(dev_priv, RS690_MC_FB_LOCATION); |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 65 | else if ((dev_priv->flags & RADEON_FAMILY_MASK) > CHIP_RV515) |
| 66 | return RADEON_READ_MCIND(dev_priv, R520_MC_FB_LOCATION); |
| 67 | else |
| 68 | return RADEON_READ(RADEON_MC_FB_LOCATION); |
| 69 | } |
| 70 | |
| 71 | static void radeon_write_fb_location(drm_radeon_private_t *dev_priv, u32 fb_loc) |
| 72 | { |
| 73 | if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV515) |
| 74 | RADEON_WRITE_MCIND(RV515_MC_FB_LOCATION, fb_loc); |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 75 | else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690) |
| 76 | RS690_WRITE_MCIND(RS690_MC_FB_LOCATION, fb_loc); |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 77 | else if ((dev_priv->flags & RADEON_FAMILY_MASK) > CHIP_RV515) |
| 78 | RADEON_WRITE_MCIND(R520_MC_FB_LOCATION, fb_loc); |
| 79 | else |
| 80 | RADEON_WRITE(RADEON_MC_FB_LOCATION, fb_loc); |
| 81 | } |
| 82 | |
| 83 | static void radeon_write_agp_location(drm_radeon_private_t *dev_priv, u32 agp_loc) |
| 84 | { |
| 85 | if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV515) |
| 86 | RADEON_WRITE_MCIND(RV515_MC_AGP_LOCATION, agp_loc); |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 87 | else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690) |
| 88 | RS690_WRITE_MCIND(RS690_MC_AGP_LOCATION, agp_loc); |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 89 | else if ((dev_priv->flags & RADEON_FAMILY_MASK) > CHIP_RV515) |
| 90 | RADEON_WRITE_MCIND(R520_MC_AGP_LOCATION, agp_loc); |
| 91 | else |
| 92 | RADEON_WRITE(RADEON_MC_AGP_LOCATION, agp_loc); |
| 93 | } |
| 94 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 95 | static int RADEON_READ_PLL(struct drm_device * dev, int addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | { |
| 97 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 98 | |
| 99 | RADEON_WRITE8(RADEON_CLOCK_CNTL_INDEX, addr & 0x1f); |
| 100 | return RADEON_READ(RADEON_CLOCK_CNTL_DATA); |
| 101 | } |
| 102 | |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 103 | 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] | 104 | { |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 105 | RADEON_WRITE8(RADEON_PCIE_INDEX, addr & 0xff); |
| 106 | return RADEON_READ(RADEON_PCIE_DATA); |
| 107 | } |
| 108 | |
Dave Airlie | f2b04cd | 2007-05-08 15:19:23 +1000 | [diff] [blame] | 109 | static u32 RADEON_READ_IGPGART(drm_radeon_private_t *dev_priv, int addr) |
| 110 | { |
| 111 | u32 ret; |
| 112 | RADEON_WRITE(RADEON_IGPGART_INDEX, addr & 0x7f); |
| 113 | ret = RADEON_READ(RADEON_IGPGART_DATA); |
| 114 | RADEON_WRITE(RADEON_IGPGART_INDEX, 0x7f); |
| 115 | return ret; |
| 116 | } |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | #if RADEON_FIFO_DEBUG |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 119 | static void radeon_status(drm_radeon_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | { |
Harvey Harrison | bf9d892 | 2008-04-30 00:55:10 -0700 | [diff] [blame] | 121 | printk("%s:\n", __func__); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 122 | printk("RBBM_STATUS = 0x%08x\n", |
| 123 | (unsigned int)RADEON_READ(RADEON_RBBM_STATUS)); |
| 124 | printk("CP_RB_RTPR = 0x%08x\n", |
| 125 | (unsigned int)RADEON_READ(RADEON_CP_RB_RPTR)); |
| 126 | printk("CP_RB_WTPR = 0x%08x\n", |
| 127 | (unsigned int)RADEON_READ(RADEON_CP_RB_WPTR)); |
| 128 | printk("AIC_CNTL = 0x%08x\n", |
| 129 | (unsigned int)RADEON_READ(RADEON_AIC_CNTL)); |
| 130 | printk("AIC_STAT = 0x%08x\n", |
| 131 | (unsigned int)RADEON_READ(RADEON_AIC_STAT)); |
| 132 | printk("AIC_PT_BASE = 0x%08x\n", |
| 133 | (unsigned int)RADEON_READ(RADEON_AIC_PT_BASE)); |
| 134 | printk("TLB_ADDR = 0x%08x\n", |
| 135 | (unsigned int)RADEON_READ(RADEON_AIC_TLB_ADDR)); |
| 136 | printk("TLB_DATA = 0x%08x\n", |
| 137 | (unsigned int)RADEON_READ(RADEON_AIC_TLB_DATA)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } |
| 139 | #endif |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | /* ================================================================ |
| 142 | * Engine, FIFO control |
| 143 | */ |
| 144 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 145 | static int radeon_do_pixcache_flush(drm_radeon_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | { |
| 147 | u32 tmp; |
| 148 | int i; |
| 149 | |
| 150 | dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE; |
| 151 | |
Michel Dänzer | b9b603d | 2006-08-07 20:41:53 +1000 | [diff] [blame] | 152 | tmp = RADEON_READ(RADEON_RB3D_DSTCACHE_CTLSTAT); |
| 153 | tmp |= RADEON_RB3D_DC_FLUSH_ALL; |
| 154 | RADEON_WRITE(RADEON_RB3D_DSTCACHE_CTLSTAT, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 156 | for (i = 0; i < dev_priv->usec_timeout; i++) { |
Michel Dänzer | b9b603d | 2006-08-07 20:41:53 +1000 | [diff] [blame] | 157 | if (!(RADEON_READ(RADEON_RB3D_DSTCACHE_CTLSTAT) |
| 158 | & RADEON_RB3D_DC_BUSY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | return 0; |
| 160 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 161 | DRM_UDELAY(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | #if RADEON_FIFO_DEBUG |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 165 | DRM_ERROR("failed!\n"); |
| 166 | radeon_status(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | #endif |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 168 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 171 | 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] | 172 | { |
| 173 | int i; |
| 174 | |
| 175 | dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE; |
| 176 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 177 | for (i = 0; i < dev_priv->usec_timeout; i++) { |
| 178 | int slots = (RADEON_READ(RADEON_RBBM_STATUS) |
| 179 | & RADEON_RBBM_FIFOCNT_MASK); |
| 180 | if (slots >= entries) |
| 181 | return 0; |
| 182 | DRM_UDELAY(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | #if RADEON_FIFO_DEBUG |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 186 | DRM_ERROR("failed!\n"); |
| 187 | radeon_status(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | #endif |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 189 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 192 | 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] | 193 | { |
| 194 | int i, ret; |
| 195 | |
| 196 | dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE; |
| 197 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 198 | ret = radeon_do_wait_for_fifo(dev_priv, 64); |
| 199 | if (ret) |
| 200 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 202 | for (i = 0; i < dev_priv->usec_timeout; i++) { |
| 203 | if (!(RADEON_READ(RADEON_RBBM_STATUS) |
| 204 | & RADEON_RBBM_ACTIVE)) { |
| 205 | radeon_do_pixcache_flush(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | return 0; |
| 207 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 208 | DRM_UDELAY(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | #if RADEON_FIFO_DEBUG |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 212 | DRM_ERROR("failed!\n"); |
| 213 | radeon_status(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | #endif |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 215 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | /* ================================================================ |
| 219 | * CP control, initialization |
| 220 | */ |
| 221 | |
| 222 | /* Load the microcode for the CP */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 223 | static void radeon_cp_load_microcode(drm_radeon_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | { |
| 225 | int i; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 226 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 228 | radeon_do_wait_for_idle(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 230 | RADEON_WRITE(RADEON_CP_ME_RAM_ADDR, 0); |
Alex Deucher | 9f18409 | 2008-05-28 11:21:25 +1000 | [diff] [blame] | 231 | if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R100) || |
| 232 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV100) || |
| 233 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV200) || |
| 234 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS100) || |
| 235 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS200)) { |
| 236 | DRM_INFO("Loading R100 Microcode\n"); |
| 237 | for (i = 0; i < 256; i++) { |
| 238 | RADEON_WRITE(RADEON_CP_ME_RAM_DATAH, |
| 239 | R100_cp_microcode[i][1]); |
| 240 | RADEON_WRITE(RADEON_CP_ME_RAM_DATAL, |
| 241 | R100_cp_microcode[i][0]); |
| 242 | } |
| 243 | } else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R200) || |
| 244 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV250) || |
| 245 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV280) || |
| 246 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS300)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | DRM_INFO("Loading R200 Microcode\n"); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 248 | for (i = 0; i < 256; i++) { |
| 249 | RADEON_WRITE(RADEON_CP_ME_RAM_DATAH, |
| 250 | R200_cp_microcode[i][1]); |
| 251 | RADEON_WRITE(RADEON_CP_ME_RAM_DATAL, |
| 252 | R200_cp_microcode[i][0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | } |
Alex Deucher | 9f18409 | 2008-05-28 11:21:25 +1000 | [diff] [blame] | 254 | } else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R300) || |
| 255 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R350) || |
| 256 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV350) || |
| 257 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV380) || |
| 258 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS400)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | DRM_INFO("Loading R300 Microcode\n"); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 260 | for (i = 0; i < 256; i++) { |
| 261 | RADEON_WRITE(RADEON_CP_ME_RAM_DATAH, |
| 262 | R300_cp_microcode[i][1]); |
| 263 | RADEON_WRITE(RADEON_CP_ME_RAM_DATAL, |
| 264 | R300_cp_microcode[i][0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } |
Alex Deucher | 9f18409 | 2008-05-28 11:21:25 +1000 | [diff] [blame] | 266 | } else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R420) || |
| 267 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV410)) { |
| 268 | DRM_INFO("Loading R400 Microcode\n"); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 269 | for (i = 0; i < 256; i++) { |
| 270 | RADEON_WRITE(RADEON_CP_ME_RAM_DATAH, |
Alex Deucher | 9f18409 | 2008-05-28 11:21:25 +1000 | [diff] [blame] | 271 | R420_cp_microcode[i][1]); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 272 | RADEON_WRITE(RADEON_CP_ME_RAM_DATAL, |
Alex Deucher | 9f18409 | 2008-05-28 11:21:25 +1000 | [diff] [blame] | 273 | R420_cp_microcode[i][0]); |
| 274 | } |
| 275 | } else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690) { |
| 276 | DRM_INFO("Loading RS690 Microcode\n"); |
| 277 | for (i = 0; i < 256; i++) { |
| 278 | RADEON_WRITE(RADEON_CP_ME_RAM_DATAH, |
| 279 | RS690_cp_microcode[i][1]); |
| 280 | RADEON_WRITE(RADEON_CP_ME_RAM_DATAL, |
| 281 | RS690_cp_microcode[i][0]); |
| 282 | } |
| 283 | } else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV515) || |
| 284 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R520) || |
| 285 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV530) || |
| 286 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R580) || |
| 287 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV560) || |
| 288 | ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV570)) { |
| 289 | DRM_INFO("Loading R500 Microcode\n"); |
| 290 | for (i = 0; i < 256; i++) { |
| 291 | RADEON_WRITE(RADEON_CP_ME_RAM_DATAH, |
| 292 | R520_cp_microcode[i][1]); |
| 293 | RADEON_WRITE(RADEON_CP_ME_RAM_DATAL, |
| 294 | R520_cp_microcode[i][0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | /* Flush any pending commands to the CP. This should only be used just |
| 300 | * prior to a wait for idle, as it informs the engine that the command |
| 301 | * stream is ending. |
| 302 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 303 | static void radeon_do_cp_flush(drm_radeon_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 305 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | #if 0 |
| 307 | u32 tmp; |
| 308 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 309 | tmp = RADEON_READ(RADEON_CP_RB_WPTR) | (1 << 31); |
| 310 | RADEON_WRITE(RADEON_CP_RB_WPTR, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | #endif |
| 312 | } |
| 313 | |
| 314 | /* Wait for the CP to go idle. |
| 315 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 316 | int radeon_do_cp_idle(drm_radeon_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | { |
| 318 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 319 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 321 | BEGIN_RING(6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
| 323 | RADEON_PURGE_CACHE(); |
| 324 | RADEON_PURGE_ZCACHE(); |
| 325 | RADEON_WAIT_UNTIL_IDLE(); |
| 326 | |
| 327 | ADVANCE_RING(); |
| 328 | COMMIT_RING(); |
| 329 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 330 | return radeon_do_wait_for_idle(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | /* Start the Command Processor. |
| 334 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 335 | static void radeon_do_cp_start(drm_radeon_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | { |
| 337 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 338 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 340 | radeon_do_wait_for_idle(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 342 | RADEON_WRITE(RADEON_CP_CSQ_CNTL, dev_priv->cp_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
| 344 | dev_priv->cp_running = 1; |
| 345 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 346 | BEGIN_RING(6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
| 348 | RADEON_PURGE_CACHE(); |
| 349 | RADEON_PURGE_ZCACHE(); |
| 350 | RADEON_WAIT_UNTIL_IDLE(); |
| 351 | |
| 352 | ADVANCE_RING(); |
| 353 | COMMIT_RING(); |
| 354 | } |
| 355 | |
| 356 | /* Reset the Command Processor. This will not flush any pending |
| 357 | * commands, so you must wait for the CP command stream to complete |
| 358 | * before calling this routine. |
| 359 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 360 | static void radeon_do_cp_reset(drm_radeon_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | { |
| 362 | u32 cur_read_ptr; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 363 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 365 | cur_read_ptr = RADEON_READ(RADEON_CP_RB_RPTR); |
| 366 | RADEON_WRITE(RADEON_CP_RB_WPTR, cur_read_ptr); |
| 367 | SET_RING_HEAD(dev_priv, cur_read_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | dev_priv->ring.tail = cur_read_ptr; |
| 369 | } |
| 370 | |
| 371 | /* Stop the Command Processor. This will not flush any pending |
| 372 | * commands, so you must flush the command stream and wait for the CP |
| 373 | * to go idle before calling this routine. |
| 374 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 375 | static void radeon_do_cp_stop(drm_radeon_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 377 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 379 | RADEON_WRITE(RADEON_CP_CSQ_CNTL, RADEON_CSQ_PRIDIS_INDDIS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | |
| 381 | dev_priv->cp_running = 0; |
| 382 | } |
| 383 | |
| 384 | /* Reset the engine. This will stop the CP if it is running. |
| 385 | */ |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 386 | static int radeon_do_engine_reset(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | { |
| 388 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 389 | u32 clock_cntl_index, mclk_cntl, rbbm_soft_reset; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 390 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 392 | radeon_do_pixcache_flush(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 394 | if ((dev_priv->flags & RADEON_FAMILY_MASK) < CHIP_RV515) { |
| 395 | clock_cntl_index = RADEON_READ(RADEON_CLOCK_CNTL_INDEX); |
| 396 | mclk_cntl = RADEON_READ_PLL(dev, RADEON_MCLK_CNTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 398 | RADEON_WRITE_PLL(RADEON_MCLK_CNTL, (mclk_cntl | |
| 399 | RADEON_FORCEON_MCLKA | |
| 400 | RADEON_FORCEON_MCLKB | |
| 401 | RADEON_FORCEON_YCLKA | |
| 402 | RADEON_FORCEON_YCLKB | |
| 403 | RADEON_FORCEON_MC | |
| 404 | RADEON_FORCEON_AIC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 406 | rbbm_soft_reset = RADEON_READ(RADEON_RBBM_SOFT_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 408 | RADEON_WRITE(RADEON_RBBM_SOFT_RESET, (rbbm_soft_reset | |
| 409 | RADEON_SOFT_RESET_CP | |
| 410 | RADEON_SOFT_RESET_HI | |
| 411 | RADEON_SOFT_RESET_SE | |
| 412 | RADEON_SOFT_RESET_RE | |
| 413 | RADEON_SOFT_RESET_PP | |
| 414 | RADEON_SOFT_RESET_E2 | |
| 415 | RADEON_SOFT_RESET_RB)); |
| 416 | RADEON_READ(RADEON_RBBM_SOFT_RESET); |
| 417 | RADEON_WRITE(RADEON_RBBM_SOFT_RESET, (rbbm_soft_reset & |
| 418 | ~(RADEON_SOFT_RESET_CP | |
| 419 | RADEON_SOFT_RESET_HI | |
| 420 | RADEON_SOFT_RESET_SE | |
| 421 | RADEON_SOFT_RESET_RE | |
| 422 | RADEON_SOFT_RESET_PP | |
| 423 | RADEON_SOFT_RESET_E2 | |
| 424 | RADEON_SOFT_RESET_RB))); |
| 425 | RADEON_READ(RADEON_RBBM_SOFT_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 427 | RADEON_WRITE_PLL(RADEON_MCLK_CNTL, mclk_cntl); |
| 428 | RADEON_WRITE(RADEON_CLOCK_CNTL_INDEX, clock_cntl_index); |
| 429 | RADEON_WRITE(RADEON_RBBM_SOFT_RESET, rbbm_soft_reset); |
| 430 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
| 432 | /* Reset the CP ring */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 433 | radeon_do_cp_reset(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
| 435 | /* The CP is no longer running after an engine reset */ |
| 436 | dev_priv->cp_running = 0; |
| 437 | |
| 438 | /* Reset any pending vertex, indirect buffers */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 439 | radeon_freelist_reset(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
| 441 | return 0; |
| 442 | } |
| 443 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 444 | static void radeon_cp_init_ring_buffer(struct drm_device * dev, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 445 | drm_radeon_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | { |
| 447 | u32 ring_start, cur_read_ptr; |
| 448 | u32 tmp; |
Dave Airlie | bc5f452 | 2007-11-05 12:50:58 +1000 | [diff] [blame] | 449 | |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 450 | /* Initialize the memory controller. With new memory map, the fb location |
| 451 | * is not changed, it should have been properly initialized already. Part |
| 452 | * of the problem is that the code below is bogus, assuming the GART is |
| 453 | * always appended to the fb which is not necessarily the case |
| 454 | */ |
| 455 | if (!dev_priv->new_memmap) |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 456 | radeon_write_fb_location(dev_priv, |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 457 | ((dev_priv->gart_vm_start - 1) & 0xffff0000) |
| 458 | | (dev_priv->fb_location >> 16)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | |
| 460 | #if __OS_HAS_AGP |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 461 | if (dev_priv->flags & RADEON_IS_AGP) { |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 462 | RADEON_WRITE(RADEON_AGP_BASE, (unsigned int)dev->agp->base); |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 463 | radeon_write_agp_location(dev_priv, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 464 | (((dev_priv->gart_vm_start - 1 + |
| 465 | dev_priv->gart_size) & 0xffff0000) | |
| 466 | (dev_priv->gart_vm_start >> 16))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | |
| 468 | ring_start = (dev_priv->cp_ring->offset |
| 469 | - dev->agp->base |
| 470 | + dev_priv->gart_vm_start); |
Ivan Kokshaysky | b0917bd | 2005-10-26 11:05:25 +0100 | [diff] [blame] | 471 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | #endif |
| 473 | ring_start = (dev_priv->cp_ring->offset |
Ivan Kokshaysky | b0917bd | 2005-10-26 11:05:25 +0100 | [diff] [blame] | 474 | - (unsigned long)dev->sg->virtual |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | + dev_priv->gart_vm_start); |
| 476 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 477 | RADEON_WRITE(RADEON_CP_RB_BASE, ring_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
| 479 | /* Set the write pointer delay */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 480 | RADEON_WRITE(RADEON_CP_RB_WPTR_DELAY, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
| 482 | /* Initialize the ring buffer's read and write pointers */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 483 | cur_read_ptr = RADEON_READ(RADEON_CP_RB_RPTR); |
| 484 | RADEON_WRITE(RADEON_CP_RB_WPTR, cur_read_ptr); |
| 485 | SET_RING_HEAD(dev_priv, cur_read_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | dev_priv->ring.tail = cur_read_ptr; |
| 487 | |
| 488 | #if __OS_HAS_AGP |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 489 | if (dev_priv->flags & RADEON_IS_AGP) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 490 | RADEON_WRITE(RADEON_CP_RB_RPTR_ADDR, |
| 491 | dev_priv->ring_rptr->offset |
| 492 | - dev->agp->base + dev_priv->gart_vm_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | } else |
| 494 | #endif |
| 495 | { |
Dave Airlie | 5591051 | 2007-07-11 16:53:40 +1000 | [diff] [blame] | 496 | struct drm_sg_mem *entry = dev->sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | unsigned long tmp_ofs, page_ofs; |
| 498 | |
Ivan Kokshaysky | b0917bd | 2005-10-26 11:05:25 +0100 | [diff] [blame] | 499 | tmp_ofs = dev_priv->ring_rptr->offset - |
| 500 | (unsigned long)dev->sg->virtual; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | page_ofs = tmp_ofs >> PAGE_SHIFT; |
| 502 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 503 | RADEON_WRITE(RADEON_CP_RB_RPTR_ADDR, entry->busaddr[page_ofs]); |
| 504 | DRM_DEBUG("ring rptr: offset=0x%08lx handle=0x%08lx\n", |
| 505 | (unsigned long)entry->busaddr[page_ofs], |
| 506 | entry->handle + tmp_ofs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | } |
| 508 | |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 509 | /* Set ring buffer size */ |
| 510 | #ifdef __BIG_ENDIAN |
| 511 | RADEON_WRITE(RADEON_CP_RB_CNTL, |
Roland Scheidegger | 576cc45 | 2008-02-07 14:59:24 +1000 | [diff] [blame] | 512 | RADEON_BUF_SWAP_32BIT | |
| 513 | (dev_priv->ring.fetch_size_l2ow << 18) | |
| 514 | (dev_priv->ring.rptr_update_l2qw << 8) | |
| 515 | dev_priv->ring.size_l2qw); |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 516 | #else |
Roland Scheidegger | 576cc45 | 2008-02-07 14:59:24 +1000 | [diff] [blame] | 517 | RADEON_WRITE(RADEON_CP_RB_CNTL, |
| 518 | (dev_priv->ring.fetch_size_l2ow << 18) | |
| 519 | (dev_priv->ring.rptr_update_l2qw << 8) | |
| 520 | dev_priv->ring.size_l2qw); |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 521 | #endif |
| 522 | |
| 523 | /* Start with assuming that writeback doesn't work */ |
| 524 | dev_priv->writeback_works = 0; |
| 525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | /* Initialize the scratch register pointer. This will cause |
| 527 | * the scratch register values to be written out to memory |
| 528 | * whenever they are updated. |
| 529 | * |
| 530 | * We simply put this behind the ring read pointer, this works |
| 531 | * with PCI GART as well as (whatever kind of) AGP GART |
| 532 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 533 | RADEON_WRITE(RADEON_SCRATCH_ADDR, RADEON_READ(RADEON_CP_RB_RPTR_ADDR) |
| 534 | + RADEON_SCRATCH_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | |
| 536 | dev_priv->scratch = ((__volatile__ u32 *) |
| 537 | dev_priv->ring_rptr->handle + |
| 538 | (RADEON_SCRATCH_REG_OFFSET / sizeof(u32))); |
| 539 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 540 | RADEON_WRITE(RADEON_SCRATCH_UMSK, 0x7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 542 | /* Turn on bus mastering */ |
| 543 | tmp = RADEON_READ(RADEON_BUS_CNTL) & ~RADEON_BUS_MASTER_DIS; |
| 544 | RADEON_WRITE(RADEON_BUS_CNTL, tmp); |
| 545 | |
| 546 | dev_priv->sarea_priv->last_frame = dev_priv->scratch[0] = 0; |
| 547 | RADEON_WRITE(RADEON_LAST_FRAME_REG, dev_priv->sarea_priv->last_frame); |
| 548 | |
| 549 | dev_priv->sarea_priv->last_dispatch = dev_priv->scratch[1] = 0; |
| 550 | RADEON_WRITE(RADEON_LAST_DISPATCH_REG, |
| 551 | dev_priv->sarea_priv->last_dispatch); |
| 552 | |
| 553 | dev_priv->sarea_priv->last_clear = dev_priv->scratch[2] = 0; |
| 554 | RADEON_WRITE(RADEON_LAST_CLEAR_REG, dev_priv->sarea_priv->last_clear); |
| 555 | |
| 556 | radeon_do_wait_for_idle(dev_priv); |
| 557 | |
| 558 | /* Sync everything up */ |
| 559 | RADEON_WRITE(RADEON_ISYNC_CNTL, |
| 560 | (RADEON_ISYNC_ANY2D_IDLE3D | |
| 561 | RADEON_ISYNC_ANY3D_IDLE2D | |
| 562 | RADEON_ISYNC_WAIT_IDLEGUI | |
| 563 | RADEON_ISYNC_CPSCRATCH_IDLEGUI)); |
| 564 | |
| 565 | } |
| 566 | |
| 567 | static void radeon_test_writeback(drm_radeon_private_t * dev_priv) |
| 568 | { |
| 569 | u32 tmp; |
| 570 | |
| 571 | /* Writeback doesn't seem to work everywhere, test it here and possibly |
| 572 | * enable it if it appears to work |
| 573 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 574 | DRM_WRITE32(dev_priv->ring_rptr, RADEON_SCRATCHOFF(1), 0); |
| 575 | RADEON_WRITE(RADEON_SCRATCH_REG1, 0xdeadbeef); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 577 | for (tmp = 0; tmp < dev_priv->usec_timeout; tmp++) { |
| 578 | if (DRM_READ32(dev_priv->ring_rptr, RADEON_SCRATCHOFF(1)) == |
| 579 | 0xdeadbeef) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | break; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 581 | DRM_UDELAY(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | } |
| 583 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 584 | if (tmp < dev_priv->usec_timeout) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | dev_priv->writeback_works = 1; |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 586 | DRM_INFO("writeback test succeeded in %d usecs\n", tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | } else { |
| 588 | dev_priv->writeback_works = 0; |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 589 | DRM_INFO("writeback test failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | } |
Dave Airlie | 689b9d7 | 2005-09-30 17:09:07 +1000 | [diff] [blame] | 591 | if (radeon_no_wb == 1) { |
| 592 | dev_priv->writeback_works = 0; |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 593 | DRM_INFO("writeback forced off\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | } |
Michel Dänzer | ae1b1a48 | 2006-08-07 20:37:46 +1000 | [diff] [blame] | 595 | |
| 596 | if (!dev_priv->writeback_works) { |
| 597 | /* Disable writeback to avoid unnecessary bus master transfer */ |
| 598 | RADEON_WRITE(RADEON_CP_RB_CNTL, RADEON_READ(RADEON_CP_RB_CNTL) | |
| 599 | RADEON_RB_NO_UPDATE); |
| 600 | RADEON_WRITE(RADEON_SCRATCH_UMSK, 0); |
| 601 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Dave Airlie | f2b04cd | 2007-05-08 15:19:23 +1000 | [diff] [blame] | 604 | /* Enable or disable IGP GART on the chip */ |
| 605 | static void radeon_set_igpgart(drm_radeon_private_t * dev_priv, int on) |
| 606 | { |
| 607 | u32 temp, tmp; |
| 608 | |
| 609 | tmp = RADEON_READ(RADEON_AIC_CNTL); |
| 610 | if (on) { |
| 611 | DRM_DEBUG("programming igpgart %08X %08lX %08X\n", |
| 612 | dev_priv->gart_vm_start, |
| 613 | (long)dev_priv->gart_info.bus_addr, |
| 614 | dev_priv->gart_size); |
| 615 | |
| 616 | RADEON_WRITE_IGPGART(RADEON_IGPGART_UNK_18, 0x1000); |
| 617 | RADEON_WRITE_IGPGART(RADEON_IGPGART_ENABLE, 0x1); |
| 618 | RADEON_WRITE_IGPGART(RADEON_IGPGART_CTRL, 0x42040800); |
| 619 | RADEON_WRITE_IGPGART(RADEON_IGPGART_BASE_ADDR, |
| 620 | dev_priv->gart_info.bus_addr); |
| 621 | |
| 622 | temp = RADEON_READ_IGPGART(dev_priv, RADEON_IGPGART_UNK_39); |
| 623 | RADEON_WRITE_IGPGART(RADEON_IGPGART_UNK_39, temp); |
| 624 | |
| 625 | RADEON_WRITE(RADEON_AGP_BASE, (unsigned int)dev_priv->gart_vm_start); |
| 626 | dev_priv->gart_size = 32*1024*1024; |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 627 | radeon_write_agp_location(dev_priv, |
Dave Airlie | f2b04cd | 2007-05-08 15:19:23 +1000 | [diff] [blame] | 628 | (((dev_priv->gart_vm_start - 1 + |
| 629 | dev_priv->gart_size) & 0xffff0000) | |
| 630 | (dev_priv->gart_vm_start >> 16))); |
| 631 | |
| 632 | temp = RADEON_READ_IGPGART(dev_priv, RADEON_IGPGART_ENABLE); |
| 633 | RADEON_WRITE_IGPGART(RADEON_IGPGART_ENABLE, temp); |
| 634 | |
| 635 | RADEON_READ_IGPGART(dev_priv, RADEON_IGPGART_FLUSH); |
| 636 | RADEON_WRITE_IGPGART(RADEON_IGPGART_FLUSH, 0x1); |
| 637 | RADEON_READ_IGPGART(dev_priv, RADEON_IGPGART_FLUSH); |
| 638 | RADEON_WRITE_IGPGART(RADEON_IGPGART_FLUSH, 0x0); |
| 639 | } |
| 640 | } |
| 641 | |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 642 | /* Enable or disable RS690 GART on the chip */ |
| 643 | static void radeon_set_rs690gart(drm_radeon_private_t *dev_priv, int on) |
| 644 | { |
| 645 | u32 temp; |
| 646 | |
| 647 | if (on) { |
| 648 | DRM_DEBUG("programming rs690 gart %08X %08lX %08X\n", |
| 649 | dev_priv->gart_vm_start, |
| 650 | (long)dev_priv->gart_info.bus_addr, |
| 651 | dev_priv->gart_size); |
| 652 | |
| 653 | temp = RS690_READ_MCIND(dev_priv, RS690_MC_MISC_CNTL); |
| 654 | RS690_WRITE_MCIND(RS690_MC_MISC_CNTL, 0x5000); |
| 655 | |
| 656 | RS690_WRITE_MCIND(RS690_MC_AGP_SIZE, |
| 657 | RS690_MC_GART_EN | RS690_MC_AGP_SIZE_32MB); |
| 658 | |
| 659 | temp = RS690_READ_MCIND(dev_priv, RS690_MC_GART_FEATURE_ID); |
| 660 | RS690_WRITE_MCIND(RS690_MC_GART_FEATURE_ID, 0x42040800); |
| 661 | |
Dave Airlie | fa0d71b | 2008-05-28 11:27:01 +1000 | [diff] [blame^] | 662 | temp = dev_priv->gart_info.bus_addr & 0xfffff000; |
| 663 | temp |= (upper_32_bits(dev_priv->gart_info.bus_addr) & 0xff) << 4; |
| 664 | RS690_WRITE_MCIND(RS690_MC_GART_BASE, temp); |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 665 | |
| 666 | temp = RS690_READ_MCIND(dev_priv, RS690_MC_AGP_MODE_CONTROL); |
| 667 | RS690_WRITE_MCIND(RS690_MC_AGP_MODE_CONTROL, 0x01400000); |
| 668 | |
| 669 | RS690_WRITE_MCIND(RS690_MC_AGP_BASE, |
| 670 | (unsigned int)dev_priv->gart_vm_start); |
| 671 | |
| 672 | dev_priv->gart_size = 32*1024*1024; |
| 673 | temp = (((dev_priv->gart_vm_start - 1 + dev_priv->gart_size) & |
| 674 | 0xffff0000) | (dev_priv->gart_vm_start >> 16)); |
| 675 | |
| 676 | RS690_WRITE_MCIND(RS690_MC_AGP_LOCATION, temp); |
| 677 | |
| 678 | temp = RS690_READ_MCIND(dev_priv, RS690_MC_AGP_SIZE); |
| 679 | RS690_WRITE_MCIND(RS690_MC_AGP_SIZE, |
| 680 | RS690_MC_GART_EN | RS690_MC_AGP_SIZE_32MB); |
| 681 | |
| 682 | do { |
| 683 | temp = RS690_READ_MCIND(dev_priv, RS690_MC_GART_CACHE_CNTL); |
| 684 | if ((temp & RS690_MC_GART_CLEAR_STATUS) == |
| 685 | RS690_MC_GART_CLEAR_DONE) |
| 686 | break; |
| 687 | DRM_UDELAY(1); |
| 688 | } while (1); |
| 689 | |
| 690 | RS690_WRITE_MCIND(RS690_MC_GART_CACHE_CNTL, |
| 691 | RS690_MC_GART_CC_CLEAR); |
| 692 | do { |
| 693 | temp = RS690_READ_MCIND(dev_priv, RS690_MC_GART_CACHE_CNTL); |
| 694 | if ((temp & RS690_MC_GART_CLEAR_STATUS) == |
| 695 | RS690_MC_GART_CLEAR_DONE) |
| 696 | break; |
| 697 | DRM_UDELAY(1); |
| 698 | } while (1); |
| 699 | |
| 700 | RS690_WRITE_MCIND(RS690_MC_GART_CACHE_CNTL, |
| 701 | RS690_MC_GART_CC_NO_CHANGE); |
| 702 | } else { |
| 703 | RS690_WRITE_MCIND(RS690_MC_AGP_SIZE, RS690_MC_GART_DIS); |
| 704 | } |
| 705 | } |
| 706 | |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 707 | 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] | 708 | { |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 709 | u32 tmp = RADEON_READ_PCIE(dev_priv, RADEON_PCIE_TX_GART_CNTL); |
| 710 | if (on) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 712 | DRM_DEBUG("programming pcie %08X %08lX %08X\n", |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 713 | dev_priv->gart_vm_start, |
| 714 | (long)dev_priv->gart_info.bus_addr, |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 715 | dev_priv->gart_size); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 716 | RADEON_WRITE_PCIE(RADEON_PCIE_TX_DISCARD_RD_ADDR_LO, |
| 717 | dev_priv->gart_vm_start); |
| 718 | RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_BASE, |
| 719 | dev_priv->gart_info.bus_addr); |
| 720 | RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_START_LO, |
| 721 | dev_priv->gart_vm_start); |
| 722 | RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_END_LO, |
| 723 | dev_priv->gart_vm_start + |
| 724 | dev_priv->gart_size - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 726 | radeon_write_agp_location(dev_priv, 0xffffffc0); /* ?? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 728 | RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_CNTL, |
| 729 | RADEON_PCIE_TX_GART_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | } else { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 731 | RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_CNTL, |
| 732 | tmp & ~RADEON_PCIE_TX_GART_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | } |
| 734 | } |
| 735 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | /* Enable or disable PCI GART on the chip */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 737 | 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] | 738 | { |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 739 | u32 tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | |
Maciej Cencora | 60f9268 | 2008-02-19 21:32:45 +1000 | [diff] [blame] | 741 | if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690) { |
| 742 | radeon_set_rs690gart(dev_priv, on); |
| 743 | return; |
| 744 | } |
| 745 | |
Dave Airlie | f2b04cd | 2007-05-08 15:19:23 +1000 | [diff] [blame] | 746 | if (dev_priv->flags & RADEON_IS_IGPGART) { |
| 747 | radeon_set_igpgart(dev_priv, on); |
| 748 | return; |
| 749 | } |
| 750 | |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 751 | if (dev_priv->flags & RADEON_IS_PCIE) { |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 752 | radeon_set_pciegart(dev_priv, on); |
| 753 | return; |
| 754 | } |
| 755 | |
Dave Airlie | bc5f452 | 2007-11-05 12:50:58 +1000 | [diff] [blame] | 756 | tmp = RADEON_READ(RADEON_AIC_CNTL); |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 757 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 758 | if (on) { |
| 759 | RADEON_WRITE(RADEON_AIC_CNTL, |
| 760 | tmp | RADEON_PCIGART_TRANSLATE_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | |
| 762 | /* set PCI GART page-table base address |
| 763 | */ |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 764 | RADEON_WRITE(RADEON_AIC_PT_BASE, dev_priv->gart_info.bus_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | |
| 766 | /* set address range for PCI address translate |
| 767 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 768 | RADEON_WRITE(RADEON_AIC_LO_ADDR, dev_priv->gart_vm_start); |
| 769 | RADEON_WRITE(RADEON_AIC_HI_ADDR, dev_priv->gart_vm_start |
| 770 | + dev_priv->gart_size - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | |
| 772 | /* Turn off AGP aperture -- is this required for PCI GART? |
| 773 | */ |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 774 | radeon_write_agp_location(dev_priv, 0xffffffc0); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 775 | RADEON_WRITE(RADEON_AGP_COMMAND, 0); /* clear AGP_COMMAND */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | } else { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 777 | RADEON_WRITE(RADEON_AIC_CNTL, |
| 778 | tmp & ~RADEON_PCIGART_TRANSLATE_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | } |
| 780 | } |
| 781 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 782 | static int radeon_do_init_cp(struct drm_device * dev, drm_radeon_init_t * init) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | { |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 784 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 785 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 786 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | |
Dave Airlie | f3dd5c3 | 2006-03-25 18:09:46 +1100 | [diff] [blame] | 788 | /* 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] | 789 | if ((dev_priv->flags & RADEON_NEW_MEMMAP) && !dev_priv->new_memmap) { |
Dave Airlie | b15ec36 | 2006-08-19 17:43:52 +1000 | [diff] [blame] | 790 | 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] | 791 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 792 | return -EINVAL; |
Dave Airlie | f3dd5c3 | 2006-03-25 18:09:46 +1100 | [diff] [blame] | 793 | } |
| 794 | |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 795 | if (init->is_pci && (dev_priv->flags & RADEON_IS_AGP)) { |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 796 | DRM_DEBUG("Forcing AGP card to PCI mode\n"); |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 797 | dev_priv->flags &= ~RADEON_IS_AGP; |
| 798 | } 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] | 799 | && !init->is_pci) { |
| 800 | DRM_DEBUG("Restoring AGP flag\n"); |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 801 | dev_priv->flags |= RADEON_IS_AGP; |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 802 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 804 | if ((!(dev_priv->flags & RADEON_IS_AGP)) && !dev->sg) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 805 | DRM_ERROR("PCI GART memory not allocated!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 807 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | dev_priv->usec_timeout = init->usec_timeout; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 811 | if (dev_priv->usec_timeout < 1 || |
| 812 | dev_priv->usec_timeout > RADEON_MAX_USEC_TIMEOUT) { |
| 813 | DRM_DEBUG("TIMEOUT problem!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 815 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | } |
| 817 | |
Dave Airlie | ddbee33 | 2007-07-11 12:16:01 +1000 | [diff] [blame] | 818 | /* Enable vblank on CRTC1 for older X servers |
| 819 | */ |
| 820 | dev_priv->vblank_crtc = DRM_RADEON_VBLANK_CRTC1; |
| 821 | |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 822 | switch(init->func) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | case RADEON_INIT_R200_CP: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 824 | dev_priv->microcode_version = UCODE_R200; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | break; |
| 826 | case RADEON_INIT_R300_CP: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 827 | dev_priv->microcode_version = UCODE_R300; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | break; |
| 829 | default: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 830 | dev_priv->microcode_version = UCODE_R100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 832 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | dev_priv->do_boxes = 0; |
| 834 | dev_priv->cp_mode = init->cp_mode; |
| 835 | |
| 836 | /* We don't support anything other than bus-mastering ring mode, |
| 837 | * but the ring can be in either AGP or PCI space for the ring |
| 838 | * read pointer. |
| 839 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 840 | if ((init->cp_mode != RADEON_CSQ_PRIBM_INDDIS) && |
| 841 | (init->cp_mode != RADEON_CSQ_PRIBM_INDBM)) { |
| 842 | DRM_DEBUG("BAD cp_mode (%x)!\n", init->cp_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 844 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | } |
| 846 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 847 | switch (init->fb_bpp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | case 16: |
| 849 | dev_priv->color_fmt = RADEON_COLOR_FORMAT_RGB565; |
| 850 | break; |
| 851 | case 32: |
| 852 | default: |
| 853 | dev_priv->color_fmt = RADEON_COLOR_FORMAT_ARGB8888; |
| 854 | break; |
| 855 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 856 | dev_priv->front_offset = init->front_offset; |
| 857 | dev_priv->front_pitch = init->front_pitch; |
| 858 | dev_priv->back_offset = init->back_offset; |
| 859 | dev_priv->back_pitch = init->back_pitch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 861 | switch (init->depth_bpp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | case 16: |
| 863 | dev_priv->depth_fmt = RADEON_DEPTH_FORMAT_16BIT_INT_Z; |
| 864 | break; |
| 865 | case 32: |
| 866 | default: |
| 867 | dev_priv->depth_fmt = RADEON_DEPTH_FORMAT_24BIT_INT_Z; |
| 868 | break; |
| 869 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 870 | dev_priv->depth_offset = init->depth_offset; |
| 871 | dev_priv->depth_pitch = init->depth_pitch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | |
| 873 | /* Hardware state for depth clears. Remove this if/when we no |
| 874 | * longer clear the depth buffer with a 3D rectangle. Hard-code |
| 875 | * all values to prevent unwanted 3D state from slipping through |
| 876 | * and screwing with the clear operation. |
| 877 | */ |
| 878 | dev_priv->depth_clear.rb3d_cntl = (RADEON_PLANE_MASK_ENABLE | |
| 879 | (dev_priv->color_fmt << 10) | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 880 | (dev_priv->microcode_version == |
| 881 | UCODE_R100 ? RADEON_ZBLOCK16 : 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 883 | dev_priv->depth_clear.rb3d_zstencilcntl = |
| 884 | (dev_priv->depth_fmt | |
| 885 | RADEON_Z_TEST_ALWAYS | |
| 886 | RADEON_STENCIL_TEST_ALWAYS | |
| 887 | RADEON_STENCIL_S_FAIL_REPLACE | |
| 888 | RADEON_STENCIL_ZPASS_REPLACE | |
| 889 | RADEON_STENCIL_ZFAIL_REPLACE | RADEON_Z_WRITE_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | |
| 891 | dev_priv->depth_clear.se_cntl = (RADEON_FFACE_CULL_CW | |
| 892 | RADEON_BFACE_SOLID | |
| 893 | RADEON_FFACE_SOLID | |
| 894 | RADEON_FLAT_SHADE_VTX_LAST | |
| 895 | RADEON_DIFFUSE_SHADE_FLAT | |
| 896 | RADEON_ALPHA_SHADE_FLAT | |
| 897 | RADEON_SPECULAR_SHADE_FLAT | |
| 898 | RADEON_FOG_SHADE_FLAT | |
| 899 | RADEON_VTX_PIX_CENTER_OGL | |
| 900 | RADEON_ROUND_MODE_TRUNC | |
| 901 | RADEON_ROUND_PREC_8TH_PIX); |
| 902 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | dev_priv->ring_offset = init->ring_offset; |
| 905 | dev_priv->ring_rptr_offset = init->ring_rptr_offset; |
| 906 | dev_priv->buffers_offset = init->buffers_offset; |
| 907 | dev_priv->gart_textures_offset = init->gart_textures_offset; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 908 | |
Dave Airlie | da509d7 | 2007-05-26 05:04:51 +1000 | [diff] [blame] | 909 | dev_priv->sarea = drm_getsarea(dev); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 910 | if (!dev_priv->sarea) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | DRM_ERROR("could not find sarea!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 913 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | } |
| 915 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | dev_priv->cp_ring = drm_core_findmap(dev, init->ring_offset); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 917 | if (!dev_priv->cp_ring) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | DRM_ERROR("could not find cp ring region!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 920 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | } |
| 922 | dev_priv->ring_rptr = drm_core_findmap(dev, init->ring_rptr_offset); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 923 | if (!dev_priv->ring_rptr) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | DRM_ERROR("could not find ring read pointer!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 926 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | } |
Dave Airlie | d1f2b55 | 2005-08-05 22:11:22 +1000 | [diff] [blame] | 928 | dev->agp_buffer_token = init->buffers_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 930 | if (!dev->agp_buffer_map) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | DRM_ERROR("could not find dma buffer region!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 933 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | } |
| 935 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 936 | if (init->gart_textures_offset) { |
| 937 | dev_priv->gart_textures = |
| 938 | drm_core_findmap(dev, init->gart_textures_offset); |
| 939 | if (!dev_priv->gart_textures) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | DRM_ERROR("could not find GART texture region!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 942 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | } |
| 944 | } |
| 945 | |
| 946 | dev_priv->sarea_priv = |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 947 | (drm_radeon_sarea_t *) ((u8 *) dev_priv->sarea->handle + |
| 948 | init->sarea_priv_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | |
| 950 | #if __OS_HAS_AGP |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 951 | if (dev_priv->flags & RADEON_IS_AGP) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 952 | drm_core_ioremap(dev_priv->cp_ring, dev); |
| 953 | drm_core_ioremap(dev_priv->ring_rptr, dev); |
| 954 | drm_core_ioremap(dev->agp_buffer_map, dev); |
| 955 | if (!dev_priv->cp_ring->handle || |
| 956 | !dev_priv->ring_rptr->handle || |
| 957 | !dev->agp_buffer_map->handle) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | DRM_ERROR("could not find ioremap agp regions!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 960 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | } |
| 962 | } else |
| 963 | #endif |
| 964 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 965 | dev_priv->cp_ring->handle = (void *)dev_priv->cp_ring->offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | dev_priv->ring_rptr->handle = |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 967 | (void *)dev_priv->ring_rptr->offset; |
| 968 | dev->agp_buffer_map->handle = |
| 969 | (void *)dev->agp_buffer_map->offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 971 | DRM_DEBUG("dev_priv->cp_ring->handle %p\n", |
| 972 | dev_priv->cp_ring->handle); |
| 973 | DRM_DEBUG("dev_priv->ring_rptr->handle %p\n", |
| 974 | dev_priv->ring_rptr->handle); |
| 975 | DRM_DEBUG("dev->agp_buffer_map->handle %p\n", |
| 976 | dev->agp_buffer_map->handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | } |
| 978 | |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 979 | dev_priv->fb_location = (radeon_read_fb_location(dev_priv) & 0xffff) << 16; |
Dave Airlie | bc5f452 | 2007-11-05 12:50:58 +1000 | [diff] [blame] | 980 | dev_priv->fb_size = |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 981 | ((radeon_read_fb_location(dev_priv) & 0xffff0000u) + 0x10000) |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 982 | - dev_priv->fb_location; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 984 | dev_priv->front_pitch_offset = (((dev_priv->front_pitch / 64) << 22) | |
| 985 | ((dev_priv->front_offset |
| 986 | + dev_priv->fb_location) >> 10)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 988 | dev_priv->back_pitch_offset = (((dev_priv->back_pitch / 64) << 22) | |
| 989 | ((dev_priv->back_offset |
| 990 | + dev_priv->fb_location) >> 10)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 992 | dev_priv->depth_pitch_offset = (((dev_priv->depth_pitch / 64) << 22) | |
| 993 | ((dev_priv->depth_offset |
| 994 | + dev_priv->fb_location) >> 10)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | |
| 996 | dev_priv->gart_size = init->gart_size; |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 997 | |
| 998 | /* New let's set the memory map ... */ |
| 999 | if (dev_priv->new_memmap) { |
| 1000 | u32 base = 0; |
| 1001 | |
| 1002 | DRM_INFO("Setting GART location based on new memory map\n"); |
| 1003 | |
| 1004 | /* If using AGP, try to locate the AGP aperture at the same |
| 1005 | * location in the card and on the bus, though we have to |
| 1006 | * align it down. |
| 1007 | */ |
| 1008 | #if __OS_HAS_AGP |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1009 | if (dev_priv->flags & RADEON_IS_AGP) { |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 1010 | base = dev->agp->base; |
| 1011 | /* Check if valid */ |
Michel Dänzer | 80b2c38 | 2007-02-18 18:03:21 +1100 | [diff] [blame] | 1012 | if ((base + dev_priv->gart_size - 1) >= dev_priv->fb_location && |
| 1013 | base < (dev_priv->fb_location + dev_priv->fb_size - 1)) { |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 1014 | DRM_INFO("Can't use AGP base @0x%08lx, won't fit\n", |
| 1015 | dev->agp->base); |
| 1016 | base = 0; |
| 1017 | } |
| 1018 | } |
| 1019 | #endif |
| 1020 | /* If not or if AGP is at 0 (Macs), try to put it elsewhere */ |
| 1021 | if (base == 0) { |
| 1022 | base = dev_priv->fb_location + dev_priv->fb_size; |
Michel Dänzer | 80b2c38 | 2007-02-18 18:03:21 +1100 | [diff] [blame] | 1023 | if (base < dev_priv->fb_location || |
| 1024 | ((base + dev_priv->gart_size) & 0xfffffffful) < base) |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 1025 | base = dev_priv->fb_location |
| 1026 | - dev_priv->gart_size; |
Dave Airlie | bc5f452 | 2007-11-05 12:50:58 +1000 | [diff] [blame] | 1027 | } |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 1028 | dev_priv->gart_vm_start = base & 0xffc00000u; |
| 1029 | if (dev_priv->gart_vm_start != base) |
| 1030 | DRM_INFO("GART aligned down from 0x%08x to 0x%08x\n", |
| 1031 | base, dev_priv->gart_vm_start); |
| 1032 | } else { |
| 1033 | DRM_INFO("Setting GART location based on old memory map\n"); |
| 1034 | dev_priv->gart_vm_start = dev_priv->fb_location + |
| 1035 | RADEON_READ(RADEON_CONFIG_APER_SIZE); |
| 1036 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | |
| 1038 | #if __OS_HAS_AGP |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1039 | if (dev_priv->flags & RADEON_IS_AGP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1041 | - dev->agp->base |
| 1042 | + dev_priv->gart_vm_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | else |
| 1044 | #endif |
| 1045 | dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset |
Ivan Kokshaysky | b0917bd | 2005-10-26 11:05:25 +0100 | [diff] [blame] | 1046 | - (unsigned long)dev->sg->virtual |
| 1047 | + dev_priv->gart_vm_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1049 | DRM_DEBUG("dev_priv->gart_size %d\n", dev_priv->gart_size); |
| 1050 | DRM_DEBUG("dev_priv->gart_vm_start 0x%x\n", dev_priv->gart_vm_start); |
| 1051 | DRM_DEBUG("dev_priv->gart_buffers_offset 0x%lx\n", |
| 1052 | dev_priv->gart_buffers_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1054 | dev_priv->ring.start = (u32 *) dev_priv->cp_ring->handle; |
| 1055 | dev_priv->ring.end = ((u32 *) dev_priv->cp_ring->handle |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | + init->ring_size / sizeof(u32)); |
| 1057 | dev_priv->ring.size = init->ring_size; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1058 | dev_priv->ring.size_l2qw = drm_order(init->ring_size / 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | |
Roland Scheidegger | 576cc45 | 2008-02-07 14:59:24 +1000 | [diff] [blame] | 1060 | dev_priv->ring.rptr_update = /* init->rptr_update */ 4096; |
| 1061 | dev_priv->ring.rptr_update_l2qw = drm_order( /* init->rptr_update */ 4096 / 8); |
| 1062 | |
| 1063 | dev_priv->ring.fetch_size = /* init->fetch_size */ 32; |
| 1064 | 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] | 1065 | dev_priv->ring.tail_mask = (dev_priv->ring.size / sizeof(u32)) - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | |
| 1067 | dev_priv->ring.high_mark = RADEON_RING_HIGH_MARK; |
| 1068 | |
| 1069 | #if __OS_HAS_AGP |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1070 | if (dev_priv->flags & RADEON_IS_AGP) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | /* Turn off PCI GART */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1072 | radeon_set_pcigart(dev_priv, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | } else |
| 1074 | #endif |
| 1075 | { |
Dave Airlie | b05c238 | 2008-03-17 10:24:24 +1000 | [diff] [blame] | 1076 | dev_priv->gart_info.table_mask = DMA_BIT_MASK(32); |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 1077 | /* if we have an offset set from userspace */ |
Dave Airlie | f2b04cd | 2007-05-08 15:19:23 +1000 | [diff] [blame] | 1078 | if (dev_priv->pcigart_offset_set) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1079 | dev_priv->gart_info.bus_addr = |
| 1080 | dev_priv->pcigart_offset + dev_priv->fb_location; |
Dave Airlie | f26c473 | 2006-01-02 17:18:39 +1100 | [diff] [blame] | 1081 | dev_priv->gart_info.mapping.offset = |
Dave Airlie | 7fc8686 | 2007-11-05 10:45:27 +1000 | [diff] [blame] | 1082 | dev_priv->pcigart_offset + dev_priv->fb_aper_offset; |
Dave Airlie | f26c473 | 2006-01-02 17:18:39 +1100 | [diff] [blame] | 1083 | dev_priv->gart_info.mapping.size = |
Dave Airlie | f2b04cd | 2007-05-08 15:19:23 +1000 | [diff] [blame] | 1084 | dev_priv->gart_info.table_size; |
Dave Airlie | f26c473 | 2006-01-02 17:18:39 +1100 | [diff] [blame] | 1085 | |
| 1086 | drm_core_ioremap(&dev_priv->gart_info.mapping, dev); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1087 | dev_priv->gart_info.addr = |
Dave Airlie | f26c473 | 2006-01-02 17:18:39 +1100 | [diff] [blame] | 1088 | dev_priv->gart_info.mapping.handle; |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 1089 | |
Dave Airlie | f2b04cd | 2007-05-08 15:19:23 +1000 | [diff] [blame] | 1090 | if (dev_priv->flags & RADEON_IS_PCIE) |
| 1091 | dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_PCIE; |
| 1092 | else |
| 1093 | dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_PCI; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1094 | dev_priv->gart_info.gart_table_location = |
| 1095 | DRM_ATI_GART_FB; |
| 1096 | |
Dave Airlie | f26c473 | 2006-01-02 17:18:39 +1100 | [diff] [blame] | 1097 | DRM_DEBUG("Setting phys_pci_gart to %p %08lX\n", |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1098 | dev_priv->gart_info.addr, |
| 1099 | dev_priv->pcigart_offset); |
| 1100 | } else { |
Dave Airlie | f2b04cd | 2007-05-08 15:19:23 +1000 | [diff] [blame] | 1101 | if (dev_priv->flags & RADEON_IS_IGPGART) |
| 1102 | dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_IGP; |
| 1103 | else |
| 1104 | dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_PCI; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1105 | dev_priv->gart_info.gart_table_location = |
| 1106 | DRM_ATI_GART_MAIN; |
Dave Airlie | f26c473 | 2006-01-02 17:18:39 +1100 | [diff] [blame] | 1107 | dev_priv->gart_info.addr = NULL; |
| 1108 | dev_priv->gart_info.bus_addr = 0; |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1109 | if (dev_priv->flags & RADEON_IS_PCIE) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1110 | DRM_ERROR |
| 1111 | ("Cannot use PCI Express without GART in FB memory\n"); |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 1112 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1113 | return -EINVAL; |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 1114 | } |
| 1115 | } |
| 1116 | |
| 1117 | if (!drm_ati_pcigart_init(dev, &dev_priv->gart_info)) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1118 | DRM_ERROR("failed to init PCI GART!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | radeon_do_cleanup_cp(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1120 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | /* Turn on PCI GART */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1124 | radeon_set_pcigart(dev_priv, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1127 | radeon_cp_load_microcode(dev_priv); |
| 1128 | radeon_cp_init_ring_buffer(dev, dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | |
| 1130 | dev_priv->last_buf = 0; |
| 1131 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1132 | radeon_do_engine_reset(dev); |
Dave Airlie | d5ea702 | 2006-03-19 19:37:55 +1100 | [diff] [blame] | 1133 | radeon_test_writeback(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | |
| 1135 | return 0; |
| 1136 | } |
| 1137 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 1138 | static int radeon_do_cleanup_cp(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | { |
| 1140 | drm_radeon_private_t *dev_priv = dev->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1141 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | |
| 1143 | /* Make sure interrupts are disabled here because the uninstall ioctl |
| 1144 | * may not have been called from userspace and after dev_private |
| 1145 | * is freed, it's too late. |
| 1146 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1147 | if (dev->irq_enabled) |
| 1148 | drm_irq_uninstall(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | |
| 1150 | #if __OS_HAS_AGP |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1151 | if (dev_priv->flags & RADEON_IS_AGP) { |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 1152 | if (dev_priv->cp_ring != NULL) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1153 | drm_core_ioremapfree(dev_priv->cp_ring, dev); |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 1154 | dev_priv->cp_ring = NULL; |
| 1155 | } |
| 1156 | if (dev_priv->ring_rptr != NULL) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1157 | drm_core_ioremapfree(dev_priv->ring_rptr, dev); |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 1158 | dev_priv->ring_rptr = NULL; |
| 1159 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1160 | if (dev->agp_buffer_map != NULL) { |
| 1161 | drm_core_ioremapfree(dev->agp_buffer_map, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | dev->agp_buffer_map = NULL; |
| 1163 | } |
| 1164 | } else |
| 1165 | #endif |
| 1166 | { |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 1167 | |
| 1168 | if (dev_priv->gart_info.bus_addr) { |
| 1169 | /* Turn off PCI GART */ |
| 1170 | radeon_set_pcigart(dev_priv, 0); |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 1171 | if (!drm_ati_pcigart_cleanup(dev, &dev_priv->gart_info)) |
| 1172 | DRM_ERROR("failed to cleanup PCI GART!\n"); |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 1173 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1174 | |
Dave Airlie | d985c10 | 2006-01-02 21:32:48 +1100 | [diff] [blame] | 1175 | if (dev_priv->gart_info.gart_table_location == DRM_ATI_GART_FB) |
| 1176 | { |
Dave Airlie | f26c473 | 2006-01-02 17:18:39 +1100 | [diff] [blame] | 1177 | drm_core_ioremapfree(&dev_priv->gart_info.mapping, dev); |
Dave Airlie | f2b04cd | 2007-05-08 15:19:23 +1000 | [diff] [blame] | 1178 | dev_priv->gart_info.addr = 0; |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 1179 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | /* only clear to the start of flags */ |
| 1182 | memset(dev_priv, 0, offsetof(drm_radeon_private_t, flags)); |
| 1183 | |
| 1184 | return 0; |
| 1185 | } |
| 1186 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1187 | /* This code will reinit the Radeon CP hardware after a resume from disc. |
| 1188 | * 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] | 1189 | * here we make sure that all Radeon hardware initialisation is re-done without |
| 1190 | * affecting running applications. |
| 1191 | * |
| 1192 | * Charl P. Botha <http://cpbotha.net> |
| 1193 | */ |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 1194 | static int radeon_do_resume_cp(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | { |
| 1196 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 1197 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1198 | if (!dev_priv) { |
| 1199 | DRM_ERROR("Called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1200 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | DRM_DEBUG("Starting radeon_do_resume_cp()\n"); |
| 1204 | |
| 1205 | #if __OS_HAS_AGP |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1206 | if (dev_priv->flags & RADEON_IS_AGP) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | /* Turn off PCI GART */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1208 | radeon_set_pcigart(dev_priv, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | } else |
| 1210 | #endif |
| 1211 | { |
| 1212 | /* Turn on PCI GART */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1213 | radeon_set_pcigart(dev_priv, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1216 | radeon_cp_load_microcode(dev_priv); |
| 1217 | radeon_cp_init_ring_buffer(dev, dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1219 | radeon_do_engine_reset(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | |
| 1221 | DRM_DEBUG("radeon_do_resume_cp() complete\n"); |
| 1222 | |
| 1223 | return 0; |
| 1224 | } |
| 1225 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1226 | 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] | 1227 | { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1228 | drm_radeon_init_t *init = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1230 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1232 | if (init->func == RADEON_INIT_R300_CP) |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 1233 | r300_init_reg_flags(dev); |
Dave Airlie | 414ed53 | 2005-08-16 20:43:16 +1000 | [diff] [blame] | 1234 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1235 | switch (init->func) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | case RADEON_INIT_CP: |
| 1237 | case RADEON_INIT_R200_CP: |
| 1238 | case RADEON_INIT_R300_CP: |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1239 | return radeon_do_init_cp(dev, init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | case RADEON_CLEANUP_CP: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1241 | return radeon_do_cleanup_cp(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | } |
| 1243 | |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1244 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | } |
| 1246 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1247 | 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] | 1248 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | drm_radeon_private_t *dev_priv = dev->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1250 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1252 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1254 | if (dev_priv->cp_running) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 1255 | DRM_DEBUG("while CP running\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | return 0; |
| 1257 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1258 | if (dev_priv->cp_mode == RADEON_CSQ_PRIDIS_INDDIS) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 1259 | DRM_DEBUG("called with bogus CP mode (%d)\n", |
| 1260 | dev_priv->cp_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | return 0; |
| 1262 | } |
| 1263 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1264 | radeon_do_cp_start(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | |
| 1266 | return 0; |
| 1267 | } |
| 1268 | |
| 1269 | /* Stop the CP. The engine must have been idled before calling this |
| 1270 | * routine. |
| 1271 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1272 | 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] | 1273 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | drm_radeon_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1275 | drm_radeon_cp_stop_t *stop = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | int ret; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1277 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1279 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | if (!dev_priv->cp_running) |
| 1282 | return 0; |
| 1283 | |
| 1284 | /* Flush any pending CP commands. This ensures any outstanding |
| 1285 | * commands are exectuted by the engine before we turn it off. |
| 1286 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1287 | if (stop->flush) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1288 | radeon_do_cp_flush(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | /* If we fail to make the engine go idle, we return an error |
| 1292 | * code so that the DRM ioctl wrapper can try again. |
| 1293 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1294 | if (stop->idle) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1295 | ret = radeon_do_cp_idle(dev_priv); |
| 1296 | if (ret) |
| 1297 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | /* Finally, we can turn off the CP. If the engine isn't idle, |
| 1301 | * we will get some dropped triangles as they won't be fully |
| 1302 | * rendered before the CP is shut down. |
| 1303 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1304 | radeon_do_cp_stop(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | |
| 1306 | /* Reset the engine */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1307 | radeon_do_engine_reset(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | |
| 1309 | return 0; |
| 1310 | } |
| 1311 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 1312 | void radeon_do_release(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | { |
| 1314 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 1315 | int i, ret; |
| 1316 | |
| 1317 | if (dev_priv) { |
| 1318 | if (dev_priv->cp_running) { |
| 1319 | /* Stop the cp */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1320 | while ((ret = radeon_do_cp_idle(dev_priv)) != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | DRM_DEBUG("radeon_do_cp_idle %d\n", ret); |
| 1322 | #ifdef __linux__ |
| 1323 | schedule(); |
| 1324 | #else |
| 1325 | tsleep(&ret, PZERO, "rdnrel", 1); |
| 1326 | #endif |
| 1327 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1328 | radeon_do_cp_stop(dev_priv); |
| 1329 | radeon_do_engine_reset(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | /* Disable *all* interrupts */ |
| 1333 | if (dev_priv->mmio) /* remove this after permanent addmaps */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1334 | RADEON_WRITE(RADEON_GEN_INT_CNTL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1336 | if (dev_priv->mmio) { /* remove all surfaces */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | for (i = 0; i < RADEON_MAX_SURFACES; i++) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1338 | RADEON_WRITE(RADEON_SURFACE0_INFO + 16 * i, 0); |
| 1339 | RADEON_WRITE(RADEON_SURFACE0_LOWER_BOUND + |
| 1340 | 16 * i, 0); |
| 1341 | RADEON_WRITE(RADEON_SURFACE0_UPPER_BOUND + |
| 1342 | 16 * i, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | } |
| 1344 | } |
| 1345 | |
| 1346 | /* Free memory heap structures */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1347 | radeon_mem_takedown(&(dev_priv->gart_heap)); |
| 1348 | radeon_mem_takedown(&(dev_priv->fb_heap)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | |
| 1350 | /* deallocate kernel resources */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1351 | radeon_do_cleanup_cp(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | } |
| 1353 | } |
| 1354 | |
| 1355 | /* Just reset the CP ring. Called as part of an X Server engine reset. |
| 1356 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1357 | 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] | 1358 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | drm_radeon_private_t *dev_priv = dev->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1360 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1362 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1364 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 1365 | DRM_DEBUG("called before init done\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1366 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | } |
| 1368 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1369 | radeon_do_cp_reset(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | |
| 1371 | /* The CP is no longer running after an engine reset */ |
| 1372 | dev_priv->cp_running = 0; |
| 1373 | |
| 1374 | return 0; |
| 1375 | } |
| 1376 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1377 | 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] | 1378 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | drm_radeon_private_t *dev_priv = dev->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1380 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1382 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1384 | return radeon_do_cp_idle(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | /* Added by Charl P. Botha to call radeon_do_resume_cp(). |
| 1388 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1389 | 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] | 1390 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | |
| 1392 | return radeon_do_resume_cp(dev); |
| 1393 | } |
| 1394 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1395 | 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] | 1396 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1397 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1399 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1401 | return radeon_do_engine_reset(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | } |
| 1403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | /* ================================================================ |
| 1405 | * Fullscreen mode |
| 1406 | */ |
| 1407 | |
| 1408 | /* KW: Deprecated to say the least: |
| 1409 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1410 | 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] | 1411 | { |
| 1412 | return 0; |
| 1413 | } |
| 1414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | /* ================================================================ |
| 1416 | * Freelist management |
| 1417 | */ |
| 1418 | |
| 1419 | /* Original comment: FIXME: ROTATE_BUFS is a hack to cycle through |
| 1420 | * bufs until freelist code is used. Note this hides a problem with |
| 1421 | * the scratch register * (used to keep track of last buffer |
| 1422 | * completed) being written to before * the last buffer has actually |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1423 | * completed rendering. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | * |
| 1425 | * KW: It's also a good way to find free buffers quickly. |
| 1426 | * |
| 1427 | * KW: Ideally this loop wouldn't exist, and freelist_get wouldn't |
| 1428 | * sleep. However, bugs in older versions of radeon_accel.c mean that |
| 1429 | * we essentially have to do this, else old clients will break. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1430 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | * However, it does leave open a potential deadlock where all the |
| 1432 | * buffers are held by other clients, which can't release them because |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1433 | * they can't get the lock. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | */ |
| 1435 | |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 1436 | struct drm_buf *radeon_freelist_get(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | { |
Dave Airlie | cdd55a2 | 2007-07-11 16:32:08 +1000 | [diff] [blame] | 1438 | struct drm_device_dma *dma = dev->dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 1440 | drm_radeon_buf_priv_t *buf_priv; |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 1441 | struct drm_buf *buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | int i, t; |
| 1443 | int start; |
| 1444 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1445 | if (++dev_priv->last_buf >= dma->buf_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | dev_priv->last_buf = 0; |
| 1447 | |
| 1448 | start = dev_priv->last_buf; |
| 1449 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1450 | for (t = 0; t < dev_priv->usec_timeout; t++) { |
| 1451 | u32 done_age = GET_SCRATCH(1); |
| 1452 | DRM_DEBUG("done_age = %d\n", done_age); |
| 1453 | for (i = start; i < dma->buf_count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | buf = dma->buflist[i]; |
| 1455 | buf_priv = buf->dev_private; |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1456 | if (buf->file_priv == NULL || (buf->pending && |
| 1457 | buf_priv->age <= |
| 1458 | done_age)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | dev_priv->stats.requested_bufs++; |
| 1460 | buf->pending = 0; |
| 1461 | return buf; |
| 1462 | } |
| 1463 | start = 0; |
| 1464 | } |
| 1465 | |
| 1466 | if (t) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1467 | DRM_UDELAY(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | dev_priv->stats.freelist_loops++; |
| 1469 | } |
| 1470 | } |
| 1471 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1472 | DRM_DEBUG("returning NULL!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | return NULL; |
| 1474 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1475 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | #if 0 |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 1477 | struct drm_buf *radeon_freelist_get(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | { |
Dave Airlie | cdd55a2 | 2007-07-11 16:32:08 +1000 | [diff] [blame] | 1479 | struct drm_device_dma *dma = dev->dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 1481 | drm_radeon_buf_priv_t *buf_priv; |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 1482 | struct drm_buf *buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | int i, t; |
| 1484 | int start; |
| 1485 | u32 done_age = DRM_READ32(dev_priv->ring_rptr, RADEON_SCRATCHOFF(1)); |
| 1486 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1487 | if (++dev_priv->last_buf >= dma->buf_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | dev_priv->last_buf = 0; |
| 1489 | |
| 1490 | start = dev_priv->last_buf; |
| 1491 | dev_priv->stats.freelist_loops++; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1492 | |
| 1493 | for (t = 0; t < 2; t++) { |
| 1494 | for (i = start; i < dma->buf_count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | buf = dma->buflist[i]; |
| 1496 | buf_priv = buf->dev_private; |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1497 | if (buf->file_priv == 0 || (buf->pending && |
| 1498 | buf_priv->age <= |
| 1499 | done_age)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | dev_priv->stats.requested_bufs++; |
| 1501 | buf->pending = 0; |
| 1502 | return buf; |
| 1503 | } |
| 1504 | } |
| 1505 | start = 0; |
| 1506 | } |
| 1507 | |
| 1508 | return NULL; |
| 1509 | } |
| 1510 | #endif |
| 1511 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 1512 | void radeon_freelist_reset(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | { |
Dave Airlie | cdd55a2 | 2007-07-11 16:32:08 +1000 | [diff] [blame] | 1514 | struct drm_device_dma *dma = dev->dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 1516 | int i; |
| 1517 | |
| 1518 | dev_priv->last_buf = 0; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1519 | for (i = 0; i < dma->buf_count; i++) { |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 1520 | struct drm_buf *buf = dma->buflist[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | drm_radeon_buf_priv_t *buf_priv = buf->dev_private; |
| 1522 | buf_priv->age = 0; |
| 1523 | } |
| 1524 | } |
| 1525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | /* ================================================================ |
| 1527 | * CP command submission |
| 1528 | */ |
| 1529 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1530 | int radeon_wait_ring(drm_radeon_private_t * dev_priv, int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1531 | { |
| 1532 | drm_radeon_ring_buffer_t *ring = &dev_priv->ring; |
| 1533 | int i; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1534 | u32 last_head = GET_RING_HEAD(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1536 | for (i = 0; i < dev_priv->usec_timeout; i++) { |
| 1537 | u32 head = GET_RING_HEAD(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1538 | |
| 1539 | ring->space = (head - ring->tail) * sizeof(u32); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1540 | if (ring->space <= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | ring->space += ring->size; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1542 | if (ring->space > n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | return 0; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1544 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE; |
| 1546 | |
| 1547 | if (head != last_head) |
| 1548 | i = 0; |
| 1549 | last_head = head; |
| 1550 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1551 | DRM_UDELAY(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | /* FIXME: This return value is ignored in the BEGIN_RING macro! */ |
| 1555 | #if RADEON_FIFO_DEBUG |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1556 | radeon_status(dev_priv); |
| 1557 | DRM_ERROR("failed!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | #endif |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1559 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | } |
| 1561 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1562 | static int radeon_cp_get_buffers(struct drm_device *dev, |
| 1563 | struct drm_file *file_priv, |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 1564 | struct drm_dma * d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | { |
| 1566 | int i; |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 1567 | struct drm_buf *buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1569 | for (i = d->granted_count; i < d->request_count; i++) { |
| 1570 | buf = radeon_freelist_get(dev); |
| 1571 | if (!buf) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1572 | return -EBUSY; /* NOTE: broken client */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1574 | buf->file_priv = file_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1576 | if (DRM_COPY_TO_USER(&d->request_indices[i], &buf->idx, |
| 1577 | sizeof(buf->idx))) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1578 | return -EFAULT; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1579 | if (DRM_COPY_TO_USER(&d->request_sizes[i], &buf->total, |
| 1580 | sizeof(buf->total))) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1581 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | |
| 1583 | d->granted_count++; |
| 1584 | } |
| 1585 | return 0; |
| 1586 | } |
| 1587 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1588 | 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] | 1589 | { |
Dave Airlie | cdd55a2 | 2007-07-11 16:32:08 +1000 | [diff] [blame] | 1590 | struct drm_device_dma *dma = dev->dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | int ret = 0; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1592 | struct drm_dma *d = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1594 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | /* Please don't send us buffers. |
| 1597 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1598 | if (d->send_count != 0) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1599 | DRM_ERROR("Process %d trying to send %d buffers via drmDMA\n", |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1600 | DRM_CURRENTPID, d->send_count); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1601 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | } |
| 1603 | |
| 1604 | /* We'll send you buffers. |
| 1605 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1606 | if (d->request_count < 0 || d->request_count > dma->buf_count) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1607 | 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] | 1608 | DRM_CURRENTPID, d->request_count, dma->buf_count); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1609 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | } |
| 1611 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1612 | d->granted_count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1614 | if (d->request_count) { |
| 1615 | ret = radeon_cp_get_buffers(dev, file_priv, d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | } |
| 1617 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | return ret; |
| 1619 | } |
| 1620 | |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 1621 | int radeon_driver_load(struct drm_device *dev, unsigned long flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | { |
| 1623 | drm_radeon_private_t *dev_priv; |
| 1624 | int ret = 0; |
| 1625 | |
| 1626 | dev_priv = drm_alloc(sizeof(drm_radeon_private_t), DRM_MEM_DRIVER); |
| 1627 | if (dev_priv == NULL) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1628 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | |
| 1630 | memset(dev_priv, 0, sizeof(drm_radeon_private_t)); |
| 1631 | dev->dev_private = (void *)dev_priv; |
| 1632 | dev_priv->flags = flags; |
| 1633 | |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1634 | switch (flags & RADEON_FAMILY_MASK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | case CHIP_R100: |
| 1636 | case CHIP_RV200: |
| 1637 | case CHIP_R200: |
| 1638 | case CHIP_R300: |
Dave Airlie | b15ec36 | 2006-08-19 17:43:52 +1000 | [diff] [blame] | 1639 | case CHIP_R350: |
Dave Airlie | 414ed53 | 2005-08-16 20:43:16 +1000 | [diff] [blame] | 1640 | case CHIP_R420: |
Dave Airlie | b15ec36 | 2006-08-19 17:43:52 +1000 | [diff] [blame] | 1641 | case CHIP_RV410: |
Dave Airlie | 3d5e2c1 | 2008-02-07 15:01:05 +1000 | [diff] [blame] | 1642 | case CHIP_RV515: |
| 1643 | case CHIP_R520: |
| 1644 | case CHIP_RV570: |
| 1645 | case CHIP_R580: |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1646 | dev_priv->flags |= RADEON_HAS_HIERZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | break; |
| 1648 | default: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1649 | /* all other chips have no hierarchical z buffer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | break; |
| 1651 | } |
Dave Airlie | 414ed53 | 2005-08-16 20:43:16 +1000 | [diff] [blame] | 1652 | |
| 1653 | if (drm_device_is_agp(dev)) |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1654 | dev_priv->flags |= RADEON_IS_AGP; |
Dave Airlie | b15ec36 | 2006-08-19 17:43:52 +1000 | [diff] [blame] | 1655 | else if (drm_device_is_pcie(dev)) |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1656 | dev_priv->flags |= RADEON_IS_PCIE; |
Dave Airlie | b15ec36 | 2006-08-19 17:43:52 +1000 | [diff] [blame] | 1657 | else |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1658 | dev_priv->flags |= RADEON_IS_PCI; |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 1659 | |
Dave Airlie | 414ed53 | 2005-08-16 20:43:16 +1000 | [diff] [blame] | 1660 | DRM_DEBUG("%s card detected\n", |
Dave Airlie | 54a56ac | 2006-09-22 04:25:09 +1000 | [diff] [blame] | 1661 | ((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] | 1662 | return ret; |
| 1663 | } |
| 1664 | |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 1665 | /* Create mappings for registers and framebuffer so userland doesn't necessarily |
| 1666 | * have to find them. |
| 1667 | */ |
| 1668 | int radeon_driver_firstopen(struct drm_device *dev) |
Dave Airlie | 836cf04 | 2005-07-10 19:27:04 +1000 | [diff] [blame] | 1669 | { |
| 1670 | int ret; |
| 1671 | drm_local_map_t *map; |
| 1672 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 1673 | |
Dave Airlie | f2b04cd | 2007-05-08 15:19:23 +1000 | [diff] [blame] | 1674 | dev_priv->gart_info.table_size = RADEON_PCIGART_TABLE_SIZE; |
| 1675 | |
Dave Airlie | 836cf04 | 2005-07-10 19:27:04 +1000 | [diff] [blame] | 1676 | ret = drm_addmap(dev, drm_get_resource_start(dev, 2), |
| 1677 | drm_get_resource_len(dev, 2), _DRM_REGISTERS, |
| 1678 | _DRM_READ_ONLY, &dev_priv->mmio); |
| 1679 | if (ret != 0) |
| 1680 | return ret; |
| 1681 | |
Dave Airlie | 7fc8686 | 2007-11-05 10:45:27 +1000 | [diff] [blame] | 1682 | dev_priv->fb_aper_offset = drm_get_resource_start(dev, 0); |
| 1683 | ret = drm_addmap(dev, dev_priv->fb_aper_offset, |
Dave Airlie | 836cf04 | 2005-07-10 19:27:04 +1000 | [diff] [blame] | 1684 | drm_get_resource_len(dev, 0), _DRM_FRAME_BUFFER, |
| 1685 | _DRM_WRITE_COMBINING, &map); |
| 1686 | if (ret != 0) |
| 1687 | return ret; |
| 1688 | |
| 1689 | return 0; |
| 1690 | } |
| 1691 | |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 1692 | int radeon_driver_unload(struct drm_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | { |
| 1694 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 1695 | |
| 1696 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | drm_free(dev_priv, sizeof(*dev_priv), DRM_MEM_DRIVER); |
| 1698 | |
| 1699 | dev->dev_private = NULL; |
| 1700 | return 0; |
| 1701 | } |