xref: /openbmc/linux/include/drm/drm_writeback.h (revision a34a9f1a)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * (C) COPYRIGHT 2016 ARM Limited. All rights reserved.
4  * Author: Brian Starkey <brian.starkey@arm.com>
5  *
6  * This program is free software and is provided to you under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation, and any use by you of this program is subject to the terms
9  * of such GNU licence.
10  */
11 
12 #ifndef __DRM_WRITEBACK_H__
13 #define __DRM_WRITEBACK_H__
14 #include <drm/drm_connector.h>
15 #include <drm/drm_encoder.h>
16 #include <linux/workqueue.h>
17 
18 /**
19  * struct drm_writeback_connector - DRM writeback connector
20  */
21 struct drm_writeback_connector {
22 	/**
23 	 * @base: base drm_connector object
24 	 */
25 	struct drm_connector base;
26 
27 	/**
28 	 * @encoder: Internal encoder used by the connector to fulfill
29 	 * the DRM framework requirements. The users of the
30 	 * @drm_writeback_connector control the behaviour of the @encoder
31 	 * by passing the @enc_funcs parameter to drm_writeback_connector_init()
32 	 * function.
33 	 * For users of drm_writeback_connector_init_with_encoder(), this field
34 	 * is not valid as the encoder is managed within their drivers.
35 	 */
36 	struct drm_encoder encoder;
37 
38 	/**
39 	 * @pixel_formats_blob_ptr:
40 	 *
41 	 * DRM blob property data for the pixel formats list on writeback
42 	 * connectors
43 	 * See also drm_writeback_connector_init()
44 	 */
45 	struct drm_property_blob *pixel_formats_blob_ptr;
46 
47 	/** @job_lock: Protects job_queue */
48 	spinlock_t job_lock;
49 
50 	/**
51 	 * @job_queue:
52 	 *
53 	 * Holds a list of a connector's writeback jobs; the last item is the
54 	 * most recent. The first item may be either waiting for the hardware
55 	 * to begin writing, or currently being written.
56 	 *
57 	 * See also: drm_writeback_queue_job() and
58 	 * drm_writeback_signal_completion()
59 	 */
60 	struct list_head job_queue;
61 
62 	/**
63 	 * @fence_context:
64 	 *
65 	 * timeline context used for fence operations.
66 	 */
67 	unsigned int fence_context;
68 	/**
69 	 * @fence_lock:
70 	 *
71 	 * spinlock to protect the fences in the fence_context.
72 	 */
73 	spinlock_t fence_lock;
74 	/**
75 	 * @fence_seqno:
76 	 *
77 	 * Seqno variable used as monotonic counter for the fences
78 	 * created on the connector's timeline.
79 	 */
80 	unsigned long fence_seqno;
81 	/**
82 	 * @timeline_name:
83 	 *
84 	 * The name of the connector's fence timeline.
85 	 */
86 	char timeline_name[32];
87 };
88 
89 /**
90  * struct drm_writeback_job - DRM writeback job
91  */
92 struct drm_writeback_job {
93 	/**
94 	 * @connector:
95 	 *
96 	 * Back-pointer to the writeback connector associated with the job
97 	 */
98 	struct drm_writeback_connector *connector;
99 
100 	/**
101 	 * @prepared:
102 	 *
103 	 * Set when the job has been prepared with drm_writeback_prepare_job()
104 	 */
105 	bool prepared;
106 
107 	/**
108 	 * @cleanup_work:
109 	 *
110 	 * Used to allow drm_writeback_signal_completion to defer dropping the
111 	 * framebuffer reference to a workqueue
112 	 */
113 	struct work_struct cleanup_work;
114 
115 	/**
116 	 * @list_entry:
117 	 *
118 	 * List item for the writeback connector's @job_queue
119 	 */
120 	struct list_head list_entry;
121 
122 	/**
123 	 * @fb:
124 	 *
125 	 * Framebuffer to be written to by the writeback connector. Do not set
126 	 * directly, use drm_writeback_set_fb()
127 	 */
128 	struct drm_framebuffer *fb;
129 
130 	/**
131 	 * @out_fence:
132 	 *
133 	 * Fence which will signal once the writeback has completed
134 	 */
135 	struct dma_fence *out_fence;
136 
137 	/**
138 	 * @priv:
139 	 *
140 	 * Driver-private data
141 	 */
142 	void *priv;
143 };
144 
145 static inline struct drm_writeback_connector *
146 drm_connector_to_writeback(struct drm_connector *connector)
147 {
148 	return container_of(connector, struct drm_writeback_connector, base);
149 }
150 
151 int drm_writeback_connector_init(struct drm_device *dev,
152 				 struct drm_writeback_connector *wb_connector,
153 				 const struct drm_connector_funcs *con_funcs,
154 				 const struct drm_encoder_helper_funcs *enc_helper_funcs,
155 				 const u32 *formats, int n_formats,
156 				 u32 possible_crtcs);
157 
158 int drm_writeback_connector_init_with_encoder(struct drm_device *dev,
159 				struct drm_writeback_connector *wb_connector,
160 				struct drm_encoder *enc,
161 				const struct drm_connector_funcs *con_funcs, const u32 *formats,
162 				int n_formats);
163 
164 int drm_writeback_set_fb(struct drm_connector_state *conn_state,
165 			 struct drm_framebuffer *fb);
166 
167 int drm_writeback_prepare_job(struct drm_writeback_job *job);
168 
169 void drm_writeback_queue_job(struct drm_writeback_connector *wb_connector,
170 			     struct drm_connector_state *conn_state);
171 
172 void drm_writeback_cleanup_job(struct drm_writeback_job *job);
173 
174 void
175 drm_writeback_signal_completion(struct drm_writeback_connector *wb_connector,
176 				int status);
177 
178 struct dma_fence *
179 drm_writeback_get_out_fence(struct drm_writeback_connector *wb_connector);
180 #endif
181