[Mesa-dev] [PATCH 12/16] pipe-loader: extract a standalone get_driver_descriptor helper function
Nicolai Hähnle
nhaehnle at gmail.com
Fri Jun 30 12:45:53 UTC 2017
From: Nicolai Hähnle <nicolai.haehnle at amd.com>
---
.../auxiliary/pipe-loader/pipe_loader_drm.c | 49 +++++++++++++---------
1 file changed, 30 insertions(+), 19 deletions(-)
diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
index 193c8dd..92b2421 100644
--- a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
+++ b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
@@ -149,20 +149,45 @@ static const struct drm_driver_descriptor driver_descriptors[] = {
.configuration = configuration_query,
},
{
.driver_name = "imx-drm",
.create_screen = pipe_imx_drm_create_screen,
.configuration = configuration_query,
}
};
#endif
+static const struct drm_driver_descriptor *
+get_driver_descriptor(const char *driver_name, struct util_dl_library **plib)
+{
+#ifdef GALLIUM_STATIC_TARGETS
+ for (int i = 0; i < ARRAY_SIZE(driver_descriptors); i++) {
+ if (strcmp(driver_descriptors[i].driver_name, driver_name) == 0)
+ return &driver_descriptors[i];
+ }
+#else
+ *plib = pipe_loader_find_module(driver_name, PIPE_SEARCH_DIR);
+ if (!*plib)
+ return NULL;
+
+ const struct drm_driver_descriptor *dd =
+ (const struct drm_driver_descriptor *)
+ util_dl_get_proc_address(*plib, "driver_descriptor");
+
+ /* sanity check on the driver name */
+ if (dd && strcmp(dd->driver_name, driver_name) == 0)
+ return dd;
+#endif
+
+ return NULL;
+}
+
bool
pipe_loader_drm_probe_fd(struct pipe_loader_device **dev, int fd)
{
struct pipe_loader_drm_device *ddev = CALLOC_STRUCT(pipe_loader_drm_device);
int vendor_id, chip_id;
if (!ddev)
return false;
if (loader_get_pci_id_for_fd(fd, &vendor_id, &chip_id)) {
@@ -172,41 +197,27 @@ pipe_loader_drm_probe_fd(struct pipe_loader_device **dev, int fd)
} else {
ddev->base.type = PIPE_LOADER_DEVICE_PLATFORM;
}
ddev->base.ops = &pipe_loader_drm_ops;
ddev->fd = fd;
ddev->base.driver_name = loader_get_driver_for_fd(fd);
if (!ddev->base.driver_name)
goto fail;
-#ifdef GALLIUM_STATIC_TARGETS
- for (int i = 0; i < ARRAY_SIZE(driver_descriptors); i++) {
- if (strcmp(driver_descriptors[i].driver_name, ddev->base.driver_name) == 0) {
- ddev->dd = &driver_descriptors[i];
- break;
- }
- }
+ struct util_dl_library **plib = NULL;
+#ifndef GALLIUM_STATIC_TARGETS
+ plib = &ddev->lib;
+#endif
+ ddev->dd = get_driver_descriptor(ddev->base.driver_name, plib);
if (!ddev->dd)
goto fail;
-#else
- ddev->lib = pipe_loader_find_module(&ddev->base, PIPE_SEARCH_DIR);
- if (!ddev->lib)
- goto fail;
-
- ddev->dd = (const struct drm_driver_descriptor *)
- util_dl_get_proc_address(ddev->lib, "driver_descriptor");
-
- /* sanity check on the driver name */
- if (!ddev->dd || strcmp(ddev->dd->driver_name, ddev->base.driver_name) != 0)
- goto fail;
-#endif
*dev = &ddev->base;
return true;
fail:
#ifndef GALLIUM_STATIC_TARGETS
if (ddev->lib)
util_dl_close(ddev->lib);
#endif
FREE(ddev);
--
2.9.3
More information about the mesa-dev
mailing list