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 "pipe/p_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 * \return Number of devices available in the system. 81 */ 82 int 83 pipe_loader_probe(struct pipe_loader_device **devs, int ndev); 84 85 /** 86 * Create a pipe_screen for the specified device. 87 * 88 * \param dev Device the screen will be created for. 89 * \param sw_vk Device is for software vulkan 90 */ 91 struct pipe_screen * 92 pipe_loader_create_screen_vk(struct pipe_loader_device *dev, bool sw_vk); 93 94 /** 95 * Create a pipe_screen for the specified device. 96 * 97 * \param dev Device the screen will be created for. 98 */ 99 struct pipe_screen * 100 pipe_loader_create_screen(struct pipe_loader_device *dev); 101 102 /** 103 * Ensures that the driconf option cache has been parsed for the driver. 104 * 105 * Drivers may parse during screen creation, but for those that don't (probably 106 * due to not having any driver-specific driconf options), this can be used to 107 * finish the parsing so that general driconf options can be queried. 108 */ 109 void 110 pipe_loader_config_options(struct pipe_loader_device *dev); 111 112 /** 113 * Get the driinfo XML string used by the given driver. 114 * 115 * The returned string is heap-allocated. 116 */ 117 char * 118 pipe_loader_get_driinfo_xml(const char *driver_name); 119 120 /** 121 * Release resources allocated for a list of devices. 122 * 123 * Should be called when the specified devices are no longer in use to 124 * release any resources allocated by pipe_loader_probe. 125 * 126 * \param devs Devices to release. 127 * \param ndev Number of devices to release. 128 */ 129 void 130 pipe_loader_release(struct pipe_loader_device **devs, int ndev); 131 132 /** 133 * Initialize sw dri device give the drisw_loader_funcs. 134 * 135 * This function is platform-specific. 136 * 137 * Function does not take ownership of the fd, but duplicates it locally. 138 * The local fd is closed during pipe_loader_release. 139 * 140 * \sa pipe_loader_probe 141 */ 142 bool 143 pipe_loader_sw_probe_dri(struct pipe_loader_device **devs, 144 const struct drisw_loader_funcs *drisw_lf); 145 146 /** 147 * Initialize a kms backed sw device given an fd. 148 * 149 * This function is platform-specific. 150 * 151 * Function does not take ownership of the fd, but duplicates it locally. 152 * The local fd is closed during pipe_loader_release. 153 * 154 * \sa pipe_loader_probe 155 */ 156 bool 157 pipe_loader_sw_probe_kms(struct pipe_loader_device **devs, int fd); 158 159 /** 160 * Initialize a null sw device. 161 * 162 * This function is platform-specific. 163 * 164 * \sa pipe_loader_probe 165 */ 166 bool 167 pipe_loader_sw_probe_null(struct pipe_loader_device **devs); 168 169 /** 170 * Get a list of known software devices. 171 * 172 * This function is platform-specific. 173 * 174 * \sa pipe_loader_probe 175 */ 176 int 177 pipe_loader_sw_probe(struct pipe_loader_device **devs, int ndev); 178 179 /** 180 * Get a software device wrapped atop another device. 181 * 182 * This function is platform-specific. 183 * 184 * \sa pipe_loader_probe 185 */ 186 boolean 187 pipe_loader_sw_probe_wrapped(struct pipe_loader_device **dev, 188 struct pipe_screen *screen); 189 190 /** 191 * Get a list of known DRM devices. 192 * 193 * This function is platform-specific. 194 * 195 * \sa pipe_loader_probe 196 */ 197 int 198 pipe_loader_drm_probe(struct pipe_loader_device **devs, int ndev); 199 200 /** 201 * Initialize a DRM device in an already opened fd. 202 * 203 * This function is platform-specific. 204 * 205 * \sa pipe_loader_probe 206 */ 207 bool 208 pipe_loader_drm_probe_fd(struct pipe_loader_device **dev, int fd); 209 210 /** 211 * Get the dri options used for the DRM driver of the given name, if any. 212 * 213 * The returned array is heap-allocated. 214 */ 215 const struct driOptionDescription * 216 pipe_loader_drm_get_driconf_by_name(const char *driver_name, unsigned *count); 217 218 #ifdef __cplusplus 219 } 220 #endif 221 222 #endif /* PIPE_LOADER_H */ 223