Make sure we are locked when creating drm buffer objects.
authorThomas Hellstrom <thomas-at-tungstengraphics-dot-com>
Mon, 16 Apr 2007 14:04:12 +0000 (16:04 +0200)
committerThomas Hellstrom <thomas-at-tungstengraphics-dot-com>
Mon, 16 Apr 2007 14:04:12 +0000 (16:04 +0200)
Don't place buffer objects on unfenced list when newly created.
Fix a buffer object wait-for-idle deadlock.

src/mesa/drivers/dri/common/dri_bufmgr.c
src/mesa/drivers/dri/common/dri_drmpool.c
src/mesa/drivers/dri/i915tex/intel_batchpool.c
src/mesa/drivers/dri/i915tex/intel_buffer_objects.c
src/mesa/drivers/dri/i915tex/intel_regions.c
src/mesa/drivers/dri/i915tex/intel_screen.c

index 65d654596573a66e47719da622411ef71ce62968..eaa4fb09c70a8054cf2327a292ac8a545a7d5e43 100644 (file)
@@ -190,11 +190,16 @@ driBOKernel(struct _DriBufferObject *buf)
 void
 driBOWaitIdle(struct _DriBufferObject *buf, int lazy)
 {
-   assert(buf->private != NULL);
+   struct _DriBufferPool *pool;
+   void *priv;
 
    _glthread_LOCK_MUTEX(buf->mutex);
-   BM_CKFATAL(buf->pool->waitIdle(buf->pool, buf->private, lazy));
+   pool = buf->pool;
+   priv = buf->private;
    _glthread_UNLOCK_MUTEX(buf->mutex);
+   
+   assert(priv != NULL);
+   BM_CKFATAL(buf->pool->waitIdle(pool, priv, lazy));
 }
 
 void *
@@ -296,7 +301,8 @@ driBOData(struct _DriBufferObject *buf,
          pool->destroy(pool, buf->private);
       if (!flags)
          flags = buf->flags;
-      buf->private = pool->create(pool, size, flags, 0, buf->alignment);
+      buf->private = pool->create(pool, size, flags, DRM_BO_HINT_DONT_FENCE, 
+                                 buf->alignment);
       if (!buf->private)
          BM_CKFATAL(-ENOMEM);
       BM_CKFATAL(pool->map(pool, buf->private,
index b5b324be5003ff6190d5672183f6372e60b2eb65..878a148b397c964e3f2383cade98bca485621f42 100644 (file)
@@ -185,7 +185,7 @@ pool_setstatic(struct _DriBufferPool *pool, unsigned long offset,
       return NULL;
 
    ret = drmBOCreate(pool->fd, offset, size, 0, NULL, drm_bo_type_fake,
-                     flags, 0, buf);
+                     flags, DRM_BO_HINT_DONT_FENCE, buf);
 
    if (ret) {
       free(buf);
index 3c17c50204bd05417f962347f7f1605670064367..2503b8a62a1b38348a844318be11fc15b5927a29 100644 (file)
@@ -96,7 +96,7 @@ createBPool(int fd, unsigned long bufSize, unsigned numBufs, unsigned flags,
    _glthread_INIT_MUTEX(p->mutex);
 
    if (drmBOCreate(fd, 0, numBufs * bufSize, 0, NULL, drm_bo_type_dc,
-                   flags, 0, &p->kernelBO)) {
+                   flags, DRM_BO_HINT_DONT_FENCE, &p->kernelBO)) {
       free(p->bufs);
       free(p);
       return NULL;
index ba3c7f0c1f7d53668eaa80d40e932ed0ce4fc0db..91c45ad95be56ca85e3e9ad3ba4b824cefeecf9f 100644 (file)
@@ -76,7 +76,9 @@ intel_bufferobj_release_region(struct intel_context *intel,
     */
    driGenBuffers(intel->intelScreen->regionPool,
                  "buffer object", 1, &intel_obj->buffer, 64, 0, 0);
+   LOCK_HARDWARE(intel);
    driBOData(intel_obj->buffer, intel_obj->Base.Size, NULL, 0);
+   UNLOCK_HARDWARE(intel);
 }
 
 /* Break the COW tie to the region.  Both the pbo and the region end
@@ -137,7 +139,9 @@ intel_bufferobj_data(GLcontext * ctx,
    if (intel_obj->region)
       intel_bufferobj_release_region(intel, intel_obj);
 
+   LOCK_HARDWARE(intel);
    driBOData(intel_obj->buffer, size, data, 0);
+   UNLOCK_HARDWARE(intel);
 }
 
 
index a114bdf89656ba7dafc09a12457794d2c67bc05e..7d19bd07d367a6fc21cdf40ca5881cc6f8c54178 100644 (file)
@@ -90,6 +90,7 @@ intel_region_alloc(intelScreenPrivate *intelScreen,
                    GLuint cpp, GLuint pitch, GLuint height)
 {
    struct intel_region *region = calloc(sizeof(*region), 1);
+   struct intel_context *intel = intelScreenContext(intelScreen);
 
    DBG("%s\n", __FUNCTION__);
 
@@ -107,7 +108,9 @@ intel_region_alloc(intelScreenPrivate *intelScreen,
                 0,
 #endif
                 0);
+   LOCK_HARDWARE(intel);
    driBOData(region->buffer, pitch * cpp * height, NULL, 0);
+   UNLOCK_HARDWARE(intel);
    return region;
 }
 
@@ -392,6 +395,8 @@ void
 intel_region_release_pbo(intelScreenPrivate *intelScreen,
                          struct intel_region *region)
 {
+   struct intel_context *intel = intelScreenContext(intelScreen);
+
    assert(region->buffer == region->pbo->buffer);
    region->pbo->region = NULL;
    region->pbo = NULL;
@@ -400,8 +405,11 @@ intel_region_release_pbo(intelScreenPrivate *intelScreen,
 
    driGenBuffers(intelScreen->regionPool,
                  "region", 1, &region->buffer, 64, 0, 0);
+   
+   LOCK_HARDWARE(intel);
    driBOData(region->buffer,
              region->cpp * region->pitch * region->height, NULL, 0);
+   UNLOCK_HARDWARE(intel);
 }
 
 /* Break the COW tie to the pbo.  Both the pbo and the region end up
index 9034ee1b22306c57b7d08a1e288caa9420df4a69..87a5aeb17c98881cab46cb1eabd11463582a4e4a 100644 (file)
@@ -878,9 +878,19 @@ __driCreateNewScreen_20050727(__DRInativeDisplay * dpy, int scrn,
    static const __DRIversion ddx_expected = { 1, 5, 0 };
    static const __DRIversion dri_expected = { 4, 0, 0 };
    static const __DRIversion drm_expected = { 1, 7, 0 };
+   int tmpContextID;
+   GLuint tmpContext;
 
    dri_interface = interface;
 
+   if (!(*dri_interface->createContext)(dpy, modes->screen,
+                                       modes->fbconfigID, 
+                                       &tmpContextID, &tmpContext)) {
+       fprintf(stderr, "Could not create temporary context.\n");
+       return NULL;
+   }
+   DRM_LIGHT_LOCK(fd, &((drm_sarea_t *)pSAREA)->lock, tmpContext);
+
    if (!driCheckDriDdxDrmVersions2("i915",
                                    dri_version, &dri_expected,
                                    ddx_version, &ddx_expected,
@@ -892,6 +902,10 @@ __driCreateNewScreen_20050727(__DRInativeDisplay * dpy, int scrn,
                                   ddx_version, dri_version, drm_version,
                                   frame_buffer, pSAREA, fd,
                                   internal_api_version, &intelAPI);
+
+   DRM_UNLOCK(fd, &((drm_sarea_t *)pSAREA)->lock, tmpContext);
+   (void) (*dri_interface->destroyContext)(dpy, modes->screen, tmpContextID);
+
    if (psp != NULL) {
       I830DRIPtr dri_priv = (I830DRIPtr) psp->pDevPriv;
       *driver_modes = intelFillInModes(dri_priv->cpp * 8,