blob: b36afcbbc83febc9ccdee1cc63442b1a3ed8a46c [file] [log] [blame]
Ilia Mirkin515de6b2013-09-07 20:33:43 -04001/*
2 * Copyright 2013 Ilia Mirkin
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 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 *
22 * Implementation based on the pre-KMS implementation in xf86-video-nouveau,
23 * written by Arthur Huillet.
24 */
25
26#include <drm/drmP.h>
27#include <drm/drm_crtc.h>
28#include <drm/drm_fourcc.h>
29
30#include "nouveau_drm.h"
31
32#include "nouveau_bo.h"
33#include "nouveau_connector.h"
34#include "nouveau_display.h"
35#include "nvreg.h"
36
37
38struct nouveau_plane {
39 struct drm_plane base;
40 bool flip;
41 struct nouveau_bo *cur;
42
43 struct {
44 struct drm_property *colorkey;
45 struct drm_property *contrast;
46 struct drm_property *brightness;
47 struct drm_property *hue;
48 struct drm_property *saturation;
49 struct drm_property *iturbt_709;
50 } props;
51
52 int colorkey;
53 int contrast;
54 int brightness;
55 int hue;
56 int saturation;
57 int iturbt_709;
Ilia Mirkinab9b18a2013-11-15 11:26:45 -050058
59 void (*set_params)(struct nouveau_plane *);
Ilia Mirkin515de6b2013-09-07 20:33:43 -040060};
61
62static uint32_t formats[] = {
Ilia Mirkin7ffb0782013-11-15 11:26:44 -050063 DRM_FORMAT_YUYV,
Ilia Mirkin515de6b2013-09-07 20:33:43 -040064 DRM_FORMAT_UYVY,
Ilia Mirkinefffa982013-11-15 11:26:43 -050065 DRM_FORMAT_NV12,
Ilia Mirkin515de6b2013-09-07 20:33:43 -040066};
67
68/* Sine can be approximated with
69 * http://en.wikipedia.org/wiki/Bhaskara_I's_sine_approximation_formula
70 * sin(x degrees) ~= 4 x (180 - x) / (40500 - x (180 - x) )
71 * Note that this only works for the range [0, 180].
72 * Also note that sin(x) == -sin(x - 180)
73 */
74static inline int
75sin_mul(int degrees, int factor)
76{
77 if (degrees > 180) {
78 degrees -= 180;
79 factor *= -1;
80 }
81 return factor * 4 * degrees * (180 - degrees) /
82 (40500 - degrees * (180 - degrees));
83}
84
85/* cos(x) = sin(x + 90) */
86static inline int
87cos_mul(int degrees, int factor)
88{
89 return sin_mul((degrees + 90) % 360, factor);
90}
91
92static int
93nv10_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
94 struct drm_framebuffer *fb, int crtc_x, int crtc_y,
95 unsigned int crtc_w, unsigned int crtc_h,
96 uint32_t src_x, uint32_t src_y,
97 uint32_t src_w, uint32_t src_h)
98{
Ben Skeggs967e7bd2014-08-10 04:10:22 +100099 struct nvif_device *dev = &nouveau_drm(plane->dev)->device;
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400100 struct nouveau_plane *nv_plane = (struct nouveau_plane *)plane;
101 struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
102 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
103 struct nouveau_bo *cur = nv_plane->cur;
104 bool flip = nv_plane->flip;
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400105 int soff = NV_PCRTC0_SIZE * nv_crtc->index;
106 int soff2 = NV_PCRTC0_SIZE * !nv_crtc->index;
Ilia Mirkin92e5b0a2013-11-15 11:26:41 -0500107 int format, ret;
108
109 /* Source parameters given in 16.16 fixed point, ignore fractional. */
110 src_x >>= 16;
111 src_y >>= 16;
112 src_w >>= 16;
113 src_h >>= 16;
114
115 format = ALIGN(src_w * 4, 0x100);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400116
117 if (format > 0xffff)
Ilia Mirkin050828e2013-11-15 11:26:42 -0500118 return -ERANGE;
119
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000120 if (dev->info.chipset >= 0x30) {
Ilia Mirkin050828e2013-11-15 11:26:42 -0500121 if (crtc_w < (src_w >> 1) || crtc_h < (src_h >> 1))
122 return -ERANGE;
123 } else {
124 if (crtc_w < (src_w >> 3) || crtc_h < (src_h >> 3))
125 return -ERANGE;
126 }
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400127
128 ret = nouveau_bo_pin(nv_fb->nvbo, TTM_PL_FLAG_VRAM);
129 if (ret)
130 return ret;
131
132 nv_plane->cur = nv_fb->nvbo;
133
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000134 nvif_mask(dev, NV_PCRTC_ENGINE_CTRL + soff, NV_CRTC_FSEL_OVERLAY, NV_CRTC_FSEL_OVERLAY);
135 nvif_mask(dev, NV_PCRTC_ENGINE_CTRL + soff2, NV_CRTC_FSEL_OVERLAY, 0);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400136
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000137 nvif_wr32(dev, NV_PVIDEO_BASE(flip), 0);
138 nvif_wr32(dev, NV_PVIDEO_OFFSET_BUFF(flip), nv_fb->nvbo->bo.offset);
139 nvif_wr32(dev, NV_PVIDEO_SIZE_IN(flip), src_h << 16 | src_w);
140 nvif_wr32(dev, NV_PVIDEO_POINT_IN(flip), src_y << 16 | src_x);
141 nvif_wr32(dev, NV_PVIDEO_DS_DX(flip), (src_w << 20) / crtc_w);
142 nvif_wr32(dev, NV_PVIDEO_DT_DY(flip), (src_h << 20) / crtc_h);
143 nvif_wr32(dev, NV_PVIDEO_POINT_OUT(flip), crtc_y << 16 | crtc_x);
144 nvif_wr32(dev, NV_PVIDEO_SIZE_OUT(flip), crtc_h << 16 | crtc_w);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400145
Ilia Mirkin7ffb0782013-11-15 11:26:44 -0500146 if (fb->pixel_format != DRM_FORMAT_UYVY)
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400147 format |= NV_PVIDEO_FORMAT_COLOR_LE_CR8YB8CB8YA8;
Ilia Mirkin7ffb0782013-11-15 11:26:44 -0500148 if (fb->pixel_format == DRM_FORMAT_NV12)
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400149 format |= NV_PVIDEO_FORMAT_PLANAR;
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400150 if (nv_plane->iturbt_709)
151 format |= NV_PVIDEO_FORMAT_MATRIX_ITURBT709;
152 if (nv_plane->colorkey & (1 << 24))
153 format |= NV_PVIDEO_FORMAT_DISPLAY_COLOR_KEY;
154
155 if (fb->pixel_format == DRM_FORMAT_NV12) {
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000156 nvif_wr32(dev, NV_PVIDEO_UVPLANE_BASE(flip), 0);
157 nvif_wr32(dev, NV_PVIDEO_UVPLANE_OFFSET_BUFF(flip),
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400158 nv_fb->nvbo->bo.offset + fb->offsets[1]);
159 }
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000160 nvif_wr32(dev, NV_PVIDEO_FORMAT(flip), format);
161 nvif_wr32(dev, NV_PVIDEO_STOP, 0);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400162 /* TODO: wait for vblank? */
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000163 nvif_wr32(dev, NV_PVIDEO_BUFFER, flip ? 0x10 : 0x1);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400164 nv_plane->flip = !flip;
165
166 if (cur)
167 nouveau_bo_unpin(cur);
168
169 return 0;
170}
171
172static int
173nv10_disable_plane(struct drm_plane *plane)
174{
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000175 struct nvif_device *dev = &nouveau_drm(plane->dev)->device;
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400176 struct nouveau_plane *nv_plane = (struct nouveau_plane *)plane;
177
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000178 nvif_wr32(dev, NV_PVIDEO_STOP, 1);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400179 if (nv_plane->cur) {
180 nouveau_bo_unpin(nv_plane->cur);
181 nv_plane->cur = NULL;
182 }
183
184 return 0;
185}
186
187static void
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500188nv_destroy_plane(struct drm_plane *plane)
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400189{
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500190 plane->funcs->disable_plane(plane);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400191 drm_plane_cleanup(plane);
192 kfree(plane);
193}
194
195static void
196nv10_set_params(struct nouveau_plane *plane)
197{
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000198 struct nvif_device *dev = &nouveau_drm(plane->base.dev)->device;
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400199 u32 luma = (plane->brightness - 512) << 16 | plane->contrast;
200 u32 chroma = ((sin_mul(plane->hue, plane->saturation) & 0xffff) << 16) |
201 (cos_mul(plane->hue, plane->saturation) & 0xffff);
202 u32 format = 0;
203
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000204 nvif_wr32(dev, NV_PVIDEO_LUMINANCE(0), luma);
205 nvif_wr32(dev, NV_PVIDEO_LUMINANCE(1), luma);
206 nvif_wr32(dev, NV_PVIDEO_CHROMINANCE(0), chroma);
207 nvif_wr32(dev, NV_PVIDEO_CHROMINANCE(1), chroma);
208 nvif_wr32(dev, NV_PVIDEO_COLOR_KEY, plane->colorkey & 0xffffff);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400209
210 if (plane->cur) {
211 if (plane->iturbt_709)
212 format |= NV_PVIDEO_FORMAT_MATRIX_ITURBT709;
213 if (plane->colorkey & (1 << 24))
214 format |= NV_PVIDEO_FORMAT_DISPLAY_COLOR_KEY;
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000215 nvif_mask(dev, NV_PVIDEO_FORMAT(plane->flip),
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400216 NV_PVIDEO_FORMAT_MATRIX_ITURBT709 |
217 NV_PVIDEO_FORMAT_DISPLAY_COLOR_KEY,
218 format);
219 }
220}
221
222static int
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500223nv_set_property(struct drm_plane *plane,
224 struct drm_property *property,
225 uint64_t value)
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400226{
227 struct nouveau_plane *nv_plane = (struct nouveau_plane *)plane;
228
229 if (property == nv_plane->props.colorkey)
230 nv_plane->colorkey = value;
231 else if (property == nv_plane->props.contrast)
232 nv_plane->contrast = value;
233 else if (property == nv_plane->props.brightness)
234 nv_plane->brightness = value;
235 else if (property == nv_plane->props.hue)
236 nv_plane->hue = value;
237 else if (property == nv_plane->props.saturation)
238 nv_plane->saturation = value;
239 else if (property == nv_plane->props.iturbt_709)
240 nv_plane->iturbt_709 = value;
241 else
242 return -EINVAL;
243
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500244 if (nv_plane->set_params)
245 nv_plane->set_params(nv_plane);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400246 return 0;
247}
248
249static const struct drm_plane_funcs nv10_plane_funcs = {
250 .update_plane = nv10_update_plane,
251 .disable_plane = nv10_disable_plane,
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500252 .set_property = nv_set_property,
253 .destroy = nv_destroy_plane,
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400254};
255
256static void
257nv10_overlay_init(struct drm_device *device)
258{
Ben Skeggsfa2bade2014-08-10 04:10:22 +1000259 struct nouveau_drm *drm = nouveau_drm(device);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400260 struct nouveau_plane *plane = kzalloc(sizeof(struct nouveau_plane), GFP_KERNEL);
Ilia Mirkinefffa982013-11-15 11:26:43 -0500261 int num_formats = ARRAY_SIZE(formats);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400262 int ret;
263
264 if (!plane)
265 return;
266
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000267 switch (drm->device.info.chipset) {
Ilia Mirkinefffa982013-11-15 11:26:43 -0500268 case 0x10:
269 case 0x11:
270 case 0x15:
271 case 0x1a:
272 case 0x20:
Ilia Mirkin7ffb0782013-11-15 11:26:44 -0500273 num_formats = 2;
Ilia Mirkinefffa982013-11-15 11:26:43 -0500274 break;
275 }
276
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400277 ret = drm_plane_init(device, &plane->base, 3 /* both crtc's */,
278 &nv10_plane_funcs,
Ilia Mirkinefffa982013-11-15 11:26:43 -0500279 formats, num_formats, false);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400280 if (ret)
281 goto err;
282
283 /* Set up the plane properties */
284 plane->props.colorkey = drm_property_create_range(
285 device, 0, "colorkey", 0, 0x01ffffff);
286 plane->props.contrast = drm_property_create_range(
287 device, 0, "contrast", 0, 8192 - 1);
288 plane->props.brightness = drm_property_create_range(
289 device, 0, "brightness", 0, 1024);
290 plane->props.hue = drm_property_create_range(
291 device, 0, "hue", 0, 359);
292 plane->props.saturation = drm_property_create_range(
293 device, 0, "saturation", 0, 8192 - 1);
294 plane->props.iturbt_709 = drm_property_create_range(
295 device, 0, "iturbt_709", 0, 1);
296 if (!plane->props.colorkey ||
297 !plane->props.contrast ||
298 !plane->props.brightness ||
299 !plane->props.hue ||
300 !plane->props.saturation ||
301 !plane->props.iturbt_709)
302 goto cleanup;
303
304 plane->colorkey = 0;
305 drm_object_attach_property(&plane->base.base,
306 plane->props.colorkey, plane->colorkey);
307
308 plane->contrast = 0x1000;
309 drm_object_attach_property(&plane->base.base,
310 plane->props.contrast, plane->contrast);
311
312 plane->brightness = 512;
313 drm_object_attach_property(&plane->base.base,
314 plane->props.brightness, plane->brightness);
315
316 plane->hue = 0;
317 drm_object_attach_property(&plane->base.base,
318 plane->props.hue, plane->hue);
319
320 plane->saturation = 0x1000;
321 drm_object_attach_property(&plane->base.base,
322 plane->props.saturation, plane->saturation);
323
324 plane->iturbt_709 = 0;
325 drm_object_attach_property(&plane->base.base,
326 plane->props.iturbt_709, plane->iturbt_709);
327
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500328 plane->set_params = nv10_set_params;
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400329 nv10_set_params(plane);
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500330 nv10_disable_plane(&plane->base);
331 return;
332cleanup:
333 drm_plane_cleanup(&plane->base);
334err:
335 kfree(plane);
Ben Skeggsfa2bade2014-08-10 04:10:22 +1000336 NV_ERROR(drm, "Failed to create plane\n");
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500337}
338
339static int
340nv04_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
341 struct drm_framebuffer *fb, int crtc_x, int crtc_y,
342 unsigned int crtc_w, unsigned int crtc_h,
343 uint32_t src_x, uint32_t src_y,
344 uint32_t src_w, uint32_t src_h)
345{
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000346 struct nvif_device *dev = &nouveau_drm(plane->dev)->device;
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500347 struct nouveau_plane *nv_plane = (struct nouveau_plane *)plane;
348 struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
349 struct nouveau_bo *cur = nv_plane->cur;
350 uint32_t overlay = 1;
351 int brightness = (nv_plane->brightness - 512) * 62 / 512;
352 int pitch, ret, i;
353
354 /* Source parameters given in 16.16 fixed point, ignore fractional. */
355 src_x >>= 16;
356 src_y >>= 16;
357 src_w >>= 16;
358 src_h >>= 16;
359
360 pitch = ALIGN(src_w * 4, 0x100);
361
362 if (pitch > 0xffff)
363 return -ERANGE;
364
365 /* TODO: Compute an offset? Not sure how to do this for YUYV. */
366 if (src_x != 0 || src_y != 0)
367 return -ERANGE;
368
369 if (crtc_w < src_w || crtc_h < src_h)
370 return -ERANGE;
371
372 ret = nouveau_bo_pin(nv_fb->nvbo, TTM_PL_FLAG_VRAM);
373 if (ret)
374 return ret;
375
376 nv_plane->cur = nv_fb->nvbo;
377
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000378 nvif_wr32(dev, NV_PVIDEO_OE_STATE, 0);
379 nvif_wr32(dev, NV_PVIDEO_SU_STATE, 0);
380 nvif_wr32(dev, NV_PVIDEO_RM_STATE, 0);
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500381
382 for (i = 0; i < 2; i++) {
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000383 nvif_wr32(dev, NV_PVIDEO_BUFF0_START_ADDRESS + 4 * i,
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500384 nv_fb->nvbo->bo.offset);
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000385 nvif_wr32(dev, NV_PVIDEO_BUFF0_PITCH_LENGTH + 4 * i, pitch);
386 nvif_wr32(dev, NV_PVIDEO_BUFF0_OFFSET + 4 * i, 0);
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500387 }
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000388 nvif_wr32(dev, NV_PVIDEO_WINDOW_START, crtc_y << 16 | crtc_x);
389 nvif_wr32(dev, NV_PVIDEO_WINDOW_SIZE, crtc_h << 16 | crtc_w);
390 nvif_wr32(dev, NV_PVIDEO_STEP_SIZE,
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500391 (uint32_t)(((src_h - 1) << 11) / (crtc_h - 1)) << 16 | (uint32_t)(((src_w - 1) << 11) / (crtc_w - 1)));
392
393 /* It should be possible to convert hue/contrast to this */
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000394 nvif_wr32(dev, NV_PVIDEO_RED_CSC_OFFSET, 0x69 - brightness);
395 nvif_wr32(dev, NV_PVIDEO_GREEN_CSC_OFFSET, 0x3e + brightness);
396 nvif_wr32(dev, NV_PVIDEO_BLUE_CSC_OFFSET, 0x89 - brightness);
397 nvif_wr32(dev, NV_PVIDEO_CSC_ADJUST, 0);
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500398
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000399 nvif_wr32(dev, NV_PVIDEO_CONTROL_Y, 0x001); /* (BLUR_ON, LINE_HALF) */
400 nvif_wr32(dev, NV_PVIDEO_CONTROL_X, 0x111); /* (WEIGHT_HEAVY, SHARPENING_ON, SMOOTHING_ON) */
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500401
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000402 nvif_wr32(dev, NV_PVIDEO_FIFO_BURST_LENGTH, 0x03);
403 nvif_wr32(dev, NV_PVIDEO_FIFO_THRES_SIZE, 0x38);
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500404
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000405 nvif_wr32(dev, NV_PVIDEO_KEY, nv_plane->colorkey);
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500406
407 if (nv_plane->colorkey & (1 << 24))
408 overlay |= 0x10;
409 if (fb->pixel_format == DRM_FORMAT_YUYV)
410 overlay |= 0x100;
411
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000412 nvif_wr32(dev, NV_PVIDEO_OVERLAY, overlay);
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500413
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000414 nvif_wr32(dev, NV_PVIDEO_SU_STATE, nvif_rd32(dev, NV_PVIDEO_SU_STATE) ^ (1 << 16));
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500415
416 if (cur)
417 nouveau_bo_unpin(cur);
418
419 return 0;
420}
421
422static int
423nv04_disable_plane(struct drm_plane *plane)
424{
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000425 struct nvif_device *dev = &nouveau_drm(plane->dev)->device;
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500426 struct nouveau_plane *nv_plane = (struct nouveau_plane *)plane;
427
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000428 nvif_mask(dev, NV_PVIDEO_OVERLAY, 1, 0);
429 nvif_wr32(dev, NV_PVIDEO_OE_STATE, 0);
430 nvif_wr32(dev, NV_PVIDEO_SU_STATE, 0);
431 nvif_wr32(dev, NV_PVIDEO_RM_STATE, 0);
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500432 if (nv_plane->cur) {
433 nouveau_bo_unpin(nv_plane->cur);
434 nv_plane->cur = NULL;
435 }
436
437 return 0;
438}
439
440static const struct drm_plane_funcs nv04_plane_funcs = {
441 .update_plane = nv04_update_plane,
442 .disable_plane = nv04_disable_plane,
443 .set_property = nv_set_property,
444 .destroy = nv_destroy_plane,
445};
446
447static void
448nv04_overlay_init(struct drm_device *device)
449{
Ben Skeggsfa2bade2014-08-10 04:10:22 +1000450 struct nouveau_drm *drm = nouveau_drm(device);
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500451 struct nouveau_plane *plane = kzalloc(sizeof(struct nouveau_plane), GFP_KERNEL);
452 int ret;
453
454 if (!plane)
455 return;
456
457 ret = drm_plane_init(device, &plane->base, 1 /* single crtc */,
458 &nv04_plane_funcs,
459 formats, 2, false);
460 if (ret)
461 goto err;
462
463 /* Set up the plane properties */
464 plane->props.colorkey = drm_property_create_range(
465 device, 0, "colorkey", 0, 0x01ffffff);
466 plane->props.brightness = drm_property_create_range(
467 device, 0, "brightness", 0, 1024);
468 if (!plane->props.colorkey ||
469 !plane->props.brightness)
470 goto cleanup;
471
472 plane->colorkey = 0;
473 drm_object_attach_property(&plane->base.base,
474 plane->props.colorkey, plane->colorkey);
475
476 plane->brightness = 512;
477 drm_object_attach_property(&plane->base.base,
478 plane->props.brightness, plane->brightness);
479
480 nv04_disable_plane(&plane->base);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400481 return;
482cleanup:
483 drm_plane_cleanup(&plane->base);
484err:
485 kfree(plane);
Ben Skeggsfa2bade2014-08-10 04:10:22 +1000486 NV_ERROR(drm, "Failed to create plane\n");
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400487}
488
489void
490nouveau_overlay_init(struct drm_device *device)
491{
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000492 struct nvif_device *dev = &nouveau_drm(device)->device;
493 if (dev->info.chipset < 0x10)
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500494 nv04_overlay_init(device);
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000495 else if (dev->info.chipset <= 0x40)
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400496 nv10_overlay_init(device);
497}