xref: /aosp_15_r20/external/igt-gpu-tools/tests/i915/gem_largeobject.c (revision d83cc019efdc2edc6c4b16e9034a3ceb8d35d77c)
1 /*
2  * Copyright © 2008 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  *    Jesse Barnes <[email protected]>
25  *
26  */
27 
28 #include "igt.h"
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <string.h>
32 #include <fcntl.h>
33 #include <inttypes.h>
34 #include <errno.h>
35 #include <sys/stat.h>
36 #include <sys/ioctl.h>
37 #include "drm.h"
38 
39 /* Should take 64 pages to store the page pointers on 64 bit */
40 #define OBJ_SIZE (128 * 1024 * 1024)
41 
42 unsigned char *data;
43 
44 static void
test_large_object(int fd)45 test_large_object(int fd)
46 {
47 	struct drm_i915_gem_create create;
48 	struct drm_i915_gem_pin pin;
49 	uint32_t obj_size;
50 	char *ptr;
51 
52 	memset(&create, 0, sizeof(create));
53 	memset(&pin, 0, sizeof(pin));
54 
55 	if (gem_aperture_size(fd)*3/4 < OBJ_SIZE/2)
56 		obj_size = OBJ_SIZE / 4;
57 	else if (gem_aperture_size(fd)*3/4 < OBJ_SIZE)
58 		obj_size = OBJ_SIZE / 2;
59 	else
60 		obj_size = OBJ_SIZE;
61 	create.size = obj_size;
62 	igt_info("obj size %i\n", obj_size);
63 
64 	igt_assert(ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create) == 0);
65 
66 	/* prefault */
67 	ptr = gem_mmap__gtt(fd, create.handle, obj_size,
68 			    PROT_WRITE | PROT_READ);
69 	*ptr = 0;
70 
71 	gem_write(fd, create.handle, 0, data, obj_size);
72 
73 	/* kernel should clean this up for us */
74 }
75 
76 igt_simple_main
77 {
78 	int fd;
79 
80 	igt_skip_on_simulation();
81 
82 	data = malloc(OBJ_SIZE);
83 	igt_assert(data);
84 
85 	fd = drm_open_driver(DRIVER_INTEL);
86 
87 	test_large_object(fd);
88 
89 	free(data);
90 }
91