drm/fb-helper: Prepare to move out commit code
[linux-block.git] / include / drm / drm_client.h
CommitLineData
c76f0f7c
NT
1/* SPDX-License-Identifier: GPL-2.0 */
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
d81294af
NT
10#include <drm/drm_crtc.h>
11
c76f0f7c
NT
12struct drm_client_dev;
13struct drm_device;
14struct drm_file;
15struct drm_framebuffer;
16struct drm_gem_object;
e896c132 17struct drm_minor;
c76f0f7c
NT
18struct module;
19
d81294af
NT
20#define DRM_CLIENT_MAX_CLONED_CONNECTORS 8
21
c76f0f7c
NT
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
1e55a53a 35 * releasing its resources using drm_client_release().
c76f0f7c
NT
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 */
66struct 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;
d81294af
NT
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;
c76f0f7c
NT
104};
105
4d4c2d89
NT
106int drm_client_init(struct drm_device *dev, struct drm_client_dev *client,
107 const char *name, const struct drm_client_funcs *funcs);
c76f0f7c 108void drm_client_release(struct drm_client_dev *client);
e33898a2 109void drm_client_register(struct drm_client_dev *client);
c76f0f7c
NT
110
111void drm_client_dev_unregister(struct drm_device *dev);
112void drm_client_dev_hotplug(struct drm_device *dev);
113void drm_client_dev_restore(struct drm_device *dev);
114
115/**
116 * struct drm_client_buffer - DRM client buffer
117 */
118struct 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
150struct drm_client_buffer *
151drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format);
152void drm_client_framebuffer_delete(struct drm_client_buffer *buffer);
153
d81294af
NT
154int drm_client_modeset_create(struct drm_client_dev *client);
155void drm_client_modeset_free(struct drm_client_dev *client);
156void drm_client_modeset_release(struct drm_client_dev *client);
157struct 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
e896c132
NT
168int drm_client_debugfs_init(struct drm_minor *minor);
169
c76f0f7c 170#endif