a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/*
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * All Rights Reserved.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync *
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * Permission is hereby granted, free of charge, to any person obtaining a
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * copy of this software and associated documentation files (the
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * "Software"), to deal in the Software without restriction, including
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * without limitation the rights to use, copy, modify, merge, publish,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * distribute, sub license, and/or sell copies of the Software, and to
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * permit persons to whom the Software is furnished to do so, subject to
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * the following conditions:
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync *
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * The above copyright notice and this permission notice (including the
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * next paragraph) shall be included in all copies or substantial portions
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * of the Software.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync *
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync *
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync *
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * Author: Alan Hourihane <alanh@tungstengraphics.com>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync *
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <errno.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <drm.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <xf86drm.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <xf86Crtc.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <damage.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#ifdef GLAMOR
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define GLAMOR_FOR_XORG 1
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include "glamor.h"
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#ifdef GLAMOR_HAS_GBM
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <gbm.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#endif
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#endif
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include "drmmode_display.h"
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define DRV_ERROR(msg) xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsynctypedef struct {
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync int lastInstance;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync int refCount;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ScrnInfoPtr pScrn_1;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ScrnInfoPtr pScrn_2;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync} EntRec, *EntPtr;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsynctypedef void (*ms_drm_handler_proc)(uint64_t frame,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync uint64_t usec,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync void *data);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsynctypedef void (*ms_drm_abort_proc)(void *data);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/**
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * A tracked handler for an event that will hopefully be generated by
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * the kernel, and what to do when it is encountered.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncstruct ms_drm_queue {
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync struct xorg_list list;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync xf86CrtcPtr crtc;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync uint32_t seq;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync void *data;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ScrnInfoPtr scrn;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ms_drm_handler_proc handler;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ms_drm_abort_proc abort;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync};
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsynctypedef struct _modesettingRec {
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync int fd;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync EntPtr entityPrivate;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync int Chipset;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync EntityInfoPtr pEnt;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#if XSERVER_LIBPCIACCESS
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync struct pci_device *PciInfo;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#else
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync pciVideoPtr PciInfo;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync PCITAG PciTag;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#endif
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync Bool noAccel;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync CloseScreenProcPtr CloseScreen;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync /* Broken-out options. */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync OptionInfoPtr Options;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync unsigned int SaveGeneration;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync CreateScreenResourcesProcPtr createScreenResources;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ScreenBlockHandlerProcPtr BlockHandler;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync void *driver;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync drmmode_rec drmmode;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync drmEventContext event_context;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync DamagePtr damage;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync Bool dirty_enabled;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync uint32_t cursor_width, cursor_height;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync} modesettingRec, *modesettingPtr;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncuint32_t ms_drm_queue_alloc(xf86CrtcPtr crtc,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync void *data,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ms_drm_handler_proc handler,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ms_drm_abort_proc abort);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncvoid ms_drm_abort(ScrnInfoPtr scrn,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync Bool (*match)(void *data, void *match_data),
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync void *match_data);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncxf86CrtcPtr ms_dri2_crtc_covering_drawable(DrawablePtr pDraw);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncxf86CrtcPtr ms_covering_crtc(ScrnInfoPtr scrn, BoxPtr box,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync xf86CrtcPtr desired, BoxPtr crtc_box_ret);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncint ms_get_crtc_ust_msc(xf86CrtcPtr crtc, CARD64 *ust, CARD64 *msc);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncuint32_t ms_crtc_msc_to_kernel_msc(xf86CrtcPtr crtc, uint64_t expect);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncuint64_t ms_kernel_msc_to_crtc_msc(xf86CrtcPtr crtc, uint32_t sequence);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncBool ms_dri2_screen_init(ScreenPtr screen);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncvoid ms_dri2_close_screen(ScreenPtr screen);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncBool ms_vblank_screen_init(ScreenPtr screen);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncvoid ms_vblank_close_screen(ScreenPtr screen);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncBool ms_present_screen_init(ScreenPtr screen);