summaryrefslogtreecommitdiff
path: root/tools/amd_hdmi_compliance.c
blob: 1a7592995260d36e4327754d33b25e5d4ca74af0 (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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
 * Copyright 2019 Advanced Micro Devices, Inc.
 *
 * 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 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) 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.
 */

#include "igt.h"

/* Common test data */
typedef struct data {
	struct igt_fb pattern_fb_info;
	int fd;
	igt_display_t display;
	igt_plane_t *primary;
	igt_output_t *output;
	igt_pipe_t *pipe;
	enum pipe pipe_id;
	bool use_virtual_connector;
} data_t;

/* Video modes indexed by VIC */
static drmModeModeInfo test_modes[] = {
	[1] = { 25175,
		640, 656, 752, 800, 0,
		480, 489, 492, 525, 0,
		60, 0xa, 0x40,
		"640x480",	/* VIC 1 */
	},
	[96] = { 594000,
		 3840, 4896, 4984, 5280, 0,
		 2160, 2168, 2178, 2250, 0,
		 50, 0x5|DRM_MODE_FLAG_PIC_AR_16_9, 0x40,
		 "3840x2160",	/* VIC 96 */
	},
	[97] = { 594000,
		 3840, 4016, 4104, 4400, 0,
		 2160, 2168, 2178, 2250, 0,
		 60, 0x5|DRM_MODE_FLAG_PIC_AR_16_9, 0x40,
		 "3840x2160",	/* VIC 97 */
	},
	[101] = { 594000,
		  4096, 5064, 5152, 5280, 0,
		  2160, 2168, 2178, 2250, 0,
		  50, 0x5|DRM_MODE_FLAG_PIC_AR_256_135, 0x40,
		  "4096x2160",	/* VIC 101 */
	},
	[102] = { 594000,
		  4096, 4184, 4272, 4400, 0,
		  2160, 2168, 2178, 2250, 0,
		  60, 0x5|DRM_MODE_FLAG_PIC_AR_256_135, 0x40,
		  "4096x2160",	/* VIC 102 */
	},
	[106] = { 594000,
		  3840, 4896, 4984, 5280, 0,
		  2160, 2168, 2178, 2250, 0,
		  50, 0x5|DRM_MODE_FLAG_PIC_AR_64_27, 0x40,
		  "3840x2160",	/* VIC 106 */
	},
	[107] = { 594000,
		  3840, 4016, 4104, 4400, 0,
		  2160, 2168, 2178, 2250, 0,
		  60, 0x5|DRM_MODE_FLAG_PIC_AR_64_27, 0x40,
		  "3840x2160",	/* VIC 107 */
	},
};

/* Common test setup. */
static void test_init(data_t *data)
{
	igt_display_t *display = &data->display;

	data->pipe_id = PIPE_A;
	data->pipe = &data->display.pipes[data->pipe_id];

	igt_display_reset(display);

	/* find a connected HDMI output */
	data->output = NULL;
	for (int i=0; i < data->display.n_outputs; ++i) {
		drmModeConnector *connector = data->display.outputs[i].config.connector;
		if (connector->connection == DRM_MODE_CONNECTED &&
				(connector->connector_type == DRM_MODE_CONNECTOR_HDMIA ||
				 (data->use_virtual_connector &&
				  connector->connector_type == DRM_MODE_CONNECTOR_VIRTUAL))) {
			data->output = &data->display.outputs[i];
		}
	}

	igt_require(data->output);

	data->primary =
		igt_pipe_get_plane_type(data->pipe, DRM_PLANE_TYPE_PRIMARY);

	igt_output_set_pipe(data->output, data->pipe_id);

}

/* Common test cleanup. */
static void test_fini(data_t *data)
{
	igt_display_reset(&data->display);
}

static void wait_for_keypress(void)
{
	while (getchar() != '\n')
		;
}

static void test_vic_mode(data_t *data, int vic)
{
	igt_display_t *display = &data->display;
	drmModeModeInfo *mode;
	igt_fb_t afb;

	test_init(data);

	mode = &test_modes[vic];

	igt_output_override_mode(data->output, mode);

	igt_create_pattern_fb(data->fd, mode->hdisplay, mode->vdisplay, DRM_FORMAT_XRGB8888, 0, &afb);

	igt_plane_set_fb(data->primary, &afb);

	igt_display_commit_atomic(display, DRM_MODE_ATOMIC_ALLOW_MODESET, NULL);

	igt_info("Press [Enter] to finish\n");
	wait_for_keypress();

	test_fini(data);
}

const char *optstr = "hvt:";
static void usage(const char *name)
{
	igt_info("Usage: %s [options]\n", name);
	igt_info("-h      Show help\n");
	igt_info("-t vic  Select video mode based on VIC\n");
	igt_info("-v      Test on 'Virtual' connector as well, for debugging.\n");
}

int main(int argc, char **argv)
{
	data_t data;
	int c;
	int vic = 1; /* default to VIC 1 (640x480) */

	memset(&data, 0, sizeof(data));

	while((c = getopt(argc, argv, optstr)) != -1) {
		switch(c) {
		case 't':
			vic = atoi(optarg);
			break;
		case 'v':
			data.use_virtual_connector = true;
			break;
		default:
		case 'h':
			usage(argv[0]);
			exit(EXIT_SUCCESS);
		}
	}

	if (vic < 1 ||
		vic > ARRAY_SIZE(test_modes) ||
		!test_modes[vic].name[0]) {
		igt_warn("VIC %d is not supported\n", vic);
		exit(EXIT_FAILURE);
	}

	data.fd = drm_open_driver_master(DRIVER_ANY);
	kmstest_set_vt_graphics_mode();

	igt_display_require(&data.display, data.fd);
	igt_require(data.display.is_atomic);
	igt_display_require_output(&data.display);

	test_vic_mode(&data, vic);

	igt_display_fini(&data.display);
}