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