blob: 7cb210df5f0c6d12c91321985f2847fc6ac4dc09 [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
Thomas Wood804e11f2015-08-17 17:57:43 +010028#include "igt.h"
Jeff McGeeae339f02015-03-12 17:26:25 -070029#include <unistd.h>
30#include <errno.h>
31#include <xf86drm.h>
32#include <i915_drm.h>
Jeff McGeeae339f02015-03-12 17:26:25 -070033#include "intel_bufmgr.h"
34
35IGT_TEST_DESCRIPTION("Tests the export of parameters via DRM_IOCTL_I915_GETPARAM\n");
36
37int drm_fd;
38int devid;
39
40static void
41init(void)
42{
Micah Fedkec81d2932015-07-22 21:54:02 +000043 drm_fd = drm_open_driver(DRIVER_INTEL);
Jeff McGeeae339f02015-03-12 17:26:25 -070044 devid = intel_get_drm_devid(drm_fd);
45}
46
47static void
48deinit(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
56static int
57getparam(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
72static void
73subslice_total(void)
74{
75 unsigned int subslice_total = 0;
76 int ret;
77
78 ret = getparam(LOCAL_I915_PARAM_SUBSLICE_TOTAL, (int*)&subslice_total);
Shuang Heb556c9e2011-04-19 04:16:06 +080079 igt_skip_on_f(ret == -EINVAL && intel_gen(devid), "Interface not supported by kernel\n");
Jeff McGeeae339f02015-03-12 17:26:25 -070080
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.
Shuang Heb556c9e2011-04-19 04:16:06 +080094 */
Jeff McGeeae339f02015-03-12 17:26:25 -070095 } else {
Jeff McGee301b9e42015-03-24 11:30:57 -070096 igt_assert_eq(ret, 0);
Jeff McGeeae339f02015-03-12 17:26:25 -070097 }
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
109static void
110eu_total(void)
111{
112 unsigned int eu_total = 0;
113 int ret;
114
115 ret = getparam(LOCAL_I915_PARAM_EU_TOTAL, (int*)&eu_total);
Jeff McGee301b9e42015-03-24 11:30:57 -0700116 igt_skip_on_f(ret == -EINVAL, "Interface not supported by kernel\n");
Jeff McGeeae339f02015-03-12 17:26:25 -0700117
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 {
Jeff McGee301b9e42015-03-24 11:30:57 -0700133 igt_assert_eq(ret, 0);
Jeff McGeeae339f02015-03-12 17:26:25 -0700134 }
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
146static void
147exit_handler(int sig)
148{
149 deinit();
150}
151
152igt_main
153{
154 igt_fixture {
155 igt_install_exit_handler(exit_handler);
156 init();
157 }
158
Jesse Barnesb0d8d732015-08-13 12:58:25 -0700159 igt_subtest("basic-subslice-total")
Jeff McGeeae339f02015-03-12 17:26:25 -0700160 subslice_total();
161
Jesse Barnesb0d8d732015-08-13 12:58:25 -0700162 igt_subtest("basic-eu-total")
Jeff McGeeae339f02015-03-12 17:26:25 -0700163 eu_total();
164}