Dave Airlie | bc5f452 | 2007-11-05 12:50:58 +1000 | [diff] [blame] | 1 | /* r128_cce.c -- ATI Rage 128 driver -*- linux-c -*- |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Created: Wed Apr 5 19:24:19 2000 by kevin@precisioninsight.com |
Dave Airlie | f26c473 | 2006-01-02 17:18:39 +1100 | [diff] [blame] | 3 | */ |
| 4 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas. |
| 6 | * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. |
| 7 | * All Rights Reserved. |
| 8 | * |
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 10 | * copy of this software and associated documentation files (the "Software"), |
| 11 | * to deal in the Software without restriction, including without limitation |
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 13 | * and/or sell copies of the Software, and to permit persons to whom the |
| 14 | * Software is furnished to do so, subject to the following conditions: |
| 15 | * |
| 16 | * The above copyright notice and this permission notice (including the next |
| 17 | * paragraph) shall be included in all copies or substantial portions of the |
| 18 | * Software. |
| 19 | * |
| 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 23 | * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 24 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 25 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 26 | * DEALINGS IN THE SOFTWARE. |
| 27 | * |
| 28 | * Authors: |
| 29 | * Gareth Hughes <gareth@valinux.com> |
| 30 | */ |
| 31 | |
Ben Hutchings | 52f97df | 2009-08-23 18:37:26 +0100 | [diff] [blame] | 32 | #include <linux/firmware.h> |
| 33 | #include <linux/platform_device.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/slab.h> |
Paul Gortmaker | e0cd360 | 2011-08-30 11:04:30 -0400 | [diff] [blame] | 35 | #include <linux/module.h> |
Ben Hutchings | 52f97df | 2009-08-23 18:37:26 +0100 | [diff] [blame] | 36 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 37 | #include <drm/drmP.h> |
| 38 | #include <drm/r128_drm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include "r128_drv.h" |
| 40 | |
| 41 | #define R128_FIFO_DEBUG 0 |
| 42 | |
Ben Hutchings | 52f97df | 2009-08-23 18:37:26 +0100 | [diff] [blame] | 43 | #define FIRMWARE_NAME "r128/r128_cce.bin" |
| 44 | |
| 45 | MODULE_FIRMWARE(FIRMWARE_NAME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 47 | static int R128_READ_PLL(struct drm_device *dev, int addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | { |
| 49 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 50 | |
| 51 | R128_WRITE8(R128_CLOCK_CNTL_INDEX, addr & 0x1f); |
| 52 | return R128_READ(R128_CLOCK_CNTL_DATA); |
| 53 | } |
| 54 | |
| 55 | #if R128_FIFO_DEBUG |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 56 | static void r128_status(drm_r128_private_t *dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 58 | printk("GUI_STAT = 0x%08x\n", |
| 59 | (unsigned int)R128_READ(R128_GUI_STAT)); |
| 60 | printk("PM4_STAT = 0x%08x\n", |
| 61 | (unsigned int)R128_READ(R128_PM4_STAT)); |
| 62 | printk("PM4_BUFFER_DL_WPTR = 0x%08x\n", |
| 63 | (unsigned int)R128_READ(R128_PM4_BUFFER_DL_WPTR)); |
| 64 | printk("PM4_BUFFER_DL_RPTR = 0x%08x\n", |
| 65 | (unsigned int)R128_READ(R128_PM4_BUFFER_DL_RPTR)); |
| 66 | printk("PM4_MICRO_CNTL = 0x%08x\n", |
| 67 | (unsigned int)R128_READ(R128_PM4_MICRO_CNTL)); |
| 68 | printk("PM4_BUFFER_CNTL = 0x%08x\n", |
| 69 | (unsigned int)R128_READ(R128_PM4_BUFFER_CNTL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | } |
| 71 | #endif |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | /* ================================================================ |
| 74 | * Engine, FIFO control |
| 75 | */ |
| 76 | |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 77 | static int r128_do_pixcache_flush(drm_r128_private_t *dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { |
| 79 | u32 tmp; |
| 80 | int i; |
| 81 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 82 | tmp = R128_READ(R128_PC_NGUI_CTLSTAT) | R128_PC_FLUSH_ALL; |
| 83 | R128_WRITE(R128_PC_NGUI_CTLSTAT, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 85 | for (i = 0; i < dev_priv->usec_timeout; i++) { |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 86 | if (!(R128_READ(R128_PC_NGUI_CTLSTAT) & R128_PC_BUSY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | return 0; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 88 | DRM_UDELAY(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | #if R128_FIFO_DEBUG |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 92 | DRM_ERROR("failed!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | #endif |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 94 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 97 | static int r128_do_wait_for_fifo(drm_r128_private_t *dev_priv, int entries) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | { |
| 99 | int i; |
| 100 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 101 | for (i = 0; i < dev_priv->usec_timeout; i++) { |
| 102 | int slots = R128_READ(R128_GUI_STAT) & R128_GUI_FIFOCNT_MASK; |
| 103 | if (slots >= entries) |
| 104 | return 0; |
| 105 | DRM_UDELAY(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | #if R128_FIFO_DEBUG |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 109 | DRM_ERROR("failed!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | #endif |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 111 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 114 | static int r128_do_wait_for_idle(drm_r128_private_t *dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | { |
| 116 | int i, ret; |
| 117 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 118 | ret = r128_do_wait_for_fifo(dev_priv, 64); |
| 119 | if (ret) |
| 120 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 122 | for (i = 0; i < dev_priv->usec_timeout; i++) { |
| 123 | if (!(R128_READ(R128_GUI_STAT) & R128_GUI_ACTIVE)) { |
| 124 | r128_do_pixcache_flush(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | return 0; |
| 126 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 127 | DRM_UDELAY(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | #if R128_FIFO_DEBUG |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 131 | DRM_ERROR("failed!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | #endif |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 133 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | /* ================================================================ |
| 137 | * CCE control, initialization |
| 138 | */ |
| 139 | |
| 140 | /* Load the microcode for the CCE */ |
Ben Hutchings | 52f97df | 2009-08-23 18:37:26 +0100 | [diff] [blame] | 141 | static int r128_cce_load_microcode(drm_r128_private_t *dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
Ben Hutchings | 52f97df | 2009-08-23 18:37:26 +0100 | [diff] [blame] | 143 | struct platform_device *pdev; |
| 144 | const struct firmware *fw; |
| 145 | const __be32 *fw_data; |
| 146 | int rc, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 148 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
Ben Hutchings | 52f97df | 2009-08-23 18:37:26 +0100 | [diff] [blame] | 150 | pdev = platform_device_register_simple("r128_cce", 0, NULL, 0); |
| 151 | if (IS_ERR(pdev)) { |
| 152 | printk(KERN_ERR "r128_cce: Failed to register firmware\n"); |
| 153 | return PTR_ERR(pdev); |
| 154 | } |
| 155 | rc = request_firmware(&fw, FIRMWARE_NAME, &pdev->dev); |
| 156 | platform_device_unregister(pdev); |
| 157 | if (rc) { |
| 158 | printk(KERN_ERR "r128_cce: Failed to load firmware \"%s\"\n", |
| 159 | FIRMWARE_NAME); |
| 160 | return rc; |
| 161 | } |
| 162 | |
| 163 | if (fw->size != 256 * 8) { |
| 164 | printk(KERN_ERR |
| 165 | "r128_cce: Bogus length %zu in firmware \"%s\"\n", |
| 166 | fw->size, FIRMWARE_NAME); |
| 167 | rc = -EINVAL; |
| 168 | goto out_release; |
| 169 | } |
| 170 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 171 | r128_do_wait_for_idle(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
Ben Hutchings | 52f97df | 2009-08-23 18:37:26 +0100 | [diff] [blame] | 173 | fw_data = (const __be32 *)fw->data; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 174 | R128_WRITE(R128_PM4_MICROCODE_ADDR, 0); |
| 175 | for (i = 0; i < 256; i++) { |
Ben Hutchings | 52f97df | 2009-08-23 18:37:26 +0100 | [diff] [blame] | 176 | R128_WRITE(R128_PM4_MICROCODE_DATAH, |
| 177 | be32_to_cpup(&fw_data[i * 2])); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 178 | R128_WRITE(R128_PM4_MICROCODE_DATAL, |
Ben Hutchings | 52f97df | 2009-08-23 18:37:26 +0100 | [diff] [blame] | 179 | be32_to_cpup(&fw_data[i * 2 + 1])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
Ben Hutchings | 52f97df | 2009-08-23 18:37:26 +0100 | [diff] [blame] | 181 | |
| 182 | out_release: |
| 183 | release_firmware(fw); |
| 184 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | /* Flush any pending commands to the CCE. This should only be used just |
| 188 | * prior to a wait for idle, as it informs the engine that the command |
| 189 | * stream is ending. |
| 190 | */ |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 191 | static void r128_do_cce_flush(drm_r128_private_t *dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | { |
| 193 | u32 tmp; |
| 194 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 195 | tmp = R128_READ(R128_PM4_BUFFER_DL_WPTR) | R128_PM4_BUFFER_DL_DONE; |
| 196 | R128_WRITE(R128_PM4_BUFFER_DL_WPTR, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | /* Wait for the CCE to go idle. |
| 200 | */ |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 201 | int r128_do_cce_idle(drm_r128_private_t *dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | { |
| 203 | int i; |
| 204 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 205 | for (i = 0; i < dev_priv->usec_timeout; i++) { |
| 206 | if (GET_RING_HEAD(dev_priv) == dev_priv->ring.tail) { |
| 207 | int pm4stat = R128_READ(R128_PM4_STAT); |
| 208 | if (((pm4stat & R128_PM4_FIFOCNT_MASK) >= |
| 209 | dev_priv->cce_fifo_size) && |
| 210 | !(pm4stat & (R128_PM4_BUSY | |
| 211 | R128_PM4_GUI_ACTIVE))) { |
| 212 | return r128_do_pixcache_flush(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | } |
| 214 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 215 | DRM_UDELAY(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | #if R128_FIFO_DEBUG |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 219 | DRM_ERROR("failed!\n"); |
| 220 | r128_status(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | #endif |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 222 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | /* Start the Concurrent Command Engine. |
| 226 | */ |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 227 | static void r128_do_cce_start(drm_r128_private_t *dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 229 | r128_do_wait_for_idle(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 231 | R128_WRITE(R128_PM4_BUFFER_CNTL, |
| 232 | dev_priv->cce_mode | dev_priv->ring.size_l2qw |
| 233 | | R128_PM4_BUFFER_CNTL_NOUPDATE); |
| 234 | R128_READ(R128_PM4_BUFFER_ADDR); /* as per the sample code */ |
| 235 | R128_WRITE(R128_PM4_MICRO_CNTL, R128_PM4_MICRO_FREERUN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
| 237 | dev_priv->cce_running = 1; |
| 238 | } |
| 239 | |
| 240 | /* Reset the Concurrent Command Engine. This will not flush any pending |
| 241 | * commands, so you must wait for the CCE command stream to complete |
| 242 | * before calling this routine. |
| 243 | */ |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 244 | static void r128_do_cce_reset(drm_r128_private_t *dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 246 | R128_WRITE(R128_PM4_BUFFER_DL_WPTR, 0); |
| 247 | R128_WRITE(R128_PM4_BUFFER_DL_RPTR, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | dev_priv->ring.tail = 0; |
| 249 | } |
| 250 | |
| 251 | /* Stop the Concurrent Command Engine. This will not flush any pending |
| 252 | * commands, so you must flush the command stream and wait for the CCE |
| 253 | * to go idle before calling this routine. |
| 254 | */ |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 255 | static void r128_do_cce_stop(drm_r128_private_t *dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 257 | R128_WRITE(R128_PM4_MICRO_CNTL, 0); |
| 258 | R128_WRITE(R128_PM4_BUFFER_CNTL, |
| 259 | R128_PM4_NONPM4 | R128_PM4_BUFFER_CNTL_NOUPDATE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
| 261 | dev_priv->cce_running = 0; |
| 262 | } |
| 263 | |
| 264 | /* Reset the engine. This will stop the CCE if it is running. |
| 265 | */ |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 266 | static int r128_do_engine_reset(struct drm_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | { |
| 268 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 269 | u32 clock_cntl_index, mclk_cntl, gen_reset_cntl; |
| 270 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 271 | r128_do_pixcache_flush(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 273 | clock_cntl_index = R128_READ(R128_CLOCK_CNTL_INDEX); |
| 274 | mclk_cntl = R128_READ_PLL(dev, R128_MCLK_CNTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 276 | R128_WRITE_PLL(R128_MCLK_CNTL, |
| 277 | mclk_cntl | R128_FORCE_GCP | R128_FORCE_PIPE3D_CP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 279 | gen_reset_cntl = R128_READ(R128_GEN_RESET_CNTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
| 281 | /* Taken from the sample code - do not change */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 282 | R128_WRITE(R128_GEN_RESET_CNTL, gen_reset_cntl | R128_SOFT_RESET_GUI); |
| 283 | R128_READ(R128_GEN_RESET_CNTL); |
| 284 | R128_WRITE(R128_GEN_RESET_CNTL, gen_reset_cntl & ~R128_SOFT_RESET_GUI); |
| 285 | R128_READ(R128_GEN_RESET_CNTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 287 | R128_WRITE_PLL(R128_MCLK_CNTL, mclk_cntl); |
| 288 | R128_WRITE(R128_CLOCK_CNTL_INDEX, clock_cntl_index); |
| 289 | R128_WRITE(R128_GEN_RESET_CNTL, gen_reset_cntl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
| 291 | /* Reset the CCE ring */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 292 | r128_do_cce_reset(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
| 294 | /* The CCE is no longer running after an engine reset */ |
| 295 | dev_priv->cce_running = 0; |
| 296 | |
| 297 | /* Reset any pending vertex, indirect buffers */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 298 | r128_freelist_reset(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
| 300 | return 0; |
| 301 | } |
| 302 | |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 303 | static void r128_cce_init_ring_buffer(struct drm_device *dev, |
| 304 | drm_r128_private_t *dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | { |
| 306 | u32 ring_start; |
| 307 | u32 tmp; |
| 308 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 309 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
| 311 | /* The manual (p. 2) says this address is in "VM space". This |
| 312 | * means it's an offset from the start of AGP space. |
| 313 | */ |
| 314 | #if __OS_HAS_AGP |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 315 | if (!dev_priv->is_pci) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | ring_start = dev_priv->cce_ring->offset - dev->agp->base; |
| 317 | else |
| 318 | #endif |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 319 | ring_start = dev_priv->cce_ring->offset - |
| 320 | (unsigned long)dev->sg->virtual; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 322 | R128_WRITE(R128_PM4_BUFFER_OFFSET, ring_start | R128_AGP_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 324 | R128_WRITE(R128_PM4_BUFFER_DL_WPTR, 0); |
| 325 | R128_WRITE(R128_PM4_BUFFER_DL_RPTR, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
| 327 | /* Set watermark control */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 328 | R128_WRITE(R128_PM4_BUFFER_WM_CNTL, |
| 329 | ((R128_WATERMARK_L / 4) << R128_WMA_SHIFT) |
| 330 | | ((R128_WATERMARK_M / 4) << R128_WMB_SHIFT) |
| 331 | | ((R128_WATERMARK_N / 4) << R128_WMC_SHIFT) |
| 332 | | ((R128_WATERMARK_K / 64) << R128_WB_WM_SHIFT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | |
| 334 | /* Force read. Why? Because it's in the examples... */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 335 | R128_READ(R128_PM4_BUFFER_ADDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
| 337 | /* Turn on bus mastering */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 338 | tmp = R128_READ(R128_BUS_CNTL) & ~R128_BUS_MASTER_DIS; |
| 339 | R128_WRITE(R128_BUS_CNTL, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 342 | static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | { |
| 344 | drm_r128_private_t *dev_priv; |
Ben Hutchings | 52f97df | 2009-08-23 18:37:26 +0100 | [diff] [blame] | 345 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 347 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
Ben Hutchings | 7dc482d | 2009-08-23 16:59:04 +0100 | [diff] [blame] | 349 | if (dev->dev_private) { |
| 350 | DRM_DEBUG("called when already initialized\n"); |
| 351 | return -EINVAL; |
| 352 | } |
| 353 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 354 | dev_priv = kzalloc(sizeof(drm_r128_private_t), GFP_KERNEL); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 355 | if (dev_priv == NULL) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 356 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | dev_priv->is_pci = init->is_pci; |
| 359 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 360 | if (dev_priv->is_pci && !dev->sg) { |
| 361 | DRM_ERROR("PCI GART memory not allocated!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | dev->dev_private = (void *)dev_priv; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 363 | r128_do_cleanup_cce(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 364 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | dev_priv->usec_timeout = init->usec_timeout; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 368 | if (dev_priv->usec_timeout < 1 || |
| 369 | dev_priv->usec_timeout > R128_MAX_USEC_TIMEOUT) { |
| 370 | DRM_DEBUG("TIMEOUT problem!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | dev->dev_private = (void *)dev_priv; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 372 | r128_do_cleanup_cce(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 373 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | dev_priv->cce_mode = init->cce_mode; |
| 377 | |
| 378 | /* GH: Simple idle check. |
| 379 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 380 | atomic_set(&dev_priv->idle_count, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
| 382 | /* We don't support anything other than bus-mastering ring mode, |
| 383 | * but the ring can be in either AGP or PCI space for the ring |
| 384 | * read pointer. |
| 385 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 386 | if ((init->cce_mode != R128_PM4_192BM) && |
| 387 | (init->cce_mode != R128_PM4_128BM_64INDBM) && |
| 388 | (init->cce_mode != R128_PM4_64BM_128INDBM) && |
| 389 | (init->cce_mode != R128_PM4_64BM_64VCBM_64INDBM)) { |
| 390 | DRM_DEBUG("Bad cce_mode!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | dev->dev_private = (void *)dev_priv; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 392 | r128_do_cleanup_cce(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 393 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 396 | switch (init->cce_mode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | case R128_PM4_NONPM4: |
| 398 | dev_priv->cce_fifo_size = 0; |
| 399 | break; |
| 400 | case R128_PM4_192PIO: |
| 401 | case R128_PM4_192BM: |
| 402 | dev_priv->cce_fifo_size = 192; |
| 403 | break; |
| 404 | case R128_PM4_128PIO_64INDBM: |
| 405 | case R128_PM4_128BM_64INDBM: |
| 406 | dev_priv->cce_fifo_size = 128; |
| 407 | break; |
| 408 | case R128_PM4_64PIO_128INDBM: |
| 409 | case R128_PM4_64BM_128INDBM: |
| 410 | case R128_PM4_64PIO_64VCBM_64INDBM: |
| 411 | case R128_PM4_64BM_64VCBM_64INDBM: |
| 412 | case R128_PM4_64PIO_64VCPIO_64INDPIO: |
| 413 | dev_priv->cce_fifo_size = 64; |
| 414 | break; |
| 415 | } |
| 416 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 417 | switch (init->fb_bpp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | case 16: |
| 419 | dev_priv->color_fmt = R128_DATATYPE_RGB565; |
| 420 | break; |
| 421 | case 32: |
| 422 | default: |
| 423 | dev_priv->color_fmt = R128_DATATYPE_ARGB8888; |
| 424 | break; |
| 425 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 426 | dev_priv->front_offset = init->front_offset; |
| 427 | dev_priv->front_pitch = init->front_pitch; |
| 428 | dev_priv->back_offset = init->back_offset; |
| 429 | dev_priv->back_pitch = init->back_pitch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 431 | switch (init->depth_bpp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | case 16: |
| 433 | dev_priv->depth_fmt = R128_DATATYPE_RGB565; |
| 434 | break; |
| 435 | case 24: |
| 436 | case 32: |
| 437 | default: |
| 438 | dev_priv->depth_fmt = R128_DATATYPE_ARGB8888; |
| 439 | break; |
| 440 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 441 | dev_priv->depth_offset = init->depth_offset; |
| 442 | dev_priv->depth_pitch = init->depth_pitch; |
| 443 | dev_priv->span_offset = init->span_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 445 | dev_priv->front_pitch_offset_c = (((dev_priv->front_pitch / 8) << 21) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | (dev_priv->front_offset >> 5)); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 447 | dev_priv->back_pitch_offset_c = (((dev_priv->back_pitch / 8) << 21) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | (dev_priv->back_offset >> 5)); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 449 | dev_priv->depth_pitch_offset_c = (((dev_priv->depth_pitch / 8) << 21) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | (dev_priv->depth_offset >> 5) | |
| 451 | R128_DST_TILE); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 452 | dev_priv->span_pitch_offset_c = (((dev_priv->depth_pitch / 8) << 21) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | (dev_priv->span_offset >> 5)); |
| 454 | |
David Herrmann | 9fc5cde | 2014-08-29 12:12:28 +0200 | [diff] [blame] | 455 | dev_priv->sarea = drm_legacy_getsarea(dev); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 456 | if (!dev_priv->sarea) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | DRM_ERROR("could not find sarea!\n"); |
| 458 | dev->dev_private = (void *)dev_priv; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 459 | r128_do_cleanup_cce(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 460 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Daniel Vetter | 86c1fbd | 2014-09-10 12:43:56 +0200 | [diff] [blame] | 463 | dev_priv->mmio = drm_legacy_findmap(dev, init->mmio_offset); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 464 | if (!dev_priv->mmio) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | DRM_ERROR("could not find mmio region!\n"); |
| 466 | dev->dev_private = (void *)dev_priv; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 467 | r128_do_cleanup_cce(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 468 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | } |
Daniel Vetter | 86c1fbd | 2014-09-10 12:43:56 +0200 | [diff] [blame] | 470 | dev_priv->cce_ring = drm_legacy_findmap(dev, init->ring_offset); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 471 | if (!dev_priv->cce_ring) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | DRM_ERROR("could not find cce ring region!\n"); |
| 473 | dev->dev_private = (void *)dev_priv; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 474 | r128_do_cleanup_cce(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 475 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } |
Daniel Vetter | 86c1fbd | 2014-09-10 12:43:56 +0200 | [diff] [blame] | 477 | dev_priv->ring_rptr = drm_legacy_findmap(dev, init->ring_rptr_offset); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 478 | if (!dev_priv->ring_rptr) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | DRM_ERROR("could not find ring read pointer!\n"); |
| 480 | dev->dev_private = (void *)dev_priv; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 481 | r128_do_cleanup_cce(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 482 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | } |
Dave Airlie | d1f2b55 | 2005-08-05 22:11:22 +1000 | [diff] [blame] | 484 | dev->agp_buffer_token = init->buffers_offset; |
Daniel Vetter | 86c1fbd | 2014-09-10 12:43:56 +0200 | [diff] [blame] | 485 | dev->agp_buffer_map = drm_legacy_findmap(dev, init->buffers_offset); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 486 | if (!dev->agp_buffer_map) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | DRM_ERROR("could not find dma buffer region!\n"); |
| 488 | dev->dev_private = (void *)dev_priv; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 489 | r128_do_cleanup_cce(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 490 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 493 | if (!dev_priv->is_pci) { |
| 494 | dev_priv->agp_textures = |
Daniel Vetter | 86c1fbd | 2014-09-10 12:43:56 +0200 | [diff] [blame] | 495 | drm_legacy_findmap(dev, init->agp_textures_offset); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 496 | if (!dev_priv->agp_textures) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | DRM_ERROR("could not find agp texture region!\n"); |
| 498 | dev->dev_private = (void *)dev_priv; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 499 | r128_do_cleanup_cce(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 500 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | } |
| 502 | } |
| 503 | |
| 504 | dev_priv->sarea_priv = |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 505 | (drm_r128_sarea_t *) ((u8 *) dev_priv->sarea->handle + |
| 506 | init->sarea_priv_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
| 508 | #if __OS_HAS_AGP |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 509 | if (!dev_priv->is_pci) { |
Daniel Vetter | 86c1fbd | 2014-09-10 12:43:56 +0200 | [diff] [blame] | 510 | drm_legacy_ioremap_wc(dev_priv->cce_ring, dev); |
| 511 | drm_legacy_ioremap_wc(dev_priv->ring_rptr, dev); |
| 512 | drm_legacy_ioremap_wc(dev->agp_buffer_map, dev); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 513 | if (!dev_priv->cce_ring->handle || |
| 514 | !dev_priv->ring_rptr->handle || |
| 515 | !dev->agp_buffer_map->handle) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | DRM_ERROR("Could not ioremap agp regions!\n"); |
| 517 | dev->dev_private = (void *)dev_priv; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 518 | r128_do_cleanup_cce(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 519 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | } |
| 521 | } else |
| 522 | #endif |
| 523 | { |
Benjamin Herrenschmidt | 41c2e75 | 2009-02-02 16:55:47 +1100 | [diff] [blame] | 524 | dev_priv->cce_ring->handle = |
| 525 | (void *)(unsigned long)dev_priv->cce_ring->offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | dev_priv->ring_rptr->handle = |
Benjamin Herrenschmidt | 41c2e75 | 2009-02-02 16:55:47 +1100 | [diff] [blame] | 527 | (void *)(unsigned long)dev_priv->ring_rptr->offset; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 528 | dev->agp_buffer_map->handle = |
Benjamin Herrenschmidt | 41c2e75 | 2009-02-02 16:55:47 +1100 | [diff] [blame] | 529 | (void *)(unsigned long)dev->agp_buffer_map->offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | #if __OS_HAS_AGP |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 533 | if (!dev_priv->is_pci) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | dev_priv->cce_buffers_offset = dev->agp->base; |
| 535 | else |
| 536 | #endif |
Dave Airlie | d1f2b55 | 2005-08-05 22:11:22 +1000 | [diff] [blame] | 537 | dev_priv->cce_buffers_offset = (unsigned long)dev->sg->virtual; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 539 | dev_priv->ring.start = (u32 *) dev_priv->cce_ring->handle; |
| 540 | dev_priv->ring.end = ((u32 *) dev_priv->cce_ring->handle |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | + init->ring_size / sizeof(u32)); |
| 542 | dev_priv->ring.size = init->ring_size; |
Daniel Vetter | 0e26794 | 2013-07-10 14:11:58 +0200 | [diff] [blame] | 543 | dev_priv->ring.size_l2qw = order_base_2(init->ring_size / 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 545 | dev_priv->ring.tail_mask = (dev_priv->ring.size / sizeof(u32)) - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
| 547 | dev_priv->ring.high_mark = 128; |
| 548 | |
| 549 | dev_priv->sarea_priv->last_frame = 0; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 550 | R128_WRITE(R128_LAST_FRAME_REG, dev_priv->sarea_priv->last_frame); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
| 552 | dev_priv->sarea_priv->last_dispatch = 0; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 553 | R128_WRITE(R128_LAST_DISPATCH_REG, dev_priv->sarea_priv->last_dispatch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
| 555 | #if __OS_HAS_AGP |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 556 | if (dev_priv->is_pci) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | #endif |
Dave Airlie | b05c238 | 2008-03-17 10:24:24 +1000 | [diff] [blame] | 558 | dev_priv->gart_info.table_mask = DMA_BIT_MASK(32); |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 559 | dev_priv->gart_info.gart_table_location = DRM_ATI_GART_MAIN; |
Dave Airlie | f2b04cd | 2007-05-08 15:19:23 +1000 | [diff] [blame] | 560 | dev_priv->gart_info.table_size = R128_PCIGART_TABLE_SIZE; |
Dave Airlie | f26c473 | 2006-01-02 17:18:39 +1100 | [diff] [blame] | 561 | dev_priv->gart_info.addr = NULL; |
| 562 | dev_priv->gart_info.bus_addr = 0; |
Dave Airlie | f2b04cd | 2007-05-08 15:19:23 +1000 | [diff] [blame] | 563 | dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_PCI; |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 564 | if (!drm_ati_pcigart_init(dev, &dev_priv->gart_info)) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 565 | DRM_ERROR("failed to init PCI GART!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | dev->dev_private = (void *)dev_priv; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 567 | r128_do_cleanup_cce(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 568 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | } |
Dave Airlie | ea98a92 | 2005-09-11 20:28:11 +1000 | [diff] [blame] | 570 | R128_WRITE(R128_PCI_GART_PAGE, dev_priv->gart_info.bus_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | #if __OS_HAS_AGP |
| 572 | } |
| 573 | #endif |
| 574 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 575 | r128_cce_init_ring_buffer(dev, dev_priv); |
Ben Hutchings | 52f97df | 2009-08-23 18:37:26 +0100 | [diff] [blame] | 576 | rc = r128_cce_load_microcode(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | |
| 578 | dev->dev_private = (void *)dev_priv; |
| 579 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 580 | r128_do_engine_reset(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
Ben Hutchings | 52f97df | 2009-08-23 18:37:26 +0100 | [diff] [blame] | 582 | if (rc) { |
| 583 | DRM_ERROR("Failed to load firmware!\n"); |
| 584 | r128_do_cleanup_cce(dev); |
| 585 | } |
| 586 | |
| 587 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 590 | int r128_do_cleanup_cce(struct drm_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | { |
| 592 | |
| 593 | /* Make sure interrupts are disabled here because the uninstall ioctl |
| 594 | * may not have been called from userspace and after dev_private |
| 595 | * is freed, it's too late. |
| 596 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 597 | if (dev->irq_enabled) |
| 598 | drm_irq_uninstall(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 600 | if (dev->dev_private) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 602 | |
| 603 | #if __OS_HAS_AGP |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 604 | if (!dev_priv->is_pci) { |
| 605 | if (dev_priv->cce_ring != NULL) |
Daniel Vetter | 86c1fbd | 2014-09-10 12:43:56 +0200 | [diff] [blame] | 606 | drm_legacy_ioremapfree(dev_priv->cce_ring, dev); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 607 | if (dev_priv->ring_rptr != NULL) |
Daniel Vetter | 86c1fbd | 2014-09-10 12:43:56 +0200 | [diff] [blame] | 608 | drm_legacy_ioremapfree(dev_priv->ring_rptr, dev); |
Dave Airlie | f26c473 | 2006-01-02 17:18:39 +1100 | [diff] [blame] | 609 | if (dev->agp_buffer_map != NULL) { |
Daniel Vetter | 86c1fbd | 2014-09-10 12:43:56 +0200 | [diff] [blame] | 610 | drm_legacy_ioremapfree(dev->agp_buffer_map, dev); |
Dave Airlie | f26c473 | 2006-01-02 17:18:39 +1100 | [diff] [blame] | 611 | dev->agp_buffer_map = NULL; |
| 612 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | } else |
| 614 | #endif |
| 615 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 616 | if (dev_priv->gart_info.bus_addr) |
| 617 | if (!drm_ati_pcigart_cleanup(dev, |
Dave Airlie | f26c473 | 2006-01-02 17:18:39 +1100 | [diff] [blame] | 618 | &dev_priv->gart_info)) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 619 | DRM_ERROR |
| 620 | ("failed to cleanup PCI GART!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | } |
| 622 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 623 | kfree(dev->dev_private); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | dev->dev_private = NULL; |
| 625 | } |
| 626 | |
| 627 | return 0; |
| 628 | } |
| 629 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 630 | int r128_cce_init(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 632 | drm_r128_init_t *init = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 634 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 636 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 638 | switch (init->func) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | case R128_INIT_CCE: |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 640 | return r128_do_init_cce(dev, init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | case R128_CLEANUP_CCE: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 642 | return r128_do_cleanup_cce(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | } |
| 644 | |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 645 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | } |
| 647 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 648 | int r128_cce_start(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | drm_r128_private_t *dev_priv = dev->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 651 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 653 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | |
Ben Hutchings | 7dc482d | 2009-08-23 16:59:04 +0100 | [diff] [blame] | 655 | DEV_INIT_TEST_WITH_RETURN(dev_priv); |
| 656 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 657 | if (dev_priv->cce_running || dev_priv->cce_mode == R128_PM4_NONPM4) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 658 | DRM_DEBUG("while CCE running\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | return 0; |
| 660 | } |
| 661 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 662 | r128_do_cce_start(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | /* Stop the CCE. The engine must have been idled before calling this |
| 668 | * routine. |
| 669 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 670 | int r128_cce_stop(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | drm_r128_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 673 | drm_r128_cce_stop_t *stop = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | int ret; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 675 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 677 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | |
Ben Hutchings | 7dc482d | 2009-08-23 16:59:04 +0100 | [diff] [blame] | 679 | DEV_INIT_TEST_WITH_RETURN(dev_priv); |
| 680 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | /* Flush any pending CCE commands. This ensures any outstanding |
| 682 | * commands are exectuted by the engine before we turn it off. |
| 683 | */ |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 684 | if (stop->flush) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 685 | r128_do_cce_flush(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | |
| 687 | /* If we fail to make the engine go idle, we return an error |
| 688 | * code so that the DRM ioctl wrapper can try again. |
| 689 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 690 | if (stop->idle) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 691 | ret = r128_do_cce_idle(dev_priv); |
| 692 | if (ret) |
| 693 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | /* Finally, we can turn off the CCE. If the engine isn't idle, |
| 697 | * we will get some dropped triangles as they won't be fully |
| 698 | * rendered before the CCE is shut down. |
| 699 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 700 | r128_do_cce_stop(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | |
| 702 | /* Reset the engine */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 703 | r128_do_engine_reset(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | |
| 705 | return 0; |
| 706 | } |
| 707 | |
| 708 | /* Just reset the CCE ring. Called as part of an X Server engine reset. |
| 709 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 710 | int r128_cce_reset(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | drm_r128_private_t *dev_priv = dev->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 713 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 715 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | |
Ben Hutchings | 7dc482d | 2009-08-23 16:59:04 +0100 | [diff] [blame] | 717 | DEV_INIT_TEST_WITH_RETURN(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 719 | r128_do_cce_reset(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | |
| 721 | /* The CCE is no longer running after an engine reset */ |
| 722 | dev_priv->cce_running = 0; |
| 723 | |
| 724 | return 0; |
| 725 | } |
| 726 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 727 | int r128_cce_idle(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | drm_r128_private_t *dev_priv = dev->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 730 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 732 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
Ben Hutchings | 7dc482d | 2009-08-23 16:59:04 +0100 | [diff] [blame] | 734 | DEV_INIT_TEST_WITH_RETURN(dev_priv); |
| 735 | |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 736 | if (dev_priv->cce_running) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 737 | r128_do_cce_flush(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 739 | return r128_do_cce_idle(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | } |
| 741 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 742 | int r128_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] | 743 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 744 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 746 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | |
Ben Hutchings | 7dc482d | 2009-08-23 16:59:04 +0100 | [diff] [blame] | 748 | DEV_INIT_TEST_WITH_RETURN(dev->dev_private); |
| 749 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 750 | return r128_do_engine_reset(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | } |
| 752 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 753 | int r128_fullscreen(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | { |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 755 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | /* ================================================================ |
| 759 | * Freelist management |
| 760 | */ |
| 761 | #define R128_BUFFER_USED 0xffffffff |
| 762 | #define R128_BUFFER_FREE 0 |
| 763 | |
| 764 | #if 0 |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 765 | static int r128_freelist_init(struct drm_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | { |
Dave Airlie | cdd55a2 | 2007-07-11 16:32:08 +1000 | [diff] [blame] | 767 | struct drm_device_dma *dma = dev->dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | drm_r128_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 769 | struct drm_buf *buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | drm_r128_buf_priv_t *buf_priv; |
| 771 | drm_r128_freelist_t *entry; |
| 772 | int i; |
| 773 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 774 | dev_priv->head = kzalloc(sizeof(drm_r128_freelist_t), GFP_KERNEL); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 775 | if (dev_priv->head == NULL) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 776 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | dev_priv->head->age = R128_BUFFER_USED; |
| 779 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 780 | for (i = 0; i < dma->buf_count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | buf = dma->buflist[i]; |
| 782 | buf_priv = buf->dev_private; |
| 783 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 784 | entry = kmalloc(sizeof(drm_r128_freelist_t), GFP_KERNEL); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 785 | if (!entry) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 786 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | |
| 788 | entry->age = R128_BUFFER_FREE; |
| 789 | entry->buf = buf; |
| 790 | entry->prev = dev_priv->head; |
| 791 | entry->next = dev_priv->head->next; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 792 | if (!entry->next) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | dev_priv->tail = entry; |
| 794 | |
| 795 | buf_priv->discard = 0; |
| 796 | buf_priv->dispatched = 0; |
| 797 | buf_priv->list_entry = entry; |
| 798 | |
| 799 | dev_priv->head->next = entry; |
| 800 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 801 | if (dev_priv->head->next) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | dev_priv->head->next->prev = entry; |
| 803 | } |
| 804 | |
| 805 | return 0; |
| 806 | |
| 807 | } |
| 808 | #endif |
| 809 | |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 810 | static struct drm_buf *r128_freelist_get(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | { |
Dave Airlie | cdd55a2 | 2007-07-11 16:32:08 +1000 | [diff] [blame] | 812 | struct drm_device_dma *dma = dev->dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 814 | drm_r128_buf_priv_t *buf_priv; |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 815 | struct drm_buf *buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | int i, t; |
| 817 | |
| 818 | /* FIXME: Optimize -- use freelist code */ |
| 819 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 820 | for (i = 0; i < dma->buf_count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | buf = dma->buflist[i]; |
| 822 | buf_priv = buf->dev_private; |
Harvey Harrison | 8da5630 | 2008-04-28 14:13:20 -0700 | [diff] [blame] | 823 | if (!buf->file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | return buf; |
| 825 | } |
| 826 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 827 | for (t = 0; t < dev_priv->usec_timeout; t++) { |
| 828 | u32 done_age = R128_READ(R128_LAST_DISPATCH_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 830 | for (i = 0; i < dma->buf_count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | buf = dma->buflist[i]; |
| 832 | buf_priv = buf->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 833 | if (buf->pending && buf_priv->age <= done_age) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | /* The buffer has been processed, so it |
| 835 | * can now be used. |
| 836 | */ |
| 837 | buf->pending = 0; |
| 838 | return buf; |
| 839 | } |
| 840 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 841 | DRM_UDELAY(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | } |
| 843 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 844 | DRM_DEBUG("returning NULL!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | return NULL; |
| 846 | } |
| 847 | |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 848 | void r128_freelist_reset(struct drm_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | { |
Dave Airlie | cdd55a2 | 2007-07-11 16:32:08 +1000 | [diff] [blame] | 850 | struct drm_device_dma *dma = dev->dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | int i; |
| 852 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 853 | for (i = 0; i < dma->buf_count; i++) { |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 854 | struct drm_buf *buf = dma->buflist[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | drm_r128_buf_priv_t *buf_priv = buf->dev_private; |
| 856 | buf_priv->age = 0; |
| 857 | } |
| 858 | } |
| 859 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | /* ================================================================ |
| 861 | * CCE command submission |
| 862 | */ |
| 863 | |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 864 | int r128_wait_ring(drm_r128_private_t *dev_priv, int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | { |
| 866 | drm_r128_ring_buffer_t *ring = &dev_priv->ring; |
| 867 | int i; |
| 868 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 869 | for (i = 0; i < dev_priv->usec_timeout; i++) { |
| 870 | r128_update_ring_snapshot(dev_priv); |
| 871 | if (ring->space >= n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | return 0; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 873 | DRM_UDELAY(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | /* FIXME: This is being ignored... */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 877 | DRM_ERROR("failed!\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 878 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | } |
| 880 | |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 881 | static int r128_cce_get_buffers(struct drm_device *dev, |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 882 | struct drm_file *file_priv, |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 883 | struct drm_dma *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | { |
| 885 | int i; |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 886 | struct drm_buf *buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 888 | for (i = d->granted_count; i < d->request_count; i++) { |
| 889 | buf = r128_freelist_get(dev); |
| 890 | if (!buf) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 891 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 893 | buf->file_priv = file_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | |
Daniel Vetter | 1d6ac18 | 2013-12-11 11:34:44 +0100 | [diff] [blame] | 895 | if (copy_to_user(&d->request_indices[i], &buf->idx, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 896 | sizeof(buf->idx))) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 897 | return -EFAULT; |
Daniel Vetter | 1d6ac18 | 2013-12-11 11:34:44 +0100 | [diff] [blame] | 898 | if (copy_to_user(&d->request_sizes[i], &buf->total, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 899 | sizeof(buf->total))) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 900 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | |
| 902 | d->granted_count++; |
| 903 | } |
| 904 | return 0; |
| 905 | } |
| 906 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 907 | int r128_cce_buffers(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | { |
Dave Airlie | cdd55a2 | 2007-07-11 16:32:08 +1000 | [diff] [blame] | 909 | struct drm_device_dma *dma = dev->dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | int ret = 0; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 911 | struct drm_dma *d = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 913 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | /* Please don't send us buffers. |
| 916 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 917 | if (d->send_count != 0) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 918 | DRM_ERROR("Process %d trying to send %d buffers via drmDMA\n", |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 919 | DRM_CURRENTPID, d->send_count); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 920 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | /* We'll send you buffers. |
| 924 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 925 | if (d->request_count < 0 || d->request_count > dma->buf_count) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 926 | 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] | 927 | DRM_CURRENTPID, d->request_count, dma->buf_count); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 928 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | } |
| 930 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 931 | d->granted_count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | |
Nicolas Kaiser | bc5e9d6 | 2010-07-12 13:44:23 +0200 | [diff] [blame] | 933 | if (d->request_count) |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 934 | ret = r128_cce_get_buffers(dev, file_priv, d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | return ret; |
| 937 | } |