Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 Broadcom |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | */ |
| 8 | |
| 9 | #include "drmP.h" |
| 10 | #include "drm_gem_cma_helper.h" |
Eric Anholt | cdec4d3 | 2017-04-12 12:12:02 -0700 | [diff] [blame] | 11 | #include "drm_gem_cma_helper.h" |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 12 | |
Eric Anholt | cdec4d3 | 2017-04-12 12:12:02 -0700 | [diff] [blame] | 13 | #include <linux/reservation.h> |
Laurent Pinchart | 9338203 | 2016-11-28 20:51:09 +0200 | [diff] [blame] | 14 | #include <drm/drm_encoder.h> |
| 15 | |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 16 | struct vc4_dev { |
| 17 | struct drm_device *dev; |
| 18 | |
| 19 | struct vc4_hdmi *hdmi; |
| 20 | struct vc4_hvs *hvs; |
Eric Anholt | d3f5168 | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 21 | struct vc4_v3d *v3d; |
Eric Anholt | 08302c3 | 2016-02-10 11:42:32 -0800 | [diff] [blame] | 22 | struct vc4_dpi *dpi; |
Eric Anholt | 4078f57 | 2017-01-31 11:29:11 -0800 | [diff] [blame] | 23 | struct vc4_dsi *dsi1; |
Boris Brezillon | e4b81f8 | 2016-12-02 14:48:10 +0100 | [diff] [blame] | 24 | struct vc4_vec *vec; |
Derek Foreman | 48666d5 | 2015-07-02 11:19:54 -0500 | [diff] [blame] | 25 | |
| 26 | struct drm_fbdev_cma *fbdev; |
Eric Anholt | c826a6e | 2015-10-09 20:25:07 -0700 | [diff] [blame] | 27 | |
Eric Anholt | 2146136 | 2015-10-30 10:09:02 -0700 | [diff] [blame] | 28 | struct vc4_hang_state *hang_state; |
| 29 | |
Eric Anholt | c826a6e | 2015-10-09 20:25:07 -0700 | [diff] [blame] | 30 | /* The kernel-space BO cache. Tracks buffers that have been |
| 31 | * unreferenced by all other users (refcounts of 0!) but not |
| 32 | * yet freed, so we can do cheap allocations. |
| 33 | */ |
| 34 | struct vc4_bo_cache { |
| 35 | /* Array of list heads for entries in the BO cache, |
| 36 | * based on number of pages, so we can do O(1) lookups |
| 37 | * in the cache when allocating. |
| 38 | */ |
| 39 | struct list_head *size_list; |
| 40 | uint32_t size_list_size; |
| 41 | |
| 42 | /* List of all BOs in the cache, ordered by age, so we |
| 43 | * can do O(1) lookups when trying to free old |
| 44 | * buffers. |
| 45 | */ |
| 46 | struct list_head time_list; |
| 47 | struct work_struct time_work; |
| 48 | struct timer_list time_timer; |
| 49 | } bo_cache; |
| 50 | |
| 51 | struct vc4_bo_stats { |
| 52 | u32 num_allocated; |
| 53 | u32 size_allocated; |
| 54 | u32 num_cached; |
| 55 | u32 size_cached; |
| 56 | } bo_stats; |
| 57 | |
| 58 | /* Protects bo_cache and the BO stats. */ |
| 59 | struct mutex bo_lock; |
Eric Anholt | d5b1a78 | 2015-11-30 12:13:37 -0800 | [diff] [blame] | 60 | |
Eric Anholt | cdec4d3 | 2017-04-12 12:12:02 -0700 | [diff] [blame] | 61 | uint64_t dma_fence_context; |
| 62 | |
Varad Gautam | ca26d28 | 2016-02-17 19:08:21 +0530 | [diff] [blame] | 63 | /* Sequence number for the last job queued in bin_job_list. |
Eric Anholt | d5b1a78 | 2015-11-30 12:13:37 -0800 | [diff] [blame] | 64 | * Starts at 0 (no jobs emitted). |
| 65 | */ |
| 66 | uint64_t emit_seqno; |
| 67 | |
| 68 | /* Sequence number for the last completed job on the GPU. |
| 69 | * Starts at 0 (no jobs completed). |
| 70 | */ |
| 71 | uint64_t finished_seqno; |
| 72 | |
Varad Gautam | ca26d28 | 2016-02-17 19:08:21 +0530 | [diff] [blame] | 73 | /* List of all struct vc4_exec_info for jobs to be executed in |
| 74 | * the binner. The first job in the list is the one currently |
| 75 | * programmed into ct0ca for execution. |
Eric Anholt | d5b1a78 | 2015-11-30 12:13:37 -0800 | [diff] [blame] | 76 | */ |
Varad Gautam | ca26d28 | 2016-02-17 19:08:21 +0530 | [diff] [blame] | 77 | struct list_head bin_job_list; |
| 78 | |
| 79 | /* List of all struct vc4_exec_info for jobs that have |
| 80 | * completed binning and are ready for rendering. The first |
| 81 | * job in the list is the one currently programmed into ct1ca |
| 82 | * for execution. |
| 83 | */ |
| 84 | struct list_head render_job_list; |
| 85 | |
Eric Anholt | d5b1a78 | 2015-11-30 12:13:37 -0800 | [diff] [blame] | 86 | /* List of the finished vc4_exec_infos waiting to be freed by |
| 87 | * job_done_work. |
| 88 | */ |
| 89 | struct list_head job_done_list; |
| 90 | /* Spinlock used to synchronize the job_list and seqno |
| 91 | * accesses between the IRQ handler and GEM ioctls. |
| 92 | */ |
| 93 | spinlock_t job_lock; |
| 94 | wait_queue_head_t job_wait_queue; |
| 95 | struct work_struct job_done_work; |
| 96 | |
Eric Anholt | b501bac | 2015-11-30 12:34:01 -0800 | [diff] [blame] | 97 | /* List of struct vc4_seqno_cb for callbacks to be made from a |
| 98 | * workqueue when the given seqno is passed. |
| 99 | */ |
| 100 | struct list_head seqno_cb_list; |
| 101 | |
Eric Anholt | 553c942 | 2017-03-27 16:10:25 -0700 | [diff] [blame^] | 102 | /* The memory used for storing binner tile alloc, tile state, |
| 103 | * and overflow memory allocations. This is freed when V3D |
| 104 | * powers down. |
Eric Anholt | d5b1a78 | 2015-11-30 12:13:37 -0800 | [diff] [blame] | 105 | */ |
Eric Anholt | 553c942 | 2017-03-27 16:10:25 -0700 | [diff] [blame^] | 106 | struct vc4_bo *bin_bo; |
| 107 | |
| 108 | /* Size of blocks allocated within bin_bo. */ |
| 109 | uint32_t bin_alloc_size; |
| 110 | |
| 111 | /* Bitmask of the bin_alloc_size chunks in bin_bo that are |
| 112 | * used. |
| 113 | */ |
| 114 | uint32_t bin_alloc_used; |
| 115 | |
| 116 | /* Bitmask of the current bin_alloc used for overflow memory. */ |
| 117 | uint32_t bin_alloc_overflow; |
| 118 | |
Eric Anholt | d5b1a78 | 2015-11-30 12:13:37 -0800 | [diff] [blame] | 119 | struct work_struct overflow_mem_work; |
| 120 | |
Eric Anholt | 36cb625 | 2016-02-08 12:59:02 -0800 | [diff] [blame] | 121 | int power_refcount; |
| 122 | |
| 123 | /* Mutex controlling the power refcount. */ |
| 124 | struct mutex power_lock; |
| 125 | |
Eric Anholt | d5b1a78 | 2015-11-30 12:13:37 -0800 | [diff] [blame] | 126 | struct { |
Eric Anholt | d5b1a78 | 2015-11-30 12:13:37 -0800 | [diff] [blame] | 127 | struct timer_list timer; |
| 128 | struct work_struct reset_work; |
| 129 | } hangcheck; |
| 130 | |
| 131 | struct semaphore async_modeset; |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | static inline struct vc4_dev * |
| 135 | to_vc4_dev(struct drm_device *dev) |
| 136 | { |
| 137 | return (struct vc4_dev *)dev->dev_private; |
| 138 | } |
| 139 | |
| 140 | struct vc4_bo { |
| 141 | struct drm_gem_cma_object base; |
Eric Anholt | c826a6e | 2015-10-09 20:25:07 -0700 | [diff] [blame] | 142 | |
Eric Anholt | 7edabee | 2016-09-27 09:03:13 -0700 | [diff] [blame] | 143 | /* seqno of the last job to render using this BO. */ |
Eric Anholt | d5b1a78 | 2015-11-30 12:13:37 -0800 | [diff] [blame] | 144 | uint64_t seqno; |
| 145 | |
Eric Anholt | 7edabee | 2016-09-27 09:03:13 -0700 | [diff] [blame] | 146 | /* seqno of the last job to use the RCL to write to this BO. |
| 147 | * |
| 148 | * Note that this doesn't include binner overflow memory |
| 149 | * writes. |
| 150 | */ |
| 151 | uint64_t write_seqno; |
| 152 | |
Eric Anholt | c826a6e | 2015-10-09 20:25:07 -0700 | [diff] [blame] | 153 | /* List entry for the BO's position in either |
| 154 | * vc4_exec_info->unref_list or vc4_dev->bo_cache.time_list |
| 155 | */ |
| 156 | struct list_head unref_head; |
| 157 | |
| 158 | /* Time in jiffies when the BO was put in vc4->bo_cache. */ |
| 159 | unsigned long free_time; |
| 160 | |
| 161 | /* List entry for the BO's position in vc4_dev->bo_cache.size_list */ |
| 162 | struct list_head size_head; |
Eric Anholt | 463873d | 2015-11-30 11:41:40 -0800 | [diff] [blame] | 163 | |
| 164 | /* Struct for shader validation state, if created by |
| 165 | * DRM_IOCTL_VC4_CREATE_SHADER_BO. |
| 166 | */ |
| 167 | struct vc4_validated_shader_info *validated_shader; |
Eric Anholt | cdec4d3 | 2017-04-12 12:12:02 -0700 | [diff] [blame] | 168 | |
| 169 | /* normally (resv == &_resv) except for imported bo's */ |
| 170 | struct reservation_object *resv; |
| 171 | struct reservation_object _resv; |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 172 | }; |
| 173 | |
| 174 | static inline struct vc4_bo * |
| 175 | to_vc4_bo(struct drm_gem_object *bo) |
| 176 | { |
| 177 | return (struct vc4_bo *)bo; |
| 178 | } |
| 179 | |
Eric Anholt | cdec4d3 | 2017-04-12 12:12:02 -0700 | [diff] [blame] | 180 | struct vc4_fence { |
| 181 | struct dma_fence base; |
| 182 | struct drm_device *dev; |
| 183 | /* vc4 seqno for signaled() test */ |
| 184 | uint64_t seqno; |
| 185 | }; |
| 186 | |
| 187 | static inline struct vc4_fence * |
| 188 | to_vc4_fence(struct dma_fence *fence) |
| 189 | { |
| 190 | return (struct vc4_fence *)fence; |
| 191 | } |
| 192 | |
Eric Anholt | b501bac | 2015-11-30 12:34:01 -0800 | [diff] [blame] | 193 | struct vc4_seqno_cb { |
| 194 | struct work_struct work; |
| 195 | uint64_t seqno; |
| 196 | void (*func)(struct vc4_seqno_cb *cb); |
| 197 | }; |
| 198 | |
Eric Anholt | d3f5168 | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 199 | struct vc4_v3d { |
Eric Anholt | 001bdb5 | 2016-02-05 17:41:49 -0800 | [diff] [blame] | 200 | struct vc4_dev *vc4; |
Eric Anholt | d3f5168 | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 201 | struct platform_device *pdev; |
| 202 | void __iomem *regs; |
| 203 | }; |
| 204 | |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 205 | struct vc4_hvs { |
| 206 | struct platform_device *pdev; |
| 207 | void __iomem *regs; |
Eric Anholt | d8dbf44 | 2015-12-28 13:25:41 -0800 | [diff] [blame] | 208 | u32 __iomem *dlist; |
| 209 | |
| 210 | /* Memory manager for CRTCs to allocate space in the display |
| 211 | * list. Units are dwords. |
| 212 | */ |
| 213 | struct drm_mm dlist_mm; |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 214 | /* Memory manager for the LBM memory used by HVS scaling. */ |
| 215 | struct drm_mm lbm_mm; |
Eric Anholt | d8dbf44 | 2015-12-28 13:25:41 -0800 | [diff] [blame] | 216 | spinlock_t mm_lock; |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 217 | |
| 218 | struct drm_mm_node mitchell_netravali_filter; |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 219 | }; |
| 220 | |
| 221 | struct vc4_plane { |
| 222 | struct drm_plane base; |
| 223 | }; |
| 224 | |
| 225 | static inline struct vc4_plane * |
| 226 | to_vc4_plane(struct drm_plane *plane) |
| 227 | { |
| 228 | return (struct vc4_plane *)plane; |
| 229 | } |
| 230 | |
| 231 | enum vc4_encoder_type { |
Boris Brezillon | ab8df60 | 2016-12-02 14:48:07 +0100 | [diff] [blame] | 232 | VC4_ENCODER_TYPE_NONE, |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 233 | VC4_ENCODER_TYPE_HDMI, |
| 234 | VC4_ENCODER_TYPE_VEC, |
| 235 | VC4_ENCODER_TYPE_DSI0, |
| 236 | VC4_ENCODER_TYPE_DSI1, |
| 237 | VC4_ENCODER_TYPE_SMI, |
| 238 | VC4_ENCODER_TYPE_DPI, |
| 239 | }; |
| 240 | |
| 241 | struct vc4_encoder { |
| 242 | struct drm_encoder base; |
| 243 | enum vc4_encoder_type type; |
| 244 | u32 clock_select; |
| 245 | }; |
| 246 | |
| 247 | static inline struct vc4_encoder * |
| 248 | to_vc4_encoder(struct drm_encoder *encoder) |
| 249 | { |
| 250 | return container_of(encoder, struct vc4_encoder, base); |
| 251 | } |
| 252 | |
Eric Anholt | d3f5168 | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 253 | #define V3D_READ(offset) readl(vc4->v3d->regs + offset) |
| 254 | #define V3D_WRITE(offset, val) writel(val, vc4->v3d->regs + offset) |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 255 | #define HVS_READ(offset) readl(vc4->hvs->regs + offset) |
| 256 | #define HVS_WRITE(offset, val) writel(val, vc4->hvs->regs + offset) |
| 257 | |
Eric Anholt | d5b1a78 | 2015-11-30 12:13:37 -0800 | [diff] [blame] | 258 | struct vc4_exec_info { |
| 259 | /* Sequence number for this bin/render job. */ |
| 260 | uint64_t seqno; |
| 261 | |
Eric Anholt | 7edabee | 2016-09-27 09:03:13 -0700 | [diff] [blame] | 262 | /* Latest write_seqno of any BO that binning depends on. */ |
| 263 | uint64_t bin_dep_seqno; |
| 264 | |
Eric Anholt | cdec4d3 | 2017-04-12 12:12:02 -0700 | [diff] [blame] | 265 | struct dma_fence *fence; |
| 266 | |
Eric Anholt | c4ce60d | 2016-02-08 11:19:14 -0800 | [diff] [blame] | 267 | /* Last current addresses the hardware was processing when the |
| 268 | * hangcheck timer checked on us. |
| 269 | */ |
| 270 | uint32_t last_ct0ca, last_ct1ca; |
| 271 | |
Eric Anholt | d5b1a78 | 2015-11-30 12:13:37 -0800 | [diff] [blame] | 272 | /* Kernel-space copy of the ioctl arguments */ |
| 273 | struct drm_vc4_submit_cl *args; |
| 274 | |
| 275 | /* This is the array of BOs that were looked up at the start of exec. |
| 276 | * Command validation will use indices into this array. |
| 277 | */ |
| 278 | struct drm_gem_cma_object **bo; |
| 279 | uint32_t bo_count; |
| 280 | |
Eric Anholt | 7edabee | 2016-09-27 09:03:13 -0700 | [diff] [blame] | 281 | /* List of BOs that are being written by the RCL. Other than |
| 282 | * the binner temporary storage, this is all the BOs written |
| 283 | * by the job. |
| 284 | */ |
| 285 | struct drm_gem_cma_object *rcl_write_bo[4]; |
| 286 | uint32_t rcl_write_bo_count; |
| 287 | |
Eric Anholt | d5b1a78 | 2015-11-30 12:13:37 -0800 | [diff] [blame] | 288 | /* Pointers for our position in vc4->job_list */ |
| 289 | struct list_head head; |
| 290 | |
| 291 | /* List of other BOs used in the job that need to be released |
| 292 | * once the job is complete. |
| 293 | */ |
| 294 | struct list_head unref_list; |
| 295 | |
| 296 | /* Current unvalidated indices into @bo loaded by the non-hardware |
| 297 | * VC4_PACKET_GEM_HANDLES. |
| 298 | */ |
| 299 | uint32_t bo_index[2]; |
| 300 | |
| 301 | /* This is the BO where we store the validated command lists, shader |
| 302 | * records, and uniforms. |
| 303 | */ |
| 304 | struct drm_gem_cma_object *exec_bo; |
| 305 | |
| 306 | /** |
| 307 | * This tracks the per-shader-record state (packet 64) that |
| 308 | * determines the length of the shader record and the offset |
| 309 | * it's expected to be found at. It gets read in from the |
| 310 | * command lists. |
| 311 | */ |
| 312 | struct vc4_shader_state { |
| 313 | uint32_t addr; |
| 314 | /* Maximum vertex index referenced by any primitive using this |
| 315 | * shader state. |
| 316 | */ |
| 317 | uint32_t max_index; |
| 318 | } *shader_state; |
| 319 | |
| 320 | /** How many shader states the user declared they were using. */ |
| 321 | uint32_t shader_state_size; |
| 322 | /** How many shader state records the validator has seen. */ |
| 323 | uint32_t shader_state_count; |
| 324 | |
| 325 | bool found_tile_binning_mode_config_packet; |
| 326 | bool found_start_tile_binning_packet; |
| 327 | bool found_increment_semaphore_packet; |
| 328 | bool found_flush; |
| 329 | uint8_t bin_tiles_x, bin_tiles_y; |
Eric Anholt | 553c942 | 2017-03-27 16:10:25 -0700 | [diff] [blame^] | 330 | /* Physical address of the start of the tile alloc array |
| 331 | * (where each tile's binned CL will start) |
| 332 | */ |
Eric Anholt | d5b1a78 | 2015-11-30 12:13:37 -0800 | [diff] [blame] | 333 | uint32_t tile_alloc_offset; |
Eric Anholt | 553c942 | 2017-03-27 16:10:25 -0700 | [diff] [blame^] | 334 | /* Bitmask of which binner slots are freed when this job completes. */ |
| 335 | uint32_t bin_slots; |
Eric Anholt | d5b1a78 | 2015-11-30 12:13:37 -0800 | [diff] [blame] | 336 | |
| 337 | /** |
| 338 | * Computed addresses pointing into exec_bo where we start the |
| 339 | * bin thread (ct0) and render thread (ct1). |
| 340 | */ |
| 341 | uint32_t ct0ca, ct0ea; |
| 342 | uint32_t ct1ca, ct1ea; |
| 343 | |
| 344 | /* Pointer to the unvalidated bin CL (if present). */ |
| 345 | void *bin_u; |
| 346 | |
| 347 | /* Pointers to the shader recs. These paddr gets incremented as CL |
| 348 | * packets are relocated in validate_gl_shader_state, and the vaddrs |
| 349 | * (u and v) get incremented and size decremented as the shader recs |
| 350 | * themselves are validated. |
| 351 | */ |
| 352 | void *shader_rec_u; |
| 353 | void *shader_rec_v; |
| 354 | uint32_t shader_rec_p; |
| 355 | uint32_t shader_rec_size; |
| 356 | |
| 357 | /* Pointers to the uniform data. These pointers are incremented, and |
| 358 | * size decremented, as each batch of uniforms is uploaded. |
| 359 | */ |
| 360 | void *uniforms_u; |
| 361 | void *uniforms_v; |
| 362 | uint32_t uniforms_p; |
| 363 | uint32_t uniforms_size; |
| 364 | }; |
| 365 | |
| 366 | static inline struct vc4_exec_info * |
Varad Gautam | ca26d28 | 2016-02-17 19:08:21 +0530 | [diff] [blame] | 367 | vc4_first_bin_job(struct vc4_dev *vc4) |
Eric Anholt | d5b1a78 | 2015-11-30 12:13:37 -0800 | [diff] [blame] | 368 | { |
Masahiro Yamada | 57b9f56 | 2016-09-13 03:35:20 +0900 | [diff] [blame] | 369 | return list_first_entry_or_null(&vc4->bin_job_list, |
| 370 | struct vc4_exec_info, head); |
Varad Gautam | ca26d28 | 2016-02-17 19:08:21 +0530 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | static inline struct vc4_exec_info * |
| 374 | vc4_first_render_job(struct vc4_dev *vc4) |
| 375 | { |
Masahiro Yamada | 57b9f56 | 2016-09-13 03:35:20 +0900 | [diff] [blame] | 376 | return list_first_entry_or_null(&vc4->render_job_list, |
| 377 | struct vc4_exec_info, head); |
Eric Anholt | d5b1a78 | 2015-11-30 12:13:37 -0800 | [diff] [blame] | 378 | } |
| 379 | |
Eric Anholt | 9326e6f | 2016-07-26 13:47:14 -0700 | [diff] [blame] | 380 | static inline struct vc4_exec_info * |
| 381 | vc4_last_render_job(struct vc4_dev *vc4) |
| 382 | { |
| 383 | if (list_empty(&vc4->render_job_list)) |
| 384 | return NULL; |
| 385 | return list_last_entry(&vc4->render_job_list, |
| 386 | struct vc4_exec_info, head); |
| 387 | } |
| 388 | |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 389 | /** |
Eric Anholt | 463873d | 2015-11-30 11:41:40 -0800 | [diff] [blame] | 390 | * struct vc4_texture_sample_info - saves the offsets into the UBO for texture |
| 391 | * setup parameters. |
| 392 | * |
| 393 | * This will be used at draw time to relocate the reference to the texture |
| 394 | * contents in p0, and validate that the offset combined with |
| 395 | * width/height/stride/etc. from p1 and p2/p3 doesn't sample outside the BO. |
| 396 | * Note that the hardware treats unprovided config parameters as 0, so not all |
| 397 | * of them need to be set up for every texure sample, and we'll store ~0 as |
| 398 | * the offset to mark the unused ones. |
| 399 | * |
| 400 | * See the VC4 3D architecture guide page 41 ("Texture and Memory Lookup Unit |
| 401 | * Setup") for definitions of the texture parameters. |
| 402 | */ |
| 403 | struct vc4_texture_sample_info { |
| 404 | bool is_direct; |
| 405 | uint32_t p_offset[4]; |
| 406 | }; |
| 407 | |
| 408 | /** |
| 409 | * struct vc4_validated_shader_info - information about validated shaders that |
| 410 | * needs to be used from command list validation. |
| 411 | * |
| 412 | * For a given shader, each time a shader state record references it, we need |
| 413 | * to verify that the shader doesn't read more uniforms than the shader state |
| 414 | * record's uniform BO pointer can provide, and we need to apply relocations |
| 415 | * and validate the shader state record's uniforms that define the texture |
| 416 | * samples. |
| 417 | */ |
| 418 | struct vc4_validated_shader_info { |
| 419 | uint32_t uniforms_size; |
| 420 | uint32_t uniforms_src_size; |
| 421 | uint32_t num_texture_samples; |
| 422 | struct vc4_texture_sample_info *texture_samples; |
Eric Anholt | 6d45c81 | 2016-07-02 12:17:10 -0700 | [diff] [blame] | 423 | |
| 424 | uint32_t num_uniform_addr_offsets; |
| 425 | uint32_t *uniform_addr_offsets; |
Jonas Pfeil | c778cc5 | 2016-11-08 00:18:39 +0100 | [diff] [blame] | 426 | |
| 427 | bool is_threaded; |
Eric Anholt | 463873d | 2015-11-30 11:41:40 -0800 | [diff] [blame] | 428 | }; |
| 429 | |
| 430 | /** |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 431 | * _wait_for - magic (register) wait macro |
| 432 | * |
| 433 | * Does the right thing for modeset paths when run under kdgb or similar atomic |
| 434 | * contexts. Note that it's important that we check the condition again after |
| 435 | * having timed out, since the timeout could be due to preemption or similar and |
| 436 | * we've never had a chance to check the condition before the timeout. |
| 437 | */ |
| 438 | #define _wait_for(COND, MS, W) ({ \ |
| 439 | unsigned long timeout__ = jiffies + msecs_to_jiffies(MS) + 1; \ |
| 440 | int ret__ = 0; \ |
| 441 | while (!(COND)) { \ |
| 442 | if (time_after(jiffies, timeout__)) { \ |
| 443 | if (!(COND)) \ |
| 444 | ret__ = -ETIMEDOUT; \ |
| 445 | break; \ |
| 446 | } \ |
| 447 | if (W && drm_can_sleep()) { \ |
| 448 | msleep(W); \ |
| 449 | } else { \ |
| 450 | cpu_relax(); \ |
| 451 | } \ |
| 452 | } \ |
| 453 | ret__; \ |
| 454 | }) |
| 455 | |
| 456 | #define wait_for(COND, MS) _wait_for(COND, MS, 1) |
| 457 | |
| 458 | /* vc4_bo.c */ |
Eric Anholt | c826a6e | 2015-10-09 20:25:07 -0700 | [diff] [blame] | 459 | struct drm_gem_object *vc4_create_object(struct drm_device *dev, size_t size); |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 460 | void vc4_free_object(struct drm_gem_object *gem_obj); |
Eric Anholt | c826a6e | 2015-10-09 20:25:07 -0700 | [diff] [blame] | 461 | struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t size, |
| 462 | bool from_cache); |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 463 | int vc4_dumb_create(struct drm_file *file_priv, |
| 464 | struct drm_device *dev, |
| 465 | struct drm_mode_create_dumb *args); |
| 466 | struct dma_buf *vc4_prime_export(struct drm_device *dev, |
| 467 | struct drm_gem_object *obj, int flags); |
Eric Anholt | d5bc60f | 2015-01-18 09:33:17 +1300 | [diff] [blame] | 468 | int vc4_create_bo_ioctl(struct drm_device *dev, void *data, |
| 469 | struct drm_file *file_priv); |
Eric Anholt | 463873d | 2015-11-30 11:41:40 -0800 | [diff] [blame] | 470 | int vc4_create_shader_bo_ioctl(struct drm_device *dev, void *data, |
| 471 | struct drm_file *file_priv); |
Eric Anholt | d5bc60f | 2015-01-18 09:33:17 +1300 | [diff] [blame] | 472 | int vc4_mmap_bo_ioctl(struct drm_device *dev, void *data, |
| 473 | struct drm_file *file_priv); |
Eric Anholt | 2146136 | 2015-10-30 10:09:02 -0700 | [diff] [blame] | 474 | int vc4_get_hang_state_ioctl(struct drm_device *dev, void *data, |
| 475 | struct drm_file *file_priv); |
Eric Anholt | 463873d | 2015-11-30 11:41:40 -0800 | [diff] [blame] | 476 | int vc4_mmap(struct file *filp, struct vm_area_struct *vma); |
Eric Anholt | cdec4d3 | 2017-04-12 12:12:02 -0700 | [diff] [blame] | 477 | struct reservation_object *vc4_prime_res_obj(struct drm_gem_object *obj); |
Eric Anholt | 463873d | 2015-11-30 11:41:40 -0800 | [diff] [blame] | 478 | int vc4_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma); |
Eric Anholt | cdec4d3 | 2017-04-12 12:12:02 -0700 | [diff] [blame] | 479 | struct drm_gem_object *vc4_prime_import_sg_table(struct drm_device *dev, |
| 480 | struct dma_buf_attachment *attach, |
| 481 | struct sg_table *sgt); |
Eric Anholt | 463873d | 2015-11-30 11:41:40 -0800 | [diff] [blame] | 482 | void *vc4_prime_vmap(struct drm_gem_object *obj); |
Eric Anholt | c826a6e | 2015-10-09 20:25:07 -0700 | [diff] [blame] | 483 | void vc4_bo_cache_init(struct drm_device *dev); |
| 484 | void vc4_bo_cache_destroy(struct drm_device *dev); |
| 485 | int vc4_bo_stats_debugfs(struct seq_file *m, void *arg); |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 486 | |
| 487 | /* vc4_crtc.c */ |
| 488 | extern struct platform_driver vc4_crtc_driver; |
Derek Foreman | 26fc78f | 2016-11-24 12:11:55 -0600 | [diff] [blame] | 489 | bool vc4_event_pending(struct drm_crtc *crtc); |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 490 | int vc4_crtc_debugfs_regs(struct seq_file *m, void *arg); |
Mario Kleiner | 1bf59f1 | 2016-06-23 08:17:50 +0200 | [diff] [blame] | 491 | int vc4_crtc_get_scanoutpos(struct drm_device *dev, unsigned int crtc_id, |
| 492 | unsigned int flags, int *vpos, int *hpos, |
| 493 | ktime_t *stime, ktime_t *etime, |
| 494 | const struct drm_display_mode *mode); |
| 495 | int vc4_crtc_get_vblank_timestamp(struct drm_device *dev, unsigned int crtc_id, |
| 496 | int *max_error, struct timeval *vblank_time, |
| 497 | unsigned flags); |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 498 | |
| 499 | /* vc4_debugfs.c */ |
| 500 | int vc4_debugfs_init(struct drm_minor *minor); |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 501 | |
| 502 | /* vc4_drv.c */ |
| 503 | void __iomem *vc4_ioremap_regs(struct platform_device *dev, int index); |
| 504 | |
Eric Anholt | 08302c3 | 2016-02-10 11:42:32 -0800 | [diff] [blame] | 505 | /* vc4_dpi.c */ |
| 506 | extern struct platform_driver vc4_dpi_driver; |
| 507 | int vc4_dpi_debugfs_regs(struct seq_file *m, void *unused); |
| 508 | |
Eric Anholt | 4078f57 | 2017-01-31 11:29:11 -0800 | [diff] [blame] | 509 | /* vc4_dsi.c */ |
| 510 | extern struct platform_driver vc4_dsi_driver; |
| 511 | int vc4_dsi_debugfs_regs(struct seq_file *m, void *unused); |
| 512 | |
Eric Anholt | cdec4d3 | 2017-04-12 12:12:02 -0700 | [diff] [blame] | 513 | /* vc4_fence.c */ |
| 514 | extern const struct dma_fence_ops vc4_fence_ops; |
| 515 | |
Eric Anholt | d5b1a78 | 2015-11-30 12:13:37 -0800 | [diff] [blame] | 516 | /* vc4_gem.c */ |
| 517 | void vc4_gem_init(struct drm_device *dev); |
| 518 | void vc4_gem_destroy(struct drm_device *dev); |
| 519 | int vc4_submit_cl_ioctl(struct drm_device *dev, void *data, |
| 520 | struct drm_file *file_priv); |
| 521 | int vc4_wait_seqno_ioctl(struct drm_device *dev, void *data, |
| 522 | struct drm_file *file_priv); |
| 523 | int vc4_wait_bo_ioctl(struct drm_device *dev, void *data, |
| 524 | struct drm_file *file_priv); |
Varad Gautam | ca26d28 | 2016-02-17 19:08:21 +0530 | [diff] [blame] | 525 | void vc4_submit_next_bin_job(struct drm_device *dev); |
| 526 | void vc4_submit_next_render_job(struct drm_device *dev); |
| 527 | void vc4_move_job_to_render(struct drm_device *dev, struct vc4_exec_info *exec); |
Eric Anholt | d5b1a78 | 2015-11-30 12:13:37 -0800 | [diff] [blame] | 528 | int vc4_wait_for_seqno(struct drm_device *dev, uint64_t seqno, |
| 529 | uint64_t timeout_ns, bool interruptible); |
| 530 | void vc4_job_handle_completed(struct vc4_dev *vc4); |
Eric Anholt | b501bac | 2015-11-30 12:34:01 -0800 | [diff] [blame] | 531 | int vc4_queue_seqno_cb(struct drm_device *dev, |
| 532 | struct vc4_seqno_cb *cb, uint64_t seqno, |
| 533 | void (*func)(struct vc4_seqno_cb *cb)); |
Eric Anholt | d5b1a78 | 2015-11-30 12:13:37 -0800 | [diff] [blame] | 534 | |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 535 | /* vc4_hdmi.c */ |
| 536 | extern struct platform_driver vc4_hdmi_driver; |
| 537 | int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused); |
| 538 | |
Boris Brezillon | e4b81f8 | 2016-12-02 14:48:10 +0100 | [diff] [blame] | 539 | /* vc4_hdmi.c */ |
| 540 | extern struct platform_driver vc4_vec_driver; |
| 541 | int vc4_vec_debugfs_regs(struct seq_file *m, void *unused); |
| 542 | |
Eric Anholt | d5b1a78 | 2015-11-30 12:13:37 -0800 | [diff] [blame] | 543 | /* vc4_irq.c */ |
| 544 | irqreturn_t vc4_irq(int irq, void *arg); |
| 545 | void vc4_irq_preinstall(struct drm_device *dev); |
| 546 | int vc4_irq_postinstall(struct drm_device *dev); |
| 547 | void vc4_irq_uninstall(struct drm_device *dev); |
| 548 | void vc4_irq_reset(struct drm_device *dev); |
| 549 | |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 550 | /* vc4_hvs.c */ |
| 551 | extern struct platform_driver vc4_hvs_driver; |
| 552 | void vc4_hvs_dump_state(struct drm_device *dev); |
| 553 | int vc4_hvs_debugfs_regs(struct seq_file *m, void *unused); |
| 554 | |
| 555 | /* vc4_kms.c */ |
| 556 | int vc4_kms_load(struct drm_device *dev); |
| 557 | |
| 558 | /* vc4_plane.c */ |
| 559 | struct drm_plane *vc4_plane_init(struct drm_device *dev, |
| 560 | enum drm_plane_type type); |
| 561 | u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist); |
Daniel Vetter | 2f196b7 | 2016-06-02 16:21:44 +0200 | [diff] [blame] | 562 | u32 vc4_plane_dlist_size(const struct drm_plane_state *state); |
Eric Anholt | b501bac | 2015-11-30 12:34:01 -0800 | [diff] [blame] | 563 | void vc4_plane_async_set_fb(struct drm_plane *plane, |
| 564 | struct drm_framebuffer *fb); |
Eric Anholt | 463873d | 2015-11-30 11:41:40 -0800 | [diff] [blame] | 565 | |
Eric Anholt | d3f5168 | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 566 | /* vc4_v3d.c */ |
| 567 | extern struct platform_driver vc4_v3d_driver; |
| 568 | int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused); |
| 569 | int vc4_v3d_debugfs_regs(struct seq_file *m, void *unused); |
Eric Anholt | 553c942 | 2017-03-27 16:10:25 -0700 | [diff] [blame^] | 570 | int vc4_v3d_get_bin_slot(struct vc4_dev *vc4); |
Eric Anholt | d5b1a78 | 2015-11-30 12:13:37 -0800 | [diff] [blame] | 571 | |
| 572 | /* vc4_validate.c */ |
| 573 | int |
| 574 | vc4_validate_bin_cl(struct drm_device *dev, |
| 575 | void *validated, |
| 576 | void *unvalidated, |
| 577 | struct vc4_exec_info *exec); |
| 578 | |
| 579 | int |
| 580 | vc4_validate_shader_recs(struct drm_device *dev, struct vc4_exec_info *exec); |
| 581 | |
| 582 | struct drm_gem_cma_object *vc4_use_bo(struct vc4_exec_info *exec, |
| 583 | uint32_t hindex); |
| 584 | |
| 585 | int vc4_get_rcl(struct drm_device *dev, struct vc4_exec_info *exec); |
| 586 | |
| 587 | bool vc4_check_tex_size(struct vc4_exec_info *exec, |
| 588 | struct drm_gem_cma_object *fbo, |
| 589 | uint32_t offset, uint8_t tiling_format, |
| 590 | uint32_t width, uint32_t height, uint8_t cpp); |
Eric Anholt | d3f5168 | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 591 | |
Eric Anholt | 463873d | 2015-11-30 11:41:40 -0800 | [diff] [blame] | 592 | /* vc4_validate_shader.c */ |
| 593 | struct vc4_validated_shader_info * |
| 594 | vc4_validate_shader(struct drm_gem_cma_object *shader_obj); |