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