diff options
author | Ian Romanick <idr@us.ibm.com> | 2007-07-26 16:58:28 -0700 |
---|---|---|
committer | Ian Romanick <idr@us.ibm.com> | 2007-07-26 16:58:28 -0700 |
commit | c561cb4650dc5895acfb3ae00c7ff455be31a860 (patch) | |
tree | 65b21097253d216e0385778597031ae288e34023 /bsd-core/drm_bufs.c | |
parent | 2bafeb673f14b1e3799bf00817138c0b8211635e (diff) | |
parent | 4175dd818110bd10d6d09190d30c271e89202b18 (diff) |
Merge branch 'master' of ssh+git://git.freedesktop.org/git/mesa/drm into xgi-0-0-2
Conflicts:
linux-core/drmP.h
linux-core/drm_scatter.c
Diffstat (limited to 'bsd-core/drm_bufs.c')
-rw-r--r-- | bsd-core/drm_bufs.c | 239 |
1 files changed, 105 insertions, 134 deletions
diff --git a/bsd-core/drm_bufs.c b/bsd-core/drm_bufs.c index 343ab1e8..a0a3fc73 100644 --- a/bsd-core/drm_bufs.c +++ b/bsd-core/drm_bufs.c @@ -149,7 +149,7 @@ int drm_addmap(drm_device_t * dev, unsigned long offset, unsigned long size, */ map = malloc(sizeof(*map), M_DRM, M_ZERO | M_NOWAIT); if ( !map ) - return DRM_ERR(ENOMEM); + return ENOMEM; map->offset = offset; map->size = size; @@ -172,7 +172,7 @@ int drm_addmap(drm_device_t * dev, unsigned long offset, unsigned long size, map->size, drm_order(map->size), map->handle ); if ( !map->handle ) { free(map, M_DRM); - return DRM_ERR(ENOMEM); + return ENOMEM; } map->offset = (unsigned long)map->handle; if ( map->flags & _DRM_CONTAINS_LOCK ) { @@ -182,7 +182,7 @@ int drm_addmap(drm_device_t * dev, unsigned long offset, unsigned long size, DRM_UNLOCK(); free(map->handle, M_DRM); free(map, M_DRM); - return DRM_ERR(EBUSY); + return EBUSY; } dev->lock.hw_lock = map->handle; /* Pointer to lock */ DRM_UNLOCK(); @@ -202,13 +202,13 @@ int drm_addmap(drm_device_t * dev, unsigned long offset, unsigned long size, } if (!valid) { free(map, M_DRM); - return DRM_ERR(EACCES); + return EACCES; }*/ break; case _DRM_SCATTER_GATHER: if (!dev->sg) { free(map, M_DRM); - return DRM_ERR(EINVAL); + return EINVAL; } map->offset = map->offset + dev->sg->handle; break; @@ -225,7 +225,7 @@ int drm_addmap(drm_device_t * dev, unsigned long offset, unsigned long size, map->dmah = drm_pci_alloc(dev, map->size, align, 0xfffffffful); if (map->dmah == NULL) { free(map, M_DRM); - return DRM_ERR(ENOMEM); + return ENOMEM; } map->handle = map->dmah->vaddr; map->offset = map->dmah->busaddr; @@ -233,7 +233,7 @@ int drm_addmap(drm_device_t * dev, unsigned long offset, unsigned long size, default: DRM_ERROR("Bad map type %d\n", map->type); free(map, M_DRM); - return DRM_ERR(EINVAL); + return EINVAL; } DRM_LOCK(); @@ -250,39 +250,35 @@ done: return 0; } -int drm_addmap_ioctl(DRM_IOCTL_ARGS) +int drm_addmap_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv) { - drm_map_t request; + drm_map_t *request = data; drm_local_map_t *map; int err; - DRM_DEVICE; if (!(dev->flags & (FREAD|FWRITE))) - return DRM_ERR(EACCES); /* Require read/write */ - - DRM_COPY_FROM_USER_IOCTL(request, (drm_map_t *)data, sizeof(drm_map_t)); + return EACCES; /* Require read/write */ - if (!DRM_SUSER(p) && request.type != _DRM_AGP) - return DRM_ERR(EACCES); + if (!DRM_SUSER(DRM_CURPROC) && request->type != _DRM_AGP) + return EACCES; DRM_LOCK(); - err = drm_addmap(dev, request.offset, request.size, request.type, - request.flags, &map); + err = drm_addmap(dev, request->offset, request->size, request->type, + request->flags, &map); DRM_UNLOCK(); if (err != 0) return err; - request.offset = map->offset; - request.size = map->size; - request.type = map->type; - request.flags = map->flags; - request.mtrr = map->mtrr; - request.handle = map->handle; + request->offset = map->offset; + request->size = map->size; + request->type = map->type; + request->flags = map->flags; + request->mtrr = map->mtrr; + request->handle = map->handle; - if (request.type != _DRM_SHM) { - request.handle = (void *)request.offset; + if (request->type != _DRM_SHM) { + request->handle = (void *)request->offset; } - DRM_COPY_TO_USER_IOCTL((drm_map_t *)data, request, sizeof(drm_map_t)); return 0; } @@ -333,17 +329,14 @@ void drm_rmmap(drm_device_t *dev, drm_local_map_t *map) * isn't in use. */ -int drm_rmmap_ioctl(DRM_IOCTL_ARGS) +int drm_rmmap_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv) { - DRM_DEVICE; drm_local_map_t *map; - drm_map_t request; - - DRM_COPY_FROM_USER_IOCTL( request, (drm_map_t *)data, sizeof(request) ); + drm_map_t *request = data; DRM_LOCK(); TAILQ_FOREACH(map, &dev->maplist, link) { - if (map->handle == request.handle && + if (map->handle == request->handle && map->flags & _DRM_REMOVABLE) break; } @@ -351,7 +344,7 @@ int drm_rmmap_ioctl(DRM_IOCTL_ARGS) /* No match found. */ if (map == NULL) { DRM_UNLOCK(); - return DRM_ERR(EINVAL); + return EINVAL; } drm_rmmap(dev, map); @@ -441,7 +434,7 @@ static int drm_do_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request) } if (!valid) { DRM_DEBUG("zone invalid\n"); - return DRM_ERR(EINVAL); + return EINVAL; }*/ entry = &dma->bufs[order]; @@ -449,7 +442,7 @@ static int drm_do_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request) entry->buflist = malloc(count * sizeof(*entry->buflist), M_DRM, M_NOWAIT | M_ZERO); if ( !entry->buflist ) { - return DRM_ERR(ENOMEM); + return ENOMEM; } entry->buf_size = size; @@ -469,7 +462,7 @@ static int drm_do_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request) buf->address = (void *)(agp_offset + offset); buf->next = NULL; buf->pending = 0; - buf->filp = NULL; + buf->file_priv = NULL; buf->dev_priv_size = dev->driver.buf_priv_size; buf->dev_private = malloc(buf->dev_priv_size, M_DRM, @@ -478,7 +471,7 @@ static int drm_do_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request) /* Set count correctly so we free the proper amount. */ entry->buf_count = count; drm_cleanup_buf_error(dev, entry); - return DRM_ERR(ENOMEM); + return ENOMEM; } offset += alignment; @@ -494,7 +487,7 @@ static int drm_do_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request) if (temp_buflist == NULL) { /* Free the entry because it isn't valid */ drm_cleanup_buf_error(dev, entry); - return DRM_ERR(ENOMEM); + return ENOMEM; } dma->buflist = temp_buflist; @@ -563,7 +556,7 @@ static int drm_do_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request) temp_pagelist == NULL) { free(entry->buflist, M_DRM); free(entry->seglist, M_DRM); - return DRM_ERR(ENOMEM); + return ENOMEM; } memcpy(temp_pagelist, dma->pagelist, dma->page_count * @@ -586,7 +579,7 @@ static int drm_do_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request) entry->seg_count = count; drm_cleanup_buf_error(dev, entry); free(temp_pagelist, M_DRM); - return DRM_ERR(ENOMEM); + return ENOMEM; } entry->seglist[entry->seg_count++] = dmah; @@ -610,7 +603,7 @@ static int drm_do_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request) buf->bus_address = dmah->busaddr + offset; buf->next = NULL; buf->pending = 0; - buf->filp = NULL; + buf->file_priv = NULL; buf->dev_priv_size = dev->driver.buf_priv_size; buf->dev_private = malloc(buf->dev_priv_size, M_DRM, @@ -621,7 +614,7 @@ static int drm_do_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request) entry->seg_count = count; drm_cleanup_buf_error(dev, entry); free(temp_pagelist, M_DRM); - return DRM_ERR(ENOMEM); + return ENOMEM; } DRM_DEBUG( "buffer %d @ %p\n", @@ -637,7 +630,7 @@ static int drm_do_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request) /* Free the entry because it isn't valid */ drm_cleanup_buf_error(dev, entry); free(temp_pagelist, M_DRM); - return DRM_ERR(ENOMEM); + return ENOMEM; } dma->buflist = temp_buflist; @@ -705,7 +698,7 @@ static int drm_do_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request) entry->buflist = malloc(count * sizeof(*entry->buflist), M_DRM, M_NOWAIT | M_ZERO); if (entry->buflist == NULL) - return DRM_ERR(ENOMEM); + return ENOMEM; entry->buf_size = size; entry->page_order = page_order; @@ -724,7 +717,7 @@ static int drm_do_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request) buf->address = (void *)(agp_offset + offset + dev->sg->handle); buf->next = NULL; buf->pending = 0; - buf->filp = NULL; + buf->file_priv = NULL; buf->dev_priv_size = dev->driver.buf_priv_size; buf->dev_private = malloc(buf->dev_priv_size, M_DRM, @@ -733,7 +726,7 @@ static int drm_do_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request) /* Set count correctly so we free the proper amount. */ entry->buf_count = count; drm_cleanup_buf_error(dev, entry); - return DRM_ERR(ENOMEM); + return ENOMEM; } DRM_DEBUG( "buffer %d @ %p\n", @@ -752,7 +745,7 @@ static int drm_do_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request) if (temp_buflist == NULL) { /* Free the entry because it isn't valid */ drm_cleanup_buf_error(dev, entry); - return DRM_ERR(ENOMEM); + return ENOMEM; } dma->buflist = temp_buflist; @@ -781,21 +774,21 @@ int drm_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request) DRM_SPINLOCK(&dev->dma_lock); if (request->count < 0 || request->count > 4096) - return DRM_ERR(EINVAL); + return EINVAL; order = drm_order(request->size); if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER) - return DRM_ERR(EINVAL); + return EINVAL; /* No more allocations after first buffer-using ioctl. */ if (dev->buf_use != 0) { DRM_SPINUNLOCK(&dev->dma_lock); - return DRM_ERR(EBUSY); + return EBUSY; } /* No more than one allocation per order */ if (dev->dma->bufs[order].buf_count != 0) { DRM_SPINUNLOCK(&dev->dma_lock); - return DRM_ERR(ENOMEM); + return ENOMEM; } ret = drm_do_addbufs_agp(dev, request); @@ -812,24 +805,24 @@ int drm_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request) DRM_SPINLOCK(&dev->dma_lock); if (!DRM_SUSER(DRM_CURPROC)) - return DRM_ERR(EACCES); + return EACCES; if (request->count < 0 || request->count > 4096) - return DRM_ERR(EINVAL); + return EINVAL; order = drm_order(request->size); if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER) - return DRM_ERR(EINVAL); + return EINVAL; /* No more allocations after first buffer-using ioctl. */ if (dev->buf_use != 0) { DRM_SPINUNLOCK(&dev->dma_lock); - return DRM_ERR(EBUSY); + return EBUSY; } /* No more than one allocation per order */ if (dev->dma->bufs[order].buf_count != 0) { DRM_SPINUNLOCK(&dev->dma_lock); - return DRM_ERR(ENOMEM); + return ENOMEM; } ret = drm_do_addbufs_sg(dev, request); @@ -846,24 +839,24 @@ int drm_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request) DRM_SPINLOCK(&dev->dma_lock); if (!DRM_SUSER(DRM_CURPROC)) - return DRM_ERR(EACCES); + return EACCES; if (request->count < 0 || request->count > 4096) - return DRM_ERR(EINVAL); + return EINVAL; order = drm_order(request->size); if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER) - return DRM_ERR(EINVAL); + return EINVAL; /* No more allocations after first buffer-using ioctl. */ if (dev->buf_use != 0) { DRM_SPINUNLOCK(&dev->dma_lock); - return DRM_ERR(EBUSY); + return EBUSY; } /* No more than one allocation per order */ if (dev->dma->bufs[order].buf_count != 0) { DRM_SPINUNLOCK(&dev->dma_lock); - return DRM_ERR(ENOMEM); + return ENOMEM; } ret = drm_do_addbufs_pci(dev, request); @@ -873,39 +866,29 @@ int drm_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request) return ret; } -int drm_addbufs_ioctl(DRM_IOCTL_ARGS) +int drm_addbufs_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv) { - DRM_DEVICE; - drm_buf_desc_t request; + drm_buf_desc_t *request = data; int err; - DRM_COPY_FROM_USER_IOCTL(request, (drm_buf_desc_t *)data, - sizeof(request)); - - if (request.flags & _DRM_AGP_BUFFER) - err = drm_addbufs_agp(dev, &request); - else if (request.flags & _DRM_SG_BUFFER) - err = drm_addbufs_sg(dev, &request); + if (request->flags & _DRM_AGP_BUFFER) + err = drm_addbufs_agp(dev, request); + else if (request->flags & _DRM_SG_BUFFER) + err = drm_addbufs_sg(dev, request); else - err = drm_addbufs_pci(dev, &request); - - DRM_COPY_TO_USER_IOCTL((drm_buf_desc_t *)data, request, - sizeof(request)); + err = drm_addbufs_pci(dev, request); return err; } -int drm_infobufs(DRM_IOCTL_ARGS) +int drm_infobufs(drm_device_t *dev, void *data, struct drm_file *file_priv) { - DRM_DEVICE; drm_device_dma_t *dma = dev->dma; - drm_buf_info_t request; + drm_buf_info_t *request = data; int i; int count; int retcode = 0; - DRM_COPY_FROM_USER_IOCTL( request, (drm_buf_info_t *)data, sizeof(request) ); - DRM_SPINLOCK(&dev->dma_lock); ++dev->buf_use; /* Can't allocate more after this call */ DRM_SPINUNLOCK(&dev->dma_lock); @@ -916,7 +899,7 @@ int drm_infobufs(DRM_IOCTL_ARGS) DRM_DEBUG( "count = %d\n", count ); - if ( request.count >= count ) { + if ( request->count >= count ) { for ( i = 0, count = 0 ; i < DRM_MAX_ORDER + 1 ; i++ ) { if ( dma->bufs[i].buf_count ) { drm_buf_desc_t from; @@ -926,9 +909,9 @@ int drm_infobufs(DRM_IOCTL_ARGS) from.low_mark = dma->bufs[i].freelist.low_mark; from.high_mark = dma->bufs[i].freelist.high_mark; - if (DRM_COPY_TO_USER(&request.list[count], &from, + if (DRM_COPY_TO_USER(&request->list[count], &from, sizeof(drm_buf_desc_t)) != 0) { - retcode = DRM_ERR(EFAULT); + retcode = EFAULT; break; } @@ -942,76 +925,68 @@ int drm_infobufs(DRM_IOCTL_ARGS) } } } - request.count = count; - - DRM_COPY_TO_USER_IOCTL( (drm_buf_info_t *)data, request, sizeof(request) ); + request->count = count; return retcode; } -int drm_markbufs(DRM_IOCTL_ARGS) +int drm_markbufs(drm_device_t *dev, void *data, struct drm_file *file_priv) { - DRM_DEVICE; drm_device_dma_t *dma = dev->dma; - drm_buf_desc_t request; + drm_buf_desc_t *request = data; int order; - DRM_COPY_FROM_USER_IOCTL( request, (drm_buf_desc_t *)data, sizeof(request) ); - DRM_DEBUG( "%d, %d, %d\n", - request.size, request.low_mark, request.high_mark ); + request->size, request->low_mark, request->high_mark ); - order = drm_order(request.size); + order = drm_order(request->size); if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER || - request.low_mark < 0 || request.high_mark < 0) { - return DRM_ERR(EINVAL); + request->low_mark < 0 || request->high_mark < 0) { + return EINVAL; } DRM_SPINLOCK(&dev->dma_lock); - if (request.low_mark > dma->bufs[order].buf_count || - request.high_mark > dma->bufs[order].buf_count) { - return DRM_ERR(EINVAL); + if (request->low_mark > dma->bufs[order].buf_count || + request->high_mark > dma->bufs[order].buf_count) { + return EINVAL; } - dma->bufs[order].freelist.low_mark = request.low_mark; - dma->bufs[order].freelist.high_mark = request.high_mark; + dma->bufs[order].freelist.low_mark = request->low_mark; + dma->bufs[order].freelist.high_mark = request->high_mark; DRM_SPINUNLOCK(&dev->dma_lock); return 0; } -int drm_freebufs(DRM_IOCTL_ARGS) +int drm_freebufs(drm_device_t *dev, void *data, struct drm_file *file_priv) { - DRM_DEVICE; drm_device_dma_t *dma = dev->dma; - drm_buf_free_t request; + drm_buf_free_t *request = data; int i; int idx; drm_buf_t *buf; int retcode = 0; - DRM_COPY_FROM_USER_IOCTL( request, (drm_buf_free_t *)data, sizeof(request) ); - - DRM_DEBUG( "%d\n", request.count ); + DRM_DEBUG( "%d\n", request->count ); DRM_SPINLOCK(&dev->dma_lock); - for ( i = 0 ; i < request.count ; i++ ) { - if (DRM_COPY_FROM_USER(&idx, &request.list[i], sizeof(idx))) { - retcode = DRM_ERR(EFAULT); + for ( i = 0 ; i < request->count ; i++ ) { + if (DRM_COPY_FROM_USER(&idx, &request->list[i], sizeof(idx))) { + retcode = EFAULT; break; } if ( idx < 0 || idx >= dma->buf_count ) { DRM_ERROR( "Index %d (of %d max)\n", idx, dma->buf_count - 1 ); - retcode = DRM_ERR(EINVAL); + retcode = EINVAL; break; } buf = dma->buflist[idx]; - if ( buf->filp != filp ) { + if ( buf->file_priv != file_priv ) { DRM_ERROR("Process %d freeing buffer not owned\n", DRM_CURRENTPID); - retcode = DRM_ERR(EINVAL); + retcode = EINVAL; break; } drm_free_buffer(dev, buf); @@ -1021,9 +996,8 @@ int drm_freebufs(DRM_IOCTL_ARGS) return retcode; } -int drm_mapbufs(DRM_IOCTL_ARGS) +int drm_mapbufs(drm_device_t *dev, void *data, struct drm_file *file_priv) { - DRM_DEVICE; drm_device_dma_t *dma = dev->dma; int retcode = 0; const int zero = 0; @@ -1040,27 +1014,25 @@ int drm_mapbufs(DRM_IOCTL_ARGS) vaddr_t vaddr; #endif /* __NetBSD__ || __OpenBSD__ */ - drm_buf_map_t request; + drm_buf_map_t *request = data; int i; - DRM_COPY_FROM_USER_IOCTL( request, (drm_buf_map_t *)data, sizeof(request) ); - #if defined(__NetBSD__) || defined(__OpenBSD__) if (!vfinddev(kdev, VCHR, &vn)) return 0; /* FIXME: Shouldn't this be EINVAL or something? */ #endif /* __NetBSD__ || __OpenBSD */ #if defined(__FreeBSD__) && __FreeBSD_version >= 500000 - vms = p->td_proc->p_vmspace; + vms = DRM_CURPROC->td_proc->p_vmspace; #else - vms = p->p_vmspace; + vms = DRM_CURPROC->p_vmspace; #endif DRM_SPINLOCK(&dev->dma_lock); dev->buf_use++; /* Can't allocate more after this call */ DRM_SPINUNLOCK(&dev->dma_lock); - if (request.count < dma->buf_count) + if (request->count < dma->buf_count) goto done; if ((dev->driver.use_agp && (dma->flags & _DRM_DMA_USE_AGP)) || @@ -1082,10 +1054,11 @@ int drm_mapbufs(DRM_IOCTL_ARGS) vaddr = round_page((vm_offset_t)vms->vm_daddr + MAXDSIZ); #if __FreeBSD_version >= 600023 retcode = vm_mmap(&vms->vm_map, &vaddr, size, PROT_READ | PROT_WRITE, - VM_PROT_ALL, MAP_SHARED, OBJT_DEVICE, kdev, foff ); + VM_PROT_ALL, MAP_SHARED, OBJT_DEVICE, dev->devnode, foff); #else retcode = vm_mmap(&vms->vm_map, &vaddr, size, PROT_READ | PROT_WRITE, - VM_PROT_ALL, MAP_SHARED, SLIST_FIRST(&kdev->si_hlist), foff ); + VM_PROT_ALL, MAP_SHARED, SLIST_FIRST(&dev->devnode->si_hlist), + foff); #endif #elif defined(__NetBSD__) || defined(__OpenBSD__) vaddr = round_page((vaddr_t)vms->vm_daddr + MAXDSIZ); @@ -1096,26 +1069,26 @@ int drm_mapbufs(DRM_IOCTL_ARGS) if (retcode) goto done; - request.virtual = (void *)vaddr; + request->virtual = (void *)vaddr; for ( i = 0 ; i < dma->buf_count ; i++ ) { - if (DRM_COPY_TO_USER(&request.list[i].idx, - &dma->buflist[i]->idx, sizeof(request.list[0].idx))) { + if (DRM_COPY_TO_USER(&request->list[i].idx, + &dma->buflist[i]->idx, sizeof(request->list[0].idx))) { retcode = EFAULT; goto done; } - if (DRM_COPY_TO_USER(&request.list[i].total, - &dma->buflist[i]->total, sizeof(request.list[0].total))) { + if (DRM_COPY_TO_USER(&request->list[i].total, + &dma->buflist[i]->total, sizeof(request->list[0].total))) { retcode = EFAULT; goto done; } - if (DRM_COPY_TO_USER(&request.list[i].used, &zero, + if (DRM_COPY_TO_USER(&request->list[i].used, &zero, sizeof(zero))) { retcode = EFAULT; goto done; } address = vaddr + dma->buflist[i]->offset; /* *** */ - if (DRM_COPY_TO_USER(&request.list[i].address, &address, + if (DRM_COPY_TO_USER(&request->list[i].address, &address, sizeof(address))) { retcode = EFAULT; goto done; @@ -1123,11 +1096,9 @@ int drm_mapbufs(DRM_IOCTL_ARGS) } done: - request.count = dma->buf_count; - - DRM_DEBUG( "%d buffers, retcode = %d\n", request.count, retcode ); + request->count = dma->buf_count; - DRM_COPY_TO_USER_IOCTL((drm_buf_map_t *)data, request, sizeof(request)); + DRM_DEBUG( "%d buffers, retcode = %d\n", request->count, retcode ); - return DRM_ERR(retcode); + return retcode; } |