driver.h revision 35c4bbdf
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
36#ifdef GLAMOR
37#define GLAMOR_FOR_XORG 1
38#include "glamor.h"
39#ifdef GLAMOR_HAS_GBM
40#include <gbm.h>
41#endif
42#endif
43
44#include "drmmode_display.h"
45#define DRV_ERROR(msg)	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg);
46#define MS_LOGLEVEL_DEBUG 4
47
48typedef enum {
49    OPTION_SW_CURSOR,
50    OPTION_DEVICE_PATH,
51    OPTION_SHADOW_FB,
52    OPTION_ACCEL_METHOD,
53    OPTION_PAGEFLIP,
54    OPTION_ZAPHOD_HEADS,
55} modesettingOpts;
56
57typedef struct
58{
59    int fd;
60    int fd_ref;
61    unsigned long fd_wakeup_registered; /* server generation for which fd has been registered for wakeup handling */
62    int fd_wakeup_ref;
63    unsigned int assigned_crtcs;
64} modesettingEntRec, *modesettingEntPtr;
65
66typedef void (*ms_drm_handler_proc)(uint64_t frame,
67                                    uint64_t usec,
68                                    void *data);
69
70typedef void (*ms_drm_abort_proc)(void *data);
71
72/**
73 * A tracked handler for an event that will hopefully be generated by
74 * the kernel, and what to do when it is encountered.
75 */
76struct ms_drm_queue {
77    struct xorg_list list;
78    xf86CrtcPtr crtc;
79    uint32_t seq;
80    void *data;
81    ScrnInfoPtr scrn;
82    ms_drm_handler_proc handler;
83    ms_drm_abort_proc abort;
84};
85
86typedef struct _modesettingRec {
87    int fd;
88
89    int Chipset;
90    EntityInfoPtr pEnt;
91#if XSERVER_LIBPCIACCESS
92    struct pci_device *PciInfo;
93#else
94    pciVideoPtr PciInfo;
95    PCITAG PciTag;
96#endif
97
98    Bool noAccel;
99    CloseScreenProcPtr CloseScreen;
100
101    unsigned int SaveGeneration;
102
103    CreateScreenResourcesProcPtr createScreenResources;
104    ScreenBlockHandlerProcPtr BlockHandler;
105    void *driver;
106
107    drmmode_rec drmmode;
108
109    drmEventContext event_context;
110
111    /**
112     * Page flipping stuff.
113     *  @{
114     */
115    /** @} */
116
117    DamagePtr damage;
118    Bool dirty_enabled;
119
120    uint32_t cursor_width, cursor_height;
121} modesettingRec, *modesettingPtr;
122
123#define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
124modesettingEntPtr ms_ent_priv(ScrnInfoPtr scrn);
125
126uint32_t ms_drm_queue_alloc(xf86CrtcPtr crtc,
127                            void *data,
128                            ms_drm_handler_proc handler,
129                            ms_drm_abort_proc abort);
130
131void ms_drm_abort(ScrnInfoPtr scrn,
132                  Bool (*match)(void *data, void *match_data),
133                  void *match_data);
134void ms_drm_abort_seq(ScrnInfoPtr scrn, uint32_t seq);
135
136Bool ms_crtc_on(xf86CrtcPtr crtc);
137
138xf86CrtcPtr ms_dri2_crtc_covering_drawable(DrawablePtr pDraw);
139xf86CrtcPtr ms_covering_crtc(ScrnInfoPtr scrn, BoxPtr box,
140                             xf86CrtcPtr desired, BoxPtr crtc_box_ret);
141
142int ms_get_crtc_ust_msc(xf86CrtcPtr crtc, CARD64 *ust, CARD64 *msc);
143
144uint32_t ms_crtc_msc_to_kernel_msc(xf86CrtcPtr crtc, uint64_t expect);
145uint64_t ms_kernel_msc_to_crtc_msc(xf86CrtcPtr crtc, uint32_t sequence);
146
147
148Bool ms_dri2_screen_init(ScreenPtr screen);
149void ms_dri2_close_screen(ScreenPtr screen);
150
151Bool ms_vblank_screen_init(ScreenPtr screen);
152void ms_vblank_close_screen(ScreenPtr screen);
153
154Bool ms_present_screen_init(ScreenPtr screen);
155