122f7e8e5Smrg/* 222f7e8e5Smrg * Copyright 2013 VMWare, Inc. 322f7e8e5Smrg * All Rights Reserved. 422f7e8e5Smrg * 522f7e8e5Smrg * Permission is hereby granted, free of charge, to any person obtaining a 622f7e8e5Smrg * copy of this software and associated documentation files (the 722f7e8e5Smrg * "Software"), to deal in the Software without restriction, including 822f7e8e5Smrg * without limitation the rights to use, copy, modify, merge, publish, 922f7e8e5Smrg * distribute, sub license, and/or sell copies of the Software, and to 1022f7e8e5Smrg * permit persons to whom the Software is furnished to do so, subject to 1122f7e8e5Smrg * the following conditions: 1222f7e8e5Smrg * 1322f7e8e5Smrg * The above copyright notice and this permission notice (including the 1422f7e8e5Smrg * next paragraph) shall be included in all copies or substantial portions 1522f7e8e5Smrg * of the Software. 1622f7e8e5Smrg * 1722f7e8e5Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 1822f7e8e5Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 1922f7e8e5Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 2022f7e8e5Smrg * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 2122f7e8e5Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 2222f7e8e5Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 2322f7e8e5Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2422f7e8e5Smrg * 2522f7e8e5Smrg * Author: Thomas Hellstrom <thellstrom@vmware.com> 2622f7e8e5Smrg * Note: "Hosted" is a term stolen from the xf86-video-intel driver. 2722f7e8e5Smrg */ 2822f7e8e5Smrg 2922f7e8e5Smrg#ifndef _VMWGFX_HOSTED_H 3022f7e8e5Smrg#define _VMWGFX_HOSTED_H 3122f7e8e5Smrg 3222f7e8e5Smrg#include <xorg-server.h> 3322f7e8e5Smrg#include <xf86.h> 3422f7e8e5Smrg 3522f7e8e5Smrg 3622f7e8e5Smrg/** 3722f7e8e5Smrg * struct vmwgfx_hosted - hosting environment private information. 3822f7e8e5Smrg * 3922f7e8e5Smrg * This struct is completely opaque to callers and should be defined 4022f7e8e5Smrg * by the hosting environment. 4122f7e8e5Smrg */ 4222f7e8e5Smrgstruct vmwgfx_hosted; 4322f7e8e5Smrg 4422f7e8e5Smrg/** 4522f7e8e5Smrg * struct vmwgfx-hosted-driver - Driver for environments that we can run 4622f7e8e5Smrg * hosted under. 4722f7e8e5Smrg * 4822f7e8e5Smrg * @create: Initialize and create an opaque struct vmwgfx_hosted with 4922f7e8e5Smrg * environment private information. Should return NULL on failure. 5022f7e8e5Smrg * @destroy: Undo what's done in @create. 5122f7e8e5Smrg * @drm_fd: Return a file descriptor opened to DRM. 5222f7e8e5Smrg * @pre_init: Callback from vmwgfx preInit. 5322f7e8e5Smrg * @screen_init: Callback from vmwgfx screenInit. 5422f7e8e5Smrg * @screen_close: Callback from vmwgfx screenClose. 5522f7e8e5Smrg * @post_damage: Callback from vmwgfx blockHandler. This callback should 5622f7e8e5Smrg * instruct the hosting environment about damaged windows. 5722f7e8e5Smrg * @dri_auth: Authenticate a dri client. 5822f7e8e5Smrg */ 5922f7e8e5Smrgstruct vmwgfx_hosted_driver { 6022f7e8e5Smrg struct vmwgfx_hosted *(*create)(ScrnInfoPtr); 6122f7e8e5Smrg void (*destroy)(struct vmwgfx_hosted *); 6222f7e8e5Smrg int (*drm_fd)(struct vmwgfx_hosted *, const struct pci_device *); 6322f7e8e5Smrg Bool (*pre_init)(struct vmwgfx_hosted *, int); 6422f7e8e5Smrg Bool (*screen_init)(struct vmwgfx_hosted *, ScreenPtr); 6522f7e8e5Smrg void (*screen_close)(struct vmwgfx_hosted *); 6622f7e8e5Smrg void (*post_damage)(struct vmwgfx_hosted *); 6722f7e8e5Smrg int (*dri_auth)(struct vmwgfx_hosted *, ClientPtr client, uint32_t magic); 6822f7e8e5Smrg}; 6922f7e8e5Smrg 7022f7e8e5Smrgextern const struct vmwgfx_hosted_driver *vmwgfx_hosted_detect(void); 7122f7e8e5Smrgextern void vmwgfx_hosted_modify_flags(uint32_t *flags); 7222f7e8e5Smrg 7322f7e8e5Smrg/** 7422f7e8e5Smrg * vmwgfx_is_hosted - Check whether we're running hosted. 7522f7e8e5Smrg * 7622f7e8e5Smrg * @driver: Pointer to a struct vmwgfx_hosted_driver as returned by 7722f7e8e5Smrg * vmwgfx_hosted_detect() 7822f7e8e5Smrg * 7922f7e8e5Smrg */ 8022f7e8e5Smrgstatic inline Bool 8122f7e8e5Smrgvmwgfx_is_hosted(const struct vmwgfx_hosted_driver *driver) 8222f7e8e5Smrg{ 8322f7e8e5Smrg return (driver != NULL); 8422f7e8e5Smrg} 8522f7e8e5Smrg 8622f7e8e5Smrg/** 8722f7e8e5Smrg * vmwgfx_hosted_create - Set up and initialize a struct vmwgfx_hosted 8822f7e8e5Smrg * 8922f7e8e5Smrg * @driver: Pointer to a struct vmwgfx_hosted_driver as returned by 9022f7e8e5Smrg * vmwgfx_hosted_detect() 9122f7e8e5Smrg * @pScrn: Pointer to a ScrnInfo structure, that has not been populated yet. 9222f7e8e5Smrg * 9322f7e8e5Smrg * Convenience wrapper around the hosted_driver function. 9422f7e8e5Smrg */ 9522f7e8e5Smrgstatic inline struct vmwgfx_hosted* 9622f7e8e5Smrgvmwgfx_hosted_create(const struct vmwgfx_hosted_driver *driver, 9722f7e8e5Smrg ScrnInfoPtr pScrn) 9822f7e8e5Smrg{ 9922f7e8e5Smrg if (!vmwgfx_is_hosted(driver)) 10022f7e8e5Smrg return NULL; 10122f7e8e5Smrg 10222f7e8e5Smrg return driver->create(pScrn); 10322f7e8e5Smrg} 10422f7e8e5Smrg 10522f7e8e5Smrg/** 10622f7e8e5Smrg * vmwgfx_hosted_destroy - free a struct vmwgfx_hosted and take down 10722f7e8e5Smrg * hosted environment. 10822f7e8e5Smrg * 10922f7e8e5Smrg * @driver: Pointer to a struct vmwgfx_hosted_driver as returned by 11022f7e8e5Smrg * vmwgfx_hosted_detect() 11122f7e8e5Smrg * @hosted: Pointer to a struct vmwgfx_hosted, as returned by 11222f7e8e5Smrg * vmwgfx_hosted_create() 11322f7e8e5Smrg * 11422f7e8e5Smrg * Convenience wrapper around the hosted_driver function. 11522f7e8e5Smrg */ 11622f7e8e5Smrgstatic inline void 11722f7e8e5Smrgvmwgfx_hosted_destroy(const struct vmwgfx_hosted_driver *driver, 11822f7e8e5Smrg struct vmwgfx_hosted *hosted) 11922f7e8e5Smrg{ 12022f7e8e5Smrg if (!vmwgfx_is_hosted(driver)) 12122f7e8e5Smrg return; 12222f7e8e5Smrg 12322f7e8e5Smrg driver->destroy(hosted); 12422f7e8e5Smrg} 12522f7e8e5Smrg 12622f7e8e5Smrg/** 12722f7e8e5Smrg * vmwgfx_hosted_drm_fd - Return a drm file descriptor 12822f7e8e5Smrg * 12922f7e8e5Smrg * @driver: Pointer to a struct vmwgfx_hosted_driver as returned by 13022f7e8e5Smrg * vmwgfx_hosted_detect() 13122f7e8e5Smrg * @hosted: Pointer to a struct vmwgfx_hosted, as returned by 13222f7e8e5Smrg * vmwgfx_hosted_create() 13322f7e8e5Smrg * @pci: Pointer to a valid struct pci_device, describing our device. 13422f7e8e5Smrg * 13522f7e8e5Smrg * Convenience wrapper around the hosted_driver function. Returns an 13622f7e8e5Smrg * invalid file descriptor if we're not hosted. 13722f7e8e5Smrg */ 13822f7e8e5Smrgstatic inline int 13922f7e8e5Smrgvmwgfx_hosted_drm_fd(const struct vmwgfx_hosted_driver *driver, 14022f7e8e5Smrg struct vmwgfx_hosted *hosted, 14122f7e8e5Smrg const struct pci_device *pci) 14222f7e8e5Smrg{ 14322f7e8e5Smrg if (!vmwgfx_is_hosted(driver)) 14422f7e8e5Smrg return -1; 14522f7e8e5Smrg 14622f7e8e5Smrg return driver->drm_fd(hosted, pci); 14722f7e8e5Smrg} 14822f7e8e5Smrg 14922f7e8e5Smrg/** 15022f7e8e5Smrg * vmwgfx_hosted_pre_init - Initiate preInit callback. 15122f7e8e5Smrg * 15222f7e8e5Smrg * @driver: Pointer to a struct vmwgfx_hosted_driver as returned by 15322f7e8e5Smrg * vmwgfx_hosted_detect() 15422f7e8e5Smrg * @hosted: Pointer to a struct vmwgfx_hosted, as returned by 15522f7e8e5Smrg * vmwgfx_hosted_create() 15622f7e8e5Smrg * @flags: Flags passed to the vmwgfx preInit function 15722f7e8e5Smrg * 15822f7e8e5Smrg * Convenience wrapper around the hosted_driver function. Returns TRUE 15922f7e8e5Smrg * (success) if not hosted. 16022f7e8e5Smrg */ 16122f7e8e5Smrgstatic inline Bool 16222f7e8e5Smrgvmwgfx_hosted_pre_init(const struct vmwgfx_hosted_driver *driver, 16322f7e8e5Smrg struct vmwgfx_hosted *hosted, int flags) 16422f7e8e5Smrg{ 16522f7e8e5Smrg if (!vmwgfx_is_hosted(driver)) 16622f7e8e5Smrg return TRUE; 16722f7e8e5Smrg 16822f7e8e5Smrg return driver->pre_init(hosted, flags); 16922f7e8e5Smrg} 17022f7e8e5Smrg 17122f7e8e5Smrg/** 17222f7e8e5Smrg * vmwgfx_hosted_screen_init - Initiate screenInit callback. 17322f7e8e5Smrg * 17422f7e8e5Smrg * @driver: Pointer to a struct vmwgfx_hosted_driver as returned by 17522f7e8e5Smrg * vmwgfx_hosted_detect() 17622f7e8e5Smrg * @hosted: Pointer to a struct vmwgfx_hosted, as returned by 17722f7e8e5Smrg * vmwgfx_hosted_create() 17822f7e8e5Smrg * @pScreen: ScreenPtr identifying the screen we're setting up. 17922f7e8e5Smrg * 18022f7e8e5Smrg * Convenience wrapper around the hosted_driver function. Returns TRUE 18122f7e8e5Smrg * (success) if not hosted. 18222f7e8e5Smrg */ 18322f7e8e5Smrgstatic inline Bool 18422f7e8e5Smrgvmwgfx_hosted_screen_init(const struct vmwgfx_hosted_driver *driver, 18522f7e8e5Smrg struct vmwgfx_hosted *hosted, ScreenPtr pScreen) 18622f7e8e5Smrg{ 18722f7e8e5Smrg if (!vmwgfx_is_hosted(driver)) 18822f7e8e5Smrg return TRUE; 18922f7e8e5Smrg 19022f7e8e5Smrg return driver->screen_init(hosted, pScreen); 19122f7e8e5Smrg} 19222f7e8e5Smrg 19322f7e8e5Smrg/** 19422f7e8e5Smrg * vmwgfx_hosted_screen_close - Initiate screenClose callback. 19522f7e8e5Smrg * 19622f7e8e5Smrg * @driver: Pointer to a struct vmwgfx_hosted_driver as returned by 19722f7e8e5Smrg * vmwgfx_hosted_detect() 19822f7e8e5Smrg * @hosted: Pointer to a struct vmwgfx_hosted, as returned by 19922f7e8e5Smrg * vmwgfx_hosted_create() 20022f7e8e5Smrg * 20122f7e8e5Smrg * Convenience wrapper around the hosted_driver function. 20222f7e8e5Smrg * Does nothing if not hosted. 20322f7e8e5Smrg */ 20422f7e8e5Smrgstatic inline void 20522f7e8e5Smrgvmwgfx_hosted_screen_close(const struct vmwgfx_hosted_driver *driver, 20622f7e8e5Smrg struct vmwgfx_hosted *hosted) 20722f7e8e5Smrg{ 20822f7e8e5Smrg if (!vmwgfx_is_hosted(driver)) 20922f7e8e5Smrg return; 21022f7e8e5Smrg 21122f7e8e5Smrg driver->screen_close(hosted); 21222f7e8e5Smrg} 21322f7e8e5Smrg 21422f7e8e5Smrg/** 21522f7e8e5Smrg * vmwgfx_hosted_post_damage - Inform the hosting environment about 21622f7e8e5Smrg * recent rendering 21722f7e8e5Smrg * 21822f7e8e5Smrg * @driver: Pointer to a struct vmwgfx_hosted_driver as returned by 21922f7e8e5Smrg * vmwgfx_hosted_detect() 22022f7e8e5Smrg * @hosted: Pointer to a struct vmwgfx_hosted, as returned by 22122f7e8e5Smrg * vmwgfx_hosted_create() 22222f7e8e5Smrg * 22322f7e8e5Smrg * Convenience wrapper around the hosted_driver function. 22422f7e8e5Smrg * Does nothing if not hosted. 22522f7e8e5Smrg */ 22622f7e8e5Smrgstatic inline void 22722f7e8e5Smrgvmwgfx_hosted_post_damage(const struct vmwgfx_hosted_driver *driver, 22822f7e8e5Smrg struct vmwgfx_hosted *hosted) 22922f7e8e5Smrg{ 23022f7e8e5Smrg if (!vmwgfx_is_hosted(driver)) 23122f7e8e5Smrg return; 23222f7e8e5Smrg 23322f7e8e5Smrg driver->post_damage(hosted); 23422f7e8e5Smrg} 23522f7e8e5Smrg 23622f7e8e5Smrg/** 23722f7e8e5Smrg * vmwgfx_hosted_dri_auth - Ask the hosting environment to authenticate a 23822f7e8e5Smrg * dri client. 23922f7e8e5Smrg * 24022f7e8e5Smrg * @driver: Pointer to a struct vmwgfx_hosted_driver as returned by 24122f7e8e5Smrg * vmwgfx_hosted_detect() 24222f7e8e5Smrg * @hosted: Pointer to a struct vmwgfx_hosted, as returned by 24322f7e8e5Smrg * vmwgfx_hosted_create() 24422f7e8e5Smrg * @client: The client to be authenticated 24522f7e8e5Smrg * @magic: The drm magic used for authentication 24622f7e8e5Smrg * 24722f7e8e5Smrg * Convenience wrapper around the hosted_driver function. 24822f7e8e5Smrg * Does nothing if not hosted. 24922f7e8e5Smrg */ 25022f7e8e5Smrgstatic inline int 25122f7e8e5Smrgvmwgfx_hosted_dri_auth(const struct vmwgfx_hosted_driver *driver, 25222f7e8e5Smrg struct vmwgfx_hosted *hosted, 25322f7e8e5Smrg ClientPtr client, 25422f7e8e5Smrg uint32_t magic) 25522f7e8e5Smrg{ 25622f7e8e5Smrg return driver->dri_auth(hosted, client, magic); 25722f7e8e5Smrg} 25822f7e8e5Smrg#endif /* _VMWGFX_HOSTED_H */ 259