1 /**************************************************************************
3 * Copyright 2012 Francisco Jerez
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #include "pipe_loader_priv.h"
30 #include "util/u_inlines.h"
31 #include "util/u_memory.h"
32 #include "util/u_string.h"
33 #include "util/u_dl.h"
34 #include "util/u_file.h"
35 #include "util/xmlconfig.h"
36 #include "util/xmlpool.h"
42 #define PATH_MAX _MAX_PATH
45 #define MODULE_PREFIX "pipe_"
47 static int (*backends
[])(struct pipe_loader_device
**, int) = {
49 &pipe_loader_drm_probe
,
54 const char gallium_driinfo_xml
[] =
56 #include "driinfo_gallium.h"
61 pipe_loader_probe(struct pipe_loader_device
**devs
, int ndev
)
65 for (i
= 0; i
< ARRAY_SIZE(backends
); i
++)
66 n
+= backends
[i
](&devs
[n
], MAX2(0, ndev
- n
));
72 pipe_loader_release(struct pipe_loader_device
**devs
, int ndev
)
76 for (i
= 0; i
< ndev
; i
++)
77 devs
[i
]->ops
->release(&devs
[i
]);
81 pipe_loader_base_release(struct pipe_loader_device
**dev
)
83 driDestroyOptionCache(&(*dev
)->option_cache
);
84 driDestroyOptionInfo(&(*dev
)->option_info
);
90 const struct drm_conf_ret
*
91 pipe_loader_configuration(struct pipe_loader_device
*dev
,
94 return dev
->ops
->configuration(dev
, conf
);
98 pipe_loader_load_options(struct pipe_loader_device
*dev
)
100 if (dev
->option_info
.info
)
103 const char *xml_options
= gallium_driinfo_xml
;
104 const struct drm_conf_ret
*xml_options_conf
=
105 pipe_loader_configuration(dev
, DRM_CONF_XML_OPTIONS
);
107 if (xml_options_conf
)
108 xml_options
= xml_options_conf
->val
.val_pointer
;
110 driParseOptionInfo(&dev
->option_info
, xml_options
);
111 driParseConfigFiles(&dev
->option_cache
, &dev
->option_info
, 0,
112 dev
->driver_name
, NULL
);
116 pipe_loader_get_driinfo_xml(const char *driver_name
)
119 char *xml
= pipe_loader_drm_get_driinfo_xml(driver_name
);
125 xml
= strdup(gallium_driinfo_xml
);
131 pipe_loader_create_screen(struct pipe_loader_device
*dev
)
133 struct pipe_screen_config config
;
135 pipe_loader_load_options(dev
);
136 config
.options
= &dev
->option_cache
;
138 return dev
->ops
->create_screen(dev
, &config
);
141 struct util_dl_library
*
142 pipe_loader_find_module(const char *driver_name
,
143 const char *library_paths
)
145 struct util_dl_library
*lib
;
150 for (next
= library_paths
; *next
; library_paths
= next
+ 1) {
151 next
= util_strchrnul(library_paths
, ':');
152 len
= next
- library_paths
;
155 ret
= util_snprintf(path
, sizeof(path
), "%.*s/%s%s%s",
157 MODULE_PREFIX
, driver_name
, UTIL_DL_EXT
);
159 ret
= util_snprintf(path
, sizeof(path
), "%s%s%s",
160 MODULE_PREFIX
, driver_name
, UTIL_DL_EXT
);
162 if (ret
> 0 && ret
< sizeof(path
) && u_file_access(path
, 0) != -1) {
163 lib
= util_dl_open(path
);
167 fprintf(stderr
, "ERROR: Failed to load pipe driver at `%s': %s\n",
168 path
, util_dl_error());