104e5b88e2c54378b3961fbdbd60c53dcd1aac432scottmg@chromium.org/* 21dd7d6785cfafe82496c634ceeb0e97462020f9bpiman@chromium.org * Copyright © 2011 Intel Corporation 31dd7d6785cfafe82496c634ceeb0e97462020f9bpiman@chromium.org * 41dd7d6785cfafe82496c634ceeb0e97462020f9bpiman@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a 51dd7d6785cfafe82496c634ceeb0e97462020f9bpiman@chromium.org * copy of this software and associated documentation files (the "Software"), 61dd7d6785cfafe82496c634ceeb0e97462020f9bpiman@chromium.org * to deal in the Software without restriction, including without limitation 71dd7d6785cfafe82496c634ceeb0e97462020f9bpiman@chromium.org * the rights to use, copy, modify, merge, publish, distribute, sublicense, 81dd7d6785cfafe82496c634ceeb0e97462020f9bpiman@chromium.org * and/or sell copies of the Software, and to permit persons to whom the 91dd7d6785cfafe82496c634ceeb0e97462020f9bpiman@chromium.org * Software is furnished to do so, subject to the following conditions: 101dd7d6785cfafe82496c634ceeb0e97462020f9bpiman@chromium.org * 1104e5b88e2c54378b3961fbdbd60c53dcd1aac432scottmg@chromium.org * The above copyright notice and this permission notice (including the next 121dd7d6785cfafe82496c634ceeb0e97462020f9bpiman@chromium.org * paragraph) shall be included in all copies or substantial portions of the 131dd7d6785cfafe82496c634ceeb0e97462020f9bpiman@chromium.org * Software. 1404e5b88e2c54378b3961fbdbd60c53dcd1aac432scottmg@chromium.org * 151dd7d6785cfafe82496c634ceeb0e97462020f9bpiman@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 161dd7d6785cfafe82496c634ceeb0e97462020f9bpiman@chromium.org * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 171dd7d6785cfafe82496c634ceeb0e97462020f9bpiman@chromium.org * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 181dd7d6785cfafe82496c634ceeb0e97462020f9bpiman@chromium.org * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 * DEALINGS IN THE SOFTWARE. 23 * 24 * Authors: 25 * Benjamin Franzke <benjaminfranzke@googlemail.com> 26 */ 27 28#include "gbm_gallium_drmint.h" 29 30#include "util/u_memory.h" 31#include "util/u_inlines.h" 32#include "pipe-loader/pipe_loader.h" 33 34static const char * 35get_library_search_path(void) 36{ 37 const char *search_path = NULL; 38 39 /* don't allow setuid apps to use GBM_BACKENDS_PATH */ 40 if (geteuid() == getuid()) 41 search_path = getenv("GBM_BACKENDS_PATH"); 42 if (search_path == NULL) 43 search_path = PIPE_SEARCH_DIR; 44 45 return search_path; 46} 47 48int 49gallium_screen_create(struct gbm_gallium_drm_device *gdrm) 50{ 51 struct pipe_loader_device *dev; 52#ifdef HAVE_PIPE_LOADER_DRM 53 int ret; 54 55 ret = pipe_loader_drm_probe_fd(&dev, gdrm->base.base.fd); 56 if (!ret) 57 return -1; 58#endif /* HAVE_PIPE_LOADER_DRM */ 59 60 gdrm->screen = pipe_loader_create_screen(dev, get_library_search_path()); 61 if (gdrm->screen == NULL) { 62 debug_printf("failed to load driver: %s\n", gdrm->base.driver_name); 63 pipe_loader_release(&dev, 1); 64 return -1; 65 }; 66 67 gdrm->driver = dev; 68 gdrm->base.driver_name = strdup(dev->driver_name); 69 return 0; 70} 71 72void 73gallium_screen_destroy(struct gbm_gallium_drm_device *gdrm) 74{ 75 FREE(gdrm->base.driver_name); 76 gdrm->screen->destroy(gdrm->screen); 77 pipe_loader_release((struct pipe_loader_device **)&gdrm->driver, 1); 78} 79 80GBM_EXPORT struct gbm_backend gbm_backend = { 81 .backend_name = "gallium_drm", 82 .create_device = gbm_gallium_drm_device_create, 83}; 84