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