2 * Copyright © 2013 Intel Corporation
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:
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
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
24 * Paulo Zanoni <paulo.r.zanoni@intel.com>
36 #include <sys/ioctl.h>
38 #include <sys/types.h>
40 #include <linux/i2c.h>
41 #include <linux/i2c-dev.h>
46 #include "intel_batchbuffer.h"
48 #include "intel_chipset.h"
49 #include "ioctl_wrappers.h"
52 #include "igt_debugfs.h"
54 /* One day, this will be on your libdrm. */
55 #define DRM_CLIENT_CAP_UNIVERSAL_PLANES 2
57 #define MSR_PC8_RES 0x630
58 #define MSR_PC9_RES 0x631
59 #define MSR_PC10_RES 0x632
61 #define MAX_CONNECTORS 32
62 #define MAX_ENCODERS 32
65 #define POWER_DIR "/sys/devices/pci0000:00/0000:00:02.0/power"
87 #define WAIT_PC8_RES 2
91 int drm_fd, msr_fd, pm_status_fd, pc8_status_fd;
92 bool has_runtime_pm, has_pc8;
93 struct mode_set_data ms_data;
95 /* Stuff used when creating FBs and mode setting. */
96 struct mode_set_data {
98 drmModeConnectorPtr connectors[MAX_CONNECTORS];
99 drmModePropertyBlobPtr edids[MAX_CONNECTORS];
104 /* Stuff we query at different times so we can compare. */
105 struct compare_data {
107 drmModeEncoderPtr encoders[MAX_ENCODERS];
108 drmModeConnectorPtr connectors[MAX_CONNECTORS];
109 drmModeCrtcPtr crtcs[MAX_CRTCS];
110 drmModePropertyBlobPtr edids[MAX_CONNECTORS];
113 struct modeset_params {
115 uint32_t connector_id;
117 drmModeModeInfoPtr mode;
120 struct modeset_params lpsp_mode_params;
121 struct modeset_params non_lpsp_mode_params;
122 struct modeset_params *default_mode_params;
124 /* If the read fails, then the machine doesn't support PC8+ residencies. */
125 static bool supports_pc8_plus_residencies(void)
130 rc = pread(msr_fd, &val, sizeof(uint64_t), MSR_PC8_RES);
131 if (rc != sizeof(val))
133 rc = pread(msr_fd, &val, sizeof(uint64_t), MSR_PC9_RES);
134 if (rc != sizeof(val))
136 rc = pread(msr_fd, &val, sizeof(uint64_t), MSR_PC10_RES);
137 if (rc != sizeof(val))
143 static uint64_t get_residency(uint32_t type)
148 rc = pread(msr_fd, &ret, sizeof(uint64_t), type);
149 igt_assert(rc == sizeof(ret));
154 static bool pc8_plus_residency_changed(unsigned int timeout_sec)
157 uint64_t res_pc8, res_pc9, res_pc10;
158 int to_sleep = 100 * 1000;
160 res_pc8 = get_residency(MSR_PC8_RES);
161 res_pc9 = get_residency(MSR_PC9_RES);
162 res_pc10 = get_residency(MSR_PC10_RES);
164 for (i = 0; i < timeout_sec * 1000 * 1000; i += to_sleep) {
165 if (res_pc8 != get_residency(MSR_PC8_RES) ||
166 res_pc9 != get_residency(MSR_PC9_RES) ||
167 res_pc10 != get_residency(MSR_PC10_RES)) {
176 static enum pc8_status get_pc8_status(void)
179 char buf[150]; /* The whole file has less than 100 chars. */
181 lseek(pc8_status_fd, 0, SEEK_SET);
182 n_read = read(pc8_status_fd, buf, ARRAY_SIZE(buf));
183 igt_assert(n_read >= 0);
186 if (strstr(buf, "\nEnabled: yes\n"))
192 static bool wait_for_pc8_status(enum pc8_status status)
195 int hundred_ms = 100 * 1000, ten_s = 10 * 1000 * 1000;
197 for (i = 0; i < ten_s; i += hundred_ms) {
198 if (get_pc8_status() == status)
207 static bool wait_for_suspended(void)
209 if (has_pc8 && !has_runtime_pm)
210 return wait_for_pc8_status(PC8_ENABLED);
212 return igt_wait_for_pm_status(IGT_RUNTIME_PM_STATUS_SUSPENDED);
215 static bool wait_for_active(void)
217 if (has_pc8 && !has_runtime_pm)
218 return wait_for_pc8_status(PC8_DISABLED);
220 return igt_wait_for_pm_status(IGT_RUNTIME_PM_STATUS_ACTIVE);
223 static void disable_all_screens_dpms(struct mode_set_data *data)
227 for (i = 0; i < data->res->count_connectors; i++) {
228 drmModeConnectorPtr c = data->connectors[i];
230 kmstest_set_connector_dpms(drm_fd, c, DRM_MODE_DPMS_OFF);
234 static void disable_all_screens(struct mode_set_data *data)
236 kmstest_unset_all_crtcs(drm_fd, data->res);
239 #define disable_all_screens_and_wait(data) do { \
240 disable_all_screens(data); \
241 igt_assert(wait_for_suspended()); \
244 static void disable_or_dpms_all_screens(struct mode_set_data *data, bool dpms)
247 disable_all_screens_dpms(&ms_data);
249 disable_all_screens(&ms_data);
252 #define disable_or_dpms_all_screens_and_wait(data, dpms) do { \
253 disable_or_dpms_all_screens((data), (dpms)); \
254 igt_assert(wait_for_suspended()); \
257 static bool init_modeset_params_for_type(struct mode_set_data *data,
258 struct modeset_params *params,
259 enum screen_type type)
262 uint32_t connector_id = 0;
263 drmModeModeInfoPtr mode = NULL;
266 for (i = 0; i < data->res->count_connectors; i++) {
267 drmModeConnectorPtr c = data->connectors[i];
269 if (type == SCREEN_TYPE_LPSP &&
270 c->connector_type != DRM_MODE_CONNECTOR_eDP)
273 if (type == SCREEN_TYPE_NON_LPSP &&
274 c->connector_type == DRM_MODE_CONNECTOR_eDP)
277 if (c->connection == DRM_MODE_CONNECTED && c->count_modes) {
278 connector_id = c->connector_id;
287 igt_create_fb(drm_fd, mode->hdisplay, mode->vdisplay,
288 DRM_FORMAT_XRGB8888, false, ¶ms->fb);
289 cr = igt_get_cairo_ctx(drm_fd, ¶ms->fb);
290 igt_paint_test_pattern(cr, mode->hdisplay, mode->vdisplay);
293 params->crtc_id = data->res->crtcs[0];
294 params->connector_id = connector_id;
300 static void init_modeset_cached_params(struct mode_set_data *data)
304 lpsp = init_modeset_params_for_type(data, &lpsp_mode_params,
306 non_lpsp = init_modeset_params_for_type(data, &non_lpsp_mode_params,
307 SCREEN_TYPE_NON_LPSP);
310 default_mode_params = &lpsp_mode_params;
312 default_mode_params = &non_lpsp_mode_params;
314 default_mode_params = NULL;
317 static bool set_mode_for_params(struct modeset_params *params)
321 rc = drmModeSetCrtc(drm_fd, params->crtc_id, params->fb.fb_id, 0, 0,
322 ¶ms->connector_id, 1, params->mode);
326 #define set_mode_for_params_and_wait(params) do { \
327 igt_assert(set_mode_for_params(params)); \
328 igt_assert(wait_for_active()); \
331 static bool enable_one_screen_with_type(struct mode_set_data *data,
332 enum screen_type type)
334 struct modeset_params *params = NULL;
337 case SCREEN_TYPE_ANY:
338 params = default_mode_params;
340 case SCREEN_TYPE_LPSP:
341 params = &lpsp_mode_params;
343 case SCREEN_TYPE_NON_LPSP:
344 params = &non_lpsp_mode_params;
353 return set_mode_for_params(params);
356 static void enable_one_screen(struct mode_set_data *data)
358 /* SKIP if there are no connected screens. */
359 igt_require(enable_one_screen_with_type(data, SCREEN_TYPE_ANY));
362 #define enable_one_screen_and_wait(data) do { \
363 enable_one_screen(data); \
364 igt_assert(wait_for_active()); \
367 static drmModePropertyBlobPtr get_connector_edid(drmModeConnectorPtr connector,
372 drmModePropertyPtr prop;
373 drmModePropertyBlobPtr blob = NULL;
375 found = kmstest_get_property(drm_fd, connector->connector_id,
376 DRM_MODE_OBJECT_CONNECTOR, "EDID",
377 NULL, &prop_value, &prop);
380 igt_assert(prop->flags & DRM_MODE_PROP_BLOB);
381 igt_assert(prop->count_blobs == 0);
383 blob = drmModeGetPropertyBlob(drm_fd, prop_value);
385 drmModeFreeProperty(prop);
391 static void init_mode_set_data(struct mode_set_data *data)
395 data->res = drmModeGetResources(drm_fd);
396 igt_assert(data->res);
397 igt_assert(data->res->count_connectors <= MAX_CONNECTORS);
399 for (i = 0; i < data->res->count_connectors; i++) {
400 data->connectors[i] = drmModeGetConnector(drm_fd,
401 data->res->connectors[i]);
402 data->edids[i] = get_connector_edid(data->connectors[i], i);
405 data->devid = intel_get_drm_devid(drm_fd);
407 igt_set_vt_graphics_mode();
409 init_modeset_cached_params(&ms_data);
412 static void fini_mode_set_data(struct mode_set_data *data)
416 for (i = 0; i < data->res->count_connectors; i++) {
417 drmModeFreeConnector(data->connectors[i]);
418 drmModeFreePropertyBlob(data->edids[i]);
420 drmModeFreeResources(data->res);
423 static void get_drm_info(struct compare_data *data)
427 data->res = drmModeGetResources(drm_fd);
428 igt_assert(data->res);
430 igt_assert(data->res->count_connectors <= MAX_CONNECTORS);
431 igt_assert(data->res->count_encoders <= MAX_ENCODERS);
432 igt_assert(data->res->count_crtcs <= MAX_CRTCS);
434 for (i = 0; i < data->res->count_connectors; i++) {
435 data->connectors[i] = drmModeGetConnector(drm_fd,
436 data->res->connectors[i]);
437 data->edids[i] = get_connector_edid(data->connectors[i], i);
439 for (i = 0; i < data->res->count_encoders; i++)
440 data->encoders[i] = drmModeGetEncoder(drm_fd,
441 data->res->encoders[i]);
442 for (i = 0; i < data->res->count_crtcs; i++)
443 data->crtcs[i] = drmModeGetCrtc(drm_fd, data->res->crtcs[i]);
446 static void free_drm_info(struct compare_data *data)
450 for (i = 0; i < data->res->count_connectors; i++) {
451 drmModeFreeConnector(data->connectors[i]);
452 drmModeFreePropertyBlob(data->edids[i]);
454 for (i = 0; i < data->res->count_encoders; i++)
455 drmModeFreeEncoder(data->encoders[i]);
456 for (i = 0; i < data->res->count_crtcs; i++)
457 drmModeFreeCrtc(data->crtcs[i]);
459 drmModeFreeResources(data->res);
462 #define COMPARE(d1, d2, data) igt_assert(d1->data == d2->data)
463 #define COMPARE_ARRAY(d1, d2, size, data) do { \
464 for (i = 0; i < size; i++) \
465 igt_assert(d1->data[i] == d2->data[i]); \
468 static void assert_drm_resources_equal(struct compare_data *d1,
469 struct compare_data *d2)
471 COMPARE(d1, d2, res->count_connectors);
472 COMPARE(d1, d2, res->count_encoders);
473 COMPARE(d1, d2, res->count_crtcs);
474 COMPARE(d1, d2, res->min_width);
475 COMPARE(d1, d2, res->max_width);
476 COMPARE(d1, d2, res->min_height);
477 COMPARE(d1, d2, res->max_height);
480 static void assert_modes_equal(drmModeModeInfoPtr m1, drmModeModeInfoPtr m2)
482 COMPARE(m1, m2, clock);
483 COMPARE(m1, m2, hdisplay);
484 COMPARE(m1, m2, hsync_start);
485 COMPARE(m1, m2, hsync_end);
486 COMPARE(m1, m2, htotal);
487 COMPARE(m1, m2, hskew);
488 COMPARE(m1, m2, vdisplay);
489 COMPARE(m1, m2, vsync_start);
490 COMPARE(m1, m2, vsync_end);
491 COMPARE(m1, m2, vtotal);
492 COMPARE(m1, m2, vscan);
493 COMPARE(m1, m2, vrefresh);
494 COMPARE(m1, m2, flags);
495 COMPARE(m1, m2, type);
496 igt_assert(strcmp(m1->name, m2->name) == 0);
499 static void assert_drm_connectors_equal(drmModeConnectorPtr c1,
500 drmModeConnectorPtr c2)
504 COMPARE(c1, c2, connector_id);
505 COMPARE(c1, c2, connector_type);
506 COMPARE(c1, c2, connector_type_id);
507 COMPARE(c1, c2, mmWidth);
508 COMPARE(c1, c2, mmHeight);
509 COMPARE(c1, c2, count_modes);
510 COMPARE(c1, c2, count_props);
511 COMPARE(c1, c2, count_encoders);
512 COMPARE_ARRAY(c1, c2, c1->count_props, props);
513 COMPARE_ARRAY(c1, c2, c1->count_encoders, encoders);
515 for (i = 0; i < c1->count_modes; i++)
516 assert_modes_equal(&c1->modes[0], &c2->modes[0]);
519 static void assert_drm_encoders_equal(drmModeEncoderPtr e1,
520 drmModeEncoderPtr e2)
522 COMPARE(e1, e2, encoder_id);
523 COMPARE(e1, e2, encoder_type);
524 COMPARE(e1, e2, possible_crtcs);
525 COMPARE(e1, e2, possible_clones);
528 static void assert_drm_crtcs_equal(drmModeCrtcPtr c1, drmModeCrtcPtr c2)
530 COMPARE(c1, c2, crtc_id);
533 static void assert_drm_edids_equal(drmModePropertyBlobPtr e1,
534 drmModePropertyBlobPtr e2)
538 igt_assert(e1 && e2);
541 COMPARE(e1, e2, length);
543 igt_assert(memcmp(e1->data, e2->data, e1->length) == 0);
546 static void assert_drm_infos_equal(struct compare_data *d1,
547 struct compare_data *d2)
551 assert_drm_resources_equal(d1, d2);
553 for (i = 0; i < d1->res->count_connectors; i++) {
554 assert_drm_connectors_equal(d1->connectors[i],
556 assert_drm_edids_equal(d1->edids[i], d2->edids[i]);
559 for (i = 0; i < d1->res->count_encoders; i++)
560 assert_drm_encoders_equal(d1->encoders[i], d2->encoders[i]);
562 for (i = 0; i < d1->res->count_crtcs; i++)
563 assert_drm_crtcs_equal(d1->crtcs[i], d2->crtcs[i]);
566 /* We could check the checksum too, but just the header is probably enough. */
567 static bool edid_is_valid(const unsigned char *edid)
569 char edid_header[] = {
570 0x0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0,
573 return (memcmp(edid, edid_header, sizeof(edid_header)) == 0);
576 static int count_drm_valid_edids(struct mode_set_data *data)
580 for (i = 0; i < data->res->count_connectors; i++)
581 if (data->edids[i] && edid_is_valid(data->edids[i]->data))
586 static bool i2c_edid_is_valid(int fd)
589 unsigned char edid[128] = {};
590 struct i2c_msg msgs[] = {
596 }, { /* Now read the EDID. */
603 struct i2c_rdwr_ioctl_data msgset = {
608 rc = ioctl(fd, I2C_RDWR, &msgset);
609 return (rc >= 0) ? edid_is_valid(edid) : false;
612 static int count_i2c_valid_edids(void)
617 struct dirent *dirent;
620 dir = opendir("/dev/");
623 while ((dirent = readdir(dir))) {
624 if (strncmp(dirent->d_name, "i2c-", 4) == 0) {
625 snprintf(full_name, 32, "/dev/%s", dirent->d_name);
626 fd = open(full_name, O_RDWR);
627 igt_assert(fd != -1);
628 if (i2c_edid_is_valid(fd))
639 static void test_i2c(struct mode_set_data *data)
641 int i2c_edids = count_i2c_valid_edids();
642 int drm_edids = count_drm_valid_edids(data);
644 igt_assert_cmpint(i2c_edids, ==, drm_edids);
647 static void setup_pc8(void)
651 /* Only Haswell supports the PC8 feature. */
652 if (!IS_HASWELL(ms_data.devid) && !IS_BROADWELL(ms_data.devid))
655 /* Make sure our Kernel supports MSR and the module is loaded. */
656 igt_assert(system("modprobe -q msr > /dev/null 2>&1") != -1);
658 msr_fd = open("/dev/cpu/0/msr", O_RDONLY);
659 igt_assert_f(msr_fd >= 0,
660 "Can't open /dev/cpu/0/msr.\n");
662 /* Non-ULT machines don't support PC8+. */
663 if (!supports_pc8_plus_residencies())
666 pc8_status_fd = open("/sys/kernel/debug/dri/0/i915_pc8_status",
668 igt_assert_f(pc8_status_fd >= 0,
669 "Can't open /sys/kernel/debug/dri/0/i915_pc8_status");
674 /* If we want to actually reach PC8+ states, we need to properly configure all
675 * the devices on the system to allow this. This function will try to setup the
676 * things we know we need, but won't scream in case anything fails: we don't
677 * know which devices are present on your machine, so we can't really expect
678 * anything, just try to help with the more common problems. */
679 static void setup_non_graphics_runtime_pm(void)
684 /* Disk runtime PM policies. */
685 file_name = malloc(PATH_MAX);
688 snprintf(file_name, PATH_MAX,
689 "/sys/class/scsi_host/host%d/link_power_management_policy",
692 fd = open(file_name, O_WRONLY);
696 write(fd, "min_power\n", 10);
701 /* Audio runtime PM policies. */
702 fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_WRONLY);
707 fd = open("/sys/bus/pci/devices/0000:00:03.0/power/control", O_WRONLY);
709 write(fd, "auto\n", 5);
714 static void setup_environment(void)
716 drm_fd = drm_open_any();
717 igt_assert(drm_fd >= 0);
719 igt_require_f(drmSetMaster(drm_fd) == 0, "Can't become DRM master, "
720 "please check if no other DRM client is running.\n");
722 init_mode_set_data(&ms_data);
724 setup_non_graphics_runtime_pm();
726 has_runtime_pm = igt_setup_runtime_pm();
729 igt_info("Runtime PM support: %d\n", has_runtime_pm);
730 igt_info("PC8 residency support: %d\n", has_pc8);
732 igt_require(has_runtime_pm);
736 static void teardown_environment(void)
738 fini_mode_set_data(&ms_data);
742 close(pc8_status_fd);
745 static void basic_subtest(void)
747 disable_all_screens_and_wait(&ms_data);
749 enable_one_screen_and_wait(&ms_data);
752 static void pc8_residency_subtest(void)
754 igt_require(has_pc8);
756 /* Make sure PC8+ residencies move! */
757 disable_all_screens(&ms_data);
758 igt_assert_f(pc8_plus_residency_changed(120),
759 "Machine is not reaching PC8+ states, please check its "
762 /* Make sure PC8+ residencies stop! */
763 enable_one_screen(&ms_data);
764 igt_assert_f(!pc8_plus_residency_changed(10),
765 "PC8+ residency didn't stop with screen enabled.\n");
768 static void modeset_subtest(enum screen_type type, int rounds, int wait_flags)
772 if (wait_flags & WAIT_PC8_RES)
773 igt_require(has_pc8);
775 for (i = 0; i < rounds; i++) {
776 if (wait_flags & USE_DPMS)
777 disable_all_screens_dpms(&ms_data);
779 disable_all_screens(&ms_data);
781 if (wait_flags & WAIT_STATUS)
782 igt_assert(wait_for_suspended());
783 if (wait_flags & WAIT_PC8_RES)
784 igt_assert(pc8_plus_residency_changed(120));
785 if (wait_flags & WAIT_EXTRA)
788 /* If we skip this line it's because the type of screen we want
789 * is not connected. */
790 igt_require(enable_one_screen_with_type(&ms_data, type));
791 if (wait_flags & WAIT_STATUS)
792 igt_assert(wait_for_active());
793 if (wait_flags & WAIT_PC8_RES)
794 igt_assert(!pc8_plus_residency_changed(5));
795 if (wait_flags & WAIT_EXTRA)
800 /* Test of the DRM resources reported by the IOCTLs are still the same. This
801 * ensures we still see the monitors with the same eyes. We get the EDIDs and
802 * compare them, which ensures we use DP AUX or GMBUS depending on what's
804 static void drm_resources_equal_subtest(void)
806 struct compare_data pre_suspend, during_suspend, post_suspend;
808 enable_one_screen_and_wait(&ms_data);
809 get_drm_info(&pre_suspend);
810 igt_assert(wait_for_active());
812 disable_all_screens_and_wait(&ms_data);
813 get_drm_info(&during_suspend);
814 igt_assert(wait_for_suspended());
816 enable_one_screen_and_wait(&ms_data);
817 get_drm_info(&post_suspend);
818 igt_assert(wait_for_active());
820 assert_drm_infos_equal(&pre_suspend, &during_suspend);
821 assert_drm_infos_equal(&pre_suspend, &post_suspend);
823 free_drm_info(&pre_suspend);
824 free_drm_info(&during_suspend);
825 free_drm_info(&post_suspend);
828 static void i2c_subtest_check_environment(void)
830 int i2c_dev_files = 0;
832 struct dirent *dirent;
834 /* Make sure the /dev/i2c-* files exist. */
835 igt_assert(system("modprobe -q i2c-dev > /dev/null 2>&1") != -1);
837 dev_dir = opendir("/dev");
839 while ((dirent = readdir(dev_dir))) {
840 if (strncmp(dirent->d_name, "i2c-", 4) == 0)
844 igt_require(i2c_dev_files);
847 /* Try to use raw I2C, which also needs interrupts. */
848 static void i2c_subtest(void)
850 i2c_subtest_check_environment();
852 enable_one_screen_and_wait(&ms_data);
854 disable_all_screens_and_wait(&ms_data);
856 igt_assert(wait_for_suspended());
858 enable_one_screen(&ms_data);
861 static void read_full_file(const char *name)
866 igt_assert_f(wait_for_suspended(), "File: %s\n", name);
868 fd = open(name, O_RDONLY);
873 rc = read(fd, buf, ARRAY_SIZE(buf));
874 } while (rc == ARRAY_SIZE(buf));
879 igt_assert_f(wait_for_suspended(), "File: %s\n", name);
882 static void read_files_from_dir(const char *name, int level)
885 struct dirent *dirent;
892 full_name = malloc(PATH_MAX);
894 igt_assert(level < 128);
896 while ((dirent = readdir(dir))) {
897 struct stat stat_buf;
899 if (strcmp(dirent->d_name, ".") == 0)
901 if (strcmp(dirent->d_name, "..") == 0)
904 snprintf(full_name, PATH_MAX, "%s/%s", name, dirent->d_name);
906 rc = lstat(full_name, &stat_buf);
909 if (S_ISDIR(stat_buf.st_mode))
910 read_files_from_dir(full_name, level + 1);
912 if (S_ISREG(stat_buf.st_mode))
913 read_full_file(full_name);
920 /* This test will probably pass, with a small chance of hanging the machine in
921 * case of bugs. Many of the bugs exercised by this patch just result in dmesg
922 * errors, so a "pass" here should be confirmed by a check on dmesg. */
923 static void debugfs_read_subtest(void)
925 const char *path = "/sys/kernel/debug/dri/0";
929 igt_require_f(dir, "Can't open the debugfs directory\n");
932 disable_all_screens_and_wait(&ms_data);
934 read_files_from_dir(path, 0);
937 /* Read the comment on debugfs_read_subtest(). */
938 static void sysfs_read_subtest(void)
940 const char *path = "/sys/devices/pci0000:00/0000:00:02.0";
944 igt_require_f(dir, "Can't open the sysfs directory\n");
947 disable_all_screens_and_wait(&ms_data);
949 read_files_from_dir(path, 0);
952 /* Make sure we don't suspend when we have the i915_forcewake_user file open. */
953 static void debugfs_forcewake_user_subtest(void)
957 igt_require(intel_gen(ms_data.devid) >= 6);
959 disable_all_screens_and_wait(&ms_data);
961 fd = igt_open_forcewake_handle();
962 igt_require(fd >= 0);
964 if (has_runtime_pm) {
965 igt_assert(wait_for_active());
967 igt_assert(wait_for_active());
969 igt_assert(wait_for_suspended());
975 igt_assert(wait_for_suspended());
978 static void gem_mmap_subtest(bool gtt_mmap)
985 /* Create, map and set data while the device is active. */
986 enable_one_screen_and_wait(&ms_data);
988 handle = gem_create(drm_fd, buf_size);
991 gem_buf = gem_mmap__gtt(drm_fd, handle, buf_size,
992 PROT_READ | PROT_WRITE);
994 gem_buf = gem_mmap__cpu(drm_fd, handle, buf_size, 0);
997 for (i = 0; i < buf_size; i++)
998 gem_buf[i] = i & 0xFF;
1000 for (i = 0; i < buf_size; i++)
1001 igt_assert(gem_buf[i] == (i & 0xFF));
1003 /* Now suspend, read and modify. */
1004 disable_all_screens_and_wait(&ms_data);
1006 for (i = 0; i < buf_size; i++)
1007 igt_assert(gem_buf[i] == (i & 0xFF));
1008 igt_assert(wait_for_suspended());
1010 for (i = 0; i < buf_size; i++)
1011 gem_buf[i] = (~i & 0xFF);
1012 igt_assert(wait_for_suspended());
1014 /* Now resume and see if it's still there. */
1015 enable_one_screen_and_wait(&ms_data);
1016 for (i = 0; i < buf_size; i++)
1017 igt_assert(gem_buf[i] == (~i & 0xFF));
1019 igt_assert(munmap(gem_buf, buf_size) == 0);
1021 /* Now the opposite: suspend, and try to create the mmap while
1023 disable_all_screens_and_wait(&ms_data);
1026 gem_buf = gem_mmap__gtt(drm_fd, handle, buf_size,
1027 PROT_READ | PROT_WRITE);
1029 gem_buf = gem_mmap__cpu(drm_fd, handle, buf_size, 0);
1031 igt_assert(wait_for_suspended());
1033 for (i = 0; i < buf_size; i++)
1034 gem_buf[i] = i & 0xFF;
1036 for (i = 0; i < buf_size; i++)
1037 igt_assert(gem_buf[i] == (i & 0xFF));
1039 igt_assert(wait_for_suspended());
1041 /* Resume and check if it's still there. */
1042 enable_one_screen_and_wait(&ms_data);
1043 for (i = 0; i < buf_size; i++)
1044 igt_assert(gem_buf[i] == (i & 0xFF));
1046 igt_assert(munmap(gem_buf, buf_size) == 0);
1047 gem_close(drm_fd, handle);
1050 static void gem_pread_subtest(void)
1054 int buf_size = 8192;
1055 uint8_t *cpu_buf, *read_buf;
1057 cpu_buf = malloc(buf_size);
1058 read_buf = malloc(buf_size);
1059 igt_assert(cpu_buf);
1060 igt_assert(read_buf);
1061 memset(cpu_buf, 0, buf_size);
1062 memset(read_buf, 0, buf_size);
1064 /* Create and set data while the device is active. */
1065 enable_one_screen_and_wait(&ms_data);
1067 handle = gem_create(drm_fd, buf_size);
1069 for (i = 0; i < buf_size; i++)
1070 cpu_buf[i] = i & 0xFF;
1072 gem_write(drm_fd, handle, 0, cpu_buf, buf_size);
1074 gem_read(drm_fd, handle, 0, read_buf, buf_size);
1076 for (i = 0; i < buf_size; i++)
1077 igt_assert(cpu_buf[i] == read_buf[i]);
1079 /* Now suspend, read and modify. */
1080 disable_all_screens_and_wait(&ms_data);
1082 memset(read_buf, 0, buf_size);
1083 gem_read(drm_fd, handle, 0, read_buf, buf_size);
1085 for (i = 0; i < buf_size; i++)
1086 igt_assert(cpu_buf[i] == read_buf[i]);
1087 igt_assert(wait_for_suspended());
1089 for (i = 0; i < buf_size; i++)
1090 cpu_buf[i] = (~i & 0xFF);
1091 gem_write(drm_fd, handle, 0, cpu_buf, buf_size);
1092 igt_assert(wait_for_suspended());
1094 /* Now resume and see if it's still there. */
1095 enable_one_screen_and_wait(&ms_data);
1097 memset(read_buf, 0, buf_size);
1098 gem_read(drm_fd, handle, 0, read_buf, buf_size);
1100 for (i = 0; i < buf_size; i++)
1101 igt_assert(cpu_buf[i] == read_buf[i]);
1103 gem_close(drm_fd, handle);
1109 /* Paints a square of color $color, size $width x $height, at position $x x $y
1110 * of $dst_handle, which contains pitch $pitch. */
1111 static void submit_blt_cmd(uint32_t dst_handle, uint16_t x, uint16_t y,
1112 uint16_t width, uint16_t height, uint32_t pitch,
1113 uint32_t color, uint32_t *presumed_dst_offset)
1116 uint32_t batch_handle;
1117 int batch_size = 8 * sizeof(uint32_t);
1118 uint32_t batch_buf[batch_size];
1119 struct drm_i915_gem_execbuffer2 execbuf = {};
1120 struct drm_i915_gem_exec_object2 objs[2] = {{}, {}};
1121 struct drm_i915_gem_relocation_entry relocs[1] = {{}};
1122 struct drm_i915_gem_wait gem_wait;
1126 if (intel_gen(ms_data.devid) >= 8)
1127 batch_buf[i++] = XY_COLOR_BLT_CMD_NOLEN |
1128 XY_COLOR_BLT_WRITE_ALPHA |
1129 XY_COLOR_BLT_WRITE_RGB | 0x5;
1131 batch_buf[i++] = XY_COLOR_BLT_CMD_NOLEN |
1132 XY_COLOR_BLT_WRITE_ALPHA |
1133 XY_COLOR_BLT_WRITE_RGB | 0x4;
1134 batch_buf[i++] = (3 << 24) | (0xF0 << 16) | (pitch);
1135 batch_buf[i++] = (y << 16) | x;
1136 batch_buf[i++] = ((y + height) << 16) | (x + width);
1138 batch_buf[i++] = *presumed_dst_offset;
1139 if (intel_gen(ms_data.devid) >= 8)
1141 batch_buf[i++] = color;
1143 batch_buf[i++] = MI_BATCH_BUFFER_END;
1144 if (intel_gen(ms_data.devid) < 8)
1145 batch_buf[i++] = MI_NOOP;
1147 igt_assert(i * sizeof(uint32_t) == batch_size);
1149 batch_handle = gem_create(drm_fd, batch_size);
1150 gem_write(drm_fd, batch_handle, 0, batch_buf, batch_size);
1152 relocs[0].target_handle = dst_handle;
1153 relocs[0].delta = 0;
1154 relocs[0].offset = reloc_pos * sizeof(uint32_t);
1155 relocs[0].presumed_offset = *presumed_dst_offset;
1156 relocs[0].read_domains = 0;
1157 relocs[0].write_domain = I915_GEM_DOMAIN_RENDER;
1159 objs[0].handle = dst_handle;
1160 objs[0].alignment = 64;
1162 objs[1].handle = batch_handle;
1163 objs[1].relocation_count = 1;
1164 objs[1].relocs_ptr = (uintptr_t)relocs;
1166 execbuf.buffers_ptr = (uintptr_t)objs;
1167 execbuf.buffer_count = 2;
1168 execbuf.batch_len = batch_size;
1169 execbuf.flags = I915_EXEC_BLT;
1170 i915_execbuffer2_set_context_id(execbuf, 0);
1172 do_ioctl(drm_fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf);
1174 *presumed_dst_offset = relocs[0].presumed_offset;
1177 gem_wait.timeout_ns = 10000000000LL; /* 10s */
1179 gem_wait.bo_handle = batch_handle;
1180 do_ioctl(drm_fd, DRM_IOCTL_I915_GEM_WAIT, &gem_wait);
1182 gem_wait.bo_handle = dst_handle;
1183 do_ioctl(drm_fd, DRM_IOCTL_I915_GEM_WAIT, &gem_wait);
1185 gem_close(drm_fd, batch_handle);
1188 /* Make sure we can submit a batch buffer and verify its result. */
1189 static void gem_execbuf_subtest(void)
1194 int pitch = 128 * bpp;
1195 int dst_size = 128 * 128 * bpp; /* 128x128 square */
1197 uint32_t presumed_offset = 0;
1198 int sq_x = 5, sq_y = 10, sq_w = 15, sq_h = 20;
1201 /* Create and set data while the device is active. */
1202 enable_one_screen_and_wait(&ms_data);
1204 handle = gem_create(drm_fd, dst_size);
1206 cpu_buf = malloc(dst_size);
1207 igt_assert(cpu_buf);
1208 memset(cpu_buf, 0, dst_size);
1209 gem_write(drm_fd, handle, 0, cpu_buf, dst_size);
1211 /* Now suspend and try it. */
1212 disable_all_screens_and_wait(&ms_data);
1215 submit_blt_cmd(handle, sq_x, sq_y, sq_w, sq_h, pitch, color,
1217 igt_assert(wait_for_suspended());
1219 gem_read(drm_fd, handle, 0, cpu_buf, dst_size);
1220 igt_assert(wait_for_suspended());
1221 for (y = 0; y < 128; y++) {
1222 for (x = 0; x < 128; x++) {
1223 uint32_t px = cpu_buf[y * 128 + x];
1225 if (y >= sq_y && y < (sq_y + sq_h) &&
1226 x >= sq_x && x < (sq_x + sq_w))
1227 igt_assert(px == color);
1229 igt_assert(px == 0);
1233 /* Now resume and check for it again. */
1234 enable_one_screen_and_wait(&ms_data);
1236 memset(cpu_buf, 0, dst_size);
1237 gem_read(drm_fd, handle, 0, cpu_buf, dst_size);
1238 for (y = 0; y < 128; y++) {
1239 for (x = 0; x < 128; x++) {
1240 uint32_t px = cpu_buf[y * 128 + x];
1242 if (y >= sq_y && y < (sq_y + sq_h) &&
1243 x >= sq_x && x < (sq_x + sq_w))
1244 igt_assert(px == color);
1246 igt_assert(px == 0);
1250 /* Now we'll do the opposite: do the blt while active, then read while
1251 * suspended. We use the same spot, but a different color. As a bonus,
1252 * we're testing the presumed_offset from the previous command. */
1254 submit_blt_cmd(handle, sq_x, sq_y, sq_w, sq_h, pitch, color,
1257 disable_all_screens_and_wait(&ms_data);
1259 memset(cpu_buf, 0, dst_size);
1260 gem_read(drm_fd, handle, 0, cpu_buf, dst_size);
1261 for (y = 0; y < 128; y++) {
1262 for (x = 0; x < 128; x++) {
1263 uint32_t px = cpu_buf[y * 128 + x];
1265 if (y >= sq_y && y < (sq_y + sq_h) &&
1266 x >= sq_x && x < (sq_x + sq_w))
1267 igt_assert(px == color);
1269 igt_assert(px == 0);
1273 gem_close(drm_fd, handle);
1278 /* Assuming execbuf already works, let's see what happens when we force many
1279 * suspend/resume cycles with commands. */
1280 static void gem_execbuf_stress_subtest(int rounds, int wait_flags)
1283 int batch_size = 4 * sizeof(uint32_t);
1284 uint32_t batch_buf[batch_size];
1286 struct drm_i915_gem_execbuffer2 execbuf = {};
1287 struct drm_i915_gem_exec_object2 objs[1] = {{}};
1289 if (wait_flags & WAIT_PC8_RES)
1290 igt_require(has_pc8);
1293 batch_buf[i++] = MI_NOOP;
1294 batch_buf[i++] = MI_NOOP;
1295 batch_buf[i++] = MI_BATCH_BUFFER_END;
1296 batch_buf[i++] = MI_NOOP;
1297 igt_assert(i * sizeof(uint32_t) == batch_size);
1299 disable_all_screens_and_wait(&ms_data);
1301 handle = gem_create(drm_fd, batch_size);
1302 gem_write(drm_fd, handle, 0, batch_buf, batch_size);
1304 objs[0].handle = handle;
1306 execbuf.buffers_ptr = (uintptr_t)objs;
1307 execbuf.buffer_count = 1;
1308 execbuf.batch_len = batch_size;
1309 execbuf.flags = I915_EXEC_RENDER;
1310 i915_execbuffer2_set_context_id(execbuf, 0);
1312 for (i = 0; i < rounds; i++) {
1313 do_ioctl(drm_fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf);
1315 if (wait_flags & WAIT_STATUS)
1316 igt_assert(wait_for_suspended());
1317 if (wait_flags & WAIT_PC8_RES)
1318 igt_assert(pc8_plus_residency_changed(120));
1319 if (wait_flags & WAIT_EXTRA)
1323 gem_close(drm_fd, handle);
1326 /* When this test was written, it triggered WARNs and DRM_ERRORs on dmesg. */
1327 static void gem_idle_subtest(void)
1329 disable_all_screens_and_wait(&ms_data);
1333 gem_quiescent_gpu(drm_fd);
1336 /* This also triggered WARNs on dmesg at some point. */
1337 static void reg_read_ioctl_subtest(void)
1339 struct drm_i915_reg_read rr = {
1340 .offset = 0x2358, /* render ring timestamp */
1343 disable_all_screens_and_wait(&ms_data);
1345 do_ioctl(drm_fd, DRM_IOCTL_I915_REG_READ, &rr);
1347 igt_assert(wait_for_suspended());
1350 static bool device_in_pci_d3(void)
1352 struct pci_device *pci_dev;
1356 pci_dev = intel_get_pci_device();
1358 rc = pci_device_cfg_read_u16(pci_dev, &val, 0xd4);
1359 igt_assert(rc == 0);
1361 return (val & 0x3) == 0x3;
1364 static void pci_d3_state_subtest(void)
1366 igt_require(has_runtime_pm);
1368 disable_all_screens_and_wait(&ms_data);
1370 igt_assert(device_in_pci_d3());
1372 enable_one_screen_and_wait(&ms_data);
1374 igt_assert(!device_in_pci_d3());
1377 static void stay_subtest(void)
1379 disable_all_screens_and_wait(&ms_data);
1385 static void system_suspend_subtest(void)
1387 disable_all_screens_and_wait(&ms_data);
1388 igt_system_suspend_autoresume();
1389 igt_assert(wait_for_suspended());
1392 /* Enable a screen, activate DPMS, then do a modeset. At some point our driver
1393 * produced WARNs on this case. */
1394 static void dpms_mode_unset_subtest(enum screen_type type)
1396 disable_all_screens_and_wait(&ms_data);
1398 igt_require(enable_one_screen_with_type(&ms_data, type));
1399 igt_assert(wait_for_active());
1401 disable_all_screens_dpms(&ms_data);
1402 igt_assert(wait_for_suspended());
1404 disable_all_screens_and_wait(&ms_data);
1407 static void fill_igt_fb(struct igt_fb *fb, uint32_t color)
1412 ptr = gem_mmap__gtt(drm_fd, fb->gem_handle, fb->size, PROT_WRITE);
1413 for (i = 0; i < fb->size/sizeof(uint32_t); i++)
1415 igt_assert(munmap(ptr, fb->size) == 0);
1418 /* At some point, this test triggered WARNs in the Kernel. */
1419 static void cursor_subtest(bool dpms)
1422 struct igt_fb cursor_fb1, cursor_fb2, cursor_fb3;
1425 disable_all_screens_and_wait(&ms_data);
1427 igt_require(default_mode_params);
1428 crtc_id = default_mode_params->crtc_id;
1430 igt_create_fb(drm_fd, 64, 64, DRM_FORMAT_ARGB8888, false, &cursor_fb1);
1431 igt_create_fb(drm_fd, 64, 64, DRM_FORMAT_ARGB8888, false, &cursor_fb2);
1432 igt_create_fb(drm_fd, 64, 64, DRM_FORMAT_ARGB8888, true, &cursor_fb3);
1434 fill_igt_fb(&cursor_fb1, 0xFF00FFFF);
1435 fill_igt_fb(&cursor_fb2, 0xFF00FF00);
1436 fill_igt_fb(&cursor_fb3, 0xFFFF0000);
1438 set_mode_for_params_and_wait(default_mode_params);
1440 rc = drmModeSetCursor(drm_fd, crtc_id, cursor_fb1.gem_handle,
1441 cursor_fb1.width, cursor_fb1.height);
1442 igt_assert(rc == 0);
1443 rc = drmModeMoveCursor(drm_fd, crtc_id, 0, 0);
1444 igt_assert(rc == 0);
1445 igt_assert(wait_for_active());
1447 disable_or_dpms_all_screens_and_wait(&ms_data, dpms);
1449 /* First, just move the cursor. */
1450 rc = drmModeMoveCursor(drm_fd, crtc_id, 1, 1);
1451 igt_assert(rc == 0);
1452 igt_assert(wait_for_suspended());
1454 /* Then unset it, and set a new one. */
1455 rc = drmModeSetCursor(drm_fd, crtc_id, 0, 0, 0);
1456 igt_assert(rc == 0);
1457 igt_assert(wait_for_suspended());
1459 rc = drmModeSetCursor(drm_fd, crtc_id, cursor_fb2.gem_handle,
1460 cursor_fb1.width, cursor_fb2.height);
1461 igt_assert(rc == 0);
1462 igt_assert(wait_for_suspended());
1464 /* Move the new cursor. */
1465 rc = drmModeMoveCursor(drm_fd, crtc_id, 2, 2);
1466 igt_assert(rc == 0);
1467 igt_assert(wait_for_suspended());
1469 /* Now set a new one without unsetting the previous one. */
1470 rc = drmModeSetCursor(drm_fd, crtc_id, cursor_fb1.gem_handle,
1471 cursor_fb1.width, cursor_fb1.height);
1472 igt_assert(rc == 0);
1473 igt_assert(wait_for_suspended());
1475 /* Cursor 3 was created with tiling and painted with a GTT mmap, so
1476 * hopefully it has some fences around it. */
1477 rc = drmModeRmFB(drm_fd, cursor_fb3.fb_id);
1478 igt_assert(rc == 0);
1479 gem_set_tiling(drm_fd, cursor_fb3.gem_handle, false, cursor_fb3.stride);
1480 igt_assert(wait_for_suspended());
1482 rc = drmModeSetCursor(drm_fd, crtc_id, cursor_fb3.gem_handle,
1483 cursor_fb3.width, cursor_fb3.height);
1484 igt_assert(rc == 0);
1485 igt_assert(wait_for_suspended());
1487 /* Make sure nothing remains for the other tests. */
1488 rc = drmModeSetCursor(drm_fd, crtc_id, 0, 0, 0);
1489 igt_assert(rc == 0);
1490 igt_assert(wait_for_suspended());
1493 static enum plane_type get_plane_type(uint32_t plane_id)
1497 uint64_t prop_value;
1498 drmModePropertyPtr prop;
1499 const char *enum_name = NULL;
1500 enum plane_type type;
1502 found = kmstest_get_property(drm_fd, plane_id, DRM_MODE_OBJECT_PLANE,
1503 "type", NULL, &prop_value, &prop);
1506 igt_assert(prop->flags & DRM_MODE_PROP_ENUM);
1507 igt_assert(prop_value < prop->count_enums);
1509 for (i = 0; i < prop->count_enums; i++) {
1510 if (prop->enums[i].value == prop_value) {
1511 enum_name = prop->enums[i].name;
1515 igt_assert(enum_name);
1517 if (strcmp(enum_name, "Overlay") == 0)
1518 type = PLANE_OVERLAY;
1519 else if (strcmp(enum_name, "Primary") == 0)
1520 type = PLANE_PRIMARY;
1521 else if (strcmp(enum_name, "Cursor") == 0)
1522 type = PLANE_CURSOR;
1526 drmModeFreeProperty(prop);
1531 static void test_one_plane(bool dpms, uint32_t plane_id,
1532 enum plane_type plane_type)
1535 uint32_t plane_format, plane_w, plane_h;
1537 struct igt_fb plane_fb1, plane_fb2;
1538 int32_t crtc_x = 0, crtc_y = 0;
1541 disable_all_screens_and_wait(&ms_data);
1543 igt_require(default_mode_params);
1544 crtc_id = default_mode_params->crtc_id;
1546 switch (plane_type) {
1548 plane_format = DRM_FORMAT_XRGB8888;
1554 plane_format = DRM_FORMAT_XRGB8888;
1555 plane_w = default_mode_params->mode->hdisplay;
1556 plane_h = default_mode_params->mode->vdisplay;
1560 plane_format = DRM_FORMAT_ARGB8888;
1570 igt_create_fb(drm_fd, plane_w, plane_h, plane_format, tiling,
1572 igt_create_fb(drm_fd, plane_w, plane_h, plane_format, tiling,
1574 fill_igt_fb(&plane_fb1, 0xFF00FFFF);
1575 fill_igt_fb(&plane_fb2, 0xFF00FF00);
1577 set_mode_for_params_and_wait(default_mode_params);
1579 rc = drmModeSetPlane(drm_fd, plane_id, crtc_id, plane_fb1.fb_id, 0,
1580 0, 0, plane_fb1.width, plane_fb1.height,
1581 0 << 16, 0 << 16, plane_fb1.width << 16,
1582 plane_fb1.height << 16);
1583 igt_assert(rc == 0);
1585 disable_or_dpms_all_screens_and_wait(&ms_data, dpms);
1587 /* Just move the plane around. */
1588 if (plane_type != PLANE_PRIMARY) {
1592 rc = drmModeSetPlane(drm_fd, plane_id, crtc_id, plane_fb1.fb_id, 0,
1593 crtc_x, crtc_y, plane_fb1.width, plane_fb1.height,
1594 0 << 16, 0 << 16, plane_fb1.width << 16,
1595 plane_fb1.height << 16);
1596 igt_assert(rc == 0);
1597 igt_assert(wait_for_suspended());
1599 /* Unset, then change the plane. */
1600 rc = drmModeSetPlane(drm_fd, plane_id, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1601 igt_assert(rc == 0);
1602 igt_assert(wait_for_suspended());
1604 rc = drmModeSetPlane(drm_fd, plane_id, crtc_id, plane_fb2.fb_id, 0,
1605 crtc_x, crtc_y, plane_fb2.width, plane_fb2.height,
1606 0 << 16, 0 << 16, plane_fb2.width << 16,
1607 plane_fb2.height << 16);
1608 igt_assert(rc == 0);
1609 igt_assert(wait_for_suspended());
1611 /* Now change the plane without unsetting first. */
1612 rc = drmModeSetPlane(drm_fd, plane_id, crtc_id, plane_fb1.fb_id, 0,
1613 crtc_x, crtc_y, plane_fb1.width, plane_fb1.height,
1614 0 << 16, 0 << 16, plane_fb1.width << 16,
1615 plane_fb1.height << 16);
1616 igt_assert(rc == 0);
1617 igt_assert(wait_for_suspended());
1619 /* Make sure nothing remains for the other tests. */
1620 rc = drmModeSetPlane(drm_fd, plane_id, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1621 igt_assert(rc == 0);
1622 igt_assert(wait_for_suspended());
1625 /* This one also triggered WARNs on our driver at some point in time. */
1626 static void planes_subtest(bool universal, bool dpms)
1628 int i, rc, planes_tested = 0;
1629 drmModePlaneResPtr planes;
1632 rc = drmSetClientCap(drm_fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES,
1634 igt_require(rc == 0);
1637 planes = drmModeGetPlaneResources(drm_fd);
1638 for (i = 0; i < planes->count_planes; i++) {
1639 drmModePlanePtr plane;
1641 plane = drmModeGetPlane(drm_fd, planes->planes[i]);
1644 /* We just pick the first CRTC on the list, so we can test for
1645 * 0x1 as the index. */
1646 if (plane->possible_crtcs & 0x1) {
1647 enum plane_type type;
1649 type = universal ? get_plane_type(plane->plane_id) :
1651 test_one_plane(dpms, plane->plane_id, type);
1654 drmModeFreePlane(plane);
1656 drmModeFreePlaneResources(planes);
1659 rc = drmSetClientCap(drm_fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 0);
1660 igt_assert(rc == 0);
1662 igt_assert(planes_tested >= 3);
1664 igt_assert(planes_tested >= 1);
1668 static void fences_subtest(bool dpms)
1672 uint32_t tiling = false, swizzle;
1673 struct modeset_params params;
1675 disable_all_screens_and_wait(&ms_data);
1677 igt_require(default_mode_params);
1678 params.crtc_id = default_mode_params->crtc_id;
1679 params.connector_id = default_mode_params->connector_id;
1680 params.mode = default_mode_params->mode;
1681 igt_create_fb(drm_fd, params.mode->hdisplay, params.mode->vdisplay,
1682 DRM_FORMAT_XRGB8888, true, ¶ms.fb);
1684 /* Even though we passed "true" as the tiling argument, double-check
1685 * that the fb is really tiled. */
1686 gem_get_tiling(drm_fd, params.fb.gem_handle, &tiling, &swizzle);
1689 buf_ptr = gem_mmap__gtt(drm_fd, params.fb.gem_handle,
1690 params.fb.size, PROT_WRITE | PROT_READ);
1691 for (i = 0; i < params.fb.size/sizeof(uint32_t); i++)
1694 set_mode_for_params_and_wait(¶ms);
1696 disable_or_dpms_all_screens_and_wait(&ms_data, dpms);
1698 for (i = 0; i < params.fb.size/sizeof(uint32_t); i++)
1699 igt_assert_eq(buf_ptr[i], i);
1700 igt_assert(wait_for_suspended());
1703 drmModeConnectorPtr c = NULL;
1705 for (i = 0; i < ms_data.res->count_connectors; i++)
1706 if (ms_data.connectors[i]->connector_id ==
1707 params.connector_id)
1708 c = ms_data.connectors[i];
1711 kmstest_set_connector_dpms(drm_fd, c, DRM_MODE_DPMS_ON);
1713 set_mode_for_params(¶ms);
1715 igt_assert(wait_for_active());
1717 for (i = 0; i < params.fb.size/sizeof(uint32_t); i++)
1718 igt_assert_eq(buf_ptr[i], i);
1720 igt_assert(munmap(buf_ptr, params.fb.size) == 0);
1726 static int opt_handler(int opt, int opt_index)
1742 int main(int argc, char *argv[])
1744 const char *help_str =
1745 " --quick\t\tMake the stress-tests not stressful, for quick regression testing.\n"
1746 " --stay\t\tDisable all screen and try to go into runtime pm. Useful for debugging.";
1747 static struct option long_options[] = {
1748 {"quick", 0, 0, 'q'},
1749 {"stay", 0, 0, 's'},
1753 igt_subtest_init_parse_opts(argc, argv, "", long_options,
1754 help_str, opt_handler);
1756 /* Skip instead of failing in case the machine is not prepared to reach
1757 * PC8+. We don't want bug reports from cases where the machine is just
1758 * not properly configured. */
1760 setup_environment();
1766 /* Essential things */
1769 igt_subtest("drm-resources-equal")
1770 drm_resources_equal_subtest();
1771 igt_subtest("pci-d3-state")
1772 pci_d3_state_subtest();
1775 igt_subtest("modeset-lpsp")
1776 modeset_subtest(SCREEN_TYPE_LPSP, 1, WAIT_STATUS);
1777 igt_subtest("modeset-non-lpsp")
1778 modeset_subtest(SCREEN_TYPE_NON_LPSP, 1, WAIT_STATUS);
1779 igt_subtest("dpms-lpsp")
1780 modeset_subtest(SCREEN_TYPE_LPSP, 1, WAIT_STATUS | USE_DPMS);
1781 igt_subtest("dpms-non-lpsp")
1782 modeset_subtest(SCREEN_TYPE_NON_LPSP, 1, WAIT_STATUS | USE_DPMS);
1785 igt_subtest("gem-mmap-cpu")
1786 gem_mmap_subtest(false);
1787 igt_subtest("gem-mmap-gtt")
1788 gem_mmap_subtest(true);
1789 igt_subtest("gem-pread")
1790 gem_pread_subtest();
1791 igt_subtest("gem-execbuf")
1792 gem_execbuf_subtest();
1793 igt_subtest("gem-idle")
1796 /* Planes and cursors */
1797 igt_subtest("cursor")
1798 cursor_subtest(false);
1799 igt_subtest("cursor-dpms")
1800 cursor_subtest(true);
1801 igt_subtest("legacy-planes")
1802 planes_subtest(false, false);
1803 igt_subtest("legacy-planes-dpms")
1804 planes_subtest(false, true);
1805 igt_subtest("universal-planes")
1806 planes_subtest(true, false);
1807 igt_subtest("universal-planes-dpms")
1808 planes_subtest(true, true);
1811 igt_subtest("reg-read-ioctl")
1812 reg_read_ioctl_subtest();
1815 igt_subtest("pc8-residency")
1816 pc8_residency_subtest();
1817 igt_subtest("debugfs-read")
1818 debugfs_read_subtest();
1819 igt_subtest("debugfs-forcewake-user")
1820 debugfs_forcewake_user_subtest();
1821 igt_subtest("sysfs-read")
1822 sysfs_read_subtest();
1823 igt_subtest("dpms-mode-unset-lpsp")
1824 dpms_mode_unset_subtest(SCREEN_TYPE_LPSP);
1825 igt_subtest("dpms-mode-unset-non-lpsp")
1826 dpms_mode_unset_subtest(SCREEN_TYPE_NON_LPSP);
1827 igt_subtest("fences")
1828 fences_subtest(false);
1829 igt_subtest("fences-dpms")
1830 fences_subtest(true);
1832 /* Modeset stress */
1833 igt_subtest("modeset-lpsp-stress")
1834 modeset_subtest(SCREEN_TYPE_LPSP, rounds, WAIT_STATUS);
1835 igt_subtest("modeset-non-lpsp-stress")
1836 modeset_subtest(SCREEN_TYPE_NON_LPSP, rounds, WAIT_STATUS);
1837 igt_subtest("modeset-lpsp-stress-no-wait")
1838 modeset_subtest(SCREEN_TYPE_LPSP, rounds, DONT_WAIT);
1839 igt_subtest("modeset-non-lpsp-stress-no-wait")
1840 modeset_subtest(SCREEN_TYPE_NON_LPSP, rounds, DONT_WAIT);
1841 igt_subtest("modeset-pc8-residency-stress")
1842 modeset_subtest(SCREEN_TYPE_ANY, rounds, WAIT_PC8_RES);
1843 igt_subtest("modeset-stress-extra-wait")
1844 modeset_subtest(SCREEN_TYPE_ANY, rounds,
1845 WAIT_STATUS | WAIT_EXTRA);
1847 /* System suspend */
1848 igt_subtest("system-suspend")
1849 system_suspend_subtest();
1852 igt_subtest("gem-execbuf-stress")
1853 gem_execbuf_stress_subtest(rounds, WAIT_STATUS);
1854 igt_subtest("gem-execbuf-stress-pc8")
1855 gem_execbuf_stress_subtest(rounds, WAIT_PC8_RES);
1856 igt_subtest("gem-execbuf-stress-extra-wait")
1857 gem_execbuf_stress_subtest(rounds, WAIT_STATUS | WAIT_EXTRA);
1860 teardown_environment();