1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright (C) 2013 Rob Clark <robclark@freedesktop.org>
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21bf215546Sopenharmony_ci * SOFTWARE.
22bf215546Sopenharmony_ci *
23bf215546Sopenharmony_ci * Authors:
24bf215546Sopenharmony_ci *    Rob Clark <robclark@freedesktop.org>
25bf215546Sopenharmony_ci */
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#ifndef LOADER_H
28bf215546Sopenharmony_ci#define LOADER_H
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_ci#include <stdbool.h>
31bf215546Sopenharmony_ci#include <sys/stat.h>
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci#ifdef __cplusplus
34bf215546Sopenharmony_ciextern "C" {
35bf215546Sopenharmony_ci#endif
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_cistruct __DRIextensionRec;
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci/* Helpers to figure out driver and device name, eg. from pci-id, etc. */
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_ciint
42bf215546Sopenharmony_ciloader_open_device(const char *device_name);
43bf215546Sopenharmony_ci
44bf215546Sopenharmony_ciint
45bf215546Sopenharmony_ciloader_open_render_node(const char *name);
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_cichar *
48bf215546Sopenharmony_ciloader_get_render_node(dev_t device);
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_cibool
51bf215546Sopenharmony_ciloader_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id);
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_cichar *
54bf215546Sopenharmony_ciloader_get_driver_for_fd(int fd);
55bf215546Sopenharmony_ci
56bf215546Sopenharmony_civoid *
57bf215546Sopenharmony_ciloader_open_driver_lib(const char *driver_name,
58bf215546Sopenharmony_ci                       const char *lib_suffix,
59bf215546Sopenharmony_ci                       const char **search_path_vars,
60bf215546Sopenharmony_ci                       const char *default_search_path,
61bf215546Sopenharmony_ci                       bool warn_on_fail);
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ciconst struct __DRIextensionRec **
64bf215546Sopenharmony_ciloader_open_driver(const char *driver_name,
65bf215546Sopenharmony_ci                   void **out_driver_handle,
66bf215546Sopenharmony_ci                   const char **search_path_vars);
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_cichar *
69bf215546Sopenharmony_ciloader_get_device_name_for_fd(int fd);
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_ci/* Function to get a different device than the one we are to use by default,
72bf215546Sopenharmony_ci * if the user requests so and it is possible. The initial fd will be closed
73bf215546Sopenharmony_ci * if necessary. The returned fd is potentially a render-node.
74bf215546Sopenharmony_ci */
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_ciint
77bf215546Sopenharmony_ciloader_get_user_preferred_fd(int default_fd, bool *different_device);
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ci/* for logging.. keep this aligned with egllog.h so we can just use
80bf215546Sopenharmony_ci * _eglLog directly.
81bf215546Sopenharmony_ci */
82bf215546Sopenharmony_ci
83bf215546Sopenharmony_ci#define _LOADER_FATAL   0   /* unrecoverable error */
84bf215546Sopenharmony_ci#define _LOADER_WARNING 1   /* recoverable error/problem */
85bf215546Sopenharmony_ci#define _LOADER_INFO    2   /* just useful info */
86bf215546Sopenharmony_ci#define _LOADER_DEBUG   3   /* useful info for debugging */
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_citypedef void loader_logger(int level, const char *fmt, ...);
89bf215546Sopenharmony_civoid
90bf215546Sopenharmony_ciloader_set_logger(loader_logger *logger);
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_cichar *
93bf215546Sopenharmony_ciloader_get_extensions_name(const char *driver_name);
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_ci#ifdef __cplusplus
96bf215546Sopenharmony_ci}
97bf215546Sopenharmony_ci#endif
98bf215546Sopenharmony_ci
99bf215546Sopenharmony_ci#endif /* LOADER_H */
100