kms_properties.c 20.3 KB
Newer Older
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
/*
 * Copyright © 2016 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.
 */

#include "igt.h"
#include "drmtest.h"
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <time.h>

32
struct additional_test {
33
	const char *name;
34 35 36 37 38
	uint32_t obj_type;
	void (*prop_test)(int fd, uint32_t id, uint32_t type, drmModePropertyPtr prop,
			  uint32_t prop_id, uint64_t prop_value, bool atomic);
};

39 40 41 42 43 44 45 46 47
static void prepare_pipe(igt_display_t *display, enum pipe pipe, igt_output_t *output, struct igt_fb *fb)
{
	drmModeModeInfo *mode = igt_output_get_mode(output);

	igt_create_pattern_fb(display->drm_fd, mode->hdisplay, mode->vdisplay,
			      DRM_FORMAT_XRGB8888, LOCAL_DRM_FORMAT_MOD_NONE, fb);

	igt_output_set_pipe(output, pipe);

48
	igt_plane_set_fb(igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY), fb);
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

	igt_display_commit2(display, display->is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY);
}

static void cleanup_pipe(igt_display_t *display, enum pipe pipe, igt_output_t *output, struct igt_fb *fb)
{
	igt_plane_t *plane;

	for_each_plane_on_pipe(display, pipe, plane)
		igt_plane_set_fb(plane, NULL);

	igt_output_set_pipe(output, PIPE_NONE);

	igt_display_commit2(display, display->is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY);

	igt_remove_fb(display->drm_fd, fb);
}

67 68
static bool ignore_property(uint32_t obj_type, uint32_t prop_flags,
			    const char *name, bool atomic)
69
{
70
	if (prop_flags & DRM_MODE_PROP_IMMUTABLE)
71 72
		return true;

73
	switch (obj_type) {
74
	case DRM_MODE_OBJECT_CONNECTOR:
75 76 77
		if (atomic && !strcmp(name, "DPMS"))
			return true;
		break;
78
	default:
79
		break;
80
	}
81 82

	return false;
83 84
}

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
static void max_bpc_prop_test(int fd, uint32_t id, uint32_t type, drmModePropertyPtr prop,
			      uint32_t prop_id, uint64_t prop_value, bool atomic)
{
	drmModeAtomicReqPtr req = NULL;
	int i, ret;

	if (atomic)
		req = drmModeAtomicAlloc();

	for ( i = prop->values[0]; i < prop->values[1] ; i++) {
		if (!atomic) {
			ret = drmModeObjectSetProperty(fd, id, type, prop_id, i);

			igt_assert_eq(ret, 0);
		} else {
			ret = drmModeAtomicAddProperty(req, id, prop_id, i);
			igt_assert(ret >= 0);

103
			ret = drmModeAtomicCommit(fd, req, DRM_MODE_ATOMIC_TEST_ONLY | DRM_MODE_ATOMIC_ALLOW_MODESET, NULL);
104 105 106 107 108 109 110 111 112 113 114 115
			igt_assert_eq(ret, 0);
		}
	}

	if (atomic)
		drmModeAtomicFree(req);
}

static const struct additional_test property_functional_test[] = {
									{"max bpc", DRM_MODE_OBJECT_CONNECTOR,
									 max_bpc_prop_test},
								 };
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130

static bool has_additional_test_lookup(uint32_t obj_type, const char *name,
				bool atomic, int *index)
{
	int i;

	for (i = 0; i < ARRAY_SIZE(property_functional_test); i++)
		if (property_functional_test[i].obj_type == obj_type &&
		    !strcmp(name, property_functional_test[i].name)) {
			*index = i;
			return true;
		}

	return false;
}
131 132 133 134
static void test_properties(int fd, uint32_t type, uint32_t id, bool atomic)
{
	drmModeObjectPropertiesPtr props =
		drmModeObjectGetProperties(fd, id, type);
135
	int i, j, ret;
136 137 138 139 140 141 142 143 144 145 146 147 148 149
	drmModeAtomicReqPtr req = NULL;

	igt_assert(props);

	if (atomic)
		req = drmModeAtomicAlloc();

	for (i = 0; i < props->count_props; i++) {
		uint32_t prop_id = props->props[i];
		uint64_t prop_value = props->prop_values[i];
		drmModePropertyPtr prop = drmModeGetProperty(fd, prop_id);

		igt_assert(prop);

150
		if (ignore_property(type, prop->flags, prop->name, atomic)) {
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
			igt_debug("Ignoring property \"%s\"\n", prop->name);

			continue;
		}

		igt_debug("Testing property \"%s\"\n", prop->name);

		if (!atomic) {
			ret = drmModeObjectSetProperty(fd, id, type, prop_id, prop_value);

			igt_assert_eq(ret, 0);
		} else {
			ret = drmModeAtomicAddProperty(req, id, prop_id, prop_value);
			igt_assert(ret >= 0);

			ret = drmModeAtomicCommit(fd, req, DRM_MODE_ATOMIC_TEST_ONLY, NULL);
			igt_assert_eq(ret, 0);
		}

170 171 172
		if (has_additional_test_lookup(type, prop->name, atomic, &j))
			property_functional_test[j].prop_test(fd, id, type, prop, prop_id, prop_value, atomic);

173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
		drmModeFreeProperty(prop);
	}

	drmModeFreeObjectProperties(props);

	if (atomic) {
		ret = drmModeAtomicCommit(fd, req, 0, NULL);
		igt_assert_eq(ret, 0);

		drmModeAtomicFree(req);
	}
}

static void run_plane_property_tests(igt_display_t *display, enum pipe pipe, igt_output_t *output, bool atomic)
{
	struct igt_fb fb;
	igt_plane_t *plane;

	prepare_pipe(display, pipe, output, &fb);

	for_each_plane_on_pipe(display, pipe, plane) {
194 195
		igt_info("Testing plane properties on %s.#%d-%s (output: %s)\n",
			 kmstest_pipe_name(pipe), plane->index, kmstest_plane_type_name(plane->type), output->name);
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305

		test_properties(display->drm_fd, DRM_MODE_OBJECT_PLANE, plane->drm_plane->plane_id, atomic);
	}

	cleanup_pipe(display, pipe, output, &fb);
}

static void run_crtc_property_tests(igt_display_t *display, enum pipe pipe, igt_output_t *output, bool atomic)
{
	struct igt_fb fb;

	prepare_pipe(display, pipe, output, &fb);

	igt_info("Testing crtc properties on %s (output: %s)\n", kmstest_pipe_name(pipe), output->name);

	test_properties(display->drm_fd, DRM_MODE_OBJECT_CRTC, display->pipes[pipe].crtc_id, atomic);

	cleanup_pipe(display, pipe, output, &fb);
}

static void run_connector_property_tests(igt_display_t *display, enum pipe pipe, igt_output_t *output, bool atomic)
{
	struct igt_fb fb;

	if (pipe != PIPE_NONE)
		prepare_pipe(display, pipe, output, &fb);

	igt_info("Testing connector properties on output %s (pipe: %s)\n", output->name, kmstest_pipe_name(pipe));

	test_properties(display->drm_fd, DRM_MODE_OBJECT_CONNECTOR, output->id, atomic);

	if (pipe != PIPE_NONE)
		cleanup_pipe(display, pipe, output, &fb);
}

static void plane_properties(igt_display_t *display, bool atomic)
{
	bool found_any = false, found;
	igt_output_t *output;
	enum pipe pipe;

	if (atomic)
		igt_skip_on(!display->is_atomic);

	for_each_pipe(display, pipe) {
		found = false;

		for_each_valid_output_on_pipe(display, pipe, output) {
			found_any = found = true;

			run_plane_property_tests(display, pipe, output, atomic);
			break;
		}
	}

	igt_skip_on(!found_any);
}

static void crtc_properties(igt_display_t *display, bool atomic)
{
	bool found_any_valid_pipe = false, found;
	enum pipe pipe;
	igt_output_t *output;

	if (atomic)
		igt_skip_on(!display->is_atomic);

	for_each_pipe(display, pipe) {
		found = false;

		for_each_valid_output_on_pipe(display, pipe, output) {
			found_any_valid_pipe = found = true;

			run_crtc_property_tests(display, pipe, output, atomic);
			break;
		}
	}

	igt_skip_on(!found_any_valid_pipe);
}

static void connector_properties(igt_display_t *display, bool atomic)
{
	int i;
	enum pipe pipe;
	igt_output_t *output;

	if (atomic)
		igt_skip_on(!display->is_atomic);

	for_each_connected_output(display, output) {
		bool found = false;

		for_each_pipe(display, pipe) {
			if (!igt_pipe_connector_valid(pipe, output))
				continue;

			found = true;
			run_connector_property_tests(display, pipe, output, atomic);
			break;
		}

		igt_assert_f(found, "Connected output should have at least 1 valid crtc\n");
	}

	for (i = 0; i < display->n_outputs; i++)
		if (!igt_output_is_connected(&display->outputs[i]))
			run_connector_property_tests(display, PIPE_NONE, &display->outputs[i], atomic);
}

306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
static void test_invalid_properties(int fd,
				    uint32_t id1,
				    uint32_t type1,
				    uint32_t id2,
				    uint32_t type2,
				    bool atomic)
{
	drmModeObjectPropertiesPtr props1 =
		drmModeObjectGetProperties(fd, id1, type1);
	drmModeObjectPropertiesPtr props2 =
		drmModeObjectGetProperties(fd, id2, type2);

	int i, j, ret;
	drmModeAtomicReqPtr req;

	igt_assert(props1 && props2);

	for (i = 0; i < props2->count_props; i++) {
		uint32_t prop_id = props2->props[i];
		uint64_t prop_value = props2->prop_values[i];
		drmModePropertyPtr prop = drmModeGetProperty(fd, prop_id);
		bool found = false;

		igt_assert(prop);

		for (j = 0; j < props1->count_props; j++)
			if (props1->props[j] == prop_id) {
				found = true;
				break;
			}

		if (found)
			continue;

		igt_debug("Testing property \"%s\" on [%x:%u]\n", prop->name, type1, id1);

		if (!atomic) {
			ret = drmModeObjectSetProperty(fd, id1, type1, prop_id, prop_value);

			igt_assert_eq(ret, -EINVAL);
		} else {
			req = drmModeAtomicAlloc();
			igt_assert(req);

			ret = drmModeAtomicAddProperty(req, id1, prop_id, prop_value);
			igt_assert(ret >= 0);

			ret = drmModeAtomicCommit(fd, req, DRM_MODE_ATOMIC_ALLOW_MODESET, NULL);
354
			igt_assert_eq(ret, -ENOENT);
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383

			drmModeAtomicFree(req);
		}

		drmModeFreeProperty(prop);
	}

	drmModeFreeObjectProperties(props1);
	drmModeFreeObjectProperties(props2);
}
static void test_object_invalid_properties(igt_display_t *display,
					   uint32_t id, uint32_t type, bool atomic)
{
	igt_output_t *output;
	igt_plane_t *plane;
	enum pipe pipe;
	int i;

	for_each_pipe(display, pipe)
		test_invalid_properties(display->drm_fd, id, type, display->pipes[pipe].crtc_id, DRM_MODE_OBJECT_CRTC, atomic);

	for_each_pipe(display, pipe)
		for_each_plane_on_pipe(display, pipe, plane)
			test_invalid_properties(display->drm_fd, id, type, plane->drm_plane->plane_id, DRM_MODE_OBJECT_PLANE, atomic);

	for (i = 0, output = &display->outputs[0]; i < display->n_outputs; output = &display->outputs[++i])
		test_invalid_properties(display->drm_fd, id, type, output->id, DRM_MODE_OBJECT_CONNECTOR, atomic);
}

384 385
static void validate_range_prop(const struct drm_mode_get_property *prop,
				uint64_t value)
386
{
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
	const uint64_t *values = from_user_pointer(prop->values_ptr);
	bool is_unsigned = prop->flags & DRM_MODE_PROP_RANGE;
	bool immutable = prop->flags & DRM_MODE_PROP_IMMUTABLE;

	igt_assert_eq(prop->count_values, 2);
	igt_assert_eq(prop->count_enum_blobs, 0);
	igt_assert(values[0] != values[1] || immutable);

	if (is_unsigned) {
		igt_assert_lte_u64(values[0], values[1]);
		igt_assert_lte_u64(values[0], value);
		igt_assert_lte_u64(value, values[1]);
	} else {
		igt_assert_lte_s64(values[0], values[1]);
		igt_assert_lte_s64(values[0], value);
		igt_assert_lte_s64(value, values[1]);
	}

}

static void validate_enums(const struct drm_mode_get_property *prop)
{
	const uint64_t *values = from_user_pointer(prop->values_ptr);
	const struct drm_mode_property_enum *enums =
		from_user_pointer(prop->enum_blob_ptr);

	for (int i = 0; i < prop->count_enum_blobs; i++) {
		int name_len = strnlen(enums[i].name,
				       sizeof(enums[i].name));
416

417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
		igt_assert_lte(1, name_len);
		igt_assert_lte(name_len, sizeof(enums[i].name) - 1);

		/* no idea why we have this duplicated */
		igt_assert_eq_u64(values[i], enums[i].value);
	}
}

static void validate_enum_prop(const struct drm_mode_get_property *prop,
			       uint64_t value)
{
	const uint64_t *values = from_user_pointer(prop->values_ptr);
	bool immutable = prop->flags & DRM_MODE_PROP_IMMUTABLE;
	int i;

	igt_assert_lte(1, prop->count_values);
	igt_assert_eq(prop->count_enum_blobs, prop->count_values);
	igt_assert(prop->count_values != 1 || immutable);

	for (i = 0; i < prop->count_values; i++) {
		if (value == values[i])
			break;
	}
	igt_assert(i != prop->count_values);

	validate_enums(prop);
}

static void validate_bitmask_prop(const struct drm_mode_get_property *prop,
				  uint64_t value)
{
	const uint64_t *values = from_user_pointer(prop->values_ptr);
	bool immutable = prop->flags & DRM_MODE_PROP_IMMUTABLE;
	uint64_t mask = 0;

	igt_assert_lte(1, prop->count_values);
	igt_assert_eq(prop->count_enum_blobs, prop->count_values);
	igt_assert(prop->count_values != 1 || immutable);

	for (int i = 0; i < prop->count_values; i++) {
		igt_assert_lte_u64(values[i], 63);
		mask |= 1ULL << values[i];
	}

	igt_assert_eq_u64(value & ~mask, 0);
	igt_assert_neq_u64(value & mask, 0);

	validate_enums(prop);
}

static void validate_blob_prop(int fd,
			       const struct drm_mode_get_property *prop,
			       uint64_t value)
{
	struct drm_mode_get_blob blob;
472 473

	/*
474 475 476
	 * Despite what libdrm makes you believe, we never supply
	 * additional information for BLOB properties, only for enums
	 * and bitmasks
477
	 */
478 479
	igt_assert_eq(prop->count_values, 0);
	igt_assert_eq(prop->count_enum_blobs, 0);
480

481
	igt_assert_lte_u64(value, 0xffffffff);
482

483 484 485 486 487
	/*
	 * Immutable blob properties can have value==0.
	 * Happens for example with the "EDID" property
	 * when there is nothing hooked up to the connector.
	 */
488

489 490
	if (!value)
		return;
491

492 493
	memset(&blob, 0, sizeof(blob));
	blob.blob_id = value;
494

495 496
	do_ioctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &blob);
}
497

498 499 500 501 502 503 504 505
static void validate_object_prop(int fd,
				 const struct drm_mode_get_property *prop,
				 uint64_t value)
{
	const uint64_t *values = from_user_pointer(prop->values_ptr);
	bool immutable = prop->flags & DRM_MODE_PROP_IMMUTABLE;
	struct drm_mode_crtc crtc;
	struct drm_mode_fb_cmd fb;
506

507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
	igt_assert_eq(prop->count_values, 1);
	igt_assert_eq(prop->count_enum_blobs, 0);

	igt_assert_lte_u64(value, 0xffffffff);
	igt_assert(!immutable || value != 0);

	switch (values[0]) {
	case DRM_MODE_OBJECT_CRTC:
		if (!value)
			break;
		memset(&crtc, 0, sizeof(crtc));
		crtc.crtc_id = value;
		do_ioctl(fd, DRM_IOCTL_MODE_GETCRTC, &crtc);
		break;
	case DRM_MODE_OBJECT_FB:
		if (!value)
			break;
		memset(&fb, 0, sizeof(fb));
		fb.fb_id = value;
		do_ioctl(fd, DRM_IOCTL_MODE_GETFB, &fb);
		break;
	default:
		/* These are the only types we have so far */
		igt_assert(0);
531 532 533
	}
}

534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704
static void validate_property(int fd,
			      const struct drm_mode_get_property *prop,
			      uint64_t value, bool atomic)
{
	uint32_t flags = prop->flags;
	uint32_t legacy_type = flags & DRM_MODE_PROP_LEGACY_TYPE;
	uint32_t ext_type = flags & DRM_MODE_PROP_EXTENDED_TYPE;

	igt_assert_eq((flags & ~(DRM_MODE_PROP_LEGACY_TYPE |
				 DRM_MODE_PROP_EXTENDED_TYPE |
				 DRM_MODE_PROP_IMMUTABLE |
				 DRM_MODE_PROP_ATOMIC)), 0);

	igt_assert(atomic ||
		   (flags & DRM_MODE_PROP_ATOMIC) == 0);

	igt_assert_neq(!legacy_type, !ext_type);

	igt_assert(legacy_type == 0 ||
		   is_power_of_two(legacy_type));

	switch (legacy_type) {
	case DRM_MODE_PROP_RANGE:
		validate_range_prop(prop, value);
		break;
	case DRM_MODE_PROP_ENUM:
		validate_enum_prop(prop, value);
		break;
	case DRM_MODE_PROP_BITMASK:
		validate_bitmask_prop(prop, value);
		break;
	case DRM_MODE_PROP_BLOB:
		validate_blob_prop(fd, prop, value);
		break;
	default:
		igt_assert_eq(legacy_type, 0);
	}

	switch (ext_type) {
	case DRM_MODE_PROP_OBJECT:
		validate_object_prop(fd, prop, value);
		break;
	case DRM_MODE_PROP_SIGNED_RANGE:
		validate_range_prop(prop, value);
		break;
	default:
		igt_assert_eq(ext_type, 0);
	}
}

static void validate_prop(int fd, uint32_t prop_id, uint64_t value, bool atomic)
{
	struct drm_mode_get_property prop;
	struct drm_mode_property_enum *enums = NULL;
	uint64_t *values = NULL;

	memset(&prop, 0, sizeof(prop));
	prop.prop_id = prop_id;

	do_ioctl(fd, DRM_IOCTL_MODE_GETPROPERTY, &prop);

	if (prop.count_values) {
		values = calloc(prop.count_values, sizeof(values[0]));
		igt_assert(values);
		memset(values, 0x5c, sizeof(values[0])*prop.count_values);
		prop.values_ptr = to_user_pointer(values);
	}

	if (prop.count_enum_blobs) {
		enums = calloc(prop.count_enum_blobs, sizeof(enums[0]));
		memset(enums, 0x5c, sizeof(enums[0])*prop.count_enum_blobs);
		igt_assert(enums);
		prop.enum_blob_ptr = to_user_pointer(enums);
	}

	do_ioctl(fd, DRM_IOCTL_MODE_GETPROPERTY, &prop);

	for (int i = 0; i < prop.count_values; i++)
		igt_assert_neq_u64(values[i], 0x5c5c5c5c5c5c5c5cULL);

	for (int i = 0; i < prop.count_enum_blobs; i++)
		igt_assert_neq_u64(enums[i].value, 0x5c5c5c5c5c5c5c5cULL);

	validate_property(fd, &prop, value, atomic);

	free(values);
	free(enums);
}

static void validate_props(int fd, uint32_t obj_type, uint32_t obj_id, bool atomic)
{
	struct drm_mode_obj_get_properties properties;
	uint32_t *props = NULL;
	uint64_t *values = NULL;
	uint32_t count;

	memset(&properties, 0, sizeof(properties));
	properties.obj_type = obj_type;
	properties.obj_id = obj_id;

	do_ioctl(fd, DRM_IOCTL_MODE_OBJ_GETPROPERTIES, &properties);

	count = properties.count_props;

	if (count) {
		props = calloc(count, sizeof(props[0]));
		memset(props, 0x5c, sizeof(props[0])*count);
		igt_assert(props);
		properties.props_ptr = to_user_pointer(props);

		values = calloc(count, sizeof(values[0]));
		memset(values, 0x5c, sizeof(values[0])*count);
		igt_assert(values);
		properties.prop_values_ptr = to_user_pointer(values);
	}

	do_ioctl(fd, DRM_IOCTL_MODE_OBJ_GETPROPERTIES, &properties);

	igt_assert(properties.count_props == count);

	for (int i = 0; i < count; i++)
		validate_prop(fd, props[i], values[i], atomic);

	free(values);
	free(props);
}

static void expect_no_props(int fd, uint32_t obj_type, uint32_t obj_id)
{
	struct drm_mode_obj_get_properties properties;

	memset(&properties, 0, sizeof(properties));
	properties.obj_type = obj_type;
	properties.obj_id = obj_id;

	igt_assert_neq(drmIoctl(fd, DRM_IOCTL_MODE_OBJ_GETPROPERTIES, &properties), 0);
}

static void get_prop_sanity(igt_display_t *display, bool atomic)
{
	int fd = display->drm_fd;
	drmModePlaneResPtr plane_res;
	drmModeResPtr res;

	res = drmModeGetResources(fd);
	plane_res = drmModeGetPlaneResources(fd);

	for (int i = 0; i < plane_res->count_planes; i++) {
		validate_props(fd, DRM_MODE_OBJECT_PLANE,
			       plane_res->planes[i], atomic);
	}

	for (int i = 0; i < res->count_crtcs; i++) {
		validate_props(fd, DRM_MODE_OBJECT_CRTC,
			       res->crtcs[i], atomic);
	}

	for (int i = 0; i < res->count_connectors; i++) {
		validate_props(fd, DRM_MODE_OBJECT_CONNECTOR,
			       res->connectors[i], atomic);
	}

	for (int i = 0; i < res->count_encoders; i++) {
		expect_no_props(fd, DRM_MODE_OBJECT_ENCODER,
				res->encoders[i]);
	}

	drmModeFreePlaneResources(plane_res);
	drmModeFreeResources(res);
}

705 706 707 708 709 710 711
static void invalid_properties(igt_display_t *display, bool atomic)
{
	igt_output_t *output;
	igt_plane_t *plane;
	enum pipe pipe;
	int i;

712 713 714
	if (atomic)
		igt_skip_on(!display->is_atomic);

715 716 717 718 719 720 721 722 723 724 725
	for_each_pipe(display, pipe)
		test_object_invalid_properties(display, display->pipes[pipe].crtc_id, DRM_MODE_OBJECT_CRTC, atomic);

	for_each_pipe(display, pipe)
		for_each_plane_on_pipe(display, pipe, plane)
			test_object_invalid_properties(display, plane->drm_plane->plane_id, DRM_MODE_OBJECT_PLANE, atomic);

	for (i = 0, output = &display->outputs[0]; i < display->n_outputs; output = &display->outputs[++i])
		test_object_invalid_properties(display, output->id, DRM_MODE_OBJECT_CONNECTOR, atomic);
}

726 727 728 729 730 731 732 733 734 735 736
igt_main
{
	igt_display_t display;

	igt_skip_on_simulation();

	igt_fixture {
		display.drm_fd = drm_open_driver_master(DRIVER_ANY);

		kmstest_set_vt_graphics_mode();

737
		igt_display_require(&display, display.drm_fd);
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757
	}

	igt_subtest("plane-properties-legacy")
		plane_properties(&display, false);

	igt_subtest("plane-properties-atomic")
		plane_properties(&display, true);

	igt_subtest("crtc-properties-legacy")
		crtc_properties(&display, false);

	igt_subtest("crtc-properties-atomic")
		crtc_properties(&display, true);

	igt_subtest("connector-properties-legacy")
		connector_properties(&display, false);

	igt_subtest("connector-properties-atomic")
		connector_properties(&display, true);

758 759 760 761 762 763
	igt_subtest("invalid-properties-legacy")
		invalid_properties(&display, false);

	igt_subtest("invalid-properties-atomic")
		invalid_properties(&display, true);

764 765 766 767 768 769 770 771 772 773 774 775 776 777
	igt_subtest("get_properties-sanity-atomic") {
		igt_skip_on(!display.is_atomic);
		get_prop_sanity(&display, true);
	}

	igt_subtest("get_properties-sanity-non-atomic") {
		if (display.is_atomic)
			igt_assert_eq(drmSetClientCap(display.drm_fd, DRM_CLIENT_CAP_ATOMIC, 0), 0);

		get_prop_sanity(&display, false);

		if (display.is_atomic)
			igt_assert_eq(drmSetClientCap(display.drm_fd, DRM_CLIENT_CAP_ATOMIC, 1), 0);
	}
778

779 780 781 782
	igt_fixture {
		igt_display_fini(&display);
	}
}