1 /*
2 * Copyright © 2009 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 * Daniel Vetter <[email protected]>
25 *
26 */
27
28 /** @file gem_gtt_cpu_tlb.c
29 *
30 * This test checks whether gtt tlbs for cpu access are correctly invalidated.
31 */
32
33 #include "igt.h"
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <string.h>
37 #include <fcntl.h>
38 #include <inttypes.h>
39 #include <errno.h>
40 #include <sys/stat.h>
41 #include <sys/time.h>
42 #include <sys/ioctl.h>
43 #include "drm.h"
44
45 IGT_TEST_DESCRIPTION("Check whether gtt tlbs for cpu access are correctly"
46 " invalidated.");
47
48 #define OBJ_SIZE (1024*1024)
49
50 #define PAGE_SIZE 4096
51
52 static uint32_t
create_bo(int fd)53 create_bo(int fd)
54 {
55 uint32_t handle;
56 uint32_t *data;
57 int i;
58
59 handle = gem_create(fd, OBJ_SIZE);
60
61 /* Fill the BO with dwords starting at start_val */
62 data = gem_mmap__gtt(fd, handle, OBJ_SIZE, PROT_READ | PROT_WRITE);
63 gem_set_domain(fd, handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
64 for (i = 0; i < OBJ_SIZE/4; i++)
65 data[i] = i;
66 munmap(data, OBJ_SIZE);
67
68 return handle;
69 }
70
71 igt_simple_main
72 {
73 int fd;
74 int i;
75 uint32_t handle;
76
77 uint32_t *ptr;
78
79 igt_skip_on_simulation();
80
81 fd = drm_open_driver(DRIVER_INTEL);
82
83 handle = gem_create(fd, OBJ_SIZE);
84
85 /* touch one page */
86 ptr = gem_mmap__gtt(fd, handle, OBJ_SIZE, PROT_READ | PROT_WRITE);
87 gem_set_domain(fd, handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
88 *ptr = 0xdeadbeef;
89 munmap(ptr, OBJ_SIZE);
90
91 gem_close(fd, handle);
92
93 /* stirr up the page allocator a bit. */
94 ptr = malloc(OBJ_SIZE);
95 igt_assert(ptr);
96 memset(ptr, 0x1, OBJ_SIZE);
97
98 handle = create_bo(fd);
99
100 /* Read a bunch of random subsets of the data and check that they come
101 * out right.
102 */
103 gem_read(fd, handle, 0, ptr, OBJ_SIZE);
104 for (i = 0; i < OBJ_SIZE/4; i++)
105 igt_assert(ptr[i] == i);
106
107 close(fd);
108 }
109