Home | History | Annotate | Line # | Download | only in qxl
      1  1.2  riastrad /*	$NetBSD: qxl_ioctl.c,v 1.3 2021/12/18 23:45:42 riastradh Exp $	*/
      2  1.2  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright 2013 Red Hat Inc.
      5  1.1  riastrad  *
      6  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      7  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
      8  1.1  riastrad  * to deal in the Software without restriction, including without limitation
      9  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     11  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     12  1.1  riastrad  *
     13  1.1  riastrad  * The above copyright notice and this permission notice shall be included in
     14  1.1  riastrad  * all copies or substantial portions of the Software.
     15  1.1  riastrad  *
     16  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     19  1.1  riastrad  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     20  1.1  riastrad  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     21  1.1  riastrad  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     22  1.1  riastrad  * OTHER DEALINGS IN THE SOFTWARE.
     23  1.1  riastrad  *
     24  1.1  riastrad  * Authors: Dave Airlie
     25  1.1  riastrad  *          Alon Levy
     26  1.1  riastrad  */
     27  1.1  riastrad 
     28  1.2  riastrad #include <sys/cdefs.h>
     29  1.2  riastrad __KERNEL_RCSID(0, "$NetBSD: qxl_ioctl.c,v 1.3 2021/12/18 23:45:42 riastradh Exp $");
     30  1.2  riastrad 
     31  1.3  riastrad #include <linux/pci.h>
     32  1.3  riastrad #include <linux/uaccess.h>
     33  1.3  riastrad 
     34  1.1  riastrad #include "qxl_drv.h"
     35  1.1  riastrad #include "qxl_object.h"
     36  1.1  riastrad 
     37  1.1  riastrad /*
     38  1.1  riastrad  * TODO: allocating a new gem(in qxl_bo) for each request.
     39  1.1  riastrad  * This is wasteful since bo's are page aligned.
     40  1.1  riastrad  */
     41  1.1  riastrad static int qxl_alloc_ioctl(struct drm_device *dev, void *data,
     42  1.1  riastrad 			   struct drm_file *file_priv)
     43  1.1  riastrad {
     44  1.1  riastrad 	struct qxl_device *qdev = dev->dev_private;
     45  1.1  riastrad 	struct drm_qxl_alloc *qxl_alloc = data;
     46  1.1  riastrad 	int ret;
     47  1.1  riastrad 	struct qxl_bo *qobj;
     48  1.1  riastrad 	uint32_t handle;
     49  1.1  riastrad 	u32 domain = QXL_GEM_DOMAIN_VRAM;
     50  1.1  riastrad 
     51  1.1  riastrad 	if (qxl_alloc->size == 0) {
     52  1.1  riastrad 		DRM_ERROR("invalid size %d\n", qxl_alloc->size);
     53  1.1  riastrad 		return -EINVAL;
     54  1.1  riastrad 	}
     55  1.1  riastrad 	ret = qxl_gem_object_create_with_handle(qdev, file_priv,
     56  1.1  riastrad 						domain,
     57  1.1  riastrad 						qxl_alloc->size,
     58  1.1  riastrad 						NULL,
     59  1.1  riastrad 						&qobj, &handle);
     60  1.1  riastrad 	if (ret) {
     61  1.1  riastrad 		DRM_ERROR("%s: failed to create gem ret=%d\n",
     62  1.1  riastrad 			  __func__, ret);
     63  1.1  riastrad 		return -ENOMEM;
     64  1.1  riastrad 	}
     65  1.1  riastrad 	qxl_alloc->handle = handle;
     66  1.1  riastrad 	return 0;
     67  1.1  riastrad }
     68  1.1  riastrad 
     69  1.1  riastrad static int qxl_map_ioctl(struct drm_device *dev, void *data,
     70  1.1  riastrad 			 struct drm_file *file_priv)
     71  1.1  riastrad {
     72  1.1  riastrad 	struct qxl_device *qdev = dev->dev_private;
     73  1.1  riastrad 	struct drm_qxl_map *qxl_map = data;
     74  1.1  riastrad 
     75  1.3  riastrad 	return qxl_mode_dumb_mmap(file_priv, &qdev->ddev, qxl_map->handle,
     76  1.1  riastrad 				  &qxl_map->offset);
     77  1.1  riastrad }
     78  1.1  riastrad 
     79  1.1  riastrad struct qxl_reloc_info {
     80  1.1  riastrad 	int type;
     81  1.1  riastrad 	struct qxl_bo *dst_bo;
     82  1.1  riastrad 	uint32_t dst_offset;
     83  1.1  riastrad 	struct qxl_bo *src_bo;
     84  1.1  riastrad 	int src_offset;
     85  1.1  riastrad };
     86  1.1  riastrad 
     87  1.1  riastrad /*
     88  1.1  riastrad  * dst must be validated, i.e. whole bo on vram/surfacesram (right now all bo's
     89  1.1  riastrad  * are on vram).
     90  1.1  riastrad  * *(dst + dst_off) = qxl_bo_physical_address(src, src_off)
     91  1.1  riastrad  */
     92  1.1  riastrad static void
     93  1.1  riastrad apply_reloc(struct qxl_device *qdev, struct qxl_reloc_info *info)
     94  1.1  riastrad {
     95  1.1  riastrad 	void *reloc_page;
     96  1.3  riastrad 
     97  1.1  riastrad 	reloc_page = qxl_bo_kmap_atomic_page(qdev, info->dst_bo, info->dst_offset & PAGE_MASK);
     98  1.1  riastrad 	*(uint64_t *)(reloc_page + (info->dst_offset & ~PAGE_MASK)) = qxl_bo_physical_address(qdev,
     99  1.1  riastrad 											      info->src_bo,
    100  1.1  riastrad 											      info->src_offset);
    101  1.1  riastrad 	qxl_bo_kunmap_atomic_page(qdev, info->dst_bo, reloc_page);
    102  1.1  riastrad }
    103  1.1  riastrad 
    104  1.1  riastrad static void
    105  1.1  riastrad apply_surf_reloc(struct qxl_device *qdev, struct qxl_reloc_info *info)
    106  1.1  riastrad {
    107  1.1  riastrad 	uint32_t id = 0;
    108  1.1  riastrad 	void *reloc_page;
    109  1.1  riastrad 
    110  1.1  riastrad 	if (info->src_bo && !info->src_bo->is_primary)
    111  1.1  riastrad 		id = info->src_bo->surface_id;
    112  1.1  riastrad 
    113  1.1  riastrad 	reloc_page = qxl_bo_kmap_atomic_page(qdev, info->dst_bo, info->dst_offset & PAGE_MASK);
    114  1.1  riastrad 	*(uint32_t *)(reloc_page + (info->dst_offset & ~PAGE_MASK)) = id;
    115  1.1  riastrad 	qxl_bo_kunmap_atomic_page(qdev, info->dst_bo, reloc_page);
    116  1.1  riastrad }
    117  1.1  riastrad 
    118  1.1  riastrad /* return holding the reference to this object */
    119  1.3  riastrad static int qxlhw_handle_to_bo(struct drm_file *file_priv, uint64_t handle,
    120  1.2  riastrad 			      struct qxl_release *release, struct qxl_bo **qbo_p)
    121  1.1  riastrad {
    122  1.1  riastrad 	struct drm_gem_object *gobj;
    123  1.1  riastrad 	struct qxl_bo *qobj;
    124  1.1  riastrad 	int ret;
    125  1.1  riastrad 
    126  1.3  riastrad 	gobj = drm_gem_object_lookup(file_priv, handle);
    127  1.1  riastrad 	if (!gobj)
    128  1.2  riastrad 		return -EINVAL;
    129  1.1  riastrad 
    130  1.1  riastrad 	qobj = gem_to_qxl_bo(gobj);
    131  1.1  riastrad 
    132  1.1  riastrad 	ret = qxl_release_list_add(release, qobj);
    133  1.3  riastrad 	drm_gem_object_put_unlocked(gobj);
    134  1.1  riastrad 	if (ret)
    135  1.2  riastrad 		return ret;
    136  1.1  riastrad 
    137  1.2  riastrad 	*qbo_p = qobj;
    138  1.2  riastrad 	return 0;
    139  1.1  riastrad }
    140  1.1  riastrad 
    141  1.1  riastrad /*
    142  1.1  riastrad  * Usage of execbuffer:
    143  1.1  riastrad  * Relocations need to take into account the full QXLDrawable size.
    144  1.1  riastrad  * However, the command as passed from user space must *not* contain the initial
    145  1.1  riastrad  * QXLReleaseInfo struct (first XXX bytes)
    146  1.1  riastrad  */
    147  1.1  riastrad static int qxl_process_single_command(struct qxl_device *qdev,
    148  1.1  riastrad 				      struct drm_qxl_command *cmd,
    149  1.1  riastrad 				      struct drm_file *file_priv)
    150  1.1  riastrad {
    151  1.1  riastrad 	struct qxl_reloc_info *reloc_info;
    152  1.1  riastrad 	int release_type;
    153  1.1  riastrad 	struct qxl_release *release;
    154  1.1  riastrad 	struct qxl_bo *cmd_bo;
    155  1.1  riastrad 	void *fb_cmd;
    156  1.2  riastrad 	int i, ret, num_relocs;
    157  1.1  riastrad 	int unwritten;
    158  1.1  riastrad 
    159  1.1  riastrad 	switch (cmd->type) {
    160  1.1  riastrad 	case QXL_CMD_DRAW:
    161  1.1  riastrad 		release_type = QXL_RELEASE_DRAWABLE;
    162  1.1  riastrad 		break;
    163  1.1  riastrad 	case QXL_CMD_SURFACE:
    164  1.1  riastrad 	case QXL_CMD_CURSOR:
    165  1.1  riastrad 	default:
    166  1.1  riastrad 		DRM_DEBUG("Only draw commands in execbuffers\n");
    167  1.1  riastrad 		return -EINVAL;
    168  1.1  riastrad 		break;
    169  1.1  riastrad 	}
    170  1.1  riastrad 
    171  1.1  riastrad 	if (cmd->command_size > PAGE_SIZE - sizeof(union qxl_release_info))
    172  1.1  riastrad 		return -EINVAL;
    173  1.1  riastrad 
    174  1.3  riastrad 	if (!access_ok(u64_to_user_ptr(cmd->command),
    175  1.1  riastrad 		       cmd->command_size))
    176  1.1  riastrad 		return -EFAULT;
    177  1.1  riastrad 
    178  1.2  riastrad 	reloc_info = kmalloc_array(cmd->relocs_num,
    179  1.2  riastrad 				   sizeof(struct qxl_reloc_info), GFP_KERNEL);
    180  1.1  riastrad 	if (!reloc_info)
    181  1.1  riastrad 		return -ENOMEM;
    182  1.1  riastrad 
    183  1.1  riastrad 	ret = qxl_alloc_release_reserved(qdev,
    184  1.1  riastrad 					 sizeof(union qxl_release_info) +
    185  1.1  riastrad 					 cmd->command_size,
    186  1.1  riastrad 					 release_type,
    187  1.1  riastrad 					 &release,
    188  1.1  riastrad 					 &cmd_bo);
    189  1.1  riastrad 	if (ret)
    190  1.1  riastrad 		goto out_free_reloc;
    191  1.1  riastrad 
    192  1.1  riastrad 	/* TODO copy slow path code from i915 */
    193  1.3  riastrad 	fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_MASK));
    194  1.3  riastrad 	unwritten = __copy_from_user_inatomic_nocache
    195  1.3  riastrad 		(fb_cmd + sizeof(union qxl_release_info) + (release->release_offset & ~PAGE_MASK),
    196  1.3  riastrad 		 u64_to_user_ptr(cmd->command), cmd->command_size);
    197  1.1  riastrad 
    198  1.1  riastrad 	{
    199  1.1  riastrad 		struct qxl_drawable *draw = fb_cmd;
    200  1.3  riastrad 
    201  1.1  riastrad 		draw->mm_time = qdev->rom->mm_clock;
    202  1.1  riastrad 	}
    203  1.1  riastrad 
    204  1.1  riastrad 	qxl_bo_kunmap_atomic_page(qdev, cmd_bo, fb_cmd);
    205  1.1  riastrad 	if (unwritten) {
    206  1.1  riastrad 		DRM_ERROR("got unwritten %d\n", unwritten);
    207  1.1  riastrad 		ret = -EFAULT;
    208  1.1  riastrad 		goto out_free_release;
    209  1.1  riastrad 	}
    210  1.1  riastrad 
    211  1.1  riastrad 	/* fill out reloc info structs */
    212  1.1  riastrad 	num_relocs = 0;
    213  1.1  riastrad 	for (i = 0; i < cmd->relocs_num; ++i) {
    214  1.1  riastrad 		struct drm_qxl_reloc reloc;
    215  1.3  riastrad 		struct drm_qxl_reloc __user *u = u64_to_user_ptr(cmd->relocs);
    216  1.1  riastrad 
    217  1.3  riastrad 		if (copy_from_user(&reloc, u + i, sizeof(reloc))) {
    218  1.1  riastrad 			ret = -EFAULT;
    219  1.1  riastrad 			goto out_free_bos;
    220  1.1  riastrad 		}
    221  1.1  riastrad 
    222  1.1  riastrad 		/* add the bos to the list of bos to validate -
    223  1.1  riastrad 		   need to validate first then process relocs? */
    224  1.1  riastrad 		if (reloc.reloc_type != QXL_RELOC_TYPE_BO && reloc.reloc_type != QXL_RELOC_TYPE_SURF) {
    225  1.2  riastrad 			DRM_DEBUG("unknown reloc type %d\n", reloc.reloc_type);
    226  1.1  riastrad 
    227  1.1  riastrad 			ret = -EINVAL;
    228  1.1  riastrad 			goto out_free_bos;
    229  1.1  riastrad 		}
    230  1.1  riastrad 		reloc_info[i].type = reloc.reloc_type;
    231  1.1  riastrad 
    232  1.1  riastrad 		if (reloc.dst_handle) {
    233  1.3  riastrad 			ret = qxlhw_handle_to_bo(file_priv, reloc.dst_handle, release,
    234  1.2  riastrad 						 &reloc_info[i].dst_bo);
    235  1.2  riastrad 			if (ret)
    236  1.1  riastrad 				goto out_free_bos;
    237  1.1  riastrad 			reloc_info[i].dst_offset = reloc.dst_offset;
    238  1.1  riastrad 		} else {
    239  1.1  riastrad 			reloc_info[i].dst_bo = cmd_bo;
    240  1.1  riastrad 			reloc_info[i].dst_offset = reloc.dst_offset + release->release_offset;
    241  1.1  riastrad 		}
    242  1.1  riastrad 		num_relocs++;
    243  1.1  riastrad 
    244  1.1  riastrad 		/* reserve and validate the reloc dst bo */
    245  1.2  riastrad 		if (reloc.reloc_type == QXL_RELOC_TYPE_BO || reloc.src_handle) {
    246  1.3  riastrad 			ret = qxlhw_handle_to_bo(file_priv, reloc.src_handle, release,
    247  1.2  riastrad 						 &reloc_info[i].src_bo);
    248  1.2  riastrad 			if (ret)
    249  1.1  riastrad 				goto out_free_bos;
    250  1.1  riastrad 			reloc_info[i].src_offset = reloc.src_offset;
    251  1.1  riastrad 		} else {
    252  1.1  riastrad 			reloc_info[i].src_bo = NULL;
    253  1.1  riastrad 			reloc_info[i].src_offset = 0;
    254  1.1  riastrad 		}
    255  1.1  riastrad 	}
    256  1.1  riastrad 
    257  1.1  riastrad 	/* validate all buffers */
    258  1.1  riastrad 	ret = qxl_release_reserve_list(release, false);
    259  1.1  riastrad 	if (ret)
    260  1.1  riastrad 		goto out_free_bos;
    261  1.1  riastrad 
    262  1.1  riastrad 	for (i = 0; i < cmd->relocs_num; ++i) {
    263  1.1  riastrad 		if (reloc_info[i].type == QXL_RELOC_TYPE_BO)
    264  1.1  riastrad 			apply_reloc(qdev, &reloc_info[i]);
    265  1.1  riastrad 		else if (reloc_info[i].type == QXL_RELOC_TYPE_SURF)
    266  1.1  riastrad 			apply_surf_reloc(qdev, &reloc_info[i]);
    267  1.1  riastrad 	}
    268  1.1  riastrad 
    269  1.1  riastrad 	ret = qxl_push_command_ring_release(qdev, release, cmd->type, true);
    270  1.1  riastrad 	if (ret)
    271  1.1  riastrad 		qxl_release_backoff_reserve_list(release);
    272  1.1  riastrad 	else
    273  1.1  riastrad 		qxl_release_fence_buffer_objects(release);
    274  1.1  riastrad 
    275  1.1  riastrad out_free_bos:
    276  1.1  riastrad out_free_release:
    277  1.1  riastrad 	if (ret)
    278  1.1  riastrad 		qxl_release_free(qdev, release);
    279  1.1  riastrad out_free_reloc:
    280  1.1  riastrad 	kfree(reloc_info);
    281  1.1  riastrad 	return ret;
    282  1.1  riastrad }
    283  1.1  riastrad 
    284  1.1  riastrad static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
    285  1.1  riastrad 				struct drm_file *file_priv)
    286  1.1  riastrad {
    287  1.1  riastrad 	struct qxl_device *qdev = dev->dev_private;
    288  1.1  riastrad 	struct drm_qxl_execbuffer *execbuffer = data;
    289  1.1  riastrad 	struct drm_qxl_command user_cmd;
    290  1.1  riastrad 	int cmd_num;
    291  1.1  riastrad 	int ret;
    292  1.1  riastrad 
    293  1.1  riastrad 	for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
    294  1.1  riastrad 
    295  1.3  riastrad 		struct drm_qxl_command __user *commands =
    296  1.3  riastrad 			u64_to_user_ptr(execbuffer->commands);
    297  1.1  riastrad 
    298  1.3  riastrad 		if (copy_from_user(&user_cmd, commands + cmd_num,
    299  1.1  riastrad 				       sizeof(user_cmd)))
    300  1.1  riastrad 			return -EFAULT;
    301  1.1  riastrad 
    302  1.1  riastrad 		ret = qxl_process_single_command(qdev, &user_cmd, file_priv);
    303  1.1  riastrad 		if (ret)
    304  1.1  riastrad 			return ret;
    305  1.1  riastrad 	}
    306  1.1  riastrad 	return 0;
    307  1.1  riastrad }
    308  1.1  riastrad 
    309  1.1  riastrad static int qxl_update_area_ioctl(struct drm_device *dev, void *data,
    310  1.1  riastrad 				 struct drm_file *file)
    311  1.1  riastrad {
    312  1.1  riastrad 	struct qxl_device *qdev = dev->dev_private;
    313  1.1  riastrad 	struct drm_qxl_update_area *update_area = data;
    314  1.1  riastrad 	struct qxl_rect area = {.left = update_area->left,
    315  1.1  riastrad 				.top = update_area->top,
    316  1.1  riastrad 				.right = update_area->right,
    317  1.1  riastrad 				.bottom = update_area->bottom};
    318  1.1  riastrad 	int ret;
    319  1.1  riastrad 	struct drm_gem_object *gobj = NULL;
    320  1.1  riastrad 	struct qxl_bo *qobj = NULL;
    321  1.3  riastrad 	struct ttm_operation_ctx ctx = { true, false };
    322  1.1  riastrad 
    323  1.1  riastrad 	if (update_area->left >= update_area->right ||
    324  1.1  riastrad 	    update_area->top >= update_area->bottom)
    325  1.1  riastrad 		return -EINVAL;
    326  1.1  riastrad 
    327  1.3  riastrad 	gobj = drm_gem_object_lookup(file, update_area->handle);
    328  1.1  riastrad 	if (gobj == NULL)
    329  1.1  riastrad 		return -ENOENT;
    330  1.1  riastrad 
    331  1.1  riastrad 	qobj = gem_to_qxl_bo(gobj);
    332  1.1  riastrad 
    333  1.1  riastrad 	ret = qxl_bo_reserve(qobj, false);
    334  1.1  riastrad 	if (ret)
    335  1.1  riastrad 		goto out;
    336  1.1  riastrad 
    337  1.1  riastrad 	if (!qobj->pin_count) {
    338  1.1  riastrad 		qxl_ttm_placement_from_domain(qobj, qobj->type, false);
    339  1.3  riastrad 		ret = ttm_bo_validate(&qobj->tbo, &qobj->placement, &ctx);
    340  1.1  riastrad 		if (unlikely(ret))
    341  1.1  riastrad 			goto out;
    342  1.1  riastrad 	}
    343  1.1  riastrad 
    344  1.1  riastrad 	ret = qxl_bo_check_id(qdev, qobj);
    345  1.1  riastrad 	if (ret)
    346  1.1  riastrad 		goto out2;
    347  1.1  riastrad 	if (!qobj->surface_id)
    348  1.1  riastrad 		DRM_ERROR("got update area for surface with no id %d\n", update_area->handle);
    349  1.1  riastrad 	ret = qxl_io_update_area(qdev, qobj, &area);
    350  1.1  riastrad 
    351  1.1  riastrad out2:
    352  1.1  riastrad 	qxl_bo_unreserve(qobj);
    353  1.1  riastrad 
    354  1.1  riastrad out:
    355  1.3  riastrad 	drm_gem_object_put_unlocked(gobj);
    356  1.1  riastrad 	return ret;
    357  1.1  riastrad }
    358  1.1  riastrad 
    359  1.1  riastrad static int qxl_getparam_ioctl(struct drm_device *dev, void *data,
    360  1.1  riastrad 		       struct drm_file *file_priv)
    361  1.1  riastrad {
    362  1.1  riastrad 	struct qxl_device *qdev = dev->dev_private;
    363  1.1  riastrad 	struct drm_qxl_getparam *param = data;
    364  1.1  riastrad 
    365  1.1  riastrad 	switch (param->param) {
    366  1.1  riastrad 	case QXL_PARAM_NUM_SURFACES:
    367  1.1  riastrad 		param->value = qdev->rom->n_surfaces;
    368  1.1  riastrad 		break;
    369  1.1  riastrad 	case QXL_PARAM_MAX_RELOCS:
    370  1.1  riastrad 		param->value = QXL_MAX_RES;
    371  1.1  riastrad 		break;
    372  1.1  riastrad 	default:
    373  1.1  riastrad 		return -EINVAL;
    374  1.1  riastrad 	}
    375  1.1  riastrad 	return 0;
    376  1.1  riastrad }
    377  1.1  riastrad 
    378  1.1  riastrad static int qxl_clientcap_ioctl(struct drm_device *dev, void *data,
    379  1.1  riastrad 				  struct drm_file *file_priv)
    380  1.1  riastrad {
    381  1.1  riastrad 	struct qxl_device *qdev = dev->dev_private;
    382  1.1  riastrad 	struct drm_qxl_clientcap *param = data;
    383  1.1  riastrad 	int byte, idx;
    384  1.1  riastrad 
    385  1.1  riastrad 	byte = param->index / 8;
    386  1.1  riastrad 	idx = param->index % 8;
    387  1.1  riastrad 
    388  1.3  riastrad 	if (dev->pdev->revision < 4)
    389  1.1  riastrad 		return -ENOSYS;
    390  1.1  riastrad 
    391  1.1  riastrad 	if (byte >= 58)
    392  1.1  riastrad 		return -ENOSYS;
    393  1.1  riastrad 
    394  1.1  riastrad 	if (qdev->rom->client_capabilities[byte] & (1 << idx))
    395  1.1  riastrad 		return 0;
    396  1.1  riastrad 	return -ENOSYS;
    397  1.1  riastrad }
    398  1.1  riastrad 
    399  1.1  riastrad static int qxl_alloc_surf_ioctl(struct drm_device *dev, void *data,
    400  1.1  riastrad 				struct drm_file *file)
    401  1.1  riastrad {
    402  1.1  riastrad 	struct qxl_device *qdev = dev->dev_private;
    403  1.1  riastrad 	struct drm_qxl_alloc_surf *param = data;
    404  1.1  riastrad 	struct qxl_bo *qobj;
    405  1.1  riastrad 	int handle;
    406  1.1  riastrad 	int ret;
    407  1.1  riastrad 	int size, actual_stride;
    408  1.1  riastrad 	struct qxl_surface surf;
    409  1.1  riastrad 
    410  1.1  riastrad 	/* work out size allocate bo with handle */
    411  1.1  riastrad 	actual_stride = param->stride < 0 ? -param->stride : param->stride;
    412  1.1  riastrad 	size = actual_stride * param->height + actual_stride;
    413  1.1  riastrad 
    414  1.1  riastrad 	surf.format = param->format;
    415  1.1  riastrad 	surf.width = param->width;
    416  1.1  riastrad 	surf.height = param->height;
    417  1.1  riastrad 	surf.stride = param->stride;
    418  1.1  riastrad 	surf.data = 0;
    419  1.1  riastrad 
    420  1.1  riastrad 	ret = qxl_gem_object_create_with_handle(qdev, file,
    421  1.1  riastrad 						QXL_GEM_DOMAIN_SURFACE,
    422  1.1  riastrad 						size,
    423  1.1  riastrad 						&surf,
    424  1.1  riastrad 						&qobj, &handle);
    425  1.1  riastrad 	if (ret) {
    426  1.1  riastrad 		DRM_ERROR("%s: failed to create gem ret=%d\n",
    427  1.1  riastrad 			  __func__, ret);
    428  1.1  riastrad 		return -ENOMEM;
    429  1.1  riastrad 	} else
    430  1.1  riastrad 		param->handle = handle;
    431  1.1  riastrad 	return ret;
    432  1.1  riastrad }
    433  1.1  riastrad 
    434  1.1  riastrad const struct drm_ioctl_desc qxl_ioctls[] = {
    435  1.2  riastrad 	DRM_IOCTL_DEF_DRV(QXL_ALLOC, qxl_alloc_ioctl, DRM_AUTH),
    436  1.1  riastrad 
    437  1.2  riastrad 	DRM_IOCTL_DEF_DRV(QXL_MAP, qxl_map_ioctl, DRM_AUTH),
    438  1.1  riastrad 
    439  1.1  riastrad 	DRM_IOCTL_DEF_DRV(QXL_EXECBUFFER, qxl_execbuffer_ioctl,
    440  1.2  riastrad 							DRM_AUTH),
    441  1.1  riastrad 	DRM_IOCTL_DEF_DRV(QXL_UPDATE_AREA, qxl_update_area_ioctl,
    442  1.2  riastrad 							DRM_AUTH),
    443  1.1  riastrad 	DRM_IOCTL_DEF_DRV(QXL_GETPARAM, qxl_getparam_ioctl,
    444  1.2  riastrad 							DRM_AUTH),
    445  1.1  riastrad 	DRM_IOCTL_DEF_DRV(QXL_CLIENTCAP, qxl_clientcap_ioctl,
    446  1.2  riastrad 							DRM_AUTH),
    447  1.1  riastrad 
    448  1.1  riastrad 	DRM_IOCTL_DEF_DRV(QXL_ALLOC_SURF, qxl_alloc_surf_ioctl,
    449  1.2  riastrad 			  DRM_AUTH),
    450  1.1  riastrad };
    451  1.1  riastrad 
    452  1.2  riastrad int qxl_max_ioctls = ARRAY_SIZE(qxl_ioctls);
    453