Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* i810_dma.c -- DMA support for the i810 -*- linux-c -*- |
| 2 | * Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com |
| 3 | * |
| 4 | * Copyright 1999 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: Rickard E. (Rik) Faith <faith@valinux.com> |
| 28 | * Jeff Hartmann <jhartmann@valinux.com> |
| 29 | * Keith Whitwell <keith@tungstengraphics.com> |
| 30 | * |
| 31 | */ |
| 32 | |
| 33 | #include "drmP.h" |
| 34 | #include "drm.h" |
| 35 | #include "i810_drm.h" |
| 36 | #include "i810_drv.h" |
| 37 | #include <linux/interrupt.h> /* For task queue support */ |
| 38 | #include <linux/delay.h> |
| 39 | #include <linux/pagemap.h> |
| 40 | |
| 41 | #define I810_BUF_FREE 2 |
| 42 | #define I810_BUF_CLIENT 1 |
| 43 | #define I810_BUF_HARDWARE 0 |
| 44 | |
| 45 | #define I810_BUF_UNMAPPED 0 |
| 46 | #define I810_BUF_MAPPED 1 |
| 47 | |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 48 | static struct drm_buf *i810_freelist_get(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
Dave Airlie | cdd55a2 | 2007-07-11 16:32:08 +1000 | [diff] [blame] | 50 | struct drm_device_dma *dma = dev->dma; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 51 | int i; |
| 52 | int used; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | /* Linear search might not be the best solution */ |
| 55 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 56 | for (i = 0; i < dma->buf_count; i++) { |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 57 | struct drm_buf *buf = dma->buflist[i]; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 58 | drm_i810_buf_priv_t *buf_priv = buf->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | /* In use is already a pointer */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 60 | used = cmpxchg(buf_priv->in_use, I810_BUF_FREE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | I810_BUF_CLIENT); |
| 62 | if (used == I810_BUF_FREE) { |
| 63 | return buf; |
| 64 | } |
| 65 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 66 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | /* This should only be called if the buffer is not sent to the hardware |
| 70 | * yet, the hardware updates in use for us once its on the ring buffer. |
| 71 | */ |
| 72 | |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 73 | static int i810_freelist_put(struct drm_device * dev, struct drm_buf * buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 75 | drm_i810_buf_priv_t *buf_priv = buf->dev_private; |
| 76 | int used; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 78 | /* In use is already a pointer */ |
| 79 | used = cmpxchg(buf_priv->in_use, I810_BUF_CLIENT, I810_BUF_FREE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | if (used != I810_BUF_CLIENT) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 81 | DRM_ERROR("Freeing buffer thats not in use : %d\n", buf->idx); |
| 82 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 85 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Dave Airlie | c94f702 | 2005-07-07 21:03:38 +1000 | [diff] [blame] | 88 | static int i810_mmap_buffers(struct file *filp, struct vm_area_struct *vma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 90 | struct drm_file *priv = filp->private_data; |
| 91 | struct drm_device *dev; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 92 | drm_i810_private_t *dev_priv; |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 93 | struct drm_buf *buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | drm_i810_buf_priv_t *buf_priv; |
| 95 | |
| 96 | lock_kernel(); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 97 | dev = priv->head->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | dev_priv = dev->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 99 | buf = dev_priv->mmap_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | buf_priv = buf->dev_private; |
| 101 | |
| 102 | vma->vm_flags |= (VM_IO | VM_DONTCOPY); |
| 103 | vma->vm_file = filp; |
| 104 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 105 | buf_priv->currently_mapped = I810_BUF_MAPPED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | unlock_kernel(); |
| 107 | |
| 108 | if (io_remap_pfn_range(vma, vma->vm_start, |
Dave Airlie | 3d77461 | 2006-08-07 20:07:43 +1000 | [diff] [blame] | 109 | vma->vm_pgoff, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 110 | vma->vm_end - vma->vm_start, vma->vm_page_prot)) |
| 111 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | return 0; |
| 113 | } |
| 114 | |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 115 | static const struct file_operations i810_buffer_fops = { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 116 | .open = drm_open, |
Dave Airlie | c94f702 | 2005-07-07 21:03:38 +1000 | [diff] [blame] | 117 | .release = drm_release, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 118 | .ioctl = drm_ioctl, |
| 119 | .mmap = i810_mmap_buffers, |
| 120 | .fasync = drm_fasync, |
Dave Airlie | c94f702 | 2005-07-07 21:03:38 +1000 | [diff] [blame] | 121 | }; |
| 122 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 123 | static int i810_map_buffer(struct drm_buf * buf, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | { |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 125 | struct drm_device *dev = file_priv->head->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | drm_i810_buf_priv_t *buf_priv = buf->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 127 | drm_i810_private_t *dev_priv = dev->dev_private; |
Arjan van de Ven | 99ac48f | 2006-03-28 01:56:41 -0800 | [diff] [blame] | 128 | const struct file_operations *old_fops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | int retcode = 0; |
| 130 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 131 | if (buf_priv->currently_mapped == I810_BUF_MAPPED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | return -EINVAL; |
| 133 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 134 | down_write(¤t->mm->mmap_sem); |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 135 | old_fops = file_priv->filp->f_op; |
| 136 | file_priv->filp->f_op = &i810_buffer_fops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | dev_priv->mmap_buffer = buf; |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 138 | buf_priv->virtual = (void *)do_mmap(file_priv->filp, 0, buf->total, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 139 | PROT_READ | PROT_WRITE, |
| 140 | MAP_SHARED, buf->bus_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | dev_priv->mmap_buffer = NULL; |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 142 | file_priv->filp->f_op = old_fops; |
Denis Vlasenko | c7aed17 | 2006-08-16 11:54:07 +1000 | [diff] [blame] | 143 | if (IS_ERR(buf_priv->virtual)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | /* Real error */ |
| 145 | DRM_ERROR("mmap error\n"); |
Denis Vlasenko | c7aed17 | 2006-08-16 11:54:07 +1000 | [diff] [blame] | 146 | retcode = PTR_ERR(buf_priv->virtual); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | buf_priv->virtual = NULL; |
| 148 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 149 | up_write(¤t->mm->mmap_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
| 151 | return retcode; |
| 152 | } |
| 153 | |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 154 | static int i810_unmap_buffer(struct drm_buf * buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | { |
| 156 | drm_i810_buf_priv_t *buf_priv = buf->dev_private; |
| 157 | int retcode = 0; |
| 158 | |
| 159 | if (buf_priv->currently_mapped != I810_BUF_MAPPED) |
| 160 | return -EINVAL; |
| 161 | |
| 162 | down_write(¤t->mm->mmap_sem); |
| 163 | retcode = do_munmap(current->mm, |
| 164 | (unsigned long)buf_priv->virtual, |
| 165 | (size_t) buf->total); |
| 166 | up_write(¤t->mm->mmap_sem); |
| 167 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 168 | buf_priv->currently_mapped = I810_BUF_UNMAPPED; |
| 169 | buf_priv->virtual = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
| 171 | return retcode; |
| 172 | } |
| 173 | |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 174 | static int i810_dma_get_buffer(struct drm_device * dev, drm_i810_dma_t * d, |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 175 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | { |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 177 | struct drm_buf *buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | drm_i810_buf_priv_t *buf_priv; |
| 179 | int retcode = 0; |
| 180 | |
| 181 | buf = i810_freelist_get(dev); |
| 182 | if (!buf) { |
| 183 | retcode = -ENOMEM; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 184 | DRM_DEBUG("retcode=%d\n", retcode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | return retcode; |
| 186 | } |
| 187 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 188 | retcode = i810_map_buffer(buf, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | if (retcode) { |
| 190 | i810_freelist_put(dev, buf); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 191 | DRM_ERROR("mapbuf failed, retcode %d\n", retcode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | return retcode; |
| 193 | } |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 194 | buf->file_priv = file_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | buf_priv = buf->dev_private; |
| 196 | d->granted = 1; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 197 | d->request_idx = buf->idx; |
| 198 | d->request_size = buf->total; |
| 199 | d->virtual = buf_priv->virtual; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
| 201 | return retcode; |
| 202 | } |
| 203 | |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 204 | static int i810_dma_cleanup(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | { |
Dave Airlie | cdd55a2 | 2007-07-11 16:32:08 +1000 | [diff] [blame] | 206 | struct drm_device_dma *dma = dev->dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
| 208 | /* Make sure interrupts are disabled here because the uninstall ioctl |
| 209 | * may not have been called from userspace and after dev_private |
| 210 | * is freed, it's too late. |
| 211 | */ |
| 212 | if (drm_core_check_feature(dev, DRIVER_HAVE_IRQ) && dev->irq_enabled) |
| 213 | drm_irq_uninstall(dev); |
| 214 | |
| 215 | if (dev->dev_private) { |
| 216 | int i; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 217 | drm_i810_private_t *dev_priv = |
| 218 | (drm_i810_private_t *) dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
| 220 | if (dev_priv->ring.virtual_start) { |
Dave Airlie | b9094d3 | 2007-01-08 21:31:13 +1100 | [diff] [blame] | 221 | drm_core_ioremapfree(&dev_priv->ring.map, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 223 | if (dev_priv->hw_status_page) { |
| 224 | pci_free_consistent(dev->pdev, PAGE_SIZE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | dev_priv->hw_status_page, |
| 226 | dev_priv->dma_status_page); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 227 | /* Need to rewrite hardware status page */ |
| 228 | I810_WRITE(0x02080, 0x1ffff000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 230 | drm_free(dev->dev_private, sizeof(drm_i810_private_t), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | DRM_MEM_DRIVER); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 232 | dev->dev_private = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
| 234 | for (i = 0; i < dma->buf_count; i++) { |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 235 | struct drm_buf *buf = dma->buflist[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | drm_i810_buf_priv_t *buf_priv = buf->dev_private; |
Dave Airlie | b9094d3 | 2007-01-08 21:31:13 +1100 | [diff] [blame] | 237 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 238 | if (buf_priv->kernel_virtual && buf->total) |
Dave Airlie | b9094d3 | 2007-01-08 21:31:13 +1100 | [diff] [blame] | 239 | drm_core_ioremapfree(&buf_priv->map, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | } |
| 241 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | return 0; |
| 243 | } |
| 244 | |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 245 | static int i810_wait_ring(struct drm_device * dev, int n) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 246 | { |
| 247 | drm_i810_private_t *dev_priv = dev->dev_private; |
| 248 | drm_i810_ring_buffer_t *ring = &(dev_priv->ring); |
| 249 | int iters = 0; |
| 250 | unsigned long end; |
| 251 | unsigned int last_head = I810_READ(LP_RING + RING_HEAD) & HEAD_ADDR; |
| 252 | |
| 253 | end = jiffies + (HZ * 3); |
| 254 | while (ring->space < n) { |
| 255 | ring->head = I810_READ(LP_RING + RING_HEAD) & HEAD_ADDR; |
| 256 | ring->space = ring->head - (ring->tail + 8); |
| 257 | if (ring->space < 0) |
| 258 | ring->space += ring->Size; |
| 259 | |
| 260 | if (ring->head != last_head) { |
| 261 | end = jiffies + (HZ * 3); |
| 262 | last_head = ring->head; |
| 263 | } |
| 264 | |
| 265 | iters++; |
| 266 | if (time_before(end, jiffies)) { |
| 267 | DRM_ERROR("space: %d wanted %d\n", ring->space, n); |
| 268 | DRM_ERROR("lockup\n"); |
| 269 | goto out_wait_ring; |
| 270 | } |
| 271 | udelay(1); |
| 272 | } |
| 273 | |
| 274 | out_wait_ring: |
| 275 | return iters; |
| 276 | } |
| 277 | |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 278 | static void i810_kernel_lost_context(struct drm_device * dev) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 279 | { |
| 280 | drm_i810_private_t *dev_priv = dev->dev_private; |
| 281 | drm_i810_ring_buffer_t *ring = &(dev_priv->ring); |
| 282 | |
| 283 | ring->head = I810_READ(LP_RING + RING_HEAD) & HEAD_ADDR; |
| 284 | ring->tail = I810_READ(LP_RING + RING_TAIL); |
| 285 | ring->space = ring->head - (ring->tail + 8); |
| 286 | if (ring->space < 0) |
| 287 | ring->space += ring->Size; |
| 288 | } |
| 289 | |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 290 | static int i810_freelist_init(struct drm_device * dev, drm_i810_private_t * dev_priv) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 291 | { |
Dave Airlie | cdd55a2 | 2007-07-11 16:32:08 +1000 | [diff] [blame] | 292 | struct drm_device_dma *dma = dev->dma; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 293 | int my_idx = 24; |
| 294 | u32 *hw_status = (u32 *) (dev_priv->hw_status_page + my_idx); |
| 295 | int i; |
| 296 | |
| 297 | if (dma->buf_count > 1019) { |
| 298 | /* Not enough space in the status page for the freelist */ |
| 299 | return -EINVAL; |
| 300 | } |
| 301 | |
| 302 | for (i = 0; i < dma->buf_count; i++) { |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 303 | struct drm_buf *buf = dma->buflist[i]; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 304 | drm_i810_buf_priv_t *buf_priv = buf->dev_private; |
| 305 | |
| 306 | buf_priv->in_use = hw_status++; |
| 307 | buf_priv->my_use_idx = my_idx; |
| 308 | my_idx += 4; |
| 309 | |
| 310 | *buf_priv->in_use = I810_BUF_FREE; |
| 311 | |
Dave Airlie | b9094d3 | 2007-01-08 21:31:13 +1100 | [diff] [blame] | 312 | buf_priv->map.offset = buf->bus_address; |
| 313 | buf_priv->map.size = buf->total; |
| 314 | buf_priv->map.type = _DRM_AGP; |
| 315 | buf_priv->map.flags = 0; |
| 316 | buf_priv->map.mtrr = 0; |
| 317 | |
| 318 | drm_core_ioremap(&buf_priv->map, dev); |
| 319 | buf_priv->kernel_virtual = buf_priv->map.handle; |
| 320 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 321 | } |
| 322 | return 0; |
| 323 | } |
| 324 | |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 325 | static int i810_dma_initialize(struct drm_device * dev, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 326 | drm_i810_private_t * dev_priv, |
| 327 | drm_i810_init_t * init) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | { |
Dave Airlie | 5591051 | 2007-07-11 16:53:40 +1000 | [diff] [blame] | 329 | struct drm_map_list *r_list; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 330 | memset(dev_priv, 0, sizeof(drm_i810_private_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
Dave Airlie | bd1b331 | 2007-05-26 05:01:51 +1000 | [diff] [blame] | 332 | list_for_each_entry(r_list, &dev->maplist, head) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | if (r_list->map && |
| 334 | r_list->map->type == _DRM_SHM && |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 335 | r_list->map->flags & _DRM_CONTAINS_LOCK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | dev_priv->sarea_map = r_list->map; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 337 | break; |
| 338 | } |
| 339 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | if (!dev_priv->sarea_map) { |
| 341 | dev->dev_private = (void *)dev_priv; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 342 | i810_dma_cleanup(dev); |
| 343 | DRM_ERROR("can not find sarea!\n"); |
| 344 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | } |
| 346 | dev_priv->mmio_map = drm_core_findmap(dev, init->mmio_offset); |
| 347 | if (!dev_priv->mmio_map) { |
| 348 | dev->dev_private = (void *)dev_priv; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 349 | i810_dma_cleanup(dev); |
| 350 | DRM_ERROR("can not find mmio map!\n"); |
| 351 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | } |
Dave Airlie | d1f2b55 | 2005-08-05 22:11:22 +1000 | [diff] [blame] | 353 | dev->agp_buffer_token = init->buffers_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset); |
| 355 | if (!dev->agp_buffer_map) { |
| 356 | dev->dev_private = (void *)dev_priv; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 357 | i810_dma_cleanup(dev); |
| 358 | DRM_ERROR("can not find dma buffer map!\n"); |
| 359 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | dev_priv->sarea_priv = (drm_i810_sarea_t *) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 363 | ((u8 *) dev_priv->sarea_map->handle + init->sarea_priv_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 365 | dev_priv->ring.Start = init->ring_start; |
| 366 | dev_priv->ring.End = init->ring_end; |
| 367 | dev_priv->ring.Size = init->ring_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
Dave Airlie | b9094d3 | 2007-01-08 21:31:13 +1100 | [diff] [blame] | 369 | dev_priv->ring.map.offset = dev->agp->base + init->ring_start; |
| 370 | dev_priv->ring.map.size = init->ring_size; |
| 371 | dev_priv->ring.map.type = _DRM_AGP; |
| 372 | dev_priv->ring.map.flags = 0; |
| 373 | dev_priv->ring.map.mtrr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | |
Dave Airlie | b9094d3 | 2007-01-08 21:31:13 +1100 | [diff] [blame] | 375 | drm_core_ioremap(&dev_priv->ring.map, dev); |
| 376 | |
| 377 | if (dev_priv->ring.map.handle == NULL) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 378 | dev->dev_private = (void *)dev_priv; |
| 379 | i810_dma_cleanup(dev); |
| 380 | DRM_ERROR("can not ioremap virtual address for" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | " ring buffer\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 382 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Dave Airlie | b9094d3 | 2007-01-08 21:31:13 +1100 | [diff] [blame] | 385 | dev_priv->ring.virtual_start = dev_priv->ring.map.handle; |
| 386 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 387 | dev_priv->ring.tail_mask = dev_priv->ring.Size - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
| 389 | dev_priv->w = init->w; |
| 390 | dev_priv->h = init->h; |
| 391 | dev_priv->pitch = init->pitch; |
| 392 | dev_priv->back_offset = init->back_offset; |
| 393 | dev_priv->depth_offset = init->depth_offset; |
| 394 | dev_priv->front_offset = init->front_offset; |
| 395 | |
| 396 | dev_priv->overlay_offset = init->overlay_offset; |
| 397 | dev_priv->overlay_physical = init->overlay_physical; |
| 398 | |
| 399 | dev_priv->front_di1 = init->front_offset | init->pitch_bits; |
| 400 | dev_priv->back_di1 = init->back_offset | init->pitch_bits; |
| 401 | dev_priv->zi1 = init->depth_offset | init->pitch_bits; |
| 402 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 403 | /* Program Hardware Status Page */ |
| 404 | dev_priv->hw_status_page = |
| 405 | pci_alloc_consistent(dev->pdev, PAGE_SIZE, |
| 406 | &dev_priv->dma_status_page); |
| 407 | if (!dev_priv->hw_status_page) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | dev->dev_private = (void *)dev_priv; |
| 409 | i810_dma_cleanup(dev); |
| 410 | DRM_ERROR("Can not allocate hardware status page\n"); |
| 411 | return -ENOMEM; |
| 412 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 413 | memset(dev_priv->hw_status_page, 0, PAGE_SIZE); |
| 414 | DRM_DEBUG("hw status page @ %p\n", dev_priv->hw_status_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | |
| 416 | I810_WRITE(0x02080, dev_priv->dma_status_page); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 417 | DRM_DEBUG("Enabled hardware status page\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 419 | /* Now we need to init our freelist */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | if (i810_freelist_init(dev, dev_priv) != 0) { |
| 421 | dev->dev_private = (void *)dev_priv; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 422 | i810_dma_cleanup(dev); |
| 423 | DRM_ERROR("Not enough space in the status page for" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | " the freelist\n"); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 425 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | } |
| 427 | dev->dev_private = (void *)dev_priv; |
| 428 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 429 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 432 | static int i810_dma_init(struct drm_device *dev, void *data, |
| 433 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 435 | drm_i810_private_t *dev_priv; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 436 | drm_i810_init_t *init = data; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 437 | int retcode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 439 | switch (init->func) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 440 | case I810_INIT_DMA_1_4: |
| 441 | DRM_INFO("Using v1.4 init.\n"); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 442 | dev_priv = drm_alloc(sizeof(drm_i810_private_t), |
| 443 | DRM_MEM_DRIVER); |
| 444 | if (dev_priv == NULL) |
| 445 | return -ENOMEM; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 446 | retcode = i810_dma_initialize(dev, dev_priv, init); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 447 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 449 | case I810_CLEANUP_DMA: |
| 450 | DRM_INFO("DMA Cleanup\n"); |
| 451 | retcode = i810_dma_cleanup(dev); |
| 452 | break; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 453 | default: |
| 454 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 457 | return retcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | /* Most efficient way to verify state for the i810 is as it is |
| 461 | * emitted. Non-conformant state is silently dropped. |
| 462 | * |
| 463 | * Use 'volatile' & local var tmp to force the emitted values to be |
| 464 | * identical to the verified ones. |
| 465 | */ |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 466 | static void i810EmitContextVerified(struct drm_device * dev, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 467 | volatile unsigned int *code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 469 | drm_i810_private_t *dev_priv = dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | int i, j = 0; |
| 471 | unsigned int tmp; |
| 472 | RING_LOCALS; |
| 473 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 474 | BEGIN_LP_RING(I810_CTX_SETUP_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 476 | OUT_RING(GFX_OP_COLOR_FACTOR); |
| 477 | OUT_RING(code[I810_CTXREG_CF1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 479 | OUT_RING(GFX_OP_STIPPLE); |
| 480 | OUT_RING(code[I810_CTXREG_ST1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 482 | for (i = 4; i < I810_CTX_SETUP_SIZE; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | tmp = code[i]; |
| 484 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 485 | if ((tmp & (7 << 29)) == (3 << 29) && |
| 486 | (tmp & (0x1f << 24)) < (0x1d << 24)) { |
| 487 | OUT_RING(tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | j++; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 489 | } else |
| 490 | printk("constext state dropped!!!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | if (j & 1) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 494 | OUT_RING(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
| 496 | ADVANCE_LP_RING(); |
| 497 | } |
| 498 | |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 499 | static void i810EmitTexVerified(struct drm_device * dev, volatile unsigned int *code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 501 | drm_i810_private_t *dev_priv = dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | int i, j = 0; |
| 503 | unsigned int tmp; |
| 504 | RING_LOCALS; |
| 505 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 506 | BEGIN_LP_RING(I810_TEX_SETUP_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 508 | OUT_RING(GFX_OP_MAP_INFO); |
| 509 | OUT_RING(code[I810_TEXREG_MI1]); |
| 510 | OUT_RING(code[I810_TEXREG_MI2]); |
| 511 | OUT_RING(code[I810_TEXREG_MI3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 513 | for (i = 4; i < I810_TEX_SETUP_SIZE; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | tmp = code[i]; |
| 515 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 516 | if ((tmp & (7 << 29)) == (3 << 29) && |
| 517 | (tmp & (0x1f << 24)) < (0x1d << 24)) { |
| 518 | OUT_RING(tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | j++; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 520 | } else |
| 521 | printk("texture state dropped!!!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | if (j & 1) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 525 | OUT_RING(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
| 527 | ADVANCE_LP_RING(); |
| 528 | } |
| 529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | /* Need to do some additional checking when setting the dest buffer. |
| 531 | */ |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 532 | static void i810EmitDestVerified(struct drm_device * dev, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 533 | volatile unsigned int *code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 535 | drm_i810_private_t *dev_priv = dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | unsigned int tmp; |
| 537 | RING_LOCALS; |
| 538 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 539 | BEGIN_LP_RING(I810_DEST_SETUP_SIZE + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
| 541 | tmp = code[I810_DESTREG_DI1]; |
| 542 | if (tmp == dev_priv->front_di1 || tmp == dev_priv->back_di1) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 543 | OUT_RING(CMD_OP_DESTBUFFER_INFO); |
| 544 | OUT_RING(tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | } else |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 546 | DRM_DEBUG("bad di1 %x (allow %x or %x)\n", |
| 547 | tmp, dev_priv->front_di1, dev_priv->back_di1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | |
| 549 | /* invarient: |
| 550 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 551 | OUT_RING(CMD_OP_Z_BUFFER_INFO); |
| 552 | OUT_RING(dev_priv->zi1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 554 | OUT_RING(GFX_OP_DESTBUFFER_VARS); |
| 555 | OUT_RING(code[I810_DESTREG_DV1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 557 | OUT_RING(GFX_OP_DRAWRECT_INFO); |
| 558 | OUT_RING(code[I810_DESTREG_DR1]); |
| 559 | OUT_RING(code[I810_DESTREG_DR2]); |
| 560 | OUT_RING(code[I810_DESTREG_DR3]); |
| 561 | OUT_RING(code[I810_DESTREG_DR4]); |
| 562 | OUT_RING(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
| 564 | ADVANCE_LP_RING(); |
| 565 | } |
| 566 | |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 567 | static void i810EmitState(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 569 | drm_i810_private_t *dev_priv = dev->dev_private; |
| 570 | drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | unsigned int dirty = sarea_priv->dirty; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 572 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | DRM_DEBUG("%s %x\n", __FUNCTION__, dirty); |
| 574 | |
| 575 | if (dirty & I810_UPLOAD_BUFFERS) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 576 | i810EmitDestVerified(dev, sarea_priv->BufferState); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | sarea_priv->dirty &= ~I810_UPLOAD_BUFFERS; |
| 578 | } |
| 579 | |
| 580 | if (dirty & I810_UPLOAD_CTX) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 581 | i810EmitContextVerified(dev, sarea_priv->ContextState); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | sarea_priv->dirty &= ~I810_UPLOAD_CTX; |
| 583 | } |
| 584 | |
| 585 | if (dirty & I810_UPLOAD_TEX0) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 586 | i810EmitTexVerified(dev, sarea_priv->TexState[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | sarea_priv->dirty &= ~I810_UPLOAD_TEX0; |
| 588 | } |
| 589 | |
| 590 | if (dirty & I810_UPLOAD_TEX1) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 591 | i810EmitTexVerified(dev, sarea_priv->TexState[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | sarea_priv->dirty &= ~I810_UPLOAD_TEX1; |
| 593 | } |
| 594 | } |
| 595 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | /* need to verify |
| 597 | */ |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 598 | static void i810_dma_dispatch_clear(struct drm_device * dev, int flags, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 599 | unsigned int clear_color, |
| 600 | unsigned int clear_zval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 602 | drm_i810_private_t *dev_priv = dev->dev_private; |
| 603 | drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | int nbox = sarea_priv->nbox; |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 605 | struct drm_clip_rect *pbox = sarea_priv->boxes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | int pitch = dev_priv->pitch; |
| 607 | int cpp = 2; |
| 608 | int i; |
| 609 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 610 | |
| 611 | if (dev_priv->current_page == 1) { |
| 612 | unsigned int tmp = flags; |
| 613 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | flags &= ~(I810_FRONT | I810_BACK); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 615 | if (tmp & I810_FRONT) |
| 616 | flags |= I810_BACK; |
| 617 | if (tmp & I810_BACK) |
| 618 | flags |= I810_FRONT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 621 | i810_kernel_lost_context(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 623 | if (nbox > I810_NR_SAREA_CLIPRECTS) |
| 624 | nbox = I810_NR_SAREA_CLIPRECTS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 626 | for (i = 0; i < nbox; i++, pbox++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | unsigned int x = pbox->x1; |
| 628 | unsigned int y = pbox->y1; |
| 629 | unsigned int width = (pbox->x2 - x) * cpp; |
| 630 | unsigned int height = pbox->y2 - y; |
| 631 | unsigned int start = y * pitch + x * cpp; |
| 632 | |
| 633 | if (pbox->x1 > pbox->x2 || |
| 634 | pbox->y1 > pbox->y2 || |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 635 | pbox->x2 > dev_priv->w || pbox->y2 > dev_priv->h) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | continue; |
| 637 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 638 | if (flags & I810_FRONT) { |
| 639 | BEGIN_LP_RING(6); |
| 640 | OUT_RING(BR00_BITBLT_CLIENT | BR00_OP_COLOR_BLT | 0x3); |
| 641 | OUT_RING(BR13_SOLID_PATTERN | (0xF0 << 16) | pitch); |
| 642 | OUT_RING((height << 16) | width); |
| 643 | OUT_RING(start); |
| 644 | OUT_RING(clear_color); |
| 645 | OUT_RING(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | ADVANCE_LP_RING(); |
| 647 | } |
| 648 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 649 | if (flags & I810_BACK) { |
| 650 | BEGIN_LP_RING(6); |
| 651 | OUT_RING(BR00_BITBLT_CLIENT | BR00_OP_COLOR_BLT | 0x3); |
| 652 | OUT_RING(BR13_SOLID_PATTERN | (0xF0 << 16) | pitch); |
| 653 | OUT_RING((height << 16) | width); |
| 654 | OUT_RING(dev_priv->back_offset + start); |
| 655 | OUT_RING(clear_color); |
| 656 | OUT_RING(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | ADVANCE_LP_RING(); |
| 658 | } |
| 659 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 660 | if (flags & I810_DEPTH) { |
| 661 | BEGIN_LP_RING(6); |
| 662 | OUT_RING(BR00_BITBLT_CLIENT | BR00_OP_COLOR_BLT | 0x3); |
| 663 | OUT_RING(BR13_SOLID_PATTERN | (0xF0 << 16) | pitch); |
| 664 | OUT_RING((height << 16) | width); |
| 665 | OUT_RING(dev_priv->depth_offset + start); |
| 666 | OUT_RING(clear_zval); |
| 667 | OUT_RING(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | ADVANCE_LP_RING(); |
| 669 | } |
| 670 | } |
| 671 | } |
| 672 | |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 673 | static void i810_dma_dispatch_swap(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 675 | drm_i810_private_t *dev_priv = dev->dev_private; |
| 676 | drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | int nbox = sarea_priv->nbox; |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 678 | struct drm_clip_rect *pbox = sarea_priv->boxes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | int pitch = dev_priv->pitch; |
| 680 | int cpp = 2; |
| 681 | int i; |
| 682 | RING_LOCALS; |
| 683 | |
| 684 | DRM_DEBUG("swapbuffers\n"); |
| 685 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 686 | i810_kernel_lost_context(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 688 | if (nbox > I810_NR_SAREA_CLIPRECTS) |
| 689 | nbox = I810_NR_SAREA_CLIPRECTS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 691 | for (i = 0; i < nbox; i++, pbox++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | unsigned int w = pbox->x2 - pbox->x1; |
| 693 | unsigned int h = pbox->y2 - pbox->y1; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 694 | unsigned int dst = pbox->x1 * cpp + pbox->y1 * pitch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | unsigned int start = dst; |
| 696 | |
| 697 | if (pbox->x1 > pbox->x2 || |
| 698 | pbox->y1 > pbox->y2 || |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 699 | pbox->x2 > dev_priv->w || pbox->y2 > dev_priv->h) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | continue; |
| 701 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 702 | BEGIN_LP_RING(6); |
| 703 | OUT_RING(BR00_BITBLT_CLIENT | BR00_OP_SRC_COPY_BLT | 0x4); |
| 704 | OUT_RING(pitch | (0xCC << 16)); |
| 705 | OUT_RING((h << 16) | (w * cpp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | if (dev_priv->current_page == 0) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 707 | OUT_RING(dev_priv->front_offset + start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | else |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 709 | OUT_RING(dev_priv->back_offset + start); |
| 710 | OUT_RING(pitch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | if (dev_priv->current_page == 0) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 712 | OUT_RING(dev_priv->back_offset + start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | else |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 714 | OUT_RING(dev_priv->front_offset + start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | ADVANCE_LP_RING(); |
| 716 | } |
| 717 | } |
| 718 | |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 719 | static void i810_dma_dispatch_vertex(struct drm_device * dev, |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 720 | struct drm_buf * buf, int discard, int used) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 722 | drm_i810_private_t *dev_priv = dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | drm_i810_buf_priv_t *buf_priv = buf->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 724 | drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv; |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 725 | struct drm_clip_rect *box = sarea_priv->boxes; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 726 | int nbox = sarea_priv->nbox; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | unsigned long address = (unsigned long)buf->bus_address; |
| 728 | unsigned long start = address - dev->agp->base; |
| 729 | int i = 0; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 730 | RING_LOCALS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 732 | i810_kernel_lost_context(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 734 | if (nbox > I810_NR_SAREA_CLIPRECTS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | nbox = I810_NR_SAREA_CLIPRECTS; |
| 736 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 737 | if (used > 4 * 1024) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | used = 0; |
| 739 | |
| 740 | if (sarea_priv->dirty) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 741 | i810EmitState(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | |
| 743 | if (buf_priv->currently_mapped == I810_BUF_MAPPED) { |
| 744 | unsigned int prim = (sarea_priv->vertex_prim & PR_MASK); |
| 745 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 746 | *(u32 *) buf_priv->kernel_virtual = |
| 747 | ((GFX_OP_PRIMITIVE | prim | ((used / 4) - 2))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | |
| 749 | if (used & 4) { |
Denis Vlasenko | c7aed17 | 2006-08-16 11:54:07 +1000 | [diff] [blame] | 750 | *(u32 *) ((char *) buf_priv->kernel_virtual + used) = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | used += 4; |
| 752 | } |
| 753 | |
| 754 | i810_unmap_buffer(buf); |
| 755 | } |
| 756 | |
| 757 | if (used) { |
| 758 | do { |
| 759 | if (i < nbox) { |
| 760 | BEGIN_LP_RING(4); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 761 | OUT_RING(GFX_OP_SCISSOR | SC_UPDATE_SCISSOR | |
| 762 | SC_ENABLE); |
| 763 | OUT_RING(GFX_OP_SCISSOR_INFO); |
| 764 | OUT_RING(box[i].x1 | (box[i].y1 << 16)); |
| 765 | OUT_RING((box[i].x2 - |
| 766 | 1) | ((box[i].y2 - 1) << 16)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | ADVANCE_LP_RING(); |
| 768 | } |
| 769 | |
| 770 | BEGIN_LP_RING(4); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 771 | OUT_RING(CMD_OP_BATCH_BUFFER); |
| 772 | OUT_RING(start | BB1_PROTECTED); |
| 773 | OUT_RING(start + used - 4); |
| 774 | OUT_RING(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | ADVANCE_LP_RING(); |
| 776 | |
| 777 | } while (++i < nbox); |
| 778 | } |
| 779 | |
| 780 | if (discard) { |
| 781 | dev_priv->counter++; |
| 782 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 783 | (void)cmpxchg(buf_priv->in_use, I810_BUF_CLIENT, |
| 784 | I810_BUF_HARDWARE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
| 786 | BEGIN_LP_RING(8); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 787 | OUT_RING(CMD_STORE_DWORD_IDX); |
| 788 | OUT_RING(20); |
| 789 | OUT_RING(dev_priv->counter); |
| 790 | OUT_RING(CMD_STORE_DWORD_IDX); |
| 791 | OUT_RING(buf_priv->my_use_idx); |
| 792 | OUT_RING(I810_BUF_FREE); |
| 793 | OUT_RING(CMD_REPORT_HEAD); |
| 794 | OUT_RING(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | ADVANCE_LP_RING(); |
| 796 | } |
| 797 | } |
| 798 | |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 799 | static void i810_dma_dispatch_flip(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 801 | drm_i810_private_t *dev_priv = dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | int pitch = dev_priv->pitch; |
| 803 | RING_LOCALS; |
| 804 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 805 | DRM_DEBUG("%s: page=%d pfCurrentPage=%d\n", |
| 806 | __FUNCTION__, |
| 807 | dev_priv->current_page, |
| 808 | dev_priv->sarea_priv->pf_current_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 810 | i810_kernel_lost_context(dev); |
| 811 | |
| 812 | BEGIN_LP_RING(2); |
| 813 | OUT_RING(INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE); |
| 814 | OUT_RING(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | ADVANCE_LP_RING(); |
| 816 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 817 | BEGIN_LP_RING(I810_DEST_SETUP_SIZE + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | /* On i815 at least ASYNC is buggy */ |
| 819 | /* pitch<<5 is from 11.2.8 p158, |
| 820 | its the pitch / 8 then left shifted 8, |
| 821 | so (pitch >> 3) << 8 */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 822 | OUT_RING(CMD_OP_FRONTBUFFER_INFO | (pitch << 5) /*| ASYNC_FLIP */ ); |
| 823 | if (dev_priv->current_page == 0) { |
| 824 | OUT_RING(dev_priv->back_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | dev_priv->current_page = 1; |
| 826 | } else { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 827 | OUT_RING(dev_priv->front_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | dev_priv->current_page = 0; |
| 829 | } |
| 830 | OUT_RING(0); |
| 831 | ADVANCE_LP_RING(); |
| 832 | |
| 833 | BEGIN_LP_RING(2); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 834 | OUT_RING(CMD_OP_WAIT_FOR_EVENT | WAIT_FOR_PLANE_A_FLIP); |
| 835 | OUT_RING(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | ADVANCE_LP_RING(); |
| 837 | |
| 838 | /* Increment the frame counter. The client-side 3D driver must |
| 839 | * throttle the framerate by waiting for this value before |
| 840 | * performing the swapbuffer ioctl. |
| 841 | */ |
| 842 | dev_priv->sarea_priv->pf_current_page = dev_priv->current_page; |
| 843 | |
| 844 | } |
| 845 | |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 846 | static void i810_dma_quiescent(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 848 | drm_i810_private_t *dev_priv = dev->dev_private; |
| 849 | RING_LOCALS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | |
| 851 | /* printk("%s\n", __FUNCTION__); */ |
| 852 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 853 | i810_kernel_lost_context(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 855 | BEGIN_LP_RING(4); |
| 856 | OUT_RING(INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE); |
| 857 | OUT_RING(CMD_REPORT_HEAD); |
| 858 | OUT_RING(0); |
| 859 | OUT_RING(0); |
| 860 | ADVANCE_LP_RING(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 862 | i810_wait_ring(dev, dev_priv->ring.Size - 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | } |
| 864 | |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 865 | static int i810_flush_queue(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 867 | drm_i810_private_t *dev_priv = dev->dev_private; |
Dave Airlie | cdd55a2 | 2007-07-11 16:32:08 +1000 | [diff] [blame] | 868 | struct drm_device_dma *dma = dev->dma; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 869 | int i, ret = 0; |
| 870 | RING_LOCALS; |
| 871 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | /* printk("%s\n", __FUNCTION__); */ |
| 873 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 874 | i810_kernel_lost_context(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 876 | BEGIN_LP_RING(2); |
| 877 | OUT_RING(CMD_REPORT_HEAD); |
| 878 | OUT_RING(0); |
| 879 | ADVANCE_LP_RING(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 881 | i810_wait_ring(dev, dev_priv->ring.Size - 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 883 | for (i = 0; i < dma->buf_count; i++) { |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 884 | struct drm_buf *buf = dma->buflist[i]; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 885 | drm_i810_buf_priv_t *buf_priv = buf->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | |
| 887 | int used = cmpxchg(buf_priv->in_use, I810_BUF_HARDWARE, |
| 888 | I810_BUF_FREE); |
| 889 | |
| 890 | if (used == I810_BUF_HARDWARE) |
| 891 | DRM_DEBUG("reclaimed from HARDWARE\n"); |
| 892 | if (used == I810_BUF_CLIENT) |
| 893 | DRM_DEBUG("still on client\n"); |
| 894 | } |
| 895 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 896 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | /* Must be called with the lock held */ |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 900 | static void i810_reclaim_buffers(struct drm_device * dev, |
| 901 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | { |
Dave Airlie | cdd55a2 | 2007-07-11 16:32:08 +1000 | [diff] [blame] | 903 | struct drm_device_dma *dma = dev->dma; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 904 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 906 | if (!dma) |
| 907 | return; |
| 908 | if (!dev->dev_private) |
| 909 | return; |
| 910 | if (!dma->buflist) |
| 911 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 913 | i810_flush_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | |
| 915 | for (i = 0; i < dma->buf_count; i++) { |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 916 | struct drm_buf *buf = dma->buflist[i]; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 917 | drm_i810_buf_priv_t *buf_priv = buf->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 919 | if (buf->file_priv == file_priv && buf_priv) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | int used = cmpxchg(buf_priv->in_use, I810_BUF_CLIENT, |
| 921 | I810_BUF_FREE); |
| 922 | |
| 923 | if (used == I810_BUF_CLIENT) |
| 924 | DRM_DEBUG("reclaimed from client\n"); |
| 925 | if (buf_priv->currently_mapped == I810_BUF_MAPPED) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 926 | buf_priv->currently_mapped = I810_BUF_UNMAPPED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | } |
| 928 | } |
| 929 | } |
| 930 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 931 | static int i810_flush_ioctl(struct drm_device *dev, void *data, |
| 932 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | { |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 934 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 936 | i810_flush_queue(dev); |
| 937 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | } |
| 939 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 940 | static int i810_dma_vertex(struct drm_device *dev, void *data, |
| 941 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | { |
Dave Airlie | cdd55a2 | 2007-07-11 16:32:08 +1000 | [diff] [blame] | 943 | struct drm_device_dma *dma = dev->dma; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 944 | drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private; |
| 945 | u32 *hw_status = dev_priv->hw_status_page; |
| 946 | drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *) |
| 947 | dev_priv->sarea_priv; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 948 | drm_i810_vertex_t *vertex = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 950 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | |
| 952 | DRM_DEBUG("i810 dma vertex, idx %d used %d discard %d\n", |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 953 | vertex->idx, vertex->used, vertex->discard); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 955 | if (vertex->idx < 0 || vertex->idx > dma->buf_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | return -EINVAL; |
| 957 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 958 | i810_dma_dispatch_vertex(dev, |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 959 | dma->buflist[vertex->idx], |
| 960 | vertex->discard, vertex->used); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 962 | atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | atomic_inc(&dev->counts[_DRM_STAT_DMA]); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 964 | sarea_priv->last_enqueue = dev_priv->counter - 1; |
| 965 | sarea_priv->last_dispatch = (int)hw_status[5]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | |
| 967 | return 0; |
| 968 | } |
| 969 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 970 | static int i810_clear_bufs(struct drm_device *dev, void *data, |
| 971 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 973 | drm_i810_clear_t *clear = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 975 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 977 | /* GH: Someone's doing nasty things... */ |
| 978 | if (!dev->dev_private) { |
| 979 | return -EINVAL; |
| 980 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 982 | i810_dma_dispatch_clear(dev, clear->flags, |
| 983 | clear->clear_color, clear->clear_depth); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 984 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | } |
| 986 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 987 | static int i810_swap_bufs(struct drm_device *dev, void *data, |
| 988 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | DRM_DEBUG("i810_swap_bufs\n"); |
| 991 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 992 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 994 | i810_dma_dispatch_swap(dev); |
| 995 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | } |
| 997 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 998 | static int i810_getage(struct drm_device *dev, void *data, |
| 999 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1001 | drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private; |
| 1002 | u32 *hw_status = dev_priv->hw_status_page; |
| 1003 | drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *) |
| 1004 | dev_priv->sarea_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1006 | sarea_priv->last_dispatch = (int)hw_status[5]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | return 0; |
| 1008 | } |
| 1009 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1010 | static int i810_getbuf(struct drm_device *dev, void *data, |
| 1011 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1013 | int retcode = 0; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1014 | drm_i810_dma_t *d = data; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1015 | drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private; |
| 1016 | u32 *hw_status = dev_priv->hw_status_page; |
| 1017 | drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *) |
| 1018 | dev_priv->sarea_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1020 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1022 | d->granted = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1024 | retcode = i810_dma_get_buffer(dev, d, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | |
| 1026 | DRM_DEBUG("i810_dma: %d returning %d, granted = %d\n", |
Pavel Emelyanov | ba25f9d | 2007-10-18 23:40:40 -0700 | [diff] [blame^] | 1027 | task_pid_nr(current), retcode, d->granted); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1029 | sarea_priv->last_dispatch = (int)hw_status[5]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | |
| 1031 | return retcode; |
| 1032 | } |
| 1033 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1034 | static int i810_copybuf(struct drm_device *dev, void *data, |
| 1035 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | { |
| 1037 | /* Never copy - 2.4.x doesn't need it */ |
| 1038 | return 0; |
| 1039 | } |
| 1040 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1041 | static int i810_docopy(struct drm_device *dev, void *data, |
| 1042 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | { |
| 1044 | /* Never copy - 2.4.x doesn't need it */ |
| 1045 | return 0; |
| 1046 | } |
| 1047 | |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 1048 | static void i810_dma_dispatch_mc(struct drm_device * dev, struct drm_buf * buf, int used, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1049 | unsigned int last_render) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | { |
| 1051 | drm_i810_private_t *dev_priv = dev->dev_private; |
| 1052 | drm_i810_buf_priv_t *buf_priv = buf->dev_private; |
| 1053 | drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv; |
| 1054 | unsigned long address = (unsigned long)buf->bus_address; |
| 1055 | unsigned long start = address - dev->agp->base; |
| 1056 | int u; |
| 1057 | RING_LOCALS; |
| 1058 | |
| 1059 | i810_kernel_lost_context(dev); |
| 1060 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1061 | u = cmpxchg(buf_priv->in_use, I810_BUF_CLIENT, I810_BUF_HARDWARE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | if (u != I810_BUF_CLIENT) { |
| 1063 | DRM_DEBUG("MC found buffer that isn't mine!\n"); |
| 1064 | } |
| 1065 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1066 | if (used > 4 * 1024) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | used = 0; |
| 1068 | |
| 1069 | sarea_priv->dirty = 0x7f; |
| 1070 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1071 | DRM_DEBUG("dispatch mc addr 0x%lx, used 0x%x\n", address, used); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | |
| 1073 | dev_priv->counter++; |
| 1074 | DRM_DEBUG("dispatch counter : %ld\n", dev_priv->counter); |
| 1075 | DRM_DEBUG("i810_dma_dispatch_mc\n"); |
| 1076 | DRM_DEBUG("start : %lx\n", start); |
| 1077 | DRM_DEBUG("used : %d\n", used); |
| 1078 | DRM_DEBUG("start + used - 4 : %ld\n", start + used - 4); |
| 1079 | |
| 1080 | if (buf_priv->currently_mapped == I810_BUF_MAPPED) { |
| 1081 | if (used & 4) { |
Denis Vlasenko | c7aed17 | 2006-08-16 11:54:07 +1000 | [diff] [blame] | 1082 | *(u32 *) ((char *) buf_priv->virtual + used) = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | used += 4; |
| 1084 | } |
| 1085 | |
| 1086 | i810_unmap_buffer(buf); |
| 1087 | } |
| 1088 | BEGIN_LP_RING(4); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1089 | OUT_RING(CMD_OP_BATCH_BUFFER); |
| 1090 | OUT_RING(start | BB1_PROTECTED); |
| 1091 | OUT_RING(start + used - 4); |
| 1092 | OUT_RING(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | ADVANCE_LP_RING(); |
| 1094 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | BEGIN_LP_RING(8); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1096 | OUT_RING(CMD_STORE_DWORD_IDX); |
| 1097 | OUT_RING(buf_priv->my_use_idx); |
| 1098 | OUT_RING(I810_BUF_FREE); |
| 1099 | OUT_RING(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1101 | OUT_RING(CMD_STORE_DWORD_IDX); |
| 1102 | OUT_RING(16); |
| 1103 | OUT_RING(last_render); |
| 1104 | OUT_RING(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | ADVANCE_LP_RING(); |
| 1106 | } |
| 1107 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1108 | static int i810_dma_mc(struct drm_device *dev, void *data, |
| 1109 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | { |
Dave Airlie | cdd55a2 | 2007-07-11 16:32:08 +1000 | [diff] [blame] | 1111 | struct drm_device_dma *dma = dev->dma; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1112 | drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | u32 *hw_status = dev_priv->hw_status_page; |
| 1114 | drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1115 | dev_priv->sarea_priv; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1116 | drm_i810_mc_t *mc = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1118 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1120 | if (mc->idx >= dma->buf_count || mc->idx < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | return -EINVAL; |
| 1122 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1123 | i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used, |
| 1124 | mc->last_render); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1126 | atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | atomic_inc(&dev->counts[_DRM_STAT_DMA]); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1128 | sarea_priv->last_enqueue = dev_priv->counter - 1; |
| 1129 | sarea_priv->last_dispatch = (int)hw_status[5]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | |
| 1131 | return 0; |
| 1132 | } |
| 1133 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1134 | static int i810_rstatus(struct drm_device *dev, void *data, |
| 1135 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1137 | drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1139 | return (int)(((u32 *) (dev_priv->hw_status_page))[4]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | } |
| 1141 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1142 | static int i810_ov0_info(struct drm_device *dev, void *data, |
| 1143 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1145 | drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1146 | drm_i810_overlay_t *ov = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1148 | ov->offset = dev_priv->overlay_offset; |
| 1149 | ov->physical = dev_priv->overlay_physical; |
| 1150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | return 0; |
| 1152 | } |
| 1153 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1154 | static int i810_fstatus(struct drm_device *dev, void *data, |
| 1155 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1157 | drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1159 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | return I810_READ(0x30008); |
| 1161 | } |
| 1162 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1163 | static int i810_ov0_flip(struct drm_device *dev, void *data, |
| 1164 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1166 | drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1168 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | |
| 1170 | //Tell the overlay to update |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1171 | I810_WRITE(0x30000, dev_priv->overlay_physical | 0x80000000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | |
| 1173 | return 0; |
| 1174 | } |
| 1175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | /* Not sure why this isn't set all the time: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1177 | */ |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 1178 | static void i810_do_init_pageflip(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | { |
| 1180 | drm_i810_private_t *dev_priv = dev->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | DRM_DEBUG("%s\n", __FUNCTION__); |
| 1183 | dev_priv->page_flipping = 1; |
| 1184 | dev_priv->current_page = 0; |
| 1185 | dev_priv->sarea_priv->pf_current_page = dev_priv->current_page; |
| 1186 | } |
| 1187 | |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 1188 | static int i810_do_cleanup_pageflip(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | { |
| 1190 | drm_i810_private_t *dev_priv = dev->dev_private; |
| 1191 | |
| 1192 | DRM_DEBUG("%s\n", __FUNCTION__); |
| 1193 | if (dev_priv->current_page != 0) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1194 | i810_dma_dispatch_flip(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | |
| 1196 | dev_priv->page_flipping = 0; |
| 1197 | return 0; |
| 1198 | } |
| 1199 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1200 | static int i810_flip_bufs(struct drm_device *dev, void *data, |
| 1201 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | drm_i810_private_t *dev_priv = dev->dev_private; |
| 1204 | |
| 1205 | DRM_DEBUG("%s\n", __FUNCTION__); |
| 1206 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1207 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1209 | if (!dev_priv->page_flipping) |
| 1210 | i810_do_init_pageflip(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1212 | i810_dma_dispatch_flip(dev); |
| 1213 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 1216 | int i810_driver_load(struct drm_device *dev, unsigned long flags) |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 1217 | { |
| 1218 | /* i810 has 4 more counters */ |
| 1219 | dev->counters += 4; |
| 1220 | dev->types[6] = _DRM_STAT_IRQ; |
| 1221 | dev->types[7] = _DRM_STAT_PRIMARY; |
| 1222 | dev->types[8] = _DRM_STAT_SECONDARY; |
| 1223 | dev->types[9] = _DRM_STAT_DMA; |
| 1224 | |
| 1225 | return 0; |
| 1226 | } |
| 1227 | |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 1228 | void i810_driver_lastclose(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1230 | i810_dma_cleanup(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | } |
| 1232 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1233 | void i810_driver_preclose(struct drm_device * dev, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | { |
| 1235 | if (dev->dev_private) { |
| 1236 | drm_i810_private_t *dev_priv = dev->dev_private; |
| 1237 | if (dev_priv->page_flipping) { |
| 1238 | i810_do_cleanup_pageflip(dev); |
| 1239 | } |
| 1240 | } |
| 1241 | } |
| 1242 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1243 | void i810_driver_reclaim_buffers_locked(struct drm_device * dev, |
| 1244 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | { |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1246 | i810_reclaim_buffers(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | } |
| 1248 | |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 1249 | int i810_driver_dma_quiescent(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1251 | i810_dma_quiescent(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | return 0; |
| 1253 | } |
| 1254 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1255 | struct drm_ioctl_desc i810_ioctls[] = { |
| 1256 | DRM_IOCTL_DEF(DRM_I810_INIT, i810_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 1257 | DRM_IOCTL_DEF(DRM_I810_VERTEX, i810_dma_vertex, DRM_AUTH), |
| 1258 | DRM_IOCTL_DEF(DRM_I810_CLEAR, i810_clear_bufs, DRM_AUTH), |
| 1259 | DRM_IOCTL_DEF(DRM_I810_FLUSH, i810_flush_ioctl, DRM_AUTH), |
| 1260 | DRM_IOCTL_DEF(DRM_I810_GETAGE, i810_getage, DRM_AUTH), |
| 1261 | DRM_IOCTL_DEF(DRM_I810_GETBUF, i810_getbuf, DRM_AUTH), |
| 1262 | DRM_IOCTL_DEF(DRM_I810_SWAP, i810_swap_bufs, DRM_AUTH), |
| 1263 | DRM_IOCTL_DEF(DRM_I810_COPY, i810_copybuf, DRM_AUTH), |
| 1264 | DRM_IOCTL_DEF(DRM_I810_DOCOPY, i810_docopy, DRM_AUTH), |
| 1265 | DRM_IOCTL_DEF(DRM_I810_OV0INFO, i810_ov0_info, DRM_AUTH), |
| 1266 | DRM_IOCTL_DEF(DRM_I810_FSTATUS, i810_fstatus, DRM_AUTH), |
| 1267 | DRM_IOCTL_DEF(DRM_I810_OV0FLIP, i810_ov0_flip, DRM_AUTH), |
| 1268 | DRM_IOCTL_DEF(DRM_I810_MC, i810_dma_mc, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 1269 | DRM_IOCTL_DEF(DRM_I810_RSTATUS, i810_rstatus, DRM_AUTH), |
| 1270 | DRM_IOCTL_DEF(DRM_I810_FLIP, i810_flip_bufs, DRM_AUTH) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | }; |
| 1272 | |
| 1273 | int i810_max_ioctl = DRM_ARRAY_SIZE(i810_ioctls); |
Dave Airlie | cda1738 | 2005-07-10 17:31:26 +1000 | [diff] [blame] | 1274 | |
| 1275 | /** |
| 1276 | * Determine if the device really is AGP or not. |
| 1277 | * |
| 1278 | * All Intel graphics chipsets are treated as AGP, even if they are really |
| 1279 | * PCI-e. |
| 1280 | * |
| 1281 | * \param dev The device to be tested. |
| 1282 | * |
| 1283 | * \returns |
| 1284 | * A value of 1 is always retured to indictate every i810 is AGP. |
| 1285 | */ |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 1286 | int i810_driver_device_is_agp(struct drm_device * dev) |
Dave Airlie | cda1738 | 2005-07-10 17:31:26 +1000 | [diff] [blame] | 1287 | { |
| 1288 | return 1; |
| 1289 | } |