drmmode_display.c 67 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
/*
 * Copyright © 2007 Red Hat, Inc.
 *
 * 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:
 *    Dave Airlie <airlied@redhat.com>
 *
 */

28 29
#ifdef HAVE_DIX_CONFIG_H
#include "dix-config.h"
30 31 32 33 34
#endif

#include <errno.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
35
#include <unistd.h>
36
#include "dumb_bo.h"
37 38 39 40 41 42 43 44 45 46
#include "xf86str.h"
#include "X11/Xatom.h"
#include "micmap.h"
#include "xf86cmap.h"
#include "xf86DDC.h"

#include <xf86drm.h>
#include "xf86Crtc.h"
#include "drmmode_display.h"

47 48
#include <cursorstr.h>

49 50
#include <X11/extensions/dpmsconst.h>

51 52
#include "driver.h"

53
static Bool drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height);
54 55 56
static PixmapPtr drmmode_create_pixmap_header(ScreenPtr pScreen, int width, int height,
                                              int depth, int bitsPerPixel, int devKind,
                                              void *pPixData);
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
static Bool
drmmode_zaphod_string_matches(ScrnInfoPtr scrn, const char *s, char *output_name)
{
    int i = 0;
    char s1[20];

    do {
        switch(*s) {
        case ',':
            s1[i] = '\0';
            i = 0;
            if (strcmp(s1, output_name) == 0)
                return TRUE;
            break;
        case ' ':
        case '\t':
        case '\n':
        case '\r':
            break;
        default:
            s1[i] = *s;
            i++;
            break;
        }
    } while(*s++);

    s1[i] = '\0';
    if (strcmp(s1, output_name) == 0)
        return TRUE;

    return FALSE;
}

90
int
91 92 93 94
drmmode_bo_destroy(drmmode_ptr drmmode, drmmode_bo *bo)
{
    int ret;

95 96 97 98 99 100 101
#ifdef GLAMOR_HAS_GBM
    if (bo->gbm) {
        gbm_bo_destroy(bo->gbm);
        bo->gbm = NULL;
    }
#endif

102 103 104 105 106 107 108 109 110
    if (bo->dumb) {
        ret = dumb_bo_destroy(drmmode->fd, bo->dumb);
        if (ret == 0)
            bo->dumb = NULL;
    }

    return 0;
}

111
uint32_t
112 113
drmmode_bo_get_pitch(drmmode_bo *bo)
{
114 115 116 117 118
#ifdef GLAMOR_HAS_GBM
    if (bo->gbm)
        return gbm_bo_get_stride(bo->gbm);
#endif

119 120 121
    return bo->dumb->pitch;
}

122 123 124 125 126 127 128 129 130 131 132
static Bool
drmmode_bo_has_bo(drmmode_bo *bo)
{
#ifdef GLAMOR_HAS_GBM
    if (bo->gbm)
        return TRUE;
#endif

    return bo->dumb != NULL;
}

133 134 135
uint32_t
drmmode_bo_get_handle(drmmode_bo *bo)
{
136 137 138 139 140
#ifdef GLAMOR_HAS_GBM
    if (bo->gbm)
        return gbm_bo_get_handle(bo->gbm).u32;
#endif

141 142 143
    return bo->dumb->handle;
}

144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
static void *
drmmode_bo_map(drmmode_ptr drmmode, drmmode_bo *bo)
{
    int ret;

#ifdef GLAMOR_HAS_GBM
    if (bo->gbm)
        return NULL;
#endif

    if (bo->dumb->ptr)
        return bo->dumb->ptr;

    ret = dumb_bo_map(drmmode->fd, bo->dumb);
    if (ret)
        return NULL;

    return bo->dumb->ptr;
}

164 165 166 167
static Bool
drmmode_create_bo(drmmode_ptr drmmode, drmmode_bo *bo,
                  unsigned width, unsigned height, unsigned bpp)
{
168 169 170 171 172 173 174 175 176
#ifdef GLAMOR_HAS_GBM
    if (drmmode->glamor) {
        bo->gbm = gbm_bo_create(drmmode->gbm, width, height,
                                GBM_FORMAT_ARGB8888,
                                GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT);
        return bo->gbm != NULL;
    }
#endif

177 178 179 180
    bo->dumb = dumb_bo_create(drmmode->fd, width, height, bpp);
    return bo->dumb != NULL;
}

181 182 183
Bool
drmmode_bo_for_pixmap(drmmode_ptr drmmode, drmmode_bo *bo, PixmapPtr pixmap)
{
184
#ifdef GLAMOR
185
    ScreenPtr screen = xf86ScrnToScreen(drmmode->scrn);
186 187
    CARD16 pitch;
    CARD32 size;
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
    int fd;

#ifdef GLAMOR_HAS_GBM
    if (drmmode->glamor) {
        bo->gbm = glamor_gbm_bo_from_pixmap(screen, pixmap);
        bo->dumb = NULL;
        return bo->gbm != NULL;
    }
#endif

    fd = glamor_fd_from_pixmap(screen, pixmap, &pitch, &size);
    if (fd < 0) {
        xf86DrvMsg(drmmode->scrn->scrnIndex, X_ERROR,
                   "Failed to get fd for flip to new front.\n");
        return FALSE;
    }
    bo->dumb = dumb_get_bo_from_fd(drmmode->fd, fd, pitch, size);
    close(fd);
206
#endif
207 208 209 210

    return bo->dumb != NULL;
}

211 212 213
Bool
drmmode_SetSlaveBO(PixmapPtr ppix,
                   drmmode_ptr drmmode, int fd_handle, int pitch, int size)
214
{
215
    msPixmapPrivPtr ppriv = msGetPixmapPriv(drmmode, ppix);
216

217 218 219 220 221 222
    if (fd_handle == -1) {
        dumb_bo_destroy(drmmode->fd, ppriv->backing_bo);
        ppriv->backing_bo = NULL;
        return TRUE;
    }

223
    ppriv->backing_bo =
224
        dumb_get_bo_from_fd(drmmode->fd, fd_handle, pitch, size);
225 226
    if (!ppriv->backing_bo)
        return FALSE;
227

228 229
    close(fd_handle);
    return TRUE;
230 231
}

232
static void
233 234
drmmode_ConvertFromKMode(ScrnInfoPtr scrn,
                         drmModeModeInfo * kmode, DisplayModePtr mode)
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
    memset(mode, 0, sizeof(DisplayModeRec));
    mode->status = MODE_OK;

    mode->Clock = kmode->clock;

    mode->HDisplay = kmode->hdisplay;
    mode->HSyncStart = kmode->hsync_start;
    mode->HSyncEnd = kmode->hsync_end;
    mode->HTotal = kmode->htotal;
    mode->HSkew = kmode->hskew;

    mode->VDisplay = kmode->vdisplay;
    mode->VSyncStart = kmode->vsync_start;
    mode->VSyncEnd = kmode->vsync_end;
    mode->VTotal = kmode->vtotal;
    mode->VScan = kmode->vscan;

    mode->Flags = kmode->flags; //& FLAG_BITS;
    mode->name = strdup(kmode->name);

    if (kmode->type & DRM_MODE_TYPE_DRIVER)
        mode->type = M_T_DRIVER;
    if (kmode->type & DRM_MODE_TYPE_PREFERRED)
        mode->type |= M_T_PREFERRED;
    xf86SetModeCrtc(mode, scrn->adjustFlags);
261 262 263
}

static void
264 265
drmmode_ConvertToKMode(ScrnInfoPtr scrn,
                       drmModeModeInfo * kmode, DisplayModePtr mode)
266
{
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
    memset(kmode, 0, sizeof(*kmode));

    kmode->clock = mode->Clock;
    kmode->hdisplay = mode->HDisplay;
    kmode->hsync_start = mode->HSyncStart;
    kmode->hsync_end = mode->HSyncEnd;
    kmode->htotal = mode->HTotal;
    kmode->hskew = mode->HSkew;

    kmode->vdisplay = mode->VDisplay;
    kmode->vsync_start = mode->VSyncStart;
    kmode->vsync_end = mode->VSyncEnd;
    kmode->vtotal = mode->VTotal;
    kmode->vscan = mode->VScan;

    kmode->flags = mode->Flags; //& FLAG_BITS;
    if (mode->name)
        strncpy(kmode->name, mode->name, DRM_DISPLAY_MODE_LEN);
    kmode->name[DRM_DISPLAY_MODE_LEN - 1] = 0;
286 287 288 289 290 291

}

static void
drmmode_crtc_dpms(xf86CrtcPtr crtc, int mode)
{
292 293
    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
    drmmode_crtc->dpms_mode = mode;
294 295
}

296
#ifdef GLAMOR
297
static PixmapPtr
298
create_pixmap_for_fbcon(drmmode_ptr drmmode, ScrnInfoPtr pScrn, int fbcon_id)
299
{
300
    PixmapPtr pixmap = drmmode->fbcon_pixmap;
301 302
    drmModeFBPtr fbcon;
    struct drm_gem_flink flink;
303 304
    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
    Bool ret;
305

306 307
    if (pixmap)
        return pixmap;
308

309
    fbcon = drmModeGetFB(drmmode->fd, fbcon_id);
310 311 312
    if (fbcon == NULL)
        return NULL;

313 314 315 316 317
    if (fbcon->depth != pScrn->depth ||
        fbcon->width != pScrn->virtualX ||
        fbcon->height != pScrn->virtualY)
        goto out_free_fb;

318 319 320
    flink.handle = fbcon->handle;
    if (ioctl(drmmode->fd, DRM_IOCTL_GEM_FLINK, &flink) < 0) {
        xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Couldn't flink fbcon handle\n");
321
        goto out_free_fb;
322 323
    }

324 325 326
    pixmap = drmmode_create_pixmap_header(pScreen, fbcon->width,
                                          fbcon->height, fbcon->depth,
                                          fbcon->bpp, fbcon->pitch, NULL);
327
    if (!pixmap)
328 329 330 331 332 333 334
        goto out_free_fb;

    ret = glamor_egl_create_textured_pixmap(pixmap, fbcon->handle, fbcon->pitch);
    if (!ret) {
      FreePixmap(pixmap);
      pixmap = NULL;
    }
335

336 337
    drmmode->fbcon_pixmap = pixmap;
out_free_fb:
338 339
    drmModeFreeFB(fbcon);
    return pixmap;
340
}
341
#endif
342

343 344 345
void
drmmode_copy_fb(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
{
346
#ifdef GLAMOR
347 348 349 350 351 352 353 354 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 384 385 386 387 388 389 390 391 392
    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
    PixmapPtr src, dst;
    int fbcon_id = 0;
    GCPtr gc;
    int i;

    for (i = 0; i < xf86_config->num_crtc; i++) {
        drmmode_crtc_private_ptr drmmode_crtc = xf86_config->crtc[i]->driver_private;
        if (drmmode_crtc->mode_crtc->buffer_id)
            fbcon_id = drmmode_crtc->mode_crtc->buffer_id;
    }

    if (!fbcon_id)
        return;

    if (fbcon_id == drmmode->fb_id) {
        /* in some rare case there might be no fbcon and we might already
         * be the one with the current fb to avoid a false deadlck in
         * kernel ttm code just do nothing as anyway there is nothing
         * to do
         */
        return;
    }

    src = create_pixmap_for_fbcon(drmmode, pScrn, fbcon_id);
    if (!src)
        return;

    dst = pScreen->GetScreenPixmap(pScreen);

    gc = GetScratchGC(pScrn->depth, pScreen);
    ValidateGC(&dst->drawable, gc);

    (*gc->ops->CopyArea)(&src->drawable, &dst->drawable, gc, 0, 0,
                         pScrn->virtualX, pScrn->virtualY, 0, 0);

    FreeScratchGC(gc);

    glamor_finish(pScreen);

    pScreen->canDoBGNoneRoot = TRUE;

    if (drmmode->fbcon_pixmap)
        pScrn->pScreen->DestroyPixmap(drmmode->fbcon_pixmap);
    drmmode->fbcon_pixmap = NULL;
393
#endif
394
}
395 396 397

static Bool
drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
398
                       Rotation rotation, int x, int y)
399
{
400 401 402 403 404 405 406
    ScrnInfoPtr pScrn = crtc->scrn;
    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
    drmmode_ptr drmmode = drmmode_crtc->drmmode;
    int saved_x, saved_y;
    Rotation saved_rotation;
    DisplayModeRec saved_mode;
407
    uint32_t *output_ids = NULL;
408 409 410 411 412 413 414 415 416 417 418 419 420
    int output_count = 0;
    Bool ret = TRUE;
    int i;
    uint32_t fb_id;
    drmModeModeInfo kmode;
    int height;

    height = pScrn->virtualY;

    if (drmmode->fb_id == 0) {
        ret = drmModeAddFB(drmmode->fd,
                           pScrn->virtualX, height,
                           pScrn->depth, pScrn->bitsPerPixel,
421 422 423
                           drmmode_bo_get_pitch(&drmmode->front_bo),
                           drmmode_bo_get_handle(&drmmode->front_bo),
                           &drmmode->fb_id);
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
        if (ret < 0) {
            ErrorF("failed to add fb %d\n", ret);
            return FALSE;
        }
    }

    saved_mode = crtc->mode;
    saved_x = crtc->x;
    saved_y = crtc->y;
    saved_rotation = crtc->rotation;

    if (mode) {
        crtc->mode = *mode;
        crtc->x = x;
        crtc->y = y;
        crtc->rotation = rotation;
    }

    output_ids = calloc(sizeof(uint32_t), xf86_config->num_output);
    if (!output_ids) {
        ret = FALSE;
        goto done;
    }

    if (mode) {
        for (i = 0; i < xf86_config->num_output; i++) {
            xf86OutputPtr output = xf86_config->output[i];
            drmmode_output_private_ptr drmmode_output;

            if (output->crtc != crtc)
                continue;

            drmmode_output = output->driver_private;
457 458
            if (drmmode_output->output_id == -1)
                continue;
459 460 461
            output_ids[output_count] =
                drmmode_output->mode_output->connector_id;
            output_count++;
462 463
        }

464 465 466 467 468 469 470 471 472 473
        if (!xf86CrtcRotate(crtc)) {
            goto done;
        }
        crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc->gamma_green,
                               crtc->gamma_blue, crtc->gamma_size);

        drmmode_ConvertToKMode(crtc->scrn, &kmode, mode);

        fb_id = drmmode->fb_id;
        if (crtc->randr_crtc->scanout_pixmap) {
474 475 476 477 478 479 480 481
            if (!drmmode->reverse_prime_offload_mode) {
                msPixmapPrivPtr ppriv =
                    msGetPixmapPriv(drmmode, crtc->randr_crtc->scanout_pixmap);
                fb_id = ppriv->fb_id;
                x = 0;
            } else
                x = drmmode_crtc->prime_pixmap_x;
            y = 0;
482 483 484 485 486
        }
        else if (drmmode_crtc->rotate_fb_id) {
            fb_id = drmmode_crtc->rotate_fb_id;
            x = y = 0;
        }
487 488
        if (drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
                           fb_id, x, y, output_ids, output_count, &kmode)) {
489
            xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR,
490 491 492 493
                       "failed to set mode: %s\n", strerror(errno));
            ret = FALSE;
            goto done;
        } else
494 495 496 497
            ret = TRUE;

        if (crtc->scrn->pScreen)
            xf86CrtcSetScreenSubpixelOrder(crtc->scrn->pScreen);
498

499
        drmmode_crtc->need_modeset = FALSE;
500 501
        crtc->funcs->dpms(crtc, DPMSModeOn);

502 503 504
        /* go through all the outputs and force DPMS them back on? */
        for (i = 0; i < xf86_config->num_output; i++) {
            xf86OutputPtr output = xf86_config->output[i];
505
            drmmode_output_private_ptr drmmode_output;
506 507 508 509

            if (output->crtc != crtc)
                continue;

510 511 512
            drmmode_output = output->driver_private;
            if (drmmode_output->output_id == -1)
                continue;
513 514 515
            output->funcs->dpms(output, DPMSModeOn);
        }
    }
516

517 518 519 520 521 522
 done:
    if (!ret) {
        crtc->x = saved_x;
        crtc->y = saved_y;
        crtc->rotation = saved_rotation;
        crtc->mode = saved_mode;
523
    } else
524
        crtc->active = TRUE;
525

526 527
    free(output_ids);

528
    return ret;
529 530 531
}

static void
532
drmmode_set_cursor_colors(xf86CrtcPtr crtc, int bg, int fg)
533 534 535 536 537
{

}

static void
538
drmmode_set_cursor_position(xf86CrtcPtr crtc, int x, int y)
539
{
540 541
    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
    drmmode_ptr drmmode = drmmode_crtc->drmmode;
542

543
    drmModeMoveCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, x, y);
544 545 546
}

static void
547
drmmode_set_cursor(xf86CrtcPtr crtc)
548
{
549
    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
550
    drmmode_ptr drmmode = drmmode_crtc->drmmode;
551
    uint32_t handle = drmmode_crtc->cursor_bo->handle;
552 553
    modesettingPtr ms = modesettingPTR(crtc->scrn);
    static Bool use_set_cursor2 = TRUE;
554 555
    int ret;

556
    if (use_set_cursor2) {
557
        CursorPtr cursor = xf86CurrentCursor(crtc->scrn->pScreen);
558

559 560 561 562
        ret =
            drmModeSetCursor2(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
                              handle, ms->cursor_width, ms->cursor_height,
                              cursor->bits->xhot, cursor->bits->yhot);
563 564
        if (!ret)
            return;
565 566 567 568 569 570
        if (ret == -EINVAL)
            use_set_cursor2 = FALSE;
    }

    ret = drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle,
                           ms->cursor_width, ms->cursor_height);
571 572 573 574 575 576 577 578 579

    if (ret) {
        xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
        xf86CursorInfoPtr cursor_info = xf86_config->cursor_info;

        cursor_info->MaxWidth = cursor_info->MaxHeight = 0;
        drmmode_crtc->drmmode->sw_cursor = TRUE;
        /* fallback to swcursor */
    }
580 581 582
}

static void
583
drmmode_load_cursor_argb(xf86CrtcPtr crtc, CARD32 *image)
584
{
585 586
    modesettingPtr ms = modesettingPTR(crtc->scrn);
    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
587 588
    int i;
    uint32_t *ptr;
589

590 591 592 593 594
    /* cursor should be mapped already */
    ptr = (uint32_t *) (drmmode_crtc->cursor_bo->ptr);

    for (i = 0; i < ms->cursor_width * ms->cursor_height; i++)
        ptr[i] = image[i];      // cpu_to_le32(image[i]);
595

596 597
    if (drmmode_crtc->cursor_up)
        drmmode_set_cursor(crtc);
598 599 600
}

static void
601
drmmode_hide_cursor(xf86CrtcPtr crtc)
602
{
603 604 605 606
    modesettingPtr ms = modesettingPTR(crtc->scrn);
    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
    drmmode_ptr drmmode = drmmode_crtc->drmmode;

607 608
    drmmode_crtc->cursor_up = FALSE;
    drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, 0,
609
                     ms->cursor_width, ms->cursor_height);
610 611
}

612 613 614 615 616 617 618 619
static void
drmmode_show_cursor(xf86CrtcPtr crtc)
{
    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
    drmmode_crtc->cursor_up = TRUE;
    drmmode_set_cursor(crtc);
}

620
static void
621 622
drmmode_crtc_gamma_set(xf86CrtcPtr crtc, uint16_t * red, uint16_t * green,
                       uint16_t * blue, int size)
623
{
624 625
    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
    drmmode_ptr drmmode = drmmode_crtc->drmmode;
626

627 628
    drmModeCrtcSetGamma(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
                        size, red, green, blue);
629 630
}

631
static Bool
632 633 634 635 636 637
drmmode_set_scanout_pixmap_gpu(xf86CrtcPtr crtc, PixmapPtr ppix)
{
    ScreenPtr screen = xf86ScrnToScreen(crtc->scrn);
    PixmapPtr screenpix = screen->GetScreenPixmap(screen);
    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
638
    drmmode_ptr drmmode = drmmode_crtc->drmmode;
639 640 641
    int c, total_width = 0, max_height = 0, this_x = 0;

    if (!ppix) {
642
        if (crtc->randr_crtc->scanout_pixmap) {
643
            PixmapStopDirtyTracking(crtc->randr_crtc->scanout_pixmap, screenpix);
644 645 646 647 648
            if (drmmode->fb_id) {
                drmModeRmFB(drmmode->fd, drmmode->fb_id);
                drmmode->fb_id = 0;
            }
        }
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
        drmmode_crtc->prime_pixmap_x = 0;
        return TRUE;
    }
    /* iterate over all the attached crtcs to work out the bounding box */
    for (c = 0; c < xf86_config->num_crtc; c++) {
        xf86CrtcPtr iter = xf86_config->crtc[c];
        if (!iter->enabled && iter != crtc)
            continue;
        if (iter == crtc) {
            this_x = total_width;
            total_width += ppix->drawable.width;
            if (max_height < ppix->drawable.height)
                max_height = ppix->drawable.height;
        } else {
            total_width += iter->mode.HDisplay;
            if (max_height < iter->mode.VDisplay)
                max_height = iter->mode.VDisplay;
        }
    }

    if (total_width != screenpix->drawable.width ||
        max_height != screenpix->drawable.height) {

        if (!drmmode_xf86crtc_resize(crtc->scrn, total_width, max_height))
            return FALSE;

        screenpix = screen->GetScreenPixmap(screen);
        screen->width = screenpix->drawable.width = total_width;
        screen->height = screenpix->drawable.height = max_height;
    }
    drmmode_crtc->prime_pixmap_x = this_x;
680
    PixmapStartDirtyTracking(ppix, screenpix, 0, 0, this_x, 0, RR_Rotate_0);
681 682 683 684 685
    return TRUE;
}

static Bool
drmmode_set_scanout_pixmap_cpu(xf86CrtcPtr crtc, PixmapPtr ppix)
686
{
687 688 689 690 691 692 693 694 695
    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
    drmmode_ptr drmmode = drmmode_crtc->drmmode;
    msPixmapPrivPtr ppriv;
    void *ptr;

    if (!ppix) {
        if (crtc->randr_crtc->scanout_pixmap) {
            ppriv = msGetPixmapPriv(drmmode, crtc->randr_crtc->scanout_pixmap);
            drmModeRmFB(drmmode->fd, ppriv->fb_id);
696
            ppriv->fb_id = 0;
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
        }
        if (drmmode_crtc->slave_damage) {
            DamageUnregister(drmmode_crtc->slave_damage);
            drmmode_crtc->slave_damage = NULL;
        }
        return TRUE;
    }

    ppriv = msGetPixmapPriv(drmmode, ppix);
    if (!drmmode_crtc->slave_damage) {
        drmmode_crtc->slave_damage = DamageCreate(NULL, NULL,
                                                  DamageReportNone,
                                                  TRUE,
                                                  crtc->randr_crtc->pScreen,
                                                  NULL);
    }
    ptr = drmmode_map_slave_bo(drmmode, ppriv);
    ppix->devPrivate.ptr = ptr;
    DamageRegister(&ppix->drawable, drmmode_crtc->slave_damage);

    if (ppriv->fb_id == 0) {
        drmModeAddFB(drmmode->fd, ppix->drawable.width,
                     ppix->drawable.height,
                     ppix->drawable.depth,
                     ppix->drawable.bitsPerPixel,
                     ppix->devKind, ppriv->backing_bo->handle, &ppriv->fb_id);
    }
    return TRUE;
725 726
}

727 728 729 730 731 732 733 734 735 736 737 738
static Bool
drmmode_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix)
{
    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
    drmmode_ptr drmmode = drmmode_crtc->drmmode;

    if (drmmode->reverse_prime_offload_mode)
        return drmmode_set_scanout_pixmap_gpu(crtc, ppix);
    else
        return drmmode_set_scanout_pixmap_cpu(crtc, ppix);
}

739 740
static void *
drmmode_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
741
{
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788
    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
    drmmode_ptr drmmode = drmmode_crtc->drmmode;
    int ret;

    if (!drmmode_create_bo(drmmode, &drmmode_crtc->rotate_bo,
                           width, height, crtc->scrn->bitsPerPixel)) {
        xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR,
               "Couldn't allocate shadow memory for rotated CRTC\n");
        return NULL;
    }

    ret = drmModeAddFB(drmmode->fd, width, height, crtc->scrn->depth,
                       crtc->scrn->bitsPerPixel,
                       drmmode_bo_get_pitch(&drmmode_crtc->rotate_bo),
                       drmmode_bo_get_handle(&drmmode_crtc->rotate_bo),
                       &drmmode_crtc->rotate_fb_id);

    if (ret) {
        ErrorF("failed to add rotate fb\n");
        drmmode_bo_destroy(drmmode, &drmmode_crtc->rotate_bo);
        return NULL;
    }

#ifdef GLAMOR_HAS_GBM
    if (drmmode->gbm)
        return drmmode_crtc->rotate_bo.gbm;
#endif
    return drmmode_crtc->rotate_bo.dumb;
}

static PixmapPtr
drmmode_create_pixmap_header(ScreenPtr pScreen, int width, int height,
                             int depth, int bitsPerPixel, int devKind,
                             void *pPixData)
{
    PixmapPtr pixmap;

    /* width and height of 0 means don't allocate any pixmap data */
    pixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, depth, 0);

    if (pixmap) {
        if ((*pScreen->ModifyPixmapHeader)(pixmap, width, height, depth,
                                           bitsPerPixel, devKind, pPixData))
            return pixmap;
        (*pScreen->DestroyPixmap)(pixmap);
    }
    return NullPixmap;
789 790
}

791 792 793
static Bool
drmmode_set_pixmap_bo(drmmode_ptr drmmode, PixmapPtr pixmap, drmmode_bo *bo);

794 795
static PixmapPtr
drmmode_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height)
796
{
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856
    ScrnInfoPtr scrn = crtc->scrn;
    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
    drmmode_ptr drmmode = drmmode_crtc->drmmode;
    uint32_t rotate_pitch;
    PixmapPtr rotate_pixmap;
    void *pPixData = NULL;

    if (!data) {
        data = drmmode_shadow_allocate(crtc, width, height);
        if (!data) {
            xf86DrvMsg(scrn->scrnIndex, X_ERROR,
                       "Couldn't allocate shadow pixmap for rotated CRTC\n");
            return NULL;
        }
    }

    if (!drmmode_bo_has_bo(&drmmode_crtc->rotate_bo)) {
        xf86DrvMsg(scrn->scrnIndex, X_ERROR,
                   "Couldn't allocate shadow pixmap for rotated CRTC\n");
        return NULL;
    }

    pPixData = drmmode_bo_map(drmmode, &drmmode_crtc->rotate_bo);
    rotate_pitch = drmmode_bo_get_pitch(&drmmode_crtc->rotate_bo),

    rotate_pixmap = drmmode_create_pixmap_header(scrn->pScreen,
                                                 width, height,
                                                 scrn->depth,
                                                 scrn->bitsPerPixel,
                                                 rotate_pitch,
                                                 pPixData);

    if (rotate_pixmap == NULL) {
        xf86DrvMsg(scrn->scrnIndex, X_ERROR,
                   "Couldn't allocate shadow pixmap for rotated CRTC\n");
        return NULL;
    }

    drmmode_set_pixmap_bo(drmmode, rotate_pixmap, &drmmode_crtc->rotate_bo);

    return rotate_pixmap;
}

static void
drmmode_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data)
{
    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
    drmmode_ptr drmmode = drmmode_crtc->drmmode;

    if (rotate_pixmap) {
        rotate_pixmap->drawable.pScreen->DestroyPixmap(rotate_pixmap);
    }

    if (data) {
        drmModeRmFB(drmmode->fd, drmmode_crtc->rotate_fb_id);
        drmmode_crtc->rotate_fb_id = 0;

        drmmode_bo_destroy(drmmode, &drmmode_crtc->rotate_bo);
        memset(&drmmode_crtc->rotate_bo, 0, sizeof drmmode_crtc->rotate_bo);
    }
857 858
}

859 860 861 862 863 864 865 866 867 868
static const xf86CrtcFuncsRec drmmode_crtc_funcs = {
    .dpms = drmmode_crtc_dpms,
    .set_mode_major = drmmode_set_mode_major,
    .set_cursor_colors = drmmode_set_cursor_colors,
    .set_cursor_position = drmmode_set_cursor_position,
    .show_cursor = drmmode_show_cursor,
    .hide_cursor = drmmode_hide_cursor,
    .load_cursor_argb = drmmode_load_cursor_argb,

    .gamma_set = drmmode_crtc_gamma_set,
869
    .destroy = NULL,            /* XXX */
870
    .set_scanout_pixmap = drmmode_set_scanout_pixmap,
871 872
    .shadow_allocate = drmmode_shadow_allocate,
    .shadow_create = drmmode_shadow_create,
873
    .shadow_destroy = drmmode_shadow_destroy,
874 875
};

876 877 878 879 880 881 882 883 884 885 886
static uint32_t
drmmode_crtc_vblank_pipe(int crtc_id)
{
    if (crtc_id > 1)
        return crtc_id << DRM_VBLANK_HIGH_CRTC_SHIFT;
    else if (crtc_id > 0)
        return DRM_VBLANK_SECONDARY;
    else
        return 0;
}

887
static unsigned int
888
drmmode_crtc_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, drmModeResPtr mode_res, int num)
889
{
890 891
    xf86CrtcPtr crtc;
    drmmode_crtc_private_ptr drmmode_crtc;
892
    modesettingEntPtr ms_ent = ms_ent_priv(pScrn);
893 894 895

    crtc = xf86CrtcCreate(pScrn, &drmmode_crtc_funcs);
    if (crtc == NULL)
896
        return 0;
897 898 899

    drmmode_crtc = xnfcalloc(sizeof(drmmode_crtc_private_rec), 1);
    drmmode_crtc->mode_crtc =
900
        drmModeGetCrtc(drmmode->fd, mode_res->crtcs[num]);
901
    drmmode_crtc->drmmode = drmmode;
902
    drmmode_crtc->vblank_pipe = drmmode_crtc_vblank_pipe(num);
903
    crtc->driver_private = drmmode_crtc;
904 905 906 907 908 909 910

    /* Mark num'th crtc as in use on this device. */
    ms_ent->assigned_crtcs |= (1 << num);
    xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, MS_LOGLEVEL_DEBUG,
                   "Allocated crtc nr. %d to this screen.\n", num);

    return 1;
911 912 913 914 915
}

static xf86OutputStatus
drmmode_output_detect(xf86OutputPtr output)
{
916 917 918 919 920
    /* go to the hw and retrieve a new output struct */
    drmmode_output_private_ptr drmmode_output = output->driver_private;
    drmmode_ptr drmmode = drmmode_output->drmmode;
    xf86OutputStatus status;

921 922 923
    if (drmmode_output->output_id == -1)
        return XF86OutputStatusDisconnected;

924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943
    drmModeFreeConnector(drmmode_output->mode_output);

    drmmode_output->mode_output =
        drmModeGetConnector(drmmode->fd, drmmode_output->output_id);
    if (!drmmode_output->mode_output)
        return XF86OutputStatusDisconnected;

    switch (drmmode_output->mode_output->connection) {
    case DRM_MODE_CONNECTED:
        status = XF86OutputStatusConnected;
        break;
    case DRM_MODE_DISCONNECTED:
        status = XF86OutputStatusDisconnected;
        break;
    default:
    case DRM_MODE_UNKNOWNCONNECTION:
        status = XF86OutputStatusUnknown;
        break;
    }
    return status;
944 945 946 947 948
}

static Bool
drmmode_output_mode_valid(xf86OutputPtr output, DisplayModePtr pModes)
{
949
    return MODE_OK;
950 951
}

952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991
static void
drmmode_output_attach_tile(xf86OutputPtr output)
{
    drmmode_output_private_ptr drmmode_output = output->driver_private;
    drmModeConnectorPtr koutput = drmmode_output->mode_output;
    drmmode_ptr drmmode = drmmode_output->drmmode;
    int i;
    struct xf86CrtcTileInfo tile_info, *set = NULL;

    if (!koutput) {
        xf86OutputSetTile(output, NULL);
        return;
    }

    /* look for a TILE property */
    for (i = 0; i < koutput->count_props; i++) {
        drmModePropertyPtr props;
        props = drmModeGetProperty(drmmode->fd, koutput->props[i]);
        if (!props)
            continue;

        if (!(props->flags & DRM_MODE_PROP_BLOB)) {
            drmModeFreeProperty(props);
            continue;
        }

        if (!strcmp(props->name, "TILE")) {
            drmModeFreePropertyBlob(drmmode_output->tile_blob);
            drmmode_output->tile_blob =
                drmModeGetPropertyBlob(drmmode->fd, koutput->prop_values[i]);
        }
        drmModeFreeProperty(props);
    }
    if (drmmode_output->tile_blob) {
        if (xf86OutputParseKMSTile(drmmode_output->tile_blob->data, drmmode_output->tile_blob->length, &tile_info) == TRUE)
            set = &tile_info;
    }
    xf86OutputSetTile(output, set);
}

Chris Wilson's avatar
Chris Wilson committed
992 993 994
static Bool
has_panel_fitter(xf86OutputPtr output)
{
995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017
    drmmode_output_private_ptr drmmode_output = output->driver_private;
    drmModeConnectorPtr koutput = drmmode_output->mode_output;
    drmmode_ptr drmmode = drmmode_output->drmmode;
    int i;

    /* Presume that if the output supports scaling, then we have a
     * panel fitter capable of adjust any mode to suit.
     */
    for (i = 0; i < koutput->count_props; i++) {
        drmModePropertyPtr props;
        Bool found = FALSE;

        props = drmModeGetProperty(drmmode->fd, koutput->props[i]);
        if (props) {
            found = strcmp(props->name, "scaling mode") == 0;
            drmModeFreeProperty(props);
        }

        if (found)
            return TRUE;
    }

    return FALSE;
Chris Wilson's avatar
Chris Wilson committed
1018 1019 1020
}

static DisplayModePtr
1021
drmmode_output_add_gtf_modes(xf86OutputPtr output, DisplayModePtr Modes)
Chris Wilson's avatar
Chris Wilson committed
1022
{
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
    xf86MonPtr mon = output->MonInfo;
    DisplayModePtr i, m, preferred = NULL;
    int max_x = 0, max_y = 0;
    float max_vrefresh = 0.0;

    if (mon && GTF_SUPPORTED(mon->features.msc))
        return Modes;

    if (!has_panel_fitter(output))
        return Modes;

    for (m = Modes; m; m = m->next) {
        if (m->type & M_T_PREFERRED)
            preferred = m;
        max_x = max(max_x, m->HDisplay);
        max_y = max(max_y, m->VDisplay);
        max_vrefresh = max(max_vrefresh, xf86ModeVRefresh(m));
    }

    max_vrefresh = max(max_vrefresh, 60.0);
    max_vrefresh *= (1 + SYNC_TOLERANCE);

    m = xf86GetDefaultModes();
    xf86ValidateModesSize(output->scrn, m, max_x, max_y, 0);

    for (i = m; i; i = i->next) {
        if (xf86ModeVRefresh(i) > max_vrefresh)
            i->status = MODE_VSYNC;
        if (preferred &&
            i->HDisplay >= preferred->HDisplay &&
            i->VDisplay >= preferred->VDisplay &&
            xf86ModeVRefresh(i) >= xf86ModeVRefresh(preferred))
            i->status = MODE_VSYNC;
    }

    xf86PruneInvalidModes(output->scrn, &m, FALSE);

    return xf86ModesAdd(Modes, m);
Chris Wilson's avatar
Chris Wilson committed
1061 1062
}

1063 1064 1065
static DisplayModePtr
drmmode_output_get_modes(xf86OutputPtr output)
{
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
    drmmode_output_private_ptr drmmode_output = output->driver_private;
    drmModeConnectorPtr koutput = drmmode_output->mode_output;
    drmmode_ptr drmmode = drmmode_output->drmmode;
    int i;
    DisplayModePtr Modes = NULL, Mode;
    drmModePropertyPtr props;
    xf86MonPtr mon = NULL;

    if (!koutput)
        return NULL;

    /* look for an EDID property */
    for (i = 0; i < koutput->count_props; i++) {
        props = drmModeGetProperty(drmmode->fd, koutput->props[i]);
        if (props && (props->flags & DRM_MODE_PROP_BLOB)) {
            if (!strcmp(props->name, "EDID")) {
                if (drmmode_output->edid_blob)
                    drmModeFreePropertyBlob(drmmode_output->edid_blob);
                drmmode_output->edid_blob =
                    drmModeGetPropertyBlob(drmmode->fd,
                                           koutput->prop_values[i]);
            }
            drmModeFreeProperty(props);
        }
    }

    if (drmmode_output->edid_blob) {
        mon = xf86InterpretEDID(output->scrn->scrnIndex,
                                drmmode_output->edid_blob->data);
        if (mon && drmmode_output->edid_blob->length > 128)
            mon->flags |= MONITOR_EDID_COMPLETE_RAWDATA;
    }
    xf86OutputSetEDID(output, mon);

1100 1101
    drmmode_output_attach_tile(output);

1102 1103 1104 1105 1106 1107 1108 1109 1110 1111
    /* modes should already be available */
    for (i = 0; i < koutput->count_modes; i++) {
        Mode = xnfalloc(sizeof(DisplayModeRec));

        drmmode_ConvertFromKMode(output->scrn, &koutput->modes[i], Mode);
        Modes = xf86ModesAdd(Modes, Mode);

    }

    return drmmode_output_add_gtf_modes(output, Modes);
1112 1113 1114 1115 1116
}

static void
drmmode_output_destroy(xf86OutputPtr output)
{
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
    drmmode_output_private_ptr drmmode_output = output->driver_private;
    int i;

    if (drmmode_output->edid_blob)
        drmModeFreePropertyBlob(drmmode_output->edid_blob);
    for (i = 0; i < drmmode_output->num_props; i++) {
        drmModeFreeProperty(drmmode_output->props[i].mode_prop);
        free(drmmode_output->props[i].atoms);
    }
    free(drmmode_output->props);
1127 1128 1129 1130 1131
    if (drmmode_output->mode_output) {
        for (i = 0; i < drmmode_output->mode_output->count_encoders; i++) {
            drmModeFreeEncoder(drmmode_output->mode_encoders[i]);
        }
        drmModeFreeConnector(drmmode_output->mode_output);
1132 1133 1134 1135
    }
    free(drmmode_output->mode_encoders);
    free(drmmode_output);
    output->driver_private = NULL;
1136 1137 1138 1139 1140
}

static void
drmmode_output_dpms(xf86OutputPtr output, int mode)
{
1141
    drmmode_output_private_ptr drmmode_output = output->driver_private;
1142
    xf86CrtcPtr crtc = output->crtc;
1143 1144
    drmModeConnectorPtr koutput = drmmode_output->mode_output;
    drmmode_ptr drmmode = drmmode_output->drmmode;
1145

1146 1147
    if (!koutput)
        return;
1148

1149 1150
    drmModeConnectorSetProperty(drmmode->fd, koutput->connector_id,
                                drmmode_output->dpms_enum_id, mode);
1151 1152 1153 1154 1155 1156 1157

    if (mode == DPMSModeOn && crtc) {
        drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
        if (drmmode_crtc->need_modeset)
            drmmode_set_mode_major(crtc, &crtc->mode, crtc->rotation,
                                   crtc->x, crtc->y);
    }
1158
    return;
1159 1160 1161 1162 1163 1164
}

static Bool
drmmode_property_ignore(drmModePropertyPtr prop)
{
    if (!prop)
1165
        return TRUE;
1166 1167
    /* ignore blob prop */
    if (prop->flags & DRM_MODE_PROP_BLOB)
1168
        return TRUE;
1169
    /* ignore standard property */
1170 1171
    if (!strcmp(prop->name, "EDID") || !strcmp(prop->name, "DPMS"))
        return TRUE;
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184

    return FALSE;
}

static void
drmmode_output_create_resources(xf86OutputPtr output)
{
    drmmode_output_private_ptr drmmode_output = output->driver_private;
    drmModeConnectorPtr mode_output = drmmode_output->mode_output;
    drmmode_ptr drmmode = drmmode_output->drmmode;
    drmModePropertyPtr drmmode_prop;
    int i, j, err;

1185 1186
    drmmode_output->props =
        calloc(mode_output->count_props, sizeof(drmmode_prop_rec));
1187
    if (!drmmode_output->props)
1188 1189
        return;

1190 1191
    drmmode_output->num_props = 0;
    for (i = 0, j = 0; i < mode_output->count_props; i++) {
1192 1193 1194 1195 1196 1197 1198 1199 1200
        drmmode_prop = drmModeGetProperty(drmmode->fd, mode_output->props[i]);
        if (drmmode_property_ignore(drmmode_prop)) {
            drmModeFreeProperty(drmmode_prop);
            continue;
        }
        drmmode_output->props[j].mode_prop = drmmode_prop;
        drmmode_output->props[j].value = mode_output->prop_values[i];
        drmmode_output->num_props++;
        j++;
1201 1202 1203
    }

    for (i = 0; i < drmmode_output->num_props; i++) {
1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270
        drmmode_prop_ptr p = &drmmode_output->props[i];

        drmmode_prop = p->mode_prop;

        if (drmmode_prop->flags & DRM_MODE_PROP_RANGE) {
            INT32 prop_range[2];
            INT32 value = p->value;

            p->num_atoms = 1;
            p->atoms = calloc(p->num_atoms, sizeof(Atom));
            if (!p->atoms)
                continue;
            p->atoms[0] =
                MakeAtom(drmmode_prop->name, strlen(drmmode_prop->name), TRUE);
            prop_range[0] = drmmode_prop->values[0];
            prop_range[1] = drmmode_prop->values[1];
            err = RRConfigureOutputProperty(output->randr_output, p->atoms[0],
                                            FALSE, TRUE,
                                            drmmode_prop->
                                            flags & DRM_MODE_PROP_IMMUTABLE ?
                                            TRUE : FALSE, 2, prop_range);
            if (err != 0) {
                xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
                           "RRConfigureOutputProperty error, %d\n", err);
            }
            err = RRChangeOutputProperty(output->randr_output, p->atoms[0],
                                         XA_INTEGER, 32, PropModeReplace, 1,
                                         &value, FALSE, TRUE);
            if (err != 0) {
                xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
                           "RRChangeOutputProperty error, %d\n", err);
            }
        }
        else if (drmmode_prop->flags & DRM_MODE_PROP_ENUM) {
            p->num_atoms = drmmode_prop->count_enums + 1;
            p