1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
3*4882a593Smuzhiyun * Copyright 2011 Dave Airlie
4*4882a593Smuzhiyun * All Rights Reserved.
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining a
7*4882a593Smuzhiyun * copy of this software and associated documentation files (the
8*4882a593Smuzhiyun * "Software"), to deal in the Software without restriction, including
9*4882a593Smuzhiyun * without limitation the rights to use, copy, modify, merge, publish,
10*4882a593Smuzhiyun * distribute, sub license, and/or sell copies of the Software, and to
11*4882a593Smuzhiyun * permit persons to whom the Software is furnished to do so, subject to
12*4882a593Smuzhiyun * the following conditions:
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * The above copyright notice and this permission notice (including the
15*4882a593Smuzhiyun * next paragraph) shall be included in all copies or substantial portions
16*4882a593Smuzhiyun * of the Software.
17*4882a593Smuzhiyun *
18*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19*4882a593Smuzhiyun * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20*4882a593Smuzhiyun * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21*4882a593Smuzhiyun * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22*4882a593Smuzhiyun * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23*4882a593Smuzhiyun * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24*4882a593Smuzhiyun * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25*4882a593Smuzhiyun *
26*4882a593Smuzhiyun *
27*4882a593Smuzhiyun * Original Author: Alan Hourihane <alanh@tungstengraphics.com>
28*4882a593Smuzhiyun * Rewrite: Dave Airlie <airlied@redhat.com>
29*4882a593Smuzhiyun *
30*4882a593Smuzhiyun */
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun #ifdef HAVE_DIX_CONFIG_H
33*4882a593Smuzhiyun #include "dix-config.h"
34*4882a593Smuzhiyun #endif
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun #include <unistd.h>
37*4882a593Smuzhiyun #include <fcntl.h>
38*4882a593Smuzhiyun #include "xf86.h"
39*4882a593Smuzhiyun #include "xf86Priv.h"
40*4882a593Smuzhiyun #include "xf86_OSproc.h"
41*4882a593Smuzhiyun #include "compiler.h"
42*4882a593Smuzhiyun #include "xf86Pci.h"
43*4882a593Smuzhiyun #include "mipointer.h"
44*4882a593Smuzhiyun #include "mipointrst.h"
45*4882a593Smuzhiyun #include "micmap.h"
46*4882a593Smuzhiyun #include "misyncshm.h"
47*4882a593Smuzhiyun #include "misyncstr.h"
48*4882a593Smuzhiyun #include <X11/extensions/randr.h>
49*4882a593Smuzhiyun #include "fb.h"
50*4882a593Smuzhiyun #include "edid.h"
51*4882a593Smuzhiyun #include "xf86i2c.h"
52*4882a593Smuzhiyun #include "xf86Crtc.h"
53*4882a593Smuzhiyun #include "miscstruct.h"
54*4882a593Smuzhiyun #include "dixstruct.h"
55*4882a593Smuzhiyun #include "shadow.h"
56*4882a593Smuzhiyun #include <X11/extensions/Xv.h>
57*4882a593Smuzhiyun #include <xorg-config.h>
58*4882a593Smuzhiyun #ifdef XSERVER_PLATFORM_BUS
59*4882a593Smuzhiyun #include "xf86platformBus.h"
60*4882a593Smuzhiyun #endif
61*4882a593Smuzhiyun #ifdef XSERVER_LIBPCIACCESS
62*4882a593Smuzhiyun #include <pciaccess.h>
63*4882a593Smuzhiyun #endif
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun #include "driver.h"
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun static void AdjustFrame(ScrnInfoPtr pScrn, int x, int y);
68*4882a593Smuzhiyun static Bool CloseScreen(ScreenPtr pScreen);
69*4882a593Smuzhiyun static Bool EnterVT(ScrnInfoPtr pScrn);
70*4882a593Smuzhiyun static void Identify(int flags);
71*4882a593Smuzhiyun static const OptionInfoRec *AvailableOptions(int chipid, int busid);
72*4882a593Smuzhiyun static ModeStatus ValidMode(ScrnInfoPtr pScrn, DisplayModePtr mode,
73*4882a593Smuzhiyun Bool verbose, int flags);
74*4882a593Smuzhiyun static void FreeScreen(ScrnInfoPtr pScrn);
75*4882a593Smuzhiyun static void LeaveVT(ScrnInfoPtr pScrn);
76*4882a593Smuzhiyun static Bool SwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode);
77*4882a593Smuzhiyun static Bool ScreenInit(ScreenPtr pScreen, int argc, char **argv);
78*4882a593Smuzhiyun static Bool PreInit(ScrnInfoPtr pScrn, int flags);
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun static Bool Probe(DriverPtr drv, int flags);
81*4882a593Smuzhiyun static Bool ms_pci_probe(DriverPtr driver,
82*4882a593Smuzhiyun int entity_num, struct pci_device *device,
83*4882a593Smuzhiyun intptr_t match_data);
84*4882a593Smuzhiyun static Bool ms_driver_func(ScrnInfoPtr scrn, xorgDriverFuncOp op, void *data);
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun static int
87*4882a593Smuzhiyun ms_shareable_fd_from_pixmap(ScreenPtr screen,
88*4882a593Smuzhiyun PixmapPtr pixmap,
89*4882a593Smuzhiyun CARD16 *stride,
90*4882a593Smuzhiyun CARD32 *size);
91*4882a593Smuzhiyun static Bool
92*4882a593Smuzhiyun ms_back_pixmap_from_fd(PixmapPtr pixmap,
93*4882a593Smuzhiyun int fd,
94*4882a593Smuzhiyun CARD16 width,
95*4882a593Smuzhiyun CARD16 height,
96*4882a593Smuzhiyun CARD16 stride, CARD8 depth, CARD8 bpp);
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun #ifdef XSERVER_LIBPCIACCESS
99*4882a593Smuzhiyun static const struct pci_id_match ms_device_match[] = {
100*4882a593Smuzhiyun {
101*4882a593Smuzhiyun PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY,
102*4882a593Smuzhiyun 0x00030000, 0x00ff0000, 0},
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun {0, 0, 0},
105*4882a593Smuzhiyun };
106*4882a593Smuzhiyun #endif
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun #ifndef XSERVER_PLATFORM_BUS
109*4882a593Smuzhiyun struct xf86_platform_device;
110*4882a593Smuzhiyun #endif
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun #ifdef XSERVER_PLATFORM_BUS
113*4882a593Smuzhiyun static Bool ms_platform_probe(DriverPtr driver,
114*4882a593Smuzhiyun int entity_num, int flags,
115*4882a593Smuzhiyun struct xf86_platform_device *device,
116*4882a593Smuzhiyun intptr_t match_data);
117*4882a593Smuzhiyun #endif
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun _X_EXPORT DriverRec modesetting = {
120*4882a593Smuzhiyun 1,
121*4882a593Smuzhiyun "modesetting",
122*4882a593Smuzhiyun Identify,
123*4882a593Smuzhiyun Probe,
124*4882a593Smuzhiyun AvailableOptions,
125*4882a593Smuzhiyun NULL,
126*4882a593Smuzhiyun 0,
127*4882a593Smuzhiyun ms_driver_func,
128*4882a593Smuzhiyun ms_device_match,
129*4882a593Smuzhiyun ms_pci_probe,
130*4882a593Smuzhiyun #ifdef XSERVER_PLATFORM_BUS
131*4882a593Smuzhiyun ms_platform_probe,
132*4882a593Smuzhiyun #endif
133*4882a593Smuzhiyun };
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun static SymTabRec Chipsets[] = {
136*4882a593Smuzhiyun {0, "kms"},
137*4882a593Smuzhiyun {-1, NULL}
138*4882a593Smuzhiyun };
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun static const OptionInfoRec Options[] = {
141*4882a593Smuzhiyun {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE},
142*4882a593Smuzhiyun {OPTION_DEVICE_PATH, "kmsdev", OPTV_STRING, {0}, FALSE},
143*4882a593Smuzhiyun {OPTION_SHADOW_FB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE},
144*4882a593Smuzhiyun {OPTION_ACCEL_METHOD, "AccelMethod", OPTV_STRING, {0}, FALSE},
145*4882a593Smuzhiyun {OPTION_PAGEFLIP, "PageFlip", OPTV_BOOLEAN, {0}, FALSE},
146*4882a593Smuzhiyun {OPTION_ZAPHOD_HEADS, "ZaphodHeads", OPTV_STRING, {0}, FALSE},
147*4882a593Smuzhiyun {OPTION_DOUBLE_SHADOW, "DoubleShadow", OPTV_BOOLEAN, {0}, FALSE},
148*4882a593Smuzhiyun {OPTION_ATOMIC, "Atomic", OPTV_BOOLEAN, {0}, FALSE},
149*4882a593Smuzhiyun {OPTION_USE_GAMMA_LUT, "UseGammaLUT", OPTV_BOOLEAN, {0}, FALSE},
150*4882a593Smuzhiyun {OPTION_FLIP_FB, "FlipFB", OPTV_STRING, {0}, FALSE},
151*4882a593Smuzhiyun {OPTION_FLIP_FB_RATE, "MaxFlipRate", OPTV_INTEGER, {0}, 0},
152*4882a593Smuzhiyun {OPTION_BIND_CURRENT, "BindCurrent", OPTV_BOOLEAN, {0}, FALSE},
153*4882a593Smuzhiyun {OPTION_NO_EDID, "NoEDID", OPTV_BOOLEAN, {0}, FALSE},
154*4882a593Smuzhiyun {OPTION_HOTPLUG_RESET, "HotplugReset", OPTV_BOOLEAN, {0}, FALSE},
155*4882a593Smuzhiyun {OPTION_WARM_UP, "WarmUp", OPTV_BOOLEAN, {0}, FALSE},
156*4882a593Smuzhiyun {OPTION_VIRTUAL_SIZE, "VirtualSize", OPTV_STRING, {0}, FALSE},
157*4882a593Smuzhiyun {OPTION_PADDING, "Padding", OPTV_STRING, {0}, FALSE},
158*4882a593Smuzhiyun {-1, NULL, OPTV_NONE, {0}, FALSE}
159*4882a593Smuzhiyun };
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun int ms_entity_index = -1;
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun static MODULESETUPPROTO(Setup);
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun static XF86ModuleVersionInfo VersRec = {
166*4882a593Smuzhiyun "modesetting",
167*4882a593Smuzhiyun MODULEVENDORSTRING,
168*4882a593Smuzhiyun MODINFOSTRING1,
169*4882a593Smuzhiyun MODINFOSTRING2,
170*4882a593Smuzhiyun XORG_VERSION_CURRENT,
171*4882a593Smuzhiyun XORG_VERSION_MAJOR,
172*4882a593Smuzhiyun XORG_VERSION_MINOR,
173*4882a593Smuzhiyun XORG_VERSION_PATCH,
174*4882a593Smuzhiyun ABI_CLASS_VIDEODRV,
175*4882a593Smuzhiyun ABI_VIDEODRV_VERSION,
176*4882a593Smuzhiyun MOD_CLASS_VIDEODRV,
177*4882a593Smuzhiyun {0, 0, 0, 0}
178*4882a593Smuzhiyun };
179*4882a593Smuzhiyun
180*4882a593Smuzhiyun _X_EXPORT XF86ModuleData modesettingModuleData = { &VersRec, Setup, NULL };
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun static void *
Setup(void * module,void * opts,int * errmaj,int * errmin)183*4882a593Smuzhiyun Setup(void *module, void *opts, int *errmaj, int *errmin)
184*4882a593Smuzhiyun {
185*4882a593Smuzhiyun static Bool setupDone = 0;
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun /* This module should be loaded only once, but check to be sure.
188*4882a593Smuzhiyun */
189*4882a593Smuzhiyun if (!setupDone) {
190*4882a593Smuzhiyun setupDone = 1;
191*4882a593Smuzhiyun xf86AddDriver(&modesetting, module, HaveDriverFuncs);
192*4882a593Smuzhiyun
193*4882a593Smuzhiyun /*
194*4882a593Smuzhiyun * The return value must be non-NULL on success even though there
195*4882a593Smuzhiyun * is no TearDownProc.
196*4882a593Smuzhiyun */
197*4882a593Smuzhiyun return (void *) 1;
198*4882a593Smuzhiyun }
199*4882a593Smuzhiyun else {
200*4882a593Smuzhiyun if (errmaj)
201*4882a593Smuzhiyun *errmaj = LDR_ONCEONLY;
202*4882a593Smuzhiyun return NULL;
203*4882a593Smuzhiyun }
204*4882a593Smuzhiyun }
205*4882a593Smuzhiyun
206*4882a593Smuzhiyun static void
Identify(int flags)207*4882a593Smuzhiyun Identify(int flags)
208*4882a593Smuzhiyun {
209*4882a593Smuzhiyun xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers",
210*4882a593Smuzhiyun Chipsets);
211*4882a593Smuzhiyun }
212*4882a593Smuzhiyun
ms_ent_priv(ScrnInfoPtr scrn)213*4882a593Smuzhiyun modesettingEntPtr ms_ent_priv(ScrnInfoPtr scrn)
214*4882a593Smuzhiyun {
215*4882a593Smuzhiyun DevUnion *pPriv;
216*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(scrn);
217*4882a593Smuzhiyun pPriv = xf86GetEntityPrivate(ms->pEnt->index,
218*4882a593Smuzhiyun ms_entity_index);
219*4882a593Smuzhiyun return pPriv->ptr;
220*4882a593Smuzhiyun }
221*4882a593Smuzhiyun
222*4882a593Smuzhiyun static int
get_passed_fd(void)223*4882a593Smuzhiyun get_passed_fd(void)
224*4882a593Smuzhiyun {
225*4882a593Smuzhiyun if (xf86DRMMasterFd >= 0) {
226*4882a593Smuzhiyun xf86DrvMsg(-1, X_INFO, "Using passed DRM master file descriptor %d\n", xf86DRMMasterFd);
227*4882a593Smuzhiyun return dup(xf86DRMMasterFd);
228*4882a593Smuzhiyun }
229*4882a593Smuzhiyun return -1;
230*4882a593Smuzhiyun }
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun static int
open_hw(const char * dev)233*4882a593Smuzhiyun open_hw(const char *dev)
234*4882a593Smuzhiyun {
235*4882a593Smuzhiyun int fd;
236*4882a593Smuzhiyun
237*4882a593Smuzhiyun if ((fd = get_passed_fd()) != -1)
238*4882a593Smuzhiyun return fd;
239*4882a593Smuzhiyun
240*4882a593Smuzhiyun if (dev)
241*4882a593Smuzhiyun fd = open(dev, O_RDWR | O_CLOEXEC, 0);
242*4882a593Smuzhiyun else {
243*4882a593Smuzhiyun dev = getenv("KMSDEVICE");
244*4882a593Smuzhiyun if ((NULL == dev) || ((fd = open(dev, O_RDWR | O_CLOEXEC, 0)) == -1)) {
245*4882a593Smuzhiyun dev = "/dev/dri/card0";
246*4882a593Smuzhiyun fd = open(dev, O_RDWR | O_CLOEXEC, 0);
247*4882a593Smuzhiyun }
248*4882a593Smuzhiyun }
249*4882a593Smuzhiyun if (fd == -1)
250*4882a593Smuzhiyun xf86DrvMsg(-1, X_ERROR, "open %s: %s\n", dev, strerror(errno));
251*4882a593Smuzhiyun
252*4882a593Smuzhiyun return fd;
253*4882a593Smuzhiyun }
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun static int
check_outputs(int fd,int * count)256*4882a593Smuzhiyun check_outputs(int fd, int *count)
257*4882a593Smuzhiyun {
258*4882a593Smuzhiyun drmModeResPtr res = drmModeGetResources(fd);
259*4882a593Smuzhiyun int ret;
260*4882a593Smuzhiyun
261*4882a593Smuzhiyun if (!res)
262*4882a593Smuzhiyun return FALSE;
263*4882a593Smuzhiyun
264*4882a593Smuzhiyun if (count)
265*4882a593Smuzhiyun *count = res->count_connectors;
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun ret = res->count_connectors > 0;
268*4882a593Smuzhiyun #if defined(GLAMOR_HAS_GBM_LINEAR)
269*4882a593Smuzhiyun if (ret == FALSE) {
270*4882a593Smuzhiyun uint64_t value = 0;
271*4882a593Smuzhiyun if (drmGetCap(fd, DRM_CAP_PRIME, &value) == 0 &&
272*4882a593Smuzhiyun (value & DRM_PRIME_CAP_EXPORT))
273*4882a593Smuzhiyun ret = TRUE;
274*4882a593Smuzhiyun }
275*4882a593Smuzhiyun #endif
276*4882a593Smuzhiyun drmModeFreeResources(res);
277*4882a593Smuzhiyun return ret;
278*4882a593Smuzhiyun }
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun static Bool
probe_hw(const char * dev,struct xf86_platform_device * platform_dev)281*4882a593Smuzhiyun probe_hw(const char *dev, struct xf86_platform_device *platform_dev)
282*4882a593Smuzhiyun {
283*4882a593Smuzhiyun int fd;
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun #ifdef XF86_PDEV_SERVER_FD
286*4882a593Smuzhiyun if (platform_dev && (platform_dev->flags & XF86_PDEV_SERVER_FD)) {
287*4882a593Smuzhiyun fd = xf86_platform_device_odev_attributes(platform_dev)->fd;
288*4882a593Smuzhiyun if (fd == -1)
289*4882a593Smuzhiyun return FALSE;
290*4882a593Smuzhiyun return check_outputs(fd, NULL);
291*4882a593Smuzhiyun }
292*4882a593Smuzhiyun #endif
293*4882a593Smuzhiyun
294*4882a593Smuzhiyun fd = open_hw(dev);
295*4882a593Smuzhiyun if (fd != -1) {
296*4882a593Smuzhiyun int ret = check_outputs(fd, NULL);
297*4882a593Smuzhiyun
298*4882a593Smuzhiyun close(fd);
299*4882a593Smuzhiyun return ret;
300*4882a593Smuzhiyun }
301*4882a593Smuzhiyun return FALSE;
302*4882a593Smuzhiyun }
303*4882a593Smuzhiyun
304*4882a593Smuzhiyun static char *
ms_DRICreatePCIBusID(const struct pci_device * dev)305*4882a593Smuzhiyun ms_DRICreatePCIBusID(const struct pci_device *dev)
306*4882a593Smuzhiyun {
307*4882a593Smuzhiyun char *busID;
308*4882a593Smuzhiyun
309*4882a593Smuzhiyun if (asprintf(&busID, "pci:%04x:%02x:%02x.%d",
310*4882a593Smuzhiyun dev->domain, dev->bus, dev->dev, dev->func) == -1)
311*4882a593Smuzhiyun return NULL;
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun return busID;
314*4882a593Smuzhiyun }
315*4882a593Smuzhiyun
316*4882a593Smuzhiyun static Bool
probe_hw_pci(const char * dev,struct pci_device * pdev)317*4882a593Smuzhiyun probe_hw_pci(const char *dev, struct pci_device *pdev)
318*4882a593Smuzhiyun {
319*4882a593Smuzhiyun int ret = FALSE, fd = open_hw(dev);
320*4882a593Smuzhiyun char *id, *devid;
321*4882a593Smuzhiyun drmSetVersion sv;
322*4882a593Smuzhiyun
323*4882a593Smuzhiyun if (fd == -1)
324*4882a593Smuzhiyun return FALSE;
325*4882a593Smuzhiyun
326*4882a593Smuzhiyun sv.drm_di_major = 1;
327*4882a593Smuzhiyun sv.drm_di_minor = 4;
328*4882a593Smuzhiyun sv.drm_dd_major = -1;
329*4882a593Smuzhiyun sv.drm_dd_minor = -1;
330*4882a593Smuzhiyun if (drmSetInterfaceVersion(fd, &sv)) {
331*4882a593Smuzhiyun close(fd);
332*4882a593Smuzhiyun return FALSE;
333*4882a593Smuzhiyun }
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun id = drmGetBusid(fd);
336*4882a593Smuzhiyun devid = ms_DRICreatePCIBusID(pdev);
337*4882a593Smuzhiyun
338*4882a593Smuzhiyun if (id && devid && !strcmp(id, devid))
339*4882a593Smuzhiyun ret = check_outputs(fd, NULL);
340*4882a593Smuzhiyun
341*4882a593Smuzhiyun close(fd);
342*4882a593Smuzhiyun free(id);
343*4882a593Smuzhiyun free(devid);
344*4882a593Smuzhiyun return ret;
345*4882a593Smuzhiyun }
346*4882a593Smuzhiyun
347*4882a593Smuzhiyun static const OptionInfoRec *
AvailableOptions(int chipid,int busid)348*4882a593Smuzhiyun AvailableOptions(int chipid, int busid)
349*4882a593Smuzhiyun {
350*4882a593Smuzhiyun return Options;
351*4882a593Smuzhiyun }
352*4882a593Smuzhiyun
353*4882a593Smuzhiyun static Bool
ms_driver_func(ScrnInfoPtr scrn,xorgDriverFuncOp op,void * data)354*4882a593Smuzhiyun ms_driver_func(ScrnInfoPtr scrn, xorgDriverFuncOp op, void *data)
355*4882a593Smuzhiyun {
356*4882a593Smuzhiyun xorgHWFlags *flag;
357*4882a593Smuzhiyun
358*4882a593Smuzhiyun switch (op) {
359*4882a593Smuzhiyun case GET_REQUIRED_HW_INTERFACES:
360*4882a593Smuzhiyun flag = (CARD32 *) data;
361*4882a593Smuzhiyun (*flag) = 0;
362*4882a593Smuzhiyun return TRUE;
363*4882a593Smuzhiyun case SUPPORTS_SERVER_FDS:
364*4882a593Smuzhiyun return TRUE;
365*4882a593Smuzhiyun default:
366*4882a593Smuzhiyun return FALSE;
367*4882a593Smuzhiyun }
368*4882a593Smuzhiyun }
369*4882a593Smuzhiyun
370*4882a593Smuzhiyun static void
ms_setup_scrn_hooks(ScrnInfoPtr scrn)371*4882a593Smuzhiyun ms_setup_scrn_hooks(ScrnInfoPtr scrn)
372*4882a593Smuzhiyun {
373*4882a593Smuzhiyun scrn->driverVersion = 1;
374*4882a593Smuzhiyun scrn->driverName = "modesetting";
375*4882a593Smuzhiyun scrn->name = "modeset";
376*4882a593Smuzhiyun
377*4882a593Smuzhiyun scrn->Probe = NULL;
378*4882a593Smuzhiyun scrn->PreInit = PreInit;
379*4882a593Smuzhiyun scrn->ScreenInit = ScreenInit;
380*4882a593Smuzhiyun scrn->SwitchMode = SwitchMode;
381*4882a593Smuzhiyun scrn->AdjustFrame = AdjustFrame;
382*4882a593Smuzhiyun scrn->EnterVT = EnterVT;
383*4882a593Smuzhiyun scrn->LeaveVT = LeaveVT;
384*4882a593Smuzhiyun scrn->FreeScreen = FreeScreen;
385*4882a593Smuzhiyun scrn->ValidMode = ValidMode;
386*4882a593Smuzhiyun }
387*4882a593Smuzhiyun
388*4882a593Smuzhiyun static void
ms_setup_entity(ScrnInfoPtr scrn,int entity_num)389*4882a593Smuzhiyun ms_setup_entity(ScrnInfoPtr scrn, int entity_num)
390*4882a593Smuzhiyun {
391*4882a593Smuzhiyun DevUnion *pPriv;
392*4882a593Smuzhiyun
393*4882a593Smuzhiyun xf86SetEntitySharable(entity_num);
394*4882a593Smuzhiyun
395*4882a593Smuzhiyun if (ms_entity_index == -1)
396*4882a593Smuzhiyun ms_entity_index = xf86AllocateEntityPrivateIndex();
397*4882a593Smuzhiyun
398*4882a593Smuzhiyun pPriv = xf86GetEntityPrivate(entity_num,
399*4882a593Smuzhiyun ms_entity_index);
400*4882a593Smuzhiyun
401*4882a593Smuzhiyun xf86SetEntityInstanceForScreen(scrn, entity_num, xf86GetNumEntityInstances(entity_num) - 1);
402*4882a593Smuzhiyun
403*4882a593Smuzhiyun if (!pPriv->ptr)
404*4882a593Smuzhiyun pPriv->ptr = xnfcalloc(sizeof(modesettingEntRec), 1);
405*4882a593Smuzhiyun }
406*4882a593Smuzhiyun
407*4882a593Smuzhiyun #ifdef XSERVER_LIBPCIACCESS
408*4882a593Smuzhiyun static Bool
ms_pci_probe(DriverPtr driver,int entity_num,struct pci_device * dev,intptr_t match_data)409*4882a593Smuzhiyun ms_pci_probe(DriverPtr driver,
410*4882a593Smuzhiyun int entity_num, struct pci_device *dev, intptr_t match_data)
411*4882a593Smuzhiyun {
412*4882a593Smuzhiyun ScrnInfoPtr scrn = NULL;
413*4882a593Smuzhiyun
414*4882a593Smuzhiyun scrn = xf86ConfigPciEntity(scrn, 0, entity_num, NULL,
415*4882a593Smuzhiyun NULL, NULL, NULL, NULL, NULL);
416*4882a593Smuzhiyun if (scrn) {
417*4882a593Smuzhiyun const char *devpath;
418*4882a593Smuzhiyun GDevPtr devSection = xf86GetDevFromEntity(scrn->entityList[0],
419*4882a593Smuzhiyun scrn->entityInstanceList[0]);
420*4882a593Smuzhiyun
421*4882a593Smuzhiyun devpath = xf86FindOptionValue(devSection->options, "kmsdev");
422*4882a593Smuzhiyun if (probe_hw_pci(devpath, dev)) {
423*4882a593Smuzhiyun ms_setup_scrn_hooks(scrn);
424*4882a593Smuzhiyun
425*4882a593Smuzhiyun xf86DrvMsg(scrn->scrnIndex, X_CONFIG,
426*4882a593Smuzhiyun "claimed PCI slot %d@%d:%d:%d\n",
427*4882a593Smuzhiyun dev->bus, dev->domain, dev->dev, dev->func);
428*4882a593Smuzhiyun xf86DrvMsg(scrn->scrnIndex, X_INFO,
429*4882a593Smuzhiyun "using %s\n", devpath ? devpath : "default device");
430*4882a593Smuzhiyun
431*4882a593Smuzhiyun ms_setup_entity(scrn, entity_num);
432*4882a593Smuzhiyun }
433*4882a593Smuzhiyun else
434*4882a593Smuzhiyun scrn = NULL;
435*4882a593Smuzhiyun }
436*4882a593Smuzhiyun return scrn != NULL;
437*4882a593Smuzhiyun }
438*4882a593Smuzhiyun #endif
439*4882a593Smuzhiyun
440*4882a593Smuzhiyun #ifdef XSERVER_PLATFORM_BUS
441*4882a593Smuzhiyun static Bool
ms_platform_probe(DriverPtr driver,int entity_num,int flags,struct xf86_platform_device * dev,intptr_t match_data)442*4882a593Smuzhiyun ms_platform_probe(DriverPtr driver,
443*4882a593Smuzhiyun int entity_num, int flags, struct xf86_platform_device *dev,
444*4882a593Smuzhiyun intptr_t match_data)
445*4882a593Smuzhiyun {
446*4882a593Smuzhiyun ScrnInfoPtr scrn = NULL;
447*4882a593Smuzhiyun const char *path = xf86_platform_device_odev_attributes(dev)->path;
448*4882a593Smuzhiyun int scr_flags = 0;
449*4882a593Smuzhiyun
450*4882a593Smuzhiyun if (flags & PLATFORM_PROBE_GPU_SCREEN)
451*4882a593Smuzhiyun scr_flags = XF86_ALLOCATE_GPU_SCREEN;
452*4882a593Smuzhiyun
453*4882a593Smuzhiyun if (probe_hw(path, dev)) {
454*4882a593Smuzhiyun scrn = xf86AllocateScreen(driver, scr_flags);
455*4882a593Smuzhiyun if (xf86IsEntitySharable(entity_num))
456*4882a593Smuzhiyun xf86SetEntityShared(entity_num);
457*4882a593Smuzhiyun xf86AddEntityToScreen(scrn, entity_num);
458*4882a593Smuzhiyun
459*4882a593Smuzhiyun ms_setup_scrn_hooks(scrn);
460*4882a593Smuzhiyun
461*4882a593Smuzhiyun xf86DrvMsg(scrn->scrnIndex, X_INFO,
462*4882a593Smuzhiyun "using drv %s\n", path ? path : "default device");
463*4882a593Smuzhiyun
464*4882a593Smuzhiyun ms_setup_entity(scrn, entity_num);
465*4882a593Smuzhiyun }
466*4882a593Smuzhiyun
467*4882a593Smuzhiyun return scrn != NULL;
468*4882a593Smuzhiyun }
469*4882a593Smuzhiyun #endif
470*4882a593Smuzhiyun
471*4882a593Smuzhiyun static Bool
Probe(DriverPtr drv,int flags)472*4882a593Smuzhiyun Probe(DriverPtr drv, int flags)
473*4882a593Smuzhiyun {
474*4882a593Smuzhiyun int i, numDevSections;
475*4882a593Smuzhiyun GDevPtr *devSections;
476*4882a593Smuzhiyun Bool foundScreen = FALSE;
477*4882a593Smuzhiyun const char *dev;
478*4882a593Smuzhiyun ScrnInfoPtr scrn = NULL;
479*4882a593Smuzhiyun
480*4882a593Smuzhiyun if (XSERVER_PLATFORM_BUS || XSERVER_LIBPCIACCESS)
481*4882a593Smuzhiyun return FALSE;
482*4882a593Smuzhiyun
483*4882a593Smuzhiyun /* For now, just bail out for PROBE_DETECT. */
484*4882a593Smuzhiyun if (flags & PROBE_DETECT)
485*4882a593Smuzhiyun return FALSE;
486*4882a593Smuzhiyun
487*4882a593Smuzhiyun /*
488*4882a593Smuzhiyun * Find the config file Device sections that match this
489*4882a593Smuzhiyun * driver, and return if there are none.
490*4882a593Smuzhiyun */
491*4882a593Smuzhiyun if ((numDevSections = xf86MatchDevice("modesetting", &devSections)) <= 0) {
492*4882a593Smuzhiyun return FALSE;
493*4882a593Smuzhiyun }
494*4882a593Smuzhiyun
495*4882a593Smuzhiyun for (i = 0; i < numDevSections; i++) {
496*4882a593Smuzhiyun int entity_num;
497*4882a593Smuzhiyun dev = xf86FindOptionValue(devSections[i]->options, "kmsdev");
498*4882a593Smuzhiyun if (probe_hw(dev, NULL)) {
499*4882a593Smuzhiyun
500*4882a593Smuzhiyun entity_num = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE);
501*4882a593Smuzhiyun scrn = xf86ConfigFbEntity(scrn, 0, entity_num, NULL, NULL, NULL, NULL);
502*4882a593Smuzhiyun }
503*4882a593Smuzhiyun
504*4882a593Smuzhiyun if (scrn) {
505*4882a593Smuzhiyun foundScreen = TRUE;
506*4882a593Smuzhiyun ms_setup_scrn_hooks(scrn);
507*4882a593Smuzhiyun scrn->Probe = Probe;
508*4882a593Smuzhiyun
509*4882a593Smuzhiyun xf86DrvMsg(scrn->scrnIndex, X_INFO,
510*4882a593Smuzhiyun "using %s\n", dev ? dev : "default device");
511*4882a593Smuzhiyun ms_setup_entity(scrn, entity_num);
512*4882a593Smuzhiyun }
513*4882a593Smuzhiyun }
514*4882a593Smuzhiyun
515*4882a593Smuzhiyun free(devSections);
516*4882a593Smuzhiyun
517*4882a593Smuzhiyun return foundScreen;
518*4882a593Smuzhiyun }
519*4882a593Smuzhiyun
520*4882a593Smuzhiyun static Bool
GetRec(ScrnInfoPtr pScrn)521*4882a593Smuzhiyun GetRec(ScrnInfoPtr pScrn)
522*4882a593Smuzhiyun {
523*4882a593Smuzhiyun if (pScrn->driverPrivate)
524*4882a593Smuzhiyun return TRUE;
525*4882a593Smuzhiyun
526*4882a593Smuzhiyun pScrn->driverPrivate = xnfcalloc(sizeof(modesettingRec), 1);
527*4882a593Smuzhiyun
528*4882a593Smuzhiyun return TRUE;
529*4882a593Smuzhiyun }
530*4882a593Smuzhiyun
531*4882a593Smuzhiyun static int
dispatch_dirty_region(ScrnInfoPtr scrn,PixmapPtr pixmap,DamagePtr damage,int fb_id)532*4882a593Smuzhiyun dispatch_dirty_region(ScrnInfoPtr scrn,
533*4882a593Smuzhiyun PixmapPtr pixmap, DamagePtr damage, int fb_id)
534*4882a593Smuzhiyun {
535*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(scrn);
536*4882a593Smuzhiyun RegionPtr dirty = DamageRegion(damage);
537*4882a593Smuzhiyun unsigned num_cliprects = REGION_NUM_RECTS(dirty);
538*4882a593Smuzhiyun int ret = 0;
539*4882a593Smuzhiyun
540*4882a593Smuzhiyun #ifdef GLAMOR_HAS_GBM
541*4882a593Smuzhiyun /*
542*4882a593Smuzhiyun * HACK: Move glamor_block_handler's glamor_finish here to avoid
543*4882a593Smuzhiyun * blocking no-dirty path.
544*4882a593Smuzhiyun */
545*4882a593Smuzhiyun if (ms->drmmode.glamor)
546*4882a593Smuzhiyun glamor_finish(pixmap->drawable.pScreen);
547*4882a593Smuzhiyun #endif
548*4882a593Smuzhiyun
549*4882a593Smuzhiyun if (num_cliprects) {
550*4882a593Smuzhiyun drmModeClip *clip = xallocarray(num_cliprects, sizeof(drmModeClip));
551*4882a593Smuzhiyun BoxPtr rect = REGION_RECTS(dirty);
552*4882a593Smuzhiyun int i;
553*4882a593Smuzhiyun
554*4882a593Smuzhiyun if (!clip)
555*4882a593Smuzhiyun return -ENOMEM;
556*4882a593Smuzhiyun
557*4882a593Smuzhiyun /* XXX no need for copy? */
558*4882a593Smuzhiyun for (i = 0; i < num_cliprects; i++, rect++) {
559*4882a593Smuzhiyun clip[i].x1 = rect->x1;
560*4882a593Smuzhiyun clip[i].y1 = rect->y1;
561*4882a593Smuzhiyun clip[i].x2 = rect->x2;
562*4882a593Smuzhiyun clip[i].y2 = rect->y2;
563*4882a593Smuzhiyun }
564*4882a593Smuzhiyun
565*4882a593Smuzhiyun /* TODO query connector property to see if this is needed */
566*4882a593Smuzhiyun ret = drmModeDirtyFB(ms->fd, fb_id, clip, num_cliprects);
567*4882a593Smuzhiyun
568*4882a593Smuzhiyun /* if we're swamping it with work, try one at a time */
569*4882a593Smuzhiyun if (ret == -EINVAL) {
570*4882a593Smuzhiyun for (i = 0; i < num_cliprects; i++) {
571*4882a593Smuzhiyun if ((ret = drmModeDirtyFB(ms->fd, fb_id, &clip[i], 1)) < 0)
572*4882a593Smuzhiyun break;
573*4882a593Smuzhiyun }
574*4882a593Smuzhiyun }
575*4882a593Smuzhiyun
576*4882a593Smuzhiyun free(clip);
577*4882a593Smuzhiyun DamageEmpty(damage);
578*4882a593Smuzhiyun }
579*4882a593Smuzhiyun return ret;
580*4882a593Smuzhiyun }
581*4882a593Smuzhiyun
582*4882a593Smuzhiyun static void
dispatch_dirty(ScreenPtr pScreen)583*4882a593Smuzhiyun dispatch_dirty(ScreenPtr pScreen)
584*4882a593Smuzhiyun {
585*4882a593Smuzhiyun ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen);
586*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(scrn);
587*4882a593Smuzhiyun PixmapPtr pixmap = pScreen->GetScreenPixmap(pScreen);
588*4882a593Smuzhiyun int fb_id = ms->drmmode.fb_id;
589*4882a593Smuzhiyun int ret;
590*4882a593Smuzhiyun
591*4882a593Smuzhiyun ret = dispatch_dirty_region(scrn, pixmap, ms->damage, fb_id);
592*4882a593Smuzhiyun if (ret == -EINVAL || ret == -ENOSYS) {
593*4882a593Smuzhiyun ms->dirty_enabled = FALSE;
594*4882a593Smuzhiyun DamageUnregister(ms->damage);
595*4882a593Smuzhiyun DamageDestroy(ms->damage);
596*4882a593Smuzhiyun ms->damage = NULL;
597*4882a593Smuzhiyun xf86DrvMsg(scrn->scrnIndex, X_INFO,
598*4882a593Smuzhiyun "Disabling kernel dirty updates, not required.\n");
599*4882a593Smuzhiyun return;
600*4882a593Smuzhiyun }
601*4882a593Smuzhiyun }
602*4882a593Smuzhiyun
603*4882a593Smuzhiyun static void
dispatch_dirty_pixmap(ScrnInfoPtr scrn,xf86CrtcPtr crtc,PixmapPtr ppix)604*4882a593Smuzhiyun dispatch_dirty_pixmap(ScrnInfoPtr scrn, xf86CrtcPtr crtc, PixmapPtr ppix)
605*4882a593Smuzhiyun {
606*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(scrn);
607*4882a593Smuzhiyun msPixmapPrivPtr ppriv = msGetPixmapPriv(&ms->drmmode, ppix);
608*4882a593Smuzhiyun DamagePtr damage = ppriv->slave_damage;
609*4882a593Smuzhiyun int fb_id = ppriv->fb_id;
610*4882a593Smuzhiyun
611*4882a593Smuzhiyun dispatch_dirty_region(scrn, ppix, damage, fb_id);
612*4882a593Smuzhiyun }
613*4882a593Smuzhiyun
614*4882a593Smuzhiyun static void
dispatch_slave_dirty(ScreenPtr pScreen)615*4882a593Smuzhiyun dispatch_slave_dirty(ScreenPtr pScreen)
616*4882a593Smuzhiyun {
617*4882a593Smuzhiyun ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen);
618*4882a593Smuzhiyun xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
619*4882a593Smuzhiyun int c;
620*4882a593Smuzhiyun
621*4882a593Smuzhiyun for (c = 0; c < xf86_config->num_crtc; c++) {
622*4882a593Smuzhiyun xf86CrtcPtr crtc = xf86_config->crtc[c];
623*4882a593Smuzhiyun drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
624*4882a593Smuzhiyun
625*4882a593Smuzhiyun if (!drmmode_crtc)
626*4882a593Smuzhiyun continue;
627*4882a593Smuzhiyun
628*4882a593Smuzhiyun if (drmmode_crtc->prime_pixmap)
629*4882a593Smuzhiyun dispatch_dirty_pixmap(scrn, crtc, drmmode_crtc->prime_pixmap);
630*4882a593Smuzhiyun if (drmmode_crtc->prime_pixmap_back)
631*4882a593Smuzhiyun dispatch_dirty_pixmap(scrn, crtc, drmmode_crtc->prime_pixmap_back);
632*4882a593Smuzhiyun }
633*4882a593Smuzhiyun }
634*4882a593Smuzhiyun
635*4882a593Smuzhiyun static void
redisplay_dirty(ScreenPtr screen,PixmapDirtyUpdatePtr dirty,int * timeout)636*4882a593Smuzhiyun redisplay_dirty(ScreenPtr screen, PixmapDirtyUpdatePtr dirty, int *timeout)
637*4882a593Smuzhiyun {
638*4882a593Smuzhiyun RegionRec pixregion;
639*4882a593Smuzhiyun
640*4882a593Smuzhiyun PixmapRegionInit(&pixregion, dirty->slave_dst);
641*4882a593Smuzhiyun DamageRegionAppend(&dirty->slave_dst->drawable, &pixregion);
642*4882a593Smuzhiyun PixmapSyncDirtyHelper(dirty);
643*4882a593Smuzhiyun
644*4882a593Smuzhiyun if (!screen->isGPU) {
645*4882a593Smuzhiyun #ifdef GLAMOR_HAS_GBM
646*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(screen));
647*4882a593Smuzhiyun /*
648*4882a593Smuzhiyun * When copying from the master framebuffer to the shared pixmap,
649*4882a593Smuzhiyun * we must ensure the copy is complete before the slave starts a
650*4882a593Smuzhiyun * copy to its own framebuffer (some slaves scanout directly from
651*4882a593Smuzhiyun * the shared pixmap, but not all).
652*4882a593Smuzhiyun */
653*4882a593Smuzhiyun if (ms->drmmode.glamor)
654*4882a593Smuzhiyun glamor_finish(screen);
655*4882a593Smuzhiyun #endif
656*4882a593Smuzhiyun /* Ensure the slave processes the damage immediately */
657*4882a593Smuzhiyun if (timeout)
658*4882a593Smuzhiyun *timeout = 0;
659*4882a593Smuzhiyun }
660*4882a593Smuzhiyun
661*4882a593Smuzhiyun DamageRegionProcessPending(&dirty->slave_dst->drawable);
662*4882a593Smuzhiyun RegionUninit(&pixregion);
663*4882a593Smuzhiyun }
664*4882a593Smuzhiyun
665*4882a593Smuzhiyun static void
ms_dirty_update(ScreenPtr screen,int * timeout)666*4882a593Smuzhiyun ms_dirty_update(ScreenPtr screen, int *timeout)
667*4882a593Smuzhiyun {
668*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(screen));
669*4882a593Smuzhiyun
670*4882a593Smuzhiyun RegionPtr region;
671*4882a593Smuzhiyun PixmapDirtyUpdatePtr ent;
672*4882a593Smuzhiyun
673*4882a593Smuzhiyun if (xorg_list_is_empty(&screen->pixmap_dirty_list))
674*4882a593Smuzhiyun return;
675*4882a593Smuzhiyun
676*4882a593Smuzhiyun xorg_list_for_each_entry(ent, &screen->pixmap_dirty_list, ent) {
677*4882a593Smuzhiyun region = DamageRegion(ent->damage);
678*4882a593Smuzhiyun if (RegionNotEmpty(region)) {
679*4882a593Smuzhiyun if (!screen->isGPU) {
680*4882a593Smuzhiyun msPixmapPrivPtr ppriv =
681*4882a593Smuzhiyun msGetPixmapPriv(&ms->drmmode, ent->slave_dst->master_pixmap);
682*4882a593Smuzhiyun
683*4882a593Smuzhiyun if (ppriv->notify_on_damage) {
684*4882a593Smuzhiyun ppriv->notify_on_damage = FALSE;
685*4882a593Smuzhiyun
686*4882a593Smuzhiyun ent->slave_dst->drawable.pScreen->
687*4882a593Smuzhiyun SharedPixmapNotifyDamage(ent->slave_dst);
688*4882a593Smuzhiyun }
689*4882a593Smuzhiyun
690*4882a593Smuzhiyun /* Requested manual updating */
691*4882a593Smuzhiyun if (ppriv->defer_dirty_update)
692*4882a593Smuzhiyun continue;
693*4882a593Smuzhiyun }
694*4882a593Smuzhiyun
695*4882a593Smuzhiyun redisplay_dirty(screen, ent, timeout);
696*4882a593Smuzhiyun DamageEmpty(ent->damage);
697*4882a593Smuzhiyun }
698*4882a593Smuzhiyun }
699*4882a593Smuzhiyun }
700*4882a593Smuzhiyun
701*4882a593Smuzhiyun static PixmapDirtyUpdatePtr
ms_dirty_get_ent(ScreenPtr screen,PixmapPtr slave_dst)702*4882a593Smuzhiyun ms_dirty_get_ent(ScreenPtr screen, PixmapPtr slave_dst)
703*4882a593Smuzhiyun {
704*4882a593Smuzhiyun PixmapDirtyUpdatePtr ent;
705*4882a593Smuzhiyun
706*4882a593Smuzhiyun if (xorg_list_is_empty(&screen->pixmap_dirty_list))
707*4882a593Smuzhiyun return NULL;
708*4882a593Smuzhiyun
709*4882a593Smuzhiyun xorg_list_for_each_entry(ent, &screen->pixmap_dirty_list, ent) {
710*4882a593Smuzhiyun if (ent->slave_dst == slave_dst)
711*4882a593Smuzhiyun return ent;
712*4882a593Smuzhiyun }
713*4882a593Smuzhiyun
714*4882a593Smuzhiyun return NULL;
715*4882a593Smuzhiyun }
716*4882a593Smuzhiyun
717*4882a593Smuzhiyun static Bool
msBlockHandler(ScreenPtr pScreen,void * timeout)718*4882a593Smuzhiyun msBlockHandler(ScreenPtr pScreen, void *timeout)
719*4882a593Smuzhiyun {
720*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(pScreen));
721*4882a593Smuzhiyun ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
722*4882a593Smuzhiyun xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
723*4882a593Smuzhiyun int c;
724*4882a593Smuzhiyun
725*4882a593Smuzhiyun /* HACK: Ignore the first request */
726*4882a593Smuzhiyun if (ms->warm_up) {
727*4882a593Smuzhiyun ms->warm_up = FALSE;
728*4882a593Smuzhiyun *((int *)timeout) = 16;
729*4882a593Smuzhiyun return FALSE;
730*4882a593Smuzhiyun }
731*4882a593Smuzhiyun
732*4882a593Smuzhiyun if (!access(getenv("XSERVER_FREEZE_DISPLAY") ? : "", F_OK)) {
733*4882a593Smuzhiyun *((int *)timeout) = 16;
734*4882a593Smuzhiyun return FALSE;
735*4882a593Smuzhiyun }
736*4882a593Smuzhiyun
737*4882a593Smuzhiyun pScreen->BlockHandler = ms->BlockHandler;
738*4882a593Smuzhiyun pScreen->BlockHandler(pScreen, timeout);
739*4882a593Smuzhiyun ms->BlockHandler = pScreen->BlockHandler;
740*4882a593Smuzhiyun pScreen->BlockHandler = (void *)msBlockHandler;
741*4882a593Smuzhiyun if (pScreen->isGPU && !ms->drmmode.reverse_prime_offload_mode)
742*4882a593Smuzhiyun dispatch_slave_dirty(pScreen);
743*4882a593Smuzhiyun else {
744*4882a593Smuzhiyun if (ms->dirty_enabled)
745*4882a593Smuzhiyun dispatch_dirty(pScreen);
746*4882a593Smuzhiyun
747*4882a593Smuzhiyun for (c = 0; c < xf86_config->num_crtc; c++) {
748*4882a593Smuzhiyun xf86CrtcPtr crtc = xf86_config->crtc[c];
749*4882a593Smuzhiyun drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
750*4882a593Smuzhiyun
751*4882a593Smuzhiyun if (!drmmode_crtc || drmmode_flip_fb(crtc, timeout))
752*4882a593Smuzhiyun continue;
753*4882a593Smuzhiyun
754*4882a593Smuzhiyun drmmode_crtc->can_flip_fb = FALSE;
755*4882a593Smuzhiyun drmmode_set_desired_modes(pScrn, &ms->drmmode, TRUE, FALSE);
756*4882a593Smuzhiyun break;
757*4882a593Smuzhiyun }
758*4882a593Smuzhiyun }
759*4882a593Smuzhiyun
760*4882a593Smuzhiyun ms_dirty_update(pScreen, timeout);
761*4882a593Smuzhiyun return TRUE;
762*4882a593Smuzhiyun }
763*4882a593Smuzhiyun
764*4882a593Smuzhiyun static void
msBlockHandler_oneshot(ScreenPtr pScreen,void * pTimeout)765*4882a593Smuzhiyun msBlockHandler_oneshot(ScreenPtr pScreen, void *pTimeout)
766*4882a593Smuzhiyun {
767*4882a593Smuzhiyun ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
768*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(pScrn);
769*4882a593Smuzhiyun
770*4882a593Smuzhiyun if (!msBlockHandler(pScreen, pTimeout))
771*4882a593Smuzhiyun return;
772*4882a593Smuzhiyun
773*4882a593Smuzhiyun drmmode_set_desired_modes(pScrn, &ms->drmmode, TRUE, FALSE);
774*4882a593Smuzhiyun }
775*4882a593Smuzhiyun
776*4882a593Smuzhiyun static void
FreeRec(ScrnInfoPtr pScrn)777*4882a593Smuzhiyun FreeRec(ScrnInfoPtr pScrn)
778*4882a593Smuzhiyun {
779*4882a593Smuzhiyun modesettingPtr ms;
780*4882a593Smuzhiyun
781*4882a593Smuzhiyun if (!pScrn)
782*4882a593Smuzhiyun return;
783*4882a593Smuzhiyun
784*4882a593Smuzhiyun ms = modesettingPTR(pScrn);
785*4882a593Smuzhiyun if (!ms)
786*4882a593Smuzhiyun return;
787*4882a593Smuzhiyun
788*4882a593Smuzhiyun if (ms->fd > 0) {
789*4882a593Smuzhiyun modesettingEntPtr ms_ent;
790*4882a593Smuzhiyun int ret;
791*4882a593Smuzhiyun
792*4882a593Smuzhiyun ms_ent = ms_ent_priv(pScrn);
793*4882a593Smuzhiyun ms_ent->fd_ref--;
794*4882a593Smuzhiyun if (!ms_ent->fd_ref) {
795*4882a593Smuzhiyun if (ms->pEnt->location.type == BUS_PCI)
796*4882a593Smuzhiyun ret = drmClose(ms->fd);
797*4882a593Smuzhiyun else
798*4882a593Smuzhiyun #ifdef XF86_PDEV_SERVER_FD
799*4882a593Smuzhiyun if (!(ms->pEnt->location.type == BUS_PLATFORM &&
800*4882a593Smuzhiyun (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD)))
801*4882a593Smuzhiyun #endif
802*4882a593Smuzhiyun ret = close(ms->fd);
803*4882a593Smuzhiyun (void) ret;
804*4882a593Smuzhiyun ms_ent->fd = 0;
805*4882a593Smuzhiyun }
806*4882a593Smuzhiyun }
807*4882a593Smuzhiyun pScrn->driverPrivate = NULL;
808*4882a593Smuzhiyun free(ms->drmmode.Options);
809*4882a593Smuzhiyun free(ms);
810*4882a593Smuzhiyun
811*4882a593Smuzhiyun }
812*4882a593Smuzhiyun
813*4882a593Smuzhiyun static void
try_enable_exa(ScrnInfoPtr pScrn)814*4882a593Smuzhiyun try_enable_exa(ScrnInfoPtr pScrn)
815*4882a593Smuzhiyun {
816*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(pScrn);
817*4882a593Smuzhiyun
818*4882a593Smuzhiyun if (xf86LoadSubModule(pScrn, "exa"))
819*4882a593Smuzhiyun ms_init_exa(pScrn);
820*4882a593Smuzhiyun
821*4882a593Smuzhiyun if (ms->drmmode.exa)
822*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_INFO, "exa initialized\n");
823*4882a593Smuzhiyun else
824*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "exa initialization failed\n");
825*4882a593Smuzhiyun }
826*4882a593Smuzhiyun
827*4882a593Smuzhiyun static void
try_enable_glamor(ScrnInfoPtr pScrn)828*4882a593Smuzhiyun try_enable_glamor(ScrnInfoPtr pScrn)
829*4882a593Smuzhiyun {
830*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(pScrn);
831*4882a593Smuzhiyun const char *accel_method_str = xf86GetOptValString(ms->drmmode.Options,
832*4882a593Smuzhiyun OPTION_ACCEL_METHOD);
833*4882a593Smuzhiyun Bool do_glamor = (!accel_method_str ||
834*4882a593Smuzhiyun strcmp(accel_method_str, "glamor") == 0);
835*4882a593Smuzhiyun
836*4882a593Smuzhiyun ms->drmmode.glamor = FALSE;
837*4882a593Smuzhiyun
838*4882a593Smuzhiyun #ifdef GLAMOR_HAS_GBM
839*4882a593Smuzhiyun if (ms->drmmode.force_24_32) {
840*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Cannot use glamor with 24bpp packed fb\n");
841*4882a593Smuzhiyun return;
842*4882a593Smuzhiyun }
843*4882a593Smuzhiyun
844*4882a593Smuzhiyun if (!do_glamor) {
845*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "glamor disabled\n");
846*4882a593Smuzhiyun return;
847*4882a593Smuzhiyun }
848*4882a593Smuzhiyun
849*4882a593Smuzhiyun if (xf86LoadSubModule(pScrn, GLAMOR_EGL_MODULE_NAME)) {
850*4882a593Smuzhiyun if (glamor_egl_init(pScrn, ms->fd)) {
851*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_INFO, "glamor initialized\n");
852*4882a593Smuzhiyun ms->drmmode.glamor = TRUE;
853*4882a593Smuzhiyun } else {
854*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
855*4882a593Smuzhiyun "glamor initialization failed\n");
856*4882a593Smuzhiyun }
857*4882a593Smuzhiyun } else {
858*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
859*4882a593Smuzhiyun "Failed to load glamor module.\n");
860*4882a593Smuzhiyun }
861*4882a593Smuzhiyun #else
862*4882a593Smuzhiyun if (do_glamor) {
863*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_INFO,
864*4882a593Smuzhiyun "No glamor support in the X Server\n");
865*4882a593Smuzhiyun }
866*4882a593Smuzhiyun #endif
867*4882a593Smuzhiyun }
868*4882a593Smuzhiyun
869*4882a593Smuzhiyun static Bool
msShouldDoubleShadow(ScrnInfoPtr pScrn,modesettingPtr ms)870*4882a593Smuzhiyun msShouldDoubleShadow(ScrnInfoPtr pScrn, modesettingPtr ms)
871*4882a593Smuzhiyun {
872*4882a593Smuzhiyun Bool ret = FALSE, asked;
873*4882a593Smuzhiyun int from;
874*4882a593Smuzhiyun drmVersionPtr v;
875*4882a593Smuzhiyun
876*4882a593Smuzhiyun if (!ms->drmmode.shadow_enable)
877*4882a593Smuzhiyun return FALSE;
878*4882a593Smuzhiyun
879*4882a593Smuzhiyun v = drmGetVersion(ms->fd);
880*4882a593Smuzhiyun if (!strcmp(v->name, "mgag200") ||
881*4882a593Smuzhiyun !strcmp(v->name, "ast")) /* XXX || rn50 */
882*4882a593Smuzhiyun ret = TRUE;
883*4882a593Smuzhiyun
884*4882a593Smuzhiyun drmFreeVersion(v);
885*4882a593Smuzhiyun
886*4882a593Smuzhiyun asked = xf86GetOptValBool(ms->drmmode.Options, OPTION_DOUBLE_SHADOW, &ret);
887*4882a593Smuzhiyun
888*4882a593Smuzhiyun if (asked)
889*4882a593Smuzhiyun from = X_CONFIG;
890*4882a593Smuzhiyun else
891*4882a593Smuzhiyun from = X_INFO;
892*4882a593Smuzhiyun
893*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, from,
894*4882a593Smuzhiyun "Double-buffered shadow updates: %s\n", ret ? "on" : "off");
895*4882a593Smuzhiyun
896*4882a593Smuzhiyun return ret;
897*4882a593Smuzhiyun }
898*4882a593Smuzhiyun
899*4882a593Smuzhiyun static Bool
ms_get_drm_master_fd(ScrnInfoPtr pScrn)900*4882a593Smuzhiyun ms_get_drm_master_fd(ScrnInfoPtr pScrn)
901*4882a593Smuzhiyun {
902*4882a593Smuzhiyun EntityInfoPtr pEnt;
903*4882a593Smuzhiyun modesettingPtr ms;
904*4882a593Smuzhiyun modesettingEntPtr ms_ent;
905*4882a593Smuzhiyun
906*4882a593Smuzhiyun ms = modesettingPTR(pScrn);
907*4882a593Smuzhiyun ms_ent = ms_ent_priv(pScrn);
908*4882a593Smuzhiyun
909*4882a593Smuzhiyun pEnt = ms->pEnt;
910*4882a593Smuzhiyun
911*4882a593Smuzhiyun if (ms_ent->fd) {
912*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_INFO,
913*4882a593Smuzhiyun " reusing fd for second head\n");
914*4882a593Smuzhiyun ms->fd = ms_ent->fd;
915*4882a593Smuzhiyun ms_ent->fd_ref++;
916*4882a593Smuzhiyun return TRUE;
917*4882a593Smuzhiyun }
918*4882a593Smuzhiyun
919*4882a593Smuzhiyun ms->fd_passed = FALSE;
920*4882a593Smuzhiyun if ((ms->fd = get_passed_fd()) >= 0) {
921*4882a593Smuzhiyun ms->fd_passed = TRUE;
922*4882a593Smuzhiyun return TRUE;
923*4882a593Smuzhiyun }
924*4882a593Smuzhiyun
925*4882a593Smuzhiyun #ifdef XSERVER_PLATFORM_BUS
926*4882a593Smuzhiyun if (pEnt->location.type == BUS_PLATFORM) {
927*4882a593Smuzhiyun #ifdef XF86_PDEV_SERVER_FD
928*4882a593Smuzhiyun if (pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD)
929*4882a593Smuzhiyun ms->fd =
930*4882a593Smuzhiyun xf86_platform_device_odev_attributes(pEnt->location.id.plat)->
931*4882a593Smuzhiyun fd;
932*4882a593Smuzhiyun else
933*4882a593Smuzhiyun #endif
934*4882a593Smuzhiyun {
935*4882a593Smuzhiyun char *path =
936*4882a593Smuzhiyun xf86_platform_device_odev_attributes(pEnt->location.id.plat)->
937*4882a593Smuzhiyun path;
938*4882a593Smuzhiyun ms->fd = open_hw(path);
939*4882a593Smuzhiyun }
940*4882a593Smuzhiyun }
941*4882a593Smuzhiyun else
942*4882a593Smuzhiyun #endif
943*4882a593Smuzhiyun #ifdef XSERVER_LIBPCIACCESS
944*4882a593Smuzhiyun if (pEnt->location.type == BUS_PCI) {
945*4882a593Smuzhiyun char *BusID = NULL;
946*4882a593Smuzhiyun struct pci_device *PciInfo;
947*4882a593Smuzhiyun
948*4882a593Smuzhiyun PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
949*4882a593Smuzhiyun if (PciInfo) {
950*4882a593Smuzhiyun if ((BusID = ms_DRICreatePCIBusID(PciInfo)) != NULL) {
951*4882a593Smuzhiyun ms->fd = drmOpen(NULL, BusID);
952*4882a593Smuzhiyun free(BusID);
953*4882a593Smuzhiyun }
954*4882a593Smuzhiyun }
955*4882a593Smuzhiyun }
956*4882a593Smuzhiyun else
957*4882a593Smuzhiyun #endif
958*4882a593Smuzhiyun {
959*4882a593Smuzhiyun const char *devicename;
960*4882a593Smuzhiyun devicename = xf86FindOptionValue(ms->pEnt->device->options, "kmsdev");
961*4882a593Smuzhiyun ms->fd = open_hw(devicename);
962*4882a593Smuzhiyun }
963*4882a593Smuzhiyun if (ms->fd < 0)
964*4882a593Smuzhiyun return FALSE;
965*4882a593Smuzhiyun
966*4882a593Smuzhiyun ms_ent->fd = ms->fd;
967*4882a593Smuzhiyun ms_ent->fd_ref = 1;
968*4882a593Smuzhiyun return TRUE;
969*4882a593Smuzhiyun }
970*4882a593Smuzhiyun
971*4882a593Smuzhiyun static Bool
PreInit(ScrnInfoPtr pScrn,int flags)972*4882a593Smuzhiyun PreInit(ScrnInfoPtr pScrn, int flags)
973*4882a593Smuzhiyun {
974*4882a593Smuzhiyun modesettingPtr ms;
975*4882a593Smuzhiyun rgb defaultWeight = { 0, 0, 0 };
976*4882a593Smuzhiyun EntityInfoPtr pEnt;
977*4882a593Smuzhiyun const char *str_value;
978*4882a593Smuzhiyun uint64_t value = 0;
979*4882a593Smuzhiyun int ret;
980*4882a593Smuzhiyun int bppflags, connector_count;
981*4882a593Smuzhiyun int defaultdepth, defaultbpp;
982*4882a593Smuzhiyun
983*4882a593Smuzhiyun if (pScrn->numEntities != 1)
984*4882a593Smuzhiyun return FALSE;
985*4882a593Smuzhiyun
986*4882a593Smuzhiyun if (flags & PROBE_DETECT) {
987*4882a593Smuzhiyun return FALSE;
988*4882a593Smuzhiyun }
989*4882a593Smuzhiyun
990*4882a593Smuzhiyun /* Allocate driverPrivate */
991*4882a593Smuzhiyun if (!GetRec(pScrn))
992*4882a593Smuzhiyun return FALSE;
993*4882a593Smuzhiyun
994*4882a593Smuzhiyun pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
995*4882a593Smuzhiyun
996*4882a593Smuzhiyun ms = modesettingPTR(pScrn);
997*4882a593Smuzhiyun ms->SaveGeneration = -1;
998*4882a593Smuzhiyun ms->pEnt = pEnt;
999*4882a593Smuzhiyun ms->drmmode.is_secondary = FALSE;
1000*4882a593Smuzhiyun pScrn->displayWidth = 640; /* default it */
1001*4882a593Smuzhiyun
1002*4882a593Smuzhiyun if (xf86IsEntityShared(pScrn->entityList[0])) {
1003*4882a593Smuzhiyun if (xf86IsPrimInitDone(pScrn->entityList[0]))
1004*4882a593Smuzhiyun ms->drmmode.is_secondary = TRUE;
1005*4882a593Smuzhiyun else
1006*4882a593Smuzhiyun xf86SetPrimInitDone(pScrn->entityList[0]);
1007*4882a593Smuzhiyun }
1008*4882a593Smuzhiyun
1009*4882a593Smuzhiyun pScrn->monitor = pScrn->confScreen->monitor;
1010*4882a593Smuzhiyun pScrn->progClock = TRUE;
1011*4882a593Smuzhiyun pScrn->rgbBits = 8;
1012*4882a593Smuzhiyun
1013*4882a593Smuzhiyun if (!ms_get_drm_master_fd(pScrn))
1014*4882a593Smuzhiyun return FALSE;
1015*4882a593Smuzhiyun ms->drmmode.fd = ms->fd;
1016*4882a593Smuzhiyun
1017*4882a593Smuzhiyun if (!check_outputs(ms->fd, &connector_count))
1018*4882a593Smuzhiyun return FALSE;
1019*4882a593Smuzhiyun
1020*4882a593Smuzhiyun drmmode_get_default_bpp(pScrn, &ms->drmmode, &defaultdepth, &defaultbpp);
1021*4882a593Smuzhiyun if (defaultdepth == 24 && defaultbpp == 24) {
1022*4882a593Smuzhiyun ms->drmmode.force_24_32 = TRUE;
1023*4882a593Smuzhiyun ms->drmmode.kbpp = 24;
1024*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1025*4882a593Smuzhiyun "Using 24bpp hw front buffer with 32bpp shadow\n");
1026*4882a593Smuzhiyun defaultbpp = 32;
1027*4882a593Smuzhiyun } else {
1028*4882a593Smuzhiyun ms->drmmode.kbpp = 0;
1029*4882a593Smuzhiyun }
1030*4882a593Smuzhiyun bppflags = PreferConvert24to32 | SupportConvert24to32 | Support32bppFb;
1031*4882a593Smuzhiyun
1032*4882a593Smuzhiyun if (!xf86SetDepthBpp
1033*4882a593Smuzhiyun (pScrn, defaultdepth, defaultdepth, defaultbpp, bppflags))
1034*4882a593Smuzhiyun return FALSE;
1035*4882a593Smuzhiyun
1036*4882a593Smuzhiyun switch (pScrn->depth) {
1037*4882a593Smuzhiyun case 15:
1038*4882a593Smuzhiyun case 16:
1039*4882a593Smuzhiyun case 24:
1040*4882a593Smuzhiyun case 30:
1041*4882a593Smuzhiyun break;
1042*4882a593Smuzhiyun default:
1043*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1044*4882a593Smuzhiyun "Given depth (%d) is not supported by the driver\n",
1045*4882a593Smuzhiyun pScrn->depth);
1046*4882a593Smuzhiyun return FALSE;
1047*4882a593Smuzhiyun }
1048*4882a593Smuzhiyun xf86PrintDepthBpp(pScrn);
1049*4882a593Smuzhiyun if (!ms->drmmode.kbpp)
1050*4882a593Smuzhiyun ms->drmmode.kbpp = pScrn->bitsPerPixel;
1051*4882a593Smuzhiyun
1052*4882a593Smuzhiyun /* Process the options */
1053*4882a593Smuzhiyun xf86CollectOptions(pScrn, NULL);
1054*4882a593Smuzhiyun if (!(ms->drmmode.Options = malloc(sizeof(Options))))
1055*4882a593Smuzhiyun return FALSE;
1056*4882a593Smuzhiyun memcpy(ms->drmmode.Options, Options, sizeof(Options));
1057*4882a593Smuzhiyun xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->drmmode.Options);
1058*4882a593Smuzhiyun
1059*4882a593Smuzhiyun if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight))
1060*4882a593Smuzhiyun return FALSE;
1061*4882a593Smuzhiyun if (!xf86SetDefaultVisual(pScrn, -1))
1062*4882a593Smuzhiyun return FALSE;
1063*4882a593Smuzhiyun
1064*4882a593Smuzhiyun if (xf86ReturnOptValBool(ms->drmmode.Options, OPTION_SW_CURSOR, FALSE)) {
1065*4882a593Smuzhiyun ms->drmmode.sw_cursor = TRUE;
1066*4882a593Smuzhiyun }
1067*4882a593Smuzhiyun
1068*4882a593Smuzhiyun ms->cursor_width = 64;
1069*4882a593Smuzhiyun ms->cursor_height = 64;
1070*4882a593Smuzhiyun ret = drmGetCap(ms->fd, DRM_CAP_CURSOR_WIDTH, &value);
1071*4882a593Smuzhiyun if (!ret) {
1072*4882a593Smuzhiyun ms->cursor_width = value;
1073*4882a593Smuzhiyun }
1074*4882a593Smuzhiyun ret = drmGetCap(ms->fd, DRM_CAP_CURSOR_HEIGHT, &value);
1075*4882a593Smuzhiyun if (!ret) {
1076*4882a593Smuzhiyun ms->cursor_height = value;
1077*4882a593Smuzhiyun }
1078*4882a593Smuzhiyun
1079*4882a593Smuzhiyun try_enable_glamor(pScrn);
1080*4882a593Smuzhiyun
1081*4882a593Smuzhiyun if (!ms->drmmode.glamor) {
1082*4882a593Smuzhiyun Bool prefer_shadow = TRUE;
1083*4882a593Smuzhiyun
1084*4882a593Smuzhiyun if (ms->drmmode.force_24_32) {
1085*4882a593Smuzhiyun prefer_shadow = TRUE;
1086*4882a593Smuzhiyun ms->drmmode.shadow_enable = TRUE;
1087*4882a593Smuzhiyun } else {
1088*4882a593Smuzhiyun ret = drmGetCap(ms->fd, DRM_CAP_DUMB_PREFER_SHADOW, &value);
1089*4882a593Smuzhiyun if (!ret) {
1090*4882a593Smuzhiyun prefer_shadow = !!value;
1091*4882a593Smuzhiyun }
1092*4882a593Smuzhiyun
1093*4882a593Smuzhiyun ms->drmmode.shadow_enable =
1094*4882a593Smuzhiyun xf86ReturnOptValBool(ms->drmmode.Options, OPTION_SHADOW_FB,
1095*4882a593Smuzhiyun prefer_shadow);
1096*4882a593Smuzhiyun }
1097*4882a593Smuzhiyun
1098*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1099*4882a593Smuzhiyun "ShadowFB: preferred %s, enabled %s\n",
1100*4882a593Smuzhiyun prefer_shadow ? "YES" : "NO",
1101*4882a593Smuzhiyun ms->drmmode.force_24_32 ? "FORCE" :
1102*4882a593Smuzhiyun ms->drmmode.shadow_enable ? "YES" : "NO");
1103*4882a593Smuzhiyun
1104*4882a593Smuzhiyun ms->drmmode.shadow_enable2 = msShouldDoubleShadow(pScrn, ms);
1105*4882a593Smuzhiyun }
1106*4882a593Smuzhiyun
1107*4882a593Smuzhiyun ms->drmmode.pageflip =
1108*4882a593Smuzhiyun xf86ReturnOptValBool(ms->drmmode.Options, OPTION_PAGEFLIP, TRUE);
1109*4882a593Smuzhiyun
1110*4882a593Smuzhiyun ms->drmmode.hotplug_reset =
1111*4882a593Smuzhiyun xf86ReturnOptValBool(ms->drmmode.Options, OPTION_HOTPLUG_RESET, TRUE);
1112*4882a593Smuzhiyun
1113*4882a593Smuzhiyun ms->warm_up =
1114*4882a593Smuzhiyun xf86ReturnOptValBool(ms->drmmode.Options, OPTION_WARM_UP, TRUE);
1115*4882a593Smuzhiyun
1116*4882a593Smuzhiyun str_value = xf86GetOptValString(ms->drmmode.Options, OPTION_FLIP_FB);
1117*4882a593Smuzhiyun if (!str_value || !strcmp(str_value, "transformed"))
1118*4882a593Smuzhiyun ms->drmmode.fb_flip_mode = DRMMODE_FB_FLIP_TRANSFORMED;
1119*4882a593Smuzhiyun else if (!strcmp(str_value, "always"))
1120*4882a593Smuzhiyun ms->drmmode.fb_flip_mode = DRMMODE_FB_FLIP_ALWAYS;
1121*4882a593Smuzhiyun else
1122*4882a593Smuzhiyun ms->drmmode.fb_flip_mode = DRMMODE_FB_FLIP_NONE;
1123*4882a593Smuzhiyun
1124*4882a593Smuzhiyun ret = -1;
1125*4882a593Smuzhiyun xf86GetOptValInteger(ms->drmmode.Options, OPTION_FLIP_FB_RATE, &ret);
1126*4882a593Smuzhiyun ms->drmmode.fb_flip_rate = ret > 0 ? ret : 0;
1127*4882a593Smuzhiyun
1128*4882a593Smuzhiyun if (ms->drmmode.fb_flip_mode != DRMMODE_FB_FLIP_NONE)
1129*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1130*4882a593Smuzhiyun "FlipFB: %s, limited to: %d fps\n",
1131*4882a593Smuzhiyun (ms->drmmode.fb_flip_mode == DRMMODE_FB_FLIP_ALWAYS ?
1132*4882a593Smuzhiyun "Always" : "Transformed"), ms->drmmode.fb_flip_rate ?: -1);
1133*4882a593Smuzhiyun
1134*4882a593Smuzhiyun pScrn->capabilities = 0;
1135*4882a593Smuzhiyun ret = drmGetCap(ms->fd, DRM_CAP_PRIME, &value);
1136*4882a593Smuzhiyun if (ret == 0) {
1137*4882a593Smuzhiyun if (connector_count && (value & DRM_PRIME_CAP_IMPORT)) {
1138*4882a593Smuzhiyun pScrn->capabilities |= RR_Capability_SinkOutput;
1139*4882a593Smuzhiyun if (ms->drmmode.glamor)
1140*4882a593Smuzhiyun pScrn->capabilities |= RR_Capability_SinkOffload;
1141*4882a593Smuzhiyun }
1142*4882a593Smuzhiyun #ifdef GLAMOR_HAS_GBM_LINEAR
1143*4882a593Smuzhiyun if (value & DRM_PRIME_CAP_EXPORT && ms->drmmode.glamor)
1144*4882a593Smuzhiyun pScrn->capabilities |= RR_Capability_SourceOutput | RR_Capability_SourceOffload;
1145*4882a593Smuzhiyun #endif
1146*4882a593Smuzhiyun }
1147*4882a593Smuzhiyun
1148*4882a593Smuzhiyun if (xf86ReturnOptValBool(ms->drmmode.Options, OPTION_ATOMIC, FALSE)) {
1149*4882a593Smuzhiyun ret = drmSetClientCap(ms->fd, DRM_CLIENT_CAP_ATOMIC, 1);
1150*4882a593Smuzhiyun ms->atomic_modeset = (ret == 0);
1151*4882a593Smuzhiyun } else {
1152*4882a593Smuzhiyun ms->atomic_modeset = FALSE;
1153*4882a593Smuzhiyun }
1154*4882a593Smuzhiyun
1155*4882a593Smuzhiyun /* HACK: Force disabling atomic APIs */
1156*4882a593Smuzhiyun ms->atomic_modeset = 0;
1157*4882a593Smuzhiyun
1158*4882a593Smuzhiyun /* Try to enable atomic cap, but not doing atomic modeset */
1159*4882a593Smuzhiyun drmSetClientCap(ms->fd, DRM_CLIENT_CAP_ATOMIC, 2);
1160*4882a593Smuzhiyun
1161*4882a593Smuzhiyun drmSetClientCap(ms->fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
1162*4882a593Smuzhiyun
1163*4882a593Smuzhiyun ms->async_pageflip = FALSE;
1164*4882a593Smuzhiyun ret = drmGetCap(ms->fd, DRM_CAP_ASYNC_PAGE_FLIP, &value);
1165*4882a593Smuzhiyun if (ret == 0 && value == 1)
1166*4882a593Smuzhiyun ms->async_pageflip = TRUE;
1167*4882a593Smuzhiyun
1168*4882a593Smuzhiyun /* HACK: The Rockchip BSP kernel might wrongly enable it */
1169*4882a593Smuzhiyun ms->async_pageflip = FALSE;
1170*4882a593Smuzhiyun
1171*4882a593Smuzhiyun ms->kms_has_modifiers = FALSE;
1172*4882a593Smuzhiyun ret = drmGetCap(ms->fd, DRM_CAP_ADDFB2_MODIFIERS, &value);
1173*4882a593Smuzhiyun if (ret == 0 && value != 0)
1174*4882a593Smuzhiyun ms->kms_has_modifiers = TRUE;
1175*4882a593Smuzhiyun
1176*4882a593Smuzhiyun if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) {
1177*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n");
1178*4882a593Smuzhiyun goto fail;
1179*4882a593Smuzhiyun }
1180*4882a593Smuzhiyun
1181*4882a593Smuzhiyun /*
1182*4882a593Smuzhiyun * If the driver can do gamma correction, it should call xf86SetGamma() here.
1183*4882a593Smuzhiyun */
1184*4882a593Smuzhiyun {
1185*4882a593Smuzhiyun Gamma zeros = { 0.0, 0.0, 0.0 };
1186*4882a593Smuzhiyun
1187*4882a593Smuzhiyun if (!xf86SetGamma(pScrn, zeros)) {
1188*4882a593Smuzhiyun return FALSE;
1189*4882a593Smuzhiyun }
1190*4882a593Smuzhiyun }
1191*4882a593Smuzhiyun
1192*4882a593Smuzhiyun if (!(pScrn->is_gpu && connector_count == 0) && pScrn->modes == NULL) {
1193*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No modes.\n");
1194*4882a593Smuzhiyun return FALSE;
1195*4882a593Smuzhiyun }
1196*4882a593Smuzhiyun
1197*4882a593Smuzhiyun pScrn->currentMode = pScrn->modes;
1198*4882a593Smuzhiyun
1199*4882a593Smuzhiyun /* Set display resolution */
1200*4882a593Smuzhiyun xf86SetDpi(pScrn, 0, 0);
1201*4882a593Smuzhiyun
1202*4882a593Smuzhiyun /* Load the required sub modules */
1203*4882a593Smuzhiyun if (!xf86LoadSubModule(pScrn, "fb")) {
1204*4882a593Smuzhiyun return FALSE;
1205*4882a593Smuzhiyun }
1206*4882a593Smuzhiyun
1207*4882a593Smuzhiyun if (ms->drmmode.shadow_enable) {
1208*4882a593Smuzhiyun if (!xf86LoadSubModule(pScrn, "shadow")) {
1209*4882a593Smuzhiyun return FALSE;
1210*4882a593Smuzhiyun }
1211*4882a593Smuzhiyun }
1212*4882a593Smuzhiyun
1213*4882a593Smuzhiyun return TRUE;
1214*4882a593Smuzhiyun fail:
1215*4882a593Smuzhiyun return FALSE;
1216*4882a593Smuzhiyun }
1217*4882a593Smuzhiyun
1218*4882a593Smuzhiyun static void *
msShadowWindow(ScreenPtr screen,CARD32 row,CARD32 offset,int mode,CARD32 * size,void * closure)1219*4882a593Smuzhiyun msShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset, int mode,
1220*4882a593Smuzhiyun CARD32 *size, void *closure)
1221*4882a593Smuzhiyun {
1222*4882a593Smuzhiyun ScrnInfoPtr pScrn = xf86ScreenToScrn(screen);
1223*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(pScrn);
1224*4882a593Smuzhiyun int stride;
1225*4882a593Smuzhiyun
1226*4882a593Smuzhiyun stride = (pScrn->displayWidth * ms->drmmode.kbpp) / 8;
1227*4882a593Smuzhiyun *size = stride;
1228*4882a593Smuzhiyun
1229*4882a593Smuzhiyun return ((uint8_t *) ms->drmmode.front_bo.dumb->ptr + row * stride + offset);
1230*4882a593Smuzhiyun }
1231*4882a593Smuzhiyun
1232*4882a593Smuzhiyun /* somewhat arbitrary tile size, in pixels */
1233*4882a593Smuzhiyun #define TILE 16
1234*4882a593Smuzhiyun
1235*4882a593Smuzhiyun static int
msUpdateIntersect(modesettingPtr ms,shadowBufPtr pBuf,BoxPtr box,xRectangle * prect)1236*4882a593Smuzhiyun msUpdateIntersect(modesettingPtr ms, shadowBufPtr pBuf, BoxPtr box,
1237*4882a593Smuzhiyun xRectangle *prect)
1238*4882a593Smuzhiyun {
1239*4882a593Smuzhiyun int i, dirty = 0, stride = pBuf->pPixmap->devKind, cpp = ms->drmmode.cpp;
1240*4882a593Smuzhiyun int width = (box->x2 - box->x1) * cpp;
1241*4882a593Smuzhiyun unsigned char *old, *new;
1242*4882a593Smuzhiyun
1243*4882a593Smuzhiyun old = ms->drmmode.shadow_fb2;
1244*4882a593Smuzhiyun old += (box->y1 * stride) + (box->x1 * cpp);
1245*4882a593Smuzhiyun new = ms->drmmode.shadow_fb;
1246*4882a593Smuzhiyun new += (box->y1 * stride) + (box->x1 * cpp);
1247*4882a593Smuzhiyun
1248*4882a593Smuzhiyun for (i = box->y2 - box->y1 - 1; i >= 0; i--) {
1249*4882a593Smuzhiyun unsigned char *o = old + i * stride,
1250*4882a593Smuzhiyun *n = new + i * stride;
1251*4882a593Smuzhiyun if (memcmp(o, n, width) != 0) {
1252*4882a593Smuzhiyun dirty = 1;
1253*4882a593Smuzhiyun memcpy(o, n, width);
1254*4882a593Smuzhiyun }
1255*4882a593Smuzhiyun }
1256*4882a593Smuzhiyun
1257*4882a593Smuzhiyun if (dirty) {
1258*4882a593Smuzhiyun prect->x = box->x1;
1259*4882a593Smuzhiyun prect->y = box->y1;
1260*4882a593Smuzhiyun prect->width = box->x2 - box->x1;
1261*4882a593Smuzhiyun prect->height = box->y2 - box->y1;
1262*4882a593Smuzhiyun }
1263*4882a593Smuzhiyun
1264*4882a593Smuzhiyun return dirty;
1265*4882a593Smuzhiyun }
1266*4882a593Smuzhiyun
1267*4882a593Smuzhiyun static void
msUpdatePacked(ScreenPtr pScreen,shadowBufPtr pBuf)1268*4882a593Smuzhiyun msUpdatePacked(ScreenPtr pScreen, shadowBufPtr pBuf)
1269*4882a593Smuzhiyun {
1270*4882a593Smuzhiyun ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
1271*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(pScrn);
1272*4882a593Smuzhiyun Bool use_3224 = ms->drmmode.force_24_32 && pScrn->bitsPerPixel == 32;
1273*4882a593Smuzhiyun
1274*4882a593Smuzhiyun if (ms->drmmode.shadow_enable2 && ms->drmmode.shadow_fb2) do {
1275*4882a593Smuzhiyun RegionPtr damage = DamageRegion(pBuf->pDamage), tiles;
1276*4882a593Smuzhiyun BoxPtr extents = RegionExtents(damage);
1277*4882a593Smuzhiyun xRectangle *prect;
1278*4882a593Smuzhiyun int nrects;
1279*4882a593Smuzhiyun int i, j, tx1, tx2, ty1, ty2;
1280*4882a593Smuzhiyun
1281*4882a593Smuzhiyun tx1 = extents->x1 / TILE;
1282*4882a593Smuzhiyun tx2 = (extents->x2 + TILE - 1) / TILE;
1283*4882a593Smuzhiyun ty1 = extents->y1 / TILE;
1284*4882a593Smuzhiyun ty2 = (extents->y2 + TILE - 1) / TILE;
1285*4882a593Smuzhiyun
1286*4882a593Smuzhiyun nrects = (tx2 - tx1) * (ty2 - ty1);
1287*4882a593Smuzhiyun if (!(prect = calloc(nrects, sizeof(xRectangle))))
1288*4882a593Smuzhiyun break;
1289*4882a593Smuzhiyun
1290*4882a593Smuzhiyun nrects = 0;
1291*4882a593Smuzhiyun for (j = ty2 - 1; j >= ty1; j--) {
1292*4882a593Smuzhiyun for (i = tx2 - 1; i >= tx1; i--) {
1293*4882a593Smuzhiyun BoxRec box;
1294*4882a593Smuzhiyun
1295*4882a593Smuzhiyun box.x1 = max(i * TILE, extents->x1);
1296*4882a593Smuzhiyun box.y1 = max(j * TILE, extents->y1);
1297*4882a593Smuzhiyun box.x2 = min((i+1) * TILE, extents->x2);
1298*4882a593Smuzhiyun box.y2 = min((j+1) * TILE, extents->y2);
1299*4882a593Smuzhiyun
1300*4882a593Smuzhiyun if (RegionContainsRect(damage, &box) != rgnOUT) {
1301*4882a593Smuzhiyun if (msUpdateIntersect(ms, pBuf, &box, prect + nrects)) {
1302*4882a593Smuzhiyun nrects++;
1303*4882a593Smuzhiyun }
1304*4882a593Smuzhiyun }
1305*4882a593Smuzhiyun }
1306*4882a593Smuzhiyun }
1307*4882a593Smuzhiyun
1308*4882a593Smuzhiyun tiles = RegionFromRects(nrects, prect, CT_NONE);
1309*4882a593Smuzhiyun RegionIntersect(damage, damage, tiles);
1310*4882a593Smuzhiyun RegionDestroy(tiles);
1311*4882a593Smuzhiyun free(prect);
1312*4882a593Smuzhiyun } while (0);
1313*4882a593Smuzhiyun
1314*4882a593Smuzhiyun if (ms->drmmode.exa)
1315*4882a593Smuzhiyun ms_exa_prepare_access(pBuf->pPixmap, 0);
1316*4882a593Smuzhiyun
1317*4882a593Smuzhiyun if (use_3224)
1318*4882a593Smuzhiyun shadowUpdate32to24(pScreen, pBuf);
1319*4882a593Smuzhiyun else
1320*4882a593Smuzhiyun shadowUpdatePacked(pScreen, pBuf);
1321*4882a593Smuzhiyun
1322*4882a593Smuzhiyun if (ms->drmmode.exa)
1323*4882a593Smuzhiyun ms_exa_finish_access(pBuf->pPixmap, 0);
1324*4882a593Smuzhiyun }
1325*4882a593Smuzhiyun
1326*4882a593Smuzhiyun static Bool
msEnableSharedPixmapFlipping(RRCrtcPtr crtc,PixmapPtr front,PixmapPtr back)1327*4882a593Smuzhiyun msEnableSharedPixmapFlipping(RRCrtcPtr crtc, PixmapPtr front, PixmapPtr back)
1328*4882a593Smuzhiyun {
1329*4882a593Smuzhiyun ScreenPtr screen = crtc->pScreen;
1330*4882a593Smuzhiyun ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
1331*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(scrn);
1332*4882a593Smuzhiyun EntityInfoPtr pEnt = ms->pEnt;
1333*4882a593Smuzhiyun xf86CrtcPtr xf86Crtc = crtc->devPrivate;
1334*4882a593Smuzhiyun
1335*4882a593Smuzhiyun if (!xf86Crtc)
1336*4882a593Smuzhiyun return FALSE;
1337*4882a593Smuzhiyun
1338*4882a593Smuzhiyun /* Not supported if we can't flip */
1339*4882a593Smuzhiyun if (!ms->drmmode.pageflip)
1340*4882a593Smuzhiyun return FALSE;
1341*4882a593Smuzhiyun
1342*4882a593Smuzhiyun /* Not currently supported with reverse PRIME */
1343*4882a593Smuzhiyun if (ms->drmmode.reverse_prime_offload_mode)
1344*4882a593Smuzhiyun return FALSE;
1345*4882a593Smuzhiyun
1346*4882a593Smuzhiyun #ifdef XSERVER_PLATFORM_BUS
1347*4882a593Smuzhiyun if (pEnt->location.type == BUS_PLATFORM) {
1348*4882a593Smuzhiyun char *syspath =
1349*4882a593Smuzhiyun xf86_platform_device_odev_attributes(pEnt->location.id.plat)->
1350*4882a593Smuzhiyun syspath;
1351*4882a593Smuzhiyun
1352*4882a593Smuzhiyun /* Not supported for devices using USB transport due to misbehaved
1353*4882a593Smuzhiyun * vblank events */
1354*4882a593Smuzhiyun if (syspath && strstr(syspath, "usb"))
1355*4882a593Smuzhiyun return FALSE;
1356*4882a593Smuzhiyun
1357*4882a593Smuzhiyun /* EVDI uses USB transport but is platform device, not usb.
1358*4882a593Smuzhiyun * Blacklist it explicitly */
1359*4882a593Smuzhiyun if (syspath && strstr(syspath, "evdi"))
1360*4882a593Smuzhiyun return FALSE;
1361*4882a593Smuzhiyun }
1362*4882a593Smuzhiyun #endif
1363*4882a593Smuzhiyun
1364*4882a593Smuzhiyun return drmmode_EnableSharedPixmapFlipping(xf86Crtc, &ms->drmmode,
1365*4882a593Smuzhiyun front, back);
1366*4882a593Smuzhiyun }
1367*4882a593Smuzhiyun
1368*4882a593Smuzhiyun static void
msDisableSharedPixmapFlipping(RRCrtcPtr crtc)1369*4882a593Smuzhiyun msDisableSharedPixmapFlipping(RRCrtcPtr crtc)
1370*4882a593Smuzhiyun {
1371*4882a593Smuzhiyun ScreenPtr screen = crtc->pScreen;
1372*4882a593Smuzhiyun ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
1373*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(scrn);
1374*4882a593Smuzhiyun xf86CrtcPtr xf86Crtc = crtc->devPrivate;
1375*4882a593Smuzhiyun
1376*4882a593Smuzhiyun if (xf86Crtc)
1377*4882a593Smuzhiyun drmmode_DisableSharedPixmapFlipping(xf86Crtc, &ms->drmmode);
1378*4882a593Smuzhiyun }
1379*4882a593Smuzhiyun
1380*4882a593Smuzhiyun static Bool
msStartFlippingPixmapTracking(RRCrtcPtr crtc,DrawablePtr src,PixmapPtr slave_dst1,PixmapPtr slave_dst2,int x,int y,int dst_x,int dst_y,Rotation rotation)1381*4882a593Smuzhiyun msStartFlippingPixmapTracking(RRCrtcPtr crtc, DrawablePtr src,
1382*4882a593Smuzhiyun PixmapPtr slave_dst1, PixmapPtr slave_dst2,
1383*4882a593Smuzhiyun int x, int y, int dst_x, int dst_y,
1384*4882a593Smuzhiyun Rotation rotation)
1385*4882a593Smuzhiyun {
1386*4882a593Smuzhiyun ScreenPtr pScreen = src->pScreen;
1387*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(pScreen));
1388*4882a593Smuzhiyun
1389*4882a593Smuzhiyun msPixmapPrivPtr ppriv1 = msGetPixmapPriv(&ms->drmmode, slave_dst1->master_pixmap),
1390*4882a593Smuzhiyun ppriv2 = msGetPixmapPriv(&ms->drmmode, slave_dst2->master_pixmap);
1391*4882a593Smuzhiyun
1392*4882a593Smuzhiyun if (!PixmapStartDirtyTracking(src, slave_dst1, x, y,
1393*4882a593Smuzhiyun dst_x, dst_y, rotation)) {
1394*4882a593Smuzhiyun return FALSE;
1395*4882a593Smuzhiyun }
1396*4882a593Smuzhiyun
1397*4882a593Smuzhiyun if (!PixmapStartDirtyTracking(src, slave_dst2, x, y,
1398*4882a593Smuzhiyun dst_x, dst_y, rotation)) {
1399*4882a593Smuzhiyun PixmapStopDirtyTracking(src, slave_dst1);
1400*4882a593Smuzhiyun return FALSE;
1401*4882a593Smuzhiyun }
1402*4882a593Smuzhiyun
1403*4882a593Smuzhiyun ppriv1->slave_src = src;
1404*4882a593Smuzhiyun ppriv2->slave_src = src;
1405*4882a593Smuzhiyun
1406*4882a593Smuzhiyun ppriv1->dirty = ms_dirty_get_ent(pScreen, slave_dst1);
1407*4882a593Smuzhiyun ppriv2->dirty = ms_dirty_get_ent(pScreen, slave_dst2);
1408*4882a593Smuzhiyun
1409*4882a593Smuzhiyun ppriv1->defer_dirty_update = TRUE;
1410*4882a593Smuzhiyun ppriv2->defer_dirty_update = TRUE;
1411*4882a593Smuzhiyun
1412*4882a593Smuzhiyun return TRUE;
1413*4882a593Smuzhiyun }
1414*4882a593Smuzhiyun
1415*4882a593Smuzhiyun static Bool
msPresentSharedPixmap(PixmapPtr slave_dst)1416*4882a593Smuzhiyun msPresentSharedPixmap(PixmapPtr slave_dst)
1417*4882a593Smuzhiyun {
1418*4882a593Smuzhiyun ScreenPtr pScreen = slave_dst->master_pixmap->drawable.pScreen;
1419*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(pScreen));
1420*4882a593Smuzhiyun
1421*4882a593Smuzhiyun msPixmapPrivPtr ppriv = msGetPixmapPriv(&ms->drmmode, slave_dst->master_pixmap);
1422*4882a593Smuzhiyun
1423*4882a593Smuzhiyun RegionPtr region = DamageRegion(ppriv->dirty->damage);
1424*4882a593Smuzhiyun
1425*4882a593Smuzhiyun if (RegionNotEmpty(region)) {
1426*4882a593Smuzhiyun redisplay_dirty(ppriv->slave_src->pScreen, ppriv->dirty, NULL);
1427*4882a593Smuzhiyun DamageEmpty(ppriv->dirty->damage);
1428*4882a593Smuzhiyun
1429*4882a593Smuzhiyun return TRUE;
1430*4882a593Smuzhiyun }
1431*4882a593Smuzhiyun
1432*4882a593Smuzhiyun return FALSE;
1433*4882a593Smuzhiyun }
1434*4882a593Smuzhiyun
1435*4882a593Smuzhiyun static Bool
msStopFlippingPixmapTracking(DrawablePtr src,PixmapPtr slave_dst1,PixmapPtr slave_dst2)1436*4882a593Smuzhiyun msStopFlippingPixmapTracking(DrawablePtr src,
1437*4882a593Smuzhiyun PixmapPtr slave_dst1, PixmapPtr slave_dst2)
1438*4882a593Smuzhiyun {
1439*4882a593Smuzhiyun ScreenPtr pScreen = src->pScreen;
1440*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(pScreen));
1441*4882a593Smuzhiyun
1442*4882a593Smuzhiyun msPixmapPrivPtr ppriv1 = msGetPixmapPriv(&ms->drmmode, slave_dst1->master_pixmap),
1443*4882a593Smuzhiyun ppriv2 = msGetPixmapPriv(&ms->drmmode, slave_dst2->master_pixmap);
1444*4882a593Smuzhiyun
1445*4882a593Smuzhiyun Bool ret = TRUE;
1446*4882a593Smuzhiyun
1447*4882a593Smuzhiyun ret &= PixmapStopDirtyTracking(src, slave_dst1);
1448*4882a593Smuzhiyun ret &= PixmapStopDirtyTracking(src, slave_dst2);
1449*4882a593Smuzhiyun
1450*4882a593Smuzhiyun if (ret) {
1451*4882a593Smuzhiyun ppriv1->slave_src = NULL;
1452*4882a593Smuzhiyun ppriv2->slave_src = NULL;
1453*4882a593Smuzhiyun
1454*4882a593Smuzhiyun ppriv1->dirty = NULL;
1455*4882a593Smuzhiyun ppriv2->dirty = NULL;
1456*4882a593Smuzhiyun
1457*4882a593Smuzhiyun ppriv1->defer_dirty_update = FALSE;
1458*4882a593Smuzhiyun ppriv2->defer_dirty_update = FALSE;
1459*4882a593Smuzhiyun }
1460*4882a593Smuzhiyun
1461*4882a593Smuzhiyun return ret;
1462*4882a593Smuzhiyun }
1463*4882a593Smuzhiyun
1464*4882a593Smuzhiyun static Bool
CreateScreenResources(ScreenPtr pScreen)1465*4882a593Smuzhiyun CreateScreenResources(ScreenPtr pScreen)
1466*4882a593Smuzhiyun {
1467*4882a593Smuzhiyun ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
1468*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(pScrn);
1469*4882a593Smuzhiyun PixmapPtr rootPixmap;
1470*4882a593Smuzhiyun Bool ret;
1471*4882a593Smuzhiyun void *pixels = NULL;
1472*4882a593Smuzhiyun int err;
1473*4882a593Smuzhiyun
1474*4882a593Smuzhiyun pScreen->CreateScreenResources = ms->createScreenResources;
1475*4882a593Smuzhiyun ret = pScreen->CreateScreenResources(pScreen);
1476*4882a593Smuzhiyun pScreen->CreateScreenResources = CreateScreenResources;
1477*4882a593Smuzhiyun
1478*4882a593Smuzhiyun if (!drmmode_set_desired_modes(pScrn, &ms->drmmode, pScrn->is_gpu, FALSE))
1479*4882a593Smuzhiyun return FALSE;
1480*4882a593Smuzhiyun
1481*4882a593Smuzhiyun if (!drmmode_handle_new_screen_pixmap(&ms->drmmode))
1482*4882a593Smuzhiyun return FALSE;
1483*4882a593Smuzhiyun
1484*4882a593Smuzhiyun drmmode_uevent_init(pScrn, &ms->drmmode);
1485*4882a593Smuzhiyun
1486*4882a593Smuzhiyun if (!ms->drmmode.sw_cursor)
1487*4882a593Smuzhiyun drmmode_map_cursor_bos(pScrn, &ms->drmmode);
1488*4882a593Smuzhiyun
1489*4882a593Smuzhiyun if (!ms->drmmode.gbm && !ms->drmmode.exa) {
1490*4882a593Smuzhiyun pixels = drmmode_map_front_bo(&ms->drmmode);
1491*4882a593Smuzhiyun if (!pixels)
1492*4882a593Smuzhiyun return FALSE;
1493*4882a593Smuzhiyun
1494*4882a593Smuzhiyun drmmode_handle_new_screen_pixmap(&ms->drmmode);
1495*4882a593Smuzhiyun }
1496*4882a593Smuzhiyun
1497*4882a593Smuzhiyun rootPixmap = pScreen->GetScreenPixmap(pScreen);
1498*4882a593Smuzhiyun
1499*4882a593Smuzhiyun if (ms->drmmode.shadow_enable)
1500*4882a593Smuzhiyun pixels = ms->drmmode.shadow_fb;
1501*4882a593Smuzhiyun
1502*4882a593Smuzhiyun if (ms->drmmode.shadow_enable2) {
1503*4882a593Smuzhiyun ms->drmmode.shadow_fb2 = calloc(1, pScrn->displayWidth * pScrn->virtualY * ((pScrn->bitsPerPixel + 7) >> 3));
1504*4882a593Smuzhiyun if (!ms->drmmode.shadow_fb2)
1505*4882a593Smuzhiyun ms->drmmode.shadow_enable2 = FALSE;
1506*4882a593Smuzhiyun }
1507*4882a593Smuzhiyun
1508*4882a593Smuzhiyun if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, pixels))
1509*4882a593Smuzhiyun FatalError("Couldn't adjust screen pixmap\n");
1510*4882a593Smuzhiyun
1511*4882a593Smuzhiyun if (ms->drmmode.shadow_enable) {
1512*4882a593Smuzhiyun if (!shadowAdd(pScreen, rootPixmap, msUpdatePacked, msShadowWindow,
1513*4882a593Smuzhiyun 0, 0))
1514*4882a593Smuzhiyun return FALSE;
1515*4882a593Smuzhiyun }
1516*4882a593Smuzhiyun
1517*4882a593Smuzhiyun err = drmModeDirtyFB(ms->fd, ms->drmmode.fb_id, NULL, 0);
1518*4882a593Smuzhiyun
1519*4882a593Smuzhiyun if (err != -EINVAL && err != -ENOSYS) {
1520*4882a593Smuzhiyun ms->damage = DamageCreate(NULL, NULL, DamageReportNone, TRUE,
1521*4882a593Smuzhiyun pScreen, rootPixmap);
1522*4882a593Smuzhiyun
1523*4882a593Smuzhiyun if (ms->damage) {
1524*4882a593Smuzhiyun DamageRegister(&rootPixmap->drawable, ms->damage);
1525*4882a593Smuzhiyun ms->dirty_enabled = TRUE;
1526*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Damage tracking initialized\n");
1527*4882a593Smuzhiyun }
1528*4882a593Smuzhiyun else {
1529*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1530*4882a593Smuzhiyun "Failed to create screen damage record\n");
1531*4882a593Smuzhiyun return FALSE;
1532*4882a593Smuzhiyun }
1533*4882a593Smuzhiyun }
1534*4882a593Smuzhiyun
1535*4882a593Smuzhiyun if (dixPrivateKeyRegistered(rrPrivKey)) {
1536*4882a593Smuzhiyun rrScrPrivPtr pScrPriv = rrGetScrPriv(pScreen);
1537*4882a593Smuzhiyun
1538*4882a593Smuzhiyun pScrPriv->rrEnableSharedPixmapFlipping = msEnableSharedPixmapFlipping;
1539*4882a593Smuzhiyun pScrPriv->rrDisableSharedPixmapFlipping = msDisableSharedPixmapFlipping;
1540*4882a593Smuzhiyun
1541*4882a593Smuzhiyun pScrPriv->rrStartFlippingPixmapTracking = msStartFlippingPixmapTracking;
1542*4882a593Smuzhiyun }
1543*4882a593Smuzhiyun
1544*4882a593Smuzhiyun return ret;
1545*4882a593Smuzhiyun }
1546*4882a593Smuzhiyun
1547*4882a593Smuzhiyun static Bool
msShadowInit(ScreenPtr pScreen)1548*4882a593Smuzhiyun msShadowInit(ScreenPtr pScreen)
1549*4882a593Smuzhiyun {
1550*4882a593Smuzhiyun if (!shadowSetup(pScreen)) {
1551*4882a593Smuzhiyun return FALSE;
1552*4882a593Smuzhiyun }
1553*4882a593Smuzhiyun return TRUE;
1554*4882a593Smuzhiyun }
1555*4882a593Smuzhiyun
1556*4882a593Smuzhiyun static Bool
msSharePixmapBacking(PixmapPtr ppix,ScreenPtr screen,void ** handle)1557*4882a593Smuzhiyun msSharePixmapBacking(PixmapPtr ppix, ScreenPtr screen, void **handle)
1558*4882a593Smuzhiyun {
1559*4882a593Smuzhiyun int ret = -1;
1560*4882a593Smuzhiyun CARD16 stride;
1561*4882a593Smuzhiyun CARD32 size;
1562*4882a593Smuzhiyun ret = ms_shareable_fd_from_pixmap(ppix->drawable.pScreen, ppix,
1563*4882a593Smuzhiyun &stride, &size);
1564*4882a593Smuzhiyun if (ret == -1)
1565*4882a593Smuzhiyun return FALSE;
1566*4882a593Smuzhiyun
1567*4882a593Smuzhiyun *handle = (void *)(long)(ret);
1568*4882a593Smuzhiyun return TRUE;
1569*4882a593Smuzhiyun }
1570*4882a593Smuzhiyun
1571*4882a593Smuzhiyun static Bool
msSetSharedPixmapBacking(PixmapPtr ppix,void * fd_handle)1572*4882a593Smuzhiyun msSetSharedPixmapBacking(PixmapPtr ppix, void *fd_handle)
1573*4882a593Smuzhiyun {
1574*4882a593Smuzhiyun ScreenPtr screen = ppix->drawable.pScreen;
1575*4882a593Smuzhiyun ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
1576*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(scrn);
1577*4882a593Smuzhiyun Bool ret;
1578*4882a593Smuzhiyun int ihandle = (int) (long) fd_handle;
1579*4882a593Smuzhiyun
1580*4882a593Smuzhiyun if (ihandle == -1)
1581*4882a593Smuzhiyun if (!ms->drmmode.reverse_prime_offload_mode)
1582*4882a593Smuzhiyun return drmmode_SetSlaveBO(ppix, &ms->drmmode, ihandle, 0, 0);
1583*4882a593Smuzhiyun
1584*4882a593Smuzhiyun if (ms->drmmode.reverse_prime_offload_mode) {
1585*4882a593Smuzhiyun ret = ms_back_pixmap_from_fd(ppix, ihandle,
1586*4882a593Smuzhiyun ppix->drawable.width,
1587*4882a593Smuzhiyun ppix->drawable.height,
1588*4882a593Smuzhiyun ppix->devKind, ppix->drawable.depth,
1589*4882a593Smuzhiyun ppix->drawable.bitsPerPixel);
1590*4882a593Smuzhiyun } else {
1591*4882a593Smuzhiyun int size = ppix->devKind * ppix->drawable.height;
1592*4882a593Smuzhiyun ret = drmmode_SetSlaveBO(ppix, &ms->drmmode, ihandle, ppix->devKind, size);
1593*4882a593Smuzhiyun }
1594*4882a593Smuzhiyun if (ret == FALSE)
1595*4882a593Smuzhiyun return ret;
1596*4882a593Smuzhiyun
1597*4882a593Smuzhiyun return TRUE;
1598*4882a593Smuzhiyun }
1599*4882a593Smuzhiyun
1600*4882a593Smuzhiyun static Bool
msRequestSharedPixmapNotifyDamage(PixmapPtr ppix)1601*4882a593Smuzhiyun msRequestSharedPixmapNotifyDamage(PixmapPtr ppix)
1602*4882a593Smuzhiyun {
1603*4882a593Smuzhiyun ScreenPtr screen = ppix->drawable.pScreen;
1604*4882a593Smuzhiyun ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
1605*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(scrn);
1606*4882a593Smuzhiyun
1607*4882a593Smuzhiyun msPixmapPrivPtr ppriv = msGetPixmapPriv(&ms->drmmode, ppix->master_pixmap);
1608*4882a593Smuzhiyun
1609*4882a593Smuzhiyun ppriv->notify_on_damage = TRUE;
1610*4882a593Smuzhiyun
1611*4882a593Smuzhiyun return TRUE;
1612*4882a593Smuzhiyun }
1613*4882a593Smuzhiyun
1614*4882a593Smuzhiyun static Bool
msSharedPixmapNotifyDamage(PixmapPtr ppix)1615*4882a593Smuzhiyun msSharedPixmapNotifyDamage(PixmapPtr ppix)
1616*4882a593Smuzhiyun {
1617*4882a593Smuzhiyun Bool ret = FALSE;
1618*4882a593Smuzhiyun int c;
1619*4882a593Smuzhiyun
1620*4882a593Smuzhiyun ScreenPtr screen = ppix->drawable.pScreen;
1621*4882a593Smuzhiyun ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
1622*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(scrn);
1623*4882a593Smuzhiyun xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
1624*4882a593Smuzhiyun
1625*4882a593Smuzhiyun msPixmapPrivPtr ppriv = msGetPixmapPriv(&ms->drmmode, ppix);
1626*4882a593Smuzhiyun
1627*4882a593Smuzhiyun if (!ppriv->wait_for_damage)
1628*4882a593Smuzhiyun return ret;
1629*4882a593Smuzhiyun ppriv->wait_for_damage = FALSE;
1630*4882a593Smuzhiyun
1631*4882a593Smuzhiyun for (c = 0; c < xf86_config->num_crtc; c++) {
1632*4882a593Smuzhiyun xf86CrtcPtr crtc = xf86_config->crtc[c];
1633*4882a593Smuzhiyun drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
1634*4882a593Smuzhiyun
1635*4882a593Smuzhiyun if (!drmmode_crtc)
1636*4882a593Smuzhiyun continue;
1637*4882a593Smuzhiyun if (!(drmmode_crtc->prime_pixmap && drmmode_crtc->prime_pixmap_back))
1638*4882a593Smuzhiyun continue;
1639*4882a593Smuzhiyun
1640*4882a593Smuzhiyun // Received damage on master screen pixmap, schedule present on vblank
1641*4882a593Smuzhiyun ret |= drmmode_SharedPixmapPresentOnVBlank(ppix, crtc, &ms->drmmode);
1642*4882a593Smuzhiyun }
1643*4882a593Smuzhiyun
1644*4882a593Smuzhiyun return ret;
1645*4882a593Smuzhiyun }
1646*4882a593Smuzhiyun
1647*4882a593Smuzhiyun static Bool
SetMaster(ScrnInfoPtr pScrn)1648*4882a593Smuzhiyun SetMaster(ScrnInfoPtr pScrn)
1649*4882a593Smuzhiyun {
1650*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(pScrn);
1651*4882a593Smuzhiyun int ret;
1652*4882a593Smuzhiyun
1653*4882a593Smuzhiyun #ifdef XF86_PDEV_SERVER_FD
1654*4882a593Smuzhiyun if (ms->pEnt->location.type == BUS_PLATFORM &&
1655*4882a593Smuzhiyun (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD))
1656*4882a593Smuzhiyun return TRUE;
1657*4882a593Smuzhiyun #endif
1658*4882a593Smuzhiyun
1659*4882a593Smuzhiyun if (ms->fd_passed)
1660*4882a593Smuzhiyun return TRUE;
1661*4882a593Smuzhiyun
1662*4882a593Smuzhiyun ret = drmSetMaster(ms->fd);
1663*4882a593Smuzhiyun if (ret)
1664*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "drmSetMaster failed: %s\n",
1665*4882a593Smuzhiyun strerror(errno));
1666*4882a593Smuzhiyun
1667*4882a593Smuzhiyun return ret == 0;
1668*4882a593Smuzhiyun }
1669*4882a593Smuzhiyun
1670*4882a593Smuzhiyun /* When the root window is created, initialize the screen contents from
1671*4882a593Smuzhiyun * console if -background none was specified on the command line
1672*4882a593Smuzhiyun */
1673*4882a593Smuzhiyun static Bool
CreateWindow_oneshot(WindowPtr pWin)1674*4882a593Smuzhiyun CreateWindow_oneshot(WindowPtr pWin)
1675*4882a593Smuzhiyun {
1676*4882a593Smuzhiyun ScreenPtr pScreen = pWin->drawable.pScreen;
1677*4882a593Smuzhiyun ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
1678*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(pScrn);
1679*4882a593Smuzhiyun Bool ret;
1680*4882a593Smuzhiyun
1681*4882a593Smuzhiyun pScreen->CreateWindow = ms->CreateWindow;
1682*4882a593Smuzhiyun ret = pScreen->CreateWindow(pWin);
1683*4882a593Smuzhiyun
1684*4882a593Smuzhiyun if (ret)
1685*4882a593Smuzhiyun drmmode_copy_fb(pScrn, &ms->drmmode);
1686*4882a593Smuzhiyun return ret;
1687*4882a593Smuzhiyun }
1688*4882a593Smuzhiyun
1689*4882a593Smuzhiyun static Bool
ScreenInit(ScreenPtr pScreen,int argc,char ** argv)1690*4882a593Smuzhiyun ScreenInit(ScreenPtr pScreen, int argc, char **argv)
1691*4882a593Smuzhiyun {
1692*4882a593Smuzhiyun ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
1693*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(pScrn);
1694*4882a593Smuzhiyun VisualPtr visual;
1695*4882a593Smuzhiyun const char *str_value;
1696*4882a593Smuzhiyun
1697*4882a593Smuzhiyun pScrn->pScreen = pScreen;
1698*4882a593Smuzhiyun
1699*4882a593Smuzhiyun #if 0 // The Rockchip BSP kernels doesn't have DRM permit checking.
1700*4882a593Smuzhiyun if (!SetMaster(pScrn))
1701*4882a593Smuzhiyun return FALSE;
1702*4882a593Smuzhiyun #endif
1703*4882a593Smuzhiyun
1704*4882a593Smuzhiyun #ifdef GLAMOR_HAS_GBM
1705*4882a593Smuzhiyun if (ms->drmmode.glamor)
1706*4882a593Smuzhiyun ms->drmmode.gbm = glamor_egl_get_gbm_device(pScreen);
1707*4882a593Smuzhiyun #endif
1708*4882a593Smuzhiyun
1709*4882a593Smuzhiyun /* HW dependent - FIXME */
1710*4882a593Smuzhiyun pScrn->displayWidth = pScrn->virtualX;
1711*4882a593Smuzhiyun if (!drmmode_create_initial_bos(pScrn, &ms->drmmode))
1712*4882a593Smuzhiyun return FALSE;
1713*4882a593Smuzhiyun
1714*4882a593Smuzhiyun if (ms->drmmode.shadow_enable) {
1715*4882a593Smuzhiyun ms->drmmode.shadow_fb =
1716*4882a593Smuzhiyun calloc(1,
1717*4882a593Smuzhiyun pScrn->displayWidth * pScrn->virtualY *
1718*4882a593Smuzhiyun ((pScrn->bitsPerPixel + 7) >> 3));
1719*4882a593Smuzhiyun if (!ms->drmmode.shadow_fb)
1720*4882a593Smuzhiyun ms->drmmode.shadow_enable = FALSE;
1721*4882a593Smuzhiyun }
1722*4882a593Smuzhiyun
1723*4882a593Smuzhiyun miClearVisualTypes();
1724*4882a593Smuzhiyun
1725*4882a593Smuzhiyun if (!miSetVisualTypes(pScrn->depth,
1726*4882a593Smuzhiyun miGetDefaultVisualMask(pScrn->depth),
1727*4882a593Smuzhiyun pScrn->rgbBits, pScrn->defaultVisual))
1728*4882a593Smuzhiyun return FALSE;
1729*4882a593Smuzhiyun
1730*4882a593Smuzhiyun if (!miSetPixmapDepths())
1731*4882a593Smuzhiyun return FALSE;
1732*4882a593Smuzhiyun
1733*4882a593Smuzhiyun if (!dixRegisterScreenSpecificPrivateKey
1734*4882a593Smuzhiyun (pScreen, &ms->drmmode.pixmapPrivateKeyRec, PRIVATE_PIXMAP,
1735*4882a593Smuzhiyun sizeof(msPixmapPrivRec))) {
1736*4882a593Smuzhiyun return FALSE;
1737*4882a593Smuzhiyun }
1738*4882a593Smuzhiyun
1739*4882a593Smuzhiyun pScrn->memPhysBase = 0;
1740*4882a593Smuzhiyun pScrn->fbOffset = 0;
1741*4882a593Smuzhiyun
1742*4882a593Smuzhiyun if (!fbScreenInit(pScreen, NULL,
1743*4882a593Smuzhiyun pScrn->virtualX, pScrn->virtualY,
1744*4882a593Smuzhiyun pScrn->xDpi, pScrn->yDpi,
1745*4882a593Smuzhiyun pScrn->displayWidth, pScrn->bitsPerPixel))
1746*4882a593Smuzhiyun return FALSE;
1747*4882a593Smuzhiyun
1748*4882a593Smuzhiyun if (pScrn->bitsPerPixel > 8) {
1749*4882a593Smuzhiyun /* Fixup RGB ordering */
1750*4882a593Smuzhiyun visual = pScreen->visuals + pScreen->numVisuals;
1751*4882a593Smuzhiyun while (--visual >= pScreen->visuals) {
1752*4882a593Smuzhiyun if ((visual->class | DynamicClass) == DirectColor) {
1753*4882a593Smuzhiyun visual->offsetRed = pScrn->offset.red;
1754*4882a593Smuzhiyun visual->offsetGreen = pScrn->offset.green;
1755*4882a593Smuzhiyun visual->offsetBlue = pScrn->offset.blue;
1756*4882a593Smuzhiyun visual->redMask = pScrn->mask.red;
1757*4882a593Smuzhiyun visual->greenMask = pScrn->mask.green;
1758*4882a593Smuzhiyun visual->blueMask = pScrn->mask.blue;
1759*4882a593Smuzhiyun }
1760*4882a593Smuzhiyun }
1761*4882a593Smuzhiyun }
1762*4882a593Smuzhiyun
1763*4882a593Smuzhiyun fbPictureInit(pScreen, NULL, 0);
1764*4882a593Smuzhiyun
1765*4882a593Smuzhiyun if (drmmode_init(pScrn, &ms->drmmode) == FALSE) {
1766*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1767*4882a593Smuzhiyun "Failed to initialize glamor at ScreenInit() time.\n");
1768*4882a593Smuzhiyun return FALSE;
1769*4882a593Smuzhiyun }
1770*4882a593Smuzhiyun
1771*4882a593Smuzhiyun if (ms->drmmode.shadow_enable && !msShadowInit(pScreen)) {
1772*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "shadow fb init failed\n");
1773*4882a593Smuzhiyun return FALSE;
1774*4882a593Smuzhiyun }
1775*4882a593Smuzhiyun
1776*4882a593Smuzhiyun ms->createScreenResources = pScreen->CreateScreenResources;
1777*4882a593Smuzhiyun pScreen->CreateScreenResources = CreateScreenResources;
1778*4882a593Smuzhiyun
1779*4882a593Smuzhiyun xf86SetBlackWhitePixels(pScreen);
1780*4882a593Smuzhiyun
1781*4882a593Smuzhiyun str_value = xf86GetOptValString(ms->drmmode.Options,
1782*4882a593Smuzhiyun OPTION_ACCEL_METHOD);
1783*4882a593Smuzhiyun if (str_value && !strcmp(str_value, "exa"))
1784*4882a593Smuzhiyun try_enable_exa(pScrn);
1785*4882a593Smuzhiyun
1786*4882a593Smuzhiyun xf86SetBackingStore(pScreen);
1787*4882a593Smuzhiyun xf86SetSilkenMouse(pScreen);
1788*4882a593Smuzhiyun miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
1789*4882a593Smuzhiyun
1790*4882a593Smuzhiyun /* If pageflip is enabled hook the screen's cursor-sprite (swcursor) funcs.
1791*4882a593Smuzhiyun * So that we can disabe page-flipping on fallback to a swcursor. */
1792*4882a593Smuzhiyun if (ms->drmmode.pageflip) {
1793*4882a593Smuzhiyun miPointerScreenPtr PointPriv =
1794*4882a593Smuzhiyun dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey);
1795*4882a593Smuzhiyun
1796*4882a593Smuzhiyun if (!dixRegisterScreenPrivateKey(&ms->drmmode.spritePrivateKeyRec,
1797*4882a593Smuzhiyun pScreen, PRIVATE_DEVICE,
1798*4882a593Smuzhiyun sizeof(msSpritePrivRec)))
1799*4882a593Smuzhiyun return FALSE;
1800*4882a593Smuzhiyun
1801*4882a593Smuzhiyun ms->SpriteFuncs = PointPriv->spriteFuncs;
1802*4882a593Smuzhiyun PointPriv->spriteFuncs = &drmmode_sprite_funcs;
1803*4882a593Smuzhiyun }
1804*4882a593Smuzhiyun
1805*4882a593Smuzhiyun /* Need to extend HWcursor support to handle mask interleave */
1806*4882a593Smuzhiyun if (!ms->drmmode.sw_cursor)
1807*4882a593Smuzhiyun xf86_cursors_init(pScreen, ms->cursor_width, ms->cursor_height,
1808*4882a593Smuzhiyun HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 |
1809*4882a593Smuzhiyun HARDWARE_CURSOR_UPDATE_UNHIDDEN |
1810*4882a593Smuzhiyun HARDWARE_CURSOR_ARGB);
1811*4882a593Smuzhiyun
1812*4882a593Smuzhiyun /* Must force it before EnterVT, so we are in control of VT and
1813*4882a593Smuzhiyun * later memory should be bound when allocating, e.g rotate_mem */
1814*4882a593Smuzhiyun pScrn->vtSema = TRUE;
1815*4882a593Smuzhiyun
1816*4882a593Smuzhiyun if (serverGeneration == 1 && bgNoneRoot) {
1817*4882a593Smuzhiyun ms->CreateWindow = pScreen->CreateWindow;
1818*4882a593Smuzhiyun pScreen->CreateWindow = CreateWindow_oneshot;
1819*4882a593Smuzhiyun }
1820*4882a593Smuzhiyun
1821*4882a593Smuzhiyun pScreen->SaveScreen = xf86SaveScreen;
1822*4882a593Smuzhiyun ms->CloseScreen = pScreen->CloseScreen;
1823*4882a593Smuzhiyun pScreen->CloseScreen = CloseScreen;
1824*4882a593Smuzhiyun
1825*4882a593Smuzhiyun ms->BlockHandler = pScreen->BlockHandler;
1826*4882a593Smuzhiyun pScreen->BlockHandler = msBlockHandler_oneshot;
1827*4882a593Smuzhiyun
1828*4882a593Smuzhiyun pScreen->SharePixmapBacking = msSharePixmapBacking;
1829*4882a593Smuzhiyun pScreen->SetSharedPixmapBacking = msSetSharedPixmapBacking;
1830*4882a593Smuzhiyun pScreen->StartPixmapTracking = PixmapStartDirtyTracking;
1831*4882a593Smuzhiyun pScreen->StopPixmapTracking = PixmapStopDirtyTracking;
1832*4882a593Smuzhiyun
1833*4882a593Smuzhiyun pScreen->SharedPixmapNotifyDamage = msSharedPixmapNotifyDamage;
1834*4882a593Smuzhiyun pScreen->RequestSharedPixmapNotifyDamage =
1835*4882a593Smuzhiyun msRequestSharedPixmapNotifyDamage;
1836*4882a593Smuzhiyun
1837*4882a593Smuzhiyun pScreen->PresentSharedPixmap = msPresentSharedPixmap;
1838*4882a593Smuzhiyun pScreen->StopFlippingPixmapTracking = msStopFlippingPixmapTracking;
1839*4882a593Smuzhiyun
1840*4882a593Smuzhiyun if (!xf86CrtcScreenInit(pScreen))
1841*4882a593Smuzhiyun return FALSE;
1842*4882a593Smuzhiyun
1843*4882a593Smuzhiyun if (!drmmode_setup_colormap(pScreen, pScrn))
1844*4882a593Smuzhiyun return FALSE;
1845*4882a593Smuzhiyun
1846*4882a593Smuzhiyun if (ms->atomic_modeset)
1847*4882a593Smuzhiyun xf86DPMSInit(pScreen, drmmode_set_dpms, 0);
1848*4882a593Smuzhiyun else
1849*4882a593Smuzhiyun xf86DPMSInit(pScreen, xf86DPMSSet, 0);
1850*4882a593Smuzhiyun
1851*4882a593Smuzhiyun #ifdef GLAMOR_HAS_GBM
1852*4882a593Smuzhiyun if (ms->drmmode.glamor) {
1853*4882a593Smuzhiyun ms->adaptor = glamor_xv_init(pScreen, 16);
1854*4882a593Smuzhiyun if (ms->adaptor != NULL) {
1855*4882a593Smuzhiyun xf86XVScreenInit(pScreen, &ms->adaptor, 1);
1856*4882a593Smuzhiyun } else {
1857*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1858*4882a593Smuzhiyun "Failed to initialize XV support.\n");
1859*4882a593Smuzhiyun }
1860*4882a593Smuzhiyun }
1861*4882a593Smuzhiyun #endif
1862*4882a593Smuzhiyun
1863*4882a593Smuzhiyun if (ms->drmmode.exa) {
1864*4882a593Smuzhiyun ms->adaptor = ms_exa_xv_init(pScreen, 16);
1865*4882a593Smuzhiyun if (ms->adaptor != NULL) {
1866*4882a593Smuzhiyun xf86XVScreenInit(pScreen, &ms->adaptor, 1);
1867*4882a593Smuzhiyun } else {
1868*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1869*4882a593Smuzhiyun "Failed to initialize XV support.\n");
1870*4882a593Smuzhiyun }
1871*4882a593Smuzhiyun }
1872*4882a593Smuzhiyun
1873*4882a593Smuzhiyun if (serverGeneration == 1)
1874*4882a593Smuzhiyun xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
1875*4882a593Smuzhiyun
1876*4882a593Smuzhiyun if (!ms_vblank_screen_init(pScreen)) {
1877*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1878*4882a593Smuzhiyun "Failed to initialize vblank support.\n");
1879*4882a593Smuzhiyun return FALSE;
1880*4882a593Smuzhiyun }
1881*4882a593Smuzhiyun
1882*4882a593Smuzhiyun if (ms->drmmode.glamor || ms->drmmode.exa) {
1883*4882a593Smuzhiyun if (!(ms->drmmode.dri2_enable = ms_dri2_screen_init(pScreen))) {
1884*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1885*4882a593Smuzhiyun "Failed to initialize the DRI2 extension.\n");
1886*4882a593Smuzhiyun }
1887*4882a593Smuzhiyun
1888*4882a593Smuzhiyun if (!(ms->drmmode.present_enable = ms_present_screen_init(pScreen))) {
1889*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1890*4882a593Smuzhiyun "Failed to initialize the Present extension.\n");
1891*4882a593Smuzhiyun }
1892*4882a593Smuzhiyun /* enable reverse prime if we are a GPU screen, and accelerated, and not
1893*4882a593Smuzhiyun * i915. i915 is happy scanning out from sysmem. */
1894*4882a593Smuzhiyun if (pScreen->isGPU) {
1895*4882a593Smuzhiyun drmVersionPtr version;
1896*4882a593Smuzhiyun
1897*4882a593Smuzhiyun /* enable if we are an accelerated GPU screen */
1898*4882a593Smuzhiyun ms->drmmode.reverse_prime_offload_mode = TRUE;
1899*4882a593Smuzhiyun
1900*4882a593Smuzhiyun /* disable if we detect i915 */
1901*4882a593Smuzhiyun if ((version = drmGetVersion(ms->drmmode.fd))) {
1902*4882a593Smuzhiyun if (!strncmp("i915", version->name, version->name_len)) {
1903*4882a593Smuzhiyun ms->drmmode.reverse_prime_offload_mode = FALSE;
1904*4882a593Smuzhiyun }
1905*4882a593Smuzhiyun drmFreeVersion(version);
1906*4882a593Smuzhiyun }
1907*4882a593Smuzhiyun }
1908*4882a593Smuzhiyun }
1909*4882a593Smuzhiyun
1910*4882a593Smuzhiyun #ifdef DRI3
1911*4882a593Smuzhiyun if (ms->drmmode.exa) {
1912*4882a593Smuzhiyun if (!ms_exa_dri3_init(pScreen)) {
1913*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1914*4882a593Smuzhiyun "Failed to initialize the DRI3 extension.\n");
1915*4882a593Smuzhiyun }
1916*4882a593Smuzhiyun }
1917*4882a593Smuzhiyun #endif
1918*4882a593Smuzhiyun
1919*4882a593Smuzhiyun #if XSYNC
1920*4882a593Smuzhiyun if (ms->drmmode.exa) {
1921*4882a593Smuzhiyun #ifdef HAVE_XSHMFENCE
1922*4882a593Smuzhiyun if (!miSyncShmScreenInit(pScreen)) {
1923*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1924*4882a593Smuzhiyun "Failed to initialize sync support.\n");
1925*4882a593Smuzhiyun }
1926*4882a593Smuzhiyun #else
1927*4882a593Smuzhiyun if (!miSyncSetup(pScreen)) {
1928*4882a593Smuzhiyun xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1929*4882a593Smuzhiyun "Failed to initialize sync support.\n");
1930*4882a593Smuzhiyun }
1931*4882a593Smuzhiyun #endif
1932*4882a593Smuzhiyun }
1933*4882a593Smuzhiyun #endif
1934*4882a593Smuzhiyun
1935*4882a593Smuzhiyun pScrn->vtSema = TRUE;
1936*4882a593Smuzhiyun
1937*4882a593Smuzhiyun return TRUE;
1938*4882a593Smuzhiyun }
1939*4882a593Smuzhiyun
1940*4882a593Smuzhiyun static void
AdjustFrame(ScrnInfoPtr pScrn,int x,int y)1941*4882a593Smuzhiyun AdjustFrame(ScrnInfoPtr pScrn, int x, int y)
1942*4882a593Smuzhiyun {
1943*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(pScrn);
1944*4882a593Smuzhiyun
1945*4882a593Smuzhiyun drmmode_adjust_frame(pScrn, &ms->drmmode, x, y);
1946*4882a593Smuzhiyun }
1947*4882a593Smuzhiyun
1948*4882a593Smuzhiyun static void
FreeScreen(ScrnInfoPtr pScrn)1949*4882a593Smuzhiyun FreeScreen(ScrnInfoPtr pScrn)
1950*4882a593Smuzhiyun {
1951*4882a593Smuzhiyun FreeRec(pScrn);
1952*4882a593Smuzhiyun }
1953*4882a593Smuzhiyun
1954*4882a593Smuzhiyun static void
LeaveVT(ScrnInfoPtr pScrn)1955*4882a593Smuzhiyun LeaveVT(ScrnInfoPtr pScrn)
1956*4882a593Smuzhiyun {
1957*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(pScrn);
1958*4882a593Smuzhiyun
1959*4882a593Smuzhiyun xf86_hide_cursors(pScrn);
1960*4882a593Smuzhiyun
1961*4882a593Smuzhiyun pScrn->vtSema = FALSE;
1962*4882a593Smuzhiyun
1963*4882a593Smuzhiyun #ifdef XF86_PDEV_SERVER_FD
1964*4882a593Smuzhiyun if (ms->pEnt->location.type == BUS_PLATFORM &&
1965*4882a593Smuzhiyun (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD))
1966*4882a593Smuzhiyun return;
1967*4882a593Smuzhiyun #endif
1968*4882a593Smuzhiyun
1969*4882a593Smuzhiyun if (!ms->fd_passed)
1970*4882a593Smuzhiyun drmDropMaster(ms->fd);
1971*4882a593Smuzhiyun }
1972*4882a593Smuzhiyun
1973*4882a593Smuzhiyun /*
1974*4882a593Smuzhiyun * This gets called when gaining control of the VT, and from ScreenInit().
1975*4882a593Smuzhiyun */
1976*4882a593Smuzhiyun static Bool
EnterVT(ScrnInfoPtr pScrn)1977*4882a593Smuzhiyun EnterVT(ScrnInfoPtr pScrn)
1978*4882a593Smuzhiyun {
1979*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(pScrn);
1980*4882a593Smuzhiyun
1981*4882a593Smuzhiyun pScrn->vtSema = TRUE;
1982*4882a593Smuzhiyun
1983*4882a593Smuzhiyun SetMaster(pScrn);
1984*4882a593Smuzhiyun
1985*4882a593Smuzhiyun drmmode_update_kms_state(&ms->drmmode);
1986*4882a593Smuzhiyun
1987*4882a593Smuzhiyun /* allow not all modes to be set successfully since some events might have
1988*4882a593Smuzhiyun * happened while not being master that could prevent the previous
1989*4882a593Smuzhiyun * configuration from being re-applied.
1990*4882a593Smuzhiyun */
1991*4882a593Smuzhiyun if (!drmmode_set_desired_modes(pScrn, &ms->drmmode, TRUE, TRUE)) {
1992*4882a593Smuzhiyun xf86DisableUnusedFunctions(pScrn);
1993*4882a593Smuzhiyun
1994*4882a593Smuzhiyun /* TODO: check that at least one screen is on, to allow the user to fix
1995*4882a593Smuzhiyun * their setup if all modeset failed...
1996*4882a593Smuzhiyun */
1997*4882a593Smuzhiyun
1998*4882a593Smuzhiyun /* Tell the desktop environment that something changed, so that they
1999*4882a593Smuzhiyun * can hopefully correct the situation
2000*4882a593Smuzhiyun */
2001*4882a593Smuzhiyun RRSetChanged(xf86ScrnToScreen(pScrn));
2002*4882a593Smuzhiyun RRTellChanged(xf86ScrnToScreen(pScrn));
2003*4882a593Smuzhiyun }
2004*4882a593Smuzhiyun
2005*4882a593Smuzhiyun return TRUE;
2006*4882a593Smuzhiyun }
2007*4882a593Smuzhiyun
2008*4882a593Smuzhiyun static Bool
SwitchMode(ScrnInfoPtr pScrn,DisplayModePtr mode)2009*4882a593Smuzhiyun SwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode)
2010*4882a593Smuzhiyun {
2011*4882a593Smuzhiyun return xf86SetSingleMode(pScrn, mode, RR_Rotate_0);
2012*4882a593Smuzhiyun }
2013*4882a593Smuzhiyun
2014*4882a593Smuzhiyun static Bool
CloseScreen(ScreenPtr pScreen)2015*4882a593Smuzhiyun CloseScreen(ScreenPtr pScreen)
2016*4882a593Smuzhiyun {
2017*4882a593Smuzhiyun ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
2018*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(pScrn);
2019*4882a593Smuzhiyun modesettingEntPtr ms_ent = ms_ent_priv(pScrn);
2020*4882a593Smuzhiyun
2021*4882a593Smuzhiyun xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
2022*4882a593Smuzhiyun int c;
2023*4882a593Smuzhiyun
2024*4882a593Smuzhiyun /* HACK: All filters would be reset after screen closed */
2025*4882a593Smuzhiyun for (c = 0; c < xf86_config->num_crtc; c++) {
2026*4882a593Smuzhiyun xf86CrtcPtr crtc = xf86_config->crtc[c];
2027*4882a593Smuzhiyun crtc->transform.filter = NULL;
2028*4882a593Smuzhiyun }
2029*4882a593Smuzhiyun
2030*4882a593Smuzhiyun /* Clear mask of assigned crtc's in this generation */
2031*4882a593Smuzhiyun ms_ent->assigned_crtcs = 0;
2032*4882a593Smuzhiyun
2033*4882a593Smuzhiyun #ifdef DRI3
2034*4882a593Smuzhiyun if (ms->drmmode.dri3_device_name) {
2035*4882a593Smuzhiyun free(ms->drmmode.dri3_device_name);
2036*4882a593Smuzhiyun ms->drmmode.dri3_device_name = NULL;
2037*4882a593Smuzhiyun }
2038*4882a593Smuzhiyun #endif
2039*4882a593Smuzhiyun
2040*4882a593Smuzhiyun if (ms->drmmode.dri2_enable) {
2041*4882a593Smuzhiyun ms_dri2_close_screen(pScreen);
2042*4882a593Smuzhiyun }
2043*4882a593Smuzhiyun
2044*4882a593Smuzhiyun ms_vblank_close_screen(pScreen);
2045*4882a593Smuzhiyun
2046*4882a593Smuzhiyun if (ms->damage) {
2047*4882a593Smuzhiyun DamageUnregister(ms->damage);
2048*4882a593Smuzhiyun DamageDestroy(ms->damage);
2049*4882a593Smuzhiyun ms->damage = NULL;
2050*4882a593Smuzhiyun }
2051*4882a593Smuzhiyun
2052*4882a593Smuzhiyun if (ms->drmmode.shadow_enable) {
2053*4882a593Smuzhiyun shadowRemove(pScreen, pScreen->GetScreenPixmap(pScreen));
2054*4882a593Smuzhiyun free(ms->drmmode.shadow_fb);
2055*4882a593Smuzhiyun ms->drmmode.shadow_fb = NULL;
2056*4882a593Smuzhiyun free(ms->drmmode.shadow_fb2);
2057*4882a593Smuzhiyun ms->drmmode.shadow_fb2 = NULL;
2058*4882a593Smuzhiyun }
2059*4882a593Smuzhiyun
2060*4882a593Smuzhiyun drmmode_uevent_fini(pScrn, &ms->drmmode);
2061*4882a593Smuzhiyun
2062*4882a593Smuzhiyun drmmode_free_bos(pScrn, &ms->drmmode);
2063*4882a593Smuzhiyun
2064*4882a593Smuzhiyun if (ms->drmmode.pageflip) {
2065*4882a593Smuzhiyun miPointerScreenPtr PointPriv =
2066*4882a593Smuzhiyun dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey);
2067*4882a593Smuzhiyun
2068*4882a593Smuzhiyun if (PointPriv->spriteFuncs == &drmmode_sprite_funcs)
2069*4882a593Smuzhiyun PointPriv->spriteFuncs = ms->SpriteFuncs;
2070*4882a593Smuzhiyun }
2071*4882a593Smuzhiyun
2072*4882a593Smuzhiyun if (ms->adaptor) {
2073*4882a593Smuzhiyun free(ms->adaptor);
2074*4882a593Smuzhiyun ms->adaptor = NULL;
2075*4882a593Smuzhiyun }
2076*4882a593Smuzhiyun
2077*4882a593Smuzhiyun if (pScrn->vtSema) {
2078*4882a593Smuzhiyun LeaveVT(pScrn);
2079*4882a593Smuzhiyun }
2080*4882a593Smuzhiyun
2081*4882a593Smuzhiyun if (ms->drmmode.exa) {
2082*4882a593Smuzhiyun PixmapPtr screen_pixmap;
2083*4882a593Smuzhiyun
2084*4882a593Smuzhiyun /* Destroy exa screen pixmap before deinit exa */
2085*4882a593Smuzhiyun screen_pixmap = pScreen->GetScreenPixmap(pScreen);
2086*4882a593Smuzhiyun if (screen_pixmap == pScreen->devPrivate) {
2087*4882a593Smuzhiyun pScreen->DestroyPixmap(screen_pixmap);
2088*4882a593Smuzhiyun pScreen->devPrivate = NULL;
2089*4882a593Smuzhiyun }
2090*4882a593Smuzhiyun
2091*4882a593Smuzhiyun ms_deinit_exa(pScrn);
2092*4882a593Smuzhiyun }
2093*4882a593Smuzhiyun
2094*4882a593Smuzhiyun pScreen->CreateScreenResources = ms->createScreenResources;
2095*4882a593Smuzhiyun pScreen->BlockHandler = ms->BlockHandler;
2096*4882a593Smuzhiyun
2097*4882a593Smuzhiyun xf86_cursors_fini(pScreen);
2098*4882a593Smuzhiyun
2099*4882a593Smuzhiyun pScrn->vtSema = FALSE;
2100*4882a593Smuzhiyun pScreen->CloseScreen = ms->CloseScreen;
2101*4882a593Smuzhiyun return (*pScreen->CloseScreen) (pScreen);
2102*4882a593Smuzhiyun }
2103*4882a593Smuzhiyun
2104*4882a593Smuzhiyun static ModeStatus
ValidMode(ScrnInfoPtr arg,DisplayModePtr mode,Bool verbose,int flags)2105*4882a593Smuzhiyun ValidMode(ScrnInfoPtr arg, DisplayModePtr mode, Bool verbose, int flags)
2106*4882a593Smuzhiyun {
2107*4882a593Smuzhiyun return MODE_OK;
2108*4882a593Smuzhiyun }
2109*4882a593Smuzhiyun
2110*4882a593Smuzhiyun void
ms_exchange_buffers(PixmapPtr front,PixmapPtr back)2111*4882a593Smuzhiyun ms_exchange_buffers(PixmapPtr front, PixmapPtr back)
2112*4882a593Smuzhiyun {
2113*4882a593Smuzhiyun ScreenPtr screen = front->drawable.pScreen;
2114*4882a593Smuzhiyun ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
2115*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(scrn);
2116*4882a593Smuzhiyun
2117*4882a593Smuzhiyun #ifdef GLAMOR_HAS_GBM
2118*4882a593Smuzhiyun if (ms->drmmode.glamor)
2119*4882a593Smuzhiyun return glamor_egl_exchange_buffers(front, back);
2120*4882a593Smuzhiyun #endif
2121*4882a593Smuzhiyun
2122*4882a593Smuzhiyun if (ms->drmmode.exa)
2123*4882a593Smuzhiyun return ms_exa_exchange_buffers(front, back);
2124*4882a593Smuzhiyun }
2125*4882a593Smuzhiyun
2126*4882a593Smuzhiyun static Bool
ms_back_pixmap_from_fd(PixmapPtr pixmap,int fd,CARD16 width,CARD16 height,CARD16 stride,CARD8 depth,CARD8 bpp)2127*4882a593Smuzhiyun ms_back_pixmap_from_fd(PixmapPtr pixmap,
2128*4882a593Smuzhiyun int fd,
2129*4882a593Smuzhiyun CARD16 width,
2130*4882a593Smuzhiyun CARD16 height,
2131*4882a593Smuzhiyun CARD16 stride, CARD8 depth, CARD8 bpp)
2132*4882a593Smuzhiyun {
2133*4882a593Smuzhiyun ScreenPtr screen = pixmap->drawable.pScreen;
2134*4882a593Smuzhiyun ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
2135*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(scrn);
2136*4882a593Smuzhiyun
2137*4882a593Smuzhiyun #ifdef GLAMOR_HAS_GBM
2138*4882a593Smuzhiyun if (ms->drmmode.glamor)
2139*4882a593Smuzhiyun return glamor_back_pixmap_from_fd(pixmap, fd,
2140*4882a593Smuzhiyun width, height,
2141*4882a593Smuzhiyun stride, depth, bpp);
2142*4882a593Smuzhiyun #endif
2143*4882a593Smuzhiyun
2144*4882a593Smuzhiyun if (ms->drmmode.exa)
2145*4882a593Smuzhiyun return ms_exa_back_pixmap_from_fd(pixmap, fd,
2146*4882a593Smuzhiyun width, height,
2147*4882a593Smuzhiyun stride, depth, bpp);
2148*4882a593Smuzhiyun
2149*4882a593Smuzhiyun return FALSE;
2150*4882a593Smuzhiyun }
2151*4882a593Smuzhiyun
2152*4882a593Smuzhiyun static int
ms_shareable_fd_from_pixmap(ScreenPtr screen,PixmapPtr pixmap,CARD16 * stride,CARD32 * size)2153*4882a593Smuzhiyun ms_shareable_fd_from_pixmap(ScreenPtr screen,
2154*4882a593Smuzhiyun PixmapPtr pixmap,
2155*4882a593Smuzhiyun CARD16 *stride,
2156*4882a593Smuzhiyun CARD32 *size)
2157*4882a593Smuzhiyun {
2158*4882a593Smuzhiyun ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
2159*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(scrn);
2160*4882a593Smuzhiyun
2161*4882a593Smuzhiyun #ifdef GLAMOR_HAS_GBM
2162*4882a593Smuzhiyun if (ms->drmmode.glamor)
2163*4882a593Smuzhiyun return glamor_shareable_fd_from_pixmap(screen, pixmap, stride, size);
2164*4882a593Smuzhiyun #endif
2165*4882a593Smuzhiyun
2166*4882a593Smuzhiyun if (ms->drmmode.exa)
2167*4882a593Smuzhiyun return ms_exa_shareable_fd_from_pixmap(screen, pixmap, stride, size);
2168*4882a593Smuzhiyun
2169*4882a593Smuzhiyun return -1;
2170*4882a593Smuzhiyun }
2171*4882a593Smuzhiyun
2172*4882a593Smuzhiyun int
ms_name_from_pixmap(PixmapPtr pixmap,CARD16 * stride,CARD32 * size)2173*4882a593Smuzhiyun ms_name_from_pixmap(PixmapPtr pixmap,
2174*4882a593Smuzhiyun CARD16 *stride, CARD32 *size)
2175*4882a593Smuzhiyun {
2176*4882a593Smuzhiyun ScreenPtr screen = pixmap->drawable.pScreen;
2177*4882a593Smuzhiyun ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
2178*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(scrn);
2179*4882a593Smuzhiyun struct dumb_bo *bo;
2180*4882a593Smuzhiyun
2181*4882a593Smuzhiyun #ifdef GLAMOR_HAS_GBM
2182*4882a593Smuzhiyun if (ms->drmmode.glamor)
2183*4882a593Smuzhiyun return glamor_name_from_pixmap(pixmap, stride, size);
2184*4882a593Smuzhiyun #endif
2185*4882a593Smuzhiyun
2186*4882a593Smuzhiyun if (!ms->drmmode.exa)
2187*4882a593Smuzhiyun return -1;
2188*4882a593Smuzhiyun
2189*4882a593Smuzhiyun bo = ms_exa_bo_from_pixmap(screen, pixmap);
2190*4882a593Smuzhiyun if (!bo)
2191*4882a593Smuzhiyun return -1;
2192*4882a593Smuzhiyun
2193*4882a593Smuzhiyun *stride = bo->pitch;
2194*4882a593Smuzhiyun *size = bo->size;
2195*4882a593Smuzhiyun
2196*4882a593Smuzhiyun return dumb_bo_get_name(ms->drmmode.fd, bo);
2197*4882a593Smuzhiyun }
2198