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