i830_accel.c revision fa225cbc
1/************************************************************************** 2 3Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. 4All Rights Reserved. 5 6Permission is hereby granted, free of charge, to any person obtaining a 7copy of this software and associated documentation files (the 8"Software"), to deal in the Software without restriction, including 9without limitation the rights to use, copy, modify, merge, publish, 10distribute, sub license, and/or sell copies of the Software, and to 11permit persons to whom the Software is furnished to do so, subject to 12the following conditions: 13 14The above copyright notice and this permission notice (including the 15next paragraph) shall be included in all copies or substantial portions 16of the Software. 17 18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 22ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 26**************************************************************************/ 27 28/* 29 * Authors: 30 * Keith Whitwell <keith@tungstengraphics.com> 31 * 32 */ 33 34/* 35 * XXX So far, for GXxor this is about 40% of the speed of SW, but CPU 36 * utilisation falls from 95% to < 5%. 37 */ 38 39#ifdef HAVE_CONFIG_H 40#include "config.h" 41#endif 42 43#include <errno.h> 44 45#include "xf86.h" 46#include "i830.h" 47#include "i810_reg.h" 48#include "i830_debug.h" 49#include "i830_ring.h" 50#include "i915_drm.h" 51 52unsigned long 53intel_get_pixmap_offset(PixmapPtr pPix) 54{ 55 ScreenPtr pScreen = pPix->drawable.pScreen; 56 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 57 I830Ptr pI830 = I830PTR(pScrn); 58 59 return (unsigned long)pPix->devPrivate.ptr - (unsigned long)pI830->FbBase; 60} 61 62unsigned long 63intel_get_pixmap_pitch(PixmapPtr pPix) 64{ 65 return (unsigned long)pPix->devKind; 66} 67 68int 69I830WaitLpRing(ScrnInfoPtr pScrn, int n, int timeout_millis) 70{ 71 I830Ptr pI830 = I830PTR(pScrn); 72 I830RingBuffer *ring = &pI830->ring; 73 int iters = 0; 74 unsigned int start = 0; 75 unsigned int now = 0; 76 int last_head = 0; 77 unsigned int first = 0; 78 79 /* If your system hasn't moved the head pointer in 2 seconds, I'm going to 80 * call it crashed. 81 */ 82 if (timeout_millis == 0) 83 timeout_millis = 2000; 84 85 if (I810_DEBUG & DEBUG_VERBOSE_ACCEL) { 86 ErrorF("I830WaitLpRing %d\n", n); 87 first = GetTimeInMillis(); 88 } 89 90 while (ring->space < n) { 91 ring->head = INREG(LP_RING + RING_HEAD) & I830_HEAD_MASK; 92 ring->space = ring->head - (ring->tail + 8); 93 94 if (ring->space < 0) 95 ring->space += ring->mem->size; 96 97 iters++; 98 now = GetTimeInMillis(); 99 if (start == 0 || now < start || ring->head != last_head) { 100 if (I810_DEBUG & DEBUG_VERBOSE_ACCEL) 101 if (now > start) 102 ErrorF("space: %d wanted %d\n", ring->space, n); 103 start = now; 104 last_head = ring->head; 105 } else if (now - start > timeout_millis) { 106 ErrorF("Error in I830WaitLpRing(), timeout for %d seconds\n", 107 timeout_millis/1000); 108 if (IS_I965G(pI830)) 109 i965_dump_error_state(pScrn); 110 else 111 i830_dump_error_state(pScrn); 112 ErrorF("space: %d wanted %d\n", ring->space, n); 113 pI830->uxa_driver = NULL; 114 FatalError("lockup\n"); 115 } 116 117 DELAY(10); 118 } 119 120 if (I810_DEBUG & DEBUG_VERBOSE_ACCEL) { 121 now = GetTimeInMillis(); 122 if (now - first) { 123 ErrorF("Elapsed %u ms\n", now - first); 124 ErrorF("space: %d wanted %d\n", ring->space, n); 125 } 126 } 127 128 return iters; 129} 130 131void 132I830Sync(ScrnInfoPtr pScrn) 133{ 134 I830Ptr pI830 = I830PTR(pScrn); 135 136 if (I810_DEBUG & (DEBUG_VERBOSE_ACCEL | DEBUG_VERBOSE_SYNC)) 137 ErrorF("I830Sync\n"); 138 139 if (!pScrn->vtSema || !pI830->batch_bo) 140 return; 141 142 I830EmitFlush(pScrn); 143 144 intel_batch_flush(pScrn, TRUE); 145 intel_batch_wait_last(pScrn); 146} 147 148void 149I830EmitFlush(ScrnInfoPtr pScrn) 150{ 151 I830Ptr pI830 = I830PTR(pScrn); 152 int flags = MI_WRITE_DIRTY_STATE | MI_INVALIDATE_MAP_CACHE; 153 154 if (IS_I965G(pI830)) 155 flags = 0; 156 157 { 158 BEGIN_BATCH(1); 159 OUT_BATCH(MI_FLUSH | flags); 160 ADVANCE_BATCH(); 161 } 162} 163 164 165#if (ALWAYS_SYNC || ALWAYS_FLUSH) 166void 167i830_debug_sync(ScrnInfoPtr scrn) 168{ 169 if (ALWAYS_SYNC) 170 I830Sync(scrn); 171 else 172 intel_batch_flush(scrn, FALSE); 173} 174#endif 175 176/* The following function sets up the supported acceleration. Call it 177 * from the FbInit() function in the SVGA driver, or before ScreenInit 178 * in a monolithic server. 179 */ 180Bool 181I830AccelInit(ScreenPtr pScreen) 182{ 183 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 184 I830Ptr pI830 = I830PTR(pScrn); 185 186 /* Limits are described in the BLT engine chapter under Graphics Data Size 187 * Limitations, and the descriptions of SURFACE_STATE, 3DSTATE_BUFFER_INFO, 188 * 3DSTATE_DRAWING_RECTANGLE, 3DSTATE_MAP_INFO, and 3DSTATE_MAP_INFO. 189 * 190 * i845 through i965 limits 2D rendering to 65536 lines and pitch of 32768. 191 * 192 * i965 limits 3D surface to (2*element size)-aligned offset if un-tiled. 193 * i965 limits 3D surface to 4kB-aligned offset if tiled. 194 * i965 limits 3D surfaces to w,h of ?,8192. 195 * i965 limits 3D surface to pitch of 1B - 128kB. 196 * i965 limits 3D surface pitch alignment to 1 or 2 times the element size. 197 * i965 limits 3D surface pitch alignment to 512B if tiled. 198 * i965 limits 3D destination drawing rect to w,h of 8192,8192. 199 * 200 * i915 limits 3D textures to 4B-aligned offset if un-tiled. 201 * i915 limits 3D textures to ~4kB-aligned offset if tiled. 202 * i915 limits 3D textures to width,height of 2048,2048. 203 * i915 limits 3D textures to pitch of 16B - 8kB, in dwords. 204 * i915 limits 3D destination to ~4kB-aligned offset if tiled. 205 * i915 limits 3D destination to pitch of 16B - 8kB, in dwords, if un-tiled. 206 * i915 limits 3D destination to pitch 64B-aligned if used with depth. 207 * i915 limits 3D destination to pitch of 512B - 8kB, in tiles, if tiled. 208 * i915 limits 3D destination to POT aligned pitch if tiled. 209 * i915 limits 3D destination drawing rect to w,h of 2048,2048. 210 * 211 * i845 limits 3D textures to 4B-aligned offset if un-tiled. 212 * i845 limits 3D textures to ~4kB-aligned offset if tiled. 213 * i845 limits 3D textures to width,height of 2048,2048. 214 * i845 limits 3D textures to pitch of 4B - 8kB, in dwords. 215 * i845 limits 3D destination to 4B-aligned offset if un-tiled. 216 * i845 limits 3D destination to ~4kB-aligned offset if tiled. 217 * i845 limits 3D destination to pitch of 8B - 8kB, in dwords. 218 * i845 limits 3D destination drawing rect to w,h of 2048,2048. 219 * 220 * For the tiled issues, the only tiled buffer we draw to should be 221 * the front, which will have an appropriate pitch/offset already set up, 222 * so UXA doesn't need to worry. 223 */ 224 if (IS_I965G(pI830)) { 225 pI830->accel_pixmap_offset_alignment = 4 * 2; 226 pI830->accel_pixmap_pitch_alignment = 64; 227 pI830->accel_max_x = 8192; 228 pI830->accel_max_y = 8192; 229 } else { 230 pI830->accel_pixmap_offset_alignment = 4; 231 pI830->accel_pixmap_pitch_alignment = 64; 232 pI830->accel_max_x = 2048; 233 pI830->accel_max_y = 2048; 234 } 235 236 return i830_uxa_init(pScreen); 237} 238