diff options
author | Daniel Vetter <daniel.vetter@ffwll.ch> | 2016-09-21 04:59:28 -0400 |
---|---|---|
committer | Sean Paul <seanpaul@chromium.org> | 2016-09-22 03:04:02 -0400 |
commit | f1e2f66ce2d9f732fec184ab885fba4b53c06016 (patch) | |
tree | 5881a515e6cd2e94a14d17ca36a40eeed0e9d023 | |
parent | 1e4d84c6589e9e9d19884e705085fe4a1885b012 (diff) |
drm: Extract drm_color_mgmt.[hc]
For both the new degamm/lut/gamma atomic combo, and the old legacy
gamma tables.
Acked-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Signed-off-by: Sean Paul <seanpaul@chromium.org>
Link: http://patchwork.freedesktop.org/patch/msgid/1474448370-32227-5-git-send-email-daniel.vetter@ffwll.ch
-rw-r--r-- | drivers/gpu/drm/Makefile | 2 | ||||
-rw-r--r-- | drivers/gpu/drm/drm_color_mgmt.c | 248 | ||||
-rw-r--r-- | drivers/gpu/drm/drm_crtc.c | 220 | ||||
-rw-r--r-- | drivers/gpu/drm/drm_crtc_internal.h | 4 | ||||
-rw-r--r-- | include/drm/drm_color_mgmt.h | 56 | ||||
-rw-r--r-- | include/drm/drm_crtc.h | 28 |
6 files changed, 310 insertions, 248 deletions
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 8eeb07a35798..25c720454017 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile | |||
@@ -15,7 +15,7 @@ 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 | 18 | drm_plane.o drm_color_mgmt.o |
19 | 19 | ||
20 | drm-$(CONFIG_COMPAT) += drm_ioc32.o | 20 | drm-$(CONFIG_COMPAT) += drm_ioc32.o |
21 | drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o | 21 | drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o |
diff --git a/drivers/gpu/drm/drm_color_mgmt.c b/drivers/gpu/drm/drm_color_mgmt.c new file mode 100644 index 000000000000..aca1b7a6397c --- /dev/null +++ b/drivers/gpu/drm/drm_color_mgmt.c | |||
@@ -0,0 +1,248 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2016 Intel Corporation | ||
3 | * | ||
4 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
5 | * documentation for any purpose is hereby granted without fee, provided that | ||
6 | * the above copyright notice appear in all copies and that both that copyright | ||
7 | * notice and this permission notice appear in supporting documentation, and | ||
8 | * that the name of the copyright holders not be used in advertising or | ||
9 | * publicity pertaining to distribution of the software without specific, | ||
10 | * written prior permission. The copyright holders make no representations | ||
11 | * about the suitability of this software for any purpose. It is provided "as | ||
12 | * is" without express or implied warranty. | ||
13 | * | ||
14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | ||
15 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO | ||
16 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR | ||
17 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, | ||
18 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
19 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE | ||
20 | * OF THIS SOFTWARE. | ||
21 | */ | ||
22 | |||
23 | #include <drm/drmP.h> | ||
24 | #include <drm/drm_crtc.h> | ||
25 | #include <drm/drm_color_mgmt.h> | ||
26 | |||
27 | #include "drm_crtc_internal.h" | ||
28 | |||
29 | |||
30 | /** | ||
31 | * drm_crtc_enable_color_mgmt - enable color management properties | ||
32 | * @crtc: DRM CRTC | ||
33 | * @degamma_lut_size: the size of the degamma lut (before CSC) | ||
34 | * @has_ctm: whether to attach ctm_property for CSC matrix | ||
35 | * @gamma_lut_size: the size of the gamma lut (after CSC) | ||
36 | * | ||
37 | * This function lets the driver enable the color correction | ||
38 | * properties on a CRTC. This includes 3 degamma, csc and gamma | ||
39 | * properties that userspace can set and 2 size properties to inform | ||
40 | * the userspace of the lut sizes. Each of the properties are | ||
41 | * optional. The gamma and degamma properties are only attached if | ||
42 | * their size is not 0 and ctm_property is only attached if has_ctm is | ||
43 | * true. | ||
44 | */ | ||
45 | void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc, | ||
46 | uint degamma_lut_size, | ||
47 | bool has_ctm, | ||
48 | uint gamma_lut_size) | ||
49 | { | ||
50 | struct drm_device *dev = crtc->dev; | ||
51 | struct drm_mode_config *config = &dev->mode_config; | ||
52 | |||
53 | if (degamma_lut_size) { | ||
54 | drm_object_attach_property(&crtc->base, | ||
55 | config->degamma_lut_property, 0); | ||
56 | drm_object_attach_property(&crtc->base, | ||
57 | config->degamma_lut_size_property, | ||
58 | degamma_lut_size); | ||
59 | } | ||
60 | |||
61 | if (has_ctm) | ||
62 | drm_object_attach_property(&crtc->base, | ||
63 | config->ctm_property, 0); | ||
64 | |||
65 | if (gamma_lut_size) { | ||
66 | drm_object_attach_property(&crtc->base, | ||
67 | config->gamma_lut_property, 0); | ||
68 | drm_object_attach_property(&crtc->base, | ||
69 | config->gamma_lut_size_property, | ||
70 | gamma_lut_size); | ||
71 | } | ||
72 | } | ||
73 | EXPORT_SYMBOL(drm_crtc_enable_color_mgmt); | ||
74 | |||
75 | /** | ||
76 | * drm_mode_crtc_set_gamma_size - set the gamma table size | ||
77 | * @crtc: CRTC to set the gamma table size for | ||
78 | * @gamma_size: size of the gamma table | ||
79 | * | ||
80 | * Drivers which support gamma tables should set this to the supported gamma | ||
81 | * table size when initializing the CRTC. Currently the drm core only supports a | ||
82 | * fixed gamma table size. | ||
83 | * | ||
84 | * Returns: | ||
85 | * Zero on success, negative errno on failure. | ||
86 | */ | ||
87 | int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc, | ||
88 | int gamma_size) | ||
89 | { | ||
90 | uint16_t *r_base, *g_base, *b_base; | ||
91 | int i; | ||
92 | |||
93 | crtc->gamma_size = gamma_size; | ||
94 | |||
95 | crtc->gamma_store = kcalloc(gamma_size, sizeof(uint16_t) * 3, | ||
96 | GFP_KERNEL); | ||
97 | if (!crtc->gamma_store) { | ||
98 | crtc->gamma_size = 0; | ||
99 | return -ENOMEM; | ||
100 | } | ||
101 | |||
102 | r_base = crtc->gamma_store; | ||
103 | g_base = r_base + gamma_size; | ||
104 | b_base = g_base + gamma_size; | ||
105 | for (i = 0; i < gamma_size; i++) { | ||
106 | r_base[i] = i << 8; | ||
107 | g_base[i] = i << 8; | ||
108 | b_base[i] = i << 8; | ||
109 | } | ||
110 | |||
111 | |||
112 | return 0; | ||
113 | } | ||
114 | EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size); | ||
115 | |||
116 | /** | ||
117 | * drm_mode_gamma_set_ioctl - set the gamma table | ||
118 | * @dev: DRM device | ||
119 | * @data: ioctl data | ||
120 | * @file_priv: DRM file info | ||
121 | * | ||
122 | * Set the gamma table of a CRTC to the one passed in by the user. Userspace can | ||
123 | * inquire the required gamma table size through drm_mode_gamma_get_ioctl. | ||
124 | * | ||
125 | * Called by the user via ioctl. | ||
126 | * | ||
127 | * Returns: | ||
128 | * Zero on success, negative errno on failure. | ||
129 | */ | ||
130 | int drm_mode_gamma_set_ioctl(struct drm_device *dev, | ||
131 | void *data, struct drm_file *file_priv) | ||
132 | { | ||
133 | struct drm_mode_crtc_lut *crtc_lut = data; | ||
134 | struct drm_crtc *crtc; | ||
135 | void *r_base, *g_base, *b_base; | ||
136 | int size; | ||
137 | int ret = 0; | ||
138 | |||
139 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) | ||
140 | return -EINVAL; | ||
141 | |||
142 | drm_modeset_lock_all(dev); | ||
143 | crtc = drm_crtc_find(dev, crtc_lut->crtc_id); | ||
144 | if (!crtc) { | ||
145 | ret = -ENOENT; | ||
146 | goto out; | ||
147 | } | ||
148 | |||
149 | if (crtc->funcs->gamma_set == NULL) { | ||
150 | ret = -ENOSYS; | ||
151 | goto out; | ||
152 | } | ||
153 | |||
154 | /* memcpy into gamma store */ | ||
155 | if (crtc_lut->gamma_size != crtc->gamma_size) { | ||
156 | ret = -EINVAL; | ||
157 | goto out; | ||
158 | } | ||
159 | |||
160 | size = crtc_lut->gamma_size * (sizeof(uint16_t)); | ||
161 | r_base = crtc->gamma_store; | ||
162 | if (copy_from_user(r_base, (void __user *)(unsigned long)crtc_lut->red, size)) { | ||
163 | ret = -EFAULT; | ||
164 | goto out; | ||
165 | } | ||
166 | |||
167 | g_base = r_base + size; | ||
168 | if (copy_from_user(g_base, (void __user *)(unsigned long)crtc_lut->green, size)) { | ||
169 | ret = -EFAULT; | ||
170 | goto out; | ||
171 | } | ||
172 | |||
173 | b_base = g_base + size; | ||
174 | if (copy_from_user(b_base, (void __user *)(unsigned long)crtc_lut->blue, size)) { | ||
175 | ret = -EFAULT; | ||
176 | goto out; | ||
177 | } | ||
178 | |||
179 | ret = crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, crtc->gamma_size); | ||
180 | |||
181 | out: | ||
182 | drm_modeset_unlock_all(dev); | ||
183 | return ret; | ||
184 | |||
185 | } | ||
186 | |||
187 | /** | ||
188 | * drm_mode_gamma_get_ioctl - get the gamma table | ||
189 | * @dev: DRM device | ||
190 | * @data: ioctl data | ||
191 | * @file_priv: DRM file info | ||
192 | * | ||
193 | * Copy the current gamma table into the storage provided. This also provides | ||
194 | * the gamma table size the driver expects, which can be used to size the | ||
195 | * allocated storage. | ||
196 | * | ||
197 | * Called by the user via ioctl. | ||
198 | * | ||
199 | * Returns: | ||
200 | * Zero on success, negative errno on failure. | ||
201 | */ | ||
202 | int drm_mode_gamma_get_ioctl(struct drm_device *dev, | ||
203 | void *data, struct drm_file *file_priv) | ||
204 | { | ||
205 | struct drm_mode_crtc_lut *crtc_lut = data; | ||
206 | struct drm_crtc *crtc; | ||
207 | void *r_base, *g_base, *b_base; | ||
208 | int size; | ||
209 | int ret = 0; | ||
210 | |||
211 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) | ||
212 | return -EINVAL; | ||
213 | |||
214 | drm_modeset_lock_all(dev); | ||
215 | crtc = drm_crtc_find(dev, crtc_lut->crtc_id); | ||
216 | if (!crtc) { | ||
217 | ret = -ENOENT; | ||
218 | goto out; | ||
219 | } | ||
220 | |||
221 | /* memcpy into gamma store */ | ||
222 | if (crtc_lut->gamma_size != crtc->gamma_size) { | ||
223 | ret = -EINVAL; | ||
224 | goto out; | ||
225 | } | ||
226 | |||
227 | size = crtc_lut->gamma_size * (sizeof(uint16_t)); | ||
228 | r_base = crtc->gamma_store; | ||
229 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->red, r_base, size)) { | ||
230 | ret = -EFAULT; | ||
231 | goto out; | ||
232 | } | ||
233 | |||
234 | g_base = r_base + size; | ||
235 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->green, g_base, size)) { | ||
236 | ret = -EFAULT; | ||
237 | goto out; | ||
238 | } | ||
239 | |||
240 | b_base = g_base + size; | ||
241 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->blue, b_base, size)) { | ||
242 | ret = -EFAULT; | ||
243 | goto out; | ||
244 | } | ||
245 | out: | ||
246 | drm_modeset_unlock_all(dev); | ||
247 | return ret; | ||
248 | } | ||
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 3ac81019ae6f..2d7bedf28647 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c | |||
@@ -904,181 +904,6 @@ int drm_mode_crtc_set_obj_prop(struct drm_mode_object *obj, | |||
904 | } | 904 | } |
905 | 905 | ||
906 | /** | 906 | /** |
907 | * drm_mode_crtc_set_gamma_size - set the gamma table size | ||
908 | * @crtc: CRTC to set the gamma table size for | ||
909 | * @gamma_size: size of the gamma table | ||
910 | * | ||
911 | * Drivers which support gamma tables should set this to the supported gamma | ||
912 | * table size when initializing the CRTC. Currently the drm core only supports a | ||
913 | * fixed gamma table size. | ||
914 | * | ||
915 | * Returns: | ||
916 | * Zero on success, negative errno on failure. | ||
917 | */ | ||
918 | int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc, | ||
919 | int gamma_size) | ||
920 | { | ||
921 | uint16_t *r_base, *g_base, *b_base; | ||
922 | int i; | ||
923 | |||
924 | crtc->gamma_size = gamma_size; | ||
925 | |||
926 | crtc->gamma_store = kcalloc(gamma_size, sizeof(uint16_t) * 3, | ||
927 | GFP_KERNEL); | ||
928 | if (!crtc->gamma_store) { | ||
929 | crtc->gamma_size = 0; | ||
930 | return -ENOMEM; | ||
931 | } | ||
932 | |||
933 | r_base = crtc->gamma_store; | ||
934 | g_base = r_base + gamma_size; | ||
935 | b_base = g_base + gamma_size; | ||
936 | for (i = 0; i < gamma_size; i++) { | ||
937 | r_base[i] = i << 8; | ||
938 | g_base[i] = i << 8; | ||
939 | b_base[i] = i << 8; | ||
940 | } | ||
941 | |||
942 | |||
943 | return 0; | ||
944 | } | ||
945 | EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size); | ||
946 | |||
947 | /** | ||
948 | * drm_mode_gamma_set_ioctl - set the gamma table | ||
949 | * @dev: DRM device | ||
950 | * @data: ioctl data | ||
951 | * @file_priv: DRM file info | ||
952 | * | ||
953 | * Set the gamma table of a CRTC to the one passed in by the user. Userspace can | ||
954 | * inquire the required gamma table size through drm_mode_gamma_get_ioctl. | ||
955 | * | ||
956 | * Called by the user via ioctl. | ||
957 | * | ||
958 | * Returns: | ||
959 | * Zero on success, negative errno on failure. | ||
960 | */ | ||
961 | int drm_mode_gamma_set_ioctl(struct drm_device *dev, | ||
962 | void *data, struct drm_file *file_priv) | ||
963 | { | ||
964 | struct drm_mode_crtc_lut *crtc_lut = data; | ||
965 | struct drm_crtc *crtc; | ||
966 | void *r_base, *g_base, *b_base; | ||
967 | int size; | ||
968 | int ret = 0; | ||
969 | |||
970 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) | ||
971 | return -EINVAL; | ||
972 | |||
973 | drm_modeset_lock_all(dev); | ||
974 | crtc = drm_crtc_find(dev, crtc_lut->crtc_id); | ||
975 | if (!crtc) { | ||
976 | ret = -ENOENT; | ||
977 | goto out; | ||
978 | } | ||
979 | |||
980 | if (crtc->funcs->gamma_set == NULL) { | ||
981 | ret = -ENOSYS; | ||
982 | goto out; | ||
983 | } | ||
984 | |||
985 | /* memcpy into gamma store */ | ||
986 | if (crtc_lut->gamma_size != crtc->gamma_size) { | ||
987 | ret = -EINVAL; | ||
988 | goto out; | ||
989 | } | ||
990 | |||
991 | size = crtc_lut->gamma_size * (sizeof(uint16_t)); | ||
992 | r_base = crtc->gamma_store; | ||
993 | if (copy_from_user(r_base, (void __user *)(unsigned long)crtc_lut->red, size)) { | ||
994 | ret = -EFAULT; | ||
995 | goto out; | ||
996 | } | ||
997 | |||
998 | g_base = r_base + size; | ||
999 | if (copy_from_user(g_base, (void __user *)(unsigned long)crtc_lut->green, size)) { | ||
1000 | ret = -EFAULT; | ||
1001 | goto out; | ||
1002 | } | ||
1003 | |||
1004 | b_base = g_base + size; | ||
1005 | if (copy_from_user(b_base, (void __user *)(unsigned long)crtc_lut->blue, size)) { | ||
1006 | ret = -EFAULT; | ||
1007 | goto out; | ||
1008 | } | ||
1009 | |||
1010 | ret = crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, crtc->gamma_size); | ||
1011 | |||
1012 | out: | ||
1013 | drm_modeset_unlock_all(dev); | ||
1014 | return ret; | ||
1015 | |||
1016 | } | ||
1017 | |||
1018 | /** | ||
1019 | * drm_mode_gamma_get_ioctl - get the gamma table | ||
1020 | * @dev: DRM device | ||
1021 | * @data: ioctl data | ||
1022 | * @file_priv: DRM file info | ||
1023 | * | ||
1024 | * Copy the current gamma table into the storage provided. This also provides | ||
1025 | * the gamma table size the driver expects, which can be used to size the | ||
1026 | * allocated storage. | ||
1027 | * | ||
1028 | * Called by the user via ioctl. | ||
1029 | * | ||
1030 | * Returns: | ||
1031 | * Zero on success, negative errno on failure. | ||
1032 | */ | ||
1033 | int drm_mode_gamma_get_ioctl(struct drm_device *dev, | ||
1034 | void *data, struct drm_file *file_priv) | ||
1035 | { | ||
1036 | struct drm_mode_crtc_lut *crtc_lut = data; | ||
1037 | struct drm_crtc *crtc; | ||
1038 | void *r_base, *g_base, *b_base; | ||
1039 | int size; | ||
1040 | int ret = 0; | ||
1041 | |||
1042 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) | ||
1043 | return -EINVAL; | ||
1044 | |||
1045 | drm_modeset_lock_all(dev); | ||
1046 | crtc = drm_crtc_find(dev, crtc_lut->crtc_id); | ||
1047 | if (!crtc) { | ||
1048 | ret = -ENOENT; | ||
1049 | goto out; | ||
1050 | } | ||
1051 | |||
1052 | /* memcpy into gamma store */ | ||
1053 | if (crtc_lut->gamma_size != crtc->gamma_size) { | ||
1054 | ret = -EINVAL; | ||
1055 | goto out; | ||
1056 | } | ||
1057 | |||
1058 | size = crtc_lut->gamma_size * (sizeof(uint16_t)); | ||
1059 | r_base = crtc->gamma_store; | ||
1060 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->red, r_base, size)) { | ||
1061 | ret = -EFAULT; | ||
1062 | goto out; | ||
1063 | } | ||
1064 | |||
1065 | g_base = r_base + size; | ||
1066 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->green, g_base, size)) { | ||
1067 | ret = -EFAULT; | ||
1068 | goto out; | ||
1069 | } | ||
1070 | |||
1071 | b_base = g_base + size; | ||
1072 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->blue, b_base, size)) { | ||
1073 | ret = -EFAULT; | ||
1074 | goto out; | ||
1075 | } | ||
1076 | out: | ||
1077 | drm_modeset_unlock_all(dev); | ||
1078 | return ret; | ||
1079 | } | ||
1080 | |||
1081 | /** | ||
1082 | * drm_mode_config_reset - call ->reset callbacks | 907 | * drm_mode_config_reset - call ->reset callbacks |
1083 | * @dev: drm device | 908 | * @dev: drm device |
1084 | * | 909 | * |
@@ -1436,48 +1261,3 @@ struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev, | |||
1436 | return tg; | 1261 | return tg; |
1437 | } | 1262 | } |
1438 | EXPORT_SYMBOL(drm_mode_create_tile_group); | 1263 | EXPORT_SYMBOL(drm_mode_create_tile_group); |
1439 | |||
1440 | /** | ||
1441 | * drm_crtc_enable_color_mgmt - enable color management properties | ||
1442 | * @crtc: DRM CRTC | ||
1443 | * @degamma_lut_size: the size of the degamma lut (before CSC) | ||
1444 | * @has_ctm: whether to attach ctm_property for CSC matrix | ||
1445 | * @gamma_lut_size: the size of the gamma lut (after CSC) | ||
1446 | * | ||
1447 | * This function lets the driver enable the color correction | ||
1448 | * properties on a CRTC. This includes 3 degamma, csc and gamma | ||
1449 | * properties that userspace can set and 2 size properties to inform | ||
1450 | * the userspace of the lut sizes. Each of the properties are | ||
1451 | * optional. The gamma and degamma properties are only attached if | ||
1452 | * their size is not 0 and ctm_property is only attached if has_ctm is | ||
1453 | * true. | ||
1454 | */ | ||
1455 | void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc, | ||
1456 | uint degamma_lut_size, | ||
1457 | bool has_ctm, | ||
1458 | uint gamma_lut_size) | ||
1459 | { | ||
1460 | struct drm_device *dev = crtc->dev; | ||
1461 | struct drm_mode_config *config = &dev->mode_config; | ||
1462 | |||
1463 | if (degamma_lut_size) { | ||
1464 | drm_object_attach_property(&crtc->base, | ||
1465 | config->degamma_lut_property, 0); | ||
1466 | drm_object_attach_property(&crtc->base, | ||
1467 | config->degamma_lut_size_property, | ||
1468 | degamma_lut_size); | ||
1469 | } | ||
1470 | |||
1471 | if (has_ctm) | ||
1472 | drm_object_attach_property(&crtc->base, | ||
1473 | config->ctm_property, 0); | ||
1474 | |||
1475 | if (gamma_lut_size) { | ||
1476 | drm_object_attach_property(&crtc->base, | ||
1477 | config->gamma_lut_property, 0); | ||
1478 | drm_object_attach_property(&crtc->base, | ||
1479 | config->gamma_lut_size_property, | ||
1480 | gamma_lut_size); | ||
1481 | } | ||
1482 | } | ||
1483 | EXPORT_SYMBOL(drm_crtc_enable_color_mgmt); | ||
diff --git a/drivers/gpu/drm/drm_crtc_internal.h b/drivers/gpu/drm/drm_crtc_internal.h index 2672f3b45d9c..c48ba02c5365 100644 --- a/drivers/gpu/drm/drm_crtc_internal.h +++ b/drivers/gpu/drm/drm_crtc_internal.h | |||
@@ -58,6 +58,10 @@ int drm_mode_getcrtc(struct drm_device *dev, | |||
58 | void *data, struct drm_file *file_priv); | 58 | void *data, struct drm_file *file_priv); |
59 | int drm_mode_setcrtc(struct drm_device *dev, | 59 | int drm_mode_setcrtc(struct drm_device *dev, |
60 | void *data, struct drm_file *file_priv); | 60 | void *data, struct drm_file *file_priv); |
61 | |||
62 | /* drm_color_mgmt.c */ | ||
63 | |||
64 | /* IOCTLs */ | ||
61 | int drm_mode_gamma_get_ioctl(struct drm_device *dev, | 65 | int drm_mode_gamma_get_ioctl(struct drm_device *dev, |
62 | void *data, struct drm_file *file_priv); | 66 | void *data, struct drm_file *file_priv); |
63 | int drm_mode_gamma_set_ioctl(struct drm_device *dev, | 67 | int drm_mode_gamma_set_ioctl(struct drm_device *dev, |
diff --git a/include/drm/drm_color_mgmt.h b/include/drm/drm_color_mgmt.h new file mode 100644 index 000000000000..1e01c58bbe81 --- /dev/null +++ b/include/drm/drm_color_mgmt.h | |||
@@ -0,0 +1,56 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2016 Intel Corporation | ||
3 | * | ||
4 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
5 | * documentation for any purpose is hereby granted without fee, provided that | ||
6 | * the above copyright notice appear in all copies and that both that copyright | ||
7 | * notice and this permission notice appear in supporting documentation, and | ||
8 | * that the name of the copyright holders not be used in advertising or | ||
9 | * publicity pertaining to distribution of the software without specific, | ||
10 | * written prior permission. The copyright holders make no representations | ||
11 | * about the suitability of this software for any purpose. It is provided "as | ||
12 | * is" without express or implied warranty. | ||
13 | * | ||
14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | ||
15 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO | ||
16 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR | ||
17 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, | ||
18 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
19 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE | ||
20 | * OF THIS SOFTWARE. | ||
21 | */ | ||
22 | |||
23 | #ifndef __DRM_COLOR_MGMT_H__ | ||
24 | #define __DRM_COLOR_MGMT_H__ | ||
25 | |||
26 | #include <linux/ctype.h> | ||
27 | |||
28 | void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc, | ||
29 | uint degamma_lut_size, | ||
30 | bool has_ctm, | ||
31 | uint gamma_lut_size); | ||
32 | |||
33 | int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc, | ||
34 | int gamma_size); | ||
35 | |||
36 | /* | ||
37 | * Extract a degamma/gamma LUT value provided by user and round it to the | ||
38 | * precision supported by the hardware. | ||
39 | */ | ||
40 | static inline uint32_t drm_color_lut_extract(uint32_t user_input, | ||
41 | uint32_t bit_precision) | ||
42 | { | ||
43 | uint32_t val = user_input; | ||
44 | uint32_t max = 0xffff >> (16 - bit_precision); | ||
45 | |||
46 | /* Round only if we're not using full precision. */ | ||
47 | if (bit_precision < 16) { | ||
48 | val += 1UL << (16 - bit_precision - 1); | ||
49 | val >>= 16 - bit_precision; | ||
50 | } | ||
51 | |||
52 | return clamp_val(val, 0, max); | ||
53 | } | ||
54 | |||
55 | |||
56 | #endif | ||
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index 8d06cabede59..a544b7502493 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h | |||
@@ -46,6 +46,7 @@ | |||
46 | #include <drm/drm_edid.h> | 46 | #include <drm/drm_edid.h> |
47 | #include <drm/drm_plane.h> | 47 | #include <drm/drm_plane.h> |
48 | #include <drm/drm_blend.h> | 48 | #include <drm/drm_blend.h> |
49 | #include <drm/drm_color_mgmt.h> | ||
49 | 50 | ||
50 | struct drm_device; | 51 | struct drm_device; |
51 | struct drm_mode_set; | 52 | struct drm_mode_set; |
@@ -1337,9 +1338,6 @@ extern void drm_mode_config_init(struct drm_device *dev); | |||
1337 | extern void drm_mode_config_reset(struct drm_device *dev); | 1338 | extern void drm_mode_config_reset(struct drm_device *dev); |
1338 | extern void drm_mode_config_cleanup(struct drm_device *dev); | 1339 | extern void drm_mode_config_cleanup(struct drm_device *dev); |
1339 | 1340 | ||
1340 | extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc, | ||
1341 | int gamma_size); | ||
1342 | |||
1343 | extern int drm_mode_set_config_internal(struct drm_mode_set *set); | 1341 | extern int drm_mode_set_config_internal(struct drm_mode_set *set); |
1344 | 1342 | ||
1345 | extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev, | 1343 | extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev, |
@@ -1349,11 +1347,6 @@ extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev, | |||
1349 | extern void drm_mode_put_tile_group(struct drm_device *dev, | 1347 | extern void drm_mode_put_tile_group(struct drm_device *dev, |
1350 | struct drm_tile_group *tg); | 1348 | struct drm_tile_group *tg); |
1351 | 1349 | ||
1352 | extern void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc, | ||
1353 | uint degamma_lut_size, | ||
1354 | bool has_ctm, | ||
1355 | uint gamma_lut_size); | ||
1356 | |||
1357 | /* Helpers */ | 1350 | /* Helpers */ |
1358 | static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev, | 1351 | static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev, |
1359 | uint32_t id) | 1352 | uint32_t id) |
@@ -1363,25 +1356,6 @@ static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev, | |||
1363 | return mo ? obj_to_crtc(mo) : NULL; | 1356 | return mo ? obj_to_crtc(mo) : NULL; |
1364 | } | 1357 | } |
1365 | 1358 | ||
1366 | /* | ||
1367 | * Extract a degamma/gamma LUT value provided by user and round it to the | ||
1368 | * precision supported by the hardware. | ||
1369 | */ | ||
1370 | static inline uint32_t drm_color_lut_extract(uint32_t user_input, | ||
1371 | uint32_t bit_precision) | ||
1372 | { | ||
1373 | uint32_t val = user_input; | ||
1374 | uint32_t max = 0xffff >> (16 - bit_precision); | ||
1375 | |||
1376 | /* Round only if we're not using full precision. */ | ||
1377 | if (bit_precision < 16) { | ||
1378 | val += 1UL << (16 - bit_precision - 1); | ||
1379 | val >>= 16 - bit_precision; | ||
1380 | } | ||
1381 | |||
1382 | return clamp_val(val, 0, max); | ||
1383 | } | ||
1384 | |||
1385 | #define drm_for_each_crtc(crtc, dev) \ | 1359 | #define drm_for_each_crtc(crtc, dev) \ |
1386 | list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head) | 1360 | list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head) |
1387 | 1361 | ||