xref: /aosp_15_r20/external/igt-gpu-tools/tests/vc4_dmabuf_poll.c (revision d83cc019efdc2edc6c4b16e9034a3ceb8d35d77c)
1 /*
2  * Copyright © 2017 Broadcom
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 
24 #include "igt.h"
25 #include "igt_vc4.h"
26 #include <unistd.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include <fcntl.h>
31 #include <inttypes.h>
32 #include <errno.h>
33 #include <sys/stat.h>
34 #include <sys/ioctl.h>
35 #include <poll.h>
36 #include "vc4_drm.h"
37 
38 static void
poll_write_bo_test(int fd,int poll_flag)39 poll_write_bo_test(int fd, int poll_flag)
40 {
41 	size_t size = 1024 * 1024 * 4;
42 	uint32_t clearval = 0xaabbccdd;
43 	/* Get a BO that's being rendered to. */
44 	int handle = igt_vc4_get_cleared_bo(fd, size, clearval);
45 	int dmabuf_fd = prime_handle_to_fd(fd, handle);
46 	struct pollfd p = {
47 		.fd = dmabuf_fd,
48 		.events = POLLIN,
49 	};
50 	struct drm_vc4_wait_bo wait = {
51 		.handle = handle,
52 		.timeout_ns = 0,
53 	};
54 
55 	/* Block for a couple of minutes waiting for rendering to complete. */
56 	int poll_ret = poll(&p, 1, 120 * 1000);
57 	igt_assert(poll_ret == 1);
58 
59 	/* Now that we've waited for idle, a nonblocking wait for the
60 	 * BO should pass.
61 	 */
62 	do_ioctl(fd, DRM_IOCTL_VC4_WAIT_BO, &wait);
63 
64 	close(dmabuf_fd);
65 	gem_close(fd, handle);
66 }
67 
68 igt_main
69 {
70 	int fd;
71 
72 	igt_fixture
73 		fd = drm_open_driver(DRIVER_VC4);
74 
75 	igt_subtest("poll-write-waits-until-write-done") {
76 		poll_write_bo_test(fd, POLLOUT);
77 	}
78 
79 	igt_subtest("poll-read-waits-until-write-done") {
80 		poll_write_bo_test(fd, POLLIN);
81 	}
82 
83 	igt_fixture
84 		close(fd);
85 }
86