Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

virtio-gpu: add basic prime support

This is enough to enable DRI3.

Signed-off-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>

authored by

Dave Airlie and committed by
Gerd Hoffmann
11a8f280 62fb7a5e

+96 -2
+1 -1
drivers/gpu/drm/virtio/Makefile
··· 7 7 virtio-gpu-y := virtgpu_drv.o virtgpu_kms.o virtgpu_drm_bus.o virtgpu_gem.o \ 8 8 virtgpu_fb.o virtgpu_display.o virtgpu_vq.o virtgpu_ttm.o \ 9 9 virtgpu_fence.o virtgpu_object.o virtgpu_debugfs.o virtgpu_plane.o \ 10 - virtgpu_ioctl.o 10 + virtgpu_ioctl.o virtgpu_prime.o 11 11 12 12 obj-$(CONFIG_DRM_VIRTIO_GPU) += virtio-gpu.o
+12 -1
drivers/gpu/drm/virtio/virtgpu_drv.c
··· 118 118 119 119 120 120 static struct drm_driver driver = { 121 - .driver_features = DRIVER_MODESET | DRIVER_GEM, 121 + .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME, 122 122 .set_busid = drm_virtio_set_busid, 123 123 .load = virtio_gpu_driver_load, 124 124 .unload = virtio_gpu_driver_unload, ··· 133 133 .debugfs_init = virtio_gpu_debugfs_init, 134 134 .debugfs_cleanup = virtio_gpu_debugfs_takedown, 135 135 #endif 136 + .prime_handle_to_fd = drm_gem_prime_handle_to_fd, 137 + .prime_fd_to_handle = drm_gem_prime_fd_to_handle, 138 + .gem_prime_export = drm_gem_prime_export, 139 + .gem_prime_import = drm_gem_prime_import, 140 + .gem_prime_pin = virtgpu_gem_prime_pin, 141 + .gem_prime_unpin = virtgpu_gem_prime_unpin, 142 + .gem_prime_get_sg_table = virtgpu_gem_prime_get_sg_table, 143 + .gem_prime_import_sg_table = virtgpu_gem_prime_import_sg_table, 144 + .gem_prime_vmap = virtgpu_gem_prime_vmap, 145 + .gem_prime_vunmap = virtgpu_gem_prime_vunmap, 146 + .gem_prime_mmap = virtgpu_gem_prime_mmap, 136 147 137 148 .gem_free_object = virtio_gpu_gem_free_object, 138 149 .gem_open_object = virtio_gpu_gem_object_open,
+12
drivers/gpu/drm/virtio/virtgpu_drv.h
··· 359 359 void virtio_gpu_object_free_sg_table(struct virtio_gpu_object *bo); 360 360 int virtio_gpu_object_wait(struct virtio_gpu_object *bo, bool no_wait); 361 361 362 + /* virtgpu_prime.c */ 363 + int virtgpu_gem_prime_pin(struct drm_gem_object *obj); 364 + void virtgpu_gem_prime_unpin(struct drm_gem_object *obj); 365 + struct sg_table *virtgpu_gem_prime_get_sg_table(struct drm_gem_object *obj); 366 + struct drm_gem_object *virtgpu_gem_prime_import_sg_table( 367 + struct drm_device *dev, struct dma_buf_attachment *attach, 368 + struct sg_table *sgt); 369 + void *virtgpu_gem_prime_vmap(struct drm_gem_object *obj); 370 + void virtgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr); 371 + int virtgpu_gem_prime_mmap(struct drm_gem_object *obj, 372 + struct vm_area_struct *vma); 373 + 362 374 static inline struct virtio_gpu_object* 363 375 virtio_gpu_object_ref(struct virtio_gpu_object *bo) 364 376 {
+71
drivers/gpu/drm/virtio/virtgpu_prime.c
··· 1 + /* 2 + * Copyright 2014 Canonical 3 + * 4 + * Permission is hereby granted, free of charge, to any person obtaining a 5 + * copy of this software and associated documentation files (the "Software"), 6 + * to deal in the Software without restriction, including without limitation 7 + * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 + * and/or sell copies of the Software, and to permit persons to whom the 9 + * Software is furnished to do so, subject to the following conditions: 10 + * 11 + * The above copyright notice and this permission notice shall be included in 12 + * all copies or substantial portions of the Software. 13 + * 14 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 + * OTHER DEALINGS IN THE SOFTWARE. 21 + * 22 + * Authors: Andreas Pokorny 23 + */ 24 + 25 + #include "virtgpu_drv.h" 26 + 27 + /* Empty Implementations as there should not be any other driver for a virtual 28 + * device that might share buffers with virtgpu */ 29 + 30 + int virtgpu_gem_prime_pin(struct drm_gem_object *obj) 31 + { 32 + WARN_ONCE(1, "not implemented"); 33 + return -ENODEV; 34 + } 35 + 36 + void virtgpu_gem_prime_unpin(struct drm_gem_object *obj) 37 + { 38 + WARN_ONCE(1, "not implemented"); 39 + } 40 + 41 + 42 + struct sg_table *virtgpu_gem_prime_get_sg_table(struct drm_gem_object *obj) 43 + { 44 + WARN_ONCE(1, "not implemented"); 45 + return ERR_PTR(-ENODEV); 46 + } 47 + 48 + struct drm_gem_object *virtgpu_gem_prime_import_sg_table( 49 + struct drm_device *dev, struct dma_buf_attachment *attach, 50 + struct sg_table *table) 51 + { 52 + WARN_ONCE(1, "not implemented"); 53 + return ERR_PTR(-ENODEV); 54 + } 55 + 56 + void *virtgpu_gem_prime_vmap(struct drm_gem_object *obj) 57 + { 58 + WARN_ONCE(1, "not implemented"); 59 + return ERR_PTR(-ENODEV); 60 + } 61 + 62 + void virtgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr) 63 + { 64 + WARN_ONCE(1, "not implemented"); 65 + } 66 + 67 + int virtgpu_gem_prime_mmap(struct drm_gem_object *obj, 68 + struct vm_area_struct *area) 69 + { 70 + return -ENODEV; 71 + }