Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 1 | /* r128_cce.c -- ATI Rage 128 driver -*- linux-c -*- |
| 2 | * Created: Wed Apr 5 19:24:19 2000 by kevin@precisioninsight.com |
| 3 | * |
| 4 | * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas. |
| 5 | * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. |
| 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: |
Gareth Hughes | 01a1478 | 2001-02-16 05:24:06 +0000 | [diff] [blame] | 28 | * Gareth Hughes <gareth@valinux.com> |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 29 | */ |
| 30 | |
Gareth Hughes | 3604753 | 2001-02-15 08:12:14 +0000 | [diff] [blame] | 31 | #include "r128.h" |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 32 | #include "drmP.h" |
Jens Owen | 3903e5a | 2002-04-09 21:54:56 +0000 | [diff] [blame] | 33 | #include "drm.h" |
| 34 | #include "r128_drm.h" |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 35 | #include "r128_drv.h" |
| 36 | |
Kevin E Martin | 0994e63 | 2001-01-05 22:57:55 +0000 | [diff] [blame] | 37 | #define R128_FIFO_DEBUG 0 |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 38 | |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 39 | /* CCE microcode (from ATI) */ |
| 40 | static u32 r128_cce_microcode[] = { |
| 41 | 0, 276838400, 0, 268449792, 2, 142, 2, 145, 0, 1076765731, 0, |
| 42 | 1617039951, 0, 774592877, 0, 1987540286, 0, 2307490946U, 0, |
| 43 | 599558925, 0, 589505315, 0, 596487092, 0, 589505315, 1, |
| 44 | 11544576, 1, 206848, 1, 311296, 1, 198656, 2, 912273422, 11, |
| 45 | 262144, 0, 0, 1, 33559837, 1, 7438, 1, 14809, 1, 6615, 12, 28, |
| 46 | 1, 6614, 12, 28, 2, 23, 11, 18874368, 0, 16790922, 1, 409600, 9, |
| 47 | 30, 1, 147854772, 16, 420483072, 3, 8192, 0, 10240, 1, 198656, |
| 48 | 1, 15630, 1, 51200, 10, 34858, 9, 42, 1, 33559823, 2, 10276, 1, |
| 49 | 15717, 1, 15718, 2, 43, 1, 15936948, 1, 570480831, 1, 14715071, |
| 50 | 12, 322123831, 1, 33953125, 12, 55, 1, 33559908, 1, 15718, 2, |
| 51 | 46, 4, 2099258, 1, 526336, 1, 442623, 4, 4194365, 1, 509952, 1, |
| 52 | 459007, 3, 0, 12, 92, 2, 46, 12, 176, 1, 15734, 1, 206848, 1, |
| 53 | 18432, 1, 133120, 1, 100670734, 1, 149504, 1, 165888, 1, |
| 54 | 15975928, 1, 1048576, 6, 3145806, 1, 15715, 16, 2150645232U, 2, |
| 55 | 268449859, 2, 10307, 12, 176, 1, 15734, 1, 15735, 1, 15630, 1, |
| 56 | 15631, 1, 5253120, 6, 3145810, 16, 2150645232U, 1, 15864, 2, 82, |
| 57 | 1, 343310, 1, 1064207, 2, 3145813, 1, 15728, 1, 7817, 1, 15729, |
| 58 | 3, 15730, 12, 92, 2, 98, 1, 16168, 1, 16167, 1, 16002, 1, 16008, |
| 59 | 1, 15974, 1, 15975, 1, 15990, 1, 15976, 1, 15977, 1, 15980, 0, |
| 60 | 15981, 1, 10240, 1, 5253120, 1, 15720, 1, 198656, 6, 110, 1, |
| 61 | 180224, 1, 103824738, 2, 112, 2, 3145839, 0, 536885440, 1, |
| 62 | 114880, 14, 125, 12, 206975, 1, 33559995, 12, 198784, 0, |
| 63 | 33570236, 1, 15803, 0, 15804, 3, 294912, 1, 294912, 3, 442370, |
| 64 | 1, 11544576, 0, 811612160, 1, 12593152, 1, 11536384, 1, |
| 65 | 14024704, 7, 310382726, 0, 10240, 1, 14796, 1, 14797, 1, 14793, |
| 66 | 1, 14794, 0, 14795, 1, 268679168, 1, 9437184, 1, 268449792, 1, |
| 67 | 198656, 1, 9452827, 1, 1075854602, 1, 1075854603, 1, 557056, 1, |
| 68 | 114880, 14, 159, 12, 198784, 1, 1109409213, 12, 198783, 1, |
| 69 | 1107312059, 12, 198784, 1, 1109409212, 2, 162, 1, 1075854781, 1, |
| 70 | 1073757627, 1, 1075854780, 1, 540672, 1, 10485760, 6, 3145894, |
| 71 | 16, 274741248, 9, 168, 3, 4194304, 3, 4209949, 0, 0, 0, 256, 14, |
| 72 | 174, 1, 114857, 1, 33560007, 12, 176, 0, 10240, 1, 114858, 1, |
| 73 | 33560018, 1, 114857, 3, 33560007, 1, 16008, 1, 114874, 1, |
| 74 | 33560360, 1, 114875, 1, 33560154, 0, 15963, 0, 256, 0, 4096, 1, |
| 75 | 409611, 9, 188, 0, 10240, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 76 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 77 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 78 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 79 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 80 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 81 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 82 | }; |
| 83 | |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 84 | int R128_READ_PLL(drm_device_t *dev, int addr) |
| 85 | { |
| 86 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 87 | |
| 88 | R128_WRITE8(R128_CLOCK_CNTL_INDEX, addr & 0x1f); |
| 89 | return R128_READ(R128_CLOCK_CNTL_DATA); |
| 90 | } |
| 91 | |
Kevin E Martin | 0994e63 | 2001-01-05 22:57:55 +0000 | [diff] [blame] | 92 | #if R128_FIFO_DEBUG |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 93 | static void r128_status( drm_r128_private_t *dev_priv ) |
| 94 | { |
| 95 | printk( "GUI_STAT = 0x%08x\n", |
| 96 | (unsigned int)R128_READ( R128_GUI_STAT ) ); |
| 97 | printk( "PM4_STAT = 0x%08x\n", |
| 98 | (unsigned int)R128_READ( R128_PM4_STAT ) ); |
| 99 | printk( "PM4_BUFFER_DL_WPTR = 0x%08x\n", |
| 100 | (unsigned int)R128_READ( R128_PM4_BUFFER_DL_WPTR ) ); |
| 101 | printk( "PM4_BUFFER_DL_RPTR = 0x%08x\n", |
| 102 | (unsigned int)R128_READ( R128_PM4_BUFFER_DL_RPTR ) ); |
| 103 | printk( "PM4_MICRO_CNTL = 0x%08x\n", |
| 104 | (unsigned int)R128_READ( R128_PM4_MICRO_CNTL ) ); |
| 105 | printk( "PM4_BUFFER_CNTL = 0x%08x\n", |
| 106 | (unsigned int)R128_READ( R128_PM4_BUFFER_CNTL ) ); |
| 107 | } |
Gareth Hughes | 8725828 | 2000-12-12 14:50:50 +0000 | [diff] [blame] | 108 | #endif |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 109 | |
| 110 | |
| 111 | /* ================================================================ |
| 112 | * Engine, FIFO control |
| 113 | */ |
| 114 | |
| 115 | static int r128_do_pixcache_flush( drm_r128_private_t *dev_priv ) |
| 116 | { |
| 117 | u32 tmp; |
| 118 | int i; |
| 119 | |
| 120 | tmp = R128_READ( R128_PC_NGUI_CTLSTAT ) | R128_PC_FLUSH_ALL; |
| 121 | R128_WRITE( R128_PC_NGUI_CTLSTAT, tmp ); |
| 122 | |
| 123 | for ( i = 0 ; i < dev_priv->usec_timeout ; i++ ) { |
| 124 | if ( !(R128_READ( R128_PC_NGUI_CTLSTAT ) & R128_PC_BUSY) ) { |
| 125 | return 0; |
| 126 | } |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 127 | DRM_UDELAY( 1 ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 128 | } |
| 129 | |
David Dawes | d87c873 | 2001-06-14 22:23:44 +0000 | [diff] [blame] | 130 | #if R128_FIFO_DEBUG |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 131 | DRM_ERROR( "failed!\n" ); |
David Dawes | d87c873 | 2001-06-14 22:23:44 +0000 | [diff] [blame] | 132 | #endif |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 133 | return DRM_ERR(EBUSY); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | static int r128_do_wait_for_fifo( drm_r128_private_t *dev_priv, int entries ) |
| 137 | { |
| 138 | int i; |
| 139 | |
| 140 | for ( i = 0 ; i < dev_priv->usec_timeout ; i++ ) { |
| 141 | int slots = R128_READ( R128_GUI_STAT ) & R128_GUI_FIFOCNT_MASK; |
| 142 | if ( slots >= entries ) return 0; |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 143 | DRM_UDELAY( 1 ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 144 | } |
| 145 | |
David Dawes | d87c873 | 2001-06-14 22:23:44 +0000 | [diff] [blame] | 146 | #if R128_FIFO_DEBUG |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 147 | DRM_ERROR( "failed!\n" ); |
David Dawes | d87c873 | 2001-06-14 22:23:44 +0000 | [diff] [blame] | 148 | #endif |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 149 | return DRM_ERR(EBUSY); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Eric Anholt | 0f094c3 | 2003-08-18 23:42:16 +0000 | [diff] [blame] | 152 | static int r128_do_wait_for_idle( drm_r128_private_t *dev_priv ) |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 153 | { |
| 154 | int i, ret; |
| 155 | |
| 156 | ret = r128_do_wait_for_fifo( dev_priv, 64 ); |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 157 | if ( ret ) return ret; |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 158 | |
| 159 | for ( i = 0 ; i < dev_priv->usec_timeout ; i++ ) { |
| 160 | if ( !(R128_READ( R128_GUI_STAT ) & R128_GUI_ACTIVE) ) { |
| 161 | r128_do_pixcache_flush( dev_priv ); |
| 162 | return 0; |
| 163 | } |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 164 | DRM_UDELAY( 1 ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 165 | } |
| 166 | |
David Dawes | d87c873 | 2001-06-14 22:23:44 +0000 | [diff] [blame] | 167 | #if R128_FIFO_DEBUG |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 168 | DRM_ERROR( "failed!\n" ); |
David Dawes | d87c873 | 2001-06-14 22:23:44 +0000 | [diff] [blame] | 169 | #endif |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 170 | return DRM_ERR(EBUSY); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | |
| 174 | /* ================================================================ |
| 175 | * CCE control, initialization |
| 176 | */ |
| 177 | |
| 178 | /* Load the microcode for the CCE */ |
| 179 | static void r128_cce_load_microcode( drm_r128_private_t *dev_priv ) |
| 180 | { |
| 181 | int i; |
| 182 | |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 183 | DRM_DEBUG( "\n" ); |
Kevin E Martin | 5d6ddbc | 2001-04-05 22:16:12 +0000 | [diff] [blame] | 184 | |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 185 | r128_do_wait_for_idle( dev_priv ); |
| 186 | |
| 187 | R128_WRITE( R128_PM4_MICROCODE_ADDR, 0 ); |
| 188 | for ( i = 0 ; i < 256 ; i++ ) { |
| 189 | R128_WRITE( R128_PM4_MICROCODE_DATAH, |
| 190 | r128_cce_microcode[i * 2] ); |
| 191 | R128_WRITE( R128_PM4_MICROCODE_DATAL, |
| 192 | r128_cce_microcode[i * 2 + 1] ); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | /* Flush any pending commands to the CCE. This should only be used just |
| 197 | * prior to a wait for idle, as it informs the engine that the command |
| 198 | * stream is ending. |
| 199 | */ |
| 200 | static void r128_do_cce_flush( drm_r128_private_t *dev_priv ) |
| 201 | { |
| 202 | u32 tmp; |
| 203 | |
| 204 | tmp = R128_READ( R128_PM4_BUFFER_DL_WPTR ) | R128_PM4_BUFFER_DL_DONE; |
| 205 | R128_WRITE( R128_PM4_BUFFER_DL_WPTR, tmp ); |
| 206 | } |
| 207 | |
| 208 | /* Wait for the CCE to go idle. |
| 209 | */ |
Gareth Hughes | 4d2a445 | 2001-01-24 15:34:46 +0000 | [diff] [blame] | 210 | int r128_do_cce_idle( drm_r128_private_t *dev_priv ) |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 211 | { |
| 212 | int i; |
| 213 | |
| 214 | for ( i = 0 ; i < dev_priv->usec_timeout ; i++ ) { |
Michel Daenzer | 355b204 | 2003-10-16 14:18:52 +0000 | [diff] [blame] | 215 | if ( GET_RING_HEAD( dev_priv ) == dev_priv->ring.tail ) { |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 216 | int pm4stat = R128_READ( R128_PM4_STAT ); |
| 217 | if ( ( (pm4stat & R128_PM4_FIFOCNT_MASK) >= |
| 218 | dev_priv->cce_fifo_size ) && |
| 219 | !(pm4stat & (R128_PM4_BUSY | |
| 220 | R128_PM4_GUI_ACTIVE)) ) { |
| 221 | return r128_do_pixcache_flush( dev_priv ); |
| 222 | } |
| 223 | } |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 224 | DRM_UDELAY( 1 ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Kevin E Martin | 0994e63 | 2001-01-05 22:57:55 +0000 | [diff] [blame] | 227 | #if R128_FIFO_DEBUG |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 228 | DRM_ERROR( "failed!\n" ); |
| 229 | r128_status( dev_priv ); |
| 230 | #endif |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 231 | return DRM_ERR(EBUSY); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | /* Start the Concurrent Command Engine. |
| 235 | */ |
| 236 | static void r128_do_cce_start( drm_r128_private_t *dev_priv ) |
| 237 | { |
| 238 | r128_do_wait_for_idle( dev_priv ); |
| 239 | |
| 240 | R128_WRITE( R128_PM4_BUFFER_CNTL, |
Michel Daenzer | 355b204 | 2003-10-16 14:18:52 +0000 | [diff] [blame] | 241 | dev_priv->cce_mode | dev_priv->ring.size_l2qw |
| 242 | | R128_PM4_BUFFER_CNTL_NOUPDATE ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 243 | R128_READ( R128_PM4_BUFFER_ADDR ); /* as per the sample code */ |
| 244 | R128_WRITE( R128_PM4_MICRO_CNTL, R128_PM4_MICRO_FREERUN ); |
| 245 | |
| 246 | dev_priv->cce_running = 1; |
| 247 | } |
| 248 | |
| 249 | /* Reset the Concurrent Command Engine. This will not flush any pending |
Kevin E Martin | 0994e63 | 2001-01-05 22:57:55 +0000 | [diff] [blame] | 250 | * commands, so you must wait for the CCE command stream to complete |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 251 | * before calling this routine. |
| 252 | */ |
| 253 | static void r128_do_cce_reset( drm_r128_private_t *dev_priv ) |
| 254 | { |
| 255 | R128_WRITE( R128_PM4_BUFFER_DL_WPTR, 0 ); |
| 256 | R128_WRITE( R128_PM4_BUFFER_DL_RPTR, 0 ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 257 | dev_priv->ring.tail = 0; |
| 258 | } |
| 259 | |
| 260 | /* Stop the Concurrent Command Engine. This will not flush any pending |
Kevin E Martin | 0994e63 | 2001-01-05 22:57:55 +0000 | [diff] [blame] | 261 | * commands, so you must flush the command stream and wait for the CCE |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 262 | * to go idle before calling this routine. |
| 263 | */ |
| 264 | static void r128_do_cce_stop( drm_r128_private_t *dev_priv ) |
| 265 | { |
| 266 | R128_WRITE( R128_PM4_MICRO_CNTL, 0 ); |
Michel Daenzer | 355b204 | 2003-10-16 14:18:52 +0000 | [diff] [blame] | 267 | R128_WRITE( R128_PM4_BUFFER_CNTL, |
| 268 | R128_PM4_NONPM4 | R128_PM4_BUFFER_CNTL_NOUPDATE ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 269 | |
| 270 | dev_priv->cce_running = 0; |
| 271 | } |
| 272 | |
| 273 | /* Reset the engine. This will stop the CCE if it is running. |
| 274 | */ |
| 275 | static int r128_do_engine_reset( drm_device_t *dev ) |
| 276 | { |
| 277 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 278 | u32 clock_cntl_index, mclk_cntl, gen_reset_cntl; |
| 279 | |
| 280 | r128_do_pixcache_flush( dev_priv ); |
| 281 | |
| 282 | clock_cntl_index = R128_READ( R128_CLOCK_CNTL_INDEX ); |
| 283 | mclk_cntl = R128_READ_PLL( dev, R128_MCLK_CNTL ); |
| 284 | |
| 285 | R128_WRITE_PLL( R128_MCLK_CNTL, |
| 286 | mclk_cntl | R128_FORCE_GCP | R128_FORCE_PIPE3D_CP ); |
| 287 | |
| 288 | gen_reset_cntl = R128_READ( R128_GEN_RESET_CNTL ); |
| 289 | |
| 290 | /* Taken from the sample code - do not change */ |
| 291 | R128_WRITE( R128_GEN_RESET_CNTL, |
| 292 | gen_reset_cntl | R128_SOFT_RESET_GUI ); |
| 293 | R128_READ( R128_GEN_RESET_CNTL ); |
| 294 | R128_WRITE( R128_GEN_RESET_CNTL, |
| 295 | gen_reset_cntl & ~R128_SOFT_RESET_GUI ); |
| 296 | R128_READ( R128_GEN_RESET_CNTL ); |
| 297 | |
| 298 | R128_WRITE_PLL( R128_MCLK_CNTL, mclk_cntl ); |
| 299 | R128_WRITE( R128_CLOCK_CNTL_INDEX, clock_cntl_index ); |
| 300 | R128_WRITE( R128_GEN_RESET_CNTL, gen_reset_cntl ); |
| 301 | |
| 302 | /* Reset the CCE ring */ |
| 303 | r128_do_cce_reset( dev_priv ); |
| 304 | |
| 305 | /* The CCE is no longer running after an engine reset */ |
| 306 | dev_priv->cce_running = 0; |
| 307 | |
| 308 | /* Reset any pending vertex, indirect buffers */ |
| 309 | r128_freelist_reset( dev ); |
| 310 | |
| 311 | return 0; |
| 312 | } |
| 313 | |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 314 | static void r128_cce_init_ring_buffer( drm_device_t *dev, |
| 315 | drm_r128_private_t *dev_priv ) |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 316 | { |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 317 | u32 ring_start; |
| 318 | u32 tmp; |
| 319 | |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 320 | DRM_DEBUG( "\n" ); |
Kevin E Martin | 5d6ddbc | 2001-04-05 22:16:12 +0000 | [diff] [blame] | 321 | |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 322 | /* The manual (p. 2) says this address is in "VM space". This |
| 323 | * means it's an offset from the start of AGP space. |
| 324 | */ |
Kevin E Martin | 5d6ddbc | 2001-04-05 22:16:12 +0000 | [diff] [blame] | 325 | #if __REALLY_HAVE_AGP |
| 326 | if ( !dev_priv->is_pci ) |
| 327 | ring_start = dev_priv->cce_ring->offset - dev->agp->base; |
| 328 | else |
| 329 | #endif |
| 330 | ring_start = dev_priv->cce_ring->offset - dev->sg->handle; |
| 331 | |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 332 | R128_WRITE( R128_PM4_BUFFER_OFFSET, ring_start | R128_AGP_OFFSET ); |
| 333 | |
| 334 | R128_WRITE( R128_PM4_BUFFER_DL_WPTR, 0 ); |
| 335 | R128_WRITE( R128_PM4_BUFFER_DL_RPTR, 0 ); |
| 336 | |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 337 | /* Set watermark control */ |
| 338 | R128_WRITE( R128_PM4_BUFFER_WM_CNTL, |
| 339 | ((R128_WATERMARK_L/4) << R128_WMA_SHIFT) |
| 340 | | ((R128_WATERMARK_M/4) << R128_WMB_SHIFT) |
| 341 | | ((R128_WATERMARK_N/4) << R128_WMC_SHIFT) |
| 342 | | ((R128_WATERMARK_K/64) << R128_WB_WM_SHIFT) ); |
| 343 | |
| 344 | /* Force read. Why? Because it's in the examples... */ |
| 345 | R128_READ( R128_PM4_BUFFER_ADDR ); |
| 346 | |
| 347 | /* Turn on bus mastering */ |
| 348 | tmp = R128_READ( R128_BUS_CNTL ) & ~R128_BUS_MASTER_DIS; |
| 349 | R128_WRITE( R128_BUS_CNTL, tmp ); |
| 350 | } |
| 351 | |
| 352 | static int r128_do_init_cce( drm_device_t *dev, drm_r128_init_t *init ) |
| 353 | { |
| 354 | drm_r128_private_t *dev_priv; |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 355 | |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 356 | DRM_DEBUG( "\n" ); |
Kevin E Martin | 5d6ddbc | 2001-04-05 22:16:12 +0000 | [diff] [blame] | 357 | |
Gareth Hughes | 3604753 | 2001-02-15 08:12:14 +0000 | [diff] [blame] | 358 | dev_priv = DRM(alloc)( sizeof(drm_r128_private_t), DRM_MEM_DRIVER ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 359 | if ( dev_priv == NULL ) |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 360 | return DRM_ERR(ENOMEM); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 361 | |
| 362 | memset( dev_priv, 0, sizeof(drm_r128_private_t) ); |
| 363 | |
| 364 | dev_priv->is_pci = init->is_pci; |
| 365 | |
Kevin E Martin | 5d6ddbc | 2001-04-05 22:16:12 +0000 | [diff] [blame] | 366 | if ( dev_priv->is_pci && !dev->sg ) { |
Kevin E Martin | 5d6ddbc | 2001-04-05 22:16:12 +0000 | [diff] [blame] | 367 | DRM_ERROR( "PCI GART memory not allocated!\n" ); |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 368 | dev->dev_private = (void *)dev_priv; |
| 369 | r128_do_cleanup_cce( dev ); |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 370 | return DRM_ERR(EINVAL); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | dev_priv->usec_timeout = init->usec_timeout; |
| 374 | if ( dev_priv->usec_timeout < 1 || |
| 375 | dev_priv->usec_timeout > R128_MAX_USEC_TIMEOUT ) { |
Kevin E Martin | 5d6ddbc | 2001-04-05 22:16:12 +0000 | [diff] [blame] | 376 | DRM_DEBUG( "TIMEOUT problem!\n" ); |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 377 | dev->dev_private = (void *)dev_priv; |
| 378 | r128_do_cleanup_cce( dev ); |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 379 | return DRM_ERR(EINVAL); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | dev_priv->cce_mode = init->cce_mode; |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 383 | |
| 384 | /* GH: Simple idle check. |
| 385 | */ |
| 386 | atomic_set( &dev_priv->idle_count, 0 ); |
| 387 | |
| 388 | /* We don't support anything other than bus-mastering ring mode, |
| 389 | * but the ring can be in either AGP or PCI space for the ring |
| 390 | * read pointer. |
| 391 | */ |
| 392 | if ( ( init->cce_mode != R128_PM4_192BM ) && |
| 393 | ( init->cce_mode != R128_PM4_128BM_64INDBM ) && |
| 394 | ( init->cce_mode != R128_PM4_64BM_128INDBM ) && |
| 395 | ( init->cce_mode != R128_PM4_64BM_64VCBM_64INDBM ) ) { |
Kevin E Martin | 5d6ddbc | 2001-04-05 22:16:12 +0000 | [diff] [blame] | 396 | DRM_DEBUG( "Bad cce_mode!\n" ); |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 397 | dev->dev_private = (void *)dev_priv; |
| 398 | r128_do_cleanup_cce( dev ); |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 399 | return DRM_ERR(EINVAL); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | switch ( init->cce_mode ) { |
| 403 | case R128_PM4_NONPM4: |
| 404 | dev_priv->cce_fifo_size = 0; |
| 405 | break; |
| 406 | case R128_PM4_192PIO: |
| 407 | case R128_PM4_192BM: |
| 408 | dev_priv->cce_fifo_size = 192; |
| 409 | break; |
| 410 | case R128_PM4_128PIO_64INDBM: |
| 411 | case R128_PM4_128BM_64INDBM: |
| 412 | dev_priv->cce_fifo_size = 128; |
| 413 | break; |
| 414 | case R128_PM4_64PIO_128INDBM: |
| 415 | case R128_PM4_64BM_128INDBM: |
| 416 | case R128_PM4_64PIO_64VCBM_64INDBM: |
| 417 | case R128_PM4_64BM_64VCBM_64INDBM: |
| 418 | case R128_PM4_64PIO_64VCPIO_64INDPIO: |
| 419 | dev_priv->cce_fifo_size = 64; |
| 420 | break; |
| 421 | } |
| 422 | |
Gareth Hughes | 4d2a445 | 2001-01-24 15:34:46 +0000 | [diff] [blame] | 423 | switch ( init->fb_bpp ) { |
| 424 | case 16: |
| 425 | dev_priv->color_fmt = R128_DATATYPE_RGB565; |
| 426 | break; |
| 427 | case 32: |
| 428 | default: |
| 429 | dev_priv->color_fmt = R128_DATATYPE_ARGB8888; |
| 430 | break; |
| 431 | } |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 432 | dev_priv->front_offset = init->front_offset; |
| 433 | dev_priv->front_pitch = init->front_pitch; |
| 434 | dev_priv->back_offset = init->back_offset; |
| 435 | dev_priv->back_pitch = init->back_pitch; |
| 436 | |
Gareth Hughes | 4d2a445 | 2001-01-24 15:34:46 +0000 | [diff] [blame] | 437 | switch ( init->depth_bpp ) { |
| 438 | case 16: |
| 439 | dev_priv->depth_fmt = R128_DATATYPE_RGB565; |
| 440 | break; |
| 441 | case 24: |
| 442 | case 32: |
| 443 | default: |
| 444 | dev_priv->depth_fmt = R128_DATATYPE_ARGB8888; |
| 445 | break; |
| 446 | } |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 447 | dev_priv->depth_offset = init->depth_offset; |
| 448 | dev_priv->depth_pitch = init->depth_pitch; |
| 449 | dev_priv->span_offset = init->span_offset; |
| 450 | |
| 451 | dev_priv->front_pitch_offset_c = (((dev_priv->front_pitch/8) << 21) | |
| 452 | (dev_priv->front_offset >> 5)); |
| 453 | dev_priv->back_pitch_offset_c = (((dev_priv->back_pitch/8) << 21) | |
| 454 | (dev_priv->back_offset >> 5)); |
| 455 | dev_priv->depth_pitch_offset_c = (((dev_priv->depth_pitch/8) << 21) | |
| 456 | (dev_priv->depth_offset >> 5) | |
| 457 | R128_DST_TILE); |
| 458 | dev_priv->span_pitch_offset_c = (((dev_priv->depth_pitch/8) << 21) | |
| 459 | (dev_priv->span_offset >> 5)); |
| 460 | |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 461 | DRM_GETSAREA(); |
| 462 | |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 463 | if(!dev_priv->sarea) { |
| 464 | DRM_ERROR("could not find sarea!\n"); |
| 465 | dev->dev_private = (void *)dev_priv; |
| 466 | r128_do_cleanup_cce( dev ); |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 467 | return DRM_ERR(EINVAL); |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 468 | } |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 469 | |
Gareth Hughes | 4d2a445 | 2001-01-24 15:34:46 +0000 | [diff] [blame] | 470 | DRM_FIND_MAP( dev_priv->fb, init->fb_offset ); |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 471 | if(!dev_priv->fb) { |
| 472 | DRM_ERROR("could not find framebuffer!\n"); |
| 473 | dev->dev_private = (void *)dev_priv; |
| 474 | r128_do_cleanup_cce( dev ); |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 475 | return DRM_ERR(EINVAL); |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 476 | } |
Gareth Hughes | 4d2a445 | 2001-01-24 15:34:46 +0000 | [diff] [blame] | 477 | DRM_FIND_MAP( dev_priv->mmio, init->mmio_offset ); |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 478 | if(!dev_priv->mmio) { |
| 479 | DRM_ERROR("could not find mmio region!\n"); |
| 480 | dev->dev_private = (void *)dev_priv; |
| 481 | r128_do_cleanup_cce( dev ); |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 482 | return DRM_ERR(EINVAL); |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 483 | } |
Gareth Hughes | 4d2a445 | 2001-01-24 15:34:46 +0000 | [diff] [blame] | 484 | DRM_FIND_MAP( dev_priv->cce_ring, init->ring_offset ); |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 485 | if(!dev_priv->cce_ring) { |
| 486 | DRM_ERROR("could not find cce ring region!\n"); |
| 487 | dev->dev_private = (void *)dev_priv; |
| 488 | r128_do_cleanup_cce( dev ); |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 489 | return DRM_ERR(EINVAL); |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 490 | } |
Gareth Hughes | 4d2a445 | 2001-01-24 15:34:46 +0000 | [diff] [blame] | 491 | DRM_FIND_MAP( dev_priv->ring_rptr, init->ring_rptr_offset ); |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 492 | if(!dev_priv->ring_rptr) { |
| 493 | DRM_ERROR("could not find ring read pointer!\n"); |
| 494 | dev->dev_private = (void *)dev_priv; |
| 495 | r128_do_cleanup_cce( dev ); |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 496 | return DRM_ERR(EINVAL); |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 497 | } |
Gareth Hughes | 4d2a445 | 2001-01-24 15:34:46 +0000 | [diff] [blame] | 498 | DRM_FIND_MAP( dev_priv->buffers, init->buffers_offset ); |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 499 | if(!dev_priv->buffers) { |
| 500 | DRM_ERROR("could not find dma buffer region!\n"); |
| 501 | dev->dev_private = (void *)dev_priv; |
| 502 | r128_do_cleanup_cce( dev ); |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 503 | return DRM_ERR(EINVAL); |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 504 | } |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 505 | |
| 506 | if ( !dev_priv->is_pci ) { |
Gareth Hughes | 4d2a445 | 2001-01-24 15:34:46 +0000 | [diff] [blame] | 507 | DRM_FIND_MAP( dev_priv->agp_textures, |
| 508 | init->agp_textures_offset ); |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 509 | if(!dev_priv->agp_textures) { |
| 510 | DRM_ERROR("could not find agp texture region!\n"); |
| 511 | dev->dev_private = (void *)dev_priv; |
| 512 | r128_do_cleanup_cce( dev ); |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 513 | return DRM_ERR(EINVAL); |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 514 | } |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | dev_priv->sarea_priv = |
| 518 | (drm_r128_sarea_t *)((u8 *)dev_priv->sarea->handle + |
| 519 | init->sarea_priv_offset); |
| 520 | |
Michel Daenzer | e5d3c7f | 2003-05-16 23:41:27 +0000 | [diff] [blame] | 521 | #if __REALLY_HAVE_AGP |
Kevin E Martin | 5d6ddbc | 2001-04-05 22:16:12 +0000 | [diff] [blame] | 522 | if ( !dev_priv->is_pci ) { |
Michel Daenzer | e5d3c7f | 2003-05-16 23:41:27 +0000 | [diff] [blame] | 523 | DRM_IOREMAP( dev_priv->cce_ring, dev ); |
| 524 | DRM_IOREMAP( dev_priv->ring_rptr, dev ); |
| 525 | DRM_IOREMAP( dev_priv->buffers, dev ); |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 526 | if(!dev_priv->cce_ring->handle || |
| 527 | !dev_priv->ring_rptr->handle || |
| 528 | !dev_priv->buffers->handle) { |
| 529 | DRM_ERROR("Could not ioremap agp regions!\n"); |
| 530 | dev->dev_private = (void *)dev_priv; |
| 531 | r128_do_cleanup_cce( dev ); |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 532 | return DRM_ERR(ENOMEM); |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 533 | } |
Michel Daenzer | e5d3c7f | 2003-05-16 23:41:27 +0000 | [diff] [blame] | 534 | } else |
| 535 | #endif |
| 536 | { |
Kevin E Martin | 5d6ddbc | 2001-04-05 22:16:12 +0000 | [diff] [blame] | 537 | dev_priv->cce_ring->handle = |
| 538 | (void *)dev_priv->cce_ring->offset; |
| 539 | dev_priv->ring_rptr->handle = |
| 540 | (void *)dev_priv->ring_rptr->offset; |
| 541 | dev_priv->buffers->handle = (void *)dev_priv->buffers->offset; |
| 542 | } |
| 543 | |
| 544 | #if __REALLY_HAVE_AGP |
| 545 | if ( !dev_priv->is_pci ) |
| 546 | dev_priv->cce_buffers_offset = dev->agp->base; |
| 547 | else |
| 548 | #endif |
| 549 | dev_priv->cce_buffers_offset = dev->sg->handle; |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 550 | |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 551 | dev_priv->ring.start = (u32 *)dev_priv->cce_ring->handle; |
| 552 | dev_priv->ring.end = ((u32 *)dev_priv->cce_ring->handle |
| 553 | + init->ring_size / sizeof(u32)); |
| 554 | dev_priv->ring.size = init->ring_size; |
Gareth Hughes | 3604753 | 2001-02-15 08:12:14 +0000 | [diff] [blame] | 555 | dev_priv->ring.size_l2qw = DRM(order)( init->ring_size / 8 ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 556 | |
| 557 | dev_priv->ring.tail_mask = |
| 558 | (dev_priv->ring.size / sizeof(u32)) - 1; |
| 559 | |
Gareth Hughes | 4d2a445 | 2001-01-24 15:34:46 +0000 | [diff] [blame] | 560 | dev_priv->ring.high_mark = 128; |
| 561 | |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 562 | dev_priv->sarea_priv->last_frame = 0; |
| 563 | R128_WRITE( R128_LAST_FRAME_REG, dev_priv->sarea_priv->last_frame ); |
| 564 | |
| 565 | dev_priv->sarea_priv->last_dispatch = 0; |
| 566 | R128_WRITE( R128_LAST_DISPATCH_REG, |
| 567 | dev_priv->sarea_priv->last_dispatch ); |
| 568 | |
Michel Daenzer | 355b204 | 2003-10-16 14:18:52 +0000 | [diff] [blame] | 569 | #if __REALLY_HAVE_AGP |
Kevin E Martin | 5d6ddbc | 2001-04-05 22:16:12 +0000 | [diff] [blame] | 570 | if ( dev_priv->is_pci ) { |
Michel Daenzer | 355b204 | 2003-10-16 14:18:52 +0000 | [diff] [blame] | 571 | #endif |
Jeff Hartmann | 97b8aa5 | 2001-08-10 16:29:21 +0000 | [diff] [blame] | 572 | if (!DRM(ati_pcigart_init)( dev, &dev_priv->phys_pci_gart, |
| 573 | &dev_priv->bus_pci_gart) ) { |
Kevin E Martin | 5d6ddbc | 2001-04-05 22:16:12 +0000 | [diff] [blame] | 574 | DRM_ERROR( "failed to init PCI GART!\n" ); |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 575 | dev->dev_private = (void *)dev_priv; |
| 576 | r128_do_cleanup_cce( dev ); |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 577 | return DRM_ERR(ENOMEM); |
Kevin E Martin | 5d6ddbc | 2001-04-05 22:16:12 +0000 | [diff] [blame] | 578 | } |
Jeff Hartmann | 97b8aa5 | 2001-08-10 16:29:21 +0000 | [diff] [blame] | 579 | R128_WRITE( R128_PCI_GART_PAGE, dev_priv->bus_pci_gart ); |
Michel Daenzer | 355b204 | 2003-10-16 14:18:52 +0000 | [diff] [blame] | 580 | #if __REALLY_HAVE_AGP |
Kevin E Martin | 5d6ddbc | 2001-04-05 22:16:12 +0000 | [diff] [blame] | 581 | } |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 582 | #endif |
Kevin E Martin | 5d6ddbc | 2001-04-05 22:16:12 +0000 | [diff] [blame] | 583 | |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 584 | r128_cce_init_ring_buffer( dev, dev_priv ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 585 | r128_cce_load_microcode( dev_priv ); |
Jeff Hartmann | 51e38d9 | 2001-08-07 18:15:10 +0000 | [diff] [blame] | 586 | |
| 587 | dev->dev_private = (void *)dev_priv; |
| 588 | |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 589 | r128_do_engine_reset( dev ); |
| 590 | |
| 591 | return 0; |
| 592 | } |
| 593 | |
Gareth Hughes | 3604753 | 2001-02-15 08:12:14 +0000 | [diff] [blame] | 594 | int r128_do_cleanup_cce( drm_device_t *dev ) |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 595 | { |
Leif Delgass | f2a0c54 | 2003-04-26 22:28:56 +0000 | [diff] [blame] | 596 | |
Eric Anholt | 2950f9e | 2003-10-17 05:13:48 +0000 | [diff] [blame^] | 597 | #if __HAVE_IRQ |
Leif Delgass | f2a0c54 | 2003-04-26 22:28:56 +0000 | [diff] [blame] | 598 | /* Make sure interrupts are disabled here because the uninstall ioctl |
| 599 | * may not have been called from userspace and after dev_private |
| 600 | * is freed, it's too late. |
| 601 | */ |
| 602 | if ( dev->irq ) DRM(irq_uninstall)(dev); |
| 603 | #endif |
| 604 | |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 605 | if ( dev->dev_private ) { |
| 606 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 607 | |
Michel Daenzer | e5d3c7f | 2003-05-16 23:41:27 +0000 | [diff] [blame] | 608 | #if __REALLY_HAVE_AGP |
Kevin E Martin | 5d6ddbc | 2001-04-05 22:16:12 +0000 | [diff] [blame] | 609 | if ( !dev_priv->is_pci ) { |
Leif Delgass | 46e0619 | 2003-04-21 16:07:17 +0000 | [diff] [blame] | 610 | if ( dev_priv->cce_ring != NULL ) |
Michel Daenzer | e5d3c7f | 2003-05-16 23:41:27 +0000 | [diff] [blame] | 611 | DRM_IOREMAPFREE( dev_priv->cce_ring, dev ); |
Leif Delgass | 46e0619 | 2003-04-21 16:07:17 +0000 | [diff] [blame] | 612 | if ( dev_priv->ring_rptr != NULL ) |
Michel Daenzer | e5d3c7f | 2003-05-16 23:41:27 +0000 | [diff] [blame] | 613 | DRM_IOREMAPFREE( dev_priv->ring_rptr, dev ); |
Leif Delgass | 46e0619 | 2003-04-21 16:07:17 +0000 | [diff] [blame] | 614 | if ( dev_priv->buffers != NULL ) |
Michel Daenzer | e5d3c7f | 2003-05-16 23:41:27 +0000 | [diff] [blame] | 615 | DRM_IOREMAPFREE( dev_priv->buffers, dev ); |
| 616 | } else |
| 617 | #endif |
| 618 | { |
Jeff Hartmann | 97b8aa5 | 2001-08-10 16:29:21 +0000 | [diff] [blame] | 619 | if (!DRM(ati_pcigart_cleanup)( dev, |
| 620 | dev_priv->phys_pci_gart, |
| 621 | dev_priv->bus_pci_gart )) |
| 622 | DRM_ERROR( "failed to cleanup PCI GART!\n" ); |
Kevin E Martin | 5d6ddbc | 2001-04-05 22:16:12 +0000 | [diff] [blame] | 623 | } |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 624 | |
Gareth Hughes | 3604753 | 2001-02-15 08:12:14 +0000 | [diff] [blame] | 625 | DRM(free)( dev->dev_private, sizeof(drm_r128_private_t), |
| 626 | DRM_MEM_DRIVER ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 627 | dev->dev_private = NULL; |
| 628 | } |
| 629 | |
| 630 | return 0; |
| 631 | } |
| 632 | |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 633 | int r128_cce_init( DRM_IOCTL_ARGS ) |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 634 | { |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 635 | DRM_DEVICE; |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 636 | drm_r128_init_t init; |
| 637 | |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 638 | DRM_DEBUG( "\n" ); |
Kevin E Martin | 5d6ddbc | 2001-04-05 22:16:12 +0000 | [diff] [blame] | 639 | |
Leif Delgass | f2a0c54 | 2003-04-26 22:28:56 +0000 | [diff] [blame] | 640 | LOCK_TEST_WITH_RETURN( dev, filp ); |
| 641 | |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 642 | DRM_COPY_FROM_USER_IOCTL( init, (drm_r128_init_t *)data, sizeof(init) ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 643 | |
| 644 | switch ( init.func ) { |
| 645 | case R128_INIT_CCE: |
| 646 | return r128_do_init_cce( dev, &init ); |
| 647 | case R128_CLEANUP_CCE: |
| 648 | return r128_do_cleanup_cce( dev ); |
| 649 | } |
| 650 | |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 651 | return DRM_ERR(EINVAL); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 652 | } |
| 653 | |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 654 | int r128_cce_start( DRM_IOCTL_ARGS ) |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 655 | { |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 656 | DRM_DEVICE; |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 657 | drm_r128_private_t *dev_priv = dev->dev_private; |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 658 | DRM_DEBUG( "\n" ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 659 | |
Keith Whitwell | 1728bc6 | 2003-03-28 14:27:37 +0000 | [diff] [blame] | 660 | LOCK_TEST_WITH_RETURN( dev, filp ); |
Gareth Hughes | 4d2a445 | 2001-01-24 15:34:46 +0000 | [diff] [blame] | 661 | |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 662 | if ( dev_priv->cce_running || dev_priv->cce_mode == R128_PM4_NONPM4 ) { |
Keith Whitwell | 4fcde1e | 2002-08-29 07:34:49 +0000 | [diff] [blame] | 663 | DRM_DEBUG( "%s while CCE running\n", __FUNCTION__ ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | r128_do_cce_start( dev_priv ); |
| 668 | |
| 669 | return 0; |
| 670 | } |
| 671 | |
| 672 | /* Stop the CCE. The engine must have been idled before calling this |
| 673 | * routine. |
| 674 | */ |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 675 | int r128_cce_stop( DRM_IOCTL_ARGS ) |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 676 | { |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 677 | DRM_DEVICE; |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 678 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 679 | drm_r128_cce_stop_t stop; |
| 680 | int ret; |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 681 | DRM_DEBUG( "\n" ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 682 | |
Keith Whitwell | 1728bc6 | 2003-03-28 14:27:37 +0000 | [diff] [blame] | 683 | LOCK_TEST_WITH_RETURN( dev, filp ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 684 | |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 685 | DRM_COPY_FROM_USER_IOCTL(stop, (drm_r128_cce_stop_t *)data, sizeof(stop) ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 686 | |
| 687 | /* Flush any pending CCE commands. This ensures any outstanding |
| 688 | * commands are exectuted by the engine before we turn it off. |
| 689 | */ |
| 690 | if ( stop.flush ) { |
| 691 | r128_do_cce_flush( dev_priv ); |
| 692 | } |
| 693 | |
| 694 | /* If we fail to make the engine go idle, we return an error |
| 695 | * code so that the DRM ioctl wrapper can try again. |
| 696 | */ |
| 697 | if ( stop.idle ) { |
| 698 | ret = r128_do_cce_idle( dev_priv ); |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 699 | if ( ret ) return ret; |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | /* Finally, we can turn off the CCE. If the engine isn't idle, |
| 703 | * we will get some dropped triangles as they won't be fully |
| 704 | * rendered before the CCE is shut down. |
| 705 | */ |
| 706 | r128_do_cce_stop( dev_priv ); |
| 707 | |
| 708 | /* Reset the engine */ |
| 709 | r128_do_engine_reset( dev ); |
| 710 | |
| 711 | return 0; |
| 712 | } |
| 713 | |
| 714 | /* Just reset the CCE ring. Called as part of an X Server engine reset. |
| 715 | */ |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 716 | int r128_cce_reset( DRM_IOCTL_ARGS ) |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 717 | { |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 718 | DRM_DEVICE; |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 719 | drm_r128_private_t *dev_priv = dev->dev_private; |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 720 | DRM_DEBUG( "\n" ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 721 | |
Keith Whitwell | 1728bc6 | 2003-03-28 14:27:37 +0000 | [diff] [blame] | 722 | LOCK_TEST_WITH_RETURN( dev, filp ); |
Gareth Hughes | 4d2a445 | 2001-01-24 15:34:46 +0000 | [diff] [blame] | 723 | |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 724 | if ( !dev_priv ) { |
Keith Whitwell | 4fcde1e | 2002-08-29 07:34:49 +0000 | [diff] [blame] | 725 | DRM_DEBUG( "%s called before init done\n", __FUNCTION__ ); |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 726 | return DRM_ERR(EINVAL); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | r128_do_cce_reset( dev_priv ); |
| 730 | |
| 731 | /* The CCE is no longer running after an engine reset */ |
| 732 | dev_priv->cce_running = 0; |
| 733 | |
| 734 | return 0; |
| 735 | } |
| 736 | |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 737 | int r128_cce_idle( DRM_IOCTL_ARGS ) |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 738 | { |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 739 | DRM_DEVICE; |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 740 | drm_r128_private_t *dev_priv = dev->dev_private; |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 741 | DRM_DEBUG( "\n" ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 742 | |
Keith Whitwell | 1728bc6 | 2003-03-28 14:27:37 +0000 | [diff] [blame] | 743 | LOCK_TEST_WITH_RETURN( dev, filp ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 744 | |
| 745 | if ( dev_priv->cce_running ) { |
| 746 | r128_do_cce_flush( dev_priv ); |
| 747 | } |
| 748 | |
| 749 | return r128_do_cce_idle( dev_priv ); |
| 750 | } |
| 751 | |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 752 | int r128_engine_reset( DRM_IOCTL_ARGS ) |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 753 | { |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 754 | DRM_DEVICE; |
| 755 | DRM_DEBUG( "\n" ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 756 | |
Keith Whitwell | 1728bc6 | 2003-03-28 14:27:37 +0000 | [diff] [blame] | 757 | LOCK_TEST_WITH_RETURN( dev, filp ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 758 | |
| 759 | return r128_do_engine_reset( dev ); |
| 760 | } |
| 761 | |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 762 | int r128_fullscreen( DRM_IOCTL_ARGS ) |
Kevin E Martin | 0994e63 | 2001-01-05 22:57:55 +0000 | [diff] [blame] | 763 | { |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 764 | return DRM_ERR(EINVAL); |
Kevin E Martin | 0994e63 | 2001-01-05 22:57:55 +0000 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | |
| 768 | /* ================================================================ |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 769 | * Freelist management |
| 770 | */ |
| 771 | #define R128_BUFFER_USED 0xffffffff |
| 772 | #define R128_BUFFER_FREE 0 |
| 773 | |
Gareth Hughes | 8725828 | 2000-12-12 14:50:50 +0000 | [diff] [blame] | 774 | #if 0 |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 775 | static int r128_freelist_init( drm_device_t *dev ) |
| 776 | { |
| 777 | drm_device_dma_t *dma = dev->dma; |
| 778 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 779 | drm_buf_t *buf; |
| 780 | drm_r128_buf_priv_t *buf_priv; |
| 781 | drm_r128_freelist_t *entry; |
| 782 | int i; |
| 783 | |
Gareth Hughes | 3604753 | 2001-02-15 08:12:14 +0000 | [diff] [blame] | 784 | dev_priv->head = DRM(alloc)( sizeof(drm_r128_freelist_t), |
| 785 | DRM_MEM_DRIVER ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 786 | if ( dev_priv->head == NULL ) |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 787 | return DRM_ERR(ENOMEM); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 788 | |
| 789 | memset( dev_priv->head, 0, sizeof(drm_r128_freelist_t) ); |
| 790 | dev_priv->head->age = R128_BUFFER_USED; |
| 791 | |
| 792 | for ( i = 0 ; i < dma->buf_count ; i++ ) { |
| 793 | buf = dma->buflist[i]; |
| 794 | buf_priv = buf->dev_private; |
| 795 | |
Gareth Hughes | 3604753 | 2001-02-15 08:12:14 +0000 | [diff] [blame] | 796 | entry = DRM(alloc)( sizeof(drm_r128_freelist_t), |
| 797 | DRM_MEM_DRIVER ); |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 798 | if ( !entry ) return DRM_ERR(ENOMEM); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 799 | |
| 800 | entry->age = R128_BUFFER_FREE; |
| 801 | entry->buf = buf; |
| 802 | entry->prev = dev_priv->head; |
| 803 | entry->next = dev_priv->head->next; |
| 804 | if ( !entry->next ) |
| 805 | dev_priv->tail = entry; |
| 806 | |
| 807 | buf_priv->discard = 0; |
| 808 | buf_priv->dispatched = 0; |
| 809 | buf_priv->list_entry = entry; |
| 810 | |
| 811 | dev_priv->head->next = entry; |
| 812 | |
| 813 | if ( dev_priv->head->next ) |
| 814 | dev_priv->head->next->prev = entry; |
| 815 | } |
| 816 | |
| 817 | return 0; |
| 818 | |
| 819 | } |
Gareth Hughes | 8725828 | 2000-12-12 14:50:50 +0000 | [diff] [blame] | 820 | #endif |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 821 | |
| 822 | drm_buf_t *r128_freelist_get( drm_device_t *dev ) |
| 823 | { |
| 824 | drm_device_dma_t *dma = dev->dma; |
| 825 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 826 | drm_r128_buf_priv_t *buf_priv; |
| 827 | drm_buf_t *buf; |
| 828 | int i, t; |
| 829 | |
| 830 | /* FIXME: Optimize -- use freelist code */ |
| 831 | |
| 832 | for ( i = 0 ; i < dma->buf_count ; i++ ) { |
| 833 | buf = dma->buflist[i]; |
| 834 | buf_priv = buf->dev_private; |
Keith Whitwell | 1728bc6 | 2003-03-28 14:27:37 +0000 | [diff] [blame] | 835 | if ( buf->filp == 0 ) |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 836 | return buf; |
| 837 | } |
| 838 | |
| 839 | for ( t = 0 ; t < dev_priv->usec_timeout ; t++ ) { |
| 840 | u32 done_age = R128_READ( R128_LAST_DISPATCH_REG ); |
| 841 | |
| 842 | for ( i = 0 ; i < dma->buf_count ; i++ ) { |
| 843 | buf = dma->buflist[i]; |
| 844 | buf_priv = buf->dev_private; |
| 845 | if ( buf->pending && buf_priv->age <= done_age ) { |
| 846 | /* The buffer has been processed, so it |
| 847 | * can now be used. |
| 848 | */ |
| 849 | buf->pending = 0; |
| 850 | return buf; |
| 851 | } |
| 852 | } |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 853 | DRM_UDELAY( 1 ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 854 | } |
| 855 | |
Michel Daenzer | c26ffea | 2003-07-26 15:59:09 +0000 | [diff] [blame] | 856 | DRM_DEBUG( "returning NULL!\n" ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 857 | return NULL; |
| 858 | } |
| 859 | |
| 860 | void r128_freelist_reset( drm_device_t *dev ) |
| 861 | { |
| 862 | drm_device_dma_t *dma = dev->dma; |
| 863 | int i; |
| 864 | |
| 865 | for ( i = 0 ; i < dma->buf_count ; i++ ) { |
| 866 | drm_buf_t *buf = dma->buflist[i]; |
| 867 | drm_r128_buf_priv_t *buf_priv = buf->dev_private; |
| 868 | buf_priv->age = 0; |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | |
| 873 | /* ================================================================ |
Kevin E Martin | 0994e63 | 2001-01-05 22:57:55 +0000 | [diff] [blame] | 874 | * CCE command submission |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 875 | */ |
| 876 | |
| 877 | int r128_wait_ring( drm_r128_private_t *dev_priv, int n ) |
| 878 | { |
| 879 | drm_r128_ring_buffer_t *ring = &dev_priv->ring; |
| 880 | int i; |
| 881 | |
| 882 | for ( i = 0 ; i < dev_priv->usec_timeout ; i++ ) { |
Michel Daenzer | 355b204 | 2003-10-16 14:18:52 +0000 | [diff] [blame] | 883 | r128_update_ring_snapshot( dev_priv ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 884 | if ( ring->space >= n ) |
| 885 | return 0; |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 886 | DRM_UDELAY( 1 ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 887 | } |
| 888 | |
Kevin E Martin | 0994e63 | 2001-01-05 22:57:55 +0000 | [diff] [blame] | 889 | /* FIXME: This is being ignored... */ |
| 890 | DRM_ERROR( "failed!\n" ); |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 891 | return DRM_ERR(EBUSY); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 892 | } |
| 893 | |
Keith Whitwell | 1728bc6 | 2003-03-28 14:27:37 +0000 | [diff] [blame] | 894 | static int r128_cce_get_buffers( DRMFILE filp, drm_device_t *dev, drm_dma_t *d ) |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 895 | { |
| 896 | int i; |
| 897 | drm_buf_t *buf; |
| 898 | |
| 899 | for ( i = d->granted_count ; i < d->request_count ; i++ ) { |
| 900 | buf = r128_freelist_get( dev ); |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 901 | if ( !buf ) return DRM_ERR(EAGAIN); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 902 | |
Keith Whitwell | 1728bc6 | 2003-03-28 14:27:37 +0000 | [diff] [blame] | 903 | buf->filp = filp; |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 904 | |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 905 | if ( DRM_COPY_TO_USER( &d->request_indices[i], &buf->idx, |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 906 | sizeof(buf->idx) ) ) |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 907 | return DRM_ERR(EFAULT); |
| 908 | if ( DRM_COPY_TO_USER( &d->request_sizes[i], &buf->total, |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 909 | sizeof(buf->total) ) ) |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 910 | return DRM_ERR(EFAULT); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 911 | |
| 912 | d->granted_count++; |
| 913 | } |
| 914 | return 0; |
| 915 | } |
| 916 | |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 917 | int r128_cce_buffers( DRM_IOCTL_ARGS ) |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 918 | { |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 919 | DRM_DEVICE; |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 920 | drm_device_dma_t *dma = dev->dma; |
| 921 | int ret = 0; |
| 922 | drm_dma_t d; |
| 923 | |
Keith Whitwell | 1728bc6 | 2003-03-28 14:27:37 +0000 | [diff] [blame] | 924 | LOCK_TEST_WITH_RETURN( dev, filp ); |
Gareth Hughes | 4d2a445 | 2001-01-24 15:34:46 +0000 | [diff] [blame] | 925 | |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 926 | DRM_COPY_FROM_USER_IOCTL( d, (drm_dma_t *) data, sizeof(d) ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 927 | |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 928 | /* Please don't send us buffers. |
| 929 | */ |
| 930 | if ( d.send_count != 0 ) { |
| 931 | DRM_ERROR( "Process %d trying to send %d buffers via drmDMA\n", |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 932 | DRM_CURRENTPID, d.send_count ); |
| 933 | return DRM_ERR(EINVAL); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | /* We'll send you buffers. |
| 937 | */ |
| 938 | if ( d.request_count < 0 || d.request_count > dma->buf_count ) { |
| 939 | DRM_ERROR( "Process %d trying to get %d buffers (of %d max)\n", |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 940 | DRM_CURRENTPID, d.request_count, dma->buf_count ); |
| 941 | return DRM_ERR(EINVAL); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | d.granted_count = 0; |
| 945 | |
| 946 | if ( d.request_count ) { |
Keith Whitwell | 1728bc6 | 2003-03-28 14:27:37 +0000 | [diff] [blame] | 947 | ret = r128_cce_get_buffers( filp, dev, &d ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 948 | } |
| 949 | |
Alan Hourihane | 74ef13f | 2002-07-05 08:31:11 +0000 | [diff] [blame] | 950 | DRM_COPY_TO_USER_IOCTL((drm_dma_t *) data, d, sizeof(d) ); |
Gareth Hughes | e15a24e | 2000-12-02 06:14:18 +0000 | [diff] [blame] | 951 | |
| 952 | return ret; |
| 953 | } |