Commit | Line | Data |
---|---|---|
ca96088a | 1 | /* SPDX-License-Identifier: GPL-2.0 or MIT */ |
c76f0f7c NT |
2 | |
3 | #ifndef _DRM_CLIENT_H_ | |
4 | #define _DRM_CLIENT_H_ | |
5 | ||
d81294af NT |
6 | #include <linux/lockdep.h> |
7 | #include <linux/mutex.h> | |
c76f0f7c NT |
8 | #include <linux/types.h> |
9 | ||
e5852bee | 10 | #include <drm/drm_connector.h> |
d81294af NT |
11 | #include <drm/drm_crtc.h> |
12 | ||
c76f0f7c NT |
13 | struct drm_client_dev; |
14 | struct drm_device; | |
15 | struct drm_file; | |
16 | struct drm_framebuffer; | |
17 | struct drm_gem_object; | |
e896c132 | 18 | struct drm_minor; |
c76f0f7c NT |
19 | struct module; |
20 | ||
21 | /** | |
22 | * struct drm_client_funcs - DRM client callbacks | |
23 | */ | |
24 | struct drm_client_funcs { | |
25 | /** | |
26 | * @owner: The module owner | |
27 | */ | |
28 | struct module *owner; | |
29 | ||
30 | /** | |
31 | * @unregister: | |
32 | * | |
33 | * Called when &drm_device is unregistered. The client should respond by | |
1e55a53a | 34 | * releasing its resources using drm_client_release(). |
c76f0f7c NT |
35 | * |
36 | * This callback is optional. | |
37 | */ | |
38 | void (*unregister)(struct drm_client_dev *client); | |
39 | ||
40 | /** | |
41 | * @restore: | |
42 | * | |
43 | * Called on drm_lastclose(). The first client instance in the list that | |
44 | * returns zero gets the privilege to restore and no more clients are | |
45 | * called. This callback is not called after @unregister has been called. | |
46 | * | |
64914da2 DV |
47 | * Note that the core does not guarantee exclusion against concurrent |
48 | * drm_open(). Clients need to ensure this themselves, for example by | |
49 | * using drm_master_internal_acquire() and | |
50 | * drm_master_internal_release(). | |
51 | * | |
c76f0f7c NT |
52 | * This callback is optional. |
53 | */ | |
54 | int (*restore)(struct drm_client_dev *client); | |
55 | ||
56 | /** | |
57 | * @hotplug: | |
58 | * | |
59 | * Called on drm_kms_helper_hotplug_event(). | |
60 | * This callback is not called after @unregister has been called. | |
61 | * | |
62 | * This callback is optional. | |
63 | */ | |
64 | int (*hotplug)(struct drm_client_dev *client); | |
65 | }; | |
66 | ||
67 | /** | |
68 | * struct drm_client_dev - DRM client instance | |
69 | */ | |
70 | struct drm_client_dev { | |
71 | /** | |
72 | * @dev: DRM device | |
73 | */ | |
74 | struct drm_device *dev; | |
75 | ||
76 | /** | |
77 | * @name: Name of the client. | |
78 | */ | |
79 | const char *name; | |
80 | ||
81 | /** | |
82 | * @list: | |
83 | * | |
84 | * List of all clients of a DRM device, linked into | |
85 | * &drm_device.clientlist. Protected by &drm_device.clientlist_mutex. | |
86 | */ | |
87 | struct list_head list; | |
88 | ||
89 | /** | |
90 | * @funcs: DRM client functions (optional) | |
91 | */ | |
92 | const struct drm_client_funcs *funcs; | |
93 | ||
94 | /** | |
95 | * @file: DRM file | |
96 | */ | |
97 | struct drm_file *file; | |
d81294af NT |
98 | |
99 | /** | |
100 | * @modeset_mutex: Protects @modesets. | |
101 | */ | |
102 | struct mutex modeset_mutex; | |
103 | ||
104 | /** | |
105 | * @modesets: CRTC configurations | |
106 | */ | |
107 | struct drm_mode_set *modesets; | |
c76f0f7c NT |
108 | }; |
109 | ||
4d4c2d89 NT |
110 | int drm_client_init(struct drm_device *dev, struct drm_client_dev *client, |
111 | const char *name, const struct drm_client_funcs *funcs); | |
c76f0f7c | 112 | void drm_client_release(struct drm_client_dev *client); |
e33898a2 | 113 | void drm_client_register(struct drm_client_dev *client); |
c76f0f7c NT |
114 | |
115 | void drm_client_dev_unregister(struct drm_device *dev); | |
116 | void drm_client_dev_hotplug(struct drm_device *dev); | |
117 | void drm_client_dev_restore(struct drm_device *dev); | |
118 | ||
119 | /** | |
120 | * struct drm_client_buffer - DRM client buffer | |
121 | */ | |
122 | struct drm_client_buffer { | |
123 | /** | |
124 | * @client: DRM client | |
125 | */ | |
126 | struct drm_client_dev *client; | |
127 | ||
128 | /** | |
129 | * @handle: Buffer handle | |
130 | */ | |
131 | u32 handle; | |
132 | ||
133 | /** | |
134 | * @pitch: Buffer pitch | |
135 | */ | |
136 | u32 pitch; | |
137 | ||
138 | /** | |
139 | * @gem: GEM object backing this buffer | |
140 | */ | |
141 | struct drm_gem_object *gem; | |
142 | ||
143 | /** | |
144 | * @vaddr: Virtual address for the buffer | |
145 | */ | |
146 | void *vaddr; | |
147 | ||
148 | /** | |
149 | * @fb: DRM framebuffer | |
150 | */ | |
151 | struct drm_framebuffer *fb; | |
152 | }; | |
153 | ||
154 | struct drm_client_buffer * | |
155 | drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format); | |
156 | void drm_client_framebuffer_delete(struct drm_client_buffer *buffer); | |
15dd0fc8 TZ |
157 | void *drm_client_buffer_vmap(struct drm_client_buffer *buffer); |
158 | void drm_client_buffer_vunmap(struct drm_client_buffer *buffer); | |
c76f0f7c | 159 | |
d81294af NT |
160 | int drm_client_modeset_create(struct drm_client_dev *client); |
161 | void drm_client_modeset_free(struct drm_client_dev *client); | |
cf13909a | 162 | int drm_client_modeset_probe(struct drm_client_dev *client, unsigned int width, unsigned int height); |
a99076e8 | 163 | bool drm_client_rotation(struct drm_mode_set *modeset, unsigned int *rotation); |
c368ec19 | 164 | int drm_client_modeset_commit_locked(struct drm_client_dev *client); |
aec3925f NT |
165 | int drm_client_modeset_commit(struct drm_client_dev *client); |
166 | int drm_client_modeset_dpms(struct drm_client_dev *client, int mode); | |
d81294af NT |
167 | |
168 | /** | |
169 | * drm_client_for_each_modeset() - Iterate over client modesets | |
170 | * @modeset: &drm_mode_set loop cursor | |
171 | * @client: DRM client | |
172 | */ | |
173 | #define drm_client_for_each_modeset(modeset, client) \ | |
174 | for (({ lockdep_assert_held(&(client)->modeset_mutex); }), \ | |
175 | modeset = (client)->modesets; modeset->crtc; modeset++) | |
176 | ||
e5852bee NT |
177 | /** |
178 | * drm_client_for_each_connector_iter - connector_list iterator macro | |
179 | * @connector: &struct drm_connector pointer used as cursor | |
180 | * @iter: &struct drm_connector_list_iter | |
181 | * | |
182 | * This iterates the connectors that are useable for internal clients (excludes | |
183 | * writeback connectors). | |
184 | * | |
185 | * For more info see drm_for_each_connector_iter(). | |
186 | */ | |
187 | #define drm_client_for_each_connector_iter(connector, iter) \ | |
188 | drm_for_each_connector_iter(connector, iter) \ | |
189 | if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK) | |
190 | ||
7ce84471 | 191 | void drm_client_debugfs_init(struct drm_minor *minor); |
e896c132 | 192 | |
c76f0f7c | 193 | #endif |