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