2 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Author: Alan Hourihane <alanh@tungstengraphics.com>
27 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
32 #include "xorg-server.h"
34 #include "xf86_OSproc.h"
36 #include "xf86PciInfo.h"
38 #include "mipointer.h"
40 #include <X11/extensions/randr.h>
45 #include "miscstruct.h"
46 #include "dixstruct.h"
48 #ifndef XSERVER_LIBPCIACCESS
49 #error "libpciaccess needed"
52 #include <pciaccess.h>
54 #include "pipe/p_context.h"
55 #include "xorg_tracker.h"
56 #include "xorg_winsys.h"
63 * Functions and symbols exported to Xorg via pointers.
66 static Bool
drv_pre_init(ScrnInfoPtr pScrn
, int flags
);
67 static Bool
drv_screen_init(int scrnIndex
, ScreenPtr pScreen
, int argc
,
69 static Bool
drv_switch_mode(int scrnIndex
, DisplayModePtr mode
, int flags
);
70 static void drv_adjust_frame(int scrnIndex
, int x
, int y
, int flags
);
71 static Bool
drv_enter_vt(int scrnIndex
, int flags
);
72 static void drv_leave_vt(int scrnIndex
, int flags
);
73 static void drv_free_screen(int scrnIndex
, int flags
);
74 static ModeStatus
drv_valid_mode(int scrnIndex
, DisplayModePtr mode
, Bool verbose
,
83 static const OptionInfoRec drv_options
[] = {
84 {OPTION_SW_CURSOR
, "SWcursor", OPTV_BOOLEAN
, {0}, FALSE
},
85 {OPTION_2D_ACCEL
, "2DAccel", OPTV_BOOLEAN
, {0}, FALSE
},
86 {-1, NULL
, OPTV_NONE
, {0}, FALSE
}
91 * Exported Xorg driver functions to winsys
95 xorg_tracker_available_options(int chipid
, int busid
)
101 xorg_tracker_set_functions(ScrnInfoPtr scrn
)
103 scrn
->PreInit
= drv_pre_init
;
104 scrn
->ScreenInit
= drv_screen_init
;
105 scrn
->SwitchMode
= drv_switch_mode
;
106 scrn
->AdjustFrame
= drv_adjust_frame
;
107 scrn
->EnterVT
= drv_enter_vt
;
108 scrn
->LeaveVT
= drv_leave_vt
;
109 scrn
->FreeScreen
= drv_free_screen
;
110 scrn
->ValidMode
= drv_valid_mode
;
115 * Internal function definitions
118 static Bool
drv_init_front_buffer_functions(ScrnInfoPtr pScrn
);
119 static Bool
drv_close_screen(int scrnIndex
, ScreenPtr pScreen
);
120 static Bool
drv_save_hw_state(ScrnInfoPtr pScrn
);
121 static Bool
drv_restore_hw_state(ScrnInfoPtr pScrn
);
129 drv_get_rec(ScrnInfoPtr pScrn
)
131 if (pScrn
->driverPrivate
)
134 pScrn
->driverPrivate
= xnfcalloc(sizeof(modesettingRec
), 1);
140 drv_free_rec(ScrnInfoPtr pScrn
)
145 if (!pScrn
->driverPrivate
)
148 xfree(pScrn
->driverPrivate
);
150 pScrn
->driverPrivate
= NULL
;
154 drv_probe_ddc(ScrnInfoPtr pScrn
, int index
)
156 ConfiguredMonitor
= NULL
;
160 drv_crtc_resize(ScrnInfoPtr pScrn
, int width
, int height
)
162 modesettingPtr ms
= modesettingPTR(pScrn
);
163 PixmapPtr rootPixmap
;
164 ScreenPtr pScreen
= pScrn
->pScreen
;
166 if (width
== pScrn
->virtualX
&& height
== pScrn
->virtualY
)
169 pScrn
->virtualX
= width
;
170 pScrn
->virtualY
= height
;
173 * Remove the old framebuffer & texture.
175 drmModeRmFB(ms
->fd
, ms
->fb_id
);
176 if (!ms
->destroy_front_buffer(pScrn
))
177 FatalError("failed to destroy front buffer\n");
179 rootPixmap
= pScreen
->GetScreenPixmap(pScreen
);
180 if (!pScreen
->ModifyPixmapHeader(rootPixmap
, width
, height
, -1, -1, -1, NULL
))
183 pScrn
->displayWidth
= rootPixmap
->devKind
/ (rootPixmap
->drawable
.bitsPerPixel
/ 8);
185 /* now create new frontbuffer */
186 return ms
->create_front_buffer(pScrn
) && ms
->bind_front_buffer(pScrn
);
189 static const xf86CrtcConfigFuncsRec crtc_config_funcs
= {
190 .resize
= drv_crtc_resize
194 drv_init_drm(ScrnInfoPtr pScrn
)
196 modesettingPtr ms
= modesettingPTR(pScrn
);
198 /* deal with server regeneration */
203 sprintf(BusID
, "PCI:%d:%d:%d",
204 ((ms
->PciInfo
->domain
<< 8) | ms
->PciInfo
->bus
),
205 ms
->PciInfo
->dev
, ms
->PciInfo
->func
209 ms
->api
= drm_api_create();
210 ms
->fd
= drmOpen(ms
->api
? ms
->api
->driver_name
: NULL
, BusID
);
216 if (ms
->api
&& ms
->api
->destroy
)
217 ms
->api
->destroy(ms
->api
);
228 drv_close_drm(ScrnInfoPtr pScrn
)
230 modesettingPtr ms
= modesettingPTR(pScrn
);
232 if (ms
->api
&& ms
->api
->destroy
)
233 ms
->api
->destroy(ms
->api
);
243 drv_init_resource_management(ScrnInfoPtr pScrn
)
245 modesettingPtr ms
= modesettingPTR(pScrn
);
247 ScreenPtr pScreen = pScrn->pScreen;
248 PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
249 Bool fbAccessDisabled;
253 if (ms
->screen
|| ms
->kms
)
257 ms
->screen
= ms
->api
->create_screen(ms
->api
, ms
->fd
, NULL
);
262 if (ms
->api
->destroy
)
263 ms
->api
->destroy(ms
->api
);
269 if (!kms_create(ms
->fd
, &ms
->kms
))
277 drv_close_resource_management(ScrnInfoPtr pScrn
)
279 modesettingPtr ms
= modesettingPTR(pScrn
);
283 assert(ms
->ctx
== NULL
);
285 for (i
= 0; i
< XORG_NR_FENCES
; i
++) {
287 ms
->screen
->fence_finish(ms
->screen
, ms
->fence
[i
], 0);
288 ms
->screen
->fence_reference(ms
->screen
, &ms
->fence
[i
], NULL
);
291 ms
->screen
->destroy(ms
->screen
);
297 kms_destroy(&ms
->kms
);
304 drv_pre_init(ScrnInfoPtr pScrn
, int flags
)
306 xf86CrtcConfigPtr xf86_config
;
308 rgb defaultWeight
= { 0, 0, 0 };
311 int max_width
, max_height
;
313 if (pScrn
->numEntities
!= 1)
316 pEnt
= xf86GetEntityInfo(pScrn
->entityList
[0]);
318 if (flags
& PROBE_DETECT
) {
319 drv_probe_ddc(pScrn
, pEnt
->index
);
323 /* Allocate driverPrivate */
324 if (!drv_get_rec(pScrn
))
327 ms
= modesettingPTR(pScrn
);
328 ms
->SaveGeneration
= -1;
331 pScrn
->displayWidth
= 640; /* default it */
333 if (ms
->pEnt
->location
.type
!= BUS_PCI
)
336 ms
->PciInfo
= xf86GetPciInfoForEntity(ms
->pEnt
->index
);
338 /* Allocate an entity private if necessary */
339 if (xf86IsEntityShared(pScrn
->entityList
[0])) {
340 FatalError("Entity");
342 msEnt
= xf86GetEntityPrivate(pScrn
->entityList
[0],
343 modesettingEntityIndex
)->ptr
;
344 ms
->entityPrivate
= msEnt
;
349 ms
->entityPrivate
= NULL
;
351 if (xf86IsEntityShared(pScrn
->entityList
[0])) {
352 if (xf86IsPrimInitDone(pScrn
->entityList
[0])) {
355 xf86SetPrimInitDone(pScrn
->entityList
[0]);
361 if (!drv_init_drm(pScrn
))
364 pScrn
->monitor
= pScrn
->confScreen
->monitor
;
365 pScrn
->progClock
= TRUE
;
370 PreferConvert24to32
| SupportConvert24to32
| Support32bppFb
))
373 switch (pScrn
->depth
) {
379 xf86DrvMsg(pScrn
->scrnIndex
, X_ERROR
,
380 "Given depth (%d) is not supported by the driver\n",
384 xf86PrintDepthBpp(pScrn
);
386 if (!xf86SetWeight(pScrn
, defaultWeight
, defaultWeight
))
388 if (!xf86SetDefaultVisual(pScrn
, -1))
391 /* Process the options */
392 xf86CollectOptions(pScrn
, NULL
);
393 if (!(ms
->Options
= xalloc(sizeof(drv_options
))))
395 memcpy(ms
->Options
, drv_options
, sizeof(drv_options
));
396 xf86ProcessOptions(pScrn
->scrnIndex
, pScrn
->options
, ms
->Options
);
398 /* Allocate an xf86CrtcConfig */
399 xf86CrtcConfigInit(pScrn
, &crtc_config_funcs
);
400 xf86_config
= XF86_CRTC_CONFIG_PTR(pScrn
);
404 xf86CrtcSetSizeRange(pScrn
, 320, 200, max_width
, max_height
);
406 if (xf86ReturnOptValBool(ms
->Options
, OPTION_SW_CURSOR
, FALSE
)) {
410 drv_save_hw_state(pScrn
);
412 xorg_crtc_init(pScrn
);
413 xorg_output_init(pScrn
);
415 if (!xf86InitialConfiguration(pScrn
, TRUE
)) {
416 xf86DrvMsg(pScrn
->scrnIndex
, X_ERROR
, "No valid modes.\n");
417 drv_restore_hw_state(pScrn
);
421 drv_restore_hw_state(pScrn
);
424 * If the driver can do gamma correction, it should call xf86SetGamma() here.
427 Gamma zeros
= { 0.0, 0.0, 0.0 };
429 if (!xf86SetGamma(pScrn
, zeros
)) {
434 if (pScrn
->modes
== NULL
) {
435 xf86DrvMsg(pScrn
->scrnIndex
, X_ERROR
, "No modes.\n");
439 pScrn
->currentMode
= pScrn
->modes
;
441 /* Set display resolution */
442 xf86SetDpi(pScrn
, 0, 0);
444 /* Load the required sub modules */
445 if (!xf86LoadSubModule(pScrn
, "fb"))
448 /* XXX: these aren't needed when we are using libkms */
449 if (!xf86LoadSubModule(pScrn
, "exa"))
453 if (!xf86LoadSubModule(pScrn
, "dri2"))
461 drv_save_hw_state(ScrnInfoPtr pScrn
)
463 /*xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);*/
469 drv_restore_hw_state(ScrnInfoPtr pScrn
)
471 /*xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);*/
476 static void drv_block_handler(int i
, pointer blockData
, pointer pTimeout
,
479 ScreenPtr pScreen
= screenInfo
.screens
[i
];
480 modesettingPtr ms
= modesettingPTR(xf86Screens
[pScreen
->myNum
]);
482 pScreen
->BlockHandler
= ms
->blockHandler
;
483 pScreen
->BlockHandler(i
, blockData
, pTimeout
, pReadmask
);
484 pScreen
->BlockHandler
= drv_block_handler
;
489 ms
->ctx
->flush(ms
->ctx
, PIPE_FLUSH_RENDER_CACHE
, &ms
->fence
[XORG_NR_FENCES
-1]);
492 ms
->ctx
->screen
->fence_finish(ms
->ctx
->screen
, ms
->fence
[0], 0);
494 /* The amount of rendering generated by a block handler can be
495 * quite small. Let us get a fair way ahead of hardware before
498 for (j
= 0; j
< XORG_NR_FENCES
- 1; j
++)
499 ms
->screen
->fence_reference(ms
->screen
,
503 ms
->screen
->fence_reference(ms
->screen
,
504 &ms
->fence
[XORG_NR_FENCES
-1],
509 #ifdef DRM_MODE_FEATURE_DIRTYFB
511 RegionPtr dirty
= DamageRegion(ms
->damage
);
512 unsigned num_cliprects
= REGION_NUM_RECTS(dirty
);
515 drmModeClip
*clip
= alloca(num_cliprects
* sizeof(drmModeClip
));
516 BoxPtr rect
= REGION_RECTS(dirty
);
519 /* XXX no need for copy? */
520 for (i
= 0; i
< num_cliprects
; i
++, rect
++) {
521 clip
[i
].x1
= rect
->x1
;
522 clip
[i
].y1
= rect
->y1
;
523 clip
[i
].x2
= rect
->x2
;
524 clip
[i
].y2
= rect
->y2
;
527 /* TODO query connector property to see if this is needed */
528 ret
= drmModeDirtyFB(ms
->fd
, ms
->fb_id
, clip
, num_cliprects
);
530 debug_printf("%s: failed to send dirty (%i, %s)\n",
531 __func__
, ret
, strerror(-ret
));
534 DamageEmpty(ms
->damage
);
541 drv_create_screen_resources(ScreenPtr pScreen
)
543 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
544 modesettingPtr ms
= modesettingPTR(pScrn
);
545 PixmapPtr rootPixmap
;
550 pScreen
->CreateScreenResources
= ms
->createScreenResources
;
551 ret
= pScreen
->CreateScreenResources(pScreen
);
552 pScreen
->CreateScreenResources
= drv_create_screen_resources
;
554 ms
->bind_front_buffer(pScrn
);
558 drv_adjust_frame(pScrn
->scrnIndex
, pScrn
->frameX0
, pScrn
->frameY0
, 0);
560 #ifdef DRM_MODE_FEATURE_DIRTYFB
561 rootPixmap
= pScreen
->GetScreenPixmap(pScreen
);
562 ms
->damage
= DamageCreate(NULL
, NULL
, DamageReportNone
, TRUE
,
563 pScreen
, rootPixmap
);
566 DamageRegister(&rootPixmap
->drawable
, ms
->damage
);
568 xf86DrvMsg(pScrn
->scrnIndex
, X_INFO
, "Damage tracking initialized\n");
570 xf86DrvMsg(pScrn
->scrnIndex
, X_ERROR
,
571 "Failed to create screen damage record\n");
582 drv_screen_init(int scrnIndex
, ScreenPtr pScreen
, int argc
, char **argv
)
584 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
585 modesettingPtr ms
= modesettingPTR(pScrn
);
588 if (!drv_init_drm(pScrn
)) {
589 FatalError("Could not init DRM");
593 if (!drv_init_resource_management(pScrn
)) {
594 FatalError("Could not init resource management (!pipe_screen && !libkms)");
598 if (!drv_init_front_buffer_functions(pScrn
)) {
599 FatalError("Could not init front buffer manager");
603 pScrn
->pScreen
= pScreen
;
605 /* HW dependent - FIXME */
606 pScrn
->displayWidth
= pScrn
->virtualX
;
608 miClearVisualTypes();
610 if (!miSetVisualTypes(pScrn
->depth
,
611 miGetDefaultVisualMask(pScrn
->depth
),
612 pScrn
->rgbBits
, pScrn
->defaultVisual
))
615 if (!miSetPixmapDepths())
618 pScrn
->memPhysBase
= 0;
621 if (!fbScreenInit(pScreen
, NULL
,
622 pScrn
->virtualX
, pScrn
->virtualY
,
623 pScrn
->xDpi
, pScrn
->yDpi
,
624 pScrn
->displayWidth
, pScrn
->bitsPerPixel
))
627 if (pScrn
->bitsPerPixel
> 8) {
628 /* Fixup RGB ordering */
629 visual
= pScreen
->visuals
+ pScreen
->numVisuals
;
630 while (--visual
>= pScreen
->visuals
) {
631 if ((visual
->class | DynamicClass
) == DirectColor
) {
632 visual
->offsetRed
= pScrn
->offset
.red
;
633 visual
->offsetGreen
= pScrn
->offset
.green
;
634 visual
->offsetBlue
= pScrn
->offset
.blue
;
635 visual
->redMask
= pScrn
->mask
.red
;
636 visual
->greenMask
= pScrn
->mask
.green
;
637 visual
->blueMask
= pScrn
->mask
.blue
;
642 fbPictureInit(pScreen
, NULL
, 0);
644 ms
->blockHandler
= pScreen
->BlockHandler
;
645 pScreen
->BlockHandler
= drv_block_handler
;
646 ms
->createScreenResources
= pScreen
->CreateScreenResources
;
647 pScreen
->CreateScreenResources
= drv_create_screen_resources
;
649 xf86SetBlackWhitePixels(pScreen
);
652 ms
->exa
= xorg_exa_init(pScrn
, xf86ReturnOptValBool(ms
->Options
,
653 OPTION_2D_ACCEL
, TRUE
));
654 ms
->debug_fallback
= debug_get_bool_option("XORG_DEBUG_FALLBACK", TRUE
);
656 xorg_xv_init(pScreen
);
658 xorg_dri2_init(pScreen
);
662 miInitializeBackingStore(pScreen
);
663 xf86SetBackingStore(pScreen
);
664 xf86SetSilkenMouse(pScreen
);
665 miDCInitialize(pScreen
, xf86GetPointerScreenFuncs());
667 /* Need to extend HWcursor support to handle mask interleave */
669 xf86_cursors_init(pScreen
, 64, 64,
670 HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64
|
671 HARDWARE_CURSOR_ARGB
);
673 /* Must force it before EnterVT, so we are in control of VT and
674 * later memory should be bound when allocating, e.g rotate_mem */
675 pScrn
->vtSema
= TRUE
;
677 pScreen
->SaveScreen
= xf86SaveScreen
;
678 ms
->CloseScreen
= pScreen
->CloseScreen
;
679 pScreen
->CloseScreen
= drv_close_screen
;
681 if (!xf86CrtcScreenInit(pScreen
))
684 if (!miCreateDefColormap(pScreen
))
687 xf86DPMSInit(pScreen
, xf86DPMSSet
, 0);
689 if (serverGeneration
== 1)
690 xf86ShowUnusedOptions(pScrn
->scrnIndex
, pScrn
->options
);
692 if (ms
->winsys_screen_init
)
693 ms
->winsys_screen_init(pScrn
);
695 return drv_enter_vt(scrnIndex
, 1);
699 drv_adjust_frame(int scrnIndex
, int x
, int y
, int flags
)
701 ScrnInfoPtr pScrn
= xf86Screens
[scrnIndex
];
702 xf86CrtcConfigPtr config
= XF86_CRTC_CONFIG_PTR(pScrn
);
703 xf86OutputPtr output
= config
->output
[config
->compat_output
];
704 xf86CrtcPtr crtc
= output
->crtc
;
706 if (crtc
&& crtc
->enabled
) {
707 crtc
->funcs
->set_mode_major(crtc
, pScrn
->currentMode
,
709 crtc
->x
= output
->initial_x
+ x
;
710 crtc
->y
= output
->initial_y
+ y
;
715 drv_free_screen(int scrnIndex
, int flags
)
717 drv_free_rec(xf86Screens
[scrnIndex
]);
721 drv_leave_vt(int scrnIndex
, int flags
)
723 ScrnInfoPtr pScrn
= xf86Screens
[scrnIndex
];
724 modesettingPtr ms
= modesettingPTR(pScrn
);
725 xf86CrtcConfigPtr config
= XF86_CRTC_CONFIG_PTR(pScrn
);
728 if (ms
->winsys_leave_vt
)
729 ms
->winsys_leave_vt(pScrn
);
731 for (o
= 0; o
< config
->num_crtc
; o
++) {
732 xf86CrtcPtr crtc
= config
->crtc
[o
];
734 xorg_crtc_cursor_destroy(crtc
);
736 if (crtc
->rotatedPixmap
|| crtc
->rotatedData
) {
737 crtc
->funcs
->shadow_destroy(crtc
, crtc
->rotatedPixmap
,
739 crtc
->rotatedPixmap
= NULL
;
740 crtc
->rotatedData
= NULL
;
744 drmModeRmFB(ms
->fd
, ms
->fb_id
);
746 drv_restore_hw_state(pScrn
);
748 if (drmDropMaster(ms
->fd
))
749 xf86DrvMsg(pScrn
->scrnIndex
, X_WARNING
,
750 "drmDropMaster failed: %s\n", strerror(errno
));
752 pScrn
->vtSema
= FALSE
;
756 * This gets called when gaining control of the VT, and from ScreenInit().
759 drv_enter_vt(int scrnIndex
, int flags
)
761 ScrnInfoPtr pScrn
= xf86Screens
[scrnIndex
];
762 modesettingPtr ms
= modesettingPTR(pScrn
);
764 if (drmSetMaster(ms
->fd
)) {
765 if (errno
== EINVAL
) {
766 xf86DrvMsg(pScrn
->scrnIndex
, X_WARNING
,
767 "drmSetMaster failed: 2.6.29 or newer kernel required for "
768 "multi-server DRI\n");
770 xf86DrvMsg(pScrn
->scrnIndex
, X_WARNING
,
771 "drmSetMaster failed: %s\n", strerror(errno
));
776 * Only save state once per server generation since that's what most
777 * drivers do. Could change this to save state at each VT enter.
779 if (ms
->SaveGeneration
!= serverGeneration
) {
780 ms
->SaveGeneration
= serverGeneration
;
781 drv_save_hw_state(pScrn
);
784 if (!ms
->create_front_buffer(pScrn
))
787 if (!flags
&& !ms
->bind_front_buffer(pScrn
))
790 if (!xf86SetDesiredModes(pScrn
))
793 if (ms
->winsys_enter_vt
)
794 ms
->winsys_enter_vt(pScrn
);
800 drv_switch_mode(int scrnIndex
, DisplayModePtr mode
, int flags
)
802 ScrnInfoPtr pScrn
= xf86Screens
[scrnIndex
];
804 return xf86SetSingleMode(pScrn
, mode
, RR_Rotate_0
);
808 drv_close_screen(int scrnIndex
, ScreenPtr pScreen
)
810 ScrnInfoPtr pScrn
= xf86Screens
[scrnIndex
];
811 modesettingPtr ms
= modesettingPTR(pScrn
);
814 drv_leave_vt(scrnIndex
, 0);
817 if (ms
->winsys_screen_close
)
818 ms
->winsys_screen_close(pScrn
);
822 xorg_dri2_close(pScreen
);
825 pScreen
->BlockHandler
= ms
->blockHandler
;
826 pScreen
->CreateScreenResources
= ms
->createScreenResources
;
828 #ifdef DRM_MODE_FEATURE_DIRTYFB
830 DamageUnregister(&pScreen
->GetScreenPixmap(pScreen
)->drawable
, ms
->damage
);
831 DamageDestroy(ms
->damage
);
836 drmModeRmFB(ms
->fd
, ms
->fb_id
);
837 ms
->destroy_front_buffer(pScrn
);
840 xorg_exa_close(pScrn
);
843 drv_close_resource_management(pScrn
);
845 drv_close_drm(pScrn
);
847 pScrn
->vtSema
= FALSE
;
848 pScreen
->CloseScreen
= ms
->CloseScreen
;
849 return (*pScreen
->CloseScreen
) (scrnIndex
, pScreen
);
853 drv_valid_mode(int scrnIndex
, DisplayModePtr mode
, Bool verbose
, int flags
)
860 * Front buffer backing store functions.
864 drv_destroy_front_buffer_ga3d(ScrnInfoPtr pScrn
)
866 modesettingPtr ms
= modesettingPTR(pScrn
);
867 pipe_texture_reference(&ms
->root_texture
, NULL
);
872 drv_create_front_buffer_ga3d(ScrnInfoPtr pScrn
)
874 modesettingPtr ms
= modesettingPTR(pScrn
);
875 unsigned handle
, stride
;
876 struct pipe_texture
*tex
;
881 tex
= xorg_exa_create_root_texture(pScrn
, pScrn
->virtualX
, pScrn
->virtualY
,
882 pScrn
->depth
, pScrn
->bitsPerPixel
);
887 if (!ms
->api
->local_handle_from_texture(ms
->api
, ms
->screen
,
893 ret
= drmModeAddFB(ms
->fd
,
902 debug_printf("%s: failed to create framebuffer (%i, %s)",
903 __func__
, ret
, strerror(-ret
));
909 drv_adjust_frame(pScrn
->scrnIndex
, pScrn
->frameX0
, pScrn
->frameY0
, 0);
911 pipe_texture_reference(&ms
->root_texture
, tex
);
912 pipe_texture_reference(&tex
, NULL
);
917 pipe_texture_reference(&tex
, NULL
);
922 drv_bind_front_buffer_ga3d(ScrnInfoPtr pScrn
)
924 modesettingPtr ms
= modesettingPTR(pScrn
);
925 ScreenPtr pScreen
= pScrn
->pScreen
;
926 PixmapPtr rootPixmap
= pScreen
->GetScreenPixmap(pScreen
);
927 struct pipe_texture
*check
;
929 xorg_exa_set_displayed_usage(rootPixmap
);
930 xorg_exa_set_shared_usage(rootPixmap
);
931 xorg_exa_set_texture(rootPixmap
, ms
->root_texture
);
932 if (!pScreen
->ModifyPixmapHeader(rootPixmap
, -1, -1, -1, -1, -1, NULL
))
933 FatalError("Couldn't adjust screen pixmap\n");
935 check
= xorg_exa_get_texture(rootPixmap
);
936 if (ms
->root_texture
!= check
)
937 FatalError("Created new root texture\n");
939 pipe_texture_reference(&check
, NULL
);
945 drv_destroy_front_buffer_kms(ScrnInfoPtr pScrn
)
947 modesettingPtr ms
= modesettingPTR(pScrn
);
948 ScreenPtr pScreen
= pScrn
->pScreen
;
949 PixmapPtr rootPixmap
= pScreen
->GetScreenPixmap(pScreen
);
951 /* XXX Do something with the rootPixmap.
952 * This currently works fine but if we are getting crashes in
953 * the fb functions after VT switches maybe look more into it.
960 kms_bo_unmap(ms
->root_bo
);
961 kms_bo_destroy(&ms
->root_bo
);
966 drv_create_front_buffer_kms(ScrnInfoPtr pScrn
)
968 modesettingPtr ms
= modesettingPTR(pScrn
);
969 unsigned handle
, stride
;
974 attr
[0] = KMS_BO_TYPE
;
975 attr
[1] = KMS_BO_TYPE_SCANOUT
;
977 attr
[3] = pScrn
->virtualX
;
978 attr
[4] = KMS_HEIGHT
;
979 attr
[5] = pScrn
->virtualY
;
982 if (kms_bo_create(ms
->kms
, attr
, &bo
))
985 if (kms_bo_get_prop(bo
, KMS_PITCH
, &stride
))
988 if (kms_bo_get_prop(bo
, KMS_HANDLE
, &handle
))
991 ret
= drmModeAddFB(ms
->fd
,
1000 debug_printf("%s: failed to create framebuffer (%i, %s)",
1001 __func__
, ret
, strerror(-ret
));
1007 drv_adjust_frame(pScrn
->scrnIndex
, pScrn
->frameX0
, pScrn
->frameY0
, 0);
1013 kms_bo_destroy(&bo
);
1018 drv_bind_front_buffer_kms(ScrnInfoPtr pScrn
)
1020 modesettingPtr ms
= modesettingPTR(pScrn
);
1021 ScreenPtr pScreen
= pScrn
->pScreen
;
1022 PixmapPtr rootPixmap
= pScreen
->GetScreenPixmap(pScreen
);
1026 if (kms_bo_get_prop(ms
->root_bo
, KMS_PITCH
, &stride
))
1029 if (kms_bo_map(ms
->root_bo
, &ptr
))
1032 pScreen
->ModifyPixmapHeader(rootPixmap
,
1036 pScrn
->bitsPerPixel
,
1042 kms_bo_destroy(&ms
->root_bo
);
1045 #endif /* HAVE_LIBKMS */
1047 static Bool
drv_init_front_buffer_functions(ScrnInfoPtr pScrn
)
1049 modesettingPtr ms
= modesettingPTR(pScrn
);
1051 ms
->destroy_front_buffer
= drv_destroy_front_buffer_ga3d
;
1052 ms
->create_front_buffer
= drv_create_front_buffer_ga3d
;
1053 ms
->bind_front_buffer
= drv_bind_front_buffer_ga3d
;
1055 } else if (ms
->kms
) {
1056 ms
->destroy_front_buffer
= drv_destroy_front_buffer_kms
;
1057 ms
->create_front_buffer
= drv_create_front_buffer_kms
;
1058 ms
->bind_front_buffer
= drv_bind_front_buffer_kms
;
1066 /* vim: set sw=4 ts=8 sts=4: */