blob: 3752a1f647a54a66658d7c02404a01e7de85a9b6 [file] [log] [blame]
Daniel Vetter2d431fd2012-10-03 13:44:30 +02001/*
2 * Copyright (c) 2012 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 * Authors:
24 * Mika Kuoppala <mika.kuoppala@intel.com>
25 */
26
27#include <stdlib.h>
28#include <string.h>
Daniel Vetter2d431fd2012-10-03 13:44:30 +020029#include <fcntl.h>
30#include <unistd.h>
31#include <pthread.h>
32
33#include "drmtest.h"
Daniel Vettere49ceb82014-03-22 21:07:37 +010034#include "ioctl_wrappers.h"
Daniel Vetter2d431fd2012-10-03 13:44:30 +020035#include "intel_bufmgr.h"
36
37/* Testcase: check parallel access to tiled memory
38 *
39 * Parallel access to tiled memory caused sigbus
40 */
41
42#define NUM_THREADS 2
43#define WIDTH 4096
44#define HEIGHT 4096
45
46struct thread_ctx {
47 drm_intel_bo *bo;
48};
49
50static drm_intel_bufmgr *bufmgr;
51static struct thread_ctx tctx[NUM_THREADS];
52
53static void *copy_fn(void *p)
54{
55 unsigned char *buf;
56 struct thread_ctx *c = p;
57
58 buf = malloc(WIDTH * HEIGHT);
59 if (buf == NULL)
60 return (void *)1;
61
62 memcpy(buf, c->bo->virtual, WIDTH * HEIGHT);
63
64 free(buf);
65 return (void *)0;
66}
67
68static int copy_tile_threaded(drm_intel_bo *bo)
69{
70 int i;
71 int r;
72 pthread_t thr[NUM_THREADS];
73 void *status;
74
75 for (i = 0; i < NUM_THREADS; i++) {
76 tctx[i].bo = bo;
77 r = pthread_create(&thr[i], NULL, copy_fn, (void *)&tctx[i]);
Daniel Vetter83440952013-08-13 12:35:58 +020078 igt_assert(r == 0);
Daniel Vetter2d431fd2012-10-03 13:44:30 +020079 }
80
81 for (i = 0; i < NUM_THREADS; i++) {
82 pthread_join(thr[i], &status);
Daniel Vetter83440952013-08-13 12:35:58 +020083 igt_assert(status == 0);
Daniel Vetter2d431fd2012-10-03 13:44:30 +020084 }
85
86 return 0;
87}
88
Daniel Vetterdda85fb2013-12-10 10:18:32 +010089igt_simple_main
Daniel Vetter2d431fd2012-10-03 13:44:30 +020090{
91 int fd;
92 drm_intel_bo *bo;
93 uint32_t tiling_mode = I915_TILING_Y;
94 unsigned long pitch = 0;
95 int r;
96
Daniel Vetter1caaf0a2013-08-12 12:17:35 +020097 igt_skip_on_simulation();
Damien Lespiau5fa15f72013-04-29 18:40:39 +010098
Daniel Vetter2d431fd2012-10-03 13:44:30 +020099 fd = drm_open_any();
Daniel Vetter83440952013-08-13 12:35:58 +0200100 igt_assert(fd >= 0);
Daniel Vetter2d431fd2012-10-03 13:44:30 +0200101
102 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
Daniel Vetter83440952013-08-13 12:35:58 +0200103 igt_assert(bufmgr);
Daniel Vetter2d431fd2012-10-03 13:44:30 +0200104
105 bo = drm_intel_bo_alloc_tiled(bufmgr, "mmap bo", WIDTH, HEIGHT, 1,
106 &tiling_mode, &pitch, 0);
Daniel Vetter83440952013-08-13 12:35:58 +0200107 igt_assert(bo);
Daniel Vetter2d431fd2012-10-03 13:44:30 +0200108
109 r = drm_intel_gem_bo_map_gtt(bo);
Daniel Vetter83440952013-08-13 12:35:58 +0200110 igt_assert(!r);
Daniel Vetter2d431fd2012-10-03 13:44:30 +0200111
112 r = copy_tile_threaded(bo);
Daniel Vetter83440952013-08-13 12:35:58 +0200113 igt_assert(!r);
Daniel Vetter2d431fd2012-10-03 13:44:30 +0200114
115 r = drm_intel_gem_bo_unmap_gtt(bo);
Daniel Vetter83440952013-08-13 12:35:58 +0200116 igt_assert(!r);
Daniel Vetter2d431fd2012-10-03 13:44:30 +0200117
118 drm_intel_bo_unreference(bo);
119 drm_intel_bufmgr_destroy(bufmgr);
120
121 close(fd);
Daniel Vetter2d431fd2012-10-03 13:44:30 +0200122}