diff options
author | Jesse Barnes <jbarnes@virtuousgeek.org> | 2008-11-13 15:30:06 -0800 |
---|---|---|
committer | Jesse Barnes <jbarnes@virtuousgeek.org> | 2008-11-13 15:30:06 -0800 |
commit | 965b4d662a5236ee5aeb94a70f62565b6ed5644c (patch) | |
tree | 7645e5130046e3952c2a490d5561bafe67cbff89 /bsd-core | |
parent | 9a4cb7eab4f74747cc777a3fef31dbb46e1191e5 (diff) | |
parent | 7e27b3ba88f0c40680380636a436c18e3220c7ce (diff) |
Merge branch 'master' into modesetting-gem
Conflicts:
libdrm/Makefile.am
libdrm/intel/intel_bufmgr.h
libdrm/intel/intel_bufmgr_fake.c
libdrm/intel/intel_bufmgr_gem.c
shared-core/drm.h
shared-core/i915_dma.c
shared-core/i915_irq.c
shared-core/radeon_cp.c
shared-core/radeon_drv.h
Diffstat (limited to 'bsd-core')
-rw-r--r-- | bsd-core/ati_pcigart.c | 11 | ||||
-rw-r--r-- | bsd-core/drmP.h | 72 | ||||
-rw-r--r-- | bsd-core/drm_agpsupport.c | 9 | ||||
-rw-r--r-- | bsd-core/drm_auth.c | 4 | ||||
-rw-r--r-- | bsd-core/drm_bufs.c | 79 | ||||
-rw-r--r-- | bsd-core/drm_context.c | 12 | ||||
-rw-r--r-- | bsd-core/drm_dma.c | 14 | ||||
-rw-r--r-- | bsd-core/drm_drawable.c | 20 | ||||
-rw-r--r-- | bsd-core/drm_drv.c | 12 | ||||
-rw-r--r-- | bsd-core/drm_fops.c | 8 | ||||
-rw-r--r-- | bsd-core/drm_ioctl.c | 10 | ||||
-rw-r--r-- | bsd-core/drm_irq.c | 11 | ||||
-rw-r--r-- | bsd-core/drm_linux_list.h | 4 | ||||
-rw-r--r-- | bsd-core/drm_lock.c | 10 | ||||
-rw-r--r-- | bsd-core/drm_memory.c | 49 | ||||
-rw-r--r-- | bsd-core/drm_pci.c | 10 | ||||
-rw-r--r-- | bsd-core/drm_scatter.c | 12 | ||||
-rw-r--r-- | bsd-core/drm_sysctl.c | 19 | ||||
-rw-r--r-- | bsd-core/drm_vm.c | 21 | ||||
-rw-r--r-- | bsd-core/i915_drv.c | 6 | ||||
-rw-r--r-- | bsd-core/mach64_drv.c | 6 | ||||
-rw-r--r-- | bsd-core/mga_drv.c | 6 | ||||
-rw-r--r-- | bsd-core/r128_drv.c | 6 | ||||
-rw-r--r-- | bsd-core/radeon_drv.c | 6 | ||||
-rw-r--r-- | bsd-core/savage_drv.c | 6 | ||||
-rw-r--r-- | bsd-core/sis_drv.c | 6 | ||||
-rw-r--r-- | bsd-core/tdfx_drv.c | 6 | ||||
-rw-r--r-- | bsd-core/via_drv.c | 6 |
28 files changed, 226 insertions, 215 deletions
diff --git a/bsd-core/ati_pcigart.c b/bsd-core/ati_pcigart.c index 5feeeba8..bae10a69 100644 --- a/bsd-core/ati_pcigart.c +++ b/bsd-core/ati_pcigart.c @@ -61,7 +61,8 @@ drm_ati_alloc_pcigart_table(struct drm_device *dev, struct drm_dma_handle *dmah; int flags, ret; - dmah = malloc(sizeof(struct drm_dma_handle), M_DRM, M_ZERO | M_NOWAIT); + dmah = malloc(sizeof(struct drm_dma_handle), DRM_MEM_DMA, + M_ZERO | M_NOWAIT); if (dmah == NULL) return ENOMEM; @@ -74,7 +75,7 @@ drm_ati_alloc_pcigart_table(struct drm_device *dev, BUS_DMA_ALLOCNOW, NULL, NULL, /* flags, lockfunc, lockfuncargs */ &dmah->tag); if (ret != 0) { - free(dmah, M_DRM); + free(dmah, DRM_MEM_DMA); return ENOMEM; } @@ -85,7 +86,7 @@ drm_ati_alloc_pcigart_table(struct drm_device *dev, ret = bus_dmamem_alloc(dmah->tag, &dmah->vaddr, flags, &dmah->map); if (ret != 0) { bus_dma_tag_destroy(dmah->tag); - free(dmah, M_DRM); + free(dmah, DRM_MEM_DMA); return ENOMEM; } DRM_LOCK(); @@ -95,7 +96,7 @@ drm_ati_alloc_pcigart_table(struct drm_device *dev, if (ret != 0) { bus_dmamem_free(dmah->tag, dmah->vaddr, dmah->map); bus_dma_tag_destroy(dmah->tag); - free(dmah, M_DRM); + free(dmah, DRM_MEM_DMA); return ENOMEM; } @@ -112,7 +113,7 @@ drm_ati_free_pcigart_table(struct drm_device *dev, bus_dmamem_free(dmah->tag, dmah->vaddr, dmah->map); bus_dma_tag_destroy(dmah->tag); - free(dmah, M_DRM); + free(dmah, DRM_MEM_DMA); dev->sg->dmah = NULL; } diff --git a/bsd-core/drmP.h b/bsd-core/drmP.h index fcce9066..c7e40230 100644 --- a/bsd-core/drmP.h +++ b/bsd-core/drmP.h @@ -126,27 +126,24 @@ struct drm_file; #define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */ #define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */ -#define DRM_MEM_DMA 0 -#define DRM_MEM_SAREA 1 -#define DRM_MEM_DRIVER 2 -#define DRM_MEM_MAGIC 3 -#define DRM_MEM_IOCTLS 4 -#define DRM_MEM_MAPS 5 -#define DRM_MEM_BUFS 6 -#define DRM_MEM_SEGS 7 -#define DRM_MEM_PAGES 8 -#define DRM_MEM_FILES 9 -#define DRM_MEM_QUEUES 10 -#define DRM_MEM_CMDS 11 -#define DRM_MEM_MAPPINGS 12 -#define DRM_MEM_BUFLISTS 13 -#define DRM_MEM_AGPLISTS 14 -#define DRM_MEM_TOTALAGP 15 -#define DRM_MEM_BOUNDAGP 16 -#define DRM_MEM_CTXBITMAP 17 -#define DRM_MEM_STUB 18 -#define DRM_MEM_SGLISTS 19 -#define DRM_MEM_DRAWABLE 20 +MALLOC_DECLARE(DRM_MEM_DMA); +MALLOC_DECLARE(DRM_MEM_SAREA); +MALLOC_DECLARE(DRM_MEM_DRIVER); +MALLOC_DECLARE(DRM_MEM_MAGIC); +MALLOC_DECLARE(DRM_MEM_IOCTLS); +MALLOC_DECLARE(DRM_MEM_MAPS); +MALLOC_DECLARE(DRM_MEM_BUFS); +MALLOC_DECLARE(DRM_MEM_SEGS); +MALLOC_DECLARE(DRM_MEM_PAGES); +MALLOC_DECLARE(DRM_MEM_FILES); +MALLOC_DECLARE(DRM_MEM_QUEUES); +MALLOC_DECLARE(DRM_MEM_CMDS); +MALLOC_DECLARE(DRM_MEM_MAPPINGS); +MALLOC_DECLARE(DRM_MEM_BUFLISTS); +MALLOC_DECLARE(DRM_MEM_AGPLISTS); +MALLOC_DECLARE(DRM_MEM_CTXBITMAP); +MALLOC_DECLARE(DRM_MEM_SGLISTS); +MALLOC_DECLARE(DRM_MEM_DRAWABLE); #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8) @@ -157,8 +154,6 @@ struct drm_file; #define DRM_IF_VERSION(maj, min) (maj << 16 | min) -MALLOC_DECLARE(M_DRM); - #define __OS_HAS_AGP 1 #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) @@ -745,11 +740,6 @@ extern int drm_open_helper(struct cdev *kdev, int flags, int fmt, /* Memory management support (drm_memory.c) */ void drm_mem_init(void); void drm_mem_uninit(void); -void *drm_alloc(size_t size, int area); -void *drm_calloc(size_t nmemb, size_t size, int area); -void *drm_realloc(void *oldpt, size_t oldsize, size_t size, - int area); -void drm_free(void *pt, size_t size, int area); void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map); void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map); void drm_ioremapfree(drm_local_map_t *map); @@ -963,6 +953,32 @@ drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size, size_t align, dma_addr_t maxaddr); void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah); +/* Inline replacements for drm_alloc and friends */ +static __inline__ void * +drm_alloc(size_t size, struct malloc_type *area) +{ + return malloc(size, area, M_NOWAIT); +} + +static __inline__ void * +drm_calloc(size_t nmemb, size_t size, struct malloc_type *area) +{ + return malloc(size * nmemb, area, M_NOWAIT | M_ZERO); +} + +static __inline__ void * +drm_realloc(void *oldpt, size_t oldsize, size_t size, + struct malloc_type *area) +{ + return reallocf(oldpt, size, area, M_NOWAIT); +} + +static __inline__ void +drm_free(void *pt, size_t size, struct malloc_type *area) +{ + free(pt, area); +} + /* Inline replacements for DRM_IOREMAP macros */ static __inline__ void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev) diff --git a/bsd-core/drm_agpsupport.c b/bsd-core/drm_agpsupport.c index a568c5a5..34b23af1 100644 --- a/bsd-core/drm_agpsupport.c +++ b/bsd-core/drm_agpsupport.c @@ -209,7 +209,7 @@ int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request) if (!dev->agp || !dev->agp->acquired) return EINVAL; - entry = malloc(sizeof(*entry), M_DRM, M_NOWAIT | M_ZERO); + entry = malloc(sizeof(*entry), DRM_MEM_AGPLISTS, M_NOWAIT | M_ZERO); if (entry == NULL) return ENOMEM; @@ -220,7 +220,7 @@ int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request) handle = drm_agp_allocate_memory(pages, type); DRM_LOCK(); if (handle == NULL) { - free(entry, M_DRM); + free(entry, DRM_MEM_AGPLISTS); return ENOMEM; } @@ -371,7 +371,7 @@ int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request) drm_agp_free_memory(entry->handle); DRM_LOCK(); - free(entry, M_DRM); + free(entry, DRM_MEM_AGPLISTS); return 0; @@ -405,7 +405,8 @@ drm_agp_head_t *drm_agp_init(void) DRM_DEBUG("agp_available = %d\n", agp_available); if (agp_available) { - head = malloc(sizeof(*head), M_DRM, M_NOWAIT | M_ZERO); + head = malloc(sizeof(*head), DRM_MEM_AGPLISTS, + M_NOWAIT | M_ZERO); if (head == NULL) return NULL; head->agpdev = agpdev; diff --git a/bsd-core/drm_auth.c b/bsd-core/drm_auth.c index b5fc5587..6a76ed59 100644 --- a/bsd-core/drm_auth.c +++ b/bsd-core/drm_auth.c @@ -74,7 +74,7 @@ static int drm_add_magic(struct drm_device *dev, struct drm_file *priv, DRM_SPINLOCK_ASSERT(&dev->dev_lock); hash = drm_hash_magic(magic); - entry = malloc(sizeof(*entry), M_DRM, M_ZERO | M_NOWAIT); + entry = malloc(sizeof(*entry), DRM_MEM_MAGIC, M_ZERO | M_NOWAIT); if (!entry) return ENOMEM; entry->magic = magic; @@ -118,7 +118,7 @@ static int drm_remove_magic(struct drm_device *dev, drm_magic_t magic) if (prev) { prev->next = pt->next; } - free(pt, M_DRM); + free(pt, DRM_MEM_MAGIC); return 0; } } diff --git a/bsd-core/drm_bufs.c b/bsd-core/drm_bufs.c index c9b5dc4e..303b2404 100644 --- a/bsd-core/drm_bufs.c +++ b/bsd-core/drm_bufs.c @@ -135,7 +135,7 @@ int drm_addmap(struct drm_device * dev, unsigned long offset, /* Allocate a new map structure, fill it in, and do any type-specific * initialization necessary. */ - map = malloc(sizeof(*map), M_DRM, M_ZERO | M_NOWAIT); + map = malloc(sizeof(*map), DRM_MEM_MAPS, M_ZERO | M_NOWAIT); if (!map) { DRM_LOCK(); return ENOMEM; @@ -157,11 +157,11 @@ int drm_addmap(struct drm_device * dev, unsigned long offset, map->mtrr = 1; break; case _DRM_SHM: - map->handle = malloc(map->size, M_DRM, M_NOWAIT); + map->handle = malloc(map->size, DRM_MEM_MAPS, M_NOWAIT); DRM_DEBUG("%lu %d %p\n", map->size, drm_order(map->size), map->handle); if (!map->handle) { - free(map, M_DRM); + free(map, DRM_MEM_MAPS); DRM_LOCK(); return ENOMEM; } @@ -171,8 +171,8 @@ int drm_addmap(struct drm_device * dev, unsigned long offset, DRM_LOCK(); if (dev->lock.hw_lock != NULL) { DRM_UNLOCK(); - free(map->handle, M_DRM); - free(map, M_DRM); + free(map->handle, DRM_MEM_MAPS); + free(map, DRM_MEM_MAPS); return EBUSY; } dev->lock.hw_lock = map->handle; /* Pointer to lock */ @@ -202,14 +202,14 @@ int drm_addmap(struct drm_device * dev, unsigned long offset, } } if (!valid) { - free(map, M_DRM); + free(map, DRM_MEM_MAPS); DRM_LOCK(); return EACCES; }*/ break; case _DRM_SCATTER_GATHER: if (!dev->sg) { - free(map, M_DRM); + free(map, DRM_MEM_MAPS); DRM_LOCK(); return EINVAL; } @@ -227,7 +227,7 @@ int drm_addmap(struct drm_device * dev, unsigned long offset, align = PAGE_SIZE; map->dmah = drm_pci_alloc(dev, map->size, align, 0xfffffffful); if (map->dmah == NULL) { - free(map, M_DRM); + free(map, DRM_MEM_MAPS); DRM_LOCK(); return ENOMEM; } @@ -236,7 +236,7 @@ int drm_addmap(struct drm_device * dev, unsigned long offset, break; default: DRM_ERROR("Bad map type %d\n", map->type); - free(map, M_DRM); + free(map, DRM_MEM_MAPS); DRM_LOCK(); return EINVAL; } @@ -310,7 +310,7 @@ void drm_rmmap(struct drm_device *dev, drm_local_map_t *map) } break; case _DRM_SHM: - free(map->handle, M_DRM); + free(map->handle, DRM_MEM_MAPS); break; case _DRM_AGP: case _DRM_SCATTER_GATHER: @@ -328,7 +328,7 @@ void drm_rmmap(struct drm_device *dev, drm_local_map_t *map) map->bsr); } - free(map, M_DRM); + free(map, DRM_MEM_MAPS); } /* Remove a map private from list and deallocate resources if the mapping @@ -371,16 +371,16 @@ static void drm_cleanup_buf_error(struct drm_device *dev, for (i = 0; i < entry->seg_count; i++) { drm_pci_free(dev, entry->seglist[i]); } - free(entry->seglist, M_DRM); + free(entry->seglist, DRM_MEM_SEGS); entry->seg_count = 0; } if (entry->buf_count) { for (i = 0; i < entry->buf_count; i++) { - free(entry->buflist[i].dev_private, M_DRM); + free(entry->buflist[i].dev_private, DRM_MEM_BUFS); } - free(entry->buflist, M_DRM); + free(entry->buflist, DRM_MEM_BUFS); entry->buf_count = 0; } @@ -447,7 +447,7 @@ static int drm_do_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *reque entry = &dma->bufs[order]; - entry->buflist = malloc(count * sizeof(*entry->buflist), M_DRM, + entry->buflist = malloc(count * sizeof(*entry->buflist), DRM_MEM_BUFS, M_NOWAIT | M_ZERO); if (!entry->buflist) { return ENOMEM; @@ -473,7 +473,7 @@ static int drm_do_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *reque buf->file_priv = NULL; buf->dev_priv_size = dev->driver->buf_priv_size; - buf->dev_private = malloc(buf->dev_priv_size, M_DRM, + buf->dev_private = malloc(buf->dev_priv_size, DRM_MEM_BUFS, M_NOWAIT | M_ZERO); if (buf->dev_private == NULL) { /* Set count correctly so we free the proper amount. */ @@ -490,8 +490,8 @@ static int drm_do_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *reque DRM_DEBUG("byte_count: %d\n", byte_count); temp_buflist = realloc(dma->buflist, - (dma->buf_count + entry->buf_count) * sizeof(*dma->buflist), M_DRM, - M_NOWAIT); + (dma->buf_count + entry->buf_count) * sizeof(*dma->buflist), + DRM_MEM_BUFS, M_NOWAIT); if (temp_buflist == NULL) { /* Free the entry because it isn't valid */ drm_cleanup_buf_error(dev, entry); @@ -549,22 +549,22 @@ static int drm_do_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *reque entry = &dma->bufs[order]; - entry->buflist = malloc(count * sizeof(*entry->buflist), M_DRM, + entry->buflist = malloc(count * sizeof(*entry->buflist), DRM_MEM_BUFS, M_NOWAIT | M_ZERO); - entry->seglist = malloc(count * sizeof(*entry->seglist), M_DRM, + entry->seglist = malloc(count * sizeof(*entry->seglist), DRM_MEM_SEGS, M_NOWAIT | M_ZERO); /* Keep the original pagelist until we know all the allocations * have succeeded */ temp_pagelist = malloc((dma->page_count + (count << page_order)) * - sizeof(*dma->pagelist), M_DRM, M_NOWAIT); + sizeof(*dma->pagelist), DRM_MEM_PAGES, M_NOWAIT); if (entry->buflist == NULL || entry->seglist == NULL || temp_pagelist == NULL) { - free(temp_pagelist, M_DRM); - free(entry->seglist, M_DRM); - free(entry->buflist, M_DRM); + free(temp_pagelist, DRM_MEM_PAGES); + free(entry->seglist, DRM_MEM_SEGS); + free(entry->buflist, DRM_MEM_BUFS); return ENOMEM; } @@ -589,7 +589,7 @@ static int drm_do_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *reque entry->buf_count = count; entry->seg_count = count; drm_cleanup_buf_error(dev, entry); - free(temp_pagelist, M_DRM); + free(temp_pagelist, DRM_MEM_PAGES); return ENOMEM; } @@ -617,14 +617,14 @@ static int drm_do_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *reque buf->file_priv = NULL; buf->dev_priv_size = dev->driver->buf_priv_size; - buf->dev_private = malloc(buf->dev_priv_size, M_DRM, - M_NOWAIT | M_ZERO); + buf->dev_private = malloc(buf->dev_priv_size, + DRM_MEM_BUFS, M_NOWAIT | M_ZERO); if (buf->dev_private == NULL) { /* Set count correctly so we free the proper amount. */ entry->buf_count = count; entry->seg_count = count; drm_cleanup_buf_error(dev, entry); - free(temp_pagelist, M_DRM); + free(temp_pagelist, DRM_MEM_PAGES); return ENOMEM; } @@ -635,12 +635,12 @@ static int drm_do_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *reque } temp_buflist = realloc(dma->buflist, - (dma->buf_count + entry->buf_count) * sizeof(*dma->buflist), M_DRM, - M_NOWAIT); + (dma->buf_count + entry->buf_count) * sizeof(*dma->buflist), + DRM_MEM_BUFS, M_NOWAIT); if (temp_buflist == NULL) { /* Free the entry because it isn't valid */ drm_cleanup_buf_error(dev, entry); - free(temp_pagelist, M_DRM); + free(temp_pagelist, DRM_MEM_PAGES); return ENOMEM; } dma->buflist = temp_buflist; @@ -652,7 +652,7 @@ static int drm_do_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *reque /* No allocations failed, so now we can replace the orginal pagelist * with the new one. */ - free(dma->pagelist, M_DRM); + free(dma->pagelist, DRM_MEM_PAGES); dma->pagelist = temp_pagelist; dma->buf_count += entry->buf_count; @@ -706,7 +706,7 @@ static int drm_do_addbufs_sg(struct drm_device *dev, struct drm_buf_desc *reques entry = &dma->bufs[order]; - entry->buflist = malloc(count * sizeof(*entry->buflist), M_DRM, + entry->buflist = malloc(count * sizeof(*entry->buflist), DRM_MEM_BUFS, M_NOWAIT | M_ZERO); if (entry->buflist == NULL) return ENOMEM; @@ -731,7 +731,7 @@ static int drm_do_addbufs_sg(struct drm_device *dev, struct drm_buf_desc *reques buf->file_priv = NULL; buf->dev_priv_size = dev->driver->buf_priv_size; - buf->dev_private = malloc(buf->dev_priv_size, M_DRM, + buf->dev_private = malloc(buf->dev_priv_size, DRM_MEM_BUFS, M_NOWAIT | M_ZERO); if (buf->dev_private == NULL) { /* Set count correctly so we free the proper amount. */ @@ -751,8 +751,8 @@ static int drm_do_addbufs_sg(struct drm_device *dev, struct drm_buf_desc *reques DRM_DEBUG("byte_count: %d\n", byte_count); temp_buflist = realloc(dma->buflist, - (dma->buf_count + entry->buf_count) * sizeof(*dma->buflist), M_DRM, - M_NOWAIT); + (dma->buf_count + entry->buf_count) * sizeof(*dma->buflist), + DRM_MEM_BUFS, M_NOWAIT); if (temp_buflist == NULL) { /* Free the entry because it isn't valid */ drm_cleanup_buf_error(dev, entry); @@ -1099,11 +1099,12 @@ int drm_mapbufs(struct drm_device *dev, void *data, struct drm_file *file_priv) int drm_order(unsigned long size) { int order; - unsigned long tmp; - for (order = 0, tmp = size; tmp >>= 1; ++order); + if (size == 0) + return 0; - if (size & ~(1 << order)) + order = ffsl(size) - 1; + if (size & ~(1ul << order)) ++order; return order; diff --git a/bsd-core/drm_context.c b/bsd-core/drm_context.c index bca899cb..4dddd9c8 100644 --- a/bsd-core/drm_context.c +++ b/bsd-core/drm_context.c @@ -77,7 +77,7 @@ int drm_ctxbitmap_next(struct drm_device *dev) ctx_sareas = realloc(dev->context_sareas, dev->max_context * sizeof(*dev->context_sareas), - M_DRM, M_NOWAIT); + DRM_MEM_SAREA, M_NOWAIT); if (ctx_sareas == NULL) { clear_bit(bit, dev->ctx_bitmap); DRM_UNLOCK(); @@ -88,7 +88,8 @@ int drm_ctxbitmap_next(struct drm_device *dev) } else { /* max_context == 1 at this point */ dev->context_sareas = malloc(dev->max_context * - sizeof(*dev->context_sareas), M_DRM, M_NOWAIT); + sizeof(*dev->context_sareas), DRM_MEM_SAREA, + M_NOWAIT); if (dev->context_sareas == NULL) { clear_bit(bit, dev->ctx_bitmap); DRM_UNLOCK(); @@ -107,7 +108,8 @@ int drm_ctxbitmap_init(struct drm_device *dev) int temp; DRM_LOCK(); - dev->ctx_bitmap = malloc(PAGE_SIZE, M_DRM, M_NOWAIT | M_ZERO); + dev->ctx_bitmap = malloc(PAGE_SIZE, DRM_MEM_CTXBITMAP, + M_NOWAIT | M_ZERO); if (dev->ctx_bitmap == NULL) { DRM_UNLOCK(); return ENOMEM; @@ -128,8 +130,8 @@ void drm_ctxbitmap_cleanup(struct drm_device *dev) { DRM_LOCK(); if (dev->context_sareas != NULL) - free(dev->context_sareas, M_DRM); - free(dev->ctx_bitmap, M_DRM); + free(dev->context_sareas, DRM_MEM_SAREA); + free(dev->ctx_bitmap, DRM_MEM_CTXBITMAP); DRM_UNLOCK(); } diff --git a/bsd-core/drm_dma.c b/bsd-core/drm_dma.c index 51f60683..c2d9994e 100644 --- a/bsd-core/drm_dma.c +++ b/bsd-core/drm_dma.c @@ -41,7 +41,7 @@ int drm_dma_setup(struct drm_device *dev) { - dev->dma = malloc(sizeof(*dev->dma), M_DRM, M_NOWAIT | M_ZERO); + dev->dma = malloc(sizeof(*dev->dma), DRM_MEM_DRIVER, M_NOWAIT | M_ZERO); if (dev->dma == NULL) return ENOMEM; @@ -67,21 +67,21 @@ void drm_dma_takedown(struct drm_device *dev) for (j = 0; j < dma->bufs[i].seg_count; j++) { drm_pci_free(dev, dma->bufs[i].seglist[j]); } - free(dma->bufs[i].seglist, M_DRM); + free(dma->bufs[i].seglist, DRM_MEM_SEGS); } if (dma->bufs[i].buf_count) { for (j = 0; j < dma->bufs[i].buf_count; j++) { free(dma->bufs[i].buflist[j].dev_private, - M_DRM); + DRM_MEM_BUFS); } - free(dma->bufs[i].buflist, M_DRM); + free(dma->bufs[i].buflist, DRM_MEM_BUFS); } } - free(dma->buflist, M_DRM); - free(dma->pagelist, M_DRM); - free(dev->dma, M_DRM); + free(dma->buflist, DRM_MEM_BUFS); + free(dma->pagelist, DRM_MEM_PAGES); + free(dev->dma, DRM_MEM_DRIVER); dev->dma = NULL; DRM_SPINUNINIT(&dev->dma_lock); } diff --git a/bsd-core/drm_drawable.c b/bsd-core/drm_drawable.c index 018db57d..2ae11dbb 100644 --- a/bsd-core/drm_drawable.c +++ b/bsd-core/drm_drawable.c @@ -71,8 +71,8 @@ int drm_adddraw(struct drm_device *dev, void *data, struct drm_file *file_priv) struct drm_draw *draw = data; struct bsd_drm_drawable_info *info; - info = drm_calloc(1, sizeof(struct bsd_drm_drawable_info), - DRM_MEM_DRAWABLE); + info = malloc(sizeof(struct bsd_drm_drawable_info), DRM_MEM_DRAWABLE, + M_NOWAIT | M_ZERO); if (info == NULL) return ENOMEM; @@ -99,8 +99,8 @@ int drm_rmdraw(struct drm_device *dev, void *data, struct drm_file *file_priv) (struct bsd_drm_drawable_info *)info); DRM_SPINUNLOCK(&dev->drw_lock); free_unr(dev->drw_unrhdr, draw->handle); - drm_free(info, sizeof(struct bsd_drm_drawable_info), - DRM_MEM_DRAWABLE); + free(info->rects, DRM_MEM_DRAWABLE); + free(info, DRM_MEM_DRAWABLE); return 0; } else { DRM_SPINUNLOCK(&dev->drw_lock); @@ -123,9 +123,7 @@ int drm_update_draw(struct drm_device *dev, void *data, case DRM_DRAWABLE_CLIPRECTS: DRM_SPINLOCK(&dev->drw_lock); if (update->num != info->num_rects) { - drm_free(info->rects, - sizeof(*info->rects) * info->num_rects, - DRM_MEM_DRAWABLE); + free(info->rects, DRM_MEM_DRAWABLE); info->rects = NULL; info->num_rects = 0; } @@ -134,8 +132,8 @@ int drm_update_draw(struct drm_device *dev, void *data, return 0; } if (info->rects == NULL) { - info->rects = drm_alloc(sizeof(*info->rects) * - update->num, DRM_MEM_DRAWABLE); + info->rects = malloc(sizeof(*info->rects) * + update->num, DRM_MEM_DRAWABLE, M_NOWAIT); if (info->rects == NULL) { DRM_SPINUNLOCK(&dev->drw_lock); return ENOMEM; @@ -164,8 +162,8 @@ void drm_drawable_free_all(struct drm_device *dev) (struct bsd_drm_drawable_info *)info); DRM_SPINUNLOCK(&dev->drw_lock); free_unr(dev->drw_unrhdr, info->handle); - drm_free(info, sizeof(struct bsd_drm_drawable_info), - DRM_MEM_DRAWABLE); + free(info->info.rects, DRM_MEM_DRAWABLE); + free(info, DRM_MEM_DRAWABLE); DRM_SPINLOCK(&dev->drw_lock); } DRM_SPINUNLOCK(&dev->drw_lock); diff --git a/bsd-core/drm_drv.c b/bsd-core/drm_drv.c index a35d60a7..afcad193 100644 --- a/bsd-core/drm_drv.c +++ b/bsd-core/drm_drv.c @@ -280,7 +280,7 @@ static int drm_lastclose(struct drm_device *dev) drm_irq_uninstall(dev); if (dev->unique) { - free(dev->unique, M_DRM); + free(dev->unique, DRM_MEM_DRIVER); dev->unique = NULL; dev->unique_len = 0; } @@ -288,7 +288,7 @@ static int drm_lastclose(struct drm_device *dev) for (i = 0; i < DRM_HASH_SIZE; i++) { for (pt = dev->magiclist[i].head; pt; pt = next) { next = pt->next; - free(pt, M_DRM); + free(pt, DRM_MEM_MAGIC); } dev->magiclist[i].head = dev->magiclist[i].tail = NULL; } @@ -310,7 +310,7 @@ static int drm_lastclose(struct drm_device *dev) if (entry->bound) drm_agp_unbind_memory(entry->handle); drm_agp_free_memory(entry->handle); - free(entry, M_DRM); + free(entry, DRM_MEM_AGPLISTS); } dev->agp->memory = NULL; @@ -479,7 +479,7 @@ static void drm_unload(struct drm_device *dev) } if (dev->agp) { - free(dev->agp, M_DRM); + free(dev->agp, DRM_MEM_AGPLISTS); dev->agp = NULL; } @@ -534,7 +534,7 @@ int drm_open(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p) struct drm_device *dev = NULL; int retcode = 0; - dev = DRIVER_SOFTC(minor(kdev)); + dev = DRIVER_SOFTC(dev2unit(kdev)); DRM_DEBUG("open_count = %d\n", dev->open_count); @@ -623,7 +623,7 @@ void drm_close(void *data) if (dev->driver->postclose != NULL) dev->driver->postclose(dev, file_priv); TAILQ_REMOVE(&dev->files, file_priv, link); - free(file_priv, M_DRM); + free(file_priv, DRM_MEM_FILES); /* ======================================================== * End inline drm_release diff --git a/bsd-core/drm_fops.c b/bsd-core/drm_fops.c index 6850f489..e4cf8461 100644 --- a/bsd-core/drm_fops.c +++ b/bsd-core/drm_fops.c @@ -41,7 +41,7 @@ int drm_open_helper(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p, struct drm_device *dev) { struct drm_file *priv; - int m = minor(kdev); + int m = dev2unit(kdev); int retcode; if (flags & O_EXCL) @@ -50,14 +50,14 @@ int drm_open_helper(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p, DRM_DEBUG("pid = %d, minor = %d\n", DRM_CURRENTPID, m); - priv = malloc(sizeof(*priv), M_DRM, M_NOWAIT | M_ZERO); + priv = malloc(sizeof(*priv), DRM_MEM_FILES, M_NOWAIT | M_ZERO); if (priv == NULL) { return ENOMEM; } retcode = devfs_set_cdevpriv(priv, drm_close); if (retcode != 0) { - free(priv, M_DRM); + free(priv, DRM_MEM_FILES); return retcode; } @@ -76,7 +76,7 @@ int drm_open_helper(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p, retcode = -dev->driver->open(dev, priv); if (retcode != 0) { devfs_clear_cdevpriv(); - free(priv, M_DRM); + free(priv, DRM_MEM_FILES); DRM_UNLOCK(); return retcode; } diff --git a/bsd-core/drm_ioctl.c b/bsd-core/drm_ioctl.c index 0523291e..cae853ee 100644 --- a/bsd-core/drm_ioctl.c +++ b/bsd-core/drm_ioctl.c @@ -69,12 +69,12 @@ int drm_setunique(struct drm_device *dev, void *data, if (!u->unique_len || u->unique_len > 1024) return EINVAL; - busid = malloc(u->unique_len + 1, M_DRM, M_WAITOK); + busid = malloc(u->unique_len + 1, DRM_MEM_DRIVER, M_WAITOK); if (busid == NULL) return ENOMEM; if (DRM_COPY_FROM_USER(busid, u->unique, u->unique_len)) { - free(busid, M_DRM); + free(busid, DRM_MEM_DRIVER); return EFAULT; } busid[u->unique_len] = '\0'; @@ -84,7 +84,7 @@ int drm_setunique(struct drm_device *dev, void *data, */ ret = sscanf(busid, "PCI:%d:%d:%d", &bus, &slot, &func); if (ret != 3) { - free(busid, M_DRM); + free(busid, DRM_MEM_DRIVER); return EINVAL; } domain = bus >> 8; @@ -94,7 +94,7 @@ int drm_setunique(struct drm_device *dev, void *data, (bus != dev->pci_bus) || (slot != dev->pci_slot) || (func != dev->pci_func)) { - free(busid, M_DRM); + free(busid, DRM_MEM_DRIVER); return EINVAL; } @@ -125,7 +125,7 @@ drm_set_busid(struct drm_device *dev) } dev->unique_len = 20; - dev->unique = malloc(dev->unique_len + 1, M_DRM, M_NOWAIT); + dev->unique = malloc(dev->unique_len + 1, DRM_MEM_DRIVER, M_NOWAIT); if (dev->unique == NULL) { DRM_UNLOCK(); return ENOMEM; diff --git a/bsd-core/drm_irq.c b/bsd-core/drm_irq.c index 00d4b31e..5e99bb33 100644 --- a/bsd-core/drm_irq.c +++ b/bsd-core/drm_irq.c @@ -111,8 +111,7 @@ static void drm_vblank_cleanup(struct drm_device *dev) vblank_disable_fn((void *)dev); - drm_free(dev->vblank, sizeof(struct drm_vblank_info) * dev->num_crtcs, - DRM_MEM_DRIVER); + free(dev->vblank, DRM_MEM_DRIVER); dev->num_crtcs = 0; } @@ -125,8 +124,8 @@ int drm_vblank_init(struct drm_device *dev, int num_crtcs) atomic_set(&dev->vbl_signal_pending, 0); dev->num_crtcs = num_crtcs; - dev->vblank = drm_calloc(num_crtcs, sizeof(struct drm_vblank_info), - DRM_MEM_DRIVER); + dev->vblank = malloc(sizeof(struct drm_vblank_info) * num_crtcs, + DRM_MEM_DRIVER, M_NOWAIT | M_ZERO); if (!dev->vblank) goto err; @@ -429,8 +428,8 @@ int drm_wait_vblank(struct drm_device *dev, void *data, struct drm_file *file_pr if (flags & _DRM_VBLANK_SIGNAL) { #if 0 /* disabled */ - drm_vbl_sig_t *vbl_sig = malloc(sizeof(drm_vbl_sig_t), M_DRM, - M_NOWAIT | M_ZERO); + drm_vbl_sig_t *vbl_sig = malloc(sizeof(drm_vbl_sig_t), + DRM_MEM_DRIVER, M_NOWAIT | M_ZERO); if (vbl_sig == NULL) return ENOMEM; diff --git a/bsd-core/drm_linux_list.h b/bsd-core/drm_linux_list.h index c9f1b3e1..7c6a4474 100644 --- a/bsd-core/drm_linux_list.h +++ b/bsd-core/drm_linux_list.h @@ -66,6 +66,6 @@ list_del(struct list_head *entry) { #define list_for_each_safe(entry, temp, head) \ for (entry = (head)->next, temp = (entry)->next; \ - temp != head; \ - entry = temp, temp = temp->next) + entry != head; \ + entry = temp, temp = entry->next) diff --git a/bsd-core/drm_lock.c b/bsd-core/drm_lock.c index 685b0ea3..dec7281a 100644 --- a/bsd-core/drm_lock.c +++ b/bsd-core/drm_lock.c @@ -102,17 +102,15 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_lock *lock = data; + DRM_DEBUG("%d (pid %d) requests unlock (0x%08x), flags = 0x%08x\n", + lock->context, DRM_CURRENTPID, dev->lock.hw_lock->lock, + lock->flags); + if (lock->context == DRM_KERNEL_CONTEXT) { DRM_ERROR("Process %d using kernel context %d\n", DRM_CURRENTPID, lock->context); return EINVAL; } - /* Check that the context unlock being requested actually matches - * who currently holds the lock. - */ - if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || - _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock) != lock->context) - return EINVAL; DRM_SPINLOCK(&dev->tsk_lock); if (dev->locked_task_call != NULL) { diff --git a/bsd-core/drm_memory.c b/bsd-core/drm_memory.c index 2dfd2b8e..ac43cb0c 100644 --- a/bsd-core/drm_memory.c +++ b/bsd-core/drm_memory.c @@ -38,7 +38,25 @@ #include "drmP.h" -MALLOC_DEFINE(M_DRM, "drm", "DRM Data Structures"); +MALLOC_DEFINE(DRM_MEM_DMA, "drm_dma", "DRM DMA Data Structures"); +MALLOC_DEFINE(DRM_MEM_SAREA, "drm_sarea", "DRM SAREA Data Structures"); +MALLOC_DEFINE(DRM_MEM_DRIVER, "drm_driver", "DRM DRIVER Data Structures"); +MALLOC_DEFINE(DRM_MEM_MAGIC, "drm_magic", "DRM MAGIC Data Structures"); +MALLOC_DEFINE(DRM_MEM_IOCTLS, "drm_ioctls", "DRM IOCTL Data Structures"); +MALLOC_DEFINE(DRM_MEM_MAPS, "drm_maps", "DRM MAP Data Structures"); +MALLOC_DEFINE(DRM_MEM_BUFS, "drm_bufs", "DRM BUFFER Data Structures"); +MALLOC_DEFINE(DRM_MEM_SEGS, "drm_segs", "DRM SEGMENTS Data Structures"); +MALLOC_DEFINE(DRM_MEM_PAGES, "drm_pages", "DRM PAGES Data Structures"); +MALLOC_DEFINE(DRM_MEM_FILES, "drm_files", "DRM FILE Data Structures"); +MALLOC_DEFINE(DRM_MEM_QUEUES, "drm_queues", "DRM QUEUE Data Structures"); +MALLOC_DEFINE(DRM_MEM_CMDS, "drm_cmds", "DRM COMMAND Data Structures"); +MALLOC_DEFINE(DRM_MEM_MAPPINGS, "drm_mapping", "DRM MAPPING Data Structures"); +MALLOC_DEFINE(DRM_MEM_BUFLISTS, "drm_buflists", "DRM BUFLISTS Data Structures"); +MALLOC_DEFINE(DRM_MEM_AGPLISTS, "drm_agplists", "DRM AGPLISTS Data Structures"); +MALLOC_DEFINE(DRM_MEM_CTXBITMAP, "drm_ctxbitmap", + "DRM CTXBITMAP Data Structures"); +MALLOC_DEFINE(DRM_MEM_SGLISTS, "drm_sglists", "DRM SGLISTS Data Structures"); +MALLOC_DEFINE(DRM_MEM_DRAWABLE, "drm_drawable", "DRM DRAWABLE Data Structures"); void drm_mem_init(void) { @@ -48,35 +66,6 @@ void drm_mem_uninit(void) { } -void *drm_alloc(size_t size, int area) -{ - return malloc(size, M_DRM, M_NOWAIT); -} - -void *drm_calloc(size_t nmemb, size_t size, int area) -{ - return malloc(size * nmemb, M_DRM, M_NOWAIT | M_ZERO); -} - -void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area) -{ - void *pt; - - pt = malloc(size, M_DRM, M_NOWAIT); - if (pt == NULL) - return NULL; - if (oldpt && oldsize) { - memcpy(pt, oldpt, DRM_MIN(oldsize,size)); - free(oldpt, M_DRM); - } - return pt; -} - -void drm_free(void *pt, size_t size, int area) -{ - free(pt, M_DRM); -} - void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map) { return pmap_mapdev_attr(map->offset, map->size, PAT_WRITE_COMBINING); diff --git a/bsd-core/drm_pci.c b/bsd-core/drm_pci.c index e21715b2..5a3cb61b 100644 --- a/bsd-core/drm_pci.c +++ b/bsd-core/drm_pci.c @@ -64,7 +64,7 @@ drm_pci_alloc(struct drm_device *dev, size_t size, return NULL; } - dmah = malloc(sizeof(drm_dma_handle_t), M_DRM, M_ZERO | M_NOWAIT); + dmah = malloc(sizeof(drm_dma_handle_t), DRM_MEM_DMA, M_ZERO | M_NOWAIT); if (dmah == NULL) return NULL; @@ -83,7 +83,7 @@ drm_pci_alloc(struct drm_device *dev, size_t size, BUS_DMA_ALLOCNOW, NULL, NULL, /* flags, lockfunc, lockfuncargs */ &dmah->tag); if (ret != 0) { - free(dmah, M_DRM); + free(dmah, DRM_MEM_DMA); return NULL; } @@ -91,7 +91,7 @@ drm_pci_alloc(struct drm_device *dev, size_t size, &dmah->map); if (ret != 0) { bus_dma_tag_destroy(dmah->tag); - free(dmah, M_DRM); + free(dmah, DRM_MEM_DMA); return NULL; } @@ -100,7 +100,7 @@ drm_pci_alloc(struct drm_device *dev, size_t size, if (ret != 0) { bus_dmamem_free(dmah->tag, dmah->vaddr, dmah->map); bus_dma_tag_destroy(dmah->tag); - free(dmah, M_DRM); + free(dmah, DRM_MEM_DMA); return NULL; } @@ -119,7 +119,7 @@ drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah) bus_dmamem_free(dmah->tag, dmah->vaddr, dmah->map); bus_dma_tag_destroy(dmah->tag); - free(dmah, M_DRM); + free(dmah, DRM_MEM_DMA); } /*@}*/ diff --git a/bsd-core/drm_scatter.c b/bsd-core/drm_scatter.c index 550e6f88..7d47e605 100644 --- a/bsd-core/drm_scatter.c +++ b/bsd-core/drm_scatter.c @@ -40,9 +40,9 @@ void drm_sg_cleanup(drm_sg_mem_t *entry) { - free((void *)entry->handle, M_DRM); - free(entry->busaddr, M_DRM); - free(entry, M_DRM); + free((void *)entry->handle, DRM_MEM_PAGES); + free(entry->busaddr, DRM_MEM_PAGES); + free(entry, DRM_MEM_SGLISTS); } int drm_sg_alloc(struct drm_device * dev, struct drm_scatter_gather * request) @@ -54,7 +54,7 @@ int drm_sg_alloc(struct drm_device * dev, struct drm_scatter_gather * request) if (dev->sg) return EINVAL; - entry = malloc(sizeof(*entry), M_DRM, M_WAITOK | M_ZERO); + entry = malloc(sizeof(*entry), DRM_MEM_SGLISTS, M_WAITOK | M_ZERO); if (!entry) return ENOMEM; @@ -63,14 +63,14 @@ int drm_sg_alloc(struct drm_device * dev, struct drm_scatter_gather * request) entry->pages = pages; - entry->busaddr = malloc(pages * sizeof(*entry->busaddr), M_DRM, + entry->busaddr = malloc(pages * sizeof(*entry->busaddr), DRM_MEM_PAGES, M_WAITOK | M_ZERO); if (!entry->busaddr) { drm_sg_cleanup(entry); return ENOMEM; } - entry->handle = (long)malloc(pages << PAGE_SHIFT, M_DRM, + entry->handle = (long)malloc(pages << PAGE_SHIFT, DRM_MEM_PAGES, M_WAITOK | M_ZERO); if (entry->handle == 0) { drm_sg_cleanup(entry); diff --git a/bsd-core/drm_sysctl.c b/bsd-core/drm_sysctl.c index f9cfd9cf..f0227aa7 100644 --- a/bsd-core/drm_sysctl.c +++ b/bsd-core/drm_sysctl.c @@ -59,7 +59,7 @@ int drm_sysctl_init(struct drm_device *dev) struct sysctl_oid *top, *drioid; int i; - info = malloc(sizeof *info, M_DRM, M_WAITOK | M_ZERO); + info = malloc(sizeof *info, DRM_MEM_DRIVER, M_WAITOK | M_ZERO); if ( !info ) return 1; dev->sysctl = info; @@ -111,7 +111,7 @@ int drm_sysctl_cleanup(struct drm_device *dev) int error; error = sysctl_ctx_free( &dev->sysctl->ctx ); - free(dev->sysctl, M_DRM); + free(dev->sysctl, DRM_MEM_DRIVER); dev->sysctl = NULL; return error; @@ -169,7 +169,8 @@ static int drm_vm_info DRM_SYSCTL_HANDLER_ARGS TAILQ_FOREACH(map, &dev->maplist, link) mapcount++; - tempmaps = malloc(sizeof(drm_local_map_t) * mapcount, M_DRM, M_NOWAIT); + tempmaps = malloc(sizeof(drm_local_map_t) * mapcount, DRM_MEM_DRIVER, + M_NOWAIT); if (tempmaps == NULL) { DRM_UNLOCK(); return ENOMEM; @@ -205,7 +206,7 @@ static int drm_vm_info DRM_SYSCTL_HANDLER_ARGS SYSCTL_OUT(req, "", 1); done: - free(tempmaps, M_DRM); + free(tempmaps, DRM_MEM_DRIVER); return retcode; } @@ -229,7 +230,8 @@ static int drm_bufs_info DRM_SYSCTL_HANDLER_ARGS } DRM_SPINLOCK(&dev->dma_lock); tempdma = *dma; - templists = malloc(sizeof(int) * dma->buf_count, M_DRM, M_NOWAIT); + templists = malloc(sizeof(int) * dma->buf_count, DRM_MEM_DRIVER, + M_NOWAIT); for (i = 0; i < dma->buf_count; i++) templists[i] = dma->buflist[i]->list; dma = &tempdma; @@ -261,7 +263,7 @@ static int drm_bufs_info DRM_SYSCTL_HANDLER_ARGS SYSCTL_OUT(req, "", 1); done: - free(templists, M_DRM); + free(templists, DRM_MEM_DRIVER); return retcode; } @@ -279,7 +281,8 @@ static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS TAILQ_FOREACH(priv, &dev->files, link) privcount++; - tempprivs = malloc(sizeof(struct drm_file) * privcount, M_DRM, M_NOWAIT); + tempprivs = malloc(sizeof(struct drm_file) * privcount, DRM_MEM_DRIVER, + M_NOWAIT); if (tempprivs == NULL) { DRM_UNLOCK(); return ENOMEM; @@ -304,6 +307,6 @@ static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS SYSCTL_OUT(req, "", 1); done: - free(tempprivs, M_DRM); + free(tempprivs, DRM_MEM_DRIVER); return retcode; } diff --git a/bsd-core/drm_vm.c b/bsd-core/drm_vm.c index 8ee49a28..4bc6f46a 100644 --- a/bsd-core/drm_vm.c +++ b/bsd-core/drm_vm.c @@ -32,20 +32,23 @@ int drm_mmap(struct cdev *kdev, vm_offset_t offset, vm_paddr_t *paddr, int prot) { struct drm_device *dev = drm_get_device_from_kdev(kdev); - struct drm_file *file_priv; + struct drm_file *file_priv = NULL; drm_local_map_t *map; enum drm_map_type type; vm_paddr_t phys; + int error; - DRM_LOCK(); - TAILQ_FOREACH(file_priv, &dev->files, link) - if (file_priv->pid == curthread->td_proc->p_pid && - file_priv->uid == curthread->td_ucred->cr_svuid && - file_priv->authenticated == 1) - break; - DRM_UNLOCK(); + /* d_mmap gets called twice, we can only reference file_priv during + * the first call. We need to assume that if error is EBADF the + * call was succesful and the client is authenticated. + */ + error = devfs_get_cdevpriv((void **)&file_priv); + if (error == ENOENT) { + DRM_ERROR("Could not find authenticator!\n"); + return EINVAL; + } - if (!file_priv) + if (file_priv && !file_priv->authenticated) return EACCES; if (dev->dma && offset >= 0 && offset < ptoa(dev->dma->page_count)) { diff --git a/bsd-core/i915_drv.c b/bsd-core/i915_drv.c index def35f0b..0c36a6f1 100644 --- a/bsd-core/i915_drv.c +++ b/bsd-core/i915_drv.c @@ -109,9 +109,9 @@ i915_attach(device_t nbdev) { struct drm_device *dev = device_get_softc(nbdev); - bzero(dev, sizeof(struct drm_device)); + dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER, + M_WAITOK | M_ZERO); - dev->driver = malloc(sizeof(struct drm_driver_info), M_DRM, M_NOWAIT | M_ZERO); i915_configure(dev); return drm_attach(nbdev, i915_pciidlist); @@ -125,7 +125,7 @@ i915_detach(device_t nbdev) ret = drm_detach(nbdev); - free(dev->driver, M_DRM); + free(dev->driver, DRM_MEM_DRIVER); return ret; } diff --git a/bsd-core/mach64_drv.c b/bsd-core/mach64_drv.c index adb83d3a..1cbe5f39 100644 --- a/bsd-core/mach64_drv.c +++ b/bsd-core/mach64_drv.c @@ -83,9 +83,9 @@ mach64_attach(device_t nbdev) { struct drm_device *dev = device_get_softc(nbdev); - bzero(dev, sizeof(struct drm_device)); + dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER, + M_WAITOK | M_ZERO); - dev->driver = malloc(sizeof(struct drm_driver_info), M_DRM, M_NOWAIT | M_ZERO); mach64_configure(dev); return drm_attach(nbdev, mach64_pciidlist); @@ -99,7 +99,7 @@ mach64_detach(device_t nbdev) ret = drm_detach(nbdev); - free(dev->driver, M_DRM); + free(dev->driver, DRM_MEM_DRIVER); return ret; } diff --git a/bsd-core/mga_drv.c b/bsd-core/mga_drv.c index 5554236a..af250e83 100644 --- a/bsd-core/mga_drv.c +++ b/bsd-core/mga_drv.c @@ -127,9 +127,9 @@ mga_attach(device_t nbdev) { struct drm_device *dev = device_get_softc(nbdev); - bzero(dev, sizeof(struct drm_device)); + dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER, + M_WAITOK | M_ZERO); - dev->driver = malloc(sizeof(struct drm_driver_info), M_DRM, M_NOWAIT | M_ZERO); mga_configure(dev); return drm_attach(nbdev, mga_pciidlist); @@ -143,7 +143,7 @@ mga_detach(device_t nbdev) ret = drm_detach(nbdev); - free(dev->driver, M_DRM); + free(dev->driver, DRM_MEM_DRIVER); return ret; } diff --git a/bsd-core/r128_drv.c b/bsd-core/r128_drv.c index 4c20af4d..3dbf66eb 100644 --- a/bsd-core/r128_drv.c +++ b/bsd-core/r128_drv.c @@ -82,9 +82,9 @@ r128_attach(device_t nbdev) { struct drm_device *dev = device_get_softc(nbdev); - bzero(dev, sizeof(struct drm_device)); + dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER, + M_WAITOK | M_ZERO); - dev->driver = malloc(sizeof(struct drm_driver_info), M_DRM, M_NOWAIT | M_ZERO); r128_configure(dev); return drm_attach(nbdev, r128_pciidlist); @@ -98,7 +98,7 @@ r128_detach(device_t nbdev) ret = drm_detach(nbdev); - free(dev->driver, M_DRM); + free(dev->driver, DRM_MEM_DRIVER); return ret; } diff --git a/bsd-core/radeon_drv.c b/bsd-core/radeon_drv.c index 8ab3e995..46bccb39 100644 --- a/bsd-core/radeon_drv.c +++ b/bsd-core/radeon_drv.c @@ -87,9 +87,9 @@ radeon_attach(device_t nbdev) { struct drm_device *dev = device_get_softc(nbdev); - bzero(dev, sizeof(struct drm_device)); + dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER, + M_WAITOK | M_ZERO); - dev->driver = malloc(sizeof(struct drm_driver_info), M_DRM, M_NOWAIT | M_ZERO); radeon_configure(dev); return drm_attach(nbdev, radeon_pciidlist); @@ -103,7 +103,7 @@ radeon_detach(device_t nbdev) ret = drm_detach(nbdev); - free(dev->driver, M_DRM); + free(dev->driver, DRM_MEM_DRIVER); return ret; } diff --git a/bsd-core/savage_drv.c b/bsd-core/savage_drv.c index 35fcdfa3..96643aae 100644 --- a/bsd-core/savage_drv.c +++ b/bsd-core/savage_drv.c @@ -73,9 +73,9 @@ savage_attach(device_t nbdev) { struct drm_device *dev = device_get_softc(nbdev); - bzero(dev, sizeof(struct drm_device)); + dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER, + M_WAITOK | M_ZERO); - dev->driver = malloc(sizeof(struct drm_driver_info), M_DRM, M_NOWAIT | M_ZERO); savage_configure(dev); return drm_attach(nbdev, savage_pciidlist); @@ -89,7 +89,7 @@ savage_detach(device_t nbdev) ret = drm_detach(nbdev); - free(dev->driver, M_DRM); + free(dev->driver, DRM_MEM_DRIVER); return ret; } diff --git a/bsd-core/sis_drv.c b/bsd-core/sis_drv.c index 2ae1bff0..2b6be29f 100644 --- a/bsd-core/sis_drv.c +++ b/bsd-core/sis_drv.c @@ -67,9 +67,9 @@ sis_attach(device_t nbdev) { struct drm_device *dev = device_get_softc(nbdev); - bzero(dev, sizeof(struct drm_device)); + dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER, + M_WAITOK | M_ZERO); - dev->driver = malloc(sizeof(struct drm_driver_info), M_DRM, M_NOWAIT | M_ZERO); sis_configure(dev); return drm_attach(nbdev, sis_pciidlist); @@ -83,7 +83,7 @@ sis_detach(device_t nbdev) ret = drm_detach(nbdev); - free(dev->driver, M_DRM); + free(dev->driver, DRM_MEM_DRIVER); return ret; } diff --git a/bsd-core/tdfx_drv.c b/bsd-core/tdfx_drv.c index 44948b5c..775efcc1 100644 --- a/bsd-core/tdfx_drv.c +++ b/bsd-core/tdfx_drv.c @@ -69,9 +69,9 @@ tdfx_attach(device_t nbdev) { struct drm_device *dev = device_get_softc(nbdev); - bzero(dev, sizeof(struct drm_device)); + dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER, + M_WAITOK | M_ZERO); - dev->driver = malloc(sizeof(struct drm_driver_info), M_DRM, M_NOWAIT | M_ZERO); tdfx_configure(dev); return drm_attach(nbdev, tdfx_pciidlist); @@ -85,7 +85,7 @@ tdfx_detach(device_t nbdev) ret = drm_detach(nbdev); - free(dev->driver, M_DRM); + free(dev->driver, DRM_MEM_DRIVER); return ret; } diff --git a/bsd-core/via_drv.c b/bsd-core/via_drv.c index e5f7d493..cae7231c 100644 --- a/bsd-core/via_drv.c +++ b/bsd-core/via_drv.c @@ -80,9 +80,9 @@ via_attach(device_t nbdev) { struct drm_device *dev = device_get_softc(nbdev); - bzero(dev, sizeof(struct drm_device)); + dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER, + M_WAITOK | M_ZERO); - dev->driver = malloc(sizeof(struct drm_driver_info), M_DRM, M_NOWAIT | M_ZERO); via_configure(dev); return drm_attach(nbdev, via_pciidlist); @@ -96,7 +96,7 @@ via_detach(device_t nbdev) ret = drm_detach(nbdev); - free(dev->driver, M_DRM); + free(dev->driver, DRM_MEM_DRIVER); return ret; } |