1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. 3*4882a593Smuzhiyun * All Rights Reserved. 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining a 6*4882a593Smuzhiyun * copy of this software and associated documentation files (the 7*4882a593Smuzhiyun * "Software"), to deal in the Software without restriction, including 8*4882a593Smuzhiyun * without limitation the rights to use, copy, modify, merge, publish, 9*4882a593Smuzhiyun * distribute, sub license, and/or sell copies of the Software, and to 10*4882a593Smuzhiyun * permit persons to whom the Software is furnished to do so, subject to 11*4882a593Smuzhiyun * the following conditions: 12*4882a593Smuzhiyun * 13*4882a593Smuzhiyun * The above copyright notice and this permission notice (including the 14*4882a593Smuzhiyun * next paragraph) shall be included in all copies or substantial portions 15*4882a593Smuzhiyun * of the Software. 16*4882a593Smuzhiyun * 17*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18*4882a593Smuzhiyun * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19*4882a593Smuzhiyun * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20*4882a593Smuzhiyun * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 21*4882a593Smuzhiyun * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22*4882a593Smuzhiyun * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23*4882a593Smuzhiyun * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24*4882a593Smuzhiyun * 25*4882a593Smuzhiyun * 26*4882a593Smuzhiyun * Author: Alan Hourihane <alanh@tungstengraphics.com> 27*4882a593Smuzhiyun * 28*4882a593Smuzhiyun */ 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun #include <errno.h> 31*4882a593Smuzhiyun #include <drm.h> 32*4882a593Smuzhiyun #include <xf86drm.h> 33*4882a593Smuzhiyun #include <xf86xv.h> 34*4882a593Smuzhiyun #include <xf86Crtc.h> 35*4882a593Smuzhiyun #include <damage.h> 36*4882a593Smuzhiyun #include <X11/extensions/dpmsconst.h> 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun #ifdef GLAMOR_HAS_GBM 39*4882a593Smuzhiyun #define GLAMOR_FOR_XORG 1 40*4882a593Smuzhiyun #include "glamor.h" 41*4882a593Smuzhiyun #include <gbm.h> 42*4882a593Smuzhiyun #endif 43*4882a593Smuzhiyun 44*4882a593Smuzhiyun #include "drmmode_display.h" 45*4882a593Smuzhiyun #define MS_LOGLEVEL_DEBUG 4 46*4882a593Smuzhiyun 47*4882a593Smuzhiyun typedef enum { 48*4882a593Smuzhiyun OPTION_SW_CURSOR, 49*4882a593Smuzhiyun OPTION_DEVICE_PATH, 50*4882a593Smuzhiyun OPTION_SHADOW_FB, 51*4882a593Smuzhiyun OPTION_ACCEL_METHOD, 52*4882a593Smuzhiyun OPTION_PAGEFLIP, 53*4882a593Smuzhiyun OPTION_ZAPHOD_HEADS, 54*4882a593Smuzhiyun OPTION_DOUBLE_SHADOW, 55*4882a593Smuzhiyun OPTION_ATOMIC, 56*4882a593Smuzhiyun OPTION_USE_GAMMA_LUT, 57*4882a593Smuzhiyun OPTION_FLIP_FB, 58*4882a593Smuzhiyun OPTION_FLIP_FB_RATE, 59*4882a593Smuzhiyun OPTION_BIND_CURRENT, 60*4882a593Smuzhiyun OPTION_NO_EDID, 61*4882a593Smuzhiyun OPTION_HOTPLUG_RESET, 62*4882a593Smuzhiyun OPTION_WARM_UP, 63*4882a593Smuzhiyun OPTION_VIRTUAL_SIZE, 64*4882a593Smuzhiyun OPTION_PADDING, 65*4882a593Smuzhiyun } modesettingOpts; 66*4882a593Smuzhiyun 67*4882a593Smuzhiyun typedef struct 68*4882a593Smuzhiyun { 69*4882a593Smuzhiyun int fd; 70*4882a593Smuzhiyun int fd_ref; 71*4882a593Smuzhiyun unsigned long fd_wakeup_registered; /* server generation for which fd has been registered for wakeup handling */ 72*4882a593Smuzhiyun int fd_wakeup_ref; 73*4882a593Smuzhiyun unsigned int assigned_crtcs; 74*4882a593Smuzhiyun } modesettingEntRec, *modesettingEntPtr; 75*4882a593Smuzhiyun 76*4882a593Smuzhiyun typedef void (*ms_drm_handler_proc)(uint64_t frame, 77*4882a593Smuzhiyun uint64_t usec, 78*4882a593Smuzhiyun void *data); 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun typedef void (*ms_drm_abort_proc)(void *data); 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun /** 83*4882a593Smuzhiyun * A tracked handler for an event that will hopefully be generated by 84*4882a593Smuzhiyun * the kernel, and what to do when it is encountered. 85*4882a593Smuzhiyun */ 86*4882a593Smuzhiyun struct ms_drm_queue { 87*4882a593Smuzhiyun struct xorg_list list; 88*4882a593Smuzhiyun xf86CrtcPtr crtc; 89*4882a593Smuzhiyun uint32_t seq; 90*4882a593Smuzhiyun void *data; 91*4882a593Smuzhiyun ScrnInfoPtr scrn; 92*4882a593Smuzhiyun ms_drm_handler_proc handler; 93*4882a593Smuzhiyun ms_drm_abort_proc abort; 94*4882a593Smuzhiyun }; 95*4882a593Smuzhiyun 96*4882a593Smuzhiyun typedef struct _modesettingRec { 97*4882a593Smuzhiyun int fd; 98*4882a593Smuzhiyun Bool fd_passed; 99*4882a593Smuzhiyun 100*4882a593Smuzhiyun int Chipset; 101*4882a593Smuzhiyun EntityInfoPtr pEnt; 102*4882a593Smuzhiyun 103*4882a593Smuzhiyun Bool noAccel; 104*4882a593Smuzhiyun CloseScreenProcPtr CloseScreen; 105*4882a593Smuzhiyun CreateWindowProcPtr CreateWindow; 106*4882a593Smuzhiyun unsigned int SaveGeneration; 107*4882a593Smuzhiyun 108*4882a593Smuzhiyun CreateScreenResourcesProcPtr createScreenResources; 109*4882a593Smuzhiyun ScreenBlockHandlerProcPtr BlockHandler; 110*4882a593Smuzhiyun miPointerSpriteFuncPtr SpriteFuncs; 111*4882a593Smuzhiyun void *driver; 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun drmmode_rec drmmode; 114*4882a593Smuzhiyun 115*4882a593Smuzhiyun drmEventContext event_context; 116*4882a593Smuzhiyun 117*4882a593Smuzhiyun /** 118*4882a593Smuzhiyun * Page flipping stuff. 119*4882a593Smuzhiyun * @{ 120*4882a593Smuzhiyun */ 121*4882a593Smuzhiyun Bool atomic_modeset; 122*4882a593Smuzhiyun Bool pending_modeset; 123*4882a593Smuzhiyun /** @} */ 124*4882a593Smuzhiyun 125*4882a593Smuzhiyun DamagePtr damage; 126*4882a593Smuzhiyun Bool dirty_enabled; 127*4882a593Smuzhiyun 128*4882a593Smuzhiyun uint32_t cursor_width, cursor_height; 129*4882a593Smuzhiyun 130*4882a593Smuzhiyun Bool has_queue_sequence; 131*4882a593Smuzhiyun Bool tried_queue_sequence; 132*4882a593Smuzhiyun 133*4882a593Smuzhiyun Bool kms_has_modifiers; 134*4882a593Smuzhiyun Bool async_pageflip; 135*4882a593Smuzhiyun 136*4882a593Smuzhiyun Bool warm_up; 137*4882a593Smuzhiyun 138*4882a593Smuzhiyun XF86VideoAdaptorPtr adaptor; 139*4882a593Smuzhiyun } modesettingRec, *modesettingPtr; 140*4882a593Smuzhiyun 141*4882a593Smuzhiyun #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate)) 142*4882a593Smuzhiyun modesettingEntPtr ms_ent_priv(ScrnInfoPtr scrn); 143*4882a593Smuzhiyun 144*4882a593Smuzhiyun uint32_t ms_drm_queue_alloc(xf86CrtcPtr crtc, 145*4882a593Smuzhiyun void *data, 146*4882a593Smuzhiyun ms_drm_handler_proc handler, 147*4882a593Smuzhiyun ms_drm_abort_proc abort); 148*4882a593Smuzhiyun 149*4882a593Smuzhiyun typedef enum ms_queue_flag { 150*4882a593Smuzhiyun MS_QUEUE_ABSOLUTE = 0, 151*4882a593Smuzhiyun MS_QUEUE_RELATIVE = 1, 152*4882a593Smuzhiyun MS_QUEUE_NEXT_ON_MISS = 2 153*4882a593Smuzhiyun } ms_queue_flag; 154*4882a593Smuzhiyun 155*4882a593Smuzhiyun Bool ms_queue_vblank(xf86CrtcPtr crtc, ms_queue_flag flags, 156*4882a593Smuzhiyun uint64_t msc, uint64_t *msc_queued, uint32_t seq); 157*4882a593Smuzhiyun 158*4882a593Smuzhiyun void ms_drm_abort(ScrnInfoPtr scrn, 159*4882a593Smuzhiyun Bool (*match)(void *data, void *match_data), 160*4882a593Smuzhiyun void *match_data); 161*4882a593Smuzhiyun void ms_drm_abort_seq(ScrnInfoPtr scrn, uint32_t seq); 162*4882a593Smuzhiyun 163*4882a593Smuzhiyun Bool ms_crtc_on(xf86CrtcPtr crtc); 164*4882a593Smuzhiyun 165*4882a593Smuzhiyun xf86CrtcPtr ms_dri2_crtc_covering_drawable(DrawablePtr pDraw); 166*4882a593Smuzhiyun RRCrtcPtr ms_randr_crtc_covering_drawable(DrawablePtr pDraw); 167*4882a593Smuzhiyun 168*4882a593Smuzhiyun int ms_get_crtc_ust_msc(xf86CrtcPtr crtc, CARD64 *ust, CARD64 *msc); 169*4882a593Smuzhiyun 170*4882a593Smuzhiyun uint64_t ms_kernel_msc_to_crtc_msc(xf86CrtcPtr crtc, uint64_t sequence, Bool is64bit); 171*4882a593Smuzhiyun 172*4882a593Smuzhiyun 173*4882a593Smuzhiyun Bool ms_dri2_screen_init(ScreenPtr screen); 174*4882a593Smuzhiyun void ms_dri2_close_screen(ScreenPtr screen); 175*4882a593Smuzhiyun 176*4882a593Smuzhiyun Bool ms_vblank_screen_init(ScreenPtr screen); 177*4882a593Smuzhiyun void ms_vblank_close_screen(ScreenPtr screen); 178*4882a593Smuzhiyun 179*4882a593Smuzhiyun Bool ms_present_screen_init(ScreenPtr screen); 180*4882a593Smuzhiyun 181*4882a593Smuzhiyun typedef void (*ms_pageflip_handler_proc)(modesettingPtr ms, 182*4882a593Smuzhiyun uint64_t frame, 183*4882a593Smuzhiyun uint64_t usec, 184*4882a593Smuzhiyun void *data); 185*4882a593Smuzhiyun 186*4882a593Smuzhiyun typedef void (*ms_pageflip_abort_proc)(modesettingPtr ms, void *data); 187*4882a593Smuzhiyun 188*4882a593Smuzhiyun Bool ms_do_pageflip_bo(ScreenPtr screen, 189*4882a593Smuzhiyun drmmode_bo *new_front_bo, 190*4882a593Smuzhiyun void *event, 191*4882a593Smuzhiyun int ref_crtc_vblank_pipe, 192*4882a593Smuzhiyun xf86CrtcPtr target_crtc, 193*4882a593Smuzhiyun Bool async, 194*4882a593Smuzhiyun ms_pageflip_handler_proc pageflip_handler, 195*4882a593Smuzhiyun ms_pageflip_abort_proc pageflip_abort); 196*4882a593Smuzhiyun 197*4882a593Smuzhiyun Bool ms_do_pageflip(ScreenPtr screen, 198*4882a593Smuzhiyun PixmapPtr new_front, 199*4882a593Smuzhiyun void *event, 200*4882a593Smuzhiyun int ref_crtc_vblank_pipe, 201*4882a593Smuzhiyun Bool async, 202*4882a593Smuzhiyun ms_pageflip_handler_proc pageflip_handler, 203*4882a593Smuzhiyun ms_pageflip_abort_proc pageflip_abort); 204*4882a593Smuzhiyun 205*4882a593Smuzhiyun int ms_flush_drm_events(ScreenPtr screen); 206*4882a593Smuzhiyun 207*4882a593Smuzhiyun Bool ms_copy_area(PixmapPtr pSrc, PixmapPtr pDst, 208*4882a593Smuzhiyun pixman_f_transform_t *transform, RegionPtr clip); 209*4882a593Smuzhiyun 210*4882a593Smuzhiyun Bool ms_init_exa(ScrnInfoPtr scrn); 211*4882a593Smuzhiyun void ms_deinit_exa(ScrnInfoPtr scrn); 212*4882a593Smuzhiyun Bool ms_exa_set_pixmap_bo(ScrnInfoPtr scrn, PixmapPtr pPixmap, 213*4882a593Smuzhiyun struct dumb_bo *bo, Bool owned); 214*4882a593Smuzhiyun struct dumb_bo *ms_exa_bo_from_pixmap(ScreenPtr screen, PixmapPtr pixmap); 215*4882a593Smuzhiyun void ms_exa_exchange_buffers(PixmapPtr front, PixmapPtr back); 216*4882a593Smuzhiyun Bool ms_exa_back_pixmap_from_fd(PixmapPtr pixmap, int fd, 217*4882a593Smuzhiyun CARD16 width, CARD16 height, 218*4882a593Smuzhiyun CARD16 stride, CARD8 depth, CARD8 bpp); 219*4882a593Smuzhiyun int ms_exa_shareable_fd_from_pixmap(ScreenPtr screen, PixmapPtr pixmap, 220*4882a593Smuzhiyun CARD16 *stride, CARD32 *size); 221*4882a593Smuzhiyun 222*4882a593Smuzhiyun Bool ms_exa_prepare_access(PixmapPtr pPix, int index); 223*4882a593Smuzhiyun void ms_exa_finish_access(PixmapPtr pPix, int index); 224*4882a593Smuzhiyun 225*4882a593Smuzhiyun Bool ms_exa_copy_area(PixmapPtr pSrc, PixmapPtr pDst, 226*4882a593Smuzhiyun pixman_f_transform_t *transform, RegionPtr clip); 227*4882a593Smuzhiyun 228*4882a593Smuzhiyun XF86VideoAdaptorPtr ms_exa_xv_init(ScreenPtr screen, int num_texture_ports); 229*4882a593Smuzhiyun 230*4882a593Smuzhiyun #ifdef DRI3 231*4882a593Smuzhiyun Bool ms_exa_dri3_init(ScreenPtr screen); 232*4882a593Smuzhiyun #endif 233*4882a593Smuzhiyun 234*4882a593Smuzhiyun void ms_exchange_buffers(PixmapPtr front, PixmapPtr back); 235*4882a593Smuzhiyun int ms_name_from_pixmap(PixmapPtr pixmap, CARD16 *stride, CARD32 *size); 236