drm/ttm: cleanup mm_ioctl ioctls to be separate ioctls.

This is the first bunch of ioctls
main
Dave Airlie 2007-05-06 11:17:30 +10:00
parent 7b48f0022a
commit 3fdef0dc20
6 changed files with 174 additions and 93 deletions

View File

@ -3153,13 +3153,13 @@ int drmBOFenceList(int fd, drmBOList *list, unsigned fenceHandle)
int drmMMInit(int fd, unsigned long pOffset, unsigned long pSize, int drmMMInit(int fd, unsigned long pOffset, unsigned long pSize,
unsigned memType) unsigned memType)
{ {
drm_mm_init_arg_t arg; struct drm_mm_init_arg arg;
memset(&arg, 0, sizeof(arg)); memset(&arg, 0, sizeof(arg));
arg.req.op = mm_init;
arg.req.p_offset = pOffset; arg.p_offset = pOffset;
arg.req.p_size = pSize; arg.p_size = pSize;
arg.req.mem_type = memType; arg.mem_type = memType;
if (ioctl(fd, DRM_IOCTL_MM_INIT, &arg)) if (ioctl(fd, DRM_IOCTL_MM_INIT, &arg))
return -errno; return -errno;
@ -3169,14 +3169,12 @@ int drmMMInit(int fd, unsigned long pOffset, unsigned long pSize,
int drmMMTakedown(int fd, unsigned memType) int drmMMTakedown(int fd, unsigned memType)
{ {
drm_mm_init_arg_t arg; struct drm_mm_type_arg arg;
memset(&arg, 0, sizeof(arg)); memset(&arg, 0, sizeof(arg));
arg.req.op = mm_takedown; arg.mem_type = memType;
arg.req.mem_type = memType;
if (ioctl(fd, DRM_IOCTL_MM_INIT, &arg)) if (ioctl(fd, DRM_IOCTL_MM_TAKEDOWN, &arg))
return -errno; return -errno;
return 0; return 0;
@ -3184,15 +3182,14 @@ int drmMMTakedown(int fd, unsigned memType)
int drmMMLock(int fd, unsigned memType) int drmMMLock(int fd, unsigned memType)
{ {
drm_mm_init_arg_t arg; struct drm_mm_type_arg arg;
int ret; int ret;
memset(&arg, 0, sizeof(arg)); memset(&arg, 0, sizeof(arg));
arg.req.op = mm_lock; arg.mem_type = memType;
arg.req.mem_type = memType;
do{ do{
ret = ioctl(fd, DRM_IOCTL_MM_INIT, &arg); ret = ioctl(fd, DRM_IOCTL_MM_LOCK, &arg);
} while (ret && errno == EAGAIN); } while (ret && errno == EAGAIN);
return -errno; return -errno;
@ -3200,15 +3197,15 @@ int drmMMLock(int fd, unsigned memType)
int drmMMUnlock(int fd, unsigned memType) int drmMMUnlock(int fd, unsigned memType)
{ {
drm_mm_init_arg_t arg; struct drm_mm_type_arg arg;
int ret; int ret;
memset(&arg, 0, sizeof(arg)); memset(&arg, 0, sizeof(arg));
arg.req.op = mm_unlock;
arg.req.mem_type = memType; arg.mem_type = memType;
do{ do{
ret = ioctl(fd, DRM_IOCTL_MM_INIT, &arg); ret = ioctl(fd, DRM_IOCTL_MM_UNLOCK, &arg);
} while (ret && errno == EAGAIN); } while (ret && errno == EAGAIN);
return -errno; return -errno;

View File

@ -2158,11 +2158,48 @@ EXPORT_SYMBOL(drm_bo_driver_init);
int drm_mm_init_ioctl(DRM_IOCTL_ARGS) int drm_mm_init_ioctl(DRM_IOCTL_ARGS)
{ {
DRM_DEVICE; DRM_DEVICE;
struct drm_mm_init_arg arg;
int ret = 0;
drm_mm_init_arg_t arg;
drm_buffer_manager_t *bm = &dev->bm; drm_buffer_manager_t *bm = &dev->bm;
drm_bo_driver_t *driver = dev->driver->bo_driver; drm_bo_driver_t *driver = dev->driver->bo_driver;
int ret;
if (!driver) {
DRM_ERROR("Buffer objects are not supported by this driver\n");
return -EINVAL;
}
DRM_COPY_FROM_USER_IOCTL(arg, (void __user *)data, sizeof(arg));
ret = -EINVAL;
mutex_lock(&dev->bm.init_mutex);
mutex_lock(&dev->struct_mutex);
if (!bm->initialized) {
DRM_ERROR("DRM memory manager was not initialized.\n");
goto out;
}
if (arg.mem_type == 0) {
DRM_ERROR("System memory buffers already initialized.\n");
goto out;
}
ret = drm_bo_init_mm(dev, arg.mem_type,
arg.p_offset, arg.p_size);
out:
mutex_unlock(&dev->struct_mutex);
mutex_unlock(&dev->bm.init_mutex);
if (ret)
return ret;
DRM_COPY_TO_USER_IOCTL((void __user *)data, arg, sizeof(arg));
return 0;
}
int drm_mm_takedown_ioctl(DRM_IOCTL_ARGS)
{
DRM_DEVICE;
struct drm_mm_type_arg arg;
drm_buffer_manager_t *bm = &dev->bm;
drm_bo_driver_t *driver = dev->driver->bo_driver;
int ret;
if (!driver) { if (!driver) {
DRM_ERROR("Buffer objects are not supported by this driver\n"); DRM_ERROR("Buffer objects are not supported by this driver\n");
@ -2171,59 +2208,78 @@ int drm_mm_init_ioctl(DRM_IOCTL_ARGS)
DRM_COPY_FROM_USER_IOCTL(arg, (void __user *)data, sizeof(arg)); DRM_COPY_FROM_USER_IOCTL(arg, (void __user *)data, sizeof(arg));
switch (arg.req.op) {
case mm_init:
ret = -EINVAL;
mutex_lock(&dev->bm.init_mutex);
mutex_lock(&dev->struct_mutex);
if (!bm->initialized) {
DRM_ERROR("DRM memory manager was not initialized.\n");
break;
}
if (arg.req.mem_type == 0) {
DRM_ERROR
("System memory buffers already initialized.\n");
break;
}
ret = drm_bo_init_mm(dev, arg.req.mem_type,
arg.req.p_offset, arg.req.p_size);
break;
case mm_takedown:
LOCK_TEST_WITH_RETURN(dev, filp); LOCK_TEST_WITH_RETURN(dev, filp);
mutex_lock(&dev->bm.init_mutex); mutex_lock(&dev->bm.init_mutex);
mutex_lock(&dev->struct_mutex); mutex_lock(&dev->struct_mutex);
ret = -EINVAL; ret = -EINVAL;
if (!bm->initialized) { if (!bm->initialized) {
DRM_ERROR("DRM memory manager was not initialized\n"); DRM_ERROR("DRM memory manager was not initialized\n");
break; goto out;
} }
if (arg.req.mem_type == 0) { if (arg.mem_type == 0) {
DRM_ERROR("No takedown for System memory buffers.\n"); DRM_ERROR("No takedown for System memory buffers.\n");
break; goto out;
} }
ret = 0; ret = 0;
if (drm_bo_clean_mm(dev, arg.req.mem_type)) { if (drm_bo_clean_mm(dev, arg.mem_type)) {
DRM_ERROR("Memory manager type %d not clean. " DRM_ERROR("Memory manager type %d not clean. "
"Delaying takedown\n", arg.req.mem_type); "Delaying takedown\n", arg.mem_type);
} }
break; out:
case mm_lock: mutex_unlock(&dev->struct_mutex);
LOCK_TEST_WITH_RETURN(dev, filp); mutex_unlock(&dev->bm.init_mutex);
mutex_lock(&dev->bm.init_mutex); if (ret)
mutex_lock(&dev->struct_mutex); return ret;
ret = drm_bo_lock_mm(dev, arg.req.mem_type);
break; DRM_COPY_TO_USER_IOCTL((void __user *)data, arg, sizeof(arg));
case mm_unlock: return 0;
LOCK_TEST_WITH_RETURN(dev, filp); }
mutex_lock(&dev->bm.init_mutex);
mutex_lock(&dev->struct_mutex); int drm_mm_lock_ioctl(DRM_IOCTL_ARGS)
ret = 0; {
break; DRM_DEVICE;
default: struct drm_mm_type_arg arg;
DRM_ERROR("Function not implemented yet\n"); drm_bo_driver_t *driver = dev->driver->bo_driver;
int ret;
if (!driver) {
DRM_ERROR("Buffer objects are not supported by this driver\n");
return -EINVAL; return -EINVAL;
} }
DRM_COPY_FROM_USER_IOCTL(arg, (void __user *)data, sizeof(arg));
LOCK_TEST_WITH_RETURN(dev, filp);
mutex_lock(&dev->bm.init_mutex);
mutex_lock(&dev->struct_mutex);
ret = drm_bo_lock_mm(dev, arg.mem_type);
mutex_unlock(&dev->struct_mutex);
mutex_unlock(&dev->bm.init_mutex);
if (ret)
return ret;
DRM_COPY_TO_USER_IOCTL((void __user *)data, arg, sizeof(arg));
return 0;
}
int drm_mm_unlock_ioctl(DRM_IOCTL_ARGS)
{
DRM_DEVICE;
struct drm_mm_type_arg arg;
drm_bo_driver_t *driver = dev->driver->bo_driver;
int ret;
if (!driver) {
DRM_ERROR("Buffer objects are not supported by this driver\n");
return -EINVAL;
}
DRM_COPY_FROM_USER_IOCTL(arg, (void __user *)data, sizeof(arg));
LOCK_TEST_WITH_RETURN(dev, filp);
mutex_lock(&dev->bm.init_mutex);
mutex_lock(&dev->struct_mutex);
ret = 0;
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
mutex_unlock(&dev->bm.init_mutex); mutex_unlock(&dev->bm.init_mutex);
if (ret) if (ret)

View File

@ -184,7 +184,7 @@ static int drm_pte_is_clear(struct vm_area_struct *vma,
spin_unlock(&mm->page_table_lock); spin_unlock(&mm->page_table_lock);
return ret; return ret;
} }
#if 0
static int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr, static int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
unsigned long pfn) unsigned long pfn)
{ {
@ -195,6 +195,7 @@ static int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
ret = io_remap_pfn_range(vma, addr, pfn, PAGE_SIZE, vma->vm_page_prot); ret = io_remap_pfn_range(vma, addr, pfn, PAGE_SIZE, vma->vm_page_prot);
return ret; return ret;
} }
#endif
static struct page *drm_bo_vm_fault(struct vm_area_struct *vma, static struct page *drm_bo_vm_fault(struct vm_area_struct *vma,
struct fault_data *data) struct fault_data *data)

View File

@ -119,10 +119,18 @@ static drm_ioctl_desc_t drm_ioctls[] = {
[DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK)] = {drm_wait_vblank, 0}, [DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK)] = {drm_wait_vblank, 0},
[DRM_IOCTL_NR(DRM_IOCTL_FENCE)] = {drm_fence_ioctl, DRM_AUTH}, [DRM_IOCTL_NR(DRM_IOCTL_FENCE)] = {drm_fence_ioctl, DRM_AUTH},
[DRM_IOCTL_NR(DRM_IOCTL_BUFOBJ)] = {drm_bo_ioctl, DRM_AUTH}, [DRM_IOCTL_NR(DRM_IOCTL_BUFOBJ)] = {drm_bo_ioctl, DRM_AUTH},
[DRM_IOCTL_NR(DRM_IOCTL_MM_INIT)] = {drm_mm_init_ioctl,
DRM_AUTH },
[DRM_IOCTL_NR(DRM_IOCTL_UPDATE_DRAW)] = {drm_update_drawable_info, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY}, [DRM_IOCTL_NR(DRM_IOCTL_UPDATE_DRAW)] = {drm_update_drawable_info, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
[DRM_IOCTL_NR(DRM_IOCTL_MM_INIT)] = {drm_mm_init_ioctl,
DRM_AUTH },
[DRM_IOCTL_NR(DRM_IOCTL_MM_TAKEDOWN)] = {drm_mm_takedown_ioctl,
DRM_AUTH },
[DRM_IOCTL_NR(DRM_IOCTL_MM_LOCK)] = {drm_mm_lock_ioctl,
DRM_AUTH },
[DRM_IOCTL_NR(DRM_IOCTL_MM_UNLOCK)] = {drm_mm_unlock_ioctl,
DRM_AUTH },
}; };
#define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls ) #define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )

View File

@ -430,6 +430,9 @@ typedef struct drm_bo_driver {
extern int drm_bo_ioctl(DRM_IOCTL_ARGS); extern int drm_bo_ioctl(DRM_IOCTL_ARGS);
extern int drm_mm_init_ioctl(DRM_IOCTL_ARGS); extern int drm_mm_init_ioctl(DRM_IOCTL_ARGS);
extern int drm_mm_takedown_ioctl(DRM_IOCTL_ARGS);
extern int drm_mm_lock_ioctl(DRM_IOCTL_ARGS);
extern int drm_mm_unlock_ioctl(DRM_IOCTL_ARGS);
extern int drm_bo_driver_finish(struct drm_device *dev); extern int drm_bo_driver_finish(struct drm_device *dev);
extern int drm_bo_driver_init(struct drm_device *dev); extern int drm_bo_driver_init(struct drm_device *dev);
extern int drm_bo_pci_offset(struct drm_device *dev, extern int drm_bo_pci_offset(struct drm_device *dev,

View File

@ -862,24 +862,14 @@ typedef struct drm_bo_arg{
#define DRM_BO_MEM_TYPES 8 /* For now. */ #define DRM_BO_MEM_TYPES 8 /* For now. */
typedef union drm_mm_init_arg{ typedef struct drm_mm_type_arg {
struct { unsigned int mem_type;
enum { } drm_mm_type_arg_t;
mm_init,
mm_takedown, typedef struct drm_mm_init_arg {
mm_query,
mm_lock,
mm_unlock
} op;
drm_u64_t p_offset; drm_u64_t p_offset;
drm_u64_t p_size; drm_u64_t p_size;
unsigned mem_type; unsigned int mem_type;
unsigned expand_pad[8]; /*Future expansion */
} req;
struct {
drm_handle_t mm_sarea;
unsigned expand_pad[8]; /*Future expansion */
} rep;
} drm_mm_init_arg_t; } drm_mm_init_arg_t;
/** /**
@ -949,10 +939,36 @@ typedef union drm_mm_init_arg{
#define DRM_IOCTL_FENCE DRM_IOWR(0x3b, drm_fence_arg_t) #define DRM_IOCTL_FENCE DRM_IOWR(0x3b, drm_fence_arg_t)
#define DRM_IOCTL_BUFOBJ DRM_IOWR(0x3d, drm_bo_arg_t) #define DRM_IOCTL_BUFOBJ DRM_IOWR(0x3d, drm_bo_arg_t)
#define DRM_IOCTL_MM_INIT DRM_IOWR(0x3e, drm_mm_init_arg_t)
#define DRM_IOCTL_UPDATE_DRAW DRM_IOW(0x3f, drm_update_draw_t) #define DRM_IOCTL_UPDATE_DRAW DRM_IOW(0x3f, drm_update_draw_t)
#define DRM_IOCTL_MM_INIT DRM_IOWR(0xc0, drm_mm_init_arg_t)
#define DRM_IOCTL_MM_TAKEDOWN DRM_IOWR(0xc1, drm_mm_type_arg_t)
#define DRM_IOCTL_MM_LOCK DRM_IOWR(0xc2, drm_mm_type_arg_t)
#define DRM_IOCTL_MM_UNLOCK DRM_IOWR(0xc3, drm_mm_type_arg_t)
#define DRM_IOCTL_FENCE_CREATE DRM_IOWR(0xc4, drm_fence_arg_t)
#define DRM_IOCTL_FENCE_DESTROY DRM_IOWR(0xc5, drm_fence_arg_t)
#define DRM_IOCTL_FENCE_REFERENCE DRM_IOWR(0xc6, drm_fence_arg_t)
#define DRM_IOCTL_FENCE_UNREFERENCE DRM_IOWR(0xc7, drm_fence_arg_t)
#define DRM_IOCTL_FENCE_SIGNALED DRM_IOWR(0xc8, drm_fence_arg_t)
#define DRM_IOCTL_FENCE_FLUSH DRM_IOWR(0xc9, drm_fence_arg_t)
#define DRM_IOCTL_FENCE_WAIT DRM_IOWR(0xca, drm_fence_arg_t)
#define DRM_IOCTL_FENCE_BUFFERS DRM_IOWR(0xcb, drm_fence_arg_t)
#define DRM_IOCTL_BO_CREATE DRM_IOWR(0xcc, drm_bo_arg_t)
#define DRM_IOCTL_BO_DESTROY DRM_IOWR(0xcd, drm_bo_arg_t)
#define DRM_IOCTL_BO_MAP DRM_IOWR(0xce, drm_bo_arg_t)
#define DRM_IOCTL_BO_UNMAP DRM_IOWR(0xcf, drm_bo_arg_t)
#define DRM_IOCTL_BO_REFERENCE DRM_IOWR(0xd0, drm_bo_arg_t)
#define DRM_IOCTL_BO_UNREFERENCE DRM_IOWR(0xd1, drm_bo_arg_t)
#define DRM_IOCTL_BO_VALIDATE DRM_IOWR(0xd2, drm_bo_arg_t)
#define DRM_IOCTL_BO_FENCE DRM_IOWR(0xd3, drm_bo_arg_t)
#define DRM_IOCTL_BO_INFO DRM_IOWR(0xd4, drm_bo_arg_t)
#define DRM_IOCTL_BO_WAIT_IDLE DRM_IOWR(0xd5, drm_bo_arg_t)
#define DRM_IOCTL_BO_REF_FENCE DRM_IOWR(0xd6, drm_bo_arg_t)
/*@}*/ /*@}*/
/** /**