diff options
author | Matthieu Herrb <matthieu@cvs.openbsd.org> | 2020-12-12 09:31:01 +0000 |
---|---|---|
committer | Matthieu Herrb <matthieu@cvs.openbsd.org> | 2020-12-12 09:31:01 +0000 |
commit | de1becf4e6fef4f4af7ddcce36b218eb8b97e953 (patch) | |
tree | 6c9ca26361bcdb5ff8552163eef21caa9a15c4f7 /xserver/hw/xfree86/drivers/modesetting | |
parent | 547f94c1bd5f859fdb141297f602245d127f205b (diff) |
Update X server to version 1.20.10. Tested by jsg@ and naddy@
Diffstat (limited to 'xserver/hw/xfree86/drivers/modesetting')
-rw-r--r-- | xserver/hw/xfree86/drivers/modesetting/Makefile.in | 1 | ||||
-rw-r--r-- | xserver/hw/xfree86/drivers/modesetting/dri2.c | 1 | ||||
-rw-r--r-- | xserver/hw/xfree86/drivers/modesetting/driver.c | 49 | ||||
-rw-r--r-- | xserver/hw/xfree86/drivers/modesetting/driver.h | 1 | ||||
-rw-r--r-- | xserver/hw/xfree86/drivers/modesetting/drmmode_display.c | 225 | ||||
-rw-r--r-- | xserver/hw/xfree86/drivers/modesetting/drmmode_display.h | 16 | ||||
-rw-r--r-- | xserver/hw/xfree86/drivers/modesetting/present.c | 33 |
7 files changed, 238 insertions, 88 deletions
diff --git a/xserver/hw/xfree86/drivers/modesetting/Makefile.in b/xserver/hw/xfree86/drivers/modesetting/Makefile.in index 54f1779dc..aaa95a521 100644 --- a/xserver/hw/xfree86/drivers/modesetting/Makefile.in +++ b/xserver/hw/xfree86/drivers/modesetting/Makefile.in @@ -566,6 +566,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sdkdir = @sdkdir@ sharedstatedir = @sharedstatedir@ diff --git a/xserver/hw/xfree86/drivers/modesetting/dri2.c b/xserver/hw/xfree86/drivers/modesetting/dri2.c index 167814015..c0799896c 100644 --- a/xserver/hw/xfree86/drivers/modesetting/dri2.c +++ b/xserver/hw/xfree86/drivers/modesetting/dri2.c @@ -586,6 +586,7 @@ can_flip(ScrnInfoPtr scrn, DrawablePtr draw, return draw->type == DRAWABLE_WINDOW && ms->drmmode.pageflip && + !ms->drmmode.sprites_visible && !ms->drmmode.present_flipping && scrn->vtSema && DRI2CanFlip(draw) && can_exchange(scrn, draw, front, back); diff --git a/xserver/hw/xfree86/drivers/modesetting/driver.c b/xserver/hw/xfree86/drivers/modesetting/driver.c index d37c0d282..f11f44d5e 100644 --- a/xserver/hw/xfree86/drivers/modesetting/driver.c +++ b/xserver/hw/xfree86/drivers/modesetting/driver.c @@ -41,6 +41,7 @@ #include "compiler.h" #include "xf86Pci.h" #include "mipointer.h" +#include "mipointrst.h" #include "micmap.h" #include <X11/extensions/randr.h> #include "fb.h" @@ -710,7 +711,7 @@ msBlockHandler_oneshot(ScreenPtr pScreen, void *pTimeout) msBlockHandler(pScreen, pTimeout); - drmmode_set_desired_modes(pScrn, &ms->drmmode, TRUE); + drmmode_set_desired_modes(pScrn, &ms->drmmode, TRUE, FALSE); } static void @@ -1353,7 +1354,7 @@ CreateScreenResources(ScreenPtr pScreen) ret = pScreen->CreateScreenResources(pScreen); pScreen->CreateScreenResources = CreateScreenResources; - if (!drmmode_set_desired_modes(pScrn, &ms->drmmode, pScrn->is_gpu)) + if (!drmmode_set_desired_modes(pScrn, &ms->drmmode, pScrn->is_gpu, FALSE)) return FALSE; if (!drmmode_glamor_handle_new_screen_pixmap(&ms->drmmode)) @@ -1662,6 +1663,21 @@ ScreenInit(ScreenPtr pScreen, int argc, char **argv) xf86SetSilkenMouse(pScreen); miDCInitialize(pScreen, xf86GetPointerScreenFuncs()); + /* If pageflip is enabled hook the screen's cursor-sprite (swcursor) funcs. + * So that we can disabe page-flipping on fallback to a swcursor. */ + if (ms->drmmode.pageflip) { + miPointerScreenPtr PointPriv = + dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey); + + if (!dixRegisterScreenPrivateKey(&ms->drmmode.spritePrivateKeyRec, + pScreen, PRIVATE_DEVICE, + sizeof(msSpritePrivRec))) + return FALSE; + + ms->SpriteFuncs = PointPriv->spriteFuncs; + PointPriv->spriteFuncs = &drmmode_sprite_funcs; + } + /* Need to extend HWcursor support to handle mask interleave */ if (!ms->drmmode.sw_cursor) xf86_cursors_init(pScreen, ms->cursor_width, ms->cursor_height, @@ -1810,8 +1826,25 @@ EnterVT(ScrnInfoPtr pScrn) SetMaster(pScrn); - if (!drmmode_set_desired_modes(pScrn, &ms->drmmode, TRUE)) - return FALSE; + drmmode_update_kms_state(&ms->drmmode); + + /* allow not all modes to be set successfully since some events might have + * happened while not being master that could prevent the previous + * configuration from being re-applied. + */ + if (!drmmode_set_desired_modes(pScrn, &ms->drmmode, TRUE, TRUE)) { + xf86DisableUnusedFunctions(pScrn); + + /* TODO: check that at least one screen is on, to allow the user to fix + * their setup if all modeset failed... + */ + + /* Tell the desktop environment that something changed, so that they + * can hopefully correct the situation + */ + RRSetChanged(xf86ScrnToScreen(pScrn)); + RRTellChanged(xf86ScrnToScreen(pScrn)); + } return TRUE; } @@ -1858,6 +1891,14 @@ CloseScreen(ScreenPtr pScreen) drmmode_free_bos(pScrn, &ms->drmmode); + if (ms->drmmode.pageflip) { + miPointerScreenPtr PointPriv = + dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey); + + if (PointPriv->spriteFuncs == &drmmode_sprite_funcs) + PointPriv->spriteFuncs = ms->SpriteFuncs; + } + if (pScrn->vtSema) { LeaveVT(pScrn); } diff --git a/xserver/hw/xfree86/drivers/modesetting/driver.h b/xserver/hw/xfree86/drivers/modesetting/driver.h index 8bfb2fc1a..f2e7889db 100644 --- a/xserver/hw/xfree86/drivers/modesetting/driver.h +++ b/xserver/hw/xfree86/drivers/modesetting/driver.h @@ -97,6 +97,7 @@ typedef struct _modesettingRec { CreateScreenResourcesProcPtr createScreenResources; ScreenBlockHandlerProcPtr BlockHandler; + miPointerSpriteFuncPtr SpriteFuncs; void *driver; drmmode_rec drmmode; diff --git a/xserver/hw/xfree86/drivers/modesetting/drmmode_display.c b/xserver/hw/xfree86/drivers/modesetting/drmmode_display.c index 9a960e3c6..492f2238d 100644 --- a/xserver/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/xserver/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -37,6 +37,7 @@ #endif #include <unistd.h> #include "dumb_bo.h" +#include "inputstr.h" #include "xf86str.h" #include "X11/Xatom.h" #include "mi.h" @@ -2441,7 +2442,7 @@ drmmode_output_add_gtf_modes(xf86OutputPtr output, DisplayModePtr Modes) int max_x = 0, max_y = 0; float max_vrefresh = 0.0; - if (mon && GTF_SUPPORTED(mon->features.msc)) + if (mon && gtf_supported(mon)) return Modes; if (!has_panel_fitter(output)) @@ -2601,8 +2602,6 @@ drmmode_property_ignore(drmModePropertyPtr prop) return FALSE; } -static Atom backlight_atom; - static void drmmode_output_create_resources(xf86OutputPtr output) { @@ -2722,9 +2721,6 @@ drmmode_output_create_resources(xf86OutputPtr output) } } } - - backlight_atom = MakeAtom(RR_PROPERTY_BACKLIGHT, - strlen(RR_PROPERTY_BACKLIGHT), FALSE); } static Bool @@ -2784,48 +2780,7 @@ drmmode_output_set_property(xf86OutputPtr output, Atom property, static Bool drmmode_output_get_property(xf86OutputPtr output, Atom property) { - drmmode_output_private_ptr drmmode_output = output->driver_private; - drmmode_ptr drmmode = drmmode_output->drmmode; - drmModeObjectPropertiesPtr props; - int i; - - if (property != backlight_atom) - return TRUE; - - props = drmModeObjectGetProperties(drmmode->fd, drmmode_output->output_id, - DRM_MODE_OBJECT_CONNECTOR); - if (!props) - return FALSE; - - for (i = 0; i < drmmode_output->num_props; i++) { - drmmode_prop_ptr p = &drmmode_output->props[i]; - int j; - - if (p->atoms[0] != property) - continue; - - for (j = 0; j < props->count_props; j++) { - if (props->props[j] == p->mode_prop->prop_id) { - INT32 value; - int err; - - value = p->value = props->prop_values[j]; - 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); - } - - drmModeFreeObjectProperties(props); - return TRUE; - } - } - } - - drmModeFreeObjectProperties(props); - return FALSE; + return TRUE; } static const xf86OutputFuncsRec drmmode_output_funcs = { @@ -3254,10 +3209,10 @@ drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height) crtc->rotation, crtc->x, crtc->y); } - if (old_fb_id) { + if (old_fb_id) drmModeRmFB(drmmode->fd, old_fb_id); - drmmode_bo_destroy(drmmode, &old_front); - } + + drmmode_bo_destroy(drmmode, &old_front); return TRUE; @@ -3505,9 +3460,11 @@ drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y) } Bool -drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode, Bool set_hw) +drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode, Bool set_hw, + Bool ign_err) { xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + Bool success = TRUE; int c; for (c = 0; c < config->num_crtc; c++) { @@ -3555,8 +3512,17 @@ drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode, Bool set_hw) if (set_hw) { if (!crtc->funcs-> set_mode_major(crtc, &crtc->desiredMode, crtc->desiredRotation, - crtc->desiredX, crtc->desiredY)) - return FALSE; + crtc->desiredX, crtc->desiredY)) { + if (!ign_err) + return FALSE; + else { + success = FALSE; + crtc->enabled = FALSE; + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, + "Failed to set the desired mode on connector %s\n", + output->name); + } + } } else { crtc->mode = crtc->desiredMode; crtc->rotation = crtc->desiredRotation; @@ -3570,7 +3536,7 @@ drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode, Bool set_hw) /* Validate leases on VT re-entry */ drmmode_validate_leases(pScrn); - return TRUE; + return success; } static void @@ -3655,39 +3621,19 @@ drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn) return TRUE; } -#if defined(CONFIG_UDEV_KMS) || defined(CONFIG_KEVENT_KMS) - #define DRM_MODE_LINK_STATUS_GOOD 0 #define DRM_MODE_LINK_STATUS_BAD 1 -static void -drmmode_handle_uevents(int fd, void *closure) +void +drmmode_update_kms_state(drmmode_ptr drmmode) { - drmmode_ptr drmmode = closure; ScrnInfoPtr scrn = drmmode->scrn; -#ifdef CONFIG_UDEV_KMS - struct udev_device *dev; -#endif drmModeResPtr mode_res; xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); int i, j; Bool found = FALSE; Bool changed = FALSE; -#ifdef CONFIG_UDEV_KMS - while ((dev = udev_monitor_receive_device(drmmode->uevent_monitor))) { - udev_device_unref(dev); - found = TRUE; - } -#else - struct kevent ev; - if ((kevent(fd, NULL, 0, &ev, 1, NULL)) && ev.fflags & NOTE_CHANGE) - found = TRUE; -#endif - - if (!found) - return; - /* Try to re-set the mode on all the connectors with a BAD link-state: * This may happen if a link degrades and a new modeset is necessary, using * different link-training parameters. If the kernel found that the current @@ -3802,6 +3748,32 @@ out: #undef DRM_MODE_LINK_STATUS_BAD #undef DRM_MODE_LINK_STATUS_GOOD +#if defined(CONFIG_UDEV_KMS) || defined(CONFIG_KEVENT_KMS) + +static void +drmmode_handle_uevents(int fd, void *closure) +{ + drmmode_ptr drmmode = closure; + struct udev_device *dev; + Bool found = FALSE; + +#ifdef CONFIG_UDEV_KMS + while ((dev = udev_monitor_receive_device(drmmode->uevent_monitor))) { + udev_device_unref(dev); + found = TRUE; + } +#else + struct kevent ev; + if ((kevent(fd, NULL, 0, &ev, 1, NULL)) && ev.fflags & NOTE_CHANGE) + found = TRUE; +#endif + + if (!found) + return; + + drmmode_update_kms_state(drmmode); +} + #endif void @@ -4021,3 +3993,102 @@ drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int *depth, drmModeFreeResources(mode_res); return; } + +/* + * We hook the screen's cursor-sprite (swcursor) functions to see if a swcursor + * is active. When a swcursor is active we disabe page-flipping. + */ + +static void drmmode_sprite_do_set_cursor(msSpritePrivPtr sprite_priv, + ScrnInfoPtr scrn, int x, int y) +{ + modesettingPtr ms = modesettingPTR(scrn); + CursorPtr cursor = sprite_priv->cursor; + Bool sprite_visible = sprite_priv->sprite_visible; + + if (cursor) { + x -= cursor->bits->xhot; + y -= cursor->bits->yhot; + + sprite_priv->sprite_visible = + x < scrn->virtualX && y < scrn->virtualY && + (x + cursor->bits->width > 0) && + (y + cursor->bits->height > 0); + } else { + sprite_priv->sprite_visible = FALSE; + } + + ms->drmmode.sprites_visible += sprite_priv->sprite_visible - sprite_visible; +} + +static void drmmode_sprite_set_cursor(DeviceIntPtr pDev, ScreenPtr pScreen, + CursorPtr pCursor, int x, int y) +{ + ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); + modesettingPtr ms = modesettingPTR(scrn); + msSpritePrivPtr sprite_priv = msGetSpritePriv(pDev, ms, pScreen); + + sprite_priv->cursor = pCursor; + drmmode_sprite_do_set_cursor(sprite_priv, scrn, x, y); + + ms->SpriteFuncs->SetCursor(pDev, pScreen, pCursor, x, y); +} + +static void drmmode_sprite_move_cursor(DeviceIntPtr pDev, ScreenPtr pScreen, + int x, int y) +{ + ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); + modesettingPtr ms = modesettingPTR(scrn); + msSpritePrivPtr sprite_priv = msGetSpritePriv(pDev, ms, pScreen); + + drmmode_sprite_do_set_cursor(sprite_priv, scrn, x, y); + + ms->SpriteFuncs->MoveCursor(pDev, pScreen, x, y); +} + +static Bool drmmode_sprite_realize_realize_cursor(DeviceIntPtr pDev, + ScreenPtr pScreen, + CursorPtr pCursor) +{ + ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); + modesettingPtr ms = modesettingPTR(scrn); + + return ms->SpriteFuncs->RealizeCursor(pDev, pScreen, pCursor); +} + +static Bool drmmode_sprite_realize_unrealize_cursor(DeviceIntPtr pDev, + ScreenPtr pScreen, + CursorPtr pCursor) +{ + ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); + modesettingPtr ms = modesettingPTR(scrn); + + return ms->SpriteFuncs->UnrealizeCursor(pDev, pScreen, pCursor); +} + +static Bool drmmode_sprite_device_cursor_initialize(DeviceIntPtr pDev, + ScreenPtr pScreen) +{ + ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); + modesettingPtr ms = modesettingPTR(scrn); + + return ms->SpriteFuncs->DeviceCursorInitialize(pDev, pScreen); +} + +static void drmmode_sprite_device_cursor_cleanup(DeviceIntPtr pDev, + ScreenPtr pScreen) +{ + ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); + modesettingPtr ms = modesettingPTR(scrn); + + ms->SpriteFuncs->DeviceCursorCleanup(pDev, pScreen); +} + +miPointerSpriteFuncRec drmmode_sprite_funcs = { + .RealizeCursor = drmmode_sprite_realize_realize_cursor, + .UnrealizeCursor = drmmode_sprite_realize_unrealize_cursor, + .SetCursor = drmmode_sprite_set_cursor, + .MoveCursor = drmmode_sprite_move_cursor, + .DeviceCursorInitialize = drmmode_sprite_device_cursor_initialize, + .DeviceCursorCleanup = drmmode_sprite_device_cursor_cleanup, +}; diff --git a/xserver/hw/xfree86/drivers/modesetting/drmmode_display.h b/xserver/hw/xfree86/drivers/modesetting/drmmode_display.h index 7a5e98431..73d97193c 100644 --- a/xserver/hw/xfree86/drivers/modesetting/drmmode_display.h +++ b/xserver/hw/xfree86/drivers/modesetting/drmmode_display.h @@ -114,6 +114,9 @@ typedef struct { void *shadow_fb2; DevPrivateKeyRec pixmapPrivateKeyRec; + DevScreenPrivateKeyRec spritePrivateKeyRec; + /* Number of SW cursors currently visible on this screen */ + int sprites_visible; Bool reverse_prime_offload_mode; @@ -245,6 +248,15 @@ extern DevPrivateKeyRec msPixmapPrivateKeyRec; #define msGetPixmapPriv(drmmode, p) ((msPixmapPrivPtr)dixGetPrivateAddr(&(p)->devPrivates, &(drmmode)->pixmapPrivateKeyRec)) +typedef struct _msSpritePriv { + CursorPtr cursor; + Bool sprite_visible; +} msSpritePrivRec, *msSpritePrivPtr; + +#define msGetSpritePriv(dev, ms, screen) dixLookupScreenPrivate(&(dev)->devPrivates, &(ms)->drmmode.spritePrivateKeyRec, screen) + +extern miPointerSpriteFuncRec drmmode_sprite_funcs; + Bool drmmode_is_format_supported(ScrnInfoPtr scrn, uint32_t format, uint64_t modifier); int drmmode_bo_import(drmmode_ptr drmmode, drmmode_bo *bo, @@ -269,9 +281,11 @@ void drmmode_DisableSharedPixmapFlipping(xf86CrtcPtr crtc, drmmode_ptr drmmode); extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp); extern Bool drmmode_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode); void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y); -extern Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode, Bool set_hw); +extern Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode, + Bool set_hw, Bool ign_err); extern Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn); +extern void drmmode_update_kms_state(drmmode_ptr drmmode); extern void drmmode_uevent_init(ScrnInfoPtr scrn, drmmode_ptr drmmode); extern void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode); diff --git a/xserver/hw/xfree86/drivers/modesetting/present.c b/xserver/hw/xfree86/drivers/modesetting/present.c index ab79fe778..009a0790c 100644 --- a/xserver/hw/xfree86/drivers/modesetting/present.c +++ b/xserver/hw/xfree86/drivers/modesetting/present.c @@ -208,13 +208,17 @@ ms_present_flip_abort(modesettingPtr ms, void *data) /* * Test to see if page flipping is possible on the target crtc + * + * We ignore sw-cursors when *disabling* flipping, we may very well be + * returning to scanning out the normal framebuffer *because* we just + * switched to sw-cursor mode and check_flip just failed because of that. */ static Bool -ms_present_check_flip(RRCrtcPtr crtc, - WindowPtr window, - PixmapPtr pixmap, - Bool sync_flip, - PresentFlipReason *reason) +ms_present_check_unflip(RRCrtcPtr crtc, + WindowPtr window, + PixmapPtr pixmap, + Bool sync_flip, + PresentFlipReason *reason) { ScreenPtr screen = window->drawable.pScreen; ScrnInfoPtr scrn = xf86ScreenToScrn(screen); @@ -281,6 +285,23 @@ ms_present_check_flip(RRCrtcPtr crtc, return TRUE; } +static Bool +ms_present_check_flip(RRCrtcPtr crtc, + WindowPtr window, + PixmapPtr pixmap, + Bool sync_flip, + PresentFlipReason *reason) +{ + ScreenPtr screen = window->drawable.pScreen; + ScrnInfoPtr scrn = xf86ScreenToScrn(screen); + modesettingPtr ms = modesettingPTR(scrn); + + if (ms->drmmode.sprites_visible > 0) + return FALSE; + + return ms_present_check_unflip(crtc, window, pixmap, sync_flip, reason); +} + /* * Queue a flip on 'crtc' to 'pixmap' at 'target_msc'. If 'sync_flip' is true, * then wait for vblank. Otherwise, flip immediately @@ -343,7 +364,7 @@ ms_present_unflip(ScreenPtr screen, uint64_t event_id) event->event_id = event_id; event->unflip = TRUE; - if (ms_present_check_flip(NULL, screen->root, pixmap, TRUE, NULL) && + if (ms_present_check_unflip(NULL, screen->root, pixmap, TRUE, NULL) && ms_do_pageflip(screen, pixmap, event, -1, FALSE, ms_present_flip_handler, ms_present_flip_abort)) { return; |