1 /*
2  * Copyright © 2014 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  *    Jeff McGee <jeff.mcgee@intel.com>
25  *
26  */
27 
28 #include "igt.h"
29 #include <unistd.h>
30 #include <errno.h>
31 #include <xf86drm.h>
32 #include <i915_drm.h>
33 #include "intel_bufmgr.h"
34 
35 IGT_TEST_DESCRIPTION("Tests the export of parameters via DRM_IOCTL_I915_GETPARAM\n");
36 
37 int drm_fd;
38 int devid;
39 
40 static void
init(void)41 init(void)
42 {
43 	drm_fd = drm_open_driver(DRIVER_INTEL);
44 	devid = intel_get_drm_devid(drm_fd);
45 }
46 
47 static void
deinit(void)48 deinit(void)
49 {
50 	close(drm_fd);
51 }
52 
53 #define LOCAL_I915_PARAM_SUBSLICE_TOTAL	33
54 #define LOCAL_I915_PARAM_EU_TOTAL	34
55 
56 static int
getparam(int param,int * value)57 getparam(int param, int *value)
58 {
59 	drm_i915_getparam_t gp;
60 	int ret;
61 
62 	memset(&gp, 0, sizeof(gp));
63 	gp.value = value;
64 	gp.param = param;
65 	ret = drmIoctl(drm_fd, DRM_IOCTL_I915_GETPARAM, &gp);
66 	if (ret)
67 		return -errno;
68 
69 	return 0;
70 }
71 
72 static void
subslice_total(void)73 subslice_total(void)
74 {
75 	unsigned int subslice_total = 0;
76 	int ret;
77 
78 	ret = getparam(LOCAL_I915_PARAM_SUBSLICE_TOTAL, (int*)&subslice_total);
79 	igt_skip_on_f(ret == -EINVAL && intel_gen(devid), "Interface not supported by kernel\n");
80 
81 	if (ret) {
82 		/*
83 		 * These devices are not required to implement the
84 		 * interface. If they do not, -ENODEV must be returned.
85 		*/
86 		if ((intel_gen(devid) < 8) ||
87 		    IS_BROADWELL(devid) ||
88 		    igt_run_in_simulation()) {
89 			igt_assert_eq(ret, -ENODEV);
90 			igt_info("subslice total: unknown\n");
91 		/*
92 		 * All other devices must implement the interface, so
93 		 * fail them if we are here.
94 		 */
95 		} else {
96 			igt_assert_eq(ret, 0);
97 		}
98 	} else {
99 		/*
100 		 * On success, just make sure the returned count value is
101 		 * non-zero. The validity of the count value for the given
102 		 * device is not checked.
103 		*/
104 		igt_assert_neq(subslice_total, 0);
105 		igt_info("subslice total: %u\n", subslice_total);
106 	}
107 }
108 
109 static void
eu_total(void)110 eu_total(void)
111 {
112 	unsigned int eu_total = 0;
113 	int ret;
114 
115 	ret = getparam(LOCAL_I915_PARAM_EU_TOTAL, (int*)&eu_total);
116 	igt_skip_on_f(ret == -EINVAL, "Interface not supported by kernel\n");
117 
118 	if (ret) {
119 		/*
120 		 * These devices are not required to implement the
121 		 * interface. If they do not, -ENODEV must be returned.
122 		*/
123 		if ((intel_gen(devid) < 8) ||
124 		    IS_BROADWELL(devid) ||
125 		    igt_run_in_simulation()) {
126 			igt_assert_eq(ret, -ENODEV);
127 			igt_info("EU total: unknown\n");
128 		/*
129 		 * All other devices must implement the interface, so
130 		 * fail them if we are here.
131 		*/
132 		} else {
133 			igt_assert_eq(ret, 0);
134 		}
135 	} else {
136 		/*
137 		 * On success, just make sure the returned count value is
138 		 * non-zero. The validity of the count value for the given
139 		 * device is not checked.
140 		*/
141 		igt_assert_neq(eu_total, 0);
142 		igt_info("EU total: %u\n", eu_total);
143 	}
144 }
145 
146 static void
exit_handler(int sig)147 exit_handler(int sig)
148 {
149 	deinit();
150 }
151 
152 igt_main
153 {
154 	igt_fixture {
155 		igt_install_exit_handler(exit_handler);
156 		init();
157 	}
158 
159 	igt_subtest("basic-subslice-total")
160 		subslice_total();
161 
162 	igt_subtest("basic-eu-total")
163 		eu_total();
164 }
165