pm_lpsp.c 6.06 KB
Newer Older
Paulo Zanoni's avatar
Paulo Zanoni committed
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
/*
 * Copyright © 2013 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.
 *
 * Author: Paulo Zanoni <paulo.r.zanoni@intel.com>
 *
 */

27
#include "igt.h"
Paulo Zanoni's avatar
Paulo Zanoni committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>


static bool supports_lpsp(uint32_t devid)
{
	return IS_HASWELL(devid) || IS_BROADWELL(devid);
}

static bool lpsp_is_enabled(int drm_fd)
{
	uint32_t val;

	val = INREG(HSW_PWR_WELL_CTL2);
	return !(val & HSW_PWR_WELL_STATE_ENABLED);
}

/* The LPSP mode is all about an enabled pipe, but we expect to also be in the
 * low power mode when no pipes are enabled, so do this check anyway. */
static void screens_disabled_subtest(int drm_fd, drmModeResPtr drm_res)
{
51
	kmstest_unset_all_crtcs(drm_fd, drm_res);
Paulo Zanoni's avatar
Paulo Zanoni committed
52 53 54 55 56
	igt_assert(lpsp_is_enabled(drm_fd));
}

static uint32_t create_fb(int drm_fd, int width, int height)
{
57
	struct igt_fb fb;
Paulo Zanoni's avatar
Paulo Zanoni committed
58

59 60
	return igt_create_pattern_fb(drm_fd, width, height, DRM_FORMAT_XRGB8888,
				     LOCAL_DRM_FORMAT_MOD_NONE, &fb);
Paulo Zanoni's avatar
Paulo Zanoni committed
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
}

static void edp_subtest(int drm_fd, drmModeResPtr drm_res,
			drmModeConnectorPtr *drm_connectors, uint32_t devid,
			bool use_panel_fitter)
{
	int i, rc;
	uint32_t connector_id = 0, crtc_id = 0, buffer_id = 0;
	drmModeModeInfoPtr mode = NULL;
	drmModeModeInfo std_1024_mode = {
		.clock = 65000,
		.hdisplay = 1024,
		.hsync_start = 1048,
		.hsync_end = 1184,
		.htotal = 1344,
		.hskew = 0,
		.vdisplay = 768,
		.vsync_start = 771,
		.vsync_end = 777,
		.vtotal = 806,
		.vscan = 0,
		.vrefresh = 60,
		.flags = 0xA,
		.type = 0x40,
		.name = "Custom 1024x768",
	};

88
	kmstest_unset_all_crtcs(drm_fd, drm_res);
Paulo Zanoni's avatar
Paulo Zanoni committed
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

	for (i = 0; i < drm_res->count_connectors; i++) {
		drmModeConnectorPtr c = drm_connectors[i];

		if (c->connector_type != DRM_MODE_CONNECTOR_eDP)
			continue;
		if (c->connection != DRM_MODE_CONNECTED)
			continue;

		if (!use_panel_fitter && c->count_modes) {
			connector_id = c->connector_id;
			mode = &c->modes[0];
			break;
		}
		if (use_panel_fitter) {
			connector_id = c->connector_id;

			/* This is one of the modes Xorg creates for panels, so
			 * it should work just fine. Notice that Gens that
			 * support LPSP are too new for panels with native
			 * 1024x768 resolution, so this should force the panel
			 * fitter. */
			igt_assert(c->count_modes &&
				   c->modes[0].hdisplay > 1024);
			igt_assert(c->count_modes &&
				   c->modes[0].vdisplay > 768);
			mode = &std_1024_mode;
			break;
		}
	}
	igt_require(connector_id);

	crtc_id = drm_res->crtcs[0];
	buffer_id = create_fb(drm_fd, mode->hdisplay, mode->vdisplay);

	igt_assert(crtc_id);
	igt_assert(buffer_id);
	igt_assert(connector_id);
	igt_assert(mode);

	rc = drmModeSetCrtc(drm_fd, crtc_id, buffer_id, 0, 0, &connector_id, 1,
			    mode);
131
	igt_assert_eq(rc, 0);
Paulo Zanoni's avatar
Paulo Zanoni committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149

	if (use_panel_fitter) {
		if (IS_HASWELL(devid))
			igt_assert(!lpsp_is_enabled(drm_fd));
		else
			igt_assert(lpsp_is_enabled(drm_fd));
	} else {
		igt_assert(lpsp_is_enabled(drm_fd));
	}
}

static void non_edp_subtest(int drm_fd, drmModeResPtr drm_res,
			    drmModeConnectorPtr *drm_connectors)
{
	int i, rc;
	uint32_t connector_id = 0, crtc_id = 0, buffer_id = 0;
	drmModeModeInfoPtr mode = NULL;

150
	kmstest_unset_all_crtcs(drm_fd, drm_res);
Paulo Zanoni's avatar
Paulo Zanoni committed
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

	for (i = 0; i < drm_res->count_connectors; i++) {
		drmModeConnectorPtr c = drm_connectors[i];

		if (c->connector_type == DRM_MODE_CONNECTOR_eDP)
			continue;
		if (c->connection != DRM_MODE_CONNECTED)
			continue;

		if (c->count_modes) {
			connector_id = c->connector_id;
			mode = &c->modes[0];
			break;
		}
	}
	igt_require(connector_id);

	crtc_id = drm_res->crtcs[0];
	buffer_id = create_fb(drm_fd, mode->hdisplay, mode->vdisplay);

	igt_assert(crtc_id);
	igt_assert(buffer_id);
	igt_assert(connector_id);
	igt_assert(mode);

	rc = drmModeSetCrtc(drm_fd, crtc_id, buffer_id, 0, 0, &connector_id, 1,
			    mode);
178
	igt_assert_eq(rc, 0);
Paulo Zanoni's avatar
Paulo Zanoni committed
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194

	igt_assert(!lpsp_is_enabled(drm_fd));
}

#define MAX_CONNECTORS 32

int drm_fd;
uint32_t devid;
drmModeResPtr drm_res;
drmModeConnectorPtr drm_connectors[MAX_CONNECTORS];

igt_main
{
	igt_fixture {
		int i;

195
		drm_fd = drm_open_driver_master(DRIVER_INTEL);
Paulo Zanoni's avatar
Paulo Zanoni committed
196 197 198 199 200 201 202 203
		igt_require(drm_fd >= 0);

		devid = intel_get_drm_devid(drm_fd);

		drm_res = drmModeGetResources(drm_fd);
		igt_assert(drm_res->count_connectors <= MAX_CONNECTORS);

		for (i = 0; i < drm_res->count_connectors; i++)
204
			drm_connectors[i] = drmModeGetConnectorCurrent(drm_fd,
Paulo Zanoni's avatar
Paulo Zanoni committed
205 206
							drm_res->connectors[i]);

207
		igt_pm_enable_audio_runtime_pm();
Paulo Zanoni's avatar
Paulo Zanoni committed
208 209 210 211 212

		igt_require(supports_lpsp(devid));

		intel_register_access_init(intel_get_pci_device(), 0);

213
		kmstest_set_vt_graphics_mode();
Paulo Zanoni's avatar
Paulo Zanoni committed
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
	}

	igt_subtest("screens-disabled")
		screens_disabled_subtest(drm_fd, drm_res);
	igt_subtest("edp-native")
		edp_subtest(drm_fd, drm_res, drm_connectors, devid, false);
	igt_subtest("edp-panel-fitter")
		edp_subtest(drm_fd, drm_res, drm_connectors, devid, true);
	igt_subtest("non-edp")
		non_edp_subtest(drm_fd, drm_res, drm_connectors);

	igt_fixture {
		int i;

		intel_register_access_fini();
		for (i = 0; i < drm_res->count_connectors; i++)
			drmModeFreeConnector(drm_connectors[i]);
		drmModeFreeResources(drm_res);
		close(drm_fd);
	}
}