1 /************************************************************************** 2 * 3 * Copyright 2012 Francisco Jerez 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 28 /** 29 * \file Library that provides device enumeration and creation of 30 * winsys/pipe_screen instances. 31 */ 32 33 #ifndef PIPE_LOADER_H 34 #define PIPE_LOADER_H 35 36 #include "util/compiler.h" 37 #include "frontend/drm_driver.h" 38 #include "util/xmlconfig.h" 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 struct pipe_screen; 45 struct drisw_loader_funcs; 46 47 enum pipe_loader_device_type { 48 PIPE_LOADER_DEVICE_SOFTWARE, 49 PIPE_LOADER_DEVICE_PCI, 50 PIPE_LOADER_DEVICE_PLATFORM, 51 NUM_PIPE_LOADER_DEVICE_TYPES 52 }; 53 54 /** 55 * A device known to the pipe loader. 56 */ 57 struct pipe_loader_device { 58 enum pipe_loader_device_type type; 59 60 union { 61 struct { 62 int vendor_id; 63 int chip_id; 64 } pci; 65 } u; /**< Discriminated by \a type */ 66 67 char *driver_name; 68 const struct pipe_loader_ops *ops; 69 70 driOptionCache option_cache; 71 driOptionCache option_info; 72 }; 73 74 /** 75 * Get a list of known devices. 76 * 77 * \param devs Array that will be filled with pointers to the devices 78 * available in the system. 79 * \param ndev Maximum number of devices to return. 80 * \param with_zink If devices should also be loaded with zink. 81 * \return Number of devices available in the system. 82 */ 83 int 84 pipe_loader_probe(struct pipe_loader_device **devs, int ndev, bool with_zink); 85 86 /** 87 * Create a pipe_screen for the specified device. 88 * 89 * \param dev Device the screen will be created for. 90 * \param sw_vk Device is for software vulkan 91 * \param driver_name_is_inferred Whether the driver name has been directly selected. 92 */ 93 struct pipe_screen * 94 pipe_loader_create_screen_vk(struct pipe_loader_device *dev, bool sw_vk, bool driver_name_is_inferred); 95 96 /** 97 * Create a pipe_screen for the specified device. 98 * 99 * \param dev Device the screen will be created for. 100 * \param driver_name_is_inferred Whether the driver name has been directly selected. 101 */ 102 struct pipe_screen * 103 pipe_loader_create_screen(struct pipe_loader_device *dev, bool driver_name_is_inferred); 104 105 /** 106 * Ensures that the driconf option cache has been parsed for the driver. 107 * 108 * Drivers may parse during screen creation, but for those that don't (probably 109 * due to not having any driver-specific driconf options), this can be used to 110 * finish the parsing so that general driconf options can be queried. 111 */ 112 void 113 pipe_loader_config_options(struct pipe_loader_device *dev); 114 115 /** 116 * Get the driinfo XML string used by the given driver. 117 * 118 * The returned string is heap-allocated. 119 */ 120 char * 121 pipe_loader_get_driinfo_xml(const char *driver_name); 122 123 /** 124 * Release resources allocated for a list of devices. 125 * 126 * Should be called when the specified devices are no longer in use to 127 * release any resources allocated by pipe_loader_probe. 128 * 129 * \param devs Devices to release. 130 * \param ndev Number of devices to release. 131 */ 132 void 133 pipe_loader_release(struct pipe_loader_device **devs, int ndev); 134 135 /** 136 * Initialize sw dri device give the drisw_loader_funcs. 137 * 138 * This function is platform-specific. 139 * 140 * Function does not take ownership of the fd, but duplicates it locally. 141 * The local fd is closed during pipe_loader_release. 142 * 143 * \sa pipe_loader_probe 144 */ 145 bool 146 pipe_loader_sw_probe_dri(struct pipe_loader_device **devs, 147 const struct drisw_loader_funcs *drisw_lf); 148 149 /** 150 * Initialize vk dri device give the drisw_loader_funcs. 151 * 152 * This function is platform-specific. 153 * 154 * Function does not take ownership of the fd, but duplicates it locally. 155 * The local fd is closed during pipe_loader_release. 156 * 157 * \sa pipe_loader_probe 158 */ 159 bool 160 pipe_loader_vk_probe_dri(struct pipe_loader_device **devs); 161 162 #ifdef HAVE_DRISW_KMS 163 /** 164 * Initialize a kms backed sw device given an fd. 165 * 166 * This function is platform-specific. 167 * 168 * Function does not take ownership of the fd, but duplicates it locally. 169 * The local fd is closed during pipe_loader_release. 170 * 171 * \sa pipe_loader_probe 172 */ 173 bool 174 pipe_loader_sw_probe_kms(struct pipe_loader_device **devs, int fd); 175 #endif 176 177 /** 178 * Initialize a null sw device. 179 * 180 * This function is platform-specific. 181 * 182 * \sa pipe_loader_probe 183 */ 184 bool 185 pipe_loader_sw_probe_null(struct pipe_loader_device **devs); 186 187 /** 188 * Get a list of known software devices. 189 * 190 * This function is platform-specific. 191 * 192 * \sa pipe_loader_probe 193 */ 194 int 195 pipe_loader_sw_probe(struct pipe_loader_device **devs, int ndev); 196 197 /** 198 * Get a software device wrapped atop another device. 199 * 200 * This function is platform-specific. 201 * 202 * \sa pipe_loader_probe 203 */ 204 bool 205 pipe_loader_sw_probe_wrapped(struct pipe_loader_device **dev, 206 struct pipe_screen *screen); 207 208 /** 209 * Get a list of known DRM devices. 210 * 211 * This function is platform-specific. 212 * 213 * \sa pipe_loader_probe 214 */ 215 int 216 pipe_loader_drm_probe(struct pipe_loader_device **devs, int ndev); 217 218 #ifdef HAVE_ZINK 219 /** 220 * Get a list of known DRM devices compatible with zink. 221 * 222 * This function is platform-specific. 223 * 224 * \sa pipe_loader_probe 225 */ 226 int 227 pipe_loader_drm_zink_probe(struct pipe_loader_device **devs, int ndev); 228 #endif 229 230 /** 231 * Get the fd of a render-capable device compatible with a given display-only 232 * device fd. 233 */ 234 int 235 pipe_loader_get_compatible_render_capable_device_fd(int kms_only_fd); 236 237 /** 238 * Initialize a DRM device in an already opened fd. 239 * 240 * This function is platform-specific. 241 * 242 * \sa pipe_loader_probe 243 */ 244 bool 245 pipe_loader_drm_probe_fd(struct pipe_loader_device **dev, int fd, bool zink); 246 247 /** 248 * Get the dri options used for the DRM driver of the given name, if any. 249 * 250 * The returned array is heap-allocated. 251 */ 252 const struct driOptionDescription * 253 pipe_loader_drm_get_driconf_by_name(const char *driver_name, unsigned *count); 254 255 #ifdef __cplusplus 256 } 257 #endif 258 259 #endif /* PIPE_LOADER_H */ 260