summaryrefslogtreecommitdiff
path: root/tests/drv_getparams_basic.c
blob: 7cb210df5f0c6d12c91321985f2847fc6ac4dc09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 * Copyright © 2014 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
 * Authors:
 *    Jeff McGee <jeff.mcgee@intel.com>
 *
 */

#include "igt.h"
#include <unistd.h>
#include <errno.h>
#include <xf86drm.h>
#include <i915_drm.h>
#include "intel_bufmgr.h"

IGT_TEST_DESCRIPTION("Tests the export of parameters via DRM_IOCTL_I915_GETPARAM\n");

int drm_fd;
int devid;

static void
init(void)
{
	drm_fd = drm_open_driver(DRIVER_INTEL);
	devid = intel_get_drm_devid(drm_fd);
}

static void
deinit(void)
{
	close(drm_fd);
}

#define LOCAL_I915_PARAM_SUBSLICE_TOTAL	33
#define LOCAL_I915_PARAM_EU_TOTAL	34

static int
getparam(int param, int *value)
{
	drm_i915_getparam_t gp;
	int ret;

	memset(&gp, 0, sizeof(gp));
	gp.value = value;
	gp.param = param;
	ret = drmIoctl(drm_fd, DRM_IOCTL_I915_GETPARAM, &gp);
	if (ret)
		return -errno;

	return 0;
}

static void
subslice_total(void)
{
	unsigned int subslice_total = 0;
	int ret;

	ret = getparam(LOCAL_I915_PARAM_SUBSLICE_TOTAL, (int*)&subslice_total);
	igt_skip_on_f(ret == -EINVAL && intel_gen(devid), "Interface not supported by kernel\n");

	if (ret) {
		/*
		 * These devices are not required to implement the
		 * interface. If they do not, -ENODEV must be returned.
		*/
		if ((intel_gen(devid) < 8) ||
		    IS_BROADWELL(devid) ||
		    igt_run_in_simulation()) {
			igt_assert_eq(ret, -ENODEV);
			igt_info("subslice total: unknown\n");
		/*
		 * All other devices must implement the interface, so
		 * fail them if we are here.
		 */
		} else {
			igt_assert_eq(ret, 0);
		}
	} else {
		/*
		 * On success, just make sure the returned count value is
		 * non-zero. The validity of the count value for the given
		 * device is not checked.
		*/
		igt_assert_neq(subslice_total, 0);
		igt_info("subslice total: %u\n", subslice_total);
	}
}

static void
eu_total(void)
{
	unsigned int eu_total = 0;
	int ret;

	ret = getparam(LOCAL_I915_PARAM_EU_TOTAL, (int*)&eu_total);
	igt_skip_on_f(ret == -EINVAL, "Interface not supported by kernel\n");

	if (ret) {
		/*
		 * These devices are not required to implement the
		 * interface. If they do not, -ENODEV must be returned.
		*/
		if ((intel_gen(devid) < 8) ||
		    IS_BROADWELL(devid) ||
		    igt_run_in_simulation()) {
			igt_assert_eq(ret, -ENODEV);
			igt_info("EU total: unknown\n");
		/*
		 * All other devices must implement the interface, so
		 * fail them if we are here.
		*/
		} else {
			igt_assert_eq(ret, 0);
		}
	} else {
		/*
		 * On success, just make sure the returned count value is
		 * non-zero. The validity of the count value for the given
		 * device is not checked.
		*/
		igt_assert_neq(eu_total, 0);
		igt_info("EU total: %u\n", eu_total);
	}
}

static void
exit_handler(int sig)
{
	deinit();
}

igt_main
{
	igt_fixture {
		igt_install_exit_handler(exit_handler);
		init();
	}

	igt_subtest("basic-subslice-total")
		subslice_total();

	igt_subtest("basic-eu-total")
		eu_total();
}