vmwgfx_hosted.h revision 22f7e8e5
1/* 2 * Copyright 2013 VMWare, Inc. 3 * All Rights Reserved. 4 * 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: 12 * 13 * The above copyright notice and this permission notice (including the 14 * next paragraph) shall be included in all copies or substantial portions 15 * of the Software. 16 * 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. 24 * 25 * Author: Thomas Hellstrom <thellstrom@vmware.com> 26 * Note: "Hosted" is a term stolen from the xf86-video-intel driver. 27 */ 28 29#ifndef _VMWGFX_HOSTED_H 30#define _VMWGFX_HOSTED_H 31 32#include <xorg-server.h> 33#include <xf86.h> 34 35 36/** 37 * struct vmwgfx_hosted - hosting environment private information. 38 * 39 * This struct is completely opaque to callers and should be defined 40 * by the hosting environment. 41 */ 42struct vmwgfx_hosted; 43 44/** 45 * struct vmwgfx-hosted-driver - Driver for environments that we can run 46 * hosted under. 47 * 48 * @create: Initialize and create an opaque struct vmwgfx_hosted with 49 * environment private information. Should return NULL on failure. 50 * @destroy: Undo what's done in @create. 51 * @drm_fd: Return a file descriptor opened to DRM. 52 * @pre_init: Callback from vmwgfx preInit. 53 * @screen_init: Callback from vmwgfx screenInit. 54 * @screen_close: Callback from vmwgfx screenClose. 55 * @post_damage: Callback from vmwgfx blockHandler. This callback should 56 * instruct the hosting environment about damaged windows. 57 * @dri_auth: Authenticate a dri client. 58 */ 59struct vmwgfx_hosted_driver { 60 struct vmwgfx_hosted *(*create)(ScrnInfoPtr); 61 void (*destroy)(struct vmwgfx_hosted *); 62 int (*drm_fd)(struct vmwgfx_hosted *, const struct pci_device *); 63 Bool (*pre_init)(struct vmwgfx_hosted *, int); 64 Bool (*screen_init)(struct vmwgfx_hosted *, ScreenPtr); 65 void (*screen_close)(struct vmwgfx_hosted *); 66 void (*post_damage)(struct vmwgfx_hosted *); 67 int (*dri_auth)(struct vmwgfx_hosted *, ClientPtr client, uint32_t magic); 68}; 69 70extern const struct vmwgfx_hosted_driver *vmwgfx_hosted_detect(void); 71extern void vmwgfx_hosted_modify_flags(uint32_t *flags); 72 73/** 74 * vmwgfx_is_hosted - Check whether we're running hosted. 75 * 76 * @driver: Pointer to a struct vmwgfx_hosted_driver as returned by 77 * vmwgfx_hosted_detect() 78 * 79 */ 80static inline Bool 81vmwgfx_is_hosted(const struct vmwgfx_hosted_driver *driver) 82{ 83 return (driver != NULL); 84} 85 86/** 87 * vmwgfx_hosted_create - Set up and initialize a struct vmwgfx_hosted 88 * 89 * @driver: Pointer to a struct vmwgfx_hosted_driver as returned by 90 * vmwgfx_hosted_detect() 91 * @pScrn: Pointer to a ScrnInfo structure, that has not been populated yet. 92 * 93 * Convenience wrapper around the hosted_driver function. 94 */ 95static inline struct vmwgfx_hosted* 96vmwgfx_hosted_create(const struct vmwgfx_hosted_driver *driver, 97 ScrnInfoPtr pScrn) 98{ 99 if (!vmwgfx_is_hosted(driver)) 100 return NULL; 101 102 return driver->create(pScrn); 103} 104 105/** 106 * vmwgfx_hosted_destroy - free a struct vmwgfx_hosted and take down 107 * hosted environment. 108 * 109 * @driver: Pointer to a struct vmwgfx_hosted_driver as returned by 110 * vmwgfx_hosted_detect() 111 * @hosted: Pointer to a struct vmwgfx_hosted, as returned by 112 * vmwgfx_hosted_create() 113 * 114 * Convenience wrapper around the hosted_driver function. 115 */ 116static inline void 117vmwgfx_hosted_destroy(const struct vmwgfx_hosted_driver *driver, 118 struct vmwgfx_hosted *hosted) 119{ 120 if (!vmwgfx_is_hosted(driver)) 121 return; 122 123 driver->destroy(hosted); 124} 125 126/** 127 * vmwgfx_hosted_drm_fd - Return a drm file descriptor 128 * 129 * @driver: Pointer to a struct vmwgfx_hosted_driver as returned by 130 * vmwgfx_hosted_detect() 131 * @hosted: Pointer to a struct vmwgfx_hosted, as returned by 132 * vmwgfx_hosted_create() 133 * @pci: Pointer to a valid struct pci_device, describing our device. 134 * 135 * Convenience wrapper around the hosted_driver function. Returns an 136 * invalid file descriptor if we're not hosted. 137 */ 138static inline int 139vmwgfx_hosted_drm_fd(const struct vmwgfx_hosted_driver *driver, 140 struct vmwgfx_hosted *hosted, 141 const struct pci_device *pci) 142{ 143 if (!vmwgfx_is_hosted(driver)) 144 return -1; 145 146 return driver->drm_fd(hosted, pci); 147} 148 149/** 150 * vmwgfx_hosted_pre_init - Initiate preInit callback. 151 * 152 * @driver: Pointer to a struct vmwgfx_hosted_driver as returned by 153 * vmwgfx_hosted_detect() 154 * @hosted: Pointer to a struct vmwgfx_hosted, as returned by 155 * vmwgfx_hosted_create() 156 * @flags: Flags passed to the vmwgfx preInit function 157 * 158 * Convenience wrapper around the hosted_driver function. Returns TRUE 159 * (success) if not hosted. 160 */ 161static inline Bool 162vmwgfx_hosted_pre_init(const struct vmwgfx_hosted_driver *driver, 163 struct vmwgfx_hosted *hosted, int flags) 164{ 165 if (!vmwgfx_is_hosted(driver)) 166 return TRUE; 167 168 return driver->pre_init(hosted, flags); 169} 170 171/** 172 * vmwgfx_hosted_screen_init - Initiate screenInit callback. 173 * 174 * @driver: Pointer to a struct vmwgfx_hosted_driver as returned by 175 * vmwgfx_hosted_detect() 176 * @hosted: Pointer to a struct vmwgfx_hosted, as returned by 177 * vmwgfx_hosted_create() 178 * @pScreen: ScreenPtr identifying the screen we're setting up. 179 * 180 * Convenience wrapper around the hosted_driver function. Returns TRUE 181 * (success) if not hosted. 182 */ 183static inline Bool 184vmwgfx_hosted_screen_init(const struct vmwgfx_hosted_driver *driver, 185 struct vmwgfx_hosted *hosted, ScreenPtr pScreen) 186{ 187 if (!vmwgfx_is_hosted(driver)) 188 return TRUE; 189 190 return driver->screen_init(hosted, pScreen); 191} 192 193/** 194 * vmwgfx_hosted_screen_close - Initiate screenClose callback. 195 * 196 * @driver: Pointer to a struct vmwgfx_hosted_driver as returned by 197 * vmwgfx_hosted_detect() 198 * @hosted: Pointer to a struct vmwgfx_hosted, as returned by 199 * vmwgfx_hosted_create() 200 * 201 * Convenience wrapper around the hosted_driver function. 202 * Does nothing if not hosted. 203 */ 204static inline void 205vmwgfx_hosted_screen_close(const struct vmwgfx_hosted_driver *driver, 206 struct vmwgfx_hosted *hosted) 207{ 208 if (!vmwgfx_is_hosted(driver)) 209 return; 210 211 driver->screen_close(hosted); 212} 213 214/** 215 * vmwgfx_hosted_post_damage - Inform the hosting environment about 216 * recent rendering 217 * 218 * @driver: Pointer to a struct vmwgfx_hosted_driver as returned by 219 * vmwgfx_hosted_detect() 220 * @hosted: Pointer to a struct vmwgfx_hosted, as returned by 221 * vmwgfx_hosted_create() 222 * 223 * Convenience wrapper around the hosted_driver function. 224 * Does nothing if not hosted. 225 */ 226static inline void 227vmwgfx_hosted_post_damage(const struct vmwgfx_hosted_driver *driver, 228 struct vmwgfx_hosted *hosted) 229{ 230 if (!vmwgfx_is_hosted(driver)) 231 return; 232 233 driver->post_damage(hosted); 234} 235 236/** 237 * vmwgfx_hosted_dri_auth - Ask the hosting environment to authenticate a 238 * dri client. 239 * 240 * @driver: Pointer to a struct vmwgfx_hosted_driver as returned by 241 * vmwgfx_hosted_detect() 242 * @hosted: Pointer to a struct vmwgfx_hosted, as returned by 243 * vmwgfx_hosted_create() 244 * @client: The client to be authenticated 245 * @magic: The drm magic used for authentication 246 * 247 * Convenience wrapper around the hosted_driver function. 248 * Does nothing if not hosted. 249 */ 250static inline int 251vmwgfx_hosted_dri_auth(const struct vmwgfx_hosted_driver *driver, 252 struct vmwgfx_hosted *hosted, 253 ClientPtr client, 254 uint32_t magic) 255{ 256 return driver->dri_auth(hosted, client, magic); 257} 258#endif /* _VMWGFX_HOSTED_H */ 259