1 /*
2 * Copyright © 2013 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 *
23 * Author: Paulo Zanoni <[email protected]>
24 *
25 */
26
27 #include "igt.h"
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <fcntl.h>
31 #include <unistd.h>
32
33
supports_lpsp(uint32_t devid)34 static bool supports_lpsp(uint32_t devid)
35 {
36 return IS_HASWELL(devid) || IS_BROADWELL(devid);
37 }
38
lpsp_is_enabled(int drm_fd)39 static bool lpsp_is_enabled(int drm_fd)
40 {
41 uint32_t val;
42
43 val = INREG(HSW_PWR_WELL_CTL2);
44 return !(val & HSW_PWR_WELL_STATE_ENABLED);
45 }
46
47 /* The LPSP mode is all about an enabled pipe, but we expect to also be in the
48 * low power mode when no pipes are enabled, so do this check anyway. */
screens_disabled_subtest(int drm_fd,drmModeResPtr drm_res)49 static void screens_disabled_subtest(int drm_fd, drmModeResPtr drm_res)
50 {
51 kmstest_unset_all_crtcs(drm_fd, drm_res);
52 igt_assert(lpsp_is_enabled(drm_fd));
53 }
54
create_fb(int drm_fd,int width,int height)55 static uint32_t create_fb(int drm_fd, int width, int height)
56 {
57 struct igt_fb fb;
58
59 return igt_create_pattern_fb(drm_fd, width, height, DRM_FORMAT_XRGB8888,
60 LOCAL_DRM_FORMAT_MOD_NONE, &fb);
61 }
62
edp_subtest(int drm_fd,drmModeResPtr drm_res,drmModeConnectorPtr * drm_connectors,uint32_t devid,bool use_panel_fitter)63 static void edp_subtest(int drm_fd, drmModeResPtr drm_res,
64 drmModeConnectorPtr *drm_connectors, uint32_t devid,
65 bool use_panel_fitter)
66 {
67 int i, rc;
68 uint32_t crtc_id = 0, buffer_id = 0;
69 drmModeConnectorPtr connector = NULL;
70 drmModeModeInfoPtr mode = NULL;
71 drmModeModeInfo std_1024_mode = {
72 .clock = 65000,
73 .hdisplay = 1024,
74 .hsync_start = 1048,
75 .hsync_end = 1184,
76 .htotal = 1344,
77 .hskew = 0,
78 .vdisplay = 768,
79 .vsync_start = 771,
80 .vsync_end = 777,
81 .vtotal = 806,
82 .vscan = 0,
83 .vrefresh = 60,
84 .flags = 0xA,
85 .type = 0x40,
86 .name = "Custom 1024x768",
87 };
88
89 kmstest_unset_all_crtcs(drm_fd, drm_res);
90
91 for (i = 0; i < drm_res->count_connectors; i++) {
92 drmModeConnectorPtr c = drm_connectors[i];
93
94 if (c->connector_type != DRM_MODE_CONNECTOR_eDP)
95 continue;
96 if (c->connection != DRM_MODE_CONNECTED)
97 continue;
98
99 if (!use_panel_fitter && c->count_modes) {
100 connector = c;
101 mode = &c->modes[0];
102 break;
103 }
104 if (use_panel_fitter) {
105 connector = c;
106
107 /* This is one of the modes Xorg creates for panels, so
108 * it should work just fine. Notice that Gens that
109 * support LPSP are too new for panels with native
110 * 1024x768 resolution, so this should force the panel
111 * fitter. */
112 igt_assert(c->count_modes &&
113 c->modes[0].hdisplay > 1024);
114 igt_assert(c->count_modes &&
115 c->modes[0].vdisplay > 768);
116 mode = &std_1024_mode;
117 break;
118 }
119 }
120 igt_require(connector);
121
122 crtc_id = kmstest_find_crtc_for_connector(drm_fd, drm_res, connector,
123 0);
124 buffer_id = create_fb(drm_fd, mode->hdisplay, mode->vdisplay);
125
126 igt_assert(buffer_id);
127 igt_assert(connector);
128 igt_assert(mode);
129
130 rc = drmModeSetCrtc(drm_fd, crtc_id, buffer_id, 0, 0,
131 &connector->connector_id, 1, mode);
132 igt_assert_eq(rc, 0);
133
134 if (use_panel_fitter) {
135 if (IS_HASWELL(devid))
136 igt_assert(!lpsp_is_enabled(drm_fd));
137 else
138 igt_assert(lpsp_is_enabled(drm_fd));
139 } else {
140 igt_assert(lpsp_is_enabled(drm_fd));
141 }
142 }
143
non_edp_subtest(int drm_fd,drmModeResPtr drm_res,drmModeConnectorPtr * drm_connectors)144 static void non_edp_subtest(int drm_fd, drmModeResPtr drm_res,
145 drmModeConnectorPtr *drm_connectors)
146 {
147 int i, rc;
148 uint32_t crtc_id = 0, buffer_id = 0;
149 drmModeConnectorPtr connector = NULL;
150 drmModeModeInfoPtr mode = NULL;
151
152 kmstest_unset_all_crtcs(drm_fd, drm_res);
153
154 for (i = 0; i < drm_res->count_connectors; i++) {
155 drmModeConnectorPtr c = drm_connectors[i];
156
157 if (c->connector_type == DRM_MODE_CONNECTOR_eDP)
158 continue;
159 if (c->connection != DRM_MODE_CONNECTED)
160 continue;
161
162 if (c->count_modes) {
163 connector = c;
164 mode = &c->modes[0];
165 break;
166 }
167 }
168 igt_require(connector);
169
170 crtc_id = kmstest_find_crtc_for_connector(drm_fd, drm_res, connector,
171 0);
172 buffer_id = create_fb(drm_fd, mode->hdisplay, mode->vdisplay);
173
174 igt_assert(buffer_id);
175 igt_assert(mode);
176
177 rc = drmModeSetCrtc(drm_fd, crtc_id, buffer_id, 0, 0,
178 &connector->connector_id, 1, mode);
179 igt_assert_eq(rc, 0);
180
181 igt_assert(!lpsp_is_enabled(drm_fd));
182 }
183
184 #define MAX_CONNECTORS 32
185
186 int drm_fd;
187 uint32_t devid;
188 drmModeResPtr drm_res;
189 drmModeConnectorPtr drm_connectors[MAX_CONNECTORS];
190
191 igt_main
192 {
193 igt_fixture {
194 int i;
195
196 drm_fd = drm_open_driver_master(DRIVER_INTEL);
197 igt_require(drm_fd >= 0);
198
199 devid = intel_get_drm_devid(drm_fd);
200
201 drm_res = drmModeGetResources(drm_fd);
202 igt_require(drm_res);
203 igt_assert(drm_res->count_connectors <= MAX_CONNECTORS);
204
205 for (i = 0; i < drm_res->count_connectors; i++)
206 drm_connectors[i] = drmModeGetConnectorCurrent(drm_fd,
207 drm_res->connectors[i]);
208
209 igt_pm_enable_audio_runtime_pm();
210
211 igt_require(supports_lpsp(devid));
212
213 intel_register_access_init(intel_get_pci_device(), 0, drm_fd);
214
215 kmstest_set_vt_graphics_mode();
216 }
217
218 igt_subtest("screens-disabled")
219 screens_disabled_subtest(drm_fd, drm_res);
220 igt_subtest("edp-native")
221 edp_subtest(drm_fd, drm_res, drm_connectors, devid, false);
222 igt_subtest("edp-panel-fitter")
223 edp_subtest(drm_fd, drm_res, drm_connectors, devid, true);
224 igt_subtest("non-edp")
225 non_edp_subtest(drm_fd, drm_res, drm_connectors);
226
227 igt_fixture {
228 int i;
229
230 intel_register_access_fini();
231 for (i = 0; i < drm_res->count_connectors; i++)
232 drmModeFreeConnector(drm_connectors[i]);
233 drmModeFreeResources(drm_res);
234 close(drm_fd);
235 }
236 }
237