| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright © 2008-2010 Intel Corporation | 
 | 3 |  * | 
 | 4 |  * Permission is hereby granted, free of charge, to any person obtaining a | 
 | 5 |  * copy of this software and associated documentation files (the "Software"), | 
 | 6 |  * to deal in the Software without restriction, including without limitation | 
 | 7 |  * the rights to use, copy, modify, merge, publish, distribute, sublicense, | 
 | 8 |  * and/or sell copies of the Software, and to permit persons to whom the | 
 | 9 |  * Software is furnished to do so, subject to the following conditions: | 
 | 10 |  * | 
 | 11 |  * The above copyright notice and this permission notice (including the next | 
 | 12 |  * paragraph) shall be included in all copies or substantial portions of the | 
 | 13 |  * Software. | 
 | 14 |  * | 
 | 15 |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
 | 16 |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
 | 17 |  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL | 
 | 18 |  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
 | 19 |  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | 
 | 20 |  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | 
 | 21 |  * IN THE SOFTWARE. | 
 | 22 |  * | 
 | 23 |  * Authors: | 
 | 24 |  *    Eric Anholt <eric@anholt.net> | 
 | 25 |  *    Zou Nan hai <nanhai.zou@intel.com> | 
 | 26 |  *    Xiang Hai hao<haihao.xiang@intel.com> | 
 | 27 |  * | 
 | 28 |  */ | 
 | 29 |  | 
 | 30 | #include "drmP.h" | 
 | 31 | #include "drm.h" | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 32 | #include "i915_drv.h" | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 33 | #include "i915_drm.h" | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 34 | #include "i915_trace.h" | 
| Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 35 | #include "intel_drv.h" | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 36 |  | 
| Chris Wilson | 6f392d5 | 2010-08-07 11:01:22 +0100 | [diff] [blame] | 37 | static u32 i915_gem_get_seqno(struct drm_device *dev) | 
 | 38 | { | 
 | 39 | 	drm_i915_private_t *dev_priv = dev->dev_private; | 
 | 40 | 	u32 seqno; | 
 | 41 |  | 
 | 42 | 	seqno = dev_priv->next_seqno; | 
 | 43 |  | 
 | 44 | 	/* reserve 0 for non-seqno */ | 
 | 45 | 	if (++dev_priv->next_seqno == 0) | 
 | 46 | 		dev_priv->next_seqno = 1; | 
 | 47 |  | 
 | 48 | 	return seqno; | 
 | 49 | } | 
 | 50 |  | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 51 | static void | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 52 | render_ring_flush(struct intel_ring_buffer *ring, | 
| Chris Wilson | ab6f8e3 | 2010-09-19 17:53:44 +0100 | [diff] [blame] | 53 | 		  u32	invalidate_domains, | 
 | 54 | 		  u32	flush_domains) | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 55 | { | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 56 | 	struct drm_device *dev = ring->dev; | 
| Chris Wilson | 6f392d5 | 2010-08-07 11:01:22 +0100 | [diff] [blame] | 57 | 	drm_i915_private_t *dev_priv = dev->dev_private; | 
 | 58 | 	u32 cmd; | 
 | 59 |  | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 60 | #if WATCH_EXEC | 
 | 61 | 	DRM_INFO("%s: invalidate %08x flush %08x\n", __func__, | 
 | 62 | 		  invalidate_domains, flush_domains); | 
 | 63 | #endif | 
| Chris Wilson | 6f392d5 | 2010-08-07 11:01:22 +0100 | [diff] [blame] | 64 |  | 
 | 65 | 	trace_i915_gem_request_flush(dev, dev_priv->next_seqno, | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 66 | 				     invalidate_domains, flush_domains); | 
 | 67 |  | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 68 | 	if ((invalidate_domains | flush_domains) & I915_GEM_GPU_DOMAINS) { | 
 | 69 | 		/* | 
 | 70 | 		 * read/write caches: | 
 | 71 | 		 * | 
 | 72 | 		 * I915_GEM_DOMAIN_RENDER is always invalidated, but is | 
 | 73 | 		 * only flushed if MI_NO_WRITE_FLUSH is unset.  On 965, it is | 
 | 74 | 		 * also flushed at 2d versus 3d pipeline switches. | 
 | 75 | 		 * | 
 | 76 | 		 * read-only caches: | 
 | 77 | 		 * | 
 | 78 | 		 * I915_GEM_DOMAIN_SAMPLER is flushed on pre-965 if | 
 | 79 | 		 * MI_READ_FLUSH is set, and is always flushed on 965. | 
 | 80 | 		 * | 
 | 81 | 		 * I915_GEM_DOMAIN_COMMAND may not exist? | 
 | 82 | 		 * | 
 | 83 | 		 * I915_GEM_DOMAIN_INSTRUCTION, which exists on 965, is | 
 | 84 | 		 * invalidated when MI_EXE_FLUSH is set. | 
 | 85 | 		 * | 
 | 86 | 		 * I915_GEM_DOMAIN_VERTEX, which exists on 965, is | 
 | 87 | 		 * invalidated with every MI_FLUSH. | 
 | 88 | 		 * | 
 | 89 | 		 * TLBs: | 
 | 90 | 		 * | 
 | 91 | 		 * On 965, TLBs associated with I915_GEM_DOMAIN_COMMAND | 
 | 92 | 		 * and I915_GEM_DOMAIN_CPU in are invalidated at PTE write and | 
 | 93 | 		 * I915_GEM_DOMAIN_RENDER and I915_GEM_DOMAIN_SAMPLER | 
 | 94 | 		 * are flushed at any MI_FLUSH. | 
 | 95 | 		 */ | 
 | 96 |  | 
 | 97 | 		cmd = MI_FLUSH | MI_NO_WRITE_FLUSH; | 
 | 98 | 		if ((invalidate_domains|flush_domains) & | 
 | 99 | 		    I915_GEM_DOMAIN_RENDER) | 
 | 100 | 			cmd &= ~MI_NO_WRITE_FLUSH; | 
| Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 101 | 		if (INTEL_INFO(dev)->gen < 4) { | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 102 | 			/* | 
 | 103 | 			 * On the 965, the sampler cache always gets flushed | 
 | 104 | 			 * and this bit is reserved. | 
 | 105 | 			 */ | 
 | 106 | 			if (invalidate_domains & I915_GEM_DOMAIN_SAMPLER) | 
 | 107 | 				cmd |= MI_READ_FLUSH; | 
 | 108 | 		} | 
 | 109 | 		if (invalidate_domains & I915_GEM_DOMAIN_INSTRUCTION) | 
 | 110 | 			cmd |= MI_EXE_FLUSH; | 
 | 111 |  | 
 | 112 | #if WATCH_EXEC | 
 | 113 | 		DRM_INFO("%s: queue flush %08x to ring\n", __func__, cmd); | 
 | 114 | #endif | 
| Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 115 | 		if (intel_ring_begin(ring, 2) == 0) { | 
 | 116 | 			intel_ring_emit(ring, cmd); | 
 | 117 | 			intel_ring_emit(ring, MI_NOOP); | 
 | 118 | 			intel_ring_advance(ring); | 
 | 119 | 		} | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 120 | 	} | 
 | 121 | } | 
 | 122 |  | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 123 | static void ring_write_tail(struct intel_ring_buffer *ring, | 
| Chris Wilson | 297b0c5 | 2010-10-22 17:02:41 +0100 | [diff] [blame] | 124 | 			    u32 value) | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 125 | { | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 126 | 	drm_i915_private_t *dev_priv = ring->dev->dev_private; | 
| Chris Wilson | 297b0c5 | 2010-10-22 17:02:41 +0100 | [diff] [blame] | 127 | 	I915_WRITE_TAIL(ring, value); | 
| Xiang, Haihao | d46eefa | 2010-09-16 10:43:12 +0800 | [diff] [blame] | 128 | } | 
 | 129 |  | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 130 | u32 intel_ring_get_active_head(struct intel_ring_buffer *ring) | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 131 | { | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 132 | 	drm_i915_private_t *dev_priv = ring->dev->dev_private; | 
 | 133 | 	u32 acthd_reg = INTEL_INFO(ring->dev)->gen >= 4 ? | 
| Daniel Vetter | 3d281d8 | 2010-09-24 21:14:22 +0200 | [diff] [blame] | 134 | 			RING_ACTHD(ring->mmio_base) : ACTHD; | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 135 |  | 
 | 136 | 	return I915_READ(acthd_reg); | 
 | 137 | } | 
 | 138 |  | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 139 | static int init_ring_common(struct intel_ring_buffer *ring) | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 140 | { | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 141 | 	drm_i915_private_t *dev_priv = ring->dev->dev_private; | 
| Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 142 | 	struct drm_i915_gem_object *obj = ring->obj; | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 143 | 	u32 head; | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 144 |  | 
 | 145 | 	/* Stop the ring if it's running. */ | 
| Daniel Vetter | 7f2ab69 | 2010-08-02 17:06:59 +0200 | [diff] [blame] | 146 | 	I915_WRITE_CTL(ring, 0); | 
| Daniel Vetter | 570ef60 | 2010-08-02 17:06:23 +0200 | [diff] [blame] | 147 | 	I915_WRITE_HEAD(ring, 0); | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 148 | 	ring->write_tail(ring, 0); | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 149 |  | 
 | 150 | 	/* Initialize the ring. */ | 
| Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 151 | 	I915_WRITE_START(ring, obj->gtt_offset); | 
| Daniel Vetter | 570ef60 | 2010-08-02 17:06:23 +0200 | [diff] [blame] | 152 | 	head = I915_READ_HEAD(ring) & HEAD_ADDR; | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 153 |  | 
 | 154 | 	/* G45 ring initialization fails to reset head to zero */ | 
 | 155 | 	if (head != 0) { | 
 | 156 | 		DRM_ERROR("%s head not reset to zero " | 
 | 157 | 				"ctl %08x head %08x tail %08x start %08x\n", | 
 | 158 | 				ring->name, | 
| Daniel Vetter | 7f2ab69 | 2010-08-02 17:06:59 +0200 | [diff] [blame] | 159 | 				I915_READ_CTL(ring), | 
| Daniel Vetter | 570ef60 | 2010-08-02 17:06:23 +0200 | [diff] [blame] | 160 | 				I915_READ_HEAD(ring), | 
| Daniel Vetter | 870e86d | 2010-08-02 16:29:44 +0200 | [diff] [blame] | 161 | 				I915_READ_TAIL(ring), | 
| Daniel Vetter | 6c0e1c5 | 2010-08-02 16:33:33 +0200 | [diff] [blame] | 162 | 				I915_READ_START(ring)); | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 163 |  | 
| Daniel Vetter | 570ef60 | 2010-08-02 17:06:23 +0200 | [diff] [blame] | 164 | 		I915_WRITE_HEAD(ring, 0); | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 165 |  | 
 | 166 | 		DRM_ERROR("%s head forced to zero " | 
 | 167 | 				"ctl %08x head %08x tail %08x start %08x\n", | 
 | 168 | 				ring->name, | 
| Daniel Vetter | 7f2ab69 | 2010-08-02 17:06:59 +0200 | [diff] [blame] | 169 | 				I915_READ_CTL(ring), | 
| Daniel Vetter | 570ef60 | 2010-08-02 17:06:23 +0200 | [diff] [blame] | 170 | 				I915_READ_HEAD(ring), | 
| Daniel Vetter | 870e86d | 2010-08-02 16:29:44 +0200 | [diff] [blame] | 171 | 				I915_READ_TAIL(ring), | 
| Daniel Vetter | 6c0e1c5 | 2010-08-02 16:33:33 +0200 | [diff] [blame] | 172 | 				I915_READ_START(ring)); | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 173 | 	} | 
 | 174 |  | 
| Daniel Vetter | 7f2ab69 | 2010-08-02 17:06:59 +0200 | [diff] [blame] | 175 | 	I915_WRITE_CTL(ring, | 
| Chris Wilson | ae69b42 | 2010-11-07 11:45:52 +0000 | [diff] [blame] | 176 | 			((ring->size - PAGE_SIZE) & RING_NR_PAGES) | 
| Chris Wilson | 6aa5606 | 2010-10-29 21:44:37 +0100 | [diff] [blame] | 177 | 			| RING_REPORT_64K | RING_VALID); | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 178 |  | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 179 | 	/* If the head is still not zero, the ring is dead */ | 
| Chris Wilson | 176f28e | 2010-10-28 11:18:07 +0100 | [diff] [blame] | 180 | 	if ((I915_READ_CTL(ring) & RING_VALID) == 0 || | 
| Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 181 | 	    I915_READ_START(ring) != obj->gtt_offset || | 
| Chris Wilson | 176f28e | 2010-10-28 11:18:07 +0100 | [diff] [blame] | 182 | 	    (I915_READ_HEAD(ring) & HEAD_ADDR) != 0) { | 
| Chris Wilson | e74cfed | 2010-11-09 10:16:56 +0000 | [diff] [blame] | 183 | 		DRM_ERROR("%s initialization failed " | 
 | 184 | 				"ctl %08x head %08x tail %08x start %08x\n", | 
 | 185 | 				ring->name, | 
 | 186 | 				I915_READ_CTL(ring), | 
 | 187 | 				I915_READ_HEAD(ring), | 
 | 188 | 				I915_READ_TAIL(ring), | 
 | 189 | 				I915_READ_START(ring)); | 
 | 190 | 		return -EIO; | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 191 | 	} | 
 | 192 |  | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 193 | 	if (!drm_core_check_feature(ring->dev, DRIVER_MODESET)) | 
 | 194 | 		i915_kernel_lost_context(ring->dev); | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 195 | 	else { | 
| Daniel Vetter | 570ef60 | 2010-08-02 17:06:23 +0200 | [diff] [blame] | 196 | 		ring->head = I915_READ_HEAD(ring) & HEAD_ADDR; | 
| Daniel Vetter | 870e86d | 2010-08-02 16:29:44 +0200 | [diff] [blame] | 197 | 		ring->tail = I915_READ_TAIL(ring) & TAIL_ADDR; | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 198 | 		ring->space = ring->head - (ring->tail + 8); | 
 | 199 | 		if (ring->space < 0) | 
 | 200 | 			ring->space += ring->size; | 
 | 201 | 	} | 
 | 202 | 	return 0; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 203 | } | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 204 |  | 
| Chris Wilson | b6913e4 | 2010-11-12 10:46:37 +0000 | [diff] [blame^] | 205 | /* | 
 | 206 |  * 965+ support PIPE_CONTROL commands, which provide finer grained control | 
 | 207 |  * over cache flushing. | 
 | 208 |  */ | 
 | 209 | struct pipe_control { | 
 | 210 | 	struct drm_i915_gem_object *obj; | 
 | 211 | 	volatile u32 *cpu_page; | 
 | 212 | 	u32 gtt_offset; | 
 | 213 | }; | 
 | 214 |  | 
 | 215 | static int | 
 | 216 | init_pipe_control(struct intel_ring_buffer *ring) | 
 | 217 | { | 
 | 218 | 	struct pipe_control *pc; | 
 | 219 | 	struct drm_i915_gem_object *obj; | 
 | 220 | 	int ret; | 
 | 221 |  | 
 | 222 | 	if (ring->private) | 
 | 223 | 		return 0; | 
 | 224 |  | 
 | 225 | 	pc = kmalloc(sizeof(*pc), GFP_KERNEL); | 
 | 226 | 	if (!pc) | 
 | 227 | 		return -ENOMEM; | 
 | 228 |  | 
 | 229 | 	obj = i915_gem_alloc_object(ring->dev, 4096); | 
 | 230 | 	if (obj == NULL) { | 
 | 231 | 		DRM_ERROR("Failed to allocate seqno page\n"); | 
 | 232 | 		ret = -ENOMEM; | 
 | 233 | 		goto err; | 
 | 234 | 	} | 
 | 235 | 	obj->agp_type = AGP_USER_CACHED_MEMORY; | 
 | 236 |  | 
 | 237 | 	ret = i915_gem_object_pin(obj, 4096, true); | 
 | 238 | 	if (ret) | 
 | 239 | 		goto err_unref; | 
 | 240 |  | 
 | 241 | 	pc->gtt_offset = obj->gtt_offset; | 
 | 242 | 	pc->cpu_page =  kmap(obj->pages[0]); | 
 | 243 | 	if (pc->cpu_page == NULL) | 
 | 244 | 		goto err_unpin; | 
 | 245 |  | 
 | 246 | 	pc->obj = obj; | 
 | 247 | 	ring->private = pc; | 
 | 248 | 	return 0; | 
 | 249 |  | 
 | 250 | err_unpin: | 
 | 251 | 	i915_gem_object_unpin(obj); | 
 | 252 | err_unref: | 
 | 253 | 	drm_gem_object_unreference(&obj->base); | 
 | 254 | err: | 
 | 255 | 	kfree(pc); | 
 | 256 | 	return ret; | 
 | 257 | } | 
 | 258 |  | 
 | 259 | static void | 
 | 260 | cleanup_pipe_control(struct intel_ring_buffer *ring) | 
 | 261 | { | 
 | 262 | 	struct pipe_control *pc = ring->private; | 
 | 263 | 	struct drm_i915_gem_object *obj; | 
 | 264 |  | 
 | 265 | 	if (!ring->private) | 
 | 266 | 		return; | 
 | 267 |  | 
 | 268 | 	obj = pc->obj; | 
 | 269 | 	kunmap(obj->pages[0]); | 
 | 270 | 	i915_gem_object_unpin(obj); | 
 | 271 | 	drm_gem_object_unreference(&obj->base); | 
 | 272 |  | 
 | 273 | 	kfree(pc); | 
 | 274 | 	ring->private = NULL; | 
 | 275 | } | 
 | 276 |  | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 277 | static int init_render_ring(struct intel_ring_buffer *ring) | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 278 | { | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 279 | 	struct drm_device *dev = ring->dev; | 
 | 280 | 	int ret = init_ring_common(ring); | 
| Zhenyu Wang | a69ffdb | 2010-08-30 16:12:42 +0800 | [diff] [blame] | 281 |  | 
| Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 282 | 	if (INTEL_INFO(dev)->gen > 3) { | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 283 | 		drm_i915_private_t *dev_priv = dev->dev_private; | 
 | 284 | 		int mode = VS_TIMER_DISPATCH << 16 | VS_TIMER_DISPATCH; | 
| Zhenyu Wang | a69ffdb | 2010-08-30 16:12:42 +0800 | [diff] [blame] | 285 | 		if (IS_GEN6(dev)) | 
 | 286 | 			mode |= MI_FLUSH_ENABLE << 16 | MI_FLUSH_ENABLE; | 
 | 287 | 		I915_WRITE(MI_MODE, mode); | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 288 | 	} | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 289 |  | 
| Chris Wilson | b6913e4 | 2010-11-12 10:46:37 +0000 | [diff] [blame^] | 290 | 	if (HAS_PIPE_CONTROL(dev)) { | 
 | 291 | 		ret = init_pipe_control(ring); | 
 | 292 | 		if (ret) | 
 | 293 | 			return ret; | 
 | 294 | 	} | 
 | 295 |  | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 296 | 	return ret; | 
 | 297 | } | 
 | 298 |  | 
| Chris Wilson | b6913e4 | 2010-11-12 10:46:37 +0000 | [diff] [blame^] | 299 | static void render_ring_cleanup(struct intel_ring_buffer *ring) | 
 | 300 | { | 
 | 301 | 	if (!ring->private) | 
 | 302 | 		return; | 
 | 303 |  | 
 | 304 | 	cleanup_pipe_control(ring); | 
 | 305 | } | 
 | 306 |  | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 307 | #define PIPE_CONTROL_FLUSH(ring__, addr__)					\ | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 308 | do {									\ | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 309 | 	intel_ring_emit(ring__, GFX_OP_PIPE_CONTROL | PIPE_CONTROL_QW_WRITE |		\ | 
| Zhenyu Wang | ca76482 | 2010-05-27 10:26:42 +0800 | [diff] [blame] | 310 | 		 PIPE_CONTROL_DEPTH_STALL | 2);				\ | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 311 | 	intel_ring_emit(ring__, (addr__) | PIPE_CONTROL_GLOBAL_GTT);			\ | 
 | 312 | 	intel_ring_emit(ring__, 0);							\ | 
 | 313 | 	intel_ring_emit(ring__, 0);							\ | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 314 | } while (0) | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 315 |  | 
 | 316 | /** | 
 | 317 |  * Creates a new sequence number, emitting a write of it to the status page | 
 | 318 |  * plus an interrupt, which will trigger i915_user_interrupt_handler. | 
 | 319 |  * | 
 | 320 |  * Must be called with struct_lock held. | 
 | 321 |  * | 
 | 322 |  * Returned sequence numbers are nonzero on success. | 
 | 323 |  */ | 
| Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 324 | static int | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 325 | render_ring_add_request(struct intel_ring_buffer *ring, | 
| Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 326 | 			u32 *result) | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 327 | { | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 328 | 	struct drm_device *dev = ring->dev; | 
| Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 329 | 	u32 seqno = i915_gem_get_seqno(dev); | 
| Chris Wilson | b6913e4 | 2010-11-12 10:46:37 +0000 | [diff] [blame^] | 330 | 	struct pipe_control *pc = ring->private; | 
| Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 331 | 	int ret; | 
| Zhenyu Wang | ca76482 | 2010-05-27 10:26:42 +0800 | [diff] [blame] | 332 |  | 
 | 333 | 	if (IS_GEN6(dev)) { | 
| Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 334 | 		ret = intel_ring_begin(ring, 6); | 
 | 335 | 		if (ret) | 
 | 336 | 		    return ret; | 
 | 337 |  | 
 | 338 | 		intel_ring_emit(ring, GFX_OP_PIPE_CONTROL | 3); | 
 | 339 | 		intel_ring_emit(ring, PIPE_CONTROL_QW_WRITE | | 
 | 340 | 				PIPE_CONTROL_WC_FLUSH | PIPE_CONTROL_IS_FLUSH | | 
 | 341 | 				PIPE_CONTROL_NOTIFY); | 
| Chris Wilson | b6913e4 | 2010-11-12 10:46:37 +0000 | [diff] [blame^] | 342 | 		intel_ring_emit(ring, pc->gtt_offset | PIPE_CONTROL_GLOBAL_GTT); | 
| Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 343 | 		intel_ring_emit(ring, seqno); | 
 | 344 | 		intel_ring_emit(ring, 0); | 
 | 345 | 		intel_ring_emit(ring, 0); | 
| Zhenyu Wang | ca76482 | 2010-05-27 10:26:42 +0800 | [diff] [blame] | 346 | 	} else if (HAS_PIPE_CONTROL(dev)) { | 
| Chris Wilson | b6913e4 | 2010-11-12 10:46:37 +0000 | [diff] [blame^] | 347 | 		u32 scratch_addr = pc->gtt_offset + 128; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 348 |  | 
 | 349 | 		/* | 
 | 350 | 		 * Workaround qword write incoherence by flushing the | 
 | 351 | 		 * PIPE_NOTIFY buffers out to memory before requesting | 
 | 352 | 		 * an interrupt. | 
 | 353 | 		 */ | 
| Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 354 | 		ret = intel_ring_begin(ring, 32); | 
 | 355 | 		if (ret) | 
 | 356 | 			return ret; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 357 |  | 
| Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 358 | 		intel_ring_emit(ring, GFX_OP_PIPE_CONTROL | PIPE_CONTROL_QW_WRITE | | 
 | 359 | 				PIPE_CONTROL_WC_FLUSH | PIPE_CONTROL_TC_FLUSH); | 
| Chris Wilson | b6913e4 | 2010-11-12 10:46:37 +0000 | [diff] [blame^] | 360 | 		intel_ring_emit(ring, pc->gtt_offset | PIPE_CONTROL_GLOBAL_GTT); | 
| Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 361 | 		intel_ring_emit(ring, seqno); | 
 | 362 | 		intel_ring_emit(ring, 0); | 
 | 363 | 		PIPE_CONTROL_FLUSH(ring, scratch_addr); | 
 | 364 | 		scratch_addr += 128; /* write to separate cachelines */ | 
 | 365 | 		PIPE_CONTROL_FLUSH(ring, scratch_addr); | 
 | 366 | 		scratch_addr += 128; | 
 | 367 | 		PIPE_CONTROL_FLUSH(ring, scratch_addr); | 
 | 368 | 		scratch_addr += 128; | 
 | 369 | 		PIPE_CONTROL_FLUSH(ring, scratch_addr); | 
 | 370 | 		scratch_addr += 128; | 
 | 371 | 		PIPE_CONTROL_FLUSH(ring, scratch_addr); | 
 | 372 | 		scratch_addr += 128; | 
 | 373 | 		PIPE_CONTROL_FLUSH(ring, scratch_addr); | 
 | 374 | 		intel_ring_emit(ring, GFX_OP_PIPE_CONTROL | PIPE_CONTROL_QW_WRITE | | 
 | 375 | 				PIPE_CONTROL_WC_FLUSH | PIPE_CONTROL_TC_FLUSH | | 
 | 376 | 				PIPE_CONTROL_NOTIFY); | 
| Chris Wilson | b6913e4 | 2010-11-12 10:46:37 +0000 | [diff] [blame^] | 377 | 		intel_ring_emit(ring, pc->gtt_offset | PIPE_CONTROL_GLOBAL_GTT); | 
| Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 378 | 		intel_ring_emit(ring, seqno); | 
 | 379 | 		intel_ring_emit(ring, 0); | 
 | 380 | 	} else { | 
 | 381 | 		ret = intel_ring_begin(ring, 4); | 
 | 382 | 		if (ret) | 
 | 383 | 		    return ret; | 
 | 384 |  | 
 | 385 | 		intel_ring_emit(ring, MI_STORE_DWORD_INDEX); | 
 | 386 | 		intel_ring_emit(ring, I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT); | 
 | 387 | 		intel_ring_emit(ring, seqno); | 
 | 388 |  | 
 | 389 | 		intel_ring_emit(ring, MI_USER_INTERRUPT); | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 390 | 	} | 
| Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 391 |  | 
 | 392 | 	intel_ring_advance(ring); | 
 | 393 | 	*result = seqno; | 
 | 394 | 	return 0; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 395 | } | 
 | 396 |  | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 397 | static u32 | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 398 | render_ring_get_seqno(struct intel_ring_buffer *ring) | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 399 | { | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 400 | 	struct drm_device *dev = ring->dev; | 
| Chris Wilson | b6913e4 | 2010-11-12 10:46:37 +0000 | [diff] [blame^] | 401 | 	if (HAS_PIPE_CONTROL(dev)) { | 
 | 402 | 		struct pipe_control *pc = ring->private; | 
 | 403 | 		return pc->cpu_page[0]; | 
 | 404 | 	} else | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 405 | 		return intel_read_status_page(ring, I915_GEM_HWS_INDEX); | 
 | 406 | } | 
 | 407 |  | 
 | 408 | static void | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 409 | render_ring_get_user_irq(struct intel_ring_buffer *ring) | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 410 | { | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 411 | 	struct drm_device *dev = ring->dev; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 412 | 	drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | 
 | 413 | 	unsigned long irqflags; | 
 | 414 |  | 
 | 415 | 	spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 416 | 	if (dev->irq_enabled && (++ring->user_irq_refcount == 1)) { | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 417 | 		if (HAS_PCH_SPLIT(dev)) | 
 | 418 | 			ironlake_enable_graphics_irq(dev_priv, GT_PIPE_NOTIFY); | 
 | 419 | 		else | 
 | 420 | 			i915_enable_irq(dev_priv, I915_USER_INTERRUPT); | 
 | 421 | 	} | 
 | 422 | 	spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags); | 
 | 423 | } | 
 | 424 |  | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 425 | static void | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 426 | render_ring_put_user_irq(struct intel_ring_buffer *ring) | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 427 | { | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 428 | 	struct drm_device *dev = ring->dev; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 429 | 	drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | 
 | 430 | 	unsigned long irqflags; | 
 | 431 |  | 
 | 432 | 	spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 433 | 	BUG_ON(dev->irq_enabled && ring->user_irq_refcount <= 0); | 
 | 434 | 	if (dev->irq_enabled && (--ring->user_irq_refcount == 0)) { | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 435 | 		if (HAS_PCH_SPLIT(dev)) | 
 | 436 | 			ironlake_disable_graphics_irq(dev_priv, GT_PIPE_NOTIFY); | 
 | 437 | 		else | 
 | 438 | 			i915_disable_irq(dev_priv, I915_USER_INTERRUPT); | 
 | 439 | 	} | 
 | 440 | 	spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags); | 
 | 441 | } | 
 | 442 |  | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 443 | void intel_ring_setup_status_page(struct intel_ring_buffer *ring) | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 444 | { | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 445 | 	drm_i915_private_t *dev_priv = ring->dev->dev_private; | 
 | 446 | 	u32 mmio = IS_GEN6(ring->dev) ? | 
 | 447 | 		RING_HWS_PGA_GEN6(ring->mmio_base) : | 
 | 448 | 		RING_HWS_PGA(ring->mmio_base); | 
 | 449 | 	I915_WRITE(mmio, (u32)ring->status_page.gfx_addr); | 
 | 450 | 	POSTING_READ(mmio); | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 451 | } | 
 | 452 |  | 
| Chris Wilson | ab6f8e3 | 2010-09-19 17:53:44 +0100 | [diff] [blame] | 453 | static void | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 454 | bsd_ring_flush(struct intel_ring_buffer *ring, | 
 | 455 | 	       u32     invalidate_domains, | 
 | 456 | 	       u32     flush_domains) | 
| Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 457 | { | 
| Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 458 | 	if (intel_ring_begin(ring, 2) == 0) { | 
 | 459 | 		intel_ring_emit(ring, MI_FLUSH); | 
 | 460 | 		intel_ring_emit(ring, MI_NOOP); | 
 | 461 | 		intel_ring_advance(ring); | 
 | 462 | 	} | 
| Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 463 | } | 
 | 464 |  | 
| Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 465 | static int | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 466 | ring_add_request(struct intel_ring_buffer *ring, | 
| Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 467 | 		 u32 *result) | 
| Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 468 | { | 
 | 469 | 	u32 seqno; | 
| Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 470 | 	int ret; | 
 | 471 |  | 
 | 472 | 	ret = intel_ring_begin(ring, 4); | 
 | 473 | 	if (ret) | 
 | 474 | 		return ret; | 
| Chris Wilson | 6f392d5 | 2010-08-07 11:01:22 +0100 | [diff] [blame] | 475 |  | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 476 | 	seqno = i915_gem_get_seqno(ring->dev); | 
| Chris Wilson | 6f392d5 | 2010-08-07 11:01:22 +0100 | [diff] [blame] | 477 |  | 
| Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 478 | 	intel_ring_emit(ring, MI_STORE_DWORD_INDEX); | 
 | 479 | 	intel_ring_emit(ring, I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT); | 
 | 480 | 	intel_ring_emit(ring, seqno); | 
 | 481 | 	intel_ring_emit(ring, MI_USER_INTERRUPT); | 
 | 482 | 	intel_ring_advance(ring); | 
| Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 483 |  | 
 | 484 | 	DRM_DEBUG_DRIVER("%s %d\n", ring->name, seqno); | 
| Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 485 | 	*result = seqno; | 
 | 486 | 	return 0; | 
| Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 487 | } | 
 | 488 |  | 
| Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 489 | static void | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 490 | bsd_ring_get_user_irq(struct intel_ring_buffer *ring) | 
| Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 491 | { | 
 | 492 | 	/* do nothing */ | 
 | 493 | } | 
 | 494 | static void | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 495 | bsd_ring_put_user_irq(struct intel_ring_buffer *ring) | 
| Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 496 | { | 
 | 497 | 	/* do nothing */ | 
 | 498 | } | 
 | 499 |  | 
 | 500 | static u32 | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 501 | ring_status_page_get_seqno(struct intel_ring_buffer *ring) | 
| Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 502 | { | 
 | 503 | 	return intel_read_status_page(ring, I915_GEM_HWS_INDEX); | 
 | 504 | } | 
 | 505 |  | 
 | 506 | static int | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 507 | ring_dispatch_execbuffer(struct intel_ring_buffer *ring, | 
 | 508 | 			 struct drm_i915_gem_execbuffer2 *exec, | 
 | 509 | 			 struct drm_clip_rect *cliprects, | 
 | 510 | 			 uint64_t exec_offset) | 
| Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 511 | { | 
 | 512 | 	uint32_t exec_start; | 
| Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 513 | 	int ret; | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 514 |  | 
| Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 515 | 	exec_start = (uint32_t) exec_offset + exec->batch_start_offset; | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 516 |  | 
| Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 517 | 	ret = intel_ring_begin(ring, 2); | 
 | 518 | 	if (ret) | 
 | 519 | 		return ret; | 
 | 520 |  | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 521 | 	intel_ring_emit(ring, | 
 | 522 | 			MI_BATCH_BUFFER_START | | 
 | 523 | 			(2 << 6) | | 
 | 524 | 			MI_BATCH_NON_SECURE_I965); | 
 | 525 | 	intel_ring_emit(ring, exec_start); | 
 | 526 | 	intel_ring_advance(ring); | 
 | 527 |  | 
| Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 528 | 	return 0; | 
 | 529 | } | 
 | 530 |  | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 531 | static int | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 532 | render_ring_dispatch_execbuffer(struct intel_ring_buffer *ring, | 
 | 533 | 				struct drm_i915_gem_execbuffer2 *exec, | 
 | 534 | 				struct drm_clip_rect *cliprects, | 
 | 535 | 				uint64_t exec_offset) | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 536 | { | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 537 | 	struct drm_device *dev = ring->dev; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 538 | 	drm_i915_private_t *dev_priv = dev->dev_private; | 
 | 539 | 	int nbox = exec->num_cliprects; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 540 | 	uint32_t exec_start, exec_len; | 
| Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 541 | 	int i, count, ret; | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 542 |  | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 543 | 	exec_start = (uint32_t) exec_offset + exec->batch_start_offset; | 
 | 544 | 	exec_len = (uint32_t) exec->batch_len; | 
 | 545 |  | 
| Chris Wilson | 6f392d5 | 2010-08-07 11:01:22 +0100 | [diff] [blame] | 546 | 	trace_i915_gem_request_submit(dev, dev_priv->next_seqno + 1); | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 547 |  | 
 | 548 | 	count = nbox ? nbox : 1; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 549 | 	for (i = 0; i < count; i++) { | 
 | 550 | 		if (i < nbox) { | 
| Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 551 | 			ret = i915_emit_box(dev, cliprects, i, | 
 | 552 | 					    exec->DR1, exec->DR4); | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 553 | 			if (ret) | 
 | 554 | 				return ret; | 
 | 555 | 		} | 
 | 556 |  | 
 | 557 | 		if (IS_I830(dev) || IS_845G(dev)) { | 
| Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 558 | 			ret = intel_ring_begin(ring, 4); | 
 | 559 | 			if (ret) | 
 | 560 | 				return ret; | 
 | 561 |  | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 562 | 			intel_ring_emit(ring, MI_BATCH_BUFFER); | 
 | 563 | 			intel_ring_emit(ring, exec_start | MI_BATCH_NON_SECURE); | 
 | 564 | 			intel_ring_emit(ring, exec_start + exec_len - 4); | 
 | 565 | 			intel_ring_emit(ring, 0); | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 566 | 		} else { | 
| Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 567 | 			ret = intel_ring_begin(ring, 2); | 
 | 568 | 			if (ret) | 
 | 569 | 				return ret; | 
 | 570 |  | 
| Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 571 | 			if (INTEL_INFO(dev)->gen >= 4) { | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 572 | 				intel_ring_emit(ring, | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 573 | 						MI_BATCH_BUFFER_START | (2 << 6) | 
 | 574 | 						| MI_BATCH_NON_SECURE_I965); | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 575 | 				intel_ring_emit(ring, exec_start); | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 576 | 			} else { | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 577 | 				intel_ring_emit(ring, MI_BATCH_BUFFER_START | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 578 | 						| (2 << 6)); | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 579 | 				intel_ring_emit(ring, exec_start | | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 580 | 						MI_BATCH_NON_SECURE); | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 581 | 			} | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 582 | 		} | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 583 | 		intel_ring_advance(ring); | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 584 | 	} | 
 | 585 |  | 
| Chris Wilson | f00a3dd | 2010-10-21 14:57:17 +0100 | [diff] [blame] | 586 | 	if (IS_G4X(dev) || IS_GEN5(dev)) { | 
| Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 587 | 		if (intel_ring_begin(ring, 2) == 0) { | 
 | 588 | 			intel_ring_emit(ring, MI_FLUSH | | 
 | 589 | 					MI_NO_WRITE_FLUSH | | 
 | 590 | 					MI_INVALIDATE_ISP ); | 
 | 591 | 			intel_ring_emit(ring, MI_NOOP); | 
 | 592 | 			intel_ring_advance(ring); | 
 | 593 | 		} | 
| Zou Nan hai | 1cafd34 | 2010-06-25 13:40:24 +0800 | [diff] [blame] | 594 | 	} | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 595 | 	/* XXX breadcrumb */ | 
| Zou Nan hai | 1cafd34 | 2010-06-25 13:40:24 +0800 | [diff] [blame] | 596 |  | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 597 | 	return 0; | 
 | 598 | } | 
 | 599 |  | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 600 | static void cleanup_status_page(struct intel_ring_buffer *ring) | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 601 | { | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 602 | 	drm_i915_private_t *dev_priv = ring->dev->dev_private; | 
| Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 603 | 	struct drm_i915_gem_object *obj; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 604 |  | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 605 | 	obj = ring->status_page.obj; | 
 | 606 | 	if (obj == NULL) | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 607 | 		return; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 608 |  | 
| Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 609 | 	kunmap(obj->pages[0]); | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 610 | 	i915_gem_object_unpin(obj); | 
| Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 611 | 	drm_gem_object_unreference(&obj->base); | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 612 | 	ring->status_page.obj = NULL; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 613 |  | 
 | 614 | 	memset(&dev_priv->hws_map, 0, sizeof(dev_priv->hws_map)); | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 615 | } | 
 | 616 |  | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 617 | static int init_status_page(struct intel_ring_buffer *ring) | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 618 | { | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 619 | 	struct drm_device *dev = ring->dev; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 620 | 	drm_i915_private_t *dev_priv = dev->dev_private; | 
| Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 621 | 	struct drm_i915_gem_object *obj; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 622 | 	int ret; | 
 | 623 |  | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 624 | 	obj = i915_gem_alloc_object(dev, 4096); | 
 | 625 | 	if (obj == NULL) { | 
 | 626 | 		DRM_ERROR("Failed to allocate status page\n"); | 
 | 627 | 		ret = -ENOMEM; | 
 | 628 | 		goto err; | 
 | 629 | 	} | 
| Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 630 | 	obj->agp_type = AGP_USER_CACHED_MEMORY; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 631 |  | 
| Daniel Vetter | 75e9e91 | 2010-11-04 17:11:09 +0100 | [diff] [blame] | 632 | 	ret = i915_gem_object_pin(obj, 4096, true); | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 633 | 	if (ret != 0) { | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 634 | 		goto err_unref; | 
 | 635 | 	} | 
 | 636 |  | 
| Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 637 | 	ring->status_page.gfx_addr = obj->gtt_offset; | 
 | 638 | 	ring->status_page.page_addr = kmap(obj->pages[0]); | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 639 | 	if (ring->status_page.page_addr == NULL) { | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 640 | 		memset(&dev_priv->hws_map, 0, sizeof(dev_priv->hws_map)); | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 641 | 		goto err_unpin; | 
 | 642 | 	} | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 643 | 	ring->status_page.obj = obj; | 
 | 644 | 	memset(ring->status_page.page_addr, 0, PAGE_SIZE); | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 645 |  | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 646 | 	intel_ring_setup_status_page(ring); | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 647 | 	DRM_DEBUG_DRIVER("%s hws offset: 0x%08x\n", | 
 | 648 | 			ring->name, ring->status_page.gfx_addr); | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 649 |  | 
 | 650 | 	return 0; | 
 | 651 |  | 
 | 652 | err_unpin: | 
 | 653 | 	i915_gem_object_unpin(obj); | 
 | 654 | err_unref: | 
| Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 655 | 	drm_gem_object_unreference(&obj->base); | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 656 | err: | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 657 | 	return ret; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 658 | } | 
 | 659 |  | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 660 | int intel_init_ring_buffer(struct drm_device *dev, | 
| Chris Wilson | ab6f8e3 | 2010-09-19 17:53:44 +0100 | [diff] [blame] | 661 | 			   struct intel_ring_buffer *ring) | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 662 | { | 
| Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 663 | 	struct drm_i915_gem_object *obj; | 
| Chris Wilson | dd785e3 | 2010-08-07 11:01:34 +0100 | [diff] [blame] | 664 | 	int ret; | 
 | 665 |  | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 666 | 	ring->dev = dev; | 
| Chris Wilson | 23bc598 | 2010-09-29 16:10:57 +0100 | [diff] [blame] | 667 | 	INIT_LIST_HEAD(&ring->active_list); | 
 | 668 | 	INIT_LIST_HEAD(&ring->request_list); | 
| Chris Wilson | 6419340 | 2010-10-24 12:38:05 +0100 | [diff] [blame] | 669 | 	INIT_LIST_HEAD(&ring->gpu_write_list); | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 670 |  | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 671 | 	if (I915_NEED_GFX_HWS(dev)) { | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 672 | 		ret = init_status_page(ring); | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 673 | 		if (ret) | 
 | 674 | 			return ret; | 
 | 675 | 	} | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 676 |  | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 677 | 	obj = i915_gem_alloc_object(dev, ring->size); | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 678 | 	if (obj == NULL) { | 
 | 679 | 		DRM_ERROR("Failed to allocate ringbuffer\n"); | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 680 | 		ret = -ENOMEM; | 
| Chris Wilson | dd785e3 | 2010-08-07 11:01:34 +0100 | [diff] [blame] | 681 | 		goto err_hws; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 682 | 	} | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 683 |  | 
| Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 684 | 	ring->obj = obj; | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 685 |  | 
| Daniel Vetter | 75e9e91 | 2010-11-04 17:11:09 +0100 | [diff] [blame] | 686 | 	ret = i915_gem_object_pin(obj, PAGE_SIZE, true); | 
| Chris Wilson | dd785e3 | 2010-08-07 11:01:34 +0100 | [diff] [blame] | 687 | 	if (ret) | 
 | 688 | 		goto err_unref; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 689 |  | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 690 | 	ring->map.size = ring->size; | 
| Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 691 | 	ring->map.offset = dev->agp->base + obj->gtt_offset; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 692 | 	ring->map.type = 0; | 
 | 693 | 	ring->map.flags = 0; | 
 | 694 | 	ring->map.mtrr = 0; | 
 | 695 |  | 
 | 696 | 	drm_core_ioremap_wc(&ring->map, dev); | 
 | 697 | 	if (ring->map.handle == NULL) { | 
 | 698 | 		DRM_ERROR("Failed to map ringbuffer.\n"); | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 699 | 		ret = -EINVAL; | 
| Chris Wilson | dd785e3 | 2010-08-07 11:01:34 +0100 | [diff] [blame] | 700 | 		goto err_unpin; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 701 | 	} | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 702 |  | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 703 | 	ring->virtual_start = ring->map.handle; | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 704 | 	ret = ring->init(ring); | 
| Chris Wilson | dd785e3 | 2010-08-07 11:01:34 +0100 | [diff] [blame] | 705 | 	if (ret) | 
 | 706 | 		goto err_unmap; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 707 |  | 
| Chris Wilson | c584fe4 | 2010-10-29 18:15:52 +0100 | [diff] [blame] | 708 | 	return 0; | 
| Chris Wilson | dd785e3 | 2010-08-07 11:01:34 +0100 | [diff] [blame] | 709 |  | 
 | 710 | err_unmap: | 
 | 711 | 	drm_core_ioremapfree(&ring->map, dev); | 
 | 712 | err_unpin: | 
 | 713 | 	i915_gem_object_unpin(obj); | 
 | 714 | err_unref: | 
| Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 715 | 	drm_gem_object_unreference(&obj->base); | 
 | 716 | 	ring->obj = NULL; | 
| Chris Wilson | dd785e3 | 2010-08-07 11:01:34 +0100 | [diff] [blame] | 717 | err_hws: | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 718 | 	cleanup_status_page(ring); | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 719 | 	return ret; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 720 | } | 
 | 721 |  | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 722 | void intel_cleanup_ring_buffer(struct intel_ring_buffer *ring) | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 723 | { | 
| Chris Wilson | 33626e6 | 2010-10-29 16:18:36 +0100 | [diff] [blame] | 724 | 	struct drm_i915_private *dev_priv; | 
 | 725 | 	int ret; | 
 | 726 |  | 
| Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 727 | 	if (ring->obj == NULL) | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 728 | 		return; | 
 | 729 |  | 
| Chris Wilson | 33626e6 | 2010-10-29 16:18:36 +0100 | [diff] [blame] | 730 | 	/* Disable the ring buffer. The ring must be idle at this point */ | 
 | 731 | 	dev_priv = ring->dev->dev_private; | 
 | 732 | 	ret = intel_wait_ring_buffer(ring, ring->size - 8); | 
 | 733 | 	I915_WRITE_CTL(ring, 0); | 
 | 734 |  | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 735 | 	drm_core_ioremapfree(&ring->map, ring->dev); | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 736 |  | 
| Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 737 | 	i915_gem_object_unpin(ring->obj); | 
 | 738 | 	drm_gem_object_unreference(&ring->obj->base); | 
 | 739 | 	ring->obj = NULL; | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 740 |  | 
| Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 741 | 	if (ring->cleanup) | 
 | 742 | 		ring->cleanup(ring); | 
 | 743 |  | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 744 | 	cleanup_status_page(ring); | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 745 | } | 
 | 746 |  | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 747 | static int intel_wrap_ring_buffer(struct intel_ring_buffer *ring) | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 748 | { | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 749 | 	unsigned int *virt; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 750 | 	int rem; | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 751 | 	rem = ring->size - ring->tail; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 752 |  | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 753 | 	if (ring->space < rem) { | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 754 | 		int ret = intel_wait_ring_buffer(ring, rem); | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 755 | 		if (ret) | 
 | 756 | 			return ret; | 
 | 757 | 	} | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 758 |  | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 759 | 	virt = (unsigned int *)(ring->virtual_start + ring->tail); | 
| Chris Wilson | 1741dd4 | 2010-08-04 15:18:12 +0100 | [diff] [blame] | 760 | 	rem /= 8; | 
 | 761 | 	while (rem--) { | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 762 | 		*virt++ = MI_NOOP; | 
| Chris Wilson | 1741dd4 | 2010-08-04 15:18:12 +0100 | [diff] [blame] | 763 | 		*virt++ = MI_NOOP; | 
 | 764 | 	} | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 765 |  | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 766 | 	ring->tail = 0; | 
| Chris Wilson | 43ed340 | 2010-07-01 17:53:00 +0100 | [diff] [blame] | 767 | 	ring->space = ring->head - 8; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 768 |  | 
 | 769 | 	return 0; | 
 | 770 | } | 
 | 771 |  | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 772 | int intel_wait_ring_buffer(struct intel_ring_buffer *ring, int n) | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 773 | { | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 774 | 	struct drm_device *dev = ring->dev; | 
| Zou Nan hai | cae5852 | 2010-11-09 17:17:32 +0800 | [diff] [blame] | 775 | 	struct drm_i915_private *dev_priv = dev->dev_private; | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 776 | 	unsigned long end; | 
| Chris Wilson | 6aa5606 | 2010-10-29 21:44:37 +0100 | [diff] [blame] | 777 | 	u32 head; | 
 | 778 |  | 
 | 779 | 	head = intel_read_status_page(ring, 4); | 
 | 780 | 	if (head) { | 
 | 781 | 		ring->head = head & HEAD_ADDR; | 
 | 782 | 		ring->space = ring->head - (ring->tail + 8); | 
 | 783 | 		if (ring->space < 0) | 
 | 784 | 			ring->space += ring->size; | 
 | 785 | 		if (ring->space >= n) | 
 | 786 | 			return 0; | 
 | 787 | 	} | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 788 |  | 
 | 789 | 	trace_i915_ring_wait_begin (dev); | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 790 | 	end = jiffies + 3 * HZ; | 
 | 791 | 	do { | 
| Daniel Vetter | 570ef60 | 2010-08-02 17:06:23 +0200 | [diff] [blame] | 792 | 		ring->head = I915_READ_HEAD(ring) & HEAD_ADDR; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 793 | 		ring->space = ring->head - (ring->tail + 8); | 
 | 794 | 		if (ring->space < 0) | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 795 | 			ring->space += ring->size; | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 796 | 		if (ring->space >= n) { | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 797 | 			trace_i915_ring_wait_end(dev); | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 798 | 			return 0; | 
 | 799 | 		} | 
 | 800 |  | 
 | 801 | 		if (dev->primary->master) { | 
 | 802 | 			struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; | 
 | 803 | 			if (master_priv->sarea_priv) | 
 | 804 | 				master_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT; | 
 | 805 | 		} | 
| Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 806 |  | 
| Chris Wilson | e60a0b1 | 2010-10-13 10:09:14 +0100 | [diff] [blame] | 807 | 		msleep(1); | 
| Chris Wilson | f4e0b29 | 2010-10-29 21:06:16 +0100 | [diff] [blame] | 808 | 		if (atomic_read(&dev_priv->mm.wedged)) | 
 | 809 | 			return -EAGAIN; | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 810 | 	} while (!time_after(jiffies, end)); | 
| Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 811 | 	trace_i915_ring_wait_end (dev); | 
 | 812 | 	return -EBUSY; | 
 | 813 | } | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 814 |  | 
| Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 815 | int intel_ring_begin(struct intel_ring_buffer *ring, | 
 | 816 | 		     int num_dwords) | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 817 | { | 
| Zou Nan hai | be26a10 | 2010-06-12 17:40:24 +0800 | [diff] [blame] | 818 | 	int n = 4*num_dwords; | 
| Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 819 | 	int ret; | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 820 |  | 
| Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 821 | 	if (unlikely(ring->tail + n > ring->size)) { | 
 | 822 | 		ret = intel_wrap_ring_buffer(ring); | 
 | 823 | 		if (unlikely(ret)) | 
 | 824 | 			return ret; | 
 | 825 | 	} | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 826 |  | 
| Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 827 | 	if (unlikely(ring->space < n)) { | 
 | 828 | 		ret = intel_wait_ring_buffer(ring, n); | 
 | 829 | 		if (unlikely(ret)) | 
 | 830 | 			return ret; | 
 | 831 | 	} | 
| Chris Wilson | d97ed33 | 2010-08-04 15:18:13 +0100 | [diff] [blame] | 832 |  | 
 | 833 | 	ring->space -= n; | 
| Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 834 | 	return 0; | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 835 | } | 
 | 836 |  | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 837 | void intel_ring_advance(struct intel_ring_buffer *ring) | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 838 | { | 
| Chris Wilson | d97ed33 | 2010-08-04 15:18:13 +0100 | [diff] [blame] | 839 | 	ring->tail &= ring->size - 1; | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 840 | 	ring->write_tail(ring, ring->tail); | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 841 | } | 
 | 842 |  | 
| Chris Wilson | e070868 | 2010-09-19 14:46:27 +0100 | [diff] [blame] | 843 | static const struct intel_ring_buffer render_ring = { | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 844 | 	.name			= "render ring", | 
| Chris Wilson | 9220434 | 2010-09-18 11:02:01 +0100 | [diff] [blame] | 845 | 	.id			= RING_RENDER, | 
| Daniel Vetter | 333e9fe | 2010-08-02 16:24:01 +0200 | [diff] [blame] | 846 | 	.mmio_base		= RENDER_RING_BASE, | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 847 | 	.size			= 32 * PAGE_SIZE, | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 848 | 	.init			= init_render_ring, | 
| Chris Wilson | 297b0c5 | 2010-10-22 17:02:41 +0100 | [diff] [blame] | 849 | 	.write_tail		= ring_write_tail, | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 850 | 	.flush			= render_ring_flush, | 
 | 851 | 	.add_request		= render_ring_add_request, | 
| Chris Wilson | f787a5f | 2010-09-24 16:02:42 +0100 | [diff] [blame] | 852 | 	.get_seqno		= render_ring_get_seqno, | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 853 | 	.user_irq_get		= render_ring_get_user_irq, | 
 | 854 | 	.user_irq_put		= render_ring_put_user_irq, | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 855 | 	.dispatch_execbuffer	= render_ring_dispatch_execbuffer, | 
| Chris Wilson | b6913e4 | 2010-11-12 10:46:37 +0000 | [diff] [blame^] | 856 |        .cleanup			= render_ring_cleanup, | 
| Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 857 | }; | 
| Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 858 |  | 
 | 859 | /* ring buffer for bit-stream decoder */ | 
 | 860 |  | 
| Chris Wilson | e070868 | 2010-09-19 14:46:27 +0100 | [diff] [blame] | 861 | static const struct intel_ring_buffer bsd_ring = { | 
| Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 862 | 	.name                   = "bsd ring", | 
| Chris Wilson | 9220434 | 2010-09-18 11:02:01 +0100 | [diff] [blame] | 863 | 	.id			= RING_BSD, | 
| Daniel Vetter | 333e9fe | 2010-08-02 16:24:01 +0200 | [diff] [blame] | 864 | 	.mmio_base		= BSD_RING_BASE, | 
| Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 865 | 	.size			= 32 * PAGE_SIZE, | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 866 | 	.init			= init_ring_common, | 
| Chris Wilson | 297b0c5 | 2010-10-22 17:02:41 +0100 | [diff] [blame] | 867 | 	.write_tail		= ring_write_tail, | 
| Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 868 | 	.flush			= bsd_ring_flush, | 
| Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 869 | 	.add_request		= ring_add_request, | 
 | 870 | 	.get_seqno		= ring_status_page_get_seqno, | 
| Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 871 | 	.user_irq_get		= bsd_ring_get_user_irq, | 
 | 872 | 	.user_irq_put		= bsd_ring_put_user_irq, | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 873 | 	.dispatch_execbuffer	= ring_dispatch_execbuffer, | 
| Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 874 | }; | 
| Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 875 |  | 
| Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 876 |  | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 877 | static void gen6_bsd_ring_write_tail(struct intel_ring_buffer *ring, | 
| Chris Wilson | 297b0c5 | 2010-10-22 17:02:41 +0100 | [diff] [blame] | 878 | 				     u32 value) | 
| Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 879 | { | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 880 |        drm_i915_private_t *dev_priv = ring->dev->dev_private; | 
| Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 881 |  | 
 | 882 |        /* Every tail move must follow the sequence below */ | 
 | 883 |        I915_WRITE(GEN6_BSD_SLEEP_PSMI_CONTROL, | 
 | 884 | 	       GEN6_BSD_SLEEP_PSMI_CONTROL_RC_ILDL_MESSAGE_MODIFY_MASK | | 
 | 885 | 	       GEN6_BSD_SLEEP_PSMI_CONTROL_RC_ILDL_MESSAGE_DISABLE); | 
 | 886 |        I915_WRITE(GEN6_BSD_RNCID, 0x0); | 
 | 887 |  | 
 | 888 |        if (wait_for((I915_READ(GEN6_BSD_SLEEP_PSMI_CONTROL) & | 
 | 889 |                                GEN6_BSD_SLEEP_PSMI_CONTROL_IDLE_INDICATOR) == 0, | 
 | 890 |                        50)) | 
 | 891 |                DRM_ERROR("timed out waiting for IDLE Indicator\n"); | 
 | 892 |  | 
| Daniel Vetter | 870e86d | 2010-08-02 16:29:44 +0200 | [diff] [blame] | 893 |        I915_WRITE_TAIL(ring, value); | 
| Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 894 |        I915_WRITE(GEN6_BSD_SLEEP_PSMI_CONTROL, | 
 | 895 | 	       GEN6_BSD_SLEEP_PSMI_CONTROL_RC_ILDL_MESSAGE_MODIFY_MASK | | 
 | 896 | 	       GEN6_BSD_SLEEP_PSMI_CONTROL_RC_ILDL_MESSAGE_ENABLE); | 
 | 897 | } | 
 | 898 |  | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 899 | static void gen6_ring_flush(struct intel_ring_buffer *ring, | 
| Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 900 | 			    u32 invalidate_domains, | 
 | 901 | 			    u32 flush_domains) | 
| Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 902 | { | 
| Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 903 | 	if (intel_ring_begin(ring, 4) == 0) { | 
 | 904 | 		intel_ring_emit(ring, MI_FLUSH_DW); | 
 | 905 | 		intel_ring_emit(ring, 0); | 
 | 906 | 		intel_ring_emit(ring, 0); | 
 | 907 | 		intel_ring_emit(ring, 0); | 
 | 908 | 		intel_ring_advance(ring); | 
 | 909 | 	} | 
| Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 910 | } | 
 | 911 |  | 
 | 912 | static int | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 913 | gen6_ring_dispatch_execbuffer(struct intel_ring_buffer *ring, | 
 | 914 | 			      struct drm_i915_gem_execbuffer2 *exec, | 
 | 915 | 			      struct drm_clip_rect *cliprects, | 
 | 916 | 			      uint64_t exec_offset) | 
| Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 917 | { | 
 | 918 |        uint32_t exec_start; | 
| Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 919 |        int ret; | 
| Chris Wilson | ab6f8e3 | 2010-09-19 17:53:44 +0100 | [diff] [blame] | 920 |  | 
| Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 921 |        exec_start = (uint32_t) exec_offset + exec->batch_start_offset; | 
| Chris Wilson | ab6f8e3 | 2010-09-19 17:53:44 +0100 | [diff] [blame] | 922 |  | 
| Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 923 |        ret = intel_ring_begin(ring, 2); | 
 | 924 |        if (ret) | 
 | 925 | 	       return ret; | 
 | 926 |  | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 927 |        intel_ring_emit(ring, MI_BATCH_BUFFER_START | MI_BATCH_NON_SECURE_I965); | 
| Chris Wilson | ab6f8e3 | 2010-09-19 17:53:44 +0100 | [diff] [blame] | 928 |        /* bit0-7 is the length on GEN6+ */ | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 929 |        intel_ring_emit(ring, exec_start); | 
 | 930 |        intel_ring_advance(ring); | 
| Chris Wilson | ab6f8e3 | 2010-09-19 17:53:44 +0100 | [diff] [blame] | 931 |  | 
| Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 932 |        return 0; | 
 | 933 | } | 
 | 934 |  | 
 | 935 | /* ring buffer for Video Codec for Gen6+ */ | 
| Chris Wilson | e070868 | 2010-09-19 14:46:27 +0100 | [diff] [blame] | 936 | static const struct intel_ring_buffer gen6_bsd_ring = { | 
| Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 937 |        .name			= "gen6 bsd ring", | 
 | 938 |        .id			= RING_BSD, | 
| Daniel Vetter | 333e9fe | 2010-08-02 16:24:01 +0200 | [diff] [blame] | 939 |        .mmio_base		= GEN6_BSD_RING_BASE, | 
| Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 940 |        .size			= 32 * PAGE_SIZE, | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 941 |        .init			= init_ring_common, | 
| Chris Wilson | 297b0c5 | 2010-10-22 17:02:41 +0100 | [diff] [blame] | 942 |        .write_tail		= gen6_bsd_ring_write_tail, | 
| Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 943 |        .flush			= gen6_ring_flush, | 
 | 944 |        .add_request		= ring_add_request, | 
 | 945 |        .get_seqno		= ring_status_page_get_seqno, | 
| Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 946 |        .user_irq_get		= bsd_ring_get_user_irq, | 
 | 947 |        .user_irq_put		= bsd_ring_put_user_irq, | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 948 |        .dispatch_execbuffer	= gen6_ring_dispatch_execbuffer, | 
| Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 949 | }; | 
 | 950 |  | 
 | 951 | /* Blitter support (SandyBridge+) */ | 
 | 952 |  | 
 | 953 | static void | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 954 | blt_ring_get_user_irq(struct intel_ring_buffer *ring) | 
| Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 955 | { | 
 | 956 | 	/* do nothing */ | 
 | 957 | } | 
 | 958 | static void | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 959 | blt_ring_put_user_irq(struct intel_ring_buffer *ring) | 
| Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 960 | { | 
 | 961 | 	/* do nothing */ | 
 | 962 | } | 
 | 963 |  | 
| Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 964 |  | 
 | 965 | /* Workaround for some stepping of SNB, | 
 | 966 |  * each time when BLT engine ring tail moved, | 
 | 967 |  * the first command in the ring to be parsed | 
 | 968 |  * should be MI_BATCH_BUFFER_START | 
 | 969 |  */ | 
 | 970 | #define NEED_BLT_WORKAROUND(dev) \ | 
 | 971 | 	(IS_GEN6(dev) && (dev->pdev->revision < 8)) | 
 | 972 |  | 
 | 973 | static inline struct drm_i915_gem_object * | 
 | 974 | to_blt_workaround(struct intel_ring_buffer *ring) | 
 | 975 | { | 
 | 976 | 	return ring->private; | 
 | 977 | } | 
 | 978 |  | 
 | 979 | static int blt_ring_init(struct intel_ring_buffer *ring) | 
 | 980 | { | 
 | 981 | 	if (NEED_BLT_WORKAROUND(ring->dev)) { | 
 | 982 | 		struct drm_i915_gem_object *obj; | 
| Chris Wilson | 27153f7 | 2010-11-02 11:17:23 +0000 | [diff] [blame] | 983 | 		u32 *ptr; | 
| Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 984 | 		int ret; | 
 | 985 |  | 
| Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 986 | 		obj = i915_gem_alloc_object(ring->dev, 4096); | 
| Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 987 | 		if (obj == NULL) | 
 | 988 | 			return -ENOMEM; | 
 | 989 |  | 
| Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 990 | 		ret = i915_gem_object_pin(obj, 4096, true); | 
| Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 991 | 		if (ret) { | 
 | 992 | 			drm_gem_object_unreference(&obj->base); | 
 | 993 | 			return ret; | 
 | 994 | 		} | 
 | 995 |  | 
 | 996 | 		ptr = kmap(obj->pages[0]); | 
| Chris Wilson | 27153f7 | 2010-11-02 11:17:23 +0000 | [diff] [blame] | 997 | 		*ptr++ = MI_BATCH_BUFFER_END; | 
 | 998 | 		*ptr++ = MI_NOOP; | 
| Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 999 | 		kunmap(obj->pages[0]); | 
 | 1000 |  | 
| Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1001 | 		ret = i915_gem_object_set_to_gtt_domain(obj, false); | 
| Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1002 | 		if (ret) { | 
| Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1003 | 			i915_gem_object_unpin(obj); | 
| Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1004 | 			drm_gem_object_unreference(&obj->base); | 
 | 1005 | 			return ret; | 
 | 1006 | 		} | 
 | 1007 |  | 
 | 1008 | 		ring->private = obj; | 
 | 1009 | 	} | 
 | 1010 |  | 
 | 1011 | 	return init_ring_common(ring); | 
 | 1012 | } | 
 | 1013 |  | 
 | 1014 | static int blt_ring_begin(struct intel_ring_buffer *ring, | 
 | 1015 | 			  int num_dwords) | 
 | 1016 | { | 
 | 1017 | 	if (ring->private) { | 
 | 1018 | 		int ret = intel_ring_begin(ring, num_dwords+2); | 
 | 1019 | 		if (ret) | 
 | 1020 | 			return ret; | 
 | 1021 |  | 
 | 1022 | 		intel_ring_emit(ring, MI_BATCH_BUFFER_START); | 
 | 1023 | 		intel_ring_emit(ring, to_blt_workaround(ring)->gtt_offset); | 
 | 1024 |  | 
 | 1025 | 		return 0; | 
 | 1026 | 	} else | 
 | 1027 | 		return intel_ring_begin(ring, 4); | 
 | 1028 | } | 
 | 1029 |  | 
 | 1030 | static void blt_ring_flush(struct intel_ring_buffer *ring, | 
 | 1031 | 			   u32 invalidate_domains, | 
 | 1032 | 			   u32 flush_domains) | 
 | 1033 | { | 
 | 1034 | 	if (blt_ring_begin(ring, 4) == 0) { | 
 | 1035 | 		intel_ring_emit(ring, MI_FLUSH_DW); | 
 | 1036 | 		intel_ring_emit(ring, 0); | 
 | 1037 | 		intel_ring_emit(ring, 0); | 
 | 1038 | 		intel_ring_emit(ring, 0); | 
 | 1039 | 		intel_ring_advance(ring); | 
 | 1040 | 	} | 
 | 1041 | } | 
 | 1042 |  | 
 | 1043 | static int | 
 | 1044 | blt_ring_add_request(struct intel_ring_buffer *ring, | 
 | 1045 | 		     u32 *result) | 
 | 1046 | { | 
 | 1047 | 	u32 seqno; | 
 | 1048 | 	int ret; | 
 | 1049 |  | 
 | 1050 | 	ret = blt_ring_begin(ring, 4); | 
 | 1051 | 	if (ret) | 
 | 1052 | 		return ret; | 
 | 1053 |  | 
 | 1054 | 	seqno = i915_gem_get_seqno(ring->dev); | 
 | 1055 |  | 
 | 1056 | 	intel_ring_emit(ring, MI_STORE_DWORD_INDEX); | 
 | 1057 | 	intel_ring_emit(ring, I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT); | 
 | 1058 | 	intel_ring_emit(ring, seqno); | 
 | 1059 | 	intel_ring_emit(ring, MI_USER_INTERRUPT); | 
 | 1060 | 	intel_ring_advance(ring); | 
 | 1061 |  | 
 | 1062 | 	DRM_DEBUG_DRIVER("%s %d\n", ring->name, seqno); | 
 | 1063 | 	*result = seqno; | 
 | 1064 | 	return 0; | 
 | 1065 | } | 
 | 1066 |  | 
 | 1067 | static void blt_ring_cleanup(struct intel_ring_buffer *ring) | 
 | 1068 | { | 
 | 1069 | 	if (!ring->private) | 
 | 1070 | 		return; | 
 | 1071 |  | 
 | 1072 | 	i915_gem_object_unpin(ring->private); | 
 | 1073 | 	drm_gem_object_unreference(ring->private); | 
 | 1074 | 	ring->private = NULL; | 
 | 1075 | } | 
 | 1076 |  | 
| Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1077 | static const struct intel_ring_buffer gen6_blt_ring = { | 
 | 1078 |        .name			= "blt ring", | 
 | 1079 |        .id			= RING_BLT, | 
 | 1080 |        .mmio_base		= BLT_RING_BASE, | 
 | 1081 |        .size			= 32 * PAGE_SIZE, | 
| Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1082 |        .init			= blt_ring_init, | 
| Chris Wilson | 297b0c5 | 2010-10-22 17:02:41 +0100 | [diff] [blame] | 1083 |        .write_tail		= ring_write_tail, | 
| Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1084 |        .flush			= blt_ring_flush, | 
 | 1085 |        .add_request		= blt_ring_add_request, | 
| Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1086 |        .get_seqno		= ring_status_page_get_seqno, | 
 | 1087 |        .user_irq_get		= blt_ring_get_user_irq, | 
 | 1088 |        .user_irq_put		= blt_ring_put_user_irq, | 
| Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1089 |        .dispatch_execbuffer	= gen6_ring_dispatch_execbuffer, | 
| Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1090 |        .cleanup			= blt_ring_cleanup, | 
| Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1091 | }; | 
 | 1092 |  | 
| Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 1093 | int intel_init_render_ring_buffer(struct drm_device *dev) | 
 | 1094 | { | 
 | 1095 | 	drm_i915_private_t *dev_priv = dev->dev_private; | 
 | 1096 |  | 
 | 1097 | 	dev_priv->render_ring = render_ring; | 
 | 1098 |  | 
 | 1099 | 	if (!I915_NEED_GFX_HWS(dev)) { | 
 | 1100 | 		dev_priv->render_ring.status_page.page_addr | 
 | 1101 | 			= dev_priv->status_page_dmah->vaddr; | 
 | 1102 | 		memset(dev_priv->render_ring.status_page.page_addr, | 
 | 1103 | 				0, PAGE_SIZE); | 
 | 1104 | 	} | 
 | 1105 |  | 
 | 1106 | 	return intel_init_ring_buffer(dev, &dev_priv->render_ring); | 
 | 1107 | } | 
 | 1108 |  | 
 | 1109 | int intel_init_bsd_ring_buffer(struct drm_device *dev) | 
 | 1110 | { | 
 | 1111 | 	drm_i915_private_t *dev_priv = dev->dev_private; | 
 | 1112 |  | 
| Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1113 | 	if (IS_GEN6(dev)) | 
 | 1114 | 		dev_priv->bsd_ring = gen6_bsd_ring; | 
 | 1115 | 	else | 
 | 1116 | 		dev_priv->bsd_ring = bsd_ring; | 
| Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 1117 |  | 
 | 1118 | 	return intel_init_ring_buffer(dev, &dev_priv->bsd_ring); | 
 | 1119 | } | 
| Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1120 |  | 
 | 1121 | int intel_init_blt_ring_buffer(struct drm_device *dev) | 
 | 1122 | { | 
 | 1123 | 	drm_i915_private_t *dev_priv = dev->dev_private; | 
 | 1124 |  | 
 | 1125 | 	dev_priv->blt_ring = gen6_blt_ring; | 
 | 1126 |  | 
 | 1127 | 	return intel_init_ring_buffer(dev, &dev_priv->blt_ring); | 
 | 1128 | } |