aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/gpu/drm/Makefile3
-rw-r--r--drivers/gpu/drm/drm_crtc.c109
-rw-r--r--drivers/gpu/drm/drm_crtc_internal.h18
-rw-r--r--drivers/gpu/drm/drm_dumb_buffers.c138
4 files changed, 150 insertions, 118 deletions
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index f217274754d4..adcfc8f922e3 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -15,7 +15,8 @@ drm-y := drm_auth.o drm_bufs.o drm_cache.o \
15 drm_modeset_lock.o drm_atomic.o drm_bridge.o \ 15 drm_modeset_lock.o drm_atomic.o drm_bridge.o \
16 drm_framebuffer.o drm_connector.o drm_blend.o \ 16 drm_framebuffer.o drm_connector.o drm_blend.o \
17 drm_encoder.o drm_mode_object.o drm_property.o \ 17 drm_encoder.o drm_mode_object.o drm_property.o \
18 drm_plane.o drm_color_mgmt.o drm_print.o 18 drm_plane.o drm_color_mgmt.o drm_print.o \
19 drm_dumb_buffers.o
19 20
20drm-$(CONFIG_COMPAT) += drm_ioc32.o 21drm-$(CONFIG_COMPAT) += drm_ioc32.o
21drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o 22drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 7612f85e99fb..b0827634af18 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -969,115 +969,6 @@ void drm_mode_config_reset(struct drm_device *dev)
969EXPORT_SYMBOL(drm_mode_config_reset); 969EXPORT_SYMBOL(drm_mode_config_reset);
970 970
971/** 971/**
972 * drm_mode_create_dumb_ioctl - create a dumb backing storage buffer
973 * @dev: DRM device
974 * @data: ioctl data
975 * @file_priv: DRM file info
976 *
977 * This creates a new dumb buffer in the driver's backing storage manager (GEM,
978 * TTM or something else entirely) and returns the resulting buffer handle. This
979 * handle can then be wrapped up into a framebuffer modeset object.
980 *
981 * Note that userspace is not allowed to use such objects for render
982 * acceleration - drivers must create their own private ioctls for such a use
983 * case.
984 *
985 * Called by the user via ioctl.
986 *
987 * Returns:
988 * Zero on success, negative errno on failure.
989 */
990int drm_mode_create_dumb_ioctl(struct drm_device *dev,
991 void *data, struct drm_file *file_priv)
992{
993 struct drm_mode_create_dumb *args = data;
994 u32 cpp, stride, size;
995
996 if (!dev->driver->dumb_create)
997 return -ENOSYS;
998 if (!args->width || !args->height || !args->bpp)
999 return -EINVAL;
1000
1001 /* overflow checks for 32bit size calculations */
1002 /* NOTE: DIV_ROUND_UP() can overflow */
1003 cpp = DIV_ROUND_UP(args->bpp, 8);
1004 if (!cpp || cpp > 0xffffffffU / args->width)
1005 return -EINVAL;
1006 stride = cpp * args->width;
1007 if (args->height > 0xffffffffU / stride)
1008 return -EINVAL;
1009
1010 /* test for wrap-around */
1011 size = args->height * stride;
1012 if (PAGE_ALIGN(size) == 0)
1013 return -EINVAL;
1014
1015 /*
1016 * handle, pitch and size are output parameters. Zero them out to
1017 * prevent drivers from accidentally using uninitialized data. Since
1018 * not all existing userspace is clearing these fields properly we
1019 * cannot reject IOCTL with garbage in them.
1020 */
1021 args->handle = 0;
1022 args->pitch = 0;
1023 args->size = 0;
1024
1025 return dev->driver->dumb_create(file_priv, dev, args);
1026}
1027
1028/**
1029 * drm_mode_mmap_dumb_ioctl - create an mmap offset for a dumb backing storage buffer
1030 * @dev: DRM device
1031 * @data: ioctl data
1032 * @file_priv: DRM file info
1033 *
1034 * Allocate an offset in the drm device node's address space to be able to
1035 * memory map a dumb buffer.
1036 *
1037 * Called by the user via ioctl.
1038 *
1039 * Returns:
1040 * Zero on success, negative errno on failure.
1041 */
1042int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
1043 void *data, struct drm_file *file_priv)
1044{
1045 struct drm_mode_map_dumb *args = data;
1046
1047 /* call driver ioctl to get mmap offset */
1048 if (!dev->driver->dumb_map_offset)
1049 return -ENOSYS;
1050
1051 return dev->driver->dumb_map_offset(file_priv, dev, args->handle, &args->offset);
1052}
1053
1054/**
1055 * drm_mode_destroy_dumb_ioctl - destroy a dumb backing strage buffer
1056 * @dev: DRM device
1057 * @data: ioctl data
1058 * @file_priv: DRM file info
1059 *
1060 * This destroys the userspace handle for the given dumb backing storage buffer.
1061 * Since buffer objects must be reference counted in the kernel a buffer object
1062 * won't be immediately freed if a framebuffer modeset object still uses it.
1063 *
1064 * Called by the user via ioctl.
1065 *
1066 * Returns:
1067 * Zero on success, negative errno on failure.
1068 */
1069int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
1070 void *data, struct drm_file *file_priv)
1071{
1072 struct drm_mode_destroy_dumb *args = data;
1073
1074 if (!dev->driver->dumb_destroy)
1075 return -ENOSYS;
1076
1077 return dev->driver->dumb_destroy(file_priv, dev, args->handle);
1078}
1079
1080/**
1081 * drm_mode_config_init - initialize DRM mode_configuration structure 972 * drm_mode_config_init - initialize DRM mode_configuration structure
1082 * @dev: DRM device 973 * @dev: DRM device
1083 * 974 *
diff --git a/drivers/gpu/drm/drm_crtc_internal.h b/drivers/gpu/drm/drm_crtc_internal.h
index c48ba02c5365..64bb3eb7f806 100644
--- a/drivers/gpu/drm/drm_crtc_internal.h
+++ b/drivers/gpu/drm/drm_crtc_internal.h
@@ -43,14 +43,6 @@ int drm_crtc_check_viewport(const struct drm_crtc *crtc,
43 43
44void drm_fb_release(struct drm_file *file_priv); 44void drm_fb_release(struct drm_file *file_priv);
45 45
46/* dumb buffer support IOCTLs */
47int drm_mode_create_dumb_ioctl(struct drm_device *dev,
48 void *data, struct drm_file *file_priv);
49int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
50 void *data, struct drm_file *file_priv);
51int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
52 void *data, struct drm_file *file_priv);
53
54/* IOCTLs */ 46/* IOCTLs */
55int drm_mode_getresources(struct drm_device *dev, 47int drm_mode_getresources(struct drm_device *dev,
56 void *data, struct drm_file *file_priv); 48 void *data, struct drm_file *file_priv);
@@ -59,6 +51,16 @@ int drm_mode_getcrtc(struct drm_device *dev,
59int drm_mode_setcrtc(struct drm_device *dev, 51int drm_mode_setcrtc(struct drm_device *dev,
60 void *data, struct drm_file *file_priv); 52 void *data, struct drm_file *file_priv);
61 53
54/* drm_dumb_buffers.c */
55
56/* IOCTLs */
57int drm_mode_create_dumb_ioctl(struct drm_device *dev,
58 void *data, struct drm_file *file_priv);
59int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
60 void *data, struct drm_file *file_priv);
61int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
62 void *data, struct drm_file *file_priv);
63
62/* drm_color_mgmt.c */ 64/* drm_color_mgmt.c */
63 65
64/* IOCTLs */ 66/* IOCTLs */
diff --git a/drivers/gpu/drm/drm_dumb_buffers.c b/drivers/gpu/drm/drm_dumb_buffers.c
new file mode 100644
index 000000000000..cd291b538f5a
--- /dev/null
+++ b/drivers/gpu/drm/drm_dumb_buffers.c
@@ -0,0 +1,138 @@
1/*
2 * Copyright (c) 2006-2008 Intel Corporation
3 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
4 * Copyright (c) 2008 Red Hat Inc.
5 * Copyright (c) 2016 Intel Corporation
6 *
7 * Permission to use, copy, modify, distribute, and sell this software and its
8 * documentation for any purpose is hereby granted without fee, provided that
9 * the above copyright notice appear in all copies and that both that copyright
10 * notice and this permission notice appear in supporting documentation, and
11 * that the name of the copyright holders not be used in advertising or
12 * publicity pertaining to distribution of the software without specific,
13 * written prior permission. The copyright holders make no representations
14 * about the suitability of this software for any purpose. It is provided "as
15 * is" without express or implied warranty.
16 *
17 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
18 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
19 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
20 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
22 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
23 * OF THIS SOFTWARE.
24 */
25
26#include <drm/drmP.h>
27
28#include "drm_crtc_internal.h"
29
30/**
31 * drm_mode_create_dumb_ioctl - create a dumb backing storage buffer
32 * @dev: DRM device
33 * @data: ioctl data
34 * @file_priv: DRM file info
35 *
36 * This creates a new dumb buffer in the driver's backing storage manager (GEM,
37 * TTM or something else entirely) and returns the resulting buffer handle. This
38 * handle can then be wrapped up into a framebuffer modeset object.
39 *
40 * Note that userspace is not allowed to use such objects for render
41 * acceleration - drivers must create their own private ioctls for such a use
42 * case.
43 *
44 * Called by the user via ioctl.
45 *
46 * Returns:
47 * Zero on success, negative errno on failure.
48 */
49int drm_mode_create_dumb_ioctl(struct drm_device *dev,
50 void *data, struct drm_file *file_priv)
51{
52 struct drm_mode_create_dumb *args = data;
53 u32 cpp, stride, size;
54
55 if (!dev->driver->dumb_create)
56 return -ENOSYS;
57 if (!args->width || !args->height || !args->bpp)
58 return -EINVAL;
59
60 /* overflow checks for 32bit size calculations */
61 /* NOTE: DIV_ROUND_UP() can overflow */
62 cpp = DIV_ROUND_UP(args->bpp, 8);
63 if (!cpp || cpp > 0xffffffffU / args->width)
64 return -EINVAL;
65 stride = cpp * args->width;
66 if (args->height > 0xffffffffU / stride)
67 return -EINVAL;
68
69 /* test for wrap-around */
70 size = args->height * stride;
71 if (PAGE_ALIGN(size) == 0)
72 return -EINVAL;
73
74 /*
75 * handle, pitch and size are output parameters. Zero them out to
76 * prevent drivers from accidentally using uninitialized data. Since
77 * not all existing userspace is clearing these fields properly we
78 * cannot reject IOCTL with garbage in them.
79 */
80 args->handle = 0;
81 args->pitch = 0;
82 args->size = 0;
83
84 return dev->driver->dumb_create(file_priv, dev, args);
85}
86
87/**
88 * drm_mode_mmap_dumb_ioctl - create an mmap offset for a dumb backing storage buffer
89 * @dev: DRM device
90 * @data: ioctl data
91 * @file_priv: DRM file info
92 *
93 * Allocate an offset in the drm device node's address space to be able to
94 * memory map a dumb buffer.
95 *
96 * Called by the user via ioctl.
97 *
98 * Returns:
99 * Zero on success, negative errno on failure.
100 */
101int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
102 void *data, struct drm_file *file_priv)
103{
104 struct drm_mode_map_dumb *args = data;
105
106 /* call driver ioctl to get mmap offset */
107 if (!dev->driver->dumb_map_offset)
108 return -ENOSYS;
109
110 return dev->driver->dumb_map_offset(file_priv, dev, args->handle, &args->offset);
111}
112
113/**
114 * drm_mode_destroy_dumb_ioctl - destroy a dumb backing strage buffer
115 * @dev: DRM device
116 * @data: ioctl data
117 * @file_priv: DRM file info
118 *
119 * This destroys the userspace handle for the given dumb backing storage buffer.
120 * Since buffer objects must be reference counted in the kernel a buffer object
121 * won't be immediately freed if a framebuffer modeset object still uses it.
122 *
123 * Called by the user via ioctl.
124 *
125 * Returns:
126 * Zero on success, negative errno on failure.
127 */
128int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
129 void *data, struct drm_file *file_priv)
130{
131 struct drm_mode_destroy_dumb *args = data;
132
133 if (!dev->driver->dumb_destroy)
134 return -ENOSYS;
135
136 return dev->driver->dumb_destroy(file_priv, dev, args->handle);
137}
138