aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/gpu/drm/vc4/vc4_bo.c41
-rw-r--r--drivers/gpu/drm/vc4/vc4_drv.c3
-rw-r--r--drivers/gpu/drm/vc4/vc4_drv.h4
-rw-r--r--include/uapi/drm/Kbuild1
-rw-r--r--include/uapi/drm/vc4_drm.h68
5 files changed, 117 insertions, 0 deletions
diff --git a/drivers/gpu/drm/vc4/vc4_bo.c b/drivers/gpu/drm/vc4/vc4_bo.c
index 18faa5ba37b7..06cba268e17a 100644
--- a/drivers/gpu/drm/vc4/vc4_bo.c
+++ b/drivers/gpu/drm/vc4/vc4_bo.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include "vc4_drv.h" 21#include "vc4_drv.h"
22#include "uapi/drm/vc4_drm.h"
22 23
23static void vc4_bo_stats_dump(struct vc4_dev *vc4) 24static void vc4_bo_stats_dump(struct vc4_dev *vc4)
24{ 25{
@@ -346,6 +347,46 @@ static void vc4_bo_cache_time_timer(unsigned long data)
346 schedule_work(&vc4->bo_cache.time_work); 347 schedule_work(&vc4->bo_cache.time_work);
347} 348}
348 349
350int vc4_create_bo_ioctl(struct drm_device *dev, void *data,
351 struct drm_file *file_priv)
352{
353 struct drm_vc4_create_bo *args = data;
354 struct vc4_bo *bo = NULL;
355 int ret;
356
357 /*
358 * We can't allocate from the BO cache, because the BOs don't
359 * get zeroed, and that might leak data between users.
360 */
361 bo = vc4_bo_create(dev, args->size, false);
362 if (!bo)
363 return -ENOMEM;
364
365 ret = drm_gem_handle_create(file_priv, &bo->base.base, &args->handle);
366 drm_gem_object_unreference_unlocked(&bo->base.base);
367
368 return ret;
369}
370
371int vc4_mmap_bo_ioctl(struct drm_device *dev, void *data,
372 struct drm_file *file_priv)
373{
374 struct drm_vc4_mmap_bo *args = data;
375 struct drm_gem_object *gem_obj;
376
377 gem_obj = drm_gem_object_lookup(dev, file_priv, args->handle);
378 if (!gem_obj) {
379 DRM_ERROR("Failed to look up GEM BO %d\n", args->handle);
380 return -EINVAL;
381 }
382
383 /* The mmap offset was set up at BO allocation time. */
384 args->offset = drm_vma_node_offset_addr(&gem_obj->vma_node);
385
386 drm_gem_object_unreference_unlocked(gem_obj);
387 return 0;
388}
389
349void vc4_bo_cache_init(struct drm_device *dev) 390void vc4_bo_cache_init(struct drm_device *dev)
350{ 391{
351 struct vc4_dev *vc4 = to_vc4_dev(dev); 392 struct vc4_dev *vc4 = to_vc4_dev(dev);
diff --git a/drivers/gpu/drm/vc4/vc4_drv.c b/drivers/gpu/drm/vc4/vc4_drv.c
index da041fac0731..5fa468864ec8 100644
--- a/drivers/gpu/drm/vc4/vc4_drv.c
+++ b/drivers/gpu/drm/vc4/vc4_drv.c
@@ -16,6 +16,7 @@
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include "drm_fb_cma_helper.h" 17#include "drm_fb_cma_helper.h"
18 18
19#include "uapi/drm/vc4_drm.h"
19#include "vc4_drv.h" 20#include "vc4_drv.h"
20#include "vc4_regs.h" 21#include "vc4_regs.h"
21 22
@@ -73,6 +74,8 @@ static const struct file_operations vc4_drm_fops = {
73}; 74};
74 75
75static const struct drm_ioctl_desc vc4_drm_ioctls[] = { 76static const struct drm_ioctl_desc vc4_drm_ioctls[] = {
77 DRM_IOCTL_DEF_DRV(VC4_CREATE_BO, vc4_create_bo_ioctl, 0),
78 DRM_IOCTL_DEF_DRV(VC4_MMAP_BO, vc4_mmap_bo_ioctl, 0),
76}; 79};
77 80
78static struct drm_driver vc4_drm_driver = { 81static struct drm_driver vc4_drm_driver = {
diff --git a/drivers/gpu/drm/vc4/vc4_drv.h b/drivers/gpu/drm/vc4/vc4_drv.h
index 39a1ff5c8f28..fddb0a06ed3a 100644
--- a/drivers/gpu/drm/vc4/vc4_drv.h
+++ b/drivers/gpu/drm/vc4/vc4_drv.h
@@ -155,6 +155,10 @@ int vc4_dumb_create(struct drm_file *file_priv,
155 struct drm_mode_create_dumb *args); 155 struct drm_mode_create_dumb *args);
156struct dma_buf *vc4_prime_export(struct drm_device *dev, 156struct dma_buf *vc4_prime_export(struct drm_device *dev,
157 struct drm_gem_object *obj, int flags); 157 struct drm_gem_object *obj, int flags);
158int vc4_create_bo_ioctl(struct drm_device *dev, void *data,
159 struct drm_file *file_priv);
160int vc4_mmap_bo_ioctl(struct drm_device *dev, void *data,
161 struct drm_file *file_priv);
158void vc4_bo_cache_init(struct drm_device *dev); 162void vc4_bo_cache_init(struct drm_device *dev);
159void vc4_bo_cache_destroy(struct drm_device *dev); 163void vc4_bo_cache_destroy(struct drm_device *dev);
160int vc4_bo_stats_debugfs(struct seq_file *m, void *arg); 164int vc4_bo_stats_debugfs(struct seq_file *m, void *arg);
diff --git a/include/uapi/drm/Kbuild b/include/uapi/drm/Kbuild
index 38d437096c35..974fcd54e36f 100644
--- a/include/uapi/drm/Kbuild
+++ b/include/uapi/drm/Kbuild
@@ -17,4 +17,5 @@ header-y += tegra_drm.h
17header-y += via_drm.h 17header-y += via_drm.h
18header-y += vmwgfx_drm.h 18header-y += vmwgfx_drm.h
19header-y += msm_drm.h 19header-y += msm_drm.h
20header-y += vc4_drm.h
20header-y += virtgpu_drm.h 21header-y += virtgpu_drm.h
diff --git a/include/uapi/drm/vc4_drm.h b/include/uapi/drm/vc4_drm.h
new file mode 100644
index 000000000000..219d34c42272
--- /dev/null
+++ b/include/uapi/drm/vc4_drm.h
@@ -0,0 +1,68 @@
1/*
2 * Copyright © 2014-2015 Broadcom
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 (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24#ifndef _UAPI_VC4_DRM_H_
25#define _UAPI_VC4_DRM_H_
26
27#include "drm.h"
28
29#define DRM_VC4_CREATE_BO 0x03
30#define DRM_VC4_MMAP_BO 0x04
31
32#define DRM_IOCTL_VC4_CREATE_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_CREATE_BO, struct drm_vc4_create_bo)
33#define DRM_IOCTL_VC4_MMAP_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_MMAP_BO, struct drm_vc4_mmap_bo)
34
35/**
36 * struct drm_vc4_create_bo - ioctl argument for creating VC4 BOs.
37 *
38 * There are currently no values for the flags argument, but it may be
39 * used in a future extension.
40 */
41struct drm_vc4_create_bo {
42 __u32 size;
43 __u32 flags;
44 /** Returned GEM handle for the BO. */
45 __u32 handle;
46 __u32 pad;
47};
48
49/**
50 * struct drm_vc4_mmap_bo - ioctl argument for mapping VC4 BOs.
51 *
52 * This doesn't actually perform an mmap. Instead, it returns the
53 * offset you need to use in an mmap on the DRM device node. This
54 * means that tools like valgrind end up knowing about the mapped
55 * memory.
56 *
57 * There are currently no values for the flags argument, but it may be
58 * used in a future extension.
59 */
60struct drm_vc4_mmap_bo {
61 /** Handle for the object being mapped. */
62 __u32 handle;
63 __u32 flags;
64 /** offset into the drm node to use for subsequent mmap call. */
65 __u64 offset;
66};
67
68#endif /* _UAPI_VC4_DRM_H_ */