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 #include <X11/extensions/Xv.h>
49 #ifndef XSERVER_LIBPCIACCESS
50 #error "libpciaccess needed"
53 #include <pciaccess.h>
55 #include "pipe/p_context.h"
56 #include "xorg_tracker.h"
57 #include "xorg_winsys.h"
64 * Functions and symbols exported to Xorg via pointers.
67 static Bool
drv_pre_init(ScrnInfoPtr pScrn
, int flags
);
68 static Bool
drv_screen_init(int scrnIndex
, ScreenPtr pScreen
, int argc
,
70 static Bool
drv_switch_mode(int scrnIndex
, DisplayModePtr mode
, int flags
);
71 static void drv_adjust_frame(int scrnIndex
, int x
, int y
, int flags
);
72 static Bool
drv_enter_vt(int scrnIndex
, int flags
);
73 static void drv_leave_vt(int scrnIndex
, int flags
);
74 static void drv_free_screen(int scrnIndex
, int flags
);
75 static ModeStatus
drv_valid_mode(int scrnIndex
, DisplayModePtr mode
, Bool verbose
,
84 static const OptionInfoRec drv_options
[] = {
85 {OPTION_SW_CURSOR
, "SWcursor", OPTV_BOOLEAN
, {0}, FALSE
},
86 {OPTION_2D_ACCEL
, "2DAccel", OPTV_BOOLEAN
, {0}, FALSE
},
87 {-1, NULL
, OPTV_NONE
, {0}, FALSE
}
92 * Exported Xorg driver functions to winsys
96 xorg_tracker_available_options(int chipid
, int busid
)
102 xorg_tracker_set_functions(ScrnInfoPtr scrn
)
104 scrn
->PreInit
= drv_pre_init
;
105 scrn
->ScreenInit
= drv_screen_init
;
106 scrn
->SwitchMode
= drv_switch_mode
;
107 scrn
->AdjustFrame
= drv_adjust_frame
;
108 scrn
->EnterVT
= drv_enter_vt
;
109 scrn
->LeaveVT
= drv_leave_vt
;
110 scrn
->FreeScreen
= drv_free_screen
;
111 scrn
->ValidMode
= drv_valid_mode
;
116 * Internal function definitions
119 static Bool
drv_init_front_buffer_functions(ScrnInfoPtr pScrn
);
120 static Bool
drv_close_screen(int scrnIndex
, ScreenPtr pScreen
);
121 static Bool
drv_save_hw_state(ScrnInfoPtr pScrn
);
122 static Bool
drv_restore_hw_state(ScrnInfoPtr pScrn
);
130 drv_get_rec(ScrnInfoPtr pScrn
)
132 if (pScrn
->driverPrivate
)
135 pScrn
->driverPrivate
= xnfcalloc(sizeof(modesettingRec
), 1);
141 drv_free_rec(ScrnInfoPtr pScrn
)
146 if (!pScrn
->driverPrivate
)
149 xfree(pScrn
->driverPrivate
);
151 pScrn
->driverPrivate
= NULL
;
155 drv_probe_ddc(ScrnInfoPtr pScrn
, int index
)
157 ConfiguredMonitor
= NULL
;
161 drv_crtc_resize(ScrnInfoPtr pScrn
, int width
, int height
)
163 modesettingPtr ms
= modesettingPTR(pScrn
);
164 PixmapPtr rootPixmap
;
165 ScreenPtr pScreen
= pScrn
->pScreen
;
167 if (width
== pScrn
->virtualX
&& height
== pScrn
->virtualY
)
170 pScrn
->virtualX
= width
;
171 pScrn
->virtualY
= height
;
174 * Remove the old framebuffer & texture.
176 drmModeRmFB(ms
->fd
, ms
->fb_id
);
177 if (!ms
->destroy_front_buffer(pScrn
))
178 FatalError("failed to destroy front buffer\n");
180 rootPixmap
= pScreen
->GetScreenPixmap(pScreen
);
181 if (!pScreen
->ModifyPixmapHeader(rootPixmap
, width
, height
, -1, -1, -1, NULL
))
184 pScrn
->displayWidth
= rootPixmap
->devKind
/ (rootPixmap
->drawable
.bitsPerPixel
/ 8);
186 /* now create new frontbuffer */
187 return ms
->create_front_buffer(pScrn
) && ms
->bind_front_buffer(pScrn
);
190 static const xf86CrtcConfigFuncsRec crtc_config_funcs
= {
191 .resize
= drv_crtc_resize
195 drv_init_drm(ScrnInfoPtr pScrn
)
197 modesettingPtr ms
= modesettingPTR(pScrn
);
199 /* deal with server regeneration */
204 sprintf(BusID
, "PCI:%d:%d:%d",
205 ((ms
->PciInfo
->domain
<< 8) | ms
->PciInfo
->bus
),
206 ms
->PciInfo
->dev
, ms
->PciInfo
->func
210 ms
->api
= drm_api_create();
211 ms
->fd
= drmOpen(ms
->api
? ms
->api
->driver_name
: NULL
, BusID
);
217 if (ms
->api
->destroy
)
218 ms
->api
->destroy(ms
->api
);
229 drv_init_resource_management(ScrnInfoPtr pScrn
)
231 modesettingPtr ms
= modesettingPTR(pScrn
);
233 ScreenPtr pScreen = pScrn->pScreen;
234 PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
235 Bool fbAccessDisabled;
239 if (ms
->screen
|| ms
->kms
)
243 ms
->screen
= ms
->api
->create_screen(ms
->api
, ms
->fd
, NULL
);
248 if (ms
->api
->destroy
)
249 ms
->api
->destroy(ms
->api
);
255 if (!kms_create(ms
->fd
, &ms
->kms
))
263 drv_close_resource_management(ScrnInfoPtr pScrn
)
265 modesettingPtr ms
= modesettingPTR(pScrn
);
269 assert(ms
->ctx
== NULL
);
271 for (i
= 0; i
< XORG_NR_FENCES
; i
++) {
273 ms
->screen
->fence_finish(ms
->screen
, ms
->fence
[i
], 0);
274 ms
->screen
->fence_reference(ms
->screen
, &ms
->fence
[i
], NULL
);
277 ms
->screen
->destroy(ms
->screen
);
281 if (ms
->api
&& ms
->api
->destroy
)
282 ms
->api
->destroy(ms
->api
);
287 kms_destroy(&ms
->kms
);
294 drv_pre_init(ScrnInfoPtr pScrn
, int flags
)
296 xf86CrtcConfigPtr xf86_config
;
298 rgb defaultWeight
= { 0, 0, 0 };
301 int max_width
, max_height
;
303 if (pScrn
->numEntities
!= 1)
306 pEnt
= xf86GetEntityInfo(pScrn
->entityList
[0]);
308 if (flags
& PROBE_DETECT
) {
309 drv_probe_ddc(pScrn
, pEnt
->index
);
313 /* Allocate driverPrivate */
314 if (!drv_get_rec(pScrn
))
317 ms
= modesettingPTR(pScrn
);
318 ms
->SaveGeneration
= -1;
321 pScrn
->displayWidth
= 640; /* default it */
323 if (ms
->pEnt
->location
.type
!= BUS_PCI
)
326 ms
->PciInfo
= xf86GetPciInfoForEntity(ms
->pEnt
->index
);
328 /* Allocate an entity private if necessary */
329 if (xf86IsEntityShared(pScrn
->entityList
[0])) {
330 FatalError("Entity");
332 msEnt
= xf86GetEntityPrivate(pScrn
->entityList
[0],
333 modesettingEntityIndex
)->ptr
;
334 ms
->entityPrivate
= msEnt
;
339 ms
->entityPrivate
= NULL
;
341 if (xf86IsEntityShared(pScrn
->entityList
[0])) {
342 if (xf86IsPrimInitDone(pScrn
->entityList
[0])) {
345 xf86SetPrimInitDone(pScrn
->entityList
[0]);
351 if (!drv_init_drm(pScrn
))
354 pScrn
->monitor
= pScrn
->confScreen
->monitor
;
355 pScrn
->progClock
= TRUE
;
360 PreferConvert24to32
| SupportConvert24to32
| Support32bppFb
))
363 switch (pScrn
->depth
) {
369 xf86DrvMsg(pScrn
->scrnIndex
, X_ERROR
,
370 "Given depth (%d) is not supported by the driver\n",
374 xf86PrintDepthBpp(pScrn
);
376 if (!xf86SetWeight(pScrn
, defaultWeight
, defaultWeight
))
378 if (!xf86SetDefaultVisual(pScrn
, -1))
381 /* Process the options */
382 xf86CollectOptions(pScrn
, NULL
);
383 if (!(ms
->Options
= xalloc(sizeof(drv_options
))))
385 memcpy(ms
->Options
, drv_options
, sizeof(drv_options
));
386 xf86ProcessOptions(pScrn
->scrnIndex
, pScrn
->options
, ms
->Options
);
388 /* Allocate an xf86CrtcConfig */
389 xf86CrtcConfigInit(pScrn
, &crtc_config_funcs
);
390 xf86_config
= XF86_CRTC_CONFIG_PTR(pScrn
);
394 xf86CrtcSetSizeRange(pScrn
, 320, 200, max_width
, max_height
);
396 if (xf86ReturnOptValBool(ms
->Options
, OPTION_SW_CURSOR
, FALSE
)) {
400 drv_save_hw_state(pScrn
);
402 xorg_crtc_init(pScrn
);
403 xorg_output_init(pScrn
);
405 if (!xf86InitialConfiguration(pScrn
, TRUE
)) {
406 xf86DrvMsg(pScrn
->scrnIndex
, X_ERROR
, "No valid modes.\n");
407 drv_restore_hw_state(pScrn
);
411 drv_restore_hw_state(pScrn
);
414 * If the driver can do gamma correction, it should call xf86SetGamma() here.
417 Gamma zeros
= { 0.0, 0.0, 0.0 };
419 if (!xf86SetGamma(pScrn
, zeros
)) {
424 if (pScrn
->modes
== NULL
) {
425 xf86DrvMsg(pScrn
->scrnIndex
, X_ERROR
, "No modes.\n");
429 pScrn
->currentMode
= pScrn
->modes
;
431 /* Set display resolution */
432 xf86SetDpi(pScrn
, 0, 0);
434 /* Load the required sub modules */
435 if (!xf86LoadSubModule(pScrn
, "fb"))
438 /* XXX: these aren't needed when we are using libkms */
439 if (!xf86LoadSubModule(pScrn
, "exa"))
443 if (!xf86LoadSubModule(pScrn
, "dri2"))
451 drv_save_hw_state(ScrnInfoPtr pScrn
)
453 /*xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);*/
459 drv_restore_hw_state(ScrnInfoPtr pScrn
)
461 /*xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);*/
466 static void drv_block_handler(int i
, pointer blockData
, pointer pTimeout
,
469 ScreenPtr pScreen
= screenInfo
.screens
[i
];
470 modesettingPtr ms
= modesettingPTR(xf86Screens
[pScreen
->myNum
]);
472 pScreen
->BlockHandler
= ms
->blockHandler
;
473 pScreen
->BlockHandler(i
, blockData
, pTimeout
, pReadmask
);
474 pScreen
->BlockHandler
= drv_block_handler
;
479 ms
->ctx
->flush(ms
->ctx
, PIPE_FLUSH_RENDER_CACHE
, &ms
->fence
[XORG_NR_FENCES
-1]);
482 ms
->ctx
->screen
->fence_finish(ms
->ctx
->screen
, ms
->fence
[0], 0);
484 /* The amount of rendering generated by a block handler can be
485 * quite small. Let us get a fair way ahead of hardware before
488 for (j
= 0; j
< XORG_NR_FENCES
- 1; j
++)
489 ms
->screen
->fence_reference(ms
->screen
,
493 ms
->screen
->fence_reference(ms
->screen
,
494 &ms
->fence
[XORG_NR_FENCES
-1],
499 #ifdef DRM_MODE_FEATURE_DIRTYFB
501 RegionPtr dirty
= DamageRegion(ms
->damage
);
502 unsigned num_cliprects
= REGION_NUM_RECTS(dirty
);
505 drmModeClip
*clip
= alloca(num_cliprects
* sizeof(drmModeClip
));
506 BoxPtr rect
= REGION_RECTS(dirty
);
509 /* XXX no need for copy? */
510 for (i
= 0; i
< num_cliprects
; i
++, rect
++) {
511 clip
[i
].x1
= rect
->x1
;
512 clip
[i
].y1
= rect
->y1
;
513 clip
[i
].x2
= rect
->x2
;
514 clip
[i
].y2
= rect
->y2
;
517 /* TODO query connector property to see if this is needed */
518 ret
= drmModeDirtyFB(ms
->fd
, ms
->fb_id
, clip
, num_cliprects
);
520 debug_printf("%s: failed to send dirty (%i, %s)\n",
521 __func__
, ret
, strerror(-ret
));
524 DamageEmpty(ms
->damage
);
531 drv_create_screen_resources(ScreenPtr pScreen
)
533 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
534 modesettingPtr ms
= modesettingPTR(pScrn
);
535 PixmapPtr rootPixmap
;
540 pScreen
->CreateScreenResources
= ms
->createScreenResources
;
541 ret
= pScreen
->CreateScreenResources(pScreen
);
542 pScreen
->CreateScreenResources
= drv_create_screen_resources
;
544 ms
->bind_front_buffer(pScrn
);
548 drv_adjust_frame(pScrn
->scrnIndex
, pScrn
->frameX0
, pScrn
->frameY0
, 0);
550 #ifdef DRM_MODE_FEATURE_DIRTYFB
551 rootPixmap
= pScreen
->GetScreenPixmap(pScreen
);
552 ms
->damage
= DamageCreate(NULL
, NULL
, DamageReportNone
, TRUE
,
553 pScreen
, rootPixmap
);
556 DamageRegister(&rootPixmap
->drawable
, ms
->damage
);
558 xf86DrvMsg(pScrn
->scrnIndex
, X_INFO
, "Damage tracking initialized\n");
560 xf86DrvMsg(pScrn
->scrnIndex
, X_ERROR
,
561 "Failed to create screen damage record\n");
572 drv_screen_init(int scrnIndex
, ScreenPtr pScreen
, int argc
, char **argv
)
574 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
575 modesettingPtr ms
= modesettingPTR(pScrn
);
578 if (!drv_init_drm(pScrn
)) {
579 FatalError("Could not init DRM");
583 if (!drv_init_resource_management(pScrn
)) {
584 FatalError("Could not init resource management (!pipe_screen && !libkms)");
588 if (!drv_init_front_buffer_functions(pScrn
)) {
589 FatalError("Could not init front buffer manager");
593 pScrn
->pScreen
= pScreen
;
595 /* HW dependent - FIXME */
596 pScrn
->displayWidth
= pScrn
->virtualX
;
598 miClearVisualTypes();
600 if (!miSetVisualTypes(pScrn
->depth
,
601 miGetDefaultVisualMask(pScrn
->depth
),
602 pScrn
->rgbBits
, pScrn
->defaultVisual
))
605 if (!miSetPixmapDepths())
608 pScrn
->memPhysBase
= 0;
611 if (!fbScreenInit(pScreen
, NULL
,
612 pScrn
->virtualX
, pScrn
->virtualY
,
613 pScrn
->xDpi
, pScrn
->yDpi
,
614 pScrn
->displayWidth
, pScrn
->bitsPerPixel
))
617 if (pScrn
->bitsPerPixel
> 8) {
618 /* Fixup RGB ordering */
619 visual
= pScreen
->visuals
+ pScreen
->numVisuals
;
620 while (--visual
>= pScreen
->visuals
) {
621 if ((visual
->class | DynamicClass
) == DirectColor
) {
622 visual
->offsetRed
= pScrn
->offset
.red
;
623 visual
->offsetGreen
= pScrn
->offset
.green
;
624 visual
->offsetBlue
= pScrn
->offset
.blue
;
625 visual
->redMask
= pScrn
->mask
.red
;
626 visual
->greenMask
= pScrn
->mask
.green
;
627 visual
->blueMask
= pScrn
->mask
.blue
;
632 fbPictureInit(pScreen
, NULL
, 0);
634 ms
->blockHandler
= pScreen
->BlockHandler
;
635 pScreen
->BlockHandler
= drv_block_handler
;
636 ms
->createScreenResources
= pScreen
->CreateScreenResources
;
637 pScreen
->CreateScreenResources
= drv_create_screen_resources
;
639 xf86SetBlackWhitePixels(pScreen
);
642 ms
->exa
= xorg_exa_init(pScrn
, xf86ReturnOptValBool(ms
->Options
,
643 OPTION_2D_ACCEL
, TRUE
));
644 ms
->debug_fallback
= debug_get_bool_option("XORG_DEBUG_FALLBACK", TRUE
);
646 xorg_xv_init(pScreen
);
648 xorg_dri2_init(pScreen
);
652 miInitializeBackingStore(pScreen
);
653 xf86SetBackingStore(pScreen
);
654 xf86SetSilkenMouse(pScreen
);
655 miDCInitialize(pScreen
, xf86GetPointerScreenFuncs());
657 /* Need to extend HWcursor support to handle mask interleave */
659 xf86_cursors_init(pScreen
, 64, 64,
660 HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64
|
661 HARDWARE_CURSOR_ARGB
);
663 /* Must force it before EnterVT, so we are in control of VT and
664 * later memory should be bound when allocating, e.g rotate_mem */
665 pScrn
->vtSema
= TRUE
;
667 pScreen
->SaveScreen
= xf86SaveScreen
;
668 ms
->CloseScreen
= pScreen
->CloseScreen
;
669 pScreen
->CloseScreen
= drv_close_screen
;
671 if (!xf86CrtcScreenInit(pScreen
))
674 if (!miCreateDefColormap(pScreen
))
677 xf86DPMSInit(pScreen
, xf86DPMSSet
, 0);
679 if (serverGeneration
== 1)
680 xf86ShowUnusedOptions(pScrn
->scrnIndex
, pScrn
->options
);
682 if (ms
->winsys_screen_init
)
683 ms
->winsys_screen_init(pScrn
);
685 return drv_enter_vt(scrnIndex
, 1);
689 drv_adjust_frame(int scrnIndex
, int x
, int y
, int flags
)
691 ScrnInfoPtr pScrn
= xf86Screens
[scrnIndex
];
692 xf86CrtcConfigPtr config
= XF86_CRTC_CONFIG_PTR(pScrn
);
693 xf86OutputPtr output
= config
->output
[config
->compat_output
];
694 xf86CrtcPtr crtc
= output
->crtc
;
696 if (crtc
&& crtc
->enabled
) {
697 crtc
->funcs
->set_mode_major(crtc
, pScrn
->currentMode
,
699 crtc
->x
= output
->initial_x
+ x
;
700 crtc
->y
= output
->initial_y
+ y
;
705 drv_free_screen(int scrnIndex
, int flags
)
707 drv_free_rec(xf86Screens
[scrnIndex
]);
711 drv_leave_vt(int scrnIndex
, int flags
)
713 ScrnInfoPtr pScrn
= xf86Screens
[scrnIndex
];
714 modesettingPtr ms
= modesettingPTR(pScrn
);
715 xf86CrtcConfigPtr config
= XF86_CRTC_CONFIG_PTR(pScrn
);
718 if (ms
->winsys_leave_vt
)
719 ms
->winsys_leave_vt(pScrn
);
721 for (o
= 0; o
< config
->num_crtc
; o
++) {
722 xf86CrtcPtr crtc
= config
->crtc
[o
];
724 xorg_crtc_cursor_destroy(crtc
);
726 if (crtc
->rotatedPixmap
|| crtc
->rotatedData
) {
727 crtc
->funcs
->shadow_destroy(crtc
, crtc
->rotatedPixmap
,
729 crtc
->rotatedPixmap
= NULL
;
730 crtc
->rotatedData
= NULL
;
734 drmModeRmFB(ms
->fd
, ms
->fb_id
);
736 drv_restore_hw_state(pScrn
);
738 if (drmDropMaster(ms
->fd
))
739 xf86DrvMsg(pScrn
->scrnIndex
, X_WARNING
,
740 "drmDropMaster failed: %s\n", strerror(errno
));
742 pScrn
->vtSema
= FALSE
;
746 * This gets called when gaining control of the VT, and from ScreenInit().
749 drv_enter_vt(int scrnIndex
, int flags
)
751 ScrnInfoPtr pScrn
= xf86Screens
[scrnIndex
];
752 modesettingPtr ms
= modesettingPTR(pScrn
);
754 if (drmSetMaster(ms
->fd
)) {
755 if (errno
== EINVAL
) {
756 xf86DrvMsg(pScrn
->scrnIndex
, X_WARNING
,
757 "drmSetMaster failed: 2.6.29 or newer kernel required for "
758 "multi-server DRI\n");
760 xf86DrvMsg(pScrn
->scrnIndex
, X_WARNING
,
761 "drmSetMaster failed: %s\n", strerror(errno
));
766 * Only save state once per server generation since that's what most
767 * drivers do. Could change this to save state at each VT enter.
769 if (ms
->SaveGeneration
!= serverGeneration
) {
770 ms
->SaveGeneration
= serverGeneration
;
771 drv_save_hw_state(pScrn
);
774 if (!ms
->create_front_buffer(pScrn
))
777 if (!flags
&& !ms
->bind_front_buffer(pScrn
))
780 if (!xf86SetDesiredModes(pScrn
))
783 if (ms
->winsys_enter_vt
)
784 ms
->winsys_enter_vt(pScrn
);
790 drv_switch_mode(int scrnIndex
, DisplayModePtr mode
, int flags
)
792 ScrnInfoPtr pScrn
= xf86Screens
[scrnIndex
];
794 return xf86SetSingleMode(pScrn
, mode
, RR_Rotate_0
);
798 drv_close_screen(int scrnIndex
, ScreenPtr pScreen
)
800 ScrnInfoPtr pScrn
= xf86Screens
[scrnIndex
];
801 modesettingPtr ms
= modesettingPTR(pScrn
);
804 drv_leave_vt(scrnIndex
, 0);
807 if (ms
->winsys_screen_close
)
808 ms
->winsys_screen_close(pScrn
);
812 xorg_dri2_close(pScreen
);
815 pScreen
->BlockHandler
= ms
->blockHandler
;
816 pScreen
->CreateScreenResources
= ms
->createScreenResources
;
818 #ifdef DRM_MODE_FEATURE_DIRTYFB
820 DamageUnregister(&pScreen
->GetScreenPixmap(pScreen
)->drawable
, ms
->damage
);
821 DamageDestroy(ms
->damage
);
826 drmModeRmFB(ms
->fd
, ms
->fb_id
);
827 ms
->destroy_front_buffer(pScrn
);
830 xorg_exa_close(pScrn
);
833 drv_close_resource_management(pScrn
);
838 pScrn
->vtSema
= FALSE
;
839 pScreen
->CloseScreen
= ms
->CloseScreen
;
840 return (*pScreen
->CloseScreen
) (scrnIndex
, pScreen
);
844 drv_valid_mode(int scrnIndex
, DisplayModePtr mode
, Bool verbose
, int flags
)
851 * Front buffer backing store functions.
855 drv_destroy_front_buffer_ga3d(ScrnInfoPtr pScrn
)
857 modesettingPtr ms
= modesettingPTR(pScrn
);
858 pipe_texture_reference(&ms
->root_texture
, NULL
);
863 drv_create_front_buffer_ga3d(ScrnInfoPtr pScrn
)
865 modesettingPtr ms
= modesettingPTR(pScrn
);
866 unsigned handle
, stride
;
867 struct pipe_texture
*tex
;
872 tex
= xorg_exa_create_root_texture(pScrn
, pScrn
->virtualX
, pScrn
->virtualY
,
873 pScrn
->depth
, pScrn
->bitsPerPixel
);
878 if (!ms
->api
->local_handle_from_texture(ms
->api
, ms
->screen
,
884 ret
= drmModeAddFB(ms
->fd
,
893 debug_printf("%s: failed to create framebuffer (%i, %s)",
894 __func__
, ret
, strerror(-ret
));
900 drv_adjust_frame(pScrn
->scrnIndex
, pScrn
->frameX0
, pScrn
->frameY0
, 0);
902 pipe_texture_reference(&ms
->root_texture
, tex
);
903 pipe_texture_reference(&tex
, NULL
);
908 pipe_texture_reference(&tex
, NULL
);
913 drv_bind_front_buffer_ga3d(ScrnInfoPtr pScrn
)
915 modesettingPtr ms
= modesettingPTR(pScrn
);
916 ScreenPtr pScreen
= pScrn
->pScreen
;
917 PixmapPtr rootPixmap
= pScreen
->GetScreenPixmap(pScreen
);
918 struct pipe_texture
*check
;
920 xorg_exa_set_displayed_usage(rootPixmap
);
921 xorg_exa_set_shared_usage(rootPixmap
);
922 xorg_exa_set_texture(rootPixmap
, ms
->root_texture
);
923 if (!pScreen
->ModifyPixmapHeader(rootPixmap
, -1, -1, -1, -1, -1, NULL
))
924 FatalError("Couldn't adjust screen pixmap\n");
926 check
= xorg_exa_get_texture(rootPixmap
);
927 if (ms
->root_texture
!= check
)
928 FatalError("Created new root texture\n");
930 pipe_texture_reference(&check
, NULL
);
936 drv_destroy_front_buffer_kms(ScrnInfoPtr pScrn
)
938 modesettingPtr ms
= modesettingPTR(pScrn
);
939 ScreenPtr pScreen
= pScrn
->pScreen
;
940 PixmapPtr rootPixmap
= pScreen
->GetScreenPixmap(pScreen
);
942 /* XXX Do something with the rootPixmap.
943 * This currently works fine but if we are getting crashes in
944 * the fb functions after VT switches maybe look more into it.
951 kms_bo_unmap(ms
->root_bo
);
952 kms_bo_destroy(&ms
->root_bo
);
957 drv_create_front_buffer_kms(ScrnInfoPtr pScrn
)
959 modesettingPtr ms
= modesettingPTR(pScrn
);
960 unsigned handle
, stride
;
965 attr
[0] = KMS_BO_TYPE
;
966 attr
[1] = KMS_BO_TYPE_SCANOUT
;
968 attr
[3] = pScrn
->virtualX
;
969 attr
[4] = KMS_HEIGHT
;
970 attr
[5] = pScrn
->virtualY
;
973 if (kms_bo_create(ms
->kms
, attr
, &bo
))
976 if (kms_bo_get_prop(bo
, KMS_PITCH
, &stride
))
979 if (kms_bo_get_prop(bo
, KMS_HANDLE
, &handle
))
982 ret
= drmModeAddFB(ms
->fd
,
991 debug_printf("%s: failed to create framebuffer (%i, %s)",
992 __func__
, ret
, strerror(-ret
));
998 drv_adjust_frame(pScrn
->scrnIndex
, pScrn
->frameX0
, pScrn
->frameY0
, 0);
1004 kms_bo_destroy(&bo
);
1009 drv_bind_front_buffer_kms(ScrnInfoPtr pScrn
)
1011 modesettingPtr ms
= modesettingPTR(pScrn
);
1012 ScreenPtr pScreen
= pScrn
->pScreen
;
1013 PixmapPtr rootPixmap
= pScreen
->GetScreenPixmap(pScreen
);
1017 if (kms_bo_get_prop(ms
->root_bo
, KMS_PITCH
, &stride
))
1020 if (kms_bo_map(ms
->root_bo
, &ptr
))
1023 pScreen
->ModifyPixmapHeader(rootPixmap
,
1027 pScrn
->bitsPerPixel
,
1033 kms_bo_destroy(&ms
->root_bo
);
1036 #endif /* HAVE_LIBKMS */
1038 static Bool
drv_init_front_buffer_functions(ScrnInfoPtr pScrn
)
1040 modesettingPtr ms
= modesettingPTR(pScrn
);
1042 ms
->destroy_front_buffer
= drv_destroy_front_buffer_ga3d
;
1043 ms
->create_front_buffer
= drv_create_front_buffer_ga3d
;
1044 ms
->bind_front_buffer
= drv_bind_front_buffer_ga3d
;
1046 } else if (ms
->kms
) {
1047 ms
->destroy_front_buffer
= drv_destroy_front_buffer_kms
;
1048 ms
->create_front_buffer
= drv_create_front_buffer_kms
;
1049 ms
->bind_front_buffer
= drv_bind_front_buffer_kms
;
1057 /* vim: set sw=4 ts=8 sts=4: */