xref: /openbmc/linux/include/drm/drm_client.h (revision c76f0f7c)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef _DRM_CLIENT_H_
4 #define _DRM_CLIENT_H_
5 
6 #include <linux/types.h>
7 
8 struct drm_client_dev;
9 struct drm_device;
10 struct drm_file;
11 struct drm_framebuffer;
12 struct drm_gem_object;
13 struct module;
14 
15 /**
16  * struct drm_client_funcs - DRM client callbacks
17  */
18 struct drm_client_funcs {
19 	/**
20 	 * @owner: The module owner
21 	 */
22 	struct module *owner;
23 
24 	/**
25 	 * @unregister:
26 	 *
27 	 * Called when &drm_device is unregistered. The client should respond by
28 	 * releasing it's resources using drm_client_release().
29 	 *
30 	 * This callback is optional.
31 	 */
32 	void (*unregister)(struct drm_client_dev *client);
33 
34 	/**
35 	 * @restore:
36 	 *
37 	 * Called on drm_lastclose(). The first client instance in the list that
38 	 * returns zero gets the privilege to restore and no more clients are
39 	 * called. This callback is not called after @unregister has been called.
40 	 *
41 	 * This callback is optional.
42 	 */
43 	int (*restore)(struct drm_client_dev *client);
44 
45 	/**
46 	 * @hotplug:
47 	 *
48 	 * Called on drm_kms_helper_hotplug_event().
49 	 * This callback is not called after @unregister has been called.
50 	 *
51 	 * This callback is optional.
52 	 */
53 	int (*hotplug)(struct drm_client_dev *client);
54 };
55 
56 /**
57  * struct drm_client_dev - DRM client instance
58  */
59 struct drm_client_dev {
60 	/**
61 	 * @dev: DRM device
62 	 */
63 	struct drm_device *dev;
64 
65 	/**
66 	 * @name: Name of the client.
67 	 */
68 	const char *name;
69 
70 	/**
71 	 * @list:
72 	 *
73 	 * List of all clients of a DRM device, linked into
74 	 * &drm_device.clientlist. Protected by &drm_device.clientlist_mutex.
75 	 */
76 	struct list_head list;
77 
78 	/**
79 	 * @funcs: DRM client functions (optional)
80 	 */
81 	const struct drm_client_funcs *funcs;
82 
83 	/**
84 	 * @file: DRM file
85 	 */
86 	struct drm_file *file;
87 };
88 
89 int drm_client_new(struct drm_device *dev, struct drm_client_dev *client,
90 		   const char *name, const struct drm_client_funcs *funcs);
91 void drm_client_release(struct drm_client_dev *client);
92 
93 void drm_client_dev_unregister(struct drm_device *dev);
94 void drm_client_dev_hotplug(struct drm_device *dev);
95 void drm_client_dev_restore(struct drm_device *dev);
96 
97 /**
98  * struct drm_client_buffer - DRM client buffer
99  */
100 struct drm_client_buffer {
101 	/**
102 	 * @client: DRM client
103 	 */
104 	struct drm_client_dev *client;
105 
106 	/**
107 	 * @handle: Buffer handle
108 	 */
109 	u32 handle;
110 
111 	/**
112 	 * @pitch: Buffer pitch
113 	 */
114 	u32 pitch;
115 
116 	/**
117 	 * @gem: GEM object backing this buffer
118 	 */
119 	struct drm_gem_object *gem;
120 
121 	/**
122 	 * @vaddr: Virtual address for the buffer
123 	 */
124 	void *vaddr;
125 
126 	/**
127 	 * @fb: DRM framebuffer
128 	 */
129 	struct drm_framebuffer *fb;
130 };
131 
132 struct drm_client_buffer *
133 drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format);
134 void drm_client_framebuffer_delete(struct drm_client_buffer *buffer);
135 
136 #endif
137