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 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 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
|
/*
* Copyright © 2012 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.
*
* Authors:
* Paulo Zanoni <paulo.r.zanoni@intel.com>
*/
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "intel_io.h"
#include "intel_chipset.h"
#include "intel_reg.h"
#include "drmtest.h"
int gen;
uint32_t HTOTAL[] = { 0x60000, 0x61000, 0x62000 };
uint32_t VTOTAL[] = { 0x6000C, 0x6100C, 0x6200C };
uint32_t PIPECONF[] = { 0x70008, 0x71008, 0x72008 };
uint32_t PIPESRC[] = { 0x6001C, 0x6101C, 0x6201C };
uint32_t PF_CTRL1[] = { 0x68080, 0x68880, 0x69080 };
uint32_t PF_WIN_POS[] = { 0x68070, 0x68870, 0x69070 };
uint32_t PF_WIN_SZ[] = { 0x68074, 0x68874, 0x69074 };
#define PIPECONF_ENABLE (1 << 31)
#define PIPECONF_INTERLACE_MASK (7 << 21)
#define PIPECONF_PF_PD (0 << 21)
#define PIPECONF_PF_ID (1 << 21)
#define PIPECONF_IF_ID (3 << 21)
#define HTOTAL_ACTIVE_MASK (0xFFF << 0)
#define VTOTAL_ACTIVE_MASK (0xFFF << 0)
#define PIPESRC_HORIZ_MASK (0xFFF << 16)
#define PIPESRC_VERT_MASK (0xFFF << 0)
/*#define PF_ENABLE (1 << 31)*/
#define PF_PIPE_MASK (3 << 29)
#define PF_FILTER_MASK (3 << 23)
#define PF_FILTER_MED (1 << 23)
#define PF_PIPE_A (0 << 29)
#define PF_PIPE_B (1 << 29)
#define PF_PIPE_C (2 << 29)
#define PF_WIN_SZ_X_MASK (0x1FFF << 16)
#define PF_WIN_SZ_Y_MASK (0xFFF << 0)
struct pipe_info {
bool enabled;
bool pf_enabled;
uint32_t interlace_mode;
int tot_width; /* htotal */
int tot_height; /* vtotal */
int src_width; /* pipesrc.x */
int src_height; /* pipesrc.y */
int dst_width; /* pf_win_sz.x */
int dst_height; /* pf_win_sz.y */
};
static void read_pipe_info(int intel_pipe, struct pipe_info *info)
{
uint32_t conf, vtotal, htotal, src, ctrl1, win_sz;
conf = INREG(PIPECONF[intel_pipe]);
htotal = INREG(HTOTAL[intel_pipe]);
vtotal = INREG(VTOTAL[intel_pipe]);
src = INREG(PIPESRC[intel_pipe]);
ctrl1 = INREG(PF_CTRL1[intel_pipe]);
win_sz = INREG(PF_WIN_SZ[intel_pipe]);
info->enabled = (conf & PIPECONF_ENABLE) ? true : false;
info->tot_width = (htotal & HTOTAL_ACTIVE_MASK) + 1;
info->tot_height = (vtotal & VTOTAL_ACTIVE_MASK) + 1;
info->src_width = ((src & PIPESRC_HORIZ_MASK) >> 16) + 1;
info->src_height = (src & PIPESRC_VERT_MASK) + 1;
info->interlace_mode = conf & PIPECONF_INTERLACE_MASK;
info->pf_enabled = ctrl1 & PF_ENABLE;
info->dst_width = (win_sz & PF_WIN_SZ_X_MASK) >> 16;
info->dst_height = win_sz & PF_WIN_SZ_Y_MASK;
}
static void dump_pipe(int intel_pipe)
{
struct pipe_info info;
read_pipe_info(intel_pipe, &info);
printf("\nPipe %c:\n", intel_pipe + 'A');
printf("- %s\n", info.enabled ? "enabled" : "disabled");
if (!info.enabled)
return;
switch (info.interlace_mode) {
case PIPECONF_PF_PD:
printf("- progressive\n");
break;
case PIPECONF_PF_ID:
printf("- interlaced (progressive fetch)\n");
break;
case PIPECONF_IF_ID:
printf("- interlaced (interlaced fetch)\n");
break;
default:
assert(0);
}
printf("- pf %s\n", info.pf_enabled ? "enabled" : "disabled");
if (!info.pf_enabled)
return;
printf("- tot %dx%d\n", info.tot_width, info.tot_height);
printf("- src %dx%d\n", info.src_width, info.src_height);
printf("- dst %dx%d\n", info.dst_width, info.dst_height);
}
static void dump_info(void)
{
int i;
int pipes;
if (gen < 7)
pipes = 2;
else
pipes = 3;
for (i = 0; i < pipes; i++) {
dump_pipe(i);
}
}
static int change_screen_size(int intel_pipe, int x, int y)
{
struct pipe_info info;
int dst_width, dst_height, pos_x, pos_y;
uint32_t ctrl1_val;
uint32_t win_pos_val;
uint32_t win_sz_val;
read_pipe_info(intel_pipe, &info);
if (x == 0) {
if (info.dst_width != 0)
dst_width = info.dst_width;
else
dst_width = info.src_width;
} else {
dst_width = x;
}
if (y == 0) {
if (info.dst_height != 0)
dst_height = info.dst_height;
else
dst_height = info.src_height;
} else {
dst_height = y;
}
pos_x = abs((info.tot_width - dst_width)) / 2;
pos_y = abs((info.tot_height - dst_height)) / 2;
if (pos_x == 1)
pos_x = 0;
if (info.src_width / (double) dst_width > 1.125) {
printf("X is too small\n");
return 1;
} else if (info.tot_width < dst_width) {
printf("X is too big\n");
return 1;
} else if (dst_width & 1) {
printf("X must be even\n");
return 1;
} else if (info.src_height / (double) dst_height > 1.125) {
printf("Y is too small\n");
return 1;
} else if (info.tot_height < dst_height) {
printf("Y is too big\n");
return 1;
} else if (dst_height & 1) {
printf("Y must be even\n");
return 1;
}
printf("Changing size for pipe %c:\n"
"- width: %d -> %d\n"
"- height: %d -> %d\n"
"- pos: %dx%d\n",
intel_pipe + 'A', info.src_width, dst_width, info.src_height,
dst_height, pos_x, pos_y);
ctrl1_val = PF_ENABLE | PF_FILTER_MED;
/* This can break stuff if the panel fitter is already enabled for
* another pipe */
if (gen >= 7) {
switch (intel_pipe) {
case 0:
ctrl1_val |= PF_PIPE_A;
break;
case 1:
ctrl1_val |= PF_PIPE_B;
break;
case 2:
ctrl1_val |= PF_PIPE_C;
break;
default:
assert(0);
}
}
OUTREG(PF_CTRL1[intel_pipe], ctrl1_val);
win_pos_val = pos_x << 16;
win_pos_val |= pos_y;
OUTREG(PF_WIN_POS[intel_pipe], win_pos_val);
win_sz_val = dst_width << 16;
win_sz_val |= dst_height;
OUTREG(PF_WIN_SZ[intel_pipe], win_sz_val);
return 0;
}
static int disable_panel_fitter(int intel_pipe)
{
OUTREG(PF_CTRL1[intel_pipe], 0);
OUTREG(PF_WIN_POS[intel_pipe], 0);
OUTREG(PF_WIN_SZ[intel_pipe], 0);
return 0;
}
static void print_usage(void)
{
printf("Options:\n"
" -p pipe: pipe to be used (A, B or C)\n"
" -x value: final screen width size in pixels\n"
" -y value: final screen height size in pixels\n"
" -d: disable panel fitter\n"
" -l: list the current state of each pipe\n"
" -h: prints this message\n");
}
int main (int argc, char *argv[])
{
int opt;
int ret = 0;
char intel_pipe = '\0';
int x = 0, y = 0;
bool do_disable = false, do_dump = false, do_usage = false;
struct pci_device *pci_dev;
uint32_t devid;
struct intel_mmio_data mmio_data;
printf("WARNING:\n"
"This tool is a workaround for people that don't have a Kernel "
"with overscan compensation properties: it is just a temporary "
"solution that may or may not work. Use it at your own risk.\n");
pci_dev = intel_get_pci_device();
intel_register_access_init(&mmio_data, pci_dev, 0);
devid = pci_dev->device_id;
if (!HAS_PCH_SPLIT(devid)) {
printf("This tool was only tested on Ironlake and newer\n");
ret = 1;
goto out;
}
if (IS_GEN5(devid))
gen = 5;
else if (IS_GEN6(devid))
gen = 6;
else
gen = 7;
while ((opt = getopt(argc, argv, "p:x:y:dlh")) != -1) {
switch (opt) {
case 'p':
intel_pipe = optarg[0];
if (intel_pipe != 'A' && intel_pipe != 'B' &&
(gen <= 6 || intel_pipe != 'C')) {
printf("Invalid pipe\n");
ret = 1;
goto out;
}
break;
case 'x':
x = atoi(optarg);
break;
case 'y':
y = atoi(optarg);
break;
case 'd':
do_disable = true;
break;
case 'l':
do_dump = true;
break;
case 'h':
do_usage = true;
break;
default:
do_usage = true;
ret = 1;
}
}
if (do_usage) {
print_usage();
} else if (do_dump) {
dump_info();
} else if (intel_pipe) {
if (do_disable)
ret = disable_panel_fitter(intel_pipe - 'A');
else
ret = change_screen_size(intel_pipe - 'A', x, y);
} else {
print_usage();
ret = 1;
}
out:
intel_register_access_fini(&mmio_data);
return ret;
}
|