540cc38dcb90faef829eaaa19c2461a040bf0cb9
[mesa.git] / src / gallium / include / state_tracker / drm_driver.h
1
2 #ifndef _DRM_DRIVER_H_
3 #define _DRM_DRIVER_H_
4
5 #include "pipe/p_compiler.h"
6
7 struct pipe_screen;
8 struct pipe_context;
9 struct pipe_resource;
10
11 #define DRM_API_HANDLE_TYPE_SHARED 0
12 #define DRM_API_HANDLE_TYPE_KMS 1
13 #define DRM_API_HANDLE_TYPE_FD 2
14
15
16 /**
17 * For use with pipe_screen::{texture_from_handle|texture_get_handle}.
18 */
19 struct winsys_handle
20 {
21 /**
22 * Input for texture_from_handle, valid values are
23 * DRM_API_HANDLE_TYPE_SHARED or DRM_API_HANDLE_TYPE_FD.
24 * Input to texture_get_handle,
25 * to select handle for kms, flink, or prime.
26 */
27 unsigned type;
28 /**
29 * Input for texture_get_handle, allows to export the offset
30 * of a specific layer of an array texture.
31 */
32 unsigned layer;
33 /**
34 * Input to texture_from_handle.
35 * Output for texture_get_handle.
36 */
37 unsigned handle;
38 /**
39 * Input to texture_from_handle.
40 * Output for texture_get_handle.
41 */
42 unsigned stride;
43 /**
44 * Input to texture_from_handle.
45 * Output for texture_get_handle.
46 */
47 unsigned offset;
48 };
49
50
51
52 /**
53 * Configuration queries.
54 */
55 enum drm_conf {
56 /* How many frames to allow before throttling. Or -1 to indicate any number */
57 DRM_CONF_THROTTLE, /* DRM_CONF_INT. */
58 /* Can this driver, running on this kernel, import and export dma-buf fds? */
59 DRM_CONF_SHARE_FD, /* DRM_CONF_BOOL. */
60 DRM_CONF_MAX
61 };
62
63 /**
64 * Type of configuration answer
65 */
66 enum drm_conf_type {
67 DRM_CONF_INT,
68 DRM_CONF_BOOL,
69 DRM_CONF_FLOAT,
70 DRM_CONF_POINTER
71 };
72
73 /**
74 * Return value from the configuration function.
75 */
76 struct drm_conf_ret {
77 enum drm_conf_type type;
78 union {
79 int val_int;
80 bool val_bool;
81 float val_float;
82 void *val_pointer;
83 } val;
84 };
85
86 struct drm_driver_descriptor
87 {
88 /**
89 * Identifying prefix/suffix of the binary, used by the pipe-loader.
90 */
91 const char *name;
92
93 /**
94 * Kernel driver name, as accepted by drmOpenByName.
95 */
96 const char *driver_name;
97
98 /**
99 * Create a pipe srcreen.
100 *
101 * This function does any wrapping of the screen.
102 * For example wrapping trace or rbug debugging drivers around it.
103 */
104 struct pipe_screen* (*create_screen)(int drm_fd);
105
106
107 /**
108 * Return a configuration value.
109 *
110 * If this function is NULL, or if it returns NULL
111 * the state tracker- or state
112 * tracker manager should provide a reasonable default value.
113 */
114 const struct drm_conf_ret *(*configuration) (enum drm_conf conf);
115 };
116
117 extern struct drm_driver_descriptor driver_descriptor;
118
119 /**
120 * Instantiate a drm_driver_descriptor struct.
121 */
122 #define DRM_DRIVER_DESCRIPTOR(name_str, driver_name_str, func, conf) \
123 struct drm_driver_descriptor driver_descriptor = { \
124 .name = name_str, \
125 .driver_name = driver_name_str, \
126 .create_screen = func, \
127 .configuration = (conf), \
128 };
129
130 #endif