Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 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 | |
Sam Ravnborg | e2d7fc2 | 2020-04-06 21:47:46 +0200 | [diff] [blame] | 18 | /** |
| 19 | * struct drm_writeback_connector - DRM writeback connector |
| 20 | */ |
Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 21 | struct drm_writeback_connector { |
Sam Ravnborg | e2d7fc2 | 2020-04-06 21:47:46 +0200 | [diff] [blame] | 22 | /** |
| 23 | * @base: base drm_connector object |
| 24 | */ |
Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 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 | */ |
| 34 | struct drm_encoder encoder; |
| 35 | |
| 36 | /** |
| 37 | * @pixel_formats_blob_ptr: |
| 38 | * |
| 39 | * DRM blob property data for the pixel formats list on writeback |
| 40 | * connectors |
| 41 | * See also drm_writeback_connector_init() |
| 42 | */ |
| 43 | struct drm_property_blob *pixel_formats_blob_ptr; |
| 44 | |
| 45 | /** @job_lock: Protects job_queue */ |
| 46 | spinlock_t job_lock; |
| 47 | |
| 48 | /** |
| 49 | * @job_queue: |
| 50 | * |
| 51 | * Holds a list of a connector's writeback jobs; the last item is the |
| 52 | * most recent. The first item may be either waiting for the hardware |
| 53 | * to begin writing, or currently being written. |
| 54 | * |
| 55 | * See also: drm_writeback_queue_job() and |
| 56 | * drm_writeback_signal_completion() |
| 57 | */ |
| 58 | struct list_head job_queue; |
Brian Starkey | b13cc8d | 2017-03-29 17:42:33 +0100 | [diff] [blame] | 59 | |
| 60 | /** |
| 61 | * @fence_context: |
| 62 | * |
| 63 | * timeline context used for fence operations. |
| 64 | */ |
| 65 | unsigned int fence_context; |
| 66 | /** |
| 67 | * @fence_lock: |
| 68 | * |
| 69 | * spinlock to protect the fences in the fence_context. |
| 70 | */ |
| 71 | spinlock_t fence_lock; |
| 72 | /** |
| 73 | * @fence_seqno: |
| 74 | * |
| 75 | * Seqno variable used as monotonic counter for the fences |
| 76 | * created on the connector's timeline. |
| 77 | */ |
| 78 | unsigned long fence_seqno; |
| 79 | /** |
| 80 | * @timeline_name: |
| 81 | * |
| 82 | * The name of the connector's fence timeline. |
| 83 | */ |
| 84 | char timeline_name[32]; |
Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 85 | }; |
| 86 | |
Sam Ravnborg | e2d7fc2 | 2020-04-06 21:47:46 +0200 | [diff] [blame] | 87 | /** |
| 88 | * struct drm_writeback_job - DRM writeback job |
| 89 | */ |
Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 90 | struct drm_writeback_job { |
| 91 | /** |
Laurent Pinchart | 9d2230d | 2019-02-21 03:01:38 +0200 | [diff] [blame] | 92 | * @connector: |
| 93 | * |
| 94 | * Back-pointer to the writeback connector associated with the job |
| 95 | */ |
| 96 | struct drm_writeback_connector *connector; |
| 97 | |
| 98 | /** |
| 99 | * @prepared: |
| 100 | * |
| 101 | * Set when the job has been prepared with drm_writeback_prepare_job() |
| 102 | */ |
| 103 | bool prepared; |
| 104 | |
| 105 | /** |
Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 106 | * @cleanup_work: |
| 107 | * |
| 108 | * Used to allow drm_writeback_signal_completion to defer dropping the |
| 109 | * framebuffer reference to a workqueue |
| 110 | */ |
| 111 | struct work_struct cleanup_work; |
| 112 | |
| 113 | /** |
| 114 | * @list_entry: |
| 115 | * |
| 116 | * List item for the writeback connector's @job_queue |
| 117 | */ |
| 118 | struct list_head list_entry; |
| 119 | |
| 120 | /** |
| 121 | * @fb: |
| 122 | * |
| 123 | * Framebuffer to be written to by the writeback connector. Do not set |
Laurent Pinchart | 9d2230d | 2019-02-21 03:01:38 +0200 | [diff] [blame] | 124 | * directly, use drm_writeback_set_fb() |
Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 125 | */ |
| 126 | struct drm_framebuffer *fb; |
Brian Starkey | b13cc8d | 2017-03-29 17:42:33 +0100 | [diff] [blame] | 127 | |
| 128 | /** |
| 129 | * @out_fence: |
| 130 | * |
| 131 | * Fence which will signal once the writeback has completed |
| 132 | */ |
| 133 | struct dma_fence *out_fence; |
Laurent Pinchart | 9d2230d | 2019-02-21 03:01:38 +0200 | [diff] [blame] | 134 | |
| 135 | /** |
| 136 | * @priv: |
| 137 | * |
| 138 | * Driver-private data |
| 139 | */ |
| 140 | void *priv; |
Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 141 | }; |
| 142 | |
Boris Brezillon | b82c1f8 | 2018-07-03 09:50:15 +0200 | [diff] [blame] | 143 | static inline struct drm_writeback_connector * |
| 144 | drm_connector_to_writeback(struct drm_connector *connector) |
| 145 | { |
| 146 | return container_of(connector, struct drm_writeback_connector, base); |
| 147 | } |
| 148 | |
Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 149 | int drm_writeback_connector_init(struct drm_device *dev, |
| 150 | struct drm_writeback_connector *wb_connector, |
| 151 | const struct drm_connector_funcs *con_funcs, |
| 152 | const struct drm_encoder_helper_funcs *enc_helper_funcs, |
| 153 | const u32 *formats, int n_formats); |
| 154 | |
Laurent Pinchart | 9d2230d | 2019-02-21 03:01:38 +0200 | [diff] [blame] | 155 | int drm_writeback_set_fb(struct drm_connector_state *conn_state, |
| 156 | struct drm_framebuffer *fb); |
| 157 | |
| 158 | int drm_writeback_prepare_job(struct drm_writeback_job *job); |
| 159 | |
Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 160 | void drm_writeback_queue_job(struct drm_writeback_connector *wb_connector, |
Laurent Pinchart | 97eb9ea | 2019-02-21 12:17:32 +0200 | [diff] [blame] | 161 | struct drm_connector_state *conn_state); |
Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 162 | |
| 163 | void drm_writeback_cleanup_job(struct drm_writeback_job *job); |
Brian Starkey | b13cc8d | 2017-03-29 17:42:33 +0100 | [diff] [blame] | 164 | |
| 165 | void |
| 166 | drm_writeback_signal_completion(struct drm_writeback_connector *wb_connector, |
| 167 | int status); |
| 168 | |
| 169 | struct dma_fence * |
| 170 | drm_writeback_get_out_fence(struct drm_writeback_connector *wb_connector); |
Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 171 | #endif |