]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/libdrm.git/commitdiff
[FreeBSD] Ensure that drm_pci_alloc is never called while locks are held.
authorRobert Noland <rnoland@2hip.net>
Sat, 6 Sep 2008 22:37:06 +0000 (18:37 -0400)
committerRobert Noland <rnoland@2hip.net>
Sat, 6 Sep 2008 22:37:06 +0000 (18:37 -0400)
bsd-core/ati_pcigart.c
bsd-core/drm_bufs.c
bsd-core/drm_pci.c
shared-core/i915_dma.c
shared-core/mach64_dma.c

index f8d3f18d86b6f081c3cd0916eed39c30c38da937..c4453ed56656d239acf62d6f6ff38ad0c1969d8d 100644 (file)
 static int drm_ati_alloc_pcigart_table(struct drm_device *dev,
                                       struct drm_ati_pcigart_info *gart_info)
 {
-       dev->sg->dmah = drm_pci_alloc(dev, gart_info->table_size,
-                                               PAGE_SIZE,
-                                               gart_info->table_mask);
-       if (dev->sg->dmah == NULL)
+       drm_dma_handle_t *dmah;
+
+       DRM_UNLOCK();
+       dmah = drm_pci_alloc(dev, gart_info->table_size, PAGE_SIZE,
+           gart_info->table_mask);
+       DRM_LOCK();
+       if (dmah == NULL)
                return ENOMEM;
 
+       dev->sg->dmah = dmah;
+
        return 0;
 }
 
index 45e014708b4ecb3fc916dceaa0d95511880c2d4d..94f51386269e9e652bb869563a88fbaf9cc346ae 100644 (file)
@@ -595,8 +595,10 @@ static int drm_do_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *reque
        page_count = 0;
 
        while (entry->buf_count < count) {
+               DRM_SPINUNLOCK(&dev->dma_lock);
                drm_dma_handle_t *dmah = drm_pci_alloc(dev, size, alignment,
                    0xfffffffful);
+               DRM_SPINLOCK(&dev->dma_lock);
                if (dmah == NULL) {
                        /* Set count correctly so we free the proper amount. */
                        entry->buf_count = count;
index f23b2a5b7891546e6ffedae935e20e77d677566b..16c830ec7ed44db52e2890f9e22d4e7fc0fddb69 100644 (file)
@@ -71,7 +71,14 @@ drm_pci_alloc(struct drm_device *dev, size_t size,
                return NULL;
 
 #ifdef __FreeBSD__
-       DRM_UNLOCK();
+       /* Make sure we aren't holding locks here */
+       mtx_assert(&dev->dev_lock, MA_NOTOWNED);
+       if (mtx_owned(&dev->dev_lock))
+           DRM_ERROR("called while holding dev_lock\n");
+       mtx_assert(&dev->dma_lock, MA_NOTOWNED);
+       if (mtx_owned(&dev->dma_lock))
+           DRM_ERROR("called while holding dma_lock\n");
+
        ret = bus_dma_tag_create(NULL, align, 0, /* tag, align, boundary */
            maxaddr, BUS_SPACE_MAXADDR, /* lowaddr, highaddr */
            NULL, NULL, /* filtfunc, filtfuncargs */
@@ -80,7 +87,6 @@ drm_pci_alloc(struct drm_device *dev, size_t size,
            &dmah->tag);
        if (ret != 0) {
                free(dmah, M_DRM);
-               DRM_LOCK();
                return NULL;
        }
 
@@ -89,10 +95,9 @@ drm_pci_alloc(struct drm_device *dev, size_t size,
        if (ret != 0) {
                bus_dma_tag_destroy(dmah->tag);
                free(dmah, M_DRM);
-               DRM_LOCK();
                return NULL;
        }
-       DRM_LOCK();
+
        ret = bus_dmamap_load(dmah->tag, dmah->map, dmah->vaddr, size,
            drm_pci_busdma_callback, dmah, 0);
        if (ret != 0) {
index c874ce2887572013fe3006ae559e700214384121..619e6ac2c7b3a0e1bd089dec91223f0d610fc1b2 100644 (file)
@@ -72,16 +72,24 @@ int i915_wait_ring(struct drm_device * dev, int n, const char *caller)
 int i915_init_hardware_status(struct drm_device *dev)
 {
        drm_i915_private_t *dev_priv = dev->dev_private;
-       /* Program Hardware Status Page */
-       dev_priv->status_page_dmah =
-               drm_pci_alloc(dev, PAGE_SIZE, PAGE_SIZE, 0xffffffff);
+       drm_dma_handle_t *dmah;
 
-       if (!dev_priv->status_page_dmah) {
+       /* Program Hardware Status Page */
+#ifdef __FreeBSD__
+       DRM_UNLOCK();
+#endif
+       dmah = drm_pci_alloc(dev, PAGE_SIZE, PAGE_SIZE, 0xffffffff);
+#ifdef __FreeBSD__
+       DRM_LOCK();
+#endif
+       if (!dmah) {
                DRM_ERROR("Can not allocate hardware status page\n");
                return -ENOMEM;
        }
-       dev_priv->hw_status_page = dev_priv->status_page_dmah->vaddr;
-       dev_priv->dma_status_page = dev_priv->status_page_dmah->busaddr;
+
+       dev_priv->status_page_dmah = dmah;
+       dev_priv->hw_status_page = dmah->vaddr;
+       dev_priv->dma_status_page = dmah->busaddr;
 
        memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
 
index 339234fa8301503a79c3518b97d629e4d47e70c1..3f2367ba7fd4020b234efeab5a18cab129623588 100644 (file)
@@ -834,8 +834,14 @@ static int mach64_bm_dma_test(struct drm_device * dev)
 
        /* FIXME: get a dma buffer from the freelist here */
        DRM_DEBUG("Allocating data memory ...\n");
+#ifdef __FreeBSD__
+       DRM_UNLOCK();
+#endif
        cpu_addr_dmah =
            drm_pci_alloc(dev, 0x1000, 0x1000, 0xfffffffful);
+#ifdef __FreeBSD__
+       DRM_LOCK();
+#endif
        if (!cpu_addr_dmah) {
                DRM_INFO("data-memory allocation failed!\n");
                return -ENOMEM;