blob: 163bf1010d994f8b750accc3434e69c6dd759278 [file] [log] [blame]
Jesse Barnes433e1c82009-05-14 14:39:48 -07001/*
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 <jbarnes@virtuousgeek.org>
25 *
26 */
27
28#include <stdlib.h>
29#include <stdio.h>
30#include <string.h>
31#include <assert.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#include "i915_drm.h"
39#include "drmtest.h"
40
41/* Should take 64 pages to store the page pointers on 64 bit */
42#define OBJ_SIZE (128 * 1024 * 1024)
43
44unsigned char data[OBJ_SIZE];
45
46static void
47test_large_object(int fd)
48{
49 struct drm_i915_gem_create create;
Jesse Barnes433e1c82009-05-14 14:39:48 -070050 struct drm_i915_gem_pin pin;
Daniel Vetter6b4f5c72011-11-01 11:52:53 +010051 uint32_t obj_size;
Jesse Barnes433e1c82009-05-14 14:39:48 -070052 int ret;
53
54 memset(&create, 0, sizeof(create));
Jesse Barnes433e1c82009-05-14 14:39:48 -070055 memset(&pin, 0, sizeof(pin));
56
Daniel Vetter6b4f5c72011-11-01 11:52:53 +010057 if (gem_aperture_size(fd)*3/4 < OBJ_SIZE/2)
58 obj_size = OBJ_SIZE / 4;
59 else if (gem_aperture_size(fd)*3/4 < OBJ_SIZE)
60 obj_size = OBJ_SIZE / 2;
61 else
62 obj_size = OBJ_SIZE;
63 create.size = obj_size;
64 printf("obj size %i\n", obj_size);
65
Jesse Barnes433e1c82009-05-14 14:39:48 -070066 ret = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
67 if (ret) {
68 fprintf(stderr, "object creation failed: %s\n",
69 strerror(errno));
70 exit(ret);
71 }
72
73 pin.handle = create.handle;
74 ret = ioctl(fd, DRM_IOCTL_I915_GEM_PIN, &pin);
75 if (ret) {
76 fprintf(stderr, "pin failed: %s\n",
77 strerror(errno));
78 exit(ret);
79 }
80
Daniel Vetter08cd2f22012-01-10 16:10:48 +010081 gem_write(fd, create.handle, 0, data, obj_size);
Jesse Barnes433e1c82009-05-14 14:39:48 -070082
83 /* kernel should clean this up for us */
84}
85
86int main(int argc, char **argv)
87{
88 int fd;
89
90 fd = drm_open_any();
91
92 test_large_object(fd);
93
94 return 0;
95}