xref: /openbmc/linux/include/drm/drm_client.h (revision ae213c44)
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_crtc.h>
11 
12 struct drm_client_dev;
13 struct drm_device;
14 struct drm_file;
15 struct drm_framebuffer;
16 struct drm_gem_object;
17 struct drm_minor;
18 struct module;
19 
20 #define DRM_CLIENT_MAX_CLONED_CONNECTORS	8
21 
22 /**
23  * struct drm_client_funcs - DRM client callbacks
24  */
25 struct 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 	 * This callback is optional.
49 	 */
50 	int (*restore)(struct drm_client_dev *client);
51 
52 	/**
53 	 * @hotplug:
54 	 *
55 	 * Called on drm_kms_helper_hotplug_event().
56 	 * This callback is not called after @unregister has been called.
57 	 *
58 	 * This callback is optional.
59 	 */
60 	int (*hotplug)(struct drm_client_dev *client);
61 };
62 
63 /**
64  * struct drm_client_dev - DRM client instance
65  */
66 struct drm_client_dev {
67 	/**
68 	 * @dev: DRM device
69 	 */
70 	struct drm_device *dev;
71 
72 	/**
73 	 * @name: Name of the client.
74 	 */
75 	const char *name;
76 
77 	/**
78 	 * @list:
79 	 *
80 	 * List of all clients of a DRM device, linked into
81 	 * &drm_device.clientlist. Protected by &drm_device.clientlist_mutex.
82 	 */
83 	struct list_head list;
84 
85 	/**
86 	 * @funcs: DRM client functions (optional)
87 	 */
88 	const struct drm_client_funcs *funcs;
89 
90 	/**
91 	 * @file: DRM file
92 	 */
93 	struct drm_file *file;
94 
95 	/**
96 	 * @modeset_mutex: Protects @modesets.
97 	 */
98 	struct mutex modeset_mutex;
99 
100 	/**
101 	 * @modesets: CRTC configurations
102 	 */
103 	struct drm_mode_set *modesets;
104 };
105 
106 int drm_client_init(struct drm_device *dev, struct drm_client_dev *client,
107 		    const char *name, const struct drm_client_funcs *funcs);
108 void drm_client_release(struct drm_client_dev *client);
109 void drm_client_register(struct drm_client_dev *client);
110 
111 void drm_client_dev_unregister(struct drm_device *dev);
112 void drm_client_dev_hotplug(struct drm_device *dev);
113 void drm_client_dev_restore(struct drm_device *dev);
114 
115 /**
116  * struct drm_client_buffer - DRM client buffer
117  */
118 struct drm_client_buffer {
119 	/**
120 	 * @client: DRM client
121 	 */
122 	struct drm_client_dev *client;
123 
124 	/**
125 	 * @handle: Buffer handle
126 	 */
127 	u32 handle;
128 
129 	/**
130 	 * @pitch: Buffer pitch
131 	 */
132 	u32 pitch;
133 
134 	/**
135 	 * @gem: GEM object backing this buffer
136 	 */
137 	struct drm_gem_object *gem;
138 
139 	/**
140 	 * @vaddr: Virtual address for the buffer
141 	 */
142 	void *vaddr;
143 
144 	/**
145 	 * @fb: DRM framebuffer
146 	 */
147 	struct drm_framebuffer *fb;
148 };
149 
150 struct drm_client_buffer *
151 drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format);
152 void drm_client_framebuffer_delete(struct drm_client_buffer *buffer);
153 
154 int drm_client_modeset_create(struct drm_client_dev *client);
155 void drm_client_modeset_free(struct drm_client_dev *client);
156 void drm_client_modeset_release(struct drm_client_dev *client);
157 struct drm_mode_set *drm_client_find_modeset(struct drm_client_dev *client, struct drm_crtc *crtc);
158 
159 /**
160  * drm_client_for_each_modeset() - Iterate over client modesets
161  * @modeset: &drm_mode_set loop cursor
162  * @client: DRM client
163  */
164 #define drm_client_for_each_modeset(modeset, client) \
165 	for (({ lockdep_assert_held(&(client)->modeset_mutex); }), \
166 	     modeset = (client)->modesets; modeset->crtc; modeset++)
167 
168 int drm_client_debugfs_init(struct drm_minor *minor);
169 
170 #endif
171