1 /* $NetBSD: qxl_dumb.c,v 1.3 2021/12/18 23:45:42 riastradh Exp $ */ 2 3 /* 4 * Copyright 2013 Red Hat Inc. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 * OTHER DEALINGS IN THE SOFTWARE. 23 * 24 * Authors: Dave Airlie 25 * Alon Levy 26 */ 27 28 #include <sys/cdefs.h> 29 __KERNEL_RCSID(0, "$NetBSD: qxl_dumb.c,v 1.3 2021/12/18 23:45:42 riastradh Exp $"); 30 31 #include "qxl_drv.h" 32 #include "qxl_object.h" 33 34 /* dumb ioctls implementation */ 35 36 int qxl_mode_dumb_create(struct drm_file *file_priv, 37 struct drm_device *dev, 38 struct drm_mode_create_dumb *args) 39 { 40 struct qxl_device *qdev = dev->dev_private; 41 struct qxl_bo *qobj; 42 uint32_t handle; 43 int r; 44 struct qxl_surface surf; 45 uint32_t pitch, format; 46 47 pitch = args->width * ((args->bpp + 1) / 8); 48 args->size = pitch * args->height; 49 args->size = ALIGN(args->size, PAGE_SIZE); 50 51 switch (args->bpp) { 52 case 16: 53 format = SPICE_SURFACE_FMT_16_565; 54 break; 55 case 32: 56 format = SPICE_SURFACE_FMT_32_xRGB; 57 break; 58 default: 59 return -EINVAL; 60 } 61 62 surf.width = args->width; 63 surf.height = args->height; 64 surf.stride = pitch; 65 surf.format = format; 66 r = qxl_gem_object_create_with_handle(qdev, file_priv, 67 QXL_GEM_DOMAIN_SURFACE, 68 args->size, &surf, &qobj, 69 &handle); 70 if (r) 71 return r; 72 qobj->is_dumb = true; 73 args->pitch = pitch; 74 args->handle = handle; 75 return 0; 76 } 77 78 int qxl_mode_dumb_mmap(struct drm_file *file_priv, 79 struct drm_device *dev, 80 uint32_t handle, uint64_t *offset_p) 81 { 82 struct drm_gem_object *gobj; 83 struct qxl_bo *qobj; 84 85 BUG_ON(!offset_p); 86 gobj = drm_gem_object_lookup(file_priv, handle); 87 if (gobj == NULL) 88 return -ENOENT; 89 qobj = gem_to_qxl_bo(gobj); 90 *offset_p = qxl_bo_mmap_offset(qobj); 91 drm_gem_object_put_unlocked(gobj); 92 return 0; 93 } 94