1 /* basic set of prime tests between intel and nouveau */
4 1. share buffer from intel -> nouveau.
5 2. share buffer from nouveau -> intel
6 3. share intel->nouveau, map on both, write intel, read nouveau
7 4. share intel->nouveau, blit intel fill, readback on nouveau
8 test 1 + map buffer, read/write, map other size.
9 do some hw actions on the buffer
10 some illegal operations -
11 close prime fd try and map
13 TODO add some nouveau rendering tests
23 #include <sys/ioctl.h>
27 #include <xf86drmMode.h>
29 #include "ioctl_wrappers.h"
30 #include "intel_bufmgr.h"
32 #include "intel_batchbuffer.h"
34 #include "intel_chipset.h"
36 int intel_fd = -1, udl_fd = -1;
37 drm_intel_bufmgr *bufmgr;
39 struct intel_batchbuffer *intel_batch;
41 #define BO_SIZE (640*480*2)
43 static int find_and_open_devices(void)
51 for (i = 0; i < 9; i++) {
52 sprintf(path, "/sys/class/drm/card%d/device/vendor", i);
53 if (stat(path, &buf)) {
54 /* look for usb dev */
55 sprintf(path, "/sys/class/drm/card%d/device/idVendor", i);
60 fl = fopen(path, "r");
64 fgets(vendor_id, 8, fl);
67 venid = strtoul(vendor_id, NULL, 16);
68 sprintf(path, "/dev/dri/card%d", i);
69 if (venid == 0x8086) {
70 intel_fd = open(path, O_RDWR);
73 } else if (venid == 0x17e9) {
74 udl_fd = open(path, O_RDWR);
82 static int dumb_bo_destroy(int fd, uint32_t handle)
85 struct drm_mode_destroy_dumb arg;
87 memset(&arg, 0, sizeof(arg));
89 ret = drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &arg);
97 * simple share and import
99 static int test1(void)
101 drm_intel_bo *test_intel_bo;
106 test_intel_bo = drm_intel_bo_alloc(bufmgr, "test bo", BO_SIZE, 4096);
108 drm_intel_bo_gem_export_to_prime(test_intel_bo, &prime_fd);
110 ret = drmPrimeFDToHandle(udl_fd, prime_fd, &udl_handle);
112 dumb_bo_destroy(udl_fd, udl_handle);
113 drm_intel_bo_unreference(test_intel_bo);
117 static int test2(void)
119 drm_intel_bo *test_intel_bo;
126 test_intel_bo = drm_intel_bo_alloc(bufmgr, "test bo", BO_SIZE, 4096);
128 drm_intel_bo_gem_export_to_prime(test_intel_bo, &prime_fd);
130 ret = drmPrimeFDToHandle(udl_fd, prime_fd, &udl_handle);
134 ret = drmModeAddFB(udl_fd, 640, 480, 16, 16, 640, udl_handle, &fb_id);
142 ret = drmModeDirtyFB(udl_fd, fb_id, &clip, 1);
147 dumb_bo_destroy(udl_fd, udl_handle);
148 drm_intel_bo_unreference(test_intel_bo);
154 igt_skip_on_simulation();
156 igt_assert(find_and_open_devices() >= 0);
158 igt_skip_on(udl_fd == -1);
159 igt_skip_on(intel_fd == -1);
161 /* set up intel bufmgr */
162 bufmgr = drm_intel_bufmgr_gem_init(intel_fd, 4096);
163 drm_intel_bufmgr_gem_enable_reuse(bufmgr);
165 /* set up an intel batch buffer */
166 devid = intel_get_drm_devid(intel_fd);
167 intel_batch = intel_batchbuffer_alloc(bufmgr, devid);
169 /* create an object on the i915 */
170 igt_assert(test1() == 0);
172 igt_assert(test2() == 0);
174 intel_batchbuffer_free(intel_batch);
176 drm_intel_bufmgr_destroy(bufmgr);