blob: 777c14c847f03f85f5a0aa57864ef7037c5a26c3 [file] [log] [blame]
Brian Starkey935774c2017-03-29 17:42:32 +01001/* 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
18struct drm_writeback_connector {
19 struct drm_connector base;
20
21 /**
22 * @encoder: Internal encoder used by the connector to fulfill
23 * the DRM framework requirements. The users of the
24 * @drm_writeback_connector control the behaviour of the @encoder
25 * by passing the @enc_funcs parameter to drm_writeback_connector_init()
26 * function.
27 */
28 struct drm_encoder encoder;
29
30 /**
31 * @pixel_formats_blob_ptr:
32 *
33 * DRM blob property data for the pixel formats list on writeback
34 * connectors
35 * See also drm_writeback_connector_init()
36 */
37 struct drm_property_blob *pixel_formats_blob_ptr;
38
39 /** @job_lock: Protects job_queue */
40 spinlock_t job_lock;
41
42 /**
43 * @job_queue:
44 *
45 * Holds a list of a connector's writeback jobs; the last item is the
46 * most recent. The first item may be either waiting for the hardware
47 * to begin writing, or currently being written.
48 *
49 * See also: drm_writeback_queue_job() and
50 * drm_writeback_signal_completion()
51 */
52 struct list_head job_queue;
Brian Starkeyb13cc8d2017-03-29 17:42:33 +010053
54 /**
55 * @fence_context:
56 *
57 * timeline context used for fence operations.
58 */
59 unsigned int fence_context;
60 /**
61 * @fence_lock:
62 *
63 * spinlock to protect the fences in the fence_context.
64 */
65 spinlock_t fence_lock;
66 /**
67 * @fence_seqno:
68 *
69 * Seqno variable used as monotonic counter for the fences
70 * created on the connector's timeline.
71 */
72 unsigned long fence_seqno;
73 /**
74 * @timeline_name:
75 *
76 * The name of the connector's fence timeline.
77 */
78 char timeline_name[32];
Brian Starkey935774c2017-03-29 17:42:32 +010079};
80
81struct drm_writeback_job {
82 /**
Laurent Pinchart9d2230d2019-02-21 03:01:38 +020083 * @connector:
84 *
85 * Back-pointer to the writeback connector associated with the job
86 */
87 struct drm_writeback_connector *connector;
88
89 /**
90 * @prepared:
91 *
92 * Set when the job has been prepared with drm_writeback_prepare_job()
93 */
94 bool prepared;
95
96 /**
Brian Starkey935774c2017-03-29 17:42:32 +010097 * @cleanup_work:
98 *
99 * Used to allow drm_writeback_signal_completion to defer dropping the
100 * framebuffer reference to a workqueue
101 */
102 struct work_struct cleanup_work;
103
104 /**
105 * @list_entry:
106 *
107 * List item for the writeback connector's @job_queue
108 */
109 struct list_head list_entry;
110
111 /**
112 * @fb:
113 *
114 * Framebuffer to be written to by the writeback connector. Do not set
Laurent Pinchart9d2230d2019-02-21 03:01:38 +0200115 * directly, use drm_writeback_set_fb()
Brian Starkey935774c2017-03-29 17:42:32 +0100116 */
117 struct drm_framebuffer *fb;
Brian Starkeyb13cc8d2017-03-29 17:42:33 +0100118
119 /**
120 * @out_fence:
121 *
122 * Fence which will signal once the writeback has completed
123 */
124 struct dma_fence *out_fence;
Laurent Pinchart9d2230d2019-02-21 03:01:38 +0200125
126 /**
127 * @priv:
128 *
129 * Driver-private data
130 */
131 void *priv;
Brian Starkey935774c2017-03-29 17:42:32 +0100132};
133
Boris Brezillonb82c1f82018-07-03 09:50:15 +0200134static inline struct drm_writeback_connector *
135drm_connector_to_writeback(struct drm_connector *connector)
136{
137 return container_of(connector, struct drm_writeback_connector, base);
138}
139
Brian Starkey935774c2017-03-29 17:42:32 +0100140int drm_writeback_connector_init(struct drm_device *dev,
141 struct drm_writeback_connector *wb_connector,
142 const struct drm_connector_funcs *con_funcs,
143 const struct drm_encoder_helper_funcs *enc_helper_funcs,
144 const u32 *formats, int n_formats);
145
Laurent Pinchart9d2230d2019-02-21 03:01:38 +0200146int drm_writeback_set_fb(struct drm_connector_state *conn_state,
147 struct drm_framebuffer *fb);
148
149int drm_writeback_prepare_job(struct drm_writeback_job *job);
150
Brian Starkey935774c2017-03-29 17:42:32 +0100151void drm_writeback_queue_job(struct drm_writeback_connector *wb_connector,
Laurent Pinchart97eb9ea2019-02-21 12:17:32 +0200152 struct drm_connector_state *conn_state);
Brian Starkey935774c2017-03-29 17:42:32 +0100153
154void drm_writeback_cleanup_job(struct drm_writeback_job *job);
Brian Starkeyb13cc8d2017-03-29 17:42:33 +0100155
156void
157drm_writeback_signal_completion(struct drm_writeback_connector *wb_connector,
158 int status);
159
160struct dma_fence *
161drm_writeback_get_out_fence(struct drm_writeback_connector *wb_connector);
Brian Starkey935774c2017-03-29 17:42:32 +0100162#endif