blob: a164839ee2cc359bf35aa1bdb70208c98039c70a [file] [log] [blame]
Ville Syrjälä08c27e32013-10-18 17:44:42 +03001/*
2 * Copyright © 2013 Intel Corporation
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
Thomas Wood804e11f2015-08-17 17:57:43 +010025#include "igt.h"
Ville Syrjälä08c27e32013-10-18 17:44:42 +030026#include <errno.h>
Ville Syrjäläfee27cf2014-01-13 17:05:19 +020027#include <limits.h>
Ville Syrjälä08c27e32013-10-18 17:44:42 +030028#include <stdbool.h>
29#include <stdio.h>
30#include <string.h>
31
Ville Syrjälä08c27e32013-10-18 17:44:42 +030032
Thomas Wood3d0dca42014-10-13 11:40:12 +010033IGT_TEST_DESCRIPTION(
34 "Use the display CRC support to validate cursor plane functionality. "
35 "The test will position the cursor plane either fully onscreen, "
36 "partially onscreen, or fully offscreen, using either a fully opaque "
37 "or fully transparent surface. In each case it then reads the PF CRC "
38 "and compares it with the CRC value obtained when the cursor plane "
39 "was disabled.");
40
Sagar Kambleba3a1a82014-03-18 15:59:43 +053041#ifndef DRM_CAP_CURSOR_WIDTH
42#define DRM_CAP_CURSOR_WIDTH 0x8
43#endif
44#ifndef DRM_CAP_CURSOR_HEIGHT
45#define DRM_CAP_CURSOR_HEIGHT 0x9
46#endif
47
Ville Syrjälä08c27e32013-10-18 17:44:42 +030048typedef struct {
Ville Syrjälä08c27e32013-10-18 17:44:42 +030049 int drm_fd;
Damien Lespiaud4358292014-02-05 17:14:12 +000050 igt_display_t display;
Daniel Vetter9aea7ae2014-03-26 09:18:11 +010051 struct igt_fb primary_fb;
Antti Koskipaaa593d612014-04-10 15:08:05 +030052 struct igt_fb fb;
Damien Lespiaud4358292014-02-05 17:14:12 +000053 igt_output_t *output;
54 enum pipe pipe;
Ville Syrjälä08c27e32013-10-18 17:44:42 +030055 igt_crc_t ref_crc;
Ville Syrjälä08c27e32013-10-18 17:44:42 +030056 int left, right, top, bottom;
Antti Koskipaa795eddc2014-04-10 15:08:09 +030057 int screenw, screenh;
Matt Ropercd99dde2015-10-15 16:54:32 -070058 int refresh;
Antti Koskipaafe8041b2014-04-10 15:08:07 +030059 int curw, curh; /* cursor size */
Ville Syrjälä25c55d32014-09-12 18:03:25 +030060 int cursor_max_w, cursor_max_h;
Ville Syrjäläf6e86972014-04-24 19:07:18 +030061 igt_pipe_crc_t *pipe_crc;
Ville Syrjälä25c55d32014-09-12 18:03:25 +030062 uint32_t devid;
Daniel Vettera5c6b8d2015-03-13 18:02:45 +010063 unsigned flags;
Matt Roper07087ad2014-06-30 16:44:29 -070064} data_t;
Ville Syrjälä08c27e32013-10-18 17:44:42 +030065
Daniel Vettera5c6b8d2015-03-13 18:02:45 +010066#define TEST_DPMS (1<<0)
67#define TEST_SUSPEND (1<<1)
68
Ville Syrjälä25c55d32014-09-12 18:03:25 +030069static void draw_cursor(cairo_t *cr, int x, int y, int cw, int ch)
Antti Koskipaaa593d612014-04-10 15:08:05 +030070{
Ville Syrjälä25c55d32014-09-12 18:03:25 +030071 int wl, wr, ht, hb;
72
73 /* deal with odd cursor width/height */
74 wl = cw / 2;
75 wr = (cw + 1) / 2;
76 ht = ch / 2;
77 hb = (ch + 1) / 2;
78
Antti Koskipaa795eddc2014-04-10 15:08:09 +030079 /* Cairo doesn't like to be fed numbers that are too wild */
80 if ((x < SHRT_MIN) || (x > SHRT_MAX) || (y < SHRT_MIN) || (y > SHRT_MAX))
81 return;
Antti Koskipaaa593d612014-04-10 15:08:05 +030082 cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
83 /* 4 color rectangles in the corners, RGBY */
Ville Syrjälä25c55d32014-09-12 18:03:25 +030084 igt_paint_color_alpha(cr, x, y, wl, ht, 1.0, 0.0, 0.0, 1.0);
85 igt_paint_color_alpha(cr, x + wl, y, wr, ht, 0.0, 1.0, 0.0, 1.0);
86 igt_paint_color_alpha(cr, x, y + ht, wl, hb, 0.0, 0.0, 1.0, 1.0);
87 igt_paint_color_alpha(cr, x + wl, y + ht, wr, hb, 0.5, 0.5, 0.5, 1.0);
Antti Koskipaaa593d612014-04-10 15:08:05 +030088}
Ville Syrjälä08c27e32013-10-18 17:44:42 +030089
Matt Roper07087ad2014-06-30 16:44:29 -070090static void cursor_enable(data_t *data)
Damien Lespiaud4358292014-02-05 17:14:12 +000091{
Matt Roper07087ad2014-06-30 16:44:29 -070092 igt_output_t *output = data->output;
Damien Lespiaud4358292014-02-05 17:14:12 +000093 igt_plane_t *cursor;
94
Robert Fossda67e732017-01-10 18:44:19 -050095 cursor = igt_output_get_plane_type(output, DRM_PLANE_TYPE_CURSOR);
Antti Koskipaaa593d612014-04-10 15:08:05 +030096 igt_plane_set_fb(cursor, &data->fb);
Ville Syrjälä25c55d32014-09-12 18:03:25 +030097 igt_plane_set_size(cursor, data->curw, data->curh);
Damien Lespiaud4358292014-02-05 17:14:12 +000098}
99
Matt Roper07087ad2014-06-30 16:44:29 -0700100static void cursor_disable(data_t *data)
Damien Lespiaud4358292014-02-05 17:14:12 +0000101{
Matt Roper07087ad2014-06-30 16:44:29 -0700102 igt_output_t *output = data->output;
Damien Lespiaud4358292014-02-05 17:14:12 +0000103 igt_plane_t *cursor;
104
Robert Fossda67e732017-01-10 18:44:19 -0500105 cursor = igt_output_get_plane_type(output, DRM_PLANE_TYPE_CURSOR);
Damien Lespiaud4358292014-02-05 17:14:12 +0000106 igt_plane_set_fb(cursor, NULL);
Damien Lespiaud4358292014-02-05 17:14:12 +0000107}
108
Maarten Lankhorst6fcc8e82017-06-14 10:17:31 +0200109static bool chv_cursor_broken(data_t *data, int x)
110{
111 /*
112 * CHV gets a FIFO underrun on pipe C when cursor x coordinate
113 * is negative and the cursor visible.
114 *
115 * i915 is fixed to return -EINVAL on cursor updates with those
116 * negative coordinates, so require cursor update to fail with
117 * -EINVAL in that case.
118 *
119 * See also kms_chv_cursor_fail.c
120 */
121 if (x >= 0)
122 return false;
123
124 return IS_CHERRYVIEW(data->devid) && data->pipe == PIPE_C;
125}
126
127static bool cursor_visible(data_t *data, int x, int y)
128{
129 if (x + data->curw <= 0 || y + data->curh <= 0)
130 return false;
131
132 if (x >= data->screenw || y >= data->screenh)
133 return false;
134
135 return true;
136}
Antti Koskipaa7ec631c2014-04-10 15:08:06 +0300137
Matt Roper07087ad2014-06-30 16:44:29 -0700138static void do_single_test(data_t *data, int x, int y)
Antti Koskipaa7ec631c2014-04-10 15:08:06 +0300139{
Antti Koskipaa7ec631c2014-04-10 15:08:06 +0300140 igt_display_t *display = &data->display;
Matt Roper07087ad2014-06-30 16:44:29 -0700141 igt_pipe_crc_t *pipe_crc = data->pipe_crc;
Antti Koskipaa795eddc2014-04-10 15:08:09 +0300142 igt_crc_t crc, ref_crc;
Antti Koskipaa7ec631c2014-04-10 15:08:06 +0300143 igt_plane_t *cursor;
Maarten Lankhorstbe2f6fc2018-02-01 12:48:45 +0100144 cairo_t *cr;
Maarten Lankhorst6fcc8e82017-06-14 10:17:31 +0200145 int ret = 0;
Antti Koskipaa7ec631c2014-04-10 15:08:06 +0300146
Thomas Wood6a8d33c2014-09-30 17:05:39 +0100147 igt_print_activity();
Antti Koskipaa7ec631c2014-04-10 15:08:06 +0300148
Antti Koskipaa795eddc2014-04-10 15:08:09 +0300149 /* Hardware test */
Maarten Lankhorstbe2f6fc2018-02-01 12:48:45 +0100150 cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
Matt Roper07087ad2014-06-30 16:44:29 -0700151 igt_paint_test_pattern(cr, data->screenw, data->screenh);
Maarten Lankhorstbe2f6fc2018-02-01 12:48:45 +0100152 igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
153
Matt Roper07087ad2014-06-30 16:44:29 -0700154 cursor_enable(data);
Robert Fossda67e732017-01-10 18:44:19 -0500155 cursor = igt_output_get_plane_type(data->output, DRM_PLANE_TYPE_CURSOR);
Antti Koskipaa7ec631c2014-04-10 15:08:06 +0300156 igt_plane_set_position(cursor, x, y);
Maarten Lankhorst6fcc8e82017-06-14 10:17:31 +0200157
158 if (chv_cursor_broken(data, x) && cursor_visible(data, x, y)) {
159 ret = igt_display_try_commit2(display, COMMIT_LEGACY);
160 igt_assert_eq(ret, -EINVAL);
161 igt_plane_set_position(cursor, 0, y);
162
163 return;
164 }
165
Antti Koskipaa7ec631c2014-04-10 15:08:06 +0300166 igt_display_commit(display);
Maarten Lankhorst6fcc8e82017-06-14 10:17:31 +0200167
Matt Roper07087ad2014-06-30 16:44:29 -0700168 igt_wait_for_vblank(data->drm_fd, data->pipe);
Antti Koskipaa7ec631c2014-04-10 15:08:06 +0300169 igt_pipe_crc_collect_crc(pipe_crc, &crc);
Daniel Vettera5c6b8d2015-03-13 18:02:45 +0100170
171 if (data->flags & (TEST_DPMS | TEST_SUSPEND)) {
172 igt_crc_t crc_after;
173
174 if (data->flags & TEST_DPMS) {
175 igt_debug("dpms off/on cycle\n");
176 kmstest_set_connector_dpms(data->drm_fd,
177 data->output->config.connector,
178 DRM_MODE_DPMS_OFF);
179 kmstest_set_connector_dpms(data->drm_fd,
180 data->output->config.connector,
181 DRM_MODE_DPMS_ON);
182 }
183
184 if (data->flags & TEST_SUSPEND)
Imre Deak022e6f82016-09-30 17:28:53 +0300185 igt_system_suspend_autoresume(SUSPEND_STATE_MEM,
186 SUSPEND_TEST_NONE);
Daniel Vettera5c6b8d2015-03-13 18:02:45 +0100187
188 igt_pipe_crc_collect_crc(pipe_crc, &crc_after);
189 igt_assert_crc_equal(&crc, &crc_after);
190 }
191
Matt Roper07087ad2014-06-30 16:44:29 -0700192 cursor_disable(data);
Ville Syrjälä25c55d32014-09-12 18:03:25 +0300193 igt_display_commit(display);
Antti Koskipaa7ec631c2014-04-10 15:08:06 +0300194
Antti Koskipaa795eddc2014-04-10 15:08:09 +0300195 /* Now render the same in software and collect crc */
Maarten Lankhorstbe2f6fc2018-02-01 12:48:45 +0100196 cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
Ville Syrjälä25c55d32014-09-12 18:03:25 +0300197 draw_cursor(cr, x, y, data->curw, data->curh);
Maarten Lankhorstbe2f6fc2018-02-01 12:48:45 +0100198 igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
Antti Koskipaa795eddc2014-04-10 15:08:09 +0300199 igt_display_commit(display);
Daniel Vetter4fec18e2015-02-27 20:24:15 +0100200
Matt Roper07087ad2014-06-30 16:44:29 -0700201 igt_wait_for_vblank(data->drm_fd, data->pipe);
Antti Koskipaa795eddc2014-04-10 15:08:09 +0300202 igt_pipe_crc_collect_crc(pipe_crc, &ref_crc);
Daniel Vettere588f6d2015-02-27 20:37:29 +0100203 igt_assert_crc_equal(&crc, &ref_crc);
Daniel Vetter4fec18e2015-02-27 20:24:15 +0100204
Damien Lespiau09ea86e2015-05-11 16:36:51 +0100205 /* Clear screen afterwards */
Maarten Lankhorstbe2f6fc2018-02-01 12:48:45 +0100206 cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
Damien Lespiau09ea86e2015-05-11 16:36:51 +0100207 igt_paint_color(cr, 0, 0, data->screenw, data->screenh, 0.0, 0.0, 0.0);
Maarten Lankhorstbe2f6fc2018-02-01 12:48:45 +0100208 igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
Antti Koskipaa7ec631c2014-04-10 15:08:06 +0300209}
210
Matt Roper9ca2cc12015-02-02 11:07:55 -0800211static void do_fail_test(data_t *data, int x, int y, int expect)
212{
213 igt_display_t *display = &data->display;
214 igt_plane_t *cursor;
Maarten Lankhorstbe2f6fc2018-02-01 12:48:45 +0100215 cairo_t *cr;
Matt Roper9ca2cc12015-02-02 11:07:55 -0800216 int ret;
217
218 igt_print_activity();
219
220 /* Hardware test */
Maarten Lankhorstbe2f6fc2018-02-01 12:48:45 +0100221 cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
Matt Roper9ca2cc12015-02-02 11:07:55 -0800222 igt_paint_test_pattern(cr, data->screenw, data->screenh);
Maarten Lankhorstbe2f6fc2018-02-01 12:48:45 +0100223 igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
224
Matt Roper9ca2cc12015-02-02 11:07:55 -0800225 cursor_enable(data);
Robert Fossda67e732017-01-10 18:44:19 -0500226 cursor = igt_output_get_plane_type(data->output, DRM_PLANE_TYPE_CURSOR);
Matt Roper9ca2cc12015-02-02 11:07:55 -0800227 igt_plane_set_position(cursor, x, y);
228 ret = igt_display_try_commit2(display, COMMIT_LEGACY);
229
230 igt_plane_set_position(cursor, 0, 0);
231 cursor_disable(data);
232 igt_display_commit(display);
233
Matt Roper07be8fe2015-03-05 15:01:00 -0800234 igt_assert_eq(ret, expect);
Matt Roper9ca2cc12015-02-02 11:07:55 -0800235}
236
Matt Roper07087ad2014-06-30 16:44:29 -0700237static void do_test(data_t *data,
Antti Koskipaa7ec631c2014-04-10 15:08:06 +0300238 int left, int right, int top, int bottom)
239{
Matt Roper07087ad2014-06-30 16:44:29 -0700240 do_single_test(data, left, top);
241 do_single_test(data, right, top);
242 do_single_test(data, right, bottom);
243 do_single_test(data, left, bottom);
Antti Koskipaa7ec631c2014-04-10 15:08:06 +0300244}
245
Matt Roper07087ad2014-06-30 16:44:29 -0700246static void test_crc_onscreen(data_t *data)
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300247{
Matt Roper07087ad2014-06-30 16:44:29 -0700248 int left = data->left;
249 int right = data->right;
250 int top = data->top;
251 int bottom = data->bottom;
252 int cursor_w = data->curw;
253 int cursor_h = data->curh;
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300254
Antti Koskipaaead01732014-04-10 15:08:08 +0300255 /* fully inside */
Matt Roper07087ad2014-06-30 16:44:29 -0700256 do_test(data, left, right, top, bottom);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300257
Antti Koskipaaead01732014-04-10 15:08:08 +0300258 /* 2 pixels inside */
Matt Roper07087ad2014-06-30 16:44:29 -0700259 do_test(data, left - (cursor_w-2), right + (cursor_w-2), top , bottom );
260 do_test(data, left , right , top - (cursor_h-2), bottom + (cursor_h-2));
261 do_test(data, left - (cursor_w-2), right + (cursor_w-2), top - (cursor_h-2), bottom + (cursor_h-2));
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300262
Antti Koskipaaead01732014-04-10 15:08:08 +0300263 /* 1 pixel inside */
Matt Roper07087ad2014-06-30 16:44:29 -0700264 do_test(data, left - (cursor_w-1), right + (cursor_w-1), top , bottom );
265 do_test(data, left , right , top - (cursor_h-1), bottom + (cursor_h-1));
266 do_test(data, left - (cursor_w-1), right + (cursor_w-1), top - (cursor_h-1), bottom + (cursor_h-1));
Antti Koskipaaead01732014-04-10 15:08:08 +0300267}
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300268
Matt Roper07087ad2014-06-30 16:44:29 -0700269static void test_crc_offscreen(data_t *data)
Antti Koskipaaead01732014-04-10 15:08:08 +0300270{
Matt Roper07087ad2014-06-30 16:44:29 -0700271 int left = data->left;
272 int right = data->right;
273 int top = data->top;
274 int bottom = data->bottom;
275 int cursor_w = data->curw;
276 int cursor_h = data->curh;
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300277
Antti Koskipaaead01732014-04-10 15:08:08 +0300278 /* fully outside */
Matt Roper07087ad2014-06-30 16:44:29 -0700279 do_test(data, left - (cursor_w), right + (cursor_w), top , bottom );
280 do_test(data, left , right , top - (cursor_h), bottom + (cursor_h));
281 do_test(data, left - (cursor_w), right + (cursor_w), top - (cursor_h), bottom + (cursor_h));
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300282
Antti Koskipaaead01732014-04-10 15:08:08 +0300283 /* fully outside by 1 extra pixels */
Matt Roper07087ad2014-06-30 16:44:29 -0700284 do_test(data, left - (cursor_w+1), right + (cursor_w+1), top , bottom );
285 do_test(data, left , right , top - (cursor_h+1), bottom + (cursor_h+1));
286 do_test(data, left - (cursor_w+1), right + (cursor_w+1), top - (cursor_h+1), bottom + (cursor_h+1));
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300287
Antti Koskipaaead01732014-04-10 15:08:08 +0300288 /* fully outside by 2 extra pixels */
Matt Roper07087ad2014-06-30 16:44:29 -0700289 do_test(data, left - (cursor_w+2), right + (cursor_w+2), top , bottom );
290 do_test(data, left , right , top - (cursor_h+2), bottom + (cursor_h+2));
291 do_test(data, left - (cursor_w+2), right + (cursor_w+2), top - (cursor_h+2), bottom + (cursor_h+2));
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300292
Antti Koskipaaead01732014-04-10 15:08:08 +0300293 /* fully outside by a lot of extra pixels */
Matt Roper07087ad2014-06-30 16:44:29 -0700294 do_test(data, left - (cursor_w+512), right + (cursor_w+512), top , bottom );
295 do_test(data, left , right , top - (cursor_h+512), bottom + (cursor_h+512));
296 do_test(data, left - (cursor_w+512), right + (cursor_w+512), top - (cursor_h+512), bottom + (cursor_h+512));
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300297
Antti Koskipaaead01732014-04-10 15:08:08 +0300298 /* go nuts */
Matt Roper9ca2cc12015-02-02 11:07:55 -0800299 do_test(data, INT_MIN, INT_MAX - cursor_w, INT_MIN, INT_MAX - cursor_h);
300 do_test(data, SHRT_MIN, SHRT_MAX, SHRT_MIN, SHRT_MAX);
301
302 /* Make sure we get -ERANGE on integer overflow */
303 do_fail_test(data, INT_MAX - cursor_w + 1, INT_MAX - cursor_h + 1, -ERANGE);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300304}
305
Matt Roper07087ad2014-06-30 16:44:29 -0700306static void test_crc_sliding(data_t *data)
Antti Koskipaa470e5ce2014-04-10 15:08:10 +0300307{
308 int i;
309
310 /* Make sure cursor moves smoothly and pixel-by-pixel, and that there are
311 * no alignment issues. Horizontal, vertical and diagonal test.
312 */
313 for (i = 0; i < 16; i++) {
Matt Roper07087ad2014-06-30 16:44:29 -0700314 do_single_test(data, i, 0);
315 do_single_test(data, 0, i);
316 do_single_test(data, i, i);
Antti Koskipaa470e5ce2014-04-10 15:08:10 +0300317 }
318}
319
Matt Roper07087ad2014-06-30 16:44:29 -0700320static void test_crc_random(data_t *data)
Antti Koskipaafafcff92014-04-10 15:08:11 +0300321{
Daniel Vettera5c6b8d2015-03-13 18:02:45 +0100322 int i, max;
323
324 max = data->flags & (TEST_DPMS | TEST_SUSPEND) ? 2 : 50;
Antti Koskipaafafcff92014-04-10 15:08:11 +0300325
326 /* Random cursor placement */
Daniel Vettera5c6b8d2015-03-13 18:02:45 +0100327 for (i = 0; i < max; i++) {
Matt Roper07087ad2014-06-30 16:44:29 -0700328 int x = rand() % (data->screenw + data->curw * 2) - data->curw;
329 int y = rand() % (data->screenh + data->curh * 2) - data->curh;
330 do_single_test(data, x, y);
Antti Koskipaafafcff92014-04-10 15:08:11 +0300331 }
332}
333
Maarten Lankhorsta546b672017-01-05 14:13:34 +0100334static void prepare_crtc(data_t *data, igt_output_t *output,
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530335 int cursor_w, int cursor_h)
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300336{
Damien Lespiaud4358292014-02-05 17:14:12 +0000337 drmModeModeInfo *mode;
Damien Lespiaud4358292014-02-05 17:14:12 +0000338 igt_display_t *display = &data->display;
Damien Lespiaud4358292014-02-05 17:14:12 +0000339 igt_plane_t *primary;
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300340
Damien Lespiaud4358292014-02-05 17:14:12 +0000341 /* select the pipe we want to use */
Matt Roper07087ad2014-06-30 16:44:29 -0700342 igt_output_set_pipe(output, data->pipe);
Ville Syrjälä25c55d32014-09-12 18:03:25 +0300343 cursor_disable(data);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300344
Damien Lespiaud4358292014-02-05 17:14:12 +0000345 /* create and set the primary plane fb */
346 mode = igt_output_get_mode(output);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100347 igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
Matt Roper07087ad2014-06-30 16:44:29 -0700348 DRM_FORMAT_XRGB8888,
Tvrtko Ursuline36091d2015-03-03 14:11:01 +0000349 LOCAL_DRM_FORMAT_MOD_NONE,
Matt Roper07087ad2014-06-30 16:44:29 -0700350 0.0, 0.0, 0.0,
351 &data->primary_fb);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300352
Robert Fossda67e732017-01-10 18:44:19 -0500353 primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
Damien Lespiaud4358292014-02-05 17:14:12 +0000354 igt_plane_set_fb(primary, &data->primary_fb);
Ville Syrjälä3d371a72013-11-22 23:46:32 +0200355
Damien Lespiaud4358292014-02-05 17:14:12 +0000356 igt_display_commit(display);
357
358 /* create the pipe_crc object for this pipe */
Matt Roper07087ad2014-06-30 16:44:29 -0700359 if (data->pipe_crc)
360 igt_pipe_crc_free(data->pipe_crc);
Damien Lespiaud4358292014-02-05 17:14:12 +0000361
Chris Wilson83884e92017-03-21 17:16:03 +0000362 data->pipe_crc = igt_pipe_crc_new(data->drm_fd, data->pipe,
Matt Roper07087ad2014-06-30 16:44:29 -0700363 INTEL_PIPE_CRC_SOURCE_AUTO);
Daniel Vetter43def942013-10-31 16:06:40 +0100364
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300365 /* x/y position where the cursor is still fully visible */
Matt Roper07087ad2014-06-30 16:44:29 -0700366 data->left = 0;
367 data->right = mode->hdisplay - cursor_w;
368 data->top = 0;
369 data->bottom = mode->vdisplay - cursor_h;
370 data->screenw = mode->hdisplay;
371 data->screenh = mode->vdisplay;
372 data->curw = cursor_w;
373 data->curh = cursor_h;
Matt Ropercd99dde2015-10-15 16:54:32 -0700374 data->refresh = mode->vrefresh;
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300375
376 /* make sure cursor is disabled */
Matt Roper07087ad2014-06-30 16:44:29 -0700377 cursor_disable(data);
378 igt_wait_for_vblank(data->drm_fd, data->pipe);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300379
380 /* get reference crc w/o cursor */
Matt Roper07087ad2014-06-30 16:44:29 -0700381 igt_pipe_crc_collect_crc(data->pipe_crc, &data->ref_crc);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300382}
383
Matt Roper07087ad2014-06-30 16:44:29 -0700384static void cleanup_crtc(data_t *data, igt_output_t *output)
Damien Lespiaud4358292014-02-05 17:14:12 +0000385{
Ville Syrjäläa4615152014-04-25 15:27:57 +0300386 igt_display_t *display = &data->display;
Damien Lespiaud4358292014-02-05 17:14:12 +0000387 igt_plane_t *primary;
388
Matt Roper07087ad2014-06-30 16:44:29 -0700389 igt_pipe_crc_free(data->pipe_crc);
390 data->pipe_crc = NULL;
Damien Lespiaud4358292014-02-05 17:14:12 +0000391
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100392 igt_remove_fb(data->drm_fd, &data->primary_fb);
Damien Lespiaud4358292014-02-05 17:14:12 +0000393
Robert Fossda67e732017-01-10 18:44:19 -0500394 primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
Damien Lespiaud4358292014-02-05 17:14:12 +0000395 igt_plane_set_fb(primary, NULL);
396
397 igt_output_set_pipe(output, PIPE_ANY);
Ville Syrjäläa4615152014-04-25 15:27:57 +0300398 igt_display_commit(display);
Damien Lespiaud4358292014-02-05 17:14:12 +0000399}
400
Matt Roper07087ad2014-06-30 16:44:29 -0700401static void run_test(data_t *data, void (*testfunc)(data_t *), int cursor_w, int cursor_h)
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300402{
Damien Lespiaud4358292014-02-05 17:14:12 +0000403 igt_display_t *display = &data->display;
404 igt_output_t *output;
405 enum pipe p;
Daniel Vetter43def942013-10-31 16:06:40 +0100406 int valid_tests = 0;
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300407
Ville Syrjälä25c55d32014-09-12 18:03:25 +0300408 igt_require(cursor_w <= data->cursor_max_w &&
409 cursor_h <= data->cursor_max_h);
410
Maarten Lankhorsta546b672017-01-05 14:13:34 +0100411 for_each_pipe_with_valid_output(display, p, output) {
Matt Roper07087ad2014-06-30 16:44:29 -0700412 data->output = output;
Maarten Lankhorsta546b672017-01-05 14:13:34 +0100413 data->pipe = p;
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300414
Maarten Lankhorsta546b672017-01-05 14:13:34 +0100415 prepare_crtc(data, output, cursor_w, cursor_h);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300416
Maarten Lankhorsta546b672017-01-05 14:13:34 +0100417 valid_tests++;
Daniel Vetter43def942013-10-31 16:06:40 +0100418
Maarten Lankhorsta546b672017-01-05 14:13:34 +0100419 igt_info("Beginning %s on pipe %s, connector %s\n",
420 igt_subtest_name(),
421 kmstest_pipe_name(data->pipe),
422 igt_output_name(output));
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300423
Maarten Lankhorsta546b672017-01-05 14:13:34 +0100424 testfunc(data);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300425
Maarten Lankhorsta546b672017-01-05 14:13:34 +0100426 igt_info("\n%s on pipe %s, connector %s: PASSED\n\n",
427 igt_subtest_name(),
428 kmstest_pipe_name(data->pipe),
429 igt_output_name(output));
Daniel Vetter43def942013-10-31 16:06:40 +0100430
Maarten Lankhorsta546b672017-01-05 14:13:34 +0100431 /* cleanup what prepare_crtc() has done */
432 cleanup_crtc(data, output);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300433 }
Daniel Vetter43def942013-10-31 16:06:40 +0100434
435 igt_require_f(valid_tests, "no valid crtc/connector combinations found\n");
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300436}
437
Antti Koskipaaa593d612014-04-10 15:08:05 +0300438static void create_cursor_fb(data_t *data, int cur_w, int cur_h)
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300439{
440 cairo_t *cr;
Antti Koskipaaa593d612014-04-10 15:08:05 +0300441 uint32_t fb_id;
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300442
Ville Syrjälä25c55d32014-09-12 18:03:25 +0300443 /*
444 * Make the FB slightly taller and leave the extra
445 * line opaque white, so that we can see that the
446 * hardware won't scan beyond what it should (esp.
447 * with non-square cursors).
448 */
449 fb_id = igt_create_color_fb(data->drm_fd, cur_w, cur_h + 1,
Tvrtko Ursuline36091d2015-03-03 14:11:01 +0000450 DRM_FORMAT_ARGB8888,
451 LOCAL_DRM_FORMAT_MOD_NONE,
Ville Syrjälä25c55d32014-09-12 18:03:25 +0300452 1.0, 1.0, 1.0,
453 &data->fb);
454
Antti Koskipaaa593d612014-04-10 15:08:05 +0300455 igt_assert(fb_id);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300456
Antti Koskipaaa593d612014-04-10 15:08:05 +0300457 cr = igt_get_cairo_ctx(data->drm_fd, &data->fb);
Ville Syrjälä25c55d32014-09-12 18:03:25 +0300458 draw_cursor(cr, 0, 0, cur_w, cur_h);
Maarten Lankhorstbe2f6fc2018-02-01 12:48:45 +0100459 igt_put_cairo_ctx(data->drm_fd, &data->fb, cr);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300460}
461
Ville Syrjälä25c55d32014-09-12 18:03:25 +0300462static bool has_nonsquare_cursors(uint32_t devid)
463{
464 /*
465 * Test non-square cursors a bit on the platforms
466 * that support such things.
467 */
Ville Syrjäläa0433ca2017-06-01 21:15:45 +0300468 if (devid == PCI_CHIP_845_G || devid == PCI_CHIP_I865_G)
469 return true;
470
471 if (IS_VALLEYVIEW(devid) || IS_CHERRYVIEW(devid))
472 return false;
473
474 return intel_gen(devid) >= 7;
Ville Syrjälä25c55d32014-09-12 18:03:25 +0300475}
476
Matt Roper07087ad2014-06-30 16:44:29 -0700477static void test_cursor_size(data_t *data)
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300478{
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300479 igt_display_t *display = &data->display;
Matt Roper07087ad2014-06-30 16:44:29 -0700480 igt_pipe_crc_t *pipe_crc = data->pipe_crc;
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300481 igt_crc_t crc[10], ref_crc;
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300482 cairo_t *cr;
483 uint32_t fb_id;
Ville Syrjälä25c55d32014-09-12 18:03:25 +0300484 int i, size;
485 int cursor_max_size = data->cursor_max_w;
Matt Roper3f46e812014-06-30 16:44:30 -0700486 int ret;
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300487
488 /* Create a maximum size cursor, then change the size in flight to
489 * smaller ones to see that the size is applied correctly
490 */
491 fb_id = igt_create_fb(data->drm_fd, cursor_max_size, cursor_max_size,
Tvrtko Ursuline36091d2015-03-03 14:11:01 +0000492 DRM_FORMAT_ARGB8888, LOCAL_DRM_FORMAT_MOD_NONE,
493 &data->fb);
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300494 igt_assert(fb_id);
495
496 /* Use a solid white rectangle as the cursor */
497 cr = igt_get_cairo_ctx(data->drm_fd, &data->fb);
498 igt_paint_color_alpha(cr, 0, 0, cursor_max_size, cursor_max_size, 1.0, 1.0, 1.0, 1.0);
Maarten Lankhorstbe2f6fc2018-02-01 12:48:45 +0100499 igt_put_cairo_ctx(data->drm_fd, &data->fb, cr);
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300500
501 /* Hardware test loop */
Matt Roper07087ad2014-06-30 16:44:29 -0700502 cursor_enable(data);
Matt Roper3f46e812014-06-30 16:44:30 -0700503 ret = drmModeMoveCursor(data->drm_fd, data->output->config.crtc->crtc_id, 0, 0);
Matt Roper07be8fe2015-03-05 15:01:00 -0800504 igt_assert_eq(ret, 0);
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300505 for (i = 0, size = cursor_max_size; size >= 64; size /= 2, i++) {
506 /* Change size in flight: */
Matt Roper3f46e812014-06-30 16:44:30 -0700507 ret = drmModeSetCursor(data->drm_fd, data->output->config.crtc->crtc_id,
508 data->fb.gem_handle, size, size);
Matt Roper07be8fe2015-03-05 15:01:00 -0800509 igt_assert_eq(ret, 0);
Matt Roper07087ad2014-06-30 16:44:29 -0700510 igt_wait_for_vblank(data->drm_fd, data->pipe);
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300511 igt_pipe_crc_collect_crc(pipe_crc, &crc[i]);
512 }
Matt Roper07087ad2014-06-30 16:44:29 -0700513 cursor_disable(data);
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300514 /* Software test loop */
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300515 for (i = 0, size = cursor_max_size; size >= 64; size /= 2, i++) {
516 /* Now render the same in software and collect crc */
Maarten Lankhorstbe2f6fc2018-02-01 12:48:45 +0100517 cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300518 igt_paint_color_alpha(cr, 0, 0, size, size, 1.0, 1.0, 1.0, 1.0);
Maarten Lankhorstbe2f6fc2018-02-01 12:48:45 +0100519 igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
520
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300521 igt_display_commit(display);
Matt Roper07087ad2014-06-30 16:44:29 -0700522 igt_wait_for_vblank(data->drm_fd, data->pipe);
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300523 igt_pipe_crc_collect_crc(pipe_crc, &ref_crc);
524 /* Clear screen afterwards */
Maarten Lankhorstbe2f6fc2018-02-01 12:48:45 +0100525 cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
Matt Roper07087ad2014-06-30 16:44:29 -0700526 igt_paint_color(cr, 0, 0, data->screenw, data->screenh,
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300527 0.0, 0.0, 0.0);
Maarten Lankhorstbe2f6fc2018-02-01 12:48:45 +0100528 igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
Daniel Vettere588f6d2015-02-27 20:37:29 +0100529 igt_assert_crc_equal(&crc[i], &ref_crc);
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300530 }
531}
532
Matt Ropercd99dde2015-10-15 16:54:32 -0700533static void test_rapid_movement(data_t *data)
534{
535 struct timeval start, end, delta;
536 int x = 0, y = 0;
537 long usec;
538 int crtc_id = data->output->config.crtc->crtc_id;
539
540 igt_assert_eq(drmModeSetCursor(data->drm_fd, crtc_id,
541 data->fb.gem_handle, data->curw, data->curh), 0);
542
543 gettimeofday(&start, NULL);
544 for ( ; x < 100; x++)
545 igt_assert_eq(drmModeMoveCursor(data->drm_fd, crtc_id, x, y), 0);
546 for ( ; y < 100; y++)
547 igt_assert_eq(drmModeMoveCursor(data->drm_fd, crtc_id, x, y), 0);
548 for ( ; x > 0; x--)
549 igt_assert_eq(drmModeMoveCursor(data->drm_fd, crtc_id, x, y), 0);
550 for ( ; y > 0; y--)
551 igt_assert_eq(drmModeMoveCursor(data->drm_fd, crtc_id, x, y), 0);
552 gettimeofday(&end, NULL);
553
554 /*
555 * We've done 400 cursor updates now. If we're being throttled to
556 * vblank, then that would take roughly 400/refresh seconds. If the
557 * elapsed time is greater than 90% of that value, we'll consider it
558 * a failure (since cursor updates shouldn't be throttled).
559 */
560 timersub(&end, &start, &delta);
561 usec = delta.tv_usec + 1000000 * delta.tv_sec;
562 igt_assert_lt(usec, 0.9 * 400 * 1000000 / data->refresh);
563
564 igt_assert_eq(drmModeSetCursor(data->drm_fd, crtc_id,
565 0, data->curw, data->curh), 0);
566
567}
568
Ville Syrjälä25c55d32014-09-12 18:03:25 +0300569static void run_test_generic(data_t *data)
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530570{
571 int cursor_size;
Ville Syrjälä25c55d32014-09-12 18:03:25 +0300572 for (cursor_size = 64; cursor_size <= 512; cursor_size *= 2) {
573 int w = cursor_size;
574 int h = cursor_size;
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530575
Ville Syrjäläf8e5a3f2014-04-25 13:49:11 +0300576 igt_fixture
Ville Syrjälä25c55d32014-09-12 18:03:25 +0300577 create_cursor_fb(data, w, h);
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530578
579 /* Using created cursor FBs to test cursor support */
Ville Syrjälä25c55d32014-09-12 18:03:25 +0300580 igt_subtest_f("cursor-%dx%d-onscreen", w, h)
581 run_test(data, test_crc_onscreen, w, h);
582 igt_subtest_f("cursor-%dx%d-offscreen", w, h)
583 run_test(data, test_crc_offscreen, w, h);
584 igt_subtest_f("cursor-%dx%d-sliding", w, h)
585 run_test(data, test_crc_sliding, w, h);
586 igt_subtest_f("cursor-%dx%d-random", w, h)
587 run_test(data, test_crc_random, w, h);
Daniel Vettera5c6b8d2015-03-13 18:02:45 +0100588 igt_subtest_f("cursor-%dx%d-dpms", w, h) {
589 data->flags = TEST_DPMS;
590 run_test(data, test_crc_random, w, h);
591 data->flags = 0;
592 }
593
594 igt_subtest_f("cursor-%dx%d-suspend", w, h) {
595 data->flags = TEST_SUSPEND;
596 run_test(data, test_crc_random, w, h);
597 data->flags = 0;
598 }
Ville Syrjälä25c55d32014-09-12 18:03:25 +0300599
Matt Ropercd99dde2015-10-15 16:54:32 -0700600 igt_subtest_f("cursor-%dx%d-rapid-movement", w, h) {
601 run_test(data, test_rapid_movement, w, h);
602 }
603
Ville Syrjälä25c55d32014-09-12 18:03:25 +0300604 igt_fixture
605 igt_remove_fb(data->drm_fd, &data->fb);
606
607 /*
608 * Test non-square cursors a bit on the platforms
609 * that support such things. And make it a bit more
610 * interesting by using a non-pot height.
611 */
612 h /= 3;
613
614 igt_fixture
615 create_cursor_fb(data, w, h);
616
617 /* Using created cursor FBs to test cursor support */
618 igt_subtest_f("cursor-%dx%d-onscreen", w, h) {
619 igt_require(has_nonsquare_cursors(data->devid));
620 run_test(data, test_crc_onscreen, w, h);
621 }
622 igt_subtest_f("cursor-%dx%d-offscreen", w, h) {
623 igt_require(has_nonsquare_cursors(data->devid));
624 run_test(data, test_crc_offscreen, w, h);
625 }
626 igt_subtest_f("cursor-%dx%d-sliding", w, h) {
627 igt_require(has_nonsquare_cursors(data->devid));
628 run_test(data, test_crc_sliding, w, h);
629 }
630 igt_subtest_f("cursor-%dx%d-random", w, h) {
631 igt_require(has_nonsquare_cursors(data->devid));
632 run_test(data, test_crc_random, w, h);
633 }
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530634
Ville Syrjäläf8e5a3f2014-04-25 13:49:11 +0300635 igt_fixture
636 igt_remove_fb(data->drm_fd, &data->fb);
637 }
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530638}
639
Ville Syrjälä25c55d32014-09-12 18:03:25 +0300640static data_t data;
641
Daniel Vetter071e9ca2013-10-31 16:23:26 +0100642igt_main
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300643{
Ville Syrjäläfb2ccb12014-04-25 13:50:59 +0300644 uint64_t cursor_width = 64, cursor_height = 64;
Daniel Vetter52edf3a2014-03-22 14:45:54 +0100645 int ret;
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300646
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300647 igt_skip_on_simulation();
648
649 igt_fixture {
Micah Fedkec81d2932015-07-22 21:54:02 +0000650 data.drm_fd = drm_open_driver_master(DRIVER_INTEL);
Daniel Vetter1f0cf2d2013-10-31 17:02:41 +0100651
Ville Syrjälä25c55d32014-09-12 18:03:25 +0300652 data.devid = intel_get_drm_devid(data.drm_fd);
653
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530654 ret = drmGetCap(data.drm_fd, DRM_CAP_CURSOR_WIDTH, &cursor_width);
Ville Syrjäläfb2ccb12014-04-25 13:50:59 +0300655 igt_assert(ret == 0 || errno == EINVAL);
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530656 /* Not making use of cursor_height since it is same as width, still reading */
657 ret = drmGetCap(data.drm_fd, DRM_CAP_CURSOR_HEIGHT, &cursor_height);
Ville Syrjäläfb2ccb12014-04-25 13:50:59 +0300658 igt_assert(ret == 0 || errno == EINVAL);
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530659
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530660 /* We assume width and height are same so max is assigned width */
Chris Wilson3b94d3f2014-08-29 13:11:40 +0100661 igt_assert_eq(cursor_width, cursor_height);
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530662
Daniel Vetter33f08842014-08-12 11:23:09 +0200663 kmstest_set_vt_graphics_mode();
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300664
Chris Wilson83884e92017-03-21 17:16:03 +0000665 igt_require_pipe_crc(data.drm_fd);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300666
Damien Lespiaud4358292014-02-05 17:14:12 +0000667 igt_display_init(&data.display, data.drm_fd);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300668 }
669
Ville Syrjälä25c55d32014-09-12 18:03:25 +0300670 data.cursor_max_w = cursor_width;
671 data.cursor_max_h = cursor_height;
672
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300673 igt_subtest_f("cursor-size-change")
674 run_test(&data, test_cursor_size, cursor_width, cursor_height);
675
Ville Syrjälä25c55d32014-09-12 18:03:25 +0300676 run_test_generic(&data);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300677
Damien Lespiaud4358292014-02-05 17:14:12 +0000678 igt_fixture {
Damien Lespiaud4358292014-02-05 17:14:12 +0000679 igt_display_fini(&data.display);
680 }
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300681}